]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-2.9.1-3.6.7-201211172032.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.6.7-201211172032.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..de0bb2d 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,280 @@ 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 +#ifdef CONFIG_PARAVIRT
15973 + PV_RESTORE_REGS(CLBR_RDI);
15974 +#endif
15975 +
15976 + popq %rdi
15977 + pax_force_retaddr
15978 + retq
15979 +ENDPROC(pax_exit_kernel)
15980 +#endif
15981 +
15982 + .macro pax_enter_kernel_user
15983 + pax_set_fptr_mask
15984 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15985 + call pax_enter_kernel_user
15986 +#endif
15987 + .endm
15988 +
15989 + .macro pax_exit_kernel_user
15990 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15991 + call pax_exit_kernel_user
15992 +#endif
15993 +#ifdef CONFIG_PAX_RANDKSTACK
15994 + pushq %rax
15995 + call pax_randomize_kstack
15996 + popq %rax
15997 +#endif
15998 + .endm
15999 +
16000 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16001 +ENTRY(pax_enter_kernel_user)
16002 + pushq %rdi
16003 + pushq %rbx
16004 +
16005 +#ifdef CONFIG_PARAVIRT
16006 + PV_SAVE_REGS(CLBR_RDI)
16007 +#endif
16008 +
16009 + GET_CR3_INTO_RDI
16010 + mov %rdi,%rbx
16011 + add $__START_KERNEL_map,%rbx
16012 + sub phys_base(%rip),%rbx
16013 +
16014 +#ifdef CONFIG_PARAVIRT
16015 + pushq %rdi
16016 + cmpl $0, pv_info+PARAVIRT_enabled
16017 + jz 1f
16018 + i = 0
16019 + .rept USER_PGD_PTRS
16020 + mov i*8(%rbx),%rsi
16021 + mov $0,%sil
16022 + lea i*8(%rbx),%rdi
16023 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
16024 + i = i + 1
16025 + .endr
16026 + jmp 2f
16027 +1:
16028 +#endif
16029 +
16030 + i = 0
16031 + .rept USER_PGD_PTRS
16032 + movb $0,i*8(%rbx)
16033 + i = i + 1
16034 + .endr
16035 +
16036 +#ifdef CONFIG_PARAVIRT
16037 +2: popq %rdi
16038 +#endif
16039 + SET_RDI_INTO_CR3
16040 +
16041 +#ifdef CONFIG_PAX_KERNEXEC
16042 + GET_CR0_INTO_RDI
16043 + bts $16,%rdi
16044 + SET_RDI_INTO_CR0
16045 +#endif
16046 +
16047 +#ifdef CONFIG_PARAVIRT
16048 + PV_RESTORE_REGS(CLBR_RDI)
16049 +#endif
16050 +
16051 + popq %rbx
16052 + popq %rdi
16053 + pax_force_retaddr
16054 + retq
16055 +ENDPROC(pax_enter_kernel_user)
16056 +
16057 +ENTRY(pax_exit_kernel_user)
16058 + push %rdi
16059 +
16060 +#ifdef CONFIG_PARAVIRT
16061 + pushq %rbx
16062 + PV_SAVE_REGS(CLBR_RDI)
16063 +#endif
16064 +
16065 +#ifdef CONFIG_PAX_KERNEXEC
16066 + GET_CR0_INTO_RDI
16067 + btr $16,%rdi
16068 + SET_RDI_INTO_CR0
16069 +#endif
16070 +
16071 + GET_CR3_INTO_RDI
16072 + add $__START_KERNEL_map,%rdi
16073 + sub phys_base(%rip),%rdi
16074 +
16075 +#ifdef CONFIG_PARAVIRT
16076 + cmpl $0, pv_info+PARAVIRT_enabled
16077 + jz 1f
16078 + mov %rdi,%rbx
16079 + i = 0
16080 + .rept USER_PGD_PTRS
16081 + mov i*8(%rbx),%rsi
16082 + mov $0x67,%sil
16083 + lea i*8(%rbx),%rdi
16084 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
16085 + i = i + 1
16086 + .endr
16087 + jmp 2f
16088 +1:
16089 +#endif
16090 +
16091 + i = 0
16092 + .rept USER_PGD_PTRS
16093 + movb $0x67,i*8(%rdi)
16094 + i = i + 1
16095 + .endr
16096 +
16097 +#ifdef CONFIG_PARAVIRT
16098 +2: PV_RESTORE_REGS(CLBR_RDI)
16099 + popq %rbx
16100 +#endif
16101 +
16102 + popq %rdi
16103 + pax_force_retaddr
16104 + retq
16105 +ENDPROC(pax_exit_kernel_user)
16106 +#endif
16107 +
16108 +.macro pax_erase_kstack
16109 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16110 + call pax_erase_kstack
16111 +#endif
16112 +.endm
16113 +
16114 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16115 +ENTRY(pax_erase_kstack)
16116 + pushq %rdi
16117 + pushq %rcx
16118 + pushq %rax
16119 + pushq %r11
16120 +
16121 + GET_THREAD_INFO(%r11)
16122 + mov TI_lowest_stack(%r11), %rdi
16123 + mov $-0xBEEF, %rax
16124 + std
16125 +
16126 +1: mov %edi, %ecx
16127 + and $THREAD_SIZE_asm - 1, %ecx
16128 + shr $3, %ecx
16129 + repne scasq
16130 + jecxz 2f
16131 +
16132 + cmp $2*8, %ecx
16133 + jc 2f
16134 +
16135 + mov $2*8, %ecx
16136 + repe scasq
16137 + jecxz 2f
16138 + jne 1b
16139 +
16140 +2: cld
16141 + mov %esp, %ecx
16142 + sub %edi, %ecx
16143 +
16144 + cmp $THREAD_SIZE_asm, %rcx
16145 + jb 3f
16146 + ud2
16147 +3:
16148 +
16149 + shr $3, %ecx
16150 + rep stosq
16151 +
16152 + mov TI_task_thread_sp0(%r11), %rdi
16153 + sub $256, %rdi
16154 + mov %rdi, TI_lowest_stack(%r11)
16155 +
16156 + popq %r11
16157 + popq %rax
16158 + popq %rcx
16159 + popq %rdi
16160 + pax_force_retaddr
16161 + ret
16162 +ENDPROC(pax_erase_kstack)
16163 +#endif
16164
16165 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
16166 #ifdef CONFIG_TRACE_IRQFLAGS
16167 @@ -271,8 +553,8 @@ ENDPROC(native_usergs_sysret64)
16168 .endm
16169
16170 .macro UNFAKE_STACK_FRAME
16171 - addq $8*6, %rsp
16172 - CFI_ADJUST_CFA_OFFSET -(6*8)
16173 + addq $8*6 + ARG_SKIP, %rsp
16174 + CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
16175 .endm
16176
16177 /*
16178 @@ -359,7 +641,7 @@ ENDPROC(native_usergs_sysret64)
16179 movq %rsp, %rsi
16180
16181 leaq -RBP(%rsp),%rdi /* arg1 for handler */
16182 - testl $3, CS-RBP(%rsi)
16183 + testb $3, CS-RBP(%rsi)
16184 je 1f
16185 SWAPGS
16186 /*
16187 @@ -394,9 +676,10 @@ ENTRY(save_rest)
16188 movq_cfi r15, R15+16
16189 movq %r11, 8(%rsp) /* return address */
16190 FIXUP_TOP_OF_STACK %r11, 16
16191 + pax_force_retaddr
16192 ret
16193 CFI_ENDPROC
16194 -END(save_rest)
16195 +ENDPROC(save_rest)
16196
16197 /* save complete stack frame */
16198 .pushsection .kprobes.text, "ax"
16199 @@ -425,9 +708,10 @@ ENTRY(save_paranoid)
16200 js 1f /* negative -> in kernel */
16201 SWAPGS
16202 xorl %ebx,%ebx
16203 -1: ret
16204 +1: pax_force_retaddr_bts
16205 + ret
16206 CFI_ENDPROC
16207 -END(save_paranoid)
16208 +ENDPROC(save_paranoid)
16209 .popsection
16210
16211 /*
16212 @@ -449,7 +733,7 @@ ENTRY(ret_from_fork)
16213
16214 RESTORE_REST
16215
16216 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16217 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16218 jz retint_restore_args
16219
16220 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
16221 @@ -459,7 +743,7 @@ ENTRY(ret_from_fork)
16222 jmp ret_from_sys_call # go to the SYSRET fastpath
16223
16224 CFI_ENDPROC
16225 -END(ret_from_fork)
16226 +ENDPROC(ret_from_fork)
16227
16228 /*
16229 * System call entry. Up to 6 arguments in registers are supported.
16230 @@ -495,7 +779,7 @@ END(ret_from_fork)
16231 ENTRY(system_call)
16232 CFI_STARTPROC simple
16233 CFI_SIGNAL_FRAME
16234 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
16235 + CFI_DEF_CFA rsp,0
16236 CFI_REGISTER rip,rcx
16237 /*CFI_REGISTER rflags,r11*/
16238 SWAPGS_UNSAFE_STACK
16239 @@ -508,16 +792,23 @@ GLOBAL(system_call_after_swapgs)
16240
16241 movq %rsp,PER_CPU_VAR(old_rsp)
16242 movq PER_CPU_VAR(kernel_stack),%rsp
16243 + SAVE_ARGS 8*6,0
16244 + pax_enter_kernel_user
16245 +
16246 +#ifdef CONFIG_PAX_RANDKSTACK
16247 + pax_erase_kstack
16248 +#endif
16249 +
16250 /*
16251 * No need to follow this irqs off/on section - it's straight
16252 * and short:
16253 */
16254 ENABLE_INTERRUPTS(CLBR_NONE)
16255 - SAVE_ARGS 8,0
16256 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
16257 movq %rcx,RIP-ARGOFFSET(%rsp)
16258 CFI_REL_OFFSET rip,RIP-ARGOFFSET
16259 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16260 + GET_THREAD_INFO(%rcx)
16261 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
16262 jnz tracesys
16263 system_call_fastpath:
16264 #if __SYSCALL_MASK == ~0
16265 @@ -527,7 +818,7 @@ system_call_fastpath:
16266 cmpl $__NR_syscall_max,%eax
16267 #endif
16268 ja badsys
16269 - movq %r10,%rcx
16270 + movq R10-ARGOFFSET(%rsp),%rcx
16271 call *sys_call_table(,%rax,8) # XXX: rip relative
16272 movq %rax,RAX-ARGOFFSET(%rsp)
16273 /*
16274 @@ -541,10 +832,13 @@ sysret_check:
16275 LOCKDEP_SYS_EXIT
16276 DISABLE_INTERRUPTS(CLBR_NONE)
16277 TRACE_IRQS_OFF
16278 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
16279 + GET_THREAD_INFO(%rcx)
16280 + movl TI_flags(%rcx),%edx
16281 andl %edi,%edx
16282 jnz sysret_careful
16283 CFI_REMEMBER_STATE
16284 + pax_exit_kernel_user
16285 + pax_erase_kstack
16286 /*
16287 * sysretq will re-enable interrupts:
16288 */
16289 @@ -596,14 +890,18 @@ badsys:
16290 * jump back to the normal fast path.
16291 */
16292 auditsys:
16293 - movq %r10,%r9 /* 6th arg: 4th syscall arg */
16294 + movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
16295 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
16296 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
16297 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
16298 movq %rax,%rsi /* 2nd arg: syscall number */
16299 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
16300 call __audit_syscall_entry
16301 +
16302 + pax_erase_kstack
16303 +
16304 LOAD_ARGS 0 /* reload call-clobbered registers */
16305 + pax_set_fptr_mask
16306 jmp system_call_fastpath
16307
16308 /*
16309 @@ -624,7 +922,7 @@ sysret_audit:
16310 /* Do syscall tracing */
16311 tracesys:
16312 #ifdef CONFIG_AUDITSYSCALL
16313 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16314 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
16315 jz auditsys
16316 #endif
16317 SAVE_REST
16318 @@ -632,12 +930,16 @@ tracesys:
16319 FIXUP_TOP_OF_STACK %rdi
16320 movq %rsp,%rdi
16321 call syscall_trace_enter
16322 +
16323 + pax_erase_kstack
16324 +
16325 /*
16326 * Reload arg registers from stack in case ptrace changed them.
16327 * We don't reload %rax because syscall_trace_enter() returned
16328 * the value it wants us to use in the table lookup.
16329 */
16330 LOAD_ARGS ARGOFFSET, 1
16331 + pax_set_fptr_mask
16332 RESTORE_REST
16333 #if __SYSCALL_MASK == ~0
16334 cmpq $__NR_syscall_max,%rax
16335 @@ -646,7 +948,7 @@ tracesys:
16336 cmpl $__NR_syscall_max,%eax
16337 #endif
16338 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
16339 - movq %r10,%rcx /* fixup for C */
16340 + movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
16341 call *sys_call_table(,%rax,8)
16342 movq %rax,RAX-ARGOFFSET(%rsp)
16343 /* Use IRET because user could have changed frame */
16344 @@ -667,7 +969,9 @@ GLOBAL(int_with_check)
16345 andl %edi,%edx
16346 jnz int_careful
16347 andl $~TS_COMPAT,TI_status(%rcx)
16348 - jmp retint_swapgs
16349 + pax_exit_kernel_user
16350 + pax_erase_kstack
16351 + jmp retint_swapgs_pax
16352
16353 /* Either reschedule or signal or syscall exit tracking needed. */
16354 /* First do a reschedule test. */
16355 @@ -713,7 +1017,7 @@ int_restore_rest:
16356 TRACE_IRQS_OFF
16357 jmp int_with_check
16358 CFI_ENDPROC
16359 -END(system_call)
16360 +ENDPROC(system_call)
16361
16362 /*
16363 * Certain special system calls that need to save a complete full stack frame.
16364 @@ -729,7 +1033,7 @@ ENTRY(\label)
16365 call \func
16366 jmp ptregscall_common
16367 CFI_ENDPROC
16368 -END(\label)
16369 +ENDPROC(\label)
16370 .endm
16371
16372 PTREGSCALL stub_clone, sys_clone, %r8
16373 @@ -747,9 +1051,10 @@ ENTRY(ptregscall_common)
16374 movq_cfi_restore R12+8, r12
16375 movq_cfi_restore RBP+8, rbp
16376 movq_cfi_restore RBX+8, rbx
16377 + pax_force_retaddr
16378 ret $REST_SKIP /* pop extended registers */
16379 CFI_ENDPROC
16380 -END(ptregscall_common)
16381 +ENDPROC(ptregscall_common)
16382
16383 ENTRY(stub_execve)
16384 CFI_STARTPROC
16385 @@ -764,7 +1069,7 @@ ENTRY(stub_execve)
16386 RESTORE_REST
16387 jmp int_ret_from_sys_call
16388 CFI_ENDPROC
16389 -END(stub_execve)
16390 +ENDPROC(stub_execve)
16391
16392 /*
16393 * sigreturn is special because it needs to restore all registers on return.
16394 @@ -782,7 +1087,7 @@ ENTRY(stub_rt_sigreturn)
16395 RESTORE_REST
16396 jmp int_ret_from_sys_call
16397 CFI_ENDPROC
16398 -END(stub_rt_sigreturn)
16399 +ENDPROC(stub_rt_sigreturn)
16400
16401 #ifdef CONFIG_X86_X32_ABI
16402 PTREGSCALL stub_x32_sigaltstack, sys32_sigaltstack, %rdx
16403 @@ -851,7 +1156,7 @@ vector=vector+1
16404 2: jmp common_interrupt
16405 .endr
16406 CFI_ENDPROC
16407 -END(irq_entries_start)
16408 +ENDPROC(irq_entries_start)
16409
16410 .previous
16411 END(interrupt)
16412 @@ -871,6 +1176,16 @@ END(interrupt)
16413 subq $ORIG_RAX-RBP, %rsp
16414 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
16415 SAVE_ARGS_IRQ
16416 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16417 + testb $3, CS(%rdi)
16418 + jnz 1f
16419 + pax_enter_kernel
16420 + jmp 2f
16421 +1: pax_enter_kernel_user
16422 +2:
16423 +#else
16424 + pax_enter_kernel
16425 +#endif
16426 call \func
16427 .endm
16428
16429 @@ -902,7 +1217,7 @@ ret_from_intr:
16430
16431 exit_intr:
16432 GET_THREAD_INFO(%rcx)
16433 - testl $3,CS-ARGOFFSET(%rsp)
16434 + testb $3,CS-ARGOFFSET(%rsp)
16435 je retint_kernel
16436
16437 /* Interrupt came from user space */
16438 @@ -924,12 +1239,16 @@ retint_swapgs: /* return to user-space */
16439 * The iretq could re-enable interrupts:
16440 */
16441 DISABLE_INTERRUPTS(CLBR_ANY)
16442 + pax_exit_kernel_user
16443 +retint_swapgs_pax:
16444 TRACE_IRQS_IRETQ
16445 SWAPGS
16446 jmp restore_args
16447
16448 retint_restore_args: /* return to kernel space */
16449 DISABLE_INTERRUPTS(CLBR_ANY)
16450 + pax_exit_kernel
16451 + pax_force_retaddr RIP-ARGOFFSET
16452 /*
16453 * The iretq could re-enable interrupts:
16454 */
16455 @@ -1012,7 +1331,7 @@ ENTRY(retint_kernel)
16456 #endif
16457
16458 CFI_ENDPROC
16459 -END(common_interrupt)
16460 +ENDPROC(common_interrupt)
16461 /*
16462 * End of kprobes section
16463 */
16464 @@ -1029,7 +1348,7 @@ ENTRY(\sym)
16465 interrupt \do_sym
16466 jmp ret_from_intr
16467 CFI_ENDPROC
16468 -END(\sym)
16469 +ENDPROC(\sym)
16470 .endm
16471
16472 #ifdef CONFIG_SMP
16473 @@ -1084,12 +1403,22 @@ ENTRY(\sym)
16474 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16475 call error_entry
16476 DEFAULT_FRAME 0
16477 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16478 + testb $3, CS(%rsp)
16479 + jnz 1f
16480 + pax_enter_kernel
16481 + jmp 2f
16482 +1: pax_enter_kernel_user
16483 +2:
16484 +#else
16485 + pax_enter_kernel
16486 +#endif
16487 movq %rsp,%rdi /* pt_regs pointer */
16488 xorl %esi,%esi /* no error code */
16489 call \do_sym
16490 jmp error_exit /* %ebx: no swapgs flag */
16491 CFI_ENDPROC
16492 -END(\sym)
16493 +ENDPROC(\sym)
16494 .endm
16495
16496 .macro paranoidzeroentry sym do_sym
16497 @@ -1101,15 +1430,25 @@ ENTRY(\sym)
16498 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16499 call save_paranoid
16500 TRACE_IRQS_OFF
16501 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16502 + testb $3, CS(%rsp)
16503 + jnz 1f
16504 + pax_enter_kernel
16505 + jmp 2f
16506 +1: pax_enter_kernel_user
16507 +2:
16508 +#else
16509 + pax_enter_kernel
16510 +#endif
16511 movq %rsp,%rdi /* pt_regs pointer */
16512 xorl %esi,%esi /* no error code */
16513 call \do_sym
16514 jmp paranoid_exit /* %ebx: no swapgs flag */
16515 CFI_ENDPROC
16516 -END(\sym)
16517 +ENDPROC(\sym)
16518 .endm
16519
16520 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
16521 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
16522 .macro paranoidzeroentry_ist sym do_sym ist
16523 ENTRY(\sym)
16524 INTR_FRAME
16525 @@ -1119,14 +1458,30 @@ ENTRY(\sym)
16526 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16527 call save_paranoid
16528 TRACE_IRQS_OFF_DEBUG
16529 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16530 + testb $3, CS(%rsp)
16531 + jnz 1f
16532 + pax_enter_kernel
16533 + jmp 2f
16534 +1: pax_enter_kernel_user
16535 +2:
16536 +#else
16537 + pax_enter_kernel
16538 +#endif
16539 movq %rsp,%rdi /* pt_regs pointer */
16540 xorl %esi,%esi /* no error code */
16541 +#ifdef CONFIG_SMP
16542 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
16543 + lea init_tss(%r12), %r12
16544 +#else
16545 + lea init_tss(%rip), %r12
16546 +#endif
16547 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16548 call \do_sym
16549 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16550 jmp paranoid_exit /* %ebx: no swapgs flag */
16551 CFI_ENDPROC
16552 -END(\sym)
16553 +ENDPROC(\sym)
16554 .endm
16555
16556 .macro errorentry sym do_sym
16557 @@ -1137,13 +1492,23 @@ ENTRY(\sym)
16558 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16559 call error_entry
16560 DEFAULT_FRAME 0
16561 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16562 + testb $3, CS(%rsp)
16563 + jnz 1f
16564 + pax_enter_kernel
16565 + jmp 2f
16566 +1: pax_enter_kernel_user
16567 +2:
16568 +#else
16569 + pax_enter_kernel
16570 +#endif
16571 movq %rsp,%rdi /* pt_regs pointer */
16572 movq ORIG_RAX(%rsp),%rsi /* get error code */
16573 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16574 call \do_sym
16575 jmp error_exit /* %ebx: no swapgs flag */
16576 CFI_ENDPROC
16577 -END(\sym)
16578 +ENDPROC(\sym)
16579 .endm
16580
16581 /* error code is on the stack already */
16582 @@ -1156,13 +1521,23 @@ ENTRY(\sym)
16583 call save_paranoid
16584 DEFAULT_FRAME 0
16585 TRACE_IRQS_OFF
16586 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16587 + testb $3, CS(%rsp)
16588 + jnz 1f
16589 + pax_enter_kernel
16590 + jmp 2f
16591 +1: pax_enter_kernel_user
16592 +2:
16593 +#else
16594 + pax_enter_kernel
16595 +#endif
16596 movq %rsp,%rdi /* pt_regs pointer */
16597 movq ORIG_RAX(%rsp),%rsi /* get error code */
16598 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16599 call \do_sym
16600 jmp paranoid_exit /* %ebx: no swapgs flag */
16601 CFI_ENDPROC
16602 -END(\sym)
16603 +ENDPROC(\sym)
16604 .endm
16605
16606 zeroentry divide_error do_divide_error
16607 @@ -1192,9 +1567,10 @@ gs_change:
16608 2: mfence /* workaround */
16609 SWAPGS
16610 popfq_cfi
16611 + pax_force_retaddr
16612 ret
16613 CFI_ENDPROC
16614 -END(native_load_gs_index)
16615 +ENDPROC(native_load_gs_index)
16616
16617 _ASM_EXTABLE(gs_change,bad_gs)
16618 .section .fixup,"ax"
16619 @@ -1213,13 +1589,14 @@ ENTRY(kernel_thread_helper)
16620 * Here we are in the child and the registers are set as they were
16621 * at kernel_thread() invocation in the parent.
16622 */
16623 + pax_force_fptr %rsi
16624 call *%rsi
16625 # exit
16626 mov %eax, %edi
16627 call do_exit
16628 ud2 # padding for call trace
16629 CFI_ENDPROC
16630 -END(kernel_thread_helper)
16631 +ENDPROC(kernel_thread_helper)
16632
16633 /*
16634 * execve(). This function needs to use IRET, not SYSRET, to set up all state properly.
16635 @@ -1246,11 +1623,11 @@ ENTRY(kernel_execve)
16636 RESTORE_REST
16637 testq %rax,%rax
16638 je int_ret_from_sys_call
16639 - RESTORE_ARGS
16640 UNFAKE_STACK_FRAME
16641 + pax_force_retaddr
16642 ret
16643 CFI_ENDPROC
16644 -END(kernel_execve)
16645 +ENDPROC(kernel_execve)
16646
16647 /* Call softirq on interrupt stack. Interrupts are off. */
16648 ENTRY(call_softirq)
16649 @@ -1268,9 +1645,10 @@ ENTRY(call_softirq)
16650 CFI_DEF_CFA_REGISTER rsp
16651 CFI_ADJUST_CFA_OFFSET -8
16652 decl PER_CPU_VAR(irq_count)
16653 + pax_force_retaddr
16654 ret
16655 CFI_ENDPROC
16656 -END(call_softirq)
16657 +ENDPROC(call_softirq)
16658
16659 #ifdef CONFIG_XEN
16660 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
16661 @@ -1308,7 +1686,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
16662 decl PER_CPU_VAR(irq_count)
16663 jmp error_exit
16664 CFI_ENDPROC
16665 -END(xen_do_hypervisor_callback)
16666 +ENDPROC(xen_do_hypervisor_callback)
16667
16668 /*
16669 * Hypervisor uses this for application faults while it executes.
16670 @@ -1367,7 +1745,7 @@ ENTRY(xen_failsafe_callback)
16671 SAVE_ALL
16672 jmp error_exit
16673 CFI_ENDPROC
16674 -END(xen_failsafe_callback)
16675 +ENDPROC(xen_failsafe_callback)
16676
16677 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
16678 xen_hvm_callback_vector xen_evtchn_do_upcall
16679 @@ -1416,16 +1794,31 @@ ENTRY(paranoid_exit)
16680 TRACE_IRQS_OFF_DEBUG
16681 testl %ebx,%ebx /* swapgs needed? */
16682 jnz paranoid_restore
16683 - testl $3,CS(%rsp)
16684 + testb $3,CS(%rsp)
16685 jnz paranoid_userspace
16686 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16687 + pax_exit_kernel
16688 + TRACE_IRQS_IRETQ 0
16689 + SWAPGS_UNSAFE_STACK
16690 + RESTORE_ALL 8
16691 + pax_force_retaddr_bts
16692 + jmp irq_return
16693 +#endif
16694 paranoid_swapgs:
16695 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16696 + pax_exit_kernel_user
16697 +#else
16698 + pax_exit_kernel
16699 +#endif
16700 TRACE_IRQS_IRETQ 0
16701 SWAPGS_UNSAFE_STACK
16702 RESTORE_ALL 8
16703 jmp irq_return
16704 paranoid_restore:
16705 + pax_exit_kernel
16706 TRACE_IRQS_IRETQ_DEBUG 0
16707 RESTORE_ALL 8
16708 + pax_force_retaddr_bts
16709 jmp irq_return
16710 paranoid_userspace:
16711 GET_THREAD_INFO(%rcx)
16712 @@ -1454,7 +1847,7 @@ paranoid_schedule:
16713 TRACE_IRQS_OFF
16714 jmp paranoid_userspace
16715 CFI_ENDPROC
16716 -END(paranoid_exit)
16717 +ENDPROC(paranoid_exit)
16718
16719 /*
16720 * Exception entry point. This expects an error code/orig_rax on the stack.
16721 @@ -1481,12 +1874,13 @@ ENTRY(error_entry)
16722 movq_cfi r14, R14+8
16723 movq_cfi r15, R15+8
16724 xorl %ebx,%ebx
16725 - testl $3,CS+8(%rsp)
16726 + testb $3,CS+8(%rsp)
16727 je error_kernelspace
16728 error_swapgs:
16729 SWAPGS
16730 error_sti:
16731 TRACE_IRQS_OFF
16732 + pax_force_retaddr_bts
16733 ret
16734
16735 /*
16736 @@ -1513,7 +1907,7 @@ bstep_iret:
16737 movq %rcx,RIP+8(%rsp)
16738 jmp error_swapgs
16739 CFI_ENDPROC
16740 -END(error_entry)
16741 +ENDPROC(error_entry)
16742
16743
16744 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
16745 @@ -1533,7 +1927,7 @@ ENTRY(error_exit)
16746 jnz retint_careful
16747 jmp retint_swapgs
16748 CFI_ENDPROC
16749 -END(error_exit)
16750 +ENDPROC(error_exit)
16751
16752 /*
16753 * Test if a given stack is an NMI stack or not.
16754 @@ -1591,9 +1985,11 @@ ENTRY(nmi)
16755 * If %cs was not the kernel segment, then the NMI triggered in user
16756 * space, which means it is definitely not nested.
16757 */
16758 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
16759 + je 1f
16760 cmpl $__KERNEL_CS, 16(%rsp)
16761 jne first_nmi
16762 -
16763 +1:
16764 /*
16765 * Check the special variable on the stack to see if NMIs are
16766 * executing.
16767 @@ -1752,6 +2148,17 @@ end_repeat_nmi:
16768 */
16769 movq %cr2, %r12
16770
16771 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16772 + testb $3, CS(%rsp)
16773 + jnz 1f
16774 + pax_enter_kernel
16775 + jmp 2f
16776 +1: pax_enter_kernel_user
16777 +2:
16778 +#else
16779 + pax_enter_kernel
16780 +#endif
16781 +
16782 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
16783 movq %rsp,%rdi
16784 movq $-1,%rsi
16785 @@ -1767,21 +2174,32 @@ end_repeat_nmi:
16786 testl %ebx,%ebx /* swapgs needed? */
16787 jnz nmi_restore
16788 nmi_swapgs:
16789 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16790 + pax_exit_kernel_user
16791 +#else
16792 + pax_exit_kernel
16793 +#endif
16794 SWAPGS_UNSAFE_STACK
16795 + RESTORE_ALL 8
16796 + /* Clear the NMI executing stack variable */
16797 + movq $0, 10*8(%rsp)
16798 + jmp irq_return
16799 nmi_restore:
16800 + pax_exit_kernel
16801 RESTORE_ALL 8
16802 + pax_force_retaddr_bts
16803 /* Clear the NMI executing stack variable */
16804 movq $0, 10*8(%rsp)
16805 jmp irq_return
16806 CFI_ENDPROC
16807 -END(nmi)
16808 +ENDPROC(nmi)
16809
16810 ENTRY(ignore_sysret)
16811 CFI_STARTPROC
16812 mov $-ENOSYS,%eax
16813 sysret
16814 CFI_ENDPROC
16815 -END(ignore_sysret)
16816 +ENDPROC(ignore_sysret)
16817
16818 /*
16819 * End of kprobes section
16820 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
16821 index c3a7cb4..3ad00dc 100644
16822 --- a/arch/x86/kernel/ftrace.c
16823 +++ b/arch/x86/kernel/ftrace.c
16824 @@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
16825 {
16826 unsigned char replaced[MCOUNT_INSN_SIZE];
16827
16828 + ip = ktla_ktva(ip);
16829 +
16830 /*
16831 * Note: Due to modules and __init, code can
16832 * disappear and change, we need to protect against faulting
16833 @@ -212,7 +214,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
16834 unsigned char old[MCOUNT_INSN_SIZE], *new;
16835 int ret;
16836
16837 - memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
16838 + memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
16839 new = ftrace_call_replace(ip, (unsigned long)func);
16840
16841 /* See comment above by declaration of modifying_ftrace_code */
16842 @@ -605,6 +607,8 @@ static int ftrace_mod_jmp(unsigned long ip,
16843 {
16844 unsigned char code[MCOUNT_INSN_SIZE];
16845
16846 + ip = ktla_ktva(ip);
16847 +
16848 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
16849 return -EFAULT;
16850
16851 diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
16852 index c18f59d..9c0c9f6 100644
16853 --- a/arch/x86/kernel/head32.c
16854 +++ b/arch/x86/kernel/head32.c
16855 @@ -18,6 +18,7 @@
16856 #include <asm/io_apic.h>
16857 #include <asm/bios_ebda.h>
16858 #include <asm/tlbflush.h>
16859 +#include <asm/boot.h>
16860
16861 static void __init i386_default_early_setup(void)
16862 {
16863 @@ -30,8 +31,7 @@ static void __init i386_default_early_setup(void)
16864
16865 void __init i386_start_kernel(void)
16866 {
16867 - memblock_reserve(__pa_symbol(&_text),
16868 - __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
16869 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
16870
16871 #ifdef CONFIG_BLK_DEV_INITRD
16872 /* Reserve INITRD */
16873 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
16874 index d42ab17..87b9555 100644
16875 --- a/arch/x86/kernel/head_32.S
16876 +++ b/arch/x86/kernel/head_32.S
16877 @@ -26,6 +26,12 @@
16878 /* Physical address */
16879 #define pa(X) ((X) - __PAGE_OFFSET)
16880
16881 +#ifdef CONFIG_PAX_KERNEXEC
16882 +#define ta(X) (X)
16883 +#else
16884 +#define ta(X) ((X) - __PAGE_OFFSET)
16885 +#endif
16886 +
16887 /*
16888 * References to members of the new_cpu_data structure.
16889 */
16890 @@ -55,11 +61,7 @@
16891 * and small than max_low_pfn, otherwise will waste some page table entries
16892 */
16893
16894 -#if PTRS_PER_PMD > 1
16895 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
16896 -#else
16897 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
16898 -#endif
16899 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
16900
16901 /* Number of possible pages in the lowmem region */
16902 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
16903 @@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
16904 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16905
16906 /*
16907 + * Real beginning of normal "text" segment
16908 + */
16909 +ENTRY(stext)
16910 +ENTRY(_stext)
16911 +
16912 +/*
16913 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
16914 * %esi points to the real-mode code as a 32-bit pointer.
16915 * CS and DS must be 4 GB flat segments, but we don't depend on
16916 @@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16917 * can.
16918 */
16919 __HEAD
16920 +
16921 +#ifdef CONFIG_PAX_KERNEXEC
16922 + jmp startup_32
16923 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
16924 +.fill PAGE_SIZE-5,1,0xcc
16925 +#endif
16926 +
16927 ENTRY(startup_32)
16928 movl pa(stack_start),%ecx
16929
16930 @@ -106,6 +121,59 @@ ENTRY(startup_32)
16931 2:
16932 leal -__PAGE_OFFSET(%ecx),%esp
16933
16934 +#ifdef CONFIG_SMP
16935 + movl $pa(cpu_gdt_table),%edi
16936 + movl $__per_cpu_load,%eax
16937 + movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
16938 + rorl $16,%eax
16939 + movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
16940 + movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
16941 + movl $__per_cpu_end - 1,%eax
16942 + subl $__per_cpu_start,%eax
16943 + movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
16944 +#endif
16945 +
16946 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16947 + movl $NR_CPUS,%ecx
16948 + movl $pa(cpu_gdt_table),%edi
16949 +1:
16950 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
16951 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
16952 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
16953 + addl $PAGE_SIZE_asm,%edi
16954 + loop 1b
16955 +#endif
16956 +
16957 +#ifdef CONFIG_PAX_KERNEXEC
16958 + movl $pa(boot_gdt),%edi
16959 + movl $__LOAD_PHYSICAL_ADDR,%eax
16960 + movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
16961 + rorl $16,%eax
16962 + movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
16963 + movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
16964 + rorl $16,%eax
16965 +
16966 + ljmp $(__BOOT_CS),$1f
16967 +1:
16968 +
16969 + movl $NR_CPUS,%ecx
16970 + movl $pa(cpu_gdt_table),%edi
16971 + addl $__PAGE_OFFSET,%eax
16972 +1:
16973 + movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
16974 + movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
16975 + movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
16976 + movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
16977 + rorl $16,%eax
16978 + movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
16979 + movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
16980 + movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
16981 + movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
16982 + rorl $16,%eax
16983 + addl $PAGE_SIZE_asm,%edi
16984 + loop 1b
16985 +#endif
16986 +
16987 /*
16988 * Clear BSS first so that there are no surprises...
16989 */
16990 @@ -196,8 +264,11 @@ ENTRY(startup_32)
16991 movl %eax, pa(max_pfn_mapped)
16992
16993 /* Do early initialization of the fixmap area */
16994 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16995 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
16996 +#ifdef CONFIG_COMPAT_VDSO
16997 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
16998 +#else
16999 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
17000 +#endif
17001 #else /* Not PAE */
17002
17003 page_pde_offset = (__PAGE_OFFSET >> 20);
17004 @@ -227,8 +298,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
17005 movl %eax, pa(max_pfn_mapped)
17006
17007 /* Do early initialization of the fixmap area */
17008 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
17009 - movl %eax,pa(initial_page_table+0xffc)
17010 +#ifdef CONFIG_COMPAT_VDSO
17011 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
17012 +#else
17013 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
17014 +#endif
17015 #endif
17016
17017 #ifdef CONFIG_PARAVIRT
17018 @@ -242,9 +316,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
17019 cmpl $num_subarch_entries, %eax
17020 jae bad_subarch
17021
17022 - movl pa(subarch_entries)(,%eax,4), %eax
17023 - subl $__PAGE_OFFSET, %eax
17024 - jmp *%eax
17025 + jmp *pa(subarch_entries)(,%eax,4)
17026
17027 bad_subarch:
17028 WEAK(lguest_entry)
17029 @@ -256,10 +328,10 @@ WEAK(xen_entry)
17030 __INITDATA
17031
17032 subarch_entries:
17033 - .long default_entry /* normal x86/PC */
17034 - .long lguest_entry /* lguest hypervisor */
17035 - .long xen_entry /* Xen hypervisor */
17036 - .long default_entry /* Moorestown MID */
17037 + .long ta(default_entry) /* normal x86/PC */
17038 + .long ta(lguest_entry) /* lguest hypervisor */
17039 + .long ta(xen_entry) /* Xen hypervisor */
17040 + .long ta(default_entry) /* Moorestown MID */
17041 num_subarch_entries = (. - subarch_entries) / 4
17042 .previous
17043 #else
17044 @@ -310,6 +382,7 @@ default_entry:
17045 orl %edx,%eax
17046 movl %eax,%cr4
17047
17048 +#ifdef CONFIG_X86_PAE
17049 testb $X86_CR4_PAE, %al # check if PAE is enabled
17050 jz 6f
17051
17052 @@ -338,6 +411,9 @@ default_entry:
17053 /* Make changes effective */
17054 wrmsr
17055
17056 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
17057 +#endif
17058 +
17059 6:
17060
17061 /*
17062 @@ -436,14 +512,20 @@ is386: movl $2,%ecx # set MP
17063 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
17064 movl %eax,%ss # after changing gdt.
17065
17066 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
17067 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
17068 movl %eax,%ds
17069 movl %eax,%es
17070
17071 movl $(__KERNEL_PERCPU), %eax
17072 movl %eax,%fs # set this cpu's percpu
17073
17074 +#ifdef CONFIG_CC_STACKPROTECTOR
17075 movl $(__KERNEL_STACK_CANARY),%eax
17076 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
17077 + movl $(__USER_DS),%eax
17078 +#else
17079 + xorl %eax,%eax
17080 +#endif
17081 movl %eax,%gs
17082
17083 xorl %eax,%eax # Clear LDT
17084 @@ -520,8 +602,11 @@ setup_once:
17085 * relocation. Manually set base address in stack canary
17086 * segment descriptor.
17087 */
17088 - movl $gdt_page,%eax
17089 + movl $cpu_gdt_table,%eax
17090 movl $stack_canary,%ecx
17091 +#ifdef CONFIG_SMP
17092 + addl $__per_cpu_load,%ecx
17093 +#endif
17094 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
17095 shrl $16, %ecx
17096 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
17097 @@ -552,7 +637,7 @@ ENDPROC(early_idt_handlers)
17098 /* This is global to keep gas from relaxing the jumps */
17099 ENTRY(early_idt_handler)
17100 cld
17101 - cmpl $2,%ss:early_recursion_flag
17102 + cmpl $1,%ss:early_recursion_flag
17103 je hlt_loop
17104 incl %ss:early_recursion_flag
17105
17106 @@ -590,8 +675,8 @@ ENTRY(early_idt_handler)
17107 pushl (20+6*4)(%esp) /* trapno */
17108 pushl $fault_msg
17109 call printk
17110 -#endif
17111 call dump_stack
17112 +#endif
17113 hlt_loop:
17114 hlt
17115 jmp hlt_loop
17116 @@ -610,8 +695,11 @@ ENDPROC(early_idt_handler)
17117 /* This is the default interrupt "handler" :-) */
17118 ALIGN
17119 ignore_int:
17120 - cld
17121 #ifdef CONFIG_PRINTK
17122 + cmpl $2,%ss:early_recursion_flag
17123 + je hlt_loop
17124 + incl %ss:early_recursion_flag
17125 + cld
17126 pushl %eax
17127 pushl %ecx
17128 pushl %edx
17129 @@ -620,9 +708,6 @@ ignore_int:
17130 movl $(__KERNEL_DS),%eax
17131 movl %eax,%ds
17132 movl %eax,%es
17133 - cmpl $2,early_recursion_flag
17134 - je hlt_loop
17135 - incl early_recursion_flag
17136 pushl 16(%esp)
17137 pushl 24(%esp)
17138 pushl 32(%esp)
17139 @@ -656,29 +741,43 @@ ENTRY(setup_once_ref)
17140 /*
17141 * BSS section
17142 */
17143 -__PAGE_ALIGNED_BSS
17144 - .align PAGE_SIZE
17145 #ifdef CONFIG_X86_PAE
17146 +.section .initial_pg_pmd,"a",@progbits
17147 initial_pg_pmd:
17148 .fill 1024*KPMDS,4,0
17149 #else
17150 +.section .initial_page_table,"a",@progbits
17151 ENTRY(initial_page_table)
17152 .fill 1024,4,0
17153 #endif
17154 +.section .initial_pg_fixmap,"a",@progbits
17155 initial_pg_fixmap:
17156 .fill 1024,4,0
17157 +.section .empty_zero_page,"a",@progbits
17158 ENTRY(empty_zero_page)
17159 .fill 4096,1,0
17160 +.section .swapper_pg_dir,"a",@progbits
17161 ENTRY(swapper_pg_dir)
17162 +#ifdef CONFIG_X86_PAE
17163 + .fill 4,8,0
17164 +#else
17165 .fill 1024,4,0
17166 +#endif
17167 +
17168 +/*
17169 + * The IDT has to be page-aligned to simplify the Pentium
17170 + * F0 0F bug workaround.. We have a special link segment
17171 + * for this.
17172 + */
17173 +.section .idt,"a",@progbits
17174 +ENTRY(idt_table)
17175 + .fill 256,8,0
17176
17177 /*
17178 * This starts the data section.
17179 */
17180 #ifdef CONFIG_X86_PAE
17181 -__PAGE_ALIGNED_DATA
17182 - /* Page-aligned for the benefit of paravirt? */
17183 - .align PAGE_SIZE
17184 +.section .initial_page_table,"a",@progbits
17185 ENTRY(initial_page_table)
17186 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
17187 # if KPMDS == 3
17188 @@ -697,12 +796,20 @@ ENTRY(initial_page_table)
17189 # error "Kernel PMDs should be 1, 2 or 3"
17190 # endif
17191 .align PAGE_SIZE /* needs to be page-sized too */
17192 +
17193 +#ifdef CONFIG_PAX_PER_CPU_PGD
17194 +ENTRY(cpu_pgd)
17195 + .rept NR_CPUS
17196 + .fill 4,8,0
17197 + .endr
17198 +#endif
17199 +
17200 #endif
17201
17202 .data
17203 .balign 4
17204 ENTRY(stack_start)
17205 - .long init_thread_union+THREAD_SIZE
17206 + .long init_thread_union+THREAD_SIZE-8
17207
17208 __INITRODATA
17209 int_msg:
17210 @@ -730,7 +837,7 @@ fault_msg:
17211 * segment size, and 32-bit linear address value:
17212 */
17213
17214 - .data
17215 +.section .rodata,"a",@progbits
17216 .globl boot_gdt_descr
17217 .globl idt_descr
17218
17219 @@ -739,7 +846,7 @@ fault_msg:
17220 .word 0 # 32 bit align gdt_desc.address
17221 boot_gdt_descr:
17222 .word __BOOT_DS+7
17223 - .long boot_gdt - __PAGE_OFFSET
17224 + .long pa(boot_gdt)
17225
17226 .word 0 # 32-bit align idt_desc.address
17227 idt_descr:
17228 @@ -750,7 +857,7 @@ idt_descr:
17229 .word 0 # 32 bit align gdt_desc.address
17230 ENTRY(early_gdt_descr)
17231 .word GDT_ENTRIES*8-1
17232 - .long gdt_page /* Overwritten for secondary CPUs */
17233 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
17234
17235 /*
17236 * The boot_gdt must mirror the equivalent in setup.S and is
17237 @@ -759,5 +866,65 @@ ENTRY(early_gdt_descr)
17238 .align L1_CACHE_BYTES
17239 ENTRY(boot_gdt)
17240 .fill GDT_ENTRY_BOOT_CS,8,0
17241 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
17242 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
17243 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
17244 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
17245 +
17246 + .align PAGE_SIZE_asm
17247 +ENTRY(cpu_gdt_table)
17248 + .rept NR_CPUS
17249 + .quad 0x0000000000000000 /* NULL descriptor */
17250 + .quad 0x0000000000000000 /* 0x0b reserved */
17251 + .quad 0x0000000000000000 /* 0x13 reserved */
17252 + .quad 0x0000000000000000 /* 0x1b reserved */
17253 +
17254 +#ifdef CONFIG_PAX_KERNEXEC
17255 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
17256 +#else
17257 + .quad 0x0000000000000000 /* 0x20 unused */
17258 +#endif
17259 +
17260 + .quad 0x0000000000000000 /* 0x28 unused */
17261 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
17262 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
17263 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
17264 + .quad 0x0000000000000000 /* 0x4b reserved */
17265 + .quad 0x0000000000000000 /* 0x53 reserved */
17266 + .quad 0x0000000000000000 /* 0x5b reserved */
17267 +
17268 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
17269 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
17270 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
17271 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
17272 +
17273 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
17274 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
17275 +
17276 + /*
17277 + * Segments used for calling PnP BIOS have byte granularity.
17278 + * The code segments and data segments have fixed 64k limits,
17279 + * the transfer segment sizes are set at run time.
17280 + */
17281 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
17282 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
17283 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
17284 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
17285 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
17286 +
17287 + /*
17288 + * The APM segments have byte granularity and their bases
17289 + * are set at run time. All have 64k limits.
17290 + */
17291 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
17292 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
17293 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
17294 +
17295 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
17296 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
17297 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
17298 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
17299 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
17300 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
17301 +
17302 + /* Be sure this is zeroed to avoid false validations in Xen */
17303 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
17304 + .endr
17305 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
17306 index 94bf9cc..400455a 100644
17307 --- a/arch/x86/kernel/head_64.S
17308 +++ b/arch/x86/kernel/head_64.S
17309 @@ -20,6 +20,8 @@
17310 #include <asm/processor-flags.h>
17311 #include <asm/percpu.h>
17312 #include <asm/nops.h>
17313 +#include <asm/cpufeature.h>
17314 +#include <asm/alternative-asm.h>
17315
17316 #ifdef CONFIG_PARAVIRT
17317 #include <asm/asm-offsets.h>
17318 @@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
17319 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
17320 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
17321 L3_START_KERNEL = pud_index(__START_KERNEL_map)
17322 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
17323 +L3_VMALLOC_START = pud_index(VMALLOC_START)
17324 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
17325 +L3_VMALLOC_END = pud_index(VMALLOC_END)
17326 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
17327 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
17328
17329 .text
17330 __HEAD
17331 @@ -88,35 +96,23 @@ startup_64:
17332 */
17333 addq %rbp, init_level4_pgt + 0(%rip)
17334 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
17335 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
17336 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
17337 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
17338 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
17339
17340 addq %rbp, level3_ident_pgt + 0(%rip)
17341 +#ifndef CONFIG_XEN
17342 + addq %rbp, level3_ident_pgt + 8(%rip)
17343 +#endif
17344
17345 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
17346 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
17347 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
17348 +
17349 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
17350 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
17351
17352 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
17353 -
17354 - /* Add an Identity mapping if I am above 1G */
17355 - leaq _text(%rip), %rdi
17356 - andq $PMD_PAGE_MASK, %rdi
17357 -
17358 - movq %rdi, %rax
17359 - shrq $PUD_SHIFT, %rax
17360 - andq $(PTRS_PER_PUD - 1), %rax
17361 - jz ident_complete
17362 -
17363 - leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
17364 - leaq level3_ident_pgt(%rip), %rbx
17365 - movq %rdx, 0(%rbx, %rax, 8)
17366 -
17367 - movq %rdi, %rax
17368 - shrq $PMD_SHIFT, %rax
17369 - andq $(PTRS_PER_PMD - 1), %rax
17370 - leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
17371 - leaq level2_spare_pgt(%rip), %rbx
17372 - movq %rdx, 0(%rbx, %rax, 8)
17373 -ident_complete:
17374 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
17375
17376 /*
17377 * Fixup the kernel text+data virtual addresses. Note that
17378 @@ -159,8 +155,8 @@ ENTRY(secondary_startup_64)
17379 * after the boot processor executes this code.
17380 */
17381
17382 - /* Enable PAE mode and PGE */
17383 - movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
17384 + /* Enable PAE mode and PSE/PGE */
17385 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
17386 movq %rax, %cr4
17387
17388 /* Setup early boot stage 4 level pagetables. */
17389 @@ -182,9 +178,17 @@ ENTRY(secondary_startup_64)
17390 movl $MSR_EFER, %ecx
17391 rdmsr
17392 btsl $_EFER_SCE, %eax /* Enable System Call */
17393 - btl $20,%edi /* No Execute supported? */
17394 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
17395 jnc 1f
17396 btsl $_EFER_NX, %eax
17397 + leaq init_level4_pgt(%rip), %rdi
17398 +#ifndef CONFIG_EFI
17399 + btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
17400 +#endif
17401 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
17402 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
17403 + btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
17404 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
17405 1: wrmsr /* Make changes effective */
17406
17407 /* Setup cr0 */
17408 @@ -246,6 +250,7 @@ ENTRY(secondary_startup_64)
17409 * jump. In addition we need to ensure %cs is set so we make this
17410 * a far return.
17411 */
17412 + pax_set_fptr_mask
17413 movq initial_code(%rip),%rax
17414 pushq $0 # fake return address to stop unwinder
17415 pushq $__KERNEL_CS # set correct cs
17416 @@ -268,7 +273,7 @@ ENTRY(secondary_startup_64)
17417 bad_address:
17418 jmp bad_address
17419
17420 - .section ".init.text","ax"
17421 + __INIT
17422 .globl early_idt_handlers
17423 early_idt_handlers:
17424 # 104(%rsp) %rflags
17425 @@ -347,11 +352,15 @@ ENTRY(early_idt_handler)
17426 addq $16,%rsp # drop vector number and error code
17427 decl early_recursion_flag(%rip)
17428 INTERRUPT_RETURN
17429 + .previous
17430
17431 + __INITDATA
17432 .balign 4
17433 early_recursion_flag:
17434 .long 0
17435 + .previous
17436
17437 + .section .rodata,"a",@progbits
17438 #ifdef CONFIG_EARLY_PRINTK
17439 early_idt_msg:
17440 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
17441 @@ -360,6 +369,7 @@ early_idt_ripmsg:
17442 #endif /* CONFIG_EARLY_PRINTK */
17443 .previous
17444
17445 + .section .rodata,"a",@progbits
17446 #define NEXT_PAGE(name) \
17447 .balign PAGE_SIZE; \
17448 ENTRY(name)
17449 @@ -372,7 +382,6 @@ ENTRY(name)
17450 i = i + 1 ; \
17451 .endr
17452
17453 - .data
17454 /*
17455 * This default setting generates an ident mapping at address 0x100000
17456 * and a mapping for the kernel that precisely maps virtual address
17457 @@ -383,13 +392,41 @@ NEXT_PAGE(init_level4_pgt)
17458 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17459 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
17460 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17461 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
17462 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
17463 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
17464 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
17465 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
17466 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17467 .org init_level4_pgt + L4_START_KERNEL*8, 0
17468 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
17469 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
17470
17471 +#ifdef CONFIG_PAX_PER_CPU_PGD
17472 +NEXT_PAGE(cpu_pgd)
17473 + .rept NR_CPUS
17474 + .fill 512,8,0
17475 + .endr
17476 +#endif
17477 +
17478 NEXT_PAGE(level3_ident_pgt)
17479 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17480 +#ifdef CONFIG_XEN
17481 .fill 511,8,0
17482 +#else
17483 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
17484 + .fill 510,8,0
17485 +#endif
17486 +
17487 +NEXT_PAGE(level3_vmalloc_start_pgt)
17488 + .fill 512,8,0
17489 +
17490 +NEXT_PAGE(level3_vmalloc_end_pgt)
17491 + .fill 512,8,0
17492 +
17493 +NEXT_PAGE(level3_vmemmap_pgt)
17494 + .fill L3_VMEMMAP_START,8,0
17495 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17496
17497 NEXT_PAGE(level3_kernel_pgt)
17498 .fill L3_START_KERNEL,8,0
17499 @@ -397,20 +434,23 @@ NEXT_PAGE(level3_kernel_pgt)
17500 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
17501 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17502
17503 +NEXT_PAGE(level2_vmemmap_pgt)
17504 + .fill 512,8,0
17505 +
17506 NEXT_PAGE(level2_fixmap_pgt)
17507 - .fill 506,8,0
17508 - .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17509 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
17510 - .fill 5,8,0
17511 + .fill 507,8,0
17512 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
17513 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
17514 + .fill 4,8,0
17515
17516 -NEXT_PAGE(level1_fixmap_pgt)
17517 +NEXT_PAGE(level1_vsyscall_pgt)
17518 .fill 512,8,0
17519
17520 -NEXT_PAGE(level2_ident_pgt)
17521 - /* Since I easily can, map the first 1G.
17522 + /* Since I easily can, map the first 2G.
17523 * Don't set NX because code runs from these pages.
17524 */
17525 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
17526 +NEXT_PAGE(level2_ident_pgt)
17527 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
17528
17529 NEXT_PAGE(level2_kernel_pgt)
17530 /*
17531 @@ -423,37 +463,59 @@ NEXT_PAGE(level2_kernel_pgt)
17532 * If you want to increase this then increase MODULES_VADDR
17533 * too.)
17534 */
17535 - PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
17536 - KERNEL_IMAGE_SIZE/PMD_SIZE)
17537 -
17538 -NEXT_PAGE(level2_spare_pgt)
17539 - .fill 512, 8, 0
17540 + PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
17541
17542 #undef PMDS
17543 #undef NEXT_PAGE
17544
17545 - .data
17546 + .align PAGE_SIZE
17547 +ENTRY(cpu_gdt_table)
17548 + .rept NR_CPUS
17549 + .quad 0x0000000000000000 /* NULL descriptor */
17550 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
17551 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
17552 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
17553 + .quad 0x00cffb000000ffff /* __USER32_CS */
17554 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
17555 + .quad 0x00affb000000ffff /* __USER_CS */
17556 +
17557 +#ifdef CONFIG_PAX_KERNEXEC
17558 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
17559 +#else
17560 + .quad 0x0 /* unused */
17561 +#endif
17562 +
17563 + .quad 0,0 /* TSS */
17564 + .quad 0,0 /* LDT */
17565 + .quad 0,0,0 /* three TLS descriptors */
17566 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
17567 + /* asm/segment.h:GDT_ENTRIES must match this */
17568 +
17569 + /* zero the remaining page */
17570 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
17571 + .endr
17572 +
17573 .align 16
17574 .globl early_gdt_descr
17575 early_gdt_descr:
17576 .word GDT_ENTRIES*8-1
17577 early_gdt_descr_base:
17578 - .quad INIT_PER_CPU_VAR(gdt_page)
17579 + .quad cpu_gdt_table
17580
17581 ENTRY(phys_base)
17582 /* This must match the first entry in level2_kernel_pgt */
17583 .quad 0x0000000000000000
17584
17585 #include "../../x86/xen/xen-head.S"
17586 -
17587 - .section .bss, "aw", @nobits
17588 +
17589 + .section .rodata,"a",@progbits
17590 .align L1_CACHE_BYTES
17591 ENTRY(idt_table)
17592 - .skip IDT_ENTRIES * 16
17593 + .fill 512,8,0
17594
17595 .align L1_CACHE_BYTES
17596 ENTRY(nmi_idt_table)
17597 - .skip IDT_ENTRIES * 16
17598 + .fill 512,8,0
17599
17600 __PAGE_ALIGNED_BSS
17601 .align PAGE_SIZE
17602 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
17603 index 9c3bd4a..e1d9b35 100644
17604 --- a/arch/x86/kernel/i386_ksyms_32.c
17605 +++ b/arch/x86/kernel/i386_ksyms_32.c
17606 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
17607 EXPORT_SYMBOL(cmpxchg8b_emu);
17608 #endif
17609
17610 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
17611 +
17612 /* Networking helper routines. */
17613 EXPORT_SYMBOL(csum_partial_copy_generic);
17614 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
17615 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
17616
17617 EXPORT_SYMBOL(__get_user_1);
17618 EXPORT_SYMBOL(__get_user_2);
17619 @@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
17620
17621 EXPORT_SYMBOL(csum_partial);
17622 EXPORT_SYMBOL(empty_zero_page);
17623 +
17624 +#ifdef CONFIG_PAX_KERNEXEC
17625 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
17626 +#endif
17627 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
17628 index f250431..54097e7 100644
17629 --- a/arch/x86/kernel/i387.c
17630 +++ b/arch/x86/kernel/i387.c
17631 @@ -59,7 +59,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
17632 static inline bool interrupted_user_mode(void)
17633 {
17634 struct pt_regs *regs = get_irq_regs();
17635 - return regs && user_mode_vm(regs);
17636 + return regs && user_mode(regs);
17637 }
17638
17639 /*
17640 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
17641 index 36d1853..bf25736 100644
17642 --- a/arch/x86/kernel/i8259.c
17643 +++ b/arch/x86/kernel/i8259.c
17644 @@ -209,7 +209,7 @@ spurious_8259A_irq:
17645 "spurious 8259A interrupt: IRQ%d.\n", irq);
17646 spurious_irq_mask |= irqmask;
17647 }
17648 - atomic_inc(&irq_err_count);
17649 + atomic_inc_unchecked(&irq_err_count);
17650 /*
17651 * Theoretically we do not have to handle this IRQ,
17652 * but in Linux this does not cause problems and is
17653 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
17654 index 8c96897..be66bfa 100644
17655 --- a/arch/x86/kernel/ioport.c
17656 +++ b/arch/x86/kernel/ioport.c
17657 @@ -6,6 +6,7 @@
17658 #include <linux/sched.h>
17659 #include <linux/kernel.h>
17660 #include <linux/capability.h>
17661 +#include <linux/security.h>
17662 #include <linux/errno.h>
17663 #include <linux/types.h>
17664 #include <linux/ioport.h>
17665 @@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17666
17667 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
17668 return -EINVAL;
17669 +#ifdef CONFIG_GRKERNSEC_IO
17670 + if (turn_on && grsec_disable_privio) {
17671 + gr_handle_ioperm();
17672 + return -EPERM;
17673 + }
17674 +#endif
17675 if (turn_on && !capable(CAP_SYS_RAWIO))
17676 return -EPERM;
17677
17678 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17679 * because the ->io_bitmap_max value must match the bitmap
17680 * contents:
17681 */
17682 - tss = &per_cpu(init_tss, get_cpu());
17683 + tss = init_tss + get_cpu();
17684
17685 if (turn_on)
17686 bitmap_clear(t->io_bitmap_ptr, from, num);
17687 @@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
17688 return -EINVAL;
17689 /* Trying to gain more privileges? */
17690 if (level > old) {
17691 +#ifdef CONFIG_GRKERNSEC_IO
17692 + if (grsec_disable_privio) {
17693 + gr_handle_iopl();
17694 + return -EPERM;
17695 + }
17696 +#endif
17697 if (!capable(CAP_SYS_RAWIO))
17698 return -EPERM;
17699 }
17700 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
17701 index d44f782..31ab01e 100644
17702 --- a/arch/x86/kernel/irq.c
17703 +++ b/arch/x86/kernel/irq.c
17704 @@ -18,7 +18,7 @@
17705 #include <asm/mce.h>
17706 #include <asm/hw_irq.h>
17707
17708 -atomic_t irq_err_count;
17709 +atomic_unchecked_t irq_err_count;
17710
17711 /* Function pointer for generic interrupt vector handling */
17712 void (*x86_platform_ipi_callback)(void) = NULL;
17713 @@ -121,9 +121,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
17714 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
17715 seq_printf(p, " Machine check polls\n");
17716 #endif
17717 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
17718 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
17719 #if defined(CONFIG_X86_IO_APIC)
17720 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
17721 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
17722 #endif
17723 return 0;
17724 }
17725 @@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
17726
17727 u64 arch_irq_stat(void)
17728 {
17729 - u64 sum = atomic_read(&irq_err_count);
17730 + u64 sum = atomic_read_unchecked(&irq_err_count);
17731
17732 #ifdef CONFIG_X86_IO_APIC
17733 - sum += atomic_read(&irq_mis_count);
17734 + sum += atomic_read_unchecked(&irq_mis_count);
17735 #endif
17736 return sum;
17737 }
17738 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
17739 index 344faf8..355f60d 100644
17740 --- a/arch/x86/kernel/irq_32.c
17741 +++ b/arch/x86/kernel/irq_32.c
17742 @@ -39,7 +39,7 @@ static int check_stack_overflow(void)
17743 __asm__ __volatile__("andl %%esp,%0" :
17744 "=r" (sp) : "0" (THREAD_SIZE - 1));
17745
17746 - return sp < (sizeof(struct thread_info) + STACK_WARN);
17747 + return sp < STACK_WARN;
17748 }
17749
17750 static void print_stack_overflow(void)
17751 @@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
17752 * per-CPU IRQ handling contexts (thread information and stack)
17753 */
17754 union irq_ctx {
17755 - struct thread_info tinfo;
17756 - u32 stack[THREAD_SIZE/sizeof(u32)];
17757 + unsigned long previous_esp;
17758 + u32 stack[THREAD_SIZE/sizeof(u32)];
17759 } __attribute__((aligned(THREAD_SIZE)));
17760
17761 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
17762 @@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
17763 static inline int
17764 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17765 {
17766 - union irq_ctx *curctx, *irqctx;
17767 + union irq_ctx *irqctx;
17768 u32 *isp, arg1, arg2;
17769
17770 - curctx = (union irq_ctx *) current_thread_info();
17771 irqctx = __this_cpu_read(hardirq_ctx);
17772
17773 /*
17774 @@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17775 * handler) we can't do that and just have to keep using the
17776 * current stack (which is the irq stack already after all)
17777 */
17778 - if (unlikely(curctx == irqctx))
17779 + if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
17780 return 0;
17781
17782 /* build the stack frame on the IRQ stack */
17783 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17784 - irqctx->tinfo.task = curctx->tinfo.task;
17785 - irqctx->tinfo.previous_esp = current_stack_pointer;
17786 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17787 + irqctx->previous_esp = current_stack_pointer;
17788
17789 - /* Copy the preempt_count so that the [soft]irq checks work. */
17790 - irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
17791 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17792 + __set_fs(MAKE_MM_SEG(0));
17793 +#endif
17794
17795 if (unlikely(overflow))
17796 call_on_stack(print_stack_overflow, isp);
17797 @@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17798 : "0" (irq), "1" (desc), "2" (isp),
17799 "D" (desc->handle_irq)
17800 : "memory", "cc", "ecx");
17801 +
17802 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17803 + __set_fs(current_thread_info()->addr_limit);
17804 +#endif
17805 +
17806 return 1;
17807 }
17808
17809 @@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17810 */
17811 void __cpuinit irq_ctx_init(int cpu)
17812 {
17813 - union irq_ctx *irqctx;
17814 -
17815 if (per_cpu(hardirq_ctx, cpu))
17816 return;
17817
17818 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17819 - THREADINFO_GFP,
17820 - THREAD_SIZE_ORDER));
17821 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17822 - irqctx->tinfo.cpu = cpu;
17823 - irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
17824 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17825 -
17826 - per_cpu(hardirq_ctx, cpu) = irqctx;
17827 -
17828 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17829 - THREADINFO_GFP,
17830 - THREAD_SIZE_ORDER));
17831 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17832 - irqctx->tinfo.cpu = cpu;
17833 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17834 -
17835 - per_cpu(softirq_ctx, cpu) = irqctx;
17836 + per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
17837 + per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
17838 +
17839 + printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17840 + cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17841
17842 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17843 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17844 @@ -152,7 +141,6 @@ void __cpuinit irq_ctx_init(int cpu)
17845 asmlinkage void do_softirq(void)
17846 {
17847 unsigned long flags;
17848 - struct thread_info *curctx;
17849 union irq_ctx *irqctx;
17850 u32 *isp;
17851
17852 @@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
17853 local_irq_save(flags);
17854
17855 if (local_softirq_pending()) {
17856 - curctx = current_thread_info();
17857 irqctx = __this_cpu_read(softirq_ctx);
17858 - irqctx->tinfo.task = curctx->task;
17859 - irqctx->tinfo.previous_esp = current_stack_pointer;
17860 + irqctx->previous_esp = current_stack_pointer;
17861
17862 /* build the stack frame on the softirq stack */
17863 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17864 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17865 +
17866 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17867 + __set_fs(MAKE_MM_SEG(0));
17868 +#endif
17869
17870 call_on_stack(__do_softirq, isp);
17871 +
17872 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17873 + __set_fs(current_thread_info()->addr_limit);
17874 +#endif
17875 +
17876 /*
17877 * Shouldn't happen, we returned above if in_interrupt():
17878 */
17879 @@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
17880 if (unlikely(!desc))
17881 return false;
17882
17883 - if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17884 + if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17885 if (unlikely(overflow))
17886 print_stack_overflow();
17887 desc->handle_irq(irq, desc);
17888 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
17889 index d04d3ec..ea4b374 100644
17890 --- a/arch/x86/kernel/irq_64.c
17891 +++ b/arch/x86/kernel/irq_64.c
17892 @@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
17893 u64 estack_top, estack_bottom;
17894 u64 curbase = (u64)task_stack_page(current);
17895
17896 - if (user_mode_vm(regs))
17897 + if (user_mode(regs))
17898 return;
17899
17900 if (regs->sp >= curbase + sizeof(struct thread_info) +
17901 diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
17902 index dc1404b..bbc43e7 100644
17903 --- a/arch/x86/kernel/kdebugfs.c
17904 +++ b/arch/x86/kernel/kdebugfs.c
17905 @@ -27,7 +27,7 @@ struct setup_data_node {
17906 u32 len;
17907 };
17908
17909 -static ssize_t setup_data_read(struct file *file, char __user *user_buf,
17910 +static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
17911 size_t count, loff_t *ppos)
17912 {
17913 struct setup_data_node *node = file->private_data;
17914 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
17915 index 3f61904..873cea9 100644
17916 --- a/arch/x86/kernel/kgdb.c
17917 +++ b/arch/x86/kernel/kgdb.c
17918 @@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
17919 #ifdef CONFIG_X86_32
17920 switch (regno) {
17921 case GDB_SS:
17922 - if (!user_mode_vm(regs))
17923 + if (!user_mode(regs))
17924 *(unsigned long *)mem = __KERNEL_DS;
17925 break;
17926 case GDB_SP:
17927 - if (!user_mode_vm(regs))
17928 + if (!user_mode(regs))
17929 *(unsigned long *)mem = kernel_stack_pointer(regs);
17930 break;
17931 case GDB_GS:
17932 @@ -476,12 +476,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
17933 case 'k':
17934 /* clear the trace bit */
17935 linux_regs->flags &= ~X86_EFLAGS_TF;
17936 - atomic_set(&kgdb_cpu_doing_single_step, -1);
17937 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
17938
17939 /* set the trace bit if we're stepping */
17940 if (remcomInBuffer[0] == 's') {
17941 linux_regs->flags |= X86_EFLAGS_TF;
17942 - atomic_set(&kgdb_cpu_doing_single_step,
17943 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
17944 raw_smp_processor_id());
17945 }
17946
17947 @@ -546,7 +546,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
17948
17949 switch (cmd) {
17950 case DIE_DEBUG:
17951 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
17952 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
17953 if (user_mode(regs))
17954 return single_step_cont(regs, args);
17955 break;
17956 diff --git a/arch/x86/kernel/kprobes-opt.c b/arch/x86/kernel/kprobes-opt.c
17957 index c5e410e..da6aaf9 100644
17958 --- a/arch/x86/kernel/kprobes-opt.c
17959 +++ b/arch/x86/kernel/kprobes-opt.c
17960 @@ -338,7 +338,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17961 * Verify if the address gap is in 2GB range, because this uses
17962 * a relative jump.
17963 */
17964 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
17965 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
17966 if (abs(rel) > 0x7fffffff)
17967 return -ERANGE;
17968
17969 @@ -359,11 +359,11 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17970 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
17971
17972 /* Set probe function call */
17973 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
17974 + synthesize_relcall(buf + TMPL_CALL_IDX, ktla_ktva(optimized_callback));
17975
17976 /* Set returning jmp instruction at the tail of out-of-line buffer */
17977 synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
17978 - (u8 *)op->kp.addr + op->optinsn.size);
17979 + (u8 *)ktla_ktva(op->kp.addr) + op->optinsn.size);
17980
17981 flush_icache_range((unsigned long) buf,
17982 (unsigned long) buf + TMPL_END_IDX +
17983 @@ -385,7 +385,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
17984 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
17985
17986 /* Backup instructions which will be replaced by jump address */
17987 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
17988 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
17989 RELATIVE_ADDR_SIZE);
17990
17991 insn_buf[0] = RELATIVEJUMP_OPCODE;
17992 diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
17993 index e2f751e..dffa2a0 100644
17994 --- a/arch/x86/kernel/kprobes.c
17995 +++ b/arch/x86/kernel/kprobes.c
17996 @@ -120,8 +120,11 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
17997 } __attribute__((packed)) *insn;
17998
17999 insn = (struct __arch_relative_insn *)from;
18000 +
18001 + pax_open_kernel();
18002 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
18003 insn->op = op;
18004 + pax_close_kernel();
18005 }
18006
18007 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
18008 @@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
18009 kprobe_opcode_t opcode;
18010 kprobe_opcode_t *orig_opcodes = opcodes;
18011
18012 - if (search_exception_tables((unsigned long)opcodes))
18013 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
18014 return 0; /* Page fault may occur on this address. */
18015
18016 retry:
18017 @@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
18018 /* Another subsystem puts a breakpoint, failed to recover */
18019 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
18020 return 0;
18021 + pax_open_kernel();
18022 memcpy(dest, insn.kaddr, insn.length);
18023 + pax_close_kernel();
18024
18025 #ifdef CONFIG_X86_64
18026 if (insn_rip_relative(&insn)) {
18027 @@ -355,7 +360,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
18028 newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
18029 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
18030 disp = (u8 *) dest + insn_offset_displacement(&insn);
18031 + pax_open_kernel();
18032 *(s32 *) disp = (s32) newdisp;
18033 + pax_close_kernel();
18034 }
18035 #endif
18036 return insn.length;
18037 @@ -485,7 +492,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
18038 * nor set current_kprobe, because it doesn't use single
18039 * stepping.
18040 */
18041 - regs->ip = (unsigned long)p->ainsn.insn;
18042 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
18043 preempt_enable_no_resched();
18044 return;
18045 }
18046 @@ -504,7 +511,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
18047 if (p->opcode == BREAKPOINT_INSTRUCTION)
18048 regs->ip = (unsigned long)p->addr;
18049 else
18050 - regs->ip = (unsigned long)p->ainsn.insn;
18051 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
18052 }
18053
18054 /*
18055 @@ -583,7 +590,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
18056 setup_singlestep(p, regs, kcb, 0);
18057 return 1;
18058 }
18059 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
18060 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
18061 /*
18062 * The breakpoint instruction was removed right
18063 * after we hit it. Another cpu has removed
18064 @@ -628,6 +635,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
18065 " movq %rax, 152(%rsp)\n"
18066 RESTORE_REGS_STRING
18067 " popfq\n"
18068 +#ifdef KERNEXEC_PLUGIN
18069 + " btsq $63,(%rsp)\n"
18070 +#endif
18071 #else
18072 " pushf\n"
18073 SAVE_REGS_STRING
18074 @@ -765,7 +775,7 @@ static void __kprobes
18075 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
18076 {
18077 unsigned long *tos = stack_addr(regs);
18078 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
18079 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
18080 unsigned long orig_ip = (unsigned long)p->addr;
18081 kprobe_opcode_t *insn = p->ainsn.insn;
18082
18083 @@ -947,7 +957,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
18084 struct die_args *args = data;
18085 int ret = NOTIFY_DONE;
18086
18087 - if (args->regs && user_mode_vm(args->regs))
18088 + if (args->regs && user_mode(args->regs))
18089 return ret;
18090
18091 switch (val) {
18092 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
18093 index ebc9873..1b9724b 100644
18094 --- a/arch/x86/kernel/ldt.c
18095 +++ b/arch/x86/kernel/ldt.c
18096 @@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
18097 if (reload) {
18098 #ifdef CONFIG_SMP
18099 preempt_disable();
18100 - load_LDT(pc);
18101 + load_LDT_nolock(pc);
18102 if (!cpumask_equal(mm_cpumask(current->mm),
18103 cpumask_of(smp_processor_id())))
18104 smp_call_function(flush_ldt, current->mm, 1);
18105 preempt_enable();
18106 #else
18107 - load_LDT(pc);
18108 + load_LDT_nolock(pc);
18109 #endif
18110 }
18111 if (oldsize) {
18112 @@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
18113 return err;
18114
18115 for (i = 0; i < old->size; i++)
18116 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
18117 + write_ldt_entry(new->ldt, i, old->ldt + i);
18118 return 0;
18119 }
18120
18121 @@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
18122 retval = copy_ldt(&mm->context, &old_mm->context);
18123 mutex_unlock(&old_mm->context.lock);
18124 }
18125 +
18126 + if (tsk == current) {
18127 + mm->context.vdso = 0;
18128 +
18129 +#ifdef CONFIG_X86_32
18130 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
18131 + mm->context.user_cs_base = 0UL;
18132 + mm->context.user_cs_limit = ~0UL;
18133 +
18134 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
18135 + cpus_clear(mm->context.cpu_user_cs_mask);
18136 +#endif
18137 +
18138 +#endif
18139 +#endif
18140 +
18141 + }
18142 +
18143 return retval;
18144 }
18145
18146 @@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
18147 }
18148 }
18149
18150 +#ifdef CONFIG_PAX_SEGMEXEC
18151 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
18152 + error = -EINVAL;
18153 + goto out_unlock;
18154 + }
18155 +#endif
18156 +
18157 fill_ldt(&ldt, &ldt_info);
18158 if (oldmode)
18159 ldt.avl = 0;
18160 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
18161 index 5b19e4d..6476a76 100644
18162 --- a/arch/x86/kernel/machine_kexec_32.c
18163 +++ b/arch/x86/kernel/machine_kexec_32.c
18164 @@ -26,7 +26,7 @@
18165 #include <asm/cacheflush.h>
18166 #include <asm/debugreg.h>
18167
18168 -static void set_idt(void *newidt, __u16 limit)
18169 +static void set_idt(struct desc_struct *newidt, __u16 limit)
18170 {
18171 struct desc_ptr curidt;
18172
18173 @@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
18174 }
18175
18176
18177 -static void set_gdt(void *newgdt, __u16 limit)
18178 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
18179 {
18180 struct desc_ptr curgdt;
18181
18182 @@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
18183 }
18184
18185 control_page = page_address(image->control_code_page);
18186 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
18187 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
18188
18189 relocate_kernel_ptr = control_page;
18190 page_list[PA_CONTROL_PAGE] = __pa(control_page);
18191 diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
18192 index 0327e2b..e43737b 100644
18193 --- a/arch/x86/kernel/microcode_intel.c
18194 +++ b/arch/x86/kernel/microcode_intel.c
18195 @@ -430,13 +430,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device)
18196
18197 static int get_ucode_user(void *to, const void *from, size_t n)
18198 {
18199 - return copy_from_user(to, from, n);
18200 + return copy_from_user(to, (const void __force_user *)from, n);
18201 }
18202
18203 static enum ucode_state
18204 request_microcode_user(int cpu, const void __user *buf, size_t size)
18205 {
18206 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
18207 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
18208 }
18209
18210 static void microcode_fini_cpu(int cpu)
18211 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
18212 index 216a4d7..b328f09 100644
18213 --- a/arch/x86/kernel/module.c
18214 +++ b/arch/x86/kernel/module.c
18215 @@ -43,15 +43,60 @@ do { \
18216 } while (0)
18217 #endif
18218
18219 -void *module_alloc(unsigned long size)
18220 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
18221 {
18222 - if (PAGE_ALIGN(size) > MODULES_LEN)
18223 + if (size == 0 || PAGE_ALIGN(size) > MODULES_LEN)
18224 return NULL;
18225 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
18226 - GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
18227 + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
18228 -1, __builtin_return_address(0));
18229 }
18230
18231 +void *module_alloc(unsigned long size)
18232 +{
18233 +
18234 +#ifdef CONFIG_PAX_KERNEXEC
18235 + return __module_alloc(size, PAGE_KERNEL);
18236 +#else
18237 + return __module_alloc(size, PAGE_KERNEL_EXEC);
18238 +#endif
18239 +
18240 +}
18241 +
18242 +#ifdef CONFIG_PAX_KERNEXEC
18243 +#ifdef CONFIG_X86_32
18244 +void *module_alloc_exec(unsigned long size)
18245 +{
18246 + struct vm_struct *area;
18247 +
18248 + if (size == 0)
18249 + return NULL;
18250 +
18251 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
18252 + return area ? area->addr : NULL;
18253 +}
18254 +EXPORT_SYMBOL(module_alloc_exec);
18255 +
18256 +void module_free_exec(struct module *mod, void *module_region)
18257 +{
18258 + vunmap(module_region);
18259 +}
18260 +EXPORT_SYMBOL(module_free_exec);
18261 +#else
18262 +void module_free_exec(struct module *mod, void *module_region)
18263 +{
18264 + module_free(mod, module_region);
18265 +}
18266 +EXPORT_SYMBOL(module_free_exec);
18267 +
18268 +void *module_alloc_exec(unsigned long size)
18269 +{
18270 + return __module_alloc(size, PAGE_KERNEL_RX);
18271 +}
18272 +EXPORT_SYMBOL(module_alloc_exec);
18273 +#endif
18274 +#endif
18275 +
18276 #ifdef CONFIG_X86_32
18277 int apply_relocate(Elf32_Shdr *sechdrs,
18278 const char *strtab,
18279 @@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18280 unsigned int i;
18281 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
18282 Elf32_Sym *sym;
18283 - uint32_t *location;
18284 + uint32_t *plocation, location;
18285
18286 DEBUGP("Applying relocate section %u to %u\n",
18287 relsec, sechdrs[relsec].sh_info);
18288 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
18289 /* This is where to make the change */
18290 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
18291 - + rel[i].r_offset;
18292 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
18293 + location = (uint32_t)plocation;
18294 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
18295 + plocation = ktla_ktva((void *)plocation);
18296 /* This is the symbol it is referring to. Note that all
18297 undefined symbols have been resolved. */
18298 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
18299 @@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18300 switch (ELF32_R_TYPE(rel[i].r_info)) {
18301 case R_386_32:
18302 /* We add the value into the location given */
18303 - *location += sym->st_value;
18304 + pax_open_kernel();
18305 + *plocation += sym->st_value;
18306 + pax_close_kernel();
18307 break;
18308 case R_386_PC32:
18309 /* Add the value, subtract its position */
18310 - *location += sym->st_value - (uint32_t)location;
18311 + pax_open_kernel();
18312 + *plocation += sym->st_value - location;
18313 + pax_close_kernel();
18314 break;
18315 default:
18316 pr_err("%s: Unknown relocation: %u\n",
18317 @@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
18318 case R_X86_64_NONE:
18319 break;
18320 case R_X86_64_64:
18321 + pax_open_kernel();
18322 *(u64 *)loc = val;
18323 + pax_close_kernel();
18324 break;
18325 case R_X86_64_32:
18326 + pax_open_kernel();
18327 *(u32 *)loc = val;
18328 + pax_close_kernel();
18329 if (val != *(u32 *)loc)
18330 goto overflow;
18331 break;
18332 case R_X86_64_32S:
18333 + pax_open_kernel();
18334 *(s32 *)loc = val;
18335 + pax_close_kernel();
18336 if ((s64)val != *(s32 *)loc)
18337 goto overflow;
18338 break;
18339 case R_X86_64_PC32:
18340 val -= (u64)loc;
18341 + pax_open_kernel();
18342 *(u32 *)loc = val;
18343 + pax_close_kernel();
18344 +
18345 #if 0
18346 if ((s64)val != *(s32 *)loc)
18347 goto overflow;
18348 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
18349 index f84f5c5..e27e54b 100644
18350 --- a/arch/x86/kernel/nmi.c
18351 +++ b/arch/x86/kernel/nmi.c
18352 @@ -479,6 +479,17 @@ static inline void nmi_nesting_postprocess(void)
18353 dotraplinkage notrace __kprobes void
18354 do_nmi(struct pt_regs *regs, long error_code)
18355 {
18356 +
18357 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18358 + if (!user_mode(regs)) {
18359 + unsigned long cs = regs->cs & 0xFFFF;
18360 + unsigned long ip = ktva_ktla(regs->ip);
18361 +
18362 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
18363 + regs->ip = ip;
18364 + }
18365 +#endif
18366 +
18367 nmi_nesting_preprocess(regs);
18368
18369 nmi_enter();
18370 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
18371 index 676b8c7..870ba04 100644
18372 --- a/arch/x86/kernel/paravirt-spinlocks.c
18373 +++ b/arch/x86/kernel/paravirt-spinlocks.c
18374 @@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
18375 arch_spin_lock(lock);
18376 }
18377
18378 -struct pv_lock_ops pv_lock_ops = {
18379 +struct pv_lock_ops pv_lock_ops __read_only = {
18380 #ifdef CONFIG_SMP
18381 .spin_is_locked = __ticket_spin_is_locked,
18382 .spin_is_contended = __ticket_spin_is_contended,
18383 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
18384 index 17fff18..7bb2088 100644
18385 --- a/arch/x86/kernel/paravirt.c
18386 +++ b/arch/x86/kernel/paravirt.c
18387 @@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
18388 {
18389 return x;
18390 }
18391 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18392 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
18393 +#endif
18394
18395 void __init default_banner(void)
18396 {
18397 @@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
18398 if (opfunc == NULL)
18399 /* If there's no function, patch it with a ud2a (BUG) */
18400 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
18401 - else if (opfunc == _paravirt_nop)
18402 + else if (opfunc == (void *)_paravirt_nop)
18403 /* If the operation is a nop, then nop the callsite */
18404 ret = paravirt_patch_nop();
18405
18406 /* identity functions just return their single argument */
18407 - else if (opfunc == _paravirt_ident_32)
18408 + else if (opfunc == (void *)_paravirt_ident_32)
18409 ret = paravirt_patch_ident_32(insnbuf, len);
18410 - else if (opfunc == _paravirt_ident_64)
18411 + else if (opfunc == (void *)_paravirt_ident_64)
18412 ret = paravirt_patch_ident_64(insnbuf, len);
18413 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18414 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
18415 + ret = paravirt_patch_ident_64(insnbuf, len);
18416 +#endif
18417
18418 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
18419 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
18420 @@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
18421 if (insn_len > len || start == NULL)
18422 insn_len = len;
18423 else
18424 - memcpy(insnbuf, start, insn_len);
18425 + memcpy(insnbuf, ktla_ktva(start), insn_len);
18426
18427 return insn_len;
18428 }
18429 @@ -304,7 +311,7 @@ void arch_flush_lazy_mmu_mode(void)
18430 preempt_enable();
18431 }
18432
18433 -struct pv_info pv_info = {
18434 +struct pv_info pv_info __read_only = {
18435 .name = "bare hardware",
18436 .paravirt_enabled = 0,
18437 .kernel_rpl = 0,
18438 @@ -315,16 +322,16 @@ struct pv_info pv_info = {
18439 #endif
18440 };
18441
18442 -struct pv_init_ops pv_init_ops = {
18443 +struct pv_init_ops pv_init_ops __read_only = {
18444 .patch = native_patch,
18445 };
18446
18447 -struct pv_time_ops pv_time_ops = {
18448 +struct pv_time_ops pv_time_ops __read_only = {
18449 .sched_clock = native_sched_clock,
18450 .steal_clock = native_steal_clock,
18451 };
18452
18453 -struct pv_irq_ops pv_irq_ops = {
18454 +struct pv_irq_ops pv_irq_ops __read_only = {
18455 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
18456 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
18457 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
18458 @@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
18459 #endif
18460 };
18461
18462 -struct pv_cpu_ops pv_cpu_ops = {
18463 +struct pv_cpu_ops pv_cpu_ops __read_only = {
18464 .cpuid = native_cpuid,
18465 .get_debugreg = native_get_debugreg,
18466 .set_debugreg = native_set_debugreg,
18467 @@ -395,21 +402,26 @@ struct pv_cpu_ops pv_cpu_ops = {
18468 .end_context_switch = paravirt_nop,
18469 };
18470
18471 -struct pv_apic_ops pv_apic_ops = {
18472 +struct pv_apic_ops pv_apic_ops __read_only = {
18473 #ifdef CONFIG_X86_LOCAL_APIC
18474 .startup_ipi_hook = paravirt_nop,
18475 #endif
18476 };
18477
18478 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
18479 +#ifdef CONFIG_X86_32
18480 +#ifdef CONFIG_X86_PAE
18481 +/* 64-bit pagetable entries */
18482 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
18483 +#else
18484 /* 32-bit pagetable entries */
18485 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
18486 +#endif
18487 #else
18488 /* 64-bit pagetable entries */
18489 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
18490 #endif
18491
18492 -struct pv_mmu_ops pv_mmu_ops = {
18493 +struct pv_mmu_ops pv_mmu_ops __read_only = {
18494
18495 .read_cr2 = native_read_cr2,
18496 .write_cr2 = native_write_cr2,
18497 @@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
18498 .make_pud = PTE_IDENT,
18499
18500 .set_pgd = native_set_pgd,
18501 + .set_pgd_batched = native_set_pgd_batched,
18502 #endif
18503 #endif /* PAGETABLE_LEVELS >= 3 */
18504
18505 @@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
18506 },
18507
18508 .set_fixmap = native_set_fixmap,
18509 +
18510 +#ifdef CONFIG_PAX_KERNEXEC
18511 + .pax_open_kernel = native_pax_open_kernel,
18512 + .pax_close_kernel = native_pax_close_kernel,
18513 +#endif
18514 +
18515 };
18516
18517 EXPORT_SYMBOL_GPL(pv_time_ops);
18518 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
18519 index 35ccf75..7a15747 100644
18520 --- a/arch/x86/kernel/pci-iommu_table.c
18521 +++ b/arch/x86/kernel/pci-iommu_table.c
18522 @@ -2,7 +2,7 @@
18523 #include <asm/iommu_table.h>
18524 #include <linux/string.h>
18525 #include <linux/kallsyms.h>
18526 -
18527 +#include <linux/sched.h>
18528
18529 #define DEBUG 1
18530
18531 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
18532 index ef6a845..8028ed3 100644
18533 --- a/arch/x86/kernel/process.c
18534 +++ b/arch/x86/kernel/process.c
18535 @@ -36,7 +36,8 @@
18536 * section. Since TSS's are completely CPU-local, we want them
18537 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
18538 */
18539 -DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
18540 +struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
18541 +EXPORT_SYMBOL(init_tss);
18542
18543 #ifdef CONFIG_X86_64
18544 static DEFINE_PER_CPU(unsigned char, is_idle);
18545 @@ -94,7 +95,7 @@ void arch_task_cache_init(void)
18546 task_xstate_cachep =
18547 kmem_cache_create("task_xstate", xstate_size,
18548 __alignof__(union thread_xstate),
18549 - SLAB_PANIC | SLAB_NOTRACK, NULL);
18550 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
18551 }
18552
18553 static inline void drop_fpu(struct task_struct *tsk)
18554 @@ -117,7 +118,7 @@ void exit_thread(void)
18555 unsigned long *bp = t->io_bitmap_ptr;
18556
18557 if (bp) {
18558 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
18559 + struct tss_struct *tss = init_tss + get_cpu();
18560
18561 t->io_bitmap_ptr = NULL;
18562 clear_thread_flag(TIF_IO_BITMAP);
18563 @@ -148,7 +149,7 @@ void show_regs_common(void)
18564 board = dmi_get_system_info(DMI_BOARD_NAME);
18565
18566 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s %s %s%s%s\n",
18567 - current->pid, current->comm, print_tainted(),
18568 + task_pid_nr(current), current->comm, print_tainted(),
18569 init_utsname()->release,
18570 (int)strcspn(init_utsname()->version, " "),
18571 init_utsname()->version,
18572 @@ -161,6 +162,9 @@ void flush_thread(void)
18573 {
18574 struct task_struct *tsk = current;
18575
18576 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18577 + loadsegment(gs, 0);
18578 +#endif
18579 flush_ptrace_hw_breakpoint(tsk);
18580 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
18581 drop_fpu(tsk);
18582 @@ -318,10 +322,10 @@ int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
18583 regs.di = (unsigned long) arg;
18584
18585 #ifdef CONFIG_X86_32
18586 - regs.ds = __USER_DS;
18587 - regs.es = __USER_DS;
18588 + regs.ds = __KERNEL_DS;
18589 + regs.es = __KERNEL_DS;
18590 regs.fs = __KERNEL_PERCPU;
18591 - regs.gs = __KERNEL_STACK_CANARY;
18592 + savesegment(gs, regs.gs);
18593 #else
18594 regs.ss = __KERNEL_DS;
18595 #endif
18596 @@ -407,7 +411,7 @@ static void __exit_idle(void)
18597 void exit_idle(void)
18598 {
18599 /* idle loop has pid 0 */
18600 - if (current->pid)
18601 + if (task_pid_nr(current))
18602 return;
18603 __exit_idle();
18604 }
18605 @@ -516,7 +520,7 @@ bool set_pm_idle_to_default(void)
18606
18607 return ret;
18608 }
18609 -void stop_this_cpu(void *dummy)
18610 +__noreturn void stop_this_cpu(void *dummy)
18611 {
18612 local_irq_disable();
18613 /*
18614 @@ -744,16 +748,37 @@ static int __init idle_setup(char *str)
18615 }
18616 early_param("idle", idle_setup);
18617
18618 -unsigned long arch_align_stack(unsigned long sp)
18619 +#ifdef CONFIG_PAX_RANDKSTACK
18620 +void pax_randomize_kstack(struct pt_regs *regs)
18621 {
18622 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
18623 - sp -= get_random_int() % 8192;
18624 - return sp & ~0xf;
18625 -}
18626 + struct thread_struct *thread = &current->thread;
18627 + unsigned long time;
18628
18629 -unsigned long arch_randomize_brk(struct mm_struct *mm)
18630 -{
18631 - unsigned long range_end = mm->brk + 0x02000000;
18632 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
18633 -}
18634 + if (!randomize_va_space)
18635 + return;
18636 +
18637 + if (v8086_mode(regs))
18638 + return;
18639
18640 + rdtscl(time);
18641 +
18642 + /* P4 seems to return a 0 LSB, ignore it */
18643 +#ifdef CONFIG_MPENTIUM4
18644 + time &= 0x3EUL;
18645 + time <<= 2;
18646 +#elif defined(CONFIG_X86_64)
18647 + time &= 0xFUL;
18648 + time <<= 4;
18649 +#else
18650 + time &= 0x1FUL;
18651 + time <<= 3;
18652 +#endif
18653 +
18654 + thread->sp0 ^= time;
18655 + load_sp0(init_tss + smp_processor_id(), thread);
18656 +
18657 +#ifdef CONFIG_X86_64
18658 + this_cpu_write(kernel_stack, thread->sp0);
18659 +#endif
18660 +}
18661 +#endif
18662 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
18663 index 516fa18..80bd9e6 100644
18664 --- a/arch/x86/kernel/process_32.c
18665 +++ b/arch/x86/kernel/process_32.c
18666 @@ -64,6 +64,7 @@ asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
18667 unsigned long thread_saved_pc(struct task_struct *tsk)
18668 {
18669 return ((unsigned long *)tsk->thread.sp)[3];
18670 +//XXX return tsk->thread.eip;
18671 }
18672
18673 void __show_regs(struct pt_regs *regs, int all)
18674 @@ -73,15 +74,14 @@ void __show_regs(struct pt_regs *regs, int all)
18675 unsigned long sp;
18676 unsigned short ss, gs;
18677
18678 - if (user_mode_vm(regs)) {
18679 + if (user_mode(regs)) {
18680 sp = regs->sp;
18681 ss = regs->ss & 0xffff;
18682 - gs = get_user_gs(regs);
18683 } else {
18684 sp = kernel_stack_pointer(regs);
18685 savesegment(ss, ss);
18686 - savesegment(gs, gs);
18687 }
18688 + gs = get_user_gs(regs);
18689
18690 show_regs_common();
18691
18692 @@ -134,13 +134,14 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18693 struct task_struct *tsk;
18694 int err;
18695
18696 - childregs = task_pt_regs(p);
18697 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
18698 *childregs = *regs;
18699 childregs->ax = 0;
18700 childregs->sp = sp;
18701
18702 p->thread.sp = (unsigned long) childregs;
18703 p->thread.sp0 = (unsigned long) (childregs+1);
18704 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18705
18706 p->thread.ip = (unsigned long) ret_from_fork;
18707
18708 @@ -231,7 +232,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18709 struct thread_struct *prev = &prev_p->thread,
18710 *next = &next_p->thread;
18711 int cpu = smp_processor_id();
18712 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
18713 + struct tss_struct *tss = init_tss + cpu;
18714 fpu_switch_t fpu;
18715
18716 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
18717 @@ -255,6 +256,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18718 */
18719 lazy_save_gs(prev->gs);
18720
18721 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18722 + __set_fs(task_thread_info(next_p)->addr_limit);
18723 +#endif
18724 +
18725 /*
18726 * Load the per-thread Thread-Local Storage descriptor.
18727 */
18728 @@ -285,6 +290,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18729 */
18730 arch_end_context_switch(next_p);
18731
18732 + this_cpu_write(current_task, next_p);
18733 + this_cpu_write(current_tinfo, &next_p->tinfo);
18734 +
18735 /*
18736 * Restore %gs if needed (which is common)
18737 */
18738 @@ -293,8 +301,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18739
18740 switch_fpu_finish(next_p, fpu);
18741
18742 - this_cpu_write(current_task, next_p);
18743 -
18744 return prev_p;
18745 }
18746
18747 @@ -324,4 +330,3 @@ unsigned long get_wchan(struct task_struct *p)
18748 } while (count++ < 16);
18749 return 0;
18750 }
18751 -
18752 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
18753 index 0a980c9..1d0e689 100644
18754 --- a/arch/x86/kernel/process_64.c
18755 +++ b/arch/x86/kernel/process_64.c
18756 @@ -153,8 +153,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18757 struct pt_regs *childregs;
18758 struct task_struct *me = current;
18759
18760 - childregs = ((struct pt_regs *)
18761 - (THREAD_SIZE + task_stack_page(p))) - 1;
18762 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 16;
18763 *childregs = *regs;
18764
18765 childregs->ax = 0;
18766 @@ -166,6 +165,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18767 p->thread.sp = (unsigned long) childregs;
18768 p->thread.sp0 = (unsigned long) (childregs+1);
18769 p->thread.usersp = me->thread.usersp;
18770 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18771
18772 set_tsk_thread_flag(p, TIF_FORK);
18773
18774 @@ -271,7 +271,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18775 struct thread_struct *prev = &prev_p->thread;
18776 struct thread_struct *next = &next_p->thread;
18777 int cpu = smp_processor_id();
18778 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
18779 + struct tss_struct *tss = init_tss + cpu;
18780 unsigned fsindex, gsindex;
18781 fpu_switch_t fpu;
18782
18783 @@ -353,10 +353,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18784 prev->usersp = this_cpu_read(old_rsp);
18785 this_cpu_write(old_rsp, next->usersp);
18786 this_cpu_write(current_task, next_p);
18787 + this_cpu_write(current_tinfo, &next_p->tinfo);
18788
18789 - this_cpu_write(kernel_stack,
18790 - (unsigned long)task_stack_page(next_p) +
18791 - THREAD_SIZE - KERNEL_STACK_OFFSET);
18792 + this_cpu_write(kernel_stack, next->sp0);
18793
18794 /*
18795 * Now maybe reload the debug registers and handle I/O bitmaps
18796 @@ -425,12 +424,11 @@ unsigned long get_wchan(struct task_struct *p)
18797 if (!p || p == current || p->state == TASK_RUNNING)
18798 return 0;
18799 stack = (unsigned long)task_stack_page(p);
18800 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
18801 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
18802 return 0;
18803 fp = *(u64 *)(p->thread.sp);
18804 do {
18805 - if (fp < (unsigned long)stack ||
18806 - fp >= (unsigned long)stack+THREAD_SIZE)
18807 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
18808 return 0;
18809 ip = *(u64 *)(fp+8);
18810 if (!in_sched_functions(ip))
18811 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
18812 index c4c6a5c..905f440 100644
18813 --- a/arch/x86/kernel/ptrace.c
18814 +++ b/arch/x86/kernel/ptrace.c
18815 @@ -824,7 +824,7 @@ long arch_ptrace(struct task_struct *child, long request,
18816 unsigned long addr, unsigned long data)
18817 {
18818 int ret;
18819 - unsigned long __user *datap = (unsigned long __user *)data;
18820 + unsigned long __user *datap = (__force unsigned long __user *)data;
18821
18822 switch (request) {
18823 /* read the word at location addr in the USER area. */
18824 @@ -909,14 +909,14 @@ long arch_ptrace(struct task_struct *child, long request,
18825 if ((int) addr < 0)
18826 return -EIO;
18827 ret = do_get_thread_area(child, addr,
18828 - (struct user_desc __user *)data);
18829 + (__force struct user_desc __user *) data);
18830 break;
18831
18832 case PTRACE_SET_THREAD_AREA:
18833 if ((int) addr < 0)
18834 return -EIO;
18835 ret = do_set_thread_area(child, addr,
18836 - (struct user_desc __user *)data, 0);
18837 + (__force struct user_desc __user *) data, 0);
18838 break;
18839 #endif
18840
18841 @@ -1426,7 +1426,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
18842 memset(info, 0, sizeof(*info));
18843 info->si_signo = SIGTRAP;
18844 info->si_code = si_code;
18845 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
18846 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
18847 }
18848
18849 void user_single_step_siginfo(struct task_struct *tsk,
18850 @@ -1455,6 +1455,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
18851 # define IS_IA32 0
18852 #endif
18853
18854 +#ifdef CONFIG_GRKERNSEC_SETXID
18855 +extern void gr_delayed_cred_worker(void);
18856 +#endif
18857 +
18858 /*
18859 * We must return the syscall number to actually look up in the table.
18860 * This can be -1L to skip running any syscall at all.
18861 @@ -1463,6 +1467,11 @@ long syscall_trace_enter(struct pt_regs *regs)
18862 {
18863 long ret = 0;
18864
18865 +#ifdef CONFIG_GRKERNSEC_SETXID
18866 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18867 + gr_delayed_cred_worker();
18868 +#endif
18869 +
18870 /*
18871 * If we stepped into a sysenter/syscall insn, it trapped in
18872 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
18873 @@ -1511,6 +1520,11 @@ void syscall_trace_leave(struct pt_regs *regs)
18874 {
18875 bool step;
18876
18877 +#ifdef CONFIG_GRKERNSEC_SETXID
18878 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18879 + gr_delayed_cred_worker();
18880 +#endif
18881 +
18882 audit_syscall_exit(regs);
18883
18884 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
18885 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
18886 index 42eb330..139955c 100644
18887 --- a/arch/x86/kernel/pvclock.c
18888 +++ b/arch/x86/kernel/pvclock.c
18889 @@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
18890 return pv_tsc_khz;
18891 }
18892
18893 -static atomic64_t last_value = ATOMIC64_INIT(0);
18894 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
18895
18896 void pvclock_resume(void)
18897 {
18898 - atomic64_set(&last_value, 0);
18899 + atomic64_set_unchecked(&last_value, 0);
18900 }
18901
18902 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18903 @@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18904 * updating at the same time, and one of them could be slightly behind,
18905 * making the assumption that last_value always go forward fail to hold.
18906 */
18907 - last = atomic64_read(&last_value);
18908 + last = atomic64_read_unchecked(&last_value);
18909 do {
18910 if (ret < last)
18911 return last;
18912 - last = atomic64_cmpxchg(&last_value, last, ret);
18913 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
18914 } while (unlikely(last != ret));
18915
18916 return ret;
18917 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
18918 index 52190a9..8074389 100644
18919 --- a/arch/x86/kernel/reboot.c
18920 +++ b/arch/x86/kernel/reboot.c
18921 @@ -36,7 +36,7 @@ void (*pm_power_off)(void);
18922 EXPORT_SYMBOL(pm_power_off);
18923
18924 static const struct desc_ptr no_idt = {};
18925 -static int reboot_mode;
18926 +static unsigned short reboot_mode;
18927 enum reboot_type reboot_type = BOOT_ACPI;
18928 int reboot_force;
18929
18930 @@ -157,6 +157,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
18931
18932 void __noreturn machine_real_restart(unsigned int type)
18933 {
18934 +
18935 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18936 + struct desc_struct *gdt;
18937 +#endif
18938 +
18939 local_irq_disable();
18940
18941 /*
18942 @@ -184,7 +189,29 @@ void __noreturn machine_real_restart(unsigned int type)
18943
18944 /* Jump to the identity-mapped low memory code */
18945 #ifdef CONFIG_X86_32
18946 - asm volatile("jmpl *%0" : :
18947 +
18948 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
18949 + gdt = get_cpu_gdt_table(smp_processor_id());
18950 + pax_open_kernel();
18951 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18952 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
18953 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
18954 + loadsegment(ds, __KERNEL_DS);
18955 + loadsegment(es, __KERNEL_DS);
18956 + loadsegment(ss, __KERNEL_DS);
18957 +#endif
18958 +#ifdef CONFIG_PAX_KERNEXEC
18959 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
18960 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
18961 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
18962 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
18963 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
18964 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
18965 +#endif
18966 + pax_close_kernel();
18967 +#endif
18968 +
18969 + asm volatile("ljmpl *%0" : :
18970 "rm" (real_mode_header->machine_real_restart_asm),
18971 "a" (type));
18972 #else
18973 @@ -539,7 +566,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
18974 * try to force a triple fault and then cycle between hitting the keyboard
18975 * controller and doing that
18976 */
18977 -static void native_machine_emergency_restart(void)
18978 +static void __noreturn native_machine_emergency_restart(void)
18979 {
18980 int i;
18981 int attempt = 0;
18982 @@ -662,13 +689,13 @@ void native_machine_shutdown(void)
18983 #endif
18984 }
18985
18986 -static void __machine_emergency_restart(int emergency)
18987 +static void __noreturn __machine_emergency_restart(int emergency)
18988 {
18989 reboot_emergency = emergency;
18990 machine_ops.emergency_restart();
18991 }
18992
18993 -static void native_machine_restart(char *__unused)
18994 +static void __noreturn native_machine_restart(char *__unused)
18995 {
18996 pr_notice("machine restart\n");
18997
18998 @@ -677,7 +704,7 @@ static void native_machine_restart(char *__unused)
18999 __machine_emergency_restart(0);
19000 }
19001
19002 -static void native_machine_halt(void)
19003 +static void __noreturn native_machine_halt(void)
19004 {
19005 /* Stop other cpus and apics */
19006 machine_shutdown();
19007 @@ -687,7 +714,7 @@ static void native_machine_halt(void)
19008 stop_this_cpu(NULL);
19009 }
19010
19011 -static void native_machine_power_off(void)
19012 +static void __noreturn native_machine_power_off(void)
19013 {
19014 if (pm_power_off) {
19015 if (!reboot_force)
19016 @@ -696,6 +723,7 @@ static void native_machine_power_off(void)
19017 }
19018 /* A fallback in case there is no PM info available */
19019 tboot_shutdown(TB_SHUTDOWN_HALT);
19020 + unreachable();
19021 }
19022
19023 struct machine_ops machine_ops = {
19024 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
19025 index 7a6f3b3..bed145d7 100644
19026 --- a/arch/x86/kernel/relocate_kernel_64.S
19027 +++ b/arch/x86/kernel/relocate_kernel_64.S
19028 @@ -11,6 +11,7 @@
19029 #include <asm/kexec.h>
19030 #include <asm/processor-flags.h>
19031 #include <asm/pgtable_types.h>
19032 +#include <asm/alternative-asm.h>
19033
19034 /*
19035 * Must be relocatable PIC code callable as a C function
19036 @@ -160,13 +161,14 @@ identity_mapped:
19037 xorq %rbp, %rbp
19038 xorq %r8, %r8
19039 xorq %r9, %r9
19040 - xorq %r10, %r9
19041 + xorq %r10, %r10
19042 xorq %r11, %r11
19043 xorq %r12, %r12
19044 xorq %r13, %r13
19045 xorq %r14, %r14
19046 xorq %r15, %r15
19047
19048 + pax_force_retaddr 0, 1
19049 ret
19050
19051 1:
19052 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
19053 index 5cee802..bc22bc3 100644
19054 --- a/arch/x86/kernel/setup.c
19055 +++ b/arch/x86/kernel/setup.c
19056 @@ -440,7 +440,7 @@ static void __init parse_setup_data(void)
19057
19058 switch (data->type) {
19059 case SETUP_E820_EXT:
19060 - parse_e820_ext(data);
19061 + parse_e820_ext((struct setup_data __force_kernel *)data);
19062 break;
19063 case SETUP_DTB:
19064 add_dtb(pa_data);
19065 @@ -632,7 +632,7 @@ static void __init trim_bios_range(void)
19066 * area (640->1Mb) as ram even though it is not.
19067 * take them out.
19068 */
19069 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
19070 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
19071 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
19072 }
19073
19074 @@ -755,14 +755,14 @@ void __init setup_arch(char **cmdline_p)
19075
19076 if (!boot_params.hdr.root_flags)
19077 root_mountflags &= ~MS_RDONLY;
19078 - init_mm.start_code = (unsigned long) _text;
19079 - init_mm.end_code = (unsigned long) _etext;
19080 + init_mm.start_code = ktla_ktva((unsigned long) _text);
19081 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
19082 init_mm.end_data = (unsigned long) _edata;
19083 init_mm.brk = _brk_end;
19084
19085 - code_resource.start = virt_to_phys(_text);
19086 - code_resource.end = virt_to_phys(_etext)-1;
19087 - data_resource.start = virt_to_phys(_etext);
19088 + code_resource.start = virt_to_phys(ktla_ktva(_text));
19089 + code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
19090 + data_resource.start = virt_to_phys(_sdata);
19091 data_resource.end = virt_to_phys(_edata)-1;
19092 bss_resource.start = virt_to_phys(&__bss_start);
19093 bss_resource.end = virt_to_phys(&__bss_stop)-1;
19094 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
19095 index 5cdff03..5810740 100644
19096 --- a/arch/x86/kernel/setup_percpu.c
19097 +++ b/arch/x86/kernel/setup_percpu.c
19098 @@ -21,19 +21,17 @@
19099 #include <asm/cpu.h>
19100 #include <asm/stackprotector.h>
19101
19102 -DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
19103 +#ifdef CONFIG_SMP
19104 +DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
19105 EXPORT_PER_CPU_SYMBOL(cpu_number);
19106 +#endif
19107
19108 -#ifdef CONFIG_X86_64
19109 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
19110 -#else
19111 -#define BOOT_PERCPU_OFFSET 0
19112 -#endif
19113
19114 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
19115 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
19116
19117 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
19118 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
19119 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
19120 };
19121 EXPORT_SYMBOL(__per_cpu_offset);
19122 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
19123 {
19124 #ifdef CONFIG_X86_32
19125 struct desc_struct gdt;
19126 + unsigned long base = per_cpu_offset(cpu);
19127
19128 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
19129 - 0x2 | DESCTYPE_S, 0x8);
19130 - gdt.s = 1;
19131 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
19132 + 0x83 | DESCTYPE_S, 0xC);
19133 write_gdt_entry(get_cpu_gdt_table(cpu),
19134 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
19135 #endif
19136 @@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
19137 /* alrighty, percpu areas up and running */
19138 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
19139 for_each_possible_cpu(cpu) {
19140 +#ifdef CONFIG_CC_STACKPROTECTOR
19141 +#ifdef CONFIG_X86_32
19142 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
19143 +#endif
19144 +#endif
19145 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
19146 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
19147 per_cpu(cpu_number, cpu) = cpu;
19148 @@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
19149 */
19150 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
19151 #endif
19152 +#ifdef CONFIG_CC_STACKPROTECTOR
19153 +#ifdef CONFIG_X86_32
19154 + if (!cpu)
19155 + per_cpu(stack_canary.canary, cpu) = canary;
19156 +#endif
19157 +#endif
19158 /*
19159 * Up to this point, the boot CPU has been using .init.data
19160 * area. Reload any changed state for the boot CPU.
19161 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
19162 index b280908..6de349e 100644
19163 --- a/arch/x86/kernel/signal.c
19164 +++ b/arch/x86/kernel/signal.c
19165 @@ -194,7 +194,7 @@ static unsigned long align_sigframe(unsigned long sp)
19166 * Align the stack pointer according to the i386 ABI,
19167 * i.e. so that on function entry ((sp + 4) & 15) == 0.
19168 */
19169 - sp = ((sp + 4) & -16ul) - 4;
19170 + sp = ((sp - 12) & -16ul) - 4;
19171 #else /* !CONFIG_X86_32 */
19172 sp = round_down(sp, 16) - 8;
19173 #endif
19174 @@ -245,11 +245,11 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
19175 * Return an always-bogus address instead so we will die with SIGSEGV.
19176 */
19177 if (onsigstack && !likely(on_sig_stack(sp)))
19178 - return (void __user *)-1L;
19179 + return (__force void __user *)-1L;
19180
19181 /* save i387 state */
19182 if (used_math() && save_i387_xstate(*fpstate) < 0)
19183 - return (void __user *)-1L;
19184 + return (__force void __user *)-1L;
19185
19186 return (void __user *)sp;
19187 }
19188 @@ -304,9 +304,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19189 }
19190
19191 if (current->mm->context.vdso)
19192 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19193 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19194 else
19195 - restorer = &frame->retcode;
19196 + restorer = (void __user *)&frame->retcode;
19197 if (ka->sa.sa_flags & SA_RESTORER)
19198 restorer = ka->sa.sa_restorer;
19199
19200 @@ -320,7 +320,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19201 * reasons and because gdb uses it as a signature to notice
19202 * signal handler stack frames.
19203 */
19204 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
19205 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
19206
19207 if (err)
19208 return -EFAULT;
19209 @@ -374,7 +374,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19210 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
19211
19212 /* Set up to return from userspace. */
19213 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19214 + if (current->mm->context.vdso)
19215 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19216 + else
19217 + restorer = (void __user *)&frame->retcode;
19218 if (ka->sa.sa_flags & SA_RESTORER)
19219 restorer = ka->sa.sa_restorer;
19220 put_user_ex(restorer, &frame->pretcode);
19221 @@ -386,7 +389,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19222 * reasons and because gdb uses it as a signature to notice
19223 * signal handler stack frames.
19224 */
19225 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
19226 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
19227 } put_user_catch(err);
19228
19229 if (err)
19230 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
19231 index 7c5a8c3..88d422f 100644
19232 --- a/arch/x86/kernel/smpboot.c
19233 +++ b/arch/x86/kernel/smpboot.c
19234 @@ -670,6 +670,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
19235 idle->thread.sp = (unsigned long) (((struct pt_regs *)
19236 (THREAD_SIZE + task_stack_page(idle))) - 1);
19237 per_cpu(current_task, cpu) = idle;
19238 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
19239
19240 #ifdef CONFIG_X86_32
19241 /* Stack for startup_32 can be just as for start_secondary onwards */
19242 @@ -677,11 +678,13 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
19243 #else
19244 clear_tsk_thread_flag(idle, TIF_FORK);
19245 initial_gs = per_cpu_offset(cpu);
19246 - per_cpu(kernel_stack, cpu) =
19247 - (unsigned long)task_stack_page(idle) -
19248 - KERNEL_STACK_OFFSET + THREAD_SIZE;
19249 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
19250 #endif
19251 +
19252 + pax_open_kernel();
19253 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
19254 + pax_close_kernel();
19255 +
19256 initial_code = (unsigned long)start_secondary;
19257 stack_start = idle->thread.sp;
19258
19259 @@ -817,6 +820,12 @@ int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle)
19260
19261 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
19262
19263 +#ifdef CONFIG_PAX_PER_CPU_PGD
19264 + clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
19265 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
19266 + KERNEL_PGD_PTRS);
19267 +#endif
19268 +
19269 err = do_boot_cpu(apicid, cpu, tidle);
19270 if (err) {
19271 pr_debug("do_boot_cpu failed %d\n", err);
19272 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
19273 index c346d11..d43b163 100644
19274 --- a/arch/x86/kernel/step.c
19275 +++ b/arch/x86/kernel/step.c
19276 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19277 struct desc_struct *desc;
19278 unsigned long base;
19279
19280 - seg &= ~7UL;
19281 + seg >>= 3;
19282
19283 mutex_lock(&child->mm->context.lock);
19284 - if (unlikely((seg >> 3) >= child->mm->context.size))
19285 + if (unlikely(seg >= child->mm->context.size))
19286 addr = -1L; /* bogus selector, access would fault */
19287 else {
19288 desc = child->mm->context.ldt + seg;
19289 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19290 addr += base;
19291 }
19292 mutex_unlock(&child->mm->context.lock);
19293 - }
19294 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
19295 + addr = ktla_ktva(addr);
19296
19297 return addr;
19298 }
19299 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
19300 unsigned char opcode[15];
19301 unsigned long addr = convert_ip_to_linear(child, regs);
19302
19303 + if (addr == -EINVAL)
19304 + return 0;
19305 +
19306 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
19307 for (i = 0; i < copied; i++) {
19308 switch (opcode[i]) {
19309 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
19310 index 0b0cb5f..db6b9ed 100644
19311 --- a/arch/x86/kernel/sys_i386_32.c
19312 +++ b/arch/x86/kernel/sys_i386_32.c
19313 @@ -24,17 +24,224 @@
19314
19315 #include <asm/syscalls.h>
19316
19317 -/*
19318 - * Do a system call from kernel instead of calling sys_execve so we
19319 - * end up with proper pt_regs.
19320 - */
19321 -int kernel_execve(const char *filename,
19322 - const char *const argv[],
19323 - const char *const envp[])
19324 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
19325 {
19326 - long __res;
19327 - asm volatile ("int $0x80"
19328 - : "=a" (__res)
19329 - : "0" (__NR_execve), "b" (filename), "c" (argv), "d" (envp) : "memory");
19330 - return __res;
19331 + unsigned long pax_task_size = TASK_SIZE;
19332 +
19333 +#ifdef CONFIG_PAX_SEGMEXEC
19334 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
19335 + pax_task_size = SEGMEXEC_TASK_SIZE;
19336 +#endif
19337 +
19338 + if (len > pax_task_size || addr > pax_task_size - len)
19339 + return -EINVAL;
19340 +
19341 + return 0;
19342 +}
19343 +
19344 +unsigned long
19345 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
19346 + unsigned long len, unsigned long pgoff, unsigned long flags)
19347 +{
19348 + struct mm_struct *mm = current->mm;
19349 + struct vm_area_struct *vma;
19350 + unsigned long start_addr, pax_task_size = TASK_SIZE;
19351 +
19352 +#ifdef CONFIG_PAX_SEGMEXEC
19353 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19354 + pax_task_size = SEGMEXEC_TASK_SIZE;
19355 +#endif
19356 +
19357 + pax_task_size -= PAGE_SIZE;
19358 +
19359 + if (len > pax_task_size)
19360 + return -ENOMEM;
19361 +
19362 + if (flags & MAP_FIXED)
19363 + return addr;
19364 +
19365 +#ifdef CONFIG_PAX_RANDMMAP
19366 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19367 +#endif
19368 +
19369 + if (addr) {
19370 + addr = PAGE_ALIGN(addr);
19371 + if (pax_task_size - len >= addr) {
19372 + vma = find_vma(mm, addr);
19373 + if (check_heap_stack_gap(vma, addr, len))
19374 + return addr;
19375 + }
19376 + }
19377 + if (len > mm->cached_hole_size) {
19378 + start_addr = addr = mm->free_area_cache;
19379 + } else {
19380 + start_addr = addr = mm->mmap_base;
19381 + mm->cached_hole_size = 0;
19382 + }
19383 +
19384 +#ifdef CONFIG_PAX_PAGEEXEC
19385 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
19386 + start_addr = 0x00110000UL;
19387 +
19388 +#ifdef CONFIG_PAX_RANDMMAP
19389 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19390 + start_addr += mm->delta_mmap & 0x03FFF000UL;
19391 +#endif
19392 +
19393 + if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
19394 + start_addr = addr = mm->mmap_base;
19395 + else
19396 + addr = start_addr;
19397 + }
19398 +#endif
19399 +
19400 +full_search:
19401 + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
19402 + /* At this point: (!vma || addr < vma->vm_end). */
19403 + if (pax_task_size - len < addr) {
19404 + /*
19405 + * Start a new search - just in case we missed
19406 + * some holes.
19407 + */
19408 + if (start_addr != mm->mmap_base) {
19409 + start_addr = addr = mm->mmap_base;
19410 + mm->cached_hole_size = 0;
19411 + goto full_search;
19412 + }
19413 + return -ENOMEM;
19414 + }
19415 + if (check_heap_stack_gap(vma, addr, len))
19416 + break;
19417 + if (addr + mm->cached_hole_size < vma->vm_start)
19418 + mm->cached_hole_size = vma->vm_start - addr;
19419 + addr = vma->vm_end;
19420 + if (mm->start_brk <= addr && addr < mm->mmap_base) {
19421 + start_addr = addr = mm->mmap_base;
19422 + mm->cached_hole_size = 0;
19423 + goto full_search;
19424 + }
19425 + }
19426 +
19427 + /*
19428 + * Remember the place where we stopped the search:
19429 + */
19430 + mm->free_area_cache = addr + len;
19431 + return addr;
19432 +}
19433 +
19434 +unsigned long
19435 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19436 + const unsigned long len, const unsigned long pgoff,
19437 + const unsigned long flags)
19438 +{
19439 + struct vm_area_struct *vma;
19440 + struct mm_struct *mm = current->mm;
19441 + unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
19442 +
19443 +#ifdef CONFIG_PAX_SEGMEXEC
19444 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19445 + pax_task_size = SEGMEXEC_TASK_SIZE;
19446 +#endif
19447 +
19448 + pax_task_size -= PAGE_SIZE;
19449 +
19450 + /* requested length too big for entire address space */
19451 + if (len > pax_task_size)
19452 + return -ENOMEM;
19453 +
19454 + if (flags & MAP_FIXED)
19455 + return addr;
19456 +
19457 +#ifdef CONFIG_PAX_PAGEEXEC
19458 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
19459 + goto bottomup;
19460 +#endif
19461 +
19462 +#ifdef CONFIG_PAX_RANDMMAP
19463 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19464 +#endif
19465 +
19466 + /* requesting a specific address */
19467 + if (addr) {
19468 + addr = PAGE_ALIGN(addr);
19469 + if (pax_task_size - len >= addr) {
19470 + vma = find_vma(mm, addr);
19471 + if (check_heap_stack_gap(vma, addr, len))
19472 + return addr;
19473 + }
19474 + }
19475 +
19476 + /* check if free_area_cache is useful for us */
19477 + if (len <= mm->cached_hole_size) {
19478 + mm->cached_hole_size = 0;
19479 + mm->free_area_cache = mm->mmap_base;
19480 + }
19481 +
19482 + /* either no address requested or can't fit in requested address hole */
19483 + addr = mm->free_area_cache;
19484 +
19485 + /* make sure it can fit in the remaining address space */
19486 + if (addr > len) {
19487 + vma = find_vma(mm, addr-len);
19488 + if (check_heap_stack_gap(vma, addr - len, len))
19489 + /* remember the address as a hint for next time */
19490 + return (mm->free_area_cache = addr-len);
19491 + }
19492 +
19493 + if (mm->mmap_base < len)
19494 + goto bottomup;
19495 +
19496 + addr = mm->mmap_base-len;
19497 +
19498 + do {
19499 + /*
19500 + * Lookup failure means no vma is above this address,
19501 + * else if new region fits below vma->vm_start,
19502 + * return with success:
19503 + */
19504 + vma = find_vma(mm, addr);
19505 + if (check_heap_stack_gap(vma, addr, len))
19506 + /* remember the address as a hint for next time */
19507 + return (mm->free_area_cache = addr);
19508 +
19509 + /* remember the largest hole we saw so far */
19510 + if (addr + mm->cached_hole_size < vma->vm_start)
19511 + mm->cached_hole_size = vma->vm_start - addr;
19512 +
19513 + /* try just below the current vma->vm_start */
19514 + addr = skip_heap_stack_gap(vma, len);
19515 + } while (!IS_ERR_VALUE(addr));
19516 +
19517 +bottomup:
19518 + /*
19519 + * A failed mmap() very likely causes application failure,
19520 + * so fall back to the bottom-up function here. This scenario
19521 + * can happen with large stack limits and large mmap()
19522 + * allocations.
19523 + */
19524 +
19525 +#ifdef CONFIG_PAX_SEGMEXEC
19526 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19527 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
19528 + else
19529 +#endif
19530 +
19531 + mm->mmap_base = TASK_UNMAPPED_BASE;
19532 +
19533 +#ifdef CONFIG_PAX_RANDMMAP
19534 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19535 + mm->mmap_base += mm->delta_mmap;
19536 +#endif
19537 +
19538 + mm->free_area_cache = mm->mmap_base;
19539 + mm->cached_hole_size = ~0UL;
19540 + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19541 + /*
19542 + * Restore the topdown base:
19543 + */
19544 + mm->mmap_base = base;
19545 + mm->free_area_cache = base;
19546 + mm->cached_hole_size = ~0UL;
19547 +
19548 + return addr;
19549 }
19550 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
19551 index b4d3c39..82bb73b 100644
19552 --- a/arch/x86/kernel/sys_x86_64.c
19553 +++ b/arch/x86/kernel/sys_x86_64.c
19554 @@ -95,8 +95,8 @@ out:
19555 return error;
19556 }
19557
19558 -static void find_start_end(unsigned long flags, unsigned long *begin,
19559 - unsigned long *end)
19560 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
19561 + unsigned long *begin, unsigned long *end)
19562 {
19563 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
19564 unsigned long new_begin;
19565 @@ -115,7 +115,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
19566 *begin = new_begin;
19567 }
19568 } else {
19569 - *begin = TASK_UNMAPPED_BASE;
19570 + *begin = mm->mmap_base;
19571 *end = TASK_SIZE;
19572 }
19573 }
19574 @@ -132,16 +132,19 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
19575 if (flags & MAP_FIXED)
19576 return addr;
19577
19578 - find_start_end(flags, &begin, &end);
19579 + find_start_end(mm, flags, &begin, &end);
19580
19581 if (len > end)
19582 return -ENOMEM;
19583
19584 +#ifdef CONFIG_PAX_RANDMMAP
19585 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19586 +#endif
19587 +
19588 if (addr) {
19589 addr = PAGE_ALIGN(addr);
19590 vma = find_vma(mm, addr);
19591 - if (end - len >= addr &&
19592 - (!vma || addr + len <= vma->vm_start))
19593 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
19594 return addr;
19595 }
19596 if (((flags & MAP_32BIT) || test_thread_flag(TIF_ADDR32))
19597 @@ -172,7 +175,7 @@ full_search:
19598 }
19599 return -ENOMEM;
19600 }
19601 - if (!vma || addr + len <= vma->vm_start) {
19602 + if (check_heap_stack_gap(vma, addr, len)) {
19603 /*
19604 * Remember the place where we stopped the search:
19605 */
19606 @@ -195,7 +198,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19607 {
19608 struct vm_area_struct *vma;
19609 struct mm_struct *mm = current->mm;
19610 - unsigned long addr = addr0, start_addr;
19611 + unsigned long base = mm->mmap_base, addr = addr0, start_addr;
19612
19613 /* requested length too big for entire address space */
19614 if (len > TASK_SIZE)
19615 @@ -208,13 +211,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19616 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
19617 goto bottomup;
19618
19619 +#ifdef CONFIG_PAX_RANDMMAP
19620 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19621 +#endif
19622 +
19623 /* requesting a specific address */
19624 if (addr) {
19625 addr = PAGE_ALIGN(addr);
19626 - vma = find_vma(mm, addr);
19627 - if (TASK_SIZE - len >= addr &&
19628 - (!vma || addr + len <= vma->vm_start))
19629 - return addr;
19630 + if (TASK_SIZE - len >= addr) {
19631 + vma = find_vma(mm, addr);
19632 + if (check_heap_stack_gap(vma, addr, len))
19633 + return addr;
19634 + }
19635 }
19636
19637 /* check if free_area_cache is useful for us */
19638 @@ -240,7 +248,7 @@ try_again:
19639 * return with success:
19640 */
19641 vma = find_vma(mm, addr);
19642 - if (!vma || addr+len <= vma->vm_start)
19643 + if (check_heap_stack_gap(vma, addr, len))
19644 /* remember the address as a hint for next time */
19645 return mm->free_area_cache = addr;
19646
19647 @@ -249,8 +257,8 @@ try_again:
19648 mm->cached_hole_size = vma->vm_start - addr;
19649
19650 /* try just below the current vma->vm_start */
19651 - addr = vma->vm_start-len;
19652 - } while (len < vma->vm_start);
19653 + addr = skip_heap_stack_gap(vma, len);
19654 + } while (!IS_ERR_VALUE(addr));
19655
19656 fail:
19657 /*
19658 @@ -270,13 +278,21 @@ bottomup:
19659 * can happen with large stack limits and large mmap()
19660 * allocations.
19661 */
19662 + mm->mmap_base = TASK_UNMAPPED_BASE;
19663 +
19664 +#ifdef CONFIG_PAX_RANDMMAP
19665 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19666 + mm->mmap_base += mm->delta_mmap;
19667 +#endif
19668 +
19669 + mm->free_area_cache = mm->mmap_base;
19670 mm->cached_hole_size = ~0UL;
19671 - mm->free_area_cache = TASK_UNMAPPED_BASE;
19672 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19673 /*
19674 * Restore the topdown base:
19675 */
19676 - mm->free_area_cache = mm->mmap_base;
19677 + mm->mmap_base = base;
19678 + mm->free_area_cache = base;
19679 mm->cached_hole_size = ~0UL;
19680
19681 return addr;
19682 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
19683 index f84fe00..93fe08f 100644
19684 --- a/arch/x86/kernel/tboot.c
19685 +++ b/arch/x86/kernel/tboot.c
19686 @@ -220,7 +220,7 @@ static int tboot_setup_sleep(void)
19687
19688 void tboot_shutdown(u32 shutdown_type)
19689 {
19690 - void (*shutdown)(void);
19691 + void (* __noreturn shutdown)(void);
19692
19693 if (!tboot_enabled())
19694 return;
19695 @@ -242,7 +242,7 @@ void tboot_shutdown(u32 shutdown_type)
19696
19697 switch_to_tboot_pt();
19698
19699 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
19700 + shutdown = (void *)tboot->shutdown_entry;
19701 shutdown();
19702
19703 /* should not reach here */
19704 @@ -300,7 +300,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
19705 return 0;
19706 }
19707
19708 -static atomic_t ap_wfs_count;
19709 +static atomic_unchecked_t ap_wfs_count;
19710
19711 static int tboot_wait_for_aps(int num_aps)
19712 {
19713 @@ -324,9 +324,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
19714 {
19715 switch (action) {
19716 case CPU_DYING:
19717 - atomic_inc(&ap_wfs_count);
19718 + atomic_inc_unchecked(&ap_wfs_count);
19719 if (num_online_cpus() == 1)
19720 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
19721 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
19722 return NOTIFY_BAD;
19723 break;
19724 }
19725 @@ -345,7 +345,7 @@ static __init int tboot_late_init(void)
19726
19727 tboot_create_trampoline();
19728
19729 - atomic_set(&ap_wfs_count, 0);
19730 + atomic_set_unchecked(&ap_wfs_count, 0);
19731 register_hotcpu_notifier(&tboot_cpu_notifier);
19732
19733 acpi_os_set_prepare_sleep(&tboot_sleep);
19734 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
19735 index 24d3c91..d06b473 100644
19736 --- a/arch/x86/kernel/time.c
19737 +++ b/arch/x86/kernel/time.c
19738 @@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
19739 {
19740 unsigned long pc = instruction_pointer(regs);
19741
19742 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
19743 + if (!user_mode(regs) && in_lock_functions(pc)) {
19744 #ifdef CONFIG_FRAME_POINTER
19745 - return *(unsigned long *)(regs->bp + sizeof(long));
19746 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
19747 #else
19748 unsigned long *sp =
19749 (unsigned long *)kernel_stack_pointer(regs);
19750 @@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
19751 * or above a saved flags. Eflags has bits 22-31 zero,
19752 * kernel addresses don't.
19753 */
19754 +
19755 +#ifdef CONFIG_PAX_KERNEXEC
19756 + return ktla_ktva(sp[0]);
19757 +#else
19758 if (sp[0] >> 22)
19759 return sp[0];
19760 if (sp[1] >> 22)
19761 return sp[1];
19762 #endif
19763 +
19764 +#endif
19765 }
19766 return pc;
19767 }
19768 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
19769 index 9d9d2f9..cad418a 100644
19770 --- a/arch/x86/kernel/tls.c
19771 +++ b/arch/x86/kernel/tls.c
19772 @@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
19773 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
19774 return -EINVAL;
19775
19776 +#ifdef CONFIG_PAX_SEGMEXEC
19777 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
19778 + return -EINVAL;
19779 +#endif
19780 +
19781 set_tls_desc(p, idx, &info, 1);
19782
19783 return 0;
19784 @@ -204,7 +209,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
19785
19786 if (kbuf)
19787 info = kbuf;
19788 - else if (__copy_from_user(infobuf, ubuf, count))
19789 + else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
19790 return -EFAULT;
19791 else
19792 info = infobuf;
19793 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
19794 index b481341..5918bbe 100644
19795 --- a/arch/x86/kernel/traps.c
19796 +++ b/arch/x86/kernel/traps.c
19797 @@ -70,12 +70,6 @@ asmlinkage int system_call(void);
19798
19799 /* Do we ignore FPU interrupts ? */
19800 char ignore_fpu_irq;
19801 -
19802 -/*
19803 - * The IDT has to be page-aligned to simplify the Pentium
19804 - * F0 0F bug workaround.
19805 - */
19806 -gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
19807 #endif
19808
19809 DECLARE_BITMAP(used_vectors, NR_VECTORS);
19810 @@ -108,13 +102,13 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
19811 }
19812
19813 static void __kprobes
19814 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19815 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
19816 long error_code, siginfo_t *info)
19817 {
19818 struct task_struct *tsk = current;
19819
19820 #ifdef CONFIG_X86_32
19821 - if (regs->flags & X86_VM_MASK) {
19822 + if (v8086_mode(regs)) {
19823 /*
19824 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
19825 * On nmi (interrupt 2), do_trap should not be called.
19826 @@ -125,7 +119,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19827 }
19828 #endif
19829
19830 - if (!user_mode(regs))
19831 + if (!user_mode_novm(regs))
19832 goto kernel_trap;
19833
19834 #ifdef CONFIG_X86_32
19835 @@ -147,7 +141,7 @@ trap_signal:
19836 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
19837 printk_ratelimit()) {
19838 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
19839 - tsk->comm, tsk->pid, str,
19840 + tsk->comm, task_pid_nr(tsk), str,
19841 regs->ip, regs->sp, error_code);
19842 print_vma_addr(" in ", regs->ip);
19843 pr_cont("\n");
19844 @@ -164,8 +158,20 @@ kernel_trap:
19845 if (!fixup_exception(regs)) {
19846 tsk->thread.error_code = error_code;
19847 tsk->thread.trap_nr = trapnr;
19848 +
19849 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19850 + if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
19851 + str = "PAX: suspicious stack segment fault";
19852 +#endif
19853 +
19854 die(str, regs, error_code);
19855 }
19856 +
19857 +#ifdef CONFIG_PAX_REFCOUNT
19858 + if (trapnr == 4)
19859 + pax_report_refcount_overflow(regs);
19860 +#endif
19861 +
19862 return;
19863
19864 #ifdef CONFIG_X86_32
19865 @@ -258,14 +264,30 @@ do_general_protection(struct pt_regs *regs, long error_code)
19866 conditional_sti(regs);
19867
19868 #ifdef CONFIG_X86_32
19869 - if (regs->flags & X86_VM_MASK)
19870 + if (v8086_mode(regs))
19871 goto gp_in_vm86;
19872 #endif
19873
19874 tsk = current;
19875 - if (!user_mode(regs))
19876 + if (!user_mode_novm(regs))
19877 goto gp_in_kernel;
19878
19879 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
19880 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
19881 + struct mm_struct *mm = tsk->mm;
19882 + unsigned long limit;
19883 +
19884 + down_write(&mm->mmap_sem);
19885 + limit = mm->context.user_cs_limit;
19886 + if (limit < TASK_SIZE) {
19887 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
19888 + up_write(&mm->mmap_sem);
19889 + return;
19890 + }
19891 + up_write(&mm->mmap_sem);
19892 + }
19893 +#endif
19894 +
19895 tsk->thread.error_code = error_code;
19896 tsk->thread.trap_nr = X86_TRAP_GP;
19897
19898 @@ -297,6 +319,13 @@ gp_in_kernel:
19899 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
19900 X86_TRAP_GP, SIGSEGV) == NOTIFY_STOP)
19901 return;
19902 +
19903 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19904 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
19905 + die("PAX: suspicious general protection fault", regs, error_code);
19906 + else
19907 +#endif
19908 +
19909 die("general protection fault", regs, error_code);
19910 }
19911
19912 @@ -432,7 +461,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19913 /* It's safe to allow irq's after DR6 has been saved */
19914 preempt_conditional_sti(regs);
19915
19916 - if (regs->flags & X86_VM_MASK) {
19917 + if (v8086_mode(regs)) {
19918 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
19919 X86_TRAP_DB);
19920 preempt_conditional_cli(regs);
19921 @@ -447,7 +476,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19922 * We already checked v86 mode above, so we can check for kernel mode
19923 * by just checking the CPL of CS.
19924 */
19925 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
19926 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
19927 tsk->thread.debugreg6 &= ~DR_STEP;
19928 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
19929 regs->flags &= ~X86_EFLAGS_TF;
19930 @@ -478,7 +507,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
19931 return;
19932 conditional_sti(regs);
19933
19934 - if (!user_mode_vm(regs))
19935 + if (!user_mode(regs))
19936 {
19937 if (!fixup_exception(regs)) {
19938 task->thread.error_code = error_code;
19939 diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
19940 index 36fd420..7e5892d 100644
19941 --- a/arch/x86/kernel/uprobes.c
19942 +++ b/arch/x86/kernel/uprobes.c
19943 @@ -607,7 +607,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
19944 int ret = NOTIFY_DONE;
19945
19946 /* We are only interested in userspace traps */
19947 - if (regs && !user_mode_vm(regs))
19948 + if (regs && !user_mode(regs))
19949 return NOTIFY_DONE;
19950
19951 switch (val) {
19952 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
19953 index b9242ba..50c5edd 100644
19954 --- a/arch/x86/kernel/verify_cpu.S
19955 +++ b/arch/x86/kernel/verify_cpu.S
19956 @@ -20,6 +20,7 @@
19957 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
19958 * arch/x86/kernel/trampoline_64.S: secondary processor verification
19959 * arch/x86/kernel/head_32.S: processor startup
19960 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
19961 *
19962 * verify_cpu, returns the status of longmode and SSE in register %eax.
19963 * 0: Success 1: Failure
19964 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
19965 index 54abcc0..eb6c848 100644
19966 --- a/arch/x86/kernel/vm86_32.c
19967 +++ b/arch/x86/kernel/vm86_32.c
19968 @@ -43,6 +43,7 @@
19969 #include <linux/ptrace.h>
19970 #include <linux/audit.h>
19971 #include <linux/stddef.h>
19972 +#include <linux/grsecurity.h>
19973
19974 #include <asm/uaccess.h>
19975 #include <asm/io.h>
19976 @@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
19977 do_exit(SIGSEGV);
19978 }
19979
19980 - tss = &per_cpu(init_tss, get_cpu());
19981 + tss = init_tss + get_cpu();
19982 current->thread.sp0 = current->thread.saved_sp0;
19983 current->thread.sysenter_cs = __KERNEL_CS;
19984 load_sp0(tss, &current->thread);
19985 @@ -212,6 +213,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
19986 struct task_struct *tsk;
19987 int tmp, ret = -EPERM;
19988
19989 +#ifdef CONFIG_GRKERNSEC_VM86
19990 + if (!capable(CAP_SYS_RAWIO)) {
19991 + gr_handle_vm86();
19992 + goto out;
19993 + }
19994 +#endif
19995 +
19996 tsk = current;
19997 if (tsk->thread.saved_sp0)
19998 goto out;
19999 @@ -242,6 +250,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
20000 int tmp, ret;
20001 struct vm86plus_struct __user *v86;
20002
20003 +#ifdef CONFIG_GRKERNSEC_VM86
20004 + if (!capable(CAP_SYS_RAWIO)) {
20005 + gr_handle_vm86();
20006 + ret = -EPERM;
20007 + goto out;
20008 + }
20009 +#endif
20010 +
20011 tsk = current;
20012 switch (cmd) {
20013 case VM86_REQUEST_IRQ:
20014 @@ -328,7 +344,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
20015 tsk->thread.saved_fs = info->regs32->fs;
20016 tsk->thread.saved_gs = get_user_gs(info->regs32);
20017
20018 - tss = &per_cpu(init_tss, get_cpu());
20019 + tss = init_tss + get_cpu();
20020 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
20021 if (cpu_has_sep)
20022 tsk->thread.sysenter_cs = 0;
20023 @@ -535,7 +551,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
20024 goto cannot_handle;
20025 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
20026 goto cannot_handle;
20027 - intr_ptr = (unsigned long __user *) (i << 2);
20028 + intr_ptr = (__force unsigned long __user *) (i << 2);
20029 if (get_user(segoffs, intr_ptr))
20030 goto cannot_handle;
20031 if ((segoffs >> 16) == BIOSSEG)
20032 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
20033 index 22a1530..8fbaaad 100644
20034 --- a/arch/x86/kernel/vmlinux.lds.S
20035 +++ b/arch/x86/kernel/vmlinux.lds.S
20036 @@ -26,6 +26,13 @@
20037 #include <asm/page_types.h>
20038 #include <asm/cache.h>
20039 #include <asm/boot.h>
20040 +#include <asm/segment.h>
20041 +
20042 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20043 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
20044 +#else
20045 +#define __KERNEL_TEXT_OFFSET 0
20046 +#endif
20047
20048 #undef i386 /* in case the preprocessor is a 32bit one */
20049
20050 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
20051
20052 PHDRS {
20053 text PT_LOAD FLAGS(5); /* R_E */
20054 +#ifdef CONFIG_X86_32
20055 + module PT_LOAD FLAGS(5); /* R_E */
20056 +#endif
20057 +#ifdef CONFIG_XEN
20058 + rodata PT_LOAD FLAGS(5); /* R_E */
20059 +#else
20060 + rodata PT_LOAD FLAGS(4); /* R__ */
20061 +#endif
20062 data PT_LOAD FLAGS(6); /* RW_ */
20063 -#ifdef CONFIG_X86_64
20064 + init.begin PT_LOAD FLAGS(6); /* RW_ */
20065 #ifdef CONFIG_SMP
20066 percpu PT_LOAD FLAGS(6); /* RW_ */
20067 #endif
20068 + text.init PT_LOAD FLAGS(5); /* R_E */
20069 + text.exit PT_LOAD FLAGS(5); /* R_E */
20070 init PT_LOAD FLAGS(7); /* RWE */
20071 -#endif
20072 note PT_NOTE FLAGS(0); /* ___ */
20073 }
20074
20075 SECTIONS
20076 {
20077 #ifdef CONFIG_X86_32
20078 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
20079 - phys_startup_32 = startup_32 - LOAD_OFFSET;
20080 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
20081 #else
20082 - . = __START_KERNEL;
20083 - phys_startup_64 = startup_64 - LOAD_OFFSET;
20084 + . = __START_KERNEL;
20085 #endif
20086
20087 /* Text and read-only data */
20088 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
20089 - _text = .;
20090 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20091 /* bootstrapping code */
20092 +#ifdef CONFIG_X86_32
20093 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20094 +#else
20095 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20096 +#endif
20097 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20098 + _text = .;
20099 HEAD_TEXT
20100 #ifdef CONFIG_X86_32
20101 . = ALIGN(PAGE_SIZE);
20102 @@ -108,13 +128,48 @@ SECTIONS
20103 IRQENTRY_TEXT
20104 *(.fixup)
20105 *(.gnu.warning)
20106 - /* End of text section */
20107 - _etext = .;
20108 } :text = 0x9090
20109
20110 - NOTES :text :note
20111 + . += __KERNEL_TEXT_OFFSET;
20112
20113 - EXCEPTION_TABLE(16) :text = 0x9090
20114 +#ifdef CONFIG_X86_32
20115 + . = ALIGN(PAGE_SIZE);
20116 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
20117 +
20118 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
20119 + MODULES_EXEC_VADDR = .;
20120 + BYTE(0)
20121 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
20122 + . = ALIGN(HPAGE_SIZE) - 1;
20123 + MODULES_EXEC_END = .;
20124 +#endif
20125 +
20126 + } :module
20127 +#endif
20128 +
20129 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
20130 + /* End of text section */
20131 + BYTE(0)
20132 + _etext = . - __KERNEL_TEXT_OFFSET;
20133 + }
20134 +
20135 +#ifdef CONFIG_X86_32
20136 + . = ALIGN(PAGE_SIZE);
20137 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
20138 + *(.idt)
20139 + . = ALIGN(PAGE_SIZE);
20140 + *(.empty_zero_page)
20141 + *(.initial_pg_fixmap)
20142 + *(.initial_pg_pmd)
20143 + *(.initial_page_table)
20144 + *(.swapper_pg_dir)
20145 + } :rodata
20146 +#endif
20147 +
20148 + . = ALIGN(PAGE_SIZE);
20149 + NOTES :rodata :note
20150 +
20151 + EXCEPTION_TABLE(16) :rodata
20152
20153 #if defined(CONFIG_DEBUG_RODATA)
20154 /* .text should occupy whole number of pages */
20155 @@ -126,16 +181,20 @@ SECTIONS
20156
20157 /* Data */
20158 .data : AT(ADDR(.data) - LOAD_OFFSET) {
20159 +
20160 +#ifdef CONFIG_PAX_KERNEXEC
20161 + . = ALIGN(HPAGE_SIZE);
20162 +#else
20163 + . = ALIGN(PAGE_SIZE);
20164 +#endif
20165 +
20166 /* Start of data section */
20167 _sdata = .;
20168
20169 /* init_task */
20170 INIT_TASK_DATA(THREAD_SIZE)
20171
20172 -#ifdef CONFIG_X86_32
20173 - /* 32 bit has nosave before _edata */
20174 NOSAVE_DATA
20175 -#endif
20176
20177 PAGE_ALIGNED_DATA(PAGE_SIZE)
20178
20179 @@ -176,12 +235,19 @@ SECTIONS
20180 #endif /* CONFIG_X86_64 */
20181
20182 /* Init code and data - will be freed after init */
20183 - . = ALIGN(PAGE_SIZE);
20184 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
20185 + BYTE(0)
20186 +
20187 +#ifdef CONFIG_PAX_KERNEXEC
20188 + . = ALIGN(HPAGE_SIZE);
20189 +#else
20190 + . = ALIGN(PAGE_SIZE);
20191 +#endif
20192 +
20193 __init_begin = .; /* paired with __init_end */
20194 - }
20195 + } :init.begin
20196
20197 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
20198 +#ifdef CONFIG_SMP
20199 /*
20200 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
20201 * output PHDR, so the next output section - .init.text - should
20202 @@ -190,12 +256,27 @@ SECTIONS
20203 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
20204 #endif
20205
20206 - INIT_TEXT_SECTION(PAGE_SIZE)
20207 -#ifdef CONFIG_X86_64
20208 - :init
20209 -#endif
20210 + . = ALIGN(PAGE_SIZE);
20211 + init_begin = .;
20212 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
20213 + VMLINUX_SYMBOL(_sinittext) = .;
20214 + INIT_TEXT
20215 + VMLINUX_SYMBOL(_einittext) = .;
20216 + . = ALIGN(PAGE_SIZE);
20217 + } :text.init
20218
20219 - INIT_DATA_SECTION(16)
20220 + /*
20221 + * .exit.text is discard at runtime, not link time, to deal with
20222 + * references from .altinstructions and .eh_frame
20223 + */
20224 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20225 + EXIT_TEXT
20226 + . = ALIGN(16);
20227 + } :text.exit
20228 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
20229 +
20230 + . = ALIGN(PAGE_SIZE);
20231 + INIT_DATA_SECTION(16) :init
20232
20233 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
20234 __x86_cpu_dev_start = .;
20235 @@ -257,19 +338,12 @@ SECTIONS
20236 }
20237
20238 . = ALIGN(8);
20239 - /*
20240 - * .exit.text is discard at runtime, not link time, to deal with
20241 - * references from .altinstructions and .eh_frame
20242 - */
20243 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
20244 - EXIT_TEXT
20245 - }
20246
20247 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
20248 EXIT_DATA
20249 }
20250
20251 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
20252 +#ifndef CONFIG_SMP
20253 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
20254 #endif
20255
20256 @@ -288,16 +362,10 @@ SECTIONS
20257 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
20258 __smp_locks = .;
20259 *(.smp_locks)
20260 - . = ALIGN(PAGE_SIZE);
20261 __smp_locks_end = .;
20262 + . = ALIGN(PAGE_SIZE);
20263 }
20264
20265 -#ifdef CONFIG_X86_64
20266 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
20267 - NOSAVE_DATA
20268 - }
20269 -#endif
20270 -
20271 /* BSS */
20272 . = ALIGN(PAGE_SIZE);
20273 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
20274 @@ -313,6 +381,7 @@ SECTIONS
20275 __brk_base = .;
20276 . += 64 * 1024; /* 64k alignment slop space */
20277 *(.brk_reservation) /* areas brk users have reserved */
20278 + . = ALIGN(HPAGE_SIZE);
20279 __brk_limit = .;
20280 }
20281
20282 @@ -339,13 +408,12 @@ SECTIONS
20283 * for the boot processor.
20284 */
20285 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
20286 -INIT_PER_CPU(gdt_page);
20287 INIT_PER_CPU(irq_stack_union);
20288
20289 /*
20290 * Build-time check on the image size:
20291 */
20292 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
20293 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
20294 "kernel image bigger than KERNEL_IMAGE_SIZE");
20295
20296 #ifdef CONFIG_SMP
20297 diff --git a/arch/x86/kernel/vsmp_64.c b/arch/x86/kernel/vsmp_64.c
20298 index 992f890..fc38904 100644
20299 --- a/arch/x86/kernel/vsmp_64.c
20300 +++ b/arch/x86/kernel/vsmp_64.c
20301 @@ -217,8 +217,8 @@ static void fill_vector_allocation_domain(int cpu, struct cpumask *retmask,
20302 static void vsmp_apic_post_init(void)
20303 {
20304 /* need to update phys_pkg_id */
20305 - apic->phys_pkg_id = apicid_phys_pkg_id;
20306 - apic->vector_allocation_domain = fill_vector_allocation_domain;
20307 + *(void **)&apic->phys_pkg_id = apicid_phys_pkg_id;
20308 + *(void **)&apic->vector_allocation_domain = fill_vector_allocation_domain;
20309 }
20310
20311 void __init vsmp_init(void)
20312 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
20313 index 8d141b3..40a0fe4 100644
20314 --- a/arch/x86/kernel/vsyscall_64.c
20315 +++ b/arch/x86/kernel/vsyscall_64.c
20316 @@ -56,15 +56,13 @@
20317 DEFINE_VVAR(int, vgetcpu_mode);
20318 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
20319
20320 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
20321 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
20322
20323 static int __init vsyscall_setup(char *str)
20324 {
20325 if (str) {
20326 if (!strcmp("emulate", str))
20327 vsyscall_mode = EMULATE;
20328 - else if (!strcmp("native", str))
20329 - vsyscall_mode = NATIVE;
20330 else if (!strcmp("none", str))
20331 vsyscall_mode = NONE;
20332 else
20333 @@ -306,8 +304,7 @@ done:
20334 return true;
20335
20336 sigsegv:
20337 - force_sig(SIGSEGV, current);
20338 - return true;
20339 + do_group_exit(SIGKILL);
20340 }
20341
20342 /*
20343 @@ -360,10 +357,7 @@ void __init map_vsyscall(void)
20344 extern char __vvar_page;
20345 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
20346
20347 - __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
20348 - vsyscall_mode == NATIVE
20349 - ? PAGE_KERNEL_VSYSCALL
20350 - : PAGE_KERNEL_VVAR);
20351 + __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
20352 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
20353 (unsigned long)VSYSCALL_START);
20354
20355 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
20356 index 6020f6f..bedd6e3 100644
20357 --- a/arch/x86/kernel/x8664_ksyms_64.c
20358 +++ b/arch/x86/kernel/x8664_ksyms_64.c
20359 @@ -30,8 +30,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
20360 EXPORT_SYMBOL(copy_user_generic_unrolled);
20361 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
20362 EXPORT_SYMBOL(__copy_user_nocache);
20363 -EXPORT_SYMBOL(_copy_from_user);
20364 -EXPORT_SYMBOL(_copy_to_user);
20365
20366 EXPORT_SYMBOL(copy_page);
20367 EXPORT_SYMBOL(clear_page);
20368 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
20369 index 3d3e207..1a73ab2 100644
20370 --- a/arch/x86/kernel/xsave.c
20371 +++ b/arch/x86/kernel/xsave.c
20372 @@ -132,7 +132,7 @@ int check_for_xstate(struct i387_fxsave_struct __user *buf,
20373 fx_sw_user->xstate_size > fx_sw_user->extended_size)
20374 return -EINVAL;
20375
20376 - err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
20377 + err = __get_user(magic2, (__u32 __user *) (((void __user *)fpstate) +
20378 fx_sw_user->extended_size -
20379 FP_XSTATE_MAGIC2_SIZE));
20380 if (err)
20381 @@ -268,7 +268,7 @@ fx_only:
20382 * the other extended state.
20383 */
20384 xrstor_state(init_xstate_buf, pcntxt_mask & ~XSTATE_FPSSE);
20385 - return fxrstor_checking((__force struct i387_fxsave_struct *)buf);
20386 + return fxrstor_checking((struct i387_fxsave_struct __force_kernel *)buf);
20387 }
20388
20389 /*
20390 @@ -297,7 +297,7 @@ int restore_i387_xstate(void __user *buf)
20391 if (use_xsave())
20392 err = restore_user_xstate(buf);
20393 else
20394 - err = fxrstor_checking((__force struct i387_fxsave_struct *)
20395 + err = fxrstor_checking((struct i387_fxsave_struct __force_kernel *)
20396 buf);
20397 if (unlikely(err)) {
20398 /*
20399 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
20400 index 0595f13..b544fa3 100644
20401 --- a/arch/x86/kvm/cpuid.c
20402 +++ b/arch/x86/kvm/cpuid.c
20403 @@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
20404 struct kvm_cpuid2 *cpuid,
20405 struct kvm_cpuid_entry2 __user *entries)
20406 {
20407 - int r;
20408 + int r, i;
20409
20410 r = -E2BIG;
20411 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
20412 goto out;
20413 r = -EFAULT;
20414 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
20415 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20416 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20417 goto out;
20418 + for (i = 0; i < cpuid->nent; ++i) {
20419 + struct kvm_cpuid_entry2 cpuid_entry;
20420 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
20421 + goto out;
20422 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
20423 + }
20424 vcpu->arch.cpuid_nent = cpuid->nent;
20425 kvm_apic_set_version(vcpu);
20426 kvm_x86_ops->cpuid_update(vcpu);
20427 @@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
20428 struct kvm_cpuid2 *cpuid,
20429 struct kvm_cpuid_entry2 __user *entries)
20430 {
20431 - int r;
20432 + int r, i;
20433
20434 r = -E2BIG;
20435 if (cpuid->nent < vcpu->arch.cpuid_nent)
20436 goto out;
20437 r = -EFAULT;
20438 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
20439 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20440 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20441 goto out;
20442 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
20443 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
20444 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
20445 + goto out;
20446 + }
20447 return 0;
20448
20449 out:
20450 diff --git a/arch/x86/kvm/cpuid.h b/arch/x86/kvm/cpuid.h
20451 index a10e460..58fc514 100644
20452 --- a/arch/x86/kvm/cpuid.h
20453 +++ b/arch/x86/kvm/cpuid.h
20454 @@ -24,6 +24,9 @@ static inline bool guest_cpuid_has_xsave(struct kvm_vcpu *vcpu)
20455 {
20456 struct kvm_cpuid_entry2 *best;
20457
20458 + if (!static_cpu_has(X86_FEATURE_XSAVE))
20459 + return 0;
20460 +
20461 best = kvm_find_cpuid_entry(vcpu, 1, 0);
20462 return best && (best->ecx & bit(X86_FEATURE_XSAVE));
20463 }
20464 diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
20465 index a3b57a2..ebbe732 100644
20466 --- a/arch/x86/kvm/emulate.c
20467 +++ b/arch/x86/kvm/emulate.c
20468 @@ -256,6 +256,7 @@ struct gprefix {
20469
20470 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
20471 do { \
20472 + unsigned long _tmp; \
20473 __asm__ __volatile__ ( \
20474 _PRE_EFLAGS("0", "4", "2") \
20475 _op _suffix " %"_x"3,%1; " \
20476 @@ -270,8 +271,6 @@ struct gprefix {
20477 /* Raw emulation: instruction has two explicit operands. */
20478 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
20479 do { \
20480 - unsigned long _tmp; \
20481 - \
20482 switch ((ctxt)->dst.bytes) { \
20483 case 2: \
20484 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
20485 @@ -287,7 +286,6 @@ struct gprefix {
20486
20487 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
20488 do { \
20489 - unsigned long _tmp; \
20490 switch ((ctxt)->dst.bytes) { \
20491 case 1: \
20492 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
20493 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
20494 index ce87878..ab48aa3 100644
20495 --- a/arch/x86/kvm/lapic.c
20496 +++ b/arch/x86/kvm/lapic.c
20497 @@ -54,7 +54,7 @@
20498 #define APIC_BUS_CYCLE_NS 1
20499
20500 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
20501 -#define apic_debug(fmt, arg...)
20502 +#define apic_debug(fmt, arg...) do {} while (0)
20503
20504 #define APIC_LVT_NUM 6
20505 /* 14 is the version for Xeon and Pentium 8.4.8*/
20506 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
20507 index bb7cf01..0348a05 100644
20508 --- a/arch/x86/kvm/paging_tmpl.h
20509 +++ b/arch/x86/kvm/paging_tmpl.h
20510 @@ -196,7 +196,7 @@ retry_walk:
20511 if (unlikely(kvm_is_error_hva(host_addr)))
20512 goto error;
20513
20514 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
20515 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
20516 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
20517 goto error;
20518
20519 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
20520 index baead95..90feeb4 100644
20521 --- a/arch/x86/kvm/svm.c
20522 +++ b/arch/x86/kvm/svm.c
20523 @@ -3516,7 +3516,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
20524 int cpu = raw_smp_processor_id();
20525
20526 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
20527 +
20528 + pax_open_kernel();
20529 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
20530 + pax_close_kernel();
20531 +
20532 load_TR_desc();
20533 }
20534
20535 @@ -3894,6 +3898,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
20536 #endif
20537 #endif
20538
20539 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20540 + __set_fs(current_thread_info()->addr_limit);
20541 +#endif
20542 +
20543 reload_tss(vcpu);
20544
20545 local_irq_disable();
20546 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
20547 index b1eb202..254e292 100644
20548 --- a/arch/x86/kvm/vmx.c
20549 +++ b/arch/x86/kvm/vmx.c
20550 @@ -1331,7 +1331,11 @@ static void reload_tss(void)
20551 struct desc_struct *descs;
20552
20553 descs = (void *)gdt->address;
20554 +
20555 + pax_open_kernel();
20556 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
20557 + pax_close_kernel();
20558 +
20559 load_TR_desc();
20560 }
20561
20562 @@ -1541,6 +1545,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
20563 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
20564 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
20565
20566 +#ifdef CONFIG_PAX_PER_CPU_PGD
20567 + vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
20568 +#endif
20569 +
20570 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
20571 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
20572 vmx->loaded_vmcs->cpu = cpu;
20573 @@ -2674,8 +2682,11 @@ static __init int hardware_setup(void)
20574 if (!cpu_has_vmx_flexpriority())
20575 flexpriority_enabled = 0;
20576
20577 - if (!cpu_has_vmx_tpr_shadow())
20578 - kvm_x86_ops->update_cr8_intercept = NULL;
20579 + if (!cpu_has_vmx_tpr_shadow()) {
20580 + pax_open_kernel();
20581 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
20582 + pax_close_kernel();
20583 + }
20584
20585 if (enable_ept && !cpu_has_vmx_ept_2m_page())
20586 kvm_disable_largepages();
20587 @@ -3745,7 +3756,10 @@ static void vmx_set_constant_host_state(void)
20588
20589 vmcs_writel(HOST_CR0, read_cr0() | X86_CR0_TS); /* 22.2.3 */
20590 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
20591 +
20592 +#ifndef CONFIG_PAX_PER_CPU_PGD
20593 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
20594 +#endif
20595
20596 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
20597 #ifdef CONFIG_X86_64
20598 @@ -3767,7 +3781,7 @@ static void vmx_set_constant_host_state(void)
20599 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
20600
20601 asm("mov $.Lkvm_vmx_return, %0" : "=r"(tmpl));
20602 - vmcs_writel(HOST_RIP, tmpl); /* 22.2.5 */
20603 + vmcs_writel(HOST_RIP, ktla_ktva(tmpl)); /* 22.2.5 */
20604
20605 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
20606 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
20607 @@ -6321,6 +6335,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20608 "jmp .Lkvm_vmx_return \n\t"
20609 ".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
20610 ".Lkvm_vmx_return: "
20611 +
20612 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20613 + "ljmp %[cs],$.Lkvm_vmx_return2\n\t"
20614 + ".Lkvm_vmx_return2: "
20615 +#endif
20616 +
20617 /* Save guest registers, load host registers, keep flags */
20618 "mov %0, %c[wordsize](%%"R"sp) \n\t"
20619 "pop %0 \n\t"
20620 @@ -6369,6 +6389,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20621 #endif
20622 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
20623 [wordsize]"i"(sizeof(ulong))
20624 +
20625 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20626 + ,[cs]"i"(__KERNEL_CS)
20627 +#endif
20628 +
20629 : "cc", "memory"
20630 , R"ax", R"bx", R"di", R"si"
20631 #ifdef CONFIG_X86_64
20632 @@ -6376,7 +6401,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20633 #endif
20634 );
20635
20636 -#ifndef CONFIG_X86_64
20637 +#ifdef CONFIG_X86_32
20638 /*
20639 * The sysexit path does not restore ds/es, so we must set them to
20640 * a reasonable value ourselves.
20641 @@ -6385,8 +6410,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20642 * may be executed in interrupt context, which saves and restore segments
20643 * around it, nullifying its effect.
20644 */
20645 - loadsegment(ds, __USER_DS);
20646 - loadsegment(es, __USER_DS);
20647 + loadsegment(ds, __KERNEL_DS);
20648 + loadsegment(es, __KERNEL_DS);
20649 + loadsegment(ss, __KERNEL_DS);
20650 +
20651 +#ifdef CONFIG_PAX_KERNEXEC
20652 + loadsegment(fs, __KERNEL_PERCPU);
20653 +#endif
20654 +
20655 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20656 + __set_fs(current_thread_info()->addr_limit);
20657 +#endif
20658 +
20659 #endif
20660
20661 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
20662 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
20663 index 2966c84..9ac0c3c 100644
20664 --- a/arch/x86/kvm/x86.c
20665 +++ b/arch/x86/kvm/x86.c
20666 @@ -1379,8 +1379,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
20667 {
20668 struct kvm *kvm = vcpu->kvm;
20669 int lm = is_long_mode(vcpu);
20670 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20671 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20672 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20673 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20674 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
20675 : kvm->arch.xen_hvm_config.blob_size_32;
20676 u32 page_num = data & ~PAGE_MASK;
20677 @@ -2243,6 +2243,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
20678 if (n < msr_list.nmsrs)
20679 goto out;
20680 r = -EFAULT;
20681 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
20682 + goto out;
20683 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
20684 num_msrs_to_save * sizeof(u32)))
20685 goto out;
20686 @@ -2368,7 +2370,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
20687 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
20688 struct kvm_interrupt *irq)
20689 {
20690 - if (irq->irq < 0 || irq->irq >= 256)
20691 + if (irq->irq >= 256)
20692 return -EINVAL;
20693 if (irqchip_in_kernel(vcpu->kvm))
20694 return -ENXIO;
20695 @@ -4889,7 +4891,7 @@ static void kvm_set_mmio_spte_mask(void)
20696 kvm_mmu_set_mmio_spte_mask(mask);
20697 }
20698
20699 -int kvm_arch_init(void *opaque)
20700 +int kvm_arch_init(const void *opaque)
20701 {
20702 int r;
20703 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
20704 @@ -5762,6 +5764,9 @@ int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
20705 int pending_vec, max_bits, idx;
20706 struct desc_ptr dt;
20707
20708 + if (!guest_cpuid_has_xsave(vcpu) && (sregs->cr4 & X86_CR4_OSXSAVE))
20709 + return -EINVAL;
20710 +
20711 dt.size = sregs->idt.limit;
20712 dt.address = sregs->idt.base;
20713 kvm_x86_ops->set_idt(vcpu, &dt);
20714 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
20715 index 642d880..cc9ebac 100644
20716 --- a/arch/x86/lguest/boot.c
20717 +++ b/arch/x86/lguest/boot.c
20718 @@ -1116,12 +1116,12 @@ static u32 lguest_apic_safe_wait_icr_idle(void)
20719
20720 static void set_lguest_basic_apic_ops(void)
20721 {
20722 - apic->read = lguest_apic_read;
20723 - apic->write = lguest_apic_write;
20724 - apic->icr_read = lguest_apic_icr_read;
20725 - apic->icr_write = lguest_apic_icr_write;
20726 - apic->wait_icr_idle = lguest_apic_wait_icr_idle;
20727 - apic->safe_wait_icr_idle = lguest_apic_safe_wait_icr_idle;
20728 + *(void **)&apic->read = lguest_apic_read;
20729 + *(void **)&apic->write = lguest_apic_write;
20730 + *(void **)&apic->icr_read = lguest_apic_icr_read;
20731 + *(void **)&apic->icr_write = lguest_apic_icr_write;
20732 + *(void **)&apic->wait_icr_idle = lguest_apic_wait_icr_idle;
20733 + *(void **)&apic->safe_wait_icr_idle = lguest_apic_safe_wait_icr_idle;
20734 };
20735 #endif
20736
20737 @@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
20738 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
20739 * Launcher to reboot us.
20740 */
20741 -static void lguest_restart(char *reason)
20742 +static __noreturn void lguest_restart(char *reason)
20743 {
20744 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
20745 + BUG();
20746 }
20747
20748 /*G:050
20749 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
20750 index 00933d5..3a64af9 100644
20751 --- a/arch/x86/lib/atomic64_386_32.S
20752 +++ b/arch/x86/lib/atomic64_386_32.S
20753 @@ -48,6 +48,10 @@ BEGIN(read)
20754 movl (v), %eax
20755 movl 4(v), %edx
20756 RET_ENDP
20757 +BEGIN(read_unchecked)
20758 + movl (v), %eax
20759 + movl 4(v), %edx
20760 +RET_ENDP
20761 #undef v
20762
20763 #define v %esi
20764 @@ -55,6 +59,10 @@ BEGIN(set)
20765 movl %ebx, (v)
20766 movl %ecx, 4(v)
20767 RET_ENDP
20768 +BEGIN(set_unchecked)
20769 + movl %ebx, (v)
20770 + movl %ecx, 4(v)
20771 +RET_ENDP
20772 #undef v
20773
20774 #define v %esi
20775 @@ -70,6 +78,20 @@ RET_ENDP
20776 BEGIN(add)
20777 addl %eax, (v)
20778 adcl %edx, 4(v)
20779 +
20780 +#ifdef CONFIG_PAX_REFCOUNT
20781 + jno 0f
20782 + subl %eax, (v)
20783 + sbbl %edx, 4(v)
20784 + int $4
20785 +0:
20786 + _ASM_EXTABLE(0b, 0b)
20787 +#endif
20788 +
20789 +RET_ENDP
20790 +BEGIN(add_unchecked)
20791 + addl %eax, (v)
20792 + adcl %edx, 4(v)
20793 RET_ENDP
20794 #undef v
20795
20796 @@ -77,6 +99,24 @@ RET_ENDP
20797 BEGIN(add_return)
20798 addl (v), %eax
20799 adcl 4(v), %edx
20800 +
20801 +#ifdef CONFIG_PAX_REFCOUNT
20802 + into
20803 +1234:
20804 + _ASM_EXTABLE(1234b, 2f)
20805 +#endif
20806 +
20807 + movl %eax, (v)
20808 + movl %edx, 4(v)
20809 +
20810 +#ifdef CONFIG_PAX_REFCOUNT
20811 +2:
20812 +#endif
20813 +
20814 +RET_ENDP
20815 +BEGIN(add_return_unchecked)
20816 + addl (v), %eax
20817 + adcl 4(v), %edx
20818 movl %eax, (v)
20819 movl %edx, 4(v)
20820 RET_ENDP
20821 @@ -86,6 +126,20 @@ RET_ENDP
20822 BEGIN(sub)
20823 subl %eax, (v)
20824 sbbl %edx, 4(v)
20825 +
20826 +#ifdef CONFIG_PAX_REFCOUNT
20827 + jno 0f
20828 + addl %eax, (v)
20829 + adcl %edx, 4(v)
20830 + int $4
20831 +0:
20832 + _ASM_EXTABLE(0b, 0b)
20833 +#endif
20834 +
20835 +RET_ENDP
20836 +BEGIN(sub_unchecked)
20837 + subl %eax, (v)
20838 + sbbl %edx, 4(v)
20839 RET_ENDP
20840 #undef v
20841
20842 @@ -96,6 +150,27 @@ BEGIN(sub_return)
20843 sbbl $0, %edx
20844 addl (v), %eax
20845 adcl 4(v), %edx
20846 +
20847 +#ifdef CONFIG_PAX_REFCOUNT
20848 + into
20849 +1234:
20850 + _ASM_EXTABLE(1234b, 2f)
20851 +#endif
20852 +
20853 + movl %eax, (v)
20854 + movl %edx, 4(v)
20855 +
20856 +#ifdef CONFIG_PAX_REFCOUNT
20857 +2:
20858 +#endif
20859 +
20860 +RET_ENDP
20861 +BEGIN(sub_return_unchecked)
20862 + negl %edx
20863 + negl %eax
20864 + sbbl $0, %edx
20865 + addl (v), %eax
20866 + adcl 4(v), %edx
20867 movl %eax, (v)
20868 movl %edx, 4(v)
20869 RET_ENDP
20870 @@ -105,6 +180,20 @@ RET_ENDP
20871 BEGIN(inc)
20872 addl $1, (v)
20873 adcl $0, 4(v)
20874 +
20875 +#ifdef CONFIG_PAX_REFCOUNT
20876 + jno 0f
20877 + subl $1, (v)
20878 + sbbl $0, 4(v)
20879 + int $4
20880 +0:
20881 + _ASM_EXTABLE(0b, 0b)
20882 +#endif
20883 +
20884 +RET_ENDP
20885 +BEGIN(inc_unchecked)
20886 + addl $1, (v)
20887 + adcl $0, 4(v)
20888 RET_ENDP
20889 #undef v
20890
20891 @@ -114,6 +203,26 @@ BEGIN(inc_return)
20892 movl 4(v), %edx
20893 addl $1, %eax
20894 adcl $0, %edx
20895 +
20896 +#ifdef CONFIG_PAX_REFCOUNT
20897 + into
20898 +1234:
20899 + _ASM_EXTABLE(1234b, 2f)
20900 +#endif
20901 +
20902 + movl %eax, (v)
20903 + movl %edx, 4(v)
20904 +
20905 +#ifdef CONFIG_PAX_REFCOUNT
20906 +2:
20907 +#endif
20908 +
20909 +RET_ENDP
20910 +BEGIN(inc_return_unchecked)
20911 + movl (v), %eax
20912 + movl 4(v), %edx
20913 + addl $1, %eax
20914 + adcl $0, %edx
20915 movl %eax, (v)
20916 movl %edx, 4(v)
20917 RET_ENDP
20918 @@ -123,6 +232,20 @@ RET_ENDP
20919 BEGIN(dec)
20920 subl $1, (v)
20921 sbbl $0, 4(v)
20922 +
20923 +#ifdef CONFIG_PAX_REFCOUNT
20924 + jno 0f
20925 + addl $1, (v)
20926 + adcl $0, 4(v)
20927 + int $4
20928 +0:
20929 + _ASM_EXTABLE(0b, 0b)
20930 +#endif
20931 +
20932 +RET_ENDP
20933 +BEGIN(dec_unchecked)
20934 + subl $1, (v)
20935 + sbbl $0, 4(v)
20936 RET_ENDP
20937 #undef v
20938
20939 @@ -132,6 +255,26 @@ BEGIN(dec_return)
20940 movl 4(v), %edx
20941 subl $1, %eax
20942 sbbl $0, %edx
20943 +
20944 +#ifdef CONFIG_PAX_REFCOUNT
20945 + into
20946 +1234:
20947 + _ASM_EXTABLE(1234b, 2f)
20948 +#endif
20949 +
20950 + movl %eax, (v)
20951 + movl %edx, 4(v)
20952 +
20953 +#ifdef CONFIG_PAX_REFCOUNT
20954 +2:
20955 +#endif
20956 +
20957 +RET_ENDP
20958 +BEGIN(dec_return_unchecked)
20959 + movl (v), %eax
20960 + movl 4(v), %edx
20961 + subl $1, %eax
20962 + sbbl $0, %edx
20963 movl %eax, (v)
20964 movl %edx, 4(v)
20965 RET_ENDP
20966 @@ -143,6 +286,13 @@ BEGIN(add_unless)
20967 adcl %edx, %edi
20968 addl (v), %eax
20969 adcl 4(v), %edx
20970 +
20971 +#ifdef CONFIG_PAX_REFCOUNT
20972 + into
20973 +1234:
20974 + _ASM_EXTABLE(1234b, 2f)
20975 +#endif
20976 +
20977 cmpl %eax, %ecx
20978 je 3f
20979 1:
20980 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
20981 1:
20982 addl $1, %eax
20983 adcl $0, %edx
20984 +
20985 +#ifdef CONFIG_PAX_REFCOUNT
20986 + into
20987 +1234:
20988 + _ASM_EXTABLE(1234b, 2f)
20989 +#endif
20990 +
20991 movl %eax, (v)
20992 movl %edx, 4(v)
20993 movl $1, %eax
20994 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
20995 movl 4(v), %edx
20996 subl $1, %eax
20997 sbbl $0, %edx
20998 +
20999 +#ifdef CONFIG_PAX_REFCOUNT
21000 + into
21001 +1234:
21002 + _ASM_EXTABLE(1234b, 1f)
21003 +#endif
21004 +
21005 js 1f
21006 movl %eax, (v)
21007 movl %edx, 4(v)
21008 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
21009 index f5cc9eb..51fa319 100644
21010 --- a/arch/x86/lib/atomic64_cx8_32.S
21011 +++ b/arch/x86/lib/atomic64_cx8_32.S
21012 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
21013 CFI_STARTPROC
21014
21015 read64 %ecx
21016 + pax_force_retaddr
21017 ret
21018 CFI_ENDPROC
21019 ENDPROC(atomic64_read_cx8)
21020
21021 +ENTRY(atomic64_read_unchecked_cx8)
21022 + CFI_STARTPROC
21023 +
21024 + read64 %ecx
21025 + pax_force_retaddr
21026 + ret
21027 + CFI_ENDPROC
21028 +ENDPROC(atomic64_read_unchecked_cx8)
21029 +
21030 ENTRY(atomic64_set_cx8)
21031 CFI_STARTPROC
21032
21033 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
21034 cmpxchg8b (%esi)
21035 jne 1b
21036
21037 + pax_force_retaddr
21038 ret
21039 CFI_ENDPROC
21040 ENDPROC(atomic64_set_cx8)
21041
21042 +ENTRY(atomic64_set_unchecked_cx8)
21043 + CFI_STARTPROC
21044 +
21045 +1:
21046 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
21047 + * are atomic on 586 and newer */
21048 + cmpxchg8b (%esi)
21049 + jne 1b
21050 +
21051 + pax_force_retaddr
21052 + ret
21053 + CFI_ENDPROC
21054 +ENDPROC(atomic64_set_unchecked_cx8)
21055 +
21056 ENTRY(atomic64_xchg_cx8)
21057 CFI_STARTPROC
21058
21059 @@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
21060 cmpxchg8b (%esi)
21061 jne 1b
21062
21063 + pax_force_retaddr
21064 ret
21065 CFI_ENDPROC
21066 ENDPROC(atomic64_xchg_cx8)
21067
21068 -.macro addsub_return func ins insc
21069 -ENTRY(atomic64_\func\()_return_cx8)
21070 +.macro addsub_return func ins insc unchecked=""
21071 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
21072 CFI_STARTPROC
21073 SAVE ebp
21074 SAVE ebx
21075 @@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
21076 movl %edx, %ecx
21077 \ins\()l %esi, %ebx
21078 \insc\()l %edi, %ecx
21079 +
21080 +.ifb \unchecked
21081 +#ifdef CONFIG_PAX_REFCOUNT
21082 + into
21083 +2:
21084 + _ASM_EXTABLE(2b, 3f)
21085 +#endif
21086 +.endif
21087 +
21088 LOCK_PREFIX
21089 cmpxchg8b (%ebp)
21090 jne 1b
21091 -
21092 -10:
21093 movl %ebx, %eax
21094 movl %ecx, %edx
21095 +
21096 +.ifb \unchecked
21097 +#ifdef CONFIG_PAX_REFCOUNT
21098 +3:
21099 +#endif
21100 +.endif
21101 +
21102 RESTORE edi
21103 RESTORE esi
21104 RESTORE ebx
21105 RESTORE ebp
21106 + pax_force_retaddr
21107 ret
21108 CFI_ENDPROC
21109 -ENDPROC(atomic64_\func\()_return_cx8)
21110 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
21111 .endm
21112
21113 addsub_return add add adc
21114 addsub_return sub sub sbb
21115 +addsub_return add add adc _unchecked
21116 +addsub_return sub sub sbb _unchecked
21117
21118 -.macro incdec_return func ins insc
21119 -ENTRY(atomic64_\func\()_return_cx8)
21120 +.macro incdec_return func ins insc unchecked=""
21121 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
21122 CFI_STARTPROC
21123 SAVE ebx
21124
21125 @@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
21126 movl %edx, %ecx
21127 \ins\()l $1, %ebx
21128 \insc\()l $0, %ecx
21129 +
21130 +.ifb \unchecked
21131 +#ifdef CONFIG_PAX_REFCOUNT
21132 + into
21133 +2:
21134 + _ASM_EXTABLE(2b, 3f)
21135 +#endif
21136 +.endif
21137 +
21138 LOCK_PREFIX
21139 cmpxchg8b (%esi)
21140 jne 1b
21141
21142 -10:
21143 movl %ebx, %eax
21144 movl %ecx, %edx
21145 +
21146 +.ifb \unchecked
21147 +#ifdef CONFIG_PAX_REFCOUNT
21148 +3:
21149 +#endif
21150 +.endif
21151 +
21152 RESTORE ebx
21153 + pax_force_retaddr
21154 ret
21155 CFI_ENDPROC
21156 -ENDPROC(atomic64_\func\()_return_cx8)
21157 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
21158 .endm
21159
21160 incdec_return inc add adc
21161 incdec_return dec sub sbb
21162 +incdec_return inc add adc _unchecked
21163 +incdec_return dec sub sbb _unchecked
21164
21165 ENTRY(atomic64_dec_if_positive_cx8)
21166 CFI_STARTPROC
21167 @@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
21168 movl %edx, %ecx
21169 subl $1, %ebx
21170 sbb $0, %ecx
21171 +
21172 +#ifdef CONFIG_PAX_REFCOUNT
21173 + into
21174 +1234:
21175 + _ASM_EXTABLE(1234b, 2f)
21176 +#endif
21177 +
21178 js 2f
21179 LOCK_PREFIX
21180 cmpxchg8b (%esi)
21181 @@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
21182 movl %ebx, %eax
21183 movl %ecx, %edx
21184 RESTORE ebx
21185 + pax_force_retaddr
21186 ret
21187 CFI_ENDPROC
21188 ENDPROC(atomic64_dec_if_positive_cx8)
21189 @@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
21190 movl %edx, %ecx
21191 addl %ebp, %ebx
21192 adcl %edi, %ecx
21193 +
21194 +#ifdef CONFIG_PAX_REFCOUNT
21195 + into
21196 +1234:
21197 + _ASM_EXTABLE(1234b, 3f)
21198 +#endif
21199 +
21200 LOCK_PREFIX
21201 cmpxchg8b (%esi)
21202 jne 1b
21203 @@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
21204 CFI_ADJUST_CFA_OFFSET -8
21205 RESTORE ebx
21206 RESTORE ebp
21207 + pax_force_retaddr
21208 ret
21209 4:
21210 cmpl %edx, 4(%esp)
21211 @@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
21212 xorl %ecx, %ecx
21213 addl $1, %ebx
21214 adcl %edx, %ecx
21215 +
21216 +#ifdef CONFIG_PAX_REFCOUNT
21217 + into
21218 +1234:
21219 + _ASM_EXTABLE(1234b, 3f)
21220 +#endif
21221 +
21222 LOCK_PREFIX
21223 cmpxchg8b (%esi)
21224 jne 1b
21225 @@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
21226 movl $1, %eax
21227 3:
21228 RESTORE ebx
21229 + pax_force_retaddr
21230 ret
21231 CFI_ENDPROC
21232 ENDPROC(atomic64_inc_not_zero_cx8)
21233 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
21234 index 2af5df3..62b1a5a 100644
21235 --- a/arch/x86/lib/checksum_32.S
21236 +++ b/arch/x86/lib/checksum_32.S
21237 @@ -29,7 +29,8 @@
21238 #include <asm/dwarf2.h>
21239 #include <asm/errno.h>
21240 #include <asm/asm.h>
21241 -
21242 +#include <asm/segment.h>
21243 +
21244 /*
21245 * computes a partial checksum, e.g. for TCP/UDP fragments
21246 */
21247 @@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
21248
21249 #define ARGBASE 16
21250 #define FP 12
21251 -
21252 -ENTRY(csum_partial_copy_generic)
21253 +
21254 +ENTRY(csum_partial_copy_generic_to_user)
21255 CFI_STARTPROC
21256 +
21257 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21258 + pushl_cfi %gs
21259 + popl_cfi %es
21260 + jmp csum_partial_copy_generic
21261 +#endif
21262 +
21263 +ENTRY(csum_partial_copy_generic_from_user)
21264 +
21265 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21266 + pushl_cfi %gs
21267 + popl_cfi %ds
21268 +#endif
21269 +
21270 +ENTRY(csum_partial_copy_generic)
21271 subl $4,%esp
21272 CFI_ADJUST_CFA_OFFSET 4
21273 pushl_cfi %edi
21274 @@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
21275 jmp 4f
21276 SRC(1: movw (%esi), %bx )
21277 addl $2, %esi
21278 -DST( movw %bx, (%edi) )
21279 +DST( movw %bx, %es:(%edi) )
21280 addl $2, %edi
21281 addw %bx, %ax
21282 adcl $0, %eax
21283 @@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
21284 SRC(1: movl (%esi), %ebx )
21285 SRC( movl 4(%esi), %edx )
21286 adcl %ebx, %eax
21287 -DST( movl %ebx, (%edi) )
21288 +DST( movl %ebx, %es:(%edi) )
21289 adcl %edx, %eax
21290 -DST( movl %edx, 4(%edi) )
21291 +DST( movl %edx, %es:4(%edi) )
21292
21293 SRC( movl 8(%esi), %ebx )
21294 SRC( movl 12(%esi), %edx )
21295 adcl %ebx, %eax
21296 -DST( movl %ebx, 8(%edi) )
21297 +DST( movl %ebx, %es:8(%edi) )
21298 adcl %edx, %eax
21299 -DST( movl %edx, 12(%edi) )
21300 +DST( movl %edx, %es:12(%edi) )
21301
21302 SRC( movl 16(%esi), %ebx )
21303 SRC( movl 20(%esi), %edx )
21304 adcl %ebx, %eax
21305 -DST( movl %ebx, 16(%edi) )
21306 +DST( movl %ebx, %es:16(%edi) )
21307 adcl %edx, %eax
21308 -DST( movl %edx, 20(%edi) )
21309 +DST( movl %edx, %es:20(%edi) )
21310
21311 SRC( movl 24(%esi), %ebx )
21312 SRC( movl 28(%esi), %edx )
21313 adcl %ebx, %eax
21314 -DST( movl %ebx, 24(%edi) )
21315 +DST( movl %ebx, %es:24(%edi) )
21316 adcl %edx, %eax
21317 -DST( movl %edx, 28(%edi) )
21318 +DST( movl %edx, %es:28(%edi) )
21319
21320 lea 32(%esi), %esi
21321 lea 32(%edi), %edi
21322 @@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
21323 shrl $2, %edx # This clears CF
21324 SRC(3: movl (%esi), %ebx )
21325 adcl %ebx, %eax
21326 -DST( movl %ebx, (%edi) )
21327 +DST( movl %ebx, %es:(%edi) )
21328 lea 4(%esi), %esi
21329 lea 4(%edi), %edi
21330 dec %edx
21331 @@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
21332 jb 5f
21333 SRC( movw (%esi), %cx )
21334 leal 2(%esi), %esi
21335 -DST( movw %cx, (%edi) )
21336 +DST( movw %cx, %es:(%edi) )
21337 leal 2(%edi), %edi
21338 je 6f
21339 shll $16,%ecx
21340 SRC(5: movb (%esi), %cl )
21341 -DST( movb %cl, (%edi) )
21342 +DST( movb %cl, %es:(%edi) )
21343 6: addl %ecx, %eax
21344 adcl $0, %eax
21345 7:
21346 @@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
21347
21348 6001:
21349 movl ARGBASE+20(%esp), %ebx # src_err_ptr
21350 - movl $-EFAULT, (%ebx)
21351 + movl $-EFAULT, %ss:(%ebx)
21352
21353 # zero the complete destination - computing the rest
21354 # is too much work
21355 @@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
21356
21357 6002:
21358 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21359 - movl $-EFAULT,(%ebx)
21360 + movl $-EFAULT,%ss:(%ebx)
21361 jmp 5000b
21362
21363 .previous
21364
21365 + pushl_cfi %ss
21366 + popl_cfi %ds
21367 + pushl_cfi %ss
21368 + popl_cfi %es
21369 popl_cfi %ebx
21370 CFI_RESTORE ebx
21371 popl_cfi %esi
21372 @@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
21373 popl_cfi %ecx # equivalent to addl $4,%esp
21374 ret
21375 CFI_ENDPROC
21376 -ENDPROC(csum_partial_copy_generic)
21377 +ENDPROC(csum_partial_copy_generic_to_user)
21378
21379 #else
21380
21381 /* Version for PentiumII/PPro */
21382
21383 #define ROUND1(x) \
21384 + nop; nop; nop; \
21385 SRC(movl x(%esi), %ebx ) ; \
21386 addl %ebx, %eax ; \
21387 - DST(movl %ebx, x(%edi) ) ;
21388 + DST(movl %ebx, %es:x(%edi)) ;
21389
21390 #define ROUND(x) \
21391 + nop; nop; nop; \
21392 SRC(movl x(%esi), %ebx ) ; \
21393 adcl %ebx, %eax ; \
21394 - DST(movl %ebx, x(%edi) ) ;
21395 + DST(movl %ebx, %es:x(%edi)) ;
21396
21397 #define ARGBASE 12
21398 -
21399 -ENTRY(csum_partial_copy_generic)
21400 +
21401 +ENTRY(csum_partial_copy_generic_to_user)
21402 CFI_STARTPROC
21403 +
21404 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21405 + pushl_cfi %gs
21406 + popl_cfi %es
21407 + jmp csum_partial_copy_generic
21408 +#endif
21409 +
21410 +ENTRY(csum_partial_copy_generic_from_user)
21411 +
21412 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21413 + pushl_cfi %gs
21414 + popl_cfi %ds
21415 +#endif
21416 +
21417 +ENTRY(csum_partial_copy_generic)
21418 pushl_cfi %ebx
21419 CFI_REL_OFFSET ebx, 0
21420 pushl_cfi %edi
21421 @@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
21422 subl %ebx, %edi
21423 lea -1(%esi),%edx
21424 andl $-32,%edx
21425 - lea 3f(%ebx,%ebx), %ebx
21426 + lea 3f(%ebx,%ebx,2), %ebx
21427 testl %esi, %esi
21428 jmp *%ebx
21429 1: addl $64,%esi
21430 @@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
21431 jb 5f
21432 SRC( movw (%esi), %dx )
21433 leal 2(%esi), %esi
21434 -DST( movw %dx, (%edi) )
21435 +DST( movw %dx, %es:(%edi) )
21436 leal 2(%edi), %edi
21437 je 6f
21438 shll $16,%edx
21439 5:
21440 SRC( movb (%esi), %dl )
21441 -DST( movb %dl, (%edi) )
21442 +DST( movb %dl, %es:(%edi) )
21443 6: addl %edx, %eax
21444 adcl $0, %eax
21445 7:
21446 .section .fixup, "ax"
21447 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
21448 - movl $-EFAULT, (%ebx)
21449 + movl $-EFAULT, %ss:(%ebx)
21450 # zero the complete destination (computing the rest is too much work)
21451 movl ARGBASE+8(%esp),%edi # dst
21452 movl ARGBASE+12(%esp),%ecx # len
21453 @@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
21454 rep; stosb
21455 jmp 7b
21456 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21457 - movl $-EFAULT, (%ebx)
21458 + movl $-EFAULT, %ss:(%ebx)
21459 jmp 7b
21460 .previous
21461
21462 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21463 + pushl_cfi %ss
21464 + popl_cfi %ds
21465 + pushl_cfi %ss
21466 + popl_cfi %es
21467 +#endif
21468 +
21469 popl_cfi %esi
21470 CFI_RESTORE esi
21471 popl_cfi %edi
21472 @@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
21473 CFI_RESTORE ebx
21474 ret
21475 CFI_ENDPROC
21476 -ENDPROC(csum_partial_copy_generic)
21477 +ENDPROC(csum_partial_copy_generic_to_user)
21478
21479 #undef ROUND
21480 #undef ROUND1
21481 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
21482 index f2145cf..cea889d 100644
21483 --- a/arch/x86/lib/clear_page_64.S
21484 +++ b/arch/x86/lib/clear_page_64.S
21485 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
21486 movl $4096/8,%ecx
21487 xorl %eax,%eax
21488 rep stosq
21489 + pax_force_retaddr
21490 ret
21491 CFI_ENDPROC
21492 ENDPROC(clear_page_c)
21493 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
21494 movl $4096,%ecx
21495 xorl %eax,%eax
21496 rep stosb
21497 + pax_force_retaddr
21498 ret
21499 CFI_ENDPROC
21500 ENDPROC(clear_page_c_e)
21501 @@ -43,6 +45,7 @@ ENTRY(clear_page)
21502 leaq 64(%rdi),%rdi
21503 jnz .Lloop
21504 nop
21505 + pax_force_retaddr
21506 ret
21507 CFI_ENDPROC
21508 .Lclear_page_end:
21509 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
21510
21511 #include <asm/cpufeature.h>
21512
21513 - .section .altinstr_replacement,"ax"
21514 + .section .altinstr_replacement,"a"
21515 1: .byte 0xeb /* jmp <disp8> */
21516 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
21517 2: .byte 0xeb /* jmp <disp8> */
21518 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
21519 index 1e572c5..2a162cd 100644
21520 --- a/arch/x86/lib/cmpxchg16b_emu.S
21521 +++ b/arch/x86/lib/cmpxchg16b_emu.S
21522 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
21523
21524 popf
21525 mov $1, %al
21526 + pax_force_retaddr
21527 ret
21528
21529 not_same:
21530 popf
21531 xor %al,%al
21532 + pax_force_retaddr
21533 ret
21534
21535 CFI_ENDPROC
21536 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
21537 index 6b34d04..dccb07f 100644
21538 --- a/arch/x86/lib/copy_page_64.S
21539 +++ b/arch/x86/lib/copy_page_64.S
21540 @@ -9,6 +9,7 @@ copy_page_c:
21541 CFI_STARTPROC
21542 movl $4096/8,%ecx
21543 rep movsq
21544 + pax_force_retaddr
21545 ret
21546 CFI_ENDPROC
21547 ENDPROC(copy_page_c)
21548 @@ -20,12 +21,14 @@ ENDPROC(copy_page_c)
21549
21550 ENTRY(copy_page)
21551 CFI_STARTPROC
21552 - subq $2*8,%rsp
21553 - CFI_ADJUST_CFA_OFFSET 2*8
21554 + subq $3*8,%rsp
21555 + CFI_ADJUST_CFA_OFFSET 3*8
21556 movq %rbx,(%rsp)
21557 CFI_REL_OFFSET rbx, 0
21558 movq %r12,1*8(%rsp)
21559 CFI_REL_OFFSET r12, 1*8
21560 + movq %r13,2*8(%rsp)
21561 + CFI_REL_OFFSET r13, 2*8
21562
21563 movl $(4096/64)-5,%ecx
21564 .p2align 4
21565 @@ -37,7 +40,7 @@ ENTRY(copy_page)
21566 movq 16 (%rsi), %rdx
21567 movq 24 (%rsi), %r8
21568 movq 32 (%rsi), %r9
21569 - movq 40 (%rsi), %r10
21570 + movq 40 (%rsi), %r13
21571 movq 48 (%rsi), %r11
21572 movq 56 (%rsi), %r12
21573
21574 @@ -48,7 +51,7 @@ ENTRY(copy_page)
21575 movq %rdx, 16 (%rdi)
21576 movq %r8, 24 (%rdi)
21577 movq %r9, 32 (%rdi)
21578 - movq %r10, 40 (%rdi)
21579 + movq %r13, 40 (%rdi)
21580 movq %r11, 48 (%rdi)
21581 movq %r12, 56 (%rdi)
21582
21583 @@ -67,7 +70,7 @@ ENTRY(copy_page)
21584 movq 16 (%rsi), %rdx
21585 movq 24 (%rsi), %r8
21586 movq 32 (%rsi), %r9
21587 - movq 40 (%rsi), %r10
21588 + movq 40 (%rsi), %r13
21589 movq 48 (%rsi), %r11
21590 movq 56 (%rsi), %r12
21591
21592 @@ -76,7 +79,7 @@ ENTRY(copy_page)
21593 movq %rdx, 16 (%rdi)
21594 movq %r8, 24 (%rdi)
21595 movq %r9, 32 (%rdi)
21596 - movq %r10, 40 (%rdi)
21597 + movq %r13, 40 (%rdi)
21598 movq %r11, 48 (%rdi)
21599 movq %r12, 56 (%rdi)
21600
21601 @@ -89,8 +92,11 @@ ENTRY(copy_page)
21602 CFI_RESTORE rbx
21603 movq 1*8(%rsp),%r12
21604 CFI_RESTORE r12
21605 - addq $2*8,%rsp
21606 - CFI_ADJUST_CFA_OFFSET -2*8
21607 + movq 2*8(%rsp),%r13
21608 + CFI_RESTORE r13
21609 + addq $3*8,%rsp
21610 + CFI_ADJUST_CFA_OFFSET -3*8
21611 + pax_force_retaddr
21612 ret
21613 .Lcopy_page_end:
21614 CFI_ENDPROC
21615 @@ -101,7 +107,7 @@ ENDPROC(copy_page)
21616
21617 #include <asm/cpufeature.h>
21618
21619 - .section .altinstr_replacement,"ax"
21620 + .section .altinstr_replacement,"a"
21621 1: .byte 0xeb /* jmp <disp8> */
21622 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
21623 2:
21624 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
21625 index 5b2995f..78e7644 100644
21626 --- a/arch/x86/lib/copy_user_64.S
21627 +++ b/arch/x86/lib/copy_user_64.S
21628 @@ -17,6 +17,7 @@
21629 #include <asm/cpufeature.h>
21630 #include <asm/alternative-asm.h>
21631 #include <asm/asm.h>
21632 +#include <asm/pgtable.h>
21633
21634 /*
21635 * By placing feature2 after feature1 in altinstructions section, we logically
21636 @@ -30,7 +31,7 @@
21637 .byte 0xe9 /* 32bit jump */
21638 .long \orig-1f /* by default jump to orig */
21639 1:
21640 - .section .altinstr_replacement,"ax"
21641 + .section .altinstr_replacement,"a"
21642 2: .byte 0xe9 /* near jump with 32bit immediate */
21643 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
21644 3: .byte 0xe9 /* near jump with 32bit immediate */
21645 @@ -69,47 +70,20 @@
21646 #endif
21647 .endm
21648
21649 -/* Standard copy_to_user with segment limit checking */
21650 -ENTRY(_copy_to_user)
21651 - CFI_STARTPROC
21652 - GET_THREAD_INFO(%rax)
21653 - movq %rdi,%rcx
21654 - addq %rdx,%rcx
21655 - jc bad_to_user
21656 - cmpq TI_addr_limit(%rax),%rcx
21657 - ja bad_to_user
21658 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21659 - copy_user_generic_unrolled,copy_user_generic_string, \
21660 - copy_user_enhanced_fast_string
21661 - CFI_ENDPROC
21662 -ENDPROC(_copy_to_user)
21663 -
21664 -/* Standard copy_from_user with segment limit checking */
21665 -ENTRY(_copy_from_user)
21666 - CFI_STARTPROC
21667 - GET_THREAD_INFO(%rax)
21668 - movq %rsi,%rcx
21669 - addq %rdx,%rcx
21670 - jc bad_from_user
21671 - cmpq TI_addr_limit(%rax),%rcx
21672 - ja bad_from_user
21673 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21674 - copy_user_generic_unrolled,copy_user_generic_string, \
21675 - copy_user_enhanced_fast_string
21676 - CFI_ENDPROC
21677 -ENDPROC(_copy_from_user)
21678 -
21679 .section .fixup,"ax"
21680 /* must zero dest */
21681 ENTRY(bad_from_user)
21682 bad_from_user:
21683 CFI_STARTPROC
21684 + testl %edx,%edx
21685 + js bad_to_user
21686 movl %edx,%ecx
21687 xorl %eax,%eax
21688 rep
21689 stosb
21690 bad_to_user:
21691 movl %edx,%eax
21692 + pax_force_retaddr
21693 ret
21694 CFI_ENDPROC
21695 ENDPROC(bad_from_user)
21696 @@ -139,19 +113,19 @@ ENTRY(copy_user_generic_unrolled)
21697 jz 17f
21698 1: movq (%rsi),%r8
21699 2: movq 1*8(%rsi),%r9
21700 -3: movq 2*8(%rsi),%r10
21701 +3: movq 2*8(%rsi),%rax
21702 4: movq 3*8(%rsi),%r11
21703 5: movq %r8,(%rdi)
21704 6: movq %r9,1*8(%rdi)
21705 -7: movq %r10,2*8(%rdi)
21706 +7: movq %rax,2*8(%rdi)
21707 8: movq %r11,3*8(%rdi)
21708 9: movq 4*8(%rsi),%r8
21709 10: movq 5*8(%rsi),%r9
21710 -11: movq 6*8(%rsi),%r10
21711 +11: movq 6*8(%rsi),%rax
21712 12: movq 7*8(%rsi),%r11
21713 13: movq %r8,4*8(%rdi)
21714 14: movq %r9,5*8(%rdi)
21715 -15: movq %r10,6*8(%rdi)
21716 +15: movq %rax,6*8(%rdi)
21717 16: movq %r11,7*8(%rdi)
21718 leaq 64(%rsi),%rsi
21719 leaq 64(%rdi),%rdi
21720 @@ -177,6 +151,7 @@ ENTRY(copy_user_generic_unrolled)
21721 decl %ecx
21722 jnz 21b
21723 23: xor %eax,%eax
21724 + pax_force_retaddr
21725 ret
21726
21727 .section .fixup,"ax"
21728 @@ -246,6 +221,7 @@ ENTRY(copy_user_generic_string)
21729 3: rep
21730 movsb
21731 4: xorl %eax,%eax
21732 + pax_force_retaddr
21733 ret
21734
21735 .section .fixup,"ax"
21736 @@ -279,6 +255,7 @@ ENTRY(copy_user_enhanced_fast_string)
21737 1: rep
21738 movsb
21739 2: xorl %eax,%eax
21740 + pax_force_retaddr
21741 ret
21742
21743 .section .fixup,"ax"
21744 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
21745 index cacddc7..09d49e4 100644
21746 --- a/arch/x86/lib/copy_user_nocache_64.S
21747 +++ b/arch/x86/lib/copy_user_nocache_64.S
21748 @@ -8,6 +8,7 @@
21749
21750 #include <linux/linkage.h>
21751 #include <asm/dwarf2.h>
21752 +#include <asm/alternative-asm.h>
21753
21754 #define FIX_ALIGNMENT 1
21755
21756 @@ -15,6 +16,7 @@
21757 #include <asm/asm-offsets.h>
21758 #include <asm/thread_info.h>
21759 #include <asm/asm.h>
21760 +#include <asm/pgtable.h>
21761
21762 .macro ALIGN_DESTINATION
21763 #ifdef FIX_ALIGNMENT
21764 @@ -48,6 +50,15 @@
21765 */
21766 ENTRY(__copy_user_nocache)
21767 CFI_STARTPROC
21768 +
21769 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21770 + mov $PAX_USER_SHADOW_BASE,%rcx
21771 + cmp %rcx,%rsi
21772 + jae 1f
21773 + add %rcx,%rsi
21774 +1:
21775 +#endif
21776 +
21777 cmpl $8,%edx
21778 jb 20f /* less then 8 bytes, go to byte copy loop */
21779 ALIGN_DESTINATION
21780 @@ -57,19 +68,19 @@ ENTRY(__copy_user_nocache)
21781 jz 17f
21782 1: movq (%rsi),%r8
21783 2: movq 1*8(%rsi),%r9
21784 -3: movq 2*8(%rsi),%r10
21785 +3: movq 2*8(%rsi),%rax
21786 4: movq 3*8(%rsi),%r11
21787 5: movnti %r8,(%rdi)
21788 6: movnti %r9,1*8(%rdi)
21789 -7: movnti %r10,2*8(%rdi)
21790 +7: movnti %rax,2*8(%rdi)
21791 8: movnti %r11,3*8(%rdi)
21792 9: movq 4*8(%rsi),%r8
21793 10: movq 5*8(%rsi),%r9
21794 -11: movq 6*8(%rsi),%r10
21795 +11: movq 6*8(%rsi),%rax
21796 12: movq 7*8(%rsi),%r11
21797 13: movnti %r8,4*8(%rdi)
21798 14: movnti %r9,5*8(%rdi)
21799 -15: movnti %r10,6*8(%rdi)
21800 +15: movnti %rax,6*8(%rdi)
21801 16: movnti %r11,7*8(%rdi)
21802 leaq 64(%rsi),%rsi
21803 leaq 64(%rdi),%rdi
21804 @@ -96,6 +107,7 @@ ENTRY(__copy_user_nocache)
21805 jnz 21b
21806 23: xorl %eax,%eax
21807 sfence
21808 + pax_force_retaddr
21809 ret
21810
21811 .section .fixup,"ax"
21812 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
21813 index 2419d5f..953ee51 100644
21814 --- a/arch/x86/lib/csum-copy_64.S
21815 +++ b/arch/x86/lib/csum-copy_64.S
21816 @@ -9,6 +9,7 @@
21817 #include <asm/dwarf2.h>
21818 #include <asm/errno.h>
21819 #include <asm/asm.h>
21820 +#include <asm/alternative-asm.h>
21821
21822 /*
21823 * Checksum copy with exception handling.
21824 @@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
21825 CFI_RESTORE rbp
21826 addq $7*8, %rsp
21827 CFI_ADJUST_CFA_OFFSET -7*8
21828 + pax_force_retaddr 0, 1
21829 ret
21830 CFI_RESTORE_STATE
21831
21832 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
21833 index 25b7ae8..3b52ccd 100644
21834 --- a/arch/x86/lib/csum-wrappers_64.c
21835 +++ b/arch/x86/lib/csum-wrappers_64.c
21836 @@ -52,7 +52,13 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
21837 len -= 2;
21838 }
21839 }
21840 - isum = csum_partial_copy_generic((__force const void *)src,
21841 +
21842 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21843 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
21844 + src += PAX_USER_SHADOW_BASE;
21845 +#endif
21846 +
21847 + isum = csum_partial_copy_generic((const void __force_kernel *)src,
21848 dst, len, isum, errp, NULL);
21849 if (unlikely(*errp))
21850 goto out_err;
21851 @@ -105,7 +111,13 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
21852 }
21853
21854 *errp = 0;
21855 - return csum_partial_copy_generic(src, (void __force *)dst,
21856 +
21857 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21858 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
21859 + dst += PAX_USER_SHADOW_BASE;
21860 +#endif
21861 +
21862 + return csum_partial_copy_generic(src, (void __force_kernel *)dst,
21863 len, isum, NULL, errp);
21864 }
21865 EXPORT_SYMBOL(csum_partial_copy_to_user);
21866 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
21867 index b33b1fb..219f389 100644
21868 --- a/arch/x86/lib/getuser.S
21869 +++ b/arch/x86/lib/getuser.S
21870 @@ -33,15 +33,38 @@
21871 #include <asm/asm-offsets.h>
21872 #include <asm/thread_info.h>
21873 #include <asm/asm.h>
21874 +#include <asm/segment.h>
21875 +#include <asm/pgtable.h>
21876 +#include <asm/alternative-asm.h>
21877 +
21878 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
21879 +#define __copyuser_seg gs;
21880 +#else
21881 +#define __copyuser_seg
21882 +#endif
21883
21884 .text
21885 ENTRY(__get_user_1)
21886 CFI_STARTPROC
21887 +
21888 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21889 GET_THREAD_INFO(%_ASM_DX)
21890 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21891 jae bad_get_user
21892 -1: movzb (%_ASM_AX),%edx
21893 +
21894 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21895 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21896 + cmp %_ASM_DX,%_ASM_AX
21897 + jae 1234f
21898 + add %_ASM_DX,%_ASM_AX
21899 +1234:
21900 +#endif
21901 +
21902 +#endif
21903 +
21904 +1: __copyuser_seg movzb (%_ASM_AX),%edx
21905 xor %eax,%eax
21906 + pax_force_retaddr
21907 ret
21908 CFI_ENDPROC
21909 ENDPROC(__get_user_1)
21910 @@ -49,12 +72,26 @@ ENDPROC(__get_user_1)
21911 ENTRY(__get_user_2)
21912 CFI_STARTPROC
21913 add $1,%_ASM_AX
21914 +
21915 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21916 jc bad_get_user
21917 GET_THREAD_INFO(%_ASM_DX)
21918 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21919 jae bad_get_user
21920 -2: movzwl -1(%_ASM_AX),%edx
21921 +
21922 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21923 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21924 + cmp %_ASM_DX,%_ASM_AX
21925 + jae 1234f
21926 + add %_ASM_DX,%_ASM_AX
21927 +1234:
21928 +#endif
21929 +
21930 +#endif
21931 +
21932 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
21933 xor %eax,%eax
21934 + pax_force_retaddr
21935 ret
21936 CFI_ENDPROC
21937 ENDPROC(__get_user_2)
21938 @@ -62,12 +99,26 @@ ENDPROC(__get_user_2)
21939 ENTRY(__get_user_4)
21940 CFI_STARTPROC
21941 add $3,%_ASM_AX
21942 +
21943 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21944 jc bad_get_user
21945 GET_THREAD_INFO(%_ASM_DX)
21946 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21947 jae bad_get_user
21948 -3: mov -3(%_ASM_AX),%edx
21949 +
21950 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21951 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21952 + cmp %_ASM_DX,%_ASM_AX
21953 + jae 1234f
21954 + add %_ASM_DX,%_ASM_AX
21955 +1234:
21956 +#endif
21957 +
21958 +#endif
21959 +
21960 +3: __copyuser_seg mov -3(%_ASM_AX),%edx
21961 xor %eax,%eax
21962 + pax_force_retaddr
21963 ret
21964 CFI_ENDPROC
21965 ENDPROC(__get_user_4)
21966 @@ -80,8 +131,18 @@ ENTRY(__get_user_8)
21967 GET_THREAD_INFO(%_ASM_DX)
21968 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21969 jae bad_get_user
21970 +
21971 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21972 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21973 + cmp %_ASM_DX,%_ASM_AX
21974 + jae 1234f
21975 + add %_ASM_DX,%_ASM_AX
21976 +1234:
21977 +#endif
21978 +
21979 4: movq -7(%_ASM_AX),%_ASM_DX
21980 xor %eax,%eax
21981 + pax_force_retaddr
21982 ret
21983 CFI_ENDPROC
21984 ENDPROC(__get_user_8)
21985 @@ -91,6 +152,7 @@ bad_get_user:
21986 CFI_STARTPROC
21987 xor %edx,%edx
21988 mov $(-EFAULT),%_ASM_AX
21989 + pax_force_retaddr
21990 ret
21991 CFI_ENDPROC
21992 END(bad_get_user)
21993 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
21994 index b1e6c4b..21ae8fc 100644
21995 --- a/arch/x86/lib/insn.c
21996 +++ b/arch/x86/lib/insn.c
21997 @@ -21,6 +21,11 @@
21998 #include <linux/string.h>
21999 #include <asm/inat.h>
22000 #include <asm/insn.h>
22001 +#ifdef __KERNEL__
22002 +#include <asm/pgtable_types.h>
22003 +#else
22004 +#define ktla_ktva(addr) addr
22005 +#endif
22006
22007 /* Verify next sizeof(t) bytes can be on the same instruction */
22008 #define validate_next(t, insn, n) \
22009 @@ -49,8 +54,8 @@
22010 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
22011 {
22012 memset(insn, 0, sizeof(*insn));
22013 - insn->kaddr = kaddr;
22014 - insn->next_byte = kaddr;
22015 + insn->kaddr = ktla_ktva(kaddr);
22016 + insn->next_byte = ktla_ktva(kaddr);
22017 insn->x86_64 = x86_64 ? 1 : 0;
22018 insn->opnd_bytes = 4;
22019 if (x86_64)
22020 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
22021 index 05a95e7..326f2fa 100644
22022 --- a/arch/x86/lib/iomap_copy_64.S
22023 +++ b/arch/x86/lib/iomap_copy_64.S
22024 @@ -17,6 +17,7 @@
22025
22026 #include <linux/linkage.h>
22027 #include <asm/dwarf2.h>
22028 +#include <asm/alternative-asm.h>
22029
22030 /*
22031 * override generic version in lib/iomap_copy.c
22032 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
22033 CFI_STARTPROC
22034 movl %edx,%ecx
22035 rep movsd
22036 + pax_force_retaddr
22037 ret
22038 CFI_ENDPROC
22039 ENDPROC(__iowrite32_copy)
22040 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
22041 index 1c273be..da9cc0e 100644
22042 --- a/arch/x86/lib/memcpy_64.S
22043 +++ b/arch/x86/lib/memcpy_64.S
22044 @@ -33,6 +33,7 @@
22045 rep movsq
22046 movl %edx, %ecx
22047 rep movsb
22048 + pax_force_retaddr
22049 ret
22050 .Lmemcpy_e:
22051 .previous
22052 @@ -49,6 +50,7 @@
22053 movq %rdi, %rax
22054 movq %rdx, %rcx
22055 rep movsb
22056 + pax_force_retaddr
22057 ret
22058 .Lmemcpy_e_e:
22059 .previous
22060 @@ -76,13 +78,13 @@ ENTRY(memcpy)
22061 */
22062 movq 0*8(%rsi), %r8
22063 movq 1*8(%rsi), %r9
22064 - movq 2*8(%rsi), %r10
22065 + movq 2*8(%rsi), %rcx
22066 movq 3*8(%rsi), %r11
22067 leaq 4*8(%rsi), %rsi
22068
22069 movq %r8, 0*8(%rdi)
22070 movq %r9, 1*8(%rdi)
22071 - movq %r10, 2*8(%rdi)
22072 + movq %rcx, 2*8(%rdi)
22073 movq %r11, 3*8(%rdi)
22074 leaq 4*8(%rdi), %rdi
22075 jae .Lcopy_forward_loop
22076 @@ -105,12 +107,12 @@ ENTRY(memcpy)
22077 subq $0x20, %rdx
22078 movq -1*8(%rsi), %r8
22079 movq -2*8(%rsi), %r9
22080 - movq -3*8(%rsi), %r10
22081 + movq -3*8(%rsi), %rcx
22082 movq -4*8(%rsi), %r11
22083 leaq -4*8(%rsi), %rsi
22084 movq %r8, -1*8(%rdi)
22085 movq %r9, -2*8(%rdi)
22086 - movq %r10, -3*8(%rdi)
22087 + movq %rcx, -3*8(%rdi)
22088 movq %r11, -4*8(%rdi)
22089 leaq -4*8(%rdi), %rdi
22090 jae .Lcopy_backward_loop
22091 @@ -130,12 +132,13 @@ ENTRY(memcpy)
22092 */
22093 movq 0*8(%rsi), %r8
22094 movq 1*8(%rsi), %r9
22095 - movq -2*8(%rsi, %rdx), %r10
22096 + movq -2*8(%rsi, %rdx), %rcx
22097 movq -1*8(%rsi, %rdx), %r11
22098 movq %r8, 0*8(%rdi)
22099 movq %r9, 1*8(%rdi)
22100 - movq %r10, -2*8(%rdi, %rdx)
22101 + movq %rcx, -2*8(%rdi, %rdx)
22102 movq %r11, -1*8(%rdi, %rdx)
22103 + pax_force_retaddr
22104 retq
22105 .p2align 4
22106 .Lless_16bytes:
22107 @@ -148,6 +151,7 @@ ENTRY(memcpy)
22108 movq -1*8(%rsi, %rdx), %r9
22109 movq %r8, 0*8(%rdi)
22110 movq %r9, -1*8(%rdi, %rdx)
22111 + pax_force_retaddr
22112 retq
22113 .p2align 4
22114 .Lless_8bytes:
22115 @@ -161,6 +165,7 @@ ENTRY(memcpy)
22116 movl -4(%rsi, %rdx), %r8d
22117 movl %ecx, (%rdi)
22118 movl %r8d, -4(%rdi, %rdx)
22119 + pax_force_retaddr
22120 retq
22121 .p2align 4
22122 .Lless_3bytes:
22123 @@ -179,6 +184,7 @@ ENTRY(memcpy)
22124 movb %cl, (%rdi)
22125
22126 .Lend:
22127 + pax_force_retaddr
22128 retq
22129 CFI_ENDPROC
22130 ENDPROC(memcpy)
22131 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
22132 index ee16461..c39c199 100644
22133 --- a/arch/x86/lib/memmove_64.S
22134 +++ b/arch/x86/lib/memmove_64.S
22135 @@ -61,13 +61,13 @@ ENTRY(memmove)
22136 5:
22137 sub $0x20, %rdx
22138 movq 0*8(%rsi), %r11
22139 - movq 1*8(%rsi), %r10
22140 + movq 1*8(%rsi), %rcx
22141 movq 2*8(%rsi), %r9
22142 movq 3*8(%rsi), %r8
22143 leaq 4*8(%rsi), %rsi
22144
22145 movq %r11, 0*8(%rdi)
22146 - movq %r10, 1*8(%rdi)
22147 + movq %rcx, 1*8(%rdi)
22148 movq %r9, 2*8(%rdi)
22149 movq %r8, 3*8(%rdi)
22150 leaq 4*8(%rdi), %rdi
22151 @@ -81,10 +81,10 @@ ENTRY(memmove)
22152 4:
22153 movq %rdx, %rcx
22154 movq -8(%rsi, %rdx), %r11
22155 - lea -8(%rdi, %rdx), %r10
22156 + lea -8(%rdi, %rdx), %r9
22157 shrq $3, %rcx
22158 rep movsq
22159 - movq %r11, (%r10)
22160 + movq %r11, (%r9)
22161 jmp 13f
22162 .Lmemmove_end_forward:
22163
22164 @@ -95,14 +95,14 @@ ENTRY(memmove)
22165 7:
22166 movq %rdx, %rcx
22167 movq (%rsi), %r11
22168 - movq %rdi, %r10
22169 + movq %rdi, %r9
22170 leaq -8(%rsi, %rdx), %rsi
22171 leaq -8(%rdi, %rdx), %rdi
22172 shrq $3, %rcx
22173 std
22174 rep movsq
22175 cld
22176 - movq %r11, (%r10)
22177 + movq %r11, (%r9)
22178 jmp 13f
22179
22180 /*
22181 @@ -127,13 +127,13 @@ ENTRY(memmove)
22182 8:
22183 subq $0x20, %rdx
22184 movq -1*8(%rsi), %r11
22185 - movq -2*8(%rsi), %r10
22186 + movq -2*8(%rsi), %rcx
22187 movq -3*8(%rsi), %r9
22188 movq -4*8(%rsi), %r8
22189 leaq -4*8(%rsi), %rsi
22190
22191 movq %r11, -1*8(%rdi)
22192 - movq %r10, -2*8(%rdi)
22193 + movq %rcx, -2*8(%rdi)
22194 movq %r9, -3*8(%rdi)
22195 movq %r8, -4*8(%rdi)
22196 leaq -4*8(%rdi), %rdi
22197 @@ -151,11 +151,11 @@ ENTRY(memmove)
22198 * Move data from 16 bytes to 31 bytes.
22199 */
22200 movq 0*8(%rsi), %r11
22201 - movq 1*8(%rsi), %r10
22202 + movq 1*8(%rsi), %rcx
22203 movq -2*8(%rsi, %rdx), %r9
22204 movq -1*8(%rsi, %rdx), %r8
22205 movq %r11, 0*8(%rdi)
22206 - movq %r10, 1*8(%rdi)
22207 + movq %rcx, 1*8(%rdi)
22208 movq %r9, -2*8(%rdi, %rdx)
22209 movq %r8, -1*8(%rdi, %rdx)
22210 jmp 13f
22211 @@ -167,9 +167,9 @@ ENTRY(memmove)
22212 * Move data from 8 bytes to 15 bytes.
22213 */
22214 movq 0*8(%rsi), %r11
22215 - movq -1*8(%rsi, %rdx), %r10
22216 + movq -1*8(%rsi, %rdx), %r9
22217 movq %r11, 0*8(%rdi)
22218 - movq %r10, -1*8(%rdi, %rdx)
22219 + movq %r9, -1*8(%rdi, %rdx)
22220 jmp 13f
22221 10:
22222 cmpq $4, %rdx
22223 @@ -178,9 +178,9 @@ ENTRY(memmove)
22224 * Move data from 4 bytes to 7 bytes.
22225 */
22226 movl (%rsi), %r11d
22227 - movl -4(%rsi, %rdx), %r10d
22228 + movl -4(%rsi, %rdx), %r9d
22229 movl %r11d, (%rdi)
22230 - movl %r10d, -4(%rdi, %rdx)
22231 + movl %r9d, -4(%rdi, %rdx)
22232 jmp 13f
22233 11:
22234 cmp $2, %rdx
22235 @@ -189,9 +189,9 @@ ENTRY(memmove)
22236 * Move data from 2 bytes to 3 bytes.
22237 */
22238 movw (%rsi), %r11w
22239 - movw -2(%rsi, %rdx), %r10w
22240 + movw -2(%rsi, %rdx), %r9w
22241 movw %r11w, (%rdi)
22242 - movw %r10w, -2(%rdi, %rdx)
22243 + movw %r9w, -2(%rdi, %rdx)
22244 jmp 13f
22245 12:
22246 cmp $1, %rdx
22247 @@ -202,6 +202,7 @@ ENTRY(memmove)
22248 movb (%rsi), %r11b
22249 movb %r11b, (%rdi)
22250 13:
22251 + pax_force_retaddr
22252 retq
22253 CFI_ENDPROC
22254
22255 @@ -210,6 +211,7 @@ ENTRY(memmove)
22256 /* Forward moving data. */
22257 movq %rdx, %rcx
22258 rep movsb
22259 + pax_force_retaddr
22260 retq
22261 .Lmemmove_end_forward_efs:
22262 .previous
22263 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
22264 index 2dcb380..963660a 100644
22265 --- a/arch/x86/lib/memset_64.S
22266 +++ b/arch/x86/lib/memset_64.S
22267 @@ -30,6 +30,7 @@
22268 movl %edx,%ecx
22269 rep stosb
22270 movq %r9,%rax
22271 + pax_force_retaddr
22272 ret
22273 .Lmemset_e:
22274 .previous
22275 @@ -52,6 +53,7 @@
22276 movq %rdx,%rcx
22277 rep stosb
22278 movq %r9,%rax
22279 + pax_force_retaddr
22280 ret
22281 .Lmemset_e_e:
22282 .previous
22283 @@ -59,7 +61,7 @@
22284 ENTRY(memset)
22285 ENTRY(__memset)
22286 CFI_STARTPROC
22287 - movq %rdi,%r10
22288 + movq %rdi,%r11
22289
22290 /* expand byte value */
22291 movzbl %sil,%ecx
22292 @@ -117,7 +119,8 @@ ENTRY(__memset)
22293 jnz .Lloop_1
22294
22295 .Lende:
22296 - movq %r10,%rax
22297 + movq %r11,%rax
22298 + pax_force_retaddr
22299 ret
22300
22301 CFI_RESTORE_STATE
22302 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
22303 index c9f2d9b..e7fd2c0 100644
22304 --- a/arch/x86/lib/mmx_32.c
22305 +++ b/arch/x86/lib/mmx_32.c
22306 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22307 {
22308 void *p;
22309 int i;
22310 + unsigned long cr0;
22311
22312 if (unlikely(in_interrupt()))
22313 return __memcpy(to, from, len);
22314 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22315 kernel_fpu_begin();
22316
22317 __asm__ __volatile__ (
22318 - "1: prefetch (%0)\n" /* This set is 28 bytes */
22319 - " prefetch 64(%0)\n"
22320 - " prefetch 128(%0)\n"
22321 - " prefetch 192(%0)\n"
22322 - " prefetch 256(%0)\n"
22323 + "1: prefetch (%1)\n" /* This set is 28 bytes */
22324 + " prefetch 64(%1)\n"
22325 + " prefetch 128(%1)\n"
22326 + " prefetch 192(%1)\n"
22327 + " prefetch 256(%1)\n"
22328 "2: \n"
22329 ".section .fixup, \"ax\"\n"
22330 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22331 + "3: \n"
22332 +
22333 +#ifdef CONFIG_PAX_KERNEXEC
22334 + " movl %%cr0, %0\n"
22335 + " movl %0, %%eax\n"
22336 + " andl $0xFFFEFFFF, %%eax\n"
22337 + " movl %%eax, %%cr0\n"
22338 +#endif
22339 +
22340 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22341 +
22342 +#ifdef CONFIG_PAX_KERNEXEC
22343 + " movl %0, %%cr0\n"
22344 +#endif
22345 +
22346 " jmp 2b\n"
22347 ".previous\n"
22348 _ASM_EXTABLE(1b, 3b)
22349 - : : "r" (from));
22350 + : "=&r" (cr0) : "r" (from) : "ax");
22351
22352 for ( ; i > 5; i--) {
22353 __asm__ __volatile__ (
22354 - "1: prefetch 320(%0)\n"
22355 - "2: movq (%0), %%mm0\n"
22356 - " movq 8(%0), %%mm1\n"
22357 - " movq 16(%0), %%mm2\n"
22358 - " movq 24(%0), %%mm3\n"
22359 - " movq %%mm0, (%1)\n"
22360 - " movq %%mm1, 8(%1)\n"
22361 - " movq %%mm2, 16(%1)\n"
22362 - " movq %%mm3, 24(%1)\n"
22363 - " movq 32(%0), %%mm0\n"
22364 - " movq 40(%0), %%mm1\n"
22365 - " movq 48(%0), %%mm2\n"
22366 - " movq 56(%0), %%mm3\n"
22367 - " movq %%mm0, 32(%1)\n"
22368 - " movq %%mm1, 40(%1)\n"
22369 - " movq %%mm2, 48(%1)\n"
22370 - " movq %%mm3, 56(%1)\n"
22371 + "1: prefetch 320(%1)\n"
22372 + "2: movq (%1), %%mm0\n"
22373 + " movq 8(%1), %%mm1\n"
22374 + " movq 16(%1), %%mm2\n"
22375 + " movq 24(%1), %%mm3\n"
22376 + " movq %%mm0, (%2)\n"
22377 + " movq %%mm1, 8(%2)\n"
22378 + " movq %%mm2, 16(%2)\n"
22379 + " movq %%mm3, 24(%2)\n"
22380 + " movq 32(%1), %%mm0\n"
22381 + " movq 40(%1), %%mm1\n"
22382 + " movq 48(%1), %%mm2\n"
22383 + " movq 56(%1), %%mm3\n"
22384 + " movq %%mm0, 32(%2)\n"
22385 + " movq %%mm1, 40(%2)\n"
22386 + " movq %%mm2, 48(%2)\n"
22387 + " movq %%mm3, 56(%2)\n"
22388 ".section .fixup, \"ax\"\n"
22389 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22390 + "3:\n"
22391 +
22392 +#ifdef CONFIG_PAX_KERNEXEC
22393 + " movl %%cr0, %0\n"
22394 + " movl %0, %%eax\n"
22395 + " andl $0xFFFEFFFF, %%eax\n"
22396 + " movl %%eax, %%cr0\n"
22397 +#endif
22398 +
22399 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22400 +
22401 +#ifdef CONFIG_PAX_KERNEXEC
22402 + " movl %0, %%cr0\n"
22403 +#endif
22404 +
22405 " jmp 2b\n"
22406 ".previous\n"
22407 _ASM_EXTABLE(1b, 3b)
22408 - : : "r" (from), "r" (to) : "memory");
22409 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22410
22411 from += 64;
22412 to += 64;
22413 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
22414 static void fast_copy_page(void *to, void *from)
22415 {
22416 int i;
22417 + unsigned long cr0;
22418
22419 kernel_fpu_begin();
22420
22421 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
22422 * but that is for later. -AV
22423 */
22424 __asm__ __volatile__(
22425 - "1: prefetch (%0)\n"
22426 - " prefetch 64(%0)\n"
22427 - " prefetch 128(%0)\n"
22428 - " prefetch 192(%0)\n"
22429 - " prefetch 256(%0)\n"
22430 + "1: prefetch (%1)\n"
22431 + " prefetch 64(%1)\n"
22432 + " prefetch 128(%1)\n"
22433 + " prefetch 192(%1)\n"
22434 + " prefetch 256(%1)\n"
22435 "2: \n"
22436 ".section .fixup, \"ax\"\n"
22437 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22438 + "3: \n"
22439 +
22440 +#ifdef CONFIG_PAX_KERNEXEC
22441 + " movl %%cr0, %0\n"
22442 + " movl %0, %%eax\n"
22443 + " andl $0xFFFEFFFF, %%eax\n"
22444 + " movl %%eax, %%cr0\n"
22445 +#endif
22446 +
22447 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22448 +
22449 +#ifdef CONFIG_PAX_KERNEXEC
22450 + " movl %0, %%cr0\n"
22451 +#endif
22452 +
22453 " jmp 2b\n"
22454 ".previous\n"
22455 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
22456 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22457
22458 for (i = 0; i < (4096-320)/64; i++) {
22459 __asm__ __volatile__ (
22460 - "1: prefetch 320(%0)\n"
22461 - "2: movq (%0), %%mm0\n"
22462 - " movntq %%mm0, (%1)\n"
22463 - " movq 8(%0), %%mm1\n"
22464 - " movntq %%mm1, 8(%1)\n"
22465 - " movq 16(%0), %%mm2\n"
22466 - " movntq %%mm2, 16(%1)\n"
22467 - " movq 24(%0), %%mm3\n"
22468 - " movntq %%mm3, 24(%1)\n"
22469 - " movq 32(%0), %%mm4\n"
22470 - " movntq %%mm4, 32(%1)\n"
22471 - " movq 40(%0), %%mm5\n"
22472 - " movntq %%mm5, 40(%1)\n"
22473 - " movq 48(%0), %%mm6\n"
22474 - " movntq %%mm6, 48(%1)\n"
22475 - " movq 56(%0), %%mm7\n"
22476 - " movntq %%mm7, 56(%1)\n"
22477 + "1: prefetch 320(%1)\n"
22478 + "2: movq (%1), %%mm0\n"
22479 + " movntq %%mm0, (%2)\n"
22480 + " movq 8(%1), %%mm1\n"
22481 + " movntq %%mm1, 8(%2)\n"
22482 + " movq 16(%1), %%mm2\n"
22483 + " movntq %%mm2, 16(%2)\n"
22484 + " movq 24(%1), %%mm3\n"
22485 + " movntq %%mm3, 24(%2)\n"
22486 + " movq 32(%1), %%mm4\n"
22487 + " movntq %%mm4, 32(%2)\n"
22488 + " movq 40(%1), %%mm5\n"
22489 + " movntq %%mm5, 40(%2)\n"
22490 + " movq 48(%1), %%mm6\n"
22491 + " movntq %%mm6, 48(%2)\n"
22492 + " movq 56(%1), %%mm7\n"
22493 + " movntq %%mm7, 56(%2)\n"
22494 ".section .fixup, \"ax\"\n"
22495 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22496 + "3:\n"
22497 +
22498 +#ifdef CONFIG_PAX_KERNEXEC
22499 + " movl %%cr0, %0\n"
22500 + " movl %0, %%eax\n"
22501 + " andl $0xFFFEFFFF, %%eax\n"
22502 + " movl %%eax, %%cr0\n"
22503 +#endif
22504 +
22505 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22506 +
22507 +#ifdef CONFIG_PAX_KERNEXEC
22508 + " movl %0, %%cr0\n"
22509 +#endif
22510 +
22511 " jmp 2b\n"
22512 ".previous\n"
22513 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
22514 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22515
22516 from += 64;
22517 to += 64;
22518 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
22519 static void fast_copy_page(void *to, void *from)
22520 {
22521 int i;
22522 + unsigned long cr0;
22523
22524 kernel_fpu_begin();
22525
22526 __asm__ __volatile__ (
22527 - "1: prefetch (%0)\n"
22528 - " prefetch 64(%0)\n"
22529 - " prefetch 128(%0)\n"
22530 - " prefetch 192(%0)\n"
22531 - " prefetch 256(%0)\n"
22532 + "1: prefetch (%1)\n"
22533 + " prefetch 64(%1)\n"
22534 + " prefetch 128(%1)\n"
22535 + " prefetch 192(%1)\n"
22536 + " prefetch 256(%1)\n"
22537 "2: \n"
22538 ".section .fixup, \"ax\"\n"
22539 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22540 + "3: \n"
22541 +
22542 +#ifdef CONFIG_PAX_KERNEXEC
22543 + " movl %%cr0, %0\n"
22544 + " movl %0, %%eax\n"
22545 + " andl $0xFFFEFFFF, %%eax\n"
22546 + " movl %%eax, %%cr0\n"
22547 +#endif
22548 +
22549 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22550 +
22551 +#ifdef CONFIG_PAX_KERNEXEC
22552 + " movl %0, %%cr0\n"
22553 +#endif
22554 +
22555 " jmp 2b\n"
22556 ".previous\n"
22557 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
22558 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22559
22560 for (i = 0; i < 4096/64; i++) {
22561 __asm__ __volatile__ (
22562 - "1: prefetch 320(%0)\n"
22563 - "2: movq (%0), %%mm0\n"
22564 - " movq 8(%0), %%mm1\n"
22565 - " movq 16(%0), %%mm2\n"
22566 - " movq 24(%0), %%mm3\n"
22567 - " movq %%mm0, (%1)\n"
22568 - " movq %%mm1, 8(%1)\n"
22569 - " movq %%mm2, 16(%1)\n"
22570 - " movq %%mm3, 24(%1)\n"
22571 - " movq 32(%0), %%mm0\n"
22572 - " movq 40(%0), %%mm1\n"
22573 - " movq 48(%0), %%mm2\n"
22574 - " movq 56(%0), %%mm3\n"
22575 - " movq %%mm0, 32(%1)\n"
22576 - " movq %%mm1, 40(%1)\n"
22577 - " movq %%mm2, 48(%1)\n"
22578 - " movq %%mm3, 56(%1)\n"
22579 + "1: prefetch 320(%1)\n"
22580 + "2: movq (%1), %%mm0\n"
22581 + " movq 8(%1), %%mm1\n"
22582 + " movq 16(%1), %%mm2\n"
22583 + " movq 24(%1), %%mm3\n"
22584 + " movq %%mm0, (%2)\n"
22585 + " movq %%mm1, 8(%2)\n"
22586 + " movq %%mm2, 16(%2)\n"
22587 + " movq %%mm3, 24(%2)\n"
22588 + " movq 32(%1), %%mm0\n"
22589 + " movq 40(%1), %%mm1\n"
22590 + " movq 48(%1), %%mm2\n"
22591 + " movq 56(%1), %%mm3\n"
22592 + " movq %%mm0, 32(%2)\n"
22593 + " movq %%mm1, 40(%2)\n"
22594 + " movq %%mm2, 48(%2)\n"
22595 + " movq %%mm3, 56(%2)\n"
22596 ".section .fixup, \"ax\"\n"
22597 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22598 + "3:\n"
22599 +
22600 +#ifdef CONFIG_PAX_KERNEXEC
22601 + " movl %%cr0, %0\n"
22602 + " movl %0, %%eax\n"
22603 + " andl $0xFFFEFFFF, %%eax\n"
22604 + " movl %%eax, %%cr0\n"
22605 +#endif
22606 +
22607 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22608 +
22609 +#ifdef CONFIG_PAX_KERNEXEC
22610 + " movl %0, %%cr0\n"
22611 +#endif
22612 +
22613 " jmp 2b\n"
22614 ".previous\n"
22615 _ASM_EXTABLE(1b, 3b)
22616 - : : "r" (from), "r" (to) : "memory");
22617 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22618
22619 from += 64;
22620 to += 64;
22621 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
22622 index f6d13ee..aca5f0b 100644
22623 --- a/arch/x86/lib/msr-reg.S
22624 +++ b/arch/x86/lib/msr-reg.S
22625 @@ -3,6 +3,7 @@
22626 #include <asm/dwarf2.h>
22627 #include <asm/asm.h>
22628 #include <asm/msr.h>
22629 +#include <asm/alternative-asm.h>
22630
22631 #ifdef CONFIG_X86_64
22632 /*
22633 @@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
22634 CFI_STARTPROC
22635 pushq_cfi %rbx
22636 pushq_cfi %rbp
22637 - movq %rdi, %r10 /* Save pointer */
22638 + movq %rdi, %r9 /* Save pointer */
22639 xorl %r11d, %r11d /* Return value */
22640 movl (%rdi), %eax
22641 movl 4(%rdi), %ecx
22642 @@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
22643 movl 28(%rdi), %edi
22644 CFI_REMEMBER_STATE
22645 1: \op
22646 -2: movl %eax, (%r10)
22647 +2: movl %eax, (%r9)
22648 movl %r11d, %eax /* Return value */
22649 - movl %ecx, 4(%r10)
22650 - movl %edx, 8(%r10)
22651 - movl %ebx, 12(%r10)
22652 - movl %ebp, 20(%r10)
22653 - movl %esi, 24(%r10)
22654 - movl %edi, 28(%r10)
22655 + movl %ecx, 4(%r9)
22656 + movl %edx, 8(%r9)
22657 + movl %ebx, 12(%r9)
22658 + movl %ebp, 20(%r9)
22659 + movl %esi, 24(%r9)
22660 + movl %edi, 28(%r9)
22661 popq_cfi %rbp
22662 popq_cfi %rbx
22663 + pax_force_retaddr
22664 ret
22665 3:
22666 CFI_RESTORE_STATE
22667 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
22668 index 7f951c8..ebd573a 100644
22669 --- a/arch/x86/lib/putuser.S
22670 +++ b/arch/x86/lib/putuser.S
22671 @@ -15,7 +15,9 @@
22672 #include <asm/thread_info.h>
22673 #include <asm/errno.h>
22674 #include <asm/asm.h>
22675 -
22676 +#include <asm/segment.h>
22677 +#include <asm/pgtable.h>
22678 +#include <asm/alternative-asm.h>
22679
22680 /*
22681 * __put_user_X
22682 @@ -29,52 +31,119 @@
22683 * as they get called from within inline assembly.
22684 */
22685
22686 -#define ENTER CFI_STARTPROC ; \
22687 - GET_THREAD_INFO(%_ASM_BX)
22688 -#define EXIT ret ; \
22689 +#define ENTER CFI_STARTPROC
22690 +#define EXIT pax_force_retaddr; ret ; \
22691 CFI_ENDPROC
22692
22693 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22694 +#define _DEST %_ASM_CX,%_ASM_BX
22695 +#else
22696 +#define _DEST %_ASM_CX
22697 +#endif
22698 +
22699 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
22700 +#define __copyuser_seg gs;
22701 +#else
22702 +#define __copyuser_seg
22703 +#endif
22704 +
22705 .text
22706 ENTRY(__put_user_1)
22707 ENTER
22708 +
22709 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22710 + GET_THREAD_INFO(%_ASM_BX)
22711 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
22712 jae bad_put_user
22713 -1: movb %al,(%_ASM_CX)
22714 +
22715 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22716 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22717 + cmp %_ASM_BX,%_ASM_CX
22718 + jb 1234f
22719 + xor %ebx,%ebx
22720 +1234:
22721 +#endif
22722 +
22723 +#endif
22724 +
22725 +1: __copyuser_seg movb %al,(_DEST)
22726 xor %eax,%eax
22727 EXIT
22728 ENDPROC(__put_user_1)
22729
22730 ENTRY(__put_user_2)
22731 ENTER
22732 +
22733 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22734 + GET_THREAD_INFO(%_ASM_BX)
22735 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22736 sub $1,%_ASM_BX
22737 cmp %_ASM_BX,%_ASM_CX
22738 jae bad_put_user
22739 -2: movw %ax,(%_ASM_CX)
22740 +
22741 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22742 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22743 + cmp %_ASM_BX,%_ASM_CX
22744 + jb 1234f
22745 + xor %ebx,%ebx
22746 +1234:
22747 +#endif
22748 +
22749 +#endif
22750 +
22751 +2: __copyuser_seg movw %ax,(_DEST)
22752 xor %eax,%eax
22753 EXIT
22754 ENDPROC(__put_user_2)
22755
22756 ENTRY(__put_user_4)
22757 ENTER
22758 +
22759 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22760 + GET_THREAD_INFO(%_ASM_BX)
22761 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22762 sub $3,%_ASM_BX
22763 cmp %_ASM_BX,%_ASM_CX
22764 jae bad_put_user
22765 -3: movl %eax,(%_ASM_CX)
22766 +
22767 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22768 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22769 + cmp %_ASM_BX,%_ASM_CX
22770 + jb 1234f
22771 + xor %ebx,%ebx
22772 +1234:
22773 +#endif
22774 +
22775 +#endif
22776 +
22777 +3: __copyuser_seg movl %eax,(_DEST)
22778 xor %eax,%eax
22779 EXIT
22780 ENDPROC(__put_user_4)
22781
22782 ENTRY(__put_user_8)
22783 ENTER
22784 +
22785 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22786 + GET_THREAD_INFO(%_ASM_BX)
22787 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22788 sub $7,%_ASM_BX
22789 cmp %_ASM_BX,%_ASM_CX
22790 jae bad_put_user
22791 -4: mov %_ASM_AX,(%_ASM_CX)
22792 +
22793 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22794 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22795 + cmp %_ASM_BX,%_ASM_CX
22796 + jb 1234f
22797 + xor %ebx,%ebx
22798 +1234:
22799 +#endif
22800 +
22801 +#endif
22802 +
22803 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
22804 #ifdef CONFIG_X86_32
22805 -5: movl %edx,4(%_ASM_CX)
22806 +5: __copyuser_seg movl %edx,4(_DEST)
22807 #endif
22808 xor %eax,%eax
22809 EXIT
22810 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
22811 index 1cad221..de671ee 100644
22812 --- a/arch/x86/lib/rwlock.S
22813 +++ b/arch/x86/lib/rwlock.S
22814 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
22815 FRAME
22816 0: LOCK_PREFIX
22817 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22818 +
22819 +#ifdef CONFIG_PAX_REFCOUNT
22820 + jno 1234f
22821 + LOCK_PREFIX
22822 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22823 + int $4
22824 +1234:
22825 + _ASM_EXTABLE(1234b, 1234b)
22826 +#endif
22827 +
22828 1: rep; nop
22829 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
22830 jne 1b
22831 LOCK_PREFIX
22832 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22833 +
22834 +#ifdef CONFIG_PAX_REFCOUNT
22835 + jno 1234f
22836 + LOCK_PREFIX
22837 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22838 + int $4
22839 +1234:
22840 + _ASM_EXTABLE(1234b, 1234b)
22841 +#endif
22842 +
22843 jnz 0b
22844 ENDFRAME
22845 + pax_force_retaddr
22846 ret
22847 CFI_ENDPROC
22848 END(__write_lock_failed)
22849 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
22850 FRAME
22851 0: LOCK_PREFIX
22852 READ_LOCK_SIZE(inc) (%__lock_ptr)
22853 +
22854 +#ifdef CONFIG_PAX_REFCOUNT
22855 + jno 1234f
22856 + LOCK_PREFIX
22857 + READ_LOCK_SIZE(dec) (%__lock_ptr)
22858 + int $4
22859 +1234:
22860 + _ASM_EXTABLE(1234b, 1234b)
22861 +#endif
22862 +
22863 1: rep; nop
22864 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
22865 js 1b
22866 LOCK_PREFIX
22867 READ_LOCK_SIZE(dec) (%__lock_ptr)
22868 +
22869 +#ifdef CONFIG_PAX_REFCOUNT
22870 + jno 1234f
22871 + LOCK_PREFIX
22872 + READ_LOCK_SIZE(inc) (%__lock_ptr)
22873 + int $4
22874 +1234:
22875 + _ASM_EXTABLE(1234b, 1234b)
22876 +#endif
22877 +
22878 js 0b
22879 ENDFRAME
22880 + pax_force_retaddr
22881 ret
22882 CFI_ENDPROC
22883 END(__read_lock_failed)
22884 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
22885 index 5dff5f0..cadebf4 100644
22886 --- a/arch/x86/lib/rwsem.S
22887 +++ b/arch/x86/lib/rwsem.S
22888 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
22889 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22890 CFI_RESTORE __ASM_REG(dx)
22891 restore_common_regs
22892 + pax_force_retaddr
22893 ret
22894 CFI_ENDPROC
22895 ENDPROC(call_rwsem_down_read_failed)
22896 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
22897 movq %rax,%rdi
22898 call rwsem_down_write_failed
22899 restore_common_regs
22900 + pax_force_retaddr
22901 ret
22902 CFI_ENDPROC
22903 ENDPROC(call_rwsem_down_write_failed)
22904 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
22905 movq %rax,%rdi
22906 call rwsem_wake
22907 restore_common_regs
22908 -1: ret
22909 +1: pax_force_retaddr
22910 + ret
22911 CFI_ENDPROC
22912 ENDPROC(call_rwsem_wake)
22913
22914 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
22915 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22916 CFI_RESTORE __ASM_REG(dx)
22917 restore_common_regs
22918 + pax_force_retaddr
22919 ret
22920 CFI_ENDPROC
22921 ENDPROC(call_rwsem_downgrade_wake)
22922 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
22923 index a63efd6..ccecad8 100644
22924 --- a/arch/x86/lib/thunk_64.S
22925 +++ b/arch/x86/lib/thunk_64.S
22926 @@ -8,6 +8,7 @@
22927 #include <linux/linkage.h>
22928 #include <asm/dwarf2.h>
22929 #include <asm/calling.h>
22930 +#include <asm/alternative-asm.h>
22931
22932 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
22933 .macro THUNK name, func, put_ret_addr_in_rdi=0
22934 @@ -41,5 +42,6 @@
22935 SAVE_ARGS
22936 restore:
22937 RESTORE_ARGS
22938 + pax_force_retaddr
22939 ret
22940 CFI_ENDPROC
22941 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
22942 index 1781b2f..90368dd 100644
22943 --- a/arch/x86/lib/usercopy_32.c
22944 +++ b/arch/x86/lib/usercopy_32.c
22945 @@ -42,10 +42,12 @@ do { \
22946 int __d0; \
22947 might_fault(); \
22948 __asm__ __volatile__( \
22949 + __COPYUSER_SET_ES \
22950 "0: rep; stosl\n" \
22951 " movl %2,%0\n" \
22952 "1: rep; stosb\n" \
22953 "2:\n" \
22954 + __COPYUSER_RESTORE_ES \
22955 ".section .fixup,\"ax\"\n" \
22956 "3: lea 0(%2,%0,4),%0\n" \
22957 " jmp 2b\n" \
22958 @@ -97,7 +99,7 @@ EXPORT_SYMBOL(__clear_user);
22959
22960 #ifdef CONFIG_X86_INTEL_USERCOPY
22961 static unsigned long
22962 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
22963 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
22964 {
22965 int d0, d1;
22966 __asm__ __volatile__(
22967 @@ -109,36 +111,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22968 " .align 2,0x90\n"
22969 "3: movl 0(%4), %%eax\n"
22970 "4: movl 4(%4), %%edx\n"
22971 - "5: movl %%eax, 0(%3)\n"
22972 - "6: movl %%edx, 4(%3)\n"
22973 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
22974 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
22975 "7: movl 8(%4), %%eax\n"
22976 "8: movl 12(%4),%%edx\n"
22977 - "9: movl %%eax, 8(%3)\n"
22978 - "10: movl %%edx, 12(%3)\n"
22979 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
22980 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
22981 "11: movl 16(%4), %%eax\n"
22982 "12: movl 20(%4), %%edx\n"
22983 - "13: movl %%eax, 16(%3)\n"
22984 - "14: movl %%edx, 20(%3)\n"
22985 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
22986 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
22987 "15: movl 24(%4), %%eax\n"
22988 "16: movl 28(%4), %%edx\n"
22989 - "17: movl %%eax, 24(%3)\n"
22990 - "18: movl %%edx, 28(%3)\n"
22991 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
22992 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
22993 "19: movl 32(%4), %%eax\n"
22994 "20: movl 36(%4), %%edx\n"
22995 - "21: movl %%eax, 32(%3)\n"
22996 - "22: movl %%edx, 36(%3)\n"
22997 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
22998 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
22999 "23: movl 40(%4), %%eax\n"
23000 "24: movl 44(%4), %%edx\n"
23001 - "25: movl %%eax, 40(%3)\n"
23002 - "26: movl %%edx, 44(%3)\n"
23003 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
23004 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
23005 "27: movl 48(%4), %%eax\n"
23006 "28: movl 52(%4), %%edx\n"
23007 - "29: movl %%eax, 48(%3)\n"
23008 - "30: movl %%edx, 52(%3)\n"
23009 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
23010 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
23011 "31: movl 56(%4), %%eax\n"
23012 "32: movl 60(%4), %%edx\n"
23013 - "33: movl %%eax, 56(%3)\n"
23014 - "34: movl %%edx, 60(%3)\n"
23015 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
23016 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
23017 " addl $-64, %0\n"
23018 " addl $64, %4\n"
23019 " addl $64, %3\n"
23020 @@ -148,10 +150,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
23021 " shrl $2, %0\n"
23022 " andl $3, %%eax\n"
23023 " cld\n"
23024 + __COPYUSER_SET_ES
23025 "99: rep; movsl\n"
23026 "36: movl %%eax, %0\n"
23027 "37: rep; movsb\n"
23028 "100:\n"
23029 + __COPYUSER_RESTORE_ES
23030 ".section .fixup,\"ax\"\n"
23031 "101: lea 0(%%eax,%0,4),%0\n"
23032 " jmp 100b\n"
23033 @@ -201,46 +205,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
23034 }
23035
23036 static unsigned long
23037 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
23038 +{
23039 + int d0, d1;
23040 + __asm__ __volatile__(
23041 + " .align 2,0x90\n"
23042 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
23043 + " cmpl $67, %0\n"
23044 + " jbe 3f\n"
23045 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
23046 + " .align 2,0x90\n"
23047 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
23048 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
23049 + "5: movl %%eax, 0(%3)\n"
23050 + "6: movl %%edx, 4(%3)\n"
23051 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
23052 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
23053 + "9: movl %%eax, 8(%3)\n"
23054 + "10: movl %%edx, 12(%3)\n"
23055 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
23056 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
23057 + "13: movl %%eax, 16(%3)\n"
23058 + "14: movl %%edx, 20(%3)\n"
23059 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
23060 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
23061 + "17: movl %%eax, 24(%3)\n"
23062 + "18: movl %%edx, 28(%3)\n"
23063 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
23064 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
23065 + "21: movl %%eax, 32(%3)\n"
23066 + "22: movl %%edx, 36(%3)\n"
23067 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
23068 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
23069 + "25: movl %%eax, 40(%3)\n"
23070 + "26: movl %%edx, 44(%3)\n"
23071 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
23072 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
23073 + "29: movl %%eax, 48(%3)\n"
23074 + "30: movl %%edx, 52(%3)\n"
23075 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
23076 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
23077 + "33: movl %%eax, 56(%3)\n"
23078 + "34: movl %%edx, 60(%3)\n"
23079 + " addl $-64, %0\n"
23080 + " addl $64, %4\n"
23081 + " addl $64, %3\n"
23082 + " cmpl $63, %0\n"
23083 + " ja 1b\n"
23084 + "35: movl %0, %%eax\n"
23085 + " shrl $2, %0\n"
23086 + " andl $3, %%eax\n"
23087 + " cld\n"
23088 + "99: rep; "__copyuser_seg" movsl\n"
23089 + "36: movl %%eax, %0\n"
23090 + "37: rep; "__copyuser_seg" movsb\n"
23091 + "100:\n"
23092 + ".section .fixup,\"ax\"\n"
23093 + "101: lea 0(%%eax,%0,4),%0\n"
23094 + " jmp 100b\n"
23095 + ".previous\n"
23096 + _ASM_EXTABLE(1b,100b)
23097 + _ASM_EXTABLE(2b,100b)
23098 + _ASM_EXTABLE(3b,100b)
23099 + _ASM_EXTABLE(4b,100b)
23100 + _ASM_EXTABLE(5b,100b)
23101 + _ASM_EXTABLE(6b,100b)
23102 + _ASM_EXTABLE(7b,100b)
23103 + _ASM_EXTABLE(8b,100b)
23104 + _ASM_EXTABLE(9b,100b)
23105 + _ASM_EXTABLE(10b,100b)
23106 + _ASM_EXTABLE(11b,100b)
23107 + _ASM_EXTABLE(12b,100b)
23108 + _ASM_EXTABLE(13b,100b)
23109 + _ASM_EXTABLE(14b,100b)
23110 + _ASM_EXTABLE(15b,100b)
23111 + _ASM_EXTABLE(16b,100b)
23112 + _ASM_EXTABLE(17b,100b)
23113 + _ASM_EXTABLE(18b,100b)
23114 + _ASM_EXTABLE(19b,100b)
23115 + _ASM_EXTABLE(20b,100b)
23116 + _ASM_EXTABLE(21b,100b)
23117 + _ASM_EXTABLE(22b,100b)
23118 + _ASM_EXTABLE(23b,100b)
23119 + _ASM_EXTABLE(24b,100b)
23120 + _ASM_EXTABLE(25b,100b)
23121 + _ASM_EXTABLE(26b,100b)
23122 + _ASM_EXTABLE(27b,100b)
23123 + _ASM_EXTABLE(28b,100b)
23124 + _ASM_EXTABLE(29b,100b)
23125 + _ASM_EXTABLE(30b,100b)
23126 + _ASM_EXTABLE(31b,100b)
23127 + _ASM_EXTABLE(32b,100b)
23128 + _ASM_EXTABLE(33b,100b)
23129 + _ASM_EXTABLE(34b,100b)
23130 + _ASM_EXTABLE(35b,100b)
23131 + _ASM_EXTABLE(36b,100b)
23132 + _ASM_EXTABLE(37b,100b)
23133 + _ASM_EXTABLE(99b,101b)
23134 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
23135 + : "1"(to), "2"(from), "0"(size)
23136 + : "eax", "edx", "memory");
23137 + return size;
23138 +}
23139 +
23140 +static unsigned long __size_overflow(3)
23141 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23142 {
23143 int d0, d1;
23144 __asm__ __volatile__(
23145 " .align 2,0x90\n"
23146 - "0: movl 32(%4), %%eax\n"
23147 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23148 " cmpl $67, %0\n"
23149 " jbe 2f\n"
23150 - "1: movl 64(%4), %%eax\n"
23151 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23152 " .align 2,0x90\n"
23153 - "2: movl 0(%4), %%eax\n"
23154 - "21: movl 4(%4), %%edx\n"
23155 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23156 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23157 " movl %%eax, 0(%3)\n"
23158 " movl %%edx, 4(%3)\n"
23159 - "3: movl 8(%4), %%eax\n"
23160 - "31: movl 12(%4),%%edx\n"
23161 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23162 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23163 " movl %%eax, 8(%3)\n"
23164 " movl %%edx, 12(%3)\n"
23165 - "4: movl 16(%4), %%eax\n"
23166 - "41: movl 20(%4), %%edx\n"
23167 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23168 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23169 " movl %%eax, 16(%3)\n"
23170 " movl %%edx, 20(%3)\n"
23171 - "10: movl 24(%4), %%eax\n"
23172 - "51: movl 28(%4), %%edx\n"
23173 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23174 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23175 " movl %%eax, 24(%3)\n"
23176 " movl %%edx, 28(%3)\n"
23177 - "11: movl 32(%4), %%eax\n"
23178 - "61: movl 36(%4), %%edx\n"
23179 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23180 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23181 " movl %%eax, 32(%3)\n"
23182 " movl %%edx, 36(%3)\n"
23183 - "12: movl 40(%4), %%eax\n"
23184 - "71: movl 44(%4), %%edx\n"
23185 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23186 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23187 " movl %%eax, 40(%3)\n"
23188 " movl %%edx, 44(%3)\n"
23189 - "13: movl 48(%4), %%eax\n"
23190 - "81: movl 52(%4), %%edx\n"
23191 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23192 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23193 " movl %%eax, 48(%3)\n"
23194 " movl %%edx, 52(%3)\n"
23195 - "14: movl 56(%4), %%eax\n"
23196 - "91: movl 60(%4), %%edx\n"
23197 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23198 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23199 " movl %%eax, 56(%3)\n"
23200 " movl %%edx, 60(%3)\n"
23201 " addl $-64, %0\n"
23202 @@ -252,9 +360,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23203 " shrl $2, %0\n"
23204 " andl $3, %%eax\n"
23205 " cld\n"
23206 - "6: rep; movsl\n"
23207 + "6: rep; "__copyuser_seg" movsl\n"
23208 " movl %%eax,%0\n"
23209 - "7: rep; movsb\n"
23210 + "7: rep; "__copyuser_seg" movsb\n"
23211 "8:\n"
23212 ".section .fixup,\"ax\"\n"
23213 "9: lea 0(%%eax,%0,4),%0\n"
23214 @@ -297,48 +405,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23215 * hyoshiok@miraclelinux.com
23216 */
23217
23218 -static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23219 +static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
23220 const void __user *from, unsigned long size)
23221 {
23222 int d0, d1;
23223
23224 __asm__ __volatile__(
23225 " .align 2,0x90\n"
23226 - "0: movl 32(%4), %%eax\n"
23227 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23228 " cmpl $67, %0\n"
23229 " jbe 2f\n"
23230 - "1: movl 64(%4), %%eax\n"
23231 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23232 " .align 2,0x90\n"
23233 - "2: movl 0(%4), %%eax\n"
23234 - "21: movl 4(%4), %%edx\n"
23235 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23236 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23237 " movnti %%eax, 0(%3)\n"
23238 " movnti %%edx, 4(%3)\n"
23239 - "3: movl 8(%4), %%eax\n"
23240 - "31: movl 12(%4),%%edx\n"
23241 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23242 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23243 " movnti %%eax, 8(%3)\n"
23244 " movnti %%edx, 12(%3)\n"
23245 - "4: movl 16(%4), %%eax\n"
23246 - "41: movl 20(%4), %%edx\n"
23247 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23248 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23249 " movnti %%eax, 16(%3)\n"
23250 " movnti %%edx, 20(%3)\n"
23251 - "10: movl 24(%4), %%eax\n"
23252 - "51: movl 28(%4), %%edx\n"
23253 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23254 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23255 " movnti %%eax, 24(%3)\n"
23256 " movnti %%edx, 28(%3)\n"
23257 - "11: movl 32(%4), %%eax\n"
23258 - "61: movl 36(%4), %%edx\n"
23259 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23260 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23261 " movnti %%eax, 32(%3)\n"
23262 " movnti %%edx, 36(%3)\n"
23263 - "12: movl 40(%4), %%eax\n"
23264 - "71: movl 44(%4), %%edx\n"
23265 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23266 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23267 " movnti %%eax, 40(%3)\n"
23268 " movnti %%edx, 44(%3)\n"
23269 - "13: movl 48(%4), %%eax\n"
23270 - "81: movl 52(%4), %%edx\n"
23271 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23272 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23273 " movnti %%eax, 48(%3)\n"
23274 " movnti %%edx, 52(%3)\n"
23275 - "14: movl 56(%4), %%eax\n"
23276 - "91: movl 60(%4), %%edx\n"
23277 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23278 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23279 " movnti %%eax, 56(%3)\n"
23280 " movnti %%edx, 60(%3)\n"
23281 " addl $-64, %0\n"
23282 @@ -351,9 +459,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23283 " shrl $2, %0\n"
23284 " andl $3, %%eax\n"
23285 " cld\n"
23286 - "6: rep; movsl\n"
23287 + "6: rep; "__copyuser_seg" movsl\n"
23288 " movl %%eax,%0\n"
23289 - "7: rep; movsb\n"
23290 + "7: rep; "__copyuser_seg" movsb\n"
23291 "8:\n"
23292 ".section .fixup,\"ax\"\n"
23293 "9: lea 0(%%eax,%0,4),%0\n"
23294 @@ -391,48 +499,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23295 return size;
23296 }
23297
23298 -static unsigned long __copy_user_intel_nocache(void *to,
23299 +static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
23300 const void __user *from, unsigned long size)
23301 {
23302 int d0, d1;
23303
23304 __asm__ __volatile__(
23305 " .align 2,0x90\n"
23306 - "0: movl 32(%4), %%eax\n"
23307 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23308 " cmpl $67, %0\n"
23309 " jbe 2f\n"
23310 - "1: movl 64(%4), %%eax\n"
23311 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23312 " .align 2,0x90\n"
23313 - "2: movl 0(%4), %%eax\n"
23314 - "21: movl 4(%4), %%edx\n"
23315 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23316 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23317 " movnti %%eax, 0(%3)\n"
23318 " movnti %%edx, 4(%3)\n"
23319 - "3: movl 8(%4), %%eax\n"
23320 - "31: movl 12(%4),%%edx\n"
23321 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23322 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23323 " movnti %%eax, 8(%3)\n"
23324 " movnti %%edx, 12(%3)\n"
23325 - "4: movl 16(%4), %%eax\n"
23326 - "41: movl 20(%4), %%edx\n"
23327 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23328 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23329 " movnti %%eax, 16(%3)\n"
23330 " movnti %%edx, 20(%3)\n"
23331 - "10: movl 24(%4), %%eax\n"
23332 - "51: movl 28(%4), %%edx\n"
23333 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23334 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23335 " movnti %%eax, 24(%3)\n"
23336 " movnti %%edx, 28(%3)\n"
23337 - "11: movl 32(%4), %%eax\n"
23338 - "61: movl 36(%4), %%edx\n"
23339 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23340 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23341 " movnti %%eax, 32(%3)\n"
23342 " movnti %%edx, 36(%3)\n"
23343 - "12: movl 40(%4), %%eax\n"
23344 - "71: movl 44(%4), %%edx\n"
23345 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23346 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23347 " movnti %%eax, 40(%3)\n"
23348 " movnti %%edx, 44(%3)\n"
23349 - "13: movl 48(%4), %%eax\n"
23350 - "81: movl 52(%4), %%edx\n"
23351 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23352 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23353 " movnti %%eax, 48(%3)\n"
23354 " movnti %%edx, 52(%3)\n"
23355 - "14: movl 56(%4), %%eax\n"
23356 - "91: movl 60(%4), %%edx\n"
23357 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23358 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23359 " movnti %%eax, 56(%3)\n"
23360 " movnti %%edx, 60(%3)\n"
23361 " addl $-64, %0\n"
23362 @@ -445,9 +553,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
23363 " shrl $2, %0\n"
23364 " andl $3, %%eax\n"
23365 " cld\n"
23366 - "6: rep; movsl\n"
23367 + "6: rep; "__copyuser_seg" movsl\n"
23368 " movl %%eax,%0\n"
23369 - "7: rep; movsb\n"
23370 + "7: rep; "__copyuser_seg" movsb\n"
23371 "8:\n"
23372 ".section .fixup,\"ax\"\n"
23373 "9: lea 0(%%eax,%0,4),%0\n"
23374 @@ -487,32 +595,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
23375 */
23376 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
23377 unsigned long size);
23378 -unsigned long __copy_user_intel(void __user *to, const void *from,
23379 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
23380 + unsigned long size);
23381 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
23382 unsigned long size);
23383 unsigned long __copy_user_zeroing_intel_nocache(void *to,
23384 const void __user *from, unsigned long size);
23385 #endif /* CONFIG_X86_INTEL_USERCOPY */
23386
23387 /* Generic arbitrary sized copy. */
23388 -#define __copy_user(to, from, size) \
23389 +#define __copy_user(to, from, size, prefix, set, restore) \
23390 do { \
23391 int __d0, __d1, __d2; \
23392 __asm__ __volatile__( \
23393 + set \
23394 " cmp $7,%0\n" \
23395 " jbe 1f\n" \
23396 " movl %1,%0\n" \
23397 " negl %0\n" \
23398 " andl $7,%0\n" \
23399 " subl %0,%3\n" \
23400 - "4: rep; movsb\n" \
23401 + "4: rep; "prefix"movsb\n" \
23402 " movl %3,%0\n" \
23403 " shrl $2,%0\n" \
23404 " andl $3,%3\n" \
23405 " .align 2,0x90\n" \
23406 - "0: rep; movsl\n" \
23407 + "0: rep; "prefix"movsl\n" \
23408 " movl %3,%0\n" \
23409 - "1: rep; movsb\n" \
23410 + "1: rep; "prefix"movsb\n" \
23411 "2:\n" \
23412 + restore \
23413 ".section .fixup,\"ax\"\n" \
23414 "5: addl %3,%0\n" \
23415 " jmp 2b\n" \
23416 @@ -537,14 +649,14 @@ do { \
23417 " negl %0\n" \
23418 " andl $7,%0\n" \
23419 " subl %0,%3\n" \
23420 - "4: rep; movsb\n" \
23421 + "4: rep; "__copyuser_seg"movsb\n" \
23422 " movl %3,%0\n" \
23423 " shrl $2,%0\n" \
23424 " andl $3,%3\n" \
23425 " .align 2,0x90\n" \
23426 - "0: rep; movsl\n" \
23427 + "0: rep; "__copyuser_seg"movsl\n" \
23428 " movl %3,%0\n" \
23429 - "1: rep; movsb\n" \
23430 + "1: rep; "__copyuser_seg"movsb\n" \
23431 "2:\n" \
23432 ".section .fixup,\"ax\"\n" \
23433 "5: addl %3,%0\n" \
23434 @@ -627,9 +739,9 @@ survive:
23435 }
23436 #endif
23437 if (movsl_is_ok(to, from, n))
23438 - __copy_user(to, from, n);
23439 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
23440 else
23441 - n = __copy_user_intel(to, from, n);
23442 + n = __generic_copy_to_user_intel(to, from, n);
23443 return n;
23444 }
23445 EXPORT_SYMBOL(__copy_to_user_ll);
23446 @@ -649,10 +761,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
23447 unsigned long n)
23448 {
23449 if (movsl_is_ok(to, from, n))
23450 - __copy_user(to, from, n);
23451 + __copy_user(to, from, n, __copyuser_seg, "", "");
23452 else
23453 - n = __copy_user_intel((void __user *)to,
23454 - (const void *)from, n);
23455 + n = __generic_copy_from_user_intel(to, from, n);
23456 return n;
23457 }
23458 EXPORT_SYMBOL(__copy_from_user_ll_nozero);
23459 @@ -679,65 +790,50 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
23460 if (n > 64 && cpu_has_xmm2)
23461 n = __copy_user_intel_nocache(to, from, n);
23462 else
23463 - __copy_user(to, from, n);
23464 + __copy_user(to, from, n, __copyuser_seg, "", "");
23465 #else
23466 - __copy_user(to, from, n);
23467 + __copy_user(to, from, n, __copyuser_seg, "", "");
23468 #endif
23469 return n;
23470 }
23471 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
23472
23473 -/**
23474 - * copy_to_user: - Copy a block of data into user space.
23475 - * @to: Destination address, in user space.
23476 - * @from: Source address, in kernel space.
23477 - * @n: Number of bytes to copy.
23478 - *
23479 - * Context: User context only. This function may sleep.
23480 - *
23481 - * Copy data from kernel space to user space.
23482 - *
23483 - * Returns number of bytes that could not be copied.
23484 - * On success, this will be zero.
23485 - */
23486 -unsigned long
23487 -copy_to_user(void __user *to, const void *from, unsigned long n)
23488 -{
23489 - if (access_ok(VERIFY_WRITE, to, n))
23490 - n = __copy_to_user(to, from, n);
23491 - return n;
23492 -}
23493 -EXPORT_SYMBOL(copy_to_user);
23494 -
23495 -/**
23496 - * copy_from_user: - Copy a block of data from user space.
23497 - * @to: Destination address, in kernel space.
23498 - * @from: Source address, in user space.
23499 - * @n: Number of bytes to copy.
23500 - *
23501 - * Context: User context only. This function may sleep.
23502 - *
23503 - * Copy data from user space to kernel space.
23504 - *
23505 - * Returns number of bytes that could not be copied.
23506 - * On success, this will be zero.
23507 - *
23508 - * If some data could not be copied, this function will pad the copied
23509 - * data to the requested size using zero bytes.
23510 - */
23511 -unsigned long
23512 -_copy_from_user(void *to, const void __user *from, unsigned long n)
23513 -{
23514 - if (access_ok(VERIFY_READ, from, n))
23515 - n = __copy_from_user(to, from, n);
23516 - else
23517 - memset(to, 0, n);
23518 - return n;
23519 -}
23520 -EXPORT_SYMBOL(_copy_from_user);
23521 -
23522 void copy_from_user_overflow(void)
23523 {
23524 WARN(1, "Buffer overflow detected!\n");
23525 }
23526 EXPORT_SYMBOL(copy_from_user_overflow);
23527 +
23528 +void copy_to_user_overflow(void)
23529 +{
23530 + WARN(1, "Buffer overflow detected!\n");
23531 +}
23532 +EXPORT_SYMBOL(copy_to_user_overflow);
23533 +
23534 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23535 +void __set_fs(mm_segment_t x)
23536 +{
23537 + switch (x.seg) {
23538 + case 0:
23539 + loadsegment(gs, 0);
23540 + break;
23541 + case TASK_SIZE_MAX:
23542 + loadsegment(gs, __USER_DS);
23543 + break;
23544 + case -1UL:
23545 + loadsegment(gs, __KERNEL_DS);
23546 + break;
23547 + default:
23548 + BUG();
23549 + }
23550 + return;
23551 +}
23552 +EXPORT_SYMBOL(__set_fs);
23553 +
23554 +void set_fs(mm_segment_t x)
23555 +{
23556 + current_thread_info()->addr_limit = x;
23557 + __set_fs(x);
23558 +}
23559 +EXPORT_SYMBOL(set_fs);
23560 +#endif
23561 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
23562 index e5b130b..6690d31 100644
23563 --- a/arch/x86/lib/usercopy_64.c
23564 +++ b/arch/x86/lib/usercopy_64.c
23565 @@ -16,6 +16,12 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
23566 {
23567 long __d0;
23568 might_fault();
23569 +
23570 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23571 + if ((unsigned long)addr < PAX_USER_SHADOW_BASE)
23572 + addr += PAX_USER_SHADOW_BASE;
23573 +#endif
23574 +
23575 /* no memory constraint because it doesn't change any memory gcc knows
23576 about */
23577 asm volatile(
23578 @@ -52,12 +58,20 @@ unsigned long clear_user(void __user *to, unsigned long n)
23579 }
23580 EXPORT_SYMBOL(clear_user);
23581
23582 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
23583 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
23584 {
23585 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23586 - return copy_user_generic((__force void *)to, (__force void *)from, len);
23587 - }
23588 - return len;
23589 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23590 +
23591 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23592 + if ((unsigned long)to < PAX_USER_SHADOW_BASE)
23593 + to += PAX_USER_SHADOW_BASE;
23594 + if ((unsigned long)from < PAX_USER_SHADOW_BASE)
23595 + from += PAX_USER_SHADOW_BASE;
23596 +#endif
23597 +
23598 + return copy_user_generic((void __force_kernel *)to, (void __force_kernel *)from, len);
23599 + }
23600 + return len;
23601 }
23602 EXPORT_SYMBOL(copy_in_user);
23603
23604 @@ -67,7 +81,7 @@ EXPORT_SYMBOL(copy_in_user);
23605 * it is not necessary to optimize tail handling.
23606 */
23607 unsigned long
23608 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23609 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
23610 {
23611 char c;
23612 unsigned zero_len;
23613 @@ -84,3 +98,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23614 break;
23615 return len;
23616 }
23617 +
23618 +void copy_from_user_overflow(void)
23619 +{
23620 + WARN(1, "Buffer overflow detected!\n");
23621 +}
23622 +EXPORT_SYMBOL(copy_from_user_overflow);
23623 +
23624 +void copy_to_user_overflow(void)
23625 +{
23626 + WARN(1, "Buffer overflow detected!\n");
23627 +}
23628 +EXPORT_SYMBOL(copy_to_user_overflow);
23629 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
23630 index 903ec1e..c4166b2 100644
23631 --- a/arch/x86/mm/extable.c
23632 +++ b/arch/x86/mm/extable.c
23633 @@ -6,12 +6,24 @@
23634 static inline unsigned long
23635 ex_insn_addr(const struct exception_table_entry *x)
23636 {
23637 - return (unsigned long)&x->insn + x->insn;
23638 + unsigned long reloc = 0;
23639 +
23640 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23641 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23642 +#endif
23643 +
23644 + return (unsigned long)&x->insn + x->insn + reloc;
23645 }
23646 static inline unsigned long
23647 ex_fixup_addr(const struct exception_table_entry *x)
23648 {
23649 - return (unsigned long)&x->fixup + x->fixup;
23650 + unsigned long reloc = 0;
23651 +
23652 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23653 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23654 +#endif
23655 +
23656 + return (unsigned long)&x->fixup + x->fixup + reloc;
23657 }
23658
23659 int fixup_exception(struct pt_regs *regs)
23660 @@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
23661 unsigned long new_ip;
23662
23663 #ifdef CONFIG_PNPBIOS
23664 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
23665 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
23666 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
23667 extern u32 pnp_bios_is_utter_crap;
23668 pnp_bios_is_utter_crap = 1;
23669 @@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
23670 i += 4;
23671 p->fixup -= i;
23672 i += 4;
23673 +
23674 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23675 + BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
23676 + p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23677 + p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23678 +#endif
23679 +
23680 }
23681 }
23682
23683 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
23684 index 76dcd9d..e9dffde 100644
23685 --- a/arch/x86/mm/fault.c
23686 +++ b/arch/x86/mm/fault.c
23687 @@ -13,11 +13,18 @@
23688 #include <linux/perf_event.h> /* perf_sw_event */
23689 #include <linux/hugetlb.h> /* hstate_index_to_shift */
23690 #include <linux/prefetch.h> /* prefetchw */
23691 +#include <linux/unistd.h>
23692 +#include <linux/compiler.h>
23693
23694 #include <asm/traps.h> /* dotraplinkage, ... */
23695 #include <asm/pgalloc.h> /* pgd_*(), ... */
23696 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
23697 #include <asm/fixmap.h> /* VSYSCALL_START */
23698 +#include <asm/tlbflush.h>
23699 +
23700 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23701 +#include <asm/stacktrace.h>
23702 +#endif
23703
23704 /*
23705 * Page fault error code bits:
23706 @@ -55,7 +62,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
23707 int ret = 0;
23708
23709 /* kprobe_running() needs smp_processor_id() */
23710 - if (kprobes_built_in() && !user_mode_vm(regs)) {
23711 + if (kprobes_built_in() && !user_mode(regs)) {
23712 preempt_disable();
23713 if (kprobe_running() && kprobe_fault_handler(regs, 14))
23714 ret = 1;
23715 @@ -116,7 +123,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
23716 return !instr_lo || (instr_lo>>1) == 1;
23717 case 0x00:
23718 /* Prefetch instruction is 0x0F0D or 0x0F18 */
23719 - if (probe_kernel_address(instr, opcode))
23720 + if (user_mode(regs)) {
23721 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23722 + return 0;
23723 + } else if (probe_kernel_address(instr, opcode))
23724 return 0;
23725
23726 *prefetch = (instr_lo == 0xF) &&
23727 @@ -150,7 +160,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
23728 while (instr < max_instr) {
23729 unsigned char opcode;
23730
23731 - if (probe_kernel_address(instr, opcode))
23732 + if (user_mode(regs)) {
23733 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23734 + break;
23735 + } else if (probe_kernel_address(instr, opcode))
23736 break;
23737
23738 instr++;
23739 @@ -181,6 +194,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
23740 force_sig_info(si_signo, &info, tsk);
23741 }
23742
23743 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23744 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
23745 +#endif
23746 +
23747 +#ifdef CONFIG_PAX_EMUTRAMP
23748 +static int pax_handle_fetch_fault(struct pt_regs *regs);
23749 +#endif
23750 +
23751 +#ifdef CONFIG_PAX_PAGEEXEC
23752 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
23753 +{
23754 + pgd_t *pgd;
23755 + pud_t *pud;
23756 + pmd_t *pmd;
23757 +
23758 + pgd = pgd_offset(mm, address);
23759 + if (!pgd_present(*pgd))
23760 + return NULL;
23761 + pud = pud_offset(pgd, address);
23762 + if (!pud_present(*pud))
23763 + return NULL;
23764 + pmd = pmd_offset(pud, address);
23765 + if (!pmd_present(*pmd))
23766 + return NULL;
23767 + return pmd;
23768 +}
23769 +#endif
23770 +
23771 DEFINE_SPINLOCK(pgd_lock);
23772 LIST_HEAD(pgd_list);
23773
23774 @@ -231,10 +272,22 @@ void vmalloc_sync_all(void)
23775 for (address = VMALLOC_START & PMD_MASK;
23776 address >= TASK_SIZE && address < FIXADDR_TOP;
23777 address += PMD_SIZE) {
23778 +
23779 +#ifdef CONFIG_PAX_PER_CPU_PGD
23780 + unsigned long cpu;
23781 +#else
23782 struct page *page;
23783 +#endif
23784
23785 spin_lock(&pgd_lock);
23786 +
23787 +#ifdef CONFIG_PAX_PER_CPU_PGD
23788 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
23789 + pgd_t *pgd = get_cpu_pgd(cpu);
23790 + pmd_t *ret;
23791 +#else
23792 list_for_each_entry(page, &pgd_list, lru) {
23793 + pgd_t *pgd = page_address(page);
23794 spinlock_t *pgt_lock;
23795 pmd_t *ret;
23796
23797 @@ -242,8 +295,13 @@ void vmalloc_sync_all(void)
23798 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
23799
23800 spin_lock(pgt_lock);
23801 - ret = vmalloc_sync_one(page_address(page), address);
23802 +#endif
23803 +
23804 + ret = vmalloc_sync_one(pgd, address);
23805 +
23806 +#ifndef CONFIG_PAX_PER_CPU_PGD
23807 spin_unlock(pgt_lock);
23808 +#endif
23809
23810 if (!ret)
23811 break;
23812 @@ -277,6 +335,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23813 * an interrupt in the middle of a task switch..
23814 */
23815 pgd_paddr = read_cr3();
23816 +
23817 +#ifdef CONFIG_PAX_PER_CPU_PGD
23818 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
23819 +#endif
23820 +
23821 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
23822 if (!pmd_k)
23823 return -1;
23824 @@ -372,7 +435,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23825 * happen within a race in page table update. In the later
23826 * case just flush:
23827 */
23828 +
23829 +#ifdef CONFIG_PAX_PER_CPU_PGD
23830 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
23831 + pgd = pgd_offset_cpu(smp_processor_id(), address);
23832 +#else
23833 pgd = pgd_offset(current->active_mm, address);
23834 +#endif
23835 +
23836 pgd_ref = pgd_offset_k(address);
23837 if (pgd_none(*pgd_ref))
23838 return -1;
23839 @@ -540,7 +610,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
23840 static int is_errata100(struct pt_regs *regs, unsigned long address)
23841 {
23842 #ifdef CONFIG_X86_64
23843 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
23844 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
23845 return 1;
23846 #endif
23847 return 0;
23848 @@ -567,7 +637,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
23849 }
23850
23851 static const char nx_warning[] = KERN_CRIT
23852 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
23853 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
23854
23855 static void
23856 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23857 @@ -576,15 +646,26 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23858 if (!oops_may_print())
23859 return;
23860
23861 - if (error_code & PF_INSTR) {
23862 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
23863 unsigned int level;
23864
23865 pte_t *pte = lookup_address(address, &level);
23866
23867 if (pte && pte_present(*pte) && !pte_exec(*pte))
23868 - printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
23869 + printk(nx_warning, from_kuid(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
23870 }
23871
23872 +#ifdef CONFIG_PAX_KERNEXEC
23873 + if (init_mm.start_code <= address && address < init_mm.end_code) {
23874 + if (current->signal->curr_ip)
23875 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23876 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
23877 + else
23878 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23879 + current->comm, task_pid_nr(current), current_uid(), current_euid());
23880 + }
23881 +#endif
23882 +
23883 printk(KERN_ALERT "BUG: unable to handle kernel ");
23884 if (address < PAGE_SIZE)
23885 printk(KERN_CONT "NULL pointer dereference");
23886 @@ -748,6 +829,21 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
23887 }
23888 #endif
23889
23890 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23891 + if (pax_is_fetch_fault(regs, error_code, address)) {
23892 +
23893 +#ifdef CONFIG_PAX_EMUTRAMP
23894 + switch (pax_handle_fetch_fault(regs)) {
23895 + case 2:
23896 + return;
23897 + }
23898 +#endif
23899 +
23900 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23901 + do_group_exit(SIGKILL);
23902 + }
23903 +#endif
23904 +
23905 if (unlikely(show_unhandled_signals))
23906 show_signal_msg(regs, error_code, address, tsk);
23907
23908 @@ -844,7 +940,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
23909 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
23910 printk(KERN_ERR
23911 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
23912 - tsk->comm, tsk->pid, address);
23913 + tsk->comm, task_pid_nr(tsk), address);
23914 code = BUS_MCEERR_AR;
23915 }
23916 #endif
23917 @@ -900,6 +996,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
23918 return 1;
23919 }
23920
23921 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23922 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
23923 +{
23924 + pte_t *pte;
23925 + pmd_t *pmd;
23926 + spinlock_t *ptl;
23927 + unsigned char pte_mask;
23928 +
23929 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
23930 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
23931 + return 0;
23932 +
23933 + /* PaX: it's our fault, let's handle it if we can */
23934 +
23935 + /* PaX: take a look at read faults before acquiring any locks */
23936 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
23937 + /* instruction fetch attempt from a protected page in user mode */
23938 + up_read(&mm->mmap_sem);
23939 +
23940 +#ifdef CONFIG_PAX_EMUTRAMP
23941 + switch (pax_handle_fetch_fault(regs)) {
23942 + case 2:
23943 + return 1;
23944 + }
23945 +#endif
23946 +
23947 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23948 + do_group_exit(SIGKILL);
23949 + }
23950 +
23951 + pmd = pax_get_pmd(mm, address);
23952 + if (unlikely(!pmd))
23953 + return 0;
23954 +
23955 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
23956 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
23957 + pte_unmap_unlock(pte, ptl);
23958 + return 0;
23959 + }
23960 +
23961 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
23962 + /* write attempt to a protected page in user mode */
23963 + pte_unmap_unlock(pte, ptl);
23964 + return 0;
23965 + }
23966 +
23967 +#ifdef CONFIG_SMP
23968 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
23969 +#else
23970 + if (likely(address > get_limit(regs->cs)))
23971 +#endif
23972 + {
23973 + set_pte(pte, pte_mkread(*pte));
23974 + __flush_tlb_one(address);
23975 + pte_unmap_unlock(pte, ptl);
23976 + up_read(&mm->mmap_sem);
23977 + return 1;
23978 + }
23979 +
23980 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
23981 +
23982 + /*
23983 + * PaX: fill DTLB with user rights and retry
23984 + */
23985 + __asm__ __volatile__ (
23986 + "orb %2,(%1)\n"
23987 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
23988 +/*
23989 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
23990 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
23991 + * page fault when examined during a TLB load attempt. this is true not only
23992 + * for PTEs holding a non-present entry but also present entries that will
23993 + * raise a page fault (such as those set up by PaX, or the copy-on-write
23994 + * mechanism). in effect it means that we do *not* need to flush the TLBs
23995 + * for our target pages since their PTEs are simply not in the TLBs at all.
23996 +
23997 + * the best thing in omitting it is that we gain around 15-20% speed in the
23998 + * fast path of the page fault handler and can get rid of tracing since we
23999 + * can no longer flush unintended entries.
24000 + */
24001 + "invlpg (%0)\n"
24002 +#endif
24003 + __copyuser_seg"testb $0,(%0)\n"
24004 + "xorb %3,(%1)\n"
24005 + :
24006 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
24007 + : "memory", "cc");
24008 + pte_unmap_unlock(pte, ptl);
24009 + up_read(&mm->mmap_sem);
24010 + return 1;
24011 +}
24012 +#endif
24013 +
24014 /*
24015 * Handle a spurious fault caused by a stale TLB entry.
24016 *
24017 @@ -972,6 +1161,9 @@ int show_unhandled_signals = 1;
24018 static inline int
24019 access_error(unsigned long error_code, struct vm_area_struct *vma)
24020 {
24021 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
24022 + return 1;
24023 +
24024 if (error_code & PF_WRITE) {
24025 /* write, present and write, not present: */
24026 if (unlikely(!(vma->vm_flags & VM_WRITE)))
24027 @@ -1005,18 +1197,33 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
24028 {
24029 struct vm_area_struct *vma;
24030 struct task_struct *tsk;
24031 - unsigned long address;
24032 struct mm_struct *mm;
24033 int fault;
24034 int write = error_code & PF_WRITE;
24035 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
24036 (write ? FAULT_FLAG_WRITE : 0);
24037
24038 - tsk = current;
24039 - mm = tsk->mm;
24040 -
24041 /* Get the faulting address: */
24042 - address = read_cr2();
24043 + unsigned long address = read_cr2();
24044 +
24045 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24046 + if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
24047 + if (!search_exception_tables(regs->ip)) {
24048 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
24049 + bad_area_nosemaphore(regs, error_code, address);
24050 + return;
24051 + }
24052 + if (address < PAX_USER_SHADOW_BASE) {
24053 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
24054 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
24055 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
24056 + } else
24057 + address -= PAX_USER_SHADOW_BASE;
24058 + }
24059 +#endif
24060 +
24061 + tsk = current;
24062 + mm = tsk->mm;
24063
24064 /*
24065 * Detect and handle instructions that would cause a page fault for
24066 @@ -1077,7 +1284,7 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
24067 * User-mode registers count as a user access even for any
24068 * potential system fault or CPU buglet:
24069 */
24070 - if (user_mode_vm(regs)) {
24071 + if (user_mode(regs)) {
24072 local_irq_enable();
24073 error_code |= PF_USER;
24074 } else {
24075 @@ -1132,6 +1339,11 @@ retry:
24076 might_sleep();
24077 }
24078
24079 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
24080 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
24081 + return;
24082 +#endif
24083 +
24084 vma = find_vma(mm, address);
24085 if (unlikely(!vma)) {
24086 bad_area(regs, error_code, address);
24087 @@ -1143,18 +1355,24 @@ retry:
24088 bad_area(regs, error_code, address);
24089 return;
24090 }
24091 - if (error_code & PF_USER) {
24092 - /*
24093 - * Accessing the stack below %sp is always a bug.
24094 - * The large cushion allows instructions like enter
24095 - * and pusha to work. ("enter $65535, $31" pushes
24096 - * 32 pointers and then decrements %sp by 65535.)
24097 - */
24098 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
24099 - bad_area(regs, error_code, address);
24100 - return;
24101 - }
24102 + /*
24103 + * Accessing the stack below %sp is always a bug.
24104 + * The large cushion allows instructions like enter
24105 + * and pusha to work. ("enter $65535, $31" pushes
24106 + * 32 pointers and then decrements %sp by 65535.)
24107 + */
24108 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
24109 + bad_area(regs, error_code, address);
24110 + return;
24111 }
24112 +
24113 +#ifdef CONFIG_PAX_SEGMEXEC
24114 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
24115 + bad_area(regs, error_code, address);
24116 + return;
24117 + }
24118 +#endif
24119 +
24120 if (unlikely(expand_stack(vma, address))) {
24121 bad_area(regs, error_code, address);
24122 return;
24123 @@ -1209,3 +1427,292 @@ good_area:
24124
24125 up_read(&mm->mmap_sem);
24126 }
24127 +
24128 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24129 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
24130 +{
24131 + struct mm_struct *mm = current->mm;
24132 + unsigned long ip = regs->ip;
24133 +
24134 + if (v8086_mode(regs))
24135 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
24136 +
24137 +#ifdef CONFIG_PAX_PAGEEXEC
24138 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
24139 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
24140 + return true;
24141 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
24142 + return true;
24143 + return false;
24144 + }
24145 +#endif
24146 +
24147 +#ifdef CONFIG_PAX_SEGMEXEC
24148 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
24149 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
24150 + return true;
24151 + return false;
24152 + }
24153 +#endif
24154 +
24155 + return false;
24156 +}
24157 +#endif
24158 +
24159 +#ifdef CONFIG_PAX_EMUTRAMP
24160 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
24161 +{
24162 + int err;
24163 +
24164 + do { /* PaX: libffi trampoline emulation */
24165 + unsigned char mov, jmp;
24166 + unsigned int addr1, addr2;
24167 +
24168 +#ifdef CONFIG_X86_64
24169 + if ((regs->ip + 9) >> 32)
24170 + break;
24171 +#endif
24172 +
24173 + err = get_user(mov, (unsigned char __user *)regs->ip);
24174 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24175 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24176 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24177 +
24178 + if (err)
24179 + break;
24180 +
24181 + if (mov == 0xB8 && jmp == 0xE9) {
24182 + regs->ax = addr1;
24183 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24184 + return 2;
24185 + }
24186 + } while (0);
24187 +
24188 + do { /* PaX: gcc trampoline emulation #1 */
24189 + unsigned char mov1, mov2;
24190 + unsigned short jmp;
24191 + unsigned int addr1, addr2;
24192 +
24193 +#ifdef CONFIG_X86_64
24194 + if ((regs->ip + 11) >> 32)
24195 + break;
24196 +#endif
24197 +
24198 + err = get_user(mov1, (unsigned char __user *)regs->ip);
24199 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24200 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
24201 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24202 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
24203 +
24204 + if (err)
24205 + break;
24206 +
24207 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
24208 + regs->cx = addr1;
24209 + regs->ax = addr2;
24210 + regs->ip = addr2;
24211 + return 2;
24212 + }
24213 + } while (0);
24214 +
24215 + do { /* PaX: gcc trampoline emulation #2 */
24216 + unsigned char mov, jmp;
24217 + unsigned int addr1, addr2;
24218 +
24219 +#ifdef CONFIG_X86_64
24220 + if ((regs->ip + 9) >> 32)
24221 + break;
24222 +#endif
24223 +
24224 + err = get_user(mov, (unsigned char __user *)regs->ip);
24225 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24226 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24227 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24228 +
24229 + if (err)
24230 + break;
24231 +
24232 + if (mov == 0xB9 && jmp == 0xE9) {
24233 + regs->cx = addr1;
24234 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24235 + return 2;
24236 + }
24237 + } while (0);
24238 +
24239 + return 1; /* PaX in action */
24240 +}
24241 +
24242 +#ifdef CONFIG_X86_64
24243 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
24244 +{
24245 + int err;
24246 +
24247 + do { /* PaX: libffi trampoline emulation */
24248 + unsigned short mov1, mov2, jmp1;
24249 + unsigned char stcclc, jmp2;
24250 + unsigned long addr1, addr2;
24251 +
24252 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24253 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24254 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24255 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24256 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
24257 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
24258 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
24259 +
24260 + if (err)
24261 + break;
24262 +
24263 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24264 + regs->r11 = addr1;
24265 + regs->r10 = addr2;
24266 + if (stcclc == 0xF8)
24267 + regs->flags &= ~X86_EFLAGS_CF;
24268 + else
24269 + regs->flags |= X86_EFLAGS_CF;
24270 + regs->ip = addr1;
24271 + return 2;
24272 + }
24273 + } while (0);
24274 +
24275 + do { /* PaX: gcc trampoline emulation #1 */
24276 + unsigned short mov1, mov2, jmp1;
24277 + unsigned char jmp2;
24278 + unsigned int addr1;
24279 + unsigned long addr2;
24280 +
24281 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24282 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
24283 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
24284 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
24285 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
24286 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
24287 +
24288 + if (err)
24289 + break;
24290 +
24291 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24292 + regs->r11 = addr1;
24293 + regs->r10 = addr2;
24294 + regs->ip = addr1;
24295 + return 2;
24296 + }
24297 + } while (0);
24298 +
24299 + do { /* PaX: gcc trampoline emulation #2 */
24300 + unsigned short mov1, mov2, jmp1;
24301 + unsigned char jmp2;
24302 + unsigned long addr1, addr2;
24303 +
24304 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24305 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24306 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24307 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24308 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
24309 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
24310 +
24311 + if (err)
24312 + break;
24313 +
24314 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24315 + regs->r11 = addr1;
24316 + regs->r10 = addr2;
24317 + regs->ip = addr1;
24318 + return 2;
24319 + }
24320 + } while (0);
24321 +
24322 + return 1; /* PaX in action */
24323 +}
24324 +#endif
24325 +
24326 +/*
24327 + * PaX: decide what to do with offenders (regs->ip = fault address)
24328 + *
24329 + * returns 1 when task should be killed
24330 + * 2 when gcc trampoline was detected
24331 + */
24332 +static int pax_handle_fetch_fault(struct pt_regs *regs)
24333 +{
24334 + if (v8086_mode(regs))
24335 + return 1;
24336 +
24337 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
24338 + return 1;
24339 +
24340 +#ifdef CONFIG_X86_32
24341 + return pax_handle_fetch_fault_32(regs);
24342 +#else
24343 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
24344 + return pax_handle_fetch_fault_32(regs);
24345 + else
24346 + return pax_handle_fetch_fault_64(regs);
24347 +#endif
24348 +}
24349 +#endif
24350 +
24351 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24352 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
24353 +{
24354 + long i;
24355 +
24356 + printk(KERN_ERR "PAX: bytes at PC: ");
24357 + for (i = 0; i < 20; i++) {
24358 + unsigned char c;
24359 + if (get_user(c, (unsigned char __force_user *)pc+i))
24360 + printk(KERN_CONT "?? ");
24361 + else
24362 + printk(KERN_CONT "%02x ", c);
24363 + }
24364 + printk("\n");
24365 +
24366 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
24367 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
24368 + unsigned long c;
24369 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
24370 +#ifdef CONFIG_X86_32
24371 + printk(KERN_CONT "???????? ");
24372 +#else
24373 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
24374 + printk(KERN_CONT "???????? ???????? ");
24375 + else
24376 + printk(KERN_CONT "???????????????? ");
24377 +#endif
24378 + } else {
24379 +#ifdef CONFIG_X86_64
24380 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
24381 + printk(KERN_CONT "%08x ", (unsigned int)c);
24382 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
24383 + } else
24384 +#endif
24385 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
24386 + }
24387 + }
24388 + printk("\n");
24389 +}
24390 +#endif
24391 +
24392 +/**
24393 + * probe_kernel_write(): safely attempt to write to a location
24394 + * @dst: address to write to
24395 + * @src: pointer to the data that shall be written
24396 + * @size: size of the data chunk
24397 + *
24398 + * Safely write to address @dst from the buffer at @src. If a kernel fault
24399 + * happens, handle that and return -EFAULT.
24400 + */
24401 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
24402 +{
24403 + long ret;
24404 + mm_segment_t old_fs = get_fs();
24405 +
24406 + set_fs(KERNEL_DS);
24407 + pagefault_disable();
24408 + pax_open_kernel();
24409 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
24410 + pax_close_kernel();
24411 + pagefault_enable();
24412 + set_fs(old_fs);
24413 +
24414 + return ret ? -EFAULT : 0;
24415 +}
24416 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
24417 index dd74e46..7d26398 100644
24418 --- a/arch/x86/mm/gup.c
24419 +++ b/arch/x86/mm/gup.c
24420 @@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
24421 addr = start;
24422 len = (unsigned long) nr_pages << PAGE_SHIFT;
24423 end = start + len;
24424 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24425 + if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24426 (void __user *)start, len)))
24427 return 0;
24428
24429 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
24430 index 6f31ee5..8ee4164 100644
24431 --- a/arch/x86/mm/highmem_32.c
24432 +++ b/arch/x86/mm/highmem_32.c
24433 @@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
24434 idx = type + KM_TYPE_NR*smp_processor_id();
24435 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
24436 BUG_ON(!pte_none(*(kmap_pte-idx)));
24437 +
24438 + pax_open_kernel();
24439 set_pte(kmap_pte-idx, mk_pte(page, prot));
24440 + pax_close_kernel();
24441 +
24442 arch_flush_lazy_mmu_mode();
24443
24444 return (void *)vaddr;
24445 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
24446 index b91e485..d00e7c9 100644
24447 --- a/arch/x86/mm/hugetlbpage.c
24448 +++ b/arch/x86/mm/hugetlbpage.c
24449 @@ -277,13 +277,20 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
24450 struct hstate *h = hstate_file(file);
24451 struct mm_struct *mm = current->mm;
24452 struct vm_area_struct *vma;
24453 - unsigned long start_addr;
24454 + unsigned long start_addr, pax_task_size = TASK_SIZE;
24455 +
24456 +#ifdef CONFIG_PAX_SEGMEXEC
24457 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24458 + pax_task_size = SEGMEXEC_TASK_SIZE;
24459 +#endif
24460 +
24461 + pax_task_size -= PAGE_SIZE;
24462
24463 if (len > mm->cached_hole_size) {
24464 - start_addr = mm->free_area_cache;
24465 + start_addr = mm->free_area_cache;
24466 } else {
24467 - start_addr = TASK_UNMAPPED_BASE;
24468 - mm->cached_hole_size = 0;
24469 + start_addr = mm->mmap_base;
24470 + mm->cached_hole_size = 0;
24471 }
24472
24473 full_search:
24474 @@ -291,26 +298,27 @@ full_search:
24475
24476 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
24477 /* At this point: (!vma || addr < vma->vm_end). */
24478 - if (TASK_SIZE - len < addr) {
24479 + if (pax_task_size - len < addr) {
24480 /*
24481 * Start a new search - just in case we missed
24482 * some holes.
24483 */
24484 - if (start_addr != TASK_UNMAPPED_BASE) {
24485 - start_addr = TASK_UNMAPPED_BASE;
24486 + if (start_addr != mm->mmap_base) {
24487 + start_addr = mm->mmap_base;
24488 mm->cached_hole_size = 0;
24489 goto full_search;
24490 }
24491 return -ENOMEM;
24492 }
24493 - if (!vma || addr + len <= vma->vm_start) {
24494 - mm->free_area_cache = addr + len;
24495 - return addr;
24496 - }
24497 + if (check_heap_stack_gap(vma, addr, len))
24498 + break;
24499 if (addr + mm->cached_hole_size < vma->vm_start)
24500 mm->cached_hole_size = vma->vm_start - addr;
24501 addr = ALIGN(vma->vm_end, huge_page_size(h));
24502 }
24503 +
24504 + mm->free_area_cache = addr + len;
24505 + return addr;
24506 }
24507
24508 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24509 @@ -321,9 +329,8 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24510 struct mm_struct *mm = current->mm;
24511 struct vm_area_struct *vma;
24512 unsigned long base = mm->mmap_base;
24513 - unsigned long addr = addr0;
24514 + unsigned long addr;
24515 unsigned long largest_hole = mm->cached_hole_size;
24516 - unsigned long start_addr;
24517
24518 /* don't allow allocations above current base */
24519 if (mm->free_area_cache > base)
24520 @@ -333,16 +340,15 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24521 largest_hole = 0;
24522 mm->free_area_cache = base;
24523 }
24524 -try_again:
24525 - start_addr = mm->free_area_cache;
24526
24527 /* make sure it can fit in the remaining address space */
24528 if (mm->free_area_cache < len)
24529 goto fail;
24530
24531 /* either no address requested or can't fit in requested address hole */
24532 - addr = (mm->free_area_cache - len) & huge_page_mask(h);
24533 + addr = mm->free_area_cache - len;
24534 do {
24535 + addr &= huge_page_mask(h);
24536 /*
24537 * Lookup failure means no vma is above this address,
24538 * i.e. return with success:
24539 @@ -351,10 +357,10 @@ try_again:
24540 if (!vma)
24541 return addr;
24542
24543 - if (addr + len <= vma->vm_start) {
24544 + if (check_heap_stack_gap(vma, addr, len)) {
24545 /* remember the address as a hint for next time */
24546 - mm->cached_hole_size = largest_hole;
24547 - return (mm->free_area_cache = addr);
24548 + mm->cached_hole_size = largest_hole;
24549 + return (mm->free_area_cache = addr);
24550 } else if (mm->free_area_cache == vma->vm_end) {
24551 /* pull free_area_cache down to the first hole */
24552 mm->free_area_cache = vma->vm_start;
24553 @@ -363,29 +369,34 @@ try_again:
24554
24555 /* remember the largest hole we saw so far */
24556 if (addr + largest_hole < vma->vm_start)
24557 - largest_hole = vma->vm_start - addr;
24558 + largest_hole = vma->vm_start - addr;
24559
24560 /* try just below the current vma->vm_start */
24561 - addr = (vma->vm_start - len) & huge_page_mask(h);
24562 - } while (len <= vma->vm_start);
24563 + addr = skip_heap_stack_gap(vma, len);
24564 + } while (!IS_ERR_VALUE(addr));
24565
24566 fail:
24567 /*
24568 - * if hint left us with no space for the requested
24569 - * mapping then try again:
24570 - */
24571 - if (start_addr != base) {
24572 - mm->free_area_cache = base;
24573 - largest_hole = 0;
24574 - goto try_again;
24575 - }
24576 - /*
24577 * A failed mmap() very likely causes application failure,
24578 * so fall back to the bottom-up function here. This scenario
24579 * can happen with large stack limits and large mmap()
24580 * allocations.
24581 */
24582 - mm->free_area_cache = TASK_UNMAPPED_BASE;
24583 +
24584 +#ifdef CONFIG_PAX_SEGMEXEC
24585 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24586 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
24587 + else
24588 +#endif
24589 +
24590 + mm->mmap_base = TASK_UNMAPPED_BASE;
24591 +
24592 +#ifdef CONFIG_PAX_RANDMMAP
24593 + if (mm->pax_flags & MF_PAX_RANDMMAP)
24594 + mm->mmap_base += mm->delta_mmap;
24595 +#endif
24596 +
24597 + mm->free_area_cache = mm->mmap_base;
24598 mm->cached_hole_size = ~0UL;
24599 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
24600 len, pgoff, flags);
24601 @@ -393,6 +404,7 @@ fail:
24602 /*
24603 * Restore the topdown base:
24604 */
24605 + mm->mmap_base = base;
24606 mm->free_area_cache = base;
24607 mm->cached_hole_size = ~0UL;
24608
24609 @@ -406,10 +418,19 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24610 struct hstate *h = hstate_file(file);
24611 struct mm_struct *mm = current->mm;
24612 struct vm_area_struct *vma;
24613 + unsigned long pax_task_size = TASK_SIZE;
24614
24615 if (len & ~huge_page_mask(h))
24616 return -EINVAL;
24617 - if (len > TASK_SIZE)
24618 +
24619 +#ifdef CONFIG_PAX_SEGMEXEC
24620 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24621 + pax_task_size = SEGMEXEC_TASK_SIZE;
24622 +#endif
24623 +
24624 + pax_task_size -= PAGE_SIZE;
24625 +
24626 + if (len > pax_task_size)
24627 return -ENOMEM;
24628
24629 if (flags & MAP_FIXED) {
24630 @@ -421,8 +442,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24631 if (addr) {
24632 addr = ALIGN(addr, huge_page_size(h));
24633 vma = find_vma(mm, addr);
24634 - if (TASK_SIZE - len >= addr &&
24635 - (!vma || addr + len <= vma->vm_start))
24636 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
24637 return addr;
24638 }
24639 if (mm->get_unmapped_area == arch_get_unmapped_area)
24640 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
24641 index d7aea41..0fc945b 100644
24642 --- a/arch/x86/mm/init.c
24643 +++ b/arch/x86/mm/init.c
24644 @@ -4,6 +4,7 @@
24645 #include <linux/swap.h>
24646 #include <linux/memblock.h>
24647 #include <linux/bootmem.h> /* for max_low_pfn */
24648 +#include <linux/tboot.h>
24649
24650 #include <asm/cacheflush.h>
24651 #include <asm/e820.h>
24652 @@ -16,6 +17,8 @@
24653 #include <asm/tlb.h>
24654 #include <asm/proto.h>
24655 #include <asm/dma.h> /* for MAX_DMA_PFN */
24656 +#include <asm/desc.h>
24657 +#include <asm/bios_ebda.h>
24658
24659 unsigned long __initdata pgt_buf_start;
24660 unsigned long __meminitdata pgt_buf_end;
24661 @@ -44,7 +47,7 @@ static void __init find_early_table_space(struct map_range *mr, int nr_range)
24662 {
24663 int i;
24664 unsigned long puds = 0, pmds = 0, ptes = 0, tables;
24665 - unsigned long start = 0, good_end;
24666 + unsigned long start = 0x100000, good_end;
24667 phys_addr_t base;
24668
24669 for (i = 0; i < nr_range; i++) {
24670 @@ -321,10 +324,40 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
24671 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
24672 * mmio resources as well as potential bios/acpi data regions.
24673 */
24674 +
24675 +#ifdef CONFIG_GRKERNSEC_KMEM
24676 +static unsigned int ebda_start __read_only;
24677 +static unsigned int ebda_end __read_only;
24678 +#endif
24679 +
24680 int devmem_is_allowed(unsigned long pagenr)
24681 {
24682 - if (pagenr < 256)
24683 +#ifdef CONFIG_GRKERNSEC_KMEM
24684 + /* allow BDA */
24685 + if (!pagenr)
24686 return 1;
24687 + /* allow EBDA */
24688 + if (pagenr >= ebda_start && pagenr < ebda_end)
24689 + return 1;
24690 + /* if tboot is in use, allow access to its hardcoded serial log range */
24691 + if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
24692 + return 1;
24693 +#else
24694 + if (!pagenr)
24695 + return 1;
24696 +#ifdef CONFIG_VM86
24697 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
24698 + return 1;
24699 +#endif
24700 +#endif
24701 +
24702 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
24703 + return 1;
24704 +#ifdef CONFIG_GRKERNSEC_KMEM
24705 + /* throw out everything else below 1MB */
24706 + if (pagenr <= 256)
24707 + return 0;
24708 +#endif
24709 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
24710 return 0;
24711 if (!page_is_ram(pagenr))
24712 @@ -381,8 +414,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
24713 #endif
24714 }
24715
24716 +#ifdef CONFIG_GRKERNSEC_KMEM
24717 +static inline void gr_init_ebda(void)
24718 +{
24719 + unsigned int ebda_addr;
24720 + unsigned int ebda_size = 0;
24721 +
24722 + ebda_addr = get_bios_ebda();
24723 + if (ebda_addr) {
24724 + ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
24725 + ebda_size <<= 10;
24726 + }
24727 + if (ebda_addr && ebda_size) {
24728 + ebda_start = ebda_addr >> PAGE_SHIFT;
24729 + ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
24730 + } else {
24731 + ebda_start = 0x9f000 >> PAGE_SHIFT;
24732 + ebda_end = 0xa0000 >> PAGE_SHIFT;
24733 + }
24734 +}
24735 +#else
24736 +static inline void gr_init_ebda(void) { }
24737 +#endif
24738 +
24739 void free_initmem(void)
24740 {
24741 +#ifdef CONFIG_PAX_KERNEXEC
24742 +#ifdef CONFIG_X86_32
24743 + /* PaX: limit KERNEL_CS to actual size */
24744 + unsigned long addr, limit;
24745 + struct desc_struct d;
24746 + int cpu;
24747 +#else
24748 + pgd_t *pgd;
24749 + pud_t *pud;
24750 + pmd_t *pmd;
24751 + unsigned long addr, end;
24752 +#endif
24753 +#endif
24754 +
24755 + gr_init_ebda();
24756 +
24757 +#ifdef CONFIG_PAX_KERNEXEC
24758 +#ifdef CONFIG_X86_32
24759 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
24760 + limit = (limit - 1UL) >> PAGE_SHIFT;
24761 +
24762 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
24763 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
24764 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
24765 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
24766 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
24767 + }
24768 +
24769 + /* PaX: make KERNEL_CS read-only */
24770 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
24771 + if (!paravirt_enabled())
24772 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
24773 +/*
24774 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
24775 + pgd = pgd_offset_k(addr);
24776 + pud = pud_offset(pgd, addr);
24777 + pmd = pmd_offset(pud, addr);
24778 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24779 + }
24780 +*/
24781 +#ifdef CONFIG_X86_PAE
24782 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
24783 +/*
24784 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
24785 + pgd = pgd_offset_k(addr);
24786 + pud = pud_offset(pgd, addr);
24787 + pmd = pmd_offset(pud, addr);
24788 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24789 + }
24790 +*/
24791 +#endif
24792 +
24793 +#ifdef CONFIG_MODULES
24794 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
24795 +#endif
24796 +
24797 +#else
24798 + /* PaX: make kernel code/rodata read-only, rest non-executable */
24799 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
24800 + pgd = pgd_offset_k(addr);
24801 + pud = pud_offset(pgd, addr);
24802 + pmd = pmd_offset(pud, addr);
24803 + if (!pmd_present(*pmd))
24804 + continue;
24805 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
24806 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24807 + else
24808 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24809 + }
24810 +
24811 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
24812 + end = addr + KERNEL_IMAGE_SIZE;
24813 + for (; addr < end; addr += PMD_SIZE) {
24814 + pgd = pgd_offset_k(addr);
24815 + pud = pud_offset(pgd, addr);
24816 + pmd = pmd_offset(pud, addr);
24817 + if (!pmd_present(*pmd))
24818 + continue;
24819 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
24820 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24821 + }
24822 +#endif
24823 +
24824 + flush_tlb_all();
24825 +#endif
24826 +
24827 free_init_pages("unused kernel memory",
24828 (unsigned long)(&__init_begin),
24829 (unsigned long)(&__init_end));
24830 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
24831 index 575d86f..4987469 100644
24832 --- a/arch/x86/mm/init_32.c
24833 +++ b/arch/x86/mm/init_32.c
24834 @@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
24835 }
24836
24837 /*
24838 - * Creates a middle page table and puts a pointer to it in the
24839 - * given global directory entry. This only returns the gd entry
24840 - * in non-PAE compilation mode, since the middle layer is folded.
24841 - */
24842 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
24843 -{
24844 - pud_t *pud;
24845 - pmd_t *pmd_table;
24846 -
24847 -#ifdef CONFIG_X86_PAE
24848 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
24849 - if (after_bootmem)
24850 - pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
24851 - else
24852 - pmd_table = (pmd_t *)alloc_low_page();
24853 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
24854 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
24855 - pud = pud_offset(pgd, 0);
24856 - BUG_ON(pmd_table != pmd_offset(pud, 0));
24857 -
24858 - return pmd_table;
24859 - }
24860 -#endif
24861 - pud = pud_offset(pgd, 0);
24862 - pmd_table = pmd_offset(pud, 0);
24863 -
24864 - return pmd_table;
24865 -}
24866 -
24867 -/*
24868 * Create a page table and place a pointer to it in a middle page
24869 * directory entry:
24870 */
24871 @@ -122,13 +92,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
24872 page_table = (pte_t *)alloc_low_page();
24873
24874 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
24875 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24876 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
24877 +#else
24878 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
24879 +#endif
24880 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
24881 }
24882
24883 return pte_offset_kernel(pmd, 0);
24884 }
24885
24886 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
24887 +{
24888 + pud_t *pud;
24889 + pmd_t *pmd_table;
24890 +
24891 + pud = pud_offset(pgd, 0);
24892 + pmd_table = pmd_offset(pud, 0);
24893 +
24894 + return pmd_table;
24895 +}
24896 +
24897 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
24898 {
24899 int pgd_idx = pgd_index(vaddr);
24900 @@ -202,6 +187,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24901 int pgd_idx, pmd_idx;
24902 unsigned long vaddr;
24903 pgd_t *pgd;
24904 + pud_t *pud;
24905 pmd_t *pmd;
24906 pte_t *pte = NULL;
24907
24908 @@ -211,8 +197,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24909 pgd = pgd_base + pgd_idx;
24910
24911 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
24912 - pmd = one_md_table_init(pgd);
24913 - pmd = pmd + pmd_index(vaddr);
24914 + pud = pud_offset(pgd, vaddr);
24915 + pmd = pmd_offset(pud, vaddr);
24916 +
24917 +#ifdef CONFIG_X86_PAE
24918 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24919 +#endif
24920 +
24921 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
24922 pmd++, pmd_idx++) {
24923 pte = page_table_kmap_check(one_page_table_init(pmd),
24924 @@ -224,11 +215,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24925 }
24926 }
24927
24928 -static inline int is_kernel_text(unsigned long addr)
24929 +static inline int is_kernel_text(unsigned long start, unsigned long end)
24930 {
24931 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
24932 - return 1;
24933 - return 0;
24934 + if ((start > ktla_ktva((unsigned long)_etext) ||
24935 + end <= ktla_ktva((unsigned long)_stext)) &&
24936 + (start > ktla_ktva((unsigned long)_einittext) ||
24937 + end <= ktla_ktva((unsigned long)_sinittext)) &&
24938 +
24939 +#ifdef CONFIG_ACPI_SLEEP
24940 + (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
24941 +#endif
24942 +
24943 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
24944 + return 0;
24945 + return 1;
24946 }
24947
24948 /*
24949 @@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned long start,
24950 unsigned long last_map_addr = end;
24951 unsigned long start_pfn, end_pfn;
24952 pgd_t *pgd_base = swapper_pg_dir;
24953 - int pgd_idx, pmd_idx, pte_ofs;
24954 + unsigned int pgd_idx, pmd_idx, pte_ofs;
24955 unsigned long pfn;
24956 pgd_t *pgd;
24957 + pud_t *pud;
24958 pmd_t *pmd;
24959 pte_t *pte;
24960 unsigned pages_2m, pages_4k;
24961 @@ -280,8 +281,13 @@ repeat:
24962 pfn = start_pfn;
24963 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24964 pgd = pgd_base + pgd_idx;
24965 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
24966 - pmd = one_md_table_init(pgd);
24967 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
24968 + pud = pud_offset(pgd, 0);
24969 + pmd = pmd_offset(pud, 0);
24970 +
24971 +#ifdef CONFIG_X86_PAE
24972 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24973 +#endif
24974
24975 if (pfn >= end_pfn)
24976 continue;
24977 @@ -293,14 +299,13 @@ repeat:
24978 #endif
24979 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
24980 pmd++, pmd_idx++) {
24981 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
24982 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
24983
24984 /*
24985 * Map with big pages if possible, otherwise
24986 * create normal page tables:
24987 */
24988 if (use_pse) {
24989 - unsigned int addr2;
24990 pgprot_t prot = PAGE_KERNEL_LARGE;
24991 /*
24992 * first pass will use the same initial
24993 @@ -310,11 +315,7 @@ repeat:
24994 __pgprot(PTE_IDENT_ATTR |
24995 _PAGE_PSE);
24996
24997 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
24998 - PAGE_OFFSET + PAGE_SIZE-1;
24999 -
25000 - if (is_kernel_text(addr) ||
25001 - is_kernel_text(addr2))
25002 + if (is_kernel_text(address, address + PMD_SIZE))
25003 prot = PAGE_KERNEL_LARGE_EXEC;
25004
25005 pages_2m++;
25006 @@ -331,7 +332,7 @@ repeat:
25007 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
25008 pte += pte_ofs;
25009 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
25010 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
25011 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
25012 pgprot_t prot = PAGE_KERNEL;
25013 /*
25014 * first pass will use the same initial
25015 @@ -339,7 +340,7 @@ repeat:
25016 */
25017 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
25018
25019 - if (is_kernel_text(addr))
25020 + if (is_kernel_text(address, address + PAGE_SIZE))
25021 prot = PAGE_KERNEL_EXEC;
25022
25023 pages_4k++;
25024 @@ -465,7 +466,7 @@ void __init native_pagetable_setup_start(pgd_t *base)
25025
25026 pud = pud_offset(pgd, va);
25027 pmd = pmd_offset(pud, va);
25028 - if (!pmd_present(*pmd))
25029 + if (!pmd_present(*pmd) || pmd_huge(*pmd))
25030 break;
25031
25032 pte = pte_offset_kernel(pmd, va);
25033 @@ -517,12 +518,10 @@ void __init early_ioremap_page_table_range_init(void)
25034
25035 static void __init pagetable_init(void)
25036 {
25037 - pgd_t *pgd_base = swapper_pg_dir;
25038 -
25039 - permanent_kmaps_init(pgd_base);
25040 + permanent_kmaps_init(swapper_pg_dir);
25041 }
25042
25043 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
25044 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
25045 EXPORT_SYMBOL_GPL(__supported_pte_mask);
25046
25047 /* user-defined highmem size */
25048 @@ -734,6 +733,12 @@ void __init mem_init(void)
25049
25050 pci_iommu_alloc();
25051
25052 +#ifdef CONFIG_PAX_PER_CPU_PGD
25053 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
25054 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25055 + KERNEL_PGD_PTRS);
25056 +#endif
25057 +
25058 #ifdef CONFIG_FLATMEM
25059 BUG_ON(!mem_map);
25060 #endif
25061 @@ -760,7 +765,7 @@ void __init mem_init(void)
25062 reservedpages++;
25063
25064 codesize = (unsigned long) &_etext - (unsigned long) &_text;
25065 - datasize = (unsigned long) &_edata - (unsigned long) &_etext;
25066 + datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
25067 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
25068
25069 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
25070 @@ -801,10 +806,10 @@ void __init mem_init(void)
25071 ((unsigned long)&__init_end -
25072 (unsigned long)&__init_begin) >> 10,
25073
25074 - (unsigned long)&_etext, (unsigned long)&_edata,
25075 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
25076 + (unsigned long)&_sdata, (unsigned long)&_edata,
25077 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
25078
25079 - (unsigned long)&_text, (unsigned long)&_etext,
25080 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
25081 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
25082
25083 /*
25084 @@ -882,6 +887,7 @@ void set_kernel_text_rw(void)
25085 if (!kernel_set_to_readonly)
25086 return;
25087
25088 + start = ktla_ktva(start);
25089 pr_debug("Set kernel text: %lx - %lx for read write\n",
25090 start, start+size);
25091
25092 @@ -896,6 +902,7 @@ void set_kernel_text_ro(void)
25093 if (!kernel_set_to_readonly)
25094 return;
25095
25096 + start = ktla_ktva(start);
25097 pr_debug("Set kernel text: %lx - %lx for read only\n",
25098 start, start+size);
25099
25100 @@ -924,6 +931,7 @@ void mark_rodata_ro(void)
25101 unsigned long start = PFN_ALIGN(_text);
25102 unsigned long size = PFN_ALIGN(_etext) - start;
25103
25104 + start = ktla_ktva(start);
25105 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
25106 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
25107 size >> 10);
25108 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
25109 index 3baff25..8b37564 100644
25110 --- a/arch/x86/mm/init_64.c
25111 +++ b/arch/x86/mm/init_64.c
25112 @@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpages_on);
25113 * around without checking the pgd every time.
25114 */
25115
25116 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
25117 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
25118 EXPORT_SYMBOL_GPL(__supported_pte_mask);
25119
25120 int force_personality32;
25121 @@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25122
25123 for (address = start; address <= end; address += PGDIR_SIZE) {
25124 const pgd_t *pgd_ref = pgd_offset_k(address);
25125 +
25126 +#ifdef CONFIG_PAX_PER_CPU_PGD
25127 + unsigned long cpu;
25128 +#else
25129 struct page *page;
25130 +#endif
25131
25132 if (pgd_none(*pgd_ref))
25133 continue;
25134
25135 spin_lock(&pgd_lock);
25136 +
25137 +#ifdef CONFIG_PAX_PER_CPU_PGD
25138 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25139 + pgd_t *pgd = pgd_offset_cpu(cpu, address);
25140 +#else
25141 list_for_each_entry(page, &pgd_list, lru) {
25142 pgd_t *pgd;
25143 spinlock_t *pgt_lock;
25144 @@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25145 /* the pgt_lock only for Xen */
25146 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
25147 spin_lock(pgt_lock);
25148 +#endif
25149
25150 if (pgd_none(*pgd))
25151 set_pgd(pgd, *pgd_ref);
25152 @@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25153 BUG_ON(pgd_page_vaddr(*pgd)
25154 != pgd_page_vaddr(*pgd_ref));
25155
25156 +#ifndef CONFIG_PAX_PER_CPU_PGD
25157 spin_unlock(pgt_lock);
25158 +#endif
25159 +
25160 }
25161 spin_unlock(&pgd_lock);
25162 }
25163 @@ -161,7 +175,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
25164 {
25165 if (pgd_none(*pgd)) {
25166 pud_t *pud = (pud_t *)spp_getpage();
25167 - pgd_populate(&init_mm, pgd, pud);
25168 + pgd_populate_kernel(&init_mm, pgd, pud);
25169 if (pud != pud_offset(pgd, 0))
25170 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
25171 pud, pud_offset(pgd, 0));
25172 @@ -173,7 +187,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
25173 {
25174 if (pud_none(*pud)) {
25175 pmd_t *pmd = (pmd_t *) spp_getpage();
25176 - pud_populate(&init_mm, pud, pmd);
25177 + pud_populate_kernel(&init_mm, pud, pmd);
25178 if (pmd != pmd_offset(pud, 0))
25179 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
25180 pmd, pmd_offset(pud, 0));
25181 @@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
25182 pmd = fill_pmd(pud, vaddr);
25183 pte = fill_pte(pmd, vaddr);
25184
25185 + pax_open_kernel();
25186 set_pte(pte, new_pte);
25187 + pax_close_kernel();
25188
25189 /*
25190 * It's enough to flush this one mapping.
25191 @@ -261,14 +277,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
25192 pgd = pgd_offset_k((unsigned long)__va(phys));
25193 if (pgd_none(*pgd)) {
25194 pud = (pud_t *) spp_getpage();
25195 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
25196 - _PAGE_USER));
25197 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
25198 }
25199 pud = pud_offset(pgd, (unsigned long)__va(phys));
25200 if (pud_none(*pud)) {
25201 pmd = (pmd_t *) spp_getpage();
25202 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
25203 - _PAGE_USER));
25204 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
25205 }
25206 pmd = pmd_offset(pud, phys);
25207 BUG_ON(!pmd_none(*pmd));
25208 @@ -329,7 +343,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
25209 if (pfn >= pgt_buf_top)
25210 panic("alloc_low_page: ran out of memory");
25211
25212 - adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
25213 + adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
25214 clear_page(adr);
25215 *phys = pfn * PAGE_SIZE;
25216 return adr;
25217 @@ -345,7 +359,7 @@ static __ref void *map_low_page(void *virt)
25218
25219 phys = __pa(virt);
25220 left = phys & (PAGE_SIZE - 1);
25221 - adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
25222 + adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
25223 adr = (void *)(((unsigned long)adr) | left);
25224
25225 return adr;
25226 @@ -553,7 +567,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
25227 unmap_low_page(pmd);
25228
25229 spin_lock(&init_mm.page_table_lock);
25230 - pud_populate(&init_mm, pud, __va(pmd_phys));
25231 + pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
25232 spin_unlock(&init_mm.page_table_lock);
25233 }
25234 __flush_tlb_all();
25235 @@ -599,7 +613,7 @@ kernel_physical_mapping_init(unsigned long start,
25236 unmap_low_page(pud);
25237
25238 spin_lock(&init_mm.page_table_lock);
25239 - pgd_populate(&init_mm, pgd, __va(pud_phys));
25240 + pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
25241 spin_unlock(&init_mm.page_table_lock);
25242 pgd_changed = true;
25243 }
25244 @@ -691,6 +705,12 @@ void __init mem_init(void)
25245
25246 pci_iommu_alloc();
25247
25248 +#ifdef CONFIG_PAX_PER_CPU_PGD
25249 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
25250 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25251 + KERNEL_PGD_PTRS);
25252 +#endif
25253 +
25254 /* clear_bss() already clear the empty_zero_page */
25255
25256 reservedpages = 0;
25257 @@ -851,8 +871,8 @@ int kern_addr_valid(unsigned long addr)
25258 static struct vm_area_struct gate_vma = {
25259 .vm_start = VSYSCALL_START,
25260 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
25261 - .vm_page_prot = PAGE_READONLY_EXEC,
25262 - .vm_flags = VM_READ | VM_EXEC
25263 + .vm_page_prot = PAGE_READONLY,
25264 + .vm_flags = VM_READ
25265 };
25266
25267 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
25268 @@ -886,7 +906,7 @@ int in_gate_area_no_mm(unsigned long addr)
25269
25270 const char *arch_vma_name(struct vm_area_struct *vma)
25271 {
25272 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
25273 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
25274 return "[vdso]";
25275 if (vma == &gate_vma)
25276 return "[vsyscall]";
25277 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
25278 index 7b179b4..6bd1777 100644
25279 --- a/arch/x86/mm/iomap_32.c
25280 +++ b/arch/x86/mm/iomap_32.c
25281 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
25282 type = kmap_atomic_idx_push();
25283 idx = type + KM_TYPE_NR * smp_processor_id();
25284 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
25285 +
25286 + pax_open_kernel();
25287 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
25288 + pax_close_kernel();
25289 +
25290 arch_flush_lazy_mmu_mode();
25291
25292 return (void *)vaddr;
25293 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
25294 index 78fe3f1..8293b6f 100644
25295 --- a/arch/x86/mm/ioremap.c
25296 +++ b/arch/x86/mm/ioremap.c
25297 @@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
25298 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
25299 int is_ram = page_is_ram(pfn);
25300
25301 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
25302 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
25303 return NULL;
25304 WARN_ON_ONCE(is_ram);
25305 }
25306 @@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
25307
25308 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
25309 if (page_is_ram(start >> PAGE_SHIFT))
25310 +#ifdef CONFIG_HIGHMEM
25311 + if ((start >> PAGE_SHIFT) < max_low_pfn)
25312 +#endif
25313 return __va(phys);
25314
25315 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
25316 @@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
25317 early_param("early_ioremap_debug", early_ioremap_debug_setup);
25318
25319 static __initdata int after_paging_init;
25320 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
25321 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
25322
25323 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
25324 {
25325 @@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
25326 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
25327
25328 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
25329 - memset(bm_pte, 0, sizeof(bm_pte));
25330 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
25331 + pmd_populate_user(&init_mm, pmd, bm_pte);
25332
25333 /*
25334 * The boot-ioremap range spans multiple pmds, for which
25335 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
25336 index d87dd6d..bf3fa66 100644
25337 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
25338 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
25339 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
25340 * memory (e.g. tracked pages)? For now, we need this to avoid
25341 * invoking kmemcheck for PnP BIOS calls.
25342 */
25343 - if (regs->flags & X86_VM_MASK)
25344 + if (v8086_mode(regs))
25345 return false;
25346 - if (regs->cs != __KERNEL_CS)
25347 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
25348 return false;
25349
25350 pte = kmemcheck_pte_lookup(address);
25351 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
25352 index 845df68..1d8d29f 100644
25353 --- a/arch/x86/mm/mmap.c
25354 +++ b/arch/x86/mm/mmap.c
25355 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
25356 * Leave an at least ~128 MB hole with possible stack randomization.
25357 */
25358 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
25359 -#define MAX_GAP (TASK_SIZE/6*5)
25360 +#define MAX_GAP (pax_task_size/6*5)
25361
25362 static int mmap_is_legacy(void)
25363 {
25364 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
25365 return rnd << PAGE_SHIFT;
25366 }
25367
25368 -static unsigned long mmap_base(void)
25369 +static unsigned long mmap_base(struct mm_struct *mm)
25370 {
25371 unsigned long gap = rlimit(RLIMIT_STACK);
25372 + unsigned long pax_task_size = TASK_SIZE;
25373 +
25374 +#ifdef CONFIG_PAX_SEGMEXEC
25375 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25376 + pax_task_size = SEGMEXEC_TASK_SIZE;
25377 +#endif
25378
25379 if (gap < MIN_GAP)
25380 gap = MIN_GAP;
25381 else if (gap > MAX_GAP)
25382 gap = MAX_GAP;
25383
25384 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
25385 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
25386 }
25387
25388 /*
25389 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
25390 * does, but not when emulating X86_32
25391 */
25392 -static unsigned long mmap_legacy_base(void)
25393 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
25394 {
25395 - if (mmap_is_ia32())
25396 + if (mmap_is_ia32()) {
25397 +
25398 +#ifdef CONFIG_PAX_SEGMEXEC
25399 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25400 + return SEGMEXEC_TASK_UNMAPPED_BASE;
25401 + else
25402 +#endif
25403 +
25404 return TASK_UNMAPPED_BASE;
25405 - else
25406 + } else
25407 return TASK_UNMAPPED_BASE + mmap_rnd();
25408 }
25409
25410 @@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
25411 void arch_pick_mmap_layout(struct mm_struct *mm)
25412 {
25413 if (mmap_is_legacy()) {
25414 - mm->mmap_base = mmap_legacy_base();
25415 + mm->mmap_base = mmap_legacy_base(mm);
25416 +
25417 +#ifdef CONFIG_PAX_RANDMMAP
25418 + if (mm->pax_flags & MF_PAX_RANDMMAP)
25419 + mm->mmap_base += mm->delta_mmap;
25420 +#endif
25421 +
25422 mm->get_unmapped_area = arch_get_unmapped_area;
25423 mm->unmap_area = arch_unmap_area;
25424 } else {
25425 - mm->mmap_base = mmap_base();
25426 + mm->mmap_base = mmap_base(mm);
25427 +
25428 +#ifdef CONFIG_PAX_RANDMMAP
25429 + if (mm->pax_flags & MF_PAX_RANDMMAP)
25430 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
25431 +#endif
25432 +
25433 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
25434 mm->unmap_area = arch_unmap_area_topdown;
25435 }
25436 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
25437 index dc0b727..dc9d71a 100644
25438 --- a/arch/x86/mm/mmio-mod.c
25439 +++ b/arch/x86/mm/mmio-mod.c
25440 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
25441 break;
25442 default:
25443 {
25444 - unsigned char *ip = (unsigned char *)instptr;
25445 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
25446 my_trace->opcode = MMIO_UNKNOWN_OP;
25447 my_trace->width = 0;
25448 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
25449 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
25450 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25451 void __iomem *addr)
25452 {
25453 - static atomic_t next_id;
25454 + static atomic_unchecked_t next_id;
25455 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
25456 /* These are page-unaligned. */
25457 struct mmiotrace_map map = {
25458 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25459 .private = trace
25460 },
25461 .phys = offset,
25462 - .id = atomic_inc_return(&next_id)
25463 + .id = atomic_inc_return_unchecked(&next_id)
25464 };
25465 map.map_id = trace->id;
25466
25467 diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
25468 index b008656..773eac2 100644
25469 --- a/arch/x86/mm/pageattr-test.c
25470 +++ b/arch/x86/mm/pageattr-test.c
25471 @@ -36,7 +36,7 @@ enum {
25472
25473 static int pte_testbit(pte_t pte)
25474 {
25475 - return pte_flags(pte) & _PAGE_UNUSED1;
25476 + return pte_flags(pte) & _PAGE_CPA_TEST;
25477 }
25478
25479 struct split_state {
25480 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
25481 index a718e0d..45efc32 100644
25482 --- a/arch/x86/mm/pageattr.c
25483 +++ b/arch/x86/mm/pageattr.c
25484 @@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25485 */
25486 #ifdef CONFIG_PCI_BIOS
25487 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
25488 - pgprot_val(forbidden) |= _PAGE_NX;
25489 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25490 #endif
25491
25492 /*
25493 @@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25494 * Does not cover __inittext since that is gone later on. On
25495 * 64bit we do not enforce !NX on the low mapping
25496 */
25497 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
25498 - pgprot_val(forbidden) |= _PAGE_NX;
25499 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
25500 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25501
25502 +#ifdef CONFIG_DEBUG_RODATA
25503 /*
25504 * The .rodata section needs to be read-only. Using the pfn
25505 * catches all aliases.
25506 @@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25507 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
25508 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
25509 pgprot_val(forbidden) |= _PAGE_RW;
25510 +#endif
25511
25512 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
25513 /*
25514 @@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25515 }
25516 #endif
25517
25518 +#ifdef CONFIG_PAX_KERNEXEC
25519 + if (within(pfn, __pa((unsigned long)&_text), __pa((unsigned long)&_sdata))) {
25520 + pgprot_val(forbidden) |= _PAGE_RW;
25521 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25522 + }
25523 +#endif
25524 +
25525 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
25526
25527 return prot;
25528 @@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
25529 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
25530 {
25531 /* change init_mm */
25532 + pax_open_kernel();
25533 set_pte_atomic(kpte, pte);
25534 +
25535 #ifdef CONFIG_X86_32
25536 if (!SHARED_KERNEL_PMD) {
25537 +
25538 +#ifdef CONFIG_PAX_PER_CPU_PGD
25539 + unsigned long cpu;
25540 +#else
25541 struct page *page;
25542 +#endif
25543
25544 +#ifdef CONFIG_PAX_PER_CPU_PGD
25545 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25546 + pgd_t *pgd = get_cpu_pgd(cpu);
25547 +#else
25548 list_for_each_entry(page, &pgd_list, lru) {
25549 - pgd_t *pgd;
25550 + pgd_t *pgd = (pgd_t *)page_address(page);
25551 +#endif
25552 +
25553 pud_t *pud;
25554 pmd_t *pmd;
25555
25556 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
25557 + pgd += pgd_index(address);
25558 pud = pud_offset(pgd, address);
25559 pmd = pmd_offset(pud, address);
25560 set_pte_atomic((pte_t *)pmd, pte);
25561 }
25562 }
25563 #endif
25564 + pax_close_kernel();
25565 }
25566
25567 static int
25568 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
25569 index 3d68ef6..7f69136 100644
25570 --- a/arch/x86/mm/pat.c
25571 +++ b/arch/x86/mm/pat.c
25572 @@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
25573
25574 if (!entry) {
25575 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
25576 - current->comm, current->pid, start, end - 1);
25577 + current->comm, task_pid_nr(current), start, end - 1);
25578 return -EINVAL;
25579 }
25580
25581 @@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
25582
25583 while (cursor < to) {
25584 if (!devmem_is_allowed(pfn)) {
25585 - printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
25586 - current->comm, from, to - 1);
25587 + printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
25588 + current->comm, from, to - 1, cursor);
25589 return 0;
25590 }
25591 cursor += PAGE_SIZE;
25592 @@ -570,7 +570,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
25593 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
25594 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
25595 "for [mem %#010Lx-%#010Lx]\n",
25596 - current->comm, current->pid,
25597 + current->comm, task_pid_nr(current),
25598 cattr_name(flags),
25599 base, (unsigned long long)(base + size-1));
25600 return -EINVAL;
25601 @@ -605,7 +605,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25602 flags = lookup_memtype(paddr);
25603 if (want_flags != flags) {
25604 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
25605 - current->comm, current->pid,
25606 + current->comm, task_pid_nr(current),
25607 cattr_name(want_flags),
25608 (unsigned long long)paddr,
25609 (unsigned long long)(paddr + size - 1),
25610 @@ -627,7 +627,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25611 free_memtype(paddr, paddr + size);
25612 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
25613 " for [mem %#010Lx-%#010Lx], got %s\n",
25614 - current->comm, current->pid,
25615 + current->comm, task_pid_nr(current),
25616 cattr_name(want_flags),
25617 (unsigned long long)paddr,
25618 (unsigned long long)(paddr + size - 1),
25619 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
25620 index 9f0614d..92ae64a 100644
25621 --- a/arch/x86/mm/pf_in.c
25622 +++ b/arch/x86/mm/pf_in.c
25623 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
25624 int i;
25625 enum reason_type rv = OTHERS;
25626
25627 - p = (unsigned char *)ins_addr;
25628 + p = (unsigned char *)ktla_ktva(ins_addr);
25629 p += skip_prefix(p, &prf);
25630 p += get_opcode(p, &opcode);
25631
25632 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
25633 struct prefix_bits prf;
25634 int i;
25635
25636 - p = (unsigned char *)ins_addr;
25637 + p = (unsigned char *)ktla_ktva(ins_addr);
25638 p += skip_prefix(p, &prf);
25639 p += get_opcode(p, &opcode);
25640
25641 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
25642 struct prefix_bits prf;
25643 int i;
25644
25645 - p = (unsigned char *)ins_addr;
25646 + p = (unsigned char *)ktla_ktva(ins_addr);
25647 p += skip_prefix(p, &prf);
25648 p += get_opcode(p, &opcode);
25649
25650 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
25651 struct prefix_bits prf;
25652 int i;
25653
25654 - p = (unsigned char *)ins_addr;
25655 + p = (unsigned char *)ktla_ktva(ins_addr);
25656 p += skip_prefix(p, &prf);
25657 p += get_opcode(p, &opcode);
25658 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
25659 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
25660 struct prefix_bits prf;
25661 int i;
25662
25663 - p = (unsigned char *)ins_addr;
25664 + p = (unsigned char *)ktla_ktva(ins_addr);
25665 p += skip_prefix(p, &prf);
25666 p += get_opcode(p, &opcode);
25667 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
25668 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
25669 index 8573b83..4f3ed7e 100644
25670 --- a/arch/x86/mm/pgtable.c
25671 +++ b/arch/x86/mm/pgtable.c
25672 @@ -84,10 +84,64 @@ static inline void pgd_list_del(pgd_t *pgd)
25673 list_del(&page->lru);
25674 }
25675
25676 -#define UNSHARED_PTRS_PER_PGD \
25677 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25678 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25679 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
25680
25681 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
25682 +{
25683 + unsigned int count = USER_PGD_PTRS;
25684
25685 + while (count--)
25686 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
25687 +}
25688 +#endif
25689 +
25690 +#ifdef CONFIG_PAX_PER_CPU_PGD
25691 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
25692 +{
25693 + unsigned int count = USER_PGD_PTRS;
25694 +
25695 + while (count--) {
25696 + pgd_t pgd;
25697 +
25698 +#ifdef CONFIG_X86_64
25699 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
25700 +#else
25701 + pgd = *src++;
25702 +#endif
25703 +
25704 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25705 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
25706 +#endif
25707 +
25708 + *dst++ = pgd;
25709 + }
25710 +
25711 +}
25712 +#endif
25713 +
25714 +#ifdef CONFIG_X86_64
25715 +#define pxd_t pud_t
25716 +#define pyd_t pgd_t
25717 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
25718 +#define pxd_free(mm, pud) pud_free((mm), (pud))
25719 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
25720 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
25721 +#define PYD_SIZE PGDIR_SIZE
25722 +#else
25723 +#define pxd_t pmd_t
25724 +#define pyd_t pud_t
25725 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
25726 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
25727 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
25728 +#define pyd_offset(mm, address) pud_offset((mm), (address))
25729 +#define PYD_SIZE PUD_SIZE
25730 +#endif
25731 +
25732 +#ifdef CONFIG_PAX_PER_CPU_PGD
25733 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
25734 +static inline void pgd_dtor(pgd_t *pgd) {}
25735 +#else
25736 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
25737 {
25738 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
25739 @@ -128,6 +182,7 @@ static void pgd_dtor(pgd_t *pgd)
25740 pgd_list_del(pgd);
25741 spin_unlock(&pgd_lock);
25742 }
25743 +#endif
25744
25745 /*
25746 * List of all pgd's needed for non-PAE so it can invalidate entries
25747 @@ -140,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
25748 * -- wli
25749 */
25750
25751 -#ifdef CONFIG_X86_PAE
25752 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25753 /*
25754 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
25755 * updating the top-level pagetable entries to guarantee the
25756 @@ -152,7 +207,7 @@ static void pgd_dtor(pgd_t *pgd)
25757 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
25758 * and initialize the kernel pmds here.
25759 */
25760 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
25761 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25762
25763 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25764 {
25765 @@ -170,36 +225,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25766 */
25767 flush_tlb_mm(mm);
25768 }
25769 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
25770 +#define PREALLOCATED_PXDS USER_PGD_PTRS
25771 #else /* !CONFIG_X86_PAE */
25772
25773 /* No need to prepopulate any pagetable entries in non-PAE modes. */
25774 -#define PREALLOCATED_PMDS 0
25775 +#define PREALLOCATED_PXDS 0
25776
25777 #endif /* CONFIG_X86_PAE */
25778
25779 -static void free_pmds(pmd_t *pmds[])
25780 +static void free_pxds(pxd_t *pxds[])
25781 {
25782 int i;
25783
25784 - for(i = 0; i < PREALLOCATED_PMDS; i++)
25785 - if (pmds[i])
25786 - free_page((unsigned long)pmds[i]);
25787 + for(i = 0; i < PREALLOCATED_PXDS; i++)
25788 + if (pxds[i])
25789 + free_page((unsigned long)pxds[i]);
25790 }
25791
25792 -static int preallocate_pmds(pmd_t *pmds[])
25793 +static int preallocate_pxds(pxd_t *pxds[])
25794 {
25795 int i;
25796 bool failed = false;
25797
25798 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
25799 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
25800 - if (pmd == NULL)
25801 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
25802 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
25803 + if (pxd == NULL)
25804 failed = true;
25805 - pmds[i] = pmd;
25806 + pxds[i] = pxd;
25807 }
25808
25809 if (failed) {
25810 - free_pmds(pmds);
25811 + free_pxds(pxds);
25812 return -ENOMEM;
25813 }
25814
25815 @@ -212,51 +269,55 @@ static int preallocate_pmds(pmd_t *pmds[])
25816 * preallocate which never got a corresponding vma will need to be
25817 * freed manually.
25818 */
25819 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
25820 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
25821 {
25822 int i;
25823
25824 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
25825 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
25826 pgd_t pgd = pgdp[i];
25827
25828 if (pgd_val(pgd) != 0) {
25829 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
25830 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
25831
25832 - pgdp[i] = native_make_pgd(0);
25833 + set_pgd(pgdp + i, native_make_pgd(0));
25834
25835 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
25836 - pmd_free(mm, pmd);
25837 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
25838 + pxd_free(mm, pxd);
25839 }
25840 }
25841 }
25842
25843 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
25844 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
25845 {
25846 - pud_t *pud;
25847 + pyd_t *pyd;
25848 unsigned long addr;
25849 int i;
25850
25851 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
25852 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
25853 return;
25854
25855 - pud = pud_offset(pgd, 0);
25856 +#ifdef CONFIG_X86_64
25857 + pyd = pyd_offset(mm, 0L);
25858 +#else
25859 + pyd = pyd_offset(pgd, 0L);
25860 +#endif
25861
25862 - for (addr = i = 0; i < PREALLOCATED_PMDS;
25863 - i++, pud++, addr += PUD_SIZE) {
25864 - pmd_t *pmd = pmds[i];
25865 + for (addr = i = 0; i < PREALLOCATED_PXDS;
25866 + i++, pyd++, addr += PYD_SIZE) {
25867 + pxd_t *pxd = pxds[i];
25868
25869 if (i >= KERNEL_PGD_BOUNDARY)
25870 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25871 - sizeof(pmd_t) * PTRS_PER_PMD);
25872 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25873 + sizeof(pxd_t) * PTRS_PER_PMD);
25874
25875 - pud_populate(mm, pud, pmd);
25876 + pyd_populate(mm, pyd, pxd);
25877 }
25878 }
25879
25880 pgd_t *pgd_alloc(struct mm_struct *mm)
25881 {
25882 pgd_t *pgd;
25883 - pmd_t *pmds[PREALLOCATED_PMDS];
25884 + pxd_t *pxds[PREALLOCATED_PXDS];
25885
25886 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
25887
25888 @@ -265,11 +326,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25889
25890 mm->pgd = pgd;
25891
25892 - if (preallocate_pmds(pmds) != 0)
25893 + if (preallocate_pxds(pxds) != 0)
25894 goto out_free_pgd;
25895
25896 if (paravirt_pgd_alloc(mm) != 0)
25897 - goto out_free_pmds;
25898 + goto out_free_pxds;
25899
25900 /*
25901 * Make sure that pre-populating the pmds is atomic with
25902 @@ -279,14 +340,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25903 spin_lock(&pgd_lock);
25904
25905 pgd_ctor(mm, pgd);
25906 - pgd_prepopulate_pmd(mm, pgd, pmds);
25907 + pgd_prepopulate_pxd(mm, pgd, pxds);
25908
25909 spin_unlock(&pgd_lock);
25910
25911 return pgd;
25912
25913 -out_free_pmds:
25914 - free_pmds(pmds);
25915 +out_free_pxds:
25916 + free_pxds(pxds);
25917 out_free_pgd:
25918 free_page((unsigned long)pgd);
25919 out:
25920 @@ -295,7 +356,7 @@ out:
25921
25922 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
25923 {
25924 - pgd_mop_up_pmds(mm, pgd);
25925 + pgd_mop_up_pxds(mm, pgd);
25926 pgd_dtor(pgd);
25927 paravirt_pgd_free(mm, pgd);
25928 free_page((unsigned long)pgd);
25929 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
25930 index a69bcb8..19068ab 100644
25931 --- a/arch/x86/mm/pgtable_32.c
25932 +++ b/arch/x86/mm/pgtable_32.c
25933 @@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
25934 return;
25935 }
25936 pte = pte_offset_kernel(pmd, vaddr);
25937 +
25938 + pax_open_kernel();
25939 if (pte_val(pteval))
25940 set_pte_at(&init_mm, vaddr, pte, pteval);
25941 else
25942 pte_clear(&init_mm, vaddr, pte);
25943 + pax_close_kernel();
25944
25945 /*
25946 * It's enough to flush this one mapping.
25947 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
25948 index 410531d..0f16030 100644
25949 --- a/arch/x86/mm/setup_nx.c
25950 +++ b/arch/x86/mm/setup_nx.c
25951 @@ -5,8 +5,10 @@
25952 #include <asm/pgtable.h>
25953 #include <asm/proto.h>
25954
25955 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25956 static int disable_nx __cpuinitdata;
25957
25958 +#ifndef CONFIG_PAX_PAGEEXEC
25959 /*
25960 * noexec = on|off
25961 *
25962 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
25963 return 0;
25964 }
25965 early_param("noexec", noexec_setup);
25966 +#endif
25967 +
25968 +#endif
25969
25970 void __cpuinit x86_configure_nx(void)
25971 {
25972 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25973 if (cpu_has_nx && !disable_nx)
25974 __supported_pte_mask |= _PAGE_NX;
25975 else
25976 +#endif
25977 __supported_pte_mask &= ~_PAGE_NX;
25978 }
25979
25980 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
25981 index 613cd83..3a21f1c 100644
25982 --- a/arch/x86/mm/tlb.c
25983 +++ b/arch/x86/mm/tlb.c
25984 @@ -48,7 +48,11 @@ void leave_mm(int cpu)
25985 BUG();
25986 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
25987 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
25988 +
25989 +#ifndef CONFIG_PAX_PER_CPU_PGD
25990 load_cr3(swapper_pg_dir);
25991 +#endif
25992 +
25993 }
25994 }
25995 EXPORT_SYMBOL_GPL(leave_mm);
25996 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
25997 index 877b9a1..a8ecf42 100644
25998 --- a/arch/x86/net/bpf_jit.S
25999 +++ b/arch/x86/net/bpf_jit.S
26000 @@ -9,6 +9,7 @@
26001 */
26002 #include <linux/linkage.h>
26003 #include <asm/dwarf2.h>
26004 +#include <asm/alternative-asm.h>
26005
26006 /*
26007 * Calling convention :
26008 @@ -35,6 +36,7 @@ sk_load_word_positive_offset:
26009 jle bpf_slow_path_word
26010 mov (SKBDATA,%rsi),%eax
26011 bswap %eax /* ntohl() */
26012 + pax_force_retaddr
26013 ret
26014
26015 sk_load_half:
26016 @@ -52,6 +54,7 @@ sk_load_half_positive_offset:
26017 jle bpf_slow_path_half
26018 movzwl (SKBDATA,%rsi),%eax
26019 rol $8,%ax # ntohs()
26020 + pax_force_retaddr
26021 ret
26022
26023 sk_load_byte:
26024 @@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
26025 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
26026 jle bpf_slow_path_byte
26027 movzbl (SKBDATA,%rsi),%eax
26028 + pax_force_retaddr
26029 ret
26030
26031 /**
26032 @@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
26033 movzbl (SKBDATA,%rsi),%ebx
26034 and $15,%bl
26035 shl $2,%bl
26036 + pax_force_retaddr
26037 ret
26038
26039 /* rsi contains offset and can be scratched */
26040 @@ -109,6 +114,7 @@ bpf_slow_path_word:
26041 js bpf_error
26042 mov -12(%rbp),%eax
26043 bswap %eax
26044 + pax_force_retaddr
26045 ret
26046
26047 bpf_slow_path_half:
26048 @@ -117,12 +123,14 @@ bpf_slow_path_half:
26049 mov -12(%rbp),%ax
26050 rol $8,%ax
26051 movzwl %ax,%eax
26052 + pax_force_retaddr
26053 ret
26054
26055 bpf_slow_path_byte:
26056 bpf_slow_path_common(1)
26057 js bpf_error
26058 movzbl -12(%rbp),%eax
26059 + pax_force_retaddr
26060 ret
26061
26062 bpf_slow_path_byte_msh:
26063 @@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
26064 and $15,%al
26065 shl $2,%al
26066 xchg %eax,%ebx
26067 + pax_force_retaddr
26068 ret
26069
26070 #define sk_negative_common(SIZE) \
26071 @@ -157,6 +166,7 @@ sk_load_word_negative_offset:
26072 sk_negative_common(4)
26073 mov (%rax), %eax
26074 bswap %eax
26075 + pax_force_retaddr
26076 ret
26077
26078 bpf_slow_path_half_neg:
26079 @@ -168,6 +178,7 @@ sk_load_half_negative_offset:
26080 mov (%rax),%ax
26081 rol $8,%ax
26082 movzwl %ax,%eax
26083 + pax_force_retaddr
26084 ret
26085
26086 bpf_slow_path_byte_neg:
26087 @@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
26088 .globl sk_load_byte_negative_offset
26089 sk_negative_common(1)
26090 movzbl (%rax), %eax
26091 + pax_force_retaddr
26092 ret
26093
26094 bpf_slow_path_byte_msh_neg:
26095 @@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
26096 and $15,%al
26097 shl $2,%al
26098 xchg %eax,%ebx
26099 + pax_force_retaddr
26100 ret
26101
26102 bpf_error:
26103 @@ -197,4 +210,5 @@ bpf_error:
26104 xor %eax,%eax
26105 mov -8(%rbp),%rbx
26106 leaveq
26107 + pax_force_retaddr
26108 ret
26109 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
26110 index 33643a8..8e44870 100644
26111 --- a/arch/x86/net/bpf_jit_comp.c
26112 +++ b/arch/x86/net/bpf_jit_comp.c
26113 @@ -120,6 +120,11 @@ static inline void bpf_flush_icache(void *start, void *end)
26114 set_fs(old_fs);
26115 }
26116
26117 +struct bpf_jit_work {
26118 + struct work_struct work;
26119 + void *image;
26120 +};
26121 +
26122 #define CHOOSE_LOAD_FUNC(K, func) \
26123 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
26124
26125 @@ -146,6 +151,10 @@ void bpf_jit_compile(struct sk_filter *fp)
26126 if (addrs == NULL)
26127 return;
26128
26129 + fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
26130 + if (!fp->work)
26131 + goto out;
26132 +
26133 /* Before first pass, make a rough estimation of addrs[]
26134 * each bpf instruction is translated to less than 64 bytes
26135 */
26136 @@ -593,17 +602,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26137 break;
26138 default:
26139 /* hmm, too complex filter, give up with jit compiler */
26140 - goto out;
26141 + goto error;
26142 }
26143 ilen = prog - temp;
26144 if (image) {
26145 if (unlikely(proglen + ilen > oldproglen)) {
26146 pr_err("bpb_jit_compile fatal error\n");
26147 - kfree(addrs);
26148 - module_free(NULL, image);
26149 - return;
26150 + module_free_exec(NULL, image);
26151 + goto error;
26152 }
26153 + pax_open_kernel();
26154 memcpy(image + proglen, temp, ilen);
26155 + pax_close_kernel();
26156 }
26157 proglen += ilen;
26158 addrs[i] = proglen;
26159 @@ -624,11 +634,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26160 break;
26161 }
26162 if (proglen == oldproglen) {
26163 - image = module_alloc(max_t(unsigned int,
26164 - proglen,
26165 - sizeof(struct work_struct)));
26166 + image = module_alloc_exec(proglen);
26167 if (!image)
26168 - goto out;
26169 + goto error;
26170 }
26171 oldproglen = proglen;
26172 }
26173 @@ -644,7 +652,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26174 bpf_flush_icache(image, image + proglen);
26175
26176 fp->bpf_func = (void *)image;
26177 - }
26178 + } else
26179 +error:
26180 + kfree(fp->work);
26181 +
26182 out:
26183 kfree(addrs);
26184 return;
26185 @@ -652,18 +663,20 @@ out:
26186
26187 static void jit_free_defer(struct work_struct *arg)
26188 {
26189 - module_free(NULL, arg);
26190 + module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
26191 + kfree(arg);
26192 }
26193
26194 /* run from softirq, we must use a work_struct to call
26195 - * module_free() from process context
26196 + * module_free_exec() from process context
26197 */
26198 void bpf_jit_free(struct sk_filter *fp)
26199 {
26200 if (fp->bpf_func != sk_run_filter) {
26201 - struct work_struct *work = (struct work_struct *)fp->bpf_func;
26202 + struct work_struct *work = &fp->work->work;
26203
26204 INIT_WORK(work, jit_free_defer);
26205 + fp->work->image = fp->bpf_func;
26206 schedule_work(work);
26207 }
26208 }
26209 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
26210 index d6aa6e8..266395a 100644
26211 --- a/arch/x86/oprofile/backtrace.c
26212 +++ b/arch/x86/oprofile/backtrace.c
26213 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
26214 struct stack_frame_ia32 *fp;
26215 unsigned long bytes;
26216
26217 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
26218 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
26219 if (bytes != sizeof(bufhead))
26220 return NULL;
26221
26222 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
26223 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
26224
26225 oprofile_add_trace(bufhead[0].return_address);
26226
26227 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
26228 struct stack_frame bufhead[2];
26229 unsigned long bytes;
26230
26231 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
26232 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
26233 if (bytes != sizeof(bufhead))
26234 return NULL;
26235
26236 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
26237 {
26238 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
26239
26240 - if (!user_mode_vm(regs)) {
26241 + if (!user_mode(regs)) {
26242 unsigned long stack = kernel_stack_pointer(regs);
26243 if (depth)
26244 dump_trace(NULL, regs, (unsigned long *)stack, 0,
26245 diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
26246 index e14a2ff..3fd6b58 100644
26247 --- a/arch/x86/pci/mrst.c
26248 +++ b/arch/x86/pci/mrst.c
26249 @@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
26250 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
26251 pci_mmcfg_late_init();
26252 pcibios_enable_irq = mrst_pci_irq_enable;
26253 - pci_root_ops = pci_mrst_ops;
26254 + pax_open_kernel();
26255 + memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
26256 + pax_close_kernel();
26257 pci_soc_mode = 1;
26258 /* Continue with standard init */
26259 return 1;
26260 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
26261 index da8fe05..7ee6704 100644
26262 --- a/arch/x86/pci/pcbios.c
26263 +++ b/arch/x86/pci/pcbios.c
26264 @@ -79,50 +79,93 @@ union bios32 {
26265 static struct {
26266 unsigned long address;
26267 unsigned short segment;
26268 -} bios32_indirect = { 0, __KERNEL_CS };
26269 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
26270
26271 /*
26272 * Returns the entry point for the given service, NULL on error
26273 */
26274
26275 -static unsigned long bios32_service(unsigned long service)
26276 +static unsigned long __devinit bios32_service(unsigned long service)
26277 {
26278 unsigned char return_code; /* %al */
26279 unsigned long address; /* %ebx */
26280 unsigned long length; /* %ecx */
26281 unsigned long entry; /* %edx */
26282 unsigned long flags;
26283 + struct desc_struct d, *gdt;
26284
26285 local_irq_save(flags);
26286 - __asm__("lcall *(%%edi); cld"
26287 +
26288 + gdt = get_cpu_gdt_table(smp_processor_id());
26289 +
26290 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
26291 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26292 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
26293 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26294 +
26295 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
26296 : "=a" (return_code),
26297 "=b" (address),
26298 "=c" (length),
26299 "=d" (entry)
26300 : "0" (service),
26301 "1" (0),
26302 - "D" (&bios32_indirect));
26303 + "D" (&bios32_indirect),
26304 + "r"(__PCIBIOS_DS)
26305 + : "memory");
26306 +
26307 + pax_open_kernel();
26308 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
26309 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
26310 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
26311 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
26312 + pax_close_kernel();
26313 +
26314 local_irq_restore(flags);
26315
26316 switch (return_code) {
26317 - case 0:
26318 - return address + entry;
26319 - case 0x80: /* Not present */
26320 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26321 - return 0;
26322 - default: /* Shouldn't happen */
26323 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26324 - service, return_code);
26325 + case 0: {
26326 + int cpu;
26327 + unsigned char flags;
26328 +
26329 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
26330 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
26331 + printk(KERN_WARNING "bios32_service: not valid\n");
26332 return 0;
26333 + }
26334 + address = address + PAGE_OFFSET;
26335 + length += 16UL; /* some BIOSs underreport this... */
26336 + flags = 4;
26337 + if (length >= 64*1024*1024) {
26338 + length >>= PAGE_SHIFT;
26339 + flags |= 8;
26340 + }
26341 +
26342 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
26343 + gdt = get_cpu_gdt_table(cpu);
26344 + pack_descriptor(&d, address, length, 0x9b, flags);
26345 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26346 + pack_descriptor(&d, address, length, 0x93, flags);
26347 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26348 + }
26349 + return entry;
26350 + }
26351 + case 0x80: /* Not present */
26352 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26353 + return 0;
26354 + default: /* Shouldn't happen */
26355 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26356 + service, return_code);
26357 + return 0;
26358 }
26359 }
26360
26361 static struct {
26362 unsigned long address;
26363 unsigned short segment;
26364 -} pci_indirect = { 0, __KERNEL_CS };
26365 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
26366
26367 -static int pci_bios_present;
26368 +static int pci_bios_present __read_only;
26369
26370 static int __devinit check_pcibios(void)
26371 {
26372 @@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
26373 unsigned long flags, pcibios_entry;
26374
26375 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
26376 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
26377 + pci_indirect.address = pcibios_entry;
26378
26379 local_irq_save(flags);
26380 - __asm__(
26381 - "lcall *(%%edi); cld\n\t"
26382 + __asm__("movw %w6, %%ds\n\t"
26383 + "lcall *%%ss:(%%edi); cld\n\t"
26384 + "push %%ss\n\t"
26385 + "pop %%ds\n\t"
26386 "jc 1f\n\t"
26387 "xor %%ah, %%ah\n"
26388 "1:"
26389 @@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
26390 "=b" (ebx),
26391 "=c" (ecx)
26392 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
26393 - "D" (&pci_indirect)
26394 + "D" (&pci_indirect),
26395 + "r" (__PCIBIOS_DS)
26396 : "memory");
26397 local_irq_restore(flags);
26398
26399 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26400
26401 switch (len) {
26402 case 1:
26403 - __asm__("lcall *(%%esi); cld\n\t"
26404 + __asm__("movw %w6, %%ds\n\t"
26405 + "lcall *%%ss:(%%esi); cld\n\t"
26406 + "push %%ss\n\t"
26407 + "pop %%ds\n\t"
26408 "jc 1f\n\t"
26409 "xor %%ah, %%ah\n"
26410 "1:"
26411 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26412 : "1" (PCIBIOS_READ_CONFIG_BYTE),
26413 "b" (bx),
26414 "D" ((long)reg),
26415 - "S" (&pci_indirect));
26416 + "S" (&pci_indirect),
26417 + "r" (__PCIBIOS_DS));
26418 /*
26419 * Zero-extend the result beyond 8 bits, do not trust the
26420 * BIOS having done it:
26421 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26422 *value &= 0xff;
26423 break;
26424 case 2:
26425 - __asm__("lcall *(%%esi); cld\n\t"
26426 + __asm__("movw %w6, %%ds\n\t"
26427 + "lcall *%%ss:(%%esi); cld\n\t"
26428 + "push %%ss\n\t"
26429 + "pop %%ds\n\t"
26430 "jc 1f\n\t"
26431 "xor %%ah, %%ah\n"
26432 "1:"
26433 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26434 : "1" (PCIBIOS_READ_CONFIG_WORD),
26435 "b" (bx),
26436 "D" ((long)reg),
26437 - "S" (&pci_indirect));
26438 + "S" (&pci_indirect),
26439 + "r" (__PCIBIOS_DS));
26440 /*
26441 * Zero-extend the result beyond 16 bits, do not trust the
26442 * BIOS having done it:
26443 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26444 *value &= 0xffff;
26445 break;
26446 case 4:
26447 - __asm__("lcall *(%%esi); cld\n\t"
26448 + __asm__("movw %w6, %%ds\n\t"
26449 + "lcall *%%ss:(%%esi); cld\n\t"
26450 + "push %%ss\n\t"
26451 + "pop %%ds\n\t"
26452 "jc 1f\n\t"
26453 "xor %%ah, %%ah\n"
26454 "1:"
26455 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26456 : "1" (PCIBIOS_READ_CONFIG_DWORD),
26457 "b" (bx),
26458 "D" ((long)reg),
26459 - "S" (&pci_indirect));
26460 + "S" (&pci_indirect),
26461 + "r" (__PCIBIOS_DS));
26462 break;
26463 }
26464
26465 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26466
26467 switch (len) {
26468 case 1:
26469 - __asm__("lcall *(%%esi); cld\n\t"
26470 + __asm__("movw %w6, %%ds\n\t"
26471 + "lcall *%%ss:(%%esi); cld\n\t"
26472 + "push %%ss\n\t"
26473 + "pop %%ds\n\t"
26474 "jc 1f\n\t"
26475 "xor %%ah, %%ah\n"
26476 "1:"
26477 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26478 "c" (value),
26479 "b" (bx),
26480 "D" ((long)reg),
26481 - "S" (&pci_indirect));
26482 + "S" (&pci_indirect),
26483 + "r" (__PCIBIOS_DS));
26484 break;
26485 case 2:
26486 - __asm__("lcall *(%%esi); cld\n\t"
26487 + __asm__("movw %w6, %%ds\n\t"
26488 + "lcall *%%ss:(%%esi); cld\n\t"
26489 + "push %%ss\n\t"
26490 + "pop %%ds\n\t"
26491 "jc 1f\n\t"
26492 "xor %%ah, %%ah\n"
26493 "1:"
26494 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26495 "c" (value),
26496 "b" (bx),
26497 "D" ((long)reg),
26498 - "S" (&pci_indirect));
26499 + "S" (&pci_indirect),
26500 + "r" (__PCIBIOS_DS));
26501 break;
26502 case 4:
26503 - __asm__("lcall *(%%esi); cld\n\t"
26504 + __asm__("movw %w6, %%ds\n\t"
26505 + "lcall *%%ss:(%%esi); cld\n\t"
26506 + "push %%ss\n\t"
26507 + "pop %%ds\n\t"
26508 "jc 1f\n\t"
26509 "xor %%ah, %%ah\n"
26510 "1:"
26511 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26512 "c" (value),
26513 "b" (bx),
26514 "D" ((long)reg),
26515 - "S" (&pci_indirect));
26516 + "S" (&pci_indirect),
26517 + "r" (__PCIBIOS_DS));
26518 break;
26519 }
26520
26521 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26522
26523 DBG("PCI: Fetching IRQ routing table... ");
26524 __asm__("push %%es\n\t"
26525 + "movw %w8, %%ds\n\t"
26526 "push %%ds\n\t"
26527 "pop %%es\n\t"
26528 - "lcall *(%%esi); cld\n\t"
26529 + "lcall *%%ss:(%%esi); cld\n\t"
26530 "pop %%es\n\t"
26531 + "push %%ss\n\t"
26532 + "pop %%ds\n"
26533 "jc 1f\n\t"
26534 "xor %%ah, %%ah\n"
26535 "1:"
26536 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26537 "1" (0),
26538 "D" ((long) &opt),
26539 "S" (&pci_indirect),
26540 - "m" (opt)
26541 + "m" (opt),
26542 + "r" (__PCIBIOS_DS)
26543 : "memory");
26544 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
26545 if (ret & 0xff00)
26546 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26547 {
26548 int ret;
26549
26550 - __asm__("lcall *(%%esi); cld\n\t"
26551 + __asm__("movw %w5, %%ds\n\t"
26552 + "lcall *%%ss:(%%esi); cld\n\t"
26553 + "push %%ss\n\t"
26554 + "pop %%ds\n"
26555 "jc 1f\n\t"
26556 "xor %%ah, %%ah\n"
26557 "1:"
26558 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26559 : "0" (PCIBIOS_SET_PCI_HW_INT),
26560 "b" ((dev->bus->number << 8) | dev->devfn),
26561 "c" ((irq << 8) | (pin + 10)),
26562 - "S" (&pci_indirect));
26563 + "S" (&pci_indirect),
26564 + "r" (__PCIBIOS_DS));
26565 return !(ret & 0xff00);
26566 }
26567 EXPORT_SYMBOL(pcibios_set_irq_routing);
26568 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
26569 index 40e4469..1ab536e 100644
26570 --- a/arch/x86/platform/efi/efi_32.c
26571 +++ b/arch/x86/platform/efi/efi_32.c
26572 @@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
26573 {
26574 struct desc_ptr gdt_descr;
26575
26576 +#ifdef CONFIG_PAX_KERNEXEC
26577 + struct desc_struct d;
26578 +#endif
26579 +
26580 local_irq_save(efi_rt_eflags);
26581
26582 load_cr3(initial_page_table);
26583 __flush_tlb_all();
26584
26585 +#ifdef CONFIG_PAX_KERNEXEC
26586 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
26587 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26588 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
26589 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26590 +#endif
26591 +
26592 gdt_descr.address = __pa(get_cpu_gdt_table(0));
26593 gdt_descr.size = GDT_SIZE - 1;
26594 load_gdt(&gdt_descr);
26595 @@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
26596 {
26597 struct desc_ptr gdt_descr;
26598
26599 +#ifdef CONFIG_PAX_KERNEXEC
26600 + struct desc_struct d;
26601 +
26602 + memset(&d, 0, sizeof d);
26603 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26604 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26605 +#endif
26606 +
26607 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
26608 gdt_descr.size = GDT_SIZE - 1;
26609 load_gdt(&gdt_descr);
26610 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
26611 index fbe66e6..eae5e38 100644
26612 --- a/arch/x86/platform/efi/efi_stub_32.S
26613 +++ b/arch/x86/platform/efi/efi_stub_32.S
26614 @@ -6,7 +6,9 @@
26615 */
26616
26617 #include <linux/linkage.h>
26618 +#include <linux/init.h>
26619 #include <asm/page_types.h>
26620 +#include <asm/segment.h>
26621
26622 /*
26623 * efi_call_phys(void *, ...) is a function with variable parameters.
26624 @@ -20,7 +22,7 @@
26625 * service functions will comply with gcc calling convention, too.
26626 */
26627
26628 -.text
26629 +__INIT
26630 ENTRY(efi_call_phys)
26631 /*
26632 * 0. The function can only be called in Linux kernel. So CS has been
26633 @@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
26634 * The mapping of lower virtual memory has been created in prelog and
26635 * epilog.
26636 */
26637 - movl $1f, %edx
26638 - subl $__PAGE_OFFSET, %edx
26639 - jmp *%edx
26640 +#ifdef CONFIG_PAX_KERNEXEC
26641 + movl $(__KERNEXEC_EFI_DS), %edx
26642 + mov %edx, %ds
26643 + mov %edx, %es
26644 + mov %edx, %ss
26645 + addl $2f,(1f)
26646 + ljmp *(1f)
26647 +
26648 +__INITDATA
26649 +1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
26650 +.previous
26651 +
26652 +2:
26653 + subl $2b,(1b)
26654 +#else
26655 + jmp 1f-__PAGE_OFFSET
26656 1:
26657 +#endif
26658
26659 /*
26660 * 2. Now on the top of stack is the return
26661 @@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
26662 * parameter 2, ..., param n. To make things easy, we save the return
26663 * address of efi_call_phys in a global variable.
26664 */
26665 - popl %edx
26666 - movl %edx, saved_return_addr
26667 - /* get the function pointer into ECX*/
26668 - popl %ecx
26669 - movl %ecx, efi_rt_function_ptr
26670 - movl $2f, %edx
26671 - subl $__PAGE_OFFSET, %edx
26672 - pushl %edx
26673 + popl (saved_return_addr)
26674 + popl (efi_rt_function_ptr)
26675
26676 /*
26677 * 3. Clear PG bit in %CR0.
26678 @@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
26679 /*
26680 * 5. Call the physical function.
26681 */
26682 - jmp *%ecx
26683 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
26684
26685 -2:
26686 /*
26687 * 6. After EFI runtime service returns, control will return to
26688 * following instruction. We'd better readjust stack pointer first.
26689 @@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
26690 movl %cr0, %edx
26691 orl $0x80000000, %edx
26692 movl %edx, %cr0
26693 - jmp 1f
26694 -1:
26695 +
26696 /*
26697 * 8. Now restore the virtual mode from flat mode by
26698 * adding EIP with PAGE_OFFSET.
26699 */
26700 - movl $1f, %edx
26701 - jmp *%edx
26702 +#ifdef CONFIG_PAX_KERNEXEC
26703 + movl $(__KERNEL_DS), %edx
26704 + mov %edx, %ds
26705 + mov %edx, %es
26706 + mov %edx, %ss
26707 + ljmp $(__KERNEL_CS),$1f
26708 +#else
26709 + jmp 1f+__PAGE_OFFSET
26710 +#endif
26711 1:
26712
26713 /*
26714 * 9. Balance the stack. And because EAX contain the return value,
26715 * we'd better not clobber it.
26716 */
26717 - leal efi_rt_function_ptr, %edx
26718 - movl (%edx), %ecx
26719 - pushl %ecx
26720 + pushl (efi_rt_function_ptr)
26721
26722 /*
26723 - * 10. Push the saved return address onto the stack and return.
26724 + * 10. Return to the saved return address.
26725 */
26726 - leal saved_return_addr, %edx
26727 - movl (%edx), %ecx
26728 - pushl %ecx
26729 - ret
26730 + jmpl *(saved_return_addr)
26731 ENDPROC(efi_call_phys)
26732 .previous
26733
26734 -.data
26735 +__INITDATA
26736 saved_return_addr:
26737 .long 0
26738 efi_rt_function_ptr:
26739 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
26740 index 4c07cca..2c8427d 100644
26741 --- a/arch/x86/platform/efi/efi_stub_64.S
26742 +++ b/arch/x86/platform/efi/efi_stub_64.S
26743 @@ -7,6 +7,7 @@
26744 */
26745
26746 #include <linux/linkage.h>
26747 +#include <asm/alternative-asm.h>
26748
26749 #define SAVE_XMM \
26750 mov %rsp, %rax; \
26751 @@ -40,6 +41,7 @@ ENTRY(efi_call0)
26752 call *%rdi
26753 addq $32, %rsp
26754 RESTORE_XMM
26755 + pax_force_retaddr 0, 1
26756 ret
26757 ENDPROC(efi_call0)
26758
26759 @@ -50,6 +52,7 @@ ENTRY(efi_call1)
26760 call *%rdi
26761 addq $32, %rsp
26762 RESTORE_XMM
26763 + pax_force_retaddr 0, 1
26764 ret
26765 ENDPROC(efi_call1)
26766
26767 @@ -60,6 +63,7 @@ ENTRY(efi_call2)
26768 call *%rdi
26769 addq $32, %rsp
26770 RESTORE_XMM
26771 + pax_force_retaddr 0, 1
26772 ret
26773 ENDPROC(efi_call2)
26774
26775 @@ -71,6 +75,7 @@ ENTRY(efi_call3)
26776 call *%rdi
26777 addq $32, %rsp
26778 RESTORE_XMM
26779 + pax_force_retaddr 0, 1
26780 ret
26781 ENDPROC(efi_call3)
26782
26783 @@ -83,6 +88,7 @@ ENTRY(efi_call4)
26784 call *%rdi
26785 addq $32, %rsp
26786 RESTORE_XMM
26787 + pax_force_retaddr 0, 1
26788 ret
26789 ENDPROC(efi_call4)
26790
26791 @@ -96,6 +102,7 @@ ENTRY(efi_call5)
26792 call *%rdi
26793 addq $48, %rsp
26794 RESTORE_XMM
26795 + pax_force_retaddr 0, 1
26796 ret
26797 ENDPROC(efi_call5)
26798
26799 @@ -112,5 +119,6 @@ ENTRY(efi_call6)
26800 call *%rdi
26801 addq $48, %rsp
26802 RESTORE_XMM
26803 + pax_force_retaddr 0, 1
26804 ret
26805 ENDPROC(efi_call6)
26806 diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
26807 index fd41a92..9c33628 100644
26808 --- a/arch/x86/platform/mrst/mrst.c
26809 +++ b/arch/x86/platform/mrst/mrst.c
26810 @@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
26811 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
26812 int sfi_mrtc_num;
26813
26814 -static void mrst_power_off(void)
26815 +static __noreturn void mrst_power_off(void)
26816 {
26817 + BUG();
26818 }
26819
26820 -static void mrst_reboot(void)
26821 +static __noreturn void mrst_reboot(void)
26822 {
26823 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
26824 + BUG();
26825 }
26826
26827 /* parse all the mtimer info to a static mtimer array */
26828 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
26829 index 218cdb1..fd55c08 100644
26830 --- a/arch/x86/power/cpu.c
26831 +++ b/arch/x86/power/cpu.c
26832 @@ -132,7 +132,7 @@ static void do_fpu_end(void)
26833 static void fix_processor_context(void)
26834 {
26835 int cpu = smp_processor_id();
26836 - struct tss_struct *t = &per_cpu(init_tss, cpu);
26837 + struct tss_struct *t = init_tss + cpu;
26838
26839 set_tss_desc(cpu, t); /*
26840 * This just modifies memory; should not be
26841 @@ -142,7 +142,9 @@ static void fix_processor_context(void)
26842 */
26843
26844 #ifdef CONFIG_X86_64
26845 + pax_open_kernel();
26846 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
26847 + pax_close_kernel();
26848
26849 syscall_init(); /* This sets MSR_*STAR and related */
26850 #endif
26851 diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
26852 index cbca565..bae7133 100644
26853 --- a/arch/x86/realmode/init.c
26854 +++ b/arch/x86/realmode/init.c
26855 @@ -62,7 +62,13 @@ void __init setup_real_mode(void)
26856 __va(real_mode_header->trampoline_header);
26857
26858 #ifdef CONFIG_X86_32
26859 - trampoline_header->start = __pa(startup_32_smp);
26860 + trampoline_header->start = __pa(ktla_ktva(startup_32_smp));
26861 +
26862 +#ifdef CONFIG_PAX_KERNEXEC
26863 + trampoline_header->start -= LOAD_PHYSICAL_ADDR;
26864 +#endif
26865 +
26866 + trampoline_header->boot_cs = __BOOT_CS;
26867 trampoline_header->gdt_limit = __BOOT_DS + 7;
26868 trampoline_header->gdt_base = __pa(boot_gdt);
26869 #else
26870 diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
26871 index 8869287..d577672 100644
26872 --- a/arch/x86/realmode/rm/Makefile
26873 +++ b/arch/x86/realmode/rm/Makefile
26874 @@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
26875 $(call cc-option, -fno-unit-at-a-time)) \
26876 $(call cc-option, -fno-stack-protector) \
26877 $(call cc-option, -mpreferred-stack-boundary=2)
26878 +ifdef CONSTIFY_PLUGIN
26879 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
26880 +endif
26881 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
26882 GCOV_PROFILE := n
26883 diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
26884 index a28221d..93c40f1 100644
26885 --- a/arch/x86/realmode/rm/header.S
26886 +++ b/arch/x86/realmode/rm/header.S
26887 @@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
26888 #endif
26889 /* APM/BIOS reboot */
26890 .long pa_machine_real_restart_asm
26891 -#ifdef CONFIG_X86_64
26892 +#ifdef CONFIG_X86_32
26893 + .long __KERNEL_CS
26894 +#else
26895 .long __KERNEL32_CS
26896 #endif
26897 END(real_mode_header)
26898 diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
26899 index c1b2791..f9e31c7 100644
26900 --- a/arch/x86/realmode/rm/trampoline_32.S
26901 +++ b/arch/x86/realmode/rm/trampoline_32.S
26902 @@ -25,6 +25,12 @@
26903 #include <asm/page_types.h>
26904 #include "realmode.h"
26905
26906 +#ifdef CONFIG_PAX_KERNEXEC
26907 +#define ta(X) (X)
26908 +#else
26909 +#define ta(X) (pa_ ## X)
26910 +#endif
26911 +
26912 .text
26913 .code16
26914
26915 @@ -39,8 +45,6 @@ ENTRY(trampoline_start)
26916
26917 cli # We should be safe anyway
26918
26919 - movl tr_start, %eax # where we need to go
26920 -
26921 movl $0xA5A5A5A5, trampoline_status
26922 # write marker for master knows we're running
26923
26924 @@ -56,7 +60,7 @@ ENTRY(trampoline_start)
26925 movw $1, %dx # protected mode (PE) bit
26926 lmsw %dx # into protected mode
26927
26928 - ljmpl $__BOOT_CS, $pa_startup_32
26929 + ljmpl *(trampoline_header)
26930
26931 .section ".text32","ax"
26932 .code32
26933 @@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
26934 .balign 8
26935 GLOBAL(trampoline_header)
26936 tr_start: .space 4
26937 - tr_gdt_pad: .space 2
26938 + tr_boot_cs: .space 2
26939 tr_gdt: .space 6
26940 END(trampoline_header)
26941
26942 diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
26943 index bb360dc..3e5945f 100644
26944 --- a/arch/x86/realmode/rm/trampoline_64.S
26945 +++ b/arch/x86/realmode/rm/trampoline_64.S
26946 @@ -107,7 +107,7 @@ ENTRY(startup_32)
26947 wrmsr
26948
26949 # Enable paging and in turn activate Long Mode
26950 - movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
26951 + movl $(X86_CR0_PG | X86_CR0_PE), %eax
26952 movl %eax, %cr0
26953
26954 /*
26955 diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
26956 index 5a1847d..deccb30 100644
26957 --- a/arch/x86/tools/relocs.c
26958 +++ b/arch/x86/tools/relocs.c
26959 @@ -12,10 +12,13 @@
26960 #include <regex.h>
26961 #include <tools/le_byteshift.h>
26962
26963 +#include "../../../include/generated/autoconf.h"
26964 +
26965 static void die(char *fmt, ...);
26966
26967 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
26968 static Elf32_Ehdr ehdr;
26969 +static Elf32_Phdr *phdr;
26970 static unsigned long reloc_count, reloc_idx;
26971 static unsigned long *relocs;
26972 static unsigned long reloc16_count, reloc16_idx;
26973 @@ -330,9 +333,39 @@ static void read_ehdr(FILE *fp)
26974 }
26975 }
26976
26977 +static void read_phdrs(FILE *fp)
26978 +{
26979 + unsigned int i;
26980 +
26981 + phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
26982 + if (!phdr) {
26983 + die("Unable to allocate %d program headers\n",
26984 + ehdr.e_phnum);
26985 + }
26986 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
26987 + die("Seek to %d failed: %s\n",
26988 + ehdr.e_phoff, strerror(errno));
26989 + }
26990 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
26991 + die("Cannot read ELF program headers: %s\n",
26992 + strerror(errno));
26993 + }
26994 + for(i = 0; i < ehdr.e_phnum; i++) {
26995 + phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
26996 + phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
26997 + phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
26998 + phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
26999 + phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
27000 + phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
27001 + phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
27002 + phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
27003 + }
27004 +
27005 +}
27006 +
27007 static void read_shdrs(FILE *fp)
27008 {
27009 - int i;
27010 + unsigned int i;
27011 Elf32_Shdr shdr;
27012
27013 secs = calloc(ehdr.e_shnum, sizeof(struct section));
27014 @@ -367,7 +400,7 @@ static void read_shdrs(FILE *fp)
27015
27016 static void read_strtabs(FILE *fp)
27017 {
27018 - int i;
27019 + unsigned int i;
27020 for (i = 0; i < ehdr.e_shnum; i++) {
27021 struct section *sec = &secs[i];
27022 if (sec->shdr.sh_type != SHT_STRTAB) {
27023 @@ -392,7 +425,7 @@ static void read_strtabs(FILE *fp)
27024
27025 static void read_symtabs(FILE *fp)
27026 {
27027 - int i,j;
27028 + unsigned int i,j;
27029 for (i = 0; i < ehdr.e_shnum; i++) {
27030 struct section *sec = &secs[i];
27031 if (sec->shdr.sh_type != SHT_SYMTAB) {
27032 @@ -423,9 +456,11 @@ static void read_symtabs(FILE *fp)
27033 }
27034
27035
27036 -static void read_relocs(FILE *fp)
27037 +static void read_relocs(FILE *fp, int use_real_mode)
27038 {
27039 - int i,j;
27040 + unsigned int i,j;
27041 + uint32_t base;
27042 +
27043 for (i = 0; i < ehdr.e_shnum; i++) {
27044 struct section *sec = &secs[i];
27045 if (sec->shdr.sh_type != SHT_REL) {
27046 @@ -445,9 +480,22 @@ static void read_relocs(FILE *fp)
27047 die("Cannot read symbol table: %s\n",
27048 strerror(errno));
27049 }
27050 + base = 0;
27051 +
27052 +#ifdef CONFIG_X86_32
27053 + for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
27054 + if (phdr[j].p_type != PT_LOAD )
27055 + continue;
27056 + 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)
27057 + continue;
27058 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
27059 + break;
27060 + }
27061 +#endif
27062 +
27063 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
27064 Elf32_Rel *rel = &sec->reltab[j];
27065 - rel->r_offset = elf32_to_cpu(rel->r_offset);
27066 + rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
27067 rel->r_info = elf32_to_cpu(rel->r_info);
27068 }
27069 }
27070 @@ -456,13 +504,13 @@ static void read_relocs(FILE *fp)
27071
27072 static void print_absolute_symbols(void)
27073 {
27074 - int i;
27075 + unsigned int i;
27076 printf("Absolute symbols\n");
27077 printf(" Num: Value Size Type Bind Visibility Name\n");
27078 for (i = 0; i < ehdr.e_shnum; i++) {
27079 struct section *sec = &secs[i];
27080 char *sym_strtab;
27081 - int j;
27082 + unsigned int j;
27083
27084 if (sec->shdr.sh_type != SHT_SYMTAB) {
27085 continue;
27086 @@ -489,14 +537,14 @@ static void print_absolute_symbols(void)
27087
27088 static void print_absolute_relocs(void)
27089 {
27090 - int i, printed = 0;
27091 + unsigned int i, printed = 0;
27092
27093 for (i = 0; i < ehdr.e_shnum; i++) {
27094 struct section *sec = &secs[i];
27095 struct section *sec_applies, *sec_symtab;
27096 char *sym_strtab;
27097 Elf32_Sym *sh_symtab;
27098 - int j;
27099 + unsigned int j;
27100 if (sec->shdr.sh_type != SHT_REL) {
27101 continue;
27102 }
27103 @@ -558,13 +606,13 @@ static void print_absolute_relocs(void)
27104 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
27105 int use_real_mode)
27106 {
27107 - int i;
27108 + unsigned int i;
27109 /* Walk through the relocations */
27110 for (i = 0; i < ehdr.e_shnum; i++) {
27111 char *sym_strtab;
27112 Elf32_Sym *sh_symtab;
27113 struct section *sec_applies, *sec_symtab;
27114 - int j;
27115 + unsigned int j;
27116 struct section *sec = &secs[i];
27117
27118 if (sec->shdr.sh_type != SHT_REL) {
27119 @@ -588,6 +636,24 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
27120 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
27121 r_type = ELF32_R_TYPE(rel->r_info);
27122
27123 + if (!use_real_mode) {
27124 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
27125 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
27126 + continue;
27127 +
27128 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
27129 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
27130 + if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
27131 + continue;
27132 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
27133 + continue;
27134 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
27135 + continue;
27136 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
27137 + continue;
27138 +#endif
27139 + }
27140 +
27141 shn_abs = sym->st_shndx == SHN_ABS;
27142
27143 switch (r_type) {
27144 @@ -681,7 +747,7 @@ static int write32(unsigned int v, FILE *f)
27145
27146 static void emit_relocs(int as_text, int use_real_mode)
27147 {
27148 - int i;
27149 + unsigned int i;
27150 /* Count how many relocations I have and allocate space for them. */
27151 reloc_count = 0;
27152 walk_relocs(count_reloc, use_real_mode);
27153 @@ -808,10 +874,11 @@ int main(int argc, char **argv)
27154 fname, strerror(errno));
27155 }
27156 read_ehdr(fp);
27157 + read_phdrs(fp);
27158 read_shdrs(fp);
27159 read_strtabs(fp);
27160 read_symtabs(fp);
27161 - read_relocs(fp);
27162 + read_relocs(fp, use_real_mode);
27163 if (show_absolute_syms) {
27164 print_absolute_symbols();
27165 return 0;
27166 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
27167 index fd14be1..e3c79c0 100644
27168 --- a/arch/x86/vdso/Makefile
27169 +++ b/arch/x86/vdso/Makefile
27170 @@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
27171 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
27172 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
27173
27174 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
27175 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
27176 GCOV_PROFILE := n
27177
27178 #
27179 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
27180 index 0faad64..39ef157 100644
27181 --- a/arch/x86/vdso/vdso32-setup.c
27182 +++ b/arch/x86/vdso/vdso32-setup.c
27183 @@ -25,6 +25,7 @@
27184 #include <asm/tlbflush.h>
27185 #include <asm/vdso.h>
27186 #include <asm/proto.h>
27187 +#include <asm/mman.h>
27188
27189 enum {
27190 VDSO_DISABLED = 0,
27191 @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
27192 void enable_sep_cpu(void)
27193 {
27194 int cpu = get_cpu();
27195 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
27196 + struct tss_struct *tss = init_tss + cpu;
27197
27198 if (!boot_cpu_has(X86_FEATURE_SEP)) {
27199 put_cpu();
27200 @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
27201 gate_vma.vm_start = FIXADDR_USER_START;
27202 gate_vma.vm_end = FIXADDR_USER_END;
27203 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
27204 - gate_vma.vm_page_prot = __P101;
27205 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
27206
27207 return 0;
27208 }
27209 @@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27210 if (compat)
27211 addr = VDSO_HIGH_BASE;
27212 else {
27213 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
27214 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
27215 if (IS_ERR_VALUE(addr)) {
27216 ret = addr;
27217 goto up_fail;
27218 }
27219 }
27220
27221 - current->mm->context.vdso = (void *)addr;
27222 + current->mm->context.vdso = addr;
27223
27224 if (compat_uses_vma || !compat) {
27225 /*
27226 @@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27227 }
27228
27229 current_thread_info()->sysenter_return =
27230 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
27231 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
27232
27233 up_fail:
27234 if (ret)
27235 - current->mm->context.vdso = NULL;
27236 + current->mm->context.vdso = 0;
27237
27238 up_write(&mm->mmap_sem);
27239
27240 @@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
27241
27242 const char *arch_vma_name(struct vm_area_struct *vma)
27243 {
27244 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
27245 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
27246 return "[vdso]";
27247 +
27248 +#ifdef CONFIG_PAX_SEGMEXEC
27249 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
27250 + return "[vdso]";
27251 +#endif
27252 +
27253 return NULL;
27254 }
27255
27256 @@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
27257 * Check to see if the corresponding task was created in compat vdso
27258 * mode.
27259 */
27260 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
27261 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
27262 return &gate_vma;
27263 return NULL;
27264 }
27265 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
27266 index 00aaf04..4a26505 100644
27267 --- a/arch/x86/vdso/vma.c
27268 +++ b/arch/x86/vdso/vma.c
27269 @@ -16,8 +16,6 @@
27270 #include <asm/vdso.h>
27271 #include <asm/page.h>
27272
27273 -unsigned int __read_mostly vdso_enabled = 1;
27274 -
27275 extern char vdso_start[], vdso_end[];
27276 extern unsigned short vdso_sync_cpuid;
27277
27278 @@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
27279 * unaligned here as a result of stack start randomization.
27280 */
27281 addr = PAGE_ALIGN(addr);
27282 - addr = align_addr(addr, NULL, ALIGN_VDSO);
27283
27284 return addr;
27285 }
27286 @@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
27287 unsigned size)
27288 {
27289 struct mm_struct *mm = current->mm;
27290 - unsigned long addr;
27291 + unsigned long addr = 0;
27292 int ret;
27293
27294 - if (!vdso_enabled)
27295 - return 0;
27296 -
27297 down_write(&mm->mmap_sem);
27298 +
27299 +#ifdef CONFIG_PAX_RANDMMAP
27300 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27301 +#endif
27302 +
27303 addr = vdso_addr(mm->start_stack, size);
27304 + addr = align_addr(addr, NULL, ALIGN_VDSO);
27305 addr = get_unmapped_area(NULL, addr, size, 0, 0);
27306 if (IS_ERR_VALUE(addr)) {
27307 ret = addr;
27308 goto up_fail;
27309 }
27310
27311 - current->mm->context.vdso = (void *)addr;
27312 + mm->context.vdso = addr;
27313
27314 ret = install_special_mapping(mm, addr, size,
27315 VM_READ|VM_EXEC|
27316 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
27317 pages);
27318 - if (ret) {
27319 - current->mm->context.vdso = NULL;
27320 - goto up_fail;
27321 - }
27322 + if (ret)
27323 + mm->context.vdso = 0;
27324
27325 up_fail:
27326 up_write(&mm->mmap_sem);
27327 @@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27328 vdsox32_size);
27329 }
27330 #endif
27331 -
27332 -static __init int vdso_setup(char *s)
27333 -{
27334 - vdso_enabled = simple_strtoul(s, NULL, 0);
27335 - return 0;
27336 -}
27337 -__setup("vdso=", vdso_setup);
27338 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
27339 index c1461de..355f120 100644
27340 --- a/arch/x86/xen/enlighten.c
27341 +++ b/arch/x86/xen/enlighten.c
27342 @@ -98,8 +98,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
27343
27344 struct shared_info xen_dummy_shared_info;
27345
27346 -void *xen_initial_gdt;
27347 -
27348 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
27349 __read_mostly int xen_have_vector_callback;
27350 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
27351 @@ -917,21 +915,21 @@ static u32 xen_safe_apic_wait_icr_idle(void)
27352
27353 static void set_xen_basic_apic_ops(void)
27354 {
27355 - apic->read = xen_apic_read;
27356 - apic->write = xen_apic_write;
27357 - apic->icr_read = xen_apic_icr_read;
27358 - apic->icr_write = xen_apic_icr_write;
27359 - apic->wait_icr_idle = xen_apic_wait_icr_idle;
27360 - apic->safe_wait_icr_idle = xen_safe_apic_wait_icr_idle;
27361 - apic->set_apic_id = xen_set_apic_id;
27362 - apic->get_apic_id = xen_get_apic_id;
27363 + *(void **)&apic->read = xen_apic_read;
27364 + *(void **)&apic->write = xen_apic_write;
27365 + *(void **)&apic->icr_read = xen_apic_icr_read;
27366 + *(void **)&apic->icr_write = xen_apic_icr_write;
27367 + *(void **)&apic->wait_icr_idle = xen_apic_wait_icr_idle;
27368 + *(void **)&apic->safe_wait_icr_idle = xen_safe_apic_wait_icr_idle;
27369 + *(void **)&apic->set_apic_id = xen_set_apic_id;
27370 + *(void **)&apic->get_apic_id = xen_get_apic_id;
27371
27372 #ifdef CONFIG_SMP
27373 - apic->send_IPI_allbutself = xen_send_IPI_allbutself;
27374 - apic->send_IPI_mask_allbutself = xen_send_IPI_mask_allbutself;
27375 - apic->send_IPI_mask = xen_send_IPI_mask;
27376 - apic->send_IPI_all = xen_send_IPI_all;
27377 - apic->send_IPI_self = xen_send_IPI_self;
27378 + *(void **)&apic->send_IPI_allbutself = xen_send_IPI_allbutself;
27379 + *(void **)&apic->send_IPI_mask_allbutself = xen_send_IPI_mask_allbutself;
27380 + *(void **)&apic->send_IPI_mask = xen_send_IPI_mask;
27381 + *(void **)&apic->send_IPI_all = xen_send_IPI_all;
27382 + *(void **)&apic->send_IPI_self = xen_send_IPI_self;
27383 #endif
27384 }
27385
27386 @@ -1221,30 +1219,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
27387 #endif
27388 };
27389
27390 -static void xen_reboot(int reason)
27391 +static __noreturn void xen_reboot(int reason)
27392 {
27393 struct sched_shutdown r = { .reason = reason };
27394
27395 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
27396 - BUG();
27397 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
27398 + BUG();
27399 }
27400
27401 -static void xen_restart(char *msg)
27402 +static __noreturn void xen_restart(char *msg)
27403 {
27404 xen_reboot(SHUTDOWN_reboot);
27405 }
27406
27407 -static void xen_emergency_restart(void)
27408 +static __noreturn void xen_emergency_restart(void)
27409 {
27410 xen_reboot(SHUTDOWN_reboot);
27411 }
27412
27413 -static void xen_machine_halt(void)
27414 +static __noreturn void xen_machine_halt(void)
27415 {
27416 xen_reboot(SHUTDOWN_poweroff);
27417 }
27418
27419 -static void xen_machine_power_off(void)
27420 +static __noreturn void xen_machine_power_off(void)
27421 {
27422 if (pm_power_off)
27423 pm_power_off();
27424 @@ -1347,7 +1345,17 @@ asmlinkage void __init xen_start_kernel(void)
27425 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
27426
27427 /* Work out if we support NX */
27428 - x86_configure_nx();
27429 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
27430 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
27431 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
27432 + unsigned l, h;
27433 +
27434 + __supported_pte_mask |= _PAGE_NX;
27435 + rdmsr(MSR_EFER, l, h);
27436 + l |= EFER_NX;
27437 + wrmsr(MSR_EFER, l, h);
27438 + }
27439 +#endif
27440
27441 xen_setup_features();
27442
27443 @@ -1378,13 +1386,6 @@ asmlinkage void __init xen_start_kernel(void)
27444
27445 machine_ops = xen_machine_ops;
27446
27447 - /*
27448 - * The only reliable way to retain the initial address of the
27449 - * percpu gdt_page is to remember it here, so we can go and
27450 - * mark it RW later, when the initial percpu area is freed.
27451 - */
27452 - xen_initial_gdt = &per_cpu(gdt_page, 0);
27453 -
27454 xen_smp_init();
27455
27456 #ifdef CONFIG_ACPI_NUMA
27457 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
27458 index dde1a3f..6b663e6 100644
27459 --- a/arch/x86/xen/mmu.c
27460 +++ b/arch/x86/xen/mmu.c
27461 @@ -1784,6 +1784,9 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27462 convert_pfn_mfn(init_level4_pgt);
27463 convert_pfn_mfn(level3_ident_pgt);
27464 convert_pfn_mfn(level3_kernel_pgt);
27465 + convert_pfn_mfn(level3_vmalloc_start_pgt);
27466 + convert_pfn_mfn(level3_vmalloc_end_pgt);
27467 + convert_pfn_mfn(level3_vmemmap_pgt);
27468
27469 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
27470 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
27471 @@ -1802,7 +1805,11 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27472 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
27473 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
27474 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
27475 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
27476 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
27477 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
27478 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
27479 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
27480 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
27481 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
27482
27483 @@ -1986,6 +1993,7 @@ static void __init xen_post_allocator_init(void)
27484 pv_mmu_ops.set_pud = xen_set_pud;
27485 #if PAGETABLE_LEVELS == 4
27486 pv_mmu_ops.set_pgd = xen_set_pgd;
27487 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
27488 #endif
27489
27490 /* This will work as long as patching hasn't happened yet
27491 @@ -2067,6 +2075,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
27492 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
27493 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
27494 .set_pgd = xen_set_pgd_hyper,
27495 + .set_pgd_batched = xen_set_pgd_hyper,
27496
27497 .alloc_pud = xen_alloc_pmd_init,
27498 .release_pud = xen_release_pmd_init,
27499 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
27500 index f58dca7..ad21f52 100644
27501 --- a/arch/x86/xen/smp.c
27502 +++ b/arch/x86/xen/smp.c
27503 @@ -229,11 +229,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
27504 {
27505 BUG_ON(smp_processor_id() != 0);
27506 native_smp_prepare_boot_cpu();
27507 -
27508 - /* We've switched to the "real" per-cpu gdt, so make sure the
27509 - old memory can be recycled */
27510 - make_lowmem_page_readwrite(xen_initial_gdt);
27511 -
27512 xen_filter_cpu_maps();
27513 xen_setup_vcpu_info_placement();
27514 }
27515 @@ -300,12 +295,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
27516 gdt = get_cpu_gdt_table(cpu);
27517
27518 ctxt->flags = VGCF_IN_KERNEL;
27519 - ctxt->user_regs.ds = __USER_DS;
27520 - ctxt->user_regs.es = __USER_DS;
27521 + ctxt->user_regs.ds = __KERNEL_DS;
27522 + ctxt->user_regs.es = __KERNEL_DS;
27523 ctxt->user_regs.ss = __KERNEL_DS;
27524 #ifdef CONFIG_X86_32
27525 ctxt->user_regs.fs = __KERNEL_PERCPU;
27526 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
27527 + savesegment(gs, ctxt->user_regs.gs);
27528 #else
27529 ctxt->gs_base_kernel = per_cpu_offset(cpu);
27530 #endif
27531 @@ -355,13 +350,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
27532 int rc;
27533
27534 per_cpu(current_task, cpu) = idle;
27535 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
27536 #ifdef CONFIG_X86_32
27537 irq_ctx_init(cpu);
27538 #else
27539 clear_tsk_thread_flag(idle, TIF_FORK);
27540 - per_cpu(kernel_stack, cpu) =
27541 - (unsigned long)task_stack_page(idle) -
27542 - KERNEL_STACK_OFFSET + THREAD_SIZE;
27543 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27544 #endif
27545 xen_setup_runstate_info(cpu);
27546 xen_setup_timer(cpu);
27547 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
27548 index f9643fc..602e8af 100644
27549 --- a/arch/x86/xen/xen-asm_32.S
27550 +++ b/arch/x86/xen/xen-asm_32.S
27551 @@ -84,14 +84,14 @@ ENTRY(xen_iret)
27552 ESP_OFFSET=4 # bytes pushed onto stack
27553
27554 /*
27555 - * Store vcpu_info pointer for easy access. Do it this way to
27556 - * avoid having to reload %fs
27557 + * Store vcpu_info pointer for easy access.
27558 */
27559 #ifdef CONFIG_SMP
27560 - GET_THREAD_INFO(%eax)
27561 - movl TI_cpu(%eax), %eax
27562 - movl __per_cpu_offset(,%eax,4), %eax
27563 - mov xen_vcpu(%eax), %eax
27564 + push %fs
27565 + mov $(__KERNEL_PERCPU), %eax
27566 + mov %eax, %fs
27567 + mov PER_CPU_VAR(xen_vcpu), %eax
27568 + pop %fs
27569 #else
27570 movl xen_vcpu, %eax
27571 #endif
27572 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
27573 index aaa7291..3f77960 100644
27574 --- a/arch/x86/xen/xen-head.S
27575 +++ b/arch/x86/xen/xen-head.S
27576 @@ -19,6 +19,17 @@ ENTRY(startup_xen)
27577 #ifdef CONFIG_X86_32
27578 mov %esi,xen_start_info
27579 mov $init_thread_union+THREAD_SIZE,%esp
27580 +#ifdef CONFIG_SMP
27581 + movl $cpu_gdt_table,%edi
27582 + movl $__per_cpu_load,%eax
27583 + movw %ax,__KERNEL_PERCPU + 2(%edi)
27584 + rorl $16,%eax
27585 + movb %al,__KERNEL_PERCPU + 4(%edi)
27586 + movb %ah,__KERNEL_PERCPU + 7(%edi)
27587 + movl $__per_cpu_end - 1,%eax
27588 + subl $__per_cpu_start,%eax
27589 + movw %ax,__KERNEL_PERCPU + 0(%edi)
27590 +#endif
27591 #else
27592 mov %rsi,xen_start_info
27593 mov $init_thread_union+THREAD_SIZE,%rsp
27594 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
27595 index 202d4c1..99b072a 100644
27596 --- a/arch/x86/xen/xen-ops.h
27597 +++ b/arch/x86/xen/xen-ops.h
27598 @@ -10,8 +10,6 @@
27599 extern const char xen_hypervisor_callback[];
27600 extern const char xen_failsafe_callback[];
27601
27602 -extern void *xen_initial_gdt;
27603 -
27604 struct trap_info;
27605 void xen_copy_trap_info(struct trap_info *traps);
27606
27607 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
27608 index 525bd3d..ef888b1 100644
27609 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
27610 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
27611 @@ -119,9 +119,9 @@
27612 ----------------------------------------------------------------------*/
27613
27614 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
27615 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
27616 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
27617 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
27618 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27619
27620 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
27621 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
27622 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
27623 index 2f33760..835e50a 100644
27624 --- a/arch/xtensa/variants/fsf/include/variant/core.h
27625 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
27626 @@ -11,6 +11,7 @@
27627 #ifndef _XTENSA_CORE_H
27628 #define _XTENSA_CORE_H
27629
27630 +#include <linux/const.h>
27631
27632 /****************************************************************************
27633 Parameters Useful for Any Code, USER or PRIVILEGED
27634 @@ -112,9 +113,9 @@
27635 ----------------------------------------------------------------------*/
27636
27637 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27638 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27639 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27640 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27641 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27642
27643 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
27644 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
27645 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
27646 index af00795..2bb8105 100644
27647 --- a/arch/xtensa/variants/s6000/include/variant/core.h
27648 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
27649 @@ -11,6 +11,7 @@
27650 #ifndef _XTENSA_CORE_CONFIGURATION_H
27651 #define _XTENSA_CORE_CONFIGURATION_H
27652
27653 +#include <linux/const.h>
27654
27655 /****************************************************************************
27656 Parameters Useful for Any Code, USER or PRIVILEGED
27657 @@ -118,9 +119,9 @@
27658 ----------------------------------------------------------------------*/
27659
27660 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27661 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27662 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27663 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27664 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27665
27666 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
27667 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
27668 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
27669 index 58916af..9cb880b 100644
27670 --- a/block/blk-iopoll.c
27671 +++ b/block/blk-iopoll.c
27672 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
27673 }
27674 EXPORT_SYMBOL(blk_iopoll_complete);
27675
27676 -static void blk_iopoll_softirq(struct softirq_action *h)
27677 +static void blk_iopoll_softirq(void)
27678 {
27679 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
27680 int rearm = 0, budget = blk_iopoll_budget;
27681 diff --git a/block/blk-map.c b/block/blk-map.c
27682 index 623e1cd..ca1e109 100644
27683 --- a/block/blk-map.c
27684 +++ b/block/blk-map.c
27685 @@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
27686 if (!len || !kbuf)
27687 return -EINVAL;
27688
27689 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
27690 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
27691 if (do_copy)
27692 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
27693 else
27694 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
27695 index 467c8de..4bddc6d 100644
27696 --- a/block/blk-softirq.c
27697 +++ b/block/blk-softirq.c
27698 @@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
27699 * Softirq action handler - move entries to local list and loop over them
27700 * while passing them to the queue registered handler.
27701 */
27702 -static void blk_done_softirq(struct softirq_action *h)
27703 +static void blk_done_softirq(void)
27704 {
27705 struct list_head *cpu_list, local_list;
27706
27707 diff --git a/block/bsg.c b/block/bsg.c
27708 index ff64ae3..593560c 100644
27709 --- a/block/bsg.c
27710 +++ b/block/bsg.c
27711 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
27712 struct sg_io_v4 *hdr, struct bsg_device *bd,
27713 fmode_t has_write_perm)
27714 {
27715 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27716 + unsigned char *cmdptr;
27717 +
27718 if (hdr->request_len > BLK_MAX_CDB) {
27719 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
27720 if (!rq->cmd)
27721 return -ENOMEM;
27722 - }
27723 + cmdptr = rq->cmd;
27724 + } else
27725 + cmdptr = tmpcmd;
27726
27727 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
27728 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
27729 hdr->request_len))
27730 return -EFAULT;
27731
27732 + if (cmdptr != rq->cmd)
27733 + memcpy(rq->cmd, cmdptr, hdr->request_len);
27734 +
27735 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
27736 if (blk_verify_command(rq->cmd, has_write_perm))
27737 return -EPERM;
27738 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
27739 index 7c668c8..db3521c 100644
27740 --- a/block/compat_ioctl.c
27741 +++ b/block/compat_ioctl.c
27742 @@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
27743 err |= __get_user(f->spec1, &uf->spec1);
27744 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
27745 err |= __get_user(name, &uf->name);
27746 - f->name = compat_ptr(name);
27747 + f->name = (void __force_kernel *)compat_ptr(name);
27748 if (err) {
27749 err = -EFAULT;
27750 goto out;
27751 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
27752 index 6296b40..417c00f 100644
27753 --- a/block/partitions/efi.c
27754 +++ b/block/partitions/efi.c
27755 @@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
27756 if (!gpt)
27757 return NULL;
27758
27759 + if (!le32_to_cpu(gpt->num_partition_entries))
27760 + return NULL;
27761 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
27762 + if (!pte)
27763 + return NULL;
27764 +
27765 count = le32_to_cpu(gpt->num_partition_entries) *
27766 le32_to_cpu(gpt->sizeof_partition_entry);
27767 - if (!count)
27768 - return NULL;
27769 - pte = kzalloc(count, GFP_KERNEL);
27770 - if (!pte)
27771 - return NULL;
27772 -
27773 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
27774 (u8 *) pte,
27775 count) < count) {
27776 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
27777 index 9a87daa..fb17486 100644
27778 --- a/block/scsi_ioctl.c
27779 +++ b/block/scsi_ioctl.c
27780 @@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
27781 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
27782 struct sg_io_hdr *hdr, fmode_t mode)
27783 {
27784 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
27785 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27786 + unsigned char *cmdptr;
27787 +
27788 + if (rq->cmd != rq->__cmd)
27789 + cmdptr = rq->cmd;
27790 + else
27791 + cmdptr = tmpcmd;
27792 +
27793 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
27794 return -EFAULT;
27795 +
27796 + if (cmdptr != rq->cmd)
27797 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
27798 +
27799 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
27800 return -EPERM;
27801
27802 @@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27803 int err;
27804 unsigned int in_len, out_len, bytes, opcode, cmdlen;
27805 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
27806 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27807 + unsigned char *cmdptr;
27808
27809 if (!sic)
27810 return -EINVAL;
27811 @@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27812 */
27813 err = -EFAULT;
27814 rq->cmd_len = cmdlen;
27815 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
27816 +
27817 + if (rq->cmd != rq->__cmd)
27818 + cmdptr = rq->cmd;
27819 + else
27820 + cmdptr = tmpcmd;
27821 +
27822 + if (copy_from_user(cmdptr, sic->data, cmdlen))
27823 goto error;
27824
27825 + if (rq->cmd != cmdptr)
27826 + memcpy(rq->cmd, cmdptr, cmdlen);
27827 +
27828 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
27829 goto error;
27830
27831 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
27832 index 671d4d6..afec999 100644
27833 --- a/crypto/cryptd.c
27834 +++ b/crypto/cryptd.c
27835 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
27836
27837 struct cryptd_blkcipher_request_ctx {
27838 crypto_completion_t complete;
27839 -};
27840 +} __no_const;
27841
27842 struct cryptd_hash_ctx {
27843 struct crypto_shash *child;
27844 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
27845
27846 struct cryptd_aead_request_ctx {
27847 crypto_completion_t complete;
27848 -};
27849 +} __no_const;
27850
27851 static void cryptd_queue_worker(struct work_struct *work);
27852
27853 @@ -137,13 +137,18 @@ static void cryptd_queue_worker(struct work_struct *work)
27854 struct crypto_async_request *req, *backlog;
27855
27856 cpu_queue = container_of(work, struct cryptd_cpu_queue, work);
27857 - /* Only handle one request at a time to avoid hogging crypto
27858 - * workqueue. preempt_disable/enable is used to prevent
27859 - * being preempted by cryptd_enqueue_request() */
27860 + /*
27861 + * Only handle one request at a time to avoid hogging crypto workqueue.
27862 + * preempt_disable/enable is used to prevent being preempted by
27863 + * cryptd_enqueue_request(). local_bh_disable/enable is used to prevent
27864 + * cryptd_enqueue_request() being accessed from software interrupts.
27865 + */
27866 + local_bh_disable();
27867 preempt_disable();
27868 backlog = crypto_get_backlog(&cpu_queue->queue);
27869 req = crypto_dequeue_request(&cpu_queue->queue);
27870 preempt_enable();
27871 + local_bh_enable();
27872
27873 if (!req)
27874 return;
27875 diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
27876 index e6defd8..c26a225 100644
27877 --- a/drivers/acpi/apei/cper.c
27878 +++ b/drivers/acpi/apei/cper.c
27879 @@ -38,12 +38,12 @@
27880 */
27881 u64 cper_next_record_id(void)
27882 {
27883 - static atomic64_t seq;
27884 + static atomic64_unchecked_t seq;
27885
27886 - if (!atomic64_read(&seq))
27887 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
27888 + if (!atomic64_read_unchecked(&seq))
27889 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
27890
27891 - return atomic64_inc_return(&seq);
27892 + return atomic64_inc_return_unchecked(&seq);
27893 }
27894 EXPORT_SYMBOL_GPL(cper_next_record_id);
27895
27896 diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
27897 index 7586544..636a2f0 100644
27898 --- a/drivers/acpi/ec_sys.c
27899 +++ b/drivers/acpi/ec_sys.c
27900 @@ -12,6 +12,7 @@
27901 #include <linux/acpi.h>
27902 #include <linux/debugfs.h>
27903 #include <linux/module.h>
27904 +#include <linux/uaccess.h>
27905 #include "internal.h"
27906
27907 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
27908 @@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27909 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
27910 */
27911 unsigned int size = EC_SPACE_SIZE;
27912 - u8 *data = (u8 *) buf;
27913 + u8 data;
27914 loff_t init_off = *off;
27915 int err = 0;
27916
27917 @@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27918 size = count;
27919
27920 while (size) {
27921 - err = ec_read(*off, &data[*off - init_off]);
27922 + err = ec_read(*off, &data);
27923 if (err)
27924 return err;
27925 + if (put_user(data, &buf[*off - init_off]))
27926 + return -EFAULT;
27927 *off += 1;
27928 size--;
27929 }
27930 @@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27931
27932 unsigned int size = count;
27933 loff_t init_off = *off;
27934 - u8 *data = (u8 *) buf;
27935 int err = 0;
27936
27937 if (*off >= EC_SPACE_SIZE)
27938 @@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27939 }
27940
27941 while (size) {
27942 - u8 byte_write = data[*off - init_off];
27943 + u8 byte_write;
27944 + if (get_user(byte_write, &buf[*off - init_off]))
27945 + return -EFAULT;
27946 err = ec_write(*off, byte_write);
27947 if (err)
27948 return err;
27949 diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
27950 index 251c7b62..000462d 100644
27951 --- a/drivers/acpi/proc.c
27952 +++ b/drivers/acpi/proc.c
27953 @@ -343,19 +343,13 @@ acpi_system_write_wakeup_device(struct file *file,
27954 size_t count, loff_t * ppos)
27955 {
27956 struct list_head *node, *next;
27957 - char strbuf[5];
27958 - char str[5] = "";
27959 - unsigned int len = count;
27960 + char strbuf[5] = {0};
27961
27962 - if (len > 4)
27963 - len = 4;
27964 - if (len < 0)
27965 + if (count > 4)
27966 + count = 4;
27967 + if (copy_from_user(strbuf, buffer, count))
27968 return -EFAULT;
27969 -
27970 - if (copy_from_user(strbuf, buffer, len))
27971 - return -EFAULT;
27972 - strbuf[len] = '\0';
27973 - sscanf(strbuf, "%s", str);
27974 + strbuf[count] = '\0';
27975
27976 mutex_lock(&acpi_device_lock);
27977 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
27978 @@ -364,7 +358,7 @@ acpi_system_write_wakeup_device(struct file *file,
27979 if (!dev->wakeup.flags.valid)
27980 continue;
27981
27982 - if (!strncmp(dev->pnp.bus_id, str, 4)) {
27983 + if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
27984 if (device_can_wakeup(&dev->dev)) {
27985 bool enable = !device_may_wakeup(&dev->dev);
27986 device_set_wakeup_enable(&dev->dev, enable);
27987 diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
27988 index bfc31cb..8213ce1 100644
27989 --- a/drivers/acpi/processor_driver.c
27990 +++ b/drivers/acpi/processor_driver.c
27991 @@ -551,7 +551,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
27992 return 0;
27993 #endif
27994
27995 - BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
27996 + BUG_ON(pr->id >= nr_cpu_ids);
27997
27998 /*
27999 * Buggy BIOS check
28000 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
28001 index 8e1039c..ea9cbd4 100644
28002 --- a/drivers/ata/libata-core.c
28003 +++ b/drivers/ata/libata-core.c
28004 @@ -4750,7 +4750,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
28005 struct ata_port *ap;
28006 unsigned int tag;
28007
28008 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
28009 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
28010 ap = qc->ap;
28011
28012 qc->flags = 0;
28013 @@ -4766,7 +4766,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
28014 struct ata_port *ap;
28015 struct ata_link *link;
28016
28017 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
28018 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
28019 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
28020 ap = qc->ap;
28021 link = qc->dev->link;
28022 @@ -5828,6 +5828,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
28023 return;
28024
28025 spin_lock(&lock);
28026 + pax_open_kernel();
28027
28028 for (cur = ops->inherits; cur; cur = cur->inherits) {
28029 void **inherit = (void **)cur;
28030 @@ -5841,8 +5842,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
28031 if (IS_ERR(*pp))
28032 *pp = NULL;
28033
28034 - ops->inherits = NULL;
28035 + *(struct ata_port_operations **)&ops->inherits = NULL;
28036
28037 + pax_close_kernel();
28038 spin_unlock(&lock);
28039 }
28040
28041 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
28042 index bfaa5cb..3ba1cc3 100644
28043 --- a/drivers/ata/pata_arasan_cf.c
28044 +++ b/drivers/ata/pata_arasan_cf.c
28045 @@ -854,7 +854,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
28046 /* Handle platform specific quirks */
28047 if (pdata->quirk) {
28048 if (pdata->quirk & CF_BROKEN_PIO) {
28049 - ap->ops->set_piomode = NULL;
28050 + pax_open_kernel();
28051 + *(void **)&ap->ops->set_piomode = NULL;
28052 + pax_close_kernel();
28053 ap->pio_mask = 0;
28054 }
28055 if (pdata->quirk & CF_BROKEN_MWDMA)
28056 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
28057 index f9b983a..887b9d8 100644
28058 --- a/drivers/atm/adummy.c
28059 +++ b/drivers/atm/adummy.c
28060 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
28061 vcc->pop(vcc, skb);
28062 else
28063 dev_kfree_skb_any(skb);
28064 - atomic_inc(&vcc->stats->tx);
28065 + atomic_inc_unchecked(&vcc->stats->tx);
28066
28067 return 0;
28068 }
28069 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
28070 index 89b30f3..7964211 100644
28071 --- a/drivers/atm/ambassador.c
28072 +++ b/drivers/atm/ambassador.c
28073 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
28074 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
28075
28076 // VC layer stats
28077 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28078 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28079
28080 // free the descriptor
28081 kfree (tx_descr);
28082 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
28083 dump_skb ("<<<", vc, skb);
28084
28085 // VC layer stats
28086 - atomic_inc(&atm_vcc->stats->rx);
28087 + atomic_inc_unchecked(&atm_vcc->stats->rx);
28088 __net_timestamp(skb);
28089 // end of our responsibility
28090 atm_vcc->push (atm_vcc, skb);
28091 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
28092 } else {
28093 PRINTK (KERN_INFO, "dropped over-size frame");
28094 // should we count this?
28095 - atomic_inc(&atm_vcc->stats->rx_drop);
28096 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
28097 }
28098
28099 } else {
28100 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
28101 }
28102
28103 if (check_area (skb->data, skb->len)) {
28104 - atomic_inc(&atm_vcc->stats->tx_err);
28105 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
28106 return -ENOMEM; // ?
28107 }
28108
28109 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
28110 index b22d71c..d6e1049 100644
28111 --- a/drivers/atm/atmtcp.c
28112 +++ b/drivers/atm/atmtcp.c
28113 @@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
28114 if (vcc->pop) vcc->pop(vcc,skb);
28115 else dev_kfree_skb(skb);
28116 if (dev_data) return 0;
28117 - atomic_inc(&vcc->stats->tx_err);
28118 + atomic_inc_unchecked(&vcc->stats->tx_err);
28119 return -ENOLINK;
28120 }
28121 size = skb->len+sizeof(struct atmtcp_hdr);
28122 @@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
28123 if (!new_skb) {
28124 if (vcc->pop) vcc->pop(vcc,skb);
28125 else dev_kfree_skb(skb);
28126 - atomic_inc(&vcc->stats->tx_err);
28127 + atomic_inc_unchecked(&vcc->stats->tx_err);
28128 return -ENOBUFS;
28129 }
28130 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
28131 @@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
28132 if (vcc->pop) vcc->pop(vcc,skb);
28133 else dev_kfree_skb(skb);
28134 out_vcc->push(out_vcc,new_skb);
28135 - atomic_inc(&vcc->stats->tx);
28136 - atomic_inc(&out_vcc->stats->rx);
28137 + atomic_inc_unchecked(&vcc->stats->tx);
28138 + atomic_inc_unchecked(&out_vcc->stats->rx);
28139 return 0;
28140 }
28141
28142 @@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
28143 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
28144 read_unlock(&vcc_sklist_lock);
28145 if (!out_vcc) {
28146 - atomic_inc(&vcc->stats->tx_err);
28147 + atomic_inc_unchecked(&vcc->stats->tx_err);
28148 goto done;
28149 }
28150 skb_pull(skb,sizeof(struct atmtcp_hdr));
28151 @@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
28152 __net_timestamp(new_skb);
28153 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
28154 out_vcc->push(out_vcc,new_skb);
28155 - atomic_inc(&vcc->stats->tx);
28156 - atomic_inc(&out_vcc->stats->rx);
28157 + atomic_inc_unchecked(&vcc->stats->tx);
28158 + atomic_inc_unchecked(&out_vcc->stats->rx);
28159 done:
28160 if (vcc->pop) vcc->pop(vcc,skb);
28161 else dev_kfree_skb(skb);
28162 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
28163 index 2059ee4..faf51c7 100644
28164 --- a/drivers/atm/eni.c
28165 +++ b/drivers/atm/eni.c
28166 @@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
28167 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
28168 vcc->dev->number);
28169 length = 0;
28170 - atomic_inc(&vcc->stats->rx_err);
28171 + atomic_inc_unchecked(&vcc->stats->rx_err);
28172 }
28173 else {
28174 length = ATM_CELL_SIZE-1; /* no HEC */
28175 @@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
28176 size);
28177 }
28178 eff = length = 0;
28179 - atomic_inc(&vcc->stats->rx_err);
28180 + atomic_inc_unchecked(&vcc->stats->rx_err);
28181 }
28182 else {
28183 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
28184 @@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
28185 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
28186 vcc->dev->number,vcc->vci,length,size << 2,descr);
28187 length = eff = 0;
28188 - atomic_inc(&vcc->stats->rx_err);
28189 + atomic_inc_unchecked(&vcc->stats->rx_err);
28190 }
28191 }
28192 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
28193 @@ -767,7 +767,7 @@ rx_dequeued++;
28194 vcc->push(vcc,skb);
28195 pushed++;
28196 }
28197 - atomic_inc(&vcc->stats->rx);
28198 + atomic_inc_unchecked(&vcc->stats->rx);
28199 }
28200 wake_up(&eni_dev->rx_wait);
28201 }
28202 @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
28203 PCI_DMA_TODEVICE);
28204 if (vcc->pop) vcc->pop(vcc,skb);
28205 else dev_kfree_skb_irq(skb);
28206 - atomic_inc(&vcc->stats->tx);
28207 + atomic_inc_unchecked(&vcc->stats->tx);
28208 wake_up(&eni_dev->tx_wait);
28209 dma_complete++;
28210 }
28211 @@ -1567,7 +1567,7 @@ tx_complete++;
28212 /*--------------------------------- entries ---------------------------------*/
28213
28214
28215 -static const char *media_name[] __devinitdata = {
28216 +static const char *media_name[] __devinitconst = {
28217 "MMF", "SMF", "MMF", "03?", /* 0- 3 */
28218 "UTP", "05?", "06?", "07?", /* 4- 7 */
28219 "TAXI","09?", "10?", "11?", /* 8-11 */
28220 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
28221 index 86fed1b..6dc4721 100644
28222 --- a/drivers/atm/firestream.c
28223 +++ b/drivers/atm/firestream.c
28224 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
28225 }
28226 }
28227
28228 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28229 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28230
28231 fs_dprintk (FS_DEBUG_TXMEM, "i");
28232 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
28233 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
28234 #endif
28235 skb_put (skb, qe->p1 & 0xffff);
28236 ATM_SKB(skb)->vcc = atm_vcc;
28237 - atomic_inc(&atm_vcc->stats->rx);
28238 + atomic_inc_unchecked(&atm_vcc->stats->rx);
28239 __net_timestamp(skb);
28240 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
28241 atm_vcc->push (atm_vcc, skb);
28242 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
28243 kfree (pe);
28244 }
28245 if (atm_vcc)
28246 - atomic_inc(&atm_vcc->stats->rx_drop);
28247 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
28248 break;
28249 case 0x1f: /* Reassembly abort: no buffers. */
28250 /* Silently increment error counter. */
28251 if (atm_vcc)
28252 - atomic_inc(&atm_vcc->stats->rx_drop);
28253 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
28254 break;
28255 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
28256 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
28257 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
28258 index 361f5ae..7fc552d 100644
28259 --- a/drivers/atm/fore200e.c
28260 +++ b/drivers/atm/fore200e.c
28261 @@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
28262 #endif
28263 /* check error condition */
28264 if (*entry->status & STATUS_ERROR)
28265 - atomic_inc(&vcc->stats->tx_err);
28266 + atomic_inc_unchecked(&vcc->stats->tx_err);
28267 else
28268 - atomic_inc(&vcc->stats->tx);
28269 + atomic_inc_unchecked(&vcc->stats->tx);
28270 }
28271 }
28272
28273 @@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
28274 if (skb == NULL) {
28275 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
28276
28277 - atomic_inc(&vcc->stats->rx_drop);
28278 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28279 return -ENOMEM;
28280 }
28281
28282 @@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
28283
28284 dev_kfree_skb_any(skb);
28285
28286 - atomic_inc(&vcc->stats->rx_drop);
28287 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28288 return -ENOMEM;
28289 }
28290
28291 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
28292
28293 vcc->push(vcc, skb);
28294 - atomic_inc(&vcc->stats->rx);
28295 + atomic_inc_unchecked(&vcc->stats->rx);
28296
28297 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
28298
28299 @@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
28300 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
28301 fore200e->atm_dev->number,
28302 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
28303 - atomic_inc(&vcc->stats->rx_err);
28304 + atomic_inc_unchecked(&vcc->stats->rx_err);
28305 }
28306 }
28307
28308 @@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
28309 goto retry_here;
28310 }
28311
28312 - atomic_inc(&vcc->stats->tx_err);
28313 + atomic_inc_unchecked(&vcc->stats->tx_err);
28314
28315 fore200e->tx_sat++;
28316 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
28317 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
28318 index b182c2f..1c6fa8a 100644
28319 --- a/drivers/atm/he.c
28320 +++ b/drivers/atm/he.c
28321 @@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28322
28323 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
28324 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
28325 - atomic_inc(&vcc->stats->rx_drop);
28326 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28327 goto return_host_buffers;
28328 }
28329
28330 @@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28331 RBRQ_LEN_ERR(he_dev->rbrq_head)
28332 ? "LEN_ERR" : "",
28333 vcc->vpi, vcc->vci);
28334 - atomic_inc(&vcc->stats->rx_err);
28335 + atomic_inc_unchecked(&vcc->stats->rx_err);
28336 goto return_host_buffers;
28337 }
28338
28339 @@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28340 vcc->push(vcc, skb);
28341 spin_lock(&he_dev->global_lock);
28342
28343 - atomic_inc(&vcc->stats->rx);
28344 + atomic_inc_unchecked(&vcc->stats->rx);
28345
28346 return_host_buffers:
28347 ++pdus_assembled;
28348 @@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
28349 tpd->vcc->pop(tpd->vcc, tpd->skb);
28350 else
28351 dev_kfree_skb_any(tpd->skb);
28352 - atomic_inc(&tpd->vcc->stats->tx_err);
28353 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
28354 }
28355 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
28356 return;
28357 @@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28358 vcc->pop(vcc, skb);
28359 else
28360 dev_kfree_skb_any(skb);
28361 - atomic_inc(&vcc->stats->tx_err);
28362 + atomic_inc_unchecked(&vcc->stats->tx_err);
28363 return -EINVAL;
28364 }
28365
28366 @@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28367 vcc->pop(vcc, skb);
28368 else
28369 dev_kfree_skb_any(skb);
28370 - atomic_inc(&vcc->stats->tx_err);
28371 + atomic_inc_unchecked(&vcc->stats->tx_err);
28372 return -EINVAL;
28373 }
28374 #endif
28375 @@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28376 vcc->pop(vcc, skb);
28377 else
28378 dev_kfree_skb_any(skb);
28379 - atomic_inc(&vcc->stats->tx_err);
28380 + atomic_inc_unchecked(&vcc->stats->tx_err);
28381 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28382 return -ENOMEM;
28383 }
28384 @@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28385 vcc->pop(vcc, skb);
28386 else
28387 dev_kfree_skb_any(skb);
28388 - atomic_inc(&vcc->stats->tx_err);
28389 + atomic_inc_unchecked(&vcc->stats->tx_err);
28390 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28391 return -ENOMEM;
28392 }
28393 @@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28394 __enqueue_tpd(he_dev, tpd, cid);
28395 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28396
28397 - atomic_inc(&vcc->stats->tx);
28398 + atomic_inc_unchecked(&vcc->stats->tx);
28399
28400 return 0;
28401 }
28402 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
28403 index 7d01c2a..4e3ac01 100644
28404 --- a/drivers/atm/horizon.c
28405 +++ b/drivers/atm/horizon.c
28406 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
28407 {
28408 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
28409 // VC layer stats
28410 - atomic_inc(&vcc->stats->rx);
28411 + atomic_inc_unchecked(&vcc->stats->rx);
28412 __net_timestamp(skb);
28413 // end of our responsibility
28414 vcc->push (vcc, skb);
28415 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
28416 dev->tx_iovec = NULL;
28417
28418 // VC layer stats
28419 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28420 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28421
28422 // free the skb
28423 hrz_kfree_skb (skb);
28424 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
28425 index 8974bd2..b856f85 100644
28426 --- a/drivers/atm/idt77252.c
28427 +++ b/drivers/atm/idt77252.c
28428 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
28429 else
28430 dev_kfree_skb(skb);
28431
28432 - atomic_inc(&vcc->stats->tx);
28433 + atomic_inc_unchecked(&vcc->stats->tx);
28434 }
28435
28436 atomic_dec(&scq->used);
28437 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28438 if ((sb = dev_alloc_skb(64)) == NULL) {
28439 printk("%s: Can't allocate buffers for aal0.\n",
28440 card->name);
28441 - atomic_add(i, &vcc->stats->rx_drop);
28442 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
28443 break;
28444 }
28445 if (!atm_charge(vcc, sb->truesize)) {
28446 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
28447 card->name);
28448 - atomic_add(i - 1, &vcc->stats->rx_drop);
28449 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
28450 dev_kfree_skb(sb);
28451 break;
28452 }
28453 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28454 ATM_SKB(sb)->vcc = vcc;
28455 __net_timestamp(sb);
28456 vcc->push(vcc, sb);
28457 - atomic_inc(&vcc->stats->rx);
28458 + atomic_inc_unchecked(&vcc->stats->rx);
28459
28460 cell += ATM_CELL_PAYLOAD;
28461 }
28462 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28463 "(CDC: %08x)\n",
28464 card->name, len, rpp->len, readl(SAR_REG_CDC));
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 (stat & SAR_RSQE_CRC) {
28471 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
28472 recycle_rx_pool_skb(card, rpp);
28473 - atomic_inc(&vcc->stats->rx_err);
28474 + atomic_inc_unchecked(&vcc->stats->rx_err);
28475 return;
28476 }
28477 if (skb_queue_len(&rpp->queue) > 1) {
28478 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28479 RXPRINTK("%s: Can't alloc RX skb.\n",
28480 card->name);
28481 recycle_rx_pool_skb(card, rpp);
28482 - atomic_inc(&vcc->stats->rx_err);
28483 + atomic_inc_unchecked(&vcc->stats->rx_err);
28484 return;
28485 }
28486 if (!atm_charge(vcc, skb->truesize)) {
28487 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28488 __net_timestamp(skb);
28489
28490 vcc->push(vcc, skb);
28491 - atomic_inc(&vcc->stats->rx);
28492 + atomic_inc_unchecked(&vcc->stats->rx);
28493
28494 return;
28495 }
28496 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28497 __net_timestamp(skb);
28498
28499 vcc->push(vcc, skb);
28500 - atomic_inc(&vcc->stats->rx);
28501 + atomic_inc_unchecked(&vcc->stats->rx);
28502
28503 if (skb->truesize > SAR_FB_SIZE_3)
28504 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
28505 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
28506 if (vcc->qos.aal != ATM_AAL0) {
28507 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
28508 card->name, vpi, vci);
28509 - atomic_inc(&vcc->stats->rx_drop);
28510 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28511 goto drop;
28512 }
28513
28514 if ((sb = dev_alloc_skb(64)) == NULL) {
28515 printk("%s: Can't allocate buffers for AAL0.\n",
28516 card->name);
28517 - atomic_inc(&vcc->stats->rx_err);
28518 + atomic_inc_unchecked(&vcc->stats->rx_err);
28519 goto drop;
28520 }
28521
28522 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
28523 ATM_SKB(sb)->vcc = vcc;
28524 __net_timestamp(sb);
28525 vcc->push(vcc, sb);
28526 - atomic_inc(&vcc->stats->rx);
28527 + atomic_inc_unchecked(&vcc->stats->rx);
28528
28529 drop:
28530 skb_pull(queue, 64);
28531 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28532
28533 if (vc == NULL) {
28534 printk("%s: NULL connection in send().\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 if (!test_bit(VCF_TX, &vc->flags)) {
28541 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
28542 - atomic_inc(&vcc->stats->tx_err);
28543 + atomic_inc_unchecked(&vcc->stats->tx_err);
28544 dev_kfree_skb(skb);
28545 return -EINVAL;
28546 }
28547 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28548 break;
28549 default:
28550 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
28551 - atomic_inc(&vcc->stats->tx_err);
28552 + atomic_inc_unchecked(&vcc->stats->tx_err);
28553 dev_kfree_skb(skb);
28554 return -EINVAL;
28555 }
28556
28557 if (skb_shinfo(skb)->nr_frags != 0) {
28558 printk("%s: No scatter-gather yet.\n", card->name);
28559 - atomic_inc(&vcc->stats->tx_err);
28560 + atomic_inc_unchecked(&vcc->stats->tx_err);
28561 dev_kfree_skb(skb);
28562 return -EINVAL;
28563 }
28564 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28565
28566 err = queue_skb(card, vc, skb, oam);
28567 if (err) {
28568 - atomic_inc(&vcc->stats->tx_err);
28569 + atomic_inc_unchecked(&vcc->stats->tx_err);
28570 dev_kfree_skb(skb);
28571 return err;
28572 }
28573 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
28574 skb = dev_alloc_skb(64);
28575 if (!skb) {
28576 printk("%s: Out of memory in send_oam().\n", card->name);
28577 - atomic_inc(&vcc->stats->tx_err);
28578 + atomic_inc_unchecked(&vcc->stats->tx_err);
28579 return -ENOMEM;
28580 }
28581 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
28582 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
28583 index 96cce6d..62c3ec5 100644
28584 --- a/drivers/atm/iphase.c
28585 +++ b/drivers/atm/iphase.c
28586 @@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
28587 status = (u_short) (buf_desc_ptr->desc_mode);
28588 if (status & (RX_CER | RX_PTE | RX_OFL))
28589 {
28590 - atomic_inc(&vcc->stats->rx_err);
28591 + atomic_inc_unchecked(&vcc->stats->rx_err);
28592 IF_ERR(printk("IA: bad packet, dropping it");)
28593 if (status & RX_CER) {
28594 IF_ERR(printk(" cause: packet CRC error\n");)
28595 @@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
28596 len = dma_addr - buf_addr;
28597 if (len > iadev->rx_buf_sz) {
28598 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
28599 - atomic_inc(&vcc->stats->rx_err);
28600 + atomic_inc_unchecked(&vcc->stats->rx_err);
28601 goto out_free_desc;
28602 }
28603
28604 @@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28605 ia_vcc = INPH_IA_VCC(vcc);
28606 if (ia_vcc == NULL)
28607 {
28608 - atomic_inc(&vcc->stats->rx_err);
28609 + atomic_inc_unchecked(&vcc->stats->rx_err);
28610 atm_return(vcc, skb->truesize);
28611 dev_kfree_skb_any(skb);
28612 goto INCR_DLE;
28613 @@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28614 if ((length > iadev->rx_buf_sz) || (length >
28615 (skb->len - sizeof(struct cpcs_trailer))))
28616 {
28617 - atomic_inc(&vcc->stats->rx_err);
28618 + atomic_inc_unchecked(&vcc->stats->rx_err);
28619 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
28620 length, skb->len);)
28621 atm_return(vcc, skb->truesize);
28622 @@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28623
28624 IF_RX(printk("rx_dle_intr: skb push");)
28625 vcc->push(vcc,skb);
28626 - atomic_inc(&vcc->stats->rx);
28627 + atomic_inc_unchecked(&vcc->stats->rx);
28628 iadev->rx_pkt_cnt++;
28629 }
28630 INCR_DLE:
28631 @@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
28632 {
28633 struct k_sonet_stats *stats;
28634 stats = &PRIV(_ia_dev[board])->sonet_stats;
28635 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
28636 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
28637 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
28638 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
28639 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
28640 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
28641 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
28642 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
28643 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
28644 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
28645 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
28646 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
28647 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
28648 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
28649 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
28650 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
28651 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
28652 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
28653 }
28654 ia_cmds.status = 0;
28655 break;
28656 @@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28657 if ((desc == 0) || (desc > iadev->num_tx_desc))
28658 {
28659 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
28660 - atomic_inc(&vcc->stats->tx);
28661 + atomic_inc_unchecked(&vcc->stats->tx);
28662 if (vcc->pop)
28663 vcc->pop(vcc, skb);
28664 else
28665 @@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28666 ATM_DESC(skb) = vcc->vci;
28667 skb_queue_tail(&iadev->tx_dma_q, skb);
28668
28669 - atomic_inc(&vcc->stats->tx);
28670 + atomic_inc_unchecked(&vcc->stats->tx);
28671 iadev->tx_pkt_cnt++;
28672 /* Increment transaction counter */
28673 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
28674
28675 #if 0
28676 /* add flow control logic */
28677 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
28678 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
28679 if (iavcc->vc_desc_cnt > 10) {
28680 vcc->tx_quota = vcc->tx_quota * 3 / 4;
28681 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
28682 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
28683 index 68c7588..7036683 100644
28684 --- a/drivers/atm/lanai.c
28685 +++ b/drivers/atm/lanai.c
28686 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
28687 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
28688 lanai_endtx(lanai, lvcc);
28689 lanai_free_skb(lvcc->tx.atmvcc, skb);
28690 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
28691 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
28692 }
28693
28694 /* Try to fill the buffer - don't call unless there is backlog */
28695 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
28696 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
28697 __net_timestamp(skb);
28698 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
28699 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
28700 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
28701 out:
28702 lvcc->rx.buf.ptr = end;
28703 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
28704 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28705 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
28706 "vcc %d\n", lanai->number, (unsigned int) s, vci);
28707 lanai->stats.service_rxnotaal5++;
28708 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28709 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28710 return 0;
28711 }
28712 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
28713 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28714 int bytes;
28715 read_unlock(&vcc_sklist_lock);
28716 DPRINTK("got trashed rx pdu on vci %d\n", vci);
28717 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28718 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28719 lvcc->stats.x.aal5.service_trash++;
28720 bytes = (SERVICE_GET_END(s) * 16) -
28721 (((unsigned long) lvcc->rx.buf.ptr) -
28722 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28723 }
28724 if (s & SERVICE_STREAM) {
28725 read_unlock(&vcc_sklist_lock);
28726 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28727 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28728 lvcc->stats.x.aal5.service_stream++;
28729 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
28730 "PDU on VCI %d!\n", lanai->number, vci);
28731 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28732 return 0;
28733 }
28734 DPRINTK("got rx crc error on vci %d\n", vci);
28735 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28736 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28737 lvcc->stats.x.aal5.service_rxcrc++;
28738 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
28739 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
28740 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
28741 index 1c70c45..300718d 100644
28742 --- a/drivers/atm/nicstar.c
28743 +++ b/drivers/atm/nicstar.c
28744 @@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28745 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
28746 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
28747 card->index);
28748 - atomic_inc(&vcc->stats->tx_err);
28749 + atomic_inc_unchecked(&vcc->stats->tx_err);
28750 dev_kfree_skb_any(skb);
28751 return -EINVAL;
28752 }
28753 @@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28754 if (!vc->tx) {
28755 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
28756 card->index);
28757 - atomic_inc(&vcc->stats->tx_err);
28758 + atomic_inc_unchecked(&vcc->stats->tx_err);
28759 dev_kfree_skb_any(skb);
28760 return -EINVAL;
28761 }
28762 @@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28763 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
28764 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
28765 card->index);
28766 - atomic_inc(&vcc->stats->tx_err);
28767 + atomic_inc_unchecked(&vcc->stats->tx_err);
28768 dev_kfree_skb_any(skb);
28769 return -EINVAL;
28770 }
28771
28772 if (skb_shinfo(skb)->nr_frags != 0) {
28773 printk("nicstar%d: No scatter-gather yet.\n", card->index);
28774 - atomic_inc(&vcc->stats->tx_err);
28775 + atomic_inc_unchecked(&vcc->stats->tx_err);
28776 dev_kfree_skb_any(skb);
28777 return -EINVAL;
28778 }
28779 @@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28780 }
28781
28782 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
28783 - atomic_inc(&vcc->stats->tx_err);
28784 + atomic_inc_unchecked(&vcc->stats->tx_err);
28785 dev_kfree_skb_any(skb);
28786 return -EIO;
28787 }
28788 - atomic_inc(&vcc->stats->tx);
28789 + atomic_inc_unchecked(&vcc->stats->tx);
28790
28791 return 0;
28792 }
28793 @@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28794 printk
28795 ("nicstar%d: Can't allocate buffers for aal0.\n",
28796 card->index);
28797 - atomic_add(i, &vcc->stats->rx_drop);
28798 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
28799 break;
28800 }
28801 if (!atm_charge(vcc, sb->truesize)) {
28802 RXPRINTK
28803 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
28804 card->index);
28805 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28806 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28807 dev_kfree_skb_any(sb);
28808 break;
28809 }
28810 @@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28811 ATM_SKB(sb)->vcc = vcc;
28812 __net_timestamp(sb);
28813 vcc->push(vcc, sb);
28814 - atomic_inc(&vcc->stats->rx);
28815 + atomic_inc_unchecked(&vcc->stats->rx);
28816 cell += ATM_CELL_PAYLOAD;
28817 }
28818
28819 @@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28820 if (iovb == NULL) {
28821 printk("nicstar%d: Out of iovec buffers.\n",
28822 card->index);
28823 - atomic_inc(&vcc->stats->rx_drop);
28824 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28825 recycle_rx_buf(card, skb);
28826 return;
28827 }
28828 @@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28829 small or large buffer itself. */
28830 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
28831 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
28832 - atomic_inc(&vcc->stats->rx_err);
28833 + atomic_inc_unchecked(&vcc->stats->rx_err);
28834 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28835 NS_MAX_IOVECS);
28836 NS_PRV_IOVCNT(iovb) = 0;
28837 @@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28838 ("nicstar%d: Expected a small buffer, and this is not one.\n",
28839 card->index);
28840 which_list(card, skb);
28841 - atomic_inc(&vcc->stats->rx_err);
28842 + atomic_inc_unchecked(&vcc->stats->rx_err);
28843 recycle_rx_buf(card, skb);
28844 vc->rx_iov = NULL;
28845 recycle_iov_buf(card, iovb);
28846 @@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28847 ("nicstar%d: Expected a large buffer, and this is not one.\n",
28848 card->index);
28849 which_list(card, skb);
28850 - atomic_inc(&vcc->stats->rx_err);
28851 + atomic_inc_unchecked(&vcc->stats->rx_err);
28852 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28853 NS_PRV_IOVCNT(iovb));
28854 vc->rx_iov = NULL;
28855 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28856 printk(" - PDU size mismatch.\n");
28857 else
28858 printk(".\n");
28859 - atomic_inc(&vcc->stats->rx_err);
28860 + atomic_inc_unchecked(&vcc->stats->rx_err);
28861 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28862 NS_PRV_IOVCNT(iovb));
28863 vc->rx_iov = NULL;
28864 @@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28865 /* skb points to a small buffer */
28866 if (!atm_charge(vcc, skb->truesize)) {
28867 push_rxbufs(card, skb);
28868 - atomic_inc(&vcc->stats->rx_drop);
28869 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28870 } else {
28871 skb_put(skb, len);
28872 dequeue_sm_buf(card, skb);
28873 @@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28874 ATM_SKB(skb)->vcc = vcc;
28875 __net_timestamp(skb);
28876 vcc->push(vcc, skb);
28877 - atomic_inc(&vcc->stats->rx);
28878 + atomic_inc_unchecked(&vcc->stats->rx);
28879 }
28880 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
28881 struct sk_buff *sb;
28882 @@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28883 if (len <= NS_SMBUFSIZE) {
28884 if (!atm_charge(vcc, sb->truesize)) {
28885 push_rxbufs(card, sb);
28886 - atomic_inc(&vcc->stats->rx_drop);
28887 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28888 } else {
28889 skb_put(sb, len);
28890 dequeue_sm_buf(card, sb);
28891 @@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28892 ATM_SKB(sb)->vcc = vcc;
28893 __net_timestamp(sb);
28894 vcc->push(vcc, sb);
28895 - atomic_inc(&vcc->stats->rx);
28896 + atomic_inc_unchecked(&vcc->stats->rx);
28897 }
28898
28899 push_rxbufs(card, skb);
28900 @@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28901
28902 if (!atm_charge(vcc, skb->truesize)) {
28903 push_rxbufs(card, skb);
28904 - atomic_inc(&vcc->stats->rx_drop);
28905 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28906 } else {
28907 dequeue_lg_buf(card, skb);
28908 #ifdef NS_USE_DESTRUCTORS
28909 @@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28910 ATM_SKB(skb)->vcc = vcc;
28911 __net_timestamp(skb);
28912 vcc->push(vcc, skb);
28913 - atomic_inc(&vcc->stats->rx);
28914 + atomic_inc_unchecked(&vcc->stats->rx);
28915 }
28916
28917 push_rxbufs(card, sb);
28918 @@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28919 printk
28920 ("nicstar%d: Out of huge buffers.\n",
28921 card->index);
28922 - atomic_inc(&vcc->stats->rx_drop);
28923 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28924 recycle_iovec_rx_bufs(card,
28925 (struct iovec *)
28926 iovb->data,
28927 @@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28928 card->hbpool.count++;
28929 } else
28930 dev_kfree_skb_any(hb);
28931 - atomic_inc(&vcc->stats->rx_drop);
28932 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28933 } else {
28934 /* Copy the small buffer to the huge buffer */
28935 sb = (struct sk_buff *)iov->iov_base;
28936 @@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28937 #endif /* NS_USE_DESTRUCTORS */
28938 __net_timestamp(hb);
28939 vcc->push(vcc, hb);
28940 - atomic_inc(&vcc->stats->rx);
28941 + atomic_inc_unchecked(&vcc->stats->rx);
28942 }
28943 }
28944
28945 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
28946 index 9851093..adb2b1e 100644
28947 --- a/drivers/atm/solos-pci.c
28948 +++ b/drivers/atm/solos-pci.c
28949 @@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
28950 }
28951 atm_charge(vcc, skb->truesize);
28952 vcc->push(vcc, skb);
28953 - atomic_inc(&vcc->stats->rx);
28954 + atomic_inc_unchecked(&vcc->stats->rx);
28955 break;
28956
28957 case PKT_STATUS:
28958 @@ -1009,7 +1009,7 @@ static uint32_t fpga_tx(struct solos_card *card)
28959 vcc = SKB_CB(oldskb)->vcc;
28960
28961 if (vcc) {
28962 - atomic_inc(&vcc->stats->tx);
28963 + atomic_inc_unchecked(&vcc->stats->tx);
28964 solos_pop(vcc, oldskb);
28965 } else
28966 dev_kfree_skb_irq(oldskb);
28967 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
28968 index 0215934..ce9f5b1 100644
28969 --- a/drivers/atm/suni.c
28970 +++ b/drivers/atm/suni.c
28971 @@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
28972
28973
28974 #define ADD_LIMITED(s,v) \
28975 - atomic_add((v),&stats->s); \
28976 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
28977 + atomic_add_unchecked((v),&stats->s); \
28978 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
28979
28980
28981 static void suni_hz(unsigned long from_timer)
28982 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
28983 index 5120a96..e2572bd 100644
28984 --- a/drivers/atm/uPD98402.c
28985 +++ b/drivers/atm/uPD98402.c
28986 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
28987 struct sonet_stats tmp;
28988 int error = 0;
28989
28990 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28991 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28992 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
28993 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
28994 if (zero && !error) {
28995 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
28996
28997
28998 #define ADD_LIMITED(s,v) \
28999 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
29000 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
29001 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
29002 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
29003 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
29004 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
29005
29006
29007 static void stat_event(struct atm_dev *dev)
29008 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
29009 if (reason & uPD98402_INT_PFM) stat_event(dev);
29010 if (reason & uPD98402_INT_PCO) {
29011 (void) GET(PCOCR); /* clear interrupt cause */
29012 - atomic_add(GET(HECCT),
29013 + atomic_add_unchecked(GET(HECCT),
29014 &PRIV(dev)->sonet_stats.uncorr_hcs);
29015 }
29016 if ((reason & uPD98402_INT_RFO) &&
29017 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
29018 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
29019 uPD98402_INT_LOS),PIMR); /* enable them */
29020 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
29021 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
29022 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
29023 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
29024 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
29025 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
29026 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
29027 return 0;
29028 }
29029
29030 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
29031 index abe4e20..83c4727 100644
29032 --- a/drivers/atm/zatm.c
29033 +++ b/drivers/atm/zatm.c
29034 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
29035 }
29036 if (!size) {
29037 dev_kfree_skb_irq(skb);
29038 - if (vcc) atomic_inc(&vcc->stats->rx_err);
29039 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
29040 continue;
29041 }
29042 if (!atm_charge(vcc,skb->truesize)) {
29043 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
29044 skb->len = size;
29045 ATM_SKB(skb)->vcc = vcc;
29046 vcc->push(vcc,skb);
29047 - atomic_inc(&vcc->stats->rx);
29048 + atomic_inc_unchecked(&vcc->stats->rx);
29049 }
29050 zout(pos & 0xffff,MTA(mbx));
29051 #if 0 /* probably a stupid idea */
29052 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
29053 skb_queue_head(&zatm_vcc->backlog,skb);
29054 break;
29055 }
29056 - atomic_inc(&vcc->stats->tx);
29057 + atomic_inc_unchecked(&vcc->stats->tx);
29058 wake_up(&zatm_vcc->tx_wait);
29059 }
29060
29061 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
29062 index deb4a45..211eff2 100644
29063 --- a/drivers/base/devtmpfs.c
29064 +++ b/drivers/base/devtmpfs.c
29065 @@ -347,7 +347,7 @@ int devtmpfs_mount(const char *mntdir)
29066 if (!thread)
29067 return 0;
29068
29069 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
29070 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
29071 if (err)
29072 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
29073 else
29074 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
29075 index cbb463b..babe2cf 100644
29076 --- a/drivers/base/power/wakeup.c
29077 +++ b/drivers/base/power/wakeup.c
29078 @@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
29079 * They need to be modified together atomically, so it's better to use one
29080 * atomic variable to hold them both.
29081 */
29082 -static atomic_t combined_event_count = ATOMIC_INIT(0);
29083 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
29084
29085 #define IN_PROGRESS_BITS (sizeof(int) * 4)
29086 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
29087
29088 static void split_counters(unsigned int *cnt, unsigned int *inpr)
29089 {
29090 - unsigned int comb = atomic_read(&combined_event_count);
29091 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
29092
29093 *cnt = (comb >> IN_PROGRESS_BITS);
29094 *inpr = comb & MAX_IN_PROGRESS;
29095 @@ -385,7 +385,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
29096 ws->start_prevent_time = ws->last_time;
29097
29098 /* Increment the counter of events in progress. */
29099 - cec = atomic_inc_return(&combined_event_count);
29100 + cec = atomic_inc_return_unchecked(&combined_event_count);
29101
29102 trace_wakeup_source_activate(ws->name, cec);
29103 }
29104 @@ -511,7 +511,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
29105 * Increment the counter of registered wakeup events and decrement the
29106 * couter of wakeup events in progress simultaneously.
29107 */
29108 - cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
29109 + cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
29110 trace_wakeup_source_deactivate(ws->name, cec);
29111
29112 split_counters(&cnt, &inpr);
29113 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
29114 index b0f553b..77b928b 100644
29115 --- a/drivers/block/cciss.c
29116 +++ b/drivers/block/cciss.c
29117 @@ -1198,6 +1198,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
29118 int err;
29119 u32 cp;
29120
29121 + memset(&arg64, 0, sizeof(arg64));
29122 +
29123 err = 0;
29124 err |=
29125 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
29126 @@ -3007,7 +3009,7 @@ static void start_io(ctlr_info_t *h)
29127 while (!list_empty(&h->reqQ)) {
29128 c = list_entry(h->reqQ.next, CommandList_struct, list);
29129 /* can't do anything if fifo is full */
29130 - if ((h->access.fifo_full(h))) {
29131 + if ((h->access->fifo_full(h))) {
29132 dev_warn(&h->pdev->dev, "fifo full\n");
29133 break;
29134 }
29135 @@ -3017,7 +3019,7 @@ static void start_io(ctlr_info_t *h)
29136 h->Qdepth--;
29137
29138 /* Tell the controller execute command */
29139 - h->access.submit_command(h, c);
29140 + h->access->submit_command(h, c);
29141
29142 /* Put job onto the completed Q */
29143 addQ(&h->cmpQ, c);
29144 @@ -3443,17 +3445,17 @@ startio:
29145
29146 static inline unsigned long get_next_completion(ctlr_info_t *h)
29147 {
29148 - return h->access.command_completed(h);
29149 + return h->access->command_completed(h);
29150 }
29151
29152 static inline int interrupt_pending(ctlr_info_t *h)
29153 {
29154 - return h->access.intr_pending(h);
29155 + return h->access->intr_pending(h);
29156 }
29157
29158 static inline long interrupt_not_for_us(ctlr_info_t *h)
29159 {
29160 - return ((h->access.intr_pending(h) == 0) ||
29161 + return ((h->access->intr_pending(h) == 0) ||
29162 (h->interrupts_enabled == 0));
29163 }
29164
29165 @@ -3486,7 +3488,7 @@ static inline u32 next_command(ctlr_info_t *h)
29166 u32 a;
29167
29168 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
29169 - return h->access.command_completed(h);
29170 + return h->access->command_completed(h);
29171
29172 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
29173 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
29174 @@ -4044,7 +4046,7 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
29175 trans_support & CFGTBL_Trans_use_short_tags);
29176
29177 /* Change the access methods to the performant access methods */
29178 - h->access = SA5_performant_access;
29179 + h->access = &SA5_performant_access;
29180 h->transMethod = CFGTBL_Trans_Performant;
29181
29182 return;
29183 @@ -4316,7 +4318,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
29184 if (prod_index < 0)
29185 return -ENODEV;
29186 h->product_name = products[prod_index].product_name;
29187 - h->access = *(products[prod_index].access);
29188 + h->access = products[prod_index].access;
29189
29190 if (cciss_board_disabled(h)) {
29191 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
29192 @@ -5041,7 +5043,7 @@ reinit_after_soft_reset:
29193 }
29194
29195 /* make sure the board interrupts are off */
29196 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29197 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29198 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
29199 if (rc)
29200 goto clean2;
29201 @@ -5093,7 +5095,7 @@ reinit_after_soft_reset:
29202 * fake ones to scoop up any residual completions.
29203 */
29204 spin_lock_irqsave(&h->lock, flags);
29205 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29206 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29207 spin_unlock_irqrestore(&h->lock, flags);
29208 free_irq(h->intr[h->intr_mode], h);
29209 rc = cciss_request_irq(h, cciss_msix_discard_completions,
29210 @@ -5113,9 +5115,9 @@ reinit_after_soft_reset:
29211 dev_info(&h->pdev->dev, "Board READY.\n");
29212 dev_info(&h->pdev->dev,
29213 "Waiting for stale completions to drain.\n");
29214 - h->access.set_intr_mask(h, CCISS_INTR_ON);
29215 + h->access->set_intr_mask(h, CCISS_INTR_ON);
29216 msleep(10000);
29217 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29218 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29219
29220 rc = controller_reset_failed(h->cfgtable);
29221 if (rc)
29222 @@ -5138,7 +5140,7 @@ reinit_after_soft_reset:
29223 cciss_scsi_setup(h);
29224
29225 /* Turn the interrupts on so we can service requests */
29226 - h->access.set_intr_mask(h, CCISS_INTR_ON);
29227 + h->access->set_intr_mask(h, CCISS_INTR_ON);
29228
29229 /* Get the firmware version */
29230 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
29231 @@ -5211,7 +5213,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
29232 kfree(flush_buf);
29233 if (return_code != IO_OK)
29234 dev_warn(&h->pdev->dev, "Error flushing cache\n");
29235 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29236 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29237 free_irq(h->intr[h->intr_mode], h);
29238 }
29239
29240 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
29241 index 7fda30e..eb5dfe0 100644
29242 --- a/drivers/block/cciss.h
29243 +++ b/drivers/block/cciss.h
29244 @@ -101,7 +101,7 @@ struct ctlr_info
29245 /* information about each logical volume */
29246 drive_info_struct *drv[CISS_MAX_LUN];
29247
29248 - struct access_method access;
29249 + struct access_method *access;
29250
29251 /* queue and queue Info */
29252 struct list_head reqQ;
29253 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
29254 index 9125bbe..eede5c8 100644
29255 --- a/drivers/block/cpqarray.c
29256 +++ b/drivers/block/cpqarray.c
29257 @@ -404,7 +404,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
29258 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
29259 goto Enomem4;
29260 }
29261 - hba[i]->access.set_intr_mask(hba[i], 0);
29262 + hba[i]->access->set_intr_mask(hba[i], 0);
29263 if (request_irq(hba[i]->intr, do_ida_intr,
29264 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
29265 {
29266 @@ -459,7 +459,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
29267 add_timer(&hba[i]->timer);
29268
29269 /* Enable IRQ now that spinlock and rate limit timer are set up */
29270 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
29271 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
29272
29273 for(j=0; j<NWD; j++) {
29274 struct gendisk *disk = ida_gendisk[i][j];
29275 @@ -694,7 +694,7 @@ DBGINFO(
29276 for(i=0; i<NR_PRODUCTS; i++) {
29277 if (board_id == products[i].board_id) {
29278 c->product_name = products[i].product_name;
29279 - c->access = *(products[i].access);
29280 + c->access = products[i].access;
29281 break;
29282 }
29283 }
29284 @@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detect(void)
29285 hba[ctlr]->intr = intr;
29286 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
29287 hba[ctlr]->product_name = products[j].product_name;
29288 - hba[ctlr]->access = *(products[j].access);
29289 + hba[ctlr]->access = products[j].access;
29290 hba[ctlr]->ctlr = ctlr;
29291 hba[ctlr]->board_id = board_id;
29292 hba[ctlr]->pci_dev = NULL; /* not PCI */
29293 @@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
29294
29295 while((c = h->reqQ) != NULL) {
29296 /* Can't do anything if we're busy */
29297 - if (h->access.fifo_full(h) == 0)
29298 + if (h->access->fifo_full(h) == 0)
29299 return;
29300
29301 /* Get the first entry from the request Q */
29302 @@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
29303 h->Qdepth--;
29304
29305 /* Tell the controller to do our bidding */
29306 - h->access.submit_command(h, c);
29307 + h->access->submit_command(h, c);
29308
29309 /* Get onto the completion Q */
29310 addQ(&h->cmpQ, c);
29311 @@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
29312 unsigned long flags;
29313 __u32 a,a1;
29314
29315 - istat = h->access.intr_pending(h);
29316 + istat = h->access->intr_pending(h);
29317 /* Is this interrupt for us? */
29318 if (istat == 0)
29319 return IRQ_NONE;
29320 @@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
29321 */
29322 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
29323 if (istat & FIFO_NOT_EMPTY) {
29324 - while((a = h->access.command_completed(h))) {
29325 + while((a = h->access->command_completed(h))) {
29326 a1 = a; a &= ~3;
29327 if ((c = h->cmpQ) == NULL)
29328 {
29329 @@ -1449,11 +1449,11 @@ static int sendcmd(
29330 /*
29331 * Disable interrupt
29332 */
29333 - info_p->access.set_intr_mask(info_p, 0);
29334 + info_p->access->set_intr_mask(info_p, 0);
29335 /* Make sure there is room in the command FIFO */
29336 /* Actually it should be completely empty at this time. */
29337 for (i = 200000; i > 0; i--) {
29338 - temp = info_p->access.fifo_full(info_p);
29339 + temp = info_p->access->fifo_full(info_p);
29340 if (temp != 0) {
29341 break;
29342 }
29343 @@ -1466,7 +1466,7 @@ DBG(
29344 /*
29345 * Send the cmd
29346 */
29347 - info_p->access.submit_command(info_p, c);
29348 + info_p->access->submit_command(info_p, c);
29349 complete = pollcomplete(ctlr);
29350
29351 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
29352 @@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
29353 * we check the new geometry. Then turn interrupts back on when
29354 * we're done.
29355 */
29356 - host->access.set_intr_mask(host, 0);
29357 + host->access->set_intr_mask(host, 0);
29358 getgeometry(ctlr);
29359 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
29360 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
29361
29362 for(i=0; i<NWD; i++) {
29363 struct gendisk *disk = ida_gendisk[ctlr][i];
29364 @@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
29365 /* Wait (up to 2 seconds) for a command to complete */
29366
29367 for (i = 200000; i > 0; i--) {
29368 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
29369 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
29370 if (done == 0) {
29371 udelay(10); /* a short fixed delay */
29372 } else
29373 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
29374 index be73e9d..7fbf140 100644
29375 --- a/drivers/block/cpqarray.h
29376 +++ b/drivers/block/cpqarray.h
29377 @@ -99,7 +99,7 @@ struct ctlr_info {
29378 drv_info_t drv[NWD];
29379 struct proc_dir_entry *proc;
29380
29381 - struct access_method access;
29382 + struct access_method *access;
29383
29384 cmdlist_t *reqQ;
29385 cmdlist_t *cmpQ;
29386 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
29387 index b953cc7..e3dc580 100644
29388 --- a/drivers/block/drbd/drbd_int.h
29389 +++ b/drivers/block/drbd/drbd_int.h
29390 @@ -735,7 +735,7 @@ struct drbd_request;
29391 struct drbd_epoch {
29392 struct list_head list;
29393 unsigned int barrier_nr;
29394 - atomic_t epoch_size; /* increased on every request added. */
29395 + atomic_unchecked_t epoch_size; /* increased on every request added. */
29396 atomic_t active; /* increased on every req. added, and dec on every finished. */
29397 unsigned long flags;
29398 };
29399 @@ -1116,7 +1116,7 @@ struct drbd_conf {
29400 void *int_dig_in;
29401 void *int_dig_vv;
29402 wait_queue_head_t seq_wait;
29403 - atomic_t packet_seq;
29404 + atomic_unchecked_t packet_seq;
29405 unsigned int peer_seq;
29406 spinlock_t peer_seq_lock;
29407 unsigned int minor;
29408 @@ -1658,30 +1658,30 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
29409
29410 static inline void drbd_tcp_cork(struct socket *sock)
29411 {
29412 - int __user val = 1;
29413 + int val = 1;
29414 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29415 - (char __user *)&val, sizeof(val));
29416 + (char __force_user *)&val, sizeof(val));
29417 }
29418
29419 static inline void drbd_tcp_uncork(struct socket *sock)
29420 {
29421 - int __user val = 0;
29422 + int val = 0;
29423 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29424 - (char __user *)&val, sizeof(val));
29425 + (char __force_user *)&val, sizeof(val));
29426 }
29427
29428 static inline void drbd_tcp_nodelay(struct socket *sock)
29429 {
29430 - int __user val = 1;
29431 + int val = 1;
29432 (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY,
29433 - (char __user *)&val, sizeof(val));
29434 + (char __force_user *)&val, sizeof(val));
29435 }
29436
29437 static inline void drbd_tcp_quickack(struct socket *sock)
29438 {
29439 - int __user val = 2;
29440 + int val = 2;
29441 (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
29442 - (char __user *)&val, sizeof(val));
29443 + (char __force_user *)&val, sizeof(val));
29444 }
29445
29446 void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo);
29447 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
29448 index f93a032..71c87bf 100644
29449 --- a/drivers/block/drbd/drbd_main.c
29450 +++ b/drivers/block/drbd/drbd_main.c
29451 @@ -2567,7 +2567,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packets cmd,
29452 p.sector = sector;
29453 p.block_id = block_id;
29454 p.blksize = blksize;
29455 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29456 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29457
29458 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
29459 return false;
29460 @@ -2865,7 +2865,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
29461
29462 p.sector = cpu_to_be64(req->sector);
29463 p.block_id = (unsigned long)req;
29464 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29465 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29466
29467 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
29468
29469 @@ -3150,7 +3150,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
29470 atomic_set(&mdev->unacked_cnt, 0);
29471 atomic_set(&mdev->local_cnt, 0);
29472 atomic_set(&mdev->net_cnt, 0);
29473 - atomic_set(&mdev->packet_seq, 0);
29474 + atomic_set_unchecked(&mdev->packet_seq, 0);
29475 atomic_set(&mdev->pp_in_use, 0);
29476 atomic_set(&mdev->pp_in_use_by_net, 0);
29477 atomic_set(&mdev->rs_sect_in, 0);
29478 @@ -3232,8 +3232,8 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
29479 mdev->receiver.t_state);
29480
29481 /* no need to lock it, I'm the only thread alive */
29482 - if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
29483 - dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
29484 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
29485 + dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
29486 mdev->al_writ_cnt =
29487 mdev->bm_writ_cnt =
29488 mdev->read_cnt =
29489 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
29490 index edb490a..ecd69da 100644
29491 --- a/drivers/block/drbd/drbd_nl.c
29492 +++ b/drivers/block/drbd/drbd_nl.c
29493 @@ -2407,7 +2407,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
29494 module_put(THIS_MODULE);
29495 }
29496
29497 -static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29498 +static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29499
29500 static unsigned short *
29501 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
29502 @@ -2478,7 +2478,7 @@ void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
29503 cn_reply->id.idx = CN_IDX_DRBD;
29504 cn_reply->id.val = CN_VAL_DRBD;
29505
29506 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29507 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29508 cn_reply->ack = 0; /* not used here. */
29509 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29510 (int)((char *)tl - (char *)reply->tag_list);
29511 @@ -2510,7 +2510,7 @@ void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
29512 cn_reply->id.idx = CN_IDX_DRBD;
29513 cn_reply->id.val = CN_VAL_DRBD;
29514
29515 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29516 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29517 cn_reply->ack = 0; /* not used here. */
29518 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29519 (int)((char *)tl - (char *)reply->tag_list);
29520 @@ -2588,7 +2588,7 @@ void drbd_bcast_ee(struct drbd_conf *mdev,
29521 cn_reply->id.idx = CN_IDX_DRBD;
29522 cn_reply->id.val = CN_VAL_DRBD;
29523
29524 - cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
29525 + cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
29526 cn_reply->ack = 0; // not used here.
29527 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29528 (int)((char*)tl - (char*)reply->tag_list);
29529 @@ -2627,7 +2627,7 @@ void drbd_bcast_sync_progress(struct drbd_conf *mdev)
29530 cn_reply->id.idx = CN_IDX_DRBD;
29531 cn_reply->id.val = CN_VAL_DRBD;
29532
29533 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29534 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29535 cn_reply->ack = 0; /* not used here. */
29536 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29537 (int)((char *)tl - (char *)reply->tag_list);
29538 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
29539 index c74ca2d..860c819 100644
29540 --- a/drivers/block/drbd/drbd_receiver.c
29541 +++ b/drivers/block/drbd/drbd_receiver.c
29542 @@ -898,7 +898,7 @@ retry:
29543 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
29544 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
29545
29546 - atomic_set(&mdev->packet_seq, 0);
29547 + atomic_set_unchecked(&mdev->packet_seq, 0);
29548 mdev->peer_seq = 0;
29549
29550 if (drbd_send_protocol(mdev) == -1)
29551 @@ -999,7 +999,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29552 do {
29553 next_epoch = NULL;
29554
29555 - epoch_size = atomic_read(&epoch->epoch_size);
29556 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
29557
29558 switch (ev & ~EV_CLEANUP) {
29559 case EV_PUT:
29560 @@ -1035,7 +1035,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29561 rv = FE_DESTROYED;
29562 } else {
29563 epoch->flags = 0;
29564 - atomic_set(&epoch->epoch_size, 0);
29565 + atomic_set_unchecked(&epoch->epoch_size, 0);
29566 /* atomic_set(&epoch->active, 0); is already zero */
29567 if (rv == FE_STILL_LIVE)
29568 rv = FE_RECYCLED;
29569 @@ -1210,14 +1210,14 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29570 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
29571 drbd_flush(mdev);
29572
29573 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
29574 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29575 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
29576 if (epoch)
29577 break;
29578 }
29579
29580 epoch = mdev->current_epoch;
29581 - wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
29582 + wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
29583
29584 D_ASSERT(atomic_read(&epoch->active) == 0);
29585 D_ASSERT(epoch->flags == 0);
29586 @@ -1229,11 +1229,11 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29587 }
29588
29589 epoch->flags = 0;
29590 - atomic_set(&epoch->epoch_size, 0);
29591 + atomic_set_unchecked(&epoch->epoch_size, 0);
29592 atomic_set(&epoch->active, 0);
29593
29594 spin_lock(&mdev->epoch_lock);
29595 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
29596 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29597 list_add(&epoch->list, &mdev->current_epoch->list);
29598 mdev->current_epoch = epoch;
29599 mdev->epochs++;
29600 @@ -1702,7 +1702,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29601 spin_unlock(&mdev->peer_seq_lock);
29602
29603 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
29604 - atomic_inc(&mdev->current_epoch->epoch_size);
29605 + atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
29606 return drbd_drain_block(mdev, data_size);
29607 }
29608
29609 @@ -1732,7 +1732,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29610
29611 spin_lock(&mdev->epoch_lock);
29612 e->epoch = mdev->current_epoch;
29613 - atomic_inc(&e->epoch->epoch_size);
29614 + atomic_inc_unchecked(&e->epoch->epoch_size);
29615 atomic_inc(&e->epoch->active);
29616 spin_unlock(&mdev->epoch_lock);
29617
29618 @@ -3954,7 +3954,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
29619 D_ASSERT(list_empty(&mdev->done_ee));
29620
29621 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
29622 - atomic_set(&mdev->current_epoch->epoch_size, 0);
29623 + atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
29624 D_ASSERT(list_empty(&mdev->current_epoch->list));
29625 }
29626
29627 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
29628 index 3bba655..6151b66 100644
29629 --- a/drivers/block/loop.c
29630 +++ b/drivers/block/loop.c
29631 @@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
29632 mm_segment_t old_fs = get_fs();
29633
29634 set_fs(get_ds());
29635 - bw = file->f_op->write(file, buf, len, &pos);
29636 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
29637 set_fs(old_fs);
29638 if (likely(bw == len))
29639 return 0;
29640 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
29641 index ea6f632..eafb192 100644
29642 --- a/drivers/char/Kconfig
29643 +++ b/drivers/char/Kconfig
29644 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
29645
29646 config DEVKMEM
29647 bool "/dev/kmem virtual device support"
29648 - default y
29649 + default n
29650 + depends on !GRKERNSEC_KMEM
29651 help
29652 Say Y here if you want to support the /dev/kmem device. The
29653 /dev/kmem device is rarely used, but can be used for certain
29654 @@ -581,6 +582,7 @@ config DEVPORT
29655 bool
29656 depends on !M68K
29657 depends on ISA || PCI
29658 + depends on !GRKERNSEC_KMEM
29659 default y
29660
29661 source "drivers/s390/char/Kconfig"
29662 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
29663 index 2e04433..22afc64 100644
29664 --- a/drivers/char/agp/frontend.c
29665 +++ b/drivers/char/agp/frontend.c
29666 @@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
29667 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
29668 return -EFAULT;
29669
29670 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
29671 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
29672 return -EFAULT;
29673
29674 client = agp_find_client_by_pid(reserve.pid);
29675 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
29676 index 21cb980..f15107c 100644
29677 --- a/drivers/char/genrtc.c
29678 +++ b/drivers/char/genrtc.c
29679 @@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
29680 switch (cmd) {
29681
29682 case RTC_PLL_GET:
29683 + memset(&pll, 0, sizeof(pll));
29684 if (get_rtc_pll(&pll))
29685 return -EINVAL;
29686 else
29687 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
29688 index dfd7876..c0b0885 100644
29689 --- a/drivers/char/hpet.c
29690 +++ b/drivers/char/hpet.c
29691 @@ -571,7 +571,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
29692 }
29693
29694 static int
29695 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
29696 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
29697 struct hpet_info *info)
29698 {
29699 struct hpet_timer __iomem *timer;
29700 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
29701 index 2c29942..604c5ba 100644
29702 --- a/drivers/char/ipmi/ipmi_msghandler.c
29703 +++ b/drivers/char/ipmi/ipmi_msghandler.c
29704 @@ -420,7 +420,7 @@ struct ipmi_smi {
29705 struct proc_dir_entry *proc_dir;
29706 char proc_dir_name[10];
29707
29708 - atomic_t stats[IPMI_NUM_STATS];
29709 + atomic_unchecked_t stats[IPMI_NUM_STATS];
29710
29711 /*
29712 * run_to_completion duplicate of smb_info, smi_info
29713 @@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
29714
29715
29716 #define ipmi_inc_stat(intf, stat) \
29717 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
29718 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
29719 #define ipmi_get_stat(intf, stat) \
29720 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
29721 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
29722
29723 static int is_lan_addr(struct ipmi_addr *addr)
29724 {
29725 @@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
29726 INIT_LIST_HEAD(&intf->cmd_rcvrs);
29727 init_waitqueue_head(&intf->waitq);
29728 for (i = 0; i < IPMI_NUM_STATS; i++)
29729 - atomic_set(&intf->stats[i], 0);
29730 + atomic_set_unchecked(&intf->stats[i], 0);
29731
29732 intf->proc_dir = NULL;
29733
29734 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
29735 index 83f85cf..279e63f 100644
29736 --- a/drivers/char/ipmi/ipmi_si_intf.c
29737 +++ b/drivers/char/ipmi/ipmi_si_intf.c
29738 @@ -275,7 +275,7 @@ struct smi_info {
29739 unsigned char slave_addr;
29740
29741 /* Counters and things for the proc filesystem. */
29742 - atomic_t stats[SI_NUM_STATS];
29743 + atomic_unchecked_t stats[SI_NUM_STATS];
29744
29745 struct task_struct *thread;
29746
29747 @@ -284,9 +284,9 @@ struct smi_info {
29748 };
29749
29750 #define smi_inc_stat(smi, stat) \
29751 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
29752 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
29753 #define smi_get_stat(smi, stat) \
29754 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
29755 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
29756
29757 #define SI_MAX_PARMS 4
29758
29759 @@ -3193,7 +3193,7 @@ static int try_smi_init(struct smi_info *new_smi)
29760 atomic_set(&new_smi->req_events, 0);
29761 new_smi->run_to_completion = 0;
29762 for (i = 0; i < SI_NUM_STATS; i++)
29763 - atomic_set(&new_smi->stats[i], 0);
29764 + atomic_set_unchecked(&new_smi->stats[i], 0);
29765
29766 new_smi->interrupt_disabled = 1;
29767 atomic_set(&new_smi->stop_operation, 0);
29768 diff --git a/drivers/char/mbcs.c b/drivers/char/mbcs.c
29769 index 47ff7e4..0c7d340 100644
29770 --- a/drivers/char/mbcs.c
29771 +++ b/drivers/char/mbcs.c
29772 @@ -799,7 +799,7 @@ static int mbcs_remove(struct cx_dev *dev)
29773 return 0;
29774 }
29775
29776 -static const struct cx_device_id __devinitdata mbcs_id_table[] = {
29777 +static const struct cx_device_id __devinitconst mbcs_id_table[] = {
29778 {
29779 .part_num = MBCS_PART_NUM,
29780 .mfg_num = MBCS_MFG_NUM,
29781 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
29782 index e5eedfa..fcab50ea 100644
29783 --- a/drivers/char/mem.c
29784 +++ b/drivers/char/mem.c
29785 @@ -18,6 +18,7 @@
29786 #include <linux/raw.h>
29787 #include <linux/tty.h>
29788 #include <linux/capability.h>
29789 +#include <linux/security.h>
29790 #include <linux/ptrace.h>
29791 #include <linux/device.h>
29792 #include <linux/highmem.h>
29793 @@ -37,6 +38,10 @@
29794
29795 #define DEVPORT_MINOR 4
29796
29797 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29798 +extern const struct file_operations grsec_fops;
29799 +#endif
29800 +
29801 static inline unsigned long size_inside_page(unsigned long start,
29802 unsigned long size)
29803 {
29804 @@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29805
29806 while (cursor < to) {
29807 if (!devmem_is_allowed(pfn)) {
29808 +#ifdef CONFIG_GRKERNSEC_KMEM
29809 + gr_handle_mem_readwrite(from, to);
29810 +#else
29811 printk(KERN_INFO
29812 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
29813 current->comm, from, to);
29814 +#endif
29815 return 0;
29816 }
29817 cursor += PAGE_SIZE;
29818 @@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29819 }
29820 return 1;
29821 }
29822 +#elif defined(CONFIG_GRKERNSEC_KMEM)
29823 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29824 +{
29825 + return 0;
29826 +}
29827 #else
29828 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29829 {
29830 @@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29831
29832 while (count > 0) {
29833 unsigned long remaining;
29834 + char *temp;
29835
29836 sz = size_inside_page(p, count);
29837
29838 @@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29839 if (!ptr)
29840 return -EFAULT;
29841
29842 - remaining = copy_to_user(buf, ptr, sz);
29843 +#ifdef CONFIG_PAX_USERCOPY
29844 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
29845 + if (!temp) {
29846 + unxlate_dev_mem_ptr(p, ptr);
29847 + return -ENOMEM;
29848 + }
29849 + memcpy(temp, ptr, sz);
29850 +#else
29851 + temp = ptr;
29852 +#endif
29853 +
29854 + remaining = copy_to_user(buf, temp, sz);
29855 +
29856 +#ifdef CONFIG_PAX_USERCOPY
29857 + kfree(temp);
29858 +#endif
29859 +
29860 unxlate_dev_mem_ptr(p, ptr);
29861 if (remaining)
29862 return -EFAULT;
29863 @@ -398,9 +429,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29864 size_t count, loff_t *ppos)
29865 {
29866 unsigned long p = *ppos;
29867 - ssize_t low_count, read, sz;
29868 + ssize_t low_count, read, sz, err = 0;
29869 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
29870 - int err = 0;
29871
29872 read = 0;
29873 if (p < (unsigned long) high_memory) {
29874 @@ -422,6 +452,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29875 }
29876 #endif
29877 while (low_count > 0) {
29878 + char *temp;
29879 +
29880 sz = size_inside_page(p, low_count);
29881
29882 /*
29883 @@ -431,7 +463,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29884 */
29885 kbuf = xlate_dev_kmem_ptr((char *)p);
29886
29887 - if (copy_to_user(buf, kbuf, sz))
29888 +#ifdef CONFIG_PAX_USERCOPY
29889 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
29890 + if (!temp)
29891 + return -ENOMEM;
29892 + memcpy(temp, kbuf, sz);
29893 +#else
29894 + temp = kbuf;
29895 +#endif
29896 +
29897 + err = copy_to_user(buf, temp, sz);
29898 +
29899 +#ifdef CONFIG_PAX_USERCOPY
29900 + kfree(temp);
29901 +#endif
29902 +
29903 + if (err)
29904 return -EFAULT;
29905 buf += sz;
29906 p += sz;
29907 @@ -833,6 +880,9 @@ static const struct memdev {
29908 #ifdef CONFIG_CRASH_DUMP
29909 [12] = { "oldmem", 0, &oldmem_fops, NULL },
29910 #endif
29911 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29912 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
29913 +#endif
29914 };
29915
29916 static int memory_open(struct inode *inode, struct file *filp)
29917 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
29918 index 9df78e2..01ba9ae 100644
29919 --- a/drivers/char/nvram.c
29920 +++ b/drivers/char/nvram.c
29921 @@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
29922
29923 spin_unlock_irq(&rtc_lock);
29924
29925 - if (copy_to_user(buf, contents, tmp - contents))
29926 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
29927 return -EFAULT;
29928
29929 *ppos = i;
29930 diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
29931 index 0a484b4..f48ccd1 100644
29932 --- a/drivers/char/pcmcia/synclink_cs.c
29933 +++ b/drivers/char/pcmcia/synclink_cs.c
29934 @@ -2340,9 +2340,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
29935
29936 if (debug_level >= DEBUG_LEVEL_INFO)
29937 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
29938 - __FILE__,__LINE__, info->device_name, port->count);
29939 + __FILE__,__LINE__, info->device_name, atomic_read(&port->count));
29940
29941 - WARN_ON(!port->count);
29942 + WARN_ON(!atomic_read(&port->count));
29943
29944 if (tty_port_close_start(port, tty, filp) == 0)
29945 goto cleanup;
29946 @@ -2360,7 +2360,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
29947 cleanup:
29948 if (debug_level >= DEBUG_LEVEL_INFO)
29949 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__,__LINE__,
29950 - tty->driver->name, port->count);
29951 + tty->driver->name, atomic_read(&port->count));
29952 }
29953
29954 /* Wait until the transmitter is empty.
29955 @@ -2502,7 +2502,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
29956
29957 if (debug_level >= DEBUG_LEVEL_INFO)
29958 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
29959 - __FILE__,__LINE__,tty->driver->name, port->count);
29960 + __FILE__,__LINE__,tty->driver->name, atomic_read(&port->count));
29961
29962 /* If port is closing, signal caller to try again */
29963 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
29964 @@ -2522,11 +2522,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
29965 goto cleanup;
29966 }
29967 spin_lock(&port->lock);
29968 - port->count++;
29969 + atomic_inc(&port->count);
29970 spin_unlock(&port->lock);
29971 spin_unlock_irqrestore(&info->netlock, flags);
29972
29973 - if (port->count == 1) {
29974 + if (atomic_read(&port->count) == 1) {
29975 /* 1st open on this device, init hardware */
29976 retval = startup(info, tty);
29977 if (retval < 0)
29978 @@ -3891,7 +3891,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
29979 unsigned short new_crctype;
29980
29981 /* return error if TTY interface open */
29982 - if (info->port.count)
29983 + if (atomic_read(&info->port.count))
29984 return -EBUSY;
29985
29986 switch (encoding)
29987 @@ -3994,7 +3994,7 @@ static int hdlcdev_open(struct net_device *dev)
29988
29989 /* arbitrate between network and tty opens */
29990 spin_lock_irqsave(&info->netlock, flags);
29991 - if (info->port.count != 0 || info->netcount != 0) {
29992 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
29993 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
29994 spin_unlock_irqrestore(&info->netlock, flags);
29995 return -EBUSY;
29996 @@ -4083,7 +4083,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
29997 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
29998
29999 /* return error if TTY interface open */
30000 - if (info->port.count)
30001 + if (atomic_read(&info->port.count))
30002 return -EBUSY;
30003
30004 if (cmd != SIOCWANDEV)
30005 diff --git a/drivers/char/random.c b/drivers/char/random.c
30006 index b86eae9..4192a7a 100644
30007 --- a/drivers/char/random.c
30008 +++ b/drivers/char/random.c
30009 @@ -272,8 +272,13 @@
30010 /*
30011 * Configuration information
30012 */
30013 +#ifdef CONFIG_GRKERNSEC_RANDNET
30014 +#define INPUT_POOL_WORDS 512
30015 +#define OUTPUT_POOL_WORDS 128
30016 +#else
30017 #define INPUT_POOL_WORDS 128
30018 #define OUTPUT_POOL_WORDS 32
30019 +#endif
30020 #define SEC_XFER_SIZE 512
30021 #define EXTRACT_SIZE 10
30022
30023 @@ -313,10 +318,17 @@ static struct poolinfo {
30024 int poolwords;
30025 int tap1, tap2, tap3, tap4, tap5;
30026 } poolinfo_table[] = {
30027 +#ifdef CONFIG_GRKERNSEC_RANDNET
30028 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
30029 + { 512, 411, 308, 208, 104, 1 },
30030 + /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
30031 + { 128, 103, 76, 51, 25, 1 },
30032 +#else
30033 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
30034 { 128, 103, 76, 51, 25, 1 },
30035 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
30036 { 32, 26, 20, 14, 7, 1 },
30037 +#endif
30038 #if 0
30039 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
30040 { 2048, 1638, 1231, 819, 411, 1 },
30041 @@ -527,8 +539,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
30042 input_rotate += i ? 7 : 14;
30043 }
30044
30045 - ACCESS_ONCE(r->input_rotate) = input_rotate;
30046 - ACCESS_ONCE(r->add_ptr) = i;
30047 + ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
30048 + ACCESS_ONCE_RW(r->add_ptr) = i;
30049 smp_wmb();
30050
30051 if (out)
30052 @@ -799,6 +811,17 @@ void add_disk_randomness(struct gendisk *disk)
30053 }
30054 #endif
30055
30056 +#ifdef CONFIG_PAX_LATENT_ENTROPY
30057 +u64 latent_entropy;
30058 +
30059 +__init void transfer_latent_entropy(void)
30060 +{
30061 + mix_pool_bytes(&input_pool, &latent_entropy, sizeof(latent_entropy), NULL);
30062 + mix_pool_bytes(&nonblocking_pool, &latent_entropy, sizeof(latent_entropy), NULL);
30063 +// printk(KERN_INFO "PAX: transferring latent entropy: %16llx\n", latent_entropy);
30064 +}
30065 +#endif
30066 +
30067 /*********************************************************************
30068 *
30069 * Entropy extraction routines
30070 @@ -1008,7 +1031,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
30071
30072 extract_buf(r, tmp);
30073 i = min_t(int, nbytes, EXTRACT_SIZE);
30074 - if (copy_to_user(buf, tmp, i)) {
30075 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
30076 ret = -EFAULT;
30077 break;
30078 }
30079 @@ -1342,7 +1365,7 @@ EXPORT_SYMBOL(generate_random_uuid);
30080 #include <linux/sysctl.h>
30081
30082 static int min_read_thresh = 8, min_write_thresh;
30083 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
30084 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
30085 static int max_write_thresh = INPUT_POOL_WORDS * 32;
30086 static char sysctl_bootid[16];
30087
30088 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
30089 index f877805..403375a 100644
30090 --- a/drivers/char/sonypi.c
30091 +++ b/drivers/char/sonypi.c
30092 @@ -54,6 +54,7 @@
30093
30094 #include <asm/uaccess.h>
30095 #include <asm/io.h>
30096 +#include <asm/local.h>
30097
30098 #include <linux/sonypi.h>
30099
30100 @@ -490,7 +491,7 @@ static struct sonypi_device {
30101 spinlock_t fifo_lock;
30102 wait_queue_head_t fifo_proc_list;
30103 struct fasync_struct *fifo_async;
30104 - int open_count;
30105 + local_t open_count;
30106 int model;
30107 struct input_dev *input_jog_dev;
30108 struct input_dev *input_key_dev;
30109 @@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
30110 static int sonypi_misc_release(struct inode *inode, struct file *file)
30111 {
30112 mutex_lock(&sonypi_device.lock);
30113 - sonypi_device.open_count--;
30114 + local_dec(&sonypi_device.open_count);
30115 mutex_unlock(&sonypi_device.lock);
30116 return 0;
30117 }
30118 @@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
30119 {
30120 mutex_lock(&sonypi_device.lock);
30121 /* Flush input queue on first open */
30122 - if (!sonypi_device.open_count)
30123 + if (!local_read(&sonypi_device.open_count))
30124 kfifo_reset(&sonypi_device.fifo);
30125 - sonypi_device.open_count++;
30126 + local_inc(&sonypi_device.open_count);
30127 mutex_unlock(&sonypi_device.lock);
30128
30129 return 0;
30130 diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
30131 index 4dc8024..90108d1 100644
30132 --- a/drivers/char/tpm/tpm.c
30133 +++ b/drivers/char/tpm/tpm.c
30134 @@ -415,7 +415,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
30135 chip->vendor.req_complete_val)
30136 goto out_recv;
30137
30138 - if ((status == chip->vendor.req_canceled)) {
30139 + if (status == chip->vendor.req_canceled) {
30140 dev_err(chip->dev, "Operation Canceled\n");
30141 rc = -ECANCELED;
30142 goto out;
30143 diff --git a/drivers/char/tpm/tpm_bios.c b/drivers/char/tpm/tpm_bios.c
30144 index 0636520..169c1d0 100644
30145 --- a/drivers/char/tpm/tpm_bios.c
30146 +++ b/drivers/char/tpm/tpm_bios.c
30147 @@ -173,7 +173,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
30148 event = addr;
30149
30150 if ((event->event_type == 0 && event->event_size == 0) ||
30151 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
30152 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
30153 return NULL;
30154
30155 return addr;
30156 @@ -198,7 +198,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
30157 return NULL;
30158
30159 if ((event->event_type == 0 && event->event_size == 0) ||
30160 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
30161 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
30162 return NULL;
30163
30164 (*pos)++;
30165 @@ -291,7 +291,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
30166 int i;
30167
30168 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
30169 - seq_putc(m, data[i]);
30170 + if (!seq_putc(m, data[i]))
30171 + return -EFAULT;
30172
30173 return 0;
30174 }
30175 @@ -410,8 +411,13 @@ static int read_log(struct tpm_bios_log *log)
30176 log->bios_event_log_end = log->bios_event_log + len;
30177
30178 virt = acpi_os_map_memory(start, len);
30179 + if (!virt) {
30180 + kfree(log->bios_event_log);
30181 + log->bios_event_log = NULL;
30182 + return -EFAULT;
30183 + }
30184
30185 - memcpy(log->bios_event_log, virt, len);
30186 + memcpy(log->bios_event_log, (const char __force_kernel *)virt, len);
30187
30188 acpi_os_unmap_memory(virt, len);
30189 return 0;
30190 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
30191 index cdf2f54..e55c197 100644
30192 --- a/drivers/char/virtio_console.c
30193 +++ b/drivers/char/virtio_console.c
30194 @@ -563,7 +563,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
30195 if (to_user) {
30196 ssize_t ret;
30197
30198 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
30199 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
30200 if (ret)
30201 return -EFAULT;
30202 } else {
30203 @@ -662,7 +662,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
30204 if (!port_has_data(port) && !port->host_connected)
30205 return 0;
30206
30207 - return fill_readbuf(port, ubuf, count, true);
30208 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
30209 }
30210
30211 static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,
30212 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
30213 index e164c55..3aabb50 100644
30214 --- a/drivers/edac/edac_pci_sysfs.c
30215 +++ b/drivers/edac/edac_pci_sysfs.c
30216 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
30217 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
30218 static int edac_pci_poll_msec = 1000; /* one second workq period */
30219
30220 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
30221 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
30222 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
30223 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
30224
30225 static struct kobject *edac_pci_top_main_kobj;
30226 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
30227 @@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30228 edac_printk(KERN_CRIT, EDAC_PCI,
30229 "Signaled System Error on %s\n",
30230 pci_name(dev));
30231 - atomic_inc(&pci_nonparity_count);
30232 + atomic_inc_unchecked(&pci_nonparity_count);
30233 }
30234
30235 if (status & (PCI_STATUS_PARITY)) {
30236 @@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30237 "Master Data Parity Error on %s\n",
30238 pci_name(dev));
30239
30240 - atomic_inc(&pci_parity_count);
30241 + atomic_inc_unchecked(&pci_parity_count);
30242 }
30243
30244 if (status & (PCI_STATUS_DETECTED_PARITY)) {
30245 @@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30246 "Detected Parity Error on %s\n",
30247 pci_name(dev));
30248
30249 - atomic_inc(&pci_parity_count);
30250 + atomic_inc_unchecked(&pci_parity_count);
30251 }
30252 }
30253
30254 @@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30255 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
30256 "Signaled System Error on %s\n",
30257 pci_name(dev));
30258 - atomic_inc(&pci_nonparity_count);
30259 + atomic_inc_unchecked(&pci_nonparity_count);
30260 }
30261
30262 if (status & (PCI_STATUS_PARITY)) {
30263 @@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30264 "Master Data Parity Error on "
30265 "%s\n", pci_name(dev));
30266
30267 - atomic_inc(&pci_parity_count);
30268 + atomic_inc_unchecked(&pci_parity_count);
30269 }
30270
30271 if (status & (PCI_STATUS_DETECTED_PARITY)) {
30272 @@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30273 "Detected Parity Error on %s\n",
30274 pci_name(dev));
30275
30276 - atomic_inc(&pci_parity_count);
30277 + atomic_inc_unchecked(&pci_parity_count);
30278 }
30279 }
30280 }
30281 @@ -676,7 +676,7 @@ void edac_pci_do_parity_check(void)
30282 if (!check_pci_errors)
30283 return;
30284
30285 - before_count = atomic_read(&pci_parity_count);
30286 + before_count = atomic_read_unchecked(&pci_parity_count);
30287
30288 /* scan all PCI devices looking for a Parity Error on devices and
30289 * bridges.
30290 @@ -688,7 +688,7 @@ void edac_pci_do_parity_check(void)
30291 /* Only if operator has selected panic on PCI Error */
30292 if (edac_pci_get_panic_on_pe()) {
30293 /* If the count is different 'after' from 'before' */
30294 - if (before_count != atomic_read(&pci_parity_count))
30295 + if (before_count != atomic_read_unchecked(&pci_parity_count))
30296 panic("EDAC: PCI Parity Error");
30297 }
30298 }
30299 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
30300 index 8c87a5e..a19cbd7 100644
30301 --- a/drivers/edac/mce_amd.h
30302 +++ b/drivers/edac/mce_amd.h
30303 @@ -80,7 +80,7 @@ extern const char * const ii_msgs[];
30304 struct amd_decoder_ops {
30305 bool (*dc_mce)(u16, u8);
30306 bool (*ic_mce)(u16, u8);
30307 -};
30308 +} __no_const;
30309
30310 void amd_report_gart_errors(bool);
30311 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
30312 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
30313 index 57ea7f4..789e3c3 100644
30314 --- a/drivers/firewire/core-card.c
30315 +++ b/drivers/firewire/core-card.c
30316 @@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
30317
30318 void fw_core_remove_card(struct fw_card *card)
30319 {
30320 - struct fw_card_driver dummy_driver = dummy_driver_template;
30321 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
30322
30323 card->driver->update_phy_reg(card, 4,
30324 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
30325 diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
30326 index f8d2287..5aaf4db 100644
30327 --- a/drivers/firewire/core-cdev.c
30328 +++ b/drivers/firewire/core-cdev.c
30329 @@ -1365,8 +1365,7 @@ static int init_iso_resource(struct client *client,
30330 int ret;
30331
30332 if ((request->channels == 0 && request->bandwidth == 0) ||
30333 - request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
30334 - request->bandwidth < 0)
30335 + request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
30336 return -EINVAL;
30337
30338 r = kmalloc(sizeof(*r), GFP_KERNEL);
30339 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
30340 index 87d6f2d..5bf9d90 100644
30341 --- a/drivers/firewire/core-transaction.c
30342 +++ b/drivers/firewire/core-transaction.c
30343 @@ -37,6 +37,7 @@
30344 #include <linux/timer.h>
30345 #include <linux/types.h>
30346 #include <linux/workqueue.h>
30347 +#include <linux/sched.h>
30348
30349 #include <asm/byteorder.h>
30350
30351 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
30352 index 515a42c..5ecf3ba 100644
30353 --- a/drivers/firewire/core.h
30354 +++ b/drivers/firewire/core.h
30355 @@ -111,6 +111,7 @@ struct fw_card_driver {
30356
30357 int (*stop_iso)(struct fw_iso_context *ctx);
30358 };
30359 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
30360
30361 void fw_card_initialize(struct fw_card *card,
30362 const struct fw_card_driver *driver, struct device *device);
30363 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
30364 index b298158..7ed8432 100644
30365 --- a/drivers/firmware/dmi_scan.c
30366 +++ b/drivers/firmware/dmi_scan.c
30367 @@ -452,11 +452,6 @@ void __init dmi_scan_machine(void)
30368 }
30369 }
30370 else {
30371 - /*
30372 - * no iounmap() for that ioremap(); it would be a no-op, but
30373 - * it's so early in setup that sucker gets confused into doing
30374 - * what it shouldn't if we actually call it.
30375 - */
30376 p = dmi_ioremap(0xF0000, 0x10000);
30377 if (p == NULL)
30378 goto error;
30379 @@ -726,7 +721,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
30380 if (buf == NULL)
30381 return -1;
30382
30383 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
30384 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
30385
30386 iounmap(buf);
30387 return 0;
30388 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
30389 index 82d5c20..44a7177 100644
30390 --- a/drivers/gpio/gpio-vr41xx.c
30391 +++ b/drivers/gpio/gpio-vr41xx.c
30392 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
30393 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
30394 maskl, pendl, maskh, pendh);
30395
30396 - atomic_inc(&irq_err_count);
30397 + atomic_inc_unchecked(&irq_err_count);
30398
30399 return -EINVAL;
30400 }
30401 diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
30402 index 3252e70..b5314ace 100644
30403 --- a/drivers/gpu/drm/drm_crtc_helper.c
30404 +++ b/drivers/gpu/drm/drm_crtc_helper.c
30405 @@ -286,7 +286,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
30406 struct drm_crtc *tmp;
30407 int crtc_mask = 1;
30408
30409 - WARN(!crtc, "checking null crtc?\n");
30410 + BUG_ON(!crtc);
30411
30412 dev = crtc->dev;
30413
30414 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
30415 index 9238de4..a27c72a 100644
30416 --- a/drivers/gpu/drm/drm_drv.c
30417 +++ b/drivers/gpu/drm/drm_drv.c
30418 @@ -307,7 +307,7 @@ module_exit(drm_core_exit);
30419 /**
30420 * Copy and IOCTL return string to user space
30421 */
30422 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
30423 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
30424 {
30425 int len;
30426
30427 @@ -390,7 +390,7 @@ long drm_ioctl(struct file *filp,
30428 return -ENODEV;
30429
30430 atomic_inc(&dev->ioctl_count);
30431 - atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
30432 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
30433 ++file_priv->ioctl_count;
30434
30435 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
30436 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
30437 index 7aff5c7..bee6c27 100644
30438 --- a/drivers/gpu/drm/drm_fops.c
30439 +++ b/drivers/gpu/drm/drm_fops.c
30440 @@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
30441 }
30442
30443 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
30444 - atomic_set(&dev->counts[i], 0);
30445 + atomic_set_unchecked(&dev->counts[i], 0);
30446
30447 dev->sigdata.lock = NULL;
30448
30449 @@ -134,7 +134,7 @@ int drm_open(struct inode *inode, struct file *filp)
30450 if (drm_device_is_unplugged(dev))
30451 return -ENODEV;
30452
30453 - if (!dev->open_count++)
30454 + if (local_inc_return(&dev->open_count) == 1)
30455 need_setup = 1;
30456 mutex_lock(&dev->struct_mutex);
30457 old_mapping = dev->dev_mapping;
30458 @@ -149,7 +149,7 @@ int drm_open(struct inode *inode, struct file *filp)
30459 retcode = drm_open_helper(inode, filp, dev);
30460 if (retcode)
30461 goto err_undo;
30462 - atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
30463 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
30464 if (need_setup) {
30465 retcode = drm_setup(dev);
30466 if (retcode)
30467 @@ -164,7 +164,7 @@ err_undo:
30468 iput(container_of(dev->dev_mapping, struct inode, i_data));
30469 dev->dev_mapping = old_mapping;
30470 mutex_unlock(&dev->struct_mutex);
30471 - dev->open_count--;
30472 + local_dec(&dev->open_count);
30473 return retcode;
30474 }
30475 EXPORT_SYMBOL(drm_open);
30476 @@ -438,7 +438,7 @@ int drm_release(struct inode *inode, struct file *filp)
30477
30478 mutex_lock(&drm_global_mutex);
30479
30480 - DRM_DEBUG("open_count = %d\n", dev->open_count);
30481 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
30482
30483 if (dev->driver->preclose)
30484 dev->driver->preclose(dev, file_priv);
30485 @@ -447,10 +447,10 @@ int drm_release(struct inode *inode, struct file *filp)
30486 * Begin inline drm_release
30487 */
30488
30489 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
30490 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
30491 task_pid_nr(current),
30492 (long)old_encode_dev(file_priv->minor->device),
30493 - dev->open_count);
30494 + local_read(&dev->open_count));
30495
30496 /* Release any auth tokens that might point to this file_priv,
30497 (do that under the drm_global_mutex) */
30498 @@ -546,8 +546,8 @@ int drm_release(struct inode *inode, struct file *filp)
30499 * End inline drm_release
30500 */
30501
30502 - atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
30503 - if (!--dev->open_count) {
30504 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
30505 + if (local_dec_and_test(&dev->open_count)) {
30506 if (atomic_read(&dev->ioctl_count)) {
30507 DRM_ERROR("Device busy: %d\n",
30508 atomic_read(&dev->ioctl_count));
30509 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
30510 index c87dc96..326055d 100644
30511 --- a/drivers/gpu/drm/drm_global.c
30512 +++ b/drivers/gpu/drm/drm_global.c
30513 @@ -36,7 +36,7 @@
30514 struct drm_global_item {
30515 struct mutex mutex;
30516 void *object;
30517 - int refcount;
30518 + atomic_t refcount;
30519 };
30520
30521 static struct drm_global_item glob[DRM_GLOBAL_NUM];
30522 @@ -49,7 +49,7 @@ void drm_global_init(void)
30523 struct drm_global_item *item = &glob[i];
30524 mutex_init(&item->mutex);
30525 item->object = NULL;
30526 - item->refcount = 0;
30527 + atomic_set(&item->refcount, 0);
30528 }
30529 }
30530
30531 @@ -59,7 +59,7 @@ void drm_global_release(void)
30532 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
30533 struct drm_global_item *item = &glob[i];
30534 BUG_ON(item->object != NULL);
30535 - BUG_ON(item->refcount != 0);
30536 + BUG_ON(atomic_read(&item->refcount) != 0);
30537 }
30538 }
30539
30540 @@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30541 void *object;
30542
30543 mutex_lock(&item->mutex);
30544 - if (item->refcount == 0) {
30545 + if (atomic_read(&item->refcount) == 0) {
30546 item->object = kzalloc(ref->size, GFP_KERNEL);
30547 if (unlikely(item->object == NULL)) {
30548 ret = -ENOMEM;
30549 @@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30550 goto out_err;
30551
30552 }
30553 - ++item->refcount;
30554 + atomic_inc(&item->refcount);
30555 ref->object = item->object;
30556 object = item->object;
30557 mutex_unlock(&item->mutex);
30558 @@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
30559 struct drm_global_item *item = &glob[ref->global_type];
30560
30561 mutex_lock(&item->mutex);
30562 - BUG_ON(item->refcount == 0);
30563 + BUG_ON(atomic_read(&item->refcount) == 0);
30564 BUG_ON(ref->object != item->object);
30565 - if (--item->refcount == 0) {
30566 + if (atomic_dec_and_test(&item->refcount)) {
30567 ref->release(ref);
30568 item->object = NULL;
30569 }
30570 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
30571 index 8928edb..0c79258 100644
30572 --- a/drivers/gpu/drm/drm_info.c
30573 +++ b/drivers/gpu/drm/drm_info.c
30574 @@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
30575 struct drm_local_map *map;
30576 struct drm_map_list *r_list;
30577
30578 - /* Hardcoded from _DRM_FRAME_BUFFER,
30579 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
30580 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
30581 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
30582 + static const char * const types[] = {
30583 + [_DRM_FRAME_BUFFER] = "FB",
30584 + [_DRM_REGISTERS] = "REG",
30585 + [_DRM_SHM] = "SHM",
30586 + [_DRM_AGP] = "AGP",
30587 + [_DRM_SCATTER_GATHER] = "SG",
30588 + [_DRM_CONSISTENT] = "PCI",
30589 + [_DRM_GEM] = "GEM" };
30590 const char *type;
30591 int i;
30592
30593 @@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
30594 map = r_list->map;
30595 if (!map)
30596 continue;
30597 - if (map->type < 0 || map->type > 5)
30598 + if (map->type >= ARRAY_SIZE(types))
30599 type = "??";
30600 else
30601 type = types[map->type];
30602 @@ -254,7 +258,11 @@ int drm_vma_info(struct seq_file *m, void *data)
30603 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
30604 vma->vm_flags & VM_LOCKED ? 'l' : '-',
30605 vma->vm_flags & VM_IO ? 'i' : '-',
30606 +#ifdef CONFIG_GRKERNSEC_HIDESYM
30607 + 0);
30608 +#else
30609 vma->vm_pgoff);
30610 +#endif
30611
30612 #if defined(__i386__)
30613 pgprot = pgprot_val(vma->vm_page_prot);
30614 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
30615 index 637fcc3..e890b33 100644
30616 --- a/drivers/gpu/drm/drm_ioc32.c
30617 +++ b/drivers/gpu/drm/drm_ioc32.c
30618 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
30619 request = compat_alloc_user_space(nbytes);
30620 if (!access_ok(VERIFY_WRITE, request, nbytes))
30621 return -EFAULT;
30622 - list = (struct drm_buf_desc *) (request + 1);
30623 + list = (struct drm_buf_desc __user *) (request + 1);
30624
30625 if (__put_user(count, &request->count)
30626 || __put_user(list, &request->list))
30627 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
30628 request = compat_alloc_user_space(nbytes);
30629 if (!access_ok(VERIFY_WRITE, request, nbytes))
30630 return -EFAULT;
30631 - list = (struct drm_buf_pub *) (request + 1);
30632 + list = (struct drm_buf_pub __user *) (request + 1);
30633
30634 if (__put_user(count, &request->count)
30635 || __put_user(list, &request->list))
30636 diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
30637 index 64a62c6..ceab35e 100644
30638 --- a/drivers/gpu/drm/drm_ioctl.c
30639 +++ b/drivers/gpu/drm/drm_ioctl.c
30640 @@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
30641 stats->data[i].value =
30642 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
30643 else
30644 - stats->data[i].value = atomic_read(&dev->counts[i]);
30645 + stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
30646 stats->data[i].type = dev->types[i];
30647 }
30648
30649 diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
30650 index 3203955..c8090af 100644
30651 --- a/drivers/gpu/drm/drm_lock.c
30652 +++ b/drivers/gpu/drm/drm_lock.c
30653 @@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30654 if (drm_lock_take(&master->lock, lock->context)) {
30655 master->lock.file_priv = file_priv;
30656 master->lock.lock_time = jiffies;
30657 - atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
30658 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
30659 break; /* Got lock */
30660 }
30661
30662 @@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30663 return -EINVAL;
30664 }
30665
30666 - atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
30667 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
30668
30669 if (drm_lock_free(&master->lock, lock->context)) {
30670 /* FIXME: Should really bail out here. */
30671 diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
30672 index 21bcd4a..8e074e0 100644
30673 --- a/drivers/gpu/drm/drm_stub.c
30674 +++ b/drivers/gpu/drm/drm_stub.c
30675 @@ -511,7 +511,7 @@ void drm_unplug_dev(struct drm_device *dev)
30676
30677 drm_device_set_unplugged(dev);
30678
30679 - if (dev->open_count == 0) {
30680 + if (local_read(&dev->open_count) == 0) {
30681 drm_put_dev(dev);
30682 }
30683 mutex_unlock(&drm_global_mutex);
30684 diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
30685 index 463ec68..f5bd2b5 100644
30686 --- a/drivers/gpu/drm/i810/i810_dma.c
30687 +++ b/drivers/gpu/drm/i810/i810_dma.c
30688 @@ -946,8 +946,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
30689 dma->buflist[vertex->idx],
30690 vertex->discard, vertex->used);
30691
30692 - atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30693 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30694 + atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30695 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30696 sarea_priv->last_enqueue = dev_priv->counter - 1;
30697 sarea_priv->last_dispatch = (int)hw_status[5];
30698
30699 @@ -1107,8 +1107,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
30700 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
30701 mc->last_render);
30702
30703 - atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30704 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30705 + atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30706 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30707 sarea_priv->last_enqueue = dev_priv->counter - 1;
30708 sarea_priv->last_dispatch = (int)hw_status[5];
30709
30710 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
30711 index 6e0acad..93c8289 100644
30712 --- a/drivers/gpu/drm/i810/i810_drv.h
30713 +++ b/drivers/gpu/drm/i810/i810_drv.h
30714 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
30715 int page_flipping;
30716
30717 wait_queue_head_t irq_queue;
30718 - atomic_t irq_received;
30719 - atomic_t irq_emitted;
30720 + atomic_unchecked_t irq_received;
30721 + atomic_unchecked_t irq_emitted;
30722
30723 int front_offset;
30724 } drm_i810_private_t;
30725 diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
30726 index 359f6e8..ada68fd 100644
30727 --- a/drivers/gpu/drm/i915/i915_debugfs.c
30728 +++ b/drivers/gpu/drm/i915/i915_debugfs.c
30729 @@ -518,7 +518,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
30730 I915_READ(GTIMR));
30731 }
30732 seq_printf(m, "Interrupts received: %d\n",
30733 - atomic_read(&dev_priv->irq_received));
30734 + atomic_read_unchecked(&dev_priv->irq_received));
30735 for (i = 0; i < I915_NUM_RINGS; i++) {
30736 if (IS_GEN6(dev) || IS_GEN7(dev)) {
30737 seq_printf(m, "Graphics Interrupt mask (%s): %08x\n",
30738 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
30739 index 0969a7c..b9ffa45 100644
30740 --- a/drivers/gpu/drm/i915/i915_dma.c
30741 +++ b/drivers/gpu/drm/i915/i915_dma.c
30742 @@ -1269,7 +1269,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
30743 bool can_switch;
30744
30745 spin_lock(&dev->count_lock);
30746 - can_switch = (dev->open_count == 0);
30747 + can_switch = (local_read(&dev->open_count) == 0);
30748 spin_unlock(&dev->count_lock);
30749 return can_switch;
30750 }
30751 diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
30752 index 627fe35..c9a7346 100644
30753 --- a/drivers/gpu/drm/i915/i915_drv.h
30754 +++ b/drivers/gpu/drm/i915/i915_drv.h
30755 @@ -272,12 +272,12 @@ struct drm_i915_display_funcs {
30756 /* render clock increase/decrease */
30757 /* display clock increase/decrease */
30758 /* pll clock increase/decrease */
30759 -};
30760 +} __no_const;
30761
30762 struct drm_i915_gt_funcs {
30763 void (*force_wake_get)(struct drm_i915_private *dev_priv);
30764 void (*force_wake_put)(struct drm_i915_private *dev_priv);
30765 -};
30766 +} __no_const;
30767
30768 struct intel_device_info {
30769 u8 gen;
30770 @@ -408,7 +408,7 @@ typedef struct drm_i915_private {
30771 int current_page;
30772 int page_flipping;
30773
30774 - atomic_t irq_received;
30775 + atomic_unchecked_t irq_received;
30776
30777 /* protects the irq masks */
30778 spinlock_t irq_lock;
30779 @@ -1014,7 +1014,7 @@ struct drm_i915_gem_object {
30780 * will be page flipped away on the next vblank. When it
30781 * reaches 0, dev_priv->pending_flip_queue will be woken up.
30782 */
30783 - atomic_t pending_flip;
30784 + atomic_unchecked_t pending_flip;
30785 };
30786
30787 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
30788 @@ -1482,7 +1482,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
30789 struct drm_i915_private *dev_priv, unsigned port);
30790 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
30791 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
30792 -extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30793 +static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30794 {
30795 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
30796 }
30797 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30798 index cdf46b5..e785624 100644
30799 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30800 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30801 @@ -189,7 +189,7 @@ i915_gem_object_set_to_gpu_domain(struct drm_i915_gem_object *obj,
30802 i915_gem_clflush_object(obj);
30803
30804 if (obj->base.pending_write_domain)
30805 - cd->flips |= atomic_read(&obj->pending_flip);
30806 + cd->flips |= atomic_read_unchecked(&obj->pending_flip);
30807
30808 /* The actual obj->write_domain will be updated with
30809 * pending_write_domain after we emit the accumulated flush for all
30810 @@ -907,9 +907,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
30811
30812 static int
30813 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
30814 - int count)
30815 + unsigned int count)
30816 {
30817 - int i;
30818 + unsigned int i;
30819
30820 for (i = 0; i < count; i++) {
30821 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
30822 diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
30823 index 73fa3e1..ab2e9b9 100644
30824 --- a/drivers/gpu/drm/i915/i915_irq.c
30825 +++ b/drivers/gpu/drm/i915/i915_irq.c
30826 @@ -514,7 +514,7 @@ static irqreturn_t valleyview_irq_handler(DRM_IRQ_ARGS)
30827 u32 pipe_stats[I915_MAX_PIPES];
30828 bool blc_event;
30829
30830 - atomic_inc(&dev_priv->irq_received);
30831 + atomic_inc_unchecked(&dev_priv->irq_received);
30832
30833 while (true) {
30834 iir = I915_READ(VLV_IIR);
30835 @@ -661,7 +661,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
30836 irqreturn_t ret = IRQ_NONE;
30837 int i;
30838
30839 - atomic_inc(&dev_priv->irq_received);
30840 + atomic_inc_unchecked(&dev_priv->irq_received);
30841
30842 /* disable master interrupt before clearing iir */
30843 de_ier = I915_READ(DEIER);
30844 @@ -736,7 +736,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
30845 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
30846 u32 hotplug_mask;
30847
30848 - atomic_inc(&dev_priv->irq_received);
30849 + atomic_inc_unchecked(&dev_priv->irq_received);
30850
30851 /* disable master interrupt before clearing iir */
30852 de_ier = I915_READ(DEIER);
30853 @@ -1717,7 +1717,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
30854 {
30855 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30856
30857 - atomic_set(&dev_priv->irq_received, 0);
30858 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30859
30860 I915_WRITE(HWSTAM, 0xeffe);
30861
30862 @@ -1743,7 +1743,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
30863 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30864 int pipe;
30865
30866 - atomic_set(&dev_priv->irq_received, 0);
30867 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30868
30869 /* VLV magic */
30870 I915_WRITE(VLV_IMR, 0);
30871 @@ -2048,7 +2048,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
30872 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30873 int pipe;
30874
30875 - atomic_set(&dev_priv->irq_received, 0);
30876 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30877
30878 for_each_pipe(pipe)
30879 I915_WRITE(PIPESTAT(pipe), 0);
30880 @@ -2099,7 +2099,7 @@ static irqreturn_t i8xx_irq_handler(DRM_IRQ_ARGS)
30881 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
30882 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
30883
30884 - atomic_inc(&dev_priv->irq_received);
30885 + atomic_inc_unchecked(&dev_priv->irq_received);
30886
30887 iir = I915_READ16(IIR);
30888 if (iir == 0)
30889 @@ -2184,7 +2184,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
30890 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30891 int pipe;
30892
30893 - atomic_set(&dev_priv->irq_received, 0);
30894 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30895
30896 if (I915_HAS_HOTPLUG(dev)) {
30897 I915_WRITE(PORT_HOTPLUG_EN, 0);
30898 @@ -2279,7 +2279,7 @@ static irqreturn_t i915_irq_handler(DRM_IRQ_ARGS)
30899 };
30900 int pipe, ret = IRQ_NONE;
30901
30902 - atomic_inc(&dev_priv->irq_received);
30903 + atomic_inc_unchecked(&dev_priv->irq_received);
30904
30905 iir = I915_READ(IIR);
30906 do {
30907 @@ -2405,7 +2405,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
30908 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30909 int pipe;
30910
30911 - atomic_set(&dev_priv->irq_received, 0);
30912 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30913
30914 I915_WRITE(PORT_HOTPLUG_EN, 0);
30915 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
30916 @@ -2512,7 +2512,7 @@ static irqreturn_t i965_irq_handler(DRM_IRQ_ARGS)
30917 int irq_received;
30918 int ret = IRQ_NONE, pipe;
30919
30920 - atomic_inc(&dev_priv->irq_received);
30921 + atomic_inc_unchecked(&dev_priv->irq_received);
30922
30923 iir = I915_READ(IIR);
30924
30925 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
30926 index b634f6f..43c62f5 100644
30927 --- a/drivers/gpu/drm/i915/intel_display.c
30928 +++ b/drivers/gpu/drm/i915/intel_display.c
30929 @@ -2182,7 +2182,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
30930
30931 wait_event(dev_priv->pending_flip_queue,
30932 atomic_read(&dev_priv->mm.wedged) ||
30933 - atomic_read(&obj->pending_flip) == 0);
30934 + atomic_read_unchecked(&obj->pending_flip) == 0);
30935
30936 /* Big Hammer, we also need to ensure that any pending
30937 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
30938 @@ -6168,8 +6168,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
30939
30940 obj = work->old_fb_obj;
30941
30942 - atomic_clear_mask(1 << intel_crtc->plane,
30943 - &obj->pending_flip.counter);
30944 + atomic_clear_mask_unchecked(1 << intel_crtc->plane, &obj->pending_flip);
30945
30946 wake_up(&dev_priv->pending_flip_queue);
30947 schedule_work(&work->work);
30948 @@ -6515,7 +6514,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30949 /* Block clients from rendering to the new back buffer until
30950 * the flip occurs and the object is no longer visible.
30951 */
30952 - atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30953 + atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30954
30955 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
30956 if (ret)
30957 @@ -6530,7 +6529,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30958 return 0;
30959
30960 cleanup_pending:
30961 - atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30962 + atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30963 drm_gem_object_unreference(&work->old_fb_obj->base);
30964 drm_gem_object_unreference(&obj->base);
30965 mutex_unlock(&dev->struct_mutex);
30966 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
30967 index 54558a0..2d97005 100644
30968 --- a/drivers/gpu/drm/mga/mga_drv.h
30969 +++ b/drivers/gpu/drm/mga/mga_drv.h
30970 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
30971 u32 clear_cmd;
30972 u32 maccess;
30973
30974 - atomic_t vbl_received; /**< Number of vblanks received. */
30975 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
30976 wait_queue_head_t fence_queue;
30977 - atomic_t last_fence_retired;
30978 + atomic_unchecked_t last_fence_retired;
30979 u32 next_fence_to_post;
30980
30981 unsigned int fb_cpp;
30982 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
30983 index 2581202..f230a8d9 100644
30984 --- a/drivers/gpu/drm/mga/mga_irq.c
30985 +++ b/drivers/gpu/drm/mga/mga_irq.c
30986 @@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
30987 if (crtc != 0)
30988 return 0;
30989
30990 - return atomic_read(&dev_priv->vbl_received);
30991 + return atomic_read_unchecked(&dev_priv->vbl_received);
30992 }
30993
30994
30995 @@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30996 /* VBLANK interrupt */
30997 if (status & MGA_VLINEPEN) {
30998 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
30999 - atomic_inc(&dev_priv->vbl_received);
31000 + atomic_inc_unchecked(&dev_priv->vbl_received);
31001 drm_handle_vblank(dev, 0);
31002 handled = 1;
31003 }
31004 @@ -79,7 +79,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
31005 if ((prim_start & ~0x03) != (prim_end & ~0x03))
31006 MGA_WRITE(MGA_PRIMEND, prim_end);
31007
31008 - atomic_inc(&dev_priv->last_fence_retired);
31009 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
31010 DRM_WAKEUP(&dev_priv->fence_queue);
31011 handled = 1;
31012 }
31013 @@ -130,7 +130,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
31014 * using fences.
31015 */
31016 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
31017 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
31018 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
31019 - *sequence) <= (1 << 23)));
31020
31021 *sequence = cur_fence;
31022 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
31023 index a0a3fe3..209bf10 100644
31024 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
31025 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
31026 @@ -5340,7 +5340,7 @@ parse_bit_U_tbl_entry(struct drm_device *dev, struct nvbios *bios,
31027 struct bit_table {
31028 const char id;
31029 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
31030 -};
31031 +} __no_const;
31032
31033 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
31034
31035 diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h
31036 index 4f2cc95..9c6c510 100644
31037 --- a/drivers/gpu/drm/nouveau/nouveau_drv.h
31038 +++ b/drivers/gpu/drm/nouveau/nouveau_drv.h
31039 @@ -302,7 +302,7 @@ struct nouveau_exec_engine {
31040 u32 handle, u16 class);
31041 void (*set_tile_region)(struct drm_device *dev, int i);
31042 void (*tlb_flush)(struct drm_device *, int engine);
31043 -};
31044 +} __no_const;
31045
31046 struct nouveau_instmem_engine {
31047 void *priv;
31048 @@ -324,13 +324,13 @@ struct nouveau_instmem_engine {
31049 struct nouveau_mc_engine {
31050 int (*init)(struct drm_device *dev);
31051 void (*takedown)(struct drm_device *dev);
31052 -};
31053 +} __no_const;
31054
31055 struct nouveau_timer_engine {
31056 int (*init)(struct drm_device *dev);
31057 void (*takedown)(struct drm_device *dev);
31058 uint64_t (*read)(struct drm_device *dev);
31059 -};
31060 +} __no_const;
31061
31062 struct nouveau_fb_engine {
31063 int num_tiles;
31064 @@ -547,7 +547,7 @@ struct nouveau_vram_engine {
31065 void (*put)(struct drm_device *, struct nouveau_mem **);
31066
31067 bool (*flags_valid)(struct drm_device *, u32 tile_flags);
31068 -};
31069 +} __no_const;
31070
31071 struct nouveau_engine {
31072 struct nouveau_instmem_engine instmem;
31073 @@ -693,7 +693,7 @@ struct drm_nouveau_private {
31074 struct drm_global_reference mem_global_ref;
31075 struct ttm_bo_global_ref bo_global_ref;
31076 struct ttm_bo_device bdev;
31077 - atomic_t validate_sequence;
31078 + atomic_unchecked_t validate_sequence;
31079 int (*move)(struct nouveau_channel *,
31080 struct ttm_buffer_object *,
31081 struct ttm_mem_reg *, struct ttm_mem_reg *);
31082 diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
31083 index af7cfb8..aadc2a3 100644
31084 --- a/drivers/gpu/drm/nouveau/nouveau_gem.c
31085 +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
31086 @@ -318,7 +318,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
31087 int trycnt = 0;
31088 int ret, i;
31089
31090 - sequence = atomic_add_return(1, &dev_priv->ttm.validate_sequence);
31091 + sequence = atomic_add_return_unchecked(1, &dev_priv->ttm.validate_sequence);
31092 retry:
31093 if (++trycnt > 100000) {
31094 NV_ERROR(dev, "%s failed and gave up.\n", __func__);
31095 diff --git a/drivers/gpu/drm/nouveau/nouveau_state.c b/drivers/gpu/drm/nouveau/nouveau_state.c
31096 index f5e9584..05934ba 100644
31097 --- a/drivers/gpu/drm/nouveau/nouveau_state.c
31098 +++ b/drivers/gpu/drm/nouveau/nouveau_state.c
31099 @@ -492,7 +492,7 @@ static bool nouveau_switcheroo_can_switch(struct pci_dev *pdev)
31100 bool can_switch;
31101
31102 spin_lock(&dev->count_lock);
31103 - can_switch = (dev->open_count == 0);
31104 + can_switch = (local_read(&dev->open_count) == 0);
31105 spin_unlock(&dev->count_lock);
31106 return can_switch;
31107 }
31108 diff --git a/drivers/gpu/drm/nouveau/nv50_sor.c b/drivers/gpu/drm/nouveau/nv50_sor.c
31109 index 93240bd..c490f60 100644
31110 --- a/drivers/gpu/drm/nouveau/nv50_sor.c
31111 +++ b/drivers/gpu/drm/nouveau/nv50_sor.c
31112 @@ -304,7 +304,7 @@ nv50_sor_dpms(struct drm_encoder *encoder, int mode)
31113 }
31114
31115 if (nv_encoder->dcb->type == OUTPUT_DP) {
31116 - struct dp_train_func func = {
31117 + static struct dp_train_func func = {
31118 .link_set = nv50_sor_dp_link_set,
31119 .train_set = nv50_sor_dp_train_set,
31120 .train_adj = nv50_sor_dp_train_adj
31121 diff --git a/drivers/gpu/drm/nouveau/nvd0_display.c b/drivers/gpu/drm/nouveau/nvd0_display.c
31122 index 8a2fc89..3a5cf40 100644
31123 --- a/drivers/gpu/drm/nouveau/nvd0_display.c
31124 +++ b/drivers/gpu/drm/nouveau/nvd0_display.c
31125 @@ -1367,7 +1367,7 @@ nvd0_sor_dpms(struct drm_encoder *encoder, int mode)
31126 nv_wait(dev, 0x61c030 + (or * 0x0800), 0x10000000, 0x00000000);
31127
31128 if (nv_encoder->dcb->type == OUTPUT_DP) {
31129 - struct dp_train_func func = {
31130 + static struct dp_train_func func = {
31131 .link_set = nvd0_sor_dp_link_set,
31132 .train_set = nvd0_sor_dp_train_set,
31133 .train_adj = nvd0_sor_dp_train_adj
31134 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
31135 index bcac90b..53bfc76 100644
31136 --- a/drivers/gpu/drm/r128/r128_cce.c
31137 +++ b/drivers/gpu/drm/r128/r128_cce.c
31138 @@ -378,7 +378,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
31139
31140 /* GH: Simple idle check.
31141 */
31142 - atomic_set(&dev_priv->idle_count, 0);
31143 + atomic_set_unchecked(&dev_priv->idle_count, 0);
31144
31145 /* We don't support anything other than bus-mastering ring mode,
31146 * but the ring can be in either AGP or PCI space for the ring
31147 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
31148 index 930c71b..499aded 100644
31149 --- a/drivers/gpu/drm/r128/r128_drv.h
31150 +++ b/drivers/gpu/drm/r128/r128_drv.h
31151 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
31152 int is_pci;
31153 unsigned long cce_buffers_offset;
31154
31155 - atomic_t idle_count;
31156 + atomic_unchecked_t idle_count;
31157
31158 int page_flipping;
31159 int current_page;
31160 u32 crtc_offset;
31161 u32 crtc_offset_cntl;
31162
31163 - atomic_t vbl_received;
31164 + atomic_unchecked_t vbl_received;
31165
31166 u32 color_fmt;
31167 unsigned int front_offset;
31168 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
31169 index 429d5a0..7e899ed 100644
31170 --- a/drivers/gpu/drm/r128/r128_irq.c
31171 +++ b/drivers/gpu/drm/r128/r128_irq.c
31172 @@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
31173 if (crtc != 0)
31174 return 0;
31175
31176 - return atomic_read(&dev_priv->vbl_received);
31177 + return atomic_read_unchecked(&dev_priv->vbl_received);
31178 }
31179
31180 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
31181 @@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
31182 /* VBLANK interrupt */
31183 if (status & R128_CRTC_VBLANK_INT) {
31184 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
31185 - atomic_inc(&dev_priv->vbl_received);
31186 + atomic_inc_unchecked(&dev_priv->vbl_received);
31187 drm_handle_vblank(dev, 0);
31188 return IRQ_HANDLED;
31189 }
31190 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
31191 index a9e33ce..09edd4b 100644
31192 --- a/drivers/gpu/drm/r128/r128_state.c
31193 +++ b/drivers/gpu/drm/r128/r128_state.c
31194 @@ -321,10 +321,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
31195
31196 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
31197 {
31198 - if (atomic_read(&dev_priv->idle_count) == 0)
31199 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
31200 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
31201 else
31202 - atomic_set(&dev_priv->idle_count, 0);
31203 + atomic_set_unchecked(&dev_priv->idle_count, 0);
31204 }
31205
31206 #endif
31207 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
31208 index 5a82b6b..9e69c73 100644
31209 --- a/drivers/gpu/drm/radeon/mkregtable.c
31210 +++ b/drivers/gpu/drm/radeon/mkregtable.c
31211 @@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
31212 regex_t mask_rex;
31213 regmatch_t match[4];
31214 char buf[1024];
31215 - size_t end;
31216 + long end;
31217 int len;
31218 int done = 0;
31219 int r;
31220 unsigned o;
31221 struct offset *offset;
31222 char last_reg_s[10];
31223 - int last_reg;
31224 + unsigned long last_reg;
31225
31226 if (regcomp
31227 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
31228 diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
31229 index 59a1531..3bab49b 100644
31230 --- a/drivers/gpu/drm/radeon/radeon.h
31231 +++ b/drivers/gpu/drm/radeon/radeon.h
31232 @@ -711,7 +711,7 @@ struct r600_blit_cp_primitives {
31233 int x2, int y2);
31234 void (*draw_auto)(struct radeon_device *rdev);
31235 void (*set_default_state)(struct radeon_device *rdev);
31236 -};
31237 +} __no_const;
31238
31239 struct r600_blit {
31240 struct radeon_bo *shader_obj;
31241 @@ -1216,7 +1216,7 @@ struct radeon_asic {
31242 u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
31243 void (*post_page_flip)(struct radeon_device *rdev, int crtc);
31244 } pflip;
31245 -};
31246 +} __no_const;
31247
31248 /*
31249 * Asic structures
31250 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
31251 index 7a3daeb..5016171 100644
31252 --- a/drivers/gpu/drm/radeon/radeon_device.c
31253 +++ b/drivers/gpu/drm/radeon/radeon_device.c
31254 @@ -952,7 +952,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
31255 bool can_switch;
31256
31257 spin_lock(&dev->count_lock);
31258 - can_switch = (dev->open_count == 0);
31259 + can_switch = (local_read(&dev->open_count) == 0);
31260 spin_unlock(&dev->count_lock);
31261 return can_switch;
31262 }
31263 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
31264 index a1b59ca..86f2d44 100644
31265 --- a/drivers/gpu/drm/radeon/radeon_drv.h
31266 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
31267 @@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
31268
31269 /* SW interrupt */
31270 wait_queue_head_t swi_queue;
31271 - atomic_t swi_emitted;
31272 + atomic_unchecked_t swi_emitted;
31273 int vblank_crtc;
31274 uint32_t irq_enable_reg;
31275 uint32_t r500_disp_irq_reg;
31276 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
31277 index 48b7cea..342236f 100644
31278 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
31279 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
31280 @@ -359,7 +359,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
31281 request = compat_alloc_user_space(sizeof(*request));
31282 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
31283 || __put_user(req32.param, &request->param)
31284 - || __put_user((void __user *)(unsigned long)req32.value,
31285 + || __put_user((unsigned long)req32.value,
31286 &request->value))
31287 return -EFAULT;
31288
31289 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
31290 index 00da384..32f972d 100644
31291 --- a/drivers/gpu/drm/radeon/radeon_irq.c
31292 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
31293 @@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_device * dev)
31294 unsigned int ret;
31295 RING_LOCALS;
31296
31297 - atomic_inc(&dev_priv->swi_emitted);
31298 - ret = atomic_read(&dev_priv->swi_emitted);
31299 + atomic_inc_unchecked(&dev_priv->swi_emitted);
31300 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
31301
31302 BEGIN_RING(4);
31303 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
31304 @@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
31305 drm_radeon_private_t *dev_priv =
31306 (drm_radeon_private_t *) dev->dev_private;
31307
31308 - atomic_set(&dev_priv->swi_emitted, 0);
31309 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
31310 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
31311
31312 dev->max_vblank_count = 0x001fffff;
31313 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
31314 index e8422ae..d22d4a8 100644
31315 --- a/drivers/gpu/drm/radeon/radeon_state.c
31316 +++ b/drivers/gpu/drm/radeon/radeon_state.c
31317 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
31318 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
31319 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
31320
31321 - if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
31322 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
31323 sarea_priv->nbox * sizeof(depth_boxes[0])))
31324 return -EFAULT;
31325
31326 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
31327 {
31328 drm_radeon_private_t *dev_priv = dev->dev_private;
31329 drm_radeon_getparam_t *param = data;
31330 - int value;
31331 + int value = 0;
31332
31333 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
31334
31335 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
31336 index 5b71c71..650f9e4 100644
31337 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
31338 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
31339 @@ -822,8 +822,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
31340 }
31341 if (unlikely(ttm_vm_ops == NULL)) {
31342 ttm_vm_ops = vma->vm_ops;
31343 - radeon_ttm_vm_ops = *ttm_vm_ops;
31344 - radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
31345 + pax_open_kernel();
31346 + memcpy((void *)&radeon_ttm_vm_ops, ttm_vm_ops, sizeof(radeon_ttm_vm_ops));
31347 + *(void **)&radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
31348 + pax_close_kernel();
31349 }
31350 vma->vm_ops = &radeon_ttm_vm_ops;
31351 return 0;
31352 diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
31353 index 3b663fc..57850f4 100644
31354 --- a/drivers/gpu/drm/radeon/rs690.c
31355 +++ b/drivers/gpu/drm/radeon/rs690.c
31356 @@ -304,9 +304,11 @@ void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
31357 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
31358 rdev->pm.sideport_bandwidth.full)
31359 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
31360 - read_delay_latency.full = dfixed_const(370 * 800 * 1000);
31361 + read_delay_latency.full = dfixed_const(800 * 1000);
31362 read_delay_latency.full = dfixed_div(read_delay_latency,
31363 rdev->pm.igp_sideport_mclk);
31364 + a.full = dfixed_const(370);
31365 + read_delay_latency.full = dfixed_mul(read_delay_latency, a);
31366 } else {
31367 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
31368 rdev->pm.k8_bandwidth.full)
31369 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31370 index ebc6fac..a8313ed 100644
31371 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
31372 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31373 @@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
31374 static int ttm_pool_mm_shrink(struct shrinker *shrink,
31375 struct shrink_control *sc)
31376 {
31377 - static atomic_t start_pool = ATOMIC_INIT(0);
31378 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
31379 unsigned i;
31380 - unsigned pool_offset = atomic_add_return(1, &start_pool);
31381 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
31382 struct ttm_page_pool *pool;
31383 int shrink_pages = sc->nr_to_scan;
31384
31385 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
31386 index 88edacc..1e5412b 100644
31387 --- a/drivers/gpu/drm/via/via_drv.h
31388 +++ b/drivers/gpu/drm/via/via_drv.h
31389 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
31390 typedef uint32_t maskarray_t[5];
31391
31392 typedef struct drm_via_irq {
31393 - atomic_t irq_received;
31394 + atomic_unchecked_t irq_received;
31395 uint32_t pending_mask;
31396 uint32_t enable_mask;
31397 wait_queue_head_t irq_queue;
31398 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
31399 struct timeval last_vblank;
31400 int last_vblank_valid;
31401 unsigned usec_per_vblank;
31402 - atomic_t vbl_received;
31403 + atomic_unchecked_t vbl_received;
31404 drm_via_state_t hc_state;
31405 char pci_buf[VIA_PCI_BUF_SIZE];
31406 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
31407 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
31408 index d391f48..10c8ca3 100644
31409 --- a/drivers/gpu/drm/via/via_irq.c
31410 +++ b/drivers/gpu/drm/via/via_irq.c
31411 @@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
31412 if (crtc != 0)
31413 return 0;
31414
31415 - return atomic_read(&dev_priv->vbl_received);
31416 + return atomic_read_unchecked(&dev_priv->vbl_received);
31417 }
31418
31419 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31420 @@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31421
31422 status = VIA_READ(VIA_REG_INTERRUPT);
31423 if (status & VIA_IRQ_VBLANK_PENDING) {
31424 - atomic_inc(&dev_priv->vbl_received);
31425 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
31426 + atomic_inc_unchecked(&dev_priv->vbl_received);
31427 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
31428 do_gettimeofday(&cur_vblank);
31429 if (dev_priv->last_vblank_valid) {
31430 dev_priv->usec_per_vblank =
31431 @@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31432 dev_priv->last_vblank = cur_vblank;
31433 dev_priv->last_vblank_valid = 1;
31434 }
31435 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
31436 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
31437 DRM_DEBUG("US per vblank is: %u\n",
31438 dev_priv->usec_per_vblank);
31439 }
31440 @@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31441
31442 for (i = 0; i < dev_priv->num_irqs; ++i) {
31443 if (status & cur_irq->pending_mask) {
31444 - atomic_inc(&cur_irq->irq_received);
31445 + atomic_inc_unchecked(&cur_irq->irq_received);
31446 DRM_WAKEUP(&cur_irq->irq_queue);
31447 handled = 1;
31448 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
31449 @@ -243,11 +243,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
31450 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31451 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
31452 masks[irq][4]));
31453 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
31454 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
31455 } else {
31456 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31457 (((cur_irq_sequence =
31458 - atomic_read(&cur_irq->irq_received)) -
31459 + atomic_read_unchecked(&cur_irq->irq_received)) -
31460 *sequence) <= (1 << 23)));
31461 }
31462 *sequence = cur_irq_sequence;
31463 @@ -285,7 +285,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
31464 }
31465
31466 for (i = 0; i < dev_priv->num_irqs; ++i) {
31467 - atomic_set(&cur_irq->irq_received, 0);
31468 + atomic_set_unchecked(&cur_irq->irq_received, 0);
31469 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
31470 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
31471 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
31472 @@ -367,7 +367,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
31473 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
31474 case VIA_IRQ_RELATIVE:
31475 irqwait->request.sequence +=
31476 - atomic_read(&cur_irq->irq_received);
31477 + atomic_read_unchecked(&cur_irq->irq_received);
31478 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
31479 case VIA_IRQ_ABSOLUTE:
31480 break;
31481 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31482 index 29c984f..4084f1a 100644
31483 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31484 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31485 @@ -263,7 +263,7 @@ struct vmw_private {
31486 * Fencing and IRQs.
31487 */
31488
31489 - atomic_t marker_seq;
31490 + atomic_unchecked_t marker_seq;
31491 wait_queue_head_t fence_queue;
31492 wait_queue_head_t fifo_queue;
31493 int fence_queue_waiters; /* Protected by hw_mutex */
31494 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31495 index a0c2f12..68ae6cb 100644
31496 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31497 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31498 @@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
31499 (unsigned int) min,
31500 (unsigned int) fifo->capabilities);
31501
31502 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31503 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31504 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
31505 vmw_marker_queue_init(&fifo->marker_queue);
31506 return vmw_fifo_send_fence(dev_priv, &dummy);
31507 @@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
31508 if (reserveable)
31509 iowrite32(bytes, fifo_mem +
31510 SVGA_FIFO_RESERVED);
31511 - return fifo_mem + (next_cmd >> 2);
31512 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
31513 } else {
31514 need_bounce = true;
31515 }
31516 @@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31517
31518 fm = vmw_fifo_reserve(dev_priv, bytes);
31519 if (unlikely(fm == NULL)) {
31520 - *seqno = atomic_read(&dev_priv->marker_seq);
31521 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31522 ret = -ENOMEM;
31523 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
31524 false, 3*HZ);
31525 @@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31526 }
31527
31528 do {
31529 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
31530 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
31531 } while (*seqno == 0);
31532
31533 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
31534 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31535 index cabc95f..14b3d77 100644
31536 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31537 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31538 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
31539 * emitted. Then the fence is stale and signaled.
31540 */
31541
31542 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
31543 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
31544 > VMW_FENCE_WRAP);
31545
31546 return ret;
31547 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
31548
31549 if (fifo_idle)
31550 down_read(&fifo_state->rwsem);
31551 - signal_seq = atomic_read(&dev_priv->marker_seq);
31552 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
31553 ret = 0;
31554
31555 for (;;) {
31556 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31557 index 8a8725c..afed796 100644
31558 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31559 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31560 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
31561 while (!vmw_lag_lt(queue, us)) {
31562 spin_lock(&queue->lock);
31563 if (list_empty(&queue->head))
31564 - seqno = atomic_read(&dev_priv->marker_seq);
31565 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31566 else {
31567 marker = list_first_entry(&queue->head,
31568 struct vmw_marker, head);
31569 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
31570 index 5de3bb3..08e5063 100644
31571 --- a/drivers/hid/hid-core.c
31572 +++ b/drivers/hid/hid-core.c
31573 @@ -2177,7 +2177,7 @@ static bool hid_ignore(struct hid_device *hdev)
31574
31575 int hid_add_device(struct hid_device *hdev)
31576 {
31577 - static atomic_t id = ATOMIC_INIT(0);
31578 + static atomic_unchecked_t id = ATOMIC_INIT(0);
31579 int ret;
31580
31581 if (WARN_ON(hdev->status & HID_STAT_ADDED))
31582 @@ -2212,7 +2212,7 @@ int hid_add_device(struct hid_device *hdev)
31583 /* XXX hack, any other cleaner solution after the driver core
31584 * is converted to allow more than 20 bytes as the device name? */
31585 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
31586 - hdev->vendor, hdev->product, atomic_inc_return(&id));
31587 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
31588
31589 hid_debug_register(hdev, dev_name(&hdev->dev));
31590 ret = device_add(&hdev->dev);
31591 diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
31592 index eec3291..8ed706b 100644
31593 --- a/drivers/hid/hid-wiimote-debug.c
31594 +++ b/drivers/hid/hid-wiimote-debug.c
31595 @@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
31596 else if (size == 0)
31597 return -EIO;
31598
31599 - if (copy_to_user(u, buf, size))
31600 + if (size > sizeof(buf) || copy_to_user(u, buf, size))
31601 return -EFAULT;
31602
31603 *off += size;
31604 diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
31605 index 14599e2..711c965 100644
31606 --- a/drivers/hid/usbhid/hiddev.c
31607 +++ b/drivers/hid/usbhid/hiddev.c
31608 @@ -625,7 +625,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
31609 break;
31610
31611 case HIDIOCAPPLICATION:
31612 - if (arg < 0 || arg >= hid->maxapplication)
31613 + if (arg >= hid->maxapplication)
31614 break;
31615
31616 for (i = 0; i < hid->maxcollection; i++)
31617 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
31618 index f4c3d28..82f45a9 100644
31619 --- a/drivers/hv/channel.c
31620 +++ b/drivers/hv/channel.c
31621 @@ -402,8 +402,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
31622 int ret = 0;
31623 int t;
31624
31625 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
31626 - atomic_inc(&vmbus_connection.next_gpadl_handle);
31627 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
31628 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
31629
31630 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
31631 if (ret)
31632 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
31633 index 86f8885..ab9cb2b 100644
31634 --- a/drivers/hv/hv.c
31635 +++ b/drivers/hv/hv.c
31636 @@ -132,7 +132,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
31637 u64 output_address = (output) ? virt_to_phys(output) : 0;
31638 u32 output_address_hi = output_address >> 32;
31639 u32 output_address_lo = output_address & 0xFFFFFFFF;
31640 - void *hypercall_page = hv_context.hypercall_page;
31641 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
31642
31643 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
31644 "=a"(hv_status_lo) : "d" (control_hi),
31645 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
31646 index 0614ff3..f0b2b5c 100644
31647 --- a/drivers/hv/hyperv_vmbus.h
31648 +++ b/drivers/hv/hyperv_vmbus.h
31649 @@ -555,7 +555,7 @@ enum vmbus_connect_state {
31650 struct vmbus_connection {
31651 enum vmbus_connect_state conn_state;
31652
31653 - atomic_t next_gpadl_handle;
31654 + atomic_unchecked_t next_gpadl_handle;
31655
31656 /*
31657 * Represents channel interrupts. Each bit position represents a
31658 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
31659 index 4748086..3abf845 100644
31660 --- a/drivers/hv/vmbus_drv.c
31661 +++ b/drivers/hv/vmbus_drv.c
31662 @@ -662,10 +662,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
31663 {
31664 int ret = 0;
31665
31666 - static atomic_t device_num = ATOMIC_INIT(0);
31667 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
31668
31669 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
31670 - atomic_inc_return(&device_num));
31671 + atomic_inc_return_unchecked(&device_num));
31672
31673 child_device_obj->device.bus = &hv_bus;
31674 child_device_obj->device.parent = &hv_acpi_dev->dev;
31675 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
31676 index 8b011d0..3de24a1 100644
31677 --- a/drivers/hwmon/sht15.c
31678 +++ b/drivers/hwmon/sht15.c
31679 @@ -166,7 +166,7 @@ struct sht15_data {
31680 int supply_uV;
31681 bool supply_uV_valid;
31682 struct work_struct update_supply_work;
31683 - atomic_t interrupt_handled;
31684 + atomic_unchecked_t interrupt_handled;
31685 };
31686
31687 /**
31688 @@ -509,13 +509,13 @@ static int sht15_measurement(struct sht15_data *data,
31689 return ret;
31690
31691 gpio_direction_input(data->pdata->gpio_data);
31692 - atomic_set(&data->interrupt_handled, 0);
31693 + atomic_set_unchecked(&data->interrupt_handled, 0);
31694
31695 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31696 if (gpio_get_value(data->pdata->gpio_data) == 0) {
31697 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
31698 /* Only relevant if the interrupt hasn't occurred. */
31699 - if (!atomic_read(&data->interrupt_handled))
31700 + if (!atomic_read_unchecked(&data->interrupt_handled))
31701 schedule_work(&data->read_work);
31702 }
31703 ret = wait_event_timeout(data->wait_queue,
31704 @@ -782,7 +782,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
31705
31706 /* First disable the interrupt */
31707 disable_irq_nosync(irq);
31708 - atomic_inc(&data->interrupt_handled);
31709 + atomic_inc_unchecked(&data->interrupt_handled);
31710 /* Then schedule a reading work struct */
31711 if (data->state != SHT15_READING_NOTHING)
31712 schedule_work(&data->read_work);
31713 @@ -804,11 +804,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
31714 * If not, then start the interrupt again - care here as could
31715 * have gone low in meantime so verify it hasn't!
31716 */
31717 - atomic_set(&data->interrupt_handled, 0);
31718 + atomic_set_unchecked(&data->interrupt_handled, 0);
31719 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31720 /* If still not occurred or another handler was scheduled */
31721 if (gpio_get_value(data->pdata->gpio_data)
31722 - || atomic_read(&data->interrupt_handled))
31723 + || atomic_read_unchecked(&data->interrupt_handled))
31724 return;
31725 }
31726
31727 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
31728 index 378fcb5..5e91fa8 100644
31729 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
31730 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
31731 @@ -43,7 +43,7 @@
31732 extern struct i2c_adapter amd756_smbus;
31733
31734 static struct i2c_adapter *s4882_adapter;
31735 -static struct i2c_algorithm *s4882_algo;
31736 +static i2c_algorithm_no_const *s4882_algo;
31737
31738 /* Wrapper access functions for multiplexed SMBus */
31739 static DEFINE_MUTEX(amd756_lock);
31740 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
31741 index 29015eb..af2d8e9 100644
31742 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
31743 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
31744 @@ -41,7 +41,7 @@
31745 extern struct i2c_adapter *nforce2_smbus;
31746
31747 static struct i2c_adapter *s4985_adapter;
31748 -static struct i2c_algorithm *s4985_algo;
31749 +static i2c_algorithm_no_const *s4985_algo;
31750
31751 /* Wrapper access functions for multiplexed SMBus */
31752 static DEFINE_MUTEX(nforce2_lock);
31753 diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
31754 index 1038c38..eb92f51 100644
31755 --- a/drivers/i2c/i2c-mux.c
31756 +++ b/drivers/i2c/i2c-mux.c
31757 @@ -30,7 +30,7 @@
31758 /* multiplexer per channel data */
31759 struct i2c_mux_priv {
31760 struct i2c_adapter adap;
31761 - struct i2c_algorithm algo;
31762 + i2c_algorithm_no_const algo;
31763
31764 struct i2c_adapter *parent;
31765 void *mux_priv; /* the mux chip/device */
31766 diff --git a/drivers/ide/aec62xx.c b/drivers/ide/aec62xx.c
31767 index 57d00ca..0145194 100644
31768 --- a/drivers/ide/aec62xx.c
31769 +++ b/drivers/ide/aec62xx.c
31770 @@ -181,7 +181,7 @@ static const struct ide_port_ops atp86x_port_ops = {
31771 .cable_detect = atp86x_cable_detect,
31772 };
31773
31774 -static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
31775 +static const struct ide_port_info aec62xx_chipsets[] __devinitconst = {
31776 { /* 0: AEC6210 */
31777 .name = DRV_NAME,
31778 .init_chipset = init_chipset_aec62xx,
31779 diff --git a/drivers/ide/alim15x3.c b/drivers/ide/alim15x3.c
31780 index 2c8016a..911a27c 100644
31781 --- a/drivers/ide/alim15x3.c
31782 +++ b/drivers/ide/alim15x3.c
31783 @@ -512,7 +512,7 @@ static const struct ide_dma_ops ali_dma_ops = {
31784 .dma_sff_read_status = ide_dma_sff_read_status,
31785 };
31786
31787 -static const struct ide_port_info ali15x3_chipset __devinitdata = {
31788 +static const struct ide_port_info ali15x3_chipset __devinitconst = {
31789 .name = DRV_NAME,
31790 .init_chipset = init_chipset_ali15x3,
31791 .init_hwif = init_hwif_ali15x3,
31792 diff --git a/drivers/ide/amd74xx.c b/drivers/ide/amd74xx.c
31793 index 3747b25..56fc995 100644
31794 --- a/drivers/ide/amd74xx.c
31795 +++ b/drivers/ide/amd74xx.c
31796 @@ -223,7 +223,7 @@ static const struct ide_port_ops amd_port_ops = {
31797 .udma_mask = udma, \
31798 }
31799
31800 -static const struct ide_port_info amd74xx_chipsets[] __devinitdata = {
31801 +static const struct ide_port_info amd74xx_chipsets[] __devinitconst = {
31802 /* 0: AMD7401 */ DECLARE_AMD_DEV(0x00, ATA_UDMA2),
31803 /* 1: AMD7409 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA4),
31804 /* 2: AMD7411/7441 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA5),
31805 diff --git a/drivers/ide/atiixp.c b/drivers/ide/atiixp.c
31806 index 15f0ead..cb43480 100644
31807 --- a/drivers/ide/atiixp.c
31808 +++ b/drivers/ide/atiixp.c
31809 @@ -139,7 +139,7 @@ static const struct ide_port_ops atiixp_port_ops = {
31810 .cable_detect = atiixp_cable_detect,
31811 };
31812
31813 -static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
31814 +static const struct ide_port_info atiixp_pci_info[] __devinitconst = {
31815 { /* 0: IXP200/300/400/700 */
31816 .name = DRV_NAME,
31817 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
31818 diff --git a/drivers/ide/cmd64x.c b/drivers/ide/cmd64x.c
31819 index 5f80312..d1fc438 100644
31820 --- a/drivers/ide/cmd64x.c
31821 +++ b/drivers/ide/cmd64x.c
31822 @@ -327,7 +327,7 @@ static const struct ide_dma_ops cmd646_rev1_dma_ops = {
31823 .dma_sff_read_status = ide_dma_sff_read_status,
31824 };
31825
31826 -static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
31827 +static const struct ide_port_info cmd64x_chipsets[] __devinitconst = {
31828 { /* 0: CMD643 */
31829 .name = DRV_NAME,
31830 .init_chipset = init_chipset_cmd64x,
31831 diff --git a/drivers/ide/cs5520.c b/drivers/ide/cs5520.c
31832 index 2c1e5f7..1444762 100644
31833 --- a/drivers/ide/cs5520.c
31834 +++ b/drivers/ide/cs5520.c
31835 @@ -94,7 +94,7 @@ static const struct ide_port_ops cs5520_port_ops = {
31836 .set_dma_mode = cs5520_set_dma_mode,
31837 };
31838
31839 -static const struct ide_port_info cyrix_chipset __devinitdata = {
31840 +static const struct ide_port_info cyrix_chipset __devinitconst = {
31841 .name = DRV_NAME,
31842 .enablebits = { { 0x60, 0x01, 0x01 }, { 0x60, 0x02, 0x02 } },
31843 .port_ops = &cs5520_port_ops,
31844 diff --git a/drivers/ide/cs5530.c b/drivers/ide/cs5530.c
31845 index 4dc4eb9..49b40ad 100644
31846 --- a/drivers/ide/cs5530.c
31847 +++ b/drivers/ide/cs5530.c
31848 @@ -245,7 +245,7 @@ static const struct ide_port_ops cs5530_port_ops = {
31849 .udma_filter = cs5530_udma_filter,
31850 };
31851
31852 -static const struct ide_port_info cs5530_chipset __devinitdata = {
31853 +static const struct ide_port_info cs5530_chipset __devinitconst = {
31854 .name = DRV_NAME,
31855 .init_chipset = init_chipset_cs5530,
31856 .init_hwif = init_hwif_cs5530,
31857 diff --git a/drivers/ide/cs5535.c b/drivers/ide/cs5535.c
31858 index 5059faf..18d4c85 100644
31859 --- a/drivers/ide/cs5535.c
31860 +++ b/drivers/ide/cs5535.c
31861 @@ -170,7 +170,7 @@ static const struct ide_port_ops cs5535_port_ops = {
31862 .cable_detect = cs5535_cable_detect,
31863 };
31864
31865 -static const struct ide_port_info cs5535_chipset __devinitdata = {
31866 +static const struct ide_port_info cs5535_chipset __devinitconst = {
31867 .name = DRV_NAME,
31868 .port_ops = &cs5535_port_ops,
31869 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_POST_SET_MODE,
31870 diff --git a/drivers/ide/cy82c693.c b/drivers/ide/cy82c693.c
31871 index 847553f..3ffb49d 100644
31872 --- a/drivers/ide/cy82c693.c
31873 +++ b/drivers/ide/cy82c693.c
31874 @@ -163,7 +163,7 @@ static const struct ide_port_ops cy82c693_port_ops = {
31875 .set_dma_mode = cy82c693_set_dma_mode,
31876 };
31877
31878 -static const struct ide_port_info cy82c693_chipset __devinitdata = {
31879 +static const struct ide_port_info cy82c693_chipset __devinitconst = {
31880 .name = DRV_NAME,
31881 .init_iops = init_iops_cy82c693,
31882 .port_ops = &cy82c693_port_ops,
31883 diff --git a/drivers/ide/hpt366.c b/drivers/ide/hpt366.c
31884 index 58c51cd..4aec3b8 100644
31885 --- a/drivers/ide/hpt366.c
31886 +++ b/drivers/ide/hpt366.c
31887 @@ -443,7 +443,7 @@ static struct hpt_timings hpt37x_timings = {
31888 }
31889 };
31890
31891 -static const struct hpt_info hpt36x __devinitdata = {
31892 +static const struct hpt_info hpt36x __devinitconst = {
31893 .chip_name = "HPT36x",
31894 .chip_type = HPT36x,
31895 .udma_mask = HPT366_ALLOW_ATA66_3 ? (HPT366_ALLOW_ATA66_4 ? ATA_UDMA4 : ATA_UDMA3) : ATA_UDMA2,
31896 @@ -451,7 +451,7 @@ static const struct hpt_info hpt36x __devinitdata = {
31897 .timings = &hpt36x_timings
31898 };
31899
31900 -static const struct hpt_info hpt370 __devinitdata = {
31901 +static const struct hpt_info hpt370 __devinitconst = {
31902 .chip_name = "HPT370",
31903 .chip_type = HPT370,
31904 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31905 @@ -459,7 +459,7 @@ static const struct hpt_info hpt370 __devinitdata = {
31906 .timings = &hpt37x_timings
31907 };
31908
31909 -static const struct hpt_info hpt370a __devinitdata = {
31910 +static const struct hpt_info hpt370a __devinitconst = {
31911 .chip_name = "HPT370A",
31912 .chip_type = HPT370A,
31913 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31914 @@ -467,7 +467,7 @@ static const struct hpt_info hpt370a __devinitdata = {
31915 .timings = &hpt37x_timings
31916 };
31917
31918 -static const struct hpt_info hpt374 __devinitdata = {
31919 +static const struct hpt_info hpt374 __devinitconst = {
31920 .chip_name = "HPT374",
31921 .chip_type = HPT374,
31922 .udma_mask = ATA_UDMA5,
31923 @@ -475,7 +475,7 @@ static const struct hpt_info hpt374 __devinitdata = {
31924 .timings = &hpt37x_timings
31925 };
31926
31927 -static const struct hpt_info hpt372 __devinitdata = {
31928 +static const struct hpt_info hpt372 __devinitconst = {
31929 .chip_name = "HPT372",
31930 .chip_type = HPT372,
31931 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31932 @@ -483,7 +483,7 @@ static const struct hpt_info hpt372 __devinitdata = {
31933 .timings = &hpt37x_timings
31934 };
31935
31936 -static const struct hpt_info hpt372a __devinitdata = {
31937 +static const struct hpt_info hpt372a __devinitconst = {
31938 .chip_name = "HPT372A",
31939 .chip_type = HPT372A,
31940 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31941 @@ -491,7 +491,7 @@ static const struct hpt_info hpt372a __devinitdata = {
31942 .timings = &hpt37x_timings
31943 };
31944
31945 -static const struct hpt_info hpt302 __devinitdata = {
31946 +static const struct hpt_info hpt302 __devinitconst = {
31947 .chip_name = "HPT302",
31948 .chip_type = HPT302,
31949 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31950 @@ -499,7 +499,7 @@ static const struct hpt_info hpt302 __devinitdata = {
31951 .timings = &hpt37x_timings
31952 };
31953
31954 -static const struct hpt_info hpt371 __devinitdata = {
31955 +static const struct hpt_info hpt371 __devinitconst = {
31956 .chip_name = "HPT371",
31957 .chip_type = HPT371,
31958 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31959 @@ -507,7 +507,7 @@ static const struct hpt_info hpt371 __devinitdata = {
31960 .timings = &hpt37x_timings
31961 };
31962
31963 -static const struct hpt_info hpt372n __devinitdata = {
31964 +static const struct hpt_info hpt372n __devinitconst = {
31965 .chip_name = "HPT372N",
31966 .chip_type = HPT372N,
31967 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31968 @@ -515,7 +515,7 @@ static const struct hpt_info hpt372n __devinitdata = {
31969 .timings = &hpt37x_timings
31970 };
31971
31972 -static const struct hpt_info hpt302n __devinitdata = {
31973 +static const struct hpt_info hpt302n __devinitconst = {
31974 .chip_name = "HPT302N",
31975 .chip_type = HPT302N,
31976 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31977 @@ -523,7 +523,7 @@ static const struct hpt_info hpt302n __devinitdata = {
31978 .timings = &hpt37x_timings
31979 };
31980
31981 -static const struct hpt_info hpt371n __devinitdata = {
31982 +static const struct hpt_info hpt371n __devinitconst = {
31983 .chip_name = "HPT371N",
31984 .chip_type = HPT371N,
31985 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31986 @@ -1361,7 +1361,7 @@ static const struct ide_dma_ops hpt36x_dma_ops = {
31987 .dma_sff_read_status = ide_dma_sff_read_status,
31988 };
31989
31990 -static const struct ide_port_info hpt366_chipsets[] __devinitdata = {
31991 +static const struct ide_port_info hpt366_chipsets[] __devinitconst = {
31992 { /* 0: HPT36x */
31993 .name = DRV_NAME,
31994 .init_chipset = init_chipset_hpt366,
31995 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
31996 index 8126824..55a2798 100644
31997 --- a/drivers/ide/ide-cd.c
31998 +++ b/drivers/ide/ide-cd.c
31999 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
32000 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
32001 if ((unsigned long)buf & alignment
32002 || blk_rq_bytes(rq) & q->dma_pad_mask
32003 - || object_is_on_stack(buf))
32004 + || object_starts_on_stack(buf))
32005 drive->dma = 0;
32006 }
32007 }
32008 diff --git a/drivers/ide/ide-pci-generic.c b/drivers/ide/ide-pci-generic.c
32009 index 7f56b73..dab5b67 100644
32010 --- a/drivers/ide/ide-pci-generic.c
32011 +++ b/drivers/ide/ide-pci-generic.c
32012 @@ -53,7 +53,7 @@ static const struct ide_port_ops netcell_port_ops = {
32013 .udma_mask = ATA_UDMA6, \
32014 }
32015
32016 -static const struct ide_port_info generic_chipsets[] __devinitdata = {
32017 +static const struct ide_port_info generic_chipsets[] __devinitconst = {
32018 /* 0: Unknown */
32019 DECLARE_GENERIC_PCI_DEV(0),
32020
32021 diff --git a/drivers/ide/it8172.c b/drivers/ide/it8172.c
32022 index 560e66d..d5dd180 100644
32023 --- a/drivers/ide/it8172.c
32024 +++ b/drivers/ide/it8172.c
32025 @@ -115,7 +115,7 @@ static const struct ide_port_ops it8172_port_ops = {
32026 .set_dma_mode = it8172_set_dma_mode,
32027 };
32028
32029 -static const struct ide_port_info it8172_port_info __devinitdata = {
32030 +static const struct ide_port_info it8172_port_info __devinitconst = {
32031 .name = DRV_NAME,
32032 .port_ops = &it8172_port_ops,
32033 .enablebits = { {0x41, 0x80, 0x80}, {0x00, 0x00, 0x00} },
32034 diff --git a/drivers/ide/it8213.c b/drivers/ide/it8213.c
32035 index 46816ba..1847aeb 100644
32036 --- a/drivers/ide/it8213.c
32037 +++ b/drivers/ide/it8213.c
32038 @@ -156,7 +156,7 @@ static const struct ide_port_ops it8213_port_ops = {
32039 .cable_detect = it8213_cable_detect,
32040 };
32041
32042 -static const struct ide_port_info it8213_chipset __devinitdata = {
32043 +static const struct ide_port_info it8213_chipset __devinitconst = {
32044 .name = DRV_NAME,
32045 .enablebits = { {0x41, 0x80, 0x80} },
32046 .port_ops = &it8213_port_ops,
32047 diff --git a/drivers/ide/it821x.c b/drivers/ide/it821x.c
32048 index 2e3169f..c5611db 100644
32049 --- a/drivers/ide/it821x.c
32050 +++ b/drivers/ide/it821x.c
32051 @@ -630,7 +630,7 @@ static const struct ide_port_ops it821x_port_ops = {
32052 .cable_detect = it821x_cable_detect,
32053 };
32054
32055 -static const struct ide_port_info it821x_chipset __devinitdata = {
32056 +static const struct ide_port_info it821x_chipset __devinitconst = {
32057 .name = DRV_NAME,
32058 .init_chipset = init_chipset_it821x,
32059 .init_hwif = init_hwif_it821x,
32060 diff --git a/drivers/ide/jmicron.c b/drivers/ide/jmicron.c
32061 index 74c2c4a..efddd7d 100644
32062 --- a/drivers/ide/jmicron.c
32063 +++ b/drivers/ide/jmicron.c
32064 @@ -102,7 +102,7 @@ static const struct ide_port_ops jmicron_port_ops = {
32065 .cable_detect = jmicron_cable_detect,
32066 };
32067
32068 -static const struct ide_port_info jmicron_chipset __devinitdata = {
32069 +static const struct ide_port_info jmicron_chipset __devinitconst = {
32070 .name = DRV_NAME,
32071 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
32072 .port_ops = &jmicron_port_ops,
32073 diff --git a/drivers/ide/ns87415.c b/drivers/ide/ns87415.c
32074 index 95327a2..73f78d8 100644
32075 --- a/drivers/ide/ns87415.c
32076 +++ b/drivers/ide/ns87415.c
32077 @@ -293,7 +293,7 @@ static const struct ide_dma_ops ns87415_dma_ops = {
32078 .dma_sff_read_status = superio_dma_sff_read_status,
32079 };
32080
32081 -static const struct ide_port_info ns87415_chipset __devinitdata = {
32082 +static const struct ide_port_info ns87415_chipset __devinitconst = {
32083 .name = DRV_NAME,
32084 .init_hwif = init_hwif_ns87415,
32085 .tp_ops = &ns87415_tp_ops,
32086 diff --git a/drivers/ide/opti621.c b/drivers/ide/opti621.c
32087 index 1a53a4c..39edc66 100644
32088 --- a/drivers/ide/opti621.c
32089 +++ b/drivers/ide/opti621.c
32090 @@ -131,7 +131,7 @@ static const struct ide_port_ops opti621_port_ops = {
32091 .set_pio_mode = opti621_set_pio_mode,
32092 };
32093
32094 -static const struct ide_port_info opti621_chipset __devinitdata = {
32095 +static const struct ide_port_info opti621_chipset __devinitconst = {
32096 .name = DRV_NAME,
32097 .enablebits = { {0x45, 0x80, 0x00}, {0x40, 0x08, 0x00} },
32098 .port_ops = &opti621_port_ops,
32099 diff --git a/drivers/ide/pdc202xx_new.c b/drivers/ide/pdc202xx_new.c
32100 index 9546fe2..2e5ceb6 100644
32101 --- a/drivers/ide/pdc202xx_new.c
32102 +++ b/drivers/ide/pdc202xx_new.c
32103 @@ -465,7 +465,7 @@ static const struct ide_port_ops pdcnew_port_ops = {
32104 .udma_mask = udma, \
32105 }
32106
32107 -static const struct ide_port_info pdcnew_chipsets[] __devinitdata = {
32108 +static const struct ide_port_info pdcnew_chipsets[] __devinitconst = {
32109 /* 0: PDC202{68,70} */ DECLARE_PDCNEW_DEV(ATA_UDMA5),
32110 /* 1: PDC202{69,71,75,76,77} */ DECLARE_PDCNEW_DEV(ATA_UDMA6),
32111 };
32112 diff --git a/drivers/ide/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c
32113 index 3a35ec6..5634510 100644
32114 --- a/drivers/ide/pdc202xx_old.c
32115 +++ b/drivers/ide/pdc202xx_old.c
32116 @@ -270,7 +270,7 @@ static const struct ide_dma_ops pdc2026x_dma_ops = {
32117 .max_sectors = sectors, \
32118 }
32119
32120 -static const struct ide_port_info pdc202xx_chipsets[] __devinitdata = {
32121 +static const struct ide_port_info pdc202xx_chipsets[] __devinitconst = {
32122 { /* 0: PDC20246 */
32123 .name = DRV_NAME,
32124 .init_chipset = init_chipset_pdc202xx,
32125 diff --git a/drivers/ide/piix.c b/drivers/ide/piix.c
32126 index 1892e81..fe0fd60 100644
32127 --- a/drivers/ide/piix.c
32128 +++ b/drivers/ide/piix.c
32129 @@ -344,7 +344,7 @@ static const struct ide_port_ops ich_port_ops = {
32130 .udma_mask = udma, \
32131 }
32132
32133 -static const struct ide_port_info piix_pci_info[] __devinitdata = {
32134 +static const struct ide_port_info piix_pci_info[] __devinitconst = {
32135 /* 0: MPIIX */
32136 { /*
32137 * MPIIX actually has only a single IDE channel mapped to
32138 diff --git a/drivers/ide/rz1000.c b/drivers/ide/rz1000.c
32139 index a6414a8..c04173e 100644
32140 --- a/drivers/ide/rz1000.c
32141 +++ b/drivers/ide/rz1000.c
32142 @@ -38,7 +38,7 @@ static int __devinit rz1000_disable_readahead(struct pci_dev *dev)
32143 }
32144 }
32145
32146 -static const struct ide_port_info rz1000_chipset __devinitdata = {
32147 +static const struct ide_port_info rz1000_chipset __devinitconst = {
32148 .name = DRV_NAME,
32149 .host_flags = IDE_HFLAG_NO_DMA,
32150 };
32151 diff --git a/drivers/ide/sc1200.c b/drivers/ide/sc1200.c
32152 index 356b9b5..d4758eb 100644
32153 --- a/drivers/ide/sc1200.c
32154 +++ b/drivers/ide/sc1200.c
32155 @@ -291,7 +291,7 @@ static const struct ide_dma_ops sc1200_dma_ops = {
32156 .dma_sff_read_status = ide_dma_sff_read_status,
32157 };
32158
32159 -static const struct ide_port_info sc1200_chipset __devinitdata = {
32160 +static const struct ide_port_info sc1200_chipset __devinitconst = {
32161 .name = DRV_NAME,
32162 .port_ops = &sc1200_port_ops,
32163 .dma_ops = &sc1200_dma_ops,
32164 diff --git a/drivers/ide/scc_pata.c b/drivers/ide/scc_pata.c
32165 index b7f5b0c..9701038 100644
32166 --- a/drivers/ide/scc_pata.c
32167 +++ b/drivers/ide/scc_pata.c
32168 @@ -811,7 +811,7 @@ static const struct ide_dma_ops scc_dma_ops = {
32169 .dma_sff_read_status = scc_dma_sff_read_status,
32170 };
32171
32172 -static const struct ide_port_info scc_chipset __devinitdata = {
32173 +static const struct ide_port_info scc_chipset __devinitconst = {
32174 .name = "sccIDE",
32175 .init_iops = init_iops_scc,
32176 .init_dma = scc_init_dma,
32177 diff --git a/drivers/ide/serverworks.c b/drivers/ide/serverworks.c
32178 index 35fb8da..24d72ef 100644
32179 --- a/drivers/ide/serverworks.c
32180 +++ b/drivers/ide/serverworks.c
32181 @@ -337,7 +337,7 @@ static const struct ide_port_ops svwks_port_ops = {
32182 .cable_detect = svwks_cable_detect,
32183 };
32184
32185 -static const struct ide_port_info serverworks_chipsets[] __devinitdata = {
32186 +static const struct ide_port_info serverworks_chipsets[] __devinitconst = {
32187 { /* 0: OSB4 */
32188 .name = DRV_NAME,
32189 .init_chipset = init_chipset_svwks,
32190 diff --git a/drivers/ide/siimage.c b/drivers/ide/siimage.c
32191 index ddeda44..46f7e30 100644
32192 --- a/drivers/ide/siimage.c
32193 +++ b/drivers/ide/siimage.c
32194 @@ -719,7 +719,7 @@ static const struct ide_dma_ops sil_dma_ops = {
32195 .udma_mask = ATA_UDMA6, \
32196 }
32197
32198 -static const struct ide_port_info siimage_chipsets[] __devinitdata = {
32199 +static const struct ide_port_info siimage_chipsets[] __devinitconst = {
32200 /* 0: SiI680 */ DECLARE_SII_DEV(&sil_pata_port_ops),
32201 /* 1: SiI3112 */ DECLARE_SII_DEV(&sil_sata_port_ops)
32202 };
32203 diff --git a/drivers/ide/sis5513.c b/drivers/ide/sis5513.c
32204 index 4a00225..09e61b4 100644
32205 --- a/drivers/ide/sis5513.c
32206 +++ b/drivers/ide/sis5513.c
32207 @@ -563,7 +563,7 @@ static const struct ide_port_ops sis_ata133_port_ops = {
32208 .cable_detect = sis_cable_detect,
32209 };
32210
32211 -static const struct ide_port_info sis5513_chipset __devinitdata = {
32212 +static const struct ide_port_info sis5513_chipset __devinitconst = {
32213 .name = DRV_NAME,
32214 .init_chipset = init_chipset_sis5513,
32215 .enablebits = { {0x4a, 0x02, 0x02}, {0x4a, 0x04, 0x04} },
32216 diff --git a/drivers/ide/sl82c105.c b/drivers/ide/sl82c105.c
32217 index f21dc2a..d051cd2 100644
32218 --- a/drivers/ide/sl82c105.c
32219 +++ b/drivers/ide/sl82c105.c
32220 @@ -299,7 +299,7 @@ static const struct ide_dma_ops sl82c105_dma_ops = {
32221 .dma_sff_read_status = ide_dma_sff_read_status,
32222 };
32223
32224 -static const struct ide_port_info sl82c105_chipset __devinitdata = {
32225 +static const struct ide_port_info sl82c105_chipset __devinitconst = {
32226 .name = DRV_NAME,
32227 .init_chipset = init_chipset_sl82c105,
32228 .enablebits = {{0x40,0x01,0x01}, {0x40,0x10,0x10}},
32229 diff --git a/drivers/ide/slc90e66.c b/drivers/ide/slc90e66.c
32230 index 864ffe0..863a5e9 100644
32231 --- a/drivers/ide/slc90e66.c
32232 +++ b/drivers/ide/slc90e66.c
32233 @@ -132,7 +132,7 @@ static const struct ide_port_ops slc90e66_port_ops = {
32234 .cable_detect = slc90e66_cable_detect,
32235 };
32236
32237 -static const struct ide_port_info slc90e66_chipset __devinitdata = {
32238 +static const struct ide_port_info slc90e66_chipset __devinitconst = {
32239 .name = DRV_NAME,
32240 .enablebits = { {0x41, 0x80, 0x80}, {0x43, 0x80, 0x80} },
32241 .port_ops = &slc90e66_port_ops,
32242 diff --git a/drivers/ide/tc86c001.c b/drivers/ide/tc86c001.c
32243 index 4799d5c..1794678 100644
32244 --- a/drivers/ide/tc86c001.c
32245 +++ b/drivers/ide/tc86c001.c
32246 @@ -192,7 +192,7 @@ static const struct ide_dma_ops tc86c001_dma_ops = {
32247 .dma_sff_read_status = ide_dma_sff_read_status,
32248 };
32249
32250 -static const struct ide_port_info tc86c001_chipset __devinitdata = {
32251 +static const struct ide_port_info tc86c001_chipset __devinitconst = {
32252 .name = DRV_NAME,
32253 .init_hwif = init_hwif_tc86c001,
32254 .port_ops = &tc86c001_port_ops,
32255 diff --git a/drivers/ide/triflex.c b/drivers/ide/triflex.c
32256 index 281c914..55ce1b8 100644
32257 --- a/drivers/ide/triflex.c
32258 +++ b/drivers/ide/triflex.c
32259 @@ -92,7 +92,7 @@ static const struct ide_port_ops triflex_port_ops = {
32260 .set_dma_mode = triflex_set_mode,
32261 };
32262
32263 -static const struct ide_port_info triflex_device __devinitdata = {
32264 +static const struct ide_port_info triflex_device __devinitconst = {
32265 .name = DRV_NAME,
32266 .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}},
32267 .port_ops = &triflex_port_ops,
32268 diff --git a/drivers/ide/trm290.c b/drivers/ide/trm290.c
32269 index 4b42ca0..e494a98 100644
32270 --- a/drivers/ide/trm290.c
32271 +++ b/drivers/ide/trm290.c
32272 @@ -324,7 +324,7 @@ static struct ide_dma_ops trm290_dma_ops = {
32273 .dma_check = trm290_dma_check,
32274 };
32275
32276 -static const struct ide_port_info trm290_chipset __devinitdata = {
32277 +static const struct ide_port_info trm290_chipset __devinitconst = {
32278 .name = DRV_NAME,
32279 .init_hwif = init_hwif_trm290,
32280 .tp_ops = &trm290_tp_ops,
32281 diff --git a/drivers/ide/via82cxxx.c b/drivers/ide/via82cxxx.c
32282 index f46f49c..eb77678 100644
32283 --- a/drivers/ide/via82cxxx.c
32284 +++ b/drivers/ide/via82cxxx.c
32285 @@ -403,7 +403,7 @@ static const struct ide_port_ops via_port_ops = {
32286 .cable_detect = via82cxxx_cable_detect,
32287 };
32288
32289 -static const struct ide_port_info via82cxxx_chipset __devinitdata = {
32290 +static const struct ide_port_info via82cxxx_chipset __devinitconst = {
32291 .name = DRV_NAME,
32292 .init_chipset = init_chipset_via82cxxx,
32293 .enablebits = { { 0x40, 0x02, 0x02 }, { 0x40, 0x01, 0x01 } },
32294 diff --git a/drivers/ieee802154/fakehard.c b/drivers/ieee802154/fakehard.c
32295 index 73d4531..c90cd2d 100644
32296 --- a/drivers/ieee802154/fakehard.c
32297 +++ b/drivers/ieee802154/fakehard.c
32298 @@ -386,7 +386,7 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
32299 phy->transmit_power = 0xbf;
32300
32301 dev->netdev_ops = &fake_ops;
32302 - dev->ml_priv = &fake_mlme;
32303 + dev->ml_priv = (void *)&fake_mlme;
32304
32305 priv = netdev_priv(dev);
32306 priv->phy = phy;
32307 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
32308 index d67999f..4c5d083 100644
32309 --- a/drivers/infiniband/core/cm.c
32310 +++ b/drivers/infiniband/core/cm.c
32311 @@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
32312
32313 struct cm_counter_group {
32314 struct kobject obj;
32315 - atomic_long_t counter[CM_ATTR_COUNT];
32316 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
32317 };
32318
32319 struct cm_counter_attribute {
32320 @@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
32321 struct ib_mad_send_buf *msg = NULL;
32322 int ret;
32323
32324 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32325 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32326 counter[CM_REQ_COUNTER]);
32327
32328 /* Quick state check to discard duplicate REQs. */
32329 @@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
32330 if (!cm_id_priv)
32331 return;
32332
32333 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32334 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32335 counter[CM_REP_COUNTER]);
32336 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
32337 if (ret)
32338 @@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
32339 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
32340 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
32341 spin_unlock_irq(&cm_id_priv->lock);
32342 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32343 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32344 counter[CM_RTU_COUNTER]);
32345 goto out;
32346 }
32347 @@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
32348 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
32349 dreq_msg->local_comm_id);
32350 if (!cm_id_priv) {
32351 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32352 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32353 counter[CM_DREQ_COUNTER]);
32354 cm_issue_drep(work->port, work->mad_recv_wc);
32355 return -EINVAL;
32356 @@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
32357 case IB_CM_MRA_REP_RCVD:
32358 break;
32359 case IB_CM_TIMEWAIT:
32360 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32361 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32362 counter[CM_DREQ_COUNTER]);
32363 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32364 goto unlock;
32365 @@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
32366 cm_free_msg(msg);
32367 goto deref;
32368 case IB_CM_DREQ_RCVD:
32369 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32370 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32371 counter[CM_DREQ_COUNTER]);
32372 goto unlock;
32373 default:
32374 @@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
32375 ib_modify_mad(cm_id_priv->av.port->mad_agent,
32376 cm_id_priv->msg, timeout)) {
32377 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
32378 - atomic_long_inc(&work->port->
32379 + atomic_long_inc_unchecked(&work->port->
32380 counter_group[CM_RECV_DUPLICATES].
32381 counter[CM_MRA_COUNTER]);
32382 goto out;
32383 @@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
32384 break;
32385 case IB_CM_MRA_REQ_RCVD:
32386 case IB_CM_MRA_REP_RCVD:
32387 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32388 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32389 counter[CM_MRA_COUNTER]);
32390 /* fall through */
32391 default:
32392 @@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
32393 case IB_CM_LAP_IDLE:
32394 break;
32395 case IB_CM_MRA_LAP_SENT:
32396 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32397 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32398 counter[CM_LAP_COUNTER]);
32399 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32400 goto unlock;
32401 @@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
32402 cm_free_msg(msg);
32403 goto deref;
32404 case IB_CM_LAP_RCVD:
32405 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32406 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32407 counter[CM_LAP_COUNTER]);
32408 goto unlock;
32409 default:
32410 @@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
32411 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
32412 if (cur_cm_id_priv) {
32413 spin_unlock_irq(&cm.lock);
32414 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32415 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32416 counter[CM_SIDR_REQ_COUNTER]);
32417 goto out; /* Duplicate message. */
32418 }
32419 @@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
32420 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
32421 msg->retries = 1;
32422
32423 - atomic_long_add(1 + msg->retries,
32424 + atomic_long_add_unchecked(1 + msg->retries,
32425 &port->counter_group[CM_XMIT].counter[attr_index]);
32426 if (msg->retries)
32427 - atomic_long_add(msg->retries,
32428 + atomic_long_add_unchecked(msg->retries,
32429 &port->counter_group[CM_XMIT_RETRIES].
32430 counter[attr_index]);
32431
32432 @@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
32433 }
32434
32435 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
32436 - atomic_long_inc(&port->counter_group[CM_RECV].
32437 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
32438 counter[attr_id - CM_ATTR_ID_OFFSET]);
32439
32440 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
32441 @@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
32442 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
32443
32444 return sprintf(buf, "%ld\n",
32445 - atomic_long_read(&group->counter[cm_attr->index]));
32446 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
32447 }
32448
32449 static const struct sysfs_ops cm_counter_ops = {
32450 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
32451 index 176c8f9..2627b62 100644
32452 --- a/drivers/infiniband/core/fmr_pool.c
32453 +++ b/drivers/infiniband/core/fmr_pool.c
32454 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
32455
32456 struct task_struct *thread;
32457
32458 - atomic_t req_ser;
32459 - atomic_t flush_ser;
32460 + atomic_unchecked_t req_ser;
32461 + atomic_unchecked_t flush_ser;
32462
32463 wait_queue_head_t force_wait;
32464 };
32465 @@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32466 struct ib_fmr_pool *pool = pool_ptr;
32467
32468 do {
32469 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
32470 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
32471 ib_fmr_batch_release(pool);
32472
32473 - atomic_inc(&pool->flush_ser);
32474 + atomic_inc_unchecked(&pool->flush_ser);
32475 wake_up_interruptible(&pool->force_wait);
32476
32477 if (pool->flush_function)
32478 @@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32479 }
32480
32481 set_current_state(TASK_INTERRUPTIBLE);
32482 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
32483 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
32484 !kthread_should_stop())
32485 schedule();
32486 __set_current_state(TASK_RUNNING);
32487 @@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
32488 pool->dirty_watermark = params->dirty_watermark;
32489 pool->dirty_len = 0;
32490 spin_lock_init(&pool->pool_lock);
32491 - atomic_set(&pool->req_ser, 0);
32492 - atomic_set(&pool->flush_ser, 0);
32493 + atomic_set_unchecked(&pool->req_ser, 0);
32494 + atomic_set_unchecked(&pool->flush_ser, 0);
32495 init_waitqueue_head(&pool->force_wait);
32496
32497 pool->thread = kthread_run(ib_fmr_cleanup_thread,
32498 @@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
32499 }
32500 spin_unlock_irq(&pool->pool_lock);
32501
32502 - serial = atomic_inc_return(&pool->req_ser);
32503 + serial = atomic_inc_return_unchecked(&pool->req_ser);
32504 wake_up_process(pool->thread);
32505
32506 if (wait_event_interruptible(pool->force_wait,
32507 - atomic_read(&pool->flush_ser) - serial >= 0))
32508 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
32509 return -EINTR;
32510
32511 return 0;
32512 @@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
32513 } else {
32514 list_add_tail(&fmr->list, &pool->dirty_list);
32515 if (++pool->dirty_len >= pool->dirty_watermark) {
32516 - atomic_inc(&pool->req_ser);
32517 + atomic_inc_unchecked(&pool->req_ser);
32518 wake_up_process(pool->thread);
32519 }
32520 }
32521 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
32522 index 57e07c6..56d09d4 100644
32523 --- a/drivers/infiniband/hw/cxgb4/mem.c
32524 +++ b/drivers/infiniband/hw/cxgb4/mem.c
32525 @@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32526 int err;
32527 struct fw_ri_tpte tpt;
32528 u32 stag_idx;
32529 - static atomic_t key;
32530 + static atomic_unchecked_t key;
32531
32532 if (c4iw_fatal_error(rdev))
32533 return -EIO;
32534 @@ -139,7 +139,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32535 if (rdev->stats.stag.cur > rdev->stats.stag.max)
32536 rdev->stats.stag.max = rdev->stats.stag.cur;
32537 mutex_unlock(&rdev->stats.lock);
32538 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
32539 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
32540 }
32541 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
32542 __func__, stag_state, type, pdid, stag_idx);
32543 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
32544 index 79b3dbc..96e5fcc 100644
32545 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
32546 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
32547 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32548 struct ib_atomic_eth *ateth;
32549 struct ipath_ack_entry *e;
32550 u64 vaddr;
32551 - atomic64_t *maddr;
32552 + atomic64_unchecked_t *maddr;
32553 u64 sdata;
32554 u32 rkey;
32555 u8 next;
32556 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32557 IB_ACCESS_REMOTE_ATOMIC)))
32558 goto nack_acc_unlck;
32559 /* Perform atomic OP and save result. */
32560 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32561 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32562 sdata = be64_to_cpu(ateth->swap_data);
32563 e = &qp->s_ack_queue[qp->r_head_ack_queue];
32564 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
32565 - (u64) atomic64_add_return(sdata, maddr) - sdata :
32566 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32567 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32568 be64_to_cpu(ateth->compare_data),
32569 sdata);
32570 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
32571 index 1f95bba..9530f87 100644
32572 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
32573 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
32574 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
32575 unsigned long flags;
32576 struct ib_wc wc;
32577 u64 sdata;
32578 - atomic64_t *maddr;
32579 + atomic64_unchecked_t *maddr;
32580 enum ib_wc_status send_status;
32581
32582 /*
32583 @@ -382,11 +382,11 @@ again:
32584 IB_ACCESS_REMOTE_ATOMIC)))
32585 goto acc_err;
32586 /* Perform atomic OP and save result. */
32587 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32588 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32589 sdata = wqe->wr.wr.atomic.compare_add;
32590 *(u64 *) sqp->s_sge.sge.vaddr =
32591 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
32592 - (u64) atomic64_add_return(sdata, maddr) - sdata :
32593 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32594 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32595 sdata, wqe->wr.wr.atomic.swap);
32596 goto send_comp;
32597 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
32598 index 7140199..da60063 100644
32599 --- a/drivers/infiniband/hw/nes/nes.c
32600 +++ b/drivers/infiniband/hw/nes/nes.c
32601 @@ -103,7 +103,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
32602 LIST_HEAD(nes_adapter_list);
32603 static LIST_HEAD(nes_dev_list);
32604
32605 -atomic_t qps_destroyed;
32606 +atomic_unchecked_t qps_destroyed;
32607
32608 static unsigned int ee_flsh_adapter;
32609 static unsigned int sysfs_nonidx_addr;
32610 @@ -272,7 +272,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
32611 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
32612 struct nes_adapter *nesadapter = nesdev->nesadapter;
32613
32614 - atomic_inc(&qps_destroyed);
32615 + atomic_inc_unchecked(&qps_destroyed);
32616
32617 /* Free the control structures */
32618
32619 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
32620 index c438e46..ca30356 100644
32621 --- a/drivers/infiniband/hw/nes/nes.h
32622 +++ b/drivers/infiniband/hw/nes/nes.h
32623 @@ -178,17 +178,17 @@ extern unsigned int nes_debug_level;
32624 extern unsigned int wqm_quanta;
32625 extern struct list_head nes_adapter_list;
32626
32627 -extern atomic_t cm_connects;
32628 -extern atomic_t cm_accepts;
32629 -extern atomic_t cm_disconnects;
32630 -extern atomic_t cm_closes;
32631 -extern atomic_t cm_connecteds;
32632 -extern atomic_t cm_connect_reqs;
32633 -extern atomic_t cm_rejects;
32634 -extern atomic_t mod_qp_timouts;
32635 -extern atomic_t qps_created;
32636 -extern atomic_t qps_destroyed;
32637 -extern atomic_t sw_qps_destroyed;
32638 +extern atomic_unchecked_t cm_connects;
32639 +extern atomic_unchecked_t cm_accepts;
32640 +extern atomic_unchecked_t cm_disconnects;
32641 +extern atomic_unchecked_t cm_closes;
32642 +extern atomic_unchecked_t cm_connecteds;
32643 +extern atomic_unchecked_t cm_connect_reqs;
32644 +extern atomic_unchecked_t cm_rejects;
32645 +extern atomic_unchecked_t mod_qp_timouts;
32646 +extern atomic_unchecked_t qps_created;
32647 +extern atomic_unchecked_t qps_destroyed;
32648 +extern atomic_unchecked_t sw_qps_destroyed;
32649 extern u32 mh_detected;
32650 extern u32 mh_pauses_sent;
32651 extern u32 cm_packets_sent;
32652 @@ -197,16 +197,16 @@ extern u32 cm_packets_created;
32653 extern u32 cm_packets_received;
32654 extern u32 cm_packets_dropped;
32655 extern u32 cm_packets_retrans;
32656 -extern atomic_t cm_listens_created;
32657 -extern atomic_t cm_listens_destroyed;
32658 +extern atomic_unchecked_t cm_listens_created;
32659 +extern atomic_unchecked_t cm_listens_destroyed;
32660 extern u32 cm_backlog_drops;
32661 -extern atomic_t cm_loopbacks;
32662 -extern atomic_t cm_nodes_created;
32663 -extern atomic_t cm_nodes_destroyed;
32664 -extern atomic_t cm_accel_dropped_pkts;
32665 -extern atomic_t cm_resets_recvd;
32666 -extern atomic_t pau_qps_created;
32667 -extern atomic_t pau_qps_destroyed;
32668 +extern atomic_unchecked_t cm_loopbacks;
32669 +extern atomic_unchecked_t cm_nodes_created;
32670 +extern atomic_unchecked_t cm_nodes_destroyed;
32671 +extern atomic_unchecked_t cm_accel_dropped_pkts;
32672 +extern atomic_unchecked_t cm_resets_recvd;
32673 +extern atomic_unchecked_t pau_qps_created;
32674 +extern atomic_unchecked_t pau_qps_destroyed;
32675
32676 extern u32 int_mod_timer_init;
32677 extern u32 int_mod_cq_depth_256;
32678 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
32679 index 020e95c..fbb3450 100644
32680 --- a/drivers/infiniband/hw/nes/nes_cm.c
32681 +++ b/drivers/infiniband/hw/nes/nes_cm.c
32682 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
32683 u32 cm_packets_retrans;
32684 u32 cm_packets_created;
32685 u32 cm_packets_received;
32686 -atomic_t cm_listens_created;
32687 -atomic_t cm_listens_destroyed;
32688 +atomic_unchecked_t cm_listens_created;
32689 +atomic_unchecked_t cm_listens_destroyed;
32690 u32 cm_backlog_drops;
32691 -atomic_t cm_loopbacks;
32692 -atomic_t cm_nodes_created;
32693 -atomic_t cm_nodes_destroyed;
32694 -atomic_t cm_accel_dropped_pkts;
32695 -atomic_t cm_resets_recvd;
32696 +atomic_unchecked_t cm_loopbacks;
32697 +atomic_unchecked_t cm_nodes_created;
32698 +atomic_unchecked_t cm_nodes_destroyed;
32699 +atomic_unchecked_t cm_accel_dropped_pkts;
32700 +atomic_unchecked_t cm_resets_recvd;
32701
32702 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
32703 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
32704 @@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
32705
32706 static struct nes_cm_core *g_cm_core;
32707
32708 -atomic_t cm_connects;
32709 -atomic_t cm_accepts;
32710 -atomic_t cm_disconnects;
32711 -atomic_t cm_closes;
32712 -atomic_t cm_connecteds;
32713 -atomic_t cm_connect_reqs;
32714 -atomic_t cm_rejects;
32715 +atomic_unchecked_t cm_connects;
32716 +atomic_unchecked_t cm_accepts;
32717 +atomic_unchecked_t cm_disconnects;
32718 +atomic_unchecked_t cm_closes;
32719 +atomic_unchecked_t cm_connecteds;
32720 +atomic_unchecked_t cm_connect_reqs;
32721 +atomic_unchecked_t cm_rejects;
32722
32723 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
32724 {
32725 @@ -1279,7 +1279,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
32726 kfree(listener);
32727 listener = NULL;
32728 ret = 0;
32729 - atomic_inc(&cm_listens_destroyed);
32730 + atomic_inc_unchecked(&cm_listens_destroyed);
32731 } else {
32732 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
32733 }
32734 @@ -1482,7 +1482,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
32735 cm_node->rem_mac);
32736
32737 add_hte_node(cm_core, cm_node);
32738 - atomic_inc(&cm_nodes_created);
32739 + atomic_inc_unchecked(&cm_nodes_created);
32740
32741 return cm_node;
32742 }
32743 @@ -1540,7 +1540,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
32744 }
32745
32746 atomic_dec(&cm_core->node_cnt);
32747 - atomic_inc(&cm_nodes_destroyed);
32748 + atomic_inc_unchecked(&cm_nodes_destroyed);
32749 nesqp = cm_node->nesqp;
32750 if (nesqp) {
32751 nesqp->cm_node = NULL;
32752 @@ -1604,7 +1604,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
32753
32754 static void drop_packet(struct sk_buff *skb)
32755 {
32756 - atomic_inc(&cm_accel_dropped_pkts);
32757 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
32758 dev_kfree_skb_any(skb);
32759 }
32760
32761 @@ -1667,7 +1667,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
32762 {
32763
32764 int reset = 0; /* whether to send reset in case of err.. */
32765 - atomic_inc(&cm_resets_recvd);
32766 + atomic_inc_unchecked(&cm_resets_recvd);
32767 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
32768 " refcnt=%d\n", cm_node, cm_node->state,
32769 atomic_read(&cm_node->ref_count));
32770 @@ -2308,7 +2308,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
32771 rem_ref_cm_node(cm_node->cm_core, cm_node);
32772 return NULL;
32773 }
32774 - atomic_inc(&cm_loopbacks);
32775 + atomic_inc_unchecked(&cm_loopbacks);
32776 loopbackremotenode->loopbackpartner = cm_node;
32777 loopbackremotenode->tcp_cntxt.rcv_wscale =
32778 NES_CM_DEFAULT_RCV_WND_SCALE;
32779 @@ -2583,7 +2583,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
32780 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
32781 else {
32782 rem_ref_cm_node(cm_core, cm_node);
32783 - atomic_inc(&cm_accel_dropped_pkts);
32784 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
32785 dev_kfree_skb_any(skb);
32786 }
32787 break;
32788 @@ -2891,7 +2891,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32789
32790 if ((cm_id) && (cm_id->event_handler)) {
32791 if (issue_disconn) {
32792 - atomic_inc(&cm_disconnects);
32793 + atomic_inc_unchecked(&cm_disconnects);
32794 cm_event.event = IW_CM_EVENT_DISCONNECT;
32795 cm_event.status = disconn_status;
32796 cm_event.local_addr = cm_id->local_addr;
32797 @@ -2913,7 +2913,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32798 }
32799
32800 if (issue_close) {
32801 - atomic_inc(&cm_closes);
32802 + atomic_inc_unchecked(&cm_closes);
32803 nes_disconnect(nesqp, 1);
32804
32805 cm_id->provider_data = nesqp;
32806 @@ -3049,7 +3049,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32807
32808 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
32809 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
32810 - atomic_inc(&cm_accepts);
32811 + atomic_inc_unchecked(&cm_accepts);
32812
32813 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
32814 netdev_refcnt_read(nesvnic->netdev));
32815 @@ -3251,7 +3251,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
32816 struct nes_cm_core *cm_core;
32817 u8 *start_buff;
32818
32819 - atomic_inc(&cm_rejects);
32820 + atomic_inc_unchecked(&cm_rejects);
32821 cm_node = (struct nes_cm_node *)cm_id->provider_data;
32822 loopback = cm_node->loopbackpartner;
32823 cm_core = cm_node->cm_core;
32824 @@ -3311,7 +3311,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32825 ntohl(cm_id->local_addr.sin_addr.s_addr),
32826 ntohs(cm_id->local_addr.sin_port));
32827
32828 - atomic_inc(&cm_connects);
32829 + atomic_inc_unchecked(&cm_connects);
32830 nesqp->active_conn = 1;
32831
32832 /* cache the cm_id in the qp */
32833 @@ -3421,7 +3421,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
32834 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
32835 return err;
32836 }
32837 - atomic_inc(&cm_listens_created);
32838 + atomic_inc_unchecked(&cm_listens_created);
32839 }
32840
32841 cm_id->add_ref(cm_id);
32842 @@ -3522,7 +3522,7 @@ static void cm_event_connected(struct nes_cm_event *event)
32843
32844 if (nesqp->destroyed)
32845 return;
32846 - atomic_inc(&cm_connecteds);
32847 + atomic_inc_unchecked(&cm_connecteds);
32848 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
32849 " local port 0x%04X. jiffies = %lu.\n",
32850 nesqp->hwqp.qp_id,
32851 @@ -3709,7 +3709,7 @@ static void cm_event_reset(struct nes_cm_event *event)
32852
32853 cm_id->add_ref(cm_id);
32854 ret = cm_id->event_handler(cm_id, &cm_event);
32855 - atomic_inc(&cm_closes);
32856 + atomic_inc_unchecked(&cm_closes);
32857 cm_event.event = IW_CM_EVENT_CLOSE;
32858 cm_event.status = 0;
32859 cm_event.provider_data = cm_id->provider_data;
32860 @@ -3745,7 +3745,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
32861 return;
32862 cm_id = cm_node->cm_id;
32863
32864 - atomic_inc(&cm_connect_reqs);
32865 + atomic_inc_unchecked(&cm_connect_reqs);
32866 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32867 cm_node, cm_id, jiffies);
32868
32869 @@ -3785,7 +3785,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
32870 return;
32871 cm_id = cm_node->cm_id;
32872
32873 - atomic_inc(&cm_connect_reqs);
32874 + atomic_inc_unchecked(&cm_connect_reqs);
32875 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32876 cm_node, cm_id, jiffies);
32877
32878 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
32879 index 3ba7be3..c81f6ff 100644
32880 --- a/drivers/infiniband/hw/nes/nes_mgt.c
32881 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
32882 @@ -40,8 +40,8 @@
32883 #include "nes.h"
32884 #include "nes_mgt.h"
32885
32886 -atomic_t pau_qps_created;
32887 -atomic_t pau_qps_destroyed;
32888 +atomic_unchecked_t pau_qps_created;
32889 +atomic_unchecked_t pau_qps_destroyed;
32890
32891 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
32892 {
32893 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
32894 {
32895 struct sk_buff *skb;
32896 unsigned long flags;
32897 - atomic_inc(&pau_qps_destroyed);
32898 + atomic_inc_unchecked(&pau_qps_destroyed);
32899
32900 /* Free packets that have not yet been forwarded */
32901 /* Lock is acquired by skb_dequeue when removing the skb */
32902 @@ -812,7 +812,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
32903 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
32904 skb_queue_head_init(&nesqp->pau_list);
32905 spin_lock_init(&nesqp->pau_lock);
32906 - atomic_inc(&pau_qps_created);
32907 + atomic_inc_unchecked(&pau_qps_created);
32908 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
32909 }
32910
32911 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
32912 index f3a3ecf..57d311d 100644
32913 --- a/drivers/infiniband/hw/nes/nes_nic.c
32914 +++ b/drivers/infiniband/hw/nes/nes_nic.c
32915 @@ -1277,39 +1277,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
32916 target_stat_values[++index] = mh_detected;
32917 target_stat_values[++index] = mh_pauses_sent;
32918 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
32919 - target_stat_values[++index] = atomic_read(&cm_connects);
32920 - target_stat_values[++index] = atomic_read(&cm_accepts);
32921 - target_stat_values[++index] = atomic_read(&cm_disconnects);
32922 - target_stat_values[++index] = atomic_read(&cm_connecteds);
32923 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
32924 - target_stat_values[++index] = atomic_read(&cm_rejects);
32925 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
32926 - target_stat_values[++index] = atomic_read(&qps_created);
32927 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
32928 - target_stat_values[++index] = atomic_read(&qps_destroyed);
32929 - target_stat_values[++index] = atomic_read(&cm_closes);
32930 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
32931 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
32932 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
32933 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
32934 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
32935 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
32936 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
32937 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
32938 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
32939 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
32940 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
32941 target_stat_values[++index] = cm_packets_sent;
32942 target_stat_values[++index] = cm_packets_bounced;
32943 target_stat_values[++index] = cm_packets_created;
32944 target_stat_values[++index] = cm_packets_received;
32945 target_stat_values[++index] = cm_packets_dropped;
32946 target_stat_values[++index] = cm_packets_retrans;
32947 - target_stat_values[++index] = atomic_read(&cm_listens_created);
32948 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
32949 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
32950 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
32951 target_stat_values[++index] = cm_backlog_drops;
32952 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
32953 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
32954 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
32955 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
32956 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
32957 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
32958 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
32959 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
32960 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
32961 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
32962 target_stat_values[++index] = nesadapter->free_4kpbl;
32963 target_stat_values[++index] = nesadapter->free_256pbl;
32964 target_stat_values[++index] = int_mod_timer_init;
32965 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
32966 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
32967 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
32968 - target_stat_values[++index] = atomic_read(&pau_qps_created);
32969 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
32970 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
32971 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
32972 }
32973
32974 /**
32975 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
32976 index 8b8812d..a5e1133 100644
32977 --- a/drivers/infiniband/hw/nes/nes_verbs.c
32978 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
32979 @@ -46,9 +46,9 @@
32980
32981 #include <rdma/ib_umem.h>
32982
32983 -atomic_t mod_qp_timouts;
32984 -atomic_t qps_created;
32985 -atomic_t sw_qps_destroyed;
32986 +atomic_unchecked_t mod_qp_timouts;
32987 +atomic_unchecked_t qps_created;
32988 +atomic_unchecked_t sw_qps_destroyed;
32989
32990 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
32991
32992 @@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
32993 if (init_attr->create_flags)
32994 return ERR_PTR(-EINVAL);
32995
32996 - atomic_inc(&qps_created);
32997 + atomic_inc_unchecked(&qps_created);
32998 switch (init_attr->qp_type) {
32999 case IB_QPT_RC:
33000 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
33001 @@ -1460,7 +1460,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
33002 struct iw_cm_event cm_event;
33003 int ret = 0;
33004
33005 - atomic_inc(&sw_qps_destroyed);
33006 + atomic_inc_unchecked(&sw_qps_destroyed);
33007 nesqp->destroyed = 1;
33008
33009 /* Blow away the connection if it exists. */
33010 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
33011 index 7b1b8669..4b69f85 100644
33012 --- a/drivers/infiniband/hw/qib/qib.h
33013 +++ b/drivers/infiniband/hw/qib/qib.h
33014 @@ -51,6 +51,7 @@
33015 #include <linux/completion.h>
33016 #include <linux/kref.h>
33017 #include <linux/sched.h>
33018 +#include <linux/slab.h>
33019
33020 #include "qib_common.h"
33021 #include "qib_verbs.h"
33022 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
33023 index da739d9..da1c7f4 100644
33024 --- a/drivers/input/gameport/gameport.c
33025 +++ b/drivers/input/gameport/gameport.c
33026 @@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
33027 */
33028 static void gameport_init_port(struct gameport *gameport)
33029 {
33030 - static atomic_t gameport_no = ATOMIC_INIT(0);
33031 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
33032
33033 __module_get(THIS_MODULE);
33034
33035 mutex_init(&gameport->drv_mutex);
33036 device_initialize(&gameport->dev);
33037 dev_set_name(&gameport->dev, "gameport%lu",
33038 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
33039 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
33040 gameport->dev.bus = &gameport_bus;
33041 gameport->dev.release = gameport_release_port;
33042 if (gameport->parent)
33043 diff --git a/drivers/input/input.c b/drivers/input/input.c
33044 index 8921c61..f5cd63d 100644
33045 --- a/drivers/input/input.c
33046 +++ b/drivers/input/input.c
33047 @@ -1814,7 +1814,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
33048 */
33049 int input_register_device(struct input_dev *dev)
33050 {
33051 - static atomic_t input_no = ATOMIC_INIT(0);
33052 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
33053 struct input_handler *handler;
33054 const char *path;
33055 int error;
33056 @@ -1851,7 +1851,7 @@ int input_register_device(struct input_dev *dev)
33057 dev->setkeycode = input_default_setkeycode;
33058
33059 dev_set_name(&dev->dev, "input%ld",
33060 - (unsigned long) atomic_inc_return(&input_no) - 1);
33061 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
33062
33063 error = device_add(&dev->dev);
33064 if (error)
33065 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
33066 index 04c69af..5f92d00 100644
33067 --- a/drivers/input/joystick/sidewinder.c
33068 +++ b/drivers/input/joystick/sidewinder.c
33069 @@ -30,6 +30,7 @@
33070 #include <linux/kernel.h>
33071 #include <linux/module.h>
33072 #include <linux/slab.h>
33073 +#include <linux/sched.h>
33074 #include <linux/init.h>
33075 #include <linux/input.h>
33076 #include <linux/gameport.h>
33077 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
33078 index 83811e4..0822b90 100644
33079 --- a/drivers/input/joystick/xpad.c
33080 +++ b/drivers/input/joystick/xpad.c
33081 @@ -726,7 +726,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
33082
33083 static int xpad_led_probe(struct usb_xpad *xpad)
33084 {
33085 - static atomic_t led_seq = ATOMIC_INIT(0);
33086 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
33087 long led_no;
33088 struct xpad_led *led;
33089 struct led_classdev *led_cdev;
33090 @@ -739,7 +739,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
33091 if (!led)
33092 return -ENOMEM;
33093
33094 - led_no = (long)atomic_inc_return(&led_seq) - 1;
33095 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
33096
33097 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
33098 led->xpad = xpad;
33099 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
33100 index 0110b5a..d3ad144 100644
33101 --- a/drivers/input/mousedev.c
33102 +++ b/drivers/input/mousedev.c
33103 @@ -763,7 +763,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
33104
33105 spin_unlock_irq(&client->packet_lock);
33106
33107 - if (copy_to_user(buffer, data, count))
33108 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
33109 return -EFAULT;
33110
33111 return count;
33112 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
33113 index d0f7533..fb8215b 100644
33114 --- a/drivers/input/serio/serio.c
33115 +++ b/drivers/input/serio/serio.c
33116 @@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
33117 */
33118 static void serio_init_port(struct serio *serio)
33119 {
33120 - static atomic_t serio_no = ATOMIC_INIT(0);
33121 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
33122
33123 __module_get(THIS_MODULE);
33124
33125 @@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
33126 mutex_init(&serio->drv_mutex);
33127 device_initialize(&serio->dev);
33128 dev_set_name(&serio->dev, "serio%ld",
33129 - (long)atomic_inc_return(&serio_no) - 1);
33130 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
33131 serio->dev.bus = &serio_bus;
33132 serio->dev.release = serio_release_port;
33133 serio->dev.groups = serio_device_attr_groups;
33134 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
33135 index 38c4bd8..58965d9 100644
33136 --- a/drivers/isdn/capi/capi.c
33137 +++ b/drivers/isdn/capi/capi.c
33138 @@ -83,8 +83,8 @@ struct capiminor {
33139
33140 struct capi20_appl *ap;
33141 u32 ncci;
33142 - atomic_t datahandle;
33143 - atomic_t msgid;
33144 + atomic_unchecked_t datahandle;
33145 + atomic_unchecked_t msgid;
33146
33147 struct tty_port port;
33148 int ttyinstop;
33149 @@ -392,7 +392,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
33150 capimsg_setu16(s, 2, mp->ap->applid);
33151 capimsg_setu8 (s, 4, CAPI_DATA_B3);
33152 capimsg_setu8 (s, 5, CAPI_RESP);
33153 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
33154 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
33155 capimsg_setu32(s, 8, mp->ncci);
33156 capimsg_setu16(s, 12, datahandle);
33157 }
33158 @@ -513,14 +513,14 @@ static void handle_minor_send(struct capiminor *mp)
33159 mp->outbytes -= len;
33160 spin_unlock_bh(&mp->outlock);
33161
33162 - datahandle = atomic_inc_return(&mp->datahandle);
33163 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
33164 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
33165 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
33166 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
33167 capimsg_setu16(skb->data, 2, mp->ap->applid);
33168 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
33169 capimsg_setu8 (skb->data, 5, CAPI_REQ);
33170 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
33171 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
33172 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
33173 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
33174 capimsg_setu16(skb->data, 16, len); /* Data length */
33175 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
33176 index a6d9fd2..afdb8a3 100644
33177 --- a/drivers/isdn/gigaset/interface.c
33178 +++ b/drivers/isdn/gigaset/interface.c
33179 @@ -160,9 +160,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
33180 }
33181 tty->driver_data = cs;
33182
33183 - ++cs->port.count;
33184 + atomic_inc(&cs->port.count);
33185
33186 - if (cs->port.count == 1) {
33187 + if (atomic_read(&cs->port.count) == 1) {
33188 tty_port_tty_set(&cs->port, tty);
33189 tty->low_latency = 1;
33190 }
33191 @@ -186,9 +186,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
33192
33193 if (!cs->connected)
33194 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
33195 - else if (!cs->port.count)
33196 + else if (!atomic_read(&cs->port.count))
33197 dev_warn(cs->dev, "%s: device not opened\n", __func__);
33198 - else if (!--cs->port.count)
33199 + else if (!atomic_dec_return(&cs->port.count))
33200 tty_port_tty_set(&cs->port, NULL);
33201
33202 mutex_unlock(&cs->mutex);
33203 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
33204 index 821f7ac..28d4030 100644
33205 --- a/drivers/isdn/hardware/avm/b1.c
33206 +++ b/drivers/isdn/hardware/avm/b1.c
33207 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
33208 }
33209 if (left) {
33210 if (t4file->user) {
33211 - if (copy_from_user(buf, dp, left))
33212 + if (left > sizeof buf || copy_from_user(buf, dp, left))
33213 return -EFAULT;
33214 } else {
33215 memcpy(buf, dp, left);
33216 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
33217 }
33218 if (left) {
33219 if (config->user) {
33220 - if (copy_from_user(buf, dp, left))
33221 + if (left > sizeof buf || copy_from_user(buf, dp, left))
33222 return -EFAULT;
33223 } else {
33224 memcpy(buf, dp, left);
33225 diff --git a/drivers/isdn/hardware/eicon/divasync.h b/drivers/isdn/hardware/eicon/divasync.h
33226 index dd6b53a..19d9ee6 100644
33227 --- a/drivers/isdn/hardware/eicon/divasync.h
33228 +++ b/drivers/isdn/hardware/eicon/divasync.h
33229 @@ -146,7 +146,7 @@ typedef struct _diva_didd_add_adapter {
33230 } diva_didd_add_adapter_t;
33231 typedef struct _diva_didd_remove_adapter {
33232 IDI_CALL p_request;
33233 -} diva_didd_remove_adapter_t;
33234 +} __no_const diva_didd_remove_adapter_t;
33235 typedef struct _diva_didd_read_adapter_array {
33236 void *buffer;
33237 dword length;
33238 diff --git a/drivers/isdn/hardware/eicon/xdi_adapter.h b/drivers/isdn/hardware/eicon/xdi_adapter.h
33239 index d303e65..28bcb7b 100644
33240 --- a/drivers/isdn/hardware/eicon/xdi_adapter.h
33241 +++ b/drivers/isdn/hardware/eicon/xdi_adapter.h
33242 @@ -44,7 +44,7 @@ typedef struct _xdi_mbox_t {
33243 typedef struct _diva_os_idi_adapter_interface {
33244 diva_init_card_proc_t cleanup_adapter_proc;
33245 diva_cmd_card_proc_t cmd_proc;
33246 -} diva_os_idi_adapter_interface_t;
33247 +} __no_const diva_os_idi_adapter_interface_t;
33248
33249 typedef struct _diva_os_xdi_adapter {
33250 struct list_head link;
33251 diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
33252 index 7bc5067..fd36232 100644
33253 --- a/drivers/isdn/i4l/isdn_tty.c
33254 +++ b/drivers/isdn/i4l/isdn_tty.c
33255 @@ -1505,9 +1505,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
33256 port = &info->port;
33257 #ifdef ISDN_DEBUG_MODEM_OPEN
33258 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
33259 - port->count);
33260 + atomic_read(&port->count))
33261 #endif
33262 - port->count++;
33263 + atomic_inc(&port->count);
33264 tty->driver_data = info;
33265 port->tty = tty;
33266 tty->port = port;
33267 @@ -1553,7 +1553,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
33268 #endif
33269 return;
33270 }
33271 - if ((tty->count == 1) && (port->count != 1)) {
33272 + if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
33273 /*
33274 * Uh, oh. tty->count is 1, which means that the tty
33275 * structure will be freed. Info->count should always
33276 @@ -1562,15 +1562,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
33277 * serial port won't be shutdown.
33278 */
33279 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
33280 - "info->count is %d\n", port->count);
33281 - port->count = 1;
33282 + "info->count is %d\n", atomic_read(&port->count));
33283 + atomic_set(&port->count, 1);
33284 }
33285 - if (--port->count < 0) {
33286 + if (atomic_dec_return(&port->count) < 0) {
33287 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
33288 - info->line, port->count);
33289 - port->count = 0;
33290 + info->line, atomic_read(&port->count));
33291 + atomic_set(&port->count, 0);
33292 }
33293 - if (port->count) {
33294 + if (atomic_read(&port->count)) {
33295 #ifdef ISDN_DEBUG_MODEM_OPEN
33296 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
33297 #endif
33298 @@ -1624,7 +1624,7 @@ isdn_tty_hangup(struct tty_struct *tty)
33299 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
33300 return;
33301 isdn_tty_shutdown(info);
33302 - port->count = 0;
33303 + atomic_set(&port->count, 0);
33304 port->flags &= ~ASYNC_NORMAL_ACTIVE;
33305 port->tty = NULL;
33306 wake_up_interruptible(&port->open_wait);
33307 @@ -1964,7 +1964,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
33308 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
33309 modem_info *info = &dev->mdm.info[i];
33310
33311 - if (info->port.count == 0)
33312 + if (atomic_read(&info->port.count) == 0)
33313 continue;
33314 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
33315 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
33316 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
33317 index e74df7c..03a03ba 100644
33318 --- a/drivers/isdn/icn/icn.c
33319 +++ b/drivers/isdn/icn/icn.c
33320 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
33321 if (count > len)
33322 count = len;
33323 if (user) {
33324 - if (copy_from_user(msg, buf, count))
33325 + if (count > sizeof msg || copy_from_user(msg, buf, count))
33326 return -EFAULT;
33327 } else
33328 memcpy(msg, buf, count);
33329 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
33330 index b5fdcb7..5b6c59f 100644
33331 --- a/drivers/lguest/core.c
33332 +++ b/drivers/lguest/core.c
33333 @@ -92,9 +92,17 @@ static __init int map_switcher(void)
33334 * it's worked so far. The end address needs +1 because __get_vm_area
33335 * allocates an extra guard page, so we need space for that.
33336 */
33337 +
33338 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
33339 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
33340 + VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
33341 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
33342 +#else
33343 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
33344 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
33345 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
33346 +#endif
33347 +
33348 if (!switcher_vma) {
33349 err = -ENOMEM;
33350 printk("lguest: could not map switcher pages high\n");
33351 @@ -119,7 +127,7 @@ static __init int map_switcher(void)
33352 * Now the Switcher is mapped at the right address, we can't fail!
33353 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
33354 */
33355 - memcpy(switcher_vma->addr, start_switcher_text,
33356 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
33357 end_switcher_text - start_switcher_text);
33358
33359 printk(KERN_INFO "lguest: mapped switcher at %p\n",
33360 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
33361 index 39809035..ce25c5e 100644
33362 --- a/drivers/lguest/x86/core.c
33363 +++ b/drivers/lguest/x86/core.c
33364 @@ -59,7 +59,7 @@ static struct {
33365 /* Offset from where switcher.S was compiled to where we've copied it */
33366 static unsigned long switcher_offset(void)
33367 {
33368 - return SWITCHER_ADDR - (unsigned long)start_switcher_text;
33369 + return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
33370 }
33371
33372 /* This cpu's struct lguest_pages. */
33373 @@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
33374 * These copies are pretty cheap, so we do them unconditionally: */
33375 /* Save the current Host top-level page directory.
33376 */
33377 +
33378 +#ifdef CONFIG_PAX_PER_CPU_PGD
33379 + pages->state.host_cr3 = read_cr3();
33380 +#else
33381 pages->state.host_cr3 = __pa(current->mm->pgd);
33382 +#endif
33383 +
33384 /*
33385 * Set up the Guest's page tables to see this CPU's pages (and no
33386 * other CPU's pages).
33387 @@ -472,7 +478,7 @@ void __init lguest_arch_host_init(void)
33388 * compiled-in switcher code and the high-mapped copy we just made.
33389 */
33390 for (i = 0; i < IDT_ENTRIES; i++)
33391 - default_idt_entries[i] += switcher_offset();
33392 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
33393
33394 /*
33395 * Set up the Switcher's per-cpu areas.
33396 @@ -555,7 +561,7 @@ void __init lguest_arch_host_init(void)
33397 * it will be undisturbed when we switch. To change %cs and jump we
33398 * need this structure to feed to Intel's "lcall" instruction.
33399 */
33400 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
33401 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
33402 lguest_entry.segment = LGUEST_CS;
33403
33404 /*
33405 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
33406 index 40634b0..4f5855e 100644
33407 --- a/drivers/lguest/x86/switcher_32.S
33408 +++ b/drivers/lguest/x86/switcher_32.S
33409 @@ -87,6 +87,7 @@
33410 #include <asm/page.h>
33411 #include <asm/segment.h>
33412 #include <asm/lguest.h>
33413 +#include <asm/processor-flags.h>
33414
33415 // We mark the start of the code to copy
33416 // It's placed in .text tho it's never run here
33417 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
33418 // Changes type when we load it: damn Intel!
33419 // For after we switch over our page tables
33420 // That entry will be read-only: we'd crash.
33421 +
33422 +#ifdef CONFIG_PAX_KERNEXEC
33423 + mov %cr0, %edx
33424 + xor $X86_CR0_WP, %edx
33425 + mov %edx, %cr0
33426 +#endif
33427 +
33428 movl $(GDT_ENTRY_TSS*8), %edx
33429 ltr %dx
33430
33431 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
33432 // Let's clear it again for our return.
33433 // The GDT descriptor of the Host
33434 // Points to the table after two "size" bytes
33435 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
33436 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
33437 // Clear "used" from type field (byte 5, bit 2)
33438 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
33439 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
33440 +
33441 +#ifdef CONFIG_PAX_KERNEXEC
33442 + mov %cr0, %eax
33443 + xor $X86_CR0_WP, %eax
33444 + mov %eax, %cr0
33445 +#endif
33446
33447 // Once our page table's switched, the Guest is live!
33448 // The Host fades as we run this final step.
33449 @@ -295,13 +309,12 @@ deliver_to_host:
33450 // I consulted gcc, and it gave
33451 // These instructions, which I gladly credit:
33452 leal (%edx,%ebx,8), %eax
33453 - movzwl (%eax),%edx
33454 - movl 4(%eax), %eax
33455 - xorw %ax, %ax
33456 - orl %eax, %edx
33457 + movl 4(%eax), %edx
33458 + movw (%eax), %dx
33459 // Now the address of the handler's in %edx
33460 // We call it now: its "iret" drops us home.
33461 - jmp *%edx
33462 + ljmp $__KERNEL_CS, $1f
33463 +1: jmp *%edx
33464
33465 // Every interrupt can come to us here
33466 // But we must truly tell each apart.
33467 diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
33468 index 20e5c2c..9e849a9 100644
33469 --- a/drivers/macintosh/macio_asic.c
33470 +++ b/drivers/macintosh/macio_asic.c
33471 @@ -748,7 +748,7 @@ static void __devexit macio_pci_remove(struct pci_dev* pdev)
33472 * MacIO is matched against any Apple ID, it's probe() function
33473 * will then decide wether it applies or not
33474 */
33475 -static const struct pci_device_id __devinitdata pci_ids [] = { {
33476 +static const struct pci_device_id __devinitconst pci_ids [] = { {
33477 .vendor = PCI_VENDOR_ID_APPLE,
33478 .device = PCI_ANY_ID,
33479 .subvendor = PCI_ANY_ID,
33480 diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
33481 index 94e7f6b..2f4a0d8 100644
33482 --- a/drivers/md/bitmap.c
33483 +++ b/drivers/md/bitmap.c
33484 @@ -1786,7 +1786,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
33485 chunk_kb ? "KB" : "B");
33486 if (bitmap->storage.file) {
33487 seq_printf(seq, ", file: ");
33488 - seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
33489 + seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
33490 }
33491
33492 seq_printf(seq, "\n");
33493 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
33494 index afd9598..528d8f9 100644
33495 --- a/drivers/md/dm-ioctl.c
33496 +++ b/drivers/md/dm-ioctl.c
33497 @@ -1593,7 +1593,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
33498 cmd == DM_LIST_VERSIONS_CMD)
33499 return 0;
33500
33501 - if ((cmd == DM_DEV_CREATE_CMD)) {
33502 + if (cmd == DM_DEV_CREATE_CMD) {
33503 if (!*param->name) {
33504 DMWARN("name not supplied when creating device");
33505 return -EINVAL;
33506 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
33507 index bc5ddba8..b961159 100644
33508 --- a/drivers/md/dm-raid1.c
33509 +++ b/drivers/md/dm-raid1.c
33510 @@ -40,7 +40,7 @@ enum dm_raid1_error {
33511
33512 struct mirror {
33513 struct mirror_set *ms;
33514 - atomic_t error_count;
33515 + atomic_unchecked_t error_count;
33516 unsigned long error_type;
33517 struct dm_dev *dev;
33518 sector_t offset;
33519 @@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
33520 struct mirror *m;
33521
33522 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
33523 - if (!atomic_read(&m->error_count))
33524 + if (!atomic_read_unchecked(&m->error_count))
33525 return m;
33526
33527 return NULL;
33528 @@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
33529 * simple way to tell if a device has encountered
33530 * errors.
33531 */
33532 - atomic_inc(&m->error_count);
33533 + atomic_inc_unchecked(&m->error_count);
33534
33535 if (test_and_set_bit(error_type, &m->error_type))
33536 return;
33537 @@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
33538 struct mirror *m = get_default_mirror(ms);
33539
33540 do {
33541 - if (likely(!atomic_read(&m->error_count)))
33542 + if (likely(!atomic_read_unchecked(&m->error_count)))
33543 return m;
33544
33545 if (m-- == ms->mirror)
33546 @@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
33547 {
33548 struct mirror *default_mirror = get_default_mirror(m->ms);
33549
33550 - return !atomic_read(&default_mirror->error_count);
33551 + return !atomic_read_unchecked(&default_mirror->error_count);
33552 }
33553
33554 static int mirror_available(struct mirror_set *ms, struct bio *bio)
33555 @@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
33556 */
33557 if (likely(region_in_sync(ms, region, 1)))
33558 m = choose_mirror(ms, bio->bi_sector);
33559 - else if (m && atomic_read(&m->error_count))
33560 + else if (m && atomic_read_unchecked(&m->error_count))
33561 m = NULL;
33562
33563 if (likely(m))
33564 @@ -938,7 +938,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
33565 }
33566
33567 ms->mirror[mirror].ms = ms;
33568 - atomic_set(&(ms->mirror[mirror].error_count), 0);
33569 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
33570 ms->mirror[mirror].error_type = 0;
33571 ms->mirror[mirror].offset = offset;
33572
33573 @@ -1356,7 +1356,7 @@ static void mirror_resume(struct dm_target *ti)
33574 */
33575 static char device_status_char(struct mirror *m)
33576 {
33577 - if (!atomic_read(&(m->error_count)))
33578 + if (!atomic_read_unchecked(&(m->error_count)))
33579 return 'A';
33580
33581 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
33582 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
33583 index a087bf2..4c94786 100644
33584 --- a/drivers/md/dm-stripe.c
33585 +++ b/drivers/md/dm-stripe.c
33586 @@ -20,7 +20,7 @@ struct stripe {
33587 struct dm_dev *dev;
33588 sector_t physical_start;
33589
33590 - atomic_t error_count;
33591 + atomic_unchecked_t error_count;
33592 };
33593
33594 struct stripe_c {
33595 @@ -183,7 +183,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
33596 kfree(sc);
33597 return r;
33598 }
33599 - atomic_set(&(sc->stripe[i].error_count), 0);
33600 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
33601 }
33602
33603 ti->private = sc;
33604 @@ -324,7 +324,7 @@ static int stripe_status(struct dm_target *ti, status_type_t type,
33605 DMEMIT("%d ", sc->stripes);
33606 for (i = 0; i < sc->stripes; i++) {
33607 DMEMIT("%s ", sc->stripe[i].dev->name);
33608 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
33609 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
33610 'D' : 'A';
33611 }
33612 buffer[i] = '\0';
33613 @@ -371,8 +371,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
33614 */
33615 for (i = 0; i < sc->stripes; i++)
33616 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
33617 - atomic_inc(&(sc->stripe[i].error_count));
33618 - if (atomic_read(&(sc->stripe[i].error_count)) <
33619 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
33620 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
33621 DM_IO_ERROR_THRESHOLD)
33622 schedule_work(&sc->trigger_event);
33623 }
33624 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
33625 index 100368e..64262ce 100644
33626 --- a/drivers/md/dm-table.c
33627 +++ b/drivers/md/dm-table.c
33628 @@ -390,7 +390,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
33629 if (!dev_size)
33630 return 0;
33631
33632 - if ((start >= dev_size) || (start + len > dev_size)) {
33633 + if ((start >= dev_size) || (len > dev_size - start)) {
33634 DMWARN("%s: %s too small for target: "
33635 "start=%llu, len=%llu, dev_size=%llu",
33636 dm_device_name(ti->table->md), bdevname(bdev, b),
33637 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
33638 index 693e149..b7e0fde 100644
33639 --- a/drivers/md/dm-thin-metadata.c
33640 +++ b/drivers/md/dm-thin-metadata.c
33641 @@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
33642 {
33643 pmd->info.tm = pmd->tm;
33644 pmd->info.levels = 2;
33645 - pmd->info.value_type.context = pmd->data_sm;
33646 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33647 pmd->info.value_type.size = sizeof(__le64);
33648 pmd->info.value_type.inc = data_block_inc;
33649 pmd->info.value_type.dec = data_block_dec;
33650 @@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
33651
33652 pmd->bl_info.tm = pmd->tm;
33653 pmd->bl_info.levels = 1;
33654 - pmd->bl_info.value_type.context = pmd->data_sm;
33655 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33656 pmd->bl_info.value_type.size = sizeof(__le64);
33657 pmd->bl_info.value_type.inc = data_block_inc;
33658 pmd->bl_info.value_type.dec = data_block_dec;
33659 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
33660 index 67ffa39..cb3b1dd 100644
33661 --- a/drivers/md/dm.c
33662 +++ b/drivers/md/dm.c
33663 @@ -176,9 +176,9 @@ struct mapped_device {
33664 /*
33665 * Event handling.
33666 */
33667 - atomic_t event_nr;
33668 + atomic_unchecked_t event_nr;
33669 wait_queue_head_t eventq;
33670 - atomic_t uevent_seq;
33671 + atomic_unchecked_t uevent_seq;
33672 struct list_head uevent_list;
33673 spinlock_t uevent_lock; /* Protect access to uevent_list */
33674
33675 @@ -1887,8 +1887,8 @@ static struct mapped_device *alloc_dev(int minor)
33676 rwlock_init(&md->map_lock);
33677 atomic_set(&md->holders, 1);
33678 atomic_set(&md->open_count, 0);
33679 - atomic_set(&md->event_nr, 0);
33680 - atomic_set(&md->uevent_seq, 0);
33681 + atomic_set_unchecked(&md->event_nr, 0);
33682 + atomic_set_unchecked(&md->uevent_seq, 0);
33683 INIT_LIST_HEAD(&md->uevent_list);
33684 spin_lock_init(&md->uevent_lock);
33685
33686 @@ -2022,7 +2022,7 @@ static void event_callback(void *context)
33687
33688 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
33689
33690 - atomic_inc(&md->event_nr);
33691 + atomic_inc_unchecked(&md->event_nr);
33692 wake_up(&md->eventq);
33693 }
33694
33695 @@ -2677,18 +2677,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
33696
33697 uint32_t dm_next_uevent_seq(struct mapped_device *md)
33698 {
33699 - return atomic_add_return(1, &md->uevent_seq);
33700 + return atomic_add_return_unchecked(1, &md->uevent_seq);
33701 }
33702
33703 uint32_t dm_get_event_nr(struct mapped_device *md)
33704 {
33705 - return atomic_read(&md->event_nr);
33706 + return atomic_read_unchecked(&md->event_nr);
33707 }
33708
33709 int dm_wait_event(struct mapped_device *md, int event_nr)
33710 {
33711 return wait_event_interruptible(md->eventq,
33712 - (event_nr != atomic_read(&md->event_nr)));
33713 + (event_nr != atomic_read_unchecked(&md->event_nr)));
33714 }
33715
33716 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
33717 diff --git a/drivers/md/md.c b/drivers/md/md.c
33718 index 308e87b..7f365d6 100644
33719 --- a/drivers/md/md.c
33720 +++ b/drivers/md/md.c
33721 @@ -277,10 +277,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
33722 * start build, activate spare
33723 */
33724 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
33725 -static atomic_t md_event_count;
33726 +static atomic_unchecked_t md_event_count;
33727 void md_new_event(struct mddev *mddev)
33728 {
33729 - atomic_inc(&md_event_count);
33730 + atomic_inc_unchecked(&md_event_count);
33731 wake_up(&md_event_waiters);
33732 }
33733 EXPORT_SYMBOL_GPL(md_new_event);
33734 @@ -290,7 +290,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
33735 */
33736 static void md_new_event_inintr(struct mddev *mddev)
33737 {
33738 - atomic_inc(&md_event_count);
33739 + atomic_inc_unchecked(&md_event_count);
33740 wake_up(&md_event_waiters);
33741 }
33742
33743 @@ -1519,7 +1519,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
33744 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
33745 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
33746 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
33747 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33748 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33749
33750 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
33751 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
33752 @@ -1763,7 +1763,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
33753 else
33754 sb->resync_offset = cpu_to_le64(0);
33755
33756 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
33757 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
33758
33759 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
33760 sb->size = cpu_to_le64(mddev->dev_sectors);
33761 @@ -2757,7 +2757,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
33762 static ssize_t
33763 errors_show(struct md_rdev *rdev, char *page)
33764 {
33765 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
33766 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
33767 }
33768
33769 static ssize_t
33770 @@ -2766,7 +2766,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
33771 char *e;
33772 unsigned long n = simple_strtoul(buf, &e, 10);
33773 if (*buf && (*e == 0 || *e == '\n')) {
33774 - atomic_set(&rdev->corrected_errors, n);
33775 + atomic_set_unchecked(&rdev->corrected_errors, n);
33776 return len;
33777 }
33778 return -EINVAL;
33779 @@ -3213,8 +3213,8 @@ int md_rdev_init(struct md_rdev *rdev)
33780 rdev->sb_loaded = 0;
33781 rdev->bb_page = NULL;
33782 atomic_set(&rdev->nr_pending, 0);
33783 - atomic_set(&rdev->read_errors, 0);
33784 - atomic_set(&rdev->corrected_errors, 0);
33785 + atomic_set_unchecked(&rdev->read_errors, 0);
33786 + atomic_set_unchecked(&rdev->corrected_errors, 0);
33787
33788 INIT_LIST_HEAD(&rdev->same_set);
33789 init_waitqueue_head(&rdev->blocked_wait);
33790 @@ -6947,7 +6947,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
33791
33792 spin_unlock(&pers_lock);
33793 seq_printf(seq, "\n");
33794 - seq->poll_event = atomic_read(&md_event_count);
33795 + seq->poll_event = atomic_read_unchecked(&md_event_count);
33796 return 0;
33797 }
33798 if (v == (void*)2) {
33799 @@ -7050,7 +7050,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
33800 return error;
33801
33802 seq = file->private_data;
33803 - seq->poll_event = atomic_read(&md_event_count);
33804 + seq->poll_event = atomic_read_unchecked(&md_event_count);
33805 return error;
33806 }
33807
33808 @@ -7064,7 +7064,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
33809 /* always allow read */
33810 mask = POLLIN | POLLRDNORM;
33811
33812 - if (seq->poll_event != atomic_read(&md_event_count))
33813 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
33814 mask |= POLLERR | POLLPRI;
33815 return mask;
33816 }
33817 @@ -7108,7 +7108,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
33818 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
33819 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
33820 (int)part_stat_read(&disk->part0, sectors[1]) -
33821 - atomic_read(&disk->sync_io);
33822 + atomic_read_unchecked(&disk->sync_io);
33823 /* sync IO will cause sync_io to increase before the disk_stats
33824 * as sync_io is counted when a request starts, and
33825 * disk_stats is counted when it completes.
33826 diff --git a/drivers/md/md.h b/drivers/md/md.h
33827 index f385b03..b600be8 100644
33828 --- a/drivers/md/md.h
33829 +++ b/drivers/md/md.h
33830 @@ -94,13 +94,13 @@ struct md_rdev {
33831 * only maintained for arrays that
33832 * support hot removal
33833 */
33834 - atomic_t read_errors; /* number of consecutive read errors that
33835 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
33836 * we have tried to ignore.
33837 */
33838 struct timespec last_read_error; /* monotonic time since our
33839 * last read error
33840 */
33841 - atomic_t corrected_errors; /* number of corrected read errors,
33842 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
33843 * for reporting to userspace and storing
33844 * in superblock.
33845 */
33846 @@ -432,7 +432,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
33847
33848 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
33849 {
33850 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33851 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33852 }
33853
33854 struct md_personality
33855 diff --git a/drivers/md/persistent-data/dm-space-map-disk.c b/drivers/md/persistent-data/dm-space-map-disk.c
33856 index f6d29e6..7917f5e 100644
33857 --- a/drivers/md/persistent-data/dm-space-map-disk.c
33858 +++ b/drivers/md/persistent-data/dm-space-map-disk.c
33859 @@ -22,7 +22,7 @@
33860 * Space map interface.
33861 */
33862 struct sm_disk {
33863 - struct dm_space_map sm;
33864 + dm_space_map_no_const sm;
33865
33866 struct ll_disk ll;
33867 struct ll_disk old_ll;
33868 diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
33869 index e89ae5e..062e4c2 100644
33870 --- a/drivers/md/persistent-data/dm-space-map-metadata.c
33871 +++ b/drivers/md/persistent-data/dm-space-map-metadata.c
33872 @@ -43,7 +43,7 @@ struct block_op {
33873 };
33874
33875 struct sm_metadata {
33876 - struct dm_space_map sm;
33877 + dm_space_map_no_const sm;
33878
33879 struct ll_disk ll;
33880 struct ll_disk old_ll;
33881 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
33882 index 1cbfc6b..56e1dbb 100644
33883 --- a/drivers/md/persistent-data/dm-space-map.h
33884 +++ b/drivers/md/persistent-data/dm-space-map.h
33885 @@ -60,6 +60,7 @@ struct dm_space_map {
33886 int (*root_size)(struct dm_space_map *sm, size_t *result);
33887 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
33888 };
33889 +typedef struct dm_space_map __no_const dm_space_map_no_const;
33890
33891 /*----------------------------------------------------------------*/
33892
33893 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
33894 index 05bb49e..84d7ce6 100644
33895 --- a/drivers/md/raid1.c
33896 +++ b/drivers/md/raid1.c
33897 @@ -1810,7 +1810,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
33898 if (r1_sync_page_io(rdev, sect, s,
33899 bio->bi_io_vec[idx].bv_page,
33900 READ) != 0)
33901 - atomic_add(s, &rdev->corrected_errors);
33902 + atomic_add_unchecked(s, &rdev->corrected_errors);
33903 }
33904 sectors -= s;
33905 sect += s;
33906 @@ -2032,7 +2032,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
33907 test_bit(In_sync, &rdev->flags)) {
33908 if (r1_sync_page_io(rdev, sect, s,
33909 conf->tmppage, READ)) {
33910 - atomic_add(s, &rdev->corrected_errors);
33911 + atomic_add_unchecked(s, &rdev->corrected_errors);
33912 printk(KERN_INFO
33913 "md/raid1:%s: read error corrected "
33914 "(%d sectors at %llu on %s)\n",
33915 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
33916 index a48c215..6bda6f4 100644
33917 --- a/drivers/md/raid10.c
33918 +++ b/drivers/md/raid10.c
33919 @@ -1810,7 +1810,7 @@ static void end_sync_read(struct bio *bio, int error)
33920 /* The write handler will notice the lack of
33921 * R10BIO_Uptodate and record any errors etc
33922 */
33923 - atomic_add(r10_bio->sectors,
33924 + atomic_add_unchecked(r10_bio->sectors,
33925 &conf->mirrors[d].rdev->corrected_errors);
33926
33927 /* for reconstruct, we always reschedule after a read.
33928 @@ -2159,7 +2159,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33929 {
33930 struct timespec cur_time_mon;
33931 unsigned long hours_since_last;
33932 - unsigned int read_errors = atomic_read(&rdev->read_errors);
33933 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
33934
33935 ktime_get_ts(&cur_time_mon);
33936
33937 @@ -2181,9 +2181,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33938 * overflowing the shift of read_errors by hours_since_last.
33939 */
33940 if (hours_since_last >= 8 * sizeof(read_errors))
33941 - atomic_set(&rdev->read_errors, 0);
33942 + atomic_set_unchecked(&rdev->read_errors, 0);
33943 else
33944 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
33945 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
33946 }
33947
33948 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
33949 @@ -2237,8 +2237,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33950 return;
33951
33952 check_decay_read_errors(mddev, rdev);
33953 - atomic_inc(&rdev->read_errors);
33954 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
33955 + atomic_inc_unchecked(&rdev->read_errors);
33956 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
33957 char b[BDEVNAME_SIZE];
33958 bdevname(rdev->bdev, b);
33959
33960 @@ -2246,7 +2246,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33961 "md/raid10:%s: %s: Raid device exceeded "
33962 "read_error threshold [cur %d:max %d]\n",
33963 mdname(mddev), b,
33964 - atomic_read(&rdev->read_errors), max_read_errors);
33965 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
33966 printk(KERN_NOTICE
33967 "md/raid10:%s: %s: Failing raid device\n",
33968 mdname(mddev), b);
33969 @@ -2401,7 +2401,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33970 sect +
33971 choose_data_offset(r10_bio, rdev)),
33972 bdevname(rdev->bdev, b));
33973 - atomic_add(s, &rdev->corrected_errors);
33974 + atomic_add_unchecked(s, &rdev->corrected_errors);
33975 }
33976
33977 rdev_dec_pending(rdev, mddev);
33978 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
33979 index 0689173..35df76c 100644
33980 --- a/drivers/md/raid5.c
33981 +++ b/drivers/md/raid5.c
33982 @@ -1756,21 +1756,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
33983 mdname(conf->mddev), STRIPE_SECTORS,
33984 (unsigned long long)s,
33985 bdevname(rdev->bdev, b));
33986 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
33987 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
33988 clear_bit(R5_ReadError, &sh->dev[i].flags);
33989 clear_bit(R5_ReWrite, &sh->dev[i].flags);
33990 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
33991 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
33992
33993 - if (atomic_read(&rdev->read_errors))
33994 - atomic_set(&rdev->read_errors, 0);
33995 + if (atomic_read_unchecked(&rdev->read_errors))
33996 + atomic_set_unchecked(&rdev->read_errors, 0);
33997 } else {
33998 const char *bdn = bdevname(rdev->bdev, b);
33999 int retry = 0;
34000 int set_bad = 0;
34001
34002 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
34003 - atomic_inc(&rdev->read_errors);
34004 + atomic_inc_unchecked(&rdev->read_errors);
34005 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
34006 printk_ratelimited(
34007 KERN_WARNING
34008 @@ -1798,7 +1798,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
34009 mdname(conf->mddev),
34010 (unsigned long long)s,
34011 bdn);
34012 - } else if (atomic_read(&rdev->read_errors)
34013 + } else if (atomic_read_unchecked(&rdev->read_errors)
34014 > conf->max_nr_stripes)
34015 printk(KERN_WARNING
34016 "md/raid:%s: Too many read errors, failing device %s.\n",
34017 diff --git a/drivers/media/dvb/ddbridge/ddbridge-core.c b/drivers/media/dvb/ddbridge/ddbridge-core.c
34018 index ebf3f05..b1f3e77 100644
34019 --- a/drivers/media/dvb/ddbridge/ddbridge-core.c
34020 +++ b/drivers/media/dvb/ddbridge/ddbridge-core.c
34021 @@ -1679,7 +1679,7 @@ static struct ddb_info ddb_v6 = {
34022 .subvendor = _subvend, .subdevice = _subdev, \
34023 .driver_data = (unsigned long)&_driverdata }
34024
34025 -static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
34026 +static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
34027 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
34028 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
34029 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
34030 diff --git a/drivers/media/dvb/dvb-core/dvb_demux.h b/drivers/media/dvb/dvb-core/dvb_demux.h
34031 index fa7188a..04a045e 100644
34032 --- a/drivers/media/dvb/dvb-core/dvb_demux.h
34033 +++ b/drivers/media/dvb/dvb-core/dvb_demux.h
34034 @@ -73,7 +73,7 @@ struct dvb_demux_feed {
34035 union {
34036 dmx_ts_cb ts;
34037 dmx_section_cb sec;
34038 - } cb;
34039 + } __no_const cb;
34040
34041 struct dvb_demux *demux;
34042 void *priv;
34043 diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
34044 index 39eab73..60033e7 100644
34045 --- a/drivers/media/dvb/dvb-core/dvbdev.c
34046 +++ b/drivers/media/dvb/dvb-core/dvbdev.c
34047 @@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
34048 const struct dvb_device *template, void *priv, int type)
34049 {
34050 struct dvb_device *dvbdev;
34051 - struct file_operations *dvbdevfops;
34052 + file_operations_no_const *dvbdevfops;
34053 struct device *clsdev;
34054 int minor;
34055 int id;
34056 diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
34057 index 3940bb0..fb3952a 100644
34058 --- a/drivers/media/dvb/dvb-usb/cxusb.c
34059 +++ b/drivers/media/dvb/dvb-usb/cxusb.c
34060 @@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
34061
34062 struct dib0700_adapter_state {
34063 int (*set_param_save) (struct dvb_frontend *);
34064 -};
34065 +} __no_const;
34066
34067 static int dib7070_set_param_override(struct dvb_frontend *fe)
34068 {
34069 diff --git a/drivers/media/dvb/dvb-usb/dw2102.c b/drivers/media/dvb/dvb-usb/dw2102.c
34070 index 9382895..ac8093c 100644
34071 --- a/drivers/media/dvb/dvb-usb/dw2102.c
34072 +++ b/drivers/media/dvb/dvb-usb/dw2102.c
34073 @@ -95,7 +95,7 @@ struct su3000_state {
34074
34075 struct s6x0_state {
34076 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
34077 -};
34078 +} __no_const;
34079
34080 /* debug */
34081 static int dvb_usb_dw2102_debug;
34082 diff --git a/drivers/media/dvb/frontends/dib3000.h b/drivers/media/dvb/frontends/dib3000.h
34083 index 404f63a..4796533 100644
34084 --- a/drivers/media/dvb/frontends/dib3000.h
34085 +++ b/drivers/media/dvb/frontends/dib3000.h
34086 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
34087 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
34088 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
34089 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
34090 -};
34091 +} __no_const;
34092
34093 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
34094 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
34095 diff --git a/drivers/media/dvb/ngene/ngene-cards.c b/drivers/media/dvb/ngene/ngene-cards.c
34096 index 72ee8de..eae0c80 100644
34097 --- a/drivers/media/dvb/ngene/ngene-cards.c
34098 +++ b/drivers/media/dvb/ngene/ngene-cards.c
34099 @@ -479,7 +479,7 @@ static struct ngene_info ngene_info_m780 = {
34100
34101 /****************************************************************************/
34102
34103 -static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
34104 +static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
34105 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
34106 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
34107 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
34108 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
34109 index 697a421..16c5a5f 100644
34110 --- a/drivers/media/radio/radio-cadet.c
34111 +++ b/drivers/media/radio/radio-cadet.c
34112 @@ -302,6 +302,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
34113 unsigned char readbuf[RDS_BUFFER];
34114 int i = 0;
34115
34116 + if (count > RDS_BUFFER)
34117 + return -EFAULT;
34118 mutex_lock(&dev->lock);
34119 if (dev->rdsstat == 0)
34120 cadet_start_rds(dev);
34121 @@ -317,7 +319,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
34122 while (i < count && dev->rdsin != dev->rdsout)
34123 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
34124
34125 - if (i && copy_to_user(data, readbuf, i))
34126 + if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
34127 i = -EFAULT;
34128 unlock:
34129 mutex_unlock(&dev->lock);
34130 diff --git a/drivers/media/radio/radio-tea5777.h b/drivers/media/radio/radio-tea5777.h
34131 index 55cbd78..428b0da 100644
34132 --- a/drivers/media/radio/radio-tea5777.h
34133 +++ b/drivers/media/radio/radio-tea5777.h
34134 @@ -63,7 +63,7 @@ struct radio_tea5777_ops {
34135
34136 struct radio_tea5777 {
34137 struct v4l2_device *v4l2_dev;
34138 - struct v4l2_file_operations fops;
34139 + v4l2_file_operations_no_const fops;
34140 struct video_device vd; /* video device */
34141 bool has_am; /* Device can tune to AM freqs */
34142 bool write_before_read; /* must write before read quirk */
34143 diff --git a/drivers/media/video/au0828/au0828.h b/drivers/media/video/au0828/au0828.h
34144 index 9cde353..8c6a1c3 100644
34145 --- a/drivers/media/video/au0828/au0828.h
34146 +++ b/drivers/media/video/au0828/au0828.h
34147 @@ -191,7 +191,7 @@ struct au0828_dev {
34148
34149 /* I2C */
34150 struct i2c_adapter i2c_adap;
34151 - struct i2c_algorithm i2c_algo;
34152 + i2c_algorithm_no_const i2c_algo;
34153 struct i2c_client i2c_client;
34154 u32 i2c_rc;
34155
34156 diff --git a/drivers/media/video/cx88/cx88-alsa.c b/drivers/media/video/cx88/cx88-alsa.c
34157 index dfac6e3..c26de31 100644
34158 --- a/drivers/media/video/cx88/cx88-alsa.c
34159 +++ b/drivers/media/video/cx88/cx88-alsa.c
34160 @@ -749,7 +749,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
34161 * Only boards with eeprom and byte 1 at eeprom=1 have it
34162 */
34163
34164 -static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitdata = {
34165 +static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitconst = {
34166 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
34167 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
34168 {0, }
34169 diff --git a/drivers/media/video/omap/omap_vout.c b/drivers/media/video/omap/omap_vout.c
34170 index 88cf9d9..bbc4b2c 100644
34171 --- a/drivers/media/video/omap/omap_vout.c
34172 +++ b/drivers/media/video/omap/omap_vout.c
34173 @@ -64,7 +64,6 @@ enum omap_vout_channels {
34174 OMAP_VIDEO2,
34175 };
34176
34177 -static struct videobuf_queue_ops video_vbq_ops;
34178 /* Variables configurable through module params*/
34179 static u32 video1_numbuffers = 3;
34180 static u32 video2_numbuffers = 3;
34181 @@ -1000,6 +999,12 @@ static int omap_vout_open(struct file *file)
34182 {
34183 struct videobuf_queue *q;
34184 struct omap_vout_device *vout = NULL;
34185 + static struct videobuf_queue_ops video_vbq_ops = {
34186 + .buf_setup = omap_vout_buffer_setup,
34187 + .buf_prepare = omap_vout_buffer_prepare,
34188 + .buf_release = omap_vout_buffer_release,
34189 + .buf_queue = omap_vout_buffer_queue,
34190 + };
34191
34192 vout = video_drvdata(file);
34193 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
34194 @@ -1017,10 +1022,6 @@ static int omap_vout_open(struct file *file)
34195 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
34196
34197 q = &vout->vbq;
34198 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
34199 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
34200 - video_vbq_ops.buf_release = omap_vout_buffer_release;
34201 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
34202 spin_lock_init(&vout->vbq_lock);
34203
34204 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
34205 diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34206 index 036952f..80d356d 100644
34207 --- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34208 +++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34209 @@ -196,7 +196,7 @@ struct pvr2_hdw {
34210
34211 /* I2C stuff */
34212 struct i2c_adapter i2c_adap;
34213 - struct i2c_algorithm i2c_algo;
34214 + i2c_algorithm_no_const i2c_algo;
34215 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
34216 int i2c_cx25840_hack_state;
34217 int i2c_linked;
34218 diff --git a/drivers/media/video/timblogiw.c b/drivers/media/video/timblogiw.c
34219 index 02194c0..091733b 100644
34220 --- a/drivers/media/video/timblogiw.c
34221 +++ b/drivers/media/video/timblogiw.c
34222 @@ -745,7 +745,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
34223
34224 /* Platform device functions */
34225
34226 -static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
34227 +static __devinitconst v4l2_ioctl_ops_no_const timblogiw_ioctl_ops = {
34228 .vidioc_querycap = timblogiw_querycap,
34229 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
34230 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
34231 @@ -767,7 +767,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
34232 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
34233 };
34234
34235 -static __devinitconst struct v4l2_file_operations timblogiw_fops = {
34236 +static __devinitconst v4l2_file_operations_no_const timblogiw_fops = {
34237 .owner = THIS_MODULE,
34238 .open = timblogiw_open,
34239 .release = timblogiw_close,
34240 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
34241 index d99db56..a16b959 100644
34242 --- a/drivers/message/fusion/mptbase.c
34243 +++ b/drivers/message/fusion/mptbase.c
34244 @@ -6751,8 +6751,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
34245 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
34246 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
34247
34248 +#ifdef CONFIG_GRKERNSEC_HIDESYM
34249 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
34250 +#else
34251 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
34252 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
34253 +#endif
34254 +
34255 /*
34256 * Rounding UP to nearest 4-kB boundary here...
34257 */
34258 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
34259 index 551262e..7551198 100644
34260 --- a/drivers/message/fusion/mptsas.c
34261 +++ b/drivers/message/fusion/mptsas.c
34262 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
34263 return 0;
34264 }
34265
34266 +static inline void
34267 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
34268 +{
34269 + if (phy_info->port_details) {
34270 + phy_info->port_details->rphy = rphy;
34271 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
34272 + ioc->name, rphy));
34273 + }
34274 +
34275 + if (rphy) {
34276 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
34277 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
34278 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
34279 + ioc->name, rphy, rphy->dev.release));
34280 + }
34281 +}
34282 +
34283 /* no mutex */
34284 static void
34285 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
34286 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
34287 return NULL;
34288 }
34289
34290 -static inline void
34291 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
34292 -{
34293 - if (phy_info->port_details) {
34294 - phy_info->port_details->rphy = rphy;
34295 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
34296 - ioc->name, rphy));
34297 - }
34298 -
34299 - if (rphy) {
34300 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
34301 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
34302 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
34303 - ioc->name, rphy, rphy->dev.release));
34304 - }
34305 -}
34306 -
34307 static inline struct sas_port *
34308 mptsas_get_port(struct mptsas_phyinfo *phy_info)
34309 {
34310 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
34311 index 0c3ced7..1fe34ec 100644
34312 --- a/drivers/message/fusion/mptscsih.c
34313 +++ b/drivers/message/fusion/mptscsih.c
34314 @@ -1270,15 +1270,16 @@ mptscsih_info(struct Scsi_Host *SChost)
34315
34316 h = shost_priv(SChost);
34317
34318 - if (h) {
34319 - if (h->info_kbuf == NULL)
34320 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34321 - return h->info_kbuf;
34322 - h->info_kbuf[0] = '\0';
34323 + if (!h)
34324 + return NULL;
34325
34326 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34327 - h->info_kbuf[size-1] = '\0';
34328 - }
34329 + if (h->info_kbuf == NULL)
34330 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34331 + return h->info_kbuf;
34332 + h->info_kbuf[0] = '\0';
34333 +
34334 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34335 + h->info_kbuf[size-1] = '\0';
34336
34337 return h->info_kbuf;
34338 }
34339 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
34340 index 8001aa6..b137580 100644
34341 --- a/drivers/message/i2o/i2o_proc.c
34342 +++ b/drivers/message/i2o/i2o_proc.c
34343 @@ -255,12 +255,6 @@ static char *scsi_devices[] = {
34344 "Array Controller Device"
34345 };
34346
34347 -static char *chtostr(char *tmp, u8 *chars, int n)
34348 -{
34349 - tmp[0] = 0;
34350 - return strncat(tmp, (char *)chars, n);
34351 -}
34352 -
34353 static int i2o_report_query_status(struct seq_file *seq, int block_status,
34354 char *group)
34355 {
34356 @@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
34357 } *result;
34358
34359 i2o_exec_execute_ddm_table ddm_table;
34360 - char tmp[28 + 1];
34361
34362 result = kmalloc(sizeof(*result), GFP_KERNEL);
34363 if (!result)
34364 @@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
34365
34366 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
34367 seq_printf(seq, "%-#8x", ddm_table.module_id);
34368 - seq_printf(seq, "%-29s",
34369 - chtostr(tmp, ddm_table.module_name_version, 28));
34370 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
34371 seq_printf(seq, "%9d ", ddm_table.data_size);
34372 seq_printf(seq, "%8d", ddm_table.code_size);
34373
34374 @@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
34375
34376 i2o_driver_result_table *result;
34377 i2o_driver_store_table *dst;
34378 - char tmp[28 + 1];
34379
34380 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
34381 if (result == NULL)
34382 @@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
34383
34384 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
34385 seq_printf(seq, "%-#8x", dst->module_id);
34386 - seq_printf(seq, "%-29s",
34387 - chtostr(tmp, dst->module_name_version, 28));
34388 - seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
34389 + seq_printf(seq, "%-.28s", dst->module_name_version);
34390 + seq_printf(seq, "%-.8s", dst->date);
34391 seq_printf(seq, "%8d ", dst->module_size);
34392 seq_printf(seq, "%8d ", dst->mpb_size);
34393 seq_printf(seq, "0x%04x", dst->module_flags);
34394 @@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
34395 // == (allow) 512d bytes (max)
34396 static u16 *work16 = (u16 *) work32;
34397 int token;
34398 - char tmp[16 + 1];
34399
34400 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
34401
34402 @@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
34403 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
34404 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
34405 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
34406 - seq_printf(seq, "Vendor info : %s\n",
34407 - chtostr(tmp, (u8 *) (work32 + 2), 16));
34408 - seq_printf(seq, "Product info : %s\n",
34409 - chtostr(tmp, (u8 *) (work32 + 6), 16));
34410 - seq_printf(seq, "Description : %s\n",
34411 - chtostr(tmp, (u8 *) (work32 + 10), 16));
34412 - seq_printf(seq, "Product rev. : %s\n",
34413 - chtostr(tmp, (u8 *) (work32 + 14), 8));
34414 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
34415 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
34416 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
34417 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
34418
34419 seq_printf(seq, "Serial number : ");
34420 print_serial_number(seq, (u8 *) (work32 + 16),
34421 @@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
34422 u8 pad[256]; // allow up to 256 byte (max) serial number
34423 } result;
34424
34425 - char tmp[24 + 1];
34426 -
34427 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
34428
34429 if (token < 0) {
34430 @@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
34431 }
34432
34433 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
34434 - seq_printf(seq, "Module name : %s\n",
34435 - chtostr(tmp, result.module_name, 24));
34436 - seq_printf(seq, "Module revision : %s\n",
34437 - chtostr(tmp, result.module_rev, 8));
34438 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
34439 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
34440
34441 seq_printf(seq, "Serial number : ");
34442 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
34443 @@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
34444 u8 instance_number[4];
34445 } result;
34446
34447 - char tmp[64 + 1];
34448 -
34449 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
34450
34451 if (token < 0) {
34452 @@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
34453 return 0;
34454 }
34455
34456 - seq_printf(seq, "Device name : %s\n",
34457 - chtostr(tmp, result.device_name, 64));
34458 - seq_printf(seq, "Service name : %s\n",
34459 - chtostr(tmp, result.service_name, 64));
34460 - seq_printf(seq, "Physical name : %s\n",
34461 - chtostr(tmp, result.physical_location, 64));
34462 - seq_printf(seq, "Instance number : %s\n",
34463 - chtostr(tmp, result.instance_number, 4));
34464 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
34465 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
34466 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
34467 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
34468
34469 return 0;
34470 }
34471 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
34472 index a8c08f3..155fe3d 100644
34473 --- a/drivers/message/i2o/iop.c
34474 +++ b/drivers/message/i2o/iop.c
34475 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
34476
34477 spin_lock_irqsave(&c->context_list_lock, flags);
34478
34479 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
34480 - atomic_inc(&c->context_list_counter);
34481 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
34482 + atomic_inc_unchecked(&c->context_list_counter);
34483
34484 - entry->context = atomic_read(&c->context_list_counter);
34485 + entry->context = atomic_read_unchecked(&c->context_list_counter);
34486
34487 list_add(&entry->list, &c->context_list);
34488
34489 @@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
34490
34491 #if BITS_PER_LONG == 64
34492 spin_lock_init(&c->context_list_lock);
34493 - atomic_set(&c->context_list_counter, 0);
34494 + atomic_set_unchecked(&c->context_list_counter, 0);
34495 INIT_LIST_HEAD(&c->context_list);
34496 #endif
34497
34498 diff --git a/drivers/mfd/abx500-core.c b/drivers/mfd/abx500-core.c
34499 index 7ce65f4..e66e9bc 100644
34500 --- a/drivers/mfd/abx500-core.c
34501 +++ b/drivers/mfd/abx500-core.c
34502 @@ -15,7 +15,7 @@ static LIST_HEAD(abx500_list);
34503
34504 struct abx500_device_entry {
34505 struct list_head list;
34506 - struct abx500_ops ops;
34507 + abx500_ops_no_const ops;
34508 struct device *dev;
34509 };
34510
34511 diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
34512 index 965c480..71f2db9 100644
34513 --- a/drivers/mfd/janz-cmodio.c
34514 +++ b/drivers/mfd/janz-cmodio.c
34515 @@ -13,6 +13,7 @@
34516
34517 #include <linux/kernel.h>
34518 #include <linux/module.h>
34519 +#include <linux/slab.h>
34520 #include <linux/init.h>
34521 #include <linux/pci.h>
34522 #include <linux/interrupt.h>
34523 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
34524 index a981e2a..5ca0c8b 100644
34525 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
34526 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
34527 @@ -466,7 +466,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
34528 * the lid is closed. This leads to interrupts as soon as a little move
34529 * is done.
34530 */
34531 - atomic_inc(&lis3->count);
34532 + atomic_inc_unchecked(&lis3->count);
34533
34534 wake_up_interruptible(&lis3->misc_wait);
34535 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
34536 @@ -552,7 +552,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
34537 if (lis3->pm_dev)
34538 pm_runtime_get_sync(lis3->pm_dev);
34539
34540 - atomic_set(&lis3->count, 0);
34541 + atomic_set_unchecked(&lis3->count, 0);
34542 return 0;
34543 }
34544
34545 @@ -585,7 +585,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
34546 add_wait_queue(&lis3->misc_wait, &wait);
34547 while (true) {
34548 set_current_state(TASK_INTERRUPTIBLE);
34549 - data = atomic_xchg(&lis3->count, 0);
34550 + data = atomic_xchg_unchecked(&lis3->count, 0);
34551 if (data)
34552 break;
34553
34554 @@ -626,7 +626,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
34555 struct lis3lv02d, miscdev);
34556
34557 poll_wait(file, &lis3->misc_wait, wait);
34558 - if (atomic_read(&lis3->count))
34559 + if (atomic_read_unchecked(&lis3->count))
34560 return POLLIN | POLLRDNORM;
34561 return 0;
34562 }
34563 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
34564 index 2b1482a..5d33616 100644
34565 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
34566 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
34567 @@ -266,7 +266,7 @@ struct lis3lv02d {
34568 struct input_polled_dev *idev; /* input device */
34569 struct platform_device *pdev; /* platform device */
34570 struct regulator_bulk_data regulators[2];
34571 - atomic_t count; /* interrupt count after last read */
34572 + atomic_unchecked_t count; /* interrupt count after last read */
34573 union axis_conversion ac; /* hw -> logical axis */
34574 int mapped_btns[3];
34575
34576 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
34577 index 2f30bad..c4c13d0 100644
34578 --- a/drivers/misc/sgi-gru/gruhandles.c
34579 +++ b/drivers/misc/sgi-gru/gruhandles.c
34580 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
34581 unsigned long nsec;
34582
34583 nsec = CLKS2NSEC(clks);
34584 - atomic_long_inc(&mcs_op_statistics[op].count);
34585 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
34586 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
34587 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
34588 if (mcs_op_statistics[op].max < nsec)
34589 mcs_op_statistics[op].max = nsec;
34590 }
34591 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
34592 index 950dbe9..eeef0f8 100644
34593 --- a/drivers/misc/sgi-gru/gruprocfs.c
34594 +++ b/drivers/misc/sgi-gru/gruprocfs.c
34595 @@ -32,9 +32,9 @@
34596
34597 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
34598
34599 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
34600 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
34601 {
34602 - unsigned long val = atomic_long_read(v);
34603 + unsigned long val = atomic_long_read_unchecked(v);
34604
34605 seq_printf(s, "%16lu %s\n", val, id);
34606 }
34607 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
34608
34609 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
34610 for (op = 0; op < mcsop_last; op++) {
34611 - count = atomic_long_read(&mcs_op_statistics[op].count);
34612 - total = atomic_long_read(&mcs_op_statistics[op].total);
34613 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
34614 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
34615 max = mcs_op_statistics[op].max;
34616 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
34617 count ? total / count : 0, max);
34618 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
34619 index 5c3ce24..4915ccb 100644
34620 --- a/drivers/misc/sgi-gru/grutables.h
34621 +++ b/drivers/misc/sgi-gru/grutables.h
34622 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
34623 * GRU statistics.
34624 */
34625 struct gru_stats_s {
34626 - atomic_long_t vdata_alloc;
34627 - atomic_long_t vdata_free;
34628 - atomic_long_t gts_alloc;
34629 - atomic_long_t gts_free;
34630 - atomic_long_t gms_alloc;
34631 - atomic_long_t gms_free;
34632 - atomic_long_t gts_double_allocate;
34633 - atomic_long_t assign_context;
34634 - atomic_long_t assign_context_failed;
34635 - atomic_long_t free_context;
34636 - atomic_long_t load_user_context;
34637 - atomic_long_t load_kernel_context;
34638 - atomic_long_t lock_kernel_context;
34639 - atomic_long_t unlock_kernel_context;
34640 - atomic_long_t steal_user_context;
34641 - atomic_long_t steal_kernel_context;
34642 - atomic_long_t steal_context_failed;
34643 - atomic_long_t nopfn;
34644 - atomic_long_t asid_new;
34645 - atomic_long_t asid_next;
34646 - atomic_long_t asid_wrap;
34647 - atomic_long_t asid_reuse;
34648 - atomic_long_t intr;
34649 - atomic_long_t intr_cbr;
34650 - atomic_long_t intr_tfh;
34651 - atomic_long_t intr_spurious;
34652 - atomic_long_t intr_mm_lock_failed;
34653 - atomic_long_t call_os;
34654 - atomic_long_t call_os_wait_queue;
34655 - atomic_long_t user_flush_tlb;
34656 - atomic_long_t user_unload_context;
34657 - atomic_long_t user_exception;
34658 - atomic_long_t set_context_option;
34659 - atomic_long_t check_context_retarget_intr;
34660 - atomic_long_t check_context_unload;
34661 - atomic_long_t tlb_dropin;
34662 - atomic_long_t tlb_preload_page;
34663 - atomic_long_t tlb_dropin_fail_no_asid;
34664 - atomic_long_t tlb_dropin_fail_upm;
34665 - atomic_long_t tlb_dropin_fail_invalid;
34666 - atomic_long_t tlb_dropin_fail_range_active;
34667 - atomic_long_t tlb_dropin_fail_idle;
34668 - atomic_long_t tlb_dropin_fail_fmm;
34669 - atomic_long_t tlb_dropin_fail_no_exception;
34670 - atomic_long_t tfh_stale_on_fault;
34671 - atomic_long_t mmu_invalidate_range;
34672 - atomic_long_t mmu_invalidate_page;
34673 - atomic_long_t flush_tlb;
34674 - atomic_long_t flush_tlb_gru;
34675 - atomic_long_t flush_tlb_gru_tgh;
34676 - atomic_long_t flush_tlb_gru_zero_asid;
34677 + atomic_long_unchecked_t vdata_alloc;
34678 + atomic_long_unchecked_t vdata_free;
34679 + atomic_long_unchecked_t gts_alloc;
34680 + atomic_long_unchecked_t gts_free;
34681 + atomic_long_unchecked_t gms_alloc;
34682 + atomic_long_unchecked_t gms_free;
34683 + atomic_long_unchecked_t gts_double_allocate;
34684 + atomic_long_unchecked_t assign_context;
34685 + atomic_long_unchecked_t assign_context_failed;
34686 + atomic_long_unchecked_t free_context;
34687 + atomic_long_unchecked_t load_user_context;
34688 + atomic_long_unchecked_t load_kernel_context;
34689 + atomic_long_unchecked_t lock_kernel_context;
34690 + atomic_long_unchecked_t unlock_kernel_context;
34691 + atomic_long_unchecked_t steal_user_context;
34692 + atomic_long_unchecked_t steal_kernel_context;
34693 + atomic_long_unchecked_t steal_context_failed;
34694 + atomic_long_unchecked_t nopfn;
34695 + atomic_long_unchecked_t asid_new;
34696 + atomic_long_unchecked_t asid_next;
34697 + atomic_long_unchecked_t asid_wrap;
34698 + atomic_long_unchecked_t asid_reuse;
34699 + atomic_long_unchecked_t intr;
34700 + atomic_long_unchecked_t intr_cbr;
34701 + atomic_long_unchecked_t intr_tfh;
34702 + atomic_long_unchecked_t intr_spurious;
34703 + atomic_long_unchecked_t intr_mm_lock_failed;
34704 + atomic_long_unchecked_t call_os;
34705 + atomic_long_unchecked_t call_os_wait_queue;
34706 + atomic_long_unchecked_t user_flush_tlb;
34707 + atomic_long_unchecked_t user_unload_context;
34708 + atomic_long_unchecked_t user_exception;
34709 + atomic_long_unchecked_t set_context_option;
34710 + atomic_long_unchecked_t check_context_retarget_intr;
34711 + atomic_long_unchecked_t check_context_unload;
34712 + atomic_long_unchecked_t tlb_dropin;
34713 + atomic_long_unchecked_t tlb_preload_page;
34714 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
34715 + atomic_long_unchecked_t tlb_dropin_fail_upm;
34716 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
34717 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
34718 + atomic_long_unchecked_t tlb_dropin_fail_idle;
34719 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
34720 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
34721 + atomic_long_unchecked_t tfh_stale_on_fault;
34722 + atomic_long_unchecked_t mmu_invalidate_range;
34723 + atomic_long_unchecked_t mmu_invalidate_page;
34724 + atomic_long_unchecked_t flush_tlb;
34725 + atomic_long_unchecked_t flush_tlb_gru;
34726 + atomic_long_unchecked_t flush_tlb_gru_tgh;
34727 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
34728
34729 - atomic_long_t copy_gpa;
34730 - atomic_long_t read_gpa;
34731 + atomic_long_unchecked_t copy_gpa;
34732 + atomic_long_unchecked_t read_gpa;
34733
34734 - atomic_long_t mesq_receive;
34735 - atomic_long_t mesq_receive_none;
34736 - atomic_long_t mesq_send;
34737 - atomic_long_t mesq_send_failed;
34738 - atomic_long_t mesq_noop;
34739 - atomic_long_t mesq_send_unexpected_error;
34740 - atomic_long_t mesq_send_lb_overflow;
34741 - atomic_long_t mesq_send_qlimit_reached;
34742 - atomic_long_t mesq_send_amo_nacked;
34743 - atomic_long_t mesq_send_put_nacked;
34744 - atomic_long_t mesq_page_overflow;
34745 - atomic_long_t mesq_qf_locked;
34746 - atomic_long_t mesq_qf_noop_not_full;
34747 - atomic_long_t mesq_qf_switch_head_failed;
34748 - atomic_long_t mesq_qf_unexpected_error;
34749 - atomic_long_t mesq_noop_unexpected_error;
34750 - atomic_long_t mesq_noop_lb_overflow;
34751 - atomic_long_t mesq_noop_qlimit_reached;
34752 - atomic_long_t mesq_noop_amo_nacked;
34753 - atomic_long_t mesq_noop_put_nacked;
34754 - atomic_long_t mesq_noop_page_overflow;
34755 + atomic_long_unchecked_t mesq_receive;
34756 + atomic_long_unchecked_t mesq_receive_none;
34757 + atomic_long_unchecked_t mesq_send;
34758 + atomic_long_unchecked_t mesq_send_failed;
34759 + atomic_long_unchecked_t mesq_noop;
34760 + atomic_long_unchecked_t mesq_send_unexpected_error;
34761 + atomic_long_unchecked_t mesq_send_lb_overflow;
34762 + atomic_long_unchecked_t mesq_send_qlimit_reached;
34763 + atomic_long_unchecked_t mesq_send_amo_nacked;
34764 + atomic_long_unchecked_t mesq_send_put_nacked;
34765 + atomic_long_unchecked_t mesq_page_overflow;
34766 + atomic_long_unchecked_t mesq_qf_locked;
34767 + atomic_long_unchecked_t mesq_qf_noop_not_full;
34768 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
34769 + atomic_long_unchecked_t mesq_qf_unexpected_error;
34770 + atomic_long_unchecked_t mesq_noop_unexpected_error;
34771 + atomic_long_unchecked_t mesq_noop_lb_overflow;
34772 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
34773 + atomic_long_unchecked_t mesq_noop_amo_nacked;
34774 + atomic_long_unchecked_t mesq_noop_put_nacked;
34775 + atomic_long_unchecked_t mesq_noop_page_overflow;
34776
34777 };
34778
34779 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
34780 tghop_invalidate, mcsop_last};
34781
34782 struct mcs_op_statistic {
34783 - atomic_long_t count;
34784 - atomic_long_t total;
34785 + atomic_long_unchecked_t count;
34786 + atomic_long_unchecked_t total;
34787 unsigned long max;
34788 };
34789
34790 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
34791
34792 #define STAT(id) do { \
34793 if (gru_options & OPT_STATS) \
34794 - atomic_long_inc(&gru_stats.id); \
34795 + atomic_long_inc_unchecked(&gru_stats.id); \
34796 } while (0)
34797
34798 #ifdef CONFIG_SGI_GRU_DEBUG
34799 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
34800 index c862cd4..0d176fe 100644
34801 --- a/drivers/misc/sgi-xp/xp.h
34802 +++ b/drivers/misc/sgi-xp/xp.h
34803 @@ -288,7 +288,7 @@ struct xpc_interface {
34804 xpc_notify_func, void *);
34805 void (*received) (short, int, void *);
34806 enum xp_retval (*partid_to_nasids) (short, void *);
34807 -};
34808 +} __no_const;
34809
34810 extern struct xpc_interface xpc_interface;
34811
34812 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
34813 index b94d5f7..7f494c5 100644
34814 --- a/drivers/misc/sgi-xp/xpc.h
34815 +++ b/drivers/misc/sgi-xp/xpc.h
34816 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
34817 void (*received_payload) (struct xpc_channel *, void *);
34818 void (*notify_senders_of_disconnect) (struct xpc_channel *);
34819 };
34820 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
34821
34822 /* struct xpc_partition act_state values (for XPC HB) */
34823
34824 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
34825 /* found in xpc_main.c */
34826 extern struct device *xpc_part;
34827 extern struct device *xpc_chan;
34828 -extern struct xpc_arch_operations xpc_arch_ops;
34829 +extern xpc_arch_operations_no_const xpc_arch_ops;
34830 extern int xpc_disengage_timelimit;
34831 extern int xpc_disengage_timedout;
34832 extern int xpc_activate_IRQ_rcvd;
34833 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
34834 index 8d082b4..aa749ae 100644
34835 --- a/drivers/misc/sgi-xp/xpc_main.c
34836 +++ b/drivers/misc/sgi-xp/xpc_main.c
34837 @@ -162,7 +162,7 @@ static struct notifier_block xpc_die_notifier = {
34838 .notifier_call = xpc_system_die,
34839 };
34840
34841 -struct xpc_arch_operations xpc_arch_ops;
34842 +xpc_arch_operations_no_const xpc_arch_ops;
34843
34844 /*
34845 * Timer function to enforce the timelimit on the partition disengage.
34846 diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
34847 index 504da71..9722d43 100644
34848 --- a/drivers/mmc/host/sdhci-pci.c
34849 +++ b/drivers/mmc/host/sdhci-pci.c
34850 @@ -653,7 +653,7 @@ static const struct sdhci_pci_fixes sdhci_via = {
34851 .probe = via_probe,
34852 };
34853
34854 -static const struct pci_device_id pci_ids[] __devinitdata = {
34855 +static const struct pci_device_id pci_ids[] __devinitconst = {
34856 {
34857 .vendor = PCI_VENDOR_ID_RICOH,
34858 .device = PCI_DEVICE_ID_RICOH_R5C822,
34859 diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
34860 index a4eb8b5..8c0628f 100644
34861 --- a/drivers/mtd/devices/doc2000.c
34862 +++ b/drivers/mtd/devices/doc2000.c
34863 @@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
34864
34865 /* The ECC will not be calculated correctly if less than 512 is written */
34866 /* DBB-
34867 - if (len != 0x200 && eccbuf)
34868 + if (len != 0x200)
34869 printk(KERN_WARNING
34870 "ECC needs a full sector write (adr: %lx size %lx)\n",
34871 (long) to, (long) len);
34872 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
34873 index 0650aaf..7718762 100644
34874 --- a/drivers/mtd/nand/denali.c
34875 +++ b/drivers/mtd/nand/denali.c
34876 @@ -26,6 +26,7 @@
34877 #include <linux/pci.h>
34878 #include <linux/mtd/mtd.h>
34879 #include <linux/module.h>
34880 +#include <linux/slab.h>
34881
34882 #include "denali.h"
34883
34884 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
34885 index 51b9d6a..52af9a7 100644
34886 --- a/drivers/mtd/nftlmount.c
34887 +++ b/drivers/mtd/nftlmount.c
34888 @@ -24,6 +24,7 @@
34889 #include <asm/errno.h>
34890 #include <linux/delay.h>
34891 #include <linux/slab.h>
34892 +#include <linux/sched.h>
34893 #include <linux/mtd/mtd.h>
34894 #include <linux/mtd/nand.h>
34895 #include <linux/mtd/nftl.h>
34896 diff --git a/drivers/net/bonding/bond_sysfs.c b/drivers/net/bonding/bond_sysfs.c
34897 index dc15d24..ef8d2a0 100644
34898 --- a/drivers/net/bonding/bond_sysfs.c
34899 +++ b/drivers/net/bonding/bond_sysfs.c
34900 @@ -1060,7 +1060,7 @@ static ssize_t bonding_store_primary(struct device *d,
34901 goto out;
34902 }
34903
34904 - sscanf(buf, "%16s", ifname); /* IFNAMSIZ */
34905 + sscanf(buf, "%15s", ifname); /* IFNAMSIZ */
34906
34907 /* check to see if we are clearing primary */
34908 if (!strlen(ifname) || buf[0] == '\n') {
34909 @@ -1237,7 +1237,7 @@ static ssize_t bonding_store_active_slave(struct device *d,
34910 goto out;
34911 }
34912
34913 - sscanf(buf, "%16s", ifname); /* IFNAMSIZ */
34914 + sscanf(buf, "%15s", ifname); /* IFNAMSIZ */
34915
34916 /* check to see if we are clearing active */
34917 if (!strlen(ifname) || buf[0] == '\n') {
34918 diff --git a/drivers/net/ethernet/atheros/atlx/atl2.c b/drivers/net/ethernet/atheros/atlx/atl2.c
34919 index 57d64b8..623dd86 100644
34920 --- a/drivers/net/ethernet/atheros/atlx/atl2.c
34921 +++ b/drivers/net/ethernet/atheros/atlx/atl2.c
34922 @@ -2845,7 +2845,7 @@ static void atl2_force_ps(struct atl2_hw *hw)
34923 */
34924
34925 #define ATL2_PARAM(X, desc) \
34926 - static const int __devinitdata X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34927 + static const int __devinitconst X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34928 MODULE_PARM(X, "1-" __MODULE_STRING(ATL2_MAX_NIC) "i"); \
34929 MODULE_PARM_DESC(X, desc);
34930 #else
34931 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
34932 index 0875ecf..794cdf3 100644
34933 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
34934 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
34935 @@ -3051,9 +3051,8 @@ static void bnx2x_drv_info_ether_stat(struct bnx2x *bp)
34936 struct eth_stats_info *ether_stat =
34937 &bp->slowpath->drv_info_to_mcp.ether_stat;
34938
34939 - /* leave last char as NULL */
34940 - memcpy(ether_stat->version, DRV_MODULE_VERSION,
34941 - ETH_STAT_INFO_VERSION_LEN - 1);
34942 + strlcpy(ether_stat->version, DRV_MODULE_VERSION,
34943 + ETH_STAT_INFO_VERSION_LEN);
34944
34945 bp->sp_objs[0].mac_obj.get_n_elements(bp, &bp->sp_objs[0].mac_obj,
34946 DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED,
34947 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34948 index f83e033..8b4f43a 100644
34949 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34950 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34951 @@ -486,7 +486,7 @@ struct bnx2x_rx_mode_obj {
34952
34953 int (*wait_comp)(struct bnx2x *bp,
34954 struct bnx2x_rx_mode_ramrod_params *p);
34955 -};
34956 +} __no_const;
34957
34958 /********************** Set multicast group ***********************************/
34959
34960 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
34961 index 6d52cb2..bc95640 100644
34962 --- a/drivers/net/ethernet/broadcom/tg3.h
34963 +++ b/drivers/net/ethernet/broadcom/tg3.h
34964 @@ -140,6 +140,7 @@
34965 #define CHIPREV_ID_5750_A0 0x4000
34966 #define CHIPREV_ID_5750_A1 0x4001
34967 #define CHIPREV_ID_5750_A3 0x4003
34968 +#define CHIPREV_ID_5750_C1 0x4201
34969 #define CHIPREV_ID_5750_C2 0x4202
34970 #define CHIPREV_ID_5752_A0_HW 0x5000
34971 #define CHIPREV_ID_5752_A0 0x6000
34972 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34973 index 8cffcdf..aadf043 100644
34974 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34975 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34976 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
34977 */
34978 struct l2t_skb_cb {
34979 arp_failure_handler_func arp_failure_handler;
34980 -};
34981 +} __no_const;
34982
34983 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
34984
34985 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
34986 index f879e92..726f20f 100644
34987 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
34988 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
34989 @@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34990 for (i=0; i<ETH_ALEN; i++) {
34991 tmp.addr[i] = dev->dev_addr[i];
34992 }
34993 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34994 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34995 break;
34996
34997 case DE4X5_SET_HWADDR: /* Set the hardware address */
34998 @@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34999 spin_lock_irqsave(&lp->lock, flags);
35000 memcpy(&statbuf, &lp->pktStats, ioc->len);
35001 spin_unlock_irqrestore(&lp->lock, flags);
35002 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
35003 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
35004 return -EFAULT;
35005 break;
35006 }
35007 diff --git a/drivers/net/ethernet/dec/tulip/eeprom.c b/drivers/net/ethernet/dec/tulip/eeprom.c
35008 index ed7d1dc..d426748 100644
35009 --- a/drivers/net/ethernet/dec/tulip/eeprom.c
35010 +++ b/drivers/net/ethernet/dec/tulip/eeprom.c
35011 @@ -79,7 +79,7 @@ static struct eeprom_fixup eeprom_fixups[] __devinitdata = {
35012 {NULL}};
35013
35014
35015 -static const char *block_name[] __devinitdata = {
35016 +static const char *block_name[] __devinitconst = {
35017 "21140 non-MII",
35018 "21140 MII PHY",
35019 "21142 Serial PHY",
35020 diff --git a/drivers/net/ethernet/dec/tulip/uli526x.c b/drivers/net/ethernet/dec/tulip/uli526x.c
35021 index 75d45f8..3d9c55b 100644
35022 --- a/drivers/net/ethernet/dec/tulip/uli526x.c
35023 +++ b/drivers/net/ethernet/dec/tulip/uli526x.c
35024 @@ -129,7 +129,7 @@ struct uli526x_board_info {
35025 struct uli_phy_ops {
35026 void (*write)(struct uli526x_board_info *, u8, u8, u16);
35027 u16 (*read)(struct uli526x_board_info *, u8, u8);
35028 - } phy;
35029 + } __no_const phy;
35030 struct net_device *next_dev; /* next device */
35031 struct pci_dev *pdev; /* PCI device */
35032 spinlock_t lock;
35033 diff --git a/drivers/net/ethernet/dec/tulip/winbond-840.c b/drivers/net/ethernet/dec/tulip/winbond-840.c
35034 index 4d1ffca..7c1ec4d 100644
35035 --- a/drivers/net/ethernet/dec/tulip/winbond-840.c
35036 +++ b/drivers/net/ethernet/dec/tulip/winbond-840.c
35037 @@ -236,7 +236,7 @@ struct pci_id_info {
35038 int drv_flags; /* Driver use, intended as capability flags. */
35039 };
35040
35041 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
35042 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
35043 { /* Sometime a Level-One switch card. */
35044 "Winbond W89c840", CanHaveMII | HasBrokenTx | FDXOnNoMII},
35045 { "Winbond W89c840", CanHaveMII | HasBrokenTx},
35046 diff --git a/drivers/net/ethernet/dlink/sundance.c b/drivers/net/ethernet/dlink/sundance.c
35047 index d7bb52a..3b83588 100644
35048 --- a/drivers/net/ethernet/dlink/sundance.c
35049 +++ b/drivers/net/ethernet/dlink/sundance.c
35050 @@ -218,7 +218,7 @@ enum {
35051 struct pci_id_info {
35052 const char *name;
35053 };
35054 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
35055 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
35056 {"D-Link DFE-550TX FAST Ethernet Adapter"},
35057 {"D-Link DFE-550FX 100Mbps Fiber-optics Adapter"},
35058 {"D-Link DFE-580TX 4 port Server Adapter"},
35059 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
35060 index 78b8aa8..dd6323a 100644
35061 --- a/drivers/net/ethernet/emulex/benet/be_main.c
35062 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
35063 @@ -403,7 +403,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
35064
35065 if (wrapped)
35066 newacc += 65536;
35067 - ACCESS_ONCE(*acc) = newacc;
35068 + ACCESS_ONCE_RW(*acc) = newacc;
35069 }
35070
35071 void be_parse_stats(struct be_adapter *adapter)
35072 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
35073 index 74d749e..eefb1bd 100644
35074 --- a/drivers/net/ethernet/faraday/ftgmac100.c
35075 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
35076 @@ -31,6 +31,8 @@
35077 #include <linux/netdevice.h>
35078 #include <linux/phy.h>
35079 #include <linux/platform_device.h>
35080 +#include <linux/interrupt.h>
35081 +#include <linux/irqreturn.h>
35082 #include <net/ip.h>
35083
35084 #include "ftgmac100.h"
35085 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
35086 index b901a01..1ff32ee 100644
35087 --- a/drivers/net/ethernet/faraday/ftmac100.c
35088 +++ b/drivers/net/ethernet/faraday/ftmac100.c
35089 @@ -31,6 +31,8 @@
35090 #include <linux/module.h>
35091 #include <linux/netdevice.h>
35092 #include <linux/platform_device.h>
35093 +#include <linux/interrupt.h>
35094 +#include <linux/irqreturn.h>
35095
35096 #include "ftmac100.h"
35097
35098 diff --git a/drivers/net/ethernet/fealnx.c b/drivers/net/ethernet/fealnx.c
35099 index 9d71c9c..0e4a0ac 100644
35100 --- a/drivers/net/ethernet/fealnx.c
35101 +++ b/drivers/net/ethernet/fealnx.c
35102 @@ -150,7 +150,7 @@ struct chip_info {
35103 int flags;
35104 };
35105
35106 -static const struct chip_info skel_netdrv_tbl[] __devinitdata = {
35107 +static const struct chip_info skel_netdrv_tbl[] __devinitconst = {
35108 { "100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
35109 { "100/10M Ethernet PCI Adapter", HAS_CHIP_XCVR },
35110 { "1000/100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
35111 diff --git a/drivers/net/ethernet/intel/e1000e/hw.h b/drivers/net/ethernet/intel/e1000e/hw.h
35112 index ed5b409..ec37828 100644
35113 --- a/drivers/net/ethernet/intel/e1000e/hw.h
35114 +++ b/drivers/net/ethernet/intel/e1000e/hw.h
35115 @@ -797,6 +797,7 @@ struct e1000_mac_operations {
35116 void (*rar_set)(struct e1000_hw *, u8 *, u32);
35117 s32 (*read_mac_addr)(struct e1000_hw *);
35118 };
35119 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35120
35121 /*
35122 * When to use various PHY register access functions:
35123 @@ -837,6 +838,7 @@ struct e1000_phy_operations {
35124 void (*power_up)(struct e1000_hw *);
35125 void (*power_down)(struct e1000_hw *);
35126 };
35127 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
35128
35129 /* Function pointers for the NVM. */
35130 struct e1000_nvm_operations {
35131 @@ -849,9 +851,10 @@ struct e1000_nvm_operations {
35132 s32 (*validate)(struct e1000_hw *);
35133 s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
35134 };
35135 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
35136
35137 struct e1000_mac_info {
35138 - struct e1000_mac_operations ops;
35139 + e1000_mac_operations_no_const ops;
35140 u8 addr[ETH_ALEN];
35141 u8 perm_addr[ETH_ALEN];
35142
35143 @@ -892,7 +895,7 @@ struct e1000_mac_info {
35144 };
35145
35146 struct e1000_phy_info {
35147 - struct e1000_phy_operations ops;
35148 + e1000_phy_operations_no_const ops;
35149
35150 enum e1000_phy_type type;
35151
35152 @@ -926,7 +929,7 @@ struct e1000_phy_info {
35153 };
35154
35155 struct e1000_nvm_info {
35156 - struct e1000_nvm_operations ops;
35157 + e1000_nvm_operations_no_const ops;
35158
35159 enum e1000_nvm_type type;
35160 enum e1000_nvm_override override;
35161 diff --git a/drivers/net/ethernet/intel/igb/e1000_hw.h b/drivers/net/ethernet/intel/igb/e1000_hw.h
35162 index c2a51dc..c2bd262 100644
35163 --- a/drivers/net/ethernet/intel/igb/e1000_hw.h
35164 +++ b/drivers/net/ethernet/intel/igb/e1000_hw.h
35165 @@ -327,6 +327,7 @@ struct e1000_mac_operations {
35166 void (*release_swfw_sync)(struct e1000_hw *, u16);
35167
35168 };
35169 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35170
35171 struct e1000_phy_operations {
35172 s32 (*acquire)(struct e1000_hw *);
35173 @@ -343,6 +344,7 @@ struct e1000_phy_operations {
35174 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
35175 s32 (*write_reg)(struct e1000_hw *, u32, u16);
35176 };
35177 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
35178
35179 struct e1000_nvm_operations {
35180 s32 (*acquire)(struct e1000_hw *);
35181 @@ -353,6 +355,7 @@ struct e1000_nvm_operations {
35182 s32 (*validate)(struct e1000_hw *);
35183 s32 (*valid_led_default)(struct e1000_hw *, u16 *);
35184 };
35185 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
35186
35187 struct e1000_info {
35188 s32 (*get_invariants)(struct e1000_hw *);
35189 @@ -364,7 +367,7 @@ struct e1000_info {
35190 extern const struct e1000_info e1000_82575_info;
35191
35192 struct e1000_mac_info {
35193 - struct e1000_mac_operations ops;
35194 + e1000_mac_operations_no_const ops;
35195
35196 u8 addr[6];
35197 u8 perm_addr[6];
35198 @@ -402,7 +405,7 @@ struct e1000_mac_info {
35199 };
35200
35201 struct e1000_phy_info {
35202 - struct e1000_phy_operations ops;
35203 + e1000_phy_operations_no_const ops;
35204
35205 enum e1000_phy_type type;
35206
35207 @@ -437,7 +440,7 @@ struct e1000_phy_info {
35208 };
35209
35210 struct e1000_nvm_info {
35211 - struct e1000_nvm_operations ops;
35212 + e1000_nvm_operations_no_const ops;
35213 enum e1000_nvm_type type;
35214 enum e1000_nvm_override override;
35215
35216 @@ -482,6 +485,7 @@ struct e1000_mbx_operations {
35217 s32 (*check_for_ack)(struct e1000_hw *, u16);
35218 s32 (*check_for_rst)(struct e1000_hw *, u16);
35219 };
35220 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
35221
35222 struct e1000_mbx_stats {
35223 u32 msgs_tx;
35224 @@ -493,7 +497,7 @@ struct e1000_mbx_stats {
35225 };
35226
35227 struct e1000_mbx_info {
35228 - struct e1000_mbx_operations ops;
35229 + e1000_mbx_operations_no_const ops;
35230 struct e1000_mbx_stats stats;
35231 u32 timeout;
35232 u32 usec_delay;
35233 diff --git a/drivers/net/ethernet/intel/igbvf/vf.h b/drivers/net/ethernet/intel/igbvf/vf.h
35234 index 57db3c6..aa825fc 100644
35235 --- a/drivers/net/ethernet/intel/igbvf/vf.h
35236 +++ b/drivers/net/ethernet/intel/igbvf/vf.h
35237 @@ -189,9 +189,10 @@ struct e1000_mac_operations {
35238 s32 (*read_mac_addr)(struct e1000_hw *);
35239 s32 (*set_vfta)(struct e1000_hw *, u16, bool);
35240 };
35241 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35242
35243 struct e1000_mac_info {
35244 - struct e1000_mac_operations ops;
35245 + e1000_mac_operations_no_const ops;
35246 u8 addr[6];
35247 u8 perm_addr[6];
35248
35249 @@ -213,6 +214,7 @@ struct e1000_mbx_operations {
35250 s32 (*check_for_ack)(struct e1000_hw *);
35251 s32 (*check_for_rst)(struct e1000_hw *);
35252 };
35253 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
35254
35255 struct e1000_mbx_stats {
35256 u32 msgs_tx;
35257 @@ -224,7 +226,7 @@ struct e1000_mbx_stats {
35258 };
35259
35260 struct e1000_mbx_info {
35261 - struct e1000_mbx_operations ops;
35262 + e1000_mbx_operations_no_const ops;
35263 struct e1000_mbx_stats stats;
35264 u32 timeout;
35265 u32 usec_delay;
35266 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
35267 index 3456d56..b688d81 100644
35268 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
35269 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
35270 @@ -884,7 +884,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
35271 /* store the new cycle speed */
35272 adapter->cycle_speed = cycle_speed;
35273
35274 - ACCESS_ONCE(adapter->base_incval) = incval;
35275 + ACCESS_ONCE_RW(adapter->base_incval) = incval;
35276 smp_mb();
35277
35278 /* grab the ptp lock */
35279 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35280 index 400f86a..7f2e062 100644
35281 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35282 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35283 @@ -2799,6 +2799,7 @@ struct ixgbe_eeprom_operations {
35284 s32 (*update_checksum)(struct ixgbe_hw *);
35285 u16 (*calc_checksum)(struct ixgbe_hw *);
35286 };
35287 +typedef struct ixgbe_eeprom_operations __no_const ixgbe_eeprom_operations_no_const;
35288
35289 struct ixgbe_mac_operations {
35290 s32 (*init_hw)(struct ixgbe_hw *);
35291 @@ -2865,6 +2866,7 @@ struct ixgbe_mac_operations {
35292 s32 (*get_thermal_sensor_data)(struct ixgbe_hw *);
35293 s32 (*init_thermal_sensor_thresh)(struct ixgbe_hw *hw);
35294 };
35295 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
35296
35297 struct ixgbe_phy_operations {
35298 s32 (*identify)(struct ixgbe_hw *);
35299 @@ -2884,9 +2886,10 @@ struct ixgbe_phy_operations {
35300 s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8);
35301 s32 (*check_overtemp)(struct ixgbe_hw *);
35302 };
35303 +typedef struct ixgbe_phy_operations __no_const ixgbe_phy_operations_no_const;
35304
35305 struct ixgbe_eeprom_info {
35306 - struct ixgbe_eeprom_operations ops;
35307 + ixgbe_eeprom_operations_no_const ops;
35308 enum ixgbe_eeprom_type type;
35309 u32 semaphore_delay;
35310 u16 word_size;
35311 @@ -2896,7 +2899,7 @@ struct ixgbe_eeprom_info {
35312
35313 #define IXGBE_FLAGS_DOUBLE_RESET_REQUIRED 0x01
35314 struct ixgbe_mac_info {
35315 - struct ixgbe_mac_operations ops;
35316 + ixgbe_mac_operations_no_const ops;
35317 enum ixgbe_mac_type type;
35318 u8 addr[ETH_ALEN];
35319 u8 perm_addr[ETH_ALEN];
35320 @@ -2926,7 +2929,7 @@ struct ixgbe_mac_info {
35321 };
35322
35323 struct ixgbe_phy_info {
35324 - struct ixgbe_phy_operations ops;
35325 + ixgbe_phy_operations_no_const ops;
35326 struct mdio_if_info mdio;
35327 enum ixgbe_phy_type type;
35328 u32 id;
35329 @@ -2954,6 +2957,7 @@ struct ixgbe_mbx_operations {
35330 s32 (*check_for_ack)(struct ixgbe_hw *, u16);
35331 s32 (*check_for_rst)(struct ixgbe_hw *, u16);
35332 };
35333 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
35334
35335 struct ixgbe_mbx_stats {
35336 u32 msgs_tx;
35337 @@ -2965,7 +2969,7 @@ struct ixgbe_mbx_stats {
35338 };
35339
35340 struct ixgbe_mbx_info {
35341 - struct ixgbe_mbx_operations ops;
35342 + ixgbe_mbx_operations_no_const ops;
35343 struct ixgbe_mbx_stats stats;
35344 u32 timeout;
35345 u32 usec_delay;
35346 diff --git a/drivers/net/ethernet/intel/ixgbevf/vf.h b/drivers/net/ethernet/intel/ixgbevf/vf.h
35347 index 25c951d..cc7cf33 100644
35348 --- a/drivers/net/ethernet/intel/ixgbevf/vf.h
35349 +++ b/drivers/net/ethernet/intel/ixgbevf/vf.h
35350 @@ -70,6 +70,7 @@ struct ixgbe_mac_operations {
35351 s32 (*clear_vfta)(struct ixgbe_hw *);
35352 s32 (*set_vfta)(struct ixgbe_hw *, u32, u32, bool);
35353 };
35354 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
35355
35356 enum ixgbe_mac_type {
35357 ixgbe_mac_unknown = 0,
35358 @@ -79,7 +80,7 @@ enum ixgbe_mac_type {
35359 };
35360
35361 struct ixgbe_mac_info {
35362 - struct ixgbe_mac_operations ops;
35363 + ixgbe_mac_operations_no_const ops;
35364 u8 addr[6];
35365 u8 perm_addr[6];
35366
35367 @@ -103,6 +104,7 @@ struct ixgbe_mbx_operations {
35368 s32 (*check_for_ack)(struct ixgbe_hw *);
35369 s32 (*check_for_rst)(struct ixgbe_hw *);
35370 };
35371 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
35372
35373 struct ixgbe_mbx_stats {
35374 u32 msgs_tx;
35375 @@ -114,7 +116,7 @@ struct ixgbe_mbx_stats {
35376 };
35377
35378 struct ixgbe_mbx_info {
35379 - struct ixgbe_mbx_operations ops;
35380 + ixgbe_mbx_operations_no_const ops;
35381 struct ixgbe_mbx_stats stats;
35382 u32 timeout;
35383 u32 udelay;
35384 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.h b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35385 index 9e0c1ee..8471f77 100644
35386 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.h
35387 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35388 @@ -514,7 +514,7 @@ struct vxge_hw_uld_cbs {
35389 void (*link_down)(struct __vxge_hw_device *devh);
35390 void (*crit_err)(struct __vxge_hw_device *devh,
35391 enum vxge_hw_event type, u64 ext_data);
35392 -};
35393 +} __no_const;
35394
35395 /*
35396 * struct __vxge_hw_blockpool_entry - Block private data structure
35397 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35398 index 4a518a3..936b334 100644
35399 --- a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35400 +++ b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35401 @@ -2088,7 +2088,7 @@ struct vxge_hw_mempool_cbs {
35402 struct vxge_hw_mempool_dma *dma_object,
35403 u32 index,
35404 u32 is_last);
35405 -};
35406 +} __no_const;
35407
35408 #define VXGE_HW_VIRTUAL_PATH_HANDLE(vpath) \
35409 ((struct __vxge_hw_vpath_handle *)(vpath)->vpath_handles.next)
35410 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
35411 index b47d5b3..273a516 100644
35412 --- a/drivers/net/ethernet/realtek/r8169.c
35413 +++ b/drivers/net/ethernet/realtek/r8169.c
35414 @@ -745,22 +745,22 @@ struct rtl8169_private {
35415 struct mdio_ops {
35416 void (*write)(struct rtl8169_private *, int, int);
35417 int (*read)(struct rtl8169_private *, int);
35418 - } mdio_ops;
35419 + } __no_const mdio_ops;
35420
35421 struct pll_power_ops {
35422 void (*down)(struct rtl8169_private *);
35423 void (*up)(struct rtl8169_private *);
35424 - } pll_power_ops;
35425 + } __no_const pll_power_ops;
35426
35427 struct jumbo_ops {
35428 void (*enable)(struct rtl8169_private *);
35429 void (*disable)(struct rtl8169_private *);
35430 - } jumbo_ops;
35431 + } __no_const jumbo_ops;
35432
35433 struct csi_ops {
35434 void (*write)(struct rtl8169_private *, int, int);
35435 u32 (*read)(struct rtl8169_private *, int);
35436 - } csi_ops;
35437 + } __no_const csi_ops;
35438
35439 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
35440 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
35441 diff --git a/drivers/net/ethernet/sis/sis190.c b/drivers/net/ethernet/sis/sis190.c
35442 index 4613591..d816601 100644
35443 --- a/drivers/net/ethernet/sis/sis190.c
35444 +++ b/drivers/net/ethernet/sis/sis190.c
35445 @@ -1618,7 +1618,7 @@ static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
35446 static int __devinit sis190_get_mac_addr_from_apc(struct pci_dev *pdev,
35447 struct net_device *dev)
35448 {
35449 - static const u16 __devinitdata ids[] = { 0x0965, 0x0966, 0x0968 };
35450 + static const u16 __devinitconst ids[] = { 0x0965, 0x0966, 0x0968 };
35451 struct sis190_private *tp = netdev_priv(dev);
35452 struct pci_dev *isa_bridge;
35453 u8 reg, tmp8;
35454 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35455 index 0c74a70..3bc6f68 100644
35456 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35457 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35458 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
35459
35460 writel(value, ioaddr + MMC_CNTRL);
35461
35462 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35463 - MMC_CNTRL, value);
35464 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35465 +// MMC_CNTRL, value);
35466 }
35467
35468 /* To mask all all interrupts.*/
35469 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
35470 index 95ceb35..318fc12 100644
35471 --- a/drivers/net/hyperv/hyperv_net.h
35472 +++ b/drivers/net/hyperv/hyperv_net.h
35473 @@ -99,7 +99,7 @@ struct rndis_device {
35474
35475 enum rndis_device_state state;
35476 bool link_state;
35477 - atomic_t new_req_id;
35478 + atomic_unchecked_t new_req_id;
35479
35480 spinlock_t request_lock;
35481 struct list_head req_list;
35482 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
35483 index 1e88a10..1b01736 100644
35484 --- a/drivers/net/hyperv/rndis_filter.c
35485 +++ b/drivers/net/hyperv/rndis_filter.c
35486 @@ -99,7 +99,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
35487 * template
35488 */
35489 set = &rndis_msg->msg.set_req;
35490 - set->req_id = atomic_inc_return(&dev->new_req_id);
35491 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35492
35493 /* Add to the request list */
35494 spin_lock_irqsave(&dev->request_lock, flags);
35495 @@ -730,7 +730,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
35496
35497 /* Setup the rndis set */
35498 halt = &request->request_msg.msg.halt_req;
35499 - halt->req_id = atomic_inc_return(&dev->new_req_id);
35500 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35501
35502 /* Ignore return since this msg is optional. */
35503 rndis_filter_send_request(dev, request);
35504 diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
35505 index daec9b0..6428fcb 100644
35506 --- a/drivers/net/phy/mdio-bitbang.c
35507 +++ b/drivers/net/phy/mdio-bitbang.c
35508 @@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
35509 struct mdiobb_ctrl *ctrl = bus->priv;
35510
35511 module_put(ctrl->ops->owner);
35512 + mdiobus_unregister(bus);
35513 mdiobus_free(bus);
35514 }
35515 EXPORT_SYMBOL(free_mdio_bitbang);
35516 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
35517 index 5c05572..389610b 100644
35518 --- a/drivers/net/ppp/ppp_generic.c
35519 +++ b/drivers/net/ppp/ppp_generic.c
35520 @@ -986,7 +986,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35521 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
35522 struct ppp_stats stats;
35523 struct ppp_comp_stats cstats;
35524 - char *vers;
35525
35526 switch (cmd) {
35527 case SIOCGPPPSTATS:
35528 @@ -1008,8 +1007,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35529 break;
35530
35531 case SIOCGPPPVER:
35532 - vers = PPP_VERSION;
35533 - if (copy_to_user(addr, vers, strlen(vers) + 1))
35534 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
35535 break;
35536 err = 0;
35537 break;
35538 diff --git a/drivers/net/tun.c b/drivers/net/tun.c
35539 index 3a16d4f..a311cec 100644
35540 --- a/drivers/net/tun.c
35541 +++ b/drivers/net/tun.c
35542 @@ -1367,7 +1367,7 @@ static int set_offload(struct tun_struct *tun, unsigned long arg)
35543 }
35544
35545 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
35546 - unsigned long arg, int ifreq_len)
35547 + unsigned long arg, size_t ifreq_len)
35548 {
35549 struct tun_file *tfile = file->private_data;
35550 struct tun_struct *tun;
35551 @@ -1378,6 +1378,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
35552 int vnet_hdr_sz;
35553 int ret;
35554
35555 + if (ifreq_len > sizeof ifr)
35556 + return -EFAULT;
35557 +
35558 if (cmd == TUNSETIFF || _IOC_TYPE(cmd) == 0x89) {
35559 if (copy_from_user(&ifr, argp, ifreq_len))
35560 return -EFAULT;
35561 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
35562 index 62f30b4..ff99dfd 100644
35563 --- a/drivers/net/usb/hso.c
35564 +++ b/drivers/net/usb/hso.c
35565 @@ -71,7 +71,7 @@
35566 #include <asm/byteorder.h>
35567 #include <linux/serial_core.h>
35568 #include <linux/serial.h>
35569 -
35570 +#include <asm/local.h>
35571
35572 #define MOD_AUTHOR "Option Wireless"
35573 #define MOD_DESCRIPTION "USB High Speed Option driver"
35574 @@ -1182,7 +1182,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
35575 struct urb *urb;
35576
35577 urb = serial->rx_urb[0];
35578 - if (serial->port.count > 0) {
35579 + if (atomic_read(&serial->port.count) > 0) {
35580 count = put_rxbuf_data(urb, serial);
35581 if (count == -1)
35582 return;
35583 @@ -1218,7 +1218,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
35584 DUMP1(urb->transfer_buffer, urb->actual_length);
35585
35586 /* Anyone listening? */
35587 - if (serial->port.count == 0)
35588 + if (atomic_read(&serial->port.count) == 0)
35589 return;
35590
35591 if (status == 0) {
35592 @@ -1300,8 +1300,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35593 tty_port_tty_set(&serial->port, tty);
35594
35595 /* check for port already opened, if not set the termios */
35596 - serial->port.count++;
35597 - if (serial->port.count == 1) {
35598 + if (atomic_inc_return(&serial->port.count) == 1) {
35599 serial->rx_state = RX_IDLE;
35600 /* Force default termio settings */
35601 _hso_serial_set_termios(tty, NULL);
35602 @@ -1313,7 +1312,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35603 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
35604 if (result) {
35605 hso_stop_serial_device(serial->parent);
35606 - serial->port.count--;
35607 + atomic_dec(&serial->port.count);
35608 kref_put(&serial->parent->ref, hso_serial_ref_free);
35609 }
35610 } else {
35611 @@ -1350,10 +1349,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
35612
35613 /* reset the rts and dtr */
35614 /* do the actual close */
35615 - serial->port.count--;
35616 + atomic_dec(&serial->port.count);
35617
35618 - if (serial->port.count <= 0) {
35619 - serial->port.count = 0;
35620 + if (atomic_read(&serial->port.count) <= 0) {
35621 + atomic_set(&serial->port.count, 0);
35622 tty_port_tty_set(&serial->port, NULL);
35623 if (!usb_gone)
35624 hso_stop_serial_device(serial->parent);
35625 @@ -1429,7 +1428,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
35626
35627 /* the actual setup */
35628 spin_lock_irqsave(&serial->serial_lock, flags);
35629 - if (serial->port.count)
35630 + if (atomic_read(&serial->port.count))
35631 _hso_serial_set_termios(tty, old);
35632 else
35633 tty->termios = old;
35634 @@ -1888,7 +1887,7 @@ static void intr_callback(struct urb *urb)
35635 D1("Pending read interrupt on port %d\n", i);
35636 spin_lock(&serial->serial_lock);
35637 if (serial->rx_state == RX_IDLE &&
35638 - serial->port.count > 0) {
35639 + atomic_read(&serial->port.count) > 0) {
35640 /* Setup and send a ctrl req read on
35641 * port i */
35642 if (!serial->rx_urb_filled[0]) {
35643 @@ -3079,7 +3078,7 @@ static int hso_resume(struct usb_interface *iface)
35644 /* Start all serial ports */
35645 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
35646 if (serial_table[i] && (serial_table[i]->interface == iface)) {
35647 - if (dev2ser(serial_table[i])->port.count) {
35648 + if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
35649 result =
35650 hso_start_serial_device(serial_table[i], GFP_NOIO);
35651 hso_kick_transmit(dev2ser(serial_table[i]));
35652 diff --git a/drivers/net/wireless/ath/ath.h b/drivers/net/wireless/ath/ath.h
35653 index 6169fbd..40e8422 100644
35654 --- a/drivers/net/wireless/ath/ath.h
35655 +++ b/drivers/net/wireless/ath/ath.h
35656 @@ -119,6 +119,7 @@ struct ath_ops {
35657 void (*write_flush) (void *);
35658 u32 (*rmw)(void *, u32 reg_offset, u32 set, u32 clr);
35659 };
35660 +typedef struct ath_ops __no_const ath_ops_no_const;
35661
35662 struct ath_common;
35663 struct ath_bus_ops;
35664 diff --git a/drivers/net/wireless/ath/ath5k/base.c b/drivers/net/wireless/ath/ath5k/base.c
35665 index 2aab20e..b761ef8 100644
35666 --- a/drivers/net/wireless/ath/ath5k/base.c
35667 +++ b/drivers/net/wireless/ath/ath5k/base.c
35668 @@ -1803,7 +1803,7 @@ ath5k_beacon_update(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
35669 {
35670 int ret;
35671 struct ath5k_hw *ah = hw->priv;
35672 - struct ath5k_vif *avf = (void *)vif->drv_priv;
35673 + struct ath5k_vif *avf;
35674 struct sk_buff *skb;
35675
35676 if (WARN_ON(!vif)) {
35677 @@ -1818,6 +1818,7 @@ ath5k_beacon_update(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
35678 goto out;
35679 }
35680
35681 + avf = (void *)vif->drv_priv;
35682 ath5k_txbuf_free_skb(ah, avf->bbuf);
35683 avf->bbuf->skb = skb;
35684 ret = ath5k_beacon_setup(ah, avf->bbuf);
35685 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35686 index 8d78253..bebbb68 100644
35687 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35688 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35689 @@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35690 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
35691 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
35692
35693 - ACCESS_ONCE(ads->ds_link) = i->link;
35694 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
35695 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
35696 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
35697
35698 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
35699 ctl6 = SM(i->keytype, AR_EncrType);
35700 @@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35701
35702 if ((i->is_first || i->is_last) &&
35703 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
35704 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
35705 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
35706 | set11nTries(i->rates, 1)
35707 | set11nTries(i->rates, 2)
35708 | set11nTries(i->rates, 3)
35709 | (i->dur_update ? AR_DurUpdateEna : 0)
35710 | SM(0, AR_BurstDur);
35711
35712 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
35713 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
35714 | set11nRate(i->rates, 1)
35715 | set11nRate(i->rates, 2)
35716 | set11nRate(i->rates, 3);
35717 } else {
35718 - ACCESS_ONCE(ads->ds_ctl2) = 0;
35719 - ACCESS_ONCE(ads->ds_ctl3) = 0;
35720 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
35721 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
35722 }
35723
35724 if (!i->is_first) {
35725 - ACCESS_ONCE(ads->ds_ctl0) = 0;
35726 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35727 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35728 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
35729 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35730 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35731 return;
35732 }
35733
35734 @@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35735 break;
35736 }
35737
35738 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35739 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35740 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35741 | SM(i->txpower, AR_XmitPower)
35742 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35743 @@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35744 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
35745 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
35746
35747 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35748 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35749 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35750 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35751
35752 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
35753 return;
35754
35755 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35756 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35757 | set11nPktDurRTSCTS(i->rates, 1);
35758
35759 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35760 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35761 | set11nPktDurRTSCTS(i->rates, 3);
35762
35763 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35764 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35765 | set11nRateFlags(i->rates, 1)
35766 | set11nRateFlags(i->rates, 2)
35767 | set11nRateFlags(i->rates, 3)
35768 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35769 index 78816b8..1fcdfae 100644
35770 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35771 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35772 @@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35773 (i->qcu << AR_TxQcuNum_S) | desc_len;
35774
35775 checksum += val;
35776 - ACCESS_ONCE(ads->info) = val;
35777 + ACCESS_ONCE_RW(ads->info) = val;
35778
35779 checksum += i->link;
35780 - ACCESS_ONCE(ads->link) = i->link;
35781 + ACCESS_ONCE_RW(ads->link) = i->link;
35782
35783 checksum += i->buf_addr[0];
35784 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
35785 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
35786 checksum += i->buf_addr[1];
35787 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
35788 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
35789 checksum += i->buf_addr[2];
35790 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
35791 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
35792 checksum += i->buf_addr[3];
35793 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
35794 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
35795
35796 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
35797 - ACCESS_ONCE(ads->ctl3) = val;
35798 + ACCESS_ONCE_RW(ads->ctl3) = val;
35799 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
35800 - ACCESS_ONCE(ads->ctl5) = val;
35801 + ACCESS_ONCE_RW(ads->ctl5) = val;
35802 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
35803 - ACCESS_ONCE(ads->ctl7) = val;
35804 + ACCESS_ONCE_RW(ads->ctl7) = val;
35805 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
35806 - ACCESS_ONCE(ads->ctl9) = val;
35807 + ACCESS_ONCE_RW(ads->ctl9) = val;
35808
35809 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
35810 - ACCESS_ONCE(ads->ctl10) = checksum;
35811 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
35812
35813 if (i->is_first || i->is_last) {
35814 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
35815 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
35816 | set11nTries(i->rates, 1)
35817 | set11nTries(i->rates, 2)
35818 | set11nTries(i->rates, 3)
35819 | (i->dur_update ? AR_DurUpdateEna : 0)
35820 | SM(0, AR_BurstDur);
35821
35822 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
35823 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
35824 | set11nRate(i->rates, 1)
35825 | set11nRate(i->rates, 2)
35826 | set11nRate(i->rates, 3);
35827 } else {
35828 - ACCESS_ONCE(ads->ctl13) = 0;
35829 - ACCESS_ONCE(ads->ctl14) = 0;
35830 + ACCESS_ONCE_RW(ads->ctl13) = 0;
35831 + ACCESS_ONCE_RW(ads->ctl14) = 0;
35832 }
35833
35834 ads->ctl20 = 0;
35835 @@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35836
35837 ctl17 = SM(i->keytype, AR_EncrType);
35838 if (!i->is_first) {
35839 - ACCESS_ONCE(ads->ctl11) = 0;
35840 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35841 - ACCESS_ONCE(ads->ctl15) = 0;
35842 - ACCESS_ONCE(ads->ctl16) = 0;
35843 - ACCESS_ONCE(ads->ctl17) = ctl17;
35844 - ACCESS_ONCE(ads->ctl18) = 0;
35845 - ACCESS_ONCE(ads->ctl19) = 0;
35846 + ACCESS_ONCE_RW(ads->ctl11) = 0;
35847 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35848 + ACCESS_ONCE_RW(ads->ctl15) = 0;
35849 + ACCESS_ONCE_RW(ads->ctl16) = 0;
35850 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35851 + ACCESS_ONCE_RW(ads->ctl18) = 0;
35852 + ACCESS_ONCE_RW(ads->ctl19) = 0;
35853 return;
35854 }
35855
35856 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35857 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35858 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35859 | SM(i->txpower, AR_XmitPower)
35860 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35861 @@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35862 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
35863 ctl12 |= SM(val, AR_PAPRDChainMask);
35864
35865 - ACCESS_ONCE(ads->ctl12) = ctl12;
35866 - ACCESS_ONCE(ads->ctl17) = ctl17;
35867 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
35868 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35869
35870 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35871 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35872 | set11nPktDurRTSCTS(i->rates, 1);
35873
35874 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35875 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35876 | set11nPktDurRTSCTS(i->rates, 3);
35877
35878 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
35879 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
35880 | set11nRateFlags(i->rates, 1)
35881 | set11nRateFlags(i->rates, 2)
35882 | set11nRateFlags(i->rates, 3)
35883 | SM(i->rtscts_rate, AR_RTSCTSRate);
35884
35885 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
35886 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
35887 }
35888
35889 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
35890 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
35891 index de6968f..29ac4c1 100644
35892 --- a/drivers/net/wireless/ath/ath9k/hw.h
35893 +++ b/drivers/net/wireless/ath/ath9k/hw.h
35894 @@ -656,7 +656,7 @@ struct ath_hw_private_ops {
35895
35896 /* ANI */
35897 void (*ani_cache_ini_regs)(struct ath_hw *ah);
35898 -};
35899 +} __no_const;
35900
35901 /**
35902 * struct ath_hw_ops - callbacks used by hardware code and driver code
35903 @@ -686,7 +686,7 @@ struct ath_hw_ops {
35904 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
35905 struct ath_hw_antcomb_conf *antconf);
35906
35907 -};
35908 +} __no_const;
35909
35910 struct ath_nf_limits {
35911 s16 max;
35912 @@ -706,7 +706,7 @@ enum ath_cal_list {
35913 #define AH_FASTCC 0x4
35914
35915 struct ath_hw {
35916 - struct ath_ops reg_ops;
35917 + ath_ops_no_const reg_ops;
35918
35919 struct ieee80211_hw *hw;
35920 struct ath_common common;
35921 diff --git a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35922 index af00e2c..ab04d34 100644
35923 --- a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35924 +++ b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35925 @@ -545,7 +545,7 @@ struct phy_func_ptr {
35926 void (*carrsuppr)(struct brcms_phy *);
35927 s32 (*rxsigpwr)(struct brcms_phy *, s32);
35928 void (*detach)(struct brcms_phy *);
35929 -};
35930 +} __no_const;
35931
35932 struct brcms_phy {
35933 struct brcms_phy_pub pubpi_ro;
35934 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
35935 index faec404..a5277f1 100644
35936 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
35937 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
35938 @@ -3611,7 +3611,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
35939 */
35940 if (il3945_mod_params.disable_hw_scan) {
35941 D_INFO("Disabling hw_scan\n");
35942 - il3945_mac_ops.hw_scan = NULL;
35943 + pax_open_kernel();
35944 + *(void **)&il3945_mac_ops.hw_scan = NULL;
35945 + pax_close_kernel();
35946 }
35947
35948 D_INFO("*** LOAD DRIVER ***\n");
35949 diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
35950 index a47b306..297daf2 100644
35951 --- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
35952 +++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
35953 @@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
35954 {
35955 struct iwl_priv *priv = file->private_data;
35956 char buf[64];
35957 - int buf_size;
35958 + size_t buf_size;
35959 u32 offset, len;
35960
35961 memset(buf, 0, sizeof(buf));
35962 @@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
35963 struct iwl_priv *priv = file->private_data;
35964
35965 char buf[8];
35966 - int buf_size;
35967 + size_t buf_size;
35968 u32 reset_flag;
35969
35970 memset(buf, 0, sizeof(buf));
35971 @@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
35972 {
35973 struct iwl_priv *priv = file->private_data;
35974 char buf[8];
35975 - int buf_size;
35976 + size_t buf_size;
35977 int ht40;
35978
35979 memset(buf, 0, sizeof(buf));
35980 @@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
35981 {
35982 struct iwl_priv *priv = file->private_data;
35983 char buf[8];
35984 - int buf_size;
35985 + size_t buf_size;
35986 int value;
35987
35988 memset(buf, 0, sizeof(buf));
35989 @@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
35990 {
35991 struct iwl_priv *priv = file->private_data;
35992 char buf[8];
35993 - int buf_size;
35994 + size_t buf_size;
35995 int clear;
35996
35997 memset(buf, 0, sizeof(buf));
35998 @@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
35999 {
36000 struct iwl_priv *priv = file->private_data;
36001 char buf[8];
36002 - int buf_size;
36003 + size_t buf_size;
36004 int trace;
36005
36006 memset(buf, 0, sizeof(buf));
36007 @@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
36008 {
36009 struct iwl_priv *priv = file->private_data;
36010 char buf[8];
36011 - int buf_size;
36012 + size_t buf_size;
36013 int missed;
36014
36015 memset(buf, 0, sizeof(buf));
36016 @@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
36017
36018 struct iwl_priv *priv = file->private_data;
36019 char buf[8];
36020 - int buf_size;
36021 + size_t buf_size;
36022 int plcp;
36023
36024 memset(buf, 0, sizeof(buf));
36025 @@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
36026
36027 struct iwl_priv *priv = file->private_data;
36028 char buf[8];
36029 - int buf_size;
36030 + size_t buf_size;
36031 int flush;
36032
36033 memset(buf, 0, sizeof(buf));
36034 @@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
36035
36036 struct iwl_priv *priv = file->private_data;
36037 char buf[8];
36038 - int buf_size;
36039 + size_t buf_size;
36040 int rts;
36041
36042 if (!priv->cfg->ht_params)
36043 @@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
36044 {
36045 struct iwl_priv *priv = file->private_data;
36046 char buf[8];
36047 - int buf_size;
36048 + size_t buf_size;
36049
36050 memset(buf, 0, sizeof(buf));
36051 buf_size = min(count, sizeof(buf) - 1);
36052 @@ -2256,7 +2256,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
36053 struct iwl_priv *priv = file->private_data;
36054 u32 event_log_flag;
36055 char buf[8];
36056 - int buf_size;
36057 + size_t buf_size;
36058
36059 /* check that the interface is up */
36060 if (!iwl_is_ready(priv))
36061 @@ -2310,7 +2310,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
36062 struct iwl_priv *priv = file->private_data;
36063 char buf[8];
36064 u32 calib_disabled;
36065 - int buf_size;
36066 + size_t buf_size;
36067
36068 memset(buf, 0, sizeof(buf));
36069 buf_size = min(count, sizeof(buf) - 1);
36070 diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
36071 index dbeebef..b45a152 100644
36072 --- a/drivers/net/wireless/iwlwifi/pcie/trans.c
36073 +++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
36074 @@ -1944,7 +1944,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
36075 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
36076
36077 char buf[8];
36078 - int buf_size;
36079 + size_t buf_size;
36080 u32 reset_flag;
36081
36082 memset(buf, 0, sizeof(buf));
36083 @@ -1965,7 +1965,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
36084 {
36085 struct iwl_trans *trans = file->private_data;
36086 char buf[8];
36087 - int buf_size;
36088 + size_t buf_size;
36089 int csr;
36090
36091 memset(buf, 0, sizeof(buf));
36092 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
36093 index 0083839..fcb7225 100644
36094 --- a/drivers/net/wireless/mac80211_hwsim.c
36095 +++ b/drivers/net/wireless/mac80211_hwsim.c
36096 @@ -1748,9 +1748,11 @@ static int __init init_mac80211_hwsim(void)
36097 return -EINVAL;
36098
36099 if (fake_hw_scan) {
36100 - mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
36101 - mac80211_hwsim_ops.sw_scan_start = NULL;
36102 - mac80211_hwsim_ops.sw_scan_complete = NULL;
36103 + pax_open_kernel();
36104 + *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
36105 + *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
36106 + *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
36107 + pax_close_kernel();
36108 }
36109
36110 spin_lock_init(&hwsim_radio_lock);
36111 diff --git a/drivers/net/wireless/mwifiex/main.h b/drivers/net/wireless/mwifiex/main.h
36112 index e7c2a82..582e228 100644
36113 --- a/drivers/net/wireless/mwifiex/main.h
36114 +++ b/drivers/net/wireless/mwifiex/main.h
36115 @@ -571,7 +571,7 @@ struct mwifiex_if_ops {
36116 int (*event_complete) (struct mwifiex_adapter *, struct sk_buff *);
36117 int (*data_complete) (struct mwifiex_adapter *, struct sk_buff *);
36118 int (*dnld_fw) (struct mwifiex_adapter *, struct mwifiex_fw_image *);
36119 -};
36120 +} __no_const;
36121
36122 struct mwifiex_adapter {
36123 u8 iface_type;
36124 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
36125 index 7a4ae9e..56e00bd 100644
36126 --- a/drivers/net/wireless/rndis_wlan.c
36127 +++ b/drivers/net/wireless/rndis_wlan.c
36128 @@ -1235,7 +1235,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
36129
36130 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
36131
36132 - if (rts_threshold < 0 || rts_threshold > 2347)
36133 + if (rts_threshold > 2347)
36134 rts_threshold = 2347;
36135
36136 tmp = cpu_to_le32(rts_threshold);
36137 diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
36138 index 8afb546..0c0dc5c 100644
36139 --- a/drivers/net/wireless/rt2x00/rt2x00.h
36140 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
36141 @@ -397,7 +397,7 @@ struct rt2x00_intf {
36142 * for hardware which doesn't support hardware
36143 * sequence counting.
36144 */
36145 - atomic_t seqno;
36146 + atomic_unchecked_t seqno;
36147 };
36148
36149 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
36150 diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
36151 index f7e74a0..da71431 100644
36152 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
36153 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
36154 @@ -240,9 +240,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
36155 * sequence counter given by mac80211.
36156 */
36157 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
36158 - seqno = atomic_add_return(0x10, &intf->seqno);
36159 + seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
36160 else
36161 - seqno = atomic_read(&intf->seqno);
36162 + seqno = atomic_read_unchecked(&intf->seqno);
36163
36164 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
36165 hdr->seq_ctrl |= cpu_to_le16(seqno);
36166 diff --git a/drivers/net/wireless/ti/wl1251/wl1251.h b/drivers/net/wireless/ti/wl1251/wl1251.h
36167 index fd02060..74ee481 100644
36168 --- a/drivers/net/wireless/ti/wl1251/wl1251.h
36169 +++ b/drivers/net/wireless/ti/wl1251/wl1251.h
36170 @@ -266,7 +266,7 @@ struct wl1251_if_operations {
36171 void (*reset)(struct wl1251 *wl);
36172 void (*enable_irq)(struct wl1251 *wl);
36173 void (*disable_irq)(struct wl1251 *wl);
36174 -};
36175 +} __no_const;
36176
36177 struct wl1251 {
36178 struct ieee80211_hw *hw;
36179 diff --git a/drivers/net/wireless/ti/wlcore/wlcore.h b/drivers/net/wireless/ti/wlcore/wlcore.h
36180 index 0ce7a8e..56a0ccf 100644
36181 --- a/drivers/net/wireless/ti/wlcore/wlcore.h
36182 +++ b/drivers/net/wireless/ti/wlcore/wlcore.h
36183 @@ -81,7 +81,7 @@ struct wlcore_ops {
36184 struct ieee80211_sta *sta,
36185 struct ieee80211_key_conf *key_conf);
36186 u32 (*pre_pkt_send)(struct wl1271 *wl, u32 buf_offset, u32 last_len);
36187 -};
36188 +} __no_const;
36189
36190 enum wlcore_partitions {
36191 PART_DOWN,
36192 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
36193 index f34b5b2..b5abb9f 100644
36194 --- a/drivers/oprofile/buffer_sync.c
36195 +++ b/drivers/oprofile/buffer_sync.c
36196 @@ -343,7 +343,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
36197 if (cookie == NO_COOKIE)
36198 offset = pc;
36199 if (cookie == INVALID_COOKIE) {
36200 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
36201 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
36202 offset = pc;
36203 }
36204 if (cookie != last_cookie) {
36205 @@ -387,14 +387,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
36206 /* add userspace sample */
36207
36208 if (!mm) {
36209 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
36210 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
36211 return 0;
36212 }
36213
36214 cookie = lookup_dcookie(mm, s->eip, &offset);
36215
36216 if (cookie == INVALID_COOKIE) {
36217 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
36218 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
36219 return 0;
36220 }
36221
36222 @@ -563,7 +563,7 @@ void sync_buffer(int cpu)
36223 /* ignore backtraces if failed to add a sample */
36224 if (state == sb_bt_start) {
36225 state = sb_bt_ignore;
36226 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
36227 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
36228 }
36229 }
36230 release_mm(mm);
36231 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
36232 index c0cc4e7..44d4e54 100644
36233 --- a/drivers/oprofile/event_buffer.c
36234 +++ b/drivers/oprofile/event_buffer.c
36235 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
36236 }
36237
36238 if (buffer_pos == buffer_size) {
36239 - atomic_inc(&oprofile_stats.event_lost_overflow);
36240 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
36241 return;
36242 }
36243
36244 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
36245 index ed2c3ec..deda85a 100644
36246 --- a/drivers/oprofile/oprof.c
36247 +++ b/drivers/oprofile/oprof.c
36248 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
36249 if (oprofile_ops.switch_events())
36250 return;
36251
36252 - atomic_inc(&oprofile_stats.multiplex_counter);
36253 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
36254 start_switch_worker();
36255 }
36256
36257 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
36258 index 917d28e..d62d981 100644
36259 --- a/drivers/oprofile/oprofile_stats.c
36260 +++ b/drivers/oprofile/oprofile_stats.c
36261 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
36262 cpu_buf->sample_invalid_eip = 0;
36263 }
36264
36265 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
36266 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
36267 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
36268 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
36269 - atomic_set(&oprofile_stats.multiplex_counter, 0);
36270 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
36271 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
36272 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
36273 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
36274 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
36275 }
36276
36277
36278 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
36279 index 38b6fc0..b5cbfce 100644
36280 --- a/drivers/oprofile/oprofile_stats.h
36281 +++ b/drivers/oprofile/oprofile_stats.h
36282 @@ -13,11 +13,11 @@
36283 #include <linux/atomic.h>
36284
36285 struct oprofile_stat_struct {
36286 - atomic_t sample_lost_no_mm;
36287 - atomic_t sample_lost_no_mapping;
36288 - atomic_t bt_lost_no_mapping;
36289 - atomic_t event_lost_overflow;
36290 - atomic_t multiplex_counter;
36291 + atomic_unchecked_t sample_lost_no_mm;
36292 + atomic_unchecked_t sample_lost_no_mapping;
36293 + atomic_unchecked_t bt_lost_no_mapping;
36294 + atomic_unchecked_t event_lost_overflow;
36295 + atomic_unchecked_t multiplex_counter;
36296 };
36297
36298 extern struct oprofile_stat_struct oprofile_stats;
36299 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
36300 index 849357c..b83c1e0 100644
36301 --- a/drivers/oprofile/oprofilefs.c
36302 +++ b/drivers/oprofile/oprofilefs.c
36303 @@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
36304
36305
36306 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
36307 - char const *name, atomic_t *val)
36308 + char const *name, atomic_unchecked_t *val)
36309 {
36310 return __oprofilefs_create_file(sb, root, name,
36311 &atomic_ro_fops, 0444, val);
36312 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
36313 index 3f56bc0..707d642 100644
36314 --- a/drivers/parport/procfs.c
36315 +++ b/drivers/parport/procfs.c
36316 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
36317
36318 *ppos += len;
36319
36320 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
36321 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
36322 }
36323
36324 #ifdef CONFIG_PARPORT_1284
36325 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
36326
36327 *ppos += len;
36328
36329 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
36330 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
36331 }
36332 #endif /* IEEE1284.3 support. */
36333
36334 diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
36335 index 9fff878..ad0ad53 100644
36336 --- a/drivers/pci/hotplug/cpci_hotplug.h
36337 +++ b/drivers/pci/hotplug/cpci_hotplug.h
36338 @@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
36339 int (*hardware_test) (struct slot* slot, u32 value);
36340 u8 (*get_power) (struct slot* slot);
36341 int (*set_power) (struct slot* slot, int value);
36342 -};
36343 +} __no_const;
36344
36345 struct cpci_hp_controller {
36346 unsigned int irq;
36347 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
36348 index 76ba8a1..20ca857 100644
36349 --- a/drivers/pci/hotplug/cpqphp_nvram.c
36350 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
36351 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
36352
36353 void compaq_nvram_init (void __iomem *rom_start)
36354 {
36355 +
36356 +#ifndef CONFIG_PAX_KERNEXEC
36357 if (rom_start) {
36358 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
36359 }
36360 +#endif
36361 +
36362 dbg("int15 entry = %p\n", compaq_int15_entry_point);
36363
36364 /* initialize our int15 lock */
36365 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
36366 index b500840..d7159d3 100644
36367 --- a/drivers/pci/pcie/aspm.c
36368 +++ b/drivers/pci/pcie/aspm.c
36369 @@ -27,9 +27,9 @@
36370 #define MODULE_PARAM_PREFIX "pcie_aspm."
36371
36372 /* Note: those are not register definitions */
36373 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
36374 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
36375 -#define ASPM_STATE_L1 (4) /* L1 state */
36376 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
36377 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
36378 +#define ASPM_STATE_L1 (4U) /* L1 state */
36379 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
36380 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
36381
36382 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
36383 index 61859d0..124539e 100644
36384 --- a/drivers/pci/probe.c
36385 +++ b/drivers/pci/probe.c
36386 @@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
36387 struct pci_bus_region region;
36388 bool bar_too_big = false, bar_disabled = false;
36389
36390 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
36391 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
36392
36393 /* No printks while decoding is disabled! */
36394 if (!dev->mmio_always_on) {
36395 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
36396 index 27911b5..5b6db88 100644
36397 --- a/drivers/pci/proc.c
36398 +++ b/drivers/pci/proc.c
36399 @@ -476,7 +476,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
36400 static int __init pci_proc_init(void)
36401 {
36402 struct pci_dev *dev = NULL;
36403 +
36404 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
36405 +#ifdef CONFIG_GRKERNSEC_PROC_USER
36406 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
36407 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
36408 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
36409 +#endif
36410 +#else
36411 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
36412 +#endif
36413 proc_create("devices", 0, proc_bus_pci_dir,
36414 &proc_bus_pci_dev_operations);
36415 proc_initialized = 1;
36416 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
36417 index 52daaa8..d6b81eb 100644
36418 --- a/drivers/platform/x86/thinkpad_acpi.c
36419 +++ b/drivers/platform/x86/thinkpad_acpi.c
36420 @@ -2097,7 +2097,7 @@ static int hotkey_mask_get(void)
36421 return 0;
36422 }
36423
36424 -void static hotkey_mask_warn_incomplete_mask(void)
36425 +static void hotkey_mask_warn_incomplete_mask(void)
36426 {
36427 /* log only what the user can fix... */
36428 const u32 wantedmask = hotkey_driver_mask &
36429 @@ -2328,11 +2328,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
36430 }
36431 }
36432
36433 -static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36434 - struct tp_nvram_state *newn,
36435 - const u32 event_mask)
36436 -{
36437 -
36438 #define TPACPI_COMPARE_KEY(__scancode, __member) \
36439 do { \
36440 if ((event_mask & (1 << __scancode)) && \
36441 @@ -2346,36 +2341,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36442 tpacpi_hotkey_send_key(__scancode); \
36443 } while (0)
36444
36445 - void issue_volchange(const unsigned int oldvol,
36446 - const unsigned int newvol)
36447 - {
36448 - unsigned int i = oldvol;
36449 +static void issue_volchange(const unsigned int oldvol,
36450 + const unsigned int newvol,
36451 + const u32 event_mask)
36452 +{
36453 + unsigned int i = oldvol;
36454
36455 - while (i > newvol) {
36456 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
36457 - i--;
36458 - }
36459 - while (i < newvol) {
36460 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36461 - i++;
36462 - }
36463 + while (i > newvol) {
36464 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
36465 + i--;
36466 }
36467 + while (i < newvol) {
36468 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36469 + i++;
36470 + }
36471 +}
36472
36473 - void issue_brightnesschange(const unsigned int oldbrt,
36474 - const unsigned int newbrt)
36475 - {
36476 - unsigned int i = oldbrt;
36477 +static void issue_brightnesschange(const unsigned int oldbrt,
36478 + const unsigned int newbrt,
36479 + const u32 event_mask)
36480 +{
36481 + unsigned int i = oldbrt;
36482
36483 - while (i > newbrt) {
36484 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
36485 - i--;
36486 - }
36487 - while (i < newbrt) {
36488 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36489 - i++;
36490 - }
36491 + while (i > newbrt) {
36492 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
36493 + i--;
36494 + }
36495 + while (i < newbrt) {
36496 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36497 + i++;
36498 }
36499 +}
36500
36501 +static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36502 + struct tp_nvram_state *newn,
36503 + const u32 event_mask)
36504 +{
36505 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
36506 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
36507 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
36508 @@ -2409,7 +2410,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36509 oldn->volume_level != newn->volume_level) {
36510 /* recently muted, or repeated mute keypress, or
36511 * multiple presses ending in mute */
36512 - issue_volchange(oldn->volume_level, newn->volume_level);
36513 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36514 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
36515 }
36516 } else {
36517 @@ -2419,7 +2420,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36518 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36519 }
36520 if (oldn->volume_level != newn->volume_level) {
36521 - issue_volchange(oldn->volume_level, newn->volume_level);
36522 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36523 } else if (oldn->volume_toggle != newn->volume_toggle) {
36524 /* repeated vol up/down keypress at end of scale ? */
36525 if (newn->volume_level == 0)
36526 @@ -2432,7 +2433,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36527 /* handle brightness */
36528 if (oldn->brightness_level != newn->brightness_level) {
36529 issue_brightnesschange(oldn->brightness_level,
36530 - newn->brightness_level);
36531 + newn->brightness_level,
36532 + event_mask);
36533 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
36534 /* repeated key presses that didn't change state */
36535 if (newn->brightness_level == 0)
36536 @@ -2441,10 +2443,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36537 && !tp_features.bright_unkfw)
36538 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36539 }
36540 +}
36541
36542 #undef TPACPI_COMPARE_KEY
36543 #undef TPACPI_MAY_SEND_KEY
36544 -}
36545
36546 /*
36547 * Polling driver
36548 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
36549 index 769d265..a3a05ca 100644
36550 --- a/drivers/pnp/pnpbios/bioscalls.c
36551 +++ b/drivers/pnp/pnpbios/bioscalls.c
36552 @@ -58,7 +58,7 @@ do { \
36553 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
36554 } while(0)
36555
36556 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
36557 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
36558 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
36559
36560 /*
36561 @@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36562
36563 cpu = get_cpu();
36564 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
36565 +
36566 + pax_open_kernel();
36567 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
36568 + pax_close_kernel();
36569
36570 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
36571 spin_lock_irqsave(&pnp_bios_lock, flags);
36572 @@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36573 :"memory");
36574 spin_unlock_irqrestore(&pnp_bios_lock, flags);
36575
36576 + pax_open_kernel();
36577 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
36578 + pax_close_kernel();
36579 +
36580 put_cpu();
36581
36582 /* If we get here and this is set then the PnP BIOS faulted on us. */
36583 @@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
36584 return status;
36585 }
36586
36587 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
36588 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
36589 {
36590 int i;
36591
36592 @@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36593 pnp_bios_callpoint.offset = header->fields.pm16offset;
36594 pnp_bios_callpoint.segment = PNP_CS16;
36595
36596 + pax_open_kernel();
36597 +
36598 for_each_possible_cpu(i) {
36599 struct desc_struct *gdt = get_cpu_gdt_table(i);
36600 if (!gdt)
36601 @@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36602 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
36603 (unsigned long)__va(header->fields.pm16dseg));
36604 }
36605 +
36606 + pax_close_kernel();
36607 }
36608 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
36609 index b0ecacb..7c9da2e 100644
36610 --- a/drivers/pnp/resource.c
36611 +++ b/drivers/pnp/resource.c
36612 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
36613 return 1;
36614
36615 /* check if the resource is valid */
36616 - if (*irq < 0 || *irq > 15)
36617 + if (*irq > 15)
36618 return 0;
36619
36620 /* check if the resource is reserved */
36621 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
36622 return 1;
36623
36624 /* check if the resource is valid */
36625 - if (*dma < 0 || *dma == 4 || *dma > 7)
36626 + if (*dma == 4 || *dma > 7)
36627 return 0;
36628
36629 /* check if the resource is reserved */
36630 diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
36631 index 181ddec..774b6da 100644
36632 --- a/drivers/power/bq27x00_battery.c
36633 +++ b/drivers/power/bq27x00_battery.c
36634 @@ -80,7 +80,7 @@
36635 struct bq27x00_device_info;
36636 struct bq27x00_access_methods {
36637 int (*read)(struct bq27x00_device_info *di, u8 reg, bool single);
36638 -};
36639 +} __no_const;
36640
36641 enum bq27x00_chip { BQ27000, BQ27500, BQ27425};
36642
36643 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
36644 index 8d53174..04c65de 100644
36645 --- a/drivers/regulator/max8660.c
36646 +++ b/drivers/regulator/max8660.c
36647 @@ -333,8 +333,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
36648 max8660->shadow_regs[MAX8660_OVER1] = 5;
36649 } else {
36650 /* Otherwise devices can be toggled via software */
36651 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
36652 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
36653 + pax_open_kernel();
36654 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
36655 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
36656 + pax_close_kernel();
36657 }
36658
36659 /*
36660 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
36661 index b388b74..ed82573 100644
36662 --- a/drivers/regulator/mc13892-regulator.c
36663 +++ b/drivers/regulator/mc13892-regulator.c
36664 @@ -565,10 +565,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
36665 }
36666 mc13xxx_unlock(mc13892);
36667
36668 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36669 + pax_open_kernel();
36670 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36671 = mc13892_vcam_set_mode;
36672 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36673 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36674 = mc13892_vcam_get_mode;
36675 + pax_close_kernel();
36676
36677 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
36678 ARRAY_SIZE(mc13892_regulators));
36679 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
36680 index cace6d3..f623fda 100644
36681 --- a/drivers/rtc/rtc-dev.c
36682 +++ b/drivers/rtc/rtc-dev.c
36683 @@ -14,6 +14,7 @@
36684 #include <linux/module.h>
36685 #include <linux/rtc.h>
36686 #include <linux/sched.h>
36687 +#include <linux/grsecurity.h>
36688 #include "rtc-core.h"
36689
36690 static dev_t rtc_devt;
36691 @@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
36692 if (copy_from_user(&tm, uarg, sizeof(tm)))
36693 return -EFAULT;
36694
36695 + gr_log_timechange();
36696 +
36697 return rtc_set_time(rtc, &tm);
36698
36699 case RTC_PIE_ON:
36700 diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
36701 index 9e933a8..4f969f7 100644
36702 --- a/drivers/scsi/aacraid/aacraid.h
36703 +++ b/drivers/scsi/aacraid/aacraid.h
36704 @@ -503,7 +503,7 @@ struct adapter_ops
36705 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
36706 /* Administrative operations */
36707 int (*adapter_comm)(struct aac_dev * dev, int comm);
36708 -};
36709 +} __no_const;
36710
36711 /*
36712 * Define which interrupt handler needs to be installed
36713 diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
36714 index 7199534..cb7f158 100644
36715 --- a/drivers/scsi/aacraid/linit.c
36716 +++ b/drivers/scsi/aacraid/linit.c
36717 @@ -93,7 +93,7 @@ static DECLARE_PCI_DEVICE_TABLE(aac_pci_tbl) = {
36718 #elif defined(__devinitconst)
36719 static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36720 #else
36721 -static const struct pci_device_id aac_pci_tbl[] __devinitdata = {
36722 +static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36723 #endif
36724 { 0x1028, 0x0001, 0x1028, 0x0001, 0, 0, 0 }, /* PERC 2/Si (Iguana/PERC2Si) */
36725 { 0x1028, 0x0002, 0x1028, 0x0002, 0, 0, 1 }, /* PERC 3/Di (Opal/PERC3Di) */
36726 diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
36727 index ff80552..1c4120c 100644
36728 --- a/drivers/scsi/aic94xx/aic94xx_init.c
36729 +++ b/drivers/scsi/aic94xx/aic94xx_init.c
36730 @@ -1012,7 +1012,7 @@ static struct sas_domain_function_template aic94xx_transport_functions = {
36731 .lldd_ata_set_dmamode = asd_set_dmamode,
36732 };
36733
36734 -static const struct pci_device_id aic94xx_pci_table[] __devinitdata = {
36735 +static const struct pci_device_id aic94xx_pci_table[] __devinitconst = {
36736 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x410),0, 0, 1},
36737 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x412),0, 0, 1},
36738 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x416),0, 0, 1},
36739 diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
36740 index 4ad7e36..d004679 100644
36741 --- a/drivers/scsi/bfa/bfa.h
36742 +++ b/drivers/scsi/bfa/bfa.h
36743 @@ -196,7 +196,7 @@ struct bfa_hwif_s {
36744 u32 *end);
36745 int cpe_vec_q0;
36746 int rme_vec_q0;
36747 -};
36748 +} __no_const;
36749 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
36750
36751 struct bfa_faa_cbfn_s {
36752 diff --git a/drivers/scsi/bfa/bfa_fcpim.c b/drivers/scsi/bfa/bfa_fcpim.c
36753 index f0f80e2..8ec946b 100644
36754 --- a/drivers/scsi/bfa/bfa_fcpim.c
36755 +++ b/drivers/scsi/bfa/bfa_fcpim.c
36756 @@ -3715,7 +3715,7 @@ bfa_fcp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
36757
36758 bfa_iotag_attach(fcp);
36759
36760 - fcp->itn_arr = (struct bfa_itn_s *) bfa_mem_kva_curp(fcp);
36761 + fcp->itn_arr = (bfa_itn_s_no_const *) bfa_mem_kva_curp(fcp);
36762 bfa_mem_kva_curp(fcp) = (u8 *)fcp->itn_arr +
36763 (fcp->num_itns * sizeof(struct bfa_itn_s));
36764 memset(fcp->itn_arr, 0,
36765 @@ -3773,7 +3773,7 @@ bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36766 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m))
36767 {
36768 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
36769 - struct bfa_itn_s *itn;
36770 + bfa_itn_s_no_const *itn;
36771
36772 itn = BFA_ITN_FROM_TAG(fcp, rport->rport_tag);
36773 itn->isr = isr;
36774 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
36775 index 36f26da..38a34a8 100644
36776 --- a/drivers/scsi/bfa/bfa_fcpim.h
36777 +++ b/drivers/scsi/bfa/bfa_fcpim.h
36778 @@ -37,6 +37,7 @@ struct bfa_iotag_s {
36779 struct bfa_itn_s {
36780 bfa_isr_func_t isr;
36781 };
36782 +typedef struct bfa_itn_s __no_const bfa_itn_s_no_const;
36783
36784 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36785 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
36786 @@ -147,7 +148,7 @@ struct bfa_fcp_mod_s {
36787 struct list_head iotag_tio_free_q; /* free IO resources */
36788 struct list_head iotag_unused_q; /* unused IO resources*/
36789 struct bfa_iotag_s *iotag_arr;
36790 - struct bfa_itn_s *itn_arr;
36791 + bfa_itn_s_no_const *itn_arr;
36792 int num_ioim_reqs;
36793 int num_fwtio_reqs;
36794 int num_itns;
36795 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
36796 index 1a99d4b..e85d64b 100644
36797 --- a/drivers/scsi/bfa/bfa_ioc.h
36798 +++ b/drivers/scsi/bfa/bfa_ioc.h
36799 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
36800 bfa_ioc_disable_cbfn_t disable_cbfn;
36801 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
36802 bfa_ioc_reset_cbfn_t reset_cbfn;
36803 -};
36804 +} __no_const;
36805
36806 /*
36807 * IOC event notification mechanism.
36808 @@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
36809 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
36810 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
36811 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
36812 -};
36813 +} __no_const;
36814
36815 /*
36816 * Queue element to wait for room in request queue. FIFO order is
36817 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
36818 index 593085a..47aa999 100644
36819 --- a/drivers/scsi/hosts.c
36820 +++ b/drivers/scsi/hosts.c
36821 @@ -42,7 +42,7 @@
36822 #include "scsi_logging.h"
36823
36824
36825 -static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
36826 +static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
36827
36828
36829 static void scsi_host_cls_release(struct device *dev)
36830 @@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
36831 * subtract one because we increment first then return, but we need to
36832 * know what the next host number was before increment
36833 */
36834 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
36835 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
36836 shost->dma_channel = 0xff;
36837
36838 /* These three are default values which can be overridden */
36839 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
36840 index f9823f2..7bc3e81 100644
36841 --- a/drivers/scsi/hpsa.c
36842 +++ b/drivers/scsi/hpsa.c
36843 @@ -536,7 +536,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
36844 unsigned long flags;
36845
36846 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
36847 - return h->access.command_completed(h, q);
36848 + return h->access->command_completed(h, q);
36849
36850 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
36851 a = rq->head[rq->current_entry];
36852 @@ -3355,7 +3355,7 @@ static void start_io(struct ctlr_info *h)
36853 while (!list_empty(&h->reqQ)) {
36854 c = list_entry(h->reqQ.next, struct CommandList, list);
36855 /* can't do anything if fifo is full */
36856 - if ((h->access.fifo_full(h))) {
36857 + if ((h->access->fifo_full(h))) {
36858 dev_warn(&h->pdev->dev, "fifo full\n");
36859 break;
36860 }
36861 @@ -3377,7 +3377,7 @@ static void start_io(struct ctlr_info *h)
36862
36863 /* Tell the controller execute command */
36864 spin_unlock_irqrestore(&h->lock, flags);
36865 - h->access.submit_command(h, c);
36866 + h->access->submit_command(h, c);
36867 spin_lock_irqsave(&h->lock, flags);
36868 }
36869 spin_unlock_irqrestore(&h->lock, flags);
36870 @@ -3385,17 +3385,17 @@ static void start_io(struct ctlr_info *h)
36871
36872 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
36873 {
36874 - return h->access.command_completed(h, q);
36875 + return h->access->command_completed(h, q);
36876 }
36877
36878 static inline bool interrupt_pending(struct ctlr_info *h)
36879 {
36880 - return h->access.intr_pending(h);
36881 + return h->access->intr_pending(h);
36882 }
36883
36884 static inline long interrupt_not_for_us(struct ctlr_info *h)
36885 {
36886 - return (h->access.intr_pending(h) == 0) ||
36887 + return (h->access->intr_pending(h) == 0) ||
36888 (h->interrupts_enabled == 0);
36889 }
36890
36891 @@ -4299,7 +4299,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
36892 if (prod_index < 0)
36893 return -ENODEV;
36894 h->product_name = products[prod_index].product_name;
36895 - h->access = *(products[prod_index].access);
36896 + h->access = products[prod_index].access;
36897
36898 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
36899 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
36900 @@ -4581,7 +4581,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
36901
36902 assert_spin_locked(&lockup_detector_lock);
36903 remove_ctlr_from_lockup_detector_list(h);
36904 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36905 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36906 spin_lock_irqsave(&h->lock, flags);
36907 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
36908 spin_unlock_irqrestore(&h->lock, flags);
36909 @@ -4759,7 +4759,7 @@ reinit_after_soft_reset:
36910 }
36911
36912 /* make sure the board interrupts are off */
36913 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36914 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36915
36916 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
36917 goto clean2;
36918 @@ -4793,7 +4793,7 @@ reinit_after_soft_reset:
36919 * fake ones to scoop up any residual completions.
36920 */
36921 spin_lock_irqsave(&h->lock, flags);
36922 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36923 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36924 spin_unlock_irqrestore(&h->lock, flags);
36925 free_irqs(h);
36926 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
36927 @@ -4812,9 +4812,9 @@ reinit_after_soft_reset:
36928 dev_info(&h->pdev->dev, "Board READY.\n");
36929 dev_info(&h->pdev->dev,
36930 "Waiting for stale completions to drain.\n");
36931 - h->access.set_intr_mask(h, HPSA_INTR_ON);
36932 + h->access->set_intr_mask(h, HPSA_INTR_ON);
36933 msleep(10000);
36934 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36935 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36936
36937 rc = controller_reset_failed(h->cfgtable);
36938 if (rc)
36939 @@ -4835,7 +4835,7 @@ reinit_after_soft_reset:
36940 }
36941
36942 /* Turn the interrupts on so we can service requests */
36943 - h->access.set_intr_mask(h, HPSA_INTR_ON);
36944 + h->access->set_intr_mask(h, HPSA_INTR_ON);
36945
36946 hpsa_hba_inquiry(h);
36947 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
36948 @@ -4887,7 +4887,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
36949 * To write all data in the battery backed cache to disks
36950 */
36951 hpsa_flush_cache(h);
36952 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36953 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36954 hpsa_free_irqs_and_disable_msix(h);
36955 }
36956
36957 @@ -5056,7 +5056,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
36958 return;
36959 }
36960 /* Change the access methods to the performant access methods */
36961 - h->access = SA5_performant_access;
36962 + h->access = &SA5_performant_access;
36963 h->transMethod = CFGTBL_Trans_Performant;
36964 }
36965
36966 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
36967 index 9816479..c5d4e97 100644
36968 --- a/drivers/scsi/hpsa.h
36969 +++ b/drivers/scsi/hpsa.h
36970 @@ -79,7 +79,7 @@ struct ctlr_info {
36971 unsigned int msix_vector;
36972 unsigned int msi_vector;
36973 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
36974 - struct access_method access;
36975 + struct access_method *access;
36976
36977 /* queue and queue Info */
36978 struct list_head reqQ;
36979 diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
36980 index f2df059..a3a9930 100644
36981 --- a/drivers/scsi/ips.h
36982 +++ b/drivers/scsi/ips.h
36983 @@ -1027,7 +1027,7 @@ typedef struct {
36984 int (*intr)(struct ips_ha *);
36985 void (*enableint)(struct ips_ha *);
36986 uint32_t (*statupd)(struct ips_ha *);
36987 -} ips_hw_func_t;
36988 +} __no_const ips_hw_func_t;
36989
36990 typedef struct ips_ha {
36991 uint8_t ha_id[IPS_MAX_CHANNELS+1];
36992 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
36993 index c772d8d..35c362c 100644
36994 --- a/drivers/scsi/libfc/fc_exch.c
36995 +++ b/drivers/scsi/libfc/fc_exch.c
36996 @@ -100,12 +100,12 @@ struct fc_exch_mgr {
36997 u16 pool_max_index;
36998
36999 struct {
37000 - atomic_t no_free_exch;
37001 - atomic_t no_free_exch_xid;
37002 - atomic_t xid_not_found;
37003 - atomic_t xid_busy;
37004 - atomic_t seq_not_found;
37005 - atomic_t non_bls_resp;
37006 + atomic_unchecked_t no_free_exch;
37007 + atomic_unchecked_t no_free_exch_xid;
37008 + atomic_unchecked_t xid_not_found;
37009 + atomic_unchecked_t xid_busy;
37010 + atomic_unchecked_t seq_not_found;
37011 + atomic_unchecked_t non_bls_resp;
37012 } stats;
37013 };
37014
37015 @@ -725,7 +725,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
37016 /* allocate memory for exchange */
37017 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
37018 if (!ep) {
37019 - atomic_inc(&mp->stats.no_free_exch);
37020 + atomic_inc_unchecked(&mp->stats.no_free_exch);
37021 goto out;
37022 }
37023 memset(ep, 0, sizeof(*ep));
37024 @@ -786,7 +786,7 @@ out:
37025 return ep;
37026 err:
37027 spin_unlock_bh(&pool->lock);
37028 - atomic_inc(&mp->stats.no_free_exch_xid);
37029 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
37030 mempool_free(ep, mp->ep_pool);
37031 return NULL;
37032 }
37033 @@ -929,7 +929,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
37034 xid = ntohs(fh->fh_ox_id); /* we originated exch */
37035 ep = fc_exch_find(mp, xid);
37036 if (!ep) {
37037 - atomic_inc(&mp->stats.xid_not_found);
37038 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37039 reject = FC_RJT_OX_ID;
37040 goto out;
37041 }
37042 @@ -959,7 +959,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
37043 ep = fc_exch_find(mp, xid);
37044 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
37045 if (ep) {
37046 - atomic_inc(&mp->stats.xid_busy);
37047 + atomic_inc_unchecked(&mp->stats.xid_busy);
37048 reject = FC_RJT_RX_ID;
37049 goto rel;
37050 }
37051 @@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
37052 }
37053 xid = ep->xid; /* get our XID */
37054 } else if (!ep) {
37055 - atomic_inc(&mp->stats.xid_not_found);
37056 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37057 reject = FC_RJT_RX_ID; /* XID not found */
37058 goto out;
37059 }
37060 @@ -987,7 +987,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
37061 } else {
37062 sp = &ep->seq;
37063 if (sp->id != fh->fh_seq_id) {
37064 - atomic_inc(&mp->stats.seq_not_found);
37065 + atomic_inc_unchecked(&mp->stats.seq_not_found);
37066 if (f_ctl & FC_FC_END_SEQ) {
37067 /*
37068 * Update sequence_id based on incoming last
37069 @@ -1437,22 +1437,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
37070
37071 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
37072 if (!ep) {
37073 - atomic_inc(&mp->stats.xid_not_found);
37074 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37075 goto out;
37076 }
37077 if (ep->esb_stat & ESB_ST_COMPLETE) {
37078 - atomic_inc(&mp->stats.xid_not_found);
37079 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37080 goto rel;
37081 }
37082 if (ep->rxid == FC_XID_UNKNOWN)
37083 ep->rxid = ntohs(fh->fh_rx_id);
37084 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
37085 - atomic_inc(&mp->stats.xid_not_found);
37086 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37087 goto rel;
37088 }
37089 if (ep->did != ntoh24(fh->fh_s_id) &&
37090 ep->did != FC_FID_FLOGI) {
37091 - atomic_inc(&mp->stats.xid_not_found);
37092 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37093 goto rel;
37094 }
37095 sof = fr_sof(fp);
37096 @@ -1461,7 +1461,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
37097 sp->ssb_stat |= SSB_ST_RESP;
37098 sp->id = fh->fh_seq_id;
37099 } else if (sp->id != fh->fh_seq_id) {
37100 - atomic_inc(&mp->stats.seq_not_found);
37101 + atomic_inc_unchecked(&mp->stats.seq_not_found);
37102 goto rel;
37103 }
37104
37105 @@ -1525,9 +1525,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
37106 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
37107
37108 if (!sp)
37109 - atomic_inc(&mp->stats.xid_not_found);
37110 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37111 else
37112 - atomic_inc(&mp->stats.non_bls_resp);
37113 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
37114
37115 fc_frame_free(fp);
37116 }
37117 @@ -2174,13 +2174,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
37118
37119 list_for_each_entry(ema, &lport->ema_list, ema_list) {
37120 mp = ema->mp;
37121 - st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
37122 + st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
37123 st->fc_no_free_exch_xid +=
37124 - atomic_read(&mp->stats.no_free_exch_xid);
37125 - st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
37126 - st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
37127 - st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
37128 - st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
37129 + atomic_read_unchecked(&mp->stats.no_free_exch_xid);
37130 + st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
37131 + st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
37132 + st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
37133 + st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
37134 }
37135 }
37136 EXPORT_SYMBOL(fc_exch_update_stats);
37137 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
37138 index a59fcdc..abe55f3 100644
37139 --- a/drivers/scsi/libsas/sas_ata.c
37140 +++ b/drivers/scsi/libsas/sas_ata.c
37141 @@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
37142 .postreset = ata_std_postreset,
37143 .error_handler = ata_std_error_handler,
37144 .post_internal_cmd = sas_ata_post_internal,
37145 - .qc_defer = ata_std_qc_defer,
37146 + .qc_defer = ata_std_qc_defer,
37147 .qc_prep = ata_noop_qc_prep,
37148 .qc_issue = sas_ata_qc_issue,
37149 .qc_fill_rtf = sas_ata_qc_fill_rtf,
37150 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
37151 index a65c05a..a39e402 100644
37152 --- a/drivers/scsi/lpfc/lpfc.h
37153 +++ b/drivers/scsi/lpfc/lpfc.h
37154 @@ -420,7 +420,7 @@ struct lpfc_vport {
37155 struct dentry *debug_nodelist;
37156 struct dentry *vport_debugfs_root;
37157 struct lpfc_debugfs_trc *disc_trc;
37158 - atomic_t disc_trc_cnt;
37159 + atomic_unchecked_t disc_trc_cnt;
37160 #endif
37161 uint8_t stat_data_enabled;
37162 uint8_t stat_data_blocked;
37163 @@ -834,8 +834,8 @@ struct lpfc_hba {
37164 struct timer_list fabric_block_timer;
37165 unsigned long bit_flags;
37166 #define FABRIC_COMANDS_BLOCKED 0
37167 - atomic_t num_rsrc_err;
37168 - atomic_t num_cmd_success;
37169 + atomic_unchecked_t num_rsrc_err;
37170 + atomic_unchecked_t num_cmd_success;
37171 unsigned long last_rsrc_error_time;
37172 unsigned long last_ramp_down_time;
37173 unsigned long last_ramp_up_time;
37174 @@ -871,7 +871,7 @@ struct lpfc_hba {
37175
37176 struct dentry *debug_slow_ring_trc;
37177 struct lpfc_debugfs_trc *slow_ring_trc;
37178 - atomic_t slow_ring_trc_cnt;
37179 + atomic_unchecked_t slow_ring_trc_cnt;
37180 /* iDiag debugfs sub-directory */
37181 struct dentry *idiag_root;
37182 struct dentry *idiag_pci_cfg;
37183 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
37184 index 3217d63..c417981 100644
37185 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
37186 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
37187 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
37188
37189 #include <linux/debugfs.h>
37190
37191 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
37192 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
37193 static unsigned long lpfc_debugfs_start_time = 0L;
37194
37195 /* iDiag */
37196 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
37197 lpfc_debugfs_enable = 0;
37198
37199 len = 0;
37200 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
37201 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
37202 (lpfc_debugfs_max_disc_trc - 1);
37203 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
37204 dtp = vport->disc_trc + i;
37205 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
37206 lpfc_debugfs_enable = 0;
37207
37208 len = 0;
37209 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
37210 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
37211 (lpfc_debugfs_max_slow_ring_trc - 1);
37212 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
37213 dtp = phba->slow_ring_trc + i;
37214 @@ -636,14 +636,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
37215 !vport || !vport->disc_trc)
37216 return;
37217
37218 - index = atomic_inc_return(&vport->disc_trc_cnt) &
37219 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
37220 (lpfc_debugfs_max_disc_trc - 1);
37221 dtp = vport->disc_trc + index;
37222 dtp->fmt = fmt;
37223 dtp->data1 = data1;
37224 dtp->data2 = data2;
37225 dtp->data3 = data3;
37226 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
37227 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
37228 dtp->jif = jiffies;
37229 #endif
37230 return;
37231 @@ -674,14 +674,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
37232 !phba || !phba->slow_ring_trc)
37233 return;
37234
37235 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
37236 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
37237 (lpfc_debugfs_max_slow_ring_trc - 1);
37238 dtp = phba->slow_ring_trc + index;
37239 dtp->fmt = fmt;
37240 dtp->data1 = data1;
37241 dtp->data2 = data2;
37242 dtp->data3 = data3;
37243 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
37244 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
37245 dtp->jif = jiffies;
37246 #endif
37247 return;
37248 @@ -4090,7 +4090,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
37249 "slow_ring buffer\n");
37250 goto debug_failed;
37251 }
37252 - atomic_set(&phba->slow_ring_trc_cnt, 0);
37253 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
37254 memset(phba->slow_ring_trc, 0,
37255 (sizeof(struct lpfc_debugfs_trc) *
37256 lpfc_debugfs_max_slow_ring_trc));
37257 @@ -4136,7 +4136,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
37258 "buffer\n");
37259 goto debug_failed;
37260 }
37261 - atomic_set(&vport->disc_trc_cnt, 0);
37262 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
37263
37264 snprintf(name, sizeof(name), "discovery_trace");
37265 vport->debug_disc_trc =
37266 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
37267 index 45c1520..35ba744 100644
37268 --- a/drivers/scsi/lpfc/lpfc_init.c
37269 +++ b/drivers/scsi/lpfc/lpfc_init.c
37270 @@ -10478,8 +10478,10 @@ lpfc_init(void)
37271 "misc_register returned with status %d", error);
37272
37273 if (lpfc_enable_npiv) {
37274 - lpfc_transport_functions.vport_create = lpfc_vport_create;
37275 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
37276 + pax_open_kernel();
37277 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
37278 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
37279 + pax_close_kernel();
37280 }
37281 lpfc_transport_template =
37282 fc_attach_transport(&lpfc_transport_functions);
37283 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
37284 index 925975d..0f1fc07 100644
37285 --- a/drivers/scsi/lpfc/lpfc_scsi.c
37286 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
37287 @@ -311,7 +311,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
37288 uint32_t evt_posted;
37289
37290 spin_lock_irqsave(&phba->hbalock, flags);
37291 - atomic_inc(&phba->num_rsrc_err);
37292 + atomic_inc_unchecked(&phba->num_rsrc_err);
37293 phba->last_rsrc_error_time = jiffies;
37294
37295 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
37296 @@ -352,7 +352,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
37297 unsigned long flags;
37298 struct lpfc_hba *phba = vport->phba;
37299 uint32_t evt_posted;
37300 - atomic_inc(&phba->num_cmd_success);
37301 + atomic_inc_unchecked(&phba->num_cmd_success);
37302
37303 if (vport->cfg_lun_queue_depth <= queue_depth)
37304 return;
37305 @@ -396,8 +396,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
37306 unsigned long num_rsrc_err, num_cmd_success;
37307 int i;
37308
37309 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
37310 - num_cmd_success = atomic_read(&phba->num_cmd_success);
37311 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
37312 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
37313
37314 /*
37315 * The error and success command counters are global per
37316 @@ -425,8 +425,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
37317 }
37318 }
37319 lpfc_destroy_vport_work_array(phba, vports);
37320 - atomic_set(&phba->num_rsrc_err, 0);
37321 - atomic_set(&phba->num_cmd_success, 0);
37322 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
37323 + atomic_set_unchecked(&phba->num_cmd_success, 0);
37324 }
37325
37326 /**
37327 @@ -460,8 +460,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
37328 }
37329 }
37330 lpfc_destroy_vport_work_array(phba, vports);
37331 - atomic_set(&phba->num_rsrc_err, 0);
37332 - atomic_set(&phba->num_cmd_success, 0);
37333 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
37334 + atomic_set_unchecked(&phba->num_cmd_success, 0);
37335 }
37336
37337 /**
37338 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
37339 index ea8a0b4..812a124 100644
37340 --- a/drivers/scsi/pmcraid.c
37341 +++ b/drivers/scsi/pmcraid.c
37342 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
37343 res->scsi_dev = scsi_dev;
37344 scsi_dev->hostdata = res;
37345 res->change_detected = 0;
37346 - atomic_set(&res->read_failures, 0);
37347 - atomic_set(&res->write_failures, 0);
37348 + atomic_set_unchecked(&res->read_failures, 0);
37349 + atomic_set_unchecked(&res->write_failures, 0);
37350 rc = 0;
37351 }
37352 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
37353 @@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
37354
37355 /* If this was a SCSI read/write command keep count of errors */
37356 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
37357 - atomic_inc(&res->read_failures);
37358 + atomic_inc_unchecked(&res->read_failures);
37359 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
37360 - atomic_inc(&res->write_failures);
37361 + atomic_inc_unchecked(&res->write_failures);
37362
37363 if (!RES_IS_GSCSI(res->cfg_entry) &&
37364 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
37365 @@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
37366 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
37367 * hrrq_id assigned here in queuecommand
37368 */
37369 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
37370 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
37371 pinstance->num_hrrq;
37372 cmd->cmd_done = pmcraid_io_done;
37373
37374 @@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
37375 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
37376 * hrrq_id assigned here in queuecommand
37377 */
37378 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
37379 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
37380 pinstance->num_hrrq;
37381
37382 if (request_size) {
37383 @@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
37384
37385 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
37386 /* add resources only after host is added into system */
37387 - if (!atomic_read(&pinstance->expose_resources))
37388 + if (!atomic_read_unchecked(&pinstance->expose_resources))
37389 return;
37390
37391 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
37392 @@ -5331,8 +5331,8 @@ static int __devinit pmcraid_init_instance(
37393 init_waitqueue_head(&pinstance->reset_wait_q);
37394
37395 atomic_set(&pinstance->outstanding_cmds, 0);
37396 - atomic_set(&pinstance->last_message_id, 0);
37397 - atomic_set(&pinstance->expose_resources, 0);
37398 + atomic_set_unchecked(&pinstance->last_message_id, 0);
37399 + atomic_set_unchecked(&pinstance->expose_resources, 0);
37400
37401 INIT_LIST_HEAD(&pinstance->free_res_q);
37402 INIT_LIST_HEAD(&pinstance->used_res_q);
37403 @@ -6047,7 +6047,7 @@ static int __devinit pmcraid_probe(
37404 /* Schedule worker thread to handle CCN and take care of adding and
37405 * removing devices to OS
37406 */
37407 - atomic_set(&pinstance->expose_resources, 1);
37408 + atomic_set_unchecked(&pinstance->expose_resources, 1);
37409 schedule_work(&pinstance->worker_q);
37410 return rc;
37411
37412 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
37413 index e1d150f..6c6df44 100644
37414 --- a/drivers/scsi/pmcraid.h
37415 +++ b/drivers/scsi/pmcraid.h
37416 @@ -748,7 +748,7 @@ struct pmcraid_instance {
37417 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
37418
37419 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
37420 - atomic_t last_message_id;
37421 + atomic_unchecked_t last_message_id;
37422
37423 /* configuration table */
37424 struct pmcraid_config_table *cfg_table;
37425 @@ -777,7 +777,7 @@ struct pmcraid_instance {
37426 atomic_t outstanding_cmds;
37427
37428 /* should add/delete resources to mid-layer now ?*/
37429 - atomic_t expose_resources;
37430 + atomic_unchecked_t expose_resources;
37431
37432
37433
37434 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
37435 struct pmcraid_config_table_entry_ext cfg_entry_ext;
37436 };
37437 struct scsi_device *scsi_dev; /* Link scsi_device structure */
37438 - atomic_t read_failures; /* count of failed READ commands */
37439 - atomic_t write_failures; /* count of failed WRITE commands */
37440 + atomic_unchecked_t read_failures; /* count of failed READ commands */
37441 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
37442
37443 /* To indicate add/delete/modify during CCN */
37444 u8 change_detected;
37445 diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
37446 index 5ab9530..2dd80f7 100644
37447 --- a/drivers/scsi/qla2xxx/qla_attr.c
37448 +++ b/drivers/scsi/qla2xxx/qla_attr.c
37449 @@ -1855,7 +1855,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
37450 return 0;
37451 }
37452
37453 -struct fc_function_template qla2xxx_transport_functions = {
37454 +fc_function_template_no_const qla2xxx_transport_functions = {
37455
37456 .show_host_node_name = 1,
37457 .show_host_port_name = 1,
37458 @@ -1902,7 +1902,7 @@ struct fc_function_template qla2xxx_transport_functions = {
37459 .bsg_timeout = qla24xx_bsg_timeout,
37460 };
37461
37462 -struct fc_function_template qla2xxx_transport_vport_functions = {
37463 +fc_function_template_no_const qla2xxx_transport_vport_functions = {
37464
37465 .show_host_node_name = 1,
37466 .show_host_port_name = 1,
37467 diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
37468 index 39007f5..7fafc64 100644
37469 --- a/drivers/scsi/qla2xxx/qla_def.h
37470 +++ b/drivers/scsi/qla2xxx/qla_def.h
37471 @@ -2284,7 +2284,7 @@ struct isp_operations {
37472 int (*start_scsi) (srb_t *);
37473 int (*abort_isp) (struct scsi_qla_host *);
37474 int (*iospace_config)(struct qla_hw_data*);
37475 -};
37476 +} __no_const;
37477
37478 /* MSI-X Support *************************************************************/
37479
37480 diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
37481 index 9eacd2d..d79629c 100644
37482 --- a/drivers/scsi/qla2xxx/qla_gbl.h
37483 +++ b/drivers/scsi/qla2xxx/qla_gbl.h
37484 @@ -484,8 +484,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
37485 struct device_attribute;
37486 extern struct device_attribute *qla2x00_host_attrs[];
37487 struct fc_function_template;
37488 -extern struct fc_function_template qla2xxx_transport_functions;
37489 -extern struct fc_function_template qla2xxx_transport_vport_functions;
37490 +extern fc_function_template_no_const qla2xxx_transport_functions;
37491 +extern fc_function_template_no_const qla2xxx_transport_vport_functions;
37492 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
37493 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
37494 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
37495 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
37496 index 7fdba7f..1b4b2c2 100644
37497 --- a/drivers/scsi/qla4xxx/ql4_def.h
37498 +++ b/drivers/scsi/qla4xxx/ql4_def.h
37499 @@ -268,7 +268,7 @@ struct ddb_entry {
37500 * (4000 only) */
37501 atomic_t relogin_timer; /* Max Time to wait for
37502 * relogin to complete */
37503 - atomic_t relogin_retry_count; /* Num of times relogin has been
37504 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
37505 * retried */
37506 uint32_t default_time2wait; /* Default Min time between
37507 * relogins (+aens) */
37508 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
37509 index 9da4266..377b3b6 100644
37510 --- a/drivers/scsi/qla4xxx/ql4_os.c
37511 +++ b/drivers/scsi/qla4xxx/ql4_os.c
37512 @@ -2615,12 +2615,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
37513 */
37514 if (!iscsi_is_session_online(cls_sess)) {
37515 /* Reset retry relogin timer */
37516 - atomic_inc(&ddb_entry->relogin_retry_count);
37517 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
37518 DEBUG2(ql4_printk(KERN_INFO, ha,
37519 "%s: index[%d] relogin timed out-retrying"
37520 " relogin (%d), retry (%d)\n", __func__,
37521 ddb_entry->fw_ddb_index,
37522 - atomic_read(&ddb_entry->relogin_retry_count),
37523 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
37524 ddb_entry->default_time2wait + 4));
37525 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
37526 atomic_set(&ddb_entry->retry_relogin_timer,
37527 @@ -4635,7 +4635,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
37528
37529 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
37530 atomic_set(&ddb_entry->relogin_timer, 0);
37531 - atomic_set(&ddb_entry->relogin_retry_count, 0);
37532 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
37533 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
37534 ddb_entry->default_relogin_timeout =
37535 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
37536 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
37537 index 2936b44..546ecdb 100644
37538 --- a/drivers/scsi/scsi.c
37539 +++ b/drivers/scsi/scsi.c
37540 @@ -660,7 +660,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
37541 unsigned long timeout;
37542 int rtn = 0;
37543
37544 - atomic_inc(&cmd->device->iorequest_cnt);
37545 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37546
37547 /* check if the device is still usable */
37548 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
37549 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
37550 index faa790f..7e351ddd 100644
37551 --- a/drivers/scsi/scsi_lib.c
37552 +++ b/drivers/scsi/scsi_lib.c
37553 @@ -1442,7 +1442,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
37554 shost = sdev->host;
37555 scsi_init_cmd_errh(cmd);
37556 cmd->result = DID_NO_CONNECT << 16;
37557 - atomic_inc(&cmd->device->iorequest_cnt);
37558 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37559
37560 /*
37561 * SCSI request completion path will do scsi_device_unbusy(),
37562 @@ -1468,9 +1468,9 @@ static void scsi_softirq_done(struct request *rq)
37563
37564 INIT_LIST_HEAD(&cmd->eh_entry);
37565
37566 - atomic_inc(&cmd->device->iodone_cnt);
37567 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
37568 if (cmd->result)
37569 - atomic_inc(&cmd->device->ioerr_cnt);
37570 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
37571
37572 disposition = scsi_decide_disposition(cmd);
37573 if (disposition != SUCCESS &&
37574 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
37575 index ce5224c..8c6d071 100644
37576 --- a/drivers/scsi/scsi_sysfs.c
37577 +++ b/drivers/scsi/scsi_sysfs.c
37578 @@ -661,7 +661,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
37579 char *buf) \
37580 { \
37581 struct scsi_device *sdev = to_scsi_device(dev); \
37582 - unsigned long long count = atomic_read(&sdev->field); \
37583 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
37584 return snprintf(buf, 20, "0x%llx\n", count); \
37585 } \
37586 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
37587 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
37588 index 84a1fdf..693b0d6 100644
37589 --- a/drivers/scsi/scsi_tgt_lib.c
37590 +++ b/drivers/scsi/scsi_tgt_lib.c
37591 @@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
37592 int err;
37593
37594 dprintk("%lx %u\n", uaddr, len);
37595 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
37596 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
37597 if (err) {
37598 /*
37599 * TODO: need to fixup sg_tablesize, max_segment_size,
37600 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
37601 index e894ca7..de9d7660 100644
37602 --- a/drivers/scsi/scsi_transport_fc.c
37603 +++ b/drivers/scsi/scsi_transport_fc.c
37604 @@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
37605 * Netlink Infrastructure
37606 */
37607
37608 -static atomic_t fc_event_seq;
37609 +static atomic_unchecked_t fc_event_seq;
37610
37611 /**
37612 * fc_get_event_number - Obtain the next sequential FC event number
37613 @@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
37614 u32
37615 fc_get_event_number(void)
37616 {
37617 - return atomic_add_return(1, &fc_event_seq);
37618 + return atomic_add_return_unchecked(1, &fc_event_seq);
37619 }
37620 EXPORT_SYMBOL(fc_get_event_number);
37621
37622 @@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
37623 {
37624 int error;
37625
37626 - atomic_set(&fc_event_seq, 0);
37627 + atomic_set_unchecked(&fc_event_seq, 0);
37628
37629 error = transport_class_register(&fc_host_class);
37630 if (error)
37631 @@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
37632 char *cp;
37633
37634 *val = simple_strtoul(buf, &cp, 0);
37635 - if ((*cp && (*cp != '\n')) || (*val < 0))
37636 + if (*cp && (*cp != '\n'))
37637 return -EINVAL;
37638 /*
37639 * Check for overflow; dev_loss_tmo is u32
37640 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
37641 index fa1dfaa..4bb620c 100644
37642 --- a/drivers/scsi/scsi_transport_iscsi.c
37643 +++ b/drivers/scsi/scsi_transport_iscsi.c
37644 @@ -79,7 +79,7 @@ struct iscsi_internal {
37645 struct transport_container session_cont;
37646 };
37647
37648 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
37649 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
37650 static struct workqueue_struct *iscsi_eh_timer_workq;
37651
37652 static DEFINE_IDA(iscsi_sess_ida);
37653 @@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
37654 int err;
37655
37656 ihost = shost->shost_data;
37657 - session->sid = atomic_add_return(1, &iscsi_session_nr);
37658 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
37659
37660 if (target_id == ISCSI_MAX_TARGET) {
37661 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
37662 @@ -2943,7 +2943,7 @@ static __init int iscsi_transport_init(void)
37663 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
37664 ISCSI_TRANSPORT_VERSION);
37665
37666 - atomic_set(&iscsi_session_nr, 0);
37667 + atomic_set_unchecked(&iscsi_session_nr, 0);
37668
37669 err = class_register(&iscsi_transport_class);
37670 if (err)
37671 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
37672 index 21a045e..ec89e03 100644
37673 --- a/drivers/scsi/scsi_transport_srp.c
37674 +++ b/drivers/scsi/scsi_transport_srp.c
37675 @@ -33,7 +33,7 @@
37676 #include "scsi_transport_srp_internal.h"
37677
37678 struct srp_host_attrs {
37679 - atomic_t next_port_id;
37680 + atomic_unchecked_t next_port_id;
37681 };
37682 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
37683
37684 @@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
37685 struct Scsi_Host *shost = dev_to_shost(dev);
37686 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
37687
37688 - atomic_set(&srp_host->next_port_id, 0);
37689 + atomic_set_unchecked(&srp_host->next_port_id, 0);
37690 return 0;
37691 }
37692
37693 @@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
37694 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
37695 rport->roles = ids->roles;
37696
37697 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
37698 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
37699 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
37700
37701 transport_setup_device(&rport->dev);
37702 diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
37703 index 4df73e5..b691c58 100644
37704 --- a/drivers/scsi/sd.c
37705 +++ b/drivers/scsi/sd.c
37706 @@ -2709,7 +2709,7 @@ static int sd_probe(struct device *dev)
37707 sdkp->disk = gd;
37708 sdkp->index = index;
37709 atomic_set(&sdkp->openers, 0);
37710 - atomic_set(&sdkp->device->ioerr_cnt, 0);
37711 + atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
37712
37713 if (!sdp->request_queue->rq_timeout) {
37714 if (sdp->type != TYPE_MOD)
37715 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
37716 index 9c5c5f2..8414557 100644
37717 --- a/drivers/scsi/sg.c
37718 +++ b/drivers/scsi/sg.c
37719 @@ -1101,7 +1101,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
37720 sdp->disk->disk_name,
37721 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
37722 NULL,
37723 - (char *)arg);
37724 + (char __user *)arg);
37725 case BLKTRACESTART:
37726 return blk_trace_startstop(sdp->device->request_queue, 1);
37727 case BLKTRACESTOP:
37728 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
37729 index 84c2861..ece0a31 100644
37730 --- a/drivers/spi/spi.c
37731 +++ b/drivers/spi/spi.c
37732 @@ -1453,7 +1453,7 @@ int spi_bus_unlock(struct spi_master *master)
37733 EXPORT_SYMBOL_GPL(spi_bus_unlock);
37734
37735 /* portable code must never pass more than 32 bytes */
37736 -#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
37737 +#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
37738
37739 static u8 *buf;
37740
37741 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
37742 index 34afc16..ffe44dd 100644
37743 --- a/drivers/staging/octeon/ethernet-rx.c
37744 +++ b/drivers/staging/octeon/ethernet-rx.c
37745 @@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37746 /* Increment RX stats for virtual ports */
37747 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
37748 #ifdef CONFIG_64BIT
37749 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
37750 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
37751 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
37752 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
37753 #else
37754 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
37755 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
37756 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
37757 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
37758 #endif
37759 }
37760 netif_receive_skb(skb);
37761 @@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37762 dev->name);
37763 */
37764 #ifdef CONFIG_64BIT
37765 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
37766 + atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37767 #else
37768 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
37769 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
37770 #endif
37771 dev_kfree_skb_irq(skb);
37772 }
37773 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
37774 index 683bedc..86dba9a 100644
37775 --- a/drivers/staging/octeon/ethernet.c
37776 +++ b/drivers/staging/octeon/ethernet.c
37777 @@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
37778 * since the RX tasklet also increments it.
37779 */
37780 #ifdef CONFIG_64BIT
37781 - atomic64_add(rx_status.dropped_packets,
37782 - (atomic64_t *)&priv->stats.rx_dropped);
37783 + atomic64_add_unchecked(rx_status.dropped_packets,
37784 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37785 #else
37786 - atomic_add(rx_status.dropped_packets,
37787 - (atomic_t *)&priv->stats.rx_dropped);
37788 + atomic_add_unchecked(rx_status.dropped_packets,
37789 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
37790 #endif
37791 }
37792
37793 diff --git a/drivers/staging/omapdrm/omap_drv.c b/drivers/staging/omapdrm/omap_drv.c
37794 index 4beab94..44149ee 100644
37795 --- a/drivers/staging/omapdrm/omap_drv.c
37796 +++ b/drivers/staging/omapdrm/omap_drv.c
37797 @@ -761,7 +761,6 @@ static struct drm_driver omap_drm_driver = {
37798 .irq_postinstall = dev_irq_postinstall,
37799 .irq_uninstall = dev_irq_uninstall,
37800 .irq_handler = dev_irq_handler,
37801 - .reclaim_buffers = drm_core_reclaim_buffers,
37802 #ifdef CONFIG_DEBUG_FS
37803 .debugfs_init = omap_debugfs_init,
37804 .debugfs_cleanup = omap_debugfs_cleanup,
37805 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
37806 index dc23395..cf7e9b1 100644
37807 --- a/drivers/staging/rtl8712/rtl871x_io.h
37808 +++ b/drivers/staging/rtl8712/rtl871x_io.h
37809 @@ -108,7 +108,7 @@ struct _io_ops {
37810 u8 *pmem);
37811 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
37812 u8 *pmem);
37813 -};
37814 +} __no_const;
37815
37816 struct io_req {
37817 struct list_head list;
37818 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
37819 index c7b5e8b..783d6cb 100644
37820 --- a/drivers/staging/sbe-2t3e3/netdev.c
37821 +++ b/drivers/staging/sbe-2t3e3/netdev.c
37822 @@ -51,7 +51,7 @@ int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
37823 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
37824
37825 if (rlen)
37826 - if (copy_to_user(data, &resp, rlen))
37827 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
37828 return -EFAULT;
37829
37830 return 0;
37831 diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h
37832 index 5d89c0f..9261317 100644
37833 --- a/drivers/staging/usbip/usbip_common.h
37834 +++ b/drivers/staging/usbip/usbip_common.h
37835 @@ -289,7 +289,7 @@ struct usbip_device {
37836 void (*shutdown)(struct usbip_device *);
37837 void (*reset)(struct usbip_device *);
37838 void (*unusable)(struct usbip_device *);
37839 - } eh_ops;
37840 + } __no_const eh_ops;
37841 };
37842
37843 #define kthread_get_run(threadfn, data, namefmt, ...) \
37844 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
37845 index c66b8b3..a4a035b 100644
37846 --- a/drivers/staging/usbip/vhci.h
37847 +++ b/drivers/staging/usbip/vhci.h
37848 @@ -83,7 +83,7 @@ struct vhci_hcd {
37849 unsigned resuming:1;
37850 unsigned long re_timeout;
37851
37852 - atomic_t seqnum;
37853 + atomic_unchecked_t seqnum;
37854
37855 /*
37856 * NOTE:
37857 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
37858 index 12a9a5f..afd8295 100644
37859 --- a/drivers/staging/usbip/vhci_hcd.c
37860 +++ b/drivers/staging/usbip/vhci_hcd.c
37861 @@ -471,7 +471,7 @@ static void vhci_tx_urb(struct urb *urb)
37862 return;
37863 }
37864
37865 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
37866 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37867 if (priv->seqnum == 0xffff)
37868 dev_info(&urb->dev->dev, "seqnum max\n");
37869
37870 @@ -723,7 +723,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
37871 return -ENOMEM;
37872 }
37873
37874 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
37875 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37876 if (unlink->seqnum == 0xffff)
37877 pr_info("seqnum max\n");
37878
37879 @@ -911,7 +911,7 @@ static int vhci_start(struct usb_hcd *hcd)
37880 vdev->rhport = rhport;
37881 }
37882
37883 - atomic_set(&vhci->seqnum, 0);
37884 + atomic_set_unchecked(&vhci->seqnum, 0);
37885 spin_lock_init(&vhci->lock);
37886
37887 hcd->power_budget = 0; /* no limit */
37888 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
37889 index f0eaf04..5a82e06 100644
37890 --- a/drivers/staging/usbip/vhci_rx.c
37891 +++ b/drivers/staging/usbip/vhci_rx.c
37892 @@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
37893 if (!urb) {
37894 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
37895 pr_info("max seqnum %d\n",
37896 - atomic_read(&the_controller->seqnum));
37897 + atomic_read_unchecked(&the_controller->seqnum));
37898 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
37899 return;
37900 }
37901 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
37902 index 6ac6f45..1b208ba 100644
37903 --- a/drivers/staging/vt6655/hostap.c
37904 +++ b/drivers/staging/vt6655/hostap.c
37905 @@ -73,14 +73,13 @@ static int msglevel =MSG_LEVEL_INFO;
37906 *
37907 */
37908
37909 +static net_device_ops_no_const apdev_netdev_ops;
37910 +
37911 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37912 {
37913 PSDevice apdev_priv;
37914 struct net_device *dev = pDevice->dev;
37915 int ret;
37916 - const struct net_device_ops apdev_netdev_ops = {
37917 - .ndo_start_xmit = pDevice->tx_80211,
37918 - };
37919
37920 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37921
37922 @@ -92,6 +91,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37923 *apdev_priv = *pDevice;
37924 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37925
37926 + /* only half broken now */
37927 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37928 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37929
37930 pDevice->apdev->type = ARPHRD_IEEE80211;
37931 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
37932 index 682002a..35ed5cf 100644
37933 --- a/drivers/staging/vt6656/hostap.c
37934 +++ b/drivers/staging/vt6656/hostap.c
37935 @@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
37936 *
37937 */
37938
37939 +static net_device_ops_no_const apdev_netdev_ops;
37940 +
37941 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37942 {
37943 PSDevice apdev_priv;
37944 struct net_device *dev = pDevice->dev;
37945 int ret;
37946 - const struct net_device_ops apdev_netdev_ops = {
37947 - .ndo_start_xmit = pDevice->tx_80211,
37948 - };
37949
37950 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37951
37952 @@ -79,6 +78,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37953 *apdev_priv = *pDevice;
37954 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37955
37956 + /* only half broken now */
37957 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37958 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37959
37960 pDevice->apdev->type = ARPHRD_IEEE80211;
37961 diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
37962 index 7843dfd..3db105f 100644
37963 --- a/drivers/staging/wlan-ng/hfa384x_usb.c
37964 +++ b/drivers/staging/wlan-ng/hfa384x_usb.c
37965 @@ -204,7 +204,7 @@ static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
37966
37967 struct usbctlx_completor {
37968 int (*complete) (struct usbctlx_completor *);
37969 -};
37970 +} __no_const;
37971
37972 static int
37973 hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
37974 diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
37975 index eaa9021..43f023b 100644
37976 --- a/drivers/staging/zcache/tmem.c
37977 +++ b/drivers/staging/zcache/tmem.c
37978 @@ -39,7 +39,7 @@
37979 * A tmem host implementation must use this function to register callbacks
37980 * for memory allocation.
37981 */
37982 -static struct tmem_hostops tmem_hostops;
37983 +static tmem_hostops_no_const tmem_hostops;
37984
37985 static void tmem_objnode_tree_init(void);
37986
37987 @@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
37988 * A tmem host implementation must use this function to register
37989 * callbacks for a page-accessible memory (PAM) implementation
37990 */
37991 -static struct tmem_pamops tmem_pamops;
37992 +static tmem_pamops_no_const tmem_pamops;
37993
37994 void tmem_register_pamops(struct tmem_pamops *m)
37995 {
37996 diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
37997 index 0d4aa82..f7832d4 100644
37998 --- a/drivers/staging/zcache/tmem.h
37999 +++ b/drivers/staging/zcache/tmem.h
38000 @@ -180,6 +180,7 @@ struct tmem_pamops {
38001 void (*new_obj)(struct tmem_obj *);
38002 int (*replace_in_obj)(void *, struct tmem_obj *);
38003 };
38004 +typedef struct tmem_pamops __no_const tmem_pamops_no_const;
38005 extern void tmem_register_pamops(struct tmem_pamops *m);
38006
38007 /* memory allocation methods provided by the host implementation */
38008 @@ -189,6 +190,7 @@ struct tmem_hostops {
38009 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
38010 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
38011 };
38012 +typedef struct tmem_hostops __no_const tmem_hostops_no_const;
38013 extern void tmem_register_hostops(struct tmem_hostops *m);
38014
38015 /* core tmem accessor functions */
38016 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
38017 index 7502660..f214d9f 100644
38018 --- a/drivers/target/target_core_transport.c
38019 +++ b/drivers/target/target_core_transport.c
38020 @@ -1098,7 +1098,7 @@ struct se_device *transport_add_device_to_core_hba(
38021 spin_lock_init(&dev->se_port_lock);
38022 spin_lock_init(&dev->se_tmr_lock);
38023 spin_lock_init(&dev->qf_cmd_lock);
38024 - atomic_set(&dev->dev_ordered_id, 0);
38025 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
38026
38027 se_dev_set_default_attribs(dev, dev_limits);
38028
38029 @@ -1288,7 +1288,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
38030 * Used to determine when ORDERED commands should go from
38031 * Dormant to Active status.
38032 */
38033 - cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
38034 + cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
38035 smp_mb__after_atomic_inc();
38036 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
38037 cmd->se_ordered_id, cmd->sam_task_attr,
38038 diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
38039 index e61cabd..7617d26 100644
38040 --- a/drivers/tty/cyclades.c
38041 +++ b/drivers/tty/cyclades.c
38042 @@ -1589,10 +1589,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
38043 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
38044 info->port.count);
38045 #endif
38046 - info->port.count++;
38047 + atomic_inc(&info->port.count);
38048 #ifdef CY_DEBUG_COUNT
38049 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
38050 - current->pid, info->port.count);
38051 + current->pid, atomic_read(&info->port.count));
38052 #endif
38053
38054 /*
38055 @@ -3987,7 +3987,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
38056 for (j = 0; j < cy_card[i].nports; j++) {
38057 info = &cy_card[i].ports[j];
38058
38059 - if (info->port.count) {
38060 + if (atomic_read(&info->port.count)) {
38061 /* XXX is the ldisc num worth this? */
38062 struct tty_struct *tty;
38063 struct tty_ldisc *ld;
38064 diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
38065 index 2d691eb..be02ebd 100644
38066 --- a/drivers/tty/hvc/hvc_console.c
38067 +++ b/drivers/tty/hvc/hvc_console.c
38068 @@ -315,7 +315,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
38069
38070 spin_lock_irqsave(&hp->port.lock, flags);
38071 /* Check and then increment for fast path open. */
38072 - if (hp->port.count++ > 0) {
38073 + if (atomic_inc_return(&hp->port.count) > 1) {
38074 spin_unlock_irqrestore(&hp->port.lock, flags);
38075 hvc_kick();
38076 return 0;
38077 @@ -366,7 +366,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
38078
38079 spin_lock_irqsave(&hp->port.lock, flags);
38080
38081 - if (--hp->port.count == 0) {
38082 + if (atomic_dec_return(&hp->port.count) == 0) {
38083 spin_unlock_irqrestore(&hp->port.lock, flags);
38084 /* We are done with the tty pointer now. */
38085 tty_port_tty_set(&hp->port, NULL);
38086 @@ -384,9 +384,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
38087 */
38088 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
38089 } else {
38090 - if (hp->port.count < 0)
38091 + if (atomic_read(&hp->port.count) < 0)
38092 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
38093 - hp->vtermno, hp->port.count);
38094 + hp->vtermno, atomic_read(&hp->port.count));
38095 spin_unlock_irqrestore(&hp->port.lock, flags);
38096 }
38097
38098 @@ -412,13 +412,13 @@ static void hvc_hangup(struct tty_struct *tty)
38099 * open->hangup case this can be called after the final close so prevent
38100 * that from happening for now.
38101 */
38102 - if (hp->port.count <= 0) {
38103 + if (atomic_read(&hp->port.count) <= 0) {
38104 spin_unlock_irqrestore(&hp->port.lock, flags);
38105 return;
38106 }
38107
38108 - temp_open_count = hp->port.count;
38109 - hp->port.count = 0;
38110 + temp_open_count = atomic_read(&hp->port.count);
38111 + atomic_set(&hp->port.count, 0);
38112 spin_unlock_irqrestore(&hp->port.lock, flags);
38113 tty_port_tty_set(&hp->port, NULL);
38114
38115 @@ -471,7 +471,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
38116 return -EPIPE;
38117
38118 /* FIXME what's this (unprotected) check for? */
38119 - if (hp->port.count <= 0)
38120 + if (atomic_read(&hp->port.count) <= 0)
38121 return -EIO;
38122
38123 spin_lock_irqsave(&hp->lock, flags);
38124 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
38125 index d56788c..12d8f85 100644
38126 --- a/drivers/tty/hvc/hvcs.c
38127 +++ b/drivers/tty/hvc/hvcs.c
38128 @@ -83,6 +83,7 @@
38129 #include <asm/hvcserver.h>
38130 #include <asm/uaccess.h>
38131 #include <asm/vio.h>
38132 +#include <asm/local.h>
38133
38134 /*
38135 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
38136 @@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
38137
38138 spin_lock_irqsave(&hvcsd->lock, flags);
38139
38140 - if (hvcsd->port.count > 0) {
38141 + if (atomic_read(&hvcsd->port.count) > 0) {
38142 spin_unlock_irqrestore(&hvcsd->lock, flags);
38143 printk(KERN_INFO "HVCS: vterm state unchanged. "
38144 "The hvcs device node is still in use.\n");
38145 @@ -1134,7 +1135,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
38146 if ((retval = hvcs_partner_connect(hvcsd)))
38147 goto error_release;
38148
38149 - hvcsd->port.count = 1;
38150 + atomic_set(&hvcsd->port.count, 1);
38151 hvcsd->port.tty = tty;
38152 tty->driver_data = hvcsd;
38153
38154 @@ -1168,7 +1169,7 @@ fast_open:
38155
38156 spin_lock_irqsave(&hvcsd->lock, flags);
38157 tty_port_get(&hvcsd->port);
38158 - hvcsd->port.count++;
38159 + atomic_inc(&hvcsd->port.count);
38160 hvcsd->todo_mask |= HVCS_SCHED_READ;
38161 spin_unlock_irqrestore(&hvcsd->lock, flags);
38162
38163 @@ -1212,7 +1213,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
38164 hvcsd = tty->driver_data;
38165
38166 spin_lock_irqsave(&hvcsd->lock, flags);
38167 - if (--hvcsd->port.count == 0) {
38168 + if (atomic_dec_and_test(&hvcsd->port.count)) {
38169
38170 vio_disable_interrupts(hvcsd->vdev);
38171
38172 @@ -1238,10 +1239,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
38173 free_irq(irq, hvcsd);
38174 tty_port_put(&hvcsd->port);
38175 return;
38176 - } else if (hvcsd->port.count < 0) {
38177 + } else if (atomic_read(&hvcsd->port.count) < 0) {
38178 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
38179 " is missmanaged.\n",
38180 - hvcsd->vdev->unit_address, hvcsd->port.count);
38181 + hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
38182 }
38183
38184 spin_unlock_irqrestore(&hvcsd->lock, flags);
38185 @@ -1257,7 +1258,7 @@ static void hvcs_hangup(struct tty_struct * tty)
38186
38187 spin_lock_irqsave(&hvcsd->lock, flags);
38188 /* Preserve this so that we know how many kref refs to put */
38189 - temp_open_count = hvcsd->port.count;
38190 + temp_open_count = atomic_read(&hvcsd->port.count);
38191
38192 /*
38193 * Don't kref put inside the spinlock because the destruction
38194 @@ -1272,7 +1273,7 @@ static void hvcs_hangup(struct tty_struct * tty)
38195 tty->driver_data = NULL;
38196 hvcsd->port.tty = NULL;
38197
38198 - hvcsd->port.count = 0;
38199 + atomic_set(&hvcsd->port.count, 0);
38200
38201 /* This will drop any buffered data on the floor which is OK in a hangup
38202 * scenario. */
38203 @@ -1343,7 +1344,7 @@ static int hvcs_write(struct tty_struct *tty,
38204 * the middle of a write operation? This is a crummy place to do this
38205 * but we want to keep it all in the spinlock.
38206 */
38207 - if (hvcsd->port.count <= 0) {
38208 + if (atomic_read(&hvcsd->port.count) <= 0) {
38209 spin_unlock_irqrestore(&hvcsd->lock, flags);
38210 return -ENODEV;
38211 }
38212 @@ -1417,7 +1418,7 @@ static int hvcs_write_room(struct tty_struct *tty)
38213 {
38214 struct hvcs_struct *hvcsd = tty->driver_data;
38215
38216 - if (!hvcsd || hvcsd->port.count <= 0)
38217 + if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
38218 return 0;
38219
38220 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
38221 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
38222 index f8b5fa0..4ba9f89 100644
38223 --- a/drivers/tty/ipwireless/tty.c
38224 +++ b/drivers/tty/ipwireless/tty.c
38225 @@ -29,6 +29,7 @@
38226 #include <linux/tty_driver.h>
38227 #include <linux/tty_flip.h>
38228 #include <linux/uaccess.h>
38229 +#include <asm/local.h>
38230
38231 #include "tty.h"
38232 #include "network.h"
38233 @@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
38234 mutex_unlock(&tty->ipw_tty_mutex);
38235 return -ENODEV;
38236 }
38237 - if (tty->port.count == 0)
38238 + if (atomic_read(&tty->port.count) == 0)
38239 tty->tx_bytes_queued = 0;
38240
38241 - tty->port.count++;
38242 + atomic_inc(&tty->port.count);
38243
38244 tty->port.tty = linux_tty;
38245 linux_tty->driver_data = tty;
38246 @@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
38247
38248 static void do_ipw_close(struct ipw_tty *tty)
38249 {
38250 - tty->port.count--;
38251 -
38252 - if (tty->port.count == 0) {
38253 + if (atomic_dec_return(&tty->port.count) == 0) {
38254 struct tty_struct *linux_tty = tty->port.tty;
38255
38256 if (linux_tty != NULL) {
38257 @@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
38258 return;
38259
38260 mutex_lock(&tty->ipw_tty_mutex);
38261 - if (tty->port.count == 0) {
38262 + if (atomic_read(&tty->port.count) == 0) {
38263 mutex_unlock(&tty->ipw_tty_mutex);
38264 return;
38265 }
38266 @@ -170,7 +169,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
38267 return;
38268 }
38269
38270 - if (!tty->port.count) {
38271 + if (!atomic_read(&tty->port.count)) {
38272 mutex_unlock(&tty->ipw_tty_mutex);
38273 return;
38274 }
38275 @@ -212,7 +211,7 @@ static int ipw_write(struct tty_struct *linux_tty,
38276 return -ENODEV;
38277
38278 mutex_lock(&tty->ipw_tty_mutex);
38279 - if (!tty->port.count) {
38280 + if (!atomic_read(&tty->port.count)) {
38281 mutex_unlock(&tty->ipw_tty_mutex);
38282 return -EINVAL;
38283 }
38284 @@ -252,7 +251,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
38285 if (!tty)
38286 return -ENODEV;
38287
38288 - if (!tty->port.count)
38289 + if (!atomic_read(&tty->port.count))
38290 return -EINVAL;
38291
38292 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
38293 @@ -294,7 +293,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
38294 if (!tty)
38295 return 0;
38296
38297 - if (!tty->port.count)
38298 + if (!atomic_read(&tty->port.count))
38299 return 0;
38300
38301 return tty->tx_bytes_queued;
38302 @@ -375,7 +374,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
38303 if (!tty)
38304 return -ENODEV;
38305
38306 - if (!tty->port.count)
38307 + if (!atomic_read(&tty->port.count))
38308 return -EINVAL;
38309
38310 return get_control_lines(tty);
38311 @@ -391,7 +390,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
38312 if (!tty)
38313 return -ENODEV;
38314
38315 - if (!tty->port.count)
38316 + if (!atomic_read(&tty->port.count))
38317 return -EINVAL;
38318
38319 return set_control_lines(tty, set, clear);
38320 @@ -405,7 +404,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
38321 if (!tty)
38322 return -ENODEV;
38323
38324 - if (!tty->port.count)
38325 + if (!atomic_read(&tty->port.count))
38326 return -EINVAL;
38327
38328 /* FIXME: Exactly how is the tty object locked here .. */
38329 @@ -561,7 +560,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
38330 * are gone */
38331 mutex_lock(&ttyj->ipw_tty_mutex);
38332 }
38333 - while (ttyj->port.count)
38334 + while (atomic_read(&ttyj->port.count))
38335 do_ipw_close(ttyj);
38336 ipwireless_disassociate_network_ttys(network,
38337 ttyj->channel_idx);
38338 diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
38339 index 324467d..504cc25 100644
38340 --- a/drivers/tty/moxa.c
38341 +++ b/drivers/tty/moxa.c
38342 @@ -1172,7 +1172,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
38343 }
38344
38345 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
38346 - ch->port.count++;
38347 + atomic_inc(&ch->port.count);
38348 tty->driver_data = ch;
38349 tty_port_tty_set(&ch->port, tty);
38350 mutex_lock(&ch->port.mutex);
38351 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
38352 index 90dff82..08119c3 100644
38353 --- a/drivers/tty/n_gsm.c
38354 +++ b/drivers/tty/n_gsm.c
38355 @@ -1639,7 +1639,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
38356 kref_init(&dlci->ref);
38357 mutex_init(&dlci->mutex);
38358 dlci->fifo = &dlci->_fifo;
38359 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
38360 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
38361 kfree(dlci);
38362 return NULL;
38363 }
38364 @@ -2909,7 +2909,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
38365 if (dlci == NULL)
38366 return -ENOMEM;
38367 port = &dlci->port;
38368 - port->count++;
38369 + atomic_inc(&port->count);
38370 tty->driver_data = dlci;
38371 dlci_get(dlci);
38372 dlci_get(dlci->gsm->dlci[0]);
38373 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
38374 index 26f0d0e..b7c4273 100644
38375 --- a/drivers/tty/n_tty.c
38376 +++ b/drivers/tty/n_tty.c
38377 @@ -2124,6 +2124,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
38378 {
38379 *ops = tty_ldisc_N_TTY;
38380 ops->owner = NULL;
38381 - ops->refcount = ops->flags = 0;
38382 + atomic_set(&ops->refcount, 0);
38383 + ops->flags = 0;
38384 }
38385 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
38386 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
38387 index 5505ffc..7affff9 100644
38388 --- a/drivers/tty/pty.c
38389 +++ b/drivers/tty/pty.c
38390 @@ -718,8 +718,10 @@ static void __init unix98_pty_init(void)
38391 panic("Couldn't register Unix98 pts driver");
38392
38393 /* Now create the /dev/ptmx special device */
38394 + pax_open_kernel();
38395 tty_default_fops(&ptmx_fops);
38396 - ptmx_fops.open = ptmx_open;
38397 + *(void **)&ptmx_fops.open = ptmx_open;
38398 + pax_close_kernel();
38399
38400 cdev_init(&ptmx_cdev, &ptmx_fops);
38401 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
38402 diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
38403 index 777d5f9..56d67ca 100644
38404 --- a/drivers/tty/rocket.c
38405 +++ b/drivers/tty/rocket.c
38406 @@ -924,7 +924,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
38407 tty->driver_data = info;
38408 tty_port_tty_set(port, tty);
38409
38410 - if (port->count++ == 0) {
38411 + if (atomic_inc_return(&port->count) == 1) {
38412 atomic_inc(&rp_num_ports_open);
38413
38414 #ifdef ROCKET_DEBUG_OPEN
38415 @@ -933,7 +933,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
38416 #endif
38417 }
38418 #ifdef ROCKET_DEBUG_OPEN
38419 - printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
38420 + printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
38421 #endif
38422
38423 /*
38424 @@ -1528,7 +1528,7 @@ static void rp_hangup(struct tty_struct *tty)
38425 spin_unlock_irqrestore(&info->port.lock, flags);
38426 return;
38427 }
38428 - if (info->port.count)
38429 + if (atomic_read(&info->port.count))
38430 atomic_dec(&rp_num_ports_open);
38431 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
38432 spin_unlock_irqrestore(&info->port.lock, flags);
38433 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
38434 index 2b42a01..32a2ed3 100644
38435 --- a/drivers/tty/serial/kgdboc.c
38436 +++ b/drivers/tty/serial/kgdboc.c
38437 @@ -24,8 +24,9 @@
38438 #define MAX_CONFIG_LEN 40
38439
38440 static struct kgdb_io kgdboc_io_ops;
38441 +static struct kgdb_io kgdboc_io_ops_console;
38442
38443 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
38444 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
38445 static int configured = -1;
38446
38447 static char config[MAX_CONFIG_LEN];
38448 @@ -148,6 +149,8 @@ static void cleanup_kgdboc(void)
38449 kgdboc_unregister_kbd();
38450 if (configured == 1)
38451 kgdb_unregister_io_module(&kgdboc_io_ops);
38452 + else if (configured == 2)
38453 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
38454 }
38455
38456 static int configure_kgdboc(void)
38457 @@ -157,13 +160,13 @@ static int configure_kgdboc(void)
38458 int err;
38459 char *cptr = config;
38460 struct console *cons;
38461 + int is_console = 0;
38462
38463 err = kgdboc_option_setup(config);
38464 if (err || !strlen(config) || isspace(config[0]))
38465 goto noconfig;
38466
38467 err = -ENODEV;
38468 - kgdboc_io_ops.is_console = 0;
38469 kgdb_tty_driver = NULL;
38470
38471 kgdboc_use_kms = 0;
38472 @@ -184,7 +187,7 @@ static int configure_kgdboc(void)
38473 int idx;
38474 if (cons->device && cons->device(cons, &idx) == p &&
38475 idx == tty_line) {
38476 - kgdboc_io_ops.is_console = 1;
38477 + is_console = 1;
38478 break;
38479 }
38480 cons = cons->next;
38481 @@ -194,12 +197,16 @@ static int configure_kgdboc(void)
38482 kgdb_tty_line = tty_line;
38483
38484 do_register:
38485 - err = kgdb_register_io_module(&kgdboc_io_ops);
38486 + if (is_console) {
38487 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
38488 + configured = 2;
38489 + } else {
38490 + err = kgdb_register_io_module(&kgdboc_io_ops);
38491 + configured = 1;
38492 + }
38493 if (err)
38494 goto noconfig;
38495
38496 - configured = 1;
38497 -
38498 return 0;
38499
38500 noconfig:
38501 @@ -213,7 +220,7 @@ noconfig:
38502 static int __init init_kgdboc(void)
38503 {
38504 /* Already configured? */
38505 - if (configured == 1)
38506 + if (configured >= 1)
38507 return 0;
38508
38509 return configure_kgdboc();
38510 @@ -262,7 +269,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
38511 if (config[len - 1] == '\n')
38512 config[len - 1] = '\0';
38513
38514 - if (configured == 1)
38515 + if (configured >= 1)
38516 cleanup_kgdboc();
38517
38518 /* Go and configure with the new params. */
38519 @@ -302,6 +309,15 @@ static struct kgdb_io kgdboc_io_ops = {
38520 .post_exception = kgdboc_post_exp_handler,
38521 };
38522
38523 +static struct kgdb_io kgdboc_io_ops_console = {
38524 + .name = "kgdboc",
38525 + .read_char = kgdboc_get_char,
38526 + .write_char = kgdboc_put_char,
38527 + .pre_exception = kgdboc_pre_exp_handler,
38528 + .post_exception = kgdboc_post_exp_handler,
38529 + .is_console = 1
38530 +};
38531 +
38532 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
38533 /* This is only available if kgdboc is a built in for early debugging */
38534 static int __init kgdboc_early_init(char *opt)
38535 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
38536 index a21dc8e..fe43e9e 100644
38537 --- a/drivers/tty/serial/serial_core.c
38538 +++ b/drivers/tty/serial/serial_core.c
38539 @@ -1392,7 +1392,7 @@ static void uart_hangup(struct tty_struct *tty)
38540 uart_flush_buffer(tty);
38541 uart_shutdown(tty, state);
38542 spin_lock_irqsave(&port->lock, flags);
38543 - port->count = 0;
38544 + atomic_set(&port->count, 0);
38545 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
38546 spin_unlock_irqrestore(&port->lock, flags);
38547 tty_port_tty_set(port, NULL);
38548 @@ -1488,7 +1488,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38549 goto end;
38550 }
38551
38552 - port->count++;
38553 + atomic_inc(&port->count);
38554 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
38555 retval = -ENXIO;
38556 goto err_dec_count;
38557 @@ -1515,7 +1515,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38558 /*
38559 * Make sure the device is in D0 state.
38560 */
38561 - if (port->count == 1)
38562 + if (atomic_read(&port->count) == 1)
38563 uart_change_pm(state, 0);
38564
38565 /*
38566 @@ -1533,7 +1533,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38567 end:
38568 return retval;
38569 err_dec_count:
38570 - port->count--;
38571 + atomic_inc(&port->count);
38572 mutex_unlock(&port->mutex);
38573 goto end;
38574 }
38575 diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
38576 index 593d40a..bdc61f3 100644
38577 --- a/drivers/tty/synclink.c
38578 +++ b/drivers/tty/synclink.c
38579 @@ -3095,7 +3095,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
38580
38581 if (debug_level >= DEBUG_LEVEL_INFO)
38582 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
38583 - __FILE__,__LINE__, info->device_name, info->port.count);
38584 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
38585
38586 if (tty_port_close_start(&info->port, tty, filp) == 0)
38587 goto cleanup;
38588 @@ -3113,7 +3113,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
38589 cleanup:
38590 if (debug_level >= DEBUG_LEVEL_INFO)
38591 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
38592 - tty->driver->name, info->port.count);
38593 + tty->driver->name, atomic_read(&info->port.count));
38594
38595 } /* end of mgsl_close() */
38596
38597 @@ -3212,8 +3212,8 @@ static void mgsl_hangup(struct tty_struct *tty)
38598
38599 mgsl_flush_buffer(tty);
38600 shutdown(info);
38601 -
38602 - info->port.count = 0;
38603 +
38604 + atomic_set(&info->port.count, 0);
38605 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38606 info->port.tty = NULL;
38607
38608 @@ -3302,12 +3302,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38609
38610 if (debug_level >= DEBUG_LEVEL_INFO)
38611 printk("%s(%d):block_til_ready before block on %s count=%d\n",
38612 - __FILE__,__LINE__, tty->driver->name, port->count );
38613 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38614
38615 spin_lock_irqsave(&info->irq_spinlock, flags);
38616 if (!tty_hung_up_p(filp)) {
38617 extra_count = true;
38618 - port->count--;
38619 + atomic_dec(&port->count);
38620 }
38621 spin_unlock_irqrestore(&info->irq_spinlock, flags);
38622 port->blocked_open++;
38623 @@ -3336,7 +3336,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38624
38625 if (debug_level >= DEBUG_LEVEL_INFO)
38626 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
38627 - __FILE__,__LINE__, tty->driver->name, port->count );
38628 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38629
38630 tty_unlock();
38631 schedule();
38632 @@ -3348,12 +3348,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38633
38634 /* FIXME: Racy on hangup during close wait */
38635 if (extra_count)
38636 - port->count++;
38637 + atomic_inc(&port->count);
38638 port->blocked_open--;
38639
38640 if (debug_level >= DEBUG_LEVEL_INFO)
38641 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
38642 - __FILE__,__LINE__, tty->driver->name, port->count );
38643 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38644
38645 if (!retval)
38646 port->flags |= ASYNC_NORMAL_ACTIVE;
38647 @@ -3398,7 +3398,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
38648
38649 if (debug_level >= DEBUG_LEVEL_INFO)
38650 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
38651 - __FILE__,__LINE__,tty->driver->name, info->port.count);
38652 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
38653
38654 /* If port is closing, signal caller to try again */
38655 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38656 @@ -3417,10 +3417,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
38657 spin_unlock_irqrestore(&info->netlock, flags);
38658 goto cleanup;
38659 }
38660 - info->port.count++;
38661 + atomic_inc(&info->port.count);
38662 spin_unlock_irqrestore(&info->netlock, flags);
38663
38664 - if (info->port.count == 1) {
38665 + if (atomic_read(&info->port.count) == 1) {
38666 /* 1st open on this device, init hardware */
38667 retval = startup(info);
38668 if (retval < 0)
38669 @@ -3444,8 +3444,8 @@ cleanup:
38670 if (retval) {
38671 if (tty->count == 1)
38672 info->port.tty = NULL; /* tty layer will release tty struct */
38673 - if(info->port.count)
38674 - info->port.count--;
38675 + if (atomic_read(&info->port.count))
38676 + atomic_dec(&info->port.count);
38677 }
38678
38679 return retval;
38680 @@ -7653,7 +7653,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38681 unsigned short new_crctype;
38682
38683 /* return error if TTY interface open */
38684 - if (info->port.count)
38685 + if (atomic_read(&info->port.count))
38686 return -EBUSY;
38687
38688 switch (encoding)
38689 @@ -7748,7 +7748,7 @@ static int hdlcdev_open(struct net_device *dev)
38690
38691 /* arbitrate between network and tty opens */
38692 spin_lock_irqsave(&info->netlock, flags);
38693 - if (info->port.count != 0 || info->netcount != 0) {
38694 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38695 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38696 spin_unlock_irqrestore(&info->netlock, flags);
38697 return -EBUSY;
38698 @@ -7834,7 +7834,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38699 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
38700
38701 /* return error if TTY interface open */
38702 - if (info->port.count)
38703 + if (atomic_read(&info->port.count))
38704 return -EBUSY;
38705
38706 if (cmd != SIOCWANDEV)
38707 diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
38708 index aa1debf..9297a16 100644
38709 --- a/drivers/tty/synclink_gt.c
38710 +++ b/drivers/tty/synclink_gt.c
38711 @@ -671,7 +671,7 @@ static int open(struct tty_struct *tty, struct file *filp)
38712 tty->driver_data = info;
38713 info->port.tty = tty;
38714
38715 - DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
38716 + DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
38717
38718 /* If port is closing, signal caller to try again */
38719 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38720 @@ -692,10 +692,10 @@ static int open(struct tty_struct *tty, struct file *filp)
38721 mutex_unlock(&info->port.mutex);
38722 goto cleanup;
38723 }
38724 - info->port.count++;
38725 + atomic_inc(&info->port.count);
38726 spin_unlock_irqrestore(&info->netlock, flags);
38727
38728 - if (info->port.count == 1) {
38729 + if (atomic_read(&info->port.count) == 1) {
38730 /* 1st open on this device, init hardware */
38731 retval = startup(info);
38732 if (retval < 0) {
38733 @@ -716,8 +716,8 @@ cleanup:
38734 if (retval) {
38735 if (tty->count == 1)
38736 info->port.tty = NULL; /* tty layer will release tty struct */
38737 - if(info->port.count)
38738 - info->port.count--;
38739 + if(atomic_read(&info->port.count))
38740 + atomic_dec(&info->port.count);
38741 }
38742
38743 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
38744 @@ -730,7 +730,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38745
38746 if (sanity_check(info, tty->name, "close"))
38747 return;
38748 - DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
38749 + DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
38750
38751 if (tty_port_close_start(&info->port, tty, filp) == 0)
38752 goto cleanup;
38753 @@ -747,7 +747,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38754 tty_port_close_end(&info->port, tty);
38755 info->port.tty = NULL;
38756 cleanup:
38757 - DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
38758 + DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
38759 }
38760
38761 static void hangup(struct tty_struct *tty)
38762 @@ -765,7 +765,7 @@ static void hangup(struct tty_struct *tty)
38763 shutdown(info);
38764
38765 spin_lock_irqsave(&info->port.lock, flags);
38766 - info->port.count = 0;
38767 + atomic_set(&info->port.count, 0);
38768 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38769 info->port.tty = NULL;
38770 spin_unlock_irqrestore(&info->port.lock, flags);
38771 @@ -1450,7 +1450,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38772 unsigned short new_crctype;
38773
38774 /* return error if TTY interface open */
38775 - if (info->port.count)
38776 + if (atomic_read(&info->port.count))
38777 return -EBUSY;
38778
38779 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
38780 @@ -1545,7 +1545,7 @@ static int hdlcdev_open(struct net_device *dev)
38781
38782 /* arbitrate between network and tty opens */
38783 spin_lock_irqsave(&info->netlock, flags);
38784 - if (info->port.count != 0 || info->netcount != 0) {
38785 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38786 DBGINFO(("%s hdlc_open busy\n", dev->name));
38787 spin_unlock_irqrestore(&info->netlock, flags);
38788 return -EBUSY;
38789 @@ -1630,7 +1630,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38790 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
38791
38792 /* return error if TTY interface open */
38793 - if (info->port.count)
38794 + if (atomic_read(&info->port.count))
38795 return -EBUSY;
38796
38797 if (cmd != SIOCWANDEV)
38798 @@ -2419,7 +2419,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
38799 if (port == NULL)
38800 continue;
38801 spin_lock(&port->lock);
38802 - if ((port->port.count || port->netcount) &&
38803 + if ((atomic_read(&port->port.count) || port->netcount) &&
38804 port->pending_bh && !port->bh_running &&
38805 !port->bh_requested) {
38806 DBGISR(("%s bh queued\n", port->device_name));
38807 @@ -3308,7 +3308,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38808 spin_lock_irqsave(&info->lock, flags);
38809 if (!tty_hung_up_p(filp)) {
38810 extra_count = true;
38811 - port->count--;
38812 + atomic_dec(&port->count);
38813 }
38814 spin_unlock_irqrestore(&info->lock, flags);
38815 port->blocked_open++;
38816 @@ -3345,7 +3345,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38817 remove_wait_queue(&port->open_wait, &wait);
38818
38819 if (extra_count)
38820 - port->count++;
38821 + atomic_inc(&port->count);
38822 port->blocked_open--;
38823
38824 if (!retval)
38825 diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
38826 index a3dddc1..8905ab2 100644
38827 --- a/drivers/tty/synclinkmp.c
38828 +++ b/drivers/tty/synclinkmp.c
38829 @@ -742,7 +742,7 @@ static int open(struct tty_struct *tty, struct file *filp)
38830
38831 if (debug_level >= DEBUG_LEVEL_INFO)
38832 printk("%s(%d):%s open(), old ref count = %d\n",
38833 - __FILE__,__LINE__,tty->driver->name, info->port.count);
38834 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
38835
38836 /* If port is closing, signal caller to try again */
38837 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38838 @@ -761,10 +761,10 @@ static int open(struct tty_struct *tty, struct file *filp)
38839 spin_unlock_irqrestore(&info->netlock, flags);
38840 goto cleanup;
38841 }
38842 - info->port.count++;
38843 + atomic_inc(&info->port.count);
38844 spin_unlock_irqrestore(&info->netlock, flags);
38845
38846 - if (info->port.count == 1) {
38847 + if (atomic_read(&info->port.count) == 1) {
38848 /* 1st open on this device, init hardware */
38849 retval = startup(info);
38850 if (retval < 0)
38851 @@ -788,8 +788,8 @@ cleanup:
38852 if (retval) {
38853 if (tty->count == 1)
38854 info->port.tty = NULL; /* tty layer will release tty struct */
38855 - if(info->port.count)
38856 - info->port.count--;
38857 + if(atomic_read(&info->port.count))
38858 + atomic_dec(&info->port.count);
38859 }
38860
38861 return retval;
38862 @@ -807,7 +807,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38863
38864 if (debug_level >= DEBUG_LEVEL_INFO)
38865 printk("%s(%d):%s close() entry, count=%d\n",
38866 - __FILE__,__LINE__, info->device_name, info->port.count);
38867 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
38868
38869 if (tty_port_close_start(&info->port, tty, filp) == 0)
38870 goto cleanup;
38871 @@ -826,7 +826,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38872 cleanup:
38873 if (debug_level >= DEBUG_LEVEL_INFO)
38874 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
38875 - tty->driver->name, info->port.count);
38876 + tty->driver->name, atomic_read(&info->port.count));
38877 }
38878
38879 /* Called by tty_hangup() when a hangup is signaled.
38880 @@ -849,7 +849,7 @@ static void hangup(struct tty_struct *tty)
38881 shutdown(info);
38882
38883 spin_lock_irqsave(&info->port.lock, flags);
38884 - info->port.count = 0;
38885 + atomic_set(&info->port.count, 0);
38886 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38887 info->port.tty = NULL;
38888 spin_unlock_irqrestore(&info->port.lock, flags);
38889 @@ -1557,7 +1557,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38890 unsigned short new_crctype;
38891
38892 /* return error if TTY interface open */
38893 - if (info->port.count)
38894 + if (atomic_read(&info->port.count))
38895 return -EBUSY;
38896
38897 switch (encoding)
38898 @@ -1652,7 +1652,7 @@ static int hdlcdev_open(struct net_device *dev)
38899
38900 /* arbitrate between network and tty opens */
38901 spin_lock_irqsave(&info->netlock, flags);
38902 - if (info->port.count != 0 || info->netcount != 0) {
38903 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38904 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38905 spin_unlock_irqrestore(&info->netlock, flags);
38906 return -EBUSY;
38907 @@ -1738,7 +1738,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38908 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
38909
38910 /* return error if TTY interface open */
38911 - if (info->port.count)
38912 + if (atomic_read(&info->port.count))
38913 return -EBUSY;
38914
38915 if (cmd != SIOCWANDEV)
38916 @@ -2623,7 +2623,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
38917 * do not request bottom half processing if the
38918 * device is not open in a normal mode.
38919 */
38920 - if ( port && (port->port.count || port->netcount) &&
38921 + if ( port && (atomic_read(&port->port.count) || port->netcount) &&
38922 port->pending_bh && !port->bh_running &&
38923 !port->bh_requested ) {
38924 if ( debug_level >= DEBUG_LEVEL_ISR )
38925 @@ -3321,12 +3321,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38926
38927 if (debug_level >= DEBUG_LEVEL_INFO)
38928 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
38929 - __FILE__,__LINE__, tty->driver->name, port->count );
38930 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38931
38932 spin_lock_irqsave(&info->lock, flags);
38933 if (!tty_hung_up_p(filp)) {
38934 extra_count = true;
38935 - port->count--;
38936 + atomic_dec(&port->count);
38937 }
38938 spin_unlock_irqrestore(&info->lock, flags);
38939 port->blocked_open++;
38940 @@ -3355,7 +3355,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38941
38942 if (debug_level >= DEBUG_LEVEL_INFO)
38943 printk("%s(%d):%s block_til_ready() count=%d\n",
38944 - __FILE__,__LINE__, tty->driver->name, port->count );
38945 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38946
38947 tty_unlock();
38948 schedule();
38949 @@ -3366,12 +3366,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38950 remove_wait_queue(&port->open_wait, &wait);
38951
38952 if (extra_count)
38953 - port->count++;
38954 + atomic_inc(&port->count);
38955 port->blocked_open--;
38956
38957 if (debug_level >= DEBUG_LEVEL_INFO)
38958 printk("%s(%d):%s block_til_ready() after, count=%d\n",
38959 - __FILE__,__LINE__, tty->driver->name, port->count );
38960 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38961
38962 if (!retval)
38963 port->flags |= ASYNC_NORMAL_ACTIVE;
38964 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
38965 index 05728894..b9d44c6 100644
38966 --- a/drivers/tty/sysrq.c
38967 +++ b/drivers/tty/sysrq.c
38968 @@ -865,7 +865,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
38969 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
38970 size_t count, loff_t *ppos)
38971 {
38972 - if (count) {
38973 + if (count && capable(CAP_SYS_ADMIN)) {
38974 char c;
38975
38976 if (get_user(c, buf))
38977 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
38978 index b425c79..08a3f06 100644
38979 --- a/drivers/tty/tty_io.c
38980 +++ b/drivers/tty/tty_io.c
38981 @@ -3283,7 +3283,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
38982
38983 void tty_default_fops(struct file_operations *fops)
38984 {
38985 - *fops = tty_fops;
38986 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
38987 }
38988
38989 /*
38990 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
38991 index 6f99c99..8947bc4 100644
38992 --- a/drivers/tty/tty_ldisc.c
38993 +++ b/drivers/tty/tty_ldisc.c
38994 @@ -56,7 +56,7 @@ static void put_ldisc(struct tty_ldisc *ld)
38995 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
38996 struct tty_ldisc_ops *ldo = ld->ops;
38997
38998 - ldo->refcount--;
38999 + atomic_dec(&ldo->refcount);
39000 module_put(ldo->owner);
39001 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
39002
39003 @@ -91,7 +91,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
39004 spin_lock_irqsave(&tty_ldisc_lock, flags);
39005 tty_ldiscs[disc] = new_ldisc;
39006 new_ldisc->num = disc;
39007 - new_ldisc->refcount = 0;
39008 + atomic_set(&new_ldisc->refcount, 0);
39009 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
39010
39011 return ret;
39012 @@ -119,7 +119,7 @@ int tty_unregister_ldisc(int disc)
39013 return -EINVAL;
39014
39015 spin_lock_irqsave(&tty_ldisc_lock, flags);
39016 - if (tty_ldiscs[disc]->refcount)
39017 + if (atomic_read(&tty_ldiscs[disc]->refcount))
39018 ret = -EBUSY;
39019 else
39020 tty_ldiscs[disc] = NULL;
39021 @@ -140,7 +140,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
39022 if (ldops) {
39023 ret = ERR_PTR(-EAGAIN);
39024 if (try_module_get(ldops->owner)) {
39025 - ldops->refcount++;
39026 + atomic_inc(&ldops->refcount);
39027 ret = ldops;
39028 }
39029 }
39030 @@ -153,7 +153,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
39031 unsigned long flags;
39032
39033 spin_lock_irqsave(&tty_ldisc_lock, flags);
39034 - ldops->refcount--;
39035 + atomic_dec(&ldops->refcount);
39036 module_put(ldops->owner);
39037 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
39038 }
39039 diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
39040 index bf6e238..d401c04 100644
39041 --- a/drivers/tty/tty_port.c
39042 +++ b/drivers/tty/tty_port.c
39043 @@ -138,7 +138,7 @@ void tty_port_hangup(struct tty_port *port)
39044 unsigned long flags;
39045
39046 spin_lock_irqsave(&port->lock, flags);
39047 - port->count = 0;
39048 + atomic_set(&port->count, 0);
39049 port->flags &= ~ASYNC_NORMAL_ACTIVE;
39050 if (port->tty) {
39051 set_bit(TTY_IO_ERROR, &port->tty->flags);
39052 @@ -264,7 +264,7 @@ int tty_port_block_til_ready(struct tty_port *port,
39053 /* The port lock protects the port counts */
39054 spin_lock_irqsave(&port->lock, flags);
39055 if (!tty_hung_up_p(filp))
39056 - port->count--;
39057 + atomic_dec(&port->count);
39058 port->blocked_open++;
39059 spin_unlock_irqrestore(&port->lock, flags);
39060
39061 @@ -306,7 +306,7 @@ int tty_port_block_til_ready(struct tty_port *port,
39062 we must not mess that up further */
39063 spin_lock_irqsave(&port->lock, flags);
39064 if (!tty_hung_up_p(filp))
39065 - port->count++;
39066 + atomic_inc(&port->count);
39067 port->blocked_open--;
39068 if (retval == 0)
39069 port->flags |= ASYNC_NORMAL_ACTIVE;
39070 @@ -326,19 +326,19 @@ int tty_port_close_start(struct tty_port *port,
39071 return 0;
39072 }
39073
39074 - if (tty->count == 1 && port->count != 1) {
39075 + if (tty->count == 1 && atomic_read(&port->count) != 1) {
39076 printk(KERN_WARNING
39077 "tty_port_close_start: tty->count = 1 port count = %d.\n",
39078 - port->count);
39079 - port->count = 1;
39080 + atomic_read(&port->count));
39081 + atomic_set(&port->count, 1);
39082 }
39083 - if (--port->count < 0) {
39084 + if (atomic_dec_return(&port->count) < 0) {
39085 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
39086 - port->count);
39087 - port->count = 0;
39088 + atomic_read(&port->count));
39089 + atomic_set(&port->count, 0);
39090 }
39091
39092 - if (port->count) {
39093 + if (atomic_read(&port->count)) {
39094 spin_unlock_irqrestore(&port->lock, flags);
39095 if (port->ops->drop)
39096 port->ops->drop(port);
39097 @@ -418,7 +418,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
39098 {
39099 spin_lock_irq(&port->lock);
39100 if (!tty_hung_up_p(filp))
39101 - ++port->count;
39102 + atomic_inc(&port->count);
39103 spin_unlock_irq(&port->lock);
39104 tty_port_tty_set(port, tty);
39105
39106 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
39107 index 770a854..e5d3db3 100644
39108 --- a/drivers/tty/vt/keyboard.c
39109 +++ b/drivers/tty/vt/keyboard.c
39110 @@ -659,6 +659,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
39111 kbd->kbdmode == VC_OFF) &&
39112 value != KVAL(K_SAK))
39113 return; /* SAK is allowed even in raw mode */
39114 +
39115 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
39116 + {
39117 + void *func = fn_handler[value];
39118 + if (func == fn_show_state || func == fn_show_ptregs ||
39119 + func == fn_show_mem)
39120 + return;
39121 + }
39122 +#endif
39123 +
39124 fn_handler[value](vc);
39125 }
39126
39127 @@ -1805,9 +1815,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
39128 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
39129 return -EFAULT;
39130
39131 - if (!capable(CAP_SYS_TTY_CONFIG))
39132 - perm = 0;
39133 -
39134 switch (cmd) {
39135 case KDGKBENT:
39136 /* Ensure another thread doesn't free it under us */
39137 @@ -1822,6 +1829,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
39138 spin_unlock_irqrestore(&kbd_event_lock, flags);
39139 return put_user(val, &user_kbe->kb_value);
39140 case KDSKBENT:
39141 + if (!capable(CAP_SYS_TTY_CONFIG))
39142 + perm = 0;
39143 +
39144 if (!perm)
39145 return -EPERM;
39146 if (!i && v == K_NOSUCHMAP) {
39147 @@ -1912,9 +1922,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
39148 int i, j, k;
39149 int ret;
39150
39151 - if (!capable(CAP_SYS_TTY_CONFIG))
39152 - perm = 0;
39153 -
39154 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
39155 if (!kbs) {
39156 ret = -ENOMEM;
39157 @@ -1948,6 +1955,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
39158 kfree(kbs);
39159 return ((p && *p) ? -EOVERFLOW : 0);
39160 case KDSKBSENT:
39161 + if (!capable(CAP_SYS_TTY_CONFIG))
39162 + perm = 0;
39163 +
39164 if (!perm) {
39165 ret = -EPERM;
39166 goto reterr;
39167 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
39168 index a783d53..cb30d94 100644
39169 --- a/drivers/uio/uio.c
39170 +++ b/drivers/uio/uio.c
39171 @@ -25,6 +25,7 @@
39172 #include <linux/kobject.h>
39173 #include <linux/cdev.h>
39174 #include <linux/uio_driver.h>
39175 +#include <asm/local.h>
39176
39177 #define UIO_MAX_DEVICES (1U << MINORBITS)
39178
39179 @@ -32,10 +33,10 @@ struct uio_device {
39180 struct module *owner;
39181 struct device *dev;
39182 int minor;
39183 - atomic_t event;
39184 + atomic_unchecked_t event;
39185 struct fasync_struct *async_queue;
39186 wait_queue_head_t wait;
39187 - int vma_count;
39188 + local_t vma_count;
39189 struct uio_info *info;
39190 struct kobject *map_dir;
39191 struct kobject *portio_dir;
39192 @@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
39193 struct device_attribute *attr, char *buf)
39194 {
39195 struct uio_device *idev = dev_get_drvdata(dev);
39196 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
39197 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
39198 }
39199
39200 static struct device_attribute uio_class_attributes[] = {
39201 @@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
39202 {
39203 struct uio_device *idev = info->uio_dev;
39204
39205 - atomic_inc(&idev->event);
39206 + atomic_inc_unchecked(&idev->event);
39207 wake_up_interruptible(&idev->wait);
39208 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
39209 }
39210 @@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
39211 }
39212
39213 listener->dev = idev;
39214 - listener->event_count = atomic_read(&idev->event);
39215 + listener->event_count = atomic_read_unchecked(&idev->event);
39216 filep->private_data = listener;
39217
39218 if (idev->info->open) {
39219 @@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
39220 return -EIO;
39221
39222 poll_wait(filep, &idev->wait, wait);
39223 - if (listener->event_count != atomic_read(&idev->event))
39224 + if (listener->event_count != atomic_read_unchecked(&idev->event))
39225 return POLLIN | POLLRDNORM;
39226 return 0;
39227 }
39228 @@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
39229 do {
39230 set_current_state(TASK_INTERRUPTIBLE);
39231
39232 - event_count = atomic_read(&idev->event);
39233 + event_count = atomic_read_unchecked(&idev->event);
39234 if (event_count != listener->event_count) {
39235 if (copy_to_user(buf, &event_count, count))
39236 retval = -EFAULT;
39237 @@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
39238 static void uio_vma_open(struct vm_area_struct *vma)
39239 {
39240 struct uio_device *idev = vma->vm_private_data;
39241 - idev->vma_count++;
39242 + local_inc(&idev->vma_count);
39243 }
39244
39245 static void uio_vma_close(struct vm_area_struct *vma)
39246 {
39247 struct uio_device *idev = vma->vm_private_data;
39248 - idev->vma_count--;
39249 + local_dec(&idev->vma_count);
39250 }
39251
39252 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
39253 @@ -821,7 +822,7 @@ int __uio_register_device(struct module *owner,
39254 idev->owner = owner;
39255 idev->info = info;
39256 init_waitqueue_head(&idev->wait);
39257 - atomic_set(&idev->event, 0);
39258 + atomic_set_unchecked(&idev->event, 0);
39259
39260 ret = uio_get_minor(idev);
39261 if (ret)
39262 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
39263 index b7eb86a..36d28af 100644
39264 --- a/drivers/usb/atm/cxacru.c
39265 +++ b/drivers/usb/atm/cxacru.c
39266 @@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
39267 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
39268 if (ret < 2)
39269 return -EINVAL;
39270 - if (index < 0 || index > 0x7f)
39271 + if (index > 0x7f)
39272 return -EINVAL;
39273 pos += tmp;
39274
39275 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
39276 index ee62b35..b663594 100644
39277 --- a/drivers/usb/atm/usbatm.c
39278 +++ b/drivers/usb/atm/usbatm.c
39279 @@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39280 if (printk_ratelimit())
39281 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
39282 __func__, vpi, vci);
39283 - atomic_inc(&vcc->stats->rx_err);
39284 + atomic_inc_unchecked(&vcc->stats->rx_err);
39285 return;
39286 }
39287
39288 @@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39289 if (length > ATM_MAX_AAL5_PDU) {
39290 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
39291 __func__, length, vcc);
39292 - atomic_inc(&vcc->stats->rx_err);
39293 + atomic_inc_unchecked(&vcc->stats->rx_err);
39294 goto out;
39295 }
39296
39297 @@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39298 if (sarb->len < pdu_length) {
39299 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
39300 __func__, pdu_length, sarb->len, vcc);
39301 - atomic_inc(&vcc->stats->rx_err);
39302 + atomic_inc_unchecked(&vcc->stats->rx_err);
39303 goto out;
39304 }
39305
39306 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
39307 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
39308 __func__, vcc);
39309 - atomic_inc(&vcc->stats->rx_err);
39310 + atomic_inc_unchecked(&vcc->stats->rx_err);
39311 goto out;
39312 }
39313
39314 @@ -387,7 +387,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39315 if (printk_ratelimit())
39316 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
39317 __func__, length);
39318 - atomic_inc(&vcc->stats->rx_drop);
39319 + atomic_inc_unchecked(&vcc->stats->rx_drop);
39320 goto out;
39321 }
39322
39323 @@ -412,7 +412,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39324
39325 vcc->push(vcc, skb);
39326
39327 - atomic_inc(&vcc->stats->rx);
39328 + atomic_inc_unchecked(&vcc->stats->rx);
39329 out:
39330 skb_trim(sarb, 0);
39331 }
39332 @@ -615,7 +615,7 @@ static void usbatm_tx_process(unsigned long data)
39333 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
39334
39335 usbatm_pop(vcc, skb);
39336 - atomic_inc(&vcc->stats->tx);
39337 + atomic_inc_unchecked(&vcc->stats->tx);
39338
39339 skb = skb_dequeue(&instance->sndqueue);
39340 }
39341 @@ -770,11 +770,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
39342 if (!left--)
39343 return sprintf(page,
39344 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
39345 - atomic_read(&atm_dev->stats.aal5.tx),
39346 - atomic_read(&atm_dev->stats.aal5.tx_err),
39347 - atomic_read(&atm_dev->stats.aal5.rx),
39348 - atomic_read(&atm_dev->stats.aal5.rx_err),
39349 - atomic_read(&atm_dev->stats.aal5.rx_drop));
39350 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
39351 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
39352 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
39353 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
39354 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
39355
39356 if (!left--) {
39357 if (instance->disconnected)
39358 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
39359 index 3440812..2a4ef1f 100644
39360 --- a/drivers/usb/core/devices.c
39361 +++ b/drivers/usb/core/devices.c
39362 @@ -126,7 +126,7 @@ static const char format_endpt[] =
39363 * time it gets called.
39364 */
39365 static struct device_connect_event {
39366 - atomic_t count;
39367 + atomic_unchecked_t count;
39368 wait_queue_head_t wait;
39369 } device_event = {
39370 .count = ATOMIC_INIT(1),
39371 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
39372
39373 void usbfs_conn_disc_event(void)
39374 {
39375 - atomic_add(2, &device_event.count);
39376 + atomic_add_unchecked(2, &device_event.count);
39377 wake_up(&device_event.wait);
39378 }
39379
39380 @@ -648,7 +648,7 @@ static unsigned int usb_device_poll(struct file *file,
39381
39382 poll_wait(file, &device_event.wait, wait);
39383
39384 - event_count = atomic_read(&device_event.count);
39385 + event_count = atomic_read_unchecked(&device_event.count);
39386 if (file->f_version != event_count) {
39387 file->f_version = event_count;
39388 return POLLIN | POLLRDNORM;
39389 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
39390 index 89dcf15..481800b 100644
39391 --- a/drivers/usb/early/ehci-dbgp.c
39392 +++ b/drivers/usb/early/ehci-dbgp.c
39393 @@ -97,7 +97,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
39394
39395 #ifdef CONFIG_KGDB
39396 static struct kgdb_io kgdbdbgp_io_ops;
39397 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
39398 +static struct kgdb_io kgdbdbgp_io_ops_console;
39399 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
39400 #else
39401 #define dbgp_kgdb_mode (0)
39402 #endif
39403 @@ -1035,6 +1036,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
39404 .write_char = kgdbdbgp_write_char,
39405 };
39406
39407 +static struct kgdb_io kgdbdbgp_io_ops_console = {
39408 + .name = "kgdbdbgp",
39409 + .read_char = kgdbdbgp_read_char,
39410 + .write_char = kgdbdbgp_write_char,
39411 + .is_console = 1
39412 +};
39413 +
39414 static int kgdbdbgp_wait_time;
39415
39416 static int __init kgdbdbgp_parse_config(char *str)
39417 @@ -1050,8 +1058,10 @@ static int __init kgdbdbgp_parse_config(char *str)
39418 ptr++;
39419 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
39420 }
39421 - kgdb_register_io_module(&kgdbdbgp_io_ops);
39422 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
39423 + if (early_dbgp_console.index != -1)
39424 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
39425 + else
39426 + kgdb_register_io_module(&kgdbdbgp_io_ops);
39427
39428 return 0;
39429 }
39430 diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
39431 index da6d479..80ed10b 100644
39432 --- a/drivers/usb/gadget/u_serial.c
39433 +++ b/drivers/usb/gadget/u_serial.c
39434 @@ -735,9 +735,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
39435 spin_lock_irq(&port->port_lock);
39436
39437 /* already open? Great. */
39438 - if (port->port.count) {
39439 + if (atomic_read(&port->port.count)) {
39440 status = 0;
39441 - port->port.count++;
39442 + atomic_inc(&port->port.count);
39443
39444 /* currently opening/closing? wait ... */
39445 } else if (port->openclose) {
39446 @@ -796,7 +796,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
39447 tty->driver_data = port;
39448 port->port.tty = tty;
39449
39450 - port->port.count = 1;
39451 + atomic_set(&port->port.count, 1);
39452 port->openclose = false;
39453
39454 /* if connected, start the I/O stream */
39455 @@ -838,11 +838,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
39456
39457 spin_lock_irq(&port->port_lock);
39458
39459 - if (port->port.count != 1) {
39460 - if (port->port.count == 0)
39461 + if (atomic_read(&port->port.count) != 1) {
39462 + if (atomic_read(&port->port.count) == 0)
39463 WARN_ON(1);
39464 else
39465 - --port->port.count;
39466 + atomic_dec(&port->port.count);
39467 goto exit;
39468 }
39469
39470 @@ -852,7 +852,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
39471 * and sleep if necessary
39472 */
39473 port->openclose = true;
39474 - port->port.count = 0;
39475 + atomic_set(&port->port.count, 0);
39476
39477 gser = port->port_usb;
39478 if (gser && gser->disconnect)
39479 @@ -1156,7 +1156,7 @@ static int gs_closed(struct gs_port *port)
39480 int cond;
39481
39482 spin_lock_irq(&port->port_lock);
39483 - cond = (port->port.count == 0) && !port->openclose;
39484 + cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
39485 spin_unlock_irq(&port->port_lock);
39486 return cond;
39487 }
39488 @@ -1269,7 +1269,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
39489 /* if it's already open, start I/O ... and notify the serial
39490 * protocol about open/close status (connect/disconnect).
39491 */
39492 - if (port->port.count) {
39493 + if (atomic_read(&port->port.count)) {
39494 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
39495 gs_start_io(port);
39496 if (gser->connect)
39497 @@ -1316,7 +1316,7 @@ void gserial_disconnect(struct gserial *gser)
39498
39499 port->port_usb = NULL;
39500 gser->ioport = NULL;
39501 - if (port->port.count > 0 || port->openclose) {
39502 + if (atomic_read(&port->port.count) > 0 || port->openclose) {
39503 wake_up_interruptible(&port->drain_wait);
39504 if (port->port.tty)
39505 tty_hangup(port->port.tty);
39506 @@ -1332,7 +1332,7 @@ void gserial_disconnect(struct gserial *gser)
39507
39508 /* finally, free any unused/unusable I/O buffers */
39509 spin_lock_irqsave(&port->port_lock, flags);
39510 - if (port->port.count == 0 && !port->openclose)
39511 + if (atomic_read(&port->port.count) == 0 && !port->openclose)
39512 gs_buf_free(&port->port_write_buf);
39513 gs_free_requests(gser->out, &port->read_pool, NULL);
39514 gs_free_requests(gser->out, &port->read_queue, NULL);
39515 diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
39516 index b9cca6d..75c75df 100644
39517 --- a/drivers/usb/serial/console.c
39518 +++ b/drivers/usb/serial/console.c
39519 @@ -127,7 +127,7 @@ static int usb_console_setup(struct console *co, char *options)
39520
39521 info->port = port;
39522
39523 - ++port->port.count;
39524 + atomic_inc(&port->port.count);
39525 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
39526 if (serial->type->set_termios) {
39527 /*
39528 @@ -177,7 +177,7 @@ static int usb_console_setup(struct console *co, char *options)
39529 }
39530 /* Now that any required fake tty operations are completed restore
39531 * the tty port count */
39532 - --port->port.count;
39533 + atomic_dec(&port->port.count);
39534 /* The console is special in terms of closing the device so
39535 * indicate this port is now acting as a system console. */
39536 port->port.console = 1;
39537 @@ -190,7 +190,7 @@ static int usb_console_setup(struct console *co, char *options)
39538 free_tty:
39539 kfree(tty);
39540 reset_open_count:
39541 - port->port.count = 0;
39542 + atomic_set(&port->port.count, 0);
39543 usb_autopm_put_interface(serial->interface);
39544 error_get_interface:
39545 usb_serial_put(serial);
39546 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
39547 index d6bea3e..60b250e 100644
39548 --- a/drivers/usb/wusbcore/wa-hc.h
39549 +++ b/drivers/usb/wusbcore/wa-hc.h
39550 @@ -192,7 +192,7 @@ struct wahc {
39551 struct list_head xfer_delayed_list;
39552 spinlock_t xfer_list_lock;
39553 struct work_struct xfer_work;
39554 - atomic_t xfer_id_count;
39555 + atomic_unchecked_t xfer_id_count;
39556 };
39557
39558
39559 @@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
39560 INIT_LIST_HEAD(&wa->xfer_delayed_list);
39561 spin_lock_init(&wa->xfer_list_lock);
39562 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
39563 - atomic_set(&wa->xfer_id_count, 1);
39564 + atomic_set_unchecked(&wa->xfer_id_count, 1);
39565 }
39566
39567 /**
39568 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
39569 index 57c01ab..8a05959 100644
39570 --- a/drivers/usb/wusbcore/wa-xfer.c
39571 +++ b/drivers/usb/wusbcore/wa-xfer.c
39572 @@ -296,7 +296,7 @@ out:
39573 */
39574 static void wa_xfer_id_init(struct wa_xfer *xfer)
39575 {
39576 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
39577 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
39578 }
39579
39580 /*
39581 diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
39582 index ef82a0d..da8a0b3 100644
39583 --- a/drivers/vhost/vhost.c
39584 +++ b/drivers/vhost/vhost.c
39585 @@ -634,7 +634,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
39586 return 0;
39587 }
39588
39589 -static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
39590 +static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
39591 {
39592 struct file *eventfp, *filep = NULL,
39593 *pollstart = NULL, *pollstop = NULL;
39594 diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
39595 index 747442d..7c0c434 100644
39596 --- a/drivers/video/aty/aty128fb.c
39597 +++ b/drivers/video/aty/aty128fb.c
39598 @@ -149,7 +149,7 @@ enum {
39599 };
39600
39601 /* Must match above enum */
39602 -static const char *r128_family[] __devinitdata = {
39603 +static const char *r128_family[] __devinitconst = {
39604 "AGP",
39605 "PCI",
39606 "PRO AGP",
39607 diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
39608 index 5c3960d..15cf8fc 100644
39609 --- a/drivers/video/fbcmap.c
39610 +++ b/drivers/video/fbcmap.c
39611 @@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
39612 rc = -ENODEV;
39613 goto out;
39614 }
39615 - if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
39616 - !info->fbops->fb_setcmap)) {
39617 + if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
39618 rc = -EINVAL;
39619 goto out1;
39620 }
39621 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
39622 index 0dff12a..2ef47b3 100644
39623 --- a/drivers/video/fbmem.c
39624 +++ b/drivers/video/fbmem.c
39625 @@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
39626 image->dx += image->width + 8;
39627 }
39628 } else if (rotate == FB_ROTATE_UD) {
39629 - for (x = 0; x < num && image->dx >= 0; x++) {
39630 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
39631 info->fbops->fb_imageblit(info, image);
39632 image->dx -= image->width + 8;
39633 }
39634 @@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
39635 image->dy += image->height + 8;
39636 }
39637 } else if (rotate == FB_ROTATE_CCW) {
39638 - for (x = 0; x < num && image->dy >= 0; x++) {
39639 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
39640 info->fbops->fb_imageblit(info, image);
39641 image->dy -= image->height + 8;
39642 }
39643 @@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
39644 return -EFAULT;
39645 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
39646 return -EINVAL;
39647 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
39648 + if (con2fb.framebuffer >= FB_MAX)
39649 return -EINVAL;
39650 if (!registered_fb[con2fb.framebuffer])
39651 request_module("fb%d", con2fb.framebuffer);
39652 diff --git a/drivers/video/geode/gx1fb_core.c b/drivers/video/geode/gx1fb_core.c
39653 index 5a5d092..265c5ed 100644
39654 --- a/drivers/video/geode/gx1fb_core.c
39655 +++ b/drivers/video/geode/gx1fb_core.c
39656 @@ -29,7 +29,7 @@ static int crt_option = 1;
39657 static char panel_option[32] = "";
39658
39659 /* Modes relevant to the GX1 (taken from modedb.c) */
39660 -static const struct fb_videomode __devinitdata gx1_modedb[] = {
39661 +static const struct fb_videomode __devinitconst gx1_modedb[] = {
39662 /* 640x480-60 VESA */
39663 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
39664 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
39665 diff --git a/drivers/video/gxt4500.c b/drivers/video/gxt4500.c
39666 index 0fad23f..0e9afa4 100644
39667 --- a/drivers/video/gxt4500.c
39668 +++ b/drivers/video/gxt4500.c
39669 @@ -156,7 +156,7 @@ struct gxt4500_par {
39670 static char *mode_option;
39671
39672 /* default mode: 1280x1024 @ 60 Hz, 8 bpp */
39673 -static const struct fb_videomode defaultmode __devinitdata = {
39674 +static const struct fb_videomode defaultmode __devinitconst = {
39675 .refresh = 60,
39676 .xres = 1280,
39677 .yres = 1024,
39678 @@ -581,7 +581,7 @@ static int gxt4500_blank(int blank, struct fb_info *info)
39679 return 0;
39680 }
39681
39682 -static const struct fb_fix_screeninfo gxt4500_fix __devinitdata = {
39683 +static const struct fb_fix_screeninfo gxt4500_fix __devinitconst = {
39684 .id = "IBM GXT4500P",
39685 .type = FB_TYPE_PACKED_PIXELS,
39686 .visual = FB_VISUAL_PSEUDOCOLOR,
39687 diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
39688 index 7672d2e..b56437f 100644
39689 --- a/drivers/video/i810/i810_accel.c
39690 +++ b/drivers/video/i810/i810_accel.c
39691 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
39692 }
39693 }
39694 printk("ringbuffer lockup!!!\n");
39695 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
39696 i810_report_error(mmio);
39697 par->dev_flags |= LOCKUP;
39698 info->pixmap.scan_align = 1;
39699 diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
39700 index b83f361..2b05a91 100644
39701 --- a/drivers/video/i810/i810_main.c
39702 +++ b/drivers/video/i810/i810_main.c
39703 @@ -97,7 +97,7 @@ static int i810fb_blank (int blank_mode, struct fb_info *info);
39704 static void i810fb_release_resource (struct fb_info *info, struct i810fb_par *par);
39705
39706 /* PCI */
39707 -static const char *i810_pci_list[] __devinitdata = {
39708 +static const char *i810_pci_list[] __devinitconst = {
39709 "Intel(R) 810 Framebuffer Device" ,
39710 "Intel(R) 810-DC100 Framebuffer Device" ,
39711 "Intel(R) 810E Framebuffer Device" ,
39712 diff --git a/drivers/video/jz4740_fb.c b/drivers/video/jz4740_fb.c
39713 index de36693..3c63fc2 100644
39714 --- a/drivers/video/jz4740_fb.c
39715 +++ b/drivers/video/jz4740_fb.c
39716 @@ -136,7 +136,7 @@ struct jzfb {
39717 uint32_t pseudo_palette[16];
39718 };
39719
39720 -static const struct fb_fix_screeninfo jzfb_fix __devinitdata = {
39721 +static const struct fb_fix_screeninfo jzfb_fix __devinitconst = {
39722 .id = "JZ4740 FB",
39723 .type = FB_TYPE_PACKED_PIXELS,
39724 .visual = FB_VISUAL_TRUECOLOR,
39725 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
39726 index 3c14e43..eafa544 100644
39727 --- a/drivers/video/logo/logo_linux_clut224.ppm
39728 +++ b/drivers/video/logo/logo_linux_clut224.ppm
39729 @@ -1,1604 +1,1123 @@
39730 P3
39731 -# Standard 224-color Linux logo
39732 80 80
39733 255
39734 - 0 0 0 0 0 0 0 0 0 0 0 0
39735 - 0 0 0 0 0 0 0 0 0 0 0 0
39736 - 0 0 0 0 0 0 0 0 0 0 0 0
39737 - 0 0 0 0 0 0 0 0 0 0 0 0
39738 - 0 0 0 0 0 0 0 0 0 0 0 0
39739 - 0 0 0 0 0 0 0 0 0 0 0 0
39740 - 0 0 0 0 0 0 0 0 0 0 0 0
39741 - 0 0 0 0 0 0 0 0 0 0 0 0
39742 - 0 0 0 0 0 0 0 0 0 0 0 0
39743 - 6 6 6 6 6 6 10 10 10 10 10 10
39744 - 10 10 10 6 6 6 6 6 6 6 6 6
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 0 0 0 0 0 0 0 0 0
39756 - 0 0 0 0 0 0 0 0 0 0 0 0
39757 - 0 0 0 0 0 0 0 0 0 0 0 0
39758 - 0 0 0 0 0 0 0 0 0 0 0 0
39759 - 0 0 0 0 0 0 0 0 0 0 0 0
39760 - 0 0 0 0 0 0 0 0 0 0 0 0
39761 - 0 0 0 0 0 0 0 0 0 0 0 0
39762 - 0 0 0 6 6 6 10 10 10 14 14 14
39763 - 22 22 22 26 26 26 30 30 30 34 34 34
39764 - 30 30 30 30 30 30 26 26 26 18 18 18
39765 - 14 14 14 10 10 10 6 6 6 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 0 0 0 0 0 0 0
39769 - 0 0 0 0 0 0 0 0 0 0 0 0
39770 - 0 0 0 0 0 0 0 0 0 0 0 0
39771 - 0 0 0 0 0 0 0 0 0 0 0 0
39772 - 0 0 0 0 0 0 0 0 0 0 0 0
39773 - 0 0 0 0 0 0 0 0 0 0 0 0
39774 - 0 0 0 0 0 0 0 0 0 0 0 0
39775 - 0 0 0 0 0 1 0 0 1 0 0 0
39776 - 0 0 0 0 0 0 0 0 0 0 0 0
39777 - 0 0 0 0 0 0 0 0 0 0 0 0
39778 - 0 0 0 0 0 0 0 0 0 0 0 0
39779 - 0 0 0 0 0 0 0 0 0 0 0 0
39780 - 0 0 0 0 0 0 0 0 0 0 0 0
39781 - 0 0 0 0 0 0 0 0 0 0 0 0
39782 - 6 6 6 14 14 14 26 26 26 42 42 42
39783 - 54 54 54 66 66 66 78 78 78 78 78 78
39784 - 78 78 78 74 74 74 66 66 66 54 54 54
39785 - 42 42 42 26 26 26 18 18 18 10 10 10
39786 - 6 6 6 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 0 0 0 0 0 0 0 0 0 0
39789 - 0 0 0 0 0 0 0 0 0 0 0 0
39790 - 0 0 0 0 0 0 0 0 0 0 0 0
39791 - 0 0 0 0 0 0 0 0 0 0 0 0
39792 - 0 0 0 0 0 0 0 0 0 0 0 0
39793 - 0 0 0 0 0 0 0 0 0 0 0 0
39794 - 0 0 0 0 0 0 0 0 0 0 0 0
39795 - 0 0 1 0 0 0 0 0 0 0 0 0
39796 - 0 0 0 0 0 0 0 0 0 0 0 0
39797 - 0 0 0 0 0 0 0 0 0 0 0 0
39798 - 0 0 0 0 0 0 0 0 0 0 0 0
39799 - 0 0 0 0 0 0 0 0 0 0 0 0
39800 - 0 0 0 0 0 0 0 0 0 0 0 0
39801 - 0 0 0 0 0 0 0 0 0 10 10 10
39802 - 22 22 22 42 42 42 66 66 66 86 86 86
39803 - 66 66 66 38 38 38 38 38 38 22 22 22
39804 - 26 26 26 34 34 34 54 54 54 66 66 66
39805 - 86 86 86 70 70 70 46 46 46 26 26 26
39806 - 14 14 14 6 6 6 0 0 0 0 0 0
39807 - 0 0 0 0 0 0 0 0 0 0 0 0
39808 - 0 0 0 0 0 0 0 0 0 0 0 0
39809 - 0 0 0 0 0 0 0 0 0 0 0 0
39810 - 0 0 0 0 0 0 0 0 0 0 0 0
39811 - 0 0 0 0 0 0 0 0 0 0 0 0
39812 - 0 0 0 0 0 0 0 0 0 0 0 0
39813 - 0 0 0 0 0 0 0 0 0 0 0 0
39814 - 0 0 0 0 0 0 0 0 0 0 0 0
39815 - 0 0 1 0 0 1 0 0 1 0 0 0
39816 - 0 0 0 0 0 0 0 0 0 0 0 0
39817 - 0 0 0 0 0 0 0 0 0 0 0 0
39818 - 0 0 0 0 0 0 0 0 0 0 0 0
39819 - 0 0 0 0 0 0 0 0 0 0 0 0
39820 - 0 0 0 0 0 0 0 0 0 0 0 0
39821 - 0 0 0 0 0 0 10 10 10 26 26 26
39822 - 50 50 50 82 82 82 58 58 58 6 6 6
39823 - 2 2 6 2 2 6 2 2 6 2 2 6
39824 - 2 2 6 2 2 6 2 2 6 2 2 6
39825 - 6 6 6 54 54 54 86 86 86 66 66 66
39826 - 38 38 38 18 18 18 6 6 6 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 0 0 0 0 0 0 0 0 0
39835 - 0 0 0 0 0 0 0 0 0 0 0 0
39836 - 0 0 0 0 0 0 0 0 0 0 0 0
39837 - 0 0 0 0 0 0 0 0 0 0 0 0
39838 - 0 0 0 0 0 0 0 0 0 0 0 0
39839 - 0 0 0 0 0 0 0 0 0 0 0 0
39840 - 0 0 0 0 0 0 0 0 0 0 0 0
39841 - 0 0 0 6 6 6 22 22 22 50 50 50
39842 - 78 78 78 34 34 34 2 2 6 2 2 6
39843 - 2 2 6 2 2 6 2 2 6 2 2 6
39844 - 2 2 6 2 2 6 2 2 6 2 2 6
39845 - 2 2 6 2 2 6 6 6 6 70 70 70
39846 - 78 78 78 46 46 46 22 22 22 6 6 6
39847 - 0 0 0 0 0 0 0 0 0 0 0 0
39848 - 0 0 0 0 0 0 0 0 0 0 0 0
39849 - 0 0 0 0 0 0 0 0 0 0 0 0
39850 - 0 0 0 0 0 0 0 0 0 0 0 0
39851 - 0 0 0 0 0 0 0 0 0 0 0 0
39852 - 0 0 0 0 0 0 0 0 0 0 0 0
39853 - 0 0 0 0 0 0 0 0 0 0 0 0
39854 - 0 0 0 0 0 0 0 0 0 0 0 0
39855 - 0 0 1 0 0 1 0 0 1 0 0 0
39856 - 0 0 0 0 0 0 0 0 0 0 0 0
39857 - 0 0 0 0 0 0 0 0 0 0 0 0
39858 - 0 0 0 0 0 0 0 0 0 0 0 0
39859 - 0 0 0 0 0 0 0 0 0 0 0 0
39860 - 0 0 0 0 0 0 0 0 0 0 0 0
39861 - 6 6 6 18 18 18 42 42 42 82 82 82
39862 - 26 26 26 2 2 6 2 2 6 2 2 6
39863 - 2 2 6 2 2 6 2 2 6 2 2 6
39864 - 2 2 6 2 2 6 2 2 6 14 14 14
39865 - 46 46 46 34 34 34 6 6 6 2 2 6
39866 - 42 42 42 78 78 78 42 42 42 18 18 18
39867 - 6 6 6 0 0 0 0 0 0 0 0 0
39868 - 0 0 0 0 0 0 0 0 0 0 0 0
39869 - 0 0 0 0 0 0 0 0 0 0 0 0
39870 - 0 0 0 0 0 0 0 0 0 0 0 0
39871 - 0 0 0 0 0 0 0 0 0 0 0 0
39872 - 0 0 0 0 0 0 0 0 0 0 0 0
39873 - 0 0 0 0 0 0 0 0 0 0 0 0
39874 - 0 0 0 0 0 0 0 0 0 0 0 0
39875 - 0 0 1 0 0 0 0 0 1 0 0 0
39876 - 0 0 0 0 0 0 0 0 0 0 0 0
39877 - 0 0 0 0 0 0 0 0 0 0 0 0
39878 - 0 0 0 0 0 0 0 0 0 0 0 0
39879 - 0 0 0 0 0 0 0 0 0 0 0 0
39880 - 0 0 0 0 0 0 0 0 0 0 0 0
39881 - 10 10 10 30 30 30 66 66 66 58 58 58
39882 - 2 2 6 2 2 6 2 2 6 2 2 6
39883 - 2 2 6 2 2 6 2 2 6 2 2 6
39884 - 2 2 6 2 2 6 2 2 6 26 26 26
39885 - 86 86 86 101 101 101 46 46 46 10 10 10
39886 - 2 2 6 58 58 58 70 70 70 34 34 34
39887 - 10 10 10 0 0 0 0 0 0 0 0 0
39888 - 0 0 0 0 0 0 0 0 0 0 0 0
39889 - 0 0 0 0 0 0 0 0 0 0 0 0
39890 - 0 0 0 0 0 0 0 0 0 0 0 0
39891 - 0 0 0 0 0 0 0 0 0 0 0 0
39892 - 0 0 0 0 0 0 0 0 0 0 0 0
39893 - 0 0 0 0 0 0 0 0 0 0 0 0
39894 - 0 0 0 0 0 0 0 0 0 0 0 0
39895 - 0 0 1 0 0 1 0 0 1 0 0 0
39896 - 0 0 0 0 0 0 0 0 0 0 0 0
39897 - 0 0 0 0 0 0 0 0 0 0 0 0
39898 - 0 0 0 0 0 0 0 0 0 0 0 0
39899 - 0 0 0 0 0 0 0 0 0 0 0 0
39900 - 0 0 0 0 0 0 0 0 0 0 0 0
39901 - 14 14 14 42 42 42 86 86 86 10 10 10
39902 - 2 2 6 2 2 6 2 2 6 2 2 6
39903 - 2 2 6 2 2 6 2 2 6 2 2 6
39904 - 2 2 6 2 2 6 2 2 6 30 30 30
39905 - 94 94 94 94 94 94 58 58 58 26 26 26
39906 - 2 2 6 6 6 6 78 78 78 54 54 54
39907 - 22 22 22 6 6 6 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 0 0 0
39914 - 0 0 0 0 0 0 0 0 0 0 0 0
39915 - 0 0 0 0 0 0 0 0 0 0 0 0
39916 - 0 0 0 0 0 0 0 0 0 0 0 0
39917 - 0 0 0 0 0 0 0 0 0 0 0 0
39918 - 0 0 0 0 0 0 0 0 0 0 0 0
39919 - 0 0 0 0 0 0 0 0 0 0 0 0
39920 - 0 0 0 0 0 0 0 0 0 6 6 6
39921 - 22 22 22 62 62 62 62 62 62 2 2 6
39922 - 2 2 6 2 2 6 2 2 6 2 2 6
39923 - 2 2 6 2 2 6 2 2 6 2 2 6
39924 - 2 2 6 2 2 6 2 2 6 26 26 26
39925 - 54 54 54 38 38 38 18 18 18 10 10 10
39926 - 2 2 6 2 2 6 34 34 34 82 82 82
39927 - 38 38 38 14 14 14 0 0 0 0 0 0
39928 - 0 0 0 0 0 0 0 0 0 0 0 0
39929 - 0 0 0 0 0 0 0 0 0 0 0 0
39930 - 0 0 0 0 0 0 0 0 0 0 0 0
39931 - 0 0 0 0 0 0 0 0 0 0 0 0
39932 - 0 0 0 0 0 0 0 0 0 0 0 0
39933 - 0 0 0 0 0 0 0 0 0 0 0 0
39934 - 0 0 0 0 0 0 0 0 0 0 0 0
39935 - 0 0 0 0 0 1 0 0 1 0 0 0
39936 - 0 0 0 0 0 0 0 0 0 0 0 0
39937 - 0 0 0 0 0 0 0 0 0 0 0 0
39938 - 0 0 0 0 0 0 0 0 0 0 0 0
39939 - 0 0 0 0 0 0 0 0 0 0 0 0
39940 - 0 0 0 0 0 0 0 0 0 6 6 6
39941 - 30 30 30 78 78 78 30 30 30 2 2 6
39942 - 2 2 6 2 2 6 2 2 6 2 2 6
39943 - 2 2 6 2 2 6 2 2 6 2 2 6
39944 - 2 2 6 2 2 6 2 2 6 10 10 10
39945 - 10 10 10 2 2 6 2 2 6 2 2 6
39946 - 2 2 6 2 2 6 2 2 6 78 78 78
39947 - 50 50 50 18 18 18 6 6 6 0 0 0
39948 - 0 0 0 0 0 0 0 0 0 0 0 0
39949 - 0 0 0 0 0 0 0 0 0 0 0 0
39950 - 0 0 0 0 0 0 0 0 0 0 0 0
39951 - 0 0 0 0 0 0 0 0 0 0 0 0
39952 - 0 0 0 0 0 0 0 0 0 0 0 0
39953 - 0 0 0 0 0 0 0 0 0 0 0 0
39954 - 0 0 0 0 0 0 0 0 0 0 0 0
39955 - 0 0 1 0 0 0 0 0 0 0 0 0
39956 - 0 0 0 0 0 0 0 0 0 0 0 0
39957 - 0 0 0 0 0 0 0 0 0 0 0 0
39958 - 0 0 0 0 0 0 0 0 0 0 0 0
39959 - 0 0 0 0 0 0 0 0 0 0 0 0
39960 - 0 0 0 0 0 0 0 0 0 10 10 10
39961 - 38 38 38 86 86 86 14 14 14 2 2 6
39962 - 2 2 6 2 2 6 2 2 6 2 2 6
39963 - 2 2 6 2 2 6 2 2 6 2 2 6
39964 - 2 2 6 2 2 6 2 2 6 2 2 6
39965 - 2 2 6 2 2 6 2 2 6 2 2 6
39966 - 2 2 6 2 2 6 2 2 6 54 54 54
39967 - 66 66 66 26 26 26 6 6 6 0 0 0
39968 - 0 0 0 0 0 0 0 0 0 0 0 0
39969 - 0 0 0 0 0 0 0 0 0 0 0 0
39970 - 0 0 0 0 0 0 0 0 0 0 0 0
39971 - 0 0 0 0 0 0 0 0 0 0 0 0
39972 - 0 0 0 0 0 0 0 0 0 0 0 0
39973 - 0 0 0 0 0 0 0 0 0 0 0 0
39974 - 0 0 0 0 0 0 0 0 0 0 0 0
39975 - 0 0 0 0 0 1 0 0 1 0 0 0
39976 - 0 0 0 0 0 0 0 0 0 0 0 0
39977 - 0 0 0 0 0 0 0 0 0 0 0 0
39978 - 0 0 0 0 0 0 0 0 0 0 0 0
39979 - 0 0 0 0 0 0 0 0 0 0 0 0
39980 - 0 0 0 0 0 0 0 0 0 14 14 14
39981 - 42 42 42 82 82 82 2 2 6 2 2 6
39982 - 2 2 6 6 6 6 10 10 10 2 2 6
39983 - 2 2 6 2 2 6 2 2 6 2 2 6
39984 - 2 2 6 2 2 6 2 2 6 6 6 6
39985 - 14 14 14 10 10 10 2 2 6 2 2 6
39986 - 2 2 6 2 2 6 2 2 6 18 18 18
39987 - 82 82 82 34 34 34 10 10 10 0 0 0
39988 - 0 0 0 0 0 0 0 0 0 0 0 0
39989 - 0 0 0 0 0 0 0 0 0 0 0 0
39990 - 0 0 0 0 0 0 0 0 0 0 0 0
39991 - 0 0 0 0 0 0 0 0 0 0 0 0
39992 - 0 0 0 0 0 0 0 0 0 0 0 0
39993 - 0 0 0 0 0 0 0 0 0 0 0 0
39994 - 0 0 0 0 0 0 0 0 0 0 0 0
39995 - 0 0 1 0 0 0 0 0 0 0 0 0
39996 - 0 0 0 0 0 0 0 0 0 0 0 0
39997 - 0 0 0 0 0 0 0 0 0 0 0 0
39998 - 0 0 0 0 0 0 0 0 0 0 0 0
39999 - 0 0 0 0 0 0 0 0 0 0 0 0
40000 - 0 0 0 0 0 0 0 0 0 14 14 14
40001 - 46 46 46 86 86 86 2 2 6 2 2 6
40002 - 6 6 6 6 6 6 22 22 22 34 34 34
40003 - 6 6 6 2 2 6 2 2 6 2 2 6
40004 - 2 2 6 2 2 6 18 18 18 34 34 34
40005 - 10 10 10 50 50 50 22 22 22 2 2 6
40006 - 2 2 6 2 2 6 2 2 6 10 10 10
40007 - 86 86 86 42 42 42 14 14 14 0 0 0
40008 - 0 0 0 0 0 0 0 0 0 0 0 0
40009 - 0 0 0 0 0 0 0 0 0 0 0 0
40010 - 0 0 0 0 0 0 0 0 0 0 0 0
40011 - 0 0 0 0 0 0 0 0 0 0 0 0
40012 - 0 0 0 0 0 0 0 0 0 0 0 0
40013 - 0 0 0 0 0 0 0 0 0 0 0 0
40014 - 0 0 0 0 0 0 0 0 0 0 0 0
40015 - 0 0 1 0 0 1 0 0 1 0 0 0
40016 - 0 0 0 0 0 0 0 0 0 0 0 0
40017 - 0 0 0 0 0 0 0 0 0 0 0 0
40018 - 0 0 0 0 0 0 0 0 0 0 0 0
40019 - 0 0 0 0 0 0 0 0 0 0 0 0
40020 - 0 0 0 0 0 0 0 0 0 14 14 14
40021 - 46 46 46 86 86 86 2 2 6 2 2 6
40022 - 38 38 38 116 116 116 94 94 94 22 22 22
40023 - 22 22 22 2 2 6 2 2 6 2 2 6
40024 - 14 14 14 86 86 86 138 138 138 162 162 162
40025 -154 154 154 38 38 38 26 26 26 6 6 6
40026 - 2 2 6 2 2 6 2 2 6 2 2 6
40027 - 86 86 86 46 46 46 14 14 14 0 0 0
40028 - 0 0 0 0 0 0 0 0 0 0 0 0
40029 - 0 0 0 0 0 0 0 0 0 0 0 0
40030 - 0 0 0 0 0 0 0 0 0 0 0 0
40031 - 0 0 0 0 0 0 0 0 0 0 0 0
40032 - 0 0 0 0 0 0 0 0 0 0 0 0
40033 - 0 0 0 0 0 0 0 0 0 0 0 0
40034 - 0 0 0 0 0 0 0 0 0 0 0 0
40035 - 0 0 0 0 0 0 0 0 0 0 0 0
40036 - 0 0 0 0 0 0 0 0 0 0 0 0
40037 - 0 0 0 0 0 0 0 0 0 0 0 0
40038 - 0 0 0 0 0 0 0 0 0 0 0 0
40039 - 0 0 0 0 0 0 0 0 0 0 0 0
40040 - 0 0 0 0 0 0 0 0 0 14 14 14
40041 - 46 46 46 86 86 86 2 2 6 14 14 14
40042 -134 134 134 198 198 198 195 195 195 116 116 116
40043 - 10 10 10 2 2 6 2 2 6 6 6 6
40044 -101 98 89 187 187 187 210 210 210 218 218 218
40045 -214 214 214 134 134 134 14 14 14 6 6 6
40046 - 2 2 6 2 2 6 2 2 6 2 2 6
40047 - 86 86 86 50 50 50 18 18 18 6 6 6
40048 - 0 0 0 0 0 0 0 0 0 0 0 0
40049 - 0 0 0 0 0 0 0 0 0 0 0 0
40050 - 0 0 0 0 0 0 0 0 0 0 0 0
40051 - 0 0 0 0 0 0 0 0 0 0 0 0
40052 - 0 0 0 0 0 0 0 0 0 0 0 0
40053 - 0 0 0 0 0 0 0 0 0 0 0 0
40054 - 0 0 0 0 0 0 0 0 1 0 0 0
40055 - 0 0 1 0 0 1 0 0 1 0 0 0
40056 - 0 0 0 0 0 0 0 0 0 0 0 0
40057 - 0 0 0 0 0 0 0 0 0 0 0 0
40058 - 0 0 0 0 0 0 0 0 0 0 0 0
40059 - 0 0 0 0 0 0 0 0 0 0 0 0
40060 - 0 0 0 0 0 0 0 0 0 14 14 14
40061 - 46 46 46 86 86 86 2 2 6 54 54 54
40062 -218 218 218 195 195 195 226 226 226 246 246 246
40063 - 58 58 58 2 2 6 2 2 6 30 30 30
40064 -210 210 210 253 253 253 174 174 174 123 123 123
40065 -221 221 221 234 234 234 74 74 74 2 2 6
40066 - 2 2 6 2 2 6 2 2 6 2 2 6
40067 - 70 70 70 58 58 58 22 22 22 6 6 6
40068 - 0 0 0 0 0 0 0 0 0 0 0 0
40069 - 0 0 0 0 0 0 0 0 0 0 0 0
40070 - 0 0 0 0 0 0 0 0 0 0 0 0
40071 - 0 0 0 0 0 0 0 0 0 0 0 0
40072 - 0 0 0 0 0 0 0 0 0 0 0 0
40073 - 0 0 0 0 0 0 0 0 0 0 0 0
40074 - 0 0 0 0 0 0 0 0 0 0 0 0
40075 - 0 0 0 0 0 0 0 0 0 0 0 0
40076 - 0 0 0 0 0 0 0 0 0 0 0 0
40077 - 0 0 0 0 0 0 0 0 0 0 0 0
40078 - 0 0 0 0 0 0 0 0 0 0 0 0
40079 - 0 0 0 0 0 0 0 0 0 0 0 0
40080 - 0 0 0 0 0 0 0 0 0 14 14 14
40081 - 46 46 46 82 82 82 2 2 6 106 106 106
40082 -170 170 170 26 26 26 86 86 86 226 226 226
40083 -123 123 123 10 10 10 14 14 14 46 46 46
40084 -231 231 231 190 190 190 6 6 6 70 70 70
40085 - 90 90 90 238 238 238 158 158 158 2 2 6
40086 - 2 2 6 2 2 6 2 2 6 2 2 6
40087 - 70 70 70 58 58 58 22 22 22 6 6 6
40088 - 0 0 0 0 0 0 0 0 0 0 0 0
40089 - 0 0 0 0 0 0 0 0 0 0 0 0
40090 - 0 0 0 0 0 0 0 0 0 0 0 0
40091 - 0 0 0 0 0 0 0 0 0 0 0 0
40092 - 0 0 0 0 0 0 0 0 0 0 0 0
40093 - 0 0 0 0 0 0 0 0 0 0 0 0
40094 - 0 0 0 0 0 0 0 0 1 0 0 0
40095 - 0 0 1 0 0 1 0 0 1 0 0 0
40096 - 0 0 0 0 0 0 0 0 0 0 0 0
40097 - 0 0 0 0 0 0 0 0 0 0 0 0
40098 - 0 0 0 0 0 0 0 0 0 0 0 0
40099 - 0 0 0 0 0 0 0 0 0 0 0 0
40100 - 0 0 0 0 0 0 0 0 0 14 14 14
40101 - 42 42 42 86 86 86 6 6 6 116 116 116
40102 -106 106 106 6 6 6 70 70 70 149 149 149
40103 -128 128 128 18 18 18 38 38 38 54 54 54
40104 -221 221 221 106 106 106 2 2 6 14 14 14
40105 - 46 46 46 190 190 190 198 198 198 2 2 6
40106 - 2 2 6 2 2 6 2 2 6 2 2 6
40107 - 74 74 74 62 62 62 22 22 22 6 6 6
40108 - 0 0 0 0 0 0 0 0 0 0 0 0
40109 - 0 0 0 0 0 0 0 0 0 0 0 0
40110 - 0 0 0 0 0 0 0 0 0 0 0 0
40111 - 0 0 0 0 0 0 0 0 0 0 0 0
40112 - 0 0 0 0 0 0 0 0 0 0 0 0
40113 - 0 0 0 0 0 0 0 0 0 0 0 0
40114 - 0 0 0 0 0 0 0 0 1 0 0 0
40115 - 0 0 1 0 0 0 0 0 1 0 0 0
40116 - 0 0 0 0 0 0 0 0 0 0 0 0
40117 - 0 0 0 0 0 0 0 0 0 0 0 0
40118 - 0 0 0 0 0 0 0 0 0 0 0 0
40119 - 0 0 0 0 0 0 0 0 0 0 0 0
40120 - 0 0 0 0 0 0 0 0 0 14 14 14
40121 - 42 42 42 94 94 94 14 14 14 101 101 101
40122 -128 128 128 2 2 6 18 18 18 116 116 116
40123 -118 98 46 121 92 8 121 92 8 98 78 10
40124 -162 162 162 106 106 106 2 2 6 2 2 6
40125 - 2 2 6 195 195 195 195 195 195 6 6 6
40126 - 2 2 6 2 2 6 2 2 6 2 2 6
40127 - 74 74 74 62 62 62 22 22 22 6 6 6
40128 - 0 0 0 0 0 0 0 0 0 0 0 0
40129 - 0 0 0 0 0 0 0 0 0 0 0 0
40130 - 0 0 0 0 0 0 0 0 0 0 0 0
40131 - 0 0 0 0 0 0 0 0 0 0 0 0
40132 - 0 0 0 0 0 0 0 0 0 0 0 0
40133 - 0 0 0 0 0 0 0 0 0 0 0 0
40134 - 0 0 0 0 0 0 0 0 1 0 0 1
40135 - 0 0 1 0 0 0 0 0 1 0 0 0
40136 - 0 0 0 0 0 0 0 0 0 0 0 0
40137 - 0 0 0 0 0 0 0 0 0 0 0 0
40138 - 0 0 0 0 0 0 0 0 0 0 0 0
40139 - 0 0 0 0 0 0 0 0 0 0 0 0
40140 - 0 0 0 0 0 0 0 0 0 10 10 10
40141 - 38 38 38 90 90 90 14 14 14 58 58 58
40142 -210 210 210 26 26 26 54 38 6 154 114 10
40143 -226 170 11 236 186 11 225 175 15 184 144 12
40144 -215 174 15 175 146 61 37 26 9 2 2 6
40145 - 70 70 70 246 246 246 138 138 138 2 2 6
40146 - 2 2 6 2 2 6 2 2 6 2 2 6
40147 - 70 70 70 66 66 66 26 26 26 6 6 6
40148 - 0 0 0 0 0 0 0 0 0 0 0 0
40149 - 0 0 0 0 0 0 0 0 0 0 0 0
40150 - 0 0 0 0 0 0 0 0 0 0 0 0
40151 - 0 0 0 0 0 0 0 0 0 0 0 0
40152 - 0 0 0 0 0 0 0 0 0 0 0 0
40153 - 0 0 0 0 0 0 0 0 0 0 0 0
40154 - 0 0 0 0 0 0 0 0 0 0 0 0
40155 - 0 0 0 0 0 0 0 0 0 0 0 0
40156 - 0 0 0 0 0 0 0 0 0 0 0 0
40157 - 0 0 0 0 0 0 0 0 0 0 0 0
40158 - 0 0 0 0 0 0 0 0 0 0 0 0
40159 - 0 0 0 0 0 0 0 0 0 0 0 0
40160 - 0 0 0 0 0 0 0 0 0 10 10 10
40161 - 38 38 38 86 86 86 14 14 14 10 10 10
40162 -195 195 195 188 164 115 192 133 9 225 175 15
40163 -239 182 13 234 190 10 232 195 16 232 200 30
40164 -245 207 45 241 208 19 232 195 16 184 144 12
40165 -218 194 134 211 206 186 42 42 42 2 2 6
40166 - 2 2 6 2 2 6 2 2 6 2 2 6
40167 - 50 50 50 74 74 74 30 30 30 6 6 6
40168 - 0 0 0 0 0 0 0 0 0 0 0 0
40169 - 0 0 0 0 0 0 0 0 0 0 0 0
40170 - 0 0 0 0 0 0 0 0 0 0 0 0
40171 - 0 0 0 0 0 0 0 0 0 0 0 0
40172 - 0 0 0 0 0 0 0 0 0 0 0 0
40173 - 0 0 0 0 0 0 0 0 0 0 0 0
40174 - 0 0 0 0 0 0 0 0 0 0 0 0
40175 - 0 0 0 0 0 0 0 0 0 0 0 0
40176 - 0 0 0 0 0 0 0 0 0 0 0 0
40177 - 0 0 0 0 0 0 0 0 0 0 0 0
40178 - 0 0 0 0 0 0 0 0 0 0 0 0
40179 - 0 0 0 0 0 0 0 0 0 0 0 0
40180 - 0 0 0 0 0 0 0 0 0 10 10 10
40181 - 34 34 34 86 86 86 14 14 14 2 2 6
40182 -121 87 25 192 133 9 219 162 10 239 182 13
40183 -236 186 11 232 195 16 241 208 19 244 214 54
40184 -246 218 60 246 218 38 246 215 20 241 208 19
40185 -241 208 19 226 184 13 121 87 25 2 2 6
40186 - 2 2 6 2 2 6 2 2 6 2 2 6
40187 - 50 50 50 82 82 82 34 34 34 10 10 10
40188 - 0 0 0 0 0 0 0 0 0 0 0 0
40189 - 0 0 0 0 0 0 0 0 0 0 0 0
40190 - 0 0 0 0 0 0 0 0 0 0 0 0
40191 - 0 0 0 0 0 0 0 0 0 0 0 0
40192 - 0 0 0 0 0 0 0 0 0 0 0 0
40193 - 0 0 0 0 0 0 0 0 0 0 0 0
40194 - 0 0 0 0 0 0 0 0 0 0 0 0
40195 - 0 0 0 0 0 0 0 0 0 0 0 0
40196 - 0 0 0 0 0 0 0 0 0 0 0 0
40197 - 0 0 0 0 0 0 0 0 0 0 0 0
40198 - 0 0 0 0 0 0 0 0 0 0 0 0
40199 - 0 0 0 0 0 0 0 0 0 0 0 0
40200 - 0 0 0 0 0 0 0 0 0 10 10 10
40201 - 34 34 34 82 82 82 30 30 30 61 42 6
40202 -180 123 7 206 145 10 230 174 11 239 182 13
40203 -234 190 10 238 202 15 241 208 19 246 218 74
40204 -246 218 38 246 215 20 246 215 20 246 215 20
40205 -226 184 13 215 174 15 184 144 12 6 6 6
40206 - 2 2 6 2 2 6 2 2 6 2 2 6
40207 - 26 26 26 94 94 94 42 42 42 14 14 14
40208 - 0 0 0 0 0 0 0 0 0 0 0 0
40209 - 0 0 0 0 0 0 0 0 0 0 0 0
40210 - 0 0 0 0 0 0 0 0 0 0 0 0
40211 - 0 0 0 0 0 0 0 0 0 0 0 0
40212 - 0 0 0 0 0 0 0 0 0 0 0 0
40213 - 0 0 0 0 0 0 0 0 0 0 0 0
40214 - 0 0 0 0 0 0 0 0 0 0 0 0
40215 - 0 0 0 0 0 0 0 0 0 0 0 0
40216 - 0 0 0 0 0 0 0 0 0 0 0 0
40217 - 0 0 0 0 0 0 0 0 0 0 0 0
40218 - 0 0 0 0 0 0 0 0 0 0 0 0
40219 - 0 0 0 0 0 0 0 0 0 0 0 0
40220 - 0 0 0 0 0 0 0 0 0 10 10 10
40221 - 30 30 30 78 78 78 50 50 50 104 69 6
40222 -192 133 9 216 158 10 236 178 12 236 186 11
40223 -232 195 16 241 208 19 244 214 54 245 215 43
40224 -246 215 20 246 215 20 241 208 19 198 155 10
40225 -200 144 11 216 158 10 156 118 10 2 2 6
40226 - 2 2 6 2 2 6 2 2 6 2 2 6
40227 - 6 6 6 90 90 90 54 54 54 18 18 18
40228 - 6 6 6 0 0 0 0 0 0 0 0 0
40229 - 0 0 0 0 0 0 0 0 0 0 0 0
40230 - 0 0 0 0 0 0 0 0 0 0 0 0
40231 - 0 0 0 0 0 0 0 0 0 0 0 0
40232 - 0 0 0 0 0 0 0 0 0 0 0 0
40233 - 0 0 0 0 0 0 0 0 0 0 0 0
40234 - 0 0 0 0 0 0 0 0 0 0 0 0
40235 - 0 0 0 0 0 0 0 0 0 0 0 0
40236 - 0 0 0 0 0 0 0 0 0 0 0 0
40237 - 0 0 0 0 0 0 0 0 0 0 0 0
40238 - 0 0 0 0 0 0 0 0 0 0 0 0
40239 - 0 0 0 0 0 0 0 0 0 0 0 0
40240 - 0 0 0 0 0 0 0 0 0 10 10 10
40241 - 30 30 30 78 78 78 46 46 46 22 22 22
40242 -137 92 6 210 162 10 239 182 13 238 190 10
40243 -238 202 15 241 208 19 246 215 20 246 215 20
40244 -241 208 19 203 166 17 185 133 11 210 150 10
40245 -216 158 10 210 150 10 102 78 10 2 2 6
40246 - 6 6 6 54 54 54 14 14 14 2 2 6
40247 - 2 2 6 62 62 62 74 74 74 30 30 30
40248 - 10 10 10 0 0 0 0 0 0 0 0 0
40249 - 0 0 0 0 0 0 0 0 0 0 0 0
40250 - 0 0 0 0 0 0 0 0 0 0 0 0
40251 - 0 0 0 0 0 0 0 0 0 0 0 0
40252 - 0 0 0 0 0 0 0 0 0 0 0 0
40253 - 0 0 0 0 0 0 0 0 0 0 0 0
40254 - 0 0 0 0 0 0 0 0 0 0 0 0
40255 - 0 0 0 0 0 0 0 0 0 0 0 0
40256 - 0 0 0 0 0 0 0 0 0 0 0 0
40257 - 0 0 0 0 0 0 0 0 0 0 0 0
40258 - 0 0 0 0 0 0 0 0 0 0 0 0
40259 - 0 0 0 0 0 0 0 0 0 0 0 0
40260 - 0 0 0 0 0 0 0 0 0 10 10 10
40261 - 34 34 34 78 78 78 50 50 50 6 6 6
40262 - 94 70 30 139 102 15 190 146 13 226 184 13
40263 -232 200 30 232 195 16 215 174 15 190 146 13
40264 -168 122 10 192 133 9 210 150 10 213 154 11
40265 -202 150 34 182 157 106 101 98 89 2 2 6
40266 - 2 2 6 78 78 78 116 116 116 58 58 58
40267 - 2 2 6 22 22 22 90 90 90 46 46 46
40268 - 18 18 18 6 6 6 0 0 0 0 0 0
40269 - 0 0 0 0 0 0 0 0 0 0 0 0
40270 - 0 0 0 0 0 0 0 0 0 0 0 0
40271 - 0 0 0 0 0 0 0 0 0 0 0 0
40272 - 0 0 0 0 0 0 0 0 0 0 0 0
40273 - 0 0 0 0 0 0 0 0 0 0 0 0
40274 - 0 0 0 0 0 0 0 0 0 0 0 0
40275 - 0 0 0 0 0 0 0 0 0 0 0 0
40276 - 0 0 0 0 0 0 0 0 0 0 0 0
40277 - 0 0 0 0 0 0 0 0 0 0 0 0
40278 - 0 0 0 0 0 0 0 0 0 0 0 0
40279 - 0 0 0 0 0 0 0 0 0 0 0 0
40280 - 0 0 0 0 0 0 0 0 0 10 10 10
40281 - 38 38 38 86 86 86 50 50 50 6 6 6
40282 -128 128 128 174 154 114 156 107 11 168 122 10
40283 -198 155 10 184 144 12 197 138 11 200 144 11
40284 -206 145 10 206 145 10 197 138 11 188 164 115
40285 -195 195 195 198 198 198 174 174 174 14 14 14
40286 - 2 2 6 22 22 22 116 116 116 116 116 116
40287 - 22 22 22 2 2 6 74 74 74 70 70 70
40288 - 30 30 30 10 10 10 0 0 0 0 0 0
40289 - 0 0 0 0 0 0 0 0 0 0 0 0
40290 - 0 0 0 0 0 0 0 0 0 0 0 0
40291 - 0 0 0 0 0 0 0 0 0 0 0 0
40292 - 0 0 0 0 0 0 0 0 0 0 0 0
40293 - 0 0 0 0 0 0 0 0 0 0 0 0
40294 - 0 0 0 0 0 0 0 0 0 0 0 0
40295 - 0 0 0 0 0 0 0 0 0 0 0 0
40296 - 0 0 0 0 0 0 0 0 0 0 0 0
40297 - 0 0 0 0 0 0 0 0 0 0 0 0
40298 - 0 0 0 0 0 0 0 0 0 0 0 0
40299 - 0 0 0 0 0 0 0 0 0 0 0 0
40300 - 0 0 0 0 0 0 6 6 6 18 18 18
40301 - 50 50 50 101 101 101 26 26 26 10 10 10
40302 -138 138 138 190 190 190 174 154 114 156 107 11
40303 -197 138 11 200 144 11 197 138 11 192 133 9
40304 -180 123 7 190 142 34 190 178 144 187 187 187
40305 -202 202 202 221 221 221 214 214 214 66 66 66
40306 - 2 2 6 2 2 6 50 50 50 62 62 62
40307 - 6 6 6 2 2 6 10 10 10 90 90 90
40308 - 50 50 50 18 18 18 6 6 6 0 0 0
40309 - 0 0 0 0 0 0 0 0 0 0 0 0
40310 - 0 0 0 0 0 0 0 0 0 0 0 0
40311 - 0 0 0 0 0 0 0 0 0 0 0 0
40312 - 0 0 0 0 0 0 0 0 0 0 0 0
40313 - 0 0 0 0 0 0 0 0 0 0 0 0
40314 - 0 0 0 0 0 0 0 0 0 0 0 0
40315 - 0 0 0 0 0 0 0 0 0 0 0 0
40316 - 0 0 0 0 0 0 0 0 0 0 0 0
40317 - 0 0 0 0 0 0 0 0 0 0 0 0
40318 - 0 0 0 0 0 0 0 0 0 0 0 0
40319 - 0 0 0 0 0 0 0 0 0 0 0 0
40320 - 0 0 0 0 0 0 10 10 10 34 34 34
40321 - 74 74 74 74 74 74 2 2 6 6 6 6
40322 -144 144 144 198 198 198 190 190 190 178 166 146
40323 -154 121 60 156 107 11 156 107 11 168 124 44
40324 -174 154 114 187 187 187 190 190 190 210 210 210
40325 -246 246 246 253 253 253 253 253 253 182 182 182
40326 - 6 6 6 2 2 6 2 2 6 2 2 6
40327 - 2 2 6 2 2 6 2 2 6 62 62 62
40328 - 74 74 74 34 34 34 14 14 14 0 0 0
40329 - 0 0 0 0 0 0 0 0 0 0 0 0
40330 - 0 0 0 0 0 0 0 0 0 0 0 0
40331 - 0 0 0 0 0 0 0 0 0 0 0 0
40332 - 0 0 0 0 0 0 0 0 0 0 0 0
40333 - 0 0 0 0 0 0 0 0 0 0 0 0
40334 - 0 0 0 0 0 0 0 0 0 0 0 0
40335 - 0 0 0 0 0 0 0 0 0 0 0 0
40336 - 0 0 0 0 0 0 0 0 0 0 0 0
40337 - 0 0 0 0 0 0 0 0 0 0 0 0
40338 - 0 0 0 0 0 0 0 0 0 0 0 0
40339 - 0 0 0 0 0 0 0 0 0 0 0 0
40340 - 0 0 0 10 10 10 22 22 22 54 54 54
40341 - 94 94 94 18 18 18 2 2 6 46 46 46
40342 -234 234 234 221 221 221 190 190 190 190 190 190
40343 -190 190 190 187 187 187 187 187 187 190 190 190
40344 -190 190 190 195 195 195 214 214 214 242 242 242
40345 -253 253 253 253 253 253 253 253 253 253 253 253
40346 - 82 82 82 2 2 6 2 2 6 2 2 6
40347 - 2 2 6 2 2 6 2 2 6 14 14 14
40348 - 86 86 86 54 54 54 22 22 22 6 6 6
40349 - 0 0 0 0 0 0 0 0 0 0 0 0
40350 - 0 0 0 0 0 0 0 0 0 0 0 0
40351 - 0 0 0 0 0 0 0 0 0 0 0 0
40352 - 0 0 0 0 0 0 0 0 0 0 0 0
40353 - 0 0 0 0 0 0 0 0 0 0 0 0
40354 - 0 0 0 0 0 0 0 0 0 0 0 0
40355 - 0 0 0 0 0 0 0 0 0 0 0 0
40356 - 0 0 0 0 0 0 0 0 0 0 0 0
40357 - 0 0 0 0 0 0 0 0 0 0 0 0
40358 - 0 0 0 0 0 0 0 0 0 0 0 0
40359 - 0 0 0 0 0 0 0 0 0 0 0 0
40360 - 6 6 6 18 18 18 46 46 46 90 90 90
40361 - 46 46 46 18 18 18 6 6 6 182 182 182
40362 -253 253 253 246 246 246 206 206 206 190 190 190
40363 -190 190 190 190 190 190 190 190 190 190 190 190
40364 -206 206 206 231 231 231 250 250 250 253 253 253
40365 -253 253 253 253 253 253 253 253 253 253 253 253
40366 -202 202 202 14 14 14 2 2 6 2 2 6
40367 - 2 2 6 2 2 6 2 2 6 2 2 6
40368 - 42 42 42 86 86 86 42 42 42 18 18 18
40369 - 6 6 6 0 0 0 0 0 0 0 0 0
40370 - 0 0 0 0 0 0 0 0 0 0 0 0
40371 - 0 0 0 0 0 0 0 0 0 0 0 0
40372 - 0 0 0 0 0 0 0 0 0 0 0 0
40373 - 0 0 0 0 0 0 0 0 0 0 0 0
40374 - 0 0 0 0 0 0 0 0 0 0 0 0
40375 - 0 0 0 0 0 0 0 0 0 0 0 0
40376 - 0 0 0 0 0 0 0 0 0 0 0 0
40377 - 0 0 0 0 0 0 0 0 0 0 0 0
40378 - 0 0 0 0 0 0 0 0 0 0 0 0
40379 - 0 0 0 0 0 0 0 0 0 6 6 6
40380 - 14 14 14 38 38 38 74 74 74 66 66 66
40381 - 2 2 6 6 6 6 90 90 90 250 250 250
40382 -253 253 253 253 253 253 238 238 238 198 198 198
40383 -190 190 190 190 190 190 195 195 195 221 221 221
40384 -246 246 246 253 253 253 253 253 253 253 253 253
40385 -253 253 253 253 253 253 253 253 253 253 253 253
40386 -253 253 253 82 82 82 2 2 6 2 2 6
40387 - 2 2 6 2 2 6 2 2 6 2 2 6
40388 - 2 2 6 78 78 78 70 70 70 34 34 34
40389 - 14 14 14 6 6 6 0 0 0 0 0 0
40390 - 0 0 0 0 0 0 0 0 0 0 0 0
40391 - 0 0 0 0 0 0 0 0 0 0 0 0
40392 - 0 0 0 0 0 0 0 0 0 0 0 0
40393 - 0 0 0 0 0 0 0 0 0 0 0 0
40394 - 0 0 0 0 0 0 0 0 0 0 0 0
40395 - 0 0 0 0 0 0 0 0 0 0 0 0
40396 - 0 0 0 0 0 0 0 0 0 0 0 0
40397 - 0 0 0 0 0 0 0 0 0 0 0 0
40398 - 0 0 0 0 0 0 0 0 0 0 0 0
40399 - 0 0 0 0 0 0 0 0 0 14 14 14
40400 - 34 34 34 66 66 66 78 78 78 6 6 6
40401 - 2 2 6 18 18 18 218 218 218 253 253 253
40402 -253 253 253 253 253 253 253 253 253 246 246 246
40403 -226 226 226 231 231 231 246 246 246 253 253 253
40404 -253 253 253 253 253 253 253 253 253 253 253 253
40405 -253 253 253 253 253 253 253 253 253 253 253 253
40406 -253 253 253 178 178 178 2 2 6 2 2 6
40407 - 2 2 6 2 2 6 2 2 6 2 2 6
40408 - 2 2 6 18 18 18 90 90 90 62 62 62
40409 - 30 30 30 10 10 10 0 0 0 0 0 0
40410 - 0 0 0 0 0 0 0 0 0 0 0 0
40411 - 0 0 0 0 0 0 0 0 0 0 0 0
40412 - 0 0 0 0 0 0 0 0 0 0 0 0
40413 - 0 0 0 0 0 0 0 0 0 0 0 0
40414 - 0 0 0 0 0 0 0 0 0 0 0 0
40415 - 0 0 0 0 0 0 0 0 0 0 0 0
40416 - 0 0 0 0 0 0 0 0 0 0 0 0
40417 - 0 0 0 0 0 0 0 0 0 0 0 0
40418 - 0 0 0 0 0 0 0 0 0 0 0 0
40419 - 0 0 0 0 0 0 10 10 10 26 26 26
40420 - 58 58 58 90 90 90 18 18 18 2 2 6
40421 - 2 2 6 110 110 110 253 253 253 253 253 253
40422 -253 253 253 253 253 253 253 253 253 253 253 253
40423 -250 250 250 253 253 253 253 253 253 253 253 253
40424 -253 253 253 253 253 253 253 253 253 253 253 253
40425 -253 253 253 253 253 253 253 253 253 253 253 253
40426 -253 253 253 231 231 231 18 18 18 2 2 6
40427 - 2 2 6 2 2 6 2 2 6 2 2 6
40428 - 2 2 6 2 2 6 18 18 18 94 94 94
40429 - 54 54 54 26 26 26 10 10 10 0 0 0
40430 - 0 0 0 0 0 0 0 0 0 0 0 0
40431 - 0 0 0 0 0 0 0 0 0 0 0 0
40432 - 0 0 0 0 0 0 0 0 0 0 0 0
40433 - 0 0 0 0 0 0 0 0 0 0 0 0
40434 - 0 0 0 0 0 0 0 0 0 0 0 0
40435 - 0 0 0 0 0 0 0 0 0 0 0 0
40436 - 0 0 0 0 0 0 0 0 0 0 0 0
40437 - 0 0 0 0 0 0 0 0 0 0 0 0
40438 - 0 0 0 0 0 0 0 0 0 0 0 0
40439 - 0 0 0 6 6 6 22 22 22 50 50 50
40440 - 90 90 90 26 26 26 2 2 6 2 2 6
40441 - 14 14 14 195 195 195 250 250 250 253 253 253
40442 -253 253 253 253 253 253 253 253 253 253 253 253
40443 -253 253 253 253 253 253 253 253 253 253 253 253
40444 -253 253 253 253 253 253 253 253 253 253 253 253
40445 -253 253 253 253 253 253 253 253 253 253 253 253
40446 -250 250 250 242 242 242 54 54 54 2 2 6
40447 - 2 2 6 2 2 6 2 2 6 2 2 6
40448 - 2 2 6 2 2 6 2 2 6 38 38 38
40449 - 86 86 86 50 50 50 22 22 22 6 6 6
40450 - 0 0 0 0 0 0 0 0 0 0 0 0
40451 - 0 0 0 0 0 0 0 0 0 0 0 0
40452 - 0 0 0 0 0 0 0 0 0 0 0 0
40453 - 0 0 0 0 0 0 0 0 0 0 0 0
40454 - 0 0 0 0 0 0 0 0 0 0 0 0
40455 - 0 0 0 0 0 0 0 0 0 0 0 0
40456 - 0 0 0 0 0 0 0 0 0 0 0 0
40457 - 0 0 0 0 0 0 0 0 0 0 0 0
40458 - 0 0 0 0 0 0 0 0 0 0 0 0
40459 - 6 6 6 14 14 14 38 38 38 82 82 82
40460 - 34 34 34 2 2 6 2 2 6 2 2 6
40461 - 42 42 42 195 195 195 246 246 246 253 253 253
40462 -253 253 253 253 253 253 253 253 253 250 250 250
40463 -242 242 242 242 242 242 250 250 250 253 253 253
40464 -253 253 253 253 253 253 253 253 253 253 253 253
40465 -253 253 253 250 250 250 246 246 246 238 238 238
40466 -226 226 226 231 231 231 101 101 101 6 6 6
40467 - 2 2 6 2 2 6 2 2 6 2 2 6
40468 - 2 2 6 2 2 6 2 2 6 2 2 6
40469 - 38 38 38 82 82 82 42 42 42 14 14 14
40470 - 6 6 6 0 0 0 0 0 0 0 0 0
40471 - 0 0 0 0 0 0 0 0 0 0 0 0
40472 - 0 0 0 0 0 0 0 0 0 0 0 0
40473 - 0 0 0 0 0 0 0 0 0 0 0 0
40474 - 0 0 0 0 0 0 0 0 0 0 0 0
40475 - 0 0 0 0 0 0 0 0 0 0 0 0
40476 - 0 0 0 0 0 0 0 0 0 0 0 0
40477 - 0 0 0 0 0 0 0 0 0 0 0 0
40478 - 0 0 0 0 0 0 0 0 0 0 0 0
40479 - 10 10 10 26 26 26 62 62 62 66 66 66
40480 - 2 2 6 2 2 6 2 2 6 6 6 6
40481 - 70 70 70 170 170 170 206 206 206 234 234 234
40482 -246 246 246 250 250 250 250 250 250 238 238 238
40483 -226 226 226 231 231 231 238 238 238 250 250 250
40484 -250 250 250 250 250 250 246 246 246 231 231 231
40485 -214 214 214 206 206 206 202 202 202 202 202 202
40486 -198 198 198 202 202 202 182 182 182 18 18 18
40487 - 2 2 6 2 2 6 2 2 6 2 2 6
40488 - 2 2 6 2 2 6 2 2 6 2 2 6
40489 - 2 2 6 62 62 62 66 66 66 30 30 30
40490 - 10 10 10 0 0 0 0 0 0 0 0 0
40491 - 0 0 0 0 0 0 0 0 0 0 0 0
40492 - 0 0 0 0 0 0 0 0 0 0 0 0
40493 - 0 0 0 0 0 0 0 0 0 0 0 0
40494 - 0 0 0 0 0 0 0 0 0 0 0 0
40495 - 0 0 0 0 0 0 0 0 0 0 0 0
40496 - 0 0 0 0 0 0 0 0 0 0 0 0
40497 - 0 0 0 0 0 0 0 0 0 0 0 0
40498 - 0 0 0 0 0 0 0 0 0 0 0 0
40499 - 14 14 14 42 42 42 82 82 82 18 18 18
40500 - 2 2 6 2 2 6 2 2 6 10 10 10
40501 - 94 94 94 182 182 182 218 218 218 242 242 242
40502 -250 250 250 253 253 253 253 253 253 250 250 250
40503 -234 234 234 253 253 253 253 253 253 253 253 253
40504 -253 253 253 253 253 253 253 253 253 246 246 246
40505 -238 238 238 226 226 226 210 210 210 202 202 202
40506 -195 195 195 195 195 195 210 210 210 158 158 158
40507 - 6 6 6 14 14 14 50 50 50 14 14 14
40508 - 2 2 6 2 2 6 2 2 6 2 2 6
40509 - 2 2 6 6 6 6 86 86 86 46 46 46
40510 - 18 18 18 6 6 6 0 0 0 0 0 0
40511 - 0 0 0 0 0 0 0 0 0 0 0 0
40512 - 0 0 0 0 0 0 0 0 0 0 0 0
40513 - 0 0 0 0 0 0 0 0 0 0 0 0
40514 - 0 0 0 0 0 0 0 0 0 0 0 0
40515 - 0 0 0 0 0 0 0 0 0 0 0 0
40516 - 0 0 0 0 0 0 0 0 0 0 0 0
40517 - 0 0 0 0 0 0 0 0 0 0 0 0
40518 - 0 0 0 0 0 0 0 0 0 6 6 6
40519 - 22 22 22 54 54 54 70 70 70 2 2 6
40520 - 2 2 6 10 10 10 2 2 6 22 22 22
40521 -166 166 166 231 231 231 250 250 250 253 253 253
40522 -253 253 253 253 253 253 253 253 253 250 250 250
40523 -242 242 242 253 253 253 253 253 253 253 253 253
40524 -253 253 253 253 253 253 253 253 253 253 253 253
40525 -253 253 253 253 253 253 253 253 253 246 246 246
40526 -231 231 231 206 206 206 198 198 198 226 226 226
40527 - 94 94 94 2 2 6 6 6 6 38 38 38
40528 - 30 30 30 2 2 6 2 2 6 2 2 6
40529 - 2 2 6 2 2 6 62 62 62 66 66 66
40530 - 26 26 26 10 10 10 0 0 0 0 0 0
40531 - 0 0 0 0 0 0 0 0 0 0 0 0
40532 - 0 0 0 0 0 0 0 0 0 0 0 0
40533 - 0 0 0 0 0 0 0 0 0 0 0 0
40534 - 0 0 0 0 0 0 0 0 0 0 0 0
40535 - 0 0 0 0 0 0 0 0 0 0 0 0
40536 - 0 0 0 0 0 0 0 0 0 0 0 0
40537 - 0 0 0 0 0 0 0 0 0 0 0 0
40538 - 0 0 0 0 0 0 0 0 0 10 10 10
40539 - 30 30 30 74 74 74 50 50 50 2 2 6
40540 - 26 26 26 26 26 26 2 2 6 106 106 106
40541 -238 238 238 253 253 253 253 253 253 253 253 253
40542 -253 253 253 253 253 253 253 253 253 253 253 253
40543 -253 253 253 253 253 253 253 253 253 253 253 253
40544 -253 253 253 253 253 253 253 253 253 253 253 253
40545 -253 253 253 253 253 253 253 253 253 253 253 253
40546 -253 253 253 246 246 246 218 218 218 202 202 202
40547 -210 210 210 14 14 14 2 2 6 2 2 6
40548 - 30 30 30 22 22 22 2 2 6 2 2 6
40549 - 2 2 6 2 2 6 18 18 18 86 86 86
40550 - 42 42 42 14 14 14 0 0 0 0 0 0
40551 - 0 0 0 0 0 0 0 0 0 0 0 0
40552 - 0 0 0 0 0 0 0 0 0 0 0 0
40553 - 0 0 0 0 0 0 0 0 0 0 0 0
40554 - 0 0 0 0 0 0 0 0 0 0 0 0
40555 - 0 0 0 0 0 0 0 0 0 0 0 0
40556 - 0 0 0 0 0 0 0 0 0 0 0 0
40557 - 0 0 0 0 0 0 0 0 0 0 0 0
40558 - 0 0 0 0 0 0 0 0 0 14 14 14
40559 - 42 42 42 90 90 90 22 22 22 2 2 6
40560 - 42 42 42 2 2 6 18 18 18 218 218 218
40561 -253 253 253 253 253 253 253 253 253 253 253 253
40562 -253 253 253 253 253 253 253 253 253 253 253 253
40563 -253 253 253 253 253 253 253 253 253 253 253 253
40564 -253 253 253 253 253 253 253 253 253 253 253 253
40565 -253 253 253 253 253 253 253 253 253 253 253 253
40566 -253 253 253 253 253 253 250 250 250 221 221 221
40567 -218 218 218 101 101 101 2 2 6 14 14 14
40568 - 18 18 18 38 38 38 10 10 10 2 2 6
40569 - 2 2 6 2 2 6 2 2 6 78 78 78
40570 - 58 58 58 22 22 22 6 6 6 0 0 0
40571 - 0 0 0 0 0 0 0 0 0 0 0 0
40572 - 0 0 0 0 0 0 0 0 0 0 0 0
40573 - 0 0 0 0 0 0 0 0 0 0 0 0
40574 - 0 0 0 0 0 0 0 0 0 0 0 0
40575 - 0 0 0 0 0 0 0 0 0 0 0 0
40576 - 0 0 0 0 0 0 0 0 0 0 0 0
40577 - 0 0 0 0 0 0 0 0 0 0 0 0
40578 - 0 0 0 0 0 0 6 6 6 18 18 18
40579 - 54 54 54 82 82 82 2 2 6 26 26 26
40580 - 22 22 22 2 2 6 123 123 123 253 253 253
40581 -253 253 253 253 253 253 253 253 253 253 253 253
40582 -253 253 253 253 253 253 253 253 253 253 253 253
40583 -253 253 253 253 253 253 253 253 253 253 253 253
40584 -253 253 253 253 253 253 253 253 253 253 253 253
40585 -253 253 253 253 253 253 253 253 253 253 253 253
40586 -253 253 253 253 253 253 253 253 253 250 250 250
40587 -238 238 238 198 198 198 6 6 6 38 38 38
40588 - 58 58 58 26 26 26 38 38 38 2 2 6
40589 - 2 2 6 2 2 6 2 2 6 46 46 46
40590 - 78 78 78 30 30 30 10 10 10 0 0 0
40591 - 0 0 0 0 0 0 0 0 0 0 0 0
40592 - 0 0 0 0 0 0 0 0 0 0 0 0
40593 - 0 0 0 0 0 0 0 0 0 0 0 0
40594 - 0 0 0 0 0 0 0 0 0 0 0 0
40595 - 0 0 0 0 0 0 0 0 0 0 0 0
40596 - 0 0 0 0 0 0 0 0 0 0 0 0
40597 - 0 0 0 0 0 0 0 0 0 0 0 0
40598 - 0 0 0 0 0 0 10 10 10 30 30 30
40599 - 74 74 74 58 58 58 2 2 6 42 42 42
40600 - 2 2 6 22 22 22 231 231 231 253 253 253
40601 -253 253 253 253 253 253 253 253 253 253 253 253
40602 -253 253 253 253 253 253 253 253 253 250 250 250
40603 -253 253 253 253 253 253 253 253 253 253 253 253
40604 -253 253 253 253 253 253 253 253 253 253 253 253
40605 -253 253 253 253 253 253 253 253 253 253 253 253
40606 -253 253 253 253 253 253 253 253 253 253 253 253
40607 -253 253 253 246 246 246 46 46 46 38 38 38
40608 - 42 42 42 14 14 14 38 38 38 14 14 14
40609 - 2 2 6 2 2 6 2 2 6 6 6 6
40610 - 86 86 86 46 46 46 14 14 14 0 0 0
40611 - 0 0 0 0 0 0 0 0 0 0 0 0
40612 - 0 0 0 0 0 0 0 0 0 0 0 0
40613 - 0 0 0 0 0 0 0 0 0 0 0 0
40614 - 0 0 0 0 0 0 0 0 0 0 0 0
40615 - 0 0 0 0 0 0 0 0 0 0 0 0
40616 - 0 0 0 0 0 0 0 0 0 0 0 0
40617 - 0 0 0 0 0 0 0 0 0 0 0 0
40618 - 0 0 0 6 6 6 14 14 14 42 42 42
40619 - 90 90 90 18 18 18 18 18 18 26 26 26
40620 - 2 2 6 116 116 116 253 253 253 253 253 253
40621 -253 253 253 253 253 253 253 253 253 253 253 253
40622 -253 253 253 253 253 253 250 250 250 238 238 238
40623 -253 253 253 253 253 253 253 253 253 253 253 253
40624 -253 253 253 253 253 253 253 253 253 253 253 253
40625 -253 253 253 253 253 253 253 253 253 253 253 253
40626 -253 253 253 253 253 253 253 253 253 253 253 253
40627 -253 253 253 253 253 253 94 94 94 6 6 6
40628 - 2 2 6 2 2 6 10 10 10 34 34 34
40629 - 2 2 6 2 2 6 2 2 6 2 2 6
40630 - 74 74 74 58 58 58 22 22 22 6 6 6
40631 - 0 0 0 0 0 0 0 0 0 0 0 0
40632 - 0 0 0 0 0 0 0 0 0 0 0 0
40633 - 0 0 0 0 0 0 0 0 0 0 0 0
40634 - 0 0 0 0 0 0 0 0 0 0 0 0
40635 - 0 0 0 0 0 0 0 0 0 0 0 0
40636 - 0 0 0 0 0 0 0 0 0 0 0 0
40637 - 0 0 0 0 0 0 0 0 0 0 0 0
40638 - 0 0 0 10 10 10 26 26 26 66 66 66
40639 - 82 82 82 2 2 6 38 38 38 6 6 6
40640 - 14 14 14 210 210 210 253 253 253 253 253 253
40641 -253 253 253 253 253 253 253 253 253 253 253 253
40642 -253 253 253 253 253 253 246 246 246 242 242 242
40643 -253 253 253 253 253 253 253 253 253 253 253 253
40644 -253 253 253 253 253 253 253 253 253 253 253 253
40645 -253 253 253 253 253 253 253 253 253 253 253 253
40646 -253 253 253 253 253 253 253 253 253 253 253 253
40647 -253 253 253 253 253 253 144 144 144 2 2 6
40648 - 2 2 6 2 2 6 2 2 6 46 46 46
40649 - 2 2 6 2 2 6 2 2 6 2 2 6
40650 - 42 42 42 74 74 74 30 30 30 10 10 10
40651 - 0 0 0 0 0 0 0 0 0 0 0 0
40652 - 0 0 0 0 0 0 0 0 0 0 0 0
40653 - 0 0 0 0 0 0 0 0 0 0 0 0
40654 - 0 0 0 0 0 0 0 0 0 0 0 0
40655 - 0 0 0 0 0 0 0 0 0 0 0 0
40656 - 0 0 0 0 0 0 0 0 0 0 0 0
40657 - 0 0 0 0 0 0 0 0 0 0 0 0
40658 - 6 6 6 14 14 14 42 42 42 90 90 90
40659 - 26 26 26 6 6 6 42 42 42 2 2 6
40660 - 74 74 74 250 250 250 253 253 253 253 253 253
40661 -253 253 253 253 253 253 253 253 253 253 253 253
40662 -253 253 253 253 253 253 242 242 242 242 242 242
40663 -253 253 253 253 253 253 253 253 253 253 253 253
40664 -253 253 253 253 253 253 253 253 253 253 253 253
40665 -253 253 253 253 253 253 253 253 253 253 253 253
40666 -253 253 253 253 253 253 253 253 253 253 253 253
40667 -253 253 253 253 253 253 182 182 182 2 2 6
40668 - 2 2 6 2 2 6 2 2 6 46 46 46
40669 - 2 2 6 2 2 6 2 2 6 2 2 6
40670 - 10 10 10 86 86 86 38 38 38 10 10 10
40671 - 0 0 0 0 0 0 0 0 0 0 0 0
40672 - 0 0 0 0 0 0 0 0 0 0 0 0
40673 - 0 0 0 0 0 0 0 0 0 0 0 0
40674 - 0 0 0 0 0 0 0 0 0 0 0 0
40675 - 0 0 0 0 0 0 0 0 0 0 0 0
40676 - 0 0 0 0 0 0 0 0 0 0 0 0
40677 - 0 0 0 0 0 0 0 0 0 0 0 0
40678 - 10 10 10 26 26 26 66 66 66 82 82 82
40679 - 2 2 6 22 22 22 18 18 18 2 2 6
40680 -149 149 149 253 253 253 253 253 253 253 253 253
40681 -253 253 253 253 253 253 253 253 253 253 253 253
40682 -253 253 253 253 253 253 234 234 234 242 242 242
40683 -253 253 253 253 253 253 253 253 253 253 253 253
40684 -253 253 253 253 253 253 253 253 253 253 253 253
40685 -253 253 253 253 253 253 253 253 253 253 253 253
40686 -253 253 253 253 253 253 253 253 253 253 253 253
40687 -253 253 253 253 253 253 206 206 206 2 2 6
40688 - 2 2 6 2 2 6 2 2 6 38 38 38
40689 - 2 2 6 2 2 6 2 2 6 2 2 6
40690 - 6 6 6 86 86 86 46 46 46 14 14 14
40691 - 0 0 0 0 0 0 0 0 0 0 0 0
40692 - 0 0 0 0 0 0 0 0 0 0 0 0
40693 - 0 0 0 0 0 0 0 0 0 0 0 0
40694 - 0 0 0 0 0 0 0 0 0 0 0 0
40695 - 0 0 0 0 0 0 0 0 0 0 0 0
40696 - 0 0 0 0 0 0 0 0 0 0 0 0
40697 - 0 0 0 0 0 0 0 0 0 6 6 6
40698 - 18 18 18 46 46 46 86 86 86 18 18 18
40699 - 2 2 6 34 34 34 10 10 10 6 6 6
40700 -210 210 210 253 253 253 253 253 253 253 253 253
40701 -253 253 253 253 253 253 253 253 253 253 253 253
40702 -253 253 253 253 253 253 234 234 234 242 242 242
40703 -253 253 253 253 253 253 253 253 253 253 253 253
40704 -253 253 253 253 253 253 253 253 253 253 253 253
40705 -253 253 253 253 253 253 253 253 253 253 253 253
40706 -253 253 253 253 253 253 253 253 253 253 253 253
40707 -253 253 253 253 253 253 221 221 221 6 6 6
40708 - 2 2 6 2 2 6 6 6 6 30 30 30
40709 - 2 2 6 2 2 6 2 2 6 2 2 6
40710 - 2 2 6 82 82 82 54 54 54 18 18 18
40711 - 6 6 6 0 0 0 0 0 0 0 0 0
40712 - 0 0 0 0 0 0 0 0 0 0 0 0
40713 - 0 0 0 0 0 0 0 0 0 0 0 0
40714 - 0 0 0 0 0 0 0 0 0 0 0 0
40715 - 0 0 0 0 0 0 0 0 0 0 0 0
40716 - 0 0 0 0 0 0 0 0 0 0 0 0
40717 - 0 0 0 0 0 0 0 0 0 10 10 10
40718 - 26 26 26 66 66 66 62 62 62 2 2 6
40719 - 2 2 6 38 38 38 10 10 10 26 26 26
40720 -238 238 238 253 253 253 253 253 253 253 253 253
40721 -253 253 253 253 253 253 253 253 253 253 253 253
40722 -253 253 253 253 253 253 231 231 231 238 238 238
40723 -253 253 253 253 253 253 253 253 253 253 253 253
40724 -253 253 253 253 253 253 253 253 253 253 253 253
40725 -253 253 253 253 253 253 253 253 253 253 253 253
40726 -253 253 253 253 253 253 253 253 253 253 253 253
40727 -253 253 253 253 253 253 231 231 231 6 6 6
40728 - 2 2 6 2 2 6 10 10 10 30 30 30
40729 - 2 2 6 2 2 6 2 2 6 2 2 6
40730 - 2 2 6 66 66 66 58 58 58 22 22 22
40731 - 6 6 6 0 0 0 0 0 0 0 0 0
40732 - 0 0 0 0 0 0 0 0 0 0 0 0
40733 - 0 0 0 0 0 0 0 0 0 0 0 0
40734 - 0 0 0 0 0 0 0 0 0 0 0 0
40735 - 0 0 0 0 0 0 0 0 0 0 0 0
40736 - 0 0 0 0 0 0 0 0 0 0 0 0
40737 - 0 0 0 0 0 0 0 0 0 10 10 10
40738 - 38 38 38 78 78 78 6 6 6 2 2 6
40739 - 2 2 6 46 46 46 14 14 14 42 42 42
40740 -246 246 246 253 253 253 253 253 253 253 253 253
40741 -253 253 253 253 253 253 253 253 253 253 253 253
40742 -253 253 253 253 253 253 231 231 231 242 242 242
40743 -253 253 253 253 253 253 253 253 253 253 253 253
40744 -253 253 253 253 253 253 253 253 253 253 253 253
40745 -253 253 253 253 253 253 253 253 253 253 253 253
40746 -253 253 253 253 253 253 253 253 253 253 253 253
40747 -253 253 253 253 253 253 234 234 234 10 10 10
40748 - 2 2 6 2 2 6 22 22 22 14 14 14
40749 - 2 2 6 2 2 6 2 2 6 2 2 6
40750 - 2 2 6 66 66 66 62 62 62 22 22 22
40751 - 6 6 6 0 0 0 0 0 0 0 0 0
40752 - 0 0 0 0 0 0 0 0 0 0 0 0
40753 - 0 0 0 0 0 0 0 0 0 0 0 0
40754 - 0 0 0 0 0 0 0 0 0 0 0 0
40755 - 0 0 0 0 0 0 0 0 0 0 0 0
40756 - 0 0 0 0 0 0 0 0 0 0 0 0
40757 - 0 0 0 0 0 0 6 6 6 18 18 18
40758 - 50 50 50 74 74 74 2 2 6 2 2 6
40759 - 14 14 14 70 70 70 34 34 34 62 62 62
40760 -250 250 250 253 253 253 253 253 253 253 253 253
40761 -253 253 253 253 253 253 253 253 253 253 253 253
40762 -253 253 253 253 253 253 231 231 231 246 246 246
40763 -253 253 253 253 253 253 253 253 253 253 253 253
40764 -253 253 253 253 253 253 253 253 253 253 253 253
40765 -253 253 253 253 253 253 253 253 253 253 253 253
40766 -253 253 253 253 253 253 253 253 253 253 253 253
40767 -253 253 253 253 253 253 234 234 234 14 14 14
40768 - 2 2 6 2 2 6 30 30 30 2 2 6
40769 - 2 2 6 2 2 6 2 2 6 2 2 6
40770 - 2 2 6 66 66 66 62 62 62 22 22 22
40771 - 6 6 6 0 0 0 0 0 0 0 0 0
40772 - 0 0 0 0 0 0 0 0 0 0 0 0
40773 - 0 0 0 0 0 0 0 0 0 0 0 0
40774 - 0 0 0 0 0 0 0 0 0 0 0 0
40775 - 0 0 0 0 0 0 0 0 0 0 0 0
40776 - 0 0 0 0 0 0 0 0 0 0 0 0
40777 - 0 0 0 0 0 0 6 6 6 18 18 18
40778 - 54 54 54 62 62 62 2 2 6 2 2 6
40779 - 2 2 6 30 30 30 46 46 46 70 70 70
40780 -250 250 250 253 253 253 253 253 253 253 253 253
40781 -253 253 253 253 253 253 253 253 253 253 253 253
40782 -253 253 253 253 253 253 231 231 231 246 246 246
40783 -253 253 253 253 253 253 253 253 253 253 253 253
40784 -253 253 253 253 253 253 253 253 253 253 253 253
40785 -253 253 253 253 253 253 253 253 253 253 253 253
40786 -253 253 253 253 253 253 253 253 253 253 253 253
40787 -253 253 253 253 253 253 226 226 226 10 10 10
40788 - 2 2 6 6 6 6 30 30 30 2 2 6
40789 - 2 2 6 2 2 6 2 2 6 2 2 6
40790 - 2 2 6 66 66 66 58 58 58 22 22 22
40791 - 6 6 6 0 0 0 0 0 0 0 0 0
40792 - 0 0 0 0 0 0 0 0 0 0 0 0
40793 - 0 0 0 0 0 0 0 0 0 0 0 0
40794 - 0 0 0 0 0 0 0 0 0 0 0 0
40795 - 0 0 0 0 0 0 0 0 0 0 0 0
40796 - 0 0 0 0 0 0 0 0 0 0 0 0
40797 - 0 0 0 0 0 0 6 6 6 22 22 22
40798 - 58 58 58 62 62 62 2 2 6 2 2 6
40799 - 2 2 6 2 2 6 30 30 30 78 78 78
40800 -250 250 250 253 253 253 253 253 253 253 253 253
40801 -253 253 253 253 253 253 253 253 253 253 253 253
40802 -253 253 253 253 253 253 231 231 231 246 246 246
40803 -253 253 253 253 253 253 253 253 253 253 253 253
40804 -253 253 253 253 253 253 253 253 253 253 253 253
40805 -253 253 253 253 253 253 253 253 253 253 253 253
40806 -253 253 253 253 253 253 253 253 253 253 253 253
40807 -253 253 253 253 253 253 206 206 206 2 2 6
40808 - 22 22 22 34 34 34 18 14 6 22 22 22
40809 - 26 26 26 18 18 18 6 6 6 2 2 6
40810 - 2 2 6 82 82 82 54 54 54 18 18 18
40811 - 6 6 6 0 0 0 0 0 0 0 0 0
40812 - 0 0 0 0 0 0 0 0 0 0 0 0
40813 - 0 0 0 0 0 0 0 0 0 0 0 0
40814 - 0 0 0 0 0 0 0 0 0 0 0 0
40815 - 0 0 0 0 0 0 0 0 0 0 0 0
40816 - 0 0 0 0 0 0 0 0 0 0 0 0
40817 - 0 0 0 0 0 0 6 6 6 26 26 26
40818 - 62 62 62 106 106 106 74 54 14 185 133 11
40819 -210 162 10 121 92 8 6 6 6 62 62 62
40820 -238 238 238 253 253 253 253 253 253 253 253 253
40821 -253 253 253 253 253 253 253 253 253 253 253 253
40822 -253 253 253 253 253 253 231 231 231 246 246 246
40823 -253 253 253 253 253 253 253 253 253 253 253 253
40824 -253 253 253 253 253 253 253 253 253 253 253 253
40825 -253 253 253 253 253 253 253 253 253 253 253 253
40826 -253 253 253 253 253 253 253 253 253 253 253 253
40827 -253 253 253 253 253 253 158 158 158 18 18 18
40828 - 14 14 14 2 2 6 2 2 6 2 2 6
40829 - 6 6 6 18 18 18 66 66 66 38 38 38
40830 - 6 6 6 94 94 94 50 50 50 18 18 18
40831 - 6 6 6 0 0 0 0 0 0 0 0 0
40832 - 0 0 0 0 0 0 0 0 0 0 0 0
40833 - 0 0 0 0 0 0 0 0 0 0 0 0
40834 - 0 0 0 0 0 0 0 0 0 0 0 0
40835 - 0 0 0 0 0 0 0 0 0 0 0 0
40836 - 0 0 0 0 0 0 0 0 0 6 6 6
40837 - 10 10 10 10 10 10 18 18 18 38 38 38
40838 - 78 78 78 142 134 106 216 158 10 242 186 14
40839 -246 190 14 246 190 14 156 118 10 10 10 10
40840 - 90 90 90 238 238 238 253 253 253 253 253 253
40841 -253 253 253 253 253 253 253 253 253 253 253 253
40842 -253 253 253 253 253 253 231 231 231 250 250 250
40843 -253 253 253 253 253 253 253 253 253 253 253 253
40844 -253 253 253 253 253 253 253 253 253 253 253 253
40845 -253 253 253 253 253 253 253 253 253 253 253 253
40846 -253 253 253 253 253 253 253 253 253 246 230 190
40847 -238 204 91 238 204 91 181 142 44 37 26 9
40848 - 2 2 6 2 2 6 2 2 6 2 2 6
40849 - 2 2 6 2 2 6 38 38 38 46 46 46
40850 - 26 26 26 106 106 106 54 54 54 18 18 18
40851 - 6 6 6 0 0 0 0 0 0 0 0 0
40852 - 0 0 0 0 0 0 0 0 0 0 0 0
40853 - 0 0 0 0 0 0 0 0 0 0 0 0
40854 - 0 0 0 0 0 0 0 0 0 0 0 0
40855 - 0 0 0 0 0 0 0 0 0 0 0 0
40856 - 0 0 0 6 6 6 14 14 14 22 22 22
40857 - 30 30 30 38 38 38 50 50 50 70 70 70
40858 -106 106 106 190 142 34 226 170 11 242 186 14
40859 -246 190 14 246 190 14 246 190 14 154 114 10
40860 - 6 6 6 74 74 74 226 226 226 253 253 253
40861 -253 253 253 253 253 253 253 253 253 253 253 253
40862 -253 253 253 253 253 253 231 231 231 250 250 250
40863 -253 253 253 253 253 253 253 253 253 253 253 253
40864 -253 253 253 253 253 253 253 253 253 253 253 253
40865 -253 253 253 253 253 253 253 253 253 253 253 253
40866 -253 253 253 253 253 253 253 253 253 228 184 62
40867 -241 196 14 241 208 19 232 195 16 38 30 10
40868 - 2 2 6 2 2 6 2 2 6 2 2 6
40869 - 2 2 6 6 6 6 30 30 30 26 26 26
40870 -203 166 17 154 142 90 66 66 66 26 26 26
40871 - 6 6 6 0 0 0 0 0 0 0 0 0
40872 - 0 0 0 0 0 0 0 0 0 0 0 0
40873 - 0 0 0 0 0 0 0 0 0 0 0 0
40874 - 0 0 0 0 0 0 0 0 0 0 0 0
40875 - 0 0 0 0 0 0 0 0 0 0 0 0
40876 - 6 6 6 18 18 18 38 38 38 58 58 58
40877 - 78 78 78 86 86 86 101 101 101 123 123 123
40878 -175 146 61 210 150 10 234 174 13 246 186 14
40879 -246 190 14 246 190 14 246 190 14 238 190 10
40880 -102 78 10 2 2 6 46 46 46 198 198 198
40881 -253 253 253 253 253 253 253 253 253 253 253 253
40882 -253 253 253 253 253 253 234 234 234 242 242 242
40883 -253 253 253 253 253 253 253 253 253 253 253 253
40884 -253 253 253 253 253 253 253 253 253 253 253 253
40885 -253 253 253 253 253 253 253 253 253 253 253 253
40886 -253 253 253 253 253 253 253 253 253 224 178 62
40887 -242 186 14 241 196 14 210 166 10 22 18 6
40888 - 2 2 6 2 2 6 2 2 6 2 2 6
40889 - 2 2 6 2 2 6 6 6 6 121 92 8
40890 -238 202 15 232 195 16 82 82 82 34 34 34
40891 - 10 10 10 0 0 0 0 0 0 0 0 0
40892 - 0 0 0 0 0 0 0 0 0 0 0 0
40893 - 0 0 0 0 0 0 0 0 0 0 0 0
40894 - 0 0 0 0 0 0 0 0 0 0 0 0
40895 - 0 0 0 0 0 0 0 0 0 0 0 0
40896 - 14 14 14 38 38 38 70 70 70 154 122 46
40897 -190 142 34 200 144 11 197 138 11 197 138 11
40898 -213 154 11 226 170 11 242 186 14 246 190 14
40899 -246 190 14 246 190 14 246 190 14 246 190 14
40900 -225 175 15 46 32 6 2 2 6 22 22 22
40901 -158 158 158 250 250 250 253 253 253 253 253 253
40902 -253 253 253 253 253 253 253 253 253 253 253 253
40903 -253 253 253 253 253 253 253 253 253 253 253 253
40904 -253 253 253 253 253 253 253 253 253 253 253 253
40905 -253 253 253 253 253 253 253 253 253 253 253 253
40906 -253 253 253 250 250 250 242 242 242 224 178 62
40907 -239 182 13 236 186 11 213 154 11 46 32 6
40908 - 2 2 6 2 2 6 2 2 6 2 2 6
40909 - 2 2 6 2 2 6 61 42 6 225 175 15
40910 -238 190 10 236 186 11 112 100 78 42 42 42
40911 - 14 14 14 0 0 0 0 0 0 0 0 0
40912 - 0 0 0 0 0 0 0 0 0 0 0 0
40913 - 0 0 0 0 0 0 0 0 0 0 0 0
40914 - 0 0 0 0 0 0 0 0 0 0 0 0
40915 - 0 0 0 0 0 0 0 0 0 6 6 6
40916 - 22 22 22 54 54 54 154 122 46 213 154 11
40917 -226 170 11 230 174 11 226 170 11 226 170 11
40918 -236 178 12 242 186 14 246 190 14 246 190 14
40919 -246 190 14 246 190 14 246 190 14 246 190 14
40920 -241 196 14 184 144 12 10 10 10 2 2 6
40921 - 6 6 6 116 116 116 242 242 242 253 253 253
40922 -253 253 253 253 253 253 253 253 253 253 253 253
40923 -253 253 253 253 253 253 253 253 253 253 253 253
40924 -253 253 253 253 253 253 253 253 253 253 253 253
40925 -253 253 253 253 253 253 253 253 253 253 253 253
40926 -253 253 253 231 231 231 198 198 198 214 170 54
40927 -236 178 12 236 178 12 210 150 10 137 92 6
40928 - 18 14 6 2 2 6 2 2 6 2 2 6
40929 - 6 6 6 70 47 6 200 144 11 236 178 12
40930 -239 182 13 239 182 13 124 112 88 58 58 58
40931 - 22 22 22 6 6 6 0 0 0 0 0 0
40932 - 0 0 0 0 0 0 0 0 0 0 0 0
40933 - 0 0 0 0 0 0 0 0 0 0 0 0
40934 - 0 0 0 0 0 0 0 0 0 0 0 0
40935 - 0 0 0 0 0 0 0 0 0 10 10 10
40936 - 30 30 30 70 70 70 180 133 36 226 170 11
40937 -239 182 13 242 186 14 242 186 14 246 186 14
40938 -246 190 14 246 190 14 246 190 14 246 190 14
40939 -246 190 14 246 190 14 246 190 14 246 190 14
40940 -246 190 14 232 195 16 98 70 6 2 2 6
40941 - 2 2 6 2 2 6 66 66 66 221 221 221
40942 -253 253 253 253 253 253 253 253 253 253 253 253
40943 -253 253 253 253 253 253 253 253 253 253 253 253
40944 -253 253 253 253 253 253 253 253 253 253 253 253
40945 -253 253 253 253 253 253 253 253 253 253 253 253
40946 -253 253 253 206 206 206 198 198 198 214 166 58
40947 -230 174 11 230 174 11 216 158 10 192 133 9
40948 -163 110 8 116 81 8 102 78 10 116 81 8
40949 -167 114 7 197 138 11 226 170 11 239 182 13
40950 -242 186 14 242 186 14 162 146 94 78 78 78
40951 - 34 34 34 14 14 14 6 6 6 0 0 0
40952 - 0 0 0 0 0 0 0 0 0 0 0 0
40953 - 0 0 0 0 0 0 0 0 0 0 0 0
40954 - 0 0 0 0 0 0 0 0 0 0 0 0
40955 - 0 0 0 0 0 0 0 0 0 6 6 6
40956 - 30 30 30 78 78 78 190 142 34 226 170 11
40957 -239 182 13 246 190 14 246 190 14 246 190 14
40958 -246 190 14 246 190 14 246 190 14 246 190 14
40959 -246 190 14 246 190 14 246 190 14 246 190 14
40960 -246 190 14 241 196 14 203 166 17 22 18 6
40961 - 2 2 6 2 2 6 2 2 6 38 38 38
40962 -218 218 218 253 253 253 253 253 253 253 253 253
40963 -253 253 253 253 253 253 253 253 253 253 253 253
40964 -253 253 253 253 253 253 253 253 253 253 253 253
40965 -253 253 253 253 253 253 253 253 253 253 253 253
40966 -250 250 250 206 206 206 198 198 198 202 162 69
40967 -226 170 11 236 178 12 224 166 10 210 150 10
40968 -200 144 11 197 138 11 192 133 9 197 138 11
40969 -210 150 10 226 170 11 242 186 14 246 190 14
40970 -246 190 14 246 186 14 225 175 15 124 112 88
40971 - 62 62 62 30 30 30 14 14 14 6 6 6
40972 - 0 0 0 0 0 0 0 0 0 0 0 0
40973 - 0 0 0 0 0 0 0 0 0 0 0 0
40974 - 0 0 0 0 0 0 0 0 0 0 0 0
40975 - 0 0 0 0 0 0 0 0 0 10 10 10
40976 - 30 30 30 78 78 78 174 135 50 224 166 10
40977 -239 182 13 246 190 14 246 190 14 246 190 14
40978 -246 190 14 246 190 14 246 190 14 246 190 14
40979 -246 190 14 246 190 14 246 190 14 246 190 14
40980 -246 190 14 246 190 14 241 196 14 139 102 15
40981 - 2 2 6 2 2 6 2 2 6 2 2 6
40982 - 78 78 78 250 250 250 253 253 253 253 253 253
40983 -253 253 253 253 253 253 253 253 253 253 253 253
40984 -253 253 253 253 253 253 253 253 253 253 253 253
40985 -253 253 253 253 253 253 253 253 253 253 253 253
40986 -250 250 250 214 214 214 198 198 198 190 150 46
40987 -219 162 10 236 178 12 234 174 13 224 166 10
40988 -216 158 10 213 154 11 213 154 11 216 158 10
40989 -226 170 11 239 182 13 246 190 14 246 190 14
40990 -246 190 14 246 190 14 242 186 14 206 162 42
40991 -101 101 101 58 58 58 30 30 30 14 14 14
40992 - 6 6 6 0 0 0 0 0 0 0 0 0
40993 - 0 0 0 0 0 0 0 0 0 0 0 0
40994 - 0 0 0 0 0 0 0 0 0 0 0 0
40995 - 0 0 0 0 0 0 0 0 0 10 10 10
40996 - 30 30 30 74 74 74 174 135 50 216 158 10
40997 -236 178 12 246 190 14 246 190 14 246 190 14
40998 -246 190 14 246 190 14 246 190 14 246 190 14
40999 -246 190 14 246 190 14 246 190 14 246 190 14
41000 -246 190 14 246 190 14 241 196 14 226 184 13
41001 - 61 42 6 2 2 6 2 2 6 2 2 6
41002 - 22 22 22 238 238 238 253 253 253 253 253 253
41003 -253 253 253 253 253 253 253 253 253 253 253 253
41004 -253 253 253 253 253 253 253 253 253 253 253 253
41005 -253 253 253 253 253 253 253 253 253 253 253 253
41006 -253 253 253 226 226 226 187 187 187 180 133 36
41007 -216 158 10 236 178 12 239 182 13 236 178 12
41008 -230 174 11 226 170 11 226 170 11 230 174 11
41009 -236 178 12 242 186 14 246 190 14 246 190 14
41010 -246 190 14 246 190 14 246 186 14 239 182 13
41011 -206 162 42 106 106 106 66 66 66 34 34 34
41012 - 14 14 14 6 6 6 0 0 0 0 0 0
41013 - 0 0 0 0 0 0 0 0 0 0 0 0
41014 - 0 0 0 0 0 0 0 0 0 0 0 0
41015 - 0 0 0 0 0 0 0 0 0 6 6 6
41016 - 26 26 26 70 70 70 163 133 67 213 154 11
41017 -236 178 12 246 190 14 246 190 14 246 190 14
41018 -246 190 14 246 190 14 246 190 14 246 190 14
41019 -246 190 14 246 190 14 246 190 14 246 190 14
41020 -246 190 14 246 190 14 246 190 14 241 196 14
41021 -190 146 13 18 14 6 2 2 6 2 2 6
41022 - 46 46 46 246 246 246 253 253 253 253 253 253
41023 -253 253 253 253 253 253 253 253 253 253 253 253
41024 -253 253 253 253 253 253 253 253 253 253 253 253
41025 -253 253 253 253 253 253 253 253 253 253 253 253
41026 -253 253 253 221 221 221 86 86 86 156 107 11
41027 -216 158 10 236 178 12 242 186 14 246 186 14
41028 -242 186 14 239 182 13 239 182 13 242 186 14
41029 -242 186 14 246 186 14 246 190 14 246 190 14
41030 -246 190 14 246 190 14 246 190 14 246 190 14
41031 -242 186 14 225 175 15 142 122 72 66 66 66
41032 - 30 30 30 10 10 10 0 0 0 0 0 0
41033 - 0 0 0 0 0 0 0 0 0 0 0 0
41034 - 0 0 0 0 0 0 0 0 0 0 0 0
41035 - 0 0 0 0 0 0 0 0 0 6 6 6
41036 - 26 26 26 70 70 70 163 133 67 210 150 10
41037 -236 178 12 246 190 14 246 190 14 246 190 14
41038 -246 190 14 246 190 14 246 190 14 246 190 14
41039 -246 190 14 246 190 14 246 190 14 246 190 14
41040 -246 190 14 246 190 14 246 190 14 246 190 14
41041 -232 195 16 121 92 8 34 34 34 106 106 106
41042 -221 221 221 253 253 253 253 253 253 253 253 253
41043 -253 253 253 253 253 253 253 253 253 253 253 253
41044 -253 253 253 253 253 253 253 253 253 253 253 253
41045 -253 253 253 253 253 253 253 253 253 253 253 253
41046 -242 242 242 82 82 82 18 14 6 163 110 8
41047 -216 158 10 236 178 12 242 186 14 246 190 14
41048 -246 190 14 246 190 14 246 190 14 246 190 14
41049 -246 190 14 246 190 14 246 190 14 246 190 14
41050 -246 190 14 246 190 14 246 190 14 246 190 14
41051 -246 190 14 246 190 14 242 186 14 163 133 67
41052 - 46 46 46 18 18 18 6 6 6 0 0 0
41053 - 0 0 0 0 0 0 0 0 0 0 0 0
41054 - 0 0 0 0 0 0 0 0 0 0 0 0
41055 - 0 0 0 0 0 0 0 0 0 10 10 10
41056 - 30 30 30 78 78 78 163 133 67 210 150 10
41057 -236 178 12 246 186 14 246 190 14 246 190 14
41058 -246 190 14 246 190 14 246 190 14 246 190 14
41059 -246 190 14 246 190 14 246 190 14 246 190 14
41060 -246 190 14 246 190 14 246 190 14 246 190 14
41061 -241 196 14 215 174 15 190 178 144 253 253 253
41062 -253 253 253 253 253 253 253 253 253 253 253 253
41063 -253 253 253 253 253 253 253 253 253 253 253 253
41064 -253 253 253 253 253 253 253 253 253 253 253 253
41065 -253 253 253 253 253 253 253 253 253 218 218 218
41066 - 58 58 58 2 2 6 22 18 6 167 114 7
41067 -216 158 10 236 178 12 246 186 14 246 190 14
41068 -246 190 14 246 190 14 246 190 14 246 190 14
41069 -246 190 14 246 190 14 246 190 14 246 190 14
41070 -246 190 14 246 190 14 246 190 14 246 190 14
41071 -246 190 14 246 186 14 242 186 14 190 150 46
41072 - 54 54 54 22 22 22 6 6 6 0 0 0
41073 - 0 0 0 0 0 0 0 0 0 0 0 0
41074 - 0 0 0 0 0 0 0 0 0 0 0 0
41075 - 0 0 0 0 0 0 0 0 0 14 14 14
41076 - 38 38 38 86 86 86 180 133 36 213 154 11
41077 -236 178 12 246 186 14 246 190 14 246 190 14
41078 -246 190 14 246 190 14 246 190 14 246 190 14
41079 -246 190 14 246 190 14 246 190 14 246 190 14
41080 -246 190 14 246 190 14 246 190 14 246 190 14
41081 -246 190 14 232 195 16 190 146 13 214 214 214
41082 -253 253 253 253 253 253 253 253 253 253 253 253
41083 -253 253 253 253 253 253 253 253 253 253 253 253
41084 -253 253 253 253 253 253 253 253 253 253 253 253
41085 -253 253 253 250 250 250 170 170 170 26 26 26
41086 - 2 2 6 2 2 6 37 26 9 163 110 8
41087 -219 162 10 239 182 13 246 186 14 246 190 14
41088 -246 190 14 246 190 14 246 190 14 246 190 14
41089 -246 190 14 246 190 14 246 190 14 246 190 14
41090 -246 190 14 246 190 14 246 190 14 246 190 14
41091 -246 186 14 236 178 12 224 166 10 142 122 72
41092 - 46 46 46 18 18 18 6 6 6 0 0 0
41093 - 0 0 0 0 0 0 0 0 0 0 0 0
41094 - 0 0 0 0 0 0 0 0 0 0 0 0
41095 - 0 0 0 0 0 0 6 6 6 18 18 18
41096 - 50 50 50 109 106 95 192 133 9 224 166 10
41097 -242 186 14 246 190 14 246 190 14 246 190 14
41098 -246 190 14 246 190 14 246 190 14 246 190 14
41099 -246 190 14 246 190 14 246 190 14 246 190 14
41100 -246 190 14 246 190 14 246 190 14 246 190 14
41101 -242 186 14 226 184 13 210 162 10 142 110 46
41102 -226 226 226 253 253 253 253 253 253 253 253 253
41103 -253 253 253 253 253 253 253 253 253 253 253 253
41104 -253 253 253 253 253 253 253 253 253 253 253 253
41105 -198 198 198 66 66 66 2 2 6 2 2 6
41106 - 2 2 6 2 2 6 50 34 6 156 107 11
41107 -219 162 10 239 182 13 246 186 14 246 190 14
41108 -246 190 14 246 190 14 246 190 14 246 190 14
41109 -246 190 14 246 190 14 246 190 14 246 190 14
41110 -246 190 14 246 190 14 246 190 14 242 186 14
41111 -234 174 13 213 154 11 154 122 46 66 66 66
41112 - 30 30 30 10 10 10 0 0 0 0 0 0
41113 - 0 0 0 0 0 0 0 0 0 0 0 0
41114 - 0 0 0 0 0 0 0 0 0 0 0 0
41115 - 0 0 0 0 0 0 6 6 6 22 22 22
41116 - 58 58 58 154 121 60 206 145 10 234 174 13
41117 -242 186 14 246 186 14 246 190 14 246 190 14
41118 -246 190 14 246 190 14 246 190 14 246 190 14
41119 -246 190 14 246 190 14 246 190 14 246 190 14
41120 -246 190 14 246 190 14 246 190 14 246 190 14
41121 -246 186 14 236 178 12 210 162 10 163 110 8
41122 - 61 42 6 138 138 138 218 218 218 250 250 250
41123 -253 253 253 253 253 253 253 253 253 250 250 250
41124 -242 242 242 210 210 210 144 144 144 66 66 66
41125 - 6 6 6 2 2 6 2 2 6 2 2 6
41126 - 2 2 6 2 2 6 61 42 6 163 110 8
41127 -216 158 10 236 178 12 246 190 14 246 190 14
41128 -246 190 14 246 190 14 246 190 14 246 190 14
41129 -246 190 14 246 190 14 246 190 14 246 190 14
41130 -246 190 14 239 182 13 230 174 11 216 158 10
41131 -190 142 34 124 112 88 70 70 70 38 38 38
41132 - 18 18 18 6 6 6 0 0 0 0 0 0
41133 - 0 0 0 0 0 0 0 0 0 0 0 0
41134 - 0 0 0 0 0 0 0 0 0 0 0 0
41135 - 0 0 0 0 0 0 6 6 6 22 22 22
41136 - 62 62 62 168 124 44 206 145 10 224 166 10
41137 -236 178 12 239 182 13 242 186 14 242 186 14
41138 -246 186 14 246 190 14 246 190 14 246 190 14
41139 -246 190 14 246 190 14 246 190 14 246 190 14
41140 -246 190 14 246 190 14 246 190 14 246 190 14
41141 -246 190 14 236 178 12 216 158 10 175 118 6
41142 - 80 54 7 2 2 6 6 6 6 30 30 30
41143 - 54 54 54 62 62 62 50 50 50 38 38 38
41144 - 14 14 14 2 2 6 2 2 6 2 2 6
41145 - 2 2 6 2 2 6 2 2 6 2 2 6
41146 - 2 2 6 6 6 6 80 54 7 167 114 7
41147 -213 154 11 236 178 12 246 190 14 246 190 14
41148 -246 190 14 246 190 14 246 190 14 246 190 14
41149 -246 190 14 242 186 14 239 182 13 239 182 13
41150 -230 174 11 210 150 10 174 135 50 124 112 88
41151 - 82 82 82 54 54 54 34 34 34 18 18 18
41152 - 6 6 6 0 0 0 0 0 0 0 0 0
41153 - 0 0 0 0 0 0 0 0 0 0 0 0
41154 - 0 0 0 0 0 0 0 0 0 0 0 0
41155 - 0 0 0 0 0 0 6 6 6 18 18 18
41156 - 50 50 50 158 118 36 192 133 9 200 144 11
41157 -216 158 10 219 162 10 224 166 10 226 170 11
41158 -230 174 11 236 178 12 239 182 13 239 182 13
41159 -242 186 14 246 186 14 246 190 14 246 190 14
41160 -246 190 14 246 190 14 246 190 14 246 190 14
41161 -246 186 14 230 174 11 210 150 10 163 110 8
41162 -104 69 6 10 10 10 2 2 6 2 2 6
41163 - 2 2 6 2 2 6 2 2 6 2 2 6
41164 - 2 2 6 2 2 6 2 2 6 2 2 6
41165 - 2 2 6 2 2 6 2 2 6 2 2 6
41166 - 2 2 6 6 6 6 91 60 6 167 114 7
41167 -206 145 10 230 174 11 242 186 14 246 190 14
41168 -246 190 14 246 190 14 246 186 14 242 186 14
41169 -239 182 13 230 174 11 224 166 10 213 154 11
41170 -180 133 36 124 112 88 86 86 86 58 58 58
41171 - 38 38 38 22 22 22 10 10 10 6 6 6
41172 - 0 0 0 0 0 0 0 0 0 0 0 0
41173 - 0 0 0 0 0 0 0 0 0 0 0 0
41174 - 0 0 0 0 0 0 0 0 0 0 0 0
41175 - 0 0 0 0 0 0 0 0 0 14 14 14
41176 - 34 34 34 70 70 70 138 110 50 158 118 36
41177 -167 114 7 180 123 7 192 133 9 197 138 11
41178 -200 144 11 206 145 10 213 154 11 219 162 10
41179 -224 166 10 230 174 11 239 182 13 242 186 14
41180 -246 186 14 246 186 14 246 186 14 246 186 14
41181 -239 182 13 216 158 10 185 133 11 152 99 6
41182 -104 69 6 18 14 6 2 2 6 2 2 6
41183 - 2 2 6 2 2 6 2 2 6 2 2 6
41184 - 2 2 6 2 2 6 2 2 6 2 2 6
41185 - 2 2 6 2 2 6 2 2 6 2 2 6
41186 - 2 2 6 6 6 6 80 54 7 152 99 6
41187 -192 133 9 219 162 10 236 178 12 239 182 13
41188 -246 186 14 242 186 14 239 182 13 236 178 12
41189 -224 166 10 206 145 10 192 133 9 154 121 60
41190 - 94 94 94 62 62 62 42 42 42 22 22 22
41191 - 14 14 14 6 6 6 0 0 0 0 0 0
41192 - 0 0 0 0 0 0 0 0 0 0 0 0
41193 - 0 0 0 0 0 0 0 0 0 0 0 0
41194 - 0 0 0 0 0 0 0 0 0 0 0 0
41195 - 0 0 0 0 0 0 0 0 0 6 6 6
41196 - 18 18 18 34 34 34 58 58 58 78 78 78
41197 -101 98 89 124 112 88 142 110 46 156 107 11
41198 -163 110 8 167 114 7 175 118 6 180 123 7
41199 -185 133 11 197 138 11 210 150 10 219 162 10
41200 -226 170 11 236 178 12 236 178 12 234 174 13
41201 -219 162 10 197 138 11 163 110 8 130 83 6
41202 - 91 60 6 10 10 10 2 2 6 2 2 6
41203 - 18 18 18 38 38 38 38 38 38 38 38 38
41204 - 38 38 38 38 38 38 38 38 38 38 38 38
41205 - 38 38 38 38 38 38 26 26 26 2 2 6
41206 - 2 2 6 6 6 6 70 47 6 137 92 6
41207 -175 118 6 200 144 11 219 162 10 230 174 11
41208 -234 174 13 230 174 11 219 162 10 210 150 10
41209 -192 133 9 163 110 8 124 112 88 82 82 82
41210 - 50 50 50 30 30 30 14 14 14 6 6 6
41211 - 0 0 0 0 0 0 0 0 0 0 0 0
41212 - 0 0 0 0 0 0 0 0 0 0 0 0
41213 - 0 0 0 0 0 0 0 0 0 0 0 0
41214 - 0 0 0 0 0 0 0 0 0 0 0 0
41215 - 0 0 0 0 0 0 0 0 0 0 0 0
41216 - 6 6 6 14 14 14 22 22 22 34 34 34
41217 - 42 42 42 58 58 58 74 74 74 86 86 86
41218 -101 98 89 122 102 70 130 98 46 121 87 25
41219 -137 92 6 152 99 6 163 110 8 180 123 7
41220 -185 133 11 197 138 11 206 145 10 200 144 11
41221 -180 123 7 156 107 11 130 83 6 104 69 6
41222 - 50 34 6 54 54 54 110 110 110 101 98 89
41223 - 86 86 86 82 82 82 78 78 78 78 78 78
41224 - 78 78 78 78 78 78 78 78 78 78 78 78
41225 - 78 78 78 82 82 82 86 86 86 94 94 94
41226 -106 106 106 101 101 101 86 66 34 124 80 6
41227 -156 107 11 180 123 7 192 133 9 200 144 11
41228 -206 145 10 200 144 11 192 133 9 175 118 6
41229 -139 102 15 109 106 95 70 70 70 42 42 42
41230 - 22 22 22 10 10 10 0 0 0 0 0 0
41231 - 0 0 0 0 0 0 0 0 0 0 0 0
41232 - 0 0 0 0 0 0 0 0 0 0 0 0
41233 - 0 0 0 0 0 0 0 0 0 0 0 0
41234 - 0 0 0 0 0 0 0 0 0 0 0 0
41235 - 0 0 0 0 0 0 0 0 0 0 0 0
41236 - 0 0 0 0 0 0 6 6 6 10 10 10
41237 - 14 14 14 22 22 22 30 30 30 38 38 38
41238 - 50 50 50 62 62 62 74 74 74 90 90 90
41239 -101 98 89 112 100 78 121 87 25 124 80 6
41240 -137 92 6 152 99 6 152 99 6 152 99 6
41241 -138 86 6 124 80 6 98 70 6 86 66 30
41242 -101 98 89 82 82 82 58 58 58 46 46 46
41243 - 38 38 38 34 34 34 34 34 34 34 34 34
41244 - 34 34 34 34 34 34 34 34 34 34 34 34
41245 - 34 34 34 34 34 34 38 38 38 42 42 42
41246 - 54 54 54 82 82 82 94 86 76 91 60 6
41247 -134 86 6 156 107 11 167 114 7 175 118 6
41248 -175 118 6 167 114 7 152 99 6 121 87 25
41249 -101 98 89 62 62 62 34 34 34 18 18 18
41250 - 6 6 6 0 0 0 0 0 0 0 0 0
41251 - 0 0 0 0 0 0 0 0 0 0 0 0
41252 - 0 0 0 0 0 0 0 0 0 0 0 0
41253 - 0 0 0 0 0 0 0 0 0 0 0 0
41254 - 0 0 0 0 0 0 0 0 0 0 0 0
41255 - 0 0 0 0 0 0 0 0 0 0 0 0
41256 - 0 0 0 0 0 0 0 0 0 0 0 0
41257 - 0 0 0 6 6 6 6 6 6 10 10 10
41258 - 18 18 18 22 22 22 30 30 30 42 42 42
41259 - 50 50 50 66 66 66 86 86 86 101 98 89
41260 -106 86 58 98 70 6 104 69 6 104 69 6
41261 -104 69 6 91 60 6 82 62 34 90 90 90
41262 - 62 62 62 38 38 38 22 22 22 14 14 14
41263 - 10 10 10 10 10 10 10 10 10 10 10 10
41264 - 10 10 10 10 10 10 6 6 6 10 10 10
41265 - 10 10 10 10 10 10 10 10 10 14 14 14
41266 - 22 22 22 42 42 42 70 70 70 89 81 66
41267 - 80 54 7 104 69 6 124 80 6 137 92 6
41268 -134 86 6 116 81 8 100 82 52 86 86 86
41269 - 58 58 58 30 30 30 14 14 14 6 6 6
41270 - 0 0 0 0 0 0 0 0 0 0 0 0
41271 - 0 0 0 0 0 0 0 0 0 0 0 0
41272 - 0 0 0 0 0 0 0 0 0 0 0 0
41273 - 0 0 0 0 0 0 0 0 0 0 0 0
41274 - 0 0 0 0 0 0 0 0 0 0 0 0
41275 - 0 0 0 0 0 0 0 0 0 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 6 6 6 10 10 10 14 14 14
41279 - 18 18 18 26 26 26 38 38 38 54 54 54
41280 - 70 70 70 86 86 86 94 86 76 89 81 66
41281 - 89 81 66 86 86 86 74 74 74 50 50 50
41282 - 30 30 30 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 - 6 6 6 18 18 18 34 34 34 58 58 58
41287 - 82 82 82 89 81 66 89 81 66 89 81 66
41288 - 94 86 66 94 86 76 74 74 74 50 50 50
41289 - 26 26 26 14 14 14 6 6 6 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 - 0 0 0 0 0 0 0 0 0 0 0 0
41293 - 0 0 0 0 0 0 0 0 0 0 0 0
41294 - 0 0 0 0 0 0 0 0 0 0 0 0
41295 - 0 0 0 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 - 6 6 6 6 6 6 14 14 14 18 18 18
41300 - 30 30 30 38 38 38 46 46 46 54 54 54
41301 - 50 50 50 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 6 6 6 14 14 14 26 26 26
41307 - 38 38 38 50 50 50 58 58 58 58 58 58
41308 - 54 54 54 42 42 42 30 30 30 18 18 18
41309 - 10 10 10 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 0 0 0
41313 - 0 0 0 0 0 0 0 0 0 0 0 0
41314 - 0 0 0 0 0 0 0 0 0 0 0 0
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 - 6 6 6 10 10 10 14 14 14 18 18 18
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 6 6 6
41327 - 14 14 14 18 18 18 22 22 22 22 22 22
41328 - 18 18 18 14 14 14 10 10 10 6 6 6
41329 - 0 0 0 0 0 0 0 0 0 0 0 0
41330 - 0 0 0 0 0 0 0 0 0 0 0 0
41331 - 0 0 0 0 0 0 0 0 0 0 0 0
41332 - 0 0 0 0 0 0 0 0 0 0 0 0
41333 - 0 0 0 0 0 0 0 0 0 0 0 0
41334 +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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4
41416 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41417 +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 4 4 4 4 4 4
41421 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41422 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
41423 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
41424 +4 4 4 4 4 4 4 4 4 4 4 4 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 1 1 1 0 0 0
41428 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41429 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
41430 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41431 +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 4 4 4 4 4 4 4 4 4 4 4 4
41435 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41436 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
41437 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
41438 +5 5 5 4 4 4 4 4 4 4 4 4 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 3 3 3 0 0 0 1 1 1 6 6 6
41442 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
41443 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
41444 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41445 +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 4 4 4 4 4 4 4 4 4 4 4 4
41449 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41450 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
41451 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
41452 +0 0 0 3 3 3 4 4 4 4 4 4 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 0 0 0 4 4 4 41 54 63 125 124 125
41456 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
41457 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
41458 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
41459 +4 4 4 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 4 4 4 4 4 4
41462 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41463 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
41464 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
41465 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
41466 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 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 5 5 5 5 5 5
41469 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
41470 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
41471 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
41472 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
41473 +4 4 4 4 4 4
41474 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41475 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41476 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41477 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
41478 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
41479 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
41480 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
41481 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41482 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
41483 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
41484 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
41485 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
41486 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
41487 +4 4 4 4 4 4
41488 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41489 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41490 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41491 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
41492 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
41493 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
41494 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
41495 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
41496 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
41497 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
41498 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
41499 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
41500 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
41501 +4 4 4 4 4 4
41502 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41503 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41504 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
41505 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
41506 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
41507 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
41508 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
41509 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
41510 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
41511 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
41512 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
41513 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
41514 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
41515 +4 4 4 4 4 4
41516 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41517 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41518 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
41519 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
41520 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
41521 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
41522 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
41523 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
41524 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
41525 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
41526 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
41527 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
41528 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
41529 +4 4 4 4 4 4
41530 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41531 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41532 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
41533 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
41534 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
41535 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
41536 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
41537 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
41538 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
41539 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
41540 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
41541 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
41542 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41543 +4 4 4 4 4 4
41544 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41545 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41546 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
41547 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
41548 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
41549 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
41550 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
41551 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
41552 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
41553 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
41554 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
41555 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
41556 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
41557 +4 4 4 4 4 4
41558 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41559 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
41560 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
41561 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
41562 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
41563 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
41564 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
41565 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
41566 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
41567 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
41568 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
41569 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
41570 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
41571 +4 4 4 4 4 4
41572 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41573 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
41574 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
41575 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
41576 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
41577 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
41578 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
41579 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
41580 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
41581 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
41582 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
41583 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
41584 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
41585 +0 0 0 4 4 4
41586 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
41587 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
41588 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
41589 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
41590 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
41591 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
41592 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
41593 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
41594 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
41595 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
41596 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
41597 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
41598 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
41599 +2 0 0 0 0 0
41600 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
41601 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
41602 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
41603 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
41604 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
41605 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
41606 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
41607 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
41608 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
41609 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
41610 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
41611 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
41612 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
41613 +37 38 37 0 0 0
41614 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
41615 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
41616 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
41617 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
41618 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
41619 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
41620 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
41621 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
41622 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
41623 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
41624 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
41625 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
41626 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
41627 +85 115 134 4 0 0
41628 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
41629 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
41630 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
41631 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
41632 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
41633 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
41634 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
41635 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
41636 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
41637 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
41638 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
41639 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
41640 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
41641 +60 73 81 4 0 0
41642 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
41643 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
41644 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
41645 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
41646 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
41647 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
41648 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
41649 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
41650 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
41651 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
41652 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
41653 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
41654 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
41655 +16 19 21 4 0 0
41656 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
41657 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
41658 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
41659 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
41660 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
41661 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
41662 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
41663 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
41664 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
41665 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
41666 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
41667 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
41668 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
41669 +4 0 0 4 3 3
41670 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
41671 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
41672 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
41673 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
41674 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
41675 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
41676 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
41677 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
41678 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
41679 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
41680 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
41681 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
41682 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
41683 +3 2 2 4 4 4
41684 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
41685 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
41686 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
41687 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
41688 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
41689 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
41690 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
41691 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
41692 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
41693 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
41694 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
41695 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
41696 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
41697 +4 4 4 4 4 4
41698 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
41699 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
41700 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
41701 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
41702 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
41703 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
41704 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
41705 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
41706 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
41707 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
41708 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
41709 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
41710 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
41711 +4 4 4 4 4 4
41712 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
41713 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
41714 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
41715 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
41716 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
41717 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41718 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
41719 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
41720 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
41721 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
41722 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
41723 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
41724 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
41725 +5 5 5 5 5 5
41726 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
41727 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
41728 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
41729 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
41730 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
41731 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41732 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
41733 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
41734 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
41735 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
41736 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
41737 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
41738 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
41739 +5 5 5 4 4 4
41740 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
41741 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
41742 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
41743 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
41744 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41745 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
41746 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
41747 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
41748 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
41749 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
41750 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
41751 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
41752 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41753 +4 4 4 4 4 4
41754 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
41755 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
41756 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
41757 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
41758 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
41759 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41760 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41761 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
41762 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
41763 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
41764 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
41765 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
41766 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41767 +4 4 4 4 4 4
41768 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
41769 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
41770 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
41771 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
41772 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41773 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
41774 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
41775 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
41776 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
41777 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
41778 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
41779 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41780 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41781 +4 4 4 4 4 4
41782 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
41783 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
41784 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
41785 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
41786 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41787 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41788 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41789 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
41790 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
41791 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
41792 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
41793 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41794 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41795 +4 4 4 4 4 4
41796 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
41797 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
41798 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
41799 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
41800 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41801 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
41802 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41803 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
41804 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
41805 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
41806 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41807 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41808 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41809 +4 4 4 4 4 4
41810 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
41811 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
41812 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
41813 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
41814 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41815 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
41816 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
41817 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
41818 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
41819 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
41820 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
41821 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41822 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41823 +4 4 4 4 4 4
41824 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
41825 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
41826 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
41827 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
41828 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41829 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
41830 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
41831 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
41832 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
41833 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
41834 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
41835 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41836 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41837 +4 4 4 4 4 4
41838 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
41839 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
41840 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
41841 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
41842 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
41843 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
41844 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
41845 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
41846 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
41847 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
41848 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41849 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41850 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41851 +4 4 4 4 4 4
41852 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
41853 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
41854 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
41855 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
41856 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41857 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
41858 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
41859 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
41860 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
41861 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
41862 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41863 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41864 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41865 +4 4 4 4 4 4
41866 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
41867 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
41868 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
41869 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
41870 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41871 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
41872 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
41873 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
41874 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
41875 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
41876 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41877 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41878 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41879 +4 4 4 4 4 4
41880 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
41881 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
41882 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41883 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
41884 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41885 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
41886 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
41887 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
41888 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41889 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41890 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41891 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41892 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41893 +4 4 4 4 4 4
41894 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41895 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
41896 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
41897 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
41898 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
41899 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
41900 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
41901 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
41902 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41903 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41904 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41905 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41906 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41907 +4 4 4 4 4 4
41908 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41909 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
41910 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41911 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
41912 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41913 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
41914 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
41915 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
41916 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41917 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41918 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41919 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41920 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41921 +4 4 4 4 4 4
41922 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
41923 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
41924 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41925 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
41926 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
41927 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
41928 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
41929 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
41930 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41931 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41932 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41933 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41934 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41935 +4 4 4 4 4 4
41936 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
41937 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
41938 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41939 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
41940 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
41941 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
41942 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
41943 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
41944 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41945 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41946 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41947 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41948 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41949 +4 4 4 4 4 4
41950 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41951 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
41952 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41953 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
41954 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
41955 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
41956 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
41957 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
41958 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41959 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41960 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41961 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41962 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41963 +4 4 4 4 4 4
41964 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
41965 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
41966 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41967 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
41968 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
41969 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
41970 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
41971 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
41972 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
41973 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41974 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41975 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41976 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41977 +4 4 4 4 4 4
41978 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41979 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
41980 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
41981 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
41982 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
41983 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
41984 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
41985 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
41986 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41987 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41988 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41989 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41990 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41991 +4 4 4 4 4 4
41992 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41993 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
41994 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41995 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
41996 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
41997 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
41998 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
41999 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
42000 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
42001 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42002 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42003 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42004 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42005 +4 4 4 4 4 4
42006 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
42007 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
42008 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
42009 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
42010 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
42011 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
42012 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
42013 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
42014 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
42015 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42016 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42017 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42018 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42019 +4 4 4 4 4 4
42020 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
42021 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
42022 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
42023 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
42024 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
42025 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
42026 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
42027 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
42028 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
42029 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42030 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42031 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42032 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42033 +4 4 4 4 4 4
42034 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
42035 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
42036 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
42037 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
42038 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
42039 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
42040 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
42041 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
42042 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
42043 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42044 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42045 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42046 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42047 +4 4 4 4 4 4
42048 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
42049 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
42050 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
42051 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
42052 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
42053 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
42054 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
42055 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
42056 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
42057 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42058 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42059 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42060 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42061 +4 4 4 4 4 4
42062 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
42063 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
42064 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
42065 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
42066 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
42067 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
42068 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
42069 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
42070 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
42071 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42072 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42073 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42074 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42075 +4 4 4 4 4 4
42076 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
42077 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
42078 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
42079 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
42080 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
42081 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
42082 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
42083 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
42084 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
42085 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42086 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42087 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42088 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42089 +4 4 4 4 4 4
42090 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
42091 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
42092 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
42093 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
42094 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
42095 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
42096 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
42097 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
42098 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
42099 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
42100 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42101 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42102 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42103 +4 4 4 4 4 4
42104 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
42105 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
42106 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
42107 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
42108 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
42109 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
42110 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
42111 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
42112 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
42113 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
42114 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42115 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42116 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42117 +4 4 4 4 4 4
42118 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
42119 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
42120 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
42121 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
42122 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
42123 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
42124 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42125 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
42126 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
42127 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
42128 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42129 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42130 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42131 +4 4 4 4 4 4
42132 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
42133 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
42134 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
42135 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
42136 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
42137 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
42138 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
42139 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
42140 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
42141 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
42142 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42143 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42144 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42145 +4 4 4 4 4 4
42146 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
42147 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
42148 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
42149 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
42150 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
42151 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
42152 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
42153 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
42154 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
42155 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
42156 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42157 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42158 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42159 +4 4 4 4 4 4
42160 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
42161 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
42162 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
42163 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
42164 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
42165 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
42166 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
42167 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
42168 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
42169 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
42170 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42171 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42172 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42173 +4 4 4 4 4 4
42174 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
42175 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
42176 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
42177 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
42178 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
42179 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
42180 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
42181 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
42182 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
42183 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
42184 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42185 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42186 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42187 +4 4 4 4 4 4
42188 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
42189 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
42190 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
42191 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
42192 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
42193 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
42194 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
42195 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
42196 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
42197 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42198 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42199 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42200 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42201 +4 4 4 4 4 4
42202 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
42203 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
42204 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
42205 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
42206 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
42207 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
42208 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
42209 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
42210 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
42211 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42212 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42213 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42214 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42215 +4 4 4 4 4 4
42216 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
42217 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
42218 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
42219 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
42220 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
42221 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
42222 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
42223 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
42224 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
42225 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42226 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42227 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42228 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42229 +4 4 4 4 4 4
42230 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
42231 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
42232 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
42233 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
42234 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
42235 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
42236 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
42237 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
42238 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42239 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42240 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42241 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42242 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42243 +4 4 4 4 4 4
42244 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
42245 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
42246 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
42247 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
42248 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
42249 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
42250 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
42251 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
42252 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42253 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42254 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42255 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42256 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42257 +4 4 4 4 4 4
42258 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
42259 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
42260 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
42261 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
42262 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
42263 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
42264 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
42265 +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
42266 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42267 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42268 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42269 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42270 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42271 +4 4 4 4 4 4
42272 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
42273 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
42274 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42275 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
42276 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
42277 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
42278 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
42279 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
42280 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42281 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42282 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42283 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42284 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42285 +4 4 4 4 4 4
42286 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42287 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
42288 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
42289 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
42290 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
42291 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
42292 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
42293 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
42294 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42295 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42296 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42297 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42298 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42299 +4 4 4 4 4 4
42300 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42301 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
42302 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
42303 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
42304 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
42305 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
42306 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
42307 +5 5 5 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42310 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42311 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42312 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42313 +4 4 4 4 4 4
42314 +4 4 4 4 4 4 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 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
42317 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
42318 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
42319 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
42320 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
42321 +4 3 3 5 5 5 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 4 4 4
42324 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42325 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42326 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42327 +4 4 4 4 4 4
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 5 5 5
42331 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42332 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
42333 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
42334 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42339 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42340 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42341 +4 4 4 4 4 4
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 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
42346 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
42347 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
42348 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
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 4 4 4 4 4 4 4 4 4 4 4 4
42353 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42354 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42355 +4 4 4 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 5 5 5 4 3 3 5 5 5 6 6 6
42360 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
42361 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
42362 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4
42367 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42368 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42369 +4 4 4 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 5 5 5 4 3 3 5 5 5
42374 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
42375 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
42376 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 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 4 4 4
42381 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42382 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42383 +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 5 5 5
42388 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
42389 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42390 +6 6 6 4 3 3 5 5 5 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42396 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42397 +4 4 4 4 4 4
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 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
42403 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
42404 +4 3 3 5 5 5 5 5 5 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42410 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42411 +4 4 4 4 4 4
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 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
42417 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
42418 +5 5 5 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4
42424 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42425 +4 4 4 4 4 4
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 5 5 5 4 3 3 6 6 6
42431 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
42432 +4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4
42438 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42439 +4 4 4 4 4 4
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 5 5 5 4 3 3
42445 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
42446 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42447 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42448 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42449 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42450 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42451 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42452 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42453 +4 4 4 4 4 4
42454 diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
42455 index 38fcfff..0072dcd 100644
42456 --- a/drivers/video/udlfb.c
42457 +++ b/drivers/video/udlfb.c
42458 @@ -620,11 +620,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
42459 dlfb_urb_completion(urb);
42460
42461 error:
42462 - atomic_add(bytes_sent, &dev->bytes_sent);
42463 - atomic_add(bytes_identical, &dev->bytes_identical);
42464 - atomic_add(width*height*2, &dev->bytes_rendered);
42465 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
42466 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
42467 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
42468 end_cycles = get_cycles();
42469 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
42470 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
42471 >> 10)), /* Kcycles */
42472 &dev->cpu_kcycles_used);
42473
42474 @@ -745,11 +745,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
42475 dlfb_urb_completion(urb);
42476
42477 error:
42478 - atomic_add(bytes_sent, &dev->bytes_sent);
42479 - atomic_add(bytes_identical, &dev->bytes_identical);
42480 - atomic_add(bytes_rendered, &dev->bytes_rendered);
42481 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
42482 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
42483 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
42484 end_cycles = get_cycles();
42485 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
42486 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
42487 >> 10)), /* Kcycles */
42488 &dev->cpu_kcycles_used);
42489 }
42490 @@ -1373,7 +1373,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
42491 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42492 struct dlfb_data *dev = fb_info->par;
42493 return snprintf(buf, PAGE_SIZE, "%u\n",
42494 - atomic_read(&dev->bytes_rendered));
42495 + atomic_read_unchecked(&dev->bytes_rendered));
42496 }
42497
42498 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
42499 @@ -1381,7 +1381,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
42500 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42501 struct dlfb_data *dev = fb_info->par;
42502 return snprintf(buf, PAGE_SIZE, "%u\n",
42503 - atomic_read(&dev->bytes_identical));
42504 + atomic_read_unchecked(&dev->bytes_identical));
42505 }
42506
42507 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
42508 @@ -1389,7 +1389,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
42509 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42510 struct dlfb_data *dev = fb_info->par;
42511 return snprintf(buf, PAGE_SIZE, "%u\n",
42512 - atomic_read(&dev->bytes_sent));
42513 + atomic_read_unchecked(&dev->bytes_sent));
42514 }
42515
42516 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
42517 @@ -1397,7 +1397,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
42518 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42519 struct dlfb_data *dev = fb_info->par;
42520 return snprintf(buf, PAGE_SIZE, "%u\n",
42521 - atomic_read(&dev->cpu_kcycles_used));
42522 + atomic_read_unchecked(&dev->cpu_kcycles_used));
42523 }
42524
42525 static ssize_t edid_show(
42526 @@ -1457,10 +1457,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
42527 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42528 struct dlfb_data *dev = fb_info->par;
42529
42530 - atomic_set(&dev->bytes_rendered, 0);
42531 - atomic_set(&dev->bytes_identical, 0);
42532 - atomic_set(&dev->bytes_sent, 0);
42533 - atomic_set(&dev->cpu_kcycles_used, 0);
42534 + atomic_set_unchecked(&dev->bytes_rendered, 0);
42535 + atomic_set_unchecked(&dev->bytes_identical, 0);
42536 + atomic_set_unchecked(&dev->bytes_sent, 0);
42537 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
42538
42539 return count;
42540 }
42541 diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
42542 index b0e2a42..e2df3ad 100644
42543 --- a/drivers/video/uvesafb.c
42544 +++ b/drivers/video/uvesafb.c
42545 @@ -19,6 +19,7 @@
42546 #include <linux/io.h>
42547 #include <linux/mutex.h>
42548 #include <linux/slab.h>
42549 +#include <linux/moduleloader.h>
42550 #include <video/edid.h>
42551 #include <video/uvesafb.h>
42552 #ifdef CONFIG_X86
42553 @@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
42554 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
42555 par->pmi_setpal = par->ypan = 0;
42556 } else {
42557 +
42558 +#ifdef CONFIG_PAX_KERNEXEC
42559 +#ifdef CONFIG_MODULES
42560 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
42561 +#endif
42562 + if (!par->pmi_code) {
42563 + par->pmi_setpal = par->ypan = 0;
42564 + return 0;
42565 + }
42566 +#endif
42567 +
42568 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
42569 + task->t.regs.edi);
42570 +
42571 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42572 + pax_open_kernel();
42573 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
42574 + pax_close_kernel();
42575 +
42576 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
42577 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
42578 +#else
42579 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
42580 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
42581 +#endif
42582 +
42583 printk(KERN_INFO "uvesafb: protected mode interface info at "
42584 "%04x:%04x\n",
42585 (u16)task->t.regs.es, (u16)task->t.regs.edi);
42586 @@ -816,13 +839,14 @@ static int __devinit uvesafb_vbe_init(struct fb_info *info)
42587 par->ypan = ypan;
42588
42589 if (par->pmi_setpal || par->ypan) {
42590 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
42591 if (__supported_pte_mask & _PAGE_NX) {
42592 par->pmi_setpal = par->ypan = 0;
42593 printk(KERN_WARNING "uvesafb: NX protection is actively."
42594 "We have better not to use the PMI.\n");
42595 - } else {
42596 + } else
42597 +#endif
42598 uvesafb_vbe_getpmi(task, par);
42599 - }
42600 }
42601 #else
42602 /* The protected mode interface is not available on non-x86. */
42603 @@ -1836,6 +1860,11 @@ out:
42604 if (par->vbe_modes)
42605 kfree(par->vbe_modes);
42606
42607 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42608 + if (par->pmi_code)
42609 + module_free_exec(NULL, par->pmi_code);
42610 +#endif
42611 +
42612 framebuffer_release(info);
42613 return err;
42614 }
42615 @@ -1862,6 +1891,12 @@ static int uvesafb_remove(struct platform_device *dev)
42616 kfree(par->vbe_state_orig);
42617 if (par->vbe_state_saved)
42618 kfree(par->vbe_state_saved);
42619 +
42620 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42621 + if (par->pmi_code)
42622 + module_free_exec(NULL, par->pmi_code);
42623 +#endif
42624 +
42625 }
42626
42627 framebuffer_release(info);
42628 diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
42629 index 501b340..86bd4cf 100644
42630 --- a/drivers/video/vesafb.c
42631 +++ b/drivers/video/vesafb.c
42632 @@ -9,6 +9,7 @@
42633 */
42634
42635 #include <linux/module.h>
42636 +#include <linux/moduleloader.h>
42637 #include <linux/kernel.h>
42638 #include <linux/errno.h>
42639 #include <linux/string.h>
42640 @@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
42641 static int vram_total __initdata; /* Set total amount of memory */
42642 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
42643 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
42644 -static void (*pmi_start)(void) __read_mostly;
42645 -static void (*pmi_pal) (void) __read_mostly;
42646 +static void (*pmi_start)(void) __read_only;
42647 +static void (*pmi_pal) (void) __read_only;
42648 static int depth __read_mostly;
42649 static int vga_compat __read_mostly;
42650 /* --------------------------------------------------------------------- */
42651 @@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
42652 unsigned int size_vmode;
42653 unsigned int size_remap;
42654 unsigned int size_total;
42655 + void *pmi_code = NULL;
42656
42657 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
42658 return -ENODEV;
42659 @@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
42660 size_remap = size_total;
42661 vesafb_fix.smem_len = size_remap;
42662
42663 -#ifndef __i386__
42664 - screen_info.vesapm_seg = 0;
42665 -#endif
42666 -
42667 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
42668 printk(KERN_WARNING
42669 "vesafb: cannot reserve video memory at 0x%lx\n",
42670 @@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
42671 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
42672 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
42673
42674 +#ifdef __i386__
42675 +
42676 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42677 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
42678 + if (!pmi_code)
42679 +#elif !defined(CONFIG_PAX_KERNEXEC)
42680 + if (0)
42681 +#endif
42682 +
42683 +#endif
42684 + screen_info.vesapm_seg = 0;
42685 +
42686 if (screen_info.vesapm_seg) {
42687 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
42688 - screen_info.vesapm_seg,screen_info.vesapm_off);
42689 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
42690 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
42691 }
42692
42693 if (screen_info.vesapm_seg < 0xc000)
42694 @@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
42695
42696 if (ypan || pmi_setpal) {
42697 unsigned short *pmi_base;
42698 +
42699 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
42700 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
42701 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
42702 +
42703 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42704 + pax_open_kernel();
42705 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
42706 +#else
42707 + pmi_code = pmi_base;
42708 +#endif
42709 +
42710 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
42711 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
42712 +
42713 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42714 + pmi_start = ktva_ktla(pmi_start);
42715 + pmi_pal = ktva_ktla(pmi_pal);
42716 + pax_close_kernel();
42717 +#endif
42718 +
42719 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
42720 if (pmi_base[3]) {
42721 printk(KERN_INFO "vesafb: pmi: ports = ");
42722 @@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
42723 info->node, info->fix.id);
42724 return 0;
42725 err:
42726 +
42727 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42728 + module_free_exec(NULL, pmi_code);
42729 +#endif
42730 +
42731 if (info->screen_base)
42732 iounmap(info->screen_base);
42733 framebuffer_release(info);
42734 diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
42735 index 88714ae..16c2e11 100644
42736 --- a/drivers/video/via/via_clock.h
42737 +++ b/drivers/video/via/via_clock.h
42738 @@ -56,7 +56,7 @@ struct via_clock {
42739
42740 void (*set_engine_pll_state)(u8 state);
42741 void (*set_engine_pll)(struct via_pll_config config);
42742 -};
42743 +} __no_const;
42744
42745
42746 static inline u32 get_pll_internal_frequency(u32 ref_freq,
42747 diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c
42748 index c3b3f7f..abd47c7 100644
42749 --- a/drivers/virtio/virtio.c
42750 +++ b/drivers/virtio/virtio.c
42751 @@ -225,8 +225,10 @@ EXPORT_SYMBOL_GPL(register_virtio_device);
42752
42753 void unregister_virtio_device(struct virtio_device *dev)
42754 {
42755 + int index = dev->index; /* save for after device release */
42756 +
42757 device_unregister(&dev->dev);
42758 - ida_simple_remove(&virtio_index_ida, dev->index);
42759 + ida_simple_remove(&virtio_index_ida, index);
42760 }
42761 EXPORT_SYMBOL_GPL(unregister_virtio_device);
42762
42763 diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
42764 index 453db0c..604973e 100644
42765 --- a/drivers/virtio/virtio_mmio.c
42766 +++ b/drivers/virtio/virtio_mmio.c
42767 @@ -521,7 +521,7 @@ static int vm_cmdline_set(const char *device,
42768
42769 resources[0].end = memparse(device, &str) - 1;
42770
42771 - processed = sscanf(str, "@%lli:%u%n:%d%n",
42772 + processed = sscanf(str, "@%lli:%llu%n:%d%n",
42773 &base, &resources[1].start, &consumed,
42774 &vm_cmdline_id, &consumed);
42775
42776 diff --git a/drivers/xen/xen-pciback/conf_space.h b/drivers/xen/xen-pciback/conf_space.h
42777 index e56c934..fc22f4b 100644
42778 --- a/drivers/xen/xen-pciback/conf_space.h
42779 +++ b/drivers/xen/xen-pciback/conf_space.h
42780 @@ -44,15 +44,15 @@ struct config_field {
42781 struct {
42782 conf_dword_write write;
42783 conf_dword_read read;
42784 - } dw;
42785 + } __no_const dw;
42786 struct {
42787 conf_word_write write;
42788 conf_word_read read;
42789 - } w;
42790 + } __no_const w;
42791 struct {
42792 conf_byte_write write;
42793 conf_byte_read read;
42794 - } b;
42795 + } __no_const b;
42796 } u;
42797 struct list_head list;
42798 };
42799 diff --git a/drivers/xen/xenbus/xenbus_dev_frontend.c b/drivers/xen/xenbus/xenbus_dev_frontend.c
42800 index 89f7625..ac72702 100644
42801 --- a/drivers/xen/xenbus/xenbus_dev_frontend.c
42802 +++ b/drivers/xen/xenbus/xenbus_dev_frontend.c
42803 @@ -458,7 +458,7 @@ static ssize_t xenbus_file_write(struct file *filp,
42804 goto out;
42805
42806 /* Can't write a xenbus message larger we can buffer */
42807 - if ((len + u->len) > sizeof(u->u.buffer)) {
42808 + if (len > sizeof(u->u.buffer) - u->len) {
42809 /* On error, dump existing buffer */
42810 u->len = 0;
42811 rc = -EINVAL;
42812 diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
42813 index fef20db..d28b1ab 100644
42814 --- a/drivers/xen/xenfs/xenstored.c
42815 +++ b/drivers/xen/xenfs/xenstored.c
42816 @@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
42817 static int xsd_kva_open(struct inode *inode, struct file *file)
42818 {
42819 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
42820 +#ifdef CONFIG_GRKERNSEC_HIDESYM
42821 + NULL);
42822 +#else
42823 xen_store_interface);
42824 +#endif
42825 +
42826 if (!file->private_data)
42827 return -ENOMEM;
42828 return 0;
42829 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
42830 index cbf9dbb..35c3af7 100644
42831 --- a/fs/9p/vfs_inode.c
42832 +++ b/fs/9p/vfs_inode.c
42833 @@ -1329,7 +1329,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
42834 void
42835 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
42836 {
42837 - char *s = nd_get_link(nd);
42838 + const char *s = nd_get_link(nd);
42839
42840 p9_debug(P9_DEBUG_VFS, " %s %s\n",
42841 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
42842 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
42843 index 0225742..1cd4732 100644
42844 --- a/fs/Kconfig.binfmt
42845 +++ b/fs/Kconfig.binfmt
42846 @@ -89,7 +89,7 @@ config HAVE_AOUT
42847
42848 config BINFMT_AOUT
42849 tristate "Kernel support for a.out and ECOFF binaries"
42850 - depends on HAVE_AOUT
42851 + depends on HAVE_AOUT && BROKEN
42852 ---help---
42853 A.out (Assembler.OUTput) is a set of formats for libraries and
42854 executables used in the earliest versions of UNIX. Linux used
42855 diff --git a/fs/aio.c b/fs/aio.c
42856 index 71f613c..9d01f1f 100644
42857 --- a/fs/aio.c
42858 +++ b/fs/aio.c
42859 @@ -111,7 +111,7 @@ static int aio_setup_ring(struct kioctx *ctx)
42860 size += sizeof(struct io_event) * nr_events;
42861 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
42862
42863 - if (nr_pages < 0)
42864 + if (nr_pages <= 0)
42865 return -EINVAL;
42866
42867 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
42868 @@ -1373,18 +1373,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
42869 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
42870 {
42871 ssize_t ret;
42872 + struct iovec iovstack;
42873
42874 #ifdef CONFIG_COMPAT
42875 if (compat)
42876 ret = compat_rw_copy_check_uvector(type,
42877 (struct compat_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 else
42882 #endif
42883 ret = rw_copy_check_uvector(type,
42884 (struct iovec __user *)kiocb->ki_buf,
42885 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
42886 + kiocb->ki_nbytes, 1, &iovstack,
42887 &kiocb->ki_iovec);
42888 if (ret < 0)
42889 goto out;
42890 @@ -1393,6 +1394,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
42891 if (ret < 0)
42892 goto out;
42893
42894 + if (kiocb->ki_iovec == &iovstack) {
42895 + kiocb->ki_inline_vec = iovstack;
42896 + kiocb->ki_iovec = &kiocb->ki_inline_vec;
42897 + }
42898 kiocb->ki_nr_segs = kiocb->ki_nbytes;
42899 kiocb->ki_cur_seg = 0;
42900 /* ki_nbytes/left now reflect bytes instead of segs */
42901 diff --git a/fs/attr.c b/fs/attr.c
42902 index 29e38a1..2bc037b 100644
42903 --- a/fs/attr.c
42904 +++ b/fs/attr.c
42905 @@ -99,6 +99,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
42906 unsigned long limit;
42907
42908 limit = rlimit(RLIMIT_FSIZE);
42909 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
42910 if (limit != RLIM_INFINITY && offset > limit)
42911 goto out_sig;
42912 if (offset > inode->i_sb->s_maxbytes)
42913 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
42914 index da8876d..4456166 100644
42915 --- a/fs/autofs4/waitq.c
42916 +++ b/fs/autofs4/waitq.c
42917 @@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
42918 {
42919 unsigned long sigpipe, flags;
42920 mm_segment_t fs;
42921 - const char *data = (const char *)addr;
42922 + const char __user *data = (const char __force_user *)addr;
42923 ssize_t wr = 0;
42924
42925 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
42926 @@ -348,6 +348,10 @@ static int validate_request(struct autofs_wait_queue **wait,
42927 return 1;
42928 }
42929
42930 +#ifdef CONFIG_GRKERNSEC_HIDESYM
42931 +static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
42932 +#endif
42933 +
42934 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
42935 enum autofs_notify notify)
42936 {
42937 @@ -381,7 +385,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
42938
42939 /* If this is a direct mount request create a dummy name */
42940 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
42941 +#ifdef CONFIG_GRKERNSEC_HIDESYM
42942 + /* this name does get written to userland via autofs4_write() */
42943 + qstr.len = sprintf(name, "%08lx", atomic_inc_return_unchecked(&autofs_dummy_name_id));
42944 +#else
42945 qstr.len = sprintf(name, "%p", dentry);
42946 +#endif
42947 else {
42948 qstr.len = autofs4_getpath(sbi, dentry, &name);
42949 if (!qstr.len) {
42950 diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
42951 index cf7f3c6..f61080d 100644
42952 --- a/fs/befs/linuxvfs.c
42953 +++ b/fs/befs/linuxvfs.c
42954 @@ -502,7 +502,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
42955 {
42956 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
42957 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
42958 - char *link = nd_get_link(nd);
42959 + const char *link = nd_get_link(nd);
42960 if (!IS_ERR(link))
42961 kfree(link);
42962 }
42963 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
42964 index d146e18..12d1bd1 100644
42965 --- a/fs/binfmt_aout.c
42966 +++ b/fs/binfmt_aout.c
42967 @@ -16,6 +16,7 @@
42968 #include <linux/string.h>
42969 #include <linux/fs.h>
42970 #include <linux/file.h>
42971 +#include <linux/security.h>
42972 #include <linux/stat.h>
42973 #include <linux/fcntl.h>
42974 #include <linux/ptrace.h>
42975 @@ -83,6 +84,8 @@ static int aout_core_dump(struct coredump_params *cprm)
42976 #endif
42977 # define START_STACK(u) ((void __user *)u.start_stack)
42978
42979 + memset(&dump, 0, sizeof(dump));
42980 +
42981 fs = get_fs();
42982 set_fs(KERNEL_DS);
42983 has_dumped = 1;
42984 @@ -94,10 +97,12 @@ static int aout_core_dump(struct coredump_params *cprm)
42985
42986 /* If the size of the dump file exceeds the rlimit, then see what would happen
42987 if we wrote the stack, but not the data area. */
42988 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
42989 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
42990 dump.u_dsize = 0;
42991
42992 /* Make sure we have enough room to write the stack and data areas. */
42993 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
42994 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
42995 dump.u_ssize = 0;
42996
42997 @@ -231,6 +236,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42998 rlim = rlimit(RLIMIT_DATA);
42999 if (rlim >= RLIM_INFINITY)
43000 rlim = ~0;
43001 +
43002 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
43003 if (ex.a_data + ex.a_bss > rlim)
43004 return -ENOMEM;
43005
43006 @@ -265,6 +272,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
43007
43008 install_exec_creds(bprm);
43009
43010 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43011 + current->mm->pax_flags = 0UL;
43012 +#endif
43013 +
43014 +#ifdef CONFIG_PAX_PAGEEXEC
43015 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
43016 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
43017 +
43018 +#ifdef CONFIG_PAX_EMUTRAMP
43019 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
43020 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
43021 +#endif
43022 +
43023 +#ifdef CONFIG_PAX_MPROTECT
43024 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
43025 + current->mm->pax_flags |= MF_PAX_MPROTECT;
43026 +#endif
43027 +
43028 + }
43029 +#endif
43030 +
43031 if (N_MAGIC(ex) == OMAGIC) {
43032 unsigned long text_addr, map_size;
43033 loff_t pos;
43034 @@ -330,7 +358,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
43035 }
43036
43037 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
43038 - PROT_READ | PROT_WRITE | PROT_EXEC,
43039 + PROT_READ | PROT_WRITE,
43040 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
43041 fd_offset + ex.a_text);
43042 if (error != N_DATADDR(ex)) {
43043 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
43044 index 0225fdd..08bda99 100644
43045 --- a/fs/binfmt_elf.c
43046 +++ b/fs/binfmt_elf.c
43047 @@ -32,6 +32,7 @@
43048 #include <linux/elf.h>
43049 #include <linux/utsname.h>
43050 #include <linux/coredump.h>
43051 +#include <linux/xattr.h>
43052 #include <asm/uaccess.h>
43053 #include <asm/param.h>
43054 #include <asm/page.h>
43055 @@ -52,6 +53,10 @@ static int elf_core_dump(struct coredump_params *cprm);
43056 #define elf_core_dump NULL
43057 #endif
43058
43059 +#ifdef CONFIG_PAX_MPROTECT
43060 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
43061 +#endif
43062 +
43063 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
43064 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
43065 #else
43066 @@ -71,6 +76,11 @@ static struct linux_binfmt elf_format = {
43067 .load_binary = load_elf_binary,
43068 .load_shlib = load_elf_library,
43069 .core_dump = elf_core_dump,
43070 +
43071 +#ifdef CONFIG_PAX_MPROTECT
43072 + .handle_mprotect= elf_handle_mprotect,
43073 +#endif
43074 +
43075 .min_coredump = ELF_EXEC_PAGESIZE,
43076 };
43077
43078 @@ -78,6 +88,8 @@ static struct linux_binfmt elf_format = {
43079
43080 static int set_brk(unsigned long start, unsigned long end)
43081 {
43082 + unsigned long e = end;
43083 +
43084 start = ELF_PAGEALIGN(start);
43085 end = ELF_PAGEALIGN(end);
43086 if (end > start) {
43087 @@ -86,7 +98,7 @@ static int set_brk(unsigned long start, unsigned long end)
43088 if (BAD_ADDR(addr))
43089 return addr;
43090 }
43091 - current->mm->start_brk = current->mm->brk = end;
43092 + current->mm->start_brk = current->mm->brk = e;
43093 return 0;
43094 }
43095
43096 @@ -147,12 +159,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
43097 elf_addr_t __user *u_rand_bytes;
43098 const char *k_platform = ELF_PLATFORM;
43099 const char *k_base_platform = ELF_BASE_PLATFORM;
43100 - unsigned char k_rand_bytes[16];
43101 + u32 k_rand_bytes[4];
43102 int items;
43103 elf_addr_t *elf_info;
43104 int ei_index = 0;
43105 const struct cred *cred = current_cred();
43106 struct vm_area_struct *vma;
43107 + unsigned long saved_auxv[AT_VECTOR_SIZE];
43108
43109 /*
43110 * In some cases (e.g. Hyper-Threading), we want to avoid L1
43111 @@ -194,8 +207,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
43112 * Generate 16 random bytes for userspace PRNG seeding.
43113 */
43114 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
43115 - u_rand_bytes = (elf_addr_t __user *)
43116 - STACK_ALLOC(p, sizeof(k_rand_bytes));
43117 + srandom32(k_rand_bytes[0] ^ random32());
43118 + srandom32(k_rand_bytes[1] ^ random32());
43119 + srandom32(k_rand_bytes[2] ^ random32());
43120 + srandom32(k_rand_bytes[3] ^ random32());
43121 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
43122 + u_rand_bytes = (elf_addr_t __user *) p;
43123 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
43124 return -EFAULT;
43125
43126 @@ -307,9 +324,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
43127 return -EFAULT;
43128 current->mm->env_end = p;
43129
43130 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
43131 +
43132 /* Put the elf_info on the stack in the right place. */
43133 sp = (elf_addr_t __user *)envp + 1;
43134 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
43135 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
43136 return -EFAULT;
43137 return 0;
43138 }
43139 @@ -373,15 +392,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
43140 an ELF header */
43141
43142 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
43143 - struct file *interpreter, unsigned long *interp_map_addr,
43144 - unsigned long no_base)
43145 + struct file *interpreter, unsigned long no_base)
43146 {
43147 struct elf_phdr *elf_phdata;
43148 struct elf_phdr *eppnt;
43149 - unsigned long load_addr = 0;
43150 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
43151 int load_addr_set = 0;
43152 unsigned long last_bss = 0, elf_bss = 0;
43153 - unsigned long error = ~0UL;
43154 + unsigned long error = -EINVAL;
43155 unsigned long total_size;
43156 int retval, i, size;
43157
43158 @@ -427,6 +445,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
43159 goto out_close;
43160 }
43161
43162 +#ifdef CONFIG_PAX_SEGMEXEC
43163 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
43164 + pax_task_size = SEGMEXEC_TASK_SIZE;
43165 +#endif
43166 +
43167 eppnt = elf_phdata;
43168 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
43169 if (eppnt->p_type == PT_LOAD) {
43170 @@ -450,8 +473,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
43171 map_addr = elf_map(interpreter, load_addr + vaddr,
43172 eppnt, elf_prot, elf_type, total_size);
43173 total_size = 0;
43174 - if (!*interp_map_addr)
43175 - *interp_map_addr = map_addr;
43176 error = map_addr;
43177 if (BAD_ADDR(map_addr))
43178 goto out_close;
43179 @@ -470,8 +491,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
43180 k = load_addr + eppnt->p_vaddr;
43181 if (BAD_ADDR(k) ||
43182 eppnt->p_filesz > eppnt->p_memsz ||
43183 - eppnt->p_memsz > TASK_SIZE ||
43184 - TASK_SIZE - eppnt->p_memsz < k) {
43185 + eppnt->p_memsz > pax_task_size ||
43186 + pax_task_size - eppnt->p_memsz < k) {
43187 error = -ENOMEM;
43188 goto out_close;
43189 }
43190 @@ -523,6 +544,311 @@ out:
43191 return error;
43192 }
43193
43194 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
43195 +#ifdef CONFIG_PAX_SOFTMODE
43196 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
43197 +{
43198 + unsigned long pax_flags = 0UL;
43199 +
43200 +#ifdef CONFIG_PAX_PAGEEXEC
43201 + if (elf_phdata->p_flags & PF_PAGEEXEC)
43202 + pax_flags |= MF_PAX_PAGEEXEC;
43203 +#endif
43204 +
43205 +#ifdef CONFIG_PAX_SEGMEXEC
43206 + if (elf_phdata->p_flags & PF_SEGMEXEC)
43207 + pax_flags |= MF_PAX_SEGMEXEC;
43208 +#endif
43209 +
43210 +#ifdef CONFIG_PAX_EMUTRAMP
43211 + if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
43212 + pax_flags |= MF_PAX_EMUTRAMP;
43213 +#endif
43214 +
43215 +#ifdef CONFIG_PAX_MPROTECT
43216 + if (elf_phdata->p_flags & PF_MPROTECT)
43217 + pax_flags |= MF_PAX_MPROTECT;
43218 +#endif
43219 +
43220 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43221 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
43222 + pax_flags |= MF_PAX_RANDMMAP;
43223 +#endif
43224 +
43225 + return pax_flags;
43226 +}
43227 +#endif
43228 +
43229 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
43230 +{
43231 + unsigned long pax_flags = 0UL;
43232 +
43233 +#ifdef CONFIG_PAX_PAGEEXEC
43234 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
43235 + pax_flags |= MF_PAX_PAGEEXEC;
43236 +#endif
43237 +
43238 +#ifdef CONFIG_PAX_SEGMEXEC
43239 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
43240 + pax_flags |= MF_PAX_SEGMEXEC;
43241 +#endif
43242 +
43243 +#ifdef CONFIG_PAX_EMUTRAMP
43244 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
43245 + pax_flags |= MF_PAX_EMUTRAMP;
43246 +#endif
43247 +
43248 +#ifdef CONFIG_PAX_MPROTECT
43249 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
43250 + pax_flags |= MF_PAX_MPROTECT;
43251 +#endif
43252 +
43253 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43254 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
43255 + pax_flags |= MF_PAX_RANDMMAP;
43256 +#endif
43257 +
43258 + return pax_flags;
43259 +}
43260 +#endif
43261 +
43262 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
43263 +#ifdef CONFIG_PAX_SOFTMODE
43264 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
43265 +{
43266 + unsigned long pax_flags = 0UL;
43267 +
43268 +#ifdef CONFIG_PAX_PAGEEXEC
43269 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
43270 + pax_flags |= MF_PAX_PAGEEXEC;
43271 +#endif
43272 +
43273 +#ifdef CONFIG_PAX_SEGMEXEC
43274 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
43275 + pax_flags |= MF_PAX_SEGMEXEC;
43276 +#endif
43277 +
43278 +#ifdef CONFIG_PAX_EMUTRAMP
43279 + if (pax_flags_softmode & MF_PAX_EMUTRAMP)
43280 + pax_flags |= MF_PAX_EMUTRAMP;
43281 +#endif
43282 +
43283 +#ifdef CONFIG_PAX_MPROTECT
43284 + if (pax_flags_softmode & MF_PAX_MPROTECT)
43285 + pax_flags |= MF_PAX_MPROTECT;
43286 +#endif
43287 +
43288 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43289 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
43290 + pax_flags |= MF_PAX_RANDMMAP;
43291 +#endif
43292 +
43293 + return pax_flags;
43294 +}
43295 +#endif
43296 +
43297 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
43298 +{
43299 + unsigned long pax_flags = 0UL;
43300 +
43301 +#ifdef CONFIG_PAX_PAGEEXEC
43302 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
43303 + pax_flags |= MF_PAX_PAGEEXEC;
43304 +#endif
43305 +
43306 +#ifdef CONFIG_PAX_SEGMEXEC
43307 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
43308 + pax_flags |= MF_PAX_SEGMEXEC;
43309 +#endif
43310 +
43311 +#ifdef CONFIG_PAX_EMUTRAMP
43312 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
43313 + pax_flags |= MF_PAX_EMUTRAMP;
43314 +#endif
43315 +
43316 +#ifdef CONFIG_PAX_MPROTECT
43317 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
43318 + pax_flags |= MF_PAX_MPROTECT;
43319 +#endif
43320 +
43321 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43322 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
43323 + pax_flags |= MF_PAX_RANDMMAP;
43324 +#endif
43325 +
43326 + return pax_flags;
43327 +}
43328 +#endif
43329 +
43330 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43331 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
43332 +{
43333 + unsigned long pax_flags = 0UL;
43334 +
43335 +#ifdef CONFIG_PAX_EI_PAX
43336 +
43337 +#ifdef CONFIG_PAX_PAGEEXEC
43338 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
43339 + pax_flags |= MF_PAX_PAGEEXEC;
43340 +#endif
43341 +
43342 +#ifdef CONFIG_PAX_SEGMEXEC
43343 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
43344 + pax_flags |= MF_PAX_SEGMEXEC;
43345 +#endif
43346 +
43347 +#ifdef CONFIG_PAX_EMUTRAMP
43348 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
43349 + pax_flags |= MF_PAX_EMUTRAMP;
43350 +#endif
43351 +
43352 +#ifdef CONFIG_PAX_MPROTECT
43353 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
43354 + pax_flags |= MF_PAX_MPROTECT;
43355 +#endif
43356 +
43357 +#ifdef CONFIG_PAX_ASLR
43358 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
43359 + pax_flags |= MF_PAX_RANDMMAP;
43360 +#endif
43361 +
43362 +#else
43363 +
43364 +#ifdef CONFIG_PAX_PAGEEXEC
43365 + pax_flags |= MF_PAX_PAGEEXEC;
43366 +#endif
43367 +
43368 +#ifdef CONFIG_PAX_SEGMEXEC
43369 + pax_flags |= MF_PAX_SEGMEXEC;
43370 +#endif
43371 +
43372 +#ifdef CONFIG_PAX_MPROTECT
43373 + pax_flags |= MF_PAX_MPROTECT;
43374 +#endif
43375 +
43376 +#ifdef CONFIG_PAX_RANDMMAP
43377 + if (randomize_va_space)
43378 + pax_flags |= MF_PAX_RANDMMAP;
43379 +#endif
43380 +
43381 +#endif
43382 +
43383 + return pax_flags;
43384 +}
43385 +
43386 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
43387 +{
43388 +
43389 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
43390 + unsigned long i;
43391 +
43392 + for (i = 0UL; i < elf_ex->e_phnum; i++)
43393 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
43394 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
43395 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
43396 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
43397 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
43398 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
43399 + return ~0UL;
43400 +
43401 +#ifdef CONFIG_PAX_SOFTMODE
43402 + if (pax_softmode)
43403 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
43404 + else
43405 +#endif
43406 +
43407 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
43408 + break;
43409 + }
43410 +#endif
43411 +
43412 + return ~0UL;
43413 +}
43414 +
43415 +static unsigned long pax_parse_xattr_pax(struct file * const file)
43416 +{
43417 +
43418 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
43419 + ssize_t xattr_size, i;
43420 + unsigned char xattr_value[5];
43421 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
43422 +
43423 + xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
43424 + if (xattr_size <= 0)
43425 + return ~0UL;
43426 +
43427 + for (i = 0; i < xattr_size; i++)
43428 + switch (xattr_value[i]) {
43429 + default:
43430 + return ~0UL;
43431 +
43432 +#define parse_flag(option1, option2, flag) \
43433 + case option1: \
43434 + pax_flags_hardmode |= MF_PAX_##flag; \
43435 + break; \
43436 + case option2: \
43437 + pax_flags_softmode |= MF_PAX_##flag; \
43438 + break;
43439 +
43440 + parse_flag('p', 'P', PAGEEXEC);
43441 + parse_flag('e', 'E', EMUTRAMP);
43442 + parse_flag('m', 'M', MPROTECT);
43443 + parse_flag('r', 'R', RANDMMAP);
43444 + parse_flag('s', 'S', SEGMEXEC);
43445 +
43446 +#undef parse_flag
43447 + }
43448 +
43449 + if (pax_flags_hardmode & pax_flags_softmode)
43450 + return ~0UL;
43451 +
43452 +#ifdef CONFIG_PAX_SOFTMODE
43453 + if (pax_softmode)
43454 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
43455 + else
43456 +#endif
43457 +
43458 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
43459 +#else
43460 + return ~0UL;
43461 +#endif
43462 +
43463 +}
43464 +
43465 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
43466 +{
43467 + unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
43468 +
43469 + pax_flags = pax_parse_ei_pax(elf_ex);
43470 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
43471 + xattr_pax_flags = pax_parse_xattr_pax(file);
43472 +
43473 + if (pt_pax_flags == ~0UL)
43474 + pt_pax_flags = xattr_pax_flags;
43475 + else if (xattr_pax_flags == ~0UL)
43476 + xattr_pax_flags = pt_pax_flags;
43477 + if (pt_pax_flags != xattr_pax_flags)
43478 + return -EINVAL;
43479 + if (pt_pax_flags != ~0UL)
43480 + pax_flags = pt_pax_flags;
43481 +
43482 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
43483 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43484 + if ((__supported_pte_mask & _PAGE_NX))
43485 + pax_flags &= ~MF_PAX_SEGMEXEC;
43486 + else
43487 + pax_flags &= ~MF_PAX_PAGEEXEC;
43488 + }
43489 +#endif
43490 +
43491 + if (0 > pax_check_flags(&pax_flags))
43492 + return -EINVAL;
43493 +
43494 + current->mm->pax_flags = pax_flags;
43495 + return 0;
43496 +}
43497 +#endif
43498 +
43499 /*
43500 * These are the functions used to load ELF style executables and shared
43501 * libraries. There is no binary dependent code anywhere else.
43502 @@ -539,6 +865,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
43503 {
43504 unsigned int random_variable = 0;
43505
43506 +#ifdef CONFIG_PAX_RANDUSTACK
43507 + if (randomize_va_space)
43508 + return stack_top - current->mm->delta_stack;
43509 +#endif
43510 +
43511 if ((current->flags & PF_RANDOMIZE) &&
43512 !(current->personality & ADDR_NO_RANDOMIZE)) {
43513 random_variable = get_random_int() & STACK_RND_MASK;
43514 @@ -557,7 +888,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43515 unsigned long load_addr = 0, load_bias = 0;
43516 int load_addr_set = 0;
43517 char * elf_interpreter = NULL;
43518 - unsigned long error;
43519 + unsigned long error = 0;
43520 struct elf_phdr *elf_ppnt, *elf_phdata;
43521 unsigned long elf_bss, elf_brk;
43522 int retval, i;
43523 @@ -567,11 +898,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43524 unsigned long start_code, end_code, start_data, end_data;
43525 unsigned long reloc_func_desc __maybe_unused = 0;
43526 int executable_stack = EXSTACK_DEFAULT;
43527 - unsigned long def_flags = 0;
43528 struct {
43529 struct elfhdr elf_ex;
43530 struct elfhdr interp_elf_ex;
43531 } *loc;
43532 + unsigned long pax_task_size = TASK_SIZE;
43533
43534 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
43535 if (!loc) {
43536 @@ -707,11 +1038,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43537 goto out_free_dentry;
43538
43539 /* OK, This is the point of no return */
43540 - current->mm->def_flags = def_flags;
43541 +
43542 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43543 + current->mm->pax_flags = 0UL;
43544 +#endif
43545 +
43546 +#ifdef CONFIG_PAX_DLRESOLVE
43547 + current->mm->call_dl_resolve = 0UL;
43548 +#endif
43549 +
43550 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
43551 + current->mm->call_syscall = 0UL;
43552 +#endif
43553 +
43554 +#ifdef CONFIG_PAX_ASLR
43555 + current->mm->delta_mmap = 0UL;
43556 + current->mm->delta_stack = 0UL;
43557 +#endif
43558 +
43559 + current->mm->def_flags = 0;
43560 +
43561 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43562 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
43563 + send_sig(SIGKILL, current, 0);
43564 + goto out_free_dentry;
43565 + }
43566 +#endif
43567 +
43568 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
43569 + pax_set_initial_flags(bprm);
43570 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
43571 + if (pax_set_initial_flags_func)
43572 + (pax_set_initial_flags_func)(bprm);
43573 +#endif
43574 +
43575 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
43576 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
43577 + current->mm->context.user_cs_limit = PAGE_SIZE;
43578 + current->mm->def_flags |= VM_PAGEEXEC;
43579 + }
43580 +#endif
43581 +
43582 +#ifdef CONFIG_PAX_SEGMEXEC
43583 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
43584 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
43585 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
43586 + pax_task_size = SEGMEXEC_TASK_SIZE;
43587 + current->mm->def_flags |= VM_NOHUGEPAGE;
43588 + }
43589 +#endif
43590 +
43591 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
43592 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43593 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
43594 + put_cpu();
43595 + }
43596 +#endif
43597
43598 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
43599 may depend on the personality. */
43600 SET_PERSONALITY(loc->elf_ex);
43601 +
43602 +#ifdef CONFIG_PAX_ASLR
43603 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
43604 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
43605 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
43606 + }
43607 +#endif
43608 +
43609 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
43610 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43611 + executable_stack = EXSTACK_DISABLE_X;
43612 + current->personality &= ~READ_IMPLIES_EXEC;
43613 + } else
43614 +#endif
43615 +
43616 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
43617 current->personality |= READ_IMPLIES_EXEC;
43618
43619 @@ -802,6 +1203,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43620 #else
43621 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
43622 #endif
43623 +
43624 +#ifdef CONFIG_PAX_RANDMMAP
43625 + /* PaX: randomize base address at the default exe base if requested */
43626 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
43627 +#ifdef CONFIG_SPARC64
43628 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
43629 +#else
43630 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
43631 +#endif
43632 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
43633 + elf_flags |= MAP_FIXED;
43634 + }
43635 +#endif
43636 +
43637 }
43638
43639 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
43640 @@ -834,9 +1249,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43641 * allowed task size. Note that p_filesz must always be
43642 * <= p_memsz so it is only necessary to check p_memsz.
43643 */
43644 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
43645 - elf_ppnt->p_memsz > TASK_SIZE ||
43646 - TASK_SIZE - elf_ppnt->p_memsz < k) {
43647 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
43648 + elf_ppnt->p_memsz > pax_task_size ||
43649 + pax_task_size - elf_ppnt->p_memsz < k) {
43650 /* set_brk can never work. Avoid overflows. */
43651 send_sig(SIGKILL, current, 0);
43652 retval = -EINVAL;
43653 @@ -875,17 +1290,44 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43654 goto out_free_dentry;
43655 }
43656 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
43657 - send_sig(SIGSEGV, current, 0);
43658 - retval = -EFAULT; /* Nobody gets to see this, but.. */
43659 - goto out_free_dentry;
43660 + /*
43661 + * This bss-zeroing can fail if the ELF
43662 + * file specifies odd protections. So
43663 + * we don't check the return value
43664 + */
43665 }
43666
43667 +#ifdef CONFIG_PAX_RANDMMAP
43668 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
43669 + unsigned long start, size;
43670 +
43671 + start = ELF_PAGEALIGN(elf_brk);
43672 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
43673 + down_read(&current->mm->mmap_sem);
43674 + retval = -ENOMEM;
43675 + if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
43676 + unsigned long prot = PROT_NONE;
43677 +
43678 + up_read(&current->mm->mmap_sem);
43679 + current->mm->brk_gap = PAGE_ALIGN(size) >> PAGE_SHIFT;
43680 +// if (current->personality & ADDR_NO_RANDOMIZE)
43681 +// prot = PROT_READ;
43682 + start = vm_mmap(NULL, start, size, prot, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
43683 + retval = IS_ERR_VALUE(start) ? start : 0;
43684 + } else
43685 + up_read(&current->mm->mmap_sem);
43686 + if (retval == 0)
43687 + retval = set_brk(start + size, start + size + PAGE_SIZE);
43688 + if (retval < 0) {
43689 + send_sig(SIGKILL, current, 0);
43690 + goto out_free_dentry;
43691 + }
43692 + }
43693 +#endif
43694 +
43695 if (elf_interpreter) {
43696 - unsigned long uninitialized_var(interp_map_addr);
43697 -
43698 elf_entry = load_elf_interp(&loc->interp_elf_ex,
43699 interpreter,
43700 - &interp_map_addr,
43701 load_bias);
43702 if (!IS_ERR((void *)elf_entry)) {
43703 /*
43704 @@ -1107,7 +1549,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
43705 * Decide what to dump of a segment, part, all or none.
43706 */
43707 static unsigned long vma_dump_size(struct vm_area_struct *vma,
43708 - unsigned long mm_flags)
43709 + unsigned long mm_flags, long signr)
43710 {
43711 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
43712
43713 @@ -1144,7 +1586,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
43714 if (vma->vm_file == NULL)
43715 return 0;
43716
43717 - if (FILTER(MAPPED_PRIVATE))
43718 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
43719 goto whole;
43720
43721 /*
43722 @@ -1366,9 +1808,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
43723 {
43724 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
43725 int i = 0;
43726 - do
43727 + do {
43728 i += 2;
43729 - while (auxv[i - 2] != AT_NULL);
43730 + } while (auxv[i - 2] != AT_NULL);
43731 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
43732 }
43733
43734 @@ -1879,14 +2321,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
43735 }
43736
43737 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
43738 - unsigned long mm_flags)
43739 + struct coredump_params *cprm)
43740 {
43741 struct vm_area_struct *vma;
43742 size_t size = 0;
43743
43744 for (vma = first_vma(current, gate_vma); vma != NULL;
43745 vma = next_vma(vma, gate_vma))
43746 - size += vma_dump_size(vma, mm_flags);
43747 + size += vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43748 return size;
43749 }
43750
43751 @@ -1980,7 +2422,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43752
43753 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
43754
43755 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
43756 + offset += elf_core_vma_data_size(gate_vma, cprm);
43757 offset += elf_core_extra_data_size();
43758 e_shoff = offset;
43759
43760 @@ -1994,10 +2436,12 @@ static int elf_core_dump(struct coredump_params *cprm)
43761 offset = dataoff;
43762
43763 size += sizeof(*elf);
43764 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43765 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
43766 goto end_coredump;
43767
43768 size += sizeof(*phdr4note);
43769 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43770 if (size > cprm->limit
43771 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
43772 goto end_coredump;
43773 @@ -2011,7 +2455,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43774 phdr.p_offset = offset;
43775 phdr.p_vaddr = vma->vm_start;
43776 phdr.p_paddr = 0;
43777 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
43778 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43779 phdr.p_memsz = vma->vm_end - vma->vm_start;
43780 offset += phdr.p_filesz;
43781 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
43782 @@ -2022,6 +2466,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43783 phdr.p_align = ELF_EXEC_PAGESIZE;
43784
43785 size += sizeof(phdr);
43786 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43787 if (size > cprm->limit
43788 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
43789 goto end_coredump;
43790 @@ -2046,7 +2491,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43791 unsigned long addr;
43792 unsigned long end;
43793
43794 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
43795 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43796
43797 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
43798 struct page *page;
43799 @@ -2055,6 +2500,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43800 page = get_dump_page(addr);
43801 if (page) {
43802 void *kaddr = kmap(page);
43803 + gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
43804 stop = ((size += PAGE_SIZE) > cprm->limit) ||
43805 !dump_write(cprm->file, kaddr,
43806 PAGE_SIZE);
43807 @@ -2072,6 +2518,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43808
43809 if (e_phnum == PN_XNUM) {
43810 size += sizeof(*shdr4extnum);
43811 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43812 if (size > cprm->limit
43813 || !dump_write(cprm->file, shdr4extnum,
43814 sizeof(*shdr4extnum)))
43815 @@ -2092,6 +2539,97 @@ out:
43816
43817 #endif /* CONFIG_ELF_CORE */
43818
43819 +#ifdef CONFIG_PAX_MPROTECT
43820 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
43821 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
43822 + * we'll remove VM_MAYWRITE for good on RELRO segments.
43823 + *
43824 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
43825 + * basis because we want to allow the common case and not the special ones.
43826 + */
43827 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
43828 +{
43829 + struct elfhdr elf_h;
43830 + struct elf_phdr elf_p;
43831 + unsigned long i;
43832 + unsigned long oldflags;
43833 + bool is_textrel_rw, is_textrel_rx, is_relro;
43834 +
43835 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
43836 + return;
43837 +
43838 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
43839 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
43840 +
43841 +#ifdef CONFIG_PAX_ELFRELOCS
43842 + /* possible TEXTREL */
43843 + is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
43844 + 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);
43845 +#else
43846 + is_textrel_rw = false;
43847 + is_textrel_rx = false;
43848 +#endif
43849 +
43850 + /* possible RELRO */
43851 + is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
43852 +
43853 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
43854 + return;
43855 +
43856 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
43857 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
43858 +
43859 +#ifdef CONFIG_PAX_ETEXECRELOCS
43860 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
43861 +#else
43862 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
43863 +#endif
43864 +
43865 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
43866 + !elf_check_arch(&elf_h) ||
43867 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
43868 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
43869 + return;
43870 +
43871 + for (i = 0UL; i < elf_h.e_phnum; i++) {
43872 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
43873 + return;
43874 + switch (elf_p.p_type) {
43875 + case PT_DYNAMIC:
43876 + if (!is_textrel_rw && !is_textrel_rx)
43877 + continue;
43878 + i = 0UL;
43879 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
43880 + elf_dyn dyn;
43881 +
43882 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
43883 + return;
43884 + if (dyn.d_tag == DT_NULL)
43885 + return;
43886 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
43887 + gr_log_textrel(vma);
43888 + if (is_textrel_rw)
43889 + vma->vm_flags |= VM_MAYWRITE;
43890 + else
43891 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
43892 + vma->vm_flags &= ~VM_MAYWRITE;
43893 + return;
43894 + }
43895 + i++;
43896 + }
43897 + return;
43898 +
43899 + case PT_GNU_RELRO:
43900 + if (!is_relro)
43901 + continue;
43902 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
43903 + vma->vm_flags &= ~VM_MAYWRITE;
43904 + return;
43905 + }
43906 + }
43907 +}
43908 +#endif
43909 +
43910 static int __init init_elf_binfmt(void)
43911 {
43912 register_binfmt(&elf_format);
43913 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
43914 index 178cb70..8972997 100644
43915 --- a/fs/binfmt_flat.c
43916 +++ b/fs/binfmt_flat.c
43917 @@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
43918 realdatastart = (unsigned long) -ENOMEM;
43919 printk("Unable to allocate RAM for process data, errno %d\n",
43920 (int)-realdatastart);
43921 + down_write(&current->mm->mmap_sem);
43922 vm_munmap(textpos, text_len);
43923 + up_write(&current->mm->mmap_sem);
43924 ret = realdatastart;
43925 goto err;
43926 }
43927 @@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
43928 }
43929 if (IS_ERR_VALUE(result)) {
43930 printk("Unable to read data+bss, errno %d\n", (int)-result);
43931 + down_write(&current->mm->mmap_sem);
43932 vm_munmap(textpos, text_len);
43933 vm_munmap(realdatastart, len);
43934 + up_write(&current->mm->mmap_sem);
43935 ret = result;
43936 goto err;
43937 }
43938 @@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
43939 }
43940 if (IS_ERR_VALUE(result)) {
43941 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
43942 + down_write(&current->mm->mmap_sem);
43943 vm_munmap(textpos, text_len + data_len + extra +
43944 MAX_SHARED_LIBS * sizeof(unsigned long));
43945 + up_write(&current->mm->mmap_sem);
43946 ret = result;
43947 goto err;
43948 }
43949 diff --git a/fs/bio.c b/fs/bio.c
43950 index 71072ab..439851b 100644
43951 --- a/fs/bio.c
43952 +++ b/fs/bio.c
43953 @@ -842,7 +842,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
43954 /*
43955 * Overflow, abort
43956 */
43957 - if (end < start)
43958 + if (end < start || end - start > INT_MAX - nr_pages)
43959 return ERR_PTR(-EINVAL);
43960
43961 nr_pages += end - start;
43962 @@ -976,7 +976,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
43963 /*
43964 * Overflow, abort
43965 */
43966 - if (end < start)
43967 + if (end < start || end - start > INT_MAX - nr_pages)
43968 return ERR_PTR(-EINVAL);
43969
43970 nr_pages += end - start;
43971 @@ -1238,7 +1238,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
43972 const int read = bio_data_dir(bio) == READ;
43973 struct bio_map_data *bmd = bio->bi_private;
43974 int i;
43975 - char *p = bmd->sgvecs[0].iov_base;
43976 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
43977
43978 __bio_for_each_segment(bvec, bio, i, 0) {
43979 char *addr = page_address(bvec->bv_page);
43980 diff --git a/fs/block_dev.c b/fs/block_dev.c
43981 index 38e721b..7a9c5bc 100644
43982 --- a/fs/block_dev.c
43983 +++ b/fs/block_dev.c
43984 @@ -704,7 +704,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
43985 else if (bdev->bd_contains == bdev)
43986 return true; /* is a whole device which isn't held */
43987
43988 - else if (whole->bd_holder == bd_may_claim)
43989 + else if (whole->bd_holder == (void *)bd_may_claim)
43990 return true; /* is a partition of a device that is being partitioned */
43991 else if (whole->bd_holder != NULL)
43992 return false; /* is a partition of a held device */
43993 diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
43994 index 9197e2e..7f731f8 100644
43995 --- a/fs/btrfs/check-integrity.c
43996 +++ b/fs/btrfs/check-integrity.c
43997 @@ -155,7 +155,7 @@ struct btrfsic_block {
43998 union {
43999 bio_end_io_t *bio;
44000 bh_end_io_t *bh;
44001 - } orig_bio_bh_end_io;
44002 + } __no_const orig_bio_bh_end_io;
44003 int submit_bio_bh_rw;
44004 u64 flush_gen; /* only valid if !never_written */
44005 };
44006 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
44007 index 6d183f6..f47cc7a 100644
44008 --- a/fs/btrfs/ctree.c
44009 +++ b/fs/btrfs/ctree.c
44010 @@ -1037,9 +1037,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
44011 free_extent_buffer(buf);
44012 add_root_to_dirty_list(root);
44013 } else {
44014 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
44015 - parent_start = parent->start;
44016 - else
44017 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
44018 + if (parent)
44019 + parent_start = parent->start;
44020 + else
44021 + parent_start = 0;
44022 + } else
44023 parent_start = 0;
44024
44025 WARN_ON(trans->transid != btrfs_header_generation(parent));
44026 diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
44027 index ec154f9..bf617a7 100644
44028 --- a/fs/btrfs/inode.c
44029 +++ b/fs/btrfs/inode.c
44030 @@ -7126,7 +7126,7 @@ fail:
44031 return -ENOMEM;
44032 }
44033
44034 -static int btrfs_getattr(struct vfsmount *mnt,
44035 +int btrfs_getattr(struct vfsmount *mnt,
44036 struct dentry *dentry, struct kstat *stat)
44037 {
44038 struct inode *inode = dentry->d_inode;
44039 @@ -7140,6 +7140,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
44040 return 0;
44041 }
44042
44043 +EXPORT_SYMBOL(btrfs_getattr);
44044 +
44045 +dev_t get_btrfs_dev_from_inode(struct inode *inode)
44046 +{
44047 + return BTRFS_I(inode)->root->anon_dev;
44048 +}
44049 +EXPORT_SYMBOL(get_btrfs_dev_from_inode);
44050 +
44051 /*
44052 * If a file is moved, it will inherit the cow and compression flags of the new
44053 * directory.
44054 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
44055 index 9df50fa..6cd20d0 100644
44056 --- a/fs/btrfs/ioctl.c
44057 +++ b/fs/btrfs/ioctl.c
44058 @@ -2942,9 +2942,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
44059 for (i = 0; i < num_types; i++) {
44060 struct btrfs_space_info *tmp;
44061
44062 + /* Don't copy in more than we allocated */
44063 if (!slot_count)
44064 break;
44065
44066 + slot_count--;
44067 +
44068 info = NULL;
44069 rcu_read_lock();
44070 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
44071 @@ -2966,10 +2969,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
44072 memcpy(dest, &space, sizeof(space));
44073 dest++;
44074 space_args.total_spaces++;
44075 - slot_count--;
44076 }
44077 - if (!slot_count)
44078 - break;
44079 }
44080 up_read(&info->groups_sem);
44081 }
44082 diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
44083 index 4da0865..01c4778 100644
44084 --- a/fs/btrfs/relocation.c
44085 +++ b/fs/btrfs/relocation.c
44086 @@ -1269,7 +1269,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
44087 }
44088 spin_unlock(&rc->reloc_root_tree.lock);
44089
44090 - BUG_ON((struct btrfs_root *)node->data != root);
44091 + BUG_ON(!node || (struct btrfs_root *)node->data != root);
44092
44093 if (!del) {
44094 spin_lock(&rc->reloc_root_tree.lock);
44095 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
44096 index 622f469..e8d2d55 100644
44097 --- a/fs/cachefiles/bind.c
44098 +++ b/fs/cachefiles/bind.c
44099 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
44100 args);
44101
44102 /* start by checking things over */
44103 - ASSERT(cache->fstop_percent >= 0 &&
44104 - cache->fstop_percent < cache->fcull_percent &&
44105 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
44106 cache->fcull_percent < cache->frun_percent &&
44107 cache->frun_percent < 100);
44108
44109 - ASSERT(cache->bstop_percent >= 0 &&
44110 - cache->bstop_percent < cache->bcull_percent &&
44111 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
44112 cache->bcull_percent < cache->brun_percent &&
44113 cache->brun_percent < 100);
44114
44115 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
44116 index 0a1467b..6a53245 100644
44117 --- a/fs/cachefiles/daemon.c
44118 +++ b/fs/cachefiles/daemon.c
44119 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
44120 if (n > buflen)
44121 return -EMSGSIZE;
44122
44123 - if (copy_to_user(_buffer, buffer, n) != 0)
44124 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
44125 return -EFAULT;
44126
44127 return n;
44128 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
44129 if (test_bit(CACHEFILES_DEAD, &cache->flags))
44130 return -EIO;
44131
44132 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
44133 + if (datalen > PAGE_SIZE - 1)
44134 return -EOPNOTSUPP;
44135
44136 /* drag the command string into the kernel so we can parse it */
44137 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
44138 if (args[0] != '%' || args[1] != '\0')
44139 return -EINVAL;
44140
44141 - if (fstop < 0 || fstop >= cache->fcull_percent)
44142 + if (fstop >= cache->fcull_percent)
44143 return cachefiles_daemon_range_error(cache, args);
44144
44145 cache->fstop_percent = fstop;
44146 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
44147 if (args[0] != '%' || args[1] != '\0')
44148 return -EINVAL;
44149
44150 - if (bstop < 0 || bstop >= cache->bcull_percent)
44151 + if (bstop >= cache->bcull_percent)
44152 return cachefiles_daemon_range_error(cache, args);
44153
44154 cache->bstop_percent = bstop;
44155 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
44156 index bd6bc1b..b627b53 100644
44157 --- a/fs/cachefiles/internal.h
44158 +++ b/fs/cachefiles/internal.h
44159 @@ -57,7 +57,7 @@ struct cachefiles_cache {
44160 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
44161 struct rb_root active_nodes; /* active nodes (can't be culled) */
44162 rwlock_t active_lock; /* lock for active_nodes */
44163 - atomic_t gravecounter; /* graveyard uniquifier */
44164 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
44165 unsigned frun_percent; /* when to stop culling (% files) */
44166 unsigned fcull_percent; /* when to start culling (% files) */
44167 unsigned fstop_percent; /* when to stop allocating (% files) */
44168 @@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
44169 * proc.c
44170 */
44171 #ifdef CONFIG_CACHEFILES_HISTOGRAM
44172 -extern atomic_t cachefiles_lookup_histogram[HZ];
44173 -extern atomic_t cachefiles_mkdir_histogram[HZ];
44174 -extern atomic_t cachefiles_create_histogram[HZ];
44175 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
44176 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
44177 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
44178
44179 extern int __init cachefiles_proc_init(void);
44180 extern void cachefiles_proc_cleanup(void);
44181 static inline
44182 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
44183 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
44184 {
44185 unsigned long jif = jiffies - start_jif;
44186 if (jif >= HZ)
44187 jif = HZ - 1;
44188 - atomic_inc(&histogram[jif]);
44189 + atomic_inc_unchecked(&histogram[jif]);
44190 }
44191
44192 #else
44193 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
44194 index b0b5f7c..039bb26 100644
44195 --- a/fs/cachefiles/namei.c
44196 +++ b/fs/cachefiles/namei.c
44197 @@ -318,7 +318,7 @@ try_again:
44198 /* first step is to make up a grave dentry in the graveyard */
44199 sprintf(nbuffer, "%08x%08x",
44200 (uint32_t) get_seconds(),
44201 - (uint32_t) atomic_inc_return(&cache->gravecounter));
44202 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
44203
44204 /* do the multiway lock magic */
44205 trap = lock_rename(cache->graveyard, dir);
44206 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
44207 index eccd339..4c1d995 100644
44208 --- a/fs/cachefiles/proc.c
44209 +++ b/fs/cachefiles/proc.c
44210 @@ -14,9 +14,9 @@
44211 #include <linux/seq_file.h>
44212 #include "internal.h"
44213
44214 -atomic_t cachefiles_lookup_histogram[HZ];
44215 -atomic_t cachefiles_mkdir_histogram[HZ];
44216 -atomic_t cachefiles_create_histogram[HZ];
44217 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
44218 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
44219 +atomic_unchecked_t cachefiles_create_histogram[HZ];
44220
44221 /*
44222 * display the latency histogram
44223 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
44224 return 0;
44225 default:
44226 index = (unsigned long) v - 3;
44227 - x = atomic_read(&cachefiles_lookup_histogram[index]);
44228 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
44229 - z = atomic_read(&cachefiles_create_histogram[index]);
44230 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
44231 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
44232 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
44233 if (x == 0 && y == 0 && z == 0)
44234 return 0;
44235
44236 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
44237 index c994691..2a1537f 100644
44238 --- a/fs/cachefiles/rdwr.c
44239 +++ b/fs/cachefiles/rdwr.c
44240 @@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
44241 old_fs = get_fs();
44242 set_fs(KERNEL_DS);
44243 ret = file->f_op->write(
44244 - file, (const void __user *) data, len, &pos);
44245 + file, (const void __force_user *) data, len, &pos);
44246 set_fs(old_fs);
44247 kunmap(page);
44248 if (ret != len)
44249 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
44250 index e5b7731..b9c59fb 100644
44251 --- a/fs/ceph/dir.c
44252 +++ b/fs/ceph/dir.c
44253 @@ -243,7 +243,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
44254 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
44255 struct ceph_mds_client *mdsc = fsc->mdsc;
44256 unsigned frag = fpos_frag(filp->f_pos);
44257 - int off = fpos_off(filp->f_pos);
44258 + unsigned int off = fpos_off(filp->f_pos);
44259 int err;
44260 u32 ftype;
44261 struct ceph_mds_reply_info_parsed *rinfo;
44262 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
44263 index d9ea6ed..1e6c8ac 100644
44264 --- a/fs/cifs/cifs_debug.c
44265 +++ b/fs/cifs/cifs_debug.c
44266 @@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
44267
44268 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
44269 #ifdef CONFIG_CIFS_STATS2
44270 - atomic_set(&totBufAllocCount, 0);
44271 - atomic_set(&totSmBufAllocCount, 0);
44272 + atomic_set_unchecked(&totBufAllocCount, 0);
44273 + atomic_set_unchecked(&totSmBufAllocCount, 0);
44274 #endif /* CONFIG_CIFS_STATS2 */
44275 spin_lock(&cifs_tcp_ses_lock);
44276 list_for_each(tmp1, &cifs_tcp_ses_list) {
44277 @@ -281,7 +281,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
44278 tcon = list_entry(tmp3,
44279 struct cifs_tcon,
44280 tcon_list);
44281 - atomic_set(&tcon->num_smbs_sent, 0);
44282 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
44283 if (server->ops->clear_stats)
44284 server->ops->clear_stats(tcon);
44285 }
44286 @@ -313,8 +313,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
44287 smBufAllocCount.counter, cifs_min_small);
44288 #ifdef CONFIG_CIFS_STATS2
44289 seq_printf(m, "Total Large %d Small %d Allocations\n",
44290 - atomic_read(&totBufAllocCount),
44291 - atomic_read(&totSmBufAllocCount));
44292 + atomic_read_unchecked(&totBufAllocCount),
44293 + atomic_read_unchecked(&totSmBufAllocCount));
44294 #endif /* CONFIG_CIFS_STATS2 */
44295
44296 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
44297 @@ -343,7 +343,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
44298 if (tcon->need_reconnect)
44299 seq_puts(m, "\tDISCONNECTED ");
44300 seq_printf(m, "\nSMBs: %d",
44301 - atomic_read(&tcon->num_smbs_sent));
44302 + atomic_read_unchecked(&tcon->num_smbs_sent));
44303 if (server->ops->print_stats)
44304 server->ops->print_stats(m, tcon);
44305 }
44306 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
44307 index db8a404..c712e2e 100644
44308 --- a/fs/cifs/cifsfs.c
44309 +++ b/fs/cifs/cifsfs.c
44310 @@ -1003,7 +1003,7 @@ cifs_init_request_bufs(void)
44311 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
44312 cifs_req_cachep = kmem_cache_create("cifs_request",
44313 CIFSMaxBufSize + max_hdr_size, 0,
44314 - SLAB_HWCACHE_ALIGN, NULL);
44315 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
44316 if (cifs_req_cachep == NULL)
44317 return -ENOMEM;
44318
44319 @@ -1030,7 +1030,7 @@ cifs_init_request_bufs(void)
44320 efficient to alloc 1 per page off the slab compared to 17K (5page)
44321 alloc of large cifs buffers even when page debugging is on */
44322 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
44323 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
44324 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
44325 NULL);
44326 if (cifs_sm_req_cachep == NULL) {
44327 mempool_destroy(cifs_req_poolp);
44328 @@ -1115,8 +1115,8 @@ init_cifs(void)
44329 atomic_set(&bufAllocCount, 0);
44330 atomic_set(&smBufAllocCount, 0);
44331 #ifdef CONFIG_CIFS_STATS2
44332 - atomic_set(&totBufAllocCount, 0);
44333 - atomic_set(&totSmBufAllocCount, 0);
44334 + atomic_set_unchecked(&totBufAllocCount, 0);
44335 + atomic_set_unchecked(&totSmBufAllocCount, 0);
44336 #endif /* CONFIG_CIFS_STATS2 */
44337
44338 atomic_set(&midCount, 0);
44339 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
44340 index 977dc0e..ba48ab9 100644
44341 --- a/fs/cifs/cifsglob.h
44342 +++ b/fs/cifs/cifsglob.h
44343 @@ -590,35 +590,35 @@ struct cifs_tcon {
44344 __u16 Flags; /* optional support bits */
44345 enum statusEnum tidStatus;
44346 #ifdef CONFIG_CIFS_STATS
44347 - atomic_t num_smbs_sent;
44348 + atomic_unchecked_t num_smbs_sent;
44349 union {
44350 struct {
44351 - atomic_t num_writes;
44352 - atomic_t num_reads;
44353 - atomic_t num_flushes;
44354 - atomic_t num_oplock_brks;
44355 - atomic_t num_opens;
44356 - atomic_t num_closes;
44357 - atomic_t num_deletes;
44358 - atomic_t num_mkdirs;
44359 - atomic_t num_posixopens;
44360 - atomic_t num_posixmkdirs;
44361 - atomic_t num_rmdirs;
44362 - atomic_t num_renames;
44363 - atomic_t num_t2renames;
44364 - atomic_t num_ffirst;
44365 - atomic_t num_fnext;
44366 - atomic_t num_fclose;
44367 - atomic_t num_hardlinks;
44368 - atomic_t num_symlinks;
44369 - atomic_t num_locks;
44370 - atomic_t num_acl_get;
44371 - atomic_t num_acl_set;
44372 + atomic_unchecked_t num_writes;
44373 + atomic_unchecked_t num_reads;
44374 + atomic_unchecked_t num_flushes;
44375 + atomic_unchecked_t num_oplock_brks;
44376 + atomic_unchecked_t num_opens;
44377 + atomic_unchecked_t num_closes;
44378 + atomic_unchecked_t num_deletes;
44379 + atomic_unchecked_t num_mkdirs;
44380 + atomic_unchecked_t num_posixopens;
44381 + atomic_unchecked_t num_posixmkdirs;
44382 + atomic_unchecked_t num_rmdirs;
44383 + atomic_unchecked_t num_renames;
44384 + atomic_unchecked_t num_t2renames;
44385 + atomic_unchecked_t num_ffirst;
44386 + atomic_unchecked_t num_fnext;
44387 + atomic_unchecked_t num_fclose;
44388 + atomic_unchecked_t num_hardlinks;
44389 + atomic_unchecked_t num_symlinks;
44390 + atomic_unchecked_t num_locks;
44391 + atomic_unchecked_t num_acl_get;
44392 + atomic_unchecked_t num_acl_set;
44393 } cifs_stats;
44394 #ifdef CONFIG_CIFS_SMB2
44395 struct {
44396 - atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
44397 - atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
44398 + atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
44399 + atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
44400 } smb2_stats;
44401 #endif /* CONFIG_CIFS_SMB2 */
44402 } stats;
44403 @@ -862,7 +862,7 @@ build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb,
44404 }
44405
44406 #ifdef CONFIG_CIFS_STATS
44407 -#define cifs_stats_inc atomic_inc
44408 +#define cifs_stats_inc atomic_inc_unchecked
44409
44410 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
44411 unsigned int bytes)
44412 @@ -1227,8 +1227,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
44413 /* Various Debug counters */
44414 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
44415 #ifdef CONFIG_CIFS_STATS2
44416 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
44417 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
44418 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
44419 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
44420 #endif
44421 GLOBAL_EXTERN atomic_t smBufAllocCount;
44422 GLOBAL_EXTERN atomic_t midCount;
44423 diff --git a/fs/cifs/link.c b/fs/cifs/link.c
44424 index e6ce3b1..adc21fd 100644
44425 --- a/fs/cifs/link.c
44426 +++ b/fs/cifs/link.c
44427 @@ -602,7 +602,7 @@ symlink_exit:
44428
44429 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
44430 {
44431 - char *p = nd_get_link(nd);
44432 + const char *p = nd_get_link(nd);
44433 if (!IS_ERR(p))
44434 kfree(p);
44435 }
44436 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
44437 index ce41fee..ac0d27a 100644
44438 --- a/fs/cifs/misc.c
44439 +++ b/fs/cifs/misc.c
44440 @@ -169,7 +169,7 @@ cifs_buf_get(void)
44441 memset(ret_buf, 0, buf_size + 3);
44442 atomic_inc(&bufAllocCount);
44443 #ifdef CONFIG_CIFS_STATS2
44444 - atomic_inc(&totBufAllocCount);
44445 + atomic_inc_unchecked(&totBufAllocCount);
44446 #endif /* CONFIG_CIFS_STATS2 */
44447 }
44448
44449 @@ -204,7 +204,7 @@ cifs_small_buf_get(void)
44450 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
44451 atomic_inc(&smBufAllocCount);
44452 #ifdef CONFIG_CIFS_STATS2
44453 - atomic_inc(&totSmBufAllocCount);
44454 + atomic_inc_unchecked(&totSmBufAllocCount);
44455 #endif /* CONFIG_CIFS_STATS2 */
44456
44457 }
44458 diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
44459 index 3129ac7..cc4a948 100644
44460 --- a/fs/cifs/smb1ops.c
44461 +++ b/fs/cifs/smb1ops.c
44462 @@ -524,27 +524,27 @@ static void
44463 cifs_clear_stats(struct cifs_tcon *tcon)
44464 {
44465 #ifdef CONFIG_CIFS_STATS
44466 - atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
44467 - atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
44468 - atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
44469 - atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
44470 - atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
44471 - atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
44472 - atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
44473 - atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
44474 - atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
44475 - atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
44476 - atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
44477 - atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
44478 - atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
44479 - atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
44480 - atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
44481 - atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
44482 - atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
44483 - atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
44484 - atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
44485 - atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
44486 - atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
44487 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
44488 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
44489 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
44490 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
44491 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
44492 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
44493 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
44494 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
44495 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
44496 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
44497 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
44498 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
44499 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
44500 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
44501 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
44502 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
44503 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
44504 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
44505 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
44506 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
44507 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
44508 #endif
44509 }
44510
44511 @@ -553,36 +553,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
44512 {
44513 #ifdef CONFIG_CIFS_STATS
44514 seq_printf(m, " Oplocks breaks: %d",
44515 - atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
44516 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
44517 seq_printf(m, "\nReads: %d Bytes: %llu",
44518 - atomic_read(&tcon->stats.cifs_stats.num_reads),
44519 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
44520 (long long)(tcon->bytes_read));
44521 seq_printf(m, "\nWrites: %d Bytes: %llu",
44522 - atomic_read(&tcon->stats.cifs_stats.num_writes),
44523 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
44524 (long long)(tcon->bytes_written));
44525 seq_printf(m, "\nFlushes: %d",
44526 - atomic_read(&tcon->stats.cifs_stats.num_flushes));
44527 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
44528 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
44529 - atomic_read(&tcon->stats.cifs_stats.num_locks),
44530 - atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
44531 - atomic_read(&tcon->stats.cifs_stats.num_symlinks));
44532 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
44533 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
44534 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
44535 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
44536 - atomic_read(&tcon->stats.cifs_stats.num_opens),
44537 - atomic_read(&tcon->stats.cifs_stats.num_closes),
44538 - atomic_read(&tcon->stats.cifs_stats.num_deletes));
44539 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
44540 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
44541 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
44542 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
44543 - atomic_read(&tcon->stats.cifs_stats.num_posixopens),
44544 - atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
44545 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
44546 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
44547 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
44548 - atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
44549 - atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
44550 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
44551 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
44552 seq_printf(m, "\nRenames: %d T2 Renames %d",
44553 - atomic_read(&tcon->stats.cifs_stats.num_renames),
44554 - atomic_read(&tcon->stats.cifs_stats.num_t2renames));
44555 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
44556 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
44557 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
44558 - atomic_read(&tcon->stats.cifs_stats.num_ffirst),
44559 - atomic_read(&tcon->stats.cifs_stats.num_fnext),
44560 - atomic_read(&tcon->stats.cifs_stats.num_fclose));
44561 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
44562 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
44563 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
44564 #endif
44565 }
44566
44567 diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
44568 index 826209b..fa460f4 100644
44569 --- a/fs/cifs/smb2ops.c
44570 +++ b/fs/cifs/smb2ops.c
44571 @@ -219,8 +219,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
44572 #ifdef CONFIG_CIFS_STATS
44573 int i;
44574 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
44575 - atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
44576 - atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
44577 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
44578 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
44579 }
44580 #endif
44581 }
44582 @@ -229,66 +229,66 @@ static void
44583 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
44584 {
44585 #ifdef CONFIG_CIFS_STATS
44586 - atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
44587 - atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
44588 + atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
44589 + atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
44590 seq_printf(m, "\nNegotiates: %d sent %d failed",
44591 - atomic_read(&sent[SMB2_NEGOTIATE_HE]),
44592 - atomic_read(&failed[SMB2_NEGOTIATE_HE]));
44593 + atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
44594 + atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
44595 seq_printf(m, "\nSessionSetups: %d sent %d failed",
44596 - atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
44597 - atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
44598 + atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
44599 + atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
44600 #define SMB2LOGOFF 0x0002 /* trivial request/resp */
44601 seq_printf(m, "\nLogoffs: %d sent %d failed",
44602 - atomic_read(&sent[SMB2_LOGOFF_HE]),
44603 - atomic_read(&failed[SMB2_LOGOFF_HE]));
44604 + atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
44605 + atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
44606 seq_printf(m, "\nTreeConnects: %d sent %d failed",
44607 - atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
44608 - atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
44609 + atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
44610 + atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
44611 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
44612 - atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
44613 - atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
44614 + atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
44615 + atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
44616 seq_printf(m, "\nCreates: %d sent %d failed",
44617 - atomic_read(&sent[SMB2_CREATE_HE]),
44618 - atomic_read(&failed[SMB2_CREATE_HE]));
44619 + atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
44620 + atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
44621 seq_printf(m, "\nCloses: %d sent %d failed",
44622 - atomic_read(&sent[SMB2_CLOSE_HE]),
44623 - atomic_read(&failed[SMB2_CLOSE_HE]));
44624 + atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
44625 + atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
44626 seq_printf(m, "\nFlushes: %d sent %d failed",
44627 - atomic_read(&sent[SMB2_FLUSH_HE]),
44628 - atomic_read(&failed[SMB2_FLUSH_HE]));
44629 + atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
44630 + atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
44631 seq_printf(m, "\nReads: %d sent %d failed",
44632 - atomic_read(&sent[SMB2_READ_HE]),
44633 - atomic_read(&failed[SMB2_READ_HE]));
44634 + atomic_read_unchecked(&sent[SMB2_READ_HE]),
44635 + atomic_read_unchecked(&failed[SMB2_READ_HE]));
44636 seq_printf(m, "\nWrites: %d sent %d failed",
44637 - atomic_read(&sent[SMB2_WRITE_HE]),
44638 - atomic_read(&failed[SMB2_WRITE_HE]));
44639 + atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
44640 + atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
44641 seq_printf(m, "\nLocks: %d sent %d failed",
44642 - atomic_read(&sent[SMB2_LOCK_HE]),
44643 - atomic_read(&failed[SMB2_LOCK_HE]));
44644 + atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
44645 + atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
44646 seq_printf(m, "\nIOCTLs: %d sent %d failed",
44647 - atomic_read(&sent[SMB2_IOCTL_HE]),
44648 - atomic_read(&failed[SMB2_IOCTL_HE]));
44649 + atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
44650 + atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
44651 seq_printf(m, "\nCancels: %d sent %d failed",
44652 - atomic_read(&sent[SMB2_CANCEL_HE]),
44653 - atomic_read(&failed[SMB2_CANCEL_HE]));
44654 + atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
44655 + atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
44656 seq_printf(m, "\nEchos: %d sent %d failed",
44657 - atomic_read(&sent[SMB2_ECHO_HE]),
44658 - atomic_read(&failed[SMB2_ECHO_HE]));
44659 + atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
44660 + atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
44661 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
44662 - atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
44663 - atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
44664 + atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
44665 + atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
44666 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
44667 - atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
44668 - atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
44669 + atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
44670 + atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
44671 seq_printf(m, "\nQueryInfos: %d sent %d failed",
44672 - atomic_read(&sent[SMB2_QUERY_INFO_HE]),
44673 - atomic_read(&failed[SMB2_QUERY_INFO_HE]));
44674 + atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
44675 + atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
44676 seq_printf(m, "\nSetInfos: %d sent %d failed",
44677 - atomic_read(&sent[SMB2_SET_INFO_HE]),
44678 - atomic_read(&failed[SMB2_SET_INFO_HE]));
44679 + atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
44680 + atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
44681 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
44682 - atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
44683 - atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
44684 + atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
44685 + atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
44686 #endif
44687 }
44688
44689 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
44690 index 958ae0e..505c9d0 100644
44691 --- a/fs/coda/cache.c
44692 +++ b/fs/coda/cache.c
44693 @@ -24,7 +24,7 @@
44694 #include "coda_linux.h"
44695 #include "coda_cache.h"
44696
44697 -static atomic_t permission_epoch = ATOMIC_INIT(0);
44698 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
44699
44700 /* replace or extend an acl cache hit */
44701 void coda_cache_enter(struct inode *inode, int mask)
44702 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
44703 struct coda_inode_info *cii = ITOC(inode);
44704
44705 spin_lock(&cii->c_lock);
44706 - cii->c_cached_epoch = atomic_read(&permission_epoch);
44707 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
44708 if (cii->c_uid != current_fsuid()) {
44709 cii->c_uid = current_fsuid();
44710 cii->c_cached_perm = mask;
44711 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
44712 {
44713 struct coda_inode_info *cii = ITOC(inode);
44714 spin_lock(&cii->c_lock);
44715 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
44716 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
44717 spin_unlock(&cii->c_lock);
44718 }
44719
44720 /* remove all acl caches */
44721 void coda_cache_clear_all(struct super_block *sb)
44722 {
44723 - atomic_inc(&permission_epoch);
44724 + atomic_inc_unchecked(&permission_epoch);
44725 }
44726
44727
44728 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
44729 spin_lock(&cii->c_lock);
44730 hit = (mask & cii->c_cached_perm) == mask &&
44731 cii->c_uid == current_fsuid() &&
44732 - cii->c_cached_epoch == atomic_read(&permission_epoch);
44733 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
44734 spin_unlock(&cii->c_lock);
44735
44736 return hit;
44737 diff --git a/fs/compat.c b/fs/compat.c
44738 index 1bdb350..9f28287 100644
44739 --- a/fs/compat.c
44740 +++ b/fs/compat.c
44741 @@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
44742
44743 set_fs(KERNEL_DS);
44744 /* The __user pointer cast is valid because of the set_fs() */
44745 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
44746 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
44747 set_fs(oldfs);
44748 /* truncating is ok because it's a user address */
44749 if (!ret)
44750 @@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
44751 goto out;
44752
44753 ret = -EINVAL;
44754 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
44755 + if (nr_segs > UIO_MAXIOV)
44756 goto out;
44757 if (nr_segs > fast_segs) {
44758 ret = -ENOMEM;
44759 @@ -831,6 +831,7 @@ struct compat_old_linux_dirent {
44760
44761 struct compat_readdir_callback {
44762 struct compat_old_linux_dirent __user *dirent;
44763 + struct file * file;
44764 int result;
44765 };
44766
44767 @@ -848,6 +849,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
44768 buf->result = -EOVERFLOW;
44769 return -EOVERFLOW;
44770 }
44771 +
44772 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44773 + return 0;
44774 +
44775 buf->result++;
44776 dirent = buf->dirent;
44777 if (!access_ok(VERIFY_WRITE, dirent,
44778 @@ -880,6 +885,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
44779
44780 buf.result = 0;
44781 buf.dirent = dirent;
44782 + buf.file = file;
44783
44784 error = vfs_readdir(file, compat_fillonedir, &buf);
44785 if (buf.result)
44786 @@ -899,6 +905,7 @@ struct compat_linux_dirent {
44787 struct compat_getdents_callback {
44788 struct compat_linux_dirent __user *current_dir;
44789 struct compat_linux_dirent __user *previous;
44790 + struct file * file;
44791 int count;
44792 int error;
44793 };
44794 @@ -920,6 +927,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
44795 buf->error = -EOVERFLOW;
44796 return -EOVERFLOW;
44797 }
44798 +
44799 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44800 + return 0;
44801 +
44802 dirent = buf->previous;
44803 if (dirent) {
44804 if (__put_user(offset, &dirent->d_off))
44805 @@ -966,6 +977,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
44806 buf.previous = NULL;
44807 buf.count = count;
44808 buf.error = 0;
44809 + buf.file = file;
44810
44811 error = vfs_readdir(file, compat_filldir, &buf);
44812 if (error >= 0)
44813 @@ -986,6 +998,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
44814 struct compat_getdents_callback64 {
44815 struct linux_dirent64 __user *current_dir;
44816 struct linux_dirent64 __user *previous;
44817 + struct file * file;
44818 int count;
44819 int error;
44820 };
44821 @@ -1002,6 +1015,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
44822 buf->error = -EINVAL; /* only used if we fail.. */
44823 if (reclen > buf->count)
44824 return -EINVAL;
44825 +
44826 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44827 + return 0;
44828 +
44829 dirent = buf->previous;
44830
44831 if (dirent) {
44832 @@ -1052,13 +1069,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
44833 buf.previous = NULL;
44834 buf.count = count;
44835 buf.error = 0;
44836 + buf.file = file;
44837
44838 error = vfs_readdir(file, compat_filldir64, &buf);
44839 if (error >= 0)
44840 error = buf.error;
44841 lastdirent = buf.previous;
44842 if (lastdirent) {
44843 - typeof(lastdirent->d_off) d_off = file->f_pos;
44844 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
44845 if (__put_user_unaligned(d_off, &lastdirent->d_off))
44846 error = -EFAULT;
44847 else
44848 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
44849 index 112e45a..b59845b 100644
44850 --- a/fs/compat_binfmt_elf.c
44851 +++ b/fs/compat_binfmt_elf.c
44852 @@ -30,11 +30,13 @@
44853 #undef elf_phdr
44854 #undef elf_shdr
44855 #undef elf_note
44856 +#undef elf_dyn
44857 #undef elf_addr_t
44858 #define elfhdr elf32_hdr
44859 #define elf_phdr elf32_phdr
44860 #define elf_shdr elf32_shdr
44861 #define elf_note elf32_note
44862 +#define elf_dyn Elf32_Dyn
44863 #define elf_addr_t Elf32_Addr
44864
44865 /*
44866 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
44867 index 5d2069f..75d31d4 100644
44868 --- a/fs/compat_ioctl.c
44869 +++ b/fs/compat_ioctl.c
44870 @@ -623,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
44871 return -EFAULT;
44872 if (__get_user(udata, &ss32->iomem_base))
44873 return -EFAULT;
44874 - ss.iomem_base = compat_ptr(udata);
44875 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
44876 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
44877 __get_user(ss.port_high, &ss32->port_high))
44878 return -EFAULT;
44879 @@ -798,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
44880 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
44881 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
44882 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
44883 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
44884 + copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
44885 return -EFAULT;
44886
44887 return ioctl_preallocate(file, p);
44888 @@ -1612,8 +1612,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
44889 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
44890 {
44891 unsigned int a, b;
44892 - a = *(unsigned int *)p;
44893 - b = *(unsigned int *)q;
44894 + a = *(const unsigned int *)p;
44895 + b = *(const unsigned int *)q;
44896 if (a > b)
44897 return 1;
44898 if (a < b)
44899 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
44900 index 7414ae2..d98ad6d 100644
44901 --- a/fs/configfs/dir.c
44902 +++ b/fs/configfs/dir.c
44903 @@ -1564,7 +1564,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
44904 }
44905 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
44906 struct configfs_dirent *next;
44907 - const char * name;
44908 + const unsigned char * name;
44909 + char d_name[sizeof(next->s_dentry->d_iname)];
44910 int len;
44911 struct inode *inode = NULL;
44912
44913 @@ -1574,7 +1575,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
44914 continue;
44915
44916 name = configfs_get_name(next);
44917 - len = strlen(name);
44918 + if (next->s_dentry && name == next->s_dentry->d_iname) {
44919 + len = next->s_dentry->d_name.len;
44920 + memcpy(d_name, name, len);
44921 + name = d_name;
44922 + } else
44923 + len = strlen(name);
44924
44925 /*
44926 * We'll have a dentry and an inode for
44927 diff --git a/fs/dcache.c b/fs/dcache.c
44928 index 693f95b..95f1223 100644
44929 --- a/fs/dcache.c
44930 +++ b/fs/dcache.c
44931 @@ -3164,7 +3164,7 @@ void __init vfs_caches_init(unsigned long mempages)
44932 mempages -= reserve;
44933
44934 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
44935 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
44936 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
44937
44938 dcache_init();
44939 inode_init();
44940 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
44941 index 4733eab..71ef6fa 100644
44942 --- a/fs/debugfs/inode.c
44943 +++ b/fs/debugfs/inode.c
44944 @@ -406,7 +406,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
44945 */
44946 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
44947 {
44948 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
44949 + return __create_file(name, S_IFDIR | S_IRWXU,
44950 +#else
44951 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
44952 +#endif
44953 parent, NULL, NULL);
44954 }
44955 EXPORT_SYMBOL_GPL(debugfs_create_dir);
44956 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
44957 index cc7709e..7e7211f 100644
44958 --- a/fs/ecryptfs/inode.c
44959 +++ b/fs/ecryptfs/inode.c
44960 @@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
44961 old_fs = get_fs();
44962 set_fs(get_ds());
44963 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
44964 - (char __user *)lower_buf,
44965 + (char __force_user *)lower_buf,
44966 PATH_MAX);
44967 set_fs(old_fs);
44968 if (rc < 0)
44969 @@ -706,7 +706,7 @@ out:
44970 static void
44971 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
44972 {
44973 - char *buf = nd_get_link(nd);
44974 + const char *buf = nd_get_link(nd);
44975 if (!IS_ERR(buf)) {
44976 /* Free the char* */
44977 kfree(buf);
44978 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
44979 index 412e6ed..4292d22 100644
44980 --- a/fs/ecryptfs/miscdev.c
44981 +++ b/fs/ecryptfs/miscdev.c
44982 @@ -315,7 +315,7 @@ check_list:
44983 goto out_unlock_msg_ctx;
44984 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
44985 if (msg_ctx->msg) {
44986 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
44987 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
44988 goto out_unlock_msg_ctx;
44989 i += packet_length_size;
44990 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
44991 diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
44992 index b2a34a1..162fa69 100644
44993 --- a/fs/ecryptfs/read_write.c
44994 +++ b/fs/ecryptfs/read_write.c
44995 @@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
44996 return -EIO;
44997 fs_save = get_fs();
44998 set_fs(get_ds());
44999 - rc = vfs_write(lower_file, data, size, &offset);
45000 + rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
45001 set_fs(fs_save);
45002 mark_inode_dirty_sync(ecryptfs_inode);
45003 return rc;
45004 @@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
45005 return -EIO;
45006 fs_save = get_fs();
45007 set_fs(get_ds());
45008 - rc = vfs_read(lower_file, data, size, &offset);
45009 + rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
45010 set_fs(fs_save);
45011 return rc;
45012 }
45013 diff --git a/fs/exec.c b/fs/exec.c
45014 index fab2c6d..4fa20c0 100644
45015 --- a/fs/exec.c
45016 +++ b/fs/exec.c
45017 @@ -55,6 +55,15 @@
45018 #include <linux/pipe_fs_i.h>
45019 #include <linux/oom.h>
45020 #include <linux/compat.h>
45021 +#include <linux/random.h>
45022 +#include <linux/seq_file.h>
45023 +
45024 +#ifdef CONFIG_PAX_REFCOUNT
45025 +#include <linux/kallsyms.h>
45026 +#include <linux/kdebug.h>
45027 +#endif
45028 +
45029 +#include <trace/events/fs.h>
45030
45031 #include <asm/uaccess.h>
45032 #include <asm/mmu_context.h>
45033 @@ -66,6 +75,18 @@
45034
45035 #include <trace/events/sched.h>
45036
45037 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
45038 +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
45039 +{
45040 + 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");
45041 +}
45042 +#endif
45043 +
45044 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
45045 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
45046 +EXPORT_SYMBOL(pax_set_initial_flags_func);
45047 +#endif
45048 +
45049 int core_uses_pid;
45050 char core_pattern[CORENAME_MAX_SIZE] = "core";
45051 unsigned int core_pipe_limit;
45052 @@ -75,7 +96,7 @@ struct core_name {
45053 char *corename;
45054 int used, size;
45055 };
45056 -static atomic_t call_count = ATOMIC_INIT(1);
45057 +static atomic_unchecked_t call_count = ATOMIC_INIT(1);
45058
45059 /* The maximal length of core_pattern is also specified in sysctl.c */
45060
45061 @@ -191,18 +212,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
45062 int write)
45063 {
45064 struct page *page;
45065 - int ret;
45066
45067 -#ifdef CONFIG_STACK_GROWSUP
45068 - if (write) {
45069 - ret = expand_downwards(bprm->vma, pos);
45070 - if (ret < 0)
45071 - return NULL;
45072 - }
45073 -#endif
45074 - ret = get_user_pages(current, bprm->mm, pos,
45075 - 1, write, 1, &page, NULL);
45076 - if (ret <= 0)
45077 + if (0 > expand_downwards(bprm->vma, pos))
45078 + return NULL;
45079 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
45080 return NULL;
45081
45082 if (write) {
45083 @@ -218,6 +231,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
45084 if (size <= ARG_MAX)
45085 return page;
45086
45087 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45088 + // only allow 512KB for argv+env on suid/sgid binaries
45089 + // to prevent easy ASLR exhaustion
45090 + if (((bprm->cred->euid != current_euid()) ||
45091 + (bprm->cred->egid != current_egid())) &&
45092 + (size > (512 * 1024))) {
45093 + put_page(page);
45094 + return NULL;
45095 + }
45096 +#endif
45097 +
45098 /*
45099 * Limit to 1/4-th the stack size for the argv+env strings.
45100 * This ensures that:
45101 @@ -277,6 +301,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
45102 vma->vm_end = STACK_TOP_MAX;
45103 vma->vm_start = vma->vm_end - PAGE_SIZE;
45104 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
45105 +
45106 +#ifdef CONFIG_PAX_SEGMEXEC
45107 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
45108 +#endif
45109 +
45110 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
45111 INIT_LIST_HEAD(&vma->anon_vma_chain);
45112
45113 @@ -287,6 +316,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
45114 mm->stack_vm = mm->total_vm = 1;
45115 up_write(&mm->mmap_sem);
45116 bprm->p = vma->vm_end - sizeof(void *);
45117 +
45118 +#ifdef CONFIG_PAX_RANDUSTACK
45119 + if (randomize_va_space)
45120 + bprm->p ^= random32() & ~PAGE_MASK;
45121 +#endif
45122 +
45123 return 0;
45124 err:
45125 up_write(&mm->mmap_sem);
45126 @@ -395,19 +430,7 @@ err:
45127 return err;
45128 }
45129
45130 -struct user_arg_ptr {
45131 -#ifdef CONFIG_COMPAT
45132 - bool is_compat;
45133 -#endif
45134 - union {
45135 - const char __user *const __user *native;
45136 -#ifdef CONFIG_COMPAT
45137 - compat_uptr_t __user *compat;
45138 -#endif
45139 - } ptr;
45140 -};
45141 -
45142 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
45143 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
45144 {
45145 const char __user *native;
45146
45147 @@ -416,14 +439,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
45148 compat_uptr_t compat;
45149
45150 if (get_user(compat, argv.ptr.compat + nr))
45151 - return ERR_PTR(-EFAULT);
45152 + return (const char __force_user *)ERR_PTR(-EFAULT);
45153
45154 return compat_ptr(compat);
45155 }
45156 #endif
45157
45158 if (get_user(native, argv.ptr.native + nr))
45159 - return ERR_PTR(-EFAULT);
45160 + return (const char __force_user *)ERR_PTR(-EFAULT);
45161
45162 return native;
45163 }
45164 @@ -442,7 +465,7 @@ static int count(struct user_arg_ptr argv, int max)
45165 if (!p)
45166 break;
45167
45168 - if (IS_ERR(p))
45169 + if (IS_ERR((const char __force_kernel *)p))
45170 return -EFAULT;
45171
45172 if (i++ >= max)
45173 @@ -476,7 +499,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
45174
45175 ret = -EFAULT;
45176 str = get_user_arg_ptr(argv, argc);
45177 - if (IS_ERR(str))
45178 + if (IS_ERR((const char __force_kernel *)str))
45179 goto out;
45180
45181 len = strnlen_user(str, MAX_ARG_STRLEN);
45182 @@ -558,7 +581,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
45183 int r;
45184 mm_segment_t oldfs = get_fs();
45185 struct user_arg_ptr argv = {
45186 - .ptr.native = (const char __user *const __user *)__argv,
45187 + .ptr.native = (const char __force_user *const __force_user *)__argv,
45188 };
45189
45190 set_fs(KERNEL_DS);
45191 @@ -593,7 +616,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
45192 unsigned long new_end = old_end - shift;
45193 struct mmu_gather tlb;
45194
45195 - BUG_ON(new_start > new_end);
45196 + if (new_start >= new_end || new_start < mmap_min_addr)
45197 + return -ENOMEM;
45198
45199 /*
45200 * ensure there are no vmas between where we want to go
45201 @@ -602,6 +626,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
45202 if (vma != find_vma(mm, new_start))
45203 return -EFAULT;
45204
45205 +#ifdef CONFIG_PAX_SEGMEXEC
45206 + BUG_ON(pax_find_mirror_vma(vma));
45207 +#endif
45208 +
45209 /*
45210 * cover the whole range: [new_start, old_end)
45211 */
45212 @@ -682,10 +710,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
45213 stack_top = arch_align_stack(stack_top);
45214 stack_top = PAGE_ALIGN(stack_top);
45215
45216 - if (unlikely(stack_top < mmap_min_addr) ||
45217 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
45218 - return -ENOMEM;
45219 -
45220 stack_shift = vma->vm_end - stack_top;
45221
45222 bprm->p -= stack_shift;
45223 @@ -697,8 +721,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
45224 bprm->exec -= stack_shift;
45225
45226 down_write(&mm->mmap_sem);
45227 +
45228 + /* Move stack pages down in memory. */
45229 + if (stack_shift) {
45230 + ret = shift_arg_pages(vma, stack_shift);
45231 + if (ret)
45232 + goto out_unlock;
45233 + }
45234 +
45235 vm_flags = VM_STACK_FLAGS;
45236
45237 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
45238 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
45239 + vm_flags &= ~VM_EXEC;
45240 +
45241 +#ifdef CONFIG_PAX_MPROTECT
45242 + if (mm->pax_flags & MF_PAX_MPROTECT)
45243 + vm_flags &= ~VM_MAYEXEC;
45244 +#endif
45245 +
45246 + }
45247 +#endif
45248 +
45249 /*
45250 * Adjust stack execute permissions; explicitly enable for
45251 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
45252 @@ -717,13 +761,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
45253 goto out_unlock;
45254 BUG_ON(prev != vma);
45255
45256 - /* Move stack pages down in memory. */
45257 - if (stack_shift) {
45258 - ret = shift_arg_pages(vma, stack_shift);
45259 - if (ret)
45260 - goto out_unlock;
45261 - }
45262 -
45263 /* mprotect_fixup is overkill to remove the temporary stack flags */
45264 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
45265
45266 @@ -781,6 +818,8 @@ struct file *open_exec(const char *name)
45267
45268 fsnotify_open(file);
45269
45270 + trace_open_exec(name);
45271 +
45272 err = deny_write_access(file);
45273 if (err)
45274 goto exit;
45275 @@ -804,7 +843,7 @@ int kernel_read(struct file *file, loff_t offset,
45276 old_fs = get_fs();
45277 set_fs(get_ds());
45278 /* The cast to a user pointer is valid due to the set_fs() */
45279 - result = vfs_read(file, (void __user *)addr, count, &pos);
45280 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
45281 set_fs(old_fs);
45282 return result;
45283 }
45284 @@ -1258,7 +1297,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
45285 }
45286 rcu_read_unlock();
45287
45288 - if (p->fs->users > n_fs) {
45289 + if (atomic_read(&p->fs->users) > n_fs) {
45290 bprm->unsafe |= LSM_UNSAFE_SHARE;
45291 } else {
45292 res = -EAGAIN;
45293 @@ -1461,6 +1500,28 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
45294
45295 EXPORT_SYMBOL(search_binary_handler);
45296
45297 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45298 +static DEFINE_PER_CPU(u64, exec_counter);
45299 +static int __init init_exec_counters(void)
45300 +{
45301 + unsigned int cpu;
45302 +
45303 + for_each_possible_cpu(cpu) {
45304 + per_cpu(exec_counter, cpu) = (u64)cpu;
45305 + }
45306 +
45307 + return 0;
45308 +}
45309 +early_initcall(init_exec_counters);
45310 +static inline void increment_exec_counter(void)
45311 +{
45312 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
45313 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
45314 +}
45315 +#else
45316 +static inline void increment_exec_counter(void) {}
45317 +#endif
45318 +
45319 /*
45320 * sys_execve() executes a new program.
45321 */
45322 @@ -1469,6 +1530,11 @@ static int do_execve_common(const char *filename,
45323 struct user_arg_ptr envp,
45324 struct pt_regs *regs)
45325 {
45326 +#ifdef CONFIG_GRKERNSEC
45327 + struct file *old_exec_file;
45328 + struct acl_subject_label *old_acl;
45329 + struct rlimit old_rlim[RLIM_NLIMITS];
45330 +#endif
45331 struct linux_binprm *bprm;
45332 struct file *file;
45333 struct files_struct *displaced;
45334 @@ -1476,6 +1542,8 @@ static int do_execve_common(const char *filename,
45335 int retval;
45336 const struct cred *cred = current_cred();
45337
45338 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
45339 +
45340 /*
45341 * We move the actual failure in case of RLIMIT_NPROC excess from
45342 * set*uid() to execve() because too many poorly written programs
45343 @@ -1516,12 +1584,27 @@ static int do_execve_common(const char *filename,
45344 if (IS_ERR(file))
45345 goto out_unmark;
45346
45347 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
45348 + retval = -EPERM;
45349 + goto out_file;
45350 + }
45351 +
45352 sched_exec();
45353
45354 bprm->file = file;
45355 bprm->filename = filename;
45356 bprm->interp = filename;
45357
45358 + if (gr_process_user_ban()) {
45359 + retval = -EPERM;
45360 + goto out_file;
45361 + }
45362 +
45363 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
45364 + retval = -EACCES;
45365 + goto out_file;
45366 + }
45367 +
45368 retval = bprm_mm_init(bprm);
45369 if (retval)
45370 goto out_file;
45371 @@ -1538,24 +1621,65 @@ static int do_execve_common(const char *filename,
45372 if (retval < 0)
45373 goto out;
45374
45375 +#ifdef CONFIG_GRKERNSEC
45376 + old_acl = current->acl;
45377 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
45378 + old_exec_file = current->exec_file;
45379 + get_file(file);
45380 + current->exec_file = file;
45381 +#endif
45382 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45383 + /* limit suid stack to 8MB
45384 + we saved the old limits above and will restore them if this exec fails
45385 + */
45386 + if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
45387 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
45388 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
45389 +#endif
45390 +
45391 + if (!gr_tpe_allow(file)) {
45392 + retval = -EACCES;
45393 + goto out_fail;
45394 + }
45395 +
45396 + if (gr_check_crash_exec(file)) {
45397 + retval = -EACCES;
45398 + goto out_fail;
45399 + }
45400 +
45401 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
45402 + bprm->unsafe);
45403 + if (retval < 0)
45404 + goto out_fail;
45405 +
45406 retval = copy_strings_kernel(1, &bprm->filename, bprm);
45407 if (retval < 0)
45408 - goto out;
45409 + goto out_fail;
45410
45411 bprm->exec = bprm->p;
45412 retval = copy_strings(bprm->envc, envp, bprm);
45413 if (retval < 0)
45414 - goto out;
45415 + goto out_fail;
45416
45417 retval = copy_strings(bprm->argc, argv, bprm);
45418 if (retval < 0)
45419 - goto out;
45420 + goto out_fail;
45421 +
45422 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
45423 +
45424 + gr_handle_exec_args(bprm, argv);
45425
45426 retval = search_binary_handler(bprm,regs);
45427 if (retval < 0)
45428 - goto out;
45429 + goto out_fail;
45430 +#ifdef CONFIG_GRKERNSEC
45431 + if (old_exec_file)
45432 + fput(old_exec_file);
45433 +#endif
45434
45435 /* execve succeeded */
45436 +
45437 + increment_exec_counter();
45438 current->fs->in_exec = 0;
45439 current->in_execve = 0;
45440 acct_update_integrals(current);
45441 @@ -1564,6 +1688,14 @@ static int do_execve_common(const char *filename,
45442 put_files_struct(displaced);
45443 return retval;
45444
45445 +out_fail:
45446 +#ifdef CONFIG_GRKERNSEC
45447 + current->acl = old_acl;
45448 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
45449 + fput(current->exec_file);
45450 + current->exec_file = old_exec_file;
45451 +#endif
45452 +
45453 out:
45454 if (bprm->mm) {
45455 acct_arg_size(bprm, 0);
45456 @@ -1637,7 +1769,7 @@ static int expand_corename(struct core_name *cn)
45457 {
45458 char *old_corename = cn->corename;
45459
45460 - cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
45461 + cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
45462 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
45463
45464 if (!cn->corename) {
45465 @@ -1734,7 +1866,7 @@ static int format_corename(struct core_name *cn, long signr)
45466 int pid_in_pattern = 0;
45467 int err = 0;
45468
45469 - cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
45470 + cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
45471 cn->corename = kmalloc(cn->size, GFP_KERNEL);
45472 cn->used = 0;
45473
45474 @@ -1831,6 +1963,250 @@ out:
45475 return ispipe;
45476 }
45477
45478 +int pax_check_flags(unsigned long *flags)
45479 +{
45480 + int retval = 0;
45481 +
45482 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
45483 + if (*flags & MF_PAX_SEGMEXEC)
45484 + {
45485 + *flags &= ~MF_PAX_SEGMEXEC;
45486 + retval = -EINVAL;
45487 + }
45488 +#endif
45489 +
45490 + if ((*flags & MF_PAX_PAGEEXEC)
45491 +
45492 +#ifdef CONFIG_PAX_PAGEEXEC
45493 + && (*flags & MF_PAX_SEGMEXEC)
45494 +#endif
45495 +
45496 + )
45497 + {
45498 + *flags &= ~MF_PAX_PAGEEXEC;
45499 + retval = -EINVAL;
45500 + }
45501 +
45502 + if ((*flags & MF_PAX_MPROTECT)
45503 +
45504 +#ifdef CONFIG_PAX_MPROTECT
45505 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
45506 +#endif
45507 +
45508 + )
45509 + {
45510 + *flags &= ~MF_PAX_MPROTECT;
45511 + retval = -EINVAL;
45512 + }
45513 +
45514 + if ((*flags & MF_PAX_EMUTRAMP)
45515 +
45516 +#ifdef CONFIG_PAX_EMUTRAMP
45517 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
45518 +#endif
45519 +
45520 + )
45521 + {
45522 + *flags &= ~MF_PAX_EMUTRAMP;
45523 + retval = -EINVAL;
45524 + }
45525 +
45526 + return retval;
45527 +}
45528 +
45529 +EXPORT_SYMBOL(pax_check_flags);
45530 +
45531 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
45532 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
45533 +{
45534 + struct task_struct *tsk = current;
45535 + struct mm_struct *mm = current->mm;
45536 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
45537 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
45538 + char *path_exec = NULL;
45539 + char *path_fault = NULL;
45540 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
45541 +
45542 + if (buffer_exec && buffer_fault) {
45543 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
45544 +
45545 + down_read(&mm->mmap_sem);
45546 + vma = mm->mmap;
45547 + while (vma && (!vma_exec || !vma_fault)) {
45548 + if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
45549 + vma_exec = vma;
45550 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
45551 + vma_fault = vma;
45552 + vma = vma->vm_next;
45553 + }
45554 + if (vma_exec) {
45555 + path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
45556 + if (IS_ERR(path_exec))
45557 + path_exec = "<path too long>";
45558 + else {
45559 + path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
45560 + if (path_exec) {
45561 + *path_exec = 0;
45562 + path_exec = buffer_exec;
45563 + } else
45564 + path_exec = "<path too long>";
45565 + }
45566 + }
45567 + if (vma_fault) {
45568 + start = vma_fault->vm_start;
45569 + end = vma_fault->vm_end;
45570 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
45571 + if (vma_fault->vm_file) {
45572 + path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
45573 + if (IS_ERR(path_fault))
45574 + path_fault = "<path too long>";
45575 + else {
45576 + path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
45577 + if (path_fault) {
45578 + *path_fault = 0;
45579 + path_fault = buffer_fault;
45580 + } else
45581 + path_fault = "<path too long>";
45582 + }
45583 + } else
45584 + path_fault = "<anonymous mapping>";
45585 + }
45586 + up_read(&mm->mmap_sem);
45587 + }
45588 + if (tsk->signal->curr_ip)
45589 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
45590 + else
45591 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
45592 + printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
45593 + "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
45594 + task_uid(tsk), task_euid(tsk), pc, sp);
45595 + free_page((unsigned long)buffer_exec);
45596 + free_page((unsigned long)buffer_fault);
45597 + pax_report_insns(regs, pc, sp);
45598 + do_coredump(SIGKILL, SIGKILL, regs);
45599 +}
45600 +#endif
45601 +
45602 +#ifdef CONFIG_PAX_REFCOUNT
45603 +void pax_report_refcount_overflow(struct pt_regs *regs)
45604 +{
45605 + if (current->signal->curr_ip)
45606 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
45607 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
45608 + else
45609 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
45610 + current->comm, task_pid_nr(current), current_uid(), current_euid());
45611 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
45612 + show_regs(regs);
45613 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
45614 +}
45615 +#endif
45616 +
45617 +#ifdef CONFIG_PAX_USERCOPY
45618 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
45619 +static noinline int check_stack_object(const void *obj, unsigned long len)
45620 +{
45621 + const void * const stack = task_stack_page(current);
45622 + const void * const stackend = stack + THREAD_SIZE;
45623 +
45624 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
45625 + const void *frame = NULL;
45626 + const void *oldframe;
45627 +#endif
45628 +
45629 + if (obj + len < obj)
45630 + return -1;
45631 +
45632 + if (obj + len <= stack || stackend <= obj)
45633 + return 0;
45634 +
45635 + if (obj < stack || stackend < obj + len)
45636 + return -1;
45637 +
45638 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
45639 + oldframe = __builtin_frame_address(1);
45640 + if (oldframe)
45641 + frame = __builtin_frame_address(2);
45642 + /*
45643 + low ----------------------------------------------> high
45644 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
45645 + ^----------------^
45646 + allow copies only within here
45647 + */
45648 + while (stack <= frame && frame < stackend) {
45649 + /* if obj + len extends past the last frame, this
45650 + check won't pass and the next frame will be 0,
45651 + causing us to bail out and correctly report
45652 + the copy as invalid
45653 + */
45654 + if (obj + len <= frame)
45655 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
45656 + oldframe = frame;
45657 + frame = *(const void * const *)frame;
45658 + }
45659 + return -1;
45660 +#else
45661 + return 1;
45662 +#endif
45663 +}
45664 +
45665 +static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
45666 +{
45667 + if (current->signal->curr_ip)
45668 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
45669 + &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
45670 + else
45671 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
45672 + to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
45673 + dump_stack();
45674 + gr_handle_kernel_exploit();
45675 + do_group_exit(SIGKILL);
45676 +}
45677 +#endif
45678 +
45679 +void check_object_size(const void *ptr, unsigned long n, bool to)
45680 +{
45681 +
45682 +#ifdef CONFIG_PAX_USERCOPY
45683 + const char *type;
45684 +
45685 + if (!n)
45686 + return;
45687 +
45688 + type = check_heap_object(ptr, n, to);
45689 + if (!type) {
45690 + if (check_stack_object(ptr, n) != -1)
45691 + return;
45692 + type = "<process stack>";
45693 + }
45694 +
45695 + pax_report_usercopy(ptr, n, to, type);
45696 +#endif
45697 +
45698 +}
45699 +EXPORT_SYMBOL(check_object_size);
45700 +
45701 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
45702 +void pax_track_stack(void)
45703 +{
45704 + unsigned long sp = (unsigned long)&sp;
45705 + if (sp < current_thread_info()->lowest_stack &&
45706 + sp > (unsigned long)task_stack_page(current))
45707 + current_thread_info()->lowest_stack = sp;
45708 +}
45709 +EXPORT_SYMBOL(pax_track_stack);
45710 +#endif
45711 +
45712 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
45713 +void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
45714 +{
45715 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
45716 + dump_stack();
45717 + do_group_exit(SIGKILL);
45718 +}
45719 +EXPORT_SYMBOL(report_size_overflow);
45720 +#endif
45721 +
45722 static int zap_process(struct task_struct *start, int exit_code)
45723 {
45724 struct task_struct *t;
45725 @@ -2041,17 +2417,17 @@ static void wait_for_dump_helpers(struct file *file)
45726 pipe = file->f_path.dentry->d_inode->i_pipe;
45727
45728 pipe_lock(pipe);
45729 - pipe->readers++;
45730 - pipe->writers--;
45731 + atomic_inc(&pipe->readers);
45732 + atomic_dec(&pipe->writers);
45733
45734 - while ((pipe->readers > 1) && (!signal_pending(current))) {
45735 + while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
45736 wake_up_interruptible_sync(&pipe->wait);
45737 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
45738 pipe_wait(pipe);
45739 }
45740
45741 - pipe->readers--;
45742 - pipe->writers++;
45743 + atomic_dec(&pipe->readers);
45744 + atomic_inc(&pipe->writers);
45745 pipe_unlock(pipe);
45746
45747 }
45748 @@ -2106,7 +2482,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45749 int flag = 0;
45750 int ispipe;
45751 bool need_nonrelative = false;
45752 - static atomic_t core_dump_count = ATOMIC_INIT(0);
45753 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
45754 struct coredump_params cprm = {
45755 .signr = signr,
45756 .regs = regs,
45757 @@ -2121,6 +2497,9 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45758
45759 audit_core_dumps(signr);
45760
45761 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
45762 + gr_handle_brute_attach(current, cprm.mm_flags);
45763 +
45764 binfmt = mm->binfmt;
45765 if (!binfmt || !binfmt->core_dump)
45766 goto fail;
45767 @@ -2191,7 +2570,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45768 }
45769 cprm.limit = RLIM_INFINITY;
45770
45771 - dump_count = atomic_inc_return(&core_dump_count);
45772 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
45773 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
45774 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
45775 task_tgid_vnr(current), current->comm);
45776 @@ -2218,6 +2597,8 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45777 } else {
45778 struct inode *inode;
45779
45780 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
45781 +
45782 if (cprm.limit < binfmt->min_coredump)
45783 goto fail_unlock;
45784
45785 @@ -2269,7 +2650,7 @@ close_fail:
45786 filp_close(cprm.file, NULL);
45787 fail_dropcount:
45788 if (ispipe)
45789 - atomic_dec(&core_dump_count);
45790 + atomic_dec_unchecked(&core_dump_count);
45791 fail_unlock:
45792 kfree(cn.corename);
45793 fail_corename:
45794 @@ -2288,7 +2669,7 @@ fail:
45795 */
45796 int dump_write(struct file *file, const void *addr, int nr)
45797 {
45798 - return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
45799 + return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
45800 }
45801 EXPORT_SYMBOL(dump_write);
45802
45803 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
45804 index 376aa77..59a129c 100644
45805 --- a/fs/ext2/balloc.c
45806 +++ b/fs/ext2/balloc.c
45807 @@ -1190,10 +1190,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
45808
45809 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45810 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45811 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45812 + if (free_blocks < root_blocks + 1 &&
45813 !uid_eq(sbi->s_resuid, current_fsuid()) &&
45814 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
45815 - !in_group_p (sbi->s_resgid))) {
45816 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
45817 return 0;
45818 }
45819 return 1;
45820 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
45821 index 90d901f..159975f 100644
45822 --- a/fs/ext3/balloc.c
45823 +++ b/fs/ext3/balloc.c
45824 @@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
45825
45826 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45827 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45828 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45829 + if (free_blocks < root_blocks + 1 &&
45830 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
45831 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
45832 - !in_group_p (sbi->s_resgid))) {
45833 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
45834 return 0;
45835 }
45836 return 1;
45837 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
45838 index cf18217..8f6b9c3 100644
45839 --- a/fs/ext4/balloc.c
45840 +++ b/fs/ext4/balloc.c
45841 @@ -498,8 +498,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
45842 /* Hm, nope. Are (enough) root reserved clusters available? */
45843 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
45844 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
45845 - capable(CAP_SYS_RESOURCE) ||
45846 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
45847 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
45848 + capable_nolog(CAP_SYS_RESOURCE)) {
45849
45850 if (free_clusters >= (nclusters + dirty_clusters))
45851 return 1;
45852 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
45853 index 5c69f2b..05dec7f 100644
45854 --- a/fs/ext4/ext4.h
45855 +++ b/fs/ext4/ext4.h
45856 @@ -1248,19 +1248,19 @@ struct ext4_sb_info {
45857 unsigned long s_mb_last_start;
45858
45859 /* stats for buddy allocator */
45860 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
45861 - atomic_t s_bal_success; /* we found long enough chunks */
45862 - atomic_t s_bal_allocated; /* in blocks */
45863 - atomic_t s_bal_ex_scanned; /* total extents scanned */
45864 - atomic_t s_bal_goals; /* goal hits */
45865 - atomic_t s_bal_breaks; /* too long searches */
45866 - atomic_t s_bal_2orders; /* 2^order hits */
45867 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
45868 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
45869 + atomic_unchecked_t s_bal_allocated; /* in blocks */
45870 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
45871 + atomic_unchecked_t s_bal_goals; /* goal hits */
45872 + atomic_unchecked_t s_bal_breaks; /* too long searches */
45873 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
45874 spinlock_t s_bal_lock;
45875 unsigned long s_mb_buddies_generated;
45876 unsigned long long s_mb_generation_time;
45877 - atomic_t s_mb_lost_chunks;
45878 - atomic_t s_mb_preallocated;
45879 - atomic_t s_mb_discarded;
45880 + atomic_unchecked_t s_mb_lost_chunks;
45881 + atomic_unchecked_t s_mb_preallocated;
45882 + atomic_unchecked_t s_mb_discarded;
45883 atomic_t s_lock_busy;
45884
45885 /* locality groups */
45886 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
45887 index b26410c..7383d90 100644
45888 --- a/fs/ext4/mballoc.c
45889 +++ b/fs/ext4/mballoc.c
45890 @@ -1746,7 +1746,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
45891 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
45892
45893 if (EXT4_SB(sb)->s_mb_stats)
45894 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
45895 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
45896
45897 break;
45898 }
45899 @@ -2040,7 +2040,7 @@ repeat:
45900 ac->ac_status = AC_STATUS_CONTINUE;
45901 ac->ac_flags |= EXT4_MB_HINT_FIRST;
45902 cr = 3;
45903 - atomic_inc(&sbi->s_mb_lost_chunks);
45904 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
45905 goto repeat;
45906 }
45907 }
45908 @@ -2551,25 +2551,25 @@ int ext4_mb_release(struct super_block *sb)
45909 if (sbi->s_mb_stats) {
45910 ext4_msg(sb, KERN_INFO,
45911 "mballoc: %u blocks %u reqs (%u success)",
45912 - atomic_read(&sbi->s_bal_allocated),
45913 - atomic_read(&sbi->s_bal_reqs),
45914 - atomic_read(&sbi->s_bal_success));
45915 + atomic_read_unchecked(&sbi->s_bal_allocated),
45916 + atomic_read_unchecked(&sbi->s_bal_reqs),
45917 + atomic_read_unchecked(&sbi->s_bal_success));
45918 ext4_msg(sb, KERN_INFO,
45919 "mballoc: %u extents scanned, %u goal hits, "
45920 "%u 2^N hits, %u breaks, %u lost",
45921 - atomic_read(&sbi->s_bal_ex_scanned),
45922 - atomic_read(&sbi->s_bal_goals),
45923 - atomic_read(&sbi->s_bal_2orders),
45924 - atomic_read(&sbi->s_bal_breaks),
45925 - atomic_read(&sbi->s_mb_lost_chunks));
45926 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
45927 + atomic_read_unchecked(&sbi->s_bal_goals),
45928 + atomic_read_unchecked(&sbi->s_bal_2orders),
45929 + atomic_read_unchecked(&sbi->s_bal_breaks),
45930 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
45931 ext4_msg(sb, KERN_INFO,
45932 "mballoc: %lu generated and it took %Lu",
45933 sbi->s_mb_buddies_generated,
45934 sbi->s_mb_generation_time);
45935 ext4_msg(sb, KERN_INFO,
45936 "mballoc: %u preallocated, %u discarded",
45937 - atomic_read(&sbi->s_mb_preallocated),
45938 - atomic_read(&sbi->s_mb_discarded));
45939 + atomic_read_unchecked(&sbi->s_mb_preallocated),
45940 + atomic_read_unchecked(&sbi->s_mb_discarded));
45941 }
45942
45943 free_percpu(sbi->s_locality_groups);
45944 @@ -3051,16 +3051,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
45945 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
45946
45947 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
45948 - atomic_inc(&sbi->s_bal_reqs);
45949 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45950 + atomic_inc_unchecked(&sbi->s_bal_reqs);
45951 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45952 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
45953 - atomic_inc(&sbi->s_bal_success);
45954 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
45955 + atomic_inc_unchecked(&sbi->s_bal_success);
45956 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
45957 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
45958 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
45959 - atomic_inc(&sbi->s_bal_goals);
45960 + atomic_inc_unchecked(&sbi->s_bal_goals);
45961 if (ac->ac_found > sbi->s_mb_max_to_scan)
45962 - atomic_inc(&sbi->s_bal_breaks);
45963 + atomic_inc_unchecked(&sbi->s_bal_breaks);
45964 }
45965
45966 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
45967 @@ -3460,7 +3460,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
45968 trace_ext4_mb_new_inode_pa(ac, pa);
45969
45970 ext4_mb_use_inode_pa(ac, pa);
45971 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
45972 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
45973
45974 ei = EXT4_I(ac->ac_inode);
45975 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45976 @@ -3520,7 +3520,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
45977 trace_ext4_mb_new_group_pa(ac, pa);
45978
45979 ext4_mb_use_group_pa(ac, pa);
45980 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45981 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45982
45983 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45984 lg = ac->ac_lg;
45985 @@ -3609,7 +3609,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
45986 * from the bitmap and continue.
45987 */
45988 }
45989 - atomic_add(free, &sbi->s_mb_discarded);
45990 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
45991
45992 return err;
45993 }
45994 @@ -3627,7 +3627,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
45995 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
45996 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
45997 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
45998 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
45999 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
46000 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
46001
46002 return 0;
46003 diff --git a/fs/fcntl.c b/fs/fcntl.c
46004 index 887b5ba..0e3f2c3 100644
46005 --- a/fs/fcntl.c
46006 +++ b/fs/fcntl.c
46007 @@ -225,6 +225,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
46008 if (err)
46009 return err;
46010
46011 + if (gr_handle_chroot_fowner(pid, type))
46012 + return -ENOENT;
46013 + if (gr_check_protected_task_fowner(pid, type))
46014 + return -EACCES;
46015 +
46016 f_modown(filp, pid, type, force);
46017 return 0;
46018 }
46019 @@ -267,7 +272,7 @@ pid_t f_getown(struct file *filp)
46020
46021 static int f_setown_ex(struct file *filp, unsigned long arg)
46022 {
46023 - struct f_owner_ex * __user owner_p = (void * __user)arg;
46024 + struct f_owner_ex __user *owner_p = (void __user *)arg;
46025 struct f_owner_ex owner;
46026 struct pid *pid;
46027 int type;
46028 @@ -307,7 +312,7 @@ static int f_setown_ex(struct file *filp, unsigned long arg)
46029
46030 static int f_getown_ex(struct file *filp, unsigned long arg)
46031 {
46032 - struct f_owner_ex * __user owner_p = (void * __user)arg;
46033 + struct f_owner_ex __user *owner_p = (void __user *)arg;
46034 struct f_owner_ex owner;
46035 int ret = 0;
46036
46037 @@ -374,6 +379,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
46038 switch (cmd) {
46039 case F_DUPFD:
46040 case F_DUPFD_CLOEXEC:
46041 + gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
46042 if (arg >= rlimit(RLIMIT_NOFILE))
46043 break;
46044 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
46045 diff --git a/fs/fifo.c b/fs/fifo.c
46046 index cf6f434..3d7942c 100644
46047 --- a/fs/fifo.c
46048 +++ b/fs/fifo.c
46049 @@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
46050 */
46051 filp->f_op = &read_pipefifo_fops;
46052 pipe->r_counter++;
46053 - if (pipe->readers++ == 0)
46054 + if (atomic_inc_return(&pipe->readers) == 1)
46055 wake_up_partner(inode);
46056
46057 - if (!pipe->writers) {
46058 + if (!atomic_read(&pipe->writers)) {
46059 if ((filp->f_flags & O_NONBLOCK)) {
46060 /* suppress POLLHUP until we have
46061 * seen a writer */
46062 @@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
46063 * errno=ENXIO when there is no process reading the FIFO.
46064 */
46065 ret = -ENXIO;
46066 - if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
46067 + if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
46068 goto err;
46069
46070 filp->f_op = &write_pipefifo_fops;
46071 pipe->w_counter++;
46072 - if (!pipe->writers++)
46073 + if (atomic_inc_return(&pipe->writers) == 1)
46074 wake_up_partner(inode);
46075
46076 - if (!pipe->readers) {
46077 + if (!atomic_read(&pipe->readers)) {
46078 if (wait_for_partner(inode, &pipe->r_counter))
46079 goto err_wr;
46080 }
46081 @@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
46082 */
46083 filp->f_op = &rdwr_pipefifo_fops;
46084
46085 - pipe->readers++;
46086 - pipe->writers++;
46087 + atomic_inc(&pipe->readers);
46088 + atomic_inc(&pipe->writers);
46089 pipe->r_counter++;
46090 pipe->w_counter++;
46091 - if (pipe->readers == 1 || pipe->writers == 1)
46092 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
46093 wake_up_partner(inode);
46094 break;
46095
46096 @@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
46097 return 0;
46098
46099 err_rd:
46100 - if (!--pipe->readers)
46101 + if (atomic_dec_and_test(&pipe->readers))
46102 wake_up_interruptible(&pipe->wait);
46103 ret = -ERESTARTSYS;
46104 goto err;
46105
46106 err_wr:
46107 - if (!--pipe->writers)
46108 + if (atomic_dec_and_test(&pipe->writers))
46109 wake_up_interruptible(&pipe->wait);
46110 ret = -ERESTARTSYS;
46111 goto err;
46112
46113 err:
46114 - if (!pipe->readers && !pipe->writers)
46115 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
46116 free_pipe_info(inode);
46117
46118 err_nocleanup:
46119 diff --git a/fs/file.c b/fs/file.c
46120 index ba3f605..fade102 100644
46121 --- a/fs/file.c
46122 +++ b/fs/file.c
46123 @@ -15,6 +15,7 @@
46124 #include <linux/slab.h>
46125 #include <linux/vmalloc.h>
46126 #include <linux/file.h>
46127 +#include <linux/security.h>
46128 #include <linux/fdtable.h>
46129 #include <linux/bitops.h>
46130 #include <linux/interrupt.h>
46131 @@ -255,6 +256,7 @@ int expand_files(struct files_struct *files, int nr)
46132 * N.B. For clone tasks sharing a files structure, this test
46133 * will limit the total number of files that can be opened.
46134 */
46135 + gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
46136 if (nr >= rlimit(RLIMIT_NOFILE))
46137 return -EMFILE;
46138
46139 diff --git a/fs/filesystems.c b/fs/filesystems.c
46140 index 96f2428..f5eeb8e 100644
46141 --- a/fs/filesystems.c
46142 +++ b/fs/filesystems.c
46143 @@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
46144 int len = dot ? dot - name : strlen(name);
46145
46146 fs = __get_fs_type(name, len);
46147 +
46148 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
46149 + if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
46150 +#else
46151 if (!fs && (request_module("%.*s", len, name) == 0))
46152 +#endif
46153 fs = __get_fs_type(name, len);
46154
46155 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
46156 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
46157 index 5df4775..9d9336f 100644
46158 --- a/fs/fs_struct.c
46159 +++ b/fs/fs_struct.c
46160 @@ -4,6 +4,7 @@
46161 #include <linux/path.h>
46162 #include <linux/slab.h>
46163 #include <linux/fs_struct.h>
46164 +#include <linux/grsecurity.h>
46165 #include "internal.h"
46166
46167 /*
46168 @@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
46169 write_seqcount_begin(&fs->seq);
46170 old_root = fs->root;
46171 fs->root = *path;
46172 + gr_set_chroot_entries(current, path);
46173 write_seqcount_end(&fs->seq);
46174 spin_unlock(&fs->lock);
46175 if (old_root.dentry)
46176 @@ -53,6 +55,21 @@ static inline int replace_path(struct path *p, const struct path *old, const str
46177 return 1;
46178 }
46179
46180 +static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
46181 +{
46182 + if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
46183 + return 0;
46184 + *p = *new;
46185 +
46186 + /* This function is only called from pivot_root(). Leave our
46187 + gr_chroot_dentry and is_chrooted flags as-is, so that a
46188 + pivoted root isn't treated as a chroot
46189 + */
46190 + //gr_set_chroot_entries(task, new);
46191 +
46192 + return 1;
46193 +}
46194 +
46195 void chroot_fs_refs(struct path *old_root, struct path *new_root)
46196 {
46197 struct task_struct *g, *p;
46198 @@ -67,7 +84,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
46199 int hits = 0;
46200 spin_lock(&fs->lock);
46201 write_seqcount_begin(&fs->seq);
46202 - hits += replace_path(&fs->root, old_root, new_root);
46203 + hits += replace_root_path(p, &fs->root, old_root, new_root);
46204 hits += replace_path(&fs->pwd, old_root, new_root);
46205 write_seqcount_end(&fs->seq);
46206 while (hits--) {
46207 @@ -99,7 +116,8 @@ void exit_fs(struct task_struct *tsk)
46208 task_lock(tsk);
46209 spin_lock(&fs->lock);
46210 tsk->fs = NULL;
46211 - kill = !--fs->users;
46212 + gr_clear_chroot_entries(tsk);
46213 + kill = !atomic_dec_return(&fs->users);
46214 spin_unlock(&fs->lock);
46215 task_unlock(tsk);
46216 if (kill)
46217 @@ -112,7 +130,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
46218 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
46219 /* We don't need to lock fs - think why ;-) */
46220 if (fs) {
46221 - fs->users = 1;
46222 + atomic_set(&fs->users, 1);
46223 fs->in_exec = 0;
46224 spin_lock_init(&fs->lock);
46225 seqcount_init(&fs->seq);
46226 @@ -121,6 +139,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
46227 spin_lock(&old->lock);
46228 fs->root = old->root;
46229 path_get(&fs->root);
46230 + /* instead of calling gr_set_chroot_entries here,
46231 + we call it from every caller of this function
46232 + */
46233 fs->pwd = old->pwd;
46234 path_get(&fs->pwd);
46235 spin_unlock(&old->lock);
46236 @@ -139,8 +160,9 @@ int unshare_fs_struct(void)
46237
46238 task_lock(current);
46239 spin_lock(&fs->lock);
46240 - kill = !--fs->users;
46241 + kill = !atomic_dec_return(&fs->users);
46242 current->fs = new_fs;
46243 + gr_set_chroot_entries(current, &new_fs->root);
46244 spin_unlock(&fs->lock);
46245 task_unlock(current);
46246
46247 @@ -153,13 +175,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
46248
46249 int current_umask(void)
46250 {
46251 - return current->fs->umask;
46252 + return current->fs->umask | gr_acl_umask();
46253 }
46254 EXPORT_SYMBOL(current_umask);
46255
46256 /* to be mentioned only in INIT_TASK */
46257 struct fs_struct init_fs = {
46258 - .users = 1,
46259 + .users = ATOMIC_INIT(1),
46260 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
46261 .seq = SEQCNT_ZERO,
46262 .umask = 0022,
46263 @@ -175,12 +197,13 @@ void daemonize_fs_struct(void)
46264 task_lock(current);
46265
46266 spin_lock(&init_fs.lock);
46267 - init_fs.users++;
46268 + atomic_inc(&init_fs.users);
46269 spin_unlock(&init_fs.lock);
46270
46271 spin_lock(&fs->lock);
46272 current->fs = &init_fs;
46273 - kill = !--fs->users;
46274 + gr_set_chroot_entries(current, &current->fs->root);
46275 + kill = !atomic_dec_return(&fs->users);
46276 spin_unlock(&fs->lock);
46277
46278 task_unlock(current);
46279 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
46280 index 9905350..02eaec4 100644
46281 --- a/fs/fscache/cookie.c
46282 +++ b/fs/fscache/cookie.c
46283 @@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
46284 parent ? (char *) parent->def->name : "<no-parent>",
46285 def->name, netfs_data);
46286
46287 - fscache_stat(&fscache_n_acquires);
46288 + fscache_stat_unchecked(&fscache_n_acquires);
46289
46290 /* if there's no parent cookie, then we don't create one here either */
46291 if (!parent) {
46292 - fscache_stat(&fscache_n_acquires_null);
46293 + fscache_stat_unchecked(&fscache_n_acquires_null);
46294 _leave(" [no parent]");
46295 return NULL;
46296 }
46297 @@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
46298 /* allocate and initialise a cookie */
46299 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
46300 if (!cookie) {
46301 - fscache_stat(&fscache_n_acquires_oom);
46302 + fscache_stat_unchecked(&fscache_n_acquires_oom);
46303 _leave(" [ENOMEM]");
46304 return NULL;
46305 }
46306 @@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
46307
46308 switch (cookie->def->type) {
46309 case FSCACHE_COOKIE_TYPE_INDEX:
46310 - fscache_stat(&fscache_n_cookie_index);
46311 + fscache_stat_unchecked(&fscache_n_cookie_index);
46312 break;
46313 case FSCACHE_COOKIE_TYPE_DATAFILE:
46314 - fscache_stat(&fscache_n_cookie_data);
46315 + fscache_stat_unchecked(&fscache_n_cookie_data);
46316 break;
46317 default:
46318 - fscache_stat(&fscache_n_cookie_special);
46319 + fscache_stat_unchecked(&fscache_n_cookie_special);
46320 break;
46321 }
46322
46323 @@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
46324 if (fscache_acquire_non_index_cookie(cookie) < 0) {
46325 atomic_dec(&parent->n_children);
46326 __fscache_cookie_put(cookie);
46327 - fscache_stat(&fscache_n_acquires_nobufs);
46328 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
46329 _leave(" = NULL");
46330 return NULL;
46331 }
46332 }
46333
46334 - fscache_stat(&fscache_n_acquires_ok);
46335 + fscache_stat_unchecked(&fscache_n_acquires_ok);
46336 _leave(" = %p", cookie);
46337 return cookie;
46338 }
46339 @@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
46340 cache = fscache_select_cache_for_object(cookie->parent);
46341 if (!cache) {
46342 up_read(&fscache_addremove_sem);
46343 - fscache_stat(&fscache_n_acquires_no_cache);
46344 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
46345 _leave(" = -ENOMEDIUM [no cache]");
46346 return -ENOMEDIUM;
46347 }
46348 @@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
46349 object = cache->ops->alloc_object(cache, cookie);
46350 fscache_stat_d(&fscache_n_cop_alloc_object);
46351 if (IS_ERR(object)) {
46352 - fscache_stat(&fscache_n_object_no_alloc);
46353 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
46354 ret = PTR_ERR(object);
46355 goto error;
46356 }
46357
46358 - fscache_stat(&fscache_n_object_alloc);
46359 + fscache_stat_unchecked(&fscache_n_object_alloc);
46360
46361 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
46362
46363 @@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
46364 struct fscache_object *object;
46365 struct hlist_node *_p;
46366
46367 - fscache_stat(&fscache_n_updates);
46368 + fscache_stat_unchecked(&fscache_n_updates);
46369
46370 if (!cookie) {
46371 - fscache_stat(&fscache_n_updates_null);
46372 + fscache_stat_unchecked(&fscache_n_updates_null);
46373 _leave(" [no cookie]");
46374 return;
46375 }
46376 @@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
46377 struct fscache_object *object;
46378 unsigned long event;
46379
46380 - fscache_stat(&fscache_n_relinquishes);
46381 + fscache_stat_unchecked(&fscache_n_relinquishes);
46382 if (retire)
46383 - fscache_stat(&fscache_n_relinquishes_retire);
46384 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
46385
46386 if (!cookie) {
46387 - fscache_stat(&fscache_n_relinquishes_null);
46388 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
46389 _leave(" [no cookie]");
46390 return;
46391 }
46392 @@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
46393
46394 /* wait for the cookie to finish being instantiated (or to fail) */
46395 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
46396 - fscache_stat(&fscache_n_relinquishes_waitcrt);
46397 + fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
46398 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
46399 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
46400 }
46401 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
46402 index f6aad48..88dcf26 100644
46403 --- a/fs/fscache/internal.h
46404 +++ b/fs/fscache/internal.h
46405 @@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
46406 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
46407 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
46408
46409 -extern atomic_t fscache_n_op_pend;
46410 -extern atomic_t fscache_n_op_run;
46411 -extern atomic_t fscache_n_op_enqueue;
46412 -extern atomic_t fscache_n_op_deferred_release;
46413 -extern atomic_t fscache_n_op_release;
46414 -extern atomic_t fscache_n_op_gc;
46415 -extern atomic_t fscache_n_op_cancelled;
46416 -extern atomic_t fscache_n_op_rejected;
46417 +extern atomic_unchecked_t fscache_n_op_pend;
46418 +extern atomic_unchecked_t fscache_n_op_run;
46419 +extern atomic_unchecked_t fscache_n_op_enqueue;
46420 +extern atomic_unchecked_t fscache_n_op_deferred_release;
46421 +extern atomic_unchecked_t fscache_n_op_release;
46422 +extern atomic_unchecked_t fscache_n_op_gc;
46423 +extern atomic_unchecked_t fscache_n_op_cancelled;
46424 +extern atomic_unchecked_t fscache_n_op_rejected;
46425
46426 -extern atomic_t fscache_n_attr_changed;
46427 -extern atomic_t fscache_n_attr_changed_ok;
46428 -extern atomic_t fscache_n_attr_changed_nobufs;
46429 -extern atomic_t fscache_n_attr_changed_nomem;
46430 -extern atomic_t fscache_n_attr_changed_calls;
46431 +extern atomic_unchecked_t fscache_n_attr_changed;
46432 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
46433 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
46434 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
46435 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
46436
46437 -extern atomic_t fscache_n_allocs;
46438 -extern atomic_t fscache_n_allocs_ok;
46439 -extern atomic_t fscache_n_allocs_wait;
46440 -extern atomic_t fscache_n_allocs_nobufs;
46441 -extern atomic_t fscache_n_allocs_intr;
46442 -extern atomic_t fscache_n_allocs_object_dead;
46443 -extern atomic_t fscache_n_alloc_ops;
46444 -extern atomic_t fscache_n_alloc_op_waits;
46445 +extern atomic_unchecked_t fscache_n_allocs;
46446 +extern atomic_unchecked_t fscache_n_allocs_ok;
46447 +extern atomic_unchecked_t fscache_n_allocs_wait;
46448 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
46449 +extern atomic_unchecked_t fscache_n_allocs_intr;
46450 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
46451 +extern atomic_unchecked_t fscache_n_alloc_ops;
46452 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
46453
46454 -extern atomic_t fscache_n_retrievals;
46455 -extern atomic_t fscache_n_retrievals_ok;
46456 -extern atomic_t fscache_n_retrievals_wait;
46457 -extern atomic_t fscache_n_retrievals_nodata;
46458 -extern atomic_t fscache_n_retrievals_nobufs;
46459 -extern atomic_t fscache_n_retrievals_intr;
46460 -extern atomic_t fscache_n_retrievals_nomem;
46461 -extern atomic_t fscache_n_retrievals_object_dead;
46462 -extern atomic_t fscache_n_retrieval_ops;
46463 -extern atomic_t fscache_n_retrieval_op_waits;
46464 +extern atomic_unchecked_t fscache_n_retrievals;
46465 +extern atomic_unchecked_t fscache_n_retrievals_ok;
46466 +extern atomic_unchecked_t fscache_n_retrievals_wait;
46467 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
46468 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
46469 +extern atomic_unchecked_t fscache_n_retrievals_intr;
46470 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
46471 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
46472 +extern atomic_unchecked_t fscache_n_retrieval_ops;
46473 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
46474
46475 -extern atomic_t fscache_n_stores;
46476 -extern atomic_t fscache_n_stores_ok;
46477 -extern atomic_t fscache_n_stores_again;
46478 -extern atomic_t fscache_n_stores_nobufs;
46479 -extern atomic_t fscache_n_stores_oom;
46480 -extern atomic_t fscache_n_store_ops;
46481 -extern atomic_t fscache_n_store_calls;
46482 -extern atomic_t fscache_n_store_pages;
46483 -extern atomic_t fscache_n_store_radix_deletes;
46484 -extern atomic_t fscache_n_store_pages_over_limit;
46485 +extern atomic_unchecked_t fscache_n_stores;
46486 +extern atomic_unchecked_t fscache_n_stores_ok;
46487 +extern atomic_unchecked_t fscache_n_stores_again;
46488 +extern atomic_unchecked_t fscache_n_stores_nobufs;
46489 +extern atomic_unchecked_t fscache_n_stores_oom;
46490 +extern atomic_unchecked_t fscache_n_store_ops;
46491 +extern atomic_unchecked_t fscache_n_store_calls;
46492 +extern atomic_unchecked_t fscache_n_store_pages;
46493 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
46494 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
46495
46496 -extern atomic_t fscache_n_store_vmscan_not_storing;
46497 -extern atomic_t fscache_n_store_vmscan_gone;
46498 -extern atomic_t fscache_n_store_vmscan_busy;
46499 -extern atomic_t fscache_n_store_vmscan_cancelled;
46500 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
46501 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
46502 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
46503 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
46504
46505 -extern atomic_t fscache_n_marks;
46506 -extern atomic_t fscache_n_uncaches;
46507 +extern atomic_unchecked_t fscache_n_marks;
46508 +extern atomic_unchecked_t fscache_n_uncaches;
46509
46510 -extern atomic_t fscache_n_acquires;
46511 -extern atomic_t fscache_n_acquires_null;
46512 -extern atomic_t fscache_n_acquires_no_cache;
46513 -extern atomic_t fscache_n_acquires_ok;
46514 -extern atomic_t fscache_n_acquires_nobufs;
46515 -extern atomic_t fscache_n_acquires_oom;
46516 +extern atomic_unchecked_t fscache_n_acquires;
46517 +extern atomic_unchecked_t fscache_n_acquires_null;
46518 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
46519 +extern atomic_unchecked_t fscache_n_acquires_ok;
46520 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
46521 +extern atomic_unchecked_t fscache_n_acquires_oom;
46522
46523 -extern atomic_t fscache_n_updates;
46524 -extern atomic_t fscache_n_updates_null;
46525 -extern atomic_t fscache_n_updates_run;
46526 +extern atomic_unchecked_t fscache_n_updates;
46527 +extern atomic_unchecked_t fscache_n_updates_null;
46528 +extern atomic_unchecked_t fscache_n_updates_run;
46529
46530 -extern atomic_t fscache_n_relinquishes;
46531 -extern atomic_t fscache_n_relinquishes_null;
46532 -extern atomic_t fscache_n_relinquishes_waitcrt;
46533 -extern atomic_t fscache_n_relinquishes_retire;
46534 +extern atomic_unchecked_t fscache_n_relinquishes;
46535 +extern atomic_unchecked_t fscache_n_relinquishes_null;
46536 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
46537 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
46538
46539 -extern atomic_t fscache_n_cookie_index;
46540 -extern atomic_t fscache_n_cookie_data;
46541 -extern atomic_t fscache_n_cookie_special;
46542 +extern atomic_unchecked_t fscache_n_cookie_index;
46543 +extern atomic_unchecked_t fscache_n_cookie_data;
46544 +extern atomic_unchecked_t fscache_n_cookie_special;
46545
46546 -extern atomic_t fscache_n_object_alloc;
46547 -extern atomic_t fscache_n_object_no_alloc;
46548 -extern atomic_t fscache_n_object_lookups;
46549 -extern atomic_t fscache_n_object_lookups_negative;
46550 -extern atomic_t fscache_n_object_lookups_positive;
46551 -extern atomic_t fscache_n_object_lookups_timed_out;
46552 -extern atomic_t fscache_n_object_created;
46553 -extern atomic_t fscache_n_object_avail;
46554 -extern atomic_t fscache_n_object_dead;
46555 +extern atomic_unchecked_t fscache_n_object_alloc;
46556 +extern atomic_unchecked_t fscache_n_object_no_alloc;
46557 +extern atomic_unchecked_t fscache_n_object_lookups;
46558 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
46559 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
46560 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
46561 +extern atomic_unchecked_t fscache_n_object_created;
46562 +extern atomic_unchecked_t fscache_n_object_avail;
46563 +extern atomic_unchecked_t fscache_n_object_dead;
46564
46565 -extern atomic_t fscache_n_checkaux_none;
46566 -extern atomic_t fscache_n_checkaux_okay;
46567 -extern atomic_t fscache_n_checkaux_update;
46568 -extern atomic_t fscache_n_checkaux_obsolete;
46569 +extern atomic_unchecked_t fscache_n_checkaux_none;
46570 +extern atomic_unchecked_t fscache_n_checkaux_okay;
46571 +extern atomic_unchecked_t fscache_n_checkaux_update;
46572 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
46573
46574 extern atomic_t fscache_n_cop_alloc_object;
46575 extern atomic_t fscache_n_cop_lookup_object;
46576 @@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
46577 atomic_inc(stat);
46578 }
46579
46580 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
46581 +{
46582 + atomic_inc_unchecked(stat);
46583 +}
46584 +
46585 static inline void fscache_stat_d(atomic_t *stat)
46586 {
46587 atomic_dec(stat);
46588 @@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
46589
46590 #define __fscache_stat(stat) (NULL)
46591 #define fscache_stat(stat) do {} while (0)
46592 +#define fscache_stat_unchecked(stat) do {} while (0)
46593 #define fscache_stat_d(stat) do {} while (0)
46594 #endif
46595
46596 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
46597 index b6b897c..0ffff9c 100644
46598 --- a/fs/fscache/object.c
46599 +++ b/fs/fscache/object.c
46600 @@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46601 /* update the object metadata on disk */
46602 case FSCACHE_OBJECT_UPDATING:
46603 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
46604 - fscache_stat(&fscache_n_updates_run);
46605 + fscache_stat_unchecked(&fscache_n_updates_run);
46606 fscache_stat(&fscache_n_cop_update_object);
46607 object->cache->ops->update_object(object);
46608 fscache_stat_d(&fscache_n_cop_update_object);
46609 @@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46610 spin_lock(&object->lock);
46611 object->state = FSCACHE_OBJECT_DEAD;
46612 spin_unlock(&object->lock);
46613 - fscache_stat(&fscache_n_object_dead);
46614 + fscache_stat_unchecked(&fscache_n_object_dead);
46615 goto terminal_transit;
46616
46617 /* handle the parent cache of this object being withdrawn from
46618 @@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46619 spin_lock(&object->lock);
46620 object->state = FSCACHE_OBJECT_DEAD;
46621 spin_unlock(&object->lock);
46622 - fscache_stat(&fscache_n_object_dead);
46623 + fscache_stat_unchecked(&fscache_n_object_dead);
46624 goto terminal_transit;
46625
46626 /* complain about the object being woken up once it is
46627 @@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
46628 parent->cookie->def->name, cookie->def->name,
46629 object->cache->tag->name);
46630
46631 - fscache_stat(&fscache_n_object_lookups);
46632 + fscache_stat_unchecked(&fscache_n_object_lookups);
46633 fscache_stat(&fscache_n_cop_lookup_object);
46634 ret = object->cache->ops->lookup_object(object);
46635 fscache_stat_d(&fscache_n_cop_lookup_object);
46636 @@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
46637 if (ret == -ETIMEDOUT) {
46638 /* probably stuck behind another object, so move this one to
46639 * the back of the queue */
46640 - fscache_stat(&fscache_n_object_lookups_timed_out);
46641 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
46642 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
46643 }
46644
46645 @@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
46646
46647 spin_lock(&object->lock);
46648 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
46649 - fscache_stat(&fscache_n_object_lookups_negative);
46650 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
46651
46652 /* transit here to allow write requests to begin stacking up
46653 * and read requests to begin returning ENODATA */
46654 @@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
46655 * result, in which case there may be data available */
46656 spin_lock(&object->lock);
46657 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
46658 - fscache_stat(&fscache_n_object_lookups_positive);
46659 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
46660
46661 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
46662
46663 @@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
46664 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
46665 } else {
46666 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
46667 - fscache_stat(&fscache_n_object_created);
46668 + fscache_stat_unchecked(&fscache_n_object_created);
46669
46670 object->state = FSCACHE_OBJECT_AVAILABLE;
46671 spin_unlock(&object->lock);
46672 @@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
46673 fscache_enqueue_dependents(object);
46674
46675 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
46676 - fscache_stat(&fscache_n_object_avail);
46677 + fscache_stat_unchecked(&fscache_n_object_avail);
46678
46679 _leave("");
46680 }
46681 @@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
46682 enum fscache_checkaux result;
46683
46684 if (!object->cookie->def->check_aux) {
46685 - fscache_stat(&fscache_n_checkaux_none);
46686 + fscache_stat_unchecked(&fscache_n_checkaux_none);
46687 return FSCACHE_CHECKAUX_OKAY;
46688 }
46689
46690 @@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
46691 switch (result) {
46692 /* entry okay as is */
46693 case FSCACHE_CHECKAUX_OKAY:
46694 - fscache_stat(&fscache_n_checkaux_okay);
46695 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
46696 break;
46697
46698 /* entry requires update */
46699 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
46700 - fscache_stat(&fscache_n_checkaux_update);
46701 + fscache_stat_unchecked(&fscache_n_checkaux_update);
46702 break;
46703
46704 /* entry requires deletion */
46705 case FSCACHE_CHECKAUX_OBSOLETE:
46706 - fscache_stat(&fscache_n_checkaux_obsolete);
46707 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
46708 break;
46709
46710 default:
46711 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
46712 index 30afdfa..2256596 100644
46713 --- a/fs/fscache/operation.c
46714 +++ b/fs/fscache/operation.c
46715 @@ -17,7 +17,7 @@
46716 #include <linux/slab.h>
46717 #include "internal.h"
46718
46719 -atomic_t fscache_op_debug_id;
46720 +atomic_unchecked_t fscache_op_debug_id;
46721 EXPORT_SYMBOL(fscache_op_debug_id);
46722
46723 /**
46724 @@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
46725 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
46726 ASSERTCMP(atomic_read(&op->usage), >, 0);
46727
46728 - fscache_stat(&fscache_n_op_enqueue);
46729 + fscache_stat_unchecked(&fscache_n_op_enqueue);
46730 switch (op->flags & FSCACHE_OP_TYPE) {
46731 case FSCACHE_OP_ASYNC:
46732 _debug("queue async");
46733 @@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
46734 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
46735 if (op->processor)
46736 fscache_enqueue_operation(op);
46737 - fscache_stat(&fscache_n_op_run);
46738 + fscache_stat_unchecked(&fscache_n_op_run);
46739 }
46740
46741 /*
46742 @@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
46743 if (object->n_ops > 1) {
46744 atomic_inc(&op->usage);
46745 list_add_tail(&op->pend_link, &object->pending_ops);
46746 - fscache_stat(&fscache_n_op_pend);
46747 + fscache_stat_unchecked(&fscache_n_op_pend);
46748 } else if (!list_empty(&object->pending_ops)) {
46749 atomic_inc(&op->usage);
46750 list_add_tail(&op->pend_link, &object->pending_ops);
46751 - fscache_stat(&fscache_n_op_pend);
46752 + fscache_stat_unchecked(&fscache_n_op_pend);
46753 fscache_start_operations(object);
46754 } else {
46755 ASSERTCMP(object->n_in_progress, ==, 0);
46756 @@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
46757 object->n_exclusive++; /* reads and writes must wait */
46758 atomic_inc(&op->usage);
46759 list_add_tail(&op->pend_link, &object->pending_ops);
46760 - fscache_stat(&fscache_n_op_pend);
46761 + fscache_stat_unchecked(&fscache_n_op_pend);
46762 ret = 0;
46763 } else {
46764 /* not allowed to submit ops in any other state */
46765 @@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
46766 if (object->n_exclusive > 0) {
46767 atomic_inc(&op->usage);
46768 list_add_tail(&op->pend_link, &object->pending_ops);
46769 - fscache_stat(&fscache_n_op_pend);
46770 + fscache_stat_unchecked(&fscache_n_op_pend);
46771 } else if (!list_empty(&object->pending_ops)) {
46772 atomic_inc(&op->usage);
46773 list_add_tail(&op->pend_link, &object->pending_ops);
46774 - fscache_stat(&fscache_n_op_pend);
46775 + fscache_stat_unchecked(&fscache_n_op_pend);
46776 fscache_start_operations(object);
46777 } else {
46778 ASSERTCMP(object->n_exclusive, ==, 0);
46779 @@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
46780 object->n_ops++;
46781 atomic_inc(&op->usage);
46782 list_add_tail(&op->pend_link, &object->pending_ops);
46783 - fscache_stat(&fscache_n_op_pend);
46784 + fscache_stat_unchecked(&fscache_n_op_pend);
46785 ret = 0;
46786 } else if (object->state == FSCACHE_OBJECT_DYING ||
46787 object->state == FSCACHE_OBJECT_LC_DYING ||
46788 object->state == FSCACHE_OBJECT_WITHDRAWING) {
46789 - fscache_stat(&fscache_n_op_rejected);
46790 + fscache_stat_unchecked(&fscache_n_op_rejected);
46791 ret = -ENOBUFS;
46792 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
46793 fscache_report_unexpected_submission(object, op, ostate);
46794 @@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
46795
46796 ret = -EBUSY;
46797 if (!list_empty(&op->pend_link)) {
46798 - fscache_stat(&fscache_n_op_cancelled);
46799 + fscache_stat_unchecked(&fscache_n_op_cancelled);
46800 list_del_init(&op->pend_link);
46801 object->n_ops--;
46802 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
46803 @@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
46804 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
46805 BUG();
46806
46807 - fscache_stat(&fscache_n_op_release);
46808 + fscache_stat_unchecked(&fscache_n_op_release);
46809
46810 if (op->release) {
46811 op->release(op);
46812 @@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
46813 * lock, and defer it otherwise */
46814 if (!spin_trylock(&object->lock)) {
46815 _debug("defer put");
46816 - fscache_stat(&fscache_n_op_deferred_release);
46817 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
46818
46819 cache = object->cache;
46820 spin_lock(&cache->op_gc_list_lock);
46821 @@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
46822
46823 _debug("GC DEFERRED REL OBJ%x OP%x",
46824 object->debug_id, op->debug_id);
46825 - fscache_stat(&fscache_n_op_gc);
46826 + fscache_stat_unchecked(&fscache_n_op_gc);
46827
46828 ASSERTCMP(atomic_read(&op->usage), ==, 0);
46829
46830 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
46831 index 3f7a59b..cf196cc 100644
46832 --- a/fs/fscache/page.c
46833 +++ b/fs/fscache/page.c
46834 @@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
46835 val = radix_tree_lookup(&cookie->stores, page->index);
46836 if (!val) {
46837 rcu_read_unlock();
46838 - fscache_stat(&fscache_n_store_vmscan_not_storing);
46839 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
46840 __fscache_uncache_page(cookie, page);
46841 return true;
46842 }
46843 @@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
46844 spin_unlock(&cookie->stores_lock);
46845
46846 if (xpage) {
46847 - fscache_stat(&fscache_n_store_vmscan_cancelled);
46848 - fscache_stat(&fscache_n_store_radix_deletes);
46849 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
46850 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46851 ASSERTCMP(xpage, ==, page);
46852 } else {
46853 - fscache_stat(&fscache_n_store_vmscan_gone);
46854 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
46855 }
46856
46857 wake_up_bit(&cookie->flags, 0);
46858 @@ -107,7 +107,7 @@ page_busy:
46859 /* we might want to wait here, but that could deadlock the allocator as
46860 * the work threads writing to the cache may all end up sleeping
46861 * on memory allocation */
46862 - fscache_stat(&fscache_n_store_vmscan_busy);
46863 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
46864 return false;
46865 }
46866 EXPORT_SYMBOL(__fscache_maybe_release_page);
46867 @@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
46868 FSCACHE_COOKIE_STORING_TAG);
46869 if (!radix_tree_tag_get(&cookie->stores, page->index,
46870 FSCACHE_COOKIE_PENDING_TAG)) {
46871 - fscache_stat(&fscache_n_store_radix_deletes);
46872 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46873 xpage = radix_tree_delete(&cookie->stores, page->index);
46874 }
46875 spin_unlock(&cookie->stores_lock);
46876 @@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
46877
46878 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
46879
46880 - fscache_stat(&fscache_n_attr_changed_calls);
46881 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
46882
46883 if (fscache_object_is_active(object)) {
46884 fscache_stat(&fscache_n_cop_attr_changed);
46885 @@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46886
46887 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46888
46889 - fscache_stat(&fscache_n_attr_changed);
46890 + fscache_stat_unchecked(&fscache_n_attr_changed);
46891
46892 op = kzalloc(sizeof(*op), GFP_KERNEL);
46893 if (!op) {
46894 - fscache_stat(&fscache_n_attr_changed_nomem);
46895 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
46896 _leave(" = -ENOMEM");
46897 return -ENOMEM;
46898 }
46899 @@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46900 if (fscache_submit_exclusive_op(object, op) < 0)
46901 goto nobufs;
46902 spin_unlock(&cookie->lock);
46903 - fscache_stat(&fscache_n_attr_changed_ok);
46904 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
46905 fscache_put_operation(op);
46906 _leave(" = 0");
46907 return 0;
46908 @@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46909 nobufs:
46910 spin_unlock(&cookie->lock);
46911 kfree(op);
46912 - fscache_stat(&fscache_n_attr_changed_nobufs);
46913 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
46914 _leave(" = %d", -ENOBUFS);
46915 return -ENOBUFS;
46916 }
46917 @@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
46918 /* allocate a retrieval operation and attempt to submit it */
46919 op = kzalloc(sizeof(*op), GFP_NOIO);
46920 if (!op) {
46921 - fscache_stat(&fscache_n_retrievals_nomem);
46922 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46923 return NULL;
46924 }
46925
46926 @@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
46927 return 0;
46928 }
46929
46930 - fscache_stat(&fscache_n_retrievals_wait);
46931 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
46932
46933 jif = jiffies;
46934 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
46935 fscache_wait_bit_interruptible,
46936 TASK_INTERRUPTIBLE) != 0) {
46937 - fscache_stat(&fscache_n_retrievals_intr);
46938 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46939 _leave(" = -ERESTARTSYS");
46940 return -ERESTARTSYS;
46941 }
46942 @@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
46943 */
46944 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46945 struct fscache_retrieval *op,
46946 - atomic_t *stat_op_waits,
46947 - atomic_t *stat_object_dead)
46948 + atomic_unchecked_t *stat_op_waits,
46949 + atomic_unchecked_t *stat_object_dead)
46950 {
46951 int ret;
46952
46953 @@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46954 goto check_if_dead;
46955
46956 _debug(">>> WT");
46957 - fscache_stat(stat_op_waits);
46958 + fscache_stat_unchecked(stat_op_waits);
46959 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
46960 fscache_wait_bit_interruptible,
46961 TASK_INTERRUPTIBLE) < 0) {
46962 @@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46963
46964 check_if_dead:
46965 if (unlikely(fscache_object_is_dead(object))) {
46966 - fscache_stat(stat_object_dead);
46967 + fscache_stat_unchecked(stat_object_dead);
46968 return -ENOBUFS;
46969 }
46970 return 0;
46971 @@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46972
46973 _enter("%p,%p,,,", cookie, page);
46974
46975 - fscache_stat(&fscache_n_retrievals);
46976 + fscache_stat_unchecked(&fscache_n_retrievals);
46977
46978 if (hlist_empty(&cookie->backing_objects))
46979 goto nobufs;
46980 @@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46981 goto nobufs_unlock;
46982 spin_unlock(&cookie->lock);
46983
46984 - fscache_stat(&fscache_n_retrieval_ops);
46985 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
46986
46987 /* pin the netfs read context in case we need to do the actual netfs
46988 * read because we've encountered a cache read failure */
46989 @@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46990
46991 error:
46992 if (ret == -ENOMEM)
46993 - fscache_stat(&fscache_n_retrievals_nomem);
46994 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46995 else if (ret == -ERESTARTSYS)
46996 - fscache_stat(&fscache_n_retrievals_intr);
46997 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46998 else if (ret == -ENODATA)
46999 - fscache_stat(&fscache_n_retrievals_nodata);
47000 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
47001 else if (ret < 0)
47002 - fscache_stat(&fscache_n_retrievals_nobufs);
47003 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
47004 else
47005 - fscache_stat(&fscache_n_retrievals_ok);
47006 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
47007
47008 fscache_put_retrieval(op);
47009 _leave(" = %d", ret);
47010 @@ -429,7 +429,7 @@ nobufs_unlock:
47011 spin_unlock(&cookie->lock);
47012 kfree(op);
47013 nobufs:
47014 - fscache_stat(&fscache_n_retrievals_nobufs);
47015 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
47016 _leave(" = -ENOBUFS");
47017 return -ENOBUFS;
47018 }
47019 @@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
47020
47021 _enter("%p,,%d,,,", cookie, *nr_pages);
47022
47023 - fscache_stat(&fscache_n_retrievals);
47024 + fscache_stat_unchecked(&fscache_n_retrievals);
47025
47026 if (hlist_empty(&cookie->backing_objects))
47027 goto nobufs;
47028 @@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
47029 goto nobufs_unlock;
47030 spin_unlock(&cookie->lock);
47031
47032 - fscache_stat(&fscache_n_retrieval_ops);
47033 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
47034
47035 /* pin the netfs read context in case we need to do the actual netfs
47036 * read because we've encountered a cache read failure */
47037 @@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
47038
47039 error:
47040 if (ret == -ENOMEM)
47041 - fscache_stat(&fscache_n_retrievals_nomem);
47042 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
47043 else if (ret == -ERESTARTSYS)
47044 - fscache_stat(&fscache_n_retrievals_intr);
47045 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
47046 else if (ret == -ENODATA)
47047 - fscache_stat(&fscache_n_retrievals_nodata);
47048 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
47049 else if (ret < 0)
47050 - fscache_stat(&fscache_n_retrievals_nobufs);
47051 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
47052 else
47053 - fscache_stat(&fscache_n_retrievals_ok);
47054 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
47055
47056 fscache_put_retrieval(op);
47057 _leave(" = %d", ret);
47058 @@ -545,7 +545,7 @@ nobufs_unlock:
47059 spin_unlock(&cookie->lock);
47060 kfree(op);
47061 nobufs:
47062 - fscache_stat(&fscache_n_retrievals_nobufs);
47063 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
47064 _leave(" = -ENOBUFS");
47065 return -ENOBUFS;
47066 }
47067 @@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
47068
47069 _enter("%p,%p,,,", cookie, page);
47070
47071 - fscache_stat(&fscache_n_allocs);
47072 + fscache_stat_unchecked(&fscache_n_allocs);
47073
47074 if (hlist_empty(&cookie->backing_objects))
47075 goto nobufs;
47076 @@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
47077 goto nobufs_unlock;
47078 spin_unlock(&cookie->lock);
47079
47080 - fscache_stat(&fscache_n_alloc_ops);
47081 + fscache_stat_unchecked(&fscache_n_alloc_ops);
47082
47083 ret = fscache_wait_for_retrieval_activation(
47084 object, op,
47085 @@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
47086
47087 error:
47088 if (ret == -ERESTARTSYS)
47089 - fscache_stat(&fscache_n_allocs_intr);
47090 + fscache_stat_unchecked(&fscache_n_allocs_intr);
47091 else if (ret < 0)
47092 - fscache_stat(&fscache_n_allocs_nobufs);
47093 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
47094 else
47095 - fscache_stat(&fscache_n_allocs_ok);
47096 + fscache_stat_unchecked(&fscache_n_allocs_ok);
47097
47098 fscache_put_retrieval(op);
47099 _leave(" = %d", ret);
47100 @@ -625,7 +625,7 @@ nobufs_unlock:
47101 spin_unlock(&cookie->lock);
47102 kfree(op);
47103 nobufs:
47104 - fscache_stat(&fscache_n_allocs_nobufs);
47105 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
47106 _leave(" = -ENOBUFS");
47107 return -ENOBUFS;
47108 }
47109 @@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
47110
47111 spin_lock(&cookie->stores_lock);
47112
47113 - fscache_stat(&fscache_n_store_calls);
47114 + fscache_stat_unchecked(&fscache_n_store_calls);
47115
47116 /* find a page to store */
47117 page = NULL;
47118 @@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
47119 page = results[0];
47120 _debug("gang %d [%lx]", n, page->index);
47121 if (page->index > op->store_limit) {
47122 - fscache_stat(&fscache_n_store_pages_over_limit);
47123 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
47124 goto superseded;
47125 }
47126
47127 @@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
47128 spin_unlock(&cookie->stores_lock);
47129 spin_unlock(&object->lock);
47130
47131 - fscache_stat(&fscache_n_store_pages);
47132 + fscache_stat_unchecked(&fscache_n_store_pages);
47133 fscache_stat(&fscache_n_cop_write_page);
47134 ret = object->cache->ops->write_page(op, page);
47135 fscache_stat_d(&fscache_n_cop_write_page);
47136 @@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
47137 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
47138 ASSERT(PageFsCache(page));
47139
47140 - fscache_stat(&fscache_n_stores);
47141 + fscache_stat_unchecked(&fscache_n_stores);
47142
47143 op = kzalloc(sizeof(*op), GFP_NOIO);
47144 if (!op)
47145 @@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
47146 spin_unlock(&cookie->stores_lock);
47147 spin_unlock(&object->lock);
47148
47149 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
47150 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
47151 op->store_limit = object->store_limit;
47152
47153 if (fscache_submit_op(object, &op->op) < 0)
47154 @@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
47155
47156 spin_unlock(&cookie->lock);
47157 radix_tree_preload_end();
47158 - fscache_stat(&fscache_n_store_ops);
47159 - fscache_stat(&fscache_n_stores_ok);
47160 + fscache_stat_unchecked(&fscache_n_store_ops);
47161 + fscache_stat_unchecked(&fscache_n_stores_ok);
47162
47163 /* the work queue now carries its own ref on the object */
47164 fscache_put_operation(&op->op);
47165 @@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
47166 return 0;
47167
47168 already_queued:
47169 - fscache_stat(&fscache_n_stores_again);
47170 + fscache_stat_unchecked(&fscache_n_stores_again);
47171 already_pending:
47172 spin_unlock(&cookie->stores_lock);
47173 spin_unlock(&object->lock);
47174 spin_unlock(&cookie->lock);
47175 radix_tree_preload_end();
47176 kfree(op);
47177 - fscache_stat(&fscache_n_stores_ok);
47178 + fscache_stat_unchecked(&fscache_n_stores_ok);
47179 _leave(" = 0");
47180 return 0;
47181
47182 @@ -851,14 +851,14 @@ nobufs:
47183 spin_unlock(&cookie->lock);
47184 radix_tree_preload_end();
47185 kfree(op);
47186 - fscache_stat(&fscache_n_stores_nobufs);
47187 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
47188 _leave(" = -ENOBUFS");
47189 return -ENOBUFS;
47190
47191 nomem_free:
47192 kfree(op);
47193 nomem:
47194 - fscache_stat(&fscache_n_stores_oom);
47195 + fscache_stat_unchecked(&fscache_n_stores_oom);
47196 _leave(" = -ENOMEM");
47197 return -ENOMEM;
47198 }
47199 @@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
47200 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
47201 ASSERTCMP(page, !=, NULL);
47202
47203 - fscache_stat(&fscache_n_uncaches);
47204 + fscache_stat_unchecked(&fscache_n_uncaches);
47205
47206 /* cache withdrawal may beat us to it */
47207 if (!PageFsCache(page))
47208 @@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
47209 unsigned long loop;
47210
47211 #ifdef CONFIG_FSCACHE_STATS
47212 - atomic_add(pagevec->nr, &fscache_n_marks);
47213 + atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
47214 #endif
47215
47216 for (loop = 0; loop < pagevec->nr; loop++) {
47217 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
47218 index 4765190..2a067f2 100644
47219 --- a/fs/fscache/stats.c
47220 +++ b/fs/fscache/stats.c
47221 @@ -18,95 +18,95 @@
47222 /*
47223 * operation counters
47224 */
47225 -atomic_t fscache_n_op_pend;
47226 -atomic_t fscache_n_op_run;
47227 -atomic_t fscache_n_op_enqueue;
47228 -atomic_t fscache_n_op_requeue;
47229 -atomic_t fscache_n_op_deferred_release;
47230 -atomic_t fscache_n_op_release;
47231 -atomic_t fscache_n_op_gc;
47232 -atomic_t fscache_n_op_cancelled;
47233 -atomic_t fscache_n_op_rejected;
47234 +atomic_unchecked_t fscache_n_op_pend;
47235 +atomic_unchecked_t fscache_n_op_run;
47236 +atomic_unchecked_t fscache_n_op_enqueue;
47237 +atomic_unchecked_t fscache_n_op_requeue;
47238 +atomic_unchecked_t fscache_n_op_deferred_release;
47239 +atomic_unchecked_t fscache_n_op_release;
47240 +atomic_unchecked_t fscache_n_op_gc;
47241 +atomic_unchecked_t fscache_n_op_cancelled;
47242 +atomic_unchecked_t fscache_n_op_rejected;
47243
47244 -atomic_t fscache_n_attr_changed;
47245 -atomic_t fscache_n_attr_changed_ok;
47246 -atomic_t fscache_n_attr_changed_nobufs;
47247 -atomic_t fscache_n_attr_changed_nomem;
47248 -atomic_t fscache_n_attr_changed_calls;
47249 +atomic_unchecked_t fscache_n_attr_changed;
47250 +atomic_unchecked_t fscache_n_attr_changed_ok;
47251 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
47252 +atomic_unchecked_t fscache_n_attr_changed_nomem;
47253 +atomic_unchecked_t fscache_n_attr_changed_calls;
47254
47255 -atomic_t fscache_n_allocs;
47256 -atomic_t fscache_n_allocs_ok;
47257 -atomic_t fscache_n_allocs_wait;
47258 -atomic_t fscache_n_allocs_nobufs;
47259 -atomic_t fscache_n_allocs_intr;
47260 -atomic_t fscache_n_allocs_object_dead;
47261 -atomic_t fscache_n_alloc_ops;
47262 -atomic_t fscache_n_alloc_op_waits;
47263 +atomic_unchecked_t fscache_n_allocs;
47264 +atomic_unchecked_t fscache_n_allocs_ok;
47265 +atomic_unchecked_t fscache_n_allocs_wait;
47266 +atomic_unchecked_t fscache_n_allocs_nobufs;
47267 +atomic_unchecked_t fscache_n_allocs_intr;
47268 +atomic_unchecked_t fscache_n_allocs_object_dead;
47269 +atomic_unchecked_t fscache_n_alloc_ops;
47270 +atomic_unchecked_t fscache_n_alloc_op_waits;
47271
47272 -atomic_t fscache_n_retrievals;
47273 -atomic_t fscache_n_retrievals_ok;
47274 -atomic_t fscache_n_retrievals_wait;
47275 -atomic_t fscache_n_retrievals_nodata;
47276 -atomic_t fscache_n_retrievals_nobufs;
47277 -atomic_t fscache_n_retrievals_intr;
47278 -atomic_t fscache_n_retrievals_nomem;
47279 -atomic_t fscache_n_retrievals_object_dead;
47280 -atomic_t fscache_n_retrieval_ops;
47281 -atomic_t fscache_n_retrieval_op_waits;
47282 +atomic_unchecked_t fscache_n_retrievals;
47283 +atomic_unchecked_t fscache_n_retrievals_ok;
47284 +atomic_unchecked_t fscache_n_retrievals_wait;
47285 +atomic_unchecked_t fscache_n_retrievals_nodata;
47286 +atomic_unchecked_t fscache_n_retrievals_nobufs;
47287 +atomic_unchecked_t fscache_n_retrievals_intr;
47288 +atomic_unchecked_t fscache_n_retrievals_nomem;
47289 +atomic_unchecked_t fscache_n_retrievals_object_dead;
47290 +atomic_unchecked_t fscache_n_retrieval_ops;
47291 +atomic_unchecked_t fscache_n_retrieval_op_waits;
47292
47293 -atomic_t fscache_n_stores;
47294 -atomic_t fscache_n_stores_ok;
47295 -atomic_t fscache_n_stores_again;
47296 -atomic_t fscache_n_stores_nobufs;
47297 -atomic_t fscache_n_stores_oom;
47298 -atomic_t fscache_n_store_ops;
47299 -atomic_t fscache_n_store_calls;
47300 -atomic_t fscache_n_store_pages;
47301 -atomic_t fscache_n_store_radix_deletes;
47302 -atomic_t fscache_n_store_pages_over_limit;
47303 +atomic_unchecked_t fscache_n_stores;
47304 +atomic_unchecked_t fscache_n_stores_ok;
47305 +atomic_unchecked_t fscache_n_stores_again;
47306 +atomic_unchecked_t fscache_n_stores_nobufs;
47307 +atomic_unchecked_t fscache_n_stores_oom;
47308 +atomic_unchecked_t fscache_n_store_ops;
47309 +atomic_unchecked_t fscache_n_store_calls;
47310 +atomic_unchecked_t fscache_n_store_pages;
47311 +atomic_unchecked_t fscache_n_store_radix_deletes;
47312 +atomic_unchecked_t fscache_n_store_pages_over_limit;
47313
47314 -atomic_t fscache_n_store_vmscan_not_storing;
47315 -atomic_t fscache_n_store_vmscan_gone;
47316 -atomic_t fscache_n_store_vmscan_busy;
47317 -atomic_t fscache_n_store_vmscan_cancelled;
47318 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
47319 +atomic_unchecked_t fscache_n_store_vmscan_gone;
47320 +atomic_unchecked_t fscache_n_store_vmscan_busy;
47321 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
47322
47323 -atomic_t fscache_n_marks;
47324 -atomic_t fscache_n_uncaches;
47325 +atomic_unchecked_t fscache_n_marks;
47326 +atomic_unchecked_t fscache_n_uncaches;
47327
47328 -atomic_t fscache_n_acquires;
47329 -atomic_t fscache_n_acquires_null;
47330 -atomic_t fscache_n_acquires_no_cache;
47331 -atomic_t fscache_n_acquires_ok;
47332 -atomic_t fscache_n_acquires_nobufs;
47333 -atomic_t fscache_n_acquires_oom;
47334 +atomic_unchecked_t fscache_n_acquires;
47335 +atomic_unchecked_t fscache_n_acquires_null;
47336 +atomic_unchecked_t fscache_n_acquires_no_cache;
47337 +atomic_unchecked_t fscache_n_acquires_ok;
47338 +atomic_unchecked_t fscache_n_acquires_nobufs;
47339 +atomic_unchecked_t fscache_n_acquires_oom;
47340
47341 -atomic_t fscache_n_updates;
47342 -atomic_t fscache_n_updates_null;
47343 -atomic_t fscache_n_updates_run;
47344 +atomic_unchecked_t fscache_n_updates;
47345 +atomic_unchecked_t fscache_n_updates_null;
47346 +atomic_unchecked_t fscache_n_updates_run;
47347
47348 -atomic_t fscache_n_relinquishes;
47349 -atomic_t fscache_n_relinquishes_null;
47350 -atomic_t fscache_n_relinquishes_waitcrt;
47351 -atomic_t fscache_n_relinquishes_retire;
47352 +atomic_unchecked_t fscache_n_relinquishes;
47353 +atomic_unchecked_t fscache_n_relinquishes_null;
47354 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
47355 +atomic_unchecked_t fscache_n_relinquishes_retire;
47356
47357 -atomic_t fscache_n_cookie_index;
47358 -atomic_t fscache_n_cookie_data;
47359 -atomic_t fscache_n_cookie_special;
47360 +atomic_unchecked_t fscache_n_cookie_index;
47361 +atomic_unchecked_t fscache_n_cookie_data;
47362 +atomic_unchecked_t fscache_n_cookie_special;
47363
47364 -atomic_t fscache_n_object_alloc;
47365 -atomic_t fscache_n_object_no_alloc;
47366 -atomic_t fscache_n_object_lookups;
47367 -atomic_t fscache_n_object_lookups_negative;
47368 -atomic_t fscache_n_object_lookups_positive;
47369 -atomic_t fscache_n_object_lookups_timed_out;
47370 -atomic_t fscache_n_object_created;
47371 -atomic_t fscache_n_object_avail;
47372 -atomic_t fscache_n_object_dead;
47373 +atomic_unchecked_t fscache_n_object_alloc;
47374 +atomic_unchecked_t fscache_n_object_no_alloc;
47375 +atomic_unchecked_t fscache_n_object_lookups;
47376 +atomic_unchecked_t fscache_n_object_lookups_negative;
47377 +atomic_unchecked_t fscache_n_object_lookups_positive;
47378 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
47379 +atomic_unchecked_t fscache_n_object_created;
47380 +atomic_unchecked_t fscache_n_object_avail;
47381 +atomic_unchecked_t fscache_n_object_dead;
47382
47383 -atomic_t fscache_n_checkaux_none;
47384 -atomic_t fscache_n_checkaux_okay;
47385 -atomic_t fscache_n_checkaux_update;
47386 -atomic_t fscache_n_checkaux_obsolete;
47387 +atomic_unchecked_t fscache_n_checkaux_none;
47388 +atomic_unchecked_t fscache_n_checkaux_okay;
47389 +atomic_unchecked_t fscache_n_checkaux_update;
47390 +atomic_unchecked_t fscache_n_checkaux_obsolete;
47391
47392 atomic_t fscache_n_cop_alloc_object;
47393 atomic_t fscache_n_cop_lookup_object;
47394 @@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
47395 seq_puts(m, "FS-Cache statistics\n");
47396
47397 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
47398 - atomic_read(&fscache_n_cookie_index),
47399 - atomic_read(&fscache_n_cookie_data),
47400 - atomic_read(&fscache_n_cookie_special));
47401 + atomic_read_unchecked(&fscache_n_cookie_index),
47402 + atomic_read_unchecked(&fscache_n_cookie_data),
47403 + atomic_read_unchecked(&fscache_n_cookie_special));
47404
47405 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
47406 - atomic_read(&fscache_n_object_alloc),
47407 - atomic_read(&fscache_n_object_no_alloc),
47408 - atomic_read(&fscache_n_object_avail),
47409 - atomic_read(&fscache_n_object_dead));
47410 + atomic_read_unchecked(&fscache_n_object_alloc),
47411 + atomic_read_unchecked(&fscache_n_object_no_alloc),
47412 + atomic_read_unchecked(&fscache_n_object_avail),
47413 + atomic_read_unchecked(&fscache_n_object_dead));
47414 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
47415 - atomic_read(&fscache_n_checkaux_none),
47416 - atomic_read(&fscache_n_checkaux_okay),
47417 - atomic_read(&fscache_n_checkaux_update),
47418 - atomic_read(&fscache_n_checkaux_obsolete));
47419 + atomic_read_unchecked(&fscache_n_checkaux_none),
47420 + atomic_read_unchecked(&fscache_n_checkaux_okay),
47421 + atomic_read_unchecked(&fscache_n_checkaux_update),
47422 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
47423
47424 seq_printf(m, "Pages : mrk=%u unc=%u\n",
47425 - atomic_read(&fscache_n_marks),
47426 - atomic_read(&fscache_n_uncaches));
47427 + atomic_read_unchecked(&fscache_n_marks),
47428 + atomic_read_unchecked(&fscache_n_uncaches));
47429
47430 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
47431 " oom=%u\n",
47432 - atomic_read(&fscache_n_acquires),
47433 - atomic_read(&fscache_n_acquires_null),
47434 - atomic_read(&fscache_n_acquires_no_cache),
47435 - atomic_read(&fscache_n_acquires_ok),
47436 - atomic_read(&fscache_n_acquires_nobufs),
47437 - atomic_read(&fscache_n_acquires_oom));
47438 + atomic_read_unchecked(&fscache_n_acquires),
47439 + atomic_read_unchecked(&fscache_n_acquires_null),
47440 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
47441 + atomic_read_unchecked(&fscache_n_acquires_ok),
47442 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
47443 + atomic_read_unchecked(&fscache_n_acquires_oom));
47444
47445 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
47446 - atomic_read(&fscache_n_object_lookups),
47447 - atomic_read(&fscache_n_object_lookups_negative),
47448 - atomic_read(&fscache_n_object_lookups_positive),
47449 - atomic_read(&fscache_n_object_created),
47450 - atomic_read(&fscache_n_object_lookups_timed_out));
47451 + atomic_read_unchecked(&fscache_n_object_lookups),
47452 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
47453 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
47454 + atomic_read_unchecked(&fscache_n_object_created),
47455 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
47456
47457 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
47458 - atomic_read(&fscache_n_updates),
47459 - atomic_read(&fscache_n_updates_null),
47460 - atomic_read(&fscache_n_updates_run));
47461 + atomic_read_unchecked(&fscache_n_updates),
47462 + atomic_read_unchecked(&fscache_n_updates_null),
47463 + atomic_read_unchecked(&fscache_n_updates_run));
47464
47465 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
47466 - atomic_read(&fscache_n_relinquishes),
47467 - atomic_read(&fscache_n_relinquishes_null),
47468 - atomic_read(&fscache_n_relinquishes_waitcrt),
47469 - atomic_read(&fscache_n_relinquishes_retire));
47470 + atomic_read_unchecked(&fscache_n_relinquishes),
47471 + atomic_read_unchecked(&fscache_n_relinquishes_null),
47472 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
47473 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
47474
47475 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
47476 - atomic_read(&fscache_n_attr_changed),
47477 - atomic_read(&fscache_n_attr_changed_ok),
47478 - atomic_read(&fscache_n_attr_changed_nobufs),
47479 - atomic_read(&fscache_n_attr_changed_nomem),
47480 - atomic_read(&fscache_n_attr_changed_calls));
47481 + atomic_read_unchecked(&fscache_n_attr_changed),
47482 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
47483 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
47484 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
47485 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
47486
47487 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
47488 - atomic_read(&fscache_n_allocs),
47489 - atomic_read(&fscache_n_allocs_ok),
47490 - atomic_read(&fscache_n_allocs_wait),
47491 - atomic_read(&fscache_n_allocs_nobufs),
47492 - atomic_read(&fscache_n_allocs_intr));
47493 + atomic_read_unchecked(&fscache_n_allocs),
47494 + atomic_read_unchecked(&fscache_n_allocs_ok),
47495 + atomic_read_unchecked(&fscache_n_allocs_wait),
47496 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
47497 + atomic_read_unchecked(&fscache_n_allocs_intr));
47498 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
47499 - atomic_read(&fscache_n_alloc_ops),
47500 - atomic_read(&fscache_n_alloc_op_waits),
47501 - atomic_read(&fscache_n_allocs_object_dead));
47502 + atomic_read_unchecked(&fscache_n_alloc_ops),
47503 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
47504 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
47505
47506 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
47507 " int=%u oom=%u\n",
47508 - atomic_read(&fscache_n_retrievals),
47509 - atomic_read(&fscache_n_retrievals_ok),
47510 - atomic_read(&fscache_n_retrievals_wait),
47511 - atomic_read(&fscache_n_retrievals_nodata),
47512 - atomic_read(&fscache_n_retrievals_nobufs),
47513 - atomic_read(&fscache_n_retrievals_intr),
47514 - atomic_read(&fscache_n_retrievals_nomem));
47515 + atomic_read_unchecked(&fscache_n_retrievals),
47516 + atomic_read_unchecked(&fscache_n_retrievals_ok),
47517 + atomic_read_unchecked(&fscache_n_retrievals_wait),
47518 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
47519 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
47520 + atomic_read_unchecked(&fscache_n_retrievals_intr),
47521 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
47522 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
47523 - atomic_read(&fscache_n_retrieval_ops),
47524 - atomic_read(&fscache_n_retrieval_op_waits),
47525 - atomic_read(&fscache_n_retrievals_object_dead));
47526 + atomic_read_unchecked(&fscache_n_retrieval_ops),
47527 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
47528 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
47529
47530 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
47531 - atomic_read(&fscache_n_stores),
47532 - atomic_read(&fscache_n_stores_ok),
47533 - atomic_read(&fscache_n_stores_again),
47534 - atomic_read(&fscache_n_stores_nobufs),
47535 - atomic_read(&fscache_n_stores_oom));
47536 + atomic_read_unchecked(&fscache_n_stores),
47537 + atomic_read_unchecked(&fscache_n_stores_ok),
47538 + atomic_read_unchecked(&fscache_n_stores_again),
47539 + atomic_read_unchecked(&fscache_n_stores_nobufs),
47540 + atomic_read_unchecked(&fscache_n_stores_oom));
47541 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
47542 - atomic_read(&fscache_n_store_ops),
47543 - atomic_read(&fscache_n_store_calls),
47544 - atomic_read(&fscache_n_store_pages),
47545 - atomic_read(&fscache_n_store_radix_deletes),
47546 - atomic_read(&fscache_n_store_pages_over_limit));
47547 + atomic_read_unchecked(&fscache_n_store_ops),
47548 + atomic_read_unchecked(&fscache_n_store_calls),
47549 + atomic_read_unchecked(&fscache_n_store_pages),
47550 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
47551 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
47552
47553 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
47554 - atomic_read(&fscache_n_store_vmscan_not_storing),
47555 - atomic_read(&fscache_n_store_vmscan_gone),
47556 - atomic_read(&fscache_n_store_vmscan_busy),
47557 - atomic_read(&fscache_n_store_vmscan_cancelled));
47558 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
47559 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
47560 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
47561 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
47562
47563 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
47564 - atomic_read(&fscache_n_op_pend),
47565 - atomic_read(&fscache_n_op_run),
47566 - atomic_read(&fscache_n_op_enqueue),
47567 - atomic_read(&fscache_n_op_cancelled),
47568 - atomic_read(&fscache_n_op_rejected));
47569 + atomic_read_unchecked(&fscache_n_op_pend),
47570 + atomic_read_unchecked(&fscache_n_op_run),
47571 + atomic_read_unchecked(&fscache_n_op_enqueue),
47572 + atomic_read_unchecked(&fscache_n_op_cancelled),
47573 + atomic_read_unchecked(&fscache_n_op_rejected));
47574 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
47575 - atomic_read(&fscache_n_op_deferred_release),
47576 - atomic_read(&fscache_n_op_release),
47577 - atomic_read(&fscache_n_op_gc));
47578 + atomic_read_unchecked(&fscache_n_op_deferred_release),
47579 + atomic_read_unchecked(&fscache_n_op_release),
47580 + atomic_read_unchecked(&fscache_n_op_gc));
47581
47582 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
47583 atomic_read(&fscache_n_cop_alloc_object),
47584 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
47585 index ee8d550..7189d8c 100644
47586 --- a/fs/fuse/cuse.c
47587 +++ b/fs/fuse/cuse.c
47588 @@ -585,10 +585,12 @@ static int __init cuse_init(void)
47589 INIT_LIST_HEAD(&cuse_conntbl[i]);
47590
47591 /* inherit and extend fuse_dev_operations */
47592 - cuse_channel_fops = fuse_dev_operations;
47593 - cuse_channel_fops.owner = THIS_MODULE;
47594 - cuse_channel_fops.open = cuse_channel_open;
47595 - cuse_channel_fops.release = cuse_channel_release;
47596 + pax_open_kernel();
47597 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
47598 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
47599 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
47600 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
47601 + pax_close_kernel();
47602
47603 cuse_class = class_create(THIS_MODULE, "cuse");
47604 if (IS_ERR(cuse_class))
47605 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
47606 index f4246cf..b4aed1d 100644
47607 --- a/fs/fuse/dev.c
47608 +++ b/fs/fuse/dev.c
47609 @@ -1242,7 +1242,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
47610 ret = 0;
47611 pipe_lock(pipe);
47612
47613 - if (!pipe->readers) {
47614 + if (!atomic_read(&pipe->readers)) {
47615 send_sig(SIGPIPE, current, 0);
47616 if (!ret)
47617 ret = -EPIPE;
47618 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
47619 index 324bc08..4fdd56e 100644
47620 --- a/fs/fuse/dir.c
47621 +++ b/fs/fuse/dir.c
47622 @@ -1226,7 +1226,7 @@ static char *read_link(struct dentry *dentry)
47623 return link;
47624 }
47625
47626 -static void free_link(char *link)
47627 +static void free_link(const char *link)
47628 {
47629 if (!IS_ERR(link))
47630 free_page((unsigned long) link);
47631 diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
47632 index 753af3d..f7b021a 100644
47633 --- a/fs/gfs2/inode.c
47634 +++ b/fs/gfs2/inode.c
47635 @@ -1498,7 +1498,7 @@ out:
47636
47637 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
47638 {
47639 - char *s = nd_get_link(nd);
47640 + const char *s = nd_get_link(nd);
47641 if (!IS_ERR(s))
47642 kfree(s);
47643 }
47644 diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c
47645 index a3bde91..2524579 100644
47646 --- a/fs/gfs2/quota.c
47647 +++ b/fs/gfs2/quota.c
47648 @@ -497,8 +497,11 @@ int gfs2_quota_hold(struct gfs2_inode *ip, u32 uid, u32 gid)
47649 struct gfs2_quota_data **qd;
47650 int error;
47651
47652 - if (ip->i_res == NULL)
47653 - gfs2_rs_alloc(ip);
47654 + if (ip->i_res == NULL) {
47655 + error = gfs2_rs_alloc(ip);
47656 + if (error)
47657 + return error;
47658 + }
47659
47660 qd = ip->i_res->rs_qa_qd;
47661
47662 diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c
47663 index c9ed814..4a45d5f 100644
47664 --- a/fs/gfs2/rgrp.c
47665 +++ b/fs/gfs2/rgrp.c
47666 @@ -477,7 +477,6 @@ void gfs2_free_clones(struct gfs2_rgrpd *rgd)
47667 */
47668 int gfs2_rs_alloc(struct gfs2_inode *ip)
47669 {
47670 - int error = 0;
47671 struct gfs2_blkreserv *res;
47672
47673 if (ip->i_res)
47674 @@ -485,7 +484,7 @@ int gfs2_rs_alloc(struct gfs2_inode *ip)
47675
47676 res = kmem_cache_zalloc(gfs2_rsrv_cachep, GFP_NOFS);
47677 if (!res)
47678 - error = -ENOMEM;
47679 + return -ENOMEM;
47680
47681 down_write(&ip->i_rw_mutex);
47682 if (ip->i_res)
47683 @@ -493,7 +492,7 @@ int gfs2_rs_alloc(struct gfs2_inode *ip)
47684 else
47685 ip->i_res = res;
47686 up_write(&ip->i_rw_mutex);
47687 - return error;
47688 + return 0;
47689 }
47690
47691 static void dump_rs(struct seq_file *seq, struct gfs2_blkreserv *rs)
47692 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
47693 index 8349a89..51a0254 100644
47694 --- a/fs/hugetlbfs/inode.c
47695 +++ b/fs/hugetlbfs/inode.c
47696 @@ -920,7 +920,7 @@ static struct file_system_type hugetlbfs_fs_type = {
47697 .kill_sb = kill_litter_super,
47698 };
47699
47700 -static struct vfsmount *hugetlbfs_vfsmount;
47701 +struct vfsmount *hugetlbfs_vfsmount;
47702
47703 static int can_do_hugetlb_shm(void)
47704 {
47705 diff --git a/fs/inode.c b/fs/inode.c
47706 index ac8d904..9f45d40 100644
47707 --- a/fs/inode.c
47708 +++ b/fs/inode.c
47709 @@ -867,8 +867,8 @@ unsigned int get_next_ino(void)
47710
47711 #ifdef CONFIG_SMP
47712 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
47713 - static atomic_t shared_last_ino;
47714 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
47715 + static atomic_unchecked_t shared_last_ino;
47716 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
47717
47718 res = next - LAST_INO_BATCH;
47719 }
47720 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
47721 index 4a6cf28..d3a29d3 100644
47722 --- a/fs/jffs2/erase.c
47723 +++ b/fs/jffs2/erase.c
47724 @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
47725 struct jffs2_unknown_node marker = {
47726 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
47727 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
47728 - .totlen = cpu_to_je32(c->cleanmarker_size)
47729 + .totlen = cpu_to_je32(c->cleanmarker_size),
47730 + .hdr_crc = cpu_to_je32(0)
47731 };
47732
47733 jffs2_prealloc_raw_node_refs(c, jeb, 1);
47734 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
47735 index a6597d6..41b30ec 100644
47736 --- a/fs/jffs2/wbuf.c
47737 +++ b/fs/jffs2/wbuf.c
47738 @@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
47739 {
47740 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
47741 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
47742 - .totlen = constant_cpu_to_je32(8)
47743 + .totlen = constant_cpu_to_je32(8),
47744 + .hdr_crc = constant_cpu_to_je32(0)
47745 };
47746
47747 /*
47748 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
47749 index c55c745..f67ee56 100644
47750 --- a/fs/jfs/super.c
47751 +++ b/fs/jfs/super.c
47752 @@ -806,7 +806,7 @@ static int __init init_jfs_fs(void)
47753
47754 jfs_inode_cachep =
47755 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
47756 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
47757 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
47758 init_once);
47759 if (jfs_inode_cachep == NULL)
47760 return -ENOMEM;
47761 diff --git a/fs/libfs.c b/fs/libfs.c
47762 index a74cb17..37fcbe4 100644
47763 --- a/fs/libfs.c
47764 +++ b/fs/libfs.c
47765 @@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
47766
47767 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
47768 struct dentry *next;
47769 + char d_name[sizeof(next->d_iname)];
47770 + const unsigned char *name;
47771 +
47772 next = list_entry(p, struct dentry, d_u.d_child);
47773 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
47774 if (!simple_positive(next)) {
47775 @@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
47776
47777 spin_unlock(&next->d_lock);
47778 spin_unlock(&dentry->d_lock);
47779 - if (filldir(dirent, next->d_name.name,
47780 + name = next->d_name.name;
47781 + if (name == next->d_iname) {
47782 + memcpy(d_name, name, next->d_name.len);
47783 + name = d_name;
47784 + }
47785 + if (filldir(dirent, name,
47786 next->d_name.len, filp->f_pos,
47787 next->d_inode->i_ino,
47788 dt_type(next->d_inode)) < 0)
47789 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
47790 index 05d2912..760abfa 100644
47791 --- a/fs/lockd/clntproc.c
47792 +++ b/fs/lockd/clntproc.c
47793 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
47794 /*
47795 * Cookie counter for NLM requests
47796 */
47797 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
47798 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
47799
47800 void nlmclnt_next_cookie(struct nlm_cookie *c)
47801 {
47802 - u32 cookie = atomic_inc_return(&nlm_cookie);
47803 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
47804
47805 memcpy(c->data, &cookie, 4);
47806 c->len=4;
47807 diff --git a/fs/locks.c b/fs/locks.c
47808 index 7e81bfc..c3649aa 100644
47809 --- a/fs/locks.c
47810 +++ b/fs/locks.c
47811 @@ -2066,16 +2066,16 @@ void locks_remove_flock(struct file *filp)
47812 return;
47813
47814 if (filp->f_op && filp->f_op->flock) {
47815 - struct file_lock fl = {
47816 + struct file_lock flock = {
47817 .fl_pid = current->tgid,
47818 .fl_file = filp,
47819 .fl_flags = FL_FLOCK,
47820 .fl_type = F_UNLCK,
47821 .fl_end = OFFSET_MAX,
47822 };
47823 - filp->f_op->flock(filp, F_SETLKW, &fl);
47824 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
47825 - fl.fl_ops->fl_release_private(&fl);
47826 + filp->f_op->flock(filp, F_SETLKW, &flock);
47827 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
47828 + flock.fl_ops->fl_release_private(&flock);
47829 }
47830
47831 lock_flocks();
47832 diff --git a/fs/namei.c b/fs/namei.c
47833 index 091c4b7..fbcb268 100644
47834 --- a/fs/namei.c
47835 +++ b/fs/namei.c
47836 @@ -265,16 +265,32 @@ int generic_permission(struct inode *inode, int mask)
47837 if (ret != -EACCES)
47838 return ret;
47839
47840 +#ifdef CONFIG_GRKERNSEC
47841 + /* we'll block if we have to log due to a denied capability use */
47842 + if (mask & MAY_NOT_BLOCK)
47843 + return -ECHILD;
47844 +#endif
47845 +
47846 if (S_ISDIR(inode->i_mode)) {
47847 /* DACs are overridable for directories */
47848 - if (inode_capable(inode, CAP_DAC_OVERRIDE))
47849 - return 0;
47850 if (!(mask & MAY_WRITE))
47851 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
47852 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
47853 + inode_capable(inode, CAP_DAC_READ_SEARCH))
47854 return 0;
47855 + if (inode_capable(inode, CAP_DAC_OVERRIDE))
47856 + return 0;
47857 return -EACCES;
47858 }
47859 /*
47860 + * Searching includes executable on directories, else just read.
47861 + */
47862 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
47863 + if (mask == MAY_READ)
47864 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
47865 + inode_capable(inode, CAP_DAC_READ_SEARCH))
47866 + return 0;
47867 +
47868 + /*
47869 * Read/write DACs are always overridable.
47870 * Executable DACs are overridable when there is
47871 * at least one exec bit set.
47872 @@ -283,14 +299,6 @@ int generic_permission(struct inode *inode, int mask)
47873 if (inode_capable(inode, CAP_DAC_OVERRIDE))
47874 return 0;
47875
47876 - /*
47877 - * Searching includes executable on directories, else just read.
47878 - */
47879 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
47880 - if (mask == MAY_READ)
47881 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
47882 - return 0;
47883 -
47884 return -EACCES;
47885 }
47886
47887 @@ -772,7 +780,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
47888 {
47889 struct dentry *dentry = link->dentry;
47890 int error;
47891 - char *s;
47892 + const char *s;
47893
47894 BUG_ON(nd->flags & LOOKUP_RCU);
47895
47896 @@ -793,6 +801,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
47897 if (error)
47898 goto out_put_nd_path;
47899
47900 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
47901 + dentry->d_inode, dentry, nd->path.mnt)) {
47902 + error = -EACCES;
47903 + goto out_put_nd_path;
47904 + }
47905 +
47906 nd->last_type = LAST_BIND;
47907 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
47908 error = PTR_ERR(*p);
47909 @@ -1550,6 +1564,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
47910 break;
47911 res = walk_component(nd, path, &nd->last,
47912 nd->last_type, LOOKUP_FOLLOW);
47913 + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
47914 + res = -EACCES;
47915 put_link(nd, &link, cookie);
47916 } while (res > 0);
47917
47918 @@ -1648,7 +1664,7 @@ EXPORT_SYMBOL(full_name_hash);
47919 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
47920 {
47921 unsigned long a, b, adata, bdata, mask, hash, len;
47922 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
47923 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
47924
47925 hash = a = 0;
47926 len = -sizeof(unsigned long);
47927 @@ -1943,6 +1959,8 @@ static int path_lookupat(int dfd, const char *name,
47928 if (err)
47929 break;
47930 err = lookup_last(nd, &path);
47931 + if (!err && gr_handle_symlink_owner(&link, nd->inode))
47932 + err = -EACCES;
47933 put_link(nd, &link, cookie);
47934 }
47935 }
47936 @@ -1950,6 +1968,21 @@ static int path_lookupat(int dfd, const char *name,
47937 if (!err)
47938 err = complete_walk(nd);
47939
47940 + if (!(nd->flags & LOOKUP_PARENT)) {
47941 +#ifdef CONFIG_GRKERNSEC
47942 + if (flags & LOOKUP_RCU) {
47943 + if (!err)
47944 + path_put(&nd->path);
47945 + err = -ECHILD;
47946 + } else
47947 +#endif
47948 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47949 + if (!err)
47950 + path_put(&nd->path);
47951 + err = -ENOENT;
47952 + }
47953 + }
47954 +
47955 if (!err && nd->flags & LOOKUP_DIRECTORY) {
47956 if (!nd->inode->i_op->lookup) {
47957 path_put(&nd->path);
47958 @@ -1977,6 +2010,15 @@ static int do_path_lookup(int dfd, const char *name,
47959 retval = path_lookupat(dfd, name, flags | LOOKUP_REVAL, nd);
47960
47961 if (likely(!retval)) {
47962 + if (*name != '/' && nd->path.dentry && nd->inode) {
47963 +#ifdef CONFIG_GRKERNSEC
47964 + if (flags & LOOKUP_RCU)
47965 + return -ECHILD;
47966 +#endif
47967 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
47968 + return -ENOENT;
47969 + }
47970 +
47971 if (unlikely(!audit_dummy_context())) {
47972 if (nd->path.dentry && nd->inode)
47973 audit_inode(name, nd->path.dentry);
47974 @@ -2336,6 +2378,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
47975 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
47976 return -EPERM;
47977
47978 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
47979 + return -EPERM;
47980 + if (gr_handle_rawio(inode))
47981 + return -EPERM;
47982 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
47983 + return -EACCES;
47984 +
47985 return 0;
47986 }
47987
47988 @@ -2557,7 +2606,7 @@ looked_up:
47989 * cleared otherwise prior to returning.
47990 */
47991 static int lookup_open(struct nameidata *nd, struct path *path,
47992 - struct file *file,
47993 + struct path *link, struct file *file,
47994 const struct open_flags *op,
47995 bool got_write, int *opened)
47996 {
47997 @@ -2592,6 +2641,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
47998 /* Negative dentry, just create the file */
47999 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
48000 umode_t mode = op->mode;
48001 +
48002 + if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
48003 + error = -EACCES;
48004 + goto out_dput;
48005 + }
48006 +
48007 + if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
48008 + error = -EACCES;
48009 + goto out_dput;
48010 + }
48011 +
48012 if (!IS_POSIXACL(dir->d_inode))
48013 mode &= ~current_umask();
48014 /*
48015 @@ -2613,6 +2673,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
48016 nd->flags & LOOKUP_EXCL);
48017 if (error)
48018 goto out_dput;
48019 + else
48020 + gr_handle_create(dentry, nd->path.mnt);
48021 }
48022 out_no_open:
48023 path->dentry = dentry;
48024 @@ -2627,7 +2689,7 @@ out_dput:
48025 /*
48026 * Handle the last step of open()
48027 */
48028 -static int do_last(struct nameidata *nd, struct path *path,
48029 +static int do_last(struct nameidata *nd, struct path *path, struct path *link,
48030 struct file *file, const struct open_flags *op,
48031 int *opened, const char *pathname)
48032 {
48033 @@ -2656,16 +2718,44 @@ static int do_last(struct nameidata *nd, struct path *path,
48034 error = complete_walk(nd);
48035 if (error)
48036 return error;
48037 +#ifdef CONFIG_GRKERNSEC
48038 + if (nd->flags & LOOKUP_RCU) {
48039 + error = -ECHILD;
48040 + goto out;
48041 + }
48042 +#endif
48043 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
48044 + error = -ENOENT;
48045 + goto out;
48046 + }
48047 audit_inode(pathname, nd->path.dentry);
48048 if (open_flag & O_CREAT) {
48049 error = -EISDIR;
48050 goto out;
48051 }
48052 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
48053 + error = -EACCES;
48054 + goto out;
48055 + }
48056 goto finish_open;
48057 case LAST_BIND:
48058 error = complete_walk(nd);
48059 if (error)
48060 return error;
48061 +#ifdef CONFIG_GRKERNSEC
48062 + if (nd->flags & LOOKUP_RCU) {
48063 + error = -ECHILD;
48064 + goto out;
48065 + }
48066 +#endif
48067 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
48068 + error = -ENOENT;
48069 + goto out;
48070 + }
48071 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
48072 + error = -EACCES;
48073 + goto out;
48074 + }
48075 audit_inode(pathname, dir);
48076 goto finish_open;
48077 }
48078 @@ -2714,7 +2804,7 @@ retry_lookup:
48079 */
48080 }
48081 mutex_lock(&dir->d_inode->i_mutex);
48082 - error = lookup_open(nd, path, file, op, got_write, opened);
48083 + error = lookup_open(nd, path, link, file, op, got_write, opened);
48084 mutex_unlock(&dir->d_inode->i_mutex);
48085
48086 if (error <= 0) {
48087 @@ -2738,11 +2828,28 @@ retry_lookup:
48088 goto finish_open_created;
48089 }
48090
48091 + if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
48092 + error = -ENOENT;
48093 + goto exit_dput;
48094 + }
48095 + if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
48096 + error = -EACCES;
48097 + goto exit_dput;
48098 + }
48099 +
48100 /*
48101 * create/update audit record if it already exists.
48102 */
48103 - if (path->dentry->d_inode)
48104 + if (path->dentry->d_inode) {
48105 + /* only check if O_CREAT is specified, all other checks need to go
48106 + into may_open */
48107 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
48108 + error = -EACCES;
48109 + goto exit_dput;
48110 + }
48111 +
48112 audit_inode(pathname, path->dentry);
48113 + }
48114
48115 /*
48116 * If atomic_open() acquired write access it is dropped now due to
48117 @@ -2783,6 +2890,11 @@ finish_lookup:
48118 }
48119 }
48120 BUG_ON(inode != path->dentry->d_inode);
48121 + /* if we're resolving a symlink to another symlink */
48122 + if (link && gr_handle_symlink_owner(link, inode)) {
48123 + error = -EACCES;
48124 + goto out;
48125 + }
48126 return 1;
48127 }
48128
48129 @@ -2792,7 +2904,6 @@ finish_lookup:
48130 save_parent.dentry = nd->path.dentry;
48131 save_parent.mnt = mntget(path->mnt);
48132 nd->path.dentry = path->dentry;
48133 -
48134 }
48135 nd->inode = inode;
48136 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
48137 @@ -2801,6 +2912,22 @@ finish_lookup:
48138 path_put(&save_parent);
48139 return error;
48140 }
48141 +
48142 +#ifdef CONFIG_GRKERNSEC
48143 + if (nd->flags & LOOKUP_RCU) {
48144 + error = -ECHILD;
48145 + goto out;
48146 + }
48147 +#endif
48148 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
48149 + error = -ENOENT;
48150 + goto out;
48151 + }
48152 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
48153 + error = -EACCES;
48154 + goto out;
48155 + }
48156 +
48157 error = -EISDIR;
48158 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
48159 goto out;
48160 @@ -2899,7 +3026,7 @@ static struct file *path_openat(int dfd, const char *pathname,
48161 if (unlikely(error))
48162 goto out;
48163
48164 - error = do_last(nd, &path, file, op, &opened, pathname);
48165 + error = do_last(nd, &path, NULL, file, op, &opened, pathname);
48166 while (unlikely(error > 0)) { /* trailing symlink */
48167 struct path link = path;
48168 void *cookie;
48169 @@ -2917,7 +3044,7 @@ static struct file *path_openat(int dfd, const char *pathname,
48170 error = follow_link(&link, nd, &cookie);
48171 if (unlikely(error))
48172 break;
48173 - error = do_last(nd, &path, file, op, &opened, pathname);
48174 + error = do_last(nd, &path, &link, file, op, &opened, pathname);
48175 put_link(nd, &link, cookie);
48176 }
48177 out:
48178 @@ -3006,8 +3133,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
48179 goto unlock;
48180
48181 error = -EEXIST;
48182 - if (dentry->d_inode)
48183 + if (dentry->d_inode) {
48184 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
48185 + error = -ENOENT;
48186 + }
48187 goto fail;
48188 + }
48189 /*
48190 * Special case - lookup gave negative, but... we had foo/bar/
48191 * From the vfs_mknod() POV we just have a negative dentry -
48192 @@ -3058,6 +3189,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
48193 }
48194 EXPORT_SYMBOL(user_path_create);
48195
48196 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, char **to, int is_dir)
48197 +{
48198 + char *tmp = getname(pathname);
48199 + struct dentry *res;
48200 + if (IS_ERR(tmp))
48201 + return ERR_CAST(tmp);
48202 + res = kern_path_create(dfd, tmp, path, is_dir);
48203 + if (IS_ERR(res))
48204 + putname(tmp);
48205 + else
48206 + *to = tmp;
48207 + return res;
48208 +}
48209 +
48210 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
48211 {
48212 int error = may_create(dir, dentry);
48213 @@ -3119,6 +3264,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
48214
48215 if (!IS_POSIXACL(path.dentry->d_inode))
48216 mode &= ~current_umask();
48217 +
48218 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
48219 + error = -EPERM;
48220 + goto out;
48221 + }
48222 +
48223 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
48224 + error = -EACCES;
48225 + goto out;
48226 + }
48227 +
48228 error = security_path_mknod(&path, dentry, mode, dev);
48229 if (error)
48230 goto out;
48231 @@ -3135,6 +3291,8 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
48232 break;
48233 }
48234 out:
48235 + if (!error)
48236 + gr_handle_create(dentry, path.mnt);
48237 done_path_create(&path, dentry);
48238 return error;
48239 }
48240 @@ -3181,9 +3339,18 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode)
48241
48242 if (!IS_POSIXACL(path.dentry->d_inode))
48243 mode &= ~current_umask();
48244 +
48245 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
48246 + error = -EACCES;
48247 + goto out;
48248 + }
48249 +
48250 error = security_path_mkdir(&path, dentry, mode);
48251 if (!error)
48252 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
48253 + if (!error)
48254 + gr_handle_create(dentry, path.mnt);
48255 +out:
48256 done_path_create(&path, dentry);
48257 return error;
48258 }
48259 @@ -3260,6 +3427,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
48260 char * name;
48261 struct dentry *dentry;
48262 struct nameidata nd;
48263 + ino_t saved_ino = 0;
48264 + dev_t saved_dev = 0;
48265
48266 error = user_path_parent(dfd, pathname, &nd, &name);
48267 if (error)
48268 @@ -3291,10 +3460,21 @@ static long do_rmdir(int dfd, const char __user *pathname)
48269 error = -ENOENT;
48270 goto exit3;
48271 }
48272 +
48273 + saved_ino = dentry->d_inode->i_ino;
48274 + saved_dev = gr_get_dev_from_dentry(dentry);
48275 +
48276 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
48277 + error = -EACCES;
48278 + goto exit3;
48279 + }
48280 +
48281 error = security_path_rmdir(&nd.path, dentry);
48282 if (error)
48283 goto exit3;
48284 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
48285 + if (!error && (saved_dev || saved_ino))
48286 + gr_handle_delete(saved_ino, saved_dev);
48287 exit3:
48288 dput(dentry);
48289 exit2:
48290 @@ -3356,6 +3536,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
48291 struct dentry *dentry;
48292 struct nameidata nd;
48293 struct inode *inode = NULL;
48294 + ino_t saved_ino = 0;
48295 + dev_t saved_dev = 0;
48296
48297 error = user_path_parent(dfd, pathname, &nd, &name);
48298 if (error)
48299 @@ -3381,10 +3563,22 @@ static long do_unlinkat(int dfd, const char __user *pathname)
48300 if (!inode)
48301 goto slashes;
48302 ihold(inode);
48303 +
48304 + if (inode->i_nlink <= 1) {
48305 + saved_ino = inode->i_ino;
48306 + saved_dev = gr_get_dev_from_dentry(dentry);
48307 + }
48308 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
48309 + error = -EACCES;
48310 + goto exit2;
48311 + }
48312 +
48313 error = security_path_unlink(&nd.path, dentry);
48314 if (error)
48315 goto exit2;
48316 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
48317 + if (!error && (saved_ino || saved_dev))
48318 + gr_handle_delete(saved_ino, saved_dev);
48319 exit2:
48320 dput(dentry);
48321 }
48322 @@ -3456,9 +3650,17 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
48323 if (IS_ERR(dentry))
48324 goto out_putname;
48325
48326 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
48327 + error = -EACCES;
48328 + goto out;
48329 + }
48330 +
48331 error = security_path_symlink(&path, dentry, from);
48332 if (!error)
48333 error = vfs_symlink(path.dentry->d_inode, dentry, from);
48334 + if (!error)
48335 + gr_handle_create(dentry, path.mnt);
48336 +out:
48337 done_path_create(&path, dentry);
48338 out_putname:
48339 putname(from);
48340 @@ -3528,6 +3730,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
48341 {
48342 struct dentry *new_dentry;
48343 struct path old_path, new_path;
48344 + char *to = NULL;
48345 int how = 0;
48346 int error;
48347
48348 @@ -3551,7 +3754,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
48349 if (error)
48350 return error;
48351
48352 - new_dentry = user_path_create(newdfd, newname, &new_path, 0);
48353 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
48354 error = PTR_ERR(new_dentry);
48355 if (IS_ERR(new_dentry))
48356 goto out;
48357 @@ -3562,11 +3765,28 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
48358 error = may_linkat(&old_path);
48359 if (unlikely(error))
48360 goto out_dput;
48361 +
48362 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
48363 + old_path.dentry->d_inode,
48364 + old_path.dentry->d_inode->i_mode, to)) {
48365 + error = -EACCES;
48366 + goto out_dput;
48367 + }
48368 +
48369 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
48370 + old_path.dentry, old_path.mnt, to)) {
48371 + error = -EACCES;
48372 + goto out_dput;
48373 + }
48374 +
48375 error = security_path_link(old_path.dentry, &new_path, new_dentry);
48376 if (error)
48377 goto out_dput;
48378 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
48379 + if (!error)
48380 + gr_handle_create(new_dentry, new_path.mnt);
48381 out_dput:
48382 + putname(to);
48383 done_path_create(&new_path, new_dentry);
48384 out:
48385 path_put(&old_path);
48386 @@ -3802,12 +4022,21 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
48387 if (new_dentry == trap)
48388 goto exit5;
48389
48390 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
48391 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
48392 + to);
48393 + if (error)
48394 + goto exit5;
48395 +
48396 error = security_path_rename(&oldnd.path, old_dentry,
48397 &newnd.path, new_dentry);
48398 if (error)
48399 goto exit5;
48400 error = vfs_rename(old_dir->d_inode, old_dentry,
48401 new_dir->d_inode, new_dentry);
48402 + if (!error)
48403 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
48404 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
48405 exit5:
48406 dput(new_dentry);
48407 exit4:
48408 @@ -3832,6 +4061,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
48409
48410 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
48411 {
48412 + char tmpbuf[64];
48413 + const char *newlink;
48414 int len;
48415
48416 len = PTR_ERR(link);
48417 @@ -3841,7 +4072,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
48418 len = strlen(link);
48419 if (len > (unsigned) buflen)
48420 len = buflen;
48421 - if (copy_to_user(buffer, link, len))
48422 +
48423 + if (len < sizeof(tmpbuf)) {
48424 + memcpy(tmpbuf, link, len);
48425 + newlink = tmpbuf;
48426 + } else
48427 + newlink = link;
48428 +
48429 + if (copy_to_user(buffer, newlink, len))
48430 len = -EFAULT;
48431 out:
48432 return len;
48433 diff --git a/fs/namespace.c b/fs/namespace.c
48434 index 7bdf790..eb79c4b 100644
48435 --- a/fs/namespace.c
48436 +++ b/fs/namespace.c
48437 @@ -1212,6 +1212,9 @@ static int do_umount(struct mount *mnt, int flags)
48438 if (!(sb->s_flags & MS_RDONLY))
48439 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
48440 up_write(&sb->s_umount);
48441 +
48442 + gr_log_remount(mnt->mnt_devname, retval);
48443 +
48444 return retval;
48445 }
48446
48447 @@ -1231,6 +1234,9 @@ static int do_umount(struct mount *mnt, int flags)
48448 br_write_unlock(&vfsmount_lock);
48449 up_write(&namespace_sem);
48450 release_mounts(&umount_list);
48451 +
48452 + gr_log_unmount(mnt->mnt_devname, retval);
48453 +
48454 return retval;
48455 }
48456
48457 @@ -2244,6 +2250,16 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
48458 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
48459 MS_STRICTATIME);
48460
48461 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
48462 + retval = -EPERM;
48463 + goto dput_out;
48464 + }
48465 +
48466 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
48467 + retval = -EPERM;
48468 + goto dput_out;
48469 + }
48470 +
48471 if (flags & MS_REMOUNT)
48472 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
48473 data_page);
48474 @@ -2258,6 +2274,9 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
48475 dev_name, data_page);
48476 dput_out:
48477 path_put(&path);
48478 +
48479 + gr_log_mount(dev_name, dir_name, retval);
48480 +
48481 return retval;
48482 }
48483
48484 @@ -2516,6 +2535,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
48485 if (error)
48486 goto out2;
48487
48488 + if (gr_handle_chroot_pivot()) {
48489 + error = -EPERM;
48490 + goto out2;
48491 + }
48492 +
48493 get_fs_root(current->fs, &root);
48494 error = lock_mount(&old);
48495 if (error)
48496 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
48497 index 9b47610..066975e 100644
48498 --- a/fs/nfs/inode.c
48499 +++ b/fs/nfs/inode.c
48500 @@ -1026,16 +1026,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
48501 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
48502 }
48503
48504 -static atomic_long_t nfs_attr_generation_counter;
48505 +static atomic_long_unchecked_t nfs_attr_generation_counter;
48506
48507 static unsigned long nfs_read_attr_generation_counter(void)
48508 {
48509 - return atomic_long_read(&nfs_attr_generation_counter);
48510 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
48511 }
48512
48513 unsigned long nfs_inc_attr_generation_counter(void)
48514 {
48515 - return atomic_long_inc_return(&nfs_attr_generation_counter);
48516 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
48517 }
48518
48519 void nfs_fattr_init(struct nfs_fattr *fattr)
48520 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
48521 index a9269f1..5490437 100644
48522 --- a/fs/nfsd/vfs.c
48523 +++ b/fs/nfsd/vfs.c
48524 @@ -941,7 +941,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
48525 } else {
48526 oldfs = get_fs();
48527 set_fs(KERNEL_DS);
48528 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
48529 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
48530 set_fs(oldfs);
48531 }
48532
48533 @@ -1045,7 +1045,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
48534
48535 /* Write the data. */
48536 oldfs = get_fs(); set_fs(KERNEL_DS);
48537 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
48538 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
48539 set_fs(oldfs);
48540 if (host_err < 0)
48541 goto out_nfserr;
48542 @@ -1581,7 +1581,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
48543 */
48544
48545 oldfs = get_fs(); set_fs(KERNEL_DS);
48546 - host_err = inode->i_op->readlink(path.dentry, buf, *lenp);
48547 + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
48548 set_fs(oldfs);
48549
48550 if (host_err < 0)
48551 diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c
48552 index f35794b..a506360 100644
48553 --- a/fs/notify/fanotify/fanotify.c
48554 +++ b/fs/notify/fanotify/fanotify.c
48555 @@ -21,6 +21,7 @@ static bool should_merge(struct fsnotify_event *old, struct fsnotify_event *new)
48556 if ((old->path.mnt == new->path.mnt) &&
48557 (old->path.dentry == new->path.dentry))
48558 return true;
48559 + break;
48560 case (FSNOTIFY_EVENT_NONE):
48561 return true;
48562 default:
48563 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
48564 index d438036..0ecadde 100644
48565 --- a/fs/notify/fanotify/fanotify_user.c
48566 +++ b/fs/notify/fanotify/fanotify_user.c
48567 @@ -274,7 +274,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
48568 goto out_close_fd;
48569
48570 ret = -EFAULT;
48571 - if (copy_to_user(buf, &fanotify_event_metadata,
48572 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
48573 + copy_to_user(buf, &fanotify_event_metadata,
48574 fanotify_event_metadata.event_len))
48575 goto out_kill_access_response;
48576
48577 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
48578 index c887b13..0fdf472 100644
48579 --- a/fs/notify/notification.c
48580 +++ b/fs/notify/notification.c
48581 @@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
48582 * get set to 0 so it will never get 'freed'
48583 */
48584 static struct fsnotify_event *q_overflow_event;
48585 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48586 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48587
48588 /**
48589 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
48590 @@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48591 */
48592 u32 fsnotify_get_cookie(void)
48593 {
48594 - return atomic_inc_return(&fsnotify_sync_cookie);
48595 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
48596 }
48597 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
48598
48599 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
48600 index 99e3610..02c1068 100644
48601 --- a/fs/ntfs/dir.c
48602 +++ b/fs/ntfs/dir.c
48603 @@ -1329,7 +1329,7 @@ find_next_index_buffer:
48604 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
48605 ~(s64)(ndir->itype.index.block_size - 1)));
48606 /* Bounds checks. */
48607 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
48608 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
48609 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
48610 "inode 0x%lx or driver bug.", vdir->i_ino);
48611 goto err_out;
48612 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
48613 index 1ecf464..e1ff8bf 100644
48614 --- a/fs/ntfs/file.c
48615 +++ b/fs/ntfs/file.c
48616 @@ -2232,6 +2232,6 @@ const struct inode_operations ntfs_file_inode_ops = {
48617 #endif /* NTFS_RW */
48618 };
48619
48620 -const struct file_operations ntfs_empty_file_ops = {};
48621 +const struct file_operations ntfs_empty_file_ops __read_only;
48622
48623 -const struct inode_operations ntfs_empty_inode_ops = {};
48624 +const struct inode_operations ntfs_empty_inode_ops __read_only;
48625 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
48626 index a9f78c7..ed8a381 100644
48627 --- a/fs/ocfs2/localalloc.c
48628 +++ b/fs/ocfs2/localalloc.c
48629 @@ -1279,7 +1279,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
48630 goto bail;
48631 }
48632
48633 - atomic_inc(&osb->alloc_stats.moves);
48634 + atomic_inc_unchecked(&osb->alloc_stats.moves);
48635
48636 bail:
48637 if (handle)
48638 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
48639 index d355e6e..578d905 100644
48640 --- a/fs/ocfs2/ocfs2.h
48641 +++ b/fs/ocfs2/ocfs2.h
48642 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
48643
48644 struct ocfs2_alloc_stats
48645 {
48646 - atomic_t moves;
48647 - atomic_t local_data;
48648 - atomic_t bitmap_data;
48649 - atomic_t bg_allocs;
48650 - atomic_t bg_extends;
48651 + atomic_unchecked_t moves;
48652 + atomic_unchecked_t local_data;
48653 + atomic_unchecked_t bitmap_data;
48654 + atomic_unchecked_t bg_allocs;
48655 + atomic_unchecked_t bg_extends;
48656 };
48657
48658 enum ocfs2_local_alloc_state
48659 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
48660 index f169da4..9112253 100644
48661 --- a/fs/ocfs2/suballoc.c
48662 +++ b/fs/ocfs2/suballoc.c
48663 @@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
48664 mlog_errno(status);
48665 goto bail;
48666 }
48667 - atomic_inc(&osb->alloc_stats.bg_extends);
48668 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
48669
48670 /* You should never ask for this much metadata */
48671 BUG_ON(bits_wanted >
48672 @@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
48673 mlog_errno(status);
48674 goto bail;
48675 }
48676 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48677 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48678
48679 *suballoc_loc = res.sr_bg_blkno;
48680 *suballoc_bit_start = res.sr_bit_offset;
48681 @@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
48682 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
48683 res->sr_bits);
48684
48685 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48686 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48687
48688 BUG_ON(res->sr_bits != 1);
48689
48690 @@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
48691 mlog_errno(status);
48692 goto bail;
48693 }
48694 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48695 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48696
48697 BUG_ON(res.sr_bits != 1);
48698
48699 @@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
48700 cluster_start,
48701 num_clusters);
48702 if (!status)
48703 - atomic_inc(&osb->alloc_stats.local_data);
48704 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
48705 } else {
48706 if (min_clusters > (osb->bitmap_cpg - 1)) {
48707 /* The only paths asking for contiguousness
48708 @@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
48709 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
48710 res.sr_bg_blkno,
48711 res.sr_bit_offset);
48712 - atomic_inc(&osb->alloc_stats.bitmap_data);
48713 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
48714 *num_clusters = res.sr_bits;
48715 }
48716 }
48717 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
48718 index 68f4541..89cfe6a 100644
48719 --- a/fs/ocfs2/super.c
48720 +++ b/fs/ocfs2/super.c
48721 @@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
48722 "%10s => GlobalAllocs: %d LocalAllocs: %d "
48723 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
48724 "Stats",
48725 - atomic_read(&osb->alloc_stats.bitmap_data),
48726 - atomic_read(&osb->alloc_stats.local_data),
48727 - atomic_read(&osb->alloc_stats.bg_allocs),
48728 - atomic_read(&osb->alloc_stats.moves),
48729 - atomic_read(&osb->alloc_stats.bg_extends));
48730 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
48731 + atomic_read_unchecked(&osb->alloc_stats.local_data),
48732 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
48733 + atomic_read_unchecked(&osb->alloc_stats.moves),
48734 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
48735
48736 out += snprintf(buf + out, len - out,
48737 "%10s => State: %u Descriptor: %llu Size: %u bits "
48738 @@ -2116,11 +2116,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
48739 spin_lock_init(&osb->osb_xattr_lock);
48740 ocfs2_init_steal_slots(osb);
48741
48742 - atomic_set(&osb->alloc_stats.moves, 0);
48743 - atomic_set(&osb->alloc_stats.local_data, 0);
48744 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
48745 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
48746 - atomic_set(&osb->alloc_stats.bg_extends, 0);
48747 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
48748 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
48749 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
48750 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
48751 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
48752
48753 /* Copy the blockcheck stats from the superblock probe */
48754 osb->osb_ecc_stats = *stats;
48755 diff --git a/fs/open.c b/fs/open.c
48756 index e1f2cdb..3bd5f39 100644
48757 --- a/fs/open.c
48758 +++ b/fs/open.c
48759 @@ -31,6 +31,8 @@
48760 #include <linux/ima.h>
48761 #include <linux/dnotify.h>
48762
48763 +#define CREATE_TRACE_POINTS
48764 +#include <trace/events/fs.h>
48765 #include "internal.h"
48766
48767 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
48768 @@ -112,6 +114,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
48769 error = locks_verify_truncate(inode, NULL, length);
48770 if (!error)
48771 error = security_path_truncate(&path);
48772 +
48773 + if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
48774 + error = -EACCES;
48775 +
48776 if (!error)
48777 error = do_truncate(path.dentry, length, 0, NULL);
48778
48779 @@ -364,6 +370,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
48780 if (__mnt_is_readonly(path.mnt))
48781 res = -EROFS;
48782
48783 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
48784 + res = -EACCES;
48785 +
48786 out_path_release:
48787 path_put(&path);
48788 out:
48789 @@ -390,6 +399,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
48790 if (error)
48791 goto dput_and_out;
48792
48793 + gr_log_chdir(path.dentry, path.mnt);
48794 +
48795 set_fs_pwd(current->fs, &path);
48796
48797 dput_and_out:
48798 @@ -416,6 +427,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
48799 goto out_putf;
48800
48801 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
48802 +
48803 + if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
48804 + error = -EPERM;
48805 +
48806 + if (!error)
48807 + gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
48808 +
48809 if (!error)
48810 set_fs_pwd(current->fs, &file->f_path);
48811 out_putf:
48812 @@ -444,7 +462,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
48813 if (error)
48814 goto dput_and_out;
48815
48816 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
48817 + goto dput_and_out;
48818 +
48819 set_fs_root(current->fs, &path);
48820 +
48821 + gr_handle_chroot_chdir(&path);
48822 +
48823 error = 0;
48824 dput_and_out:
48825 path_put(&path);
48826 @@ -462,6 +486,16 @@ static int chmod_common(struct path *path, umode_t mode)
48827 if (error)
48828 return error;
48829 mutex_lock(&inode->i_mutex);
48830 +
48831 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
48832 + error = -EACCES;
48833 + goto out_unlock;
48834 + }
48835 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
48836 + error = -EACCES;
48837 + goto out_unlock;
48838 + }
48839 +
48840 error = security_path_chmod(path, mode);
48841 if (error)
48842 goto out_unlock;
48843 @@ -517,6 +551,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
48844 uid = make_kuid(current_user_ns(), user);
48845 gid = make_kgid(current_user_ns(), group);
48846
48847 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
48848 + return -EACCES;
48849 +
48850 newattrs.ia_valid = ATTR_CTIME;
48851 if (user != (uid_t) -1) {
48852 if (!uid_valid(uid))
48853 @@ -958,6 +995,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
48854 } else {
48855 fsnotify_open(f);
48856 fd_install(fd, f);
48857 + trace_do_sys_open(tmp, flags, mode);
48858 }
48859 }
48860 putname(tmp);
48861 diff --git a/fs/pipe.c b/fs/pipe.c
48862 index 8d85d70..581036b 100644
48863 --- a/fs/pipe.c
48864 +++ b/fs/pipe.c
48865 @@ -438,9 +438,9 @@ redo:
48866 }
48867 if (bufs) /* More to do? */
48868 continue;
48869 - if (!pipe->writers)
48870 + if (!atomic_read(&pipe->writers))
48871 break;
48872 - if (!pipe->waiting_writers) {
48873 + if (!atomic_read(&pipe->waiting_writers)) {
48874 /* syscall merging: Usually we must not sleep
48875 * if O_NONBLOCK is set, or if we got some data.
48876 * But if a writer sleeps in kernel space, then
48877 @@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
48878 mutex_lock(&inode->i_mutex);
48879 pipe = inode->i_pipe;
48880
48881 - if (!pipe->readers) {
48882 + if (!atomic_read(&pipe->readers)) {
48883 send_sig(SIGPIPE, current, 0);
48884 ret = -EPIPE;
48885 goto out;
48886 @@ -553,7 +553,7 @@ redo1:
48887 for (;;) {
48888 int bufs;
48889
48890 - if (!pipe->readers) {
48891 + if (!atomic_read(&pipe->readers)) {
48892 send_sig(SIGPIPE, current, 0);
48893 if (!ret)
48894 ret = -EPIPE;
48895 @@ -644,9 +644,9 @@ redo2:
48896 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
48897 do_wakeup = 0;
48898 }
48899 - pipe->waiting_writers++;
48900 + atomic_inc(&pipe->waiting_writers);
48901 pipe_wait(pipe);
48902 - pipe->waiting_writers--;
48903 + atomic_dec(&pipe->waiting_writers);
48904 }
48905 out:
48906 mutex_unlock(&inode->i_mutex);
48907 @@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
48908 mask = 0;
48909 if (filp->f_mode & FMODE_READ) {
48910 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
48911 - if (!pipe->writers && filp->f_version != pipe->w_counter)
48912 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
48913 mask |= POLLHUP;
48914 }
48915
48916 @@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
48917 * Most Unices do not set POLLERR for FIFOs but on Linux they
48918 * behave exactly like pipes for poll().
48919 */
48920 - if (!pipe->readers)
48921 + if (!atomic_read(&pipe->readers))
48922 mask |= POLLERR;
48923 }
48924
48925 @@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
48926
48927 mutex_lock(&inode->i_mutex);
48928 pipe = inode->i_pipe;
48929 - pipe->readers -= decr;
48930 - pipe->writers -= decw;
48931 + atomic_sub(decr, &pipe->readers);
48932 + atomic_sub(decw, &pipe->writers);
48933
48934 - if (!pipe->readers && !pipe->writers) {
48935 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
48936 free_pipe_info(inode);
48937 } else {
48938 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
48939 @@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
48940
48941 if (inode->i_pipe) {
48942 ret = 0;
48943 - inode->i_pipe->readers++;
48944 + atomic_inc(&inode->i_pipe->readers);
48945 }
48946
48947 mutex_unlock(&inode->i_mutex);
48948 @@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
48949
48950 if (inode->i_pipe) {
48951 ret = 0;
48952 - inode->i_pipe->writers++;
48953 + atomic_inc(&inode->i_pipe->writers);
48954 }
48955
48956 mutex_unlock(&inode->i_mutex);
48957 @@ -868,9 +868,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
48958 if (inode->i_pipe) {
48959 ret = 0;
48960 if (filp->f_mode & FMODE_READ)
48961 - inode->i_pipe->readers++;
48962 + atomic_inc(&inode->i_pipe->readers);
48963 if (filp->f_mode & FMODE_WRITE)
48964 - inode->i_pipe->writers++;
48965 + atomic_inc(&inode->i_pipe->writers);
48966 }
48967
48968 mutex_unlock(&inode->i_mutex);
48969 @@ -962,7 +962,7 @@ void free_pipe_info(struct inode *inode)
48970 inode->i_pipe = NULL;
48971 }
48972
48973 -static struct vfsmount *pipe_mnt __read_mostly;
48974 +struct vfsmount *pipe_mnt __read_mostly;
48975
48976 /*
48977 * pipefs_dname() is called from d_path().
48978 @@ -992,7 +992,8 @@ static struct inode * get_pipe_inode(void)
48979 goto fail_iput;
48980 inode->i_pipe = pipe;
48981
48982 - pipe->readers = pipe->writers = 1;
48983 + atomic_set(&pipe->readers, 1);
48984 + atomic_set(&pipe->writers, 1);
48985 inode->i_fop = &rdwr_pipefifo_fops;
48986
48987 /*
48988 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
48989 index 15af622..0e9f4467 100644
48990 --- a/fs/proc/Kconfig
48991 +++ b/fs/proc/Kconfig
48992 @@ -30,12 +30,12 @@ config PROC_FS
48993
48994 config PROC_KCORE
48995 bool "/proc/kcore support" if !ARM
48996 - depends on PROC_FS && MMU
48997 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
48998
48999 config PROC_VMCORE
49000 bool "/proc/vmcore support"
49001 - depends on PROC_FS && CRASH_DUMP
49002 - default y
49003 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
49004 + default n
49005 help
49006 Exports the dump image of crashed kernel in ELF format.
49007
49008 @@ -59,8 +59,8 @@ config PROC_SYSCTL
49009 limited in memory.
49010
49011 config PROC_PAGE_MONITOR
49012 - default y
49013 - depends on PROC_FS && MMU
49014 + default n
49015 + depends on PROC_FS && MMU && !GRKERNSEC
49016 bool "Enable /proc page monitoring" if EXPERT
49017 help
49018 Various /proc files exist to monitor process memory utilization:
49019 diff --git a/fs/proc/array.c b/fs/proc/array.c
49020 index c1c207c..01ce725 100644
49021 --- a/fs/proc/array.c
49022 +++ b/fs/proc/array.c
49023 @@ -60,6 +60,7 @@
49024 #include <linux/tty.h>
49025 #include <linux/string.h>
49026 #include <linux/mman.h>
49027 +#include <linux/grsecurity.h>
49028 #include <linux/proc_fs.h>
49029 #include <linux/ioport.h>
49030 #include <linux/uaccess.h>
49031 @@ -346,6 +347,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
49032 seq_putc(m, '\n');
49033 }
49034
49035 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
49036 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
49037 +{
49038 + if (p->mm)
49039 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
49040 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
49041 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
49042 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
49043 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
49044 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
49045 + else
49046 + seq_printf(m, "PaX:\t-----\n");
49047 +}
49048 +#endif
49049 +
49050 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
49051 struct pid *pid, struct task_struct *task)
49052 {
49053 @@ -363,9 +379,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
49054 task_cpus_allowed(m, task);
49055 cpuset_task_status_allowed(m, task);
49056 task_context_switch_counts(m, task);
49057 +
49058 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
49059 + task_pax(m, task);
49060 +#endif
49061 +
49062 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
49063 + task_grsec_rbac(m, task);
49064 +#endif
49065 +
49066 return 0;
49067 }
49068
49069 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49070 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
49071 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
49072 + _mm->pax_flags & MF_PAX_SEGMEXEC))
49073 +#endif
49074 +
49075 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
49076 struct pid *pid, struct task_struct *task, int whole)
49077 {
49078 @@ -387,6 +418,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
49079 char tcomm[sizeof(task->comm)];
49080 unsigned long flags;
49081
49082 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49083 + if (current->exec_id != m->exec_id) {
49084 + gr_log_badprocpid("stat");
49085 + return 0;
49086 + }
49087 +#endif
49088 +
49089 state = *get_task_state(task);
49090 vsize = eip = esp = 0;
49091 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
49092 @@ -458,6 +496,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
49093 gtime = task->gtime;
49094 }
49095
49096 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49097 + if (PAX_RAND_FLAGS(mm)) {
49098 + eip = 0;
49099 + esp = 0;
49100 + wchan = 0;
49101 + }
49102 +#endif
49103 +#ifdef CONFIG_GRKERNSEC_HIDESYM
49104 + wchan = 0;
49105 + eip =0;
49106 + esp =0;
49107 +#endif
49108 +
49109 /* scale priority and nice values from timeslices to -20..20 */
49110 /* to make it look like a "normal" Unix priority/nice value */
49111 priority = task_prio(task);
49112 @@ -494,9 +545,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
49113 seq_put_decimal_ull(m, ' ', vsize);
49114 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
49115 seq_put_decimal_ull(m, ' ', rsslim);
49116 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49117 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
49118 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
49119 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
49120 +#else
49121 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
49122 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
49123 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
49124 +#endif
49125 seq_put_decimal_ull(m, ' ', esp);
49126 seq_put_decimal_ull(m, ' ', eip);
49127 /* The signal information here is obsolete.
49128 @@ -518,7 +575,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
49129 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
49130 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
49131
49132 - if (mm && permitted) {
49133 + if (mm && permitted
49134 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49135 + && !PAX_RAND_FLAGS(mm)
49136 +#endif
49137 + ) {
49138 seq_put_decimal_ull(m, ' ', mm->start_data);
49139 seq_put_decimal_ull(m, ' ', mm->end_data);
49140 seq_put_decimal_ull(m, ' ', mm->start_brk);
49141 @@ -556,8 +617,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
49142 struct pid *pid, struct task_struct *task)
49143 {
49144 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
49145 - struct mm_struct *mm = get_task_mm(task);
49146 + struct mm_struct *mm;
49147
49148 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49149 + if (current->exec_id != m->exec_id) {
49150 + gr_log_badprocpid("statm");
49151 + return 0;
49152 + }
49153 +#endif
49154 + mm = get_task_mm(task);
49155 if (mm) {
49156 size = task_statm(mm, &shared, &text, &data, &resident);
49157 mmput(mm);
49158 @@ -580,6 +648,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
49159 return 0;
49160 }
49161
49162 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49163 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
49164 +{
49165 + return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
49166 +}
49167 +#endif
49168 +
49169 #ifdef CONFIG_CHECKPOINT_RESTORE
49170 static struct pid *
49171 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
49172 diff --git a/fs/proc/base.c b/fs/proc/base.c
49173 index 1b6c84c..66b738b 100644
49174 --- a/fs/proc/base.c
49175 +++ b/fs/proc/base.c
49176 @@ -110,6 +110,14 @@ struct pid_entry {
49177 union proc_op op;
49178 };
49179
49180 +struct getdents_callback {
49181 + struct linux_dirent __user * current_dir;
49182 + struct linux_dirent __user * previous;
49183 + struct file * file;
49184 + int count;
49185 + int error;
49186 +};
49187 +
49188 #define NOD(NAME, MODE, IOP, FOP, OP) { \
49189 .name = (NAME), \
49190 .len = sizeof(NAME) - 1, \
49191 @@ -209,6 +217,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
49192 if (!mm->arg_end)
49193 goto out_mm; /* Shh! No looking before we're done */
49194
49195 + if (gr_acl_handle_procpidmem(task))
49196 + goto out_mm;
49197 +
49198 len = mm->arg_end - mm->arg_start;
49199
49200 if (len > PAGE_SIZE)
49201 @@ -236,12 +247,28 @@ out:
49202 return res;
49203 }
49204
49205 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49206 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
49207 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
49208 + _mm->pax_flags & MF_PAX_SEGMEXEC))
49209 +#endif
49210 +
49211 static int proc_pid_auxv(struct task_struct *task, char *buffer)
49212 {
49213 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
49214 int res = PTR_ERR(mm);
49215 if (mm && !IS_ERR(mm)) {
49216 unsigned int nwords = 0;
49217 +
49218 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49219 + /* allow if we're currently ptracing this task */
49220 + if (PAX_RAND_FLAGS(mm) &&
49221 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
49222 + mmput(mm);
49223 + return 0;
49224 + }
49225 +#endif
49226 +
49227 do {
49228 nwords += 2;
49229 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
49230 @@ -255,7 +282,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
49231 }
49232
49233
49234 -#ifdef CONFIG_KALLSYMS
49235 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49236 /*
49237 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
49238 * Returns the resolved symbol. If that fails, simply return the address.
49239 @@ -294,7 +321,7 @@ static void unlock_trace(struct task_struct *task)
49240 mutex_unlock(&task->signal->cred_guard_mutex);
49241 }
49242
49243 -#ifdef CONFIG_STACKTRACE
49244 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49245
49246 #define MAX_STACK_TRACE_DEPTH 64
49247
49248 @@ -486,7 +513,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
49249 return count;
49250 }
49251
49252 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49253 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49254 static int proc_pid_syscall(struct task_struct *task, char *buffer)
49255 {
49256 long nr;
49257 @@ -515,7 +542,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
49258 /************************************************************************/
49259
49260 /* permission checks */
49261 -static int proc_fd_access_allowed(struct inode *inode)
49262 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
49263 {
49264 struct task_struct *task;
49265 int allowed = 0;
49266 @@ -525,7 +552,10 @@ static int proc_fd_access_allowed(struct inode *inode)
49267 */
49268 task = get_proc_task(inode);
49269 if (task) {
49270 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
49271 + if (log)
49272 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
49273 + else
49274 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
49275 put_task_struct(task);
49276 }
49277 return allowed;
49278 @@ -563,10 +593,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
49279 struct task_struct *task,
49280 int hide_pid_min)
49281 {
49282 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49283 + return false;
49284 +
49285 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49286 + rcu_read_lock();
49287 + {
49288 + const struct cred *tmpcred = current_cred();
49289 + const struct cred *cred = __task_cred(task);
49290 +
49291 + if (!tmpcred->uid || (tmpcred->uid == cred->uid)
49292 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49293 + || in_group_p(grsec_proc_gid)
49294 +#endif
49295 + ) {
49296 + rcu_read_unlock();
49297 + return true;
49298 + }
49299 + }
49300 + rcu_read_unlock();
49301 +
49302 + if (!pid->hide_pid)
49303 + return false;
49304 +#endif
49305 +
49306 if (pid->hide_pid < hide_pid_min)
49307 return true;
49308 if (in_group_p(pid->pid_gid))
49309 return true;
49310 +
49311 return ptrace_may_access(task, PTRACE_MODE_READ);
49312 }
49313
49314 @@ -584,7 +639,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
49315 put_task_struct(task);
49316
49317 if (!has_perms) {
49318 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49319 + {
49320 +#else
49321 if (pid->hide_pid == 2) {
49322 +#endif
49323 /*
49324 * Let's make getdents(), stat(), and open()
49325 * consistent with each other. If a process
49326 @@ -682,6 +741,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
49327 if (!task)
49328 return -ESRCH;
49329
49330 + if (gr_acl_handle_procpidmem(task)) {
49331 + put_task_struct(task);
49332 + return -EPERM;
49333 + }
49334 +
49335 mm = mm_access(task, mode);
49336 put_task_struct(task);
49337
49338 @@ -697,6 +761,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
49339
49340 file->private_data = mm;
49341
49342 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49343 + file->f_version = current->exec_id;
49344 +#endif
49345 +
49346 return 0;
49347 }
49348
49349 @@ -718,6 +786,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
49350 ssize_t copied;
49351 char *page;
49352
49353 +#ifdef CONFIG_GRKERNSEC
49354 + if (write)
49355 + return -EPERM;
49356 +#endif
49357 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49358 + if (file->f_version != current->exec_id) {
49359 + gr_log_badprocpid("mem");
49360 + return 0;
49361 + }
49362 +#endif
49363 +
49364 if (!mm)
49365 return 0;
49366
49367 @@ -822,6 +901,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
49368 if (!mm)
49369 return 0;
49370
49371 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49372 + if (file->f_version != current->exec_id) {
49373 + gr_log_badprocpid("environ");
49374 + return 0;
49375 + }
49376 +#endif
49377 +
49378 page = (char *)__get_free_page(GFP_TEMPORARY);
49379 if (!page)
49380 return -ENOMEM;
49381 @@ -1435,7 +1521,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
49382 int error = -EACCES;
49383
49384 /* Are we allowed to snoop on the tasks file descriptors? */
49385 - if (!proc_fd_access_allowed(inode))
49386 + if (!proc_fd_access_allowed(inode, 0))
49387 goto out;
49388
49389 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
49390 @@ -1479,8 +1565,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
49391 struct path path;
49392
49393 /* Are we allowed to snoop on the tasks file descriptors? */
49394 - if (!proc_fd_access_allowed(inode))
49395 - goto out;
49396 + /* logging this is needed for learning on chromium to work properly,
49397 + but we don't want to flood the logs from 'ps' which does a readlink
49398 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
49399 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
49400 + */
49401 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
49402 + if (!proc_fd_access_allowed(inode,0))
49403 + goto out;
49404 + } else {
49405 + if (!proc_fd_access_allowed(inode,1))
49406 + goto out;
49407 + }
49408
49409 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
49410 if (error)
49411 @@ -1545,7 +1641,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
49412 rcu_read_lock();
49413 cred = __task_cred(task);
49414 inode->i_uid = cred->euid;
49415 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49416 + inode->i_gid = grsec_proc_gid;
49417 +#else
49418 inode->i_gid = cred->egid;
49419 +#endif
49420 rcu_read_unlock();
49421 }
49422 security_task_to_inode(task, inode);
49423 @@ -1581,10 +1681,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
49424 return -ENOENT;
49425 }
49426 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
49427 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49428 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
49429 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49430 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
49431 +#endif
49432 task_dumpable(task)) {
49433 cred = __task_cred(task);
49434 stat->uid = cred->euid;
49435 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49436 + stat->gid = grsec_proc_gid;
49437 +#else
49438 stat->gid = cred->egid;
49439 +#endif
49440 }
49441 }
49442 rcu_read_unlock();
49443 @@ -1622,11 +1731,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
49444
49445 if (task) {
49446 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
49447 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49448 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
49449 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49450 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
49451 +#endif
49452 task_dumpable(task)) {
49453 rcu_read_lock();
49454 cred = __task_cred(task);
49455 inode->i_uid = cred->euid;
49456 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49457 + inode->i_gid = grsec_proc_gid;
49458 +#else
49459 inode->i_gid = cred->egid;
49460 +#endif
49461 rcu_read_unlock();
49462 } else {
49463 inode->i_uid = GLOBAL_ROOT_UID;
49464 @@ -1744,7 +1862,8 @@ static int proc_fd_info(struct inode *inode, struct path *path, char *info)
49465 int fd = proc_fd(inode);
49466
49467 if (task) {
49468 - files = get_files_struct(task);
49469 + if (!gr_acl_handle_procpidmem(task))
49470 + files = get_files_struct(task);
49471 put_task_struct(task);
49472 }
49473 if (files) {
49474 @@ -2343,11 +2462,21 @@ static const struct file_operations proc_map_files_operations = {
49475 */
49476 static int proc_fd_permission(struct inode *inode, int mask)
49477 {
49478 + struct task_struct *task;
49479 int rv = generic_permission(inode, mask);
49480 - if (rv == 0)
49481 - return 0;
49482 +
49483 if (task_pid(current) == proc_pid(inode))
49484 rv = 0;
49485 +
49486 + task = get_proc_task(inode);
49487 + if (task == NULL)
49488 + return rv;
49489 +
49490 + if (gr_acl_handle_procpidmem(task))
49491 + rv = -EACCES;
49492 +
49493 + put_task_struct(task);
49494 +
49495 return rv;
49496 }
49497
49498 @@ -2457,6 +2586,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
49499 if (!task)
49500 goto out_no_task;
49501
49502 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49503 + goto out;
49504 +
49505 /*
49506 * Yes, it does not scale. And it should not. Don't add
49507 * new entries into /proc/<tgid>/ without very good reasons.
49508 @@ -2501,6 +2633,9 @@ static int proc_pident_readdir(struct file *filp,
49509 if (!task)
49510 goto out_no_task;
49511
49512 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49513 + goto out;
49514 +
49515 ret = 0;
49516 i = filp->f_pos;
49517 switch (i) {
49518 @@ -2771,7 +2906,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
49519 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
49520 void *cookie)
49521 {
49522 - char *s = nd_get_link(nd);
49523 + const char *s = nd_get_link(nd);
49524 if (!IS_ERR(s))
49525 __putname(s);
49526 }
49527 @@ -3040,7 +3175,7 @@ static const struct pid_entry tgid_base_stuff[] = {
49528 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
49529 #endif
49530 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
49531 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49532 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49533 INF("syscall", S_IRUGO, proc_pid_syscall),
49534 #endif
49535 INF("cmdline", S_IRUGO, proc_pid_cmdline),
49536 @@ -3065,10 +3200,10 @@ static const struct pid_entry tgid_base_stuff[] = {
49537 #ifdef CONFIG_SECURITY
49538 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
49539 #endif
49540 -#ifdef CONFIG_KALLSYMS
49541 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49542 INF("wchan", S_IRUGO, proc_pid_wchan),
49543 #endif
49544 -#ifdef CONFIG_STACKTRACE
49545 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49546 ONE("stack", S_IRUGO, proc_pid_stack),
49547 #endif
49548 #ifdef CONFIG_SCHEDSTATS
49549 @@ -3102,6 +3237,9 @@ static const struct pid_entry tgid_base_stuff[] = {
49550 #ifdef CONFIG_HARDWALL
49551 INF("hardwall", S_IRUGO, proc_pid_hardwall),
49552 #endif
49553 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49554 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
49555 +#endif
49556 #ifdef CONFIG_USER_NS
49557 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
49558 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
49559 @@ -3233,7 +3371,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
49560 if (!inode)
49561 goto out;
49562
49563 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49564 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
49565 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49566 + inode->i_gid = grsec_proc_gid;
49567 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
49568 +#else
49569 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
49570 +#endif
49571 inode->i_op = &proc_tgid_base_inode_operations;
49572 inode->i_fop = &proc_tgid_base_operations;
49573 inode->i_flags|=S_IMMUTABLE;
49574 @@ -3275,7 +3420,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
49575 if (!task)
49576 goto out;
49577
49578 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49579 + goto out_put_task;
49580 +
49581 result = proc_pid_instantiate(dir, dentry, task, NULL);
49582 +out_put_task:
49583 put_task_struct(task);
49584 out:
49585 return result;
49586 @@ -3338,6 +3487,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
49587 static int fake_filldir(void *buf, const char *name, int namelen,
49588 loff_t offset, u64 ino, unsigned d_type)
49589 {
49590 + struct getdents_callback * __buf = (struct getdents_callback *) buf;
49591 + __buf->error = -EINVAL;
49592 return 0;
49593 }
49594
49595 @@ -3404,7 +3555,7 @@ static const struct pid_entry tid_base_stuff[] = {
49596 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
49597 #endif
49598 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
49599 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49600 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49601 INF("syscall", S_IRUGO, proc_pid_syscall),
49602 #endif
49603 INF("cmdline", S_IRUGO, proc_pid_cmdline),
49604 @@ -3431,10 +3582,10 @@ static const struct pid_entry tid_base_stuff[] = {
49605 #ifdef CONFIG_SECURITY
49606 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
49607 #endif
49608 -#ifdef CONFIG_KALLSYMS
49609 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49610 INF("wchan", S_IRUGO, proc_pid_wchan),
49611 #endif
49612 -#ifdef CONFIG_STACKTRACE
49613 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49614 ONE("stack", S_IRUGO, proc_pid_stack),
49615 #endif
49616 #ifdef CONFIG_SCHEDSTATS
49617 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
49618 index 82676e3..5f8518a 100644
49619 --- a/fs/proc/cmdline.c
49620 +++ b/fs/proc/cmdline.c
49621 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
49622
49623 static int __init proc_cmdline_init(void)
49624 {
49625 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
49626 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
49627 +#else
49628 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
49629 +#endif
49630 return 0;
49631 }
49632 module_init(proc_cmdline_init);
49633 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
49634 index b143471..bb105e5 100644
49635 --- a/fs/proc/devices.c
49636 +++ b/fs/proc/devices.c
49637 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
49638
49639 static int __init proc_devices_init(void)
49640 {
49641 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
49642 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
49643 +#else
49644 proc_create("devices", 0, NULL, &proc_devinfo_operations);
49645 +#endif
49646 return 0;
49647 }
49648 module_init(proc_devices_init);
49649 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
49650 index 7ac817b..c5c9eb0 100644
49651 --- a/fs/proc/inode.c
49652 +++ b/fs/proc/inode.c
49653 @@ -21,11 +21,17 @@
49654 #include <linux/seq_file.h>
49655 #include <linux/slab.h>
49656 #include <linux/mount.h>
49657 +#include <linux/grsecurity.h>
49658
49659 #include <asm/uaccess.h>
49660
49661 #include "internal.h"
49662
49663 +#ifdef CONFIG_PROC_SYSCTL
49664 +extern const struct inode_operations proc_sys_inode_operations;
49665 +extern const struct inode_operations proc_sys_dir_operations;
49666 +#endif
49667 +
49668 static void proc_evict_inode(struct inode *inode)
49669 {
49670 struct proc_dir_entry *de;
49671 @@ -51,6 +57,13 @@ static void proc_evict_inode(struct inode *inode)
49672 ns_ops = PROC_I(inode)->ns_ops;
49673 if (ns_ops && ns_ops->put)
49674 ns_ops->put(PROC_I(inode)->ns);
49675 +
49676 +#ifdef CONFIG_PROC_SYSCTL
49677 + if (inode->i_op == &proc_sys_inode_operations ||
49678 + inode->i_op == &proc_sys_dir_operations)
49679 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
49680 +#endif
49681 +
49682 }
49683
49684 static struct kmem_cache * proc_inode_cachep;
49685 @@ -456,7 +469,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
49686 if (de->mode) {
49687 inode->i_mode = de->mode;
49688 inode->i_uid = de->uid;
49689 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49690 + inode->i_gid = grsec_proc_gid;
49691 +#else
49692 inode->i_gid = de->gid;
49693 +#endif
49694 }
49695 if (de->size)
49696 inode->i_size = de->size;
49697 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
49698 index e1167a1..bd24f20 100644
49699 --- a/fs/proc/internal.h
49700 +++ b/fs/proc/internal.h
49701 @@ -52,6 +52,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
49702 struct pid *pid, struct task_struct *task);
49703 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
49704 struct pid *pid, struct task_struct *task);
49705 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49706 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
49707 +#endif
49708 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
49709
49710 extern const struct file_operations proc_tid_children_operations;
49711 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
49712 index 86c67ee..cdca321 100644
49713 --- a/fs/proc/kcore.c
49714 +++ b/fs/proc/kcore.c
49715 @@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49716 * the addresses in the elf_phdr on our list.
49717 */
49718 start = kc_offset_to_vaddr(*fpos - elf_buflen);
49719 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
49720 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
49721 + if (tsz > buflen)
49722 tsz = buflen;
49723 -
49724 +
49725 while (buflen) {
49726 struct kcore_list *m;
49727
49728 @@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49729 kfree(elf_buf);
49730 } else {
49731 if (kern_addr_valid(start)) {
49732 - unsigned long n;
49733 + char *elf_buf;
49734 + mm_segment_t oldfs;
49735
49736 - n = copy_to_user(buffer, (char *)start, tsz);
49737 - /*
49738 - * We cannot distinguish between fault on source
49739 - * and fault on destination. When this happens
49740 - * we clear too and hope it will trigger the
49741 - * EFAULT again.
49742 - */
49743 - if (n) {
49744 - if (clear_user(buffer + tsz - n,
49745 - n))
49746 + elf_buf = kmalloc(tsz, GFP_KERNEL);
49747 + if (!elf_buf)
49748 + return -ENOMEM;
49749 + oldfs = get_fs();
49750 + set_fs(KERNEL_DS);
49751 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
49752 + set_fs(oldfs);
49753 + if (copy_to_user(buffer, elf_buf, tsz)) {
49754 + kfree(elf_buf);
49755 return -EFAULT;
49756 + }
49757 }
49758 + set_fs(oldfs);
49759 + kfree(elf_buf);
49760 } else {
49761 if (clear_user(buffer, tsz))
49762 return -EFAULT;
49763 @@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49764
49765 static int open_kcore(struct inode *inode, struct file *filp)
49766 {
49767 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
49768 + return -EPERM;
49769 +#endif
49770 if (!capable(CAP_SYS_RAWIO))
49771 return -EPERM;
49772 if (kcore_need_update)
49773 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
49774 index 80e4645..53e5fcf 100644
49775 --- a/fs/proc/meminfo.c
49776 +++ b/fs/proc/meminfo.c
49777 @@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
49778 vmi.used >> 10,
49779 vmi.largest_chunk >> 10
49780 #ifdef CONFIG_MEMORY_FAILURE
49781 - ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
49782 + ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
49783 #endif
49784 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
49785 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
49786 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
49787 index b1822dd..df622cb 100644
49788 --- a/fs/proc/nommu.c
49789 +++ b/fs/proc/nommu.c
49790 @@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
49791 if (len < 1)
49792 len = 1;
49793 seq_printf(m, "%*c", len, ' ');
49794 - seq_path(m, &file->f_path, "");
49795 + seq_path(m, &file->f_path, "\n\\");
49796 }
49797
49798 seq_putc(m, '\n');
49799 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
49800 index fe72cd0..cb9b67d 100644
49801 --- a/fs/proc/proc_net.c
49802 +++ b/fs/proc/proc_net.c
49803 @@ -23,6 +23,7 @@
49804 #include <linux/nsproxy.h>
49805 #include <net/net_namespace.h>
49806 #include <linux/seq_file.h>
49807 +#include <linux/grsecurity.h>
49808
49809 #include "internal.h"
49810
49811 @@ -105,6 +106,17 @@ static struct net *get_proc_task_net(struct inode *dir)
49812 struct task_struct *task;
49813 struct nsproxy *ns;
49814 struct net *net = NULL;
49815 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49816 + const struct cred *cred = current_cred();
49817 +#endif
49818 +
49819 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49820 + if (cred->fsuid)
49821 + return net;
49822 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49823 + if (cred->fsuid && !in_group_p(grsec_proc_gid))
49824 + return net;
49825 +#endif
49826
49827 rcu_read_lock();
49828 task = pid_task(proc_pid(dir), PIDTYPE_PID);
49829 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
49830 index eb7cc91..7327a46 100644
49831 --- a/fs/proc/proc_sysctl.c
49832 +++ b/fs/proc/proc_sysctl.c
49833 @@ -12,11 +12,15 @@
49834 #include <linux/module.h>
49835 #include "internal.h"
49836
49837 +extern int gr_handle_chroot_sysctl(const int op);
49838 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
49839 + const int op);
49840 +
49841 static const struct dentry_operations proc_sys_dentry_operations;
49842 static const struct file_operations proc_sys_file_operations;
49843 -static const struct inode_operations proc_sys_inode_operations;
49844 +const struct inode_operations proc_sys_inode_operations;
49845 static const struct file_operations proc_sys_dir_file_operations;
49846 -static const struct inode_operations proc_sys_dir_operations;
49847 +const struct inode_operations proc_sys_dir_operations;
49848
49849 void proc_sys_poll_notify(struct ctl_table_poll *poll)
49850 {
49851 @@ -467,6 +471,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
49852
49853 err = NULL;
49854 d_set_d_op(dentry, &proc_sys_dentry_operations);
49855 +
49856 + gr_handle_proc_create(dentry, inode);
49857 +
49858 d_add(dentry, inode);
49859
49860 out:
49861 @@ -482,18 +489,20 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
49862 struct inode *inode = filp->f_path.dentry->d_inode;
49863 struct ctl_table_header *head = grab_header(inode);
49864 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
49865 + int op = write ? MAY_WRITE : MAY_READ;
49866 ssize_t error;
49867 size_t res;
49868
49869 if (IS_ERR(head))
49870 return PTR_ERR(head);
49871
49872 +
49873 /*
49874 * At this point we know that the sysctl was not unregistered
49875 * and won't be until we finish.
49876 */
49877 error = -EPERM;
49878 - if (sysctl_perm(head->root, table, write ? MAY_WRITE : MAY_READ))
49879 + if (sysctl_perm(head->root, table, op))
49880 goto out;
49881
49882 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
49883 @@ -501,6 +510,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
49884 if (!table->proc_handler)
49885 goto out;
49886
49887 +#ifdef CONFIG_GRKERNSEC
49888 + error = -EPERM;
49889 + if (gr_handle_chroot_sysctl(op))
49890 + goto out;
49891 + dget(filp->f_path.dentry);
49892 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
49893 + dput(filp->f_path.dentry);
49894 + goto out;
49895 + }
49896 + dput(filp->f_path.dentry);
49897 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
49898 + goto out;
49899 + if (write && !capable(CAP_SYS_ADMIN))
49900 + goto out;
49901 +#endif
49902 +
49903 /* careful: calling conventions are nasty here */
49904 res = count;
49905 error = table->proc_handler(table, write, buf, &res, ppos);
49906 @@ -598,6 +623,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
49907 return -ENOMEM;
49908 } else {
49909 d_set_d_op(child, &proc_sys_dentry_operations);
49910 +
49911 + gr_handle_proc_create(child, inode);
49912 +
49913 d_add(child, inode);
49914 }
49915 } else {
49916 @@ -641,6 +669,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
49917 if ((*pos)++ < file->f_pos)
49918 return 0;
49919
49920 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
49921 + return 0;
49922 +
49923 if (unlikely(S_ISLNK(table->mode)))
49924 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
49925 else
49926 @@ -758,6 +789,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
49927 if (IS_ERR(head))
49928 return PTR_ERR(head);
49929
49930 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
49931 + return -ENOENT;
49932 +
49933 generic_fillattr(inode, stat);
49934 if (table)
49935 stat->mode = (stat->mode & S_IFMT) | table->mode;
49936 @@ -780,13 +814,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
49937 .llseek = generic_file_llseek,
49938 };
49939
49940 -static const struct inode_operations proc_sys_inode_operations = {
49941 +const struct inode_operations proc_sys_inode_operations = {
49942 .permission = proc_sys_permission,
49943 .setattr = proc_sys_setattr,
49944 .getattr = proc_sys_getattr,
49945 };
49946
49947 -static const struct inode_operations proc_sys_dir_operations = {
49948 +const struct inode_operations proc_sys_dir_operations = {
49949 .lookup = proc_sys_lookup,
49950 .permission = proc_sys_permission,
49951 .setattr = proc_sys_setattr,
49952 diff --git a/fs/proc/root.c b/fs/proc/root.c
49953 index 9a2d9fd..ddfc92a 100644
49954 --- a/fs/proc/root.c
49955 +++ b/fs/proc/root.c
49956 @@ -187,7 +187,15 @@ void __init proc_root_init(void)
49957 #ifdef CONFIG_PROC_DEVICETREE
49958 proc_device_tree_init();
49959 #endif
49960 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
49961 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49962 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
49963 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49964 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
49965 +#endif
49966 +#else
49967 proc_mkdir("bus", NULL);
49968 +#endif
49969 proc_sys_init();
49970 }
49971
49972 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
49973 index 4540b8f..1b9772f 100644
49974 --- a/fs/proc/task_mmu.c
49975 +++ b/fs/proc/task_mmu.c
49976 @@ -11,12 +11,19 @@
49977 #include <linux/rmap.h>
49978 #include <linux/swap.h>
49979 #include <linux/swapops.h>
49980 +#include <linux/grsecurity.h>
49981
49982 #include <asm/elf.h>
49983 #include <asm/uaccess.h>
49984 #include <asm/tlbflush.h>
49985 #include "internal.h"
49986
49987 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49988 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
49989 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
49990 + _mm->pax_flags & MF_PAX_SEGMEXEC))
49991 +#endif
49992 +
49993 void task_mem(struct seq_file *m, struct mm_struct *mm)
49994 {
49995 unsigned long data, text, lib, swap;
49996 @@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49997 "VmExe:\t%8lu kB\n"
49998 "VmLib:\t%8lu kB\n"
49999 "VmPTE:\t%8lu kB\n"
50000 - "VmSwap:\t%8lu kB\n",
50001 - hiwater_vm << (PAGE_SHIFT-10),
50002 + "VmSwap:\t%8lu kB\n"
50003 +
50004 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
50005 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
50006 +#endif
50007 +
50008 + ,hiwater_vm << (PAGE_SHIFT-10),
50009 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
50010 mm->locked_vm << (PAGE_SHIFT-10),
50011 mm->pinned_vm << (PAGE_SHIFT-10),
50012 @@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
50013 data << (PAGE_SHIFT-10),
50014 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
50015 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
50016 - swap << (PAGE_SHIFT-10));
50017 + swap << (PAGE_SHIFT-10)
50018 +
50019 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
50020 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50021 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
50022 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
50023 +#else
50024 + , mm->context.user_cs_base
50025 + , mm->context.user_cs_limit
50026 +#endif
50027 +#endif
50028 +
50029 + );
50030 }
50031
50032 unsigned long task_vsize(struct mm_struct *mm)
50033 @@ -231,13 +255,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
50034 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
50035 }
50036
50037 - /* We don't show the stack guard page in /proc/maps */
50038 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50039 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
50040 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
50041 +#else
50042 start = vma->vm_start;
50043 - if (stack_guard_page_start(vma, start))
50044 - start += PAGE_SIZE;
50045 end = vma->vm_end;
50046 - if (stack_guard_page_end(vma, end))
50047 - end -= PAGE_SIZE;
50048 +#endif
50049
50050 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
50051 start,
50052 @@ -246,7 +270,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
50053 flags & VM_WRITE ? 'w' : '-',
50054 flags & VM_EXEC ? 'x' : '-',
50055 flags & VM_MAYSHARE ? 's' : 'p',
50056 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50057 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
50058 +#else
50059 pgoff,
50060 +#endif
50061 MAJOR(dev), MINOR(dev), ino, &len);
50062
50063 /*
50064 @@ -255,7 +283,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
50065 */
50066 if (file) {
50067 pad_len_spaces(m, len);
50068 - seq_path(m, &file->f_path, "\n");
50069 + seq_path(m, &file->f_path, "\n\\");
50070 goto done;
50071 }
50072
50073 @@ -281,8 +309,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
50074 * Thread stack in /proc/PID/task/TID/maps or
50075 * the main process stack.
50076 */
50077 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
50078 - vma->vm_end >= mm->start_stack)) {
50079 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
50080 + (vma->vm_start <= mm->start_stack &&
50081 + vma->vm_end >= mm->start_stack)) {
50082 name = "[stack]";
50083 } else {
50084 /* Thread stack in /proc/PID/maps */
50085 @@ -306,6 +335,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
50086 struct proc_maps_private *priv = m->private;
50087 struct task_struct *task = priv->task;
50088
50089 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50090 + if (current->exec_id != m->exec_id) {
50091 + gr_log_badprocpid("maps");
50092 + return 0;
50093 + }
50094 +#endif
50095 +
50096 show_map_vma(m, vma, is_pid);
50097
50098 if (m->count < m->size) /* vma is copied successfully */
50099 @@ -492,12 +528,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
50100 .private = &mss,
50101 };
50102
50103 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50104 + if (current->exec_id != m->exec_id) {
50105 + gr_log_badprocpid("smaps");
50106 + return 0;
50107 + }
50108 +#endif
50109 memset(&mss, 0, sizeof mss);
50110 - mss.vma = vma;
50111 - /* mmap_sem is held in m_start */
50112 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
50113 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
50114 -
50115 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50116 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
50117 +#endif
50118 + mss.vma = vma;
50119 + /* mmap_sem is held in m_start */
50120 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
50121 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
50122 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50123 + }
50124 +#endif
50125 show_map_vma(m, vma, is_pid);
50126
50127 seq_printf(m,
50128 @@ -515,7 +562,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
50129 "KernelPageSize: %8lu kB\n"
50130 "MMUPageSize: %8lu kB\n"
50131 "Locked: %8lu kB\n",
50132 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50133 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
50134 +#else
50135 (vma->vm_end - vma->vm_start) >> 10,
50136 +#endif
50137 mss.resident >> 10,
50138 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
50139 mss.shared_clean >> 10,
50140 @@ -1164,6 +1215,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
50141 int n;
50142 char buffer[50];
50143
50144 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50145 + if (current->exec_id != m->exec_id) {
50146 + gr_log_badprocpid("numa_maps");
50147 + return 0;
50148 + }
50149 +#endif
50150 +
50151 if (!mm)
50152 return 0;
50153
50154 @@ -1181,11 +1239,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
50155 mpol_to_str(buffer, sizeof(buffer), pol, 0);
50156 mpol_cond_put(pol);
50157
50158 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50159 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
50160 +#else
50161 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
50162 +#endif
50163
50164 if (file) {
50165 seq_printf(m, " file=");
50166 - seq_path(m, &file->f_path, "\n\t= ");
50167 + seq_path(m, &file->f_path, "\n\t\\= ");
50168 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
50169 seq_printf(m, " heap");
50170 } else {
50171 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
50172 index 1ccfa53..0848f95 100644
50173 --- a/fs/proc/task_nommu.c
50174 +++ b/fs/proc/task_nommu.c
50175 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
50176 else
50177 bytes += kobjsize(mm);
50178
50179 - if (current->fs && current->fs->users > 1)
50180 + if (current->fs && atomic_read(&current->fs->users) > 1)
50181 sbytes += kobjsize(current->fs);
50182 else
50183 bytes += kobjsize(current->fs);
50184 @@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
50185
50186 if (file) {
50187 pad_len_spaces(m, len);
50188 - seq_path(m, &file->f_path, "");
50189 + seq_path(m, &file->f_path, "\n\\");
50190 } else if (mm) {
50191 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
50192
50193 diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c
50194 index 29996e8..2d1e0f3 100644
50195 --- a/fs/pstore/platform.c
50196 +++ b/fs/pstore/platform.c
50197 @@ -161,12 +161,13 @@ static void pstore_console_write(struct console *con, const char *s, unsigned c)
50198
50199 while (s < e) {
50200 unsigned long flags;
50201 + u64 id;
50202
50203 if (c > psinfo->bufsize)
50204 c = psinfo->bufsize;
50205 spin_lock_irqsave(&psinfo->buf_lock, flags);
50206 memcpy(psinfo->buf, s, c);
50207 - psinfo->write(PSTORE_TYPE_CONSOLE, 0, NULL, 0, c, psinfo);
50208 + psinfo->write(PSTORE_TYPE_CONSOLE, 0, &id, 0, c, psinfo);
50209 spin_unlock_irqrestore(&psinfo->buf_lock, flags);
50210 s += c;
50211 c = e - s;
50212 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
50213 index d67908b..d13f6a6 100644
50214 --- a/fs/quota/netlink.c
50215 +++ b/fs/quota/netlink.c
50216 @@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
50217 void quota_send_warning(short type, unsigned int id, dev_t dev,
50218 const char warntype)
50219 {
50220 - static atomic_t seq;
50221 + static atomic_unchecked_t seq;
50222 struct sk_buff *skb;
50223 void *msg_head;
50224 int ret;
50225 @@ -49,7 +49,7 @@ void quota_send_warning(short type, unsigned int id, dev_t dev,
50226 "VFS: Not enough memory to send quota warning.\n");
50227 return;
50228 }
50229 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
50230 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
50231 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
50232 if (!msg_head) {
50233 printk(KERN_ERR
50234 diff --git a/fs/readdir.c b/fs/readdir.c
50235 index 39e3370..20d446d 100644
50236 --- a/fs/readdir.c
50237 +++ b/fs/readdir.c
50238 @@ -17,6 +17,7 @@
50239 #include <linux/security.h>
50240 #include <linux/syscalls.h>
50241 #include <linux/unistd.h>
50242 +#include <linux/namei.h>
50243
50244 #include <asm/uaccess.h>
50245
50246 @@ -67,6 +68,7 @@ struct old_linux_dirent {
50247
50248 struct readdir_callback {
50249 struct old_linux_dirent __user * dirent;
50250 + struct file * file;
50251 int result;
50252 };
50253
50254 @@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
50255 buf->result = -EOVERFLOW;
50256 return -EOVERFLOW;
50257 }
50258 +
50259 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50260 + return 0;
50261 +
50262 buf->result++;
50263 dirent = buf->dirent;
50264 if (!access_ok(VERIFY_WRITE, dirent,
50265 @@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
50266
50267 buf.result = 0;
50268 buf.dirent = dirent;
50269 + buf.file = file;
50270
50271 error = vfs_readdir(file, fillonedir, &buf);
50272 if (buf.result)
50273 @@ -141,6 +148,7 @@ struct linux_dirent {
50274 struct getdents_callback {
50275 struct linux_dirent __user * current_dir;
50276 struct linux_dirent __user * previous;
50277 + struct file * file;
50278 int count;
50279 int error;
50280 };
50281 @@ -162,6 +170,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
50282 buf->error = -EOVERFLOW;
50283 return -EOVERFLOW;
50284 }
50285 +
50286 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50287 + return 0;
50288 +
50289 dirent = buf->previous;
50290 if (dirent) {
50291 if (__put_user(offset, &dirent->d_off))
50292 @@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
50293 buf.previous = NULL;
50294 buf.count = count;
50295 buf.error = 0;
50296 + buf.file = file;
50297
50298 error = vfs_readdir(file, filldir, &buf);
50299 if (error >= 0)
50300 @@ -226,6 +239,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
50301 struct getdents_callback64 {
50302 struct linux_dirent64 __user * current_dir;
50303 struct linux_dirent64 __user * previous;
50304 + struct file *file;
50305 int count;
50306 int error;
50307 };
50308 @@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
50309 buf->error = -EINVAL; /* only used if we fail.. */
50310 if (reclen > buf->count)
50311 return -EINVAL;
50312 +
50313 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50314 + return 0;
50315 +
50316 dirent = buf->previous;
50317 if (dirent) {
50318 if (__put_user(offset, &dirent->d_off))
50319 @@ -287,6 +305,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
50320
50321 buf.current_dir = dirent;
50322 buf.previous = NULL;
50323 + buf.file = file;
50324 buf.count = count;
50325 buf.error = 0;
50326
50327 @@ -295,7 +314,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
50328 error = buf.error;
50329 lastdirent = buf.previous;
50330 if (lastdirent) {
50331 - typeof(lastdirent->d_off) d_off = file->f_pos;
50332 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
50333 if (__put_user(d_off, &lastdirent->d_off))
50334 error = -EFAULT;
50335 else
50336 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
50337 index 2b7882b..1c5ef48 100644
50338 --- a/fs/reiserfs/do_balan.c
50339 +++ b/fs/reiserfs/do_balan.c
50340 @@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
50341 return;
50342 }
50343
50344 - atomic_inc(&(fs_generation(tb->tb_sb)));
50345 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
50346 do_balance_starts(tb);
50347
50348 /* balance leaf returns 0 except if combining L R and S into
50349 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
50350 index e60e870..f40ac16 100644
50351 --- a/fs/reiserfs/procfs.c
50352 +++ b/fs/reiserfs/procfs.c
50353 @@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
50354 "SMALL_TAILS " : "NO_TAILS ",
50355 replay_only(sb) ? "REPLAY_ONLY " : "",
50356 convert_reiserfs(sb) ? "CONV " : "",
50357 - atomic_read(&r->s_generation_counter),
50358 + atomic_read_unchecked(&r->s_generation_counter),
50359 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
50360 SF(s_do_balance), SF(s_unneeded_left_neighbor),
50361 SF(s_good_search_by_key_reada), SF(s_bmaps),
50362 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
50363 index 33215f5..c5d427a 100644
50364 --- a/fs/reiserfs/reiserfs.h
50365 +++ b/fs/reiserfs/reiserfs.h
50366 @@ -453,7 +453,7 @@ struct reiserfs_sb_info {
50367 /* Comment? -Hans */
50368 wait_queue_head_t s_wait;
50369 /* To be obsoleted soon by per buffer seals.. -Hans */
50370 - atomic_t s_generation_counter; // increased by one every time the
50371 + atomic_unchecked_t s_generation_counter; // increased by one every time the
50372 // tree gets re-balanced
50373 unsigned long s_properties; /* File system properties. Currently holds
50374 on-disk FS format */
50375 @@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
50376 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
50377
50378 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
50379 -#define get_generation(s) atomic_read (&fs_generation(s))
50380 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
50381 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
50382 #define __fs_changed(gen,s) (gen != get_generation (s))
50383 #define fs_changed(gen,s) \
50384 diff --git a/fs/select.c b/fs/select.c
50385 index db14c78..3aae1bd 100644
50386 --- a/fs/select.c
50387 +++ b/fs/select.c
50388 @@ -20,6 +20,7 @@
50389 #include <linux/export.h>
50390 #include <linux/slab.h>
50391 #include <linux/poll.h>
50392 +#include <linux/security.h>
50393 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
50394 #include <linux/file.h>
50395 #include <linux/fdtable.h>
50396 @@ -831,6 +832,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
50397 struct poll_list *walk = head;
50398 unsigned long todo = nfds;
50399
50400 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
50401 if (nfds > rlimit(RLIMIT_NOFILE))
50402 return -EINVAL;
50403
50404 diff --git a/fs/seq_file.c b/fs/seq_file.c
50405 index 14cf9de..adc4d5b 100644
50406 --- a/fs/seq_file.c
50407 +++ b/fs/seq_file.c
50408 @@ -9,6 +9,7 @@
50409 #include <linux/export.h>
50410 #include <linux/seq_file.h>
50411 #include <linux/slab.h>
50412 +#include <linux/sched.h>
50413
50414 #include <asm/uaccess.h>
50415 #include <asm/page.h>
50416 @@ -56,6 +57,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
50417 memset(p, 0, sizeof(*p));
50418 mutex_init(&p->lock);
50419 p->op = op;
50420 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50421 + p->exec_id = current->exec_id;
50422 +#endif
50423
50424 /*
50425 * Wrappers around seq_open(e.g. swaps_open) need to be
50426 @@ -92,7 +96,7 @@ static int traverse(struct seq_file *m, loff_t offset)
50427 return 0;
50428 }
50429 if (!m->buf) {
50430 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
50431 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
50432 if (!m->buf)
50433 return -ENOMEM;
50434 }
50435 @@ -132,7 +136,7 @@ static int traverse(struct seq_file *m, loff_t offset)
50436 Eoverflow:
50437 m->op->stop(m, p);
50438 kfree(m->buf);
50439 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
50440 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
50441 return !m->buf ? -ENOMEM : -EAGAIN;
50442 }
50443
50444 @@ -187,7 +191,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
50445
50446 /* grab buffer if we didn't have one */
50447 if (!m->buf) {
50448 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
50449 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
50450 if (!m->buf)
50451 goto Enomem;
50452 }
50453 @@ -228,7 +232,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
50454 goto Fill;
50455 m->op->stop(m, p);
50456 kfree(m->buf);
50457 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
50458 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
50459 if (!m->buf)
50460 goto Enomem;
50461 m->count = 0;
50462 @@ -577,7 +581,7 @@ static void single_stop(struct seq_file *p, void *v)
50463 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
50464 void *data)
50465 {
50466 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
50467 + seq_operations_no_const *op = kmalloc(sizeof(*op), GFP_KERNEL);
50468 int res = -ENOMEM;
50469
50470 if (op) {
50471 diff --git a/fs/splice.c b/fs/splice.c
50472 index 41514dd..6564a93 100644
50473 --- a/fs/splice.c
50474 +++ b/fs/splice.c
50475 @@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
50476 pipe_lock(pipe);
50477
50478 for (;;) {
50479 - if (!pipe->readers) {
50480 + if (!atomic_read(&pipe->readers)) {
50481 send_sig(SIGPIPE, current, 0);
50482 if (!ret)
50483 ret = -EPIPE;
50484 @@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
50485 do_wakeup = 0;
50486 }
50487
50488 - pipe->waiting_writers++;
50489 + atomic_inc(&pipe->waiting_writers);
50490 pipe_wait(pipe);
50491 - pipe->waiting_writers--;
50492 + atomic_dec(&pipe->waiting_writers);
50493 }
50494
50495 pipe_unlock(pipe);
50496 @@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
50497 old_fs = get_fs();
50498 set_fs(get_ds());
50499 /* The cast to a user pointer is valid due to the set_fs() */
50500 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
50501 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
50502 set_fs(old_fs);
50503
50504 return res;
50505 @@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
50506 old_fs = get_fs();
50507 set_fs(get_ds());
50508 /* The cast to a user pointer is valid due to the set_fs() */
50509 - res = vfs_write(file, (const char __user *)buf, count, &pos);
50510 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
50511 set_fs(old_fs);
50512
50513 return res;
50514 @@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
50515 goto err;
50516
50517 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
50518 - vec[i].iov_base = (void __user *) page_address(page);
50519 + vec[i].iov_base = (void __force_user *) page_address(page);
50520 vec[i].iov_len = this_len;
50521 spd.pages[i] = page;
50522 spd.nr_pages++;
50523 @@ -849,10 +849,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
50524 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
50525 {
50526 while (!pipe->nrbufs) {
50527 - if (!pipe->writers)
50528 + if (!atomic_read(&pipe->writers))
50529 return 0;
50530
50531 - if (!pipe->waiting_writers && sd->num_spliced)
50532 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
50533 return 0;
50534
50535 if (sd->flags & SPLICE_F_NONBLOCK)
50536 @@ -1190,7 +1190,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
50537 * out of the pipe right after the splice_to_pipe(). So set
50538 * PIPE_READERS appropriately.
50539 */
50540 - pipe->readers = 1;
50541 + atomic_set(&pipe->readers, 1);
50542
50543 current->splice_pipe = pipe;
50544 }
50545 @@ -1743,9 +1743,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50546 ret = -ERESTARTSYS;
50547 break;
50548 }
50549 - if (!pipe->writers)
50550 + if (!atomic_read(&pipe->writers))
50551 break;
50552 - if (!pipe->waiting_writers) {
50553 + if (!atomic_read(&pipe->waiting_writers)) {
50554 if (flags & SPLICE_F_NONBLOCK) {
50555 ret = -EAGAIN;
50556 break;
50557 @@ -1777,7 +1777,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50558 pipe_lock(pipe);
50559
50560 while (pipe->nrbufs >= pipe->buffers) {
50561 - if (!pipe->readers) {
50562 + if (!atomic_read(&pipe->readers)) {
50563 send_sig(SIGPIPE, current, 0);
50564 ret = -EPIPE;
50565 break;
50566 @@ -1790,9 +1790,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50567 ret = -ERESTARTSYS;
50568 break;
50569 }
50570 - pipe->waiting_writers++;
50571 + atomic_inc(&pipe->waiting_writers);
50572 pipe_wait(pipe);
50573 - pipe->waiting_writers--;
50574 + atomic_dec(&pipe->waiting_writers);
50575 }
50576
50577 pipe_unlock(pipe);
50578 @@ -1828,14 +1828,14 @@ retry:
50579 pipe_double_lock(ipipe, opipe);
50580
50581 do {
50582 - if (!opipe->readers) {
50583 + if (!atomic_read(&opipe->readers)) {
50584 send_sig(SIGPIPE, current, 0);
50585 if (!ret)
50586 ret = -EPIPE;
50587 break;
50588 }
50589
50590 - if (!ipipe->nrbufs && !ipipe->writers)
50591 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
50592 break;
50593
50594 /*
50595 @@ -1932,7 +1932,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
50596 pipe_double_lock(ipipe, opipe);
50597
50598 do {
50599 - if (!opipe->readers) {
50600 + if (!atomic_read(&opipe->readers)) {
50601 send_sig(SIGPIPE, current, 0);
50602 if (!ret)
50603 ret = -EPIPE;
50604 @@ -1977,7 +1977,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
50605 * return EAGAIN if we have the potential of some data in the
50606 * future, otherwise just return 0
50607 */
50608 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
50609 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
50610 ret = -EAGAIN;
50611
50612 pipe_unlock(ipipe);
50613 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
50614 index 2fbdff6..5530a61 100644
50615 --- a/fs/sysfs/dir.c
50616 +++ b/fs/sysfs/dir.c
50617 @@ -685,6 +685,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
50618 struct sysfs_dirent *sd;
50619 int rc;
50620
50621 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
50622 + const char *parent_name = parent_sd->s_name;
50623 +
50624 + mode = S_IFDIR | S_IRWXU;
50625 +
50626 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
50627 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
50628 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
50629 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
50630 + mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
50631 +#endif
50632 +
50633 /* allocate */
50634 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
50635 if (!sd)
50636 diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
50637 index 00012e3..8392349 100644
50638 --- a/fs/sysfs/file.c
50639 +++ b/fs/sysfs/file.c
50640 @@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
50641
50642 struct sysfs_open_dirent {
50643 atomic_t refcnt;
50644 - atomic_t event;
50645 + atomic_unchecked_t event;
50646 wait_queue_head_t poll;
50647 struct list_head buffers; /* goes through sysfs_buffer.list */
50648 };
50649 @@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
50650 if (!sysfs_get_active(attr_sd))
50651 return -ENODEV;
50652
50653 - buffer->event = atomic_read(&attr_sd->s_attr.open->event);
50654 + buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
50655 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
50656
50657 sysfs_put_active(attr_sd);
50658 @@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
50659 return -ENOMEM;
50660
50661 atomic_set(&new_od->refcnt, 0);
50662 - atomic_set(&new_od->event, 1);
50663 + atomic_set_unchecked(&new_od->event, 1);
50664 init_waitqueue_head(&new_od->poll);
50665 INIT_LIST_HEAD(&new_od->buffers);
50666 goto retry;
50667 @@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
50668
50669 sysfs_put_active(attr_sd);
50670
50671 - if (buffer->event != atomic_read(&od->event))
50672 + if (buffer->event != atomic_read_unchecked(&od->event))
50673 goto trigger;
50674
50675 return DEFAULT_POLLMASK;
50676 @@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
50677
50678 od = sd->s_attr.open;
50679 if (od) {
50680 - atomic_inc(&od->event);
50681 + atomic_inc_unchecked(&od->event);
50682 wake_up_interruptible(&od->poll);
50683 }
50684
50685 diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
50686 index a7ac78f..02158e1 100644
50687 --- a/fs/sysfs/symlink.c
50688 +++ b/fs/sysfs/symlink.c
50689 @@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
50690
50691 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
50692 {
50693 - char *page = nd_get_link(nd);
50694 + const char *page = nd_get_link(nd);
50695 if (!IS_ERR(page))
50696 free_page((unsigned long)page);
50697 }
50698 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
50699 index c175b4d..8f36a16 100644
50700 --- a/fs/udf/misc.c
50701 +++ b/fs/udf/misc.c
50702 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
50703
50704 u8 udf_tag_checksum(const struct tag *t)
50705 {
50706 - u8 *data = (u8 *)t;
50707 + const u8 *data = (const u8 *)t;
50708 u8 checksum = 0;
50709 int i;
50710 for (i = 0; i < sizeof(struct tag); ++i)
50711 diff --git a/fs/utimes.c b/fs/utimes.c
50712 index fa4dbe4..e12d1b9 100644
50713 --- a/fs/utimes.c
50714 +++ b/fs/utimes.c
50715 @@ -1,6 +1,7 @@
50716 #include <linux/compiler.h>
50717 #include <linux/file.h>
50718 #include <linux/fs.h>
50719 +#include <linux/security.h>
50720 #include <linux/linkage.h>
50721 #include <linux/mount.h>
50722 #include <linux/namei.h>
50723 @@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
50724 goto mnt_drop_write_and_out;
50725 }
50726 }
50727 +
50728 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
50729 + error = -EACCES;
50730 + goto mnt_drop_write_and_out;
50731 + }
50732 +
50733 mutex_lock(&inode->i_mutex);
50734 error = notify_change(path->dentry, &newattrs);
50735 mutex_unlock(&inode->i_mutex);
50736 diff --git a/fs/xattr.c b/fs/xattr.c
50737 index 4d45b71..2ec08e10 100644
50738 --- a/fs/xattr.c
50739 +++ b/fs/xattr.c
50740 @@ -316,7 +316,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
50741 * Extended attribute SET operations
50742 */
50743 static long
50744 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
50745 +setxattr(struct path *path, const char __user *name, const void __user *value,
50746 size_t size, int flags)
50747 {
50748 int error;
50749 @@ -349,7 +349,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
50750 }
50751 }
50752
50753 - error = vfs_setxattr(d, kname, kvalue, size, flags);
50754 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
50755 + error = -EACCES;
50756 + goto out;
50757 + }
50758 +
50759 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
50760 out:
50761 if (vvalue)
50762 vfree(vvalue);
50763 @@ -370,7 +375,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
50764 return error;
50765 error = mnt_want_write(path.mnt);
50766 if (!error) {
50767 - error = setxattr(path.dentry, name, value, size, flags);
50768 + error = setxattr(&path, name, value, size, flags);
50769 mnt_drop_write(path.mnt);
50770 }
50771 path_put(&path);
50772 @@ -389,7 +394,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
50773 return error;
50774 error = mnt_want_write(path.mnt);
50775 if (!error) {
50776 - error = setxattr(path.dentry, name, value, size, flags);
50777 + error = setxattr(&path, name, value, size, flags);
50778 mnt_drop_write(path.mnt);
50779 }
50780 path_put(&path);
50781 @@ -401,17 +406,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
50782 {
50783 int fput_needed;
50784 struct file *f;
50785 - struct dentry *dentry;
50786 int error = -EBADF;
50787
50788 f = fget_light(fd, &fput_needed);
50789 if (!f)
50790 return error;
50791 - dentry = f->f_path.dentry;
50792 - audit_inode(NULL, dentry);
50793 + audit_inode(NULL, f->f_path.dentry);
50794 error = mnt_want_write_file(f);
50795 if (!error) {
50796 - error = setxattr(dentry, name, value, size, flags);
50797 + error = setxattr(&f->f_path, name, value, size, flags);
50798 mnt_drop_write_file(f);
50799 }
50800 fput_light(f, fput_needed);
50801 diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
50802 index 69d06b0..c0996e5 100644
50803 --- a/fs/xattr_acl.c
50804 +++ b/fs/xattr_acl.c
50805 @@ -17,8 +17,8 @@
50806 struct posix_acl *
50807 posix_acl_from_xattr(const void *value, size_t size)
50808 {
50809 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
50810 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
50811 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
50812 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
50813 int count;
50814 struct posix_acl *acl;
50815 struct posix_acl_entry *acl_e;
50816 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
50817 index 848ffa7..1f249bf 100644
50818 --- a/fs/xfs/xfs_bmap.c
50819 +++ b/fs/xfs/xfs_bmap.c
50820 @@ -189,7 +189,7 @@ xfs_bmap_validate_ret(
50821 int nmap,
50822 int ret_nmap);
50823 #else
50824 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
50825 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
50826 #endif /* DEBUG */
50827
50828 STATIC int
50829 diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
50830 index 1b9fc3e..e1bdde0 100644
50831 --- a/fs/xfs/xfs_dir2_sf.c
50832 +++ b/fs/xfs/xfs_dir2_sf.c
50833 @@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
50834 }
50835
50836 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
50837 - if (filldir(dirent, (char *)sfep->name, sfep->namelen,
50838 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
50839 + char name[sfep->namelen];
50840 + memcpy(name, sfep->name, sfep->namelen);
50841 + if (filldir(dirent, name, sfep->namelen,
50842 + off & 0x7fffffff, ino, DT_UNKNOWN)) {
50843 + *offset = off & 0x7fffffff;
50844 + return 0;
50845 + }
50846 + } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
50847 off & 0x7fffffff, ino, DT_UNKNOWN)) {
50848 *offset = off & 0x7fffffff;
50849 return 0;
50850 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
50851 index 0e0232c..fa5c3fe 100644
50852 --- a/fs/xfs/xfs_ioctl.c
50853 +++ b/fs/xfs/xfs_ioctl.c
50854 @@ -126,7 +126,7 @@ xfs_find_handle(
50855 }
50856
50857 error = -EFAULT;
50858 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
50859 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
50860 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
50861 goto out_put;
50862
50863 diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
50864 index 4e00cf0..3374374 100644
50865 --- a/fs/xfs/xfs_iops.c
50866 +++ b/fs/xfs/xfs_iops.c
50867 @@ -394,7 +394,7 @@ xfs_vn_put_link(
50868 struct nameidata *nd,
50869 void *p)
50870 {
50871 - char *s = nd_get_link(nd);
50872 + const char *s = nd_get_link(nd);
50873
50874 if (!IS_ERR(s))
50875 kfree(s);
50876 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
50877 new file mode 100644
50878 index 0000000..d38b430
50879 --- /dev/null
50880 +++ b/grsecurity/Kconfig
50881 @@ -0,0 +1,947 @@
50882 +#
50883 +# grecurity configuration
50884 +#
50885 +menu "Memory Protections"
50886 +depends on GRKERNSEC
50887 +
50888 +config GRKERNSEC_KMEM
50889 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
50890 + default y if GRKERNSEC_CONFIG_AUTO
50891 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
50892 + help
50893 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
50894 + be written to or read from to modify or leak the contents of the running
50895 + kernel. /dev/port will also not be allowed to be opened. If you have module
50896 + support disabled, enabling this will close up four ways that are
50897 + currently used to insert malicious code into the running kernel.
50898 + Even with all these features enabled, we still highly recommend that
50899 + you use the RBAC system, as it is still possible for an attacker to
50900 + modify the running kernel through privileged I/O granted by ioperm/iopl.
50901 + If you are not using XFree86, you may be able to stop this additional
50902 + case by enabling the 'Disable privileged I/O' option. Though nothing
50903 + legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
50904 + but only to video memory, which is the only writing we allow in this
50905 + case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
50906 + not be allowed to mprotect it with PROT_WRITE later.
50907 + It is highly recommended that you say Y here if you meet all the
50908 + conditions above.
50909 +
50910 +config GRKERNSEC_VM86
50911 + bool "Restrict VM86 mode"
50912 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50913 + depends on X86_32
50914 +
50915 + help
50916 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
50917 + make use of a special execution mode on 32bit x86 processors called
50918 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
50919 + video cards and will still work with this option enabled. The purpose
50920 + of the option is to prevent exploitation of emulation errors in
50921 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
50922 + Nearly all users should be able to enable this option.
50923 +
50924 +config GRKERNSEC_IO
50925 + bool "Disable privileged I/O"
50926 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50927 + depends on X86
50928 + select RTC_CLASS
50929 + select RTC_INTF_DEV
50930 + select RTC_DRV_CMOS
50931 +
50932 + help
50933 + If you say Y here, all ioperm and iopl calls will return an error.
50934 + Ioperm and iopl can be used to modify the running kernel.
50935 + Unfortunately, some programs need this access to operate properly,
50936 + the most notable of which are XFree86 and hwclock. hwclock can be
50937 + remedied by having RTC support in the kernel, so real-time
50938 + clock support is enabled if this option is enabled, to ensure
50939 + that hwclock operates correctly. XFree86 still will not
50940 + operate correctly with this option enabled, so DO NOT CHOOSE Y
50941 + IF YOU USE XFree86. If you use XFree86 and you still want to
50942 + protect your kernel against modification, use the RBAC system.
50943 +
50944 +config GRKERNSEC_PROC_MEMMAP
50945 + bool "Harden ASLR against information leaks and entropy reduction"
50946 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
50947 + depends on PAX_NOEXEC || PAX_ASLR
50948 + help
50949 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
50950 + give no information about the addresses of its mappings if
50951 + PaX features that rely on random addresses are enabled on the task.
50952 + In addition to sanitizing this information and disabling other
50953 + dangerous sources of information, this option causes reads of sensitive
50954 + /proc/<pid> entries where the file descriptor was opened in a different
50955 + task than the one performing the read. Such attempts are logged.
50956 + This option also limits argv/env strings for suid/sgid binaries
50957 + to 512KB to prevent a complete exhaustion of the stack entropy provided
50958 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
50959 + binaries to prevent alternative mmap layouts from being abused.
50960 +
50961 + If you use PaX it is essential that you say Y here as it closes up
50962 + several holes that make full ASLR useless locally.
50963 +
50964 +config GRKERNSEC_BRUTE
50965 + bool "Deter exploit bruteforcing"
50966 + default y if GRKERNSEC_CONFIG_AUTO
50967 + help
50968 + If you say Y here, attempts to bruteforce exploits against forking
50969 + daemons such as apache or sshd, as well as against suid/sgid binaries
50970 + will be deterred. When a child of a forking daemon is killed by PaX
50971 + or crashes due to an illegal instruction or other suspicious signal,
50972 + the parent process will be delayed 30 seconds upon every subsequent
50973 + fork until the administrator is able to assess the situation and
50974 + restart the daemon.
50975 + In the suid/sgid case, the attempt is logged, the user has all their
50976 + processes terminated, and they are prevented from executing any further
50977 + processes for 15 minutes.
50978 + It is recommended that you also enable signal logging in the auditing
50979 + section so that logs are generated when a process triggers a suspicious
50980 + signal.
50981 + If the sysctl option is enabled, a sysctl option with name
50982 + "deter_bruteforce" is created.
50983 +
50984 +
50985 +config GRKERNSEC_MODHARDEN
50986 + bool "Harden module auto-loading"
50987 + default y if GRKERNSEC_CONFIG_AUTO
50988 + depends on MODULES
50989 + help
50990 + If you say Y here, module auto-loading in response to use of some
50991 + feature implemented by an unloaded module will be restricted to
50992 + root users. Enabling this option helps defend against attacks
50993 + by unprivileged users who abuse the auto-loading behavior to
50994 + cause a vulnerable module to load that is then exploited.
50995 +
50996 + If this option prevents a legitimate use of auto-loading for a
50997 + non-root user, the administrator can execute modprobe manually
50998 + with the exact name of the module mentioned in the alert log.
50999 + Alternatively, the administrator can add the module to the list
51000 + of modules loaded at boot by modifying init scripts.
51001 +
51002 + Modification of init scripts will most likely be needed on
51003 + Ubuntu servers with encrypted home directory support enabled,
51004 + as the first non-root user logging in will cause the ecb(aes),
51005 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
51006 +
51007 +config GRKERNSEC_HIDESYM
51008 + bool "Hide kernel symbols"
51009 + default y if GRKERNSEC_CONFIG_AUTO
51010 + select PAX_USERCOPY_SLABS
51011 + help
51012 + If you say Y here, getting information on loaded modules, and
51013 + displaying all kernel symbols through a syscall will be restricted
51014 + to users with CAP_SYS_MODULE. For software compatibility reasons,
51015 + /proc/kallsyms will be restricted to the root user. The RBAC
51016 + system can hide that entry even from root.
51017 +
51018 + This option also prevents leaking of kernel addresses through
51019 + several /proc entries.
51020 +
51021 + Note that this option is only effective provided the following
51022 + conditions are met:
51023 + 1) The kernel using grsecurity is not precompiled by some distribution
51024 + 2) You have also enabled GRKERNSEC_DMESG
51025 + 3) You are using the RBAC system and hiding other files such as your
51026 + kernel image and System.map. Alternatively, enabling this option
51027 + causes the permissions on /boot, /lib/modules, and the kernel
51028 + source directory to change at compile time to prevent
51029 + reading by non-root users.
51030 + If the above conditions are met, this option will aid in providing a
51031 + useful protection against local kernel exploitation of overflows
51032 + and arbitrary read/write vulnerabilities.
51033 +
51034 +config GRKERNSEC_KERN_LOCKOUT
51035 + bool "Active kernel exploit response"
51036 + default y if GRKERNSEC_CONFIG_AUTO
51037 + depends on X86 || ARM || PPC || SPARC
51038 + help
51039 + If you say Y here, when a PaX alert is triggered due to suspicious
51040 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
51041 + or an OOPS occurs due to bad memory accesses, instead of just
51042 + terminating the offending process (and potentially allowing
51043 + a subsequent exploit from the same user), we will take one of two
51044 + actions:
51045 + If the user was root, we will panic the system
51046 + If the user was non-root, we will log the attempt, terminate
51047 + all processes owned by the user, then prevent them from creating
51048 + any new processes until the system is restarted
51049 + This deters repeated kernel exploitation/bruteforcing attempts
51050 + and is useful for later forensics.
51051 +
51052 +endmenu
51053 +menu "Role Based Access Control Options"
51054 +depends on GRKERNSEC
51055 +
51056 +config GRKERNSEC_RBAC_DEBUG
51057 + bool
51058 +
51059 +config GRKERNSEC_NO_RBAC
51060 + bool "Disable RBAC system"
51061 + help
51062 + If you say Y here, the /dev/grsec device will be removed from the kernel,
51063 + preventing the RBAC system from being enabled. You should only say Y
51064 + here if you have no intention of using the RBAC system, so as to prevent
51065 + an attacker with root access from misusing the RBAC system to hide files
51066 + and processes when loadable module support and /dev/[k]mem have been
51067 + locked down.
51068 +
51069 +config GRKERNSEC_ACL_HIDEKERN
51070 + bool "Hide kernel processes"
51071 + help
51072 + If you say Y here, all kernel threads will be hidden to all
51073 + processes but those whose subject has the "view hidden processes"
51074 + flag.
51075 +
51076 +config GRKERNSEC_ACL_MAXTRIES
51077 + int "Maximum tries before password lockout"
51078 + default 3
51079 + help
51080 + This option enforces the maximum number of times a user can attempt
51081 + to authorize themselves with the grsecurity RBAC system before being
51082 + denied the ability to attempt authorization again for a specified time.
51083 + The lower the number, the harder it will be to brute-force a password.
51084 +
51085 +config GRKERNSEC_ACL_TIMEOUT
51086 + int "Time to wait after max password tries, in seconds"
51087 + default 30
51088 + help
51089 + This option specifies the time the user must wait after attempting to
51090 + authorize to the RBAC system with the maximum number of invalid
51091 + passwords. The higher the number, the harder it will be to brute-force
51092 + a password.
51093 +
51094 +endmenu
51095 +menu "Filesystem Protections"
51096 +depends on GRKERNSEC
51097 +
51098 +config GRKERNSEC_PROC
51099 + bool "Proc restrictions"
51100 + default y if GRKERNSEC_CONFIG_AUTO
51101 + help
51102 + If you say Y here, the permissions of the /proc filesystem
51103 + will be altered to enhance system security and privacy. You MUST
51104 + choose either a user only restriction or a user and group restriction.
51105 + Depending upon the option you choose, you can either restrict users to
51106 + see only the processes they themselves run, or choose a group that can
51107 + view all processes and files normally restricted to root if you choose
51108 + the "restrict to user only" option. NOTE: If you're running identd or
51109 + ntpd as a non-root user, you will have to run it as the group you
51110 + specify here.
51111 +
51112 +config GRKERNSEC_PROC_USER
51113 + bool "Restrict /proc to user only"
51114 + depends on GRKERNSEC_PROC
51115 + help
51116 + If you say Y here, non-root users will only be able to view their own
51117 + processes, and restricts them from viewing network-related information,
51118 + and viewing kernel symbol and module information.
51119 +
51120 +config GRKERNSEC_PROC_USERGROUP
51121 + bool "Allow special group"
51122 + default y if GRKERNSEC_CONFIG_AUTO
51123 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
51124 + help
51125 + If you say Y here, you will be able to select a group that will be
51126 + able to view all processes and network-related information. If you've
51127 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
51128 + remain hidden. This option is useful if you want to run identd as
51129 + a non-root user. The group you select may also be chosen at boot time
51130 + via "grsec_proc_gid=" on the kernel commandline.
51131 +
51132 +config GRKERNSEC_PROC_GID
51133 + int "GID for special group"
51134 + depends on GRKERNSEC_PROC_USERGROUP
51135 + default 1001
51136 +
51137 +config GRKERNSEC_PROC_ADD
51138 + bool "Additional restrictions"
51139 + default y if GRKERNSEC_CONFIG_AUTO
51140 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
51141 + help
51142 + If you say Y here, additional restrictions will be placed on
51143 + /proc that keep normal users from viewing device information and
51144 + slabinfo information that could be useful for exploits.
51145 +
51146 +config GRKERNSEC_LINK
51147 + bool "Linking restrictions"
51148 + default y if GRKERNSEC_CONFIG_AUTO
51149 + help
51150 + If you say Y here, /tmp race exploits will be prevented, since users
51151 + will no longer be able to follow symlinks owned by other users in
51152 + world-writable +t directories (e.g. /tmp), unless the owner of the
51153 + symlink is the owner of the directory. users will also not be
51154 + able to hardlink to files they do not own. If the sysctl option is
51155 + enabled, a sysctl option with name "linking_restrictions" is created.
51156 +
51157 +config GRKERNSEC_SYMLINKOWN
51158 + bool "Kernel-enforced SymlinksIfOwnerMatch"
51159 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
51160 + help
51161 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
51162 + that prevents it from being used as a security feature. As Apache
51163 + verifies the symlink by performing a stat() against the target of
51164 + the symlink before it is followed, an attacker can setup a symlink
51165 + to point to a same-owned file, then replace the symlink with one
51166 + that targets another user's file just after Apache "validates" the
51167 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
51168 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
51169 + will be in place for the group you specify. If the sysctl option
51170 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
51171 + created.
51172 +
51173 +config GRKERNSEC_SYMLINKOWN_GID
51174 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
51175 + depends on GRKERNSEC_SYMLINKOWN
51176 + default 1006
51177 + help
51178 + Setting this GID determines what group kernel-enforced
51179 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
51180 + is enabled, a sysctl option with name "symlinkown_gid" is created.
51181 +
51182 +config GRKERNSEC_FIFO
51183 + bool "FIFO restrictions"
51184 + default y if GRKERNSEC_CONFIG_AUTO
51185 + help
51186 + If you say Y here, users will not be able to write to FIFOs they don't
51187 + own in world-writable +t directories (e.g. /tmp), unless the owner of
51188 + the FIFO is the same owner of the directory it's held in. If the sysctl
51189 + option is enabled, a sysctl option with name "fifo_restrictions" is
51190 + created.
51191 +
51192 +config GRKERNSEC_SYSFS_RESTRICT
51193 + bool "Sysfs/debugfs restriction"
51194 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
51195 + depends on SYSFS
51196 + help
51197 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
51198 + any filesystem normally mounted under it (e.g. debugfs) will be
51199 + mostly accessible only by root. These filesystems generally provide access
51200 + to hardware and debug information that isn't appropriate for unprivileged
51201 + users of the system. Sysfs and debugfs have also become a large source
51202 + of new vulnerabilities, ranging from infoleaks to local compromise.
51203 + There has been very little oversight with an eye toward security involved
51204 + in adding new exporters of information to these filesystems, so their
51205 + use is discouraged.
51206 + For reasons of compatibility, a few directories have been whitelisted
51207 + for access by non-root users:
51208 + /sys/fs/selinux
51209 + /sys/fs/fuse
51210 + /sys/devices/system/cpu
51211 +
51212 +config GRKERNSEC_ROFS
51213 + bool "Runtime read-only mount protection"
51214 + help
51215 + If you say Y here, a sysctl option with name "romount_protect" will
51216 + be created. By setting this option to 1 at runtime, filesystems
51217 + will be protected in the following ways:
51218 + * No new writable mounts will be allowed
51219 + * Existing read-only mounts won't be able to be remounted read/write
51220 + * Write operations will be denied on all block devices
51221 + This option acts independently of grsec_lock: once it is set to 1,
51222 + it cannot be turned off. Therefore, please be mindful of the resulting
51223 + behavior if this option is enabled in an init script on a read-only
51224 + filesystem. This feature is mainly intended for secure embedded systems.
51225 +
51226 +config GRKERNSEC_CHROOT
51227 + bool "Chroot jail restrictions"
51228 + default y if GRKERNSEC_CONFIG_AUTO
51229 + help
51230 + If you say Y here, you will be able to choose several options that will
51231 + make breaking out of a chrooted jail much more difficult. If you
51232 + encounter no software incompatibilities with the following options, it
51233 + is recommended that you enable each one.
51234 +
51235 +config GRKERNSEC_CHROOT_MOUNT
51236 + bool "Deny mounts"
51237 + default y if GRKERNSEC_CONFIG_AUTO
51238 + depends on GRKERNSEC_CHROOT
51239 + help
51240 + If you say Y here, processes inside a chroot will not be able to
51241 + mount or remount filesystems. If the sysctl option is enabled, a
51242 + sysctl option with name "chroot_deny_mount" is created.
51243 +
51244 +config GRKERNSEC_CHROOT_DOUBLE
51245 + bool "Deny double-chroots"
51246 + default y if GRKERNSEC_CONFIG_AUTO
51247 + depends on GRKERNSEC_CHROOT
51248 + help
51249 + If you say Y here, processes inside a chroot will not be able to chroot
51250 + again outside the chroot. This is a widely used method of breaking
51251 + out of a chroot jail and should not be allowed. If the sysctl
51252 + option is enabled, a sysctl option with name
51253 + "chroot_deny_chroot" is created.
51254 +
51255 +config GRKERNSEC_CHROOT_PIVOT
51256 + bool "Deny pivot_root in chroot"
51257 + default y if GRKERNSEC_CONFIG_AUTO
51258 + depends on GRKERNSEC_CHROOT
51259 + help
51260 + If you say Y here, processes inside a chroot will not be able to use
51261 + a function called pivot_root() that was introduced in Linux 2.3.41. It
51262 + works similar to chroot in that it changes the root filesystem. This
51263 + function could be misused in a chrooted process to attempt to break out
51264 + of the chroot, and therefore should not be allowed. If the sysctl
51265 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
51266 + created.
51267 +
51268 +config GRKERNSEC_CHROOT_CHDIR
51269 + bool "Enforce chdir(\"/\") on all chroots"
51270 + default y if GRKERNSEC_CONFIG_AUTO
51271 + depends on GRKERNSEC_CHROOT
51272 + help
51273 + If you say Y here, the current working directory of all newly-chrooted
51274 + applications will be set to the the root directory of the chroot.
51275 + The man page on chroot(2) states:
51276 + Note that this call does not change the current working
51277 + directory, so that `.' can be outside the tree rooted at
51278 + `/'. In particular, the super-user can escape from a
51279 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
51280 +
51281 + It is recommended that you say Y here, since it's not known to break
51282 + any software. If the sysctl option is enabled, a sysctl option with
51283 + name "chroot_enforce_chdir" is created.
51284 +
51285 +config GRKERNSEC_CHROOT_CHMOD
51286 + bool "Deny (f)chmod +s"
51287 + default y if GRKERNSEC_CONFIG_AUTO
51288 + depends on GRKERNSEC_CHROOT
51289 + help
51290 + If you say Y here, processes inside a chroot will not be able to chmod
51291 + or fchmod files to make them have suid or sgid bits. This protects
51292 + against another published method of breaking a chroot. If the sysctl
51293 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
51294 + created.
51295 +
51296 +config GRKERNSEC_CHROOT_FCHDIR
51297 + bool "Deny fchdir out of chroot"
51298 + default y if GRKERNSEC_CONFIG_AUTO
51299 + depends on GRKERNSEC_CHROOT
51300 + help
51301 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
51302 + to a file descriptor of the chrooting process that points to a directory
51303 + outside the filesystem will be stopped. If the sysctl option
51304 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
51305 +
51306 +config GRKERNSEC_CHROOT_MKNOD
51307 + bool "Deny mknod"
51308 + default y if GRKERNSEC_CONFIG_AUTO
51309 + depends on GRKERNSEC_CHROOT
51310 + help
51311 + If you say Y here, processes inside a chroot will not be allowed to
51312 + mknod. The problem with using mknod inside a chroot is that it
51313 + would allow an attacker to create a device entry that is the same
51314 + as one on the physical root of your system, which could range from
51315 + anything from the console device to a device for your harddrive (which
51316 + they could then use to wipe the drive or steal data). It is recommended
51317 + that you say Y here, unless you run into software incompatibilities.
51318 + If the sysctl option is enabled, a sysctl option with name
51319 + "chroot_deny_mknod" is created.
51320 +
51321 +config GRKERNSEC_CHROOT_SHMAT
51322 + bool "Deny shmat() out of chroot"
51323 + default y if GRKERNSEC_CONFIG_AUTO
51324 + depends on GRKERNSEC_CHROOT
51325 + help
51326 + If you say Y here, processes inside a chroot will not be able to attach
51327 + to shared memory segments that were created outside of the chroot jail.
51328 + It is recommended that you say Y here. If the sysctl option is enabled,
51329 + a sysctl option with name "chroot_deny_shmat" is created.
51330 +
51331 +config GRKERNSEC_CHROOT_UNIX
51332 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
51333 + default y if GRKERNSEC_CONFIG_AUTO
51334 + depends on GRKERNSEC_CHROOT
51335 + help
51336 + If you say Y here, processes inside a chroot will not be able to
51337 + connect to abstract (meaning not belonging to a filesystem) Unix
51338 + domain sockets that were bound outside of a chroot. It is recommended
51339 + that you say Y here. If the sysctl option is enabled, a sysctl option
51340 + with name "chroot_deny_unix" is created.
51341 +
51342 +config GRKERNSEC_CHROOT_FINDTASK
51343 + bool "Protect outside processes"
51344 + default y if GRKERNSEC_CONFIG_AUTO
51345 + depends on GRKERNSEC_CHROOT
51346 + help
51347 + If you say Y here, processes inside a chroot will not be able to
51348 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
51349 + getsid, or view any process outside of the chroot. If the sysctl
51350 + option is enabled, a sysctl option with name "chroot_findtask" is
51351 + created.
51352 +
51353 +config GRKERNSEC_CHROOT_NICE
51354 + bool "Restrict priority changes"
51355 + default y if GRKERNSEC_CONFIG_AUTO
51356 + depends on GRKERNSEC_CHROOT
51357 + help
51358 + If you say Y here, processes inside a chroot will not be able to raise
51359 + the priority of processes in the chroot, or alter the priority of
51360 + processes outside the chroot. This provides more security than simply
51361 + removing CAP_SYS_NICE from the process' capability set. If the
51362 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
51363 + is created.
51364 +
51365 +config GRKERNSEC_CHROOT_SYSCTL
51366 + bool "Deny sysctl writes"
51367 + default y if GRKERNSEC_CONFIG_AUTO
51368 + depends on GRKERNSEC_CHROOT
51369 + help
51370 + If you say Y here, an attacker in a chroot will not be able to
51371 + write to sysctl entries, either by sysctl(2) or through a /proc
51372 + interface. It is strongly recommended that you say Y here. If the
51373 + sysctl option is enabled, a sysctl option with name
51374 + "chroot_deny_sysctl" is created.
51375 +
51376 +config GRKERNSEC_CHROOT_CAPS
51377 + bool "Capability restrictions"
51378 + default y if GRKERNSEC_CONFIG_AUTO
51379 + depends on GRKERNSEC_CHROOT
51380 + help
51381 + If you say Y here, the capabilities on all processes within a
51382 + chroot jail will be lowered to stop module insertion, raw i/o,
51383 + system and net admin tasks, rebooting the system, modifying immutable
51384 + files, modifying IPC owned by another, and changing the system time.
51385 + This is left an option because it can break some apps. Disable this
51386 + if your chrooted apps are having problems performing those kinds of
51387 + tasks. If the sysctl option is enabled, a sysctl option with
51388 + name "chroot_caps" is created.
51389 +
51390 +endmenu
51391 +menu "Kernel Auditing"
51392 +depends on GRKERNSEC
51393 +
51394 +config GRKERNSEC_AUDIT_GROUP
51395 + bool "Single group for auditing"
51396 + help
51397 + If you say Y here, the exec, chdir, and (un)mount logging features
51398 + will only operate on a group you specify. This option is recommended
51399 + if you only want to watch certain users instead of having a large
51400 + amount of logs from the entire system. If the sysctl option is enabled,
51401 + a sysctl option with name "audit_group" is created.
51402 +
51403 +config GRKERNSEC_AUDIT_GID
51404 + int "GID for auditing"
51405 + depends on GRKERNSEC_AUDIT_GROUP
51406 + default 1007
51407 +
51408 +config GRKERNSEC_EXECLOG
51409 + bool "Exec logging"
51410 + help
51411 + If you say Y here, all execve() calls will be logged (since the
51412 + other exec*() calls are frontends to execve(), all execution
51413 + will be logged). Useful for shell-servers that like to keep track
51414 + of their users. If the sysctl option is enabled, a sysctl option with
51415 + name "exec_logging" is created.
51416 + WARNING: This option when enabled will produce a LOT of logs, especially
51417 + on an active system.
51418 +
51419 +config GRKERNSEC_RESLOG
51420 + bool "Resource logging"
51421 + default y if GRKERNSEC_CONFIG_AUTO
51422 + help
51423 + If you say Y here, all attempts to overstep resource limits will
51424 + be logged with the resource name, the requested size, and the current
51425 + limit. It is highly recommended that you say Y here. If the sysctl
51426 + option is enabled, a sysctl option with name "resource_logging" is
51427 + created. If the RBAC system is enabled, the sysctl value is ignored.
51428 +
51429 +config GRKERNSEC_CHROOT_EXECLOG
51430 + bool "Log execs within chroot"
51431 + help
51432 + If you say Y here, all executions inside a chroot jail will be logged
51433 + to syslog. This can cause a large amount of logs if certain
51434 + applications (eg. djb's daemontools) are installed on the system, and
51435 + is therefore left as an option. If the sysctl option is enabled, a
51436 + sysctl option with name "chroot_execlog" is created.
51437 +
51438 +config GRKERNSEC_AUDIT_PTRACE
51439 + bool "Ptrace logging"
51440 + help
51441 + If you say Y here, all attempts to attach to a process via ptrace
51442 + will be logged. If the sysctl option is enabled, a sysctl option
51443 + with name "audit_ptrace" is created.
51444 +
51445 +config GRKERNSEC_AUDIT_CHDIR
51446 + bool "Chdir logging"
51447 + help
51448 + If you say Y here, all chdir() calls will be logged. If the sysctl
51449 + option is enabled, a sysctl option with name "audit_chdir" is created.
51450 +
51451 +config GRKERNSEC_AUDIT_MOUNT
51452 + bool "(Un)Mount logging"
51453 + help
51454 + If you say Y here, all mounts and unmounts will be logged. If the
51455 + sysctl option is enabled, a sysctl option with name "audit_mount" is
51456 + created.
51457 +
51458 +config GRKERNSEC_SIGNAL
51459 + bool "Signal logging"
51460 + default y if GRKERNSEC_CONFIG_AUTO
51461 + help
51462 + If you say Y here, certain important signals will be logged, such as
51463 + SIGSEGV, which will as a result inform you of when a error in a program
51464 + occurred, which in some cases could mean a possible exploit attempt.
51465 + If the sysctl option is enabled, a sysctl option with name
51466 + "signal_logging" is created.
51467 +
51468 +config GRKERNSEC_FORKFAIL
51469 + bool "Fork failure logging"
51470 + help
51471 + If you say Y here, all failed fork() attempts will be logged.
51472 + This could suggest a fork bomb, or someone attempting to overstep
51473 + their process limit. If the sysctl option is enabled, a sysctl option
51474 + with name "forkfail_logging" is created.
51475 +
51476 +config GRKERNSEC_TIME
51477 + bool "Time change logging"
51478 + default y if GRKERNSEC_CONFIG_AUTO
51479 + help
51480 + If you say Y here, any changes of the system clock will be logged.
51481 + If the sysctl option is enabled, a sysctl option with name
51482 + "timechange_logging" is created.
51483 +
51484 +config GRKERNSEC_PROC_IPADDR
51485 + bool "/proc/<pid>/ipaddr support"
51486 + default y if GRKERNSEC_CONFIG_AUTO
51487 + help
51488 + If you say Y here, a new entry will be added to each /proc/<pid>
51489 + directory that contains the IP address of the person using the task.
51490 + The IP is carried across local TCP and AF_UNIX stream sockets.
51491 + This information can be useful for IDS/IPSes to perform remote response
51492 + to a local attack. The entry is readable by only the owner of the
51493 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
51494 + the RBAC system), and thus does not create privacy concerns.
51495 +
51496 +config GRKERNSEC_RWXMAP_LOG
51497 + bool 'Denied RWX mmap/mprotect logging'
51498 + default y if GRKERNSEC_CONFIG_AUTO
51499 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
51500 + help
51501 + If you say Y here, calls to mmap() and mprotect() with explicit
51502 + usage of PROT_WRITE and PROT_EXEC together will be logged when
51503 + denied by the PAX_MPROTECT feature. If the sysctl option is
51504 + enabled, a sysctl option with name "rwxmap_logging" is created.
51505 +
51506 +config GRKERNSEC_AUDIT_TEXTREL
51507 + bool 'ELF text relocations logging (READ HELP)'
51508 + depends on PAX_MPROTECT
51509 + help
51510 + If you say Y here, text relocations will be logged with the filename
51511 + of the offending library or binary. The purpose of the feature is
51512 + to help Linux distribution developers get rid of libraries and
51513 + binaries that need text relocations which hinder the future progress
51514 + of PaX. Only Linux distribution developers should say Y here, and
51515 + never on a production machine, as this option creates an information
51516 + leak that could aid an attacker in defeating the randomization of
51517 + a single memory region. If the sysctl option is enabled, a sysctl
51518 + option with name "audit_textrel" is created.
51519 +
51520 +endmenu
51521 +
51522 +menu "Executable Protections"
51523 +depends on GRKERNSEC
51524 +
51525 +config GRKERNSEC_DMESG
51526 + bool "Dmesg(8) restriction"
51527 + default y if GRKERNSEC_CONFIG_AUTO
51528 + help
51529 + If you say Y here, non-root users will not be able to use dmesg(8)
51530 + to view up to the last 4kb of messages in the kernel's log buffer.
51531 + The kernel's log buffer often contains kernel addresses and other
51532 + identifying information useful to an attacker in fingerprinting a
51533 + system for a targeted exploit.
51534 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
51535 + created.
51536 +
51537 +config GRKERNSEC_HARDEN_PTRACE
51538 + bool "Deter ptrace-based process snooping"
51539 + default y if GRKERNSEC_CONFIG_AUTO
51540 + help
51541 + If you say Y here, TTY sniffers and other malicious monitoring
51542 + programs implemented through ptrace will be defeated. If you
51543 + have been using the RBAC system, this option has already been
51544 + enabled for several years for all users, with the ability to make
51545 + fine-grained exceptions.
51546 +
51547 + This option only affects the ability of non-root users to ptrace
51548 + processes that are not a descendent of the ptracing process.
51549 + This means that strace ./binary and gdb ./binary will still work,
51550 + but attaching to arbitrary processes will not. If the sysctl
51551 + option is enabled, a sysctl option with name "harden_ptrace" is
51552 + created.
51553 +
51554 +config GRKERNSEC_PTRACE_READEXEC
51555 + bool "Require read access to ptrace sensitive binaries"
51556 + default y if GRKERNSEC_CONFIG_AUTO
51557 + help
51558 + If you say Y here, unprivileged users will not be able to ptrace unreadable
51559 + binaries. This option is useful in environments that
51560 + remove the read bits (e.g. file mode 4711) from suid binaries to
51561 + prevent infoleaking of their contents. This option adds
51562 + consistency to the use of that file mode, as the binary could normally
51563 + be read out when run without privileges while ptracing.
51564 +
51565 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
51566 + is created.
51567 +
51568 +config GRKERNSEC_SETXID
51569 + bool "Enforce consistent multithreaded privileges"
51570 + default y if GRKERNSEC_CONFIG_AUTO
51571 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
51572 + help
51573 + If you say Y here, a change from a root uid to a non-root uid
51574 + in a multithreaded application will cause the resulting uids,
51575 + gids, supplementary groups, and capabilities in that thread
51576 + to be propagated to the other threads of the process. In most
51577 + cases this is unnecessary, as glibc will emulate this behavior
51578 + on behalf of the application. Other libcs do not act in the
51579 + same way, allowing the other threads of the process to continue
51580 + running with root privileges. If the sysctl option is enabled,
51581 + a sysctl option with name "consistent_setxid" is created.
51582 +
51583 +config GRKERNSEC_TPE
51584 + bool "Trusted Path Execution (TPE)"
51585 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
51586 + help
51587 + If you say Y here, you will be able to choose a gid to add to the
51588 + supplementary groups of users you want to mark as "untrusted."
51589 + These users will not be able to execute any files that are not in
51590 + root-owned directories writable only by root. If the sysctl option
51591 + is enabled, a sysctl option with name "tpe" is created.
51592 +
51593 +config GRKERNSEC_TPE_ALL
51594 + bool "Partially restrict all non-root users"
51595 + depends on GRKERNSEC_TPE
51596 + help
51597 + If you say Y here, all non-root users will be covered under
51598 + a weaker TPE restriction. This is separate from, and in addition to,
51599 + the main TPE options that you have selected elsewhere. Thus, if a
51600 + "trusted" GID is chosen, this restriction applies to even that GID.
51601 + Under this restriction, all non-root users will only be allowed to
51602 + execute files in directories they own that are not group or
51603 + world-writable, or in directories owned by root and writable only by
51604 + root. If the sysctl option is enabled, a sysctl option with name
51605 + "tpe_restrict_all" is created.
51606 +
51607 +config GRKERNSEC_TPE_INVERT
51608 + bool "Invert GID option"
51609 + depends on GRKERNSEC_TPE
51610 + help
51611 + If you say Y here, the group you specify in the TPE configuration will
51612 + decide what group TPE restrictions will be *disabled* for. This
51613 + option is useful if you want TPE restrictions to be applied to most
51614 + users on the system. If the sysctl option is enabled, a sysctl option
51615 + with name "tpe_invert" is created. Unlike other sysctl options, this
51616 + entry will default to on for backward-compatibility.
51617 +
51618 +config GRKERNSEC_TPE_GID
51619 + int
51620 + default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
51621 + default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
51622 +
51623 +config GRKERNSEC_TPE_UNTRUSTED_GID
51624 + int "GID for TPE-untrusted users"
51625 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
51626 + default 1005
51627 + help
51628 + Setting this GID determines what group TPE restrictions will be
51629 + *enabled* for. If the sysctl option is enabled, a sysctl option
51630 + with name "tpe_gid" is created.
51631 +
51632 +config GRKERNSEC_TPE_TRUSTED_GID
51633 + int "GID for TPE-trusted users"
51634 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
51635 + default 1005
51636 + help
51637 + Setting this GID determines what group TPE restrictions will be
51638 + *disabled* for. If the sysctl option is enabled, a sysctl option
51639 + with name "tpe_gid" is created.
51640 +
51641 +endmenu
51642 +menu "Network Protections"
51643 +depends on GRKERNSEC
51644 +
51645 +config GRKERNSEC_RANDNET
51646 + bool "Larger entropy pools"
51647 + default y if GRKERNSEC_CONFIG_AUTO
51648 + help
51649 + If you say Y here, the entropy pools used for many features of Linux
51650 + and grsecurity will be doubled in size. Since several grsecurity
51651 + features use additional randomness, it is recommended that you say Y
51652 + here. Saying Y here has a similar effect as modifying
51653 + /proc/sys/kernel/random/poolsize.
51654 +
51655 +config GRKERNSEC_BLACKHOLE
51656 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
51657 + default y if GRKERNSEC_CONFIG_AUTO
51658 + depends on NET
51659 + help
51660 + If you say Y here, neither TCP resets nor ICMP
51661 + destination-unreachable packets will be sent in response to packets
51662 + sent to ports for which no associated listening process exists.
51663 + This feature supports both IPV4 and IPV6 and exempts the
51664 + loopback interface from blackholing. Enabling this feature
51665 + makes a host more resilient to DoS attacks and reduces network
51666 + visibility against scanners.
51667 +
51668 + The blackhole feature as-implemented is equivalent to the FreeBSD
51669 + blackhole feature, as it prevents RST responses to all packets, not
51670 + just SYNs. Under most application behavior this causes no
51671 + problems, but applications (like haproxy) may not close certain
51672 + connections in a way that cleanly terminates them on the remote
51673 + end, leaving the remote host in LAST_ACK state. Because of this
51674 + side-effect and to prevent intentional LAST_ACK DoSes, this
51675 + feature also adds automatic mitigation against such attacks.
51676 + The mitigation drastically reduces the amount of time a socket
51677 + can spend in LAST_ACK state. If you're using haproxy and not
51678 + all servers it connects to have this option enabled, consider
51679 + disabling this feature on the haproxy host.
51680 +
51681 + If the sysctl option is enabled, two sysctl options with names
51682 + "ip_blackhole" and "lastack_retries" will be created.
51683 + While "ip_blackhole" takes the standard zero/non-zero on/off
51684 + toggle, "lastack_retries" uses the same kinds of values as
51685 + "tcp_retries1" and "tcp_retries2". The default value of 4
51686 + prevents a socket from lasting more than 45 seconds in LAST_ACK
51687 + state.
51688 +
51689 +config GRKERNSEC_SOCKET
51690 + bool "Socket restrictions"
51691 + depends on NET
51692 + help
51693 + If you say Y here, you will be able to choose from several options.
51694 + If you assign a GID on your system and add it to the supplementary
51695 + groups of users you want to restrict socket access to, this patch
51696 + will perform up to three things, based on the option(s) you choose.
51697 +
51698 +config GRKERNSEC_SOCKET_ALL
51699 + bool "Deny any sockets to group"
51700 + depends on GRKERNSEC_SOCKET
51701 + help
51702 + If you say Y here, you will be able to choose a GID of whose users will
51703 + be unable to connect to other hosts from your machine or run server
51704 + applications from your machine. If the sysctl option is enabled, a
51705 + sysctl option with name "socket_all" is created.
51706 +
51707 +config GRKERNSEC_SOCKET_ALL_GID
51708 + int "GID to deny all sockets for"
51709 + depends on GRKERNSEC_SOCKET_ALL
51710 + default 1004
51711 + help
51712 + Here you can choose the GID to disable socket access for. Remember to
51713 + add the users you want socket access disabled for to the GID
51714 + specified here. If the sysctl option is enabled, a sysctl option
51715 + with name "socket_all_gid" is created.
51716 +
51717 +config GRKERNSEC_SOCKET_CLIENT
51718 + bool "Deny client sockets to group"
51719 + depends on GRKERNSEC_SOCKET
51720 + help
51721 + If you say Y here, you will be able to choose a GID of whose users will
51722 + be unable to connect to other hosts from your machine, but will be
51723 + able to run servers. If this option is enabled, all users in the group
51724 + you specify will have to use passive mode when initiating ftp transfers
51725 + from the shell on your machine. If the sysctl option is enabled, a
51726 + sysctl option with name "socket_client" is created.
51727 +
51728 +config GRKERNSEC_SOCKET_CLIENT_GID
51729 + int "GID to deny client sockets for"
51730 + depends on GRKERNSEC_SOCKET_CLIENT
51731 + default 1003
51732 + help
51733 + Here you can choose the GID to disable client socket access for.
51734 + Remember to add the users you want client socket access disabled for to
51735 + the GID specified here. If the sysctl option is enabled, a sysctl
51736 + option with name "socket_client_gid" is created.
51737 +
51738 +config GRKERNSEC_SOCKET_SERVER
51739 + bool "Deny server sockets to group"
51740 + depends on GRKERNSEC_SOCKET
51741 + help
51742 + If you say Y here, you will be able to choose a GID of whose users will
51743 + be unable to run server applications from your machine. If the sysctl
51744 + option is enabled, a sysctl option with name "socket_server" is created.
51745 +
51746 +config GRKERNSEC_SOCKET_SERVER_GID
51747 + int "GID to deny server sockets for"
51748 + depends on GRKERNSEC_SOCKET_SERVER
51749 + default 1002
51750 + help
51751 + Here you can choose the GID to disable server socket access for.
51752 + Remember to add the users you want server socket access disabled for to
51753 + the GID specified here. If the sysctl option is enabled, a sysctl
51754 + option with name "socket_server_gid" is created.
51755 +
51756 +endmenu
51757 +menu "Sysctl Support"
51758 +depends on GRKERNSEC && SYSCTL
51759 +
51760 +config GRKERNSEC_SYSCTL
51761 + bool "Sysctl support"
51762 + default y if GRKERNSEC_CONFIG_AUTO
51763 + help
51764 + If you say Y here, you will be able to change the options that
51765 + grsecurity runs with at bootup, without having to recompile your
51766 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
51767 + to enable (1) or disable (0) various features. All the sysctl entries
51768 + are mutable until the "grsec_lock" entry is set to a non-zero value.
51769 + All features enabled in the kernel configuration are disabled at boot
51770 + if you do not say Y to the "Turn on features by default" option.
51771 + All options should be set at startup, and the grsec_lock entry should
51772 + be set to a non-zero value after all the options are set.
51773 + *THIS IS EXTREMELY IMPORTANT*
51774 +
51775 +config GRKERNSEC_SYSCTL_DISTRO
51776 + bool "Extra sysctl support for distro makers (READ HELP)"
51777 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
51778 + help
51779 + If you say Y here, additional sysctl options will be created
51780 + for features that affect processes running as root. Therefore,
51781 + it is critical when using this option that the grsec_lock entry be
51782 + enabled after boot. Only distros with prebuilt kernel packages
51783 + with this option enabled that can ensure grsec_lock is enabled
51784 + after boot should use this option.
51785 + *Failure to set grsec_lock after boot makes all grsec features
51786 + this option covers useless*
51787 +
51788 + Currently this option creates the following sysctl entries:
51789 + "Disable Privileged I/O": "disable_priv_io"
51790 +
51791 +config GRKERNSEC_SYSCTL_ON
51792 + bool "Turn on features by default"
51793 + default y if GRKERNSEC_CONFIG_AUTO
51794 + depends on GRKERNSEC_SYSCTL
51795 + help
51796 + If you say Y here, instead of having all features enabled in the
51797 + kernel configuration disabled at boot time, the features will be
51798 + enabled at boot time. It is recommended you say Y here unless
51799 + there is some reason you would want all sysctl-tunable features to
51800 + be disabled by default. As mentioned elsewhere, it is important
51801 + to enable the grsec_lock entry once you have finished modifying
51802 + the sysctl entries.
51803 +
51804 +endmenu
51805 +menu "Logging Options"
51806 +depends on GRKERNSEC
51807 +
51808 +config GRKERNSEC_FLOODTIME
51809 + int "Seconds in between log messages (minimum)"
51810 + default 10
51811 + help
51812 + This option allows you to enforce the number of seconds between
51813 + grsecurity log messages. The default should be suitable for most
51814 + people, however, if you choose to change it, choose a value small enough
51815 + to allow informative logs to be produced, but large enough to
51816 + prevent flooding.
51817 +
51818 +config GRKERNSEC_FLOODBURST
51819 + int "Number of messages in a burst (maximum)"
51820 + default 6
51821 + help
51822 + This option allows you to choose the maximum number of messages allowed
51823 + within the flood time interval you chose in a separate option. The
51824 + default should be suitable for most people, however if you find that
51825 + many of your logs are being interpreted as flooding, you may want to
51826 + raise this value.
51827 +
51828 +endmenu
51829 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
51830 new file mode 100644
51831 index 0000000..1b9afa9
51832 --- /dev/null
51833 +++ b/grsecurity/Makefile
51834 @@ -0,0 +1,38 @@
51835 +# grsecurity's ACL system was originally written in 2001 by Michael Dalton
51836 +# during 2001-2009 it has been completely redesigned by Brad Spengler
51837 +# into an RBAC system
51838 +#
51839 +# All code in this directory and various hooks inserted throughout the kernel
51840 +# are copyright Brad Spengler - Open Source Security, Inc., and released
51841 +# under the GPL v2 or higher
51842 +
51843 +KBUILD_CFLAGS += -Werror
51844 +
51845 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
51846 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
51847 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
51848 +
51849 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
51850 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
51851 + gracl_learn.o grsec_log.o
51852 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
51853 +
51854 +ifdef CONFIG_NET
51855 +obj-y += grsec_sock.o
51856 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
51857 +endif
51858 +
51859 +ifndef CONFIG_GRKERNSEC
51860 +obj-y += grsec_disabled.o
51861 +endif
51862 +
51863 +ifdef CONFIG_GRKERNSEC_HIDESYM
51864 +extra-y := grsec_hidesym.o
51865 +$(obj)/grsec_hidesym.o:
51866 + @-chmod -f 500 /boot
51867 + @-chmod -f 500 /lib/modules
51868 + @-chmod -f 500 /lib64/modules
51869 + @-chmod -f 500 /lib32/modules
51870 + @-chmod -f 700 .
51871 + @echo ' grsec: protected kernel image paths'
51872 +endif
51873 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
51874 new file mode 100644
51875 index 0000000..b736032
51876 --- /dev/null
51877 +++ b/grsecurity/gracl.c
51878 @@ -0,0 +1,4040 @@
51879 +#include <linux/kernel.h>
51880 +#include <linux/module.h>
51881 +#include <linux/sched.h>
51882 +#include <linux/mm.h>
51883 +#include <linux/file.h>
51884 +#include <linux/fs.h>
51885 +#include <linux/namei.h>
51886 +#include <linux/mount.h>
51887 +#include <linux/tty.h>
51888 +#include <linux/proc_fs.h>
51889 +#include <linux/lglock.h>
51890 +#include <linux/slab.h>
51891 +#include <linux/vmalloc.h>
51892 +#include <linux/types.h>
51893 +#include <linux/sysctl.h>
51894 +#include <linux/netdevice.h>
51895 +#include <linux/ptrace.h>
51896 +#include <linux/gracl.h>
51897 +#include <linux/gralloc.h>
51898 +#include <linux/security.h>
51899 +#include <linux/grinternal.h>
51900 +#include <linux/pid_namespace.h>
51901 +#include <linux/stop_machine.h>
51902 +#include <linux/fdtable.h>
51903 +#include <linux/percpu.h>
51904 +#include <linux/lglock.h>
51905 +#include "../fs/mount.h"
51906 +
51907 +#include <asm/uaccess.h>
51908 +#include <asm/errno.h>
51909 +#include <asm/mman.h>
51910 +
51911 +extern struct lglock vfsmount_lock;
51912 +
51913 +static struct acl_role_db acl_role_set;
51914 +static struct name_db name_set;
51915 +static struct inodev_db inodev_set;
51916 +
51917 +/* for keeping track of userspace pointers used for subjects, so we
51918 + can share references in the kernel as well
51919 +*/
51920 +
51921 +static struct path real_root;
51922 +
51923 +static struct acl_subj_map_db subj_map_set;
51924 +
51925 +static struct acl_role_label *default_role;
51926 +
51927 +static struct acl_role_label *role_list;
51928 +
51929 +static u16 acl_sp_role_value;
51930 +
51931 +extern char *gr_shared_page[4];
51932 +static DEFINE_MUTEX(gr_dev_mutex);
51933 +DEFINE_RWLOCK(gr_inode_lock);
51934 +
51935 +struct gr_arg *gr_usermode;
51936 +
51937 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
51938 +
51939 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
51940 +extern void gr_clear_learn_entries(void);
51941 +
51942 +#ifdef CONFIG_GRKERNSEC_RESLOG
51943 +extern void gr_log_resource(const struct task_struct *task,
51944 + const int res, const unsigned long wanted, const int gt);
51945 +#endif
51946 +
51947 +unsigned char *gr_system_salt;
51948 +unsigned char *gr_system_sum;
51949 +
51950 +static struct sprole_pw **acl_special_roles = NULL;
51951 +static __u16 num_sprole_pws = 0;
51952 +
51953 +static struct acl_role_label *kernel_role = NULL;
51954 +
51955 +static unsigned int gr_auth_attempts = 0;
51956 +static unsigned long gr_auth_expires = 0UL;
51957 +
51958 +#ifdef CONFIG_NET
51959 +extern struct vfsmount *sock_mnt;
51960 +#endif
51961 +
51962 +extern struct vfsmount *pipe_mnt;
51963 +extern struct vfsmount *shm_mnt;
51964 +#ifdef CONFIG_HUGETLBFS
51965 +extern struct vfsmount *hugetlbfs_vfsmount;
51966 +#endif
51967 +
51968 +static struct acl_object_label *fakefs_obj_rw;
51969 +static struct acl_object_label *fakefs_obj_rwx;
51970 +
51971 +extern int gr_init_uidset(void);
51972 +extern void gr_free_uidset(void);
51973 +extern void gr_remove_uid(uid_t uid);
51974 +extern int gr_find_uid(uid_t uid);
51975 +
51976 +__inline__ int
51977 +gr_acl_is_enabled(void)
51978 +{
51979 + return (gr_status & GR_READY);
51980 +}
51981 +
51982 +#ifdef CONFIG_BTRFS_FS
51983 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
51984 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
51985 +#endif
51986 +
51987 +static inline dev_t __get_dev(const struct dentry *dentry)
51988 +{
51989 +#ifdef CONFIG_BTRFS_FS
51990 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
51991 + return get_btrfs_dev_from_inode(dentry->d_inode);
51992 + else
51993 +#endif
51994 + return dentry->d_inode->i_sb->s_dev;
51995 +}
51996 +
51997 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
51998 +{
51999 + return __get_dev(dentry);
52000 +}
52001 +
52002 +static char gr_task_roletype_to_char(struct task_struct *task)
52003 +{
52004 + switch (task->role->roletype &
52005 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
52006 + GR_ROLE_SPECIAL)) {
52007 + case GR_ROLE_DEFAULT:
52008 + return 'D';
52009 + case GR_ROLE_USER:
52010 + return 'U';
52011 + case GR_ROLE_GROUP:
52012 + return 'G';
52013 + case GR_ROLE_SPECIAL:
52014 + return 'S';
52015 + }
52016 +
52017 + return 'X';
52018 +}
52019 +
52020 +char gr_roletype_to_char(void)
52021 +{
52022 + return gr_task_roletype_to_char(current);
52023 +}
52024 +
52025 +__inline__ int
52026 +gr_acl_tpe_check(void)
52027 +{
52028 + if (unlikely(!(gr_status & GR_READY)))
52029 + return 0;
52030 + if (current->role->roletype & GR_ROLE_TPE)
52031 + return 1;
52032 + else
52033 + return 0;
52034 +}
52035 +
52036 +int
52037 +gr_handle_rawio(const struct inode *inode)
52038 +{
52039 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
52040 + if (inode && S_ISBLK(inode->i_mode) &&
52041 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
52042 + !capable(CAP_SYS_RAWIO))
52043 + return 1;
52044 +#endif
52045 + return 0;
52046 +}
52047 +
52048 +static int
52049 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
52050 +{
52051 + if (likely(lena != lenb))
52052 + return 0;
52053 +
52054 + return !memcmp(a, b, lena);
52055 +}
52056 +
52057 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
52058 +{
52059 + *buflen -= namelen;
52060 + if (*buflen < 0)
52061 + return -ENAMETOOLONG;
52062 + *buffer -= namelen;
52063 + memcpy(*buffer, str, namelen);
52064 + return 0;
52065 +}
52066 +
52067 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
52068 +{
52069 + return prepend(buffer, buflen, name->name, name->len);
52070 +}
52071 +
52072 +static int prepend_path(const struct path *path, struct path *root,
52073 + char **buffer, int *buflen)
52074 +{
52075 + struct dentry *dentry = path->dentry;
52076 + struct vfsmount *vfsmnt = path->mnt;
52077 + struct mount *mnt = real_mount(vfsmnt);
52078 + bool slash = false;
52079 + int error = 0;
52080 +
52081 + while (dentry != root->dentry || vfsmnt != root->mnt) {
52082 + struct dentry * parent;
52083 +
52084 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
52085 + /* Global root? */
52086 + if (!mnt_has_parent(mnt)) {
52087 + goto out;
52088 + }
52089 + dentry = mnt->mnt_mountpoint;
52090 + mnt = mnt->mnt_parent;
52091 + vfsmnt = &mnt->mnt;
52092 + continue;
52093 + }
52094 + parent = dentry->d_parent;
52095 + prefetch(parent);
52096 + spin_lock(&dentry->d_lock);
52097 + error = prepend_name(buffer, buflen, &dentry->d_name);
52098 + spin_unlock(&dentry->d_lock);
52099 + if (!error)
52100 + error = prepend(buffer, buflen, "/", 1);
52101 + if (error)
52102 + break;
52103 +
52104 + slash = true;
52105 + dentry = parent;
52106 + }
52107 +
52108 +out:
52109 + if (!error && !slash)
52110 + error = prepend(buffer, buflen, "/", 1);
52111 +
52112 + return error;
52113 +}
52114 +
52115 +/* this must be called with vfsmount_lock and rename_lock held */
52116 +
52117 +static char *__our_d_path(const struct path *path, struct path *root,
52118 + char *buf, int buflen)
52119 +{
52120 + char *res = buf + buflen;
52121 + int error;
52122 +
52123 + prepend(&res, &buflen, "\0", 1);
52124 + error = prepend_path(path, root, &res, &buflen);
52125 + if (error)
52126 + return ERR_PTR(error);
52127 +
52128 + return res;
52129 +}
52130 +
52131 +static char *
52132 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
52133 +{
52134 + char *retval;
52135 +
52136 + retval = __our_d_path(path, root, buf, buflen);
52137 + if (unlikely(IS_ERR(retval)))
52138 + retval = strcpy(buf, "<path too long>");
52139 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
52140 + retval[1] = '\0';
52141 +
52142 + return retval;
52143 +}
52144 +
52145 +static char *
52146 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
52147 + char *buf, int buflen)
52148 +{
52149 + struct path path;
52150 + char *res;
52151 +
52152 + path.dentry = (struct dentry *)dentry;
52153 + path.mnt = (struct vfsmount *)vfsmnt;
52154 +
52155 + /* we can use real_root.dentry, real_root.mnt, because this is only called
52156 + by the RBAC system */
52157 + res = gen_full_path(&path, &real_root, buf, buflen);
52158 +
52159 + return res;
52160 +}
52161 +
52162 +static char *
52163 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
52164 + char *buf, int buflen)
52165 +{
52166 + char *res;
52167 + struct path path;
52168 + struct path root;
52169 + struct task_struct *reaper = init_pid_ns.child_reaper;
52170 +
52171 + path.dentry = (struct dentry *)dentry;
52172 + path.mnt = (struct vfsmount *)vfsmnt;
52173 +
52174 + /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
52175 + get_fs_root(reaper->fs, &root);
52176 +
52177 + write_seqlock(&rename_lock);
52178 + br_read_lock(&vfsmount_lock);
52179 + res = gen_full_path(&path, &root, buf, buflen);
52180 + br_read_unlock(&vfsmount_lock);
52181 + write_sequnlock(&rename_lock);
52182 +
52183 + path_put(&root);
52184 + return res;
52185 +}
52186 +
52187 +static char *
52188 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
52189 +{
52190 + char *ret;
52191 + write_seqlock(&rename_lock);
52192 + br_read_lock(&vfsmount_lock);
52193 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
52194 + PAGE_SIZE);
52195 + br_read_unlock(&vfsmount_lock);
52196 + write_sequnlock(&rename_lock);
52197 + return ret;
52198 +}
52199 +
52200 +static char *
52201 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
52202 +{
52203 + char *ret;
52204 + char *buf;
52205 + int buflen;
52206 +
52207 + write_seqlock(&rename_lock);
52208 + br_read_lock(&vfsmount_lock);
52209 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
52210 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
52211 + buflen = (int)(ret - buf);
52212 + if (buflen >= 5)
52213 + prepend(&ret, &buflen, "/proc", 5);
52214 + else
52215 + ret = strcpy(buf, "<path too long>");
52216 + br_read_unlock(&vfsmount_lock);
52217 + write_sequnlock(&rename_lock);
52218 + return ret;
52219 +}
52220 +
52221 +char *
52222 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
52223 +{
52224 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
52225 + PAGE_SIZE);
52226 +}
52227 +
52228 +char *
52229 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
52230 +{
52231 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
52232 + PAGE_SIZE);
52233 +}
52234 +
52235 +char *
52236 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
52237 +{
52238 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
52239 + PAGE_SIZE);
52240 +}
52241 +
52242 +char *
52243 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
52244 +{
52245 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
52246 + PAGE_SIZE);
52247 +}
52248 +
52249 +char *
52250 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
52251 +{
52252 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
52253 + PAGE_SIZE);
52254 +}
52255 +
52256 +__inline__ __u32
52257 +to_gr_audit(const __u32 reqmode)
52258 +{
52259 + /* masks off auditable permission flags, then shifts them to create
52260 + auditing flags, and adds the special case of append auditing if
52261 + we're requesting write */
52262 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
52263 +}
52264 +
52265 +struct acl_subject_label *
52266 +lookup_subject_map(const struct acl_subject_label *userp)
52267 +{
52268 + unsigned int index = shash(userp, subj_map_set.s_size);
52269 + struct subject_map *match;
52270 +
52271 + match = subj_map_set.s_hash[index];
52272 +
52273 + while (match && match->user != userp)
52274 + match = match->next;
52275 +
52276 + if (match != NULL)
52277 + return match->kernel;
52278 + else
52279 + return NULL;
52280 +}
52281 +
52282 +static void
52283 +insert_subj_map_entry(struct subject_map *subjmap)
52284 +{
52285 + unsigned int index = shash(subjmap->user, subj_map_set.s_size);
52286 + struct subject_map **curr;
52287 +
52288 + subjmap->prev = NULL;
52289 +
52290 + curr = &subj_map_set.s_hash[index];
52291 + if (*curr != NULL)
52292 + (*curr)->prev = subjmap;
52293 +
52294 + subjmap->next = *curr;
52295 + *curr = subjmap;
52296 +
52297 + return;
52298 +}
52299 +
52300 +static struct acl_role_label *
52301 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
52302 + const gid_t gid)
52303 +{
52304 + unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
52305 + struct acl_role_label *match;
52306 + struct role_allowed_ip *ipp;
52307 + unsigned int x;
52308 + u32 curr_ip = task->signal->curr_ip;
52309 +
52310 + task->signal->saved_ip = curr_ip;
52311 +
52312 + match = acl_role_set.r_hash[index];
52313 +
52314 + while (match) {
52315 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
52316 + for (x = 0; x < match->domain_child_num; x++) {
52317 + if (match->domain_children[x] == uid)
52318 + goto found;
52319 + }
52320 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
52321 + break;
52322 + match = match->next;
52323 + }
52324 +found:
52325 + if (match == NULL) {
52326 + try_group:
52327 + index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
52328 + match = acl_role_set.r_hash[index];
52329 +
52330 + while (match) {
52331 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
52332 + for (x = 0; x < match->domain_child_num; x++) {
52333 + if (match->domain_children[x] == gid)
52334 + goto found2;
52335 + }
52336 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
52337 + break;
52338 + match = match->next;
52339 + }
52340 +found2:
52341 + if (match == NULL)
52342 + match = default_role;
52343 + if (match->allowed_ips == NULL)
52344 + return match;
52345 + else {
52346 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
52347 + if (likely
52348 + ((ntohl(curr_ip) & ipp->netmask) ==
52349 + (ntohl(ipp->addr) & ipp->netmask)))
52350 + return match;
52351 + }
52352 + match = default_role;
52353 + }
52354 + } else if (match->allowed_ips == NULL) {
52355 + return match;
52356 + } else {
52357 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
52358 + if (likely
52359 + ((ntohl(curr_ip) & ipp->netmask) ==
52360 + (ntohl(ipp->addr) & ipp->netmask)))
52361 + return match;
52362 + }
52363 + goto try_group;
52364 + }
52365 +
52366 + return match;
52367 +}
52368 +
52369 +struct acl_subject_label *
52370 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
52371 + const struct acl_role_label *role)
52372 +{
52373 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
52374 + struct acl_subject_label *match;
52375 +
52376 + match = role->subj_hash[index];
52377 +
52378 + while (match && (match->inode != ino || match->device != dev ||
52379 + (match->mode & GR_DELETED))) {
52380 + match = match->next;
52381 + }
52382 +
52383 + if (match && !(match->mode & GR_DELETED))
52384 + return match;
52385 + else
52386 + return NULL;
52387 +}
52388 +
52389 +struct acl_subject_label *
52390 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
52391 + const struct acl_role_label *role)
52392 +{
52393 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
52394 + struct acl_subject_label *match;
52395 +
52396 + match = role->subj_hash[index];
52397 +
52398 + while (match && (match->inode != ino || match->device != dev ||
52399 + !(match->mode & GR_DELETED))) {
52400 + match = match->next;
52401 + }
52402 +
52403 + if (match && (match->mode & GR_DELETED))
52404 + return match;
52405 + else
52406 + return NULL;
52407 +}
52408 +
52409 +static struct acl_object_label *
52410 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
52411 + const struct acl_subject_label *subj)
52412 +{
52413 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
52414 + struct acl_object_label *match;
52415 +
52416 + match = subj->obj_hash[index];
52417 +
52418 + while (match && (match->inode != ino || match->device != dev ||
52419 + (match->mode & GR_DELETED))) {
52420 + match = match->next;
52421 + }
52422 +
52423 + if (match && !(match->mode & GR_DELETED))
52424 + return match;
52425 + else
52426 + return NULL;
52427 +}
52428 +
52429 +static struct acl_object_label *
52430 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
52431 + const struct acl_subject_label *subj)
52432 +{
52433 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
52434 + struct acl_object_label *match;
52435 +
52436 + match = subj->obj_hash[index];
52437 +
52438 + while (match && (match->inode != ino || match->device != dev ||
52439 + !(match->mode & GR_DELETED))) {
52440 + match = match->next;
52441 + }
52442 +
52443 + if (match && (match->mode & GR_DELETED))
52444 + return match;
52445 +
52446 + match = subj->obj_hash[index];
52447 +
52448 + while (match && (match->inode != ino || match->device != dev ||
52449 + (match->mode & GR_DELETED))) {
52450 + match = match->next;
52451 + }
52452 +
52453 + if (match && !(match->mode & GR_DELETED))
52454 + return match;
52455 + else
52456 + return NULL;
52457 +}
52458 +
52459 +static struct name_entry *
52460 +lookup_name_entry(const char *name)
52461 +{
52462 + unsigned int len = strlen(name);
52463 + unsigned int key = full_name_hash(name, len);
52464 + unsigned int index = key % name_set.n_size;
52465 + struct name_entry *match;
52466 +
52467 + match = name_set.n_hash[index];
52468 +
52469 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
52470 + match = match->next;
52471 +
52472 + return match;
52473 +}
52474 +
52475 +static struct name_entry *
52476 +lookup_name_entry_create(const char *name)
52477 +{
52478 + unsigned int len = strlen(name);
52479 + unsigned int key = full_name_hash(name, len);
52480 + unsigned int index = key % name_set.n_size;
52481 + struct name_entry *match;
52482 +
52483 + match = name_set.n_hash[index];
52484 +
52485 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
52486 + !match->deleted))
52487 + match = match->next;
52488 +
52489 + if (match && match->deleted)
52490 + return match;
52491 +
52492 + match = name_set.n_hash[index];
52493 +
52494 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
52495 + match->deleted))
52496 + match = match->next;
52497 +
52498 + if (match && !match->deleted)
52499 + return match;
52500 + else
52501 + return NULL;
52502 +}
52503 +
52504 +static struct inodev_entry *
52505 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
52506 +{
52507 + unsigned int index = fhash(ino, dev, inodev_set.i_size);
52508 + struct inodev_entry *match;
52509 +
52510 + match = inodev_set.i_hash[index];
52511 +
52512 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
52513 + match = match->next;
52514 +
52515 + return match;
52516 +}
52517 +
52518 +static void
52519 +insert_inodev_entry(struct inodev_entry *entry)
52520 +{
52521 + unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
52522 + inodev_set.i_size);
52523 + struct inodev_entry **curr;
52524 +
52525 + entry->prev = NULL;
52526 +
52527 + curr = &inodev_set.i_hash[index];
52528 + if (*curr != NULL)
52529 + (*curr)->prev = entry;
52530 +
52531 + entry->next = *curr;
52532 + *curr = entry;
52533 +
52534 + return;
52535 +}
52536 +
52537 +static void
52538 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
52539 +{
52540 + unsigned int index =
52541 + rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
52542 + struct acl_role_label **curr;
52543 + struct acl_role_label *tmp, *tmp2;
52544 +
52545 + curr = &acl_role_set.r_hash[index];
52546 +
52547 + /* simple case, slot is empty, just set it to our role */
52548 + if (*curr == NULL) {
52549 + *curr = role;
52550 + } else {
52551 + /* example:
52552 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
52553 + 2 -> 3
52554 + */
52555 + /* first check to see if we can already be reached via this slot */
52556 + tmp = *curr;
52557 + while (tmp && tmp != role)
52558 + tmp = tmp->next;
52559 + if (tmp == role) {
52560 + /* we don't need to add ourselves to this slot's chain */
52561 + return;
52562 + }
52563 + /* we need to add ourselves to this chain, two cases */
52564 + if (role->next == NULL) {
52565 + /* simple case, append the current chain to our role */
52566 + role->next = *curr;
52567 + *curr = role;
52568 + } else {
52569 + /* 1 -> 2 -> 3 -> 4
52570 + 2 -> 3 -> 4
52571 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
52572 + */
52573 + /* trickier case: walk our role's chain until we find
52574 + the role for the start of the current slot's chain */
52575 + tmp = role;
52576 + tmp2 = *curr;
52577 + while (tmp->next && tmp->next != tmp2)
52578 + tmp = tmp->next;
52579 + if (tmp->next == tmp2) {
52580 + /* from example above, we found 3, so just
52581 + replace this slot's chain with ours */
52582 + *curr = role;
52583 + } else {
52584 + /* we didn't find a subset of our role's chain
52585 + in the current slot's chain, so append their
52586 + chain to ours, and set us as the first role in
52587 + the slot's chain
52588 +
52589 + we could fold this case with the case above,
52590 + but making it explicit for clarity
52591 + */
52592 + tmp->next = tmp2;
52593 + *curr = role;
52594 + }
52595 + }
52596 + }
52597 +
52598 + return;
52599 +}
52600 +
52601 +static void
52602 +insert_acl_role_label(struct acl_role_label *role)
52603 +{
52604 + int i;
52605 +
52606 + if (role_list == NULL) {
52607 + role_list = role;
52608 + role->prev = NULL;
52609 + } else {
52610 + role->prev = role_list;
52611 + role_list = role;
52612 + }
52613 +
52614 + /* used for hash chains */
52615 + role->next = NULL;
52616 +
52617 + if (role->roletype & GR_ROLE_DOMAIN) {
52618 + for (i = 0; i < role->domain_child_num; i++)
52619 + __insert_acl_role_label(role, role->domain_children[i]);
52620 + } else
52621 + __insert_acl_role_label(role, role->uidgid);
52622 +}
52623 +
52624 +static int
52625 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
52626 +{
52627 + struct name_entry **curr, *nentry;
52628 + struct inodev_entry *ientry;
52629 + unsigned int len = strlen(name);
52630 + unsigned int key = full_name_hash(name, len);
52631 + unsigned int index = key % name_set.n_size;
52632 +
52633 + curr = &name_set.n_hash[index];
52634 +
52635 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
52636 + curr = &((*curr)->next);
52637 +
52638 + if (*curr != NULL)
52639 + return 1;
52640 +
52641 + nentry = acl_alloc(sizeof (struct name_entry));
52642 + if (nentry == NULL)
52643 + return 0;
52644 + ientry = acl_alloc(sizeof (struct inodev_entry));
52645 + if (ientry == NULL)
52646 + return 0;
52647 + ientry->nentry = nentry;
52648 +
52649 + nentry->key = key;
52650 + nentry->name = name;
52651 + nentry->inode = inode;
52652 + nentry->device = device;
52653 + nentry->len = len;
52654 + nentry->deleted = deleted;
52655 +
52656 + nentry->prev = NULL;
52657 + curr = &name_set.n_hash[index];
52658 + if (*curr != NULL)
52659 + (*curr)->prev = nentry;
52660 + nentry->next = *curr;
52661 + *curr = nentry;
52662 +
52663 + /* insert us into the table searchable by inode/dev */
52664 + insert_inodev_entry(ientry);
52665 +
52666 + return 1;
52667 +}
52668 +
52669 +static void
52670 +insert_acl_obj_label(struct acl_object_label *obj,
52671 + struct acl_subject_label *subj)
52672 +{
52673 + unsigned int index =
52674 + fhash(obj->inode, obj->device, subj->obj_hash_size);
52675 + struct acl_object_label **curr;
52676 +
52677 +
52678 + obj->prev = NULL;
52679 +
52680 + curr = &subj->obj_hash[index];
52681 + if (*curr != NULL)
52682 + (*curr)->prev = obj;
52683 +
52684 + obj->next = *curr;
52685 + *curr = obj;
52686 +
52687 + return;
52688 +}
52689 +
52690 +static void
52691 +insert_acl_subj_label(struct acl_subject_label *obj,
52692 + struct acl_role_label *role)
52693 +{
52694 + unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
52695 + struct acl_subject_label **curr;
52696 +
52697 + obj->prev = NULL;
52698 +
52699 + curr = &role->subj_hash[index];
52700 + if (*curr != NULL)
52701 + (*curr)->prev = obj;
52702 +
52703 + obj->next = *curr;
52704 + *curr = obj;
52705 +
52706 + return;
52707 +}
52708 +
52709 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
52710 +
52711 +static void *
52712 +create_table(__u32 * len, int elementsize)
52713 +{
52714 + unsigned int table_sizes[] = {
52715 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
52716 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
52717 + 4194301, 8388593, 16777213, 33554393, 67108859
52718 + };
52719 + void *newtable = NULL;
52720 + unsigned int pwr = 0;
52721 +
52722 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
52723 + table_sizes[pwr] <= *len)
52724 + pwr++;
52725 +
52726 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
52727 + return newtable;
52728 +
52729 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
52730 + newtable =
52731 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
52732 + else
52733 + newtable = vmalloc(table_sizes[pwr] * elementsize);
52734 +
52735 + *len = table_sizes[pwr];
52736 +
52737 + return newtable;
52738 +}
52739 +
52740 +static int
52741 +init_variables(const struct gr_arg *arg)
52742 +{
52743 + struct task_struct *reaper = init_pid_ns.child_reaper;
52744 + unsigned int stacksize;
52745 +
52746 + subj_map_set.s_size = arg->role_db.num_subjects;
52747 + acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
52748 + name_set.n_size = arg->role_db.num_objects;
52749 + inodev_set.i_size = arg->role_db.num_objects;
52750 +
52751 + if (!subj_map_set.s_size || !acl_role_set.r_size ||
52752 + !name_set.n_size || !inodev_set.i_size)
52753 + return 1;
52754 +
52755 + if (!gr_init_uidset())
52756 + return 1;
52757 +
52758 + /* set up the stack that holds allocation info */
52759 +
52760 + stacksize = arg->role_db.num_pointers + 5;
52761 +
52762 + if (!acl_alloc_stack_init(stacksize))
52763 + return 1;
52764 +
52765 + /* grab reference for the real root dentry and vfsmount */
52766 + get_fs_root(reaper->fs, &real_root);
52767 +
52768 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52769 + printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
52770 +#endif
52771 +
52772 + fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
52773 + if (fakefs_obj_rw == NULL)
52774 + return 1;
52775 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
52776 +
52777 + fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
52778 + if (fakefs_obj_rwx == NULL)
52779 + return 1;
52780 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
52781 +
52782 + subj_map_set.s_hash =
52783 + (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
52784 + acl_role_set.r_hash =
52785 + (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
52786 + name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
52787 + inodev_set.i_hash =
52788 + (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
52789 +
52790 + if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
52791 + !name_set.n_hash || !inodev_set.i_hash)
52792 + return 1;
52793 +
52794 + memset(subj_map_set.s_hash, 0,
52795 + sizeof(struct subject_map *) * subj_map_set.s_size);
52796 + memset(acl_role_set.r_hash, 0,
52797 + sizeof (struct acl_role_label *) * acl_role_set.r_size);
52798 + memset(name_set.n_hash, 0,
52799 + sizeof (struct name_entry *) * name_set.n_size);
52800 + memset(inodev_set.i_hash, 0,
52801 + sizeof (struct inodev_entry *) * inodev_set.i_size);
52802 +
52803 + return 0;
52804 +}
52805 +
52806 +/* free information not needed after startup
52807 + currently contains user->kernel pointer mappings for subjects
52808 +*/
52809 +
52810 +static void
52811 +free_init_variables(void)
52812 +{
52813 + __u32 i;
52814 +
52815 + if (subj_map_set.s_hash) {
52816 + for (i = 0; i < subj_map_set.s_size; i++) {
52817 + if (subj_map_set.s_hash[i]) {
52818 + kfree(subj_map_set.s_hash[i]);
52819 + subj_map_set.s_hash[i] = NULL;
52820 + }
52821 + }
52822 +
52823 + if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
52824 + PAGE_SIZE)
52825 + kfree(subj_map_set.s_hash);
52826 + else
52827 + vfree(subj_map_set.s_hash);
52828 + }
52829 +
52830 + return;
52831 +}
52832 +
52833 +static void
52834 +free_variables(void)
52835 +{
52836 + struct acl_subject_label *s;
52837 + struct acl_role_label *r;
52838 + struct task_struct *task, *task2;
52839 + unsigned int x;
52840 +
52841 + gr_clear_learn_entries();
52842 +
52843 + read_lock(&tasklist_lock);
52844 + do_each_thread(task2, task) {
52845 + task->acl_sp_role = 0;
52846 + task->acl_role_id = 0;
52847 + task->acl = NULL;
52848 + task->role = NULL;
52849 + } while_each_thread(task2, task);
52850 + read_unlock(&tasklist_lock);
52851 +
52852 + /* release the reference to the real root dentry and vfsmount */
52853 + path_put(&real_root);
52854 + memset(&real_root, 0, sizeof(real_root));
52855 +
52856 + /* free all object hash tables */
52857 +
52858 + FOR_EACH_ROLE_START(r)
52859 + if (r->subj_hash == NULL)
52860 + goto next_role;
52861 + FOR_EACH_SUBJECT_START(r, s, x)
52862 + if (s->obj_hash == NULL)
52863 + break;
52864 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
52865 + kfree(s->obj_hash);
52866 + else
52867 + vfree(s->obj_hash);
52868 + FOR_EACH_SUBJECT_END(s, x)
52869 + FOR_EACH_NESTED_SUBJECT_START(r, s)
52870 + if (s->obj_hash == NULL)
52871 + break;
52872 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
52873 + kfree(s->obj_hash);
52874 + else
52875 + vfree(s->obj_hash);
52876 + FOR_EACH_NESTED_SUBJECT_END(s)
52877 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
52878 + kfree(r->subj_hash);
52879 + else
52880 + vfree(r->subj_hash);
52881 + r->subj_hash = NULL;
52882 +next_role:
52883 + FOR_EACH_ROLE_END(r)
52884 +
52885 + acl_free_all();
52886 +
52887 + if (acl_role_set.r_hash) {
52888 + if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
52889 + PAGE_SIZE)
52890 + kfree(acl_role_set.r_hash);
52891 + else
52892 + vfree(acl_role_set.r_hash);
52893 + }
52894 + if (name_set.n_hash) {
52895 + if ((name_set.n_size * sizeof (struct name_entry *)) <=
52896 + PAGE_SIZE)
52897 + kfree(name_set.n_hash);
52898 + else
52899 + vfree(name_set.n_hash);
52900 + }
52901 +
52902 + if (inodev_set.i_hash) {
52903 + if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
52904 + PAGE_SIZE)
52905 + kfree(inodev_set.i_hash);
52906 + else
52907 + vfree(inodev_set.i_hash);
52908 + }
52909 +
52910 + gr_free_uidset();
52911 +
52912 + memset(&name_set, 0, sizeof (struct name_db));
52913 + memset(&inodev_set, 0, sizeof (struct inodev_db));
52914 + memset(&acl_role_set, 0, sizeof (struct acl_role_db));
52915 + memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
52916 +
52917 + default_role = NULL;
52918 + kernel_role = NULL;
52919 + role_list = NULL;
52920 +
52921 + return;
52922 +}
52923 +
52924 +static __u32
52925 +count_user_objs(struct acl_object_label *userp)
52926 +{
52927 + struct acl_object_label o_tmp;
52928 + __u32 num = 0;
52929 +
52930 + while (userp) {
52931 + if (copy_from_user(&o_tmp, userp,
52932 + sizeof (struct acl_object_label)))
52933 + break;
52934 +
52935 + userp = o_tmp.prev;
52936 + num++;
52937 + }
52938 +
52939 + return num;
52940 +}
52941 +
52942 +static struct acl_subject_label *
52943 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
52944 +
52945 +static int
52946 +copy_user_glob(struct acl_object_label *obj)
52947 +{
52948 + struct acl_object_label *g_tmp, **guser;
52949 + unsigned int len;
52950 + char *tmp;
52951 +
52952 + if (obj->globbed == NULL)
52953 + return 0;
52954 +
52955 + guser = &obj->globbed;
52956 + while (*guser) {
52957 + g_tmp = (struct acl_object_label *)
52958 + acl_alloc(sizeof (struct acl_object_label));
52959 + if (g_tmp == NULL)
52960 + return -ENOMEM;
52961 +
52962 + if (copy_from_user(g_tmp, *guser,
52963 + sizeof (struct acl_object_label)))
52964 + return -EFAULT;
52965 +
52966 + len = strnlen_user(g_tmp->filename, PATH_MAX);
52967 +
52968 + if (!len || len >= PATH_MAX)
52969 + return -EINVAL;
52970 +
52971 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52972 + return -ENOMEM;
52973 +
52974 + if (copy_from_user(tmp, g_tmp->filename, len))
52975 + return -EFAULT;
52976 + tmp[len-1] = '\0';
52977 + g_tmp->filename = tmp;
52978 +
52979 + *guser = g_tmp;
52980 + guser = &(g_tmp->next);
52981 + }
52982 +
52983 + return 0;
52984 +}
52985 +
52986 +static int
52987 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
52988 + struct acl_role_label *role)
52989 +{
52990 + struct acl_object_label *o_tmp;
52991 + unsigned int len;
52992 + int ret;
52993 + char *tmp;
52994 +
52995 + while (userp) {
52996 + if ((o_tmp = (struct acl_object_label *)
52997 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
52998 + return -ENOMEM;
52999 +
53000 + if (copy_from_user(o_tmp, userp,
53001 + sizeof (struct acl_object_label)))
53002 + return -EFAULT;
53003 +
53004 + userp = o_tmp->prev;
53005 +
53006 + len = strnlen_user(o_tmp->filename, PATH_MAX);
53007 +
53008 + if (!len || len >= PATH_MAX)
53009 + return -EINVAL;
53010 +
53011 + if ((tmp = (char *) acl_alloc(len)) == NULL)
53012 + return -ENOMEM;
53013 +
53014 + if (copy_from_user(tmp, o_tmp->filename, len))
53015 + return -EFAULT;
53016 + tmp[len-1] = '\0';
53017 + o_tmp->filename = tmp;
53018 +
53019 + insert_acl_obj_label(o_tmp, subj);
53020 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
53021 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
53022 + return -ENOMEM;
53023 +
53024 + ret = copy_user_glob(o_tmp);
53025 + if (ret)
53026 + return ret;
53027 +
53028 + if (o_tmp->nested) {
53029 + int already_copied;
53030 +
53031 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
53032 + if (IS_ERR(o_tmp->nested))
53033 + return PTR_ERR(o_tmp->nested);
53034 +
53035 + /* insert into nested subject list if we haven't copied this one yet
53036 + to prevent duplicate entries */
53037 + if (!already_copied) {
53038 + o_tmp->nested->next = role->hash->first;
53039 + role->hash->first = o_tmp->nested;
53040 + }
53041 + }
53042 + }
53043 +
53044 + return 0;
53045 +}
53046 +
53047 +static __u32
53048 +count_user_subjs(struct acl_subject_label *userp)
53049 +{
53050 + struct acl_subject_label s_tmp;
53051 + __u32 num = 0;
53052 +
53053 + while (userp) {
53054 + if (copy_from_user(&s_tmp, userp,
53055 + sizeof (struct acl_subject_label)))
53056 + break;
53057 +
53058 + userp = s_tmp.prev;
53059 + /* do not count nested subjects against this count, since
53060 + they are not included in the hash table, but are
53061 + attached to objects. We have already counted
53062 + the subjects in userspace for the allocation
53063 + stack
53064 + */
53065 + if (!(s_tmp.mode & GR_NESTED))
53066 + num++;
53067 + }
53068 +
53069 + return num;
53070 +}
53071 +
53072 +static int
53073 +copy_user_allowedips(struct acl_role_label *rolep)
53074 +{
53075 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
53076 +
53077 + ruserip = rolep->allowed_ips;
53078 +
53079 + while (ruserip) {
53080 + rlast = rtmp;
53081 +
53082 + if ((rtmp = (struct role_allowed_ip *)
53083 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
53084 + return -ENOMEM;
53085 +
53086 + if (copy_from_user(rtmp, ruserip,
53087 + sizeof (struct role_allowed_ip)))
53088 + return -EFAULT;
53089 +
53090 + ruserip = rtmp->prev;
53091 +
53092 + if (!rlast) {
53093 + rtmp->prev = NULL;
53094 + rolep->allowed_ips = rtmp;
53095 + } else {
53096 + rlast->next = rtmp;
53097 + rtmp->prev = rlast;
53098 + }
53099 +
53100 + if (!ruserip)
53101 + rtmp->next = NULL;
53102 + }
53103 +
53104 + return 0;
53105 +}
53106 +
53107 +static int
53108 +copy_user_transitions(struct acl_role_label *rolep)
53109 +{
53110 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
53111 +
53112 + unsigned int len;
53113 + char *tmp;
53114 +
53115 + rusertp = rolep->transitions;
53116 +
53117 + while (rusertp) {
53118 + rlast = rtmp;
53119 +
53120 + if ((rtmp = (struct role_transition *)
53121 + acl_alloc(sizeof (struct role_transition))) == NULL)
53122 + return -ENOMEM;
53123 +
53124 + if (copy_from_user(rtmp, rusertp,
53125 + sizeof (struct role_transition)))
53126 + return -EFAULT;
53127 +
53128 + rusertp = rtmp->prev;
53129 +
53130 + len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
53131 +
53132 + if (!len || len >= GR_SPROLE_LEN)
53133 + return -EINVAL;
53134 +
53135 + if ((tmp = (char *) acl_alloc(len)) == NULL)
53136 + return -ENOMEM;
53137 +
53138 + if (copy_from_user(tmp, rtmp->rolename, len))
53139 + return -EFAULT;
53140 + tmp[len-1] = '\0';
53141 + rtmp->rolename = tmp;
53142 +
53143 + if (!rlast) {
53144 + rtmp->prev = NULL;
53145 + rolep->transitions = rtmp;
53146 + } else {
53147 + rlast->next = rtmp;
53148 + rtmp->prev = rlast;
53149 + }
53150 +
53151 + if (!rusertp)
53152 + rtmp->next = NULL;
53153 + }
53154 +
53155 + return 0;
53156 +}
53157 +
53158 +static struct acl_subject_label *
53159 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
53160 +{
53161 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
53162 + unsigned int len;
53163 + char *tmp;
53164 + __u32 num_objs;
53165 + struct acl_ip_label **i_tmp, *i_utmp2;
53166 + struct gr_hash_struct ghash;
53167 + struct subject_map *subjmap;
53168 + unsigned int i_num;
53169 + int err;
53170 +
53171 + if (already_copied != NULL)
53172 + *already_copied = 0;
53173 +
53174 + s_tmp = lookup_subject_map(userp);
53175 +
53176 + /* we've already copied this subject into the kernel, just return
53177 + the reference to it, and don't copy it over again
53178 + */
53179 + if (s_tmp) {
53180 + if (already_copied != NULL)
53181 + *already_copied = 1;
53182 + return(s_tmp);
53183 + }
53184 +
53185 + if ((s_tmp = (struct acl_subject_label *)
53186 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
53187 + return ERR_PTR(-ENOMEM);
53188 +
53189 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
53190 + if (subjmap == NULL)
53191 + return ERR_PTR(-ENOMEM);
53192 +
53193 + subjmap->user = userp;
53194 + subjmap->kernel = s_tmp;
53195 + insert_subj_map_entry(subjmap);
53196 +
53197 + if (copy_from_user(s_tmp, userp,
53198 + sizeof (struct acl_subject_label)))
53199 + return ERR_PTR(-EFAULT);
53200 +
53201 + len = strnlen_user(s_tmp->filename, PATH_MAX);
53202 +
53203 + if (!len || len >= PATH_MAX)
53204 + return ERR_PTR(-EINVAL);
53205 +
53206 + if ((tmp = (char *) acl_alloc(len)) == NULL)
53207 + return ERR_PTR(-ENOMEM);
53208 +
53209 + if (copy_from_user(tmp, s_tmp->filename, len))
53210 + return ERR_PTR(-EFAULT);
53211 + tmp[len-1] = '\0';
53212 + s_tmp->filename = tmp;
53213 +
53214 + if (!strcmp(s_tmp->filename, "/"))
53215 + role->root_label = s_tmp;
53216 +
53217 + if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
53218 + return ERR_PTR(-EFAULT);
53219 +
53220 + /* copy user and group transition tables */
53221 +
53222 + if (s_tmp->user_trans_num) {
53223 + uid_t *uidlist;
53224 +
53225 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
53226 + if (uidlist == NULL)
53227 + return ERR_PTR(-ENOMEM);
53228 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
53229 + return ERR_PTR(-EFAULT);
53230 +
53231 + s_tmp->user_transitions = uidlist;
53232 + }
53233 +
53234 + if (s_tmp->group_trans_num) {
53235 + gid_t *gidlist;
53236 +
53237 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
53238 + if (gidlist == NULL)
53239 + return ERR_PTR(-ENOMEM);
53240 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
53241 + return ERR_PTR(-EFAULT);
53242 +
53243 + s_tmp->group_transitions = gidlist;
53244 + }
53245 +
53246 + /* set up object hash table */
53247 + num_objs = count_user_objs(ghash.first);
53248 +
53249 + s_tmp->obj_hash_size = num_objs;
53250 + s_tmp->obj_hash =
53251 + (struct acl_object_label **)
53252 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
53253 +
53254 + if (!s_tmp->obj_hash)
53255 + return ERR_PTR(-ENOMEM);
53256 +
53257 + memset(s_tmp->obj_hash, 0,
53258 + s_tmp->obj_hash_size *
53259 + sizeof (struct acl_object_label *));
53260 +
53261 + /* add in objects */
53262 + err = copy_user_objs(ghash.first, s_tmp, role);
53263 +
53264 + if (err)
53265 + return ERR_PTR(err);
53266 +
53267 + /* set pointer for parent subject */
53268 + if (s_tmp->parent_subject) {
53269 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
53270 +
53271 + if (IS_ERR(s_tmp2))
53272 + return s_tmp2;
53273 +
53274 + s_tmp->parent_subject = s_tmp2;
53275 + }
53276 +
53277 + /* add in ip acls */
53278 +
53279 + if (!s_tmp->ip_num) {
53280 + s_tmp->ips = NULL;
53281 + goto insert;
53282 + }
53283 +
53284 + i_tmp =
53285 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
53286 + sizeof (struct acl_ip_label *));
53287 +
53288 + if (!i_tmp)
53289 + return ERR_PTR(-ENOMEM);
53290 +
53291 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
53292 + *(i_tmp + i_num) =
53293 + (struct acl_ip_label *)
53294 + acl_alloc(sizeof (struct acl_ip_label));
53295 + if (!*(i_tmp + i_num))
53296 + return ERR_PTR(-ENOMEM);
53297 +
53298 + if (copy_from_user
53299 + (&i_utmp2, s_tmp->ips + i_num,
53300 + sizeof (struct acl_ip_label *)))
53301 + return ERR_PTR(-EFAULT);
53302 +
53303 + if (copy_from_user
53304 + (*(i_tmp + i_num), i_utmp2,
53305 + sizeof (struct acl_ip_label)))
53306 + return ERR_PTR(-EFAULT);
53307 +
53308 + if ((*(i_tmp + i_num))->iface == NULL)
53309 + continue;
53310 +
53311 + len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
53312 + if (!len || len >= IFNAMSIZ)
53313 + return ERR_PTR(-EINVAL);
53314 + tmp = acl_alloc(len);
53315 + if (tmp == NULL)
53316 + return ERR_PTR(-ENOMEM);
53317 + if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
53318 + return ERR_PTR(-EFAULT);
53319 + (*(i_tmp + i_num))->iface = tmp;
53320 + }
53321 +
53322 + s_tmp->ips = i_tmp;
53323 +
53324 +insert:
53325 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
53326 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
53327 + return ERR_PTR(-ENOMEM);
53328 +
53329 + return s_tmp;
53330 +}
53331 +
53332 +static int
53333 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
53334 +{
53335 + struct acl_subject_label s_pre;
53336 + struct acl_subject_label * ret;
53337 + int err;
53338 +
53339 + while (userp) {
53340 + if (copy_from_user(&s_pre, userp,
53341 + sizeof (struct acl_subject_label)))
53342 + return -EFAULT;
53343 +
53344 + /* do not add nested subjects here, add
53345 + while parsing objects
53346 + */
53347 +
53348 + if (s_pre.mode & GR_NESTED) {
53349 + userp = s_pre.prev;
53350 + continue;
53351 + }
53352 +
53353 + ret = do_copy_user_subj(userp, role, NULL);
53354 +
53355 + err = PTR_ERR(ret);
53356 + if (IS_ERR(ret))
53357 + return err;
53358 +
53359 + insert_acl_subj_label(ret, role);
53360 +
53361 + userp = s_pre.prev;
53362 + }
53363 +
53364 + return 0;
53365 +}
53366 +
53367 +static int
53368 +copy_user_acl(struct gr_arg *arg)
53369 +{
53370 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
53371 + struct acl_subject_label *subj_list;
53372 + struct sprole_pw *sptmp;
53373 + struct gr_hash_struct *ghash;
53374 + uid_t *domainlist;
53375 + unsigned int r_num;
53376 + unsigned int len;
53377 + char *tmp;
53378 + int err = 0;
53379 + __u16 i;
53380 + __u32 num_subjs;
53381 +
53382 + /* we need a default and kernel role */
53383 + if (arg->role_db.num_roles < 2)
53384 + return -EINVAL;
53385 +
53386 + /* copy special role authentication info from userspace */
53387 +
53388 + num_sprole_pws = arg->num_sprole_pws;
53389 + acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
53390 +
53391 + if (!acl_special_roles && num_sprole_pws)
53392 + return -ENOMEM;
53393 +
53394 + for (i = 0; i < num_sprole_pws; i++) {
53395 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
53396 + if (!sptmp)
53397 + return -ENOMEM;
53398 + if (copy_from_user(sptmp, arg->sprole_pws + i,
53399 + sizeof (struct sprole_pw)))
53400 + return -EFAULT;
53401 +
53402 + len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
53403 +
53404 + if (!len || len >= GR_SPROLE_LEN)
53405 + return -EINVAL;
53406 +
53407 + if ((tmp = (char *) acl_alloc(len)) == NULL)
53408 + return -ENOMEM;
53409 +
53410 + if (copy_from_user(tmp, sptmp->rolename, len))
53411 + return -EFAULT;
53412 +
53413 + tmp[len-1] = '\0';
53414 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53415 + printk(KERN_ALERT "Copying special role %s\n", tmp);
53416 +#endif
53417 + sptmp->rolename = tmp;
53418 + acl_special_roles[i] = sptmp;
53419 + }
53420 +
53421 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
53422 +
53423 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
53424 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
53425 +
53426 + if (!r_tmp)
53427 + return -ENOMEM;
53428 +
53429 + if (copy_from_user(&r_utmp2, r_utmp + r_num,
53430 + sizeof (struct acl_role_label *)))
53431 + return -EFAULT;
53432 +
53433 + if (copy_from_user(r_tmp, r_utmp2,
53434 + sizeof (struct acl_role_label)))
53435 + return -EFAULT;
53436 +
53437 + len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
53438 +
53439 + if (!len || len >= PATH_MAX)
53440 + return -EINVAL;
53441 +
53442 + if ((tmp = (char *) acl_alloc(len)) == NULL)
53443 + return -ENOMEM;
53444 +
53445 + if (copy_from_user(tmp, r_tmp->rolename, len))
53446 + return -EFAULT;
53447 +
53448 + tmp[len-1] = '\0';
53449 + r_tmp->rolename = tmp;
53450 +
53451 + if (!strcmp(r_tmp->rolename, "default")
53452 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
53453 + default_role = r_tmp;
53454 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
53455 + kernel_role = r_tmp;
53456 + }
53457 +
53458 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
53459 + return -ENOMEM;
53460 +
53461 + if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
53462 + return -EFAULT;
53463 +
53464 + r_tmp->hash = ghash;
53465 +
53466 + num_subjs = count_user_subjs(r_tmp->hash->first);
53467 +
53468 + r_tmp->subj_hash_size = num_subjs;
53469 + r_tmp->subj_hash =
53470 + (struct acl_subject_label **)
53471 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
53472 +
53473 + if (!r_tmp->subj_hash)
53474 + return -ENOMEM;
53475 +
53476 + err = copy_user_allowedips(r_tmp);
53477 + if (err)
53478 + return err;
53479 +
53480 + /* copy domain info */
53481 + if (r_tmp->domain_children != NULL) {
53482 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
53483 + if (domainlist == NULL)
53484 + return -ENOMEM;
53485 +
53486 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
53487 + return -EFAULT;
53488 +
53489 + r_tmp->domain_children = domainlist;
53490 + }
53491 +
53492 + err = copy_user_transitions(r_tmp);
53493 + if (err)
53494 + return err;
53495 +
53496 + memset(r_tmp->subj_hash, 0,
53497 + r_tmp->subj_hash_size *
53498 + sizeof (struct acl_subject_label *));
53499 +
53500 + /* acquire the list of subjects, then NULL out
53501 + the list prior to parsing the subjects for this role,
53502 + as during this parsing the list is replaced with a list
53503 + of *nested* subjects for the role
53504 + */
53505 + subj_list = r_tmp->hash->first;
53506 +
53507 + /* set nested subject list to null */
53508 + r_tmp->hash->first = NULL;
53509 +
53510 + err = copy_user_subjs(subj_list, r_tmp);
53511 +
53512 + if (err)
53513 + return err;
53514 +
53515 + insert_acl_role_label(r_tmp);
53516 + }
53517 +
53518 + if (default_role == NULL || kernel_role == NULL)
53519 + return -EINVAL;
53520 +
53521 + return err;
53522 +}
53523 +
53524 +static int
53525 +gracl_init(struct gr_arg *args)
53526 +{
53527 + int error = 0;
53528 +
53529 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
53530 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
53531 +
53532 + if (init_variables(args)) {
53533 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
53534 + error = -ENOMEM;
53535 + free_variables();
53536 + goto out;
53537 + }
53538 +
53539 + error = copy_user_acl(args);
53540 + free_init_variables();
53541 + if (error) {
53542 + free_variables();
53543 + goto out;
53544 + }
53545 +
53546 + if ((error = gr_set_acls(0))) {
53547 + free_variables();
53548 + goto out;
53549 + }
53550 +
53551 + pax_open_kernel();
53552 + gr_status |= GR_READY;
53553 + pax_close_kernel();
53554 +
53555 + out:
53556 + return error;
53557 +}
53558 +
53559 +/* derived from glibc fnmatch() 0: match, 1: no match*/
53560 +
53561 +static int
53562 +glob_match(const char *p, const char *n)
53563 +{
53564 + char c;
53565 +
53566 + while ((c = *p++) != '\0') {
53567 + switch (c) {
53568 + case '?':
53569 + if (*n == '\0')
53570 + return 1;
53571 + else if (*n == '/')
53572 + return 1;
53573 + break;
53574 + case '\\':
53575 + if (*n != c)
53576 + return 1;
53577 + break;
53578 + case '*':
53579 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
53580 + if (*n == '/')
53581 + return 1;
53582 + else if (c == '?') {
53583 + if (*n == '\0')
53584 + return 1;
53585 + else
53586 + ++n;
53587 + }
53588 + }
53589 + if (c == '\0') {
53590 + return 0;
53591 + } else {
53592 + const char *endp;
53593 +
53594 + if ((endp = strchr(n, '/')) == NULL)
53595 + endp = n + strlen(n);
53596 +
53597 + if (c == '[') {
53598 + for (--p; n < endp; ++n)
53599 + if (!glob_match(p, n))
53600 + return 0;
53601 + } else if (c == '/') {
53602 + while (*n != '\0' && *n != '/')
53603 + ++n;
53604 + if (*n == '/' && !glob_match(p, n + 1))
53605 + return 0;
53606 + } else {
53607 + for (--p; n < endp; ++n)
53608 + if (*n == c && !glob_match(p, n))
53609 + return 0;
53610 + }
53611 +
53612 + return 1;
53613 + }
53614 + case '[':
53615 + {
53616 + int not;
53617 + char cold;
53618 +
53619 + if (*n == '\0' || *n == '/')
53620 + return 1;
53621 +
53622 + not = (*p == '!' || *p == '^');
53623 + if (not)
53624 + ++p;
53625 +
53626 + c = *p++;
53627 + for (;;) {
53628 + unsigned char fn = (unsigned char)*n;
53629 +
53630 + if (c == '\0')
53631 + return 1;
53632 + else {
53633 + if (c == fn)
53634 + goto matched;
53635 + cold = c;
53636 + c = *p++;
53637 +
53638 + if (c == '-' && *p != ']') {
53639 + unsigned char cend = *p++;
53640 +
53641 + if (cend == '\0')
53642 + return 1;
53643 +
53644 + if (cold <= fn && fn <= cend)
53645 + goto matched;
53646 +
53647 + c = *p++;
53648 + }
53649 + }
53650 +
53651 + if (c == ']')
53652 + break;
53653 + }
53654 + if (!not)
53655 + return 1;
53656 + break;
53657 + matched:
53658 + while (c != ']') {
53659 + if (c == '\0')
53660 + return 1;
53661 +
53662 + c = *p++;
53663 + }
53664 + if (not)
53665 + return 1;
53666 + }
53667 + break;
53668 + default:
53669 + if (c != *n)
53670 + return 1;
53671 + }
53672 +
53673 + ++n;
53674 + }
53675 +
53676 + if (*n == '\0')
53677 + return 0;
53678 +
53679 + if (*n == '/')
53680 + return 0;
53681 +
53682 + return 1;
53683 +}
53684 +
53685 +static struct acl_object_label *
53686 +chk_glob_label(struct acl_object_label *globbed,
53687 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
53688 +{
53689 + struct acl_object_label *tmp;
53690 +
53691 + if (*path == NULL)
53692 + *path = gr_to_filename_nolock(dentry, mnt);
53693 +
53694 + tmp = globbed;
53695 +
53696 + while (tmp) {
53697 + if (!glob_match(tmp->filename, *path))
53698 + return tmp;
53699 + tmp = tmp->next;
53700 + }
53701 +
53702 + return NULL;
53703 +}
53704 +
53705 +static struct acl_object_label *
53706 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
53707 + const ino_t curr_ino, const dev_t curr_dev,
53708 + const struct acl_subject_label *subj, char **path, const int checkglob)
53709 +{
53710 + struct acl_subject_label *tmpsubj;
53711 + struct acl_object_label *retval;
53712 + struct acl_object_label *retval2;
53713 +
53714 + tmpsubj = (struct acl_subject_label *) subj;
53715 + read_lock(&gr_inode_lock);
53716 + do {
53717 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
53718 + if (retval) {
53719 + if (checkglob && retval->globbed) {
53720 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
53721 + if (retval2)
53722 + retval = retval2;
53723 + }
53724 + break;
53725 + }
53726 + } while ((tmpsubj = tmpsubj->parent_subject));
53727 + read_unlock(&gr_inode_lock);
53728 +
53729 + return retval;
53730 +}
53731 +
53732 +static __inline__ struct acl_object_label *
53733 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
53734 + struct dentry *curr_dentry,
53735 + const struct acl_subject_label *subj, char **path, const int checkglob)
53736 +{
53737 + int newglob = checkglob;
53738 + ino_t inode;
53739 + dev_t device;
53740 +
53741 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
53742 + as we don't want a / * rule to match instead of the / object
53743 + don't do this for create lookups that call this function though, since they're looking up
53744 + on the parent and thus need globbing checks on all paths
53745 + */
53746 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
53747 + newglob = GR_NO_GLOB;
53748 +
53749 + spin_lock(&curr_dentry->d_lock);
53750 + inode = curr_dentry->d_inode->i_ino;
53751 + device = __get_dev(curr_dentry);
53752 + spin_unlock(&curr_dentry->d_lock);
53753 +
53754 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
53755 +}
53756 +
53757 +static struct acl_object_label *
53758 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53759 + const struct acl_subject_label *subj, char *path, const int checkglob)
53760 +{
53761 + struct dentry *dentry = (struct dentry *) l_dentry;
53762 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
53763 + struct mount *real_mnt = real_mount(mnt);
53764 + struct acl_object_label *retval;
53765 + struct dentry *parent;
53766 +
53767 + write_seqlock(&rename_lock);
53768 + br_read_lock(&vfsmount_lock);
53769 +
53770 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
53771 +#ifdef CONFIG_NET
53772 + mnt == sock_mnt ||
53773 +#endif
53774 +#ifdef CONFIG_HUGETLBFS
53775 + (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
53776 +#endif
53777 + /* ignore Eric Biederman */
53778 + IS_PRIVATE(l_dentry->d_inode))) {
53779 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
53780 + goto out;
53781 + }
53782 +
53783 + for (;;) {
53784 + if (dentry == real_root.dentry && mnt == real_root.mnt)
53785 + break;
53786 +
53787 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
53788 + if (!mnt_has_parent(real_mnt))
53789 + break;
53790 +
53791 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53792 + if (retval != NULL)
53793 + goto out;
53794 +
53795 + dentry = real_mnt->mnt_mountpoint;
53796 + real_mnt = real_mnt->mnt_parent;
53797 + mnt = &real_mnt->mnt;
53798 + continue;
53799 + }
53800 +
53801 + parent = dentry->d_parent;
53802 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53803 + if (retval != NULL)
53804 + goto out;
53805 +
53806 + dentry = parent;
53807 + }
53808 +
53809 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53810 +
53811 + /* real_root is pinned so we don't have to hold a reference */
53812 + if (retval == NULL)
53813 + retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
53814 +out:
53815 + br_read_unlock(&vfsmount_lock);
53816 + write_sequnlock(&rename_lock);
53817 +
53818 + BUG_ON(retval == NULL);
53819 +
53820 + return retval;
53821 +}
53822 +
53823 +static __inline__ struct acl_object_label *
53824 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53825 + const struct acl_subject_label *subj)
53826 +{
53827 + char *path = NULL;
53828 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
53829 +}
53830 +
53831 +static __inline__ struct acl_object_label *
53832 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53833 + const struct acl_subject_label *subj)
53834 +{
53835 + char *path = NULL;
53836 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
53837 +}
53838 +
53839 +static __inline__ struct acl_object_label *
53840 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53841 + const struct acl_subject_label *subj, char *path)
53842 +{
53843 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
53844 +}
53845 +
53846 +static struct acl_subject_label *
53847 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53848 + const struct acl_role_label *role)
53849 +{
53850 + struct dentry *dentry = (struct dentry *) l_dentry;
53851 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
53852 + struct mount *real_mnt = real_mount(mnt);
53853 + struct acl_subject_label *retval;
53854 + struct dentry *parent;
53855 +
53856 + write_seqlock(&rename_lock);
53857 + br_read_lock(&vfsmount_lock);
53858 +
53859 + for (;;) {
53860 + if (dentry == real_root.dentry && mnt == real_root.mnt)
53861 + break;
53862 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
53863 + if (!mnt_has_parent(real_mnt))
53864 + break;
53865 +
53866 + spin_lock(&dentry->d_lock);
53867 + read_lock(&gr_inode_lock);
53868 + retval =
53869 + lookup_acl_subj_label(dentry->d_inode->i_ino,
53870 + __get_dev(dentry), role);
53871 + read_unlock(&gr_inode_lock);
53872 + spin_unlock(&dentry->d_lock);
53873 + if (retval != NULL)
53874 + goto out;
53875 +
53876 + dentry = real_mnt->mnt_mountpoint;
53877 + real_mnt = real_mnt->mnt_parent;
53878 + mnt = &real_mnt->mnt;
53879 + continue;
53880 + }
53881 +
53882 + spin_lock(&dentry->d_lock);
53883 + read_lock(&gr_inode_lock);
53884 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
53885 + __get_dev(dentry), role);
53886 + read_unlock(&gr_inode_lock);
53887 + parent = dentry->d_parent;
53888 + spin_unlock(&dentry->d_lock);
53889 +
53890 + if (retval != NULL)
53891 + goto out;
53892 +
53893 + dentry = parent;
53894 + }
53895 +
53896 + spin_lock(&dentry->d_lock);
53897 + read_lock(&gr_inode_lock);
53898 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
53899 + __get_dev(dentry), role);
53900 + read_unlock(&gr_inode_lock);
53901 + spin_unlock(&dentry->d_lock);
53902 +
53903 + if (unlikely(retval == NULL)) {
53904 + /* real_root is pinned, we don't need to hold a reference */
53905 + read_lock(&gr_inode_lock);
53906 + retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
53907 + __get_dev(real_root.dentry), role);
53908 + read_unlock(&gr_inode_lock);
53909 + }
53910 +out:
53911 + br_read_unlock(&vfsmount_lock);
53912 + write_sequnlock(&rename_lock);
53913 +
53914 + BUG_ON(retval == NULL);
53915 +
53916 + return retval;
53917 +}
53918 +
53919 +static void
53920 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
53921 +{
53922 + struct task_struct *task = current;
53923 + const struct cred *cred = current_cred();
53924 +
53925 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
53926 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53927 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53928 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
53929 +
53930 + return;
53931 +}
53932 +
53933 +static void
53934 +gr_log_learn_id_change(const char type, const unsigned int real,
53935 + const unsigned int effective, const unsigned int fs)
53936 +{
53937 + struct task_struct *task = current;
53938 + const struct cred *cred = current_cred();
53939 +
53940 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
53941 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53942 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53943 + type, real, effective, fs, &task->signal->saved_ip);
53944 +
53945 + return;
53946 +}
53947 +
53948 +__u32
53949 +gr_search_file(const struct dentry * dentry, const __u32 mode,
53950 + const struct vfsmount * mnt)
53951 +{
53952 + __u32 retval = mode;
53953 + struct acl_subject_label *curracl;
53954 + struct acl_object_label *currobj;
53955 +
53956 + if (unlikely(!(gr_status & GR_READY)))
53957 + return (mode & ~GR_AUDITS);
53958 +
53959 + curracl = current->acl;
53960 +
53961 + currobj = chk_obj_label(dentry, mnt, curracl);
53962 + retval = currobj->mode & mode;
53963 +
53964 + /* if we're opening a specified transfer file for writing
53965 + (e.g. /dev/initctl), then transfer our role to init
53966 + */
53967 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
53968 + current->role->roletype & GR_ROLE_PERSIST)) {
53969 + struct task_struct *task = init_pid_ns.child_reaper;
53970 +
53971 + if (task->role != current->role) {
53972 + task->acl_sp_role = 0;
53973 + task->acl_role_id = current->acl_role_id;
53974 + task->role = current->role;
53975 + rcu_read_lock();
53976 + read_lock(&grsec_exec_file_lock);
53977 + gr_apply_subject_to_task(task);
53978 + read_unlock(&grsec_exec_file_lock);
53979 + rcu_read_unlock();
53980 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
53981 + }
53982 + }
53983 +
53984 + if (unlikely
53985 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
53986 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
53987 + __u32 new_mode = mode;
53988 +
53989 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53990 +
53991 + retval = new_mode;
53992 +
53993 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
53994 + new_mode |= GR_INHERIT;
53995 +
53996 + if (!(mode & GR_NOLEARN))
53997 + gr_log_learn(dentry, mnt, new_mode);
53998 + }
53999 +
54000 + return retval;
54001 +}
54002 +
54003 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
54004 + const struct dentry *parent,
54005 + const struct vfsmount *mnt)
54006 +{
54007 + struct name_entry *match;
54008 + struct acl_object_label *matchpo;
54009 + struct acl_subject_label *curracl;
54010 + char *path;
54011 +
54012 + if (unlikely(!(gr_status & GR_READY)))
54013 + return NULL;
54014 +
54015 + preempt_disable();
54016 + path = gr_to_filename_rbac(new_dentry, mnt);
54017 + match = lookup_name_entry_create(path);
54018 +
54019 + curracl = current->acl;
54020 +
54021 + if (match) {
54022 + read_lock(&gr_inode_lock);
54023 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
54024 + read_unlock(&gr_inode_lock);
54025 +
54026 + if (matchpo) {
54027 + preempt_enable();
54028 + return matchpo;
54029 + }
54030 + }
54031 +
54032 + // lookup parent
54033 +
54034 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
54035 +
54036 + preempt_enable();
54037 + return matchpo;
54038 +}
54039 +
54040 +__u32
54041 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
54042 + const struct vfsmount * mnt, const __u32 mode)
54043 +{
54044 + struct acl_object_label *matchpo;
54045 + __u32 retval;
54046 +
54047 + if (unlikely(!(gr_status & GR_READY)))
54048 + return (mode & ~GR_AUDITS);
54049 +
54050 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
54051 +
54052 + retval = matchpo->mode & mode;
54053 +
54054 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
54055 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
54056 + __u32 new_mode = mode;
54057 +
54058 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
54059 +
54060 + gr_log_learn(new_dentry, mnt, new_mode);
54061 + return new_mode;
54062 + }
54063 +
54064 + return retval;
54065 +}
54066 +
54067 +__u32
54068 +gr_check_link(const struct dentry * new_dentry,
54069 + const struct dentry * parent_dentry,
54070 + const struct vfsmount * parent_mnt,
54071 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
54072 +{
54073 + struct acl_object_label *obj;
54074 + __u32 oldmode, newmode;
54075 + __u32 needmode;
54076 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
54077 + GR_DELETE | GR_INHERIT;
54078 +
54079 + if (unlikely(!(gr_status & GR_READY)))
54080 + return (GR_CREATE | GR_LINK);
54081 +
54082 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
54083 + oldmode = obj->mode;
54084 +
54085 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
54086 + newmode = obj->mode;
54087 +
54088 + needmode = newmode & checkmodes;
54089 +
54090 + // old name for hardlink must have at least the permissions of the new name
54091 + if ((oldmode & needmode) != needmode)
54092 + goto bad;
54093 +
54094 + // if old name had restrictions/auditing, make sure the new name does as well
54095 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
54096 +
54097 + // don't allow hardlinking of suid/sgid/fcapped files without permission
54098 + if (is_privileged_binary(old_dentry))
54099 + needmode |= GR_SETID;
54100 +
54101 + if ((newmode & needmode) != needmode)
54102 + goto bad;
54103 +
54104 + // enforce minimum permissions
54105 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
54106 + return newmode;
54107 +bad:
54108 + needmode = oldmode;
54109 + if (is_privileged_binary(old_dentry))
54110 + needmode |= GR_SETID;
54111 +
54112 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
54113 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
54114 + return (GR_CREATE | GR_LINK);
54115 + } else if (newmode & GR_SUPPRESS)
54116 + return GR_SUPPRESS;
54117 + else
54118 + return 0;
54119 +}
54120 +
54121 +int
54122 +gr_check_hidden_task(const struct task_struct *task)
54123 +{
54124 + if (unlikely(!(gr_status & GR_READY)))
54125 + return 0;
54126 +
54127 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
54128 + return 1;
54129 +
54130 + return 0;
54131 +}
54132 +
54133 +int
54134 +gr_check_protected_task(const struct task_struct *task)
54135 +{
54136 + if (unlikely(!(gr_status & GR_READY) || !task))
54137 + return 0;
54138 +
54139 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
54140 + task->acl != current->acl)
54141 + return 1;
54142 +
54143 + return 0;
54144 +}
54145 +
54146 +int
54147 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
54148 +{
54149 + struct task_struct *p;
54150 + int ret = 0;
54151 +
54152 + if (unlikely(!(gr_status & GR_READY) || !pid))
54153 + return ret;
54154 +
54155 + read_lock(&tasklist_lock);
54156 + do_each_pid_task(pid, type, p) {
54157 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
54158 + p->acl != current->acl) {
54159 + ret = 1;
54160 + goto out;
54161 + }
54162 + } while_each_pid_task(pid, type, p);
54163 +out:
54164 + read_unlock(&tasklist_lock);
54165 +
54166 + return ret;
54167 +}
54168 +
54169 +void
54170 +gr_copy_label(struct task_struct *tsk)
54171 +{
54172 + tsk->signal->used_accept = 0;
54173 + tsk->acl_sp_role = 0;
54174 + tsk->acl_role_id = current->acl_role_id;
54175 + tsk->acl = current->acl;
54176 + tsk->role = current->role;
54177 + tsk->signal->curr_ip = current->signal->curr_ip;
54178 + tsk->signal->saved_ip = current->signal->saved_ip;
54179 + if (current->exec_file)
54180 + get_file(current->exec_file);
54181 + tsk->exec_file = current->exec_file;
54182 + tsk->is_writable = current->is_writable;
54183 + if (unlikely(current->signal->used_accept)) {
54184 + current->signal->curr_ip = 0;
54185 + current->signal->saved_ip = 0;
54186 + }
54187 +
54188 + return;
54189 +}
54190 +
54191 +static void
54192 +gr_set_proc_res(struct task_struct *task)
54193 +{
54194 + struct acl_subject_label *proc;
54195 + unsigned short i;
54196 +
54197 + proc = task->acl;
54198 +
54199 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
54200 + return;
54201 +
54202 + for (i = 0; i < RLIM_NLIMITS; i++) {
54203 + if (!(proc->resmask & (1 << i)))
54204 + continue;
54205 +
54206 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
54207 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
54208 + }
54209 +
54210 + return;
54211 +}
54212 +
54213 +extern int __gr_process_user_ban(struct user_struct *user);
54214 +
54215 +int
54216 +gr_check_user_change(int real, int effective, int fs)
54217 +{
54218 + unsigned int i;
54219 + __u16 num;
54220 + uid_t *uidlist;
54221 + int curuid;
54222 + int realok = 0;
54223 + int effectiveok = 0;
54224 + int fsok = 0;
54225 +
54226 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
54227 + struct user_struct *user;
54228 +
54229 + if (real == -1)
54230 + goto skipit;
54231 +
54232 + user = find_user(real);
54233 + if (user == NULL)
54234 + goto skipit;
54235 +
54236 + if (__gr_process_user_ban(user)) {
54237 + /* for find_user */
54238 + free_uid(user);
54239 + return 1;
54240 + }
54241 +
54242 + /* for find_user */
54243 + free_uid(user);
54244 +
54245 +skipit:
54246 +#endif
54247 +
54248 + if (unlikely(!(gr_status & GR_READY)))
54249 + return 0;
54250 +
54251 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
54252 + gr_log_learn_id_change('u', real, effective, fs);
54253 +
54254 + num = current->acl->user_trans_num;
54255 + uidlist = current->acl->user_transitions;
54256 +
54257 + if (uidlist == NULL)
54258 + return 0;
54259 +
54260 + if (real == -1)
54261 + realok = 1;
54262 + if (effective == -1)
54263 + effectiveok = 1;
54264 + if (fs == -1)
54265 + fsok = 1;
54266 +
54267 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
54268 + for (i = 0; i < num; i++) {
54269 + curuid = (int)uidlist[i];
54270 + if (real == curuid)
54271 + realok = 1;
54272 + if (effective == curuid)
54273 + effectiveok = 1;
54274 + if (fs == curuid)
54275 + fsok = 1;
54276 + }
54277 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
54278 + for (i = 0; i < num; i++) {
54279 + curuid = (int)uidlist[i];
54280 + if (real == curuid)
54281 + break;
54282 + if (effective == curuid)
54283 + break;
54284 + if (fs == curuid)
54285 + break;
54286 + }
54287 + /* not in deny list */
54288 + if (i == num) {
54289 + realok = 1;
54290 + effectiveok = 1;
54291 + fsok = 1;
54292 + }
54293 + }
54294 +
54295 + if (realok && effectiveok && fsok)
54296 + return 0;
54297 + else {
54298 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
54299 + return 1;
54300 + }
54301 +}
54302 +
54303 +int
54304 +gr_check_group_change(int real, int effective, int fs)
54305 +{
54306 + unsigned int i;
54307 + __u16 num;
54308 + gid_t *gidlist;
54309 + int curgid;
54310 + int realok = 0;
54311 + int effectiveok = 0;
54312 + int fsok = 0;
54313 +
54314 + if (unlikely(!(gr_status & GR_READY)))
54315 + return 0;
54316 +
54317 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
54318 + gr_log_learn_id_change('g', real, effective, fs);
54319 +
54320 + num = current->acl->group_trans_num;
54321 + gidlist = current->acl->group_transitions;
54322 +
54323 + if (gidlist == NULL)
54324 + return 0;
54325 +
54326 + if (real == -1)
54327 + realok = 1;
54328 + if (effective == -1)
54329 + effectiveok = 1;
54330 + if (fs == -1)
54331 + fsok = 1;
54332 +
54333 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
54334 + for (i = 0; i < num; i++) {
54335 + curgid = (int)gidlist[i];
54336 + if (real == curgid)
54337 + realok = 1;
54338 + if (effective == curgid)
54339 + effectiveok = 1;
54340 + if (fs == curgid)
54341 + fsok = 1;
54342 + }
54343 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
54344 + for (i = 0; i < num; i++) {
54345 + curgid = (int)gidlist[i];
54346 + if (real == curgid)
54347 + break;
54348 + if (effective == curgid)
54349 + break;
54350 + if (fs == curgid)
54351 + break;
54352 + }
54353 + /* not in deny list */
54354 + if (i == num) {
54355 + realok = 1;
54356 + effectiveok = 1;
54357 + fsok = 1;
54358 + }
54359 + }
54360 +
54361 + if (realok && effectiveok && fsok)
54362 + return 0;
54363 + else {
54364 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
54365 + return 1;
54366 + }
54367 +}
54368 +
54369 +extern int gr_acl_is_capable(const int cap);
54370 +
54371 +void
54372 +gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
54373 +{
54374 + struct acl_role_label *role = task->role;
54375 + struct acl_subject_label *subj = NULL;
54376 + struct acl_object_label *obj;
54377 + struct file *filp;
54378 +
54379 + if (unlikely(!(gr_status & GR_READY)))
54380 + return;
54381 +
54382 + filp = task->exec_file;
54383 +
54384 + /* kernel process, we'll give them the kernel role */
54385 + if (unlikely(!filp)) {
54386 + task->role = kernel_role;
54387 + task->acl = kernel_role->root_label;
54388 + return;
54389 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
54390 + role = lookup_acl_role_label(task, uid, gid);
54391 +
54392 + /* don't change the role if we're not a privileged process */
54393 + if (role && task->role != role &&
54394 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
54395 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
54396 + return;
54397 +
54398 + /* perform subject lookup in possibly new role
54399 + we can use this result below in the case where role == task->role
54400 + */
54401 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
54402 +
54403 + /* if we changed uid/gid, but result in the same role
54404 + and are using inheritance, don't lose the inherited subject
54405 + if current subject is other than what normal lookup
54406 + would result in, we arrived via inheritance, don't
54407 + lose subject
54408 + */
54409 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
54410 + (subj == task->acl)))
54411 + task->acl = subj;
54412 +
54413 + task->role = role;
54414 +
54415 + task->is_writable = 0;
54416 +
54417 + /* ignore additional mmap checks for processes that are writable
54418 + by the default ACL */
54419 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54420 + if (unlikely(obj->mode & GR_WRITE))
54421 + task->is_writable = 1;
54422 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
54423 + if (unlikely(obj->mode & GR_WRITE))
54424 + task->is_writable = 1;
54425 +
54426 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54427 + printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54428 +#endif
54429 +
54430 + gr_set_proc_res(task);
54431 +
54432 + return;
54433 +}
54434 +
54435 +int
54436 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
54437 + const int unsafe_flags)
54438 +{
54439 + struct task_struct *task = current;
54440 + struct acl_subject_label *newacl;
54441 + struct acl_object_label *obj;
54442 + __u32 retmode;
54443 +
54444 + if (unlikely(!(gr_status & GR_READY)))
54445 + return 0;
54446 +
54447 + newacl = chk_subj_label(dentry, mnt, task->role);
54448 +
54449 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
54450 + did an exec
54451 + */
54452 + rcu_read_lock();
54453 + read_lock(&tasklist_lock);
54454 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
54455 + (task->parent->acl->mode & GR_POVERRIDE))) {
54456 + read_unlock(&tasklist_lock);
54457 + rcu_read_unlock();
54458 + goto skip_check;
54459 + }
54460 + read_unlock(&tasklist_lock);
54461 + rcu_read_unlock();
54462 +
54463 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
54464 + !(task->role->roletype & GR_ROLE_GOD) &&
54465 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
54466 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
54467 + if (unsafe_flags & LSM_UNSAFE_SHARE)
54468 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
54469 + else
54470 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
54471 + return -EACCES;
54472 + }
54473 +
54474 +skip_check:
54475 +
54476 + obj = chk_obj_label(dentry, mnt, task->acl);
54477 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
54478 +
54479 + if (!(task->acl->mode & GR_INHERITLEARN) &&
54480 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
54481 + if (obj->nested)
54482 + task->acl = obj->nested;
54483 + else
54484 + task->acl = newacl;
54485 + } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
54486 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
54487 +
54488 + task->is_writable = 0;
54489 +
54490 + /* ignore additional mmap checks for processes that are writable
54491 + by the default ACL */
54492 + obj = chk_obj_label(dentry, mnt, default_role->root_label);
54493 + if (unlikely(obj->mode & GR_WRITE))
54494 + task->is_writable = 1;
54495 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
54496 + if (unlikely(obj->mode & GR_WRITE))
54497 + task->is_writable = 1;
54498 +
54499 + gr_set_proc_res(task);
54500 +
54501 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54502 + printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54503 +#endif
54504 + return 0;
54505 +}
54506 +
54507 +/* always called with valid inodev ptr */
54508 +static void
54509 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
54510 +{
54511 + struct acl_object_label *matchpo;
54512 + struct acl_subject_label *matchps;
54513 + struct acl_subject_label *subj;
54514 + struct acl_role_label *role;
54515 + unsigned int x;
54516 +
54517 + FOR_EACH_ROLE_START(role)
54518 + FOR_EACH_SUBJECT_START(role, subj, x)
54519 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
54520 + matchpo->mode |= GR_DELETED;
54521 + FOR_EACH_SUBJECT_END(subj,x)
54522 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
54523 + /* nested subjects aren't in the role's subj_hash table */
54524 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
54525 + matchpo->mode |= GR_DELETED;
54526 + FOR_EACH_NESTED_SUBJECT_END(subj)
54527 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
54528 + matchps->mode |= GR_DELETED;
54529 + FOR_EACH_ROLE_END(role)
54530 +
54531 + inodev->nentry->deleted = 1;
54532 +
54533 + return;
54534 +}
54535 +
54536 +void
54537 +gr_handle_delete(const ino_t ino, const dev_t dev)
54538 +{
54539 + struct inodev_entry *inodev;
54540 +
54541 + if (unlikely(!(gr_status & GR_READY)))
54542 + return;
54543 +
54544 + write_lock(&gr_inode_lock);
54545 + inodev = lookup_inodev_entry(ino, dev);
54546 + if (inodev != NULL)
54547 + do_handle_delete(inodev, ino, dev);
54548 + write_unlock(&gr_inode_lock);
54549 +
54550 + return;
54551 +}
54552 +
54553 +static void
54554 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
54555 + const ino_t newinode, const dev_t newdevice,
54556 + struct acl_subject_label *subj)
54557 +{
54558 + unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
54559 + struct acl_object_label *match;
54560 +
54561 + match = subj->obj_hash[index];
54562 +
54563 + while (match && (match->inode != oldinode ||
54564 + match->device != olddevice ||
54565 + !(match->mode & GR_DELETED)))
54566 + match = match->next;
54567 +
54568 + if (match && (match->inode == oldinode)
54569 + && (match->device == olddevice)
54570 + && (match->mode & GR_DELETED)) {
54571 + if (match->prev == NULL) {
54572 + subj->obj_hash[index] = match->next;
54573 + if (match->next != NULL)
54574 + match->next->prev = NULL;
54575 + } else {
54576 + match->prev->next = match->next;
54577 + if (match->next != NULL)
54578 + match->next->prev = match->prev;
54579 + }
54580 + match->prev = NULL;
54581 + match->next = NULL;
54582 + match->inode = newinode;
54583 + match->device = newdevice;
54584 + match->mode &= ~GR_DELETED;
54585 +
54586 + insert_acl_obj_label(match, subj);
54587 + }
54588 +
54589 + return;
54590 +}
54591 +
54592 +static void
54593 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
54594 + const ino_t newinode, const dev_t newdevice,
54595 + struct acl_role_label *role)
54596 +{
54597 + unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
54598 + struct acl_subject_label *match;
54599 +
54600 + match = role->subj_hash[index];
54601 +
54602 + while (match && (match->inode != oldinode ||
54603 + match->device != olddevice ||
54604 + !(match->mode & GR_DELETED)))
54605 + match = match->next;
54606 +
54607 + if (match && (match->inode == oldinode)
54608 + && (match->device == olddevice)
54609 + && (match->mode & GR_DELETED)) {
54610 + if (match->prev == NULL) {
54611 + role->subj_hash[index] = match->next;
54612 + if (match->next != NULL)
54613 + match->next->prev = NULL;
54614 + } else {
54615 + match->prev->next = match->next;
54616 + if (match->next != NULL)
54617 + match->next->prev = match->prev;
54618 + }
54619 + match->prev = NULL;
54620 + match->next = NULL;
54621 + match->inode = newinode;
54622 + match->device = newdevice;
54623 + match->mode &= ~GR_DELETED;
54624 +
54625 + insert_acl_subj_label(match, role);
54626 + }
54627 +
54628 + return;
54629 +}
54630 +
54631 +static void
54632 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
54633 + const ino_t newinode, const dev_t newdevice)
54634 +{
54635 + unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
54636 + struct inodev_entry *match;
54637 +
54638 + match = inodev_set.i_hash[index];
54639 +
54640 + while (match && (match->nentry->inode != oldinode ||
54641 + match->nentry->device != olddevice || !match->nentry->deleted))
54642 + match = match->next;
54643 +
54644 + if (match && (match->nentry->inode == oldinode)
54645 + && (match->nentry->device == olddevice) &&
54646 + match->nentry->deleted) {
54647 + if (match->prev == NULL) {
54648 + inodev_set.i_hash[index] = match->next;
54649 + if (match->next != NULL)
54650 + match->next->prev = NULL;
54651 + } else {
54652 + match->prev->next = match->next;
54653 + if (match->next != NULL)
54654 + match->next->prev = match->prev;
54655 + }
54656 + match->prev = NULL;
54657 + match->next = NULL;
54658 + match->nentry->inode = newinode;
54659 + match->nentry->device = newdevice;
54660 + match->nentry->deleted = 0;
54661 +
54662 + insert_inodev_entry(match);
54663 + }
54664 +
54665 + return;
54666 +}
54667 +
54668 +static void
54669 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
54670 +{
54671 + struct acl_subject_label *subj;
54672 + struct acl_role_label *role;
54673 + unsigned int x;
54674 +
54675 + FOR_EACH_ROLE_START(role)
54676 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
54677 +
54678 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
54679 + if ((subj->inode == ino) && (subj->device == dev)) {
54680 + subj->inode = ino;
54681 + subj->device = dev;
54682 + }
54683 + /* nested subjects aren't in the role's subj_hash table */
54684 + update_acl_obj_label(matchn->inode, matchn->device,
54685 + ino, dev, subj);
54686 + FOR_EACH_NESTED_SUBJECT_END(subj)
54687 + FOR_EACH_SUBJECT_START(role, subj, x)
54688 + update_acl_obj_label(matchn->inode, matchn->device,
54689 + ino, dev, subj);
54690 + FOR_EACH_SUBJECT_END(subj,x)
54691 + FOR_EACH_ROLE_END(role)
54692 +
54693 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
54694 +
54695 + return;
54696 +}
54697 +
54698 +static void
54699 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
54700 + const struct vfsmount *mnt)
54701 +{
54702 + ino_t ino = dentry->d_inode->i_ino;
54703 + dev_t dev = __get_dev(dentry);
54704 +
54705 + __do_handle_create(matchn, ino, dev);
54706 +
54707 + return;
54708 +}
54709 +
54710 +void
54711 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
54712 +{
54713 + struct name_entry *matchn;
54714 +
54715 + if (unlikely(!(gr_status & GR_READY)))
54716 + return;
54717 +
54718 + preempt_disable();
54719 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
54720 +
54721 + if (unlikely((unsigned long)matchn)) {
54722 + write_lock(&gr_inode_lock);
54723 + do_handle_create(matchn, dentry, mnt);
54724 + write_unlock(&gr_inode_lock);
54725 + }
54726 + preempt_enable();
54727 +
54728 + return;
54729 +}
54730 +
54731 +void
54732 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
54733 +{
54734 + struct name_entry *matchn;
54735 +
54736 + if (unlikely(!(gr_status & GR_READY)))
54737 + return;
54738 +
54739 + preempt_disable();
54740 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
54741 +
54742 + if (unlikely((unsigned long)matchn)) {
54743 + write_lock(&gr_inode_lock);
54744 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
54745 + write_unlock(&gr_inode_lock);
54746 + }
54747 + preempt_enable();
54748 +
54749 + return;
54750 +}
54751 +
54752 +void
54753 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
54754 + struct dentry *old_dentry,
54755 + struct dentry *new_dentry,
54756 + struct vfsmount *mnt, const __u8 replace)
54757 +{
54758 + struct name_entry *matchn;
54759 + struct inodev_entry *inodev;
54760 + struct inode *inode = new_dentry->d_inode;
54761 + ino_t old_ino = old_dentry->d_inode->i_ino;
54762 + dev_t old_dev = __get_dev(old_dentry);
54763 +
54764 + /* vfs_rename swaps the name and parent link for old_dentry and
54765 + new_dentry
54766 + at this point, old_dentry has the new name, parent link, and inode
54767 + for the renamed file
54768 + if a file is being replaced by a rename, new_dentry has the inode
54769 + and name for the replaced file
54770 + */
54771 +
54772 + if (unlikely(!(gr_status & GR_READY)))
54773 + return;
54774 +
54775 + preempt_disable();
54776 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
54777 +
54778 + /* we wouldn't have to check d_inode if it weren't for
54779 + NFS silly-renaming
54780 + */
54781 +
54782 + write_lock(&gr_inode_lock);
54783 + if (unlikely(replace && inode)) {
54784 + ino_t new_ino = inode->i_ino;
54785 + dev_t new_dev = __get_dev(new_dentry);
54786 +
54787 + inodev = lookup_inodev_entry(new_ino, new_dev);
54788 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
54789 + do_handle_delete(inodev, new_ino, new_dev);
54790 + }
54791 +
54792 + inodev = lookup_inodev_entry(old_ino, old_dev);
54793 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
54794 + do_handle_delete(inodev, old_ino, old_dev);
54795 +
54796 + if (unlikely((unsigned long)matchn))
54797 + do_handle_create(matchn, old_dentry, mnt);
54798 +
54799 + write_unlock(&gr_inode_lock);
54800 + preempt_enable();
54801 +
54802 + return;
54803 +}
54804 +
54805 +static int
54806 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
54807 + unsigned char **sum)
54808 +{
54809 + struct acl_role_label *r;
54810 + struct role_allowed_ip *ipp;
54811 + struct role_transition *trans;
54812 + unsigned int i;
54813 + int found = 0;
54814 + u32 curr_ip = current->signal->curr_ip;
54815 +
54816 + current->signal->saved_ip = curr_ip;
54817 +
54818 + /* check transition table */
54819 +
54820 + for (trans = current->role->transitions; trans; trans = trans->next) {
54821 + if (!strcmp(rolename, trans->rolename)) {
54822 + found = 1;
54823 + break;
54824 + }
54825 + }
54826 +
54827 + if (!found)
54828 + return 0;
54829 +
54830 + /* handle special roles that do not require authentication
54831 + and check ip */
54832 +
54833 + FOR_EACH_ROLE_START(r)
54834 + if (!strcmp(rolename, r->rolename) &&
54835 + (r->roletype & GR_ROLE_SPECIAL)) {
54836 + found = 0;
54837 + if (r->allowed_ips != NULL) {
54838 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
54839 + if ((ntohl(curr_ip) & ipp->netmask) ==
54840 + (ntohl(ipp->addr) & ipp->netmask))
54841 + found = 1;
54842 + }
54843 + } else
54844 + found = 2;
54845 + if (!found)
54846 + return 0;
54847 +
54848 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
54849 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
54850 + *salt = NULL;
54851 + *sum = NULL;
54852 + return 1;
54853 + }
54854 + }
54855 + FOR_EACH_ROLE_END(r)
54856 +
54857 + for (i = 0; i < num_sprole_pws; i++) {
54858 + if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
54859 + *salt = acl_special_roles[i]->salt;
54860 + *sum = acl_special_roles[i]->sum;
54861 + return 1;
54862 + }
54863 + }
54864 +
54865 + return 0;
54866 +}
54867 +
54868 +static void
54869 +assign_special_role(char *rolename)
54870 +{
54871 + struct acl_object_label *obj;
54872 + struct acl_role_label *r;
54873 + struct acl_role_label *assigned = NULL;
54874 + struct task_struct *tsk;
54875 + struct file *filp;
54876 +
54877 + FOR_EACH_ROLE_START(r)
54878 + if (!strcmp(rolename, r->rolename) &&
54879 + (r->roletype & GR_ROLE_SPECIAL)) {
54880 + assigned = r;
54881 + break;
54882 + }
54883 + FOR_EACH_ROLE_END(r)
54884 +
54885 + if (!assigned)
54886 + return;
54887 +
54888 + read_lock(&tasklist_lock);
54889 + read_lock(&grsec_exec_file_lock);
54890 +
54891 + tsk = current->real_parent;
54892 + if (tsk == NULL)
54893 + goto out_unlock;
54894 +
54895 + filp = tsk->exec_file;
54896 + if (filp == NULL)
54897 + goto out_unlock;
54898 +
54899 + tsk->is_writable = 0;
54900 +
54901 + tsk->acl_sp_role = 1;
54902 + tsk->acl_role_id = ++acl_sp_role_value;
54903 + tsk->role = assigned;
54904 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
54905 +
54906 + /* ignore additional mmap checks for processes that are writable
54907 + by the default ACL */
54908 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54909 + if (unlikely(obj->mode & GR_WRITE))
54910 + tsk->is_writable = 1;
54911 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
54912 + if (unlikely(obj->mode & GR_WRITE))
54913 + tsk->is_writable = 1;
54914 +
54915 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54916 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
54917 +#endif
54918 +
54919 +out_unlock:
54920 + read_unlock(&grsec_exec_file_lock);
54921 + read_unlock(&tasklist_lock);
54922 + return;
54923 +}
54924 +
54925 +int gr_check_secure_terminal(struct task_struct *task)
54926 +{
54927 + struct task_struct *p, *p2, *p3;
54928 + struct files_struct *files;
54929 + struct fdtable *fdt;
54930 + struct file *our_file = NULL, *file;
54931 + int i;
54932 +
54933 + if (task->signal->tty == NULL)
54934 + return 1;
54935 +
54936 + files = get_files_struct(task);
54937 + if (files != NULL) {
54938 + rcu_read_lock();
54939 + fdt = files_fdtable(files);
54940 + for (i=0; i < fdt->max_fds; i++) {
54941 + file = fcheck_files(files, i);
54942 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
54943 + get_file(file);
54944 + our_file = file;
54945 + }
54946 + }
54947 + rcu_read_unlock();
54948 + put_files_struct(files);
54949 + }
54950 +
54951 + if (our_file == NULL)
54952 + return 1;
54953 +
54954 + read_lock(&tasklist_lock);
54955 + do_each_thread(p2, p) {
54956 + files = get_files_struct(p);
54957 + if (files == NULL ||
54958 + (p->signal && p->signal->tty == task->signal->tty)) {
54959 + if (files != NULL)
54960 + put_files_struct(files);
54961 + continue;
54962 + }
54963 + rcu_read_lock();
54964 + fdt = files_fdtable(files);
54965 + for (i=0; i < fdt->max_fds; i++) {
54966 + file = fcheck_files(files, i);
54967 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
54968 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
54969 + p3 = task;
54970 + while (p3->pid > 0) {
54971 + if (p3 == p)
54972 + break;
54973 + p3 = p3->real_parent;
54974 + }
54975 + if (p3 == p)
54976 + break;
54977 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
54978 + gr_handle_alertkill(p);
54979 + rcu_read_unlock();
54980 + put_files_struct(files);
54981 + read_unlock(&tasklist_lock);
54982 + fput(our_file);
54983 + return 0;
54984 + }
54985 + }
54986 + rcu_read_unlock();
54987 + put_files_struct(files);
54988 + } while_each_thread(p2, p);
54989 + read_unlock(&tasklist_lock);
54990 +
54991 + fput(our_file);
54992 + return 1;
54993 +}
54994 +
54995 +static int gr_rbac_disable(void *unused)
54996 +{
54997 + pax_open_kernel();
54998 + gr_status &= ~GR_READY;
54999 + pax_close_kernel();
55000 +
55001 + return 0;
55002 +}
55003 +
55004 +ssize_t
55005 +write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
55006 +{
55007 + struct gr_arg_wrapper uwrap;
55008 + unsigned char *sprole_salt = NULL;
55009 + unsigned char *sprole_sum = NULL;
55010 + int error = sizeof (struct gr_arg_wrapper);
55011 + int error2 = 0;
55012 +
55013 + mutex_lock(&gr_dev_mutex);
55014 +
55015 + if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
55016 + error = -EPERM;
55017 + goto out;
55018 + }
55019 +
55020 + if (count != sizeof (struct gr_arg_wrapper)) {
55021 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
55022 + error = -EINVAL;
55023 + goto out;
55024 + }
55025 +
55026 +
55027 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
55028 + gr_auth_expires = 0;
55029 + gr_auth_attempts = 0;
55030 + }
55031 +
55032 + if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
55033 + error = -EFAULT;
55034 + goto out;
55035 + }
55036 +
55037 + if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
55038 + error = -EINVAL;
55039 + goto out;
55040 + }
55041 +
55042 + if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
55043 + error = -EFAULT;
55044 + goto out;
55045 + }
55046 +
55047 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
55048 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
55049 + time_after(gr_auth_expires, get_seconds())) {
55050 + error = -EBUSY;
55051 + goto out;
55052 + }
55053 +
55054 + /* if non-root trying to do anything other than use a special role,
55055 + do not attempt authentication, do not count towards authentication
55056 + locking
55057 + */
55058 +
55059 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
55060 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
55061 + !uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
55062 + error = -EPERM;
55063 + goto out;
55064 + }
55065 +
55066 + /* ensure pw and special role name are null terminated */
55067 +
55068 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
55069 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
55070 +
55071 + /* Okay.
55072 + * We have our enough of the argument structure..(we have yet
55073 + * to copy_from_user the tables themselves) . Copy the tables
55074 + * only if we need them, i.e. for loading operations. */
55075 +
55076 + switch (gr_usermode->mode) {
55077 + case GR_STATUS:
55078 + if (gr_status & GR_READY) {
55079 + error = 1;
55080 + if (!gr_check_secure_terminal(current))
55081 + error = 3;
55082 + } else
55083 + error = 2;
55084 + goto out;
55085 + case GR_SHUTDOWN:
55086 + if ((gr_status & GR_READY)
55087 + && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
55088 + stop_machine(gr_rbac_disable, NULL, NULL);
55089 + free_variables();
55090 + memset(gr_usermode, 0, sizeof (struct gr_arg));
55091 + memset(gr_system_salt, 0, GR_SALT_LEN);
55092 + memset(gr_system_sum, 0, GR_SHA_LEN);
55093 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
55094 + } else if (gr_status & GR_READY) {
55095 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
55096 + error = -EPERM;
55097 + } else {
55098 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
55099 + error = -EAGAIN;
55100 + }
55101 + break;
55102 + case GR_ENABLE:
55103 + if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
55104 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
55105 + else {
55106 + if (gr_status & GR_READY)
55107 + error = -EAGAIN;
55108 + else
55109 + error = error2;
55110 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
55111 + }
55112 + break;
55113 + case GR_RELOAD:
55114 + if (!(gr_status & GR_READY)) {
55115 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
55116 + error = -EAGAIN;
55117 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
55118 + stop_machine(gr_rbac_disable, NULL, NULL);
55119 + free_variables();
55120 + error2 = gracl_init(gr_usermode);
55121 + if (!error2)
55122 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
55123 + else {
55124 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
55125 + error = error2;
55126 + }
55127 + } else {
55128 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
55129 + error = -EPERM;
55130 + }
55131 + break;
55132 + case GR_SEGVMOD:
55133 + if (unlikely(!(gr_status & GR_READY))) {
55134 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
55135 + error = -EAGAIN;
55136 + break;
55137 + }
55138 +
55139 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
55140 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
55141 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
55142 + struct acl_subject_label *segvacl;
55143 + segvacl =
55144 + lookup_acl_subj_label(gr_usermode->segv_inode,
55145 + gr_usermode->segv_device,
55146 + current->role);
55147 + if (segvacl) {
55148 + segvacl->crashes = 0;
55149 + segvacl->expires = 0;
55150 + }
55151 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
55152 + gr_remove_uid(gr_usermode->segv_uid);
55153 + }
55154 + } else {
55155 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
55156 + error = -EPERM;
55157 + }
55158 + break;
55159 + case GR_SPROLE:
55160 + case GR_SPROLEPAM:
55161 + if (unlikely(!(gr_status & GR_READY))) {
55162 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
55163 + error = -EAGAIN;
55164 + break;
55165 + }
55166 +
55167 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
55168 + current->role->expires = 0;
55169 + current->role->auth_attempts = 0;
55170 + }
55171 +
55172 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
55173 + time_after(current->role->expires, get_seconds())) {
55174 + error = -EBUSY;
55175 + goto out;
55176 + }
55177 +
55178 + if (lookup_special_role_auth
55179 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
55180 + && ((!sprole_salt && !sprole_sum)
55181 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
55182 + char *p = "";
55183 + assign_special_role(gr_usermode->sp_role);
55184 + read_lock(&tasklist_lock);
55185 + if (current->real_parent)
55186 + p = current->real_parent->role->rolename;
55187 + read_unlock(&tasklist_lock);
55188 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
55189 + p, acl_sp_role_value);
55190 + } else {
55191 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
55192 + error = -EPERM;
55193 + if(!(current->role->auth_attempts++))
55194 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
55195 +
55196 + goto out;
55197 + }
55198 + break;
55199 + case GR_UNSPROLE:
55200 + if (unlikely(!(gr_status & GR_READY))) {
55201 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
55202 + error = -EAGAIN;
55203 + break;
55204 + }
55205 +
55206 + if (current->role->roletype & GR_ROLE_SPECIAL) {
55207 + char *p = "";
55208 + int i = 0;
55209 +
55210 + read_lock(&tasklist_lock);
55211 + if (current->real_parent) {
55212 + p = current->real_parent->role->rolename;
55213 + i = current->real_parent->acl_role_id;
55214 + }
55215 + read_unlock(&tasklist_lock);
55216 +
55217 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
55218 + gr_set_acls(1);
55219 + } else {
55220 + error = -EPERM;
55221 + goto out;
55222 + }
55223 + break;
55224 + default:
55225 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
55226 + error = -EINVAL;
55227 + break;
55228 + }
55229 +
55230 + if (error != -EPERM)
55231 + goto out;
55232 +
55233 + if(!(gr_auth_attempts++))
55234 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
55235 +
55236 + out:
55237 + mutex_unlock(&gr_dev_mutex);
55238 + return error;
55239 +}
55240 +
55241 +/* must be called with
55242 + rcu_read_lock();
55243 + read_lock(&tasklist_lock);
55244 + read_lock(&grsec_exec_file_lock);
55245 +*/
55246 +int gr_apply_subject_to_task(struct task_struct *task)
55247 +{
55248 + struct acl_object_label *obj;
55249 + char *tmpname;
55250 + struct acl_subject_label *tmpsubj;
55251 + struct file *filp;
55252 + struct name_entry *nmatch;
55253 +
55254 + filp = task->exec_file;
55255 + if (filp == NULL)
55256 + return 0;
55257 +
55258 + /* the following is to apply the correct subject
55259 + on binaries running when the RBAC system
55260 + is enabled, when the binaries have been
55261 + replaced or deleted since their execution
55262 + -----
55263 + when the RBAC system starts, the inode/dev
55264 + from exec_file will be one the RBAC system
55265 + is unaware of. It only knows the inode/dev
55266 + of the present file on disk, or the absence
55267 + of it.
55268 + */
55269 + preempt_disable();
55270 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
55271 +
55272 + nmatch = lookup_name_entry(tmpname);
55273 + preempt_enable();
55274 + tmpsubj = NULL;
55275 + if (nmatch) {
55276 + if (nmatch->deleted)
55277 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
55278 + else
55279 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
55280 + if (tmpsubj != NULL)
55281 + task->acl = tmpsubj;
55282 + }
55283 + if (tmpsubj == NULL)
55284 + task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
55285 + task->role);
55286 + if (task->acl) {
55287 + task->is_writable = 0;
55288 + /* ignore additional mmap checks for processes that are writable
55289 + by the default ACL */
55290 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
55291 + if (unlikely(obj->mode & GR_WRITE))
55292 + task->is_writable = 1;
55293 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
55294 + if (unlikely(obj->mode & GR_WRITE))
55295 + task->is_writable = 1;
55296 +
55297 + gr_set_proc_res(task);
55298 +
55299 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
55300 + printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
55301 +#endif
55302 + } else {
55303 + return 1;
55304 + }
55305 +
55306 + return 0;
55307 +}
55308 +
55309 +int
55310 +gr_set_acls(const int type)
55311 +{
55312 + struct task_struct *task, *task2;
55313 + struct acl_role_label *role = current->role;
55314 + __u16 acl_role_id = current->acl_role_id;
55315 + const struct cred *cred;
55316 + int ret;
55317 +
55318 + rcu_read_lock();
55319 + read_lock(&tasklist_lock);
55320 + read_lock(&grsec_exec_file_lock);
55321 + do_each_thread(task2, task) {
55322 + /* check to see if we're called from the exit handler,
55323 + if so, only replace ACLs that have inherited the admin
55324 + ACL */
55325 +
55326 + if (type && (task->role != role ||
55327 + task->acl_role_id != acl_role_id))
55328 + continue;
55329 +
55330 + task->acl_role_id = 0;
55331 + task->acl_sp_role = 0;
55332 +
55333 + if (task->exec_file) {
55334 + cred = __task_cred(task);
55335 + task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
55336 + ret = gr_apply_subject_to_task(task);
55337 + if (ret) {
55338 + read_unlock(&grsec_exec_file_lock);
55339 + read_unlock(&tasklist_lock);
55340 + rcu_read_unlock();
55341 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
55342 + return ret;
55343 + }
55344 + } else {
55345 + // it's a kernel process
55346 + task->role = kernel_role;
55347 + task->acl = kernel_role->root_label;
55348 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
55349 + task->acl->mode &= ~GR_PROCFIND;
55350 +#endif
55351 + }
55352 + } while_each_thread(task2, task);
55353 + read_unlock(&grsec_exec_file_lock);
55354 + read_unlock(&tasklist_lock);
55355 + rcu_read_unlock();
55356 +
55357 + return 0;
55358 +}
55359 +
55360 +void
55361 +gr_learn_resource(const struct task_struct *task,
55362 + const int res, const unsigned long wanted, const int gt)
55363 +{
55364 + struct acl_subject_label *acl;
55365 + const struct cred *cred;
55366 +
55367 + if (unlikely((gr_status & GR_READY) &&
55368 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
55369 + goto skip_reslog;
55370 +
55371 +#ifdef CONFIG_GRKERNSEC_RESLOG
55372 + gr_log_resource(task, res, wanted, gt);
55373 +#endif
55374 + skip_reslog:
55375 +
55376 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
55377 + return;
55378 +
55379 + acl = task->acl;
55380 +
55381 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
55382 + !(acl->resmask & (1 << (unsigned short) res))))
55383 + return;
55384 +
55385 + if (wanted >= acl->res[res].rlim_cur) {
55386 + unsigned long res_add;
55387 +
55388 + res_add = wanted;
55389 + switch (res) {
55390 + case RLIMIT_CPU:
55391 + res_add += GR_RLIM_CPU_BUMP;
55392 + break;
55393 + case RLIMIT_FSIZE:
55394 + res_add += GR_RLIM_FSIZE_BUMP;
55395 + break;
55396 + case RLIMIT_DATA:
55397 + res_add += GR_RLIM_DATA_BUMP;
55398 + break;
55399 + case RLIMIT_STACK:
55400 + res_add += GR_RLIM_STACK_BUMP;
55401 + break;
55402 + case RLIMIT_CORE:
55403 + res_add += GR_RLIM_CORE_BUMP;
55404 + break;
55405 + case RLIMIT_RSS:
55406 + res_add += GR_RLIM_RSS_BUMP;
55407 + break;
55408 + case RLIMIT_NPROC:
55409 + res_add += GR_RLIM_NPROC_BUMP;
55410 + break;
55411 + case RLIMIT_NOFILE:
55412 + res_add += GR_RLIM_NOFILE_BUMP;
55413 + break;
55414 + case RLIMIT_MEMLOCK:
55415 + res_add += GR_RLIM_MEMLOCK_BUMP;
55416 + break;
55417 + case RLIMIT_AS:
55418 + res_add += GR_RLIM_AS_BUMP;
55419 + break;
55420 + case RLIMIT_LOCKS:
55421 + res_add += GR_RLIM_LOCKS_BUMP;
55422 + break;
55423 + case RLIMIT_SIGPENDING:
55424 + res_add += GR_RLIM_SIGPENDING_BUMP;
55425 + break;
55426 + case RLIMIT_MSGQUEUE:
55427 + res_add += GR_RLIM_MSGQUEUE_BUMP;
55428 + break;
55429 + case RLIMIT_NICE:
55430 + res_add += GR_RLIM_NICE_BUMP;
55431 + break;
55432 + case RLIMIT_RTPRIO:
55433 + res_add += GR_RLIM_RTPRIO_BUMP;
55434 + break;
55435 + case RLIMIT_RTTIME:
55436 + res_add += GR_RLIM_RTTIME_BUMP;
55437 + break;
55438 + }
55439 +
55440 + acl->res[res].rlim_cur = res_add;
55441 +
55442 + if (wanted > acl->res[res].rlim_max)
55443 + acl->res[res].rlim_max = res_add;
55444 +
55445 + /* only log the subject filename, since resource logging is supported for
55446 + single-subject learning only */
55447 + rcu_read_lock();
55448 + cred = __task_cred(task);
55449 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
55450 + task->role->roletype, cred->uid, cred->gid, acl->filename,
55451 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
55452 + "", (unsigned long) res, &task->signal->saved_ip);
55453 + rcu_read_unlock();
55454 + }
55455 +
55456 + return;
55457 +}
55458 +
55459 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
55460 +void
55461 +pax_set_initial_flags(struct linux_binprm *bprm)
55462 +{
55463 + struct task_struct *task = current;
55464 + struct acl_subject_label *proc;
55465 + unsigned long flags;
55466 +
55467 + if (unlikely(!(gr_status & GR_READY)))
55468 + return;
55469 +
55470 + flags = pax_get_flags(task);
55471 +
55472 + proc = task->acl;
55473 +
55474 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
55475 + flags &= ~MF_PAX_PAGEEXEC;
55476 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
55477 + flags &= ~MF_PAX_SEGMEXEC;
55478 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
55479 + flags &= ~MF_PAX_RANDMMAP;
55480 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
55481 + flags &= ~MF_PAX_EMUTRAMP;
55482 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
55483 + flags &= ~MF_PAX_MPROTECT;
55484 +
55485 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
55486 + flags |= MF_PAX_PAGEEXEC;
55487 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
55488 + flags |= MF_PAX_SEGMEXEC;
55489 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
55490 + flags |= MF_PAX_RANDMMAP;
55491 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
55492 + flags |= MF_PAX_EMUTRAMP;
55493 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
55494 + flags |= MF_PAX_MPROTECT;
55495 +
55496 + pax_set_flags(task, flags);
55497 +
55498 + return;
55499 +}
55500 +#endif
55501 +
55502 +int
55503 +gr_handle_proc_ptrace(struct task_struct *task)
55504 +{
55505 + struct file *filp;
55506 + struct task_struct *tmp = task;
55507 + struct task_struct *curtemp = current;
55508 + __u32 retmode;
55509 +
55510 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
55511 + if (unlikely(!(gr_status & GR_READY)))
55512 + return 0;
55513 +#endif
55514 +
55515 + read_lock(&tasklist_lock);
55516 + read_lock(&grsec_exec_file_lock);
55517 + filp = task->exec_file;
55518 +
55519 + while (tmp->pid > 0) {
55520 + if (tmp == curtemp)
55521 + break;
55522 + tmp = tmp->real_parent;
55523 + }
55524 +
55525 + if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
55526 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
55527 + read_unlock(&grsec_exec_file_lock);
55528 + read_unlock(&tasklist_lock);
55529 + return 1;
55530 + }
55531 +
55532 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
55533 + if (!(gr_status & GR_READY)) {
55534 + read_unlock(&grsec_exec_file_lock);
55535 + read_unlock(&tasklist_lock);
55536 + return 0;
55537 + }
55538 +#endif
55539 +
55540 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
55541 + read_unlock(&grsec_exec_file_lock);
55542 + read_unlock(&tasklist_lock);
55543 +
55544 + if (retmode & GR_NOPTRACE)
55545 + return 1;
55546 +
55547 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
55548 + && (current->acl != task->acl || (current->acl != current->role->root_label
55549 + && current->pid != task->pid)))
55550 + return 1;
55551 +
55552 + return 0;
55553 +}
55554 +
55555 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
55556 +{
55557 + if (unlikely(!(gr_status & GR_READY)))
55558 + return;
55559 +
55560 + if (!(current->role->roletype & GR_ROLE_GOD))
55561 + return;
55562 +
55563 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
55564 + p->role->rolename, gr_task_roletype_to_char(p),
55565 + p->acl->filename);
55566 +}
55567 +
55568 +int
55569 +gr_handle_ptrace(struct task_struct *task, const long request)
55570 +{
55571 + struct task_struct *tmp = task;
55572 + struct task_struct *curtemp = current;
55573 + __u32 retmode;
55574 +
55575 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
55576 + if (unlikely(!(gr_status & GR_READY)))
55577 + return 0;
55578 +#endif
55579 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
55580 + read_lock(&tasklist_lock);
55581 + while (tmp->pid > 0) {
55582 + if (tmp == curtemp)
55583 + break;
55584 + tmp = tmp->real_parent;
55585 + }
55586 +
55587 + if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
55588 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
55589 + read_unlock(&tasklist_lock);
55590 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55591 + return 1;
55592 + }
55593 + read_unlock(&tasklist_lock);
55594 + }
55595 +
55596 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
55597 + if (!(gr_status & GR_READY))
55598 + return 0;
55599 +#endif
55600 +
55601 + read_lock(&grsec_exec_file_lock);
55602 + if (unlikely(!task->exec_file)) {
55603 + read_unlock(&grsec_exec_file_lock);
55604 + return 0;
55605 + }
55606 +
55607 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
55608 + read_unlock(&grsec_exec_file_lock);
55609 +
55610 + if (retmode & GR_NOPTRACE) {
55611 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55612 + return 1;
55613 + }
55614 +
55615 + if (retmode & GR_PTRACERD) {
55616 + switch (request) {
55617 + case PTRACE_SEIZE:
55618 + case PTRACE_POKETEXT:
55619 + case PTRACE_POKEDATA:
55620 + case PTRACE_POKEUSR:
55621 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
55622 + case PTRACE_SETREGS:
55623 + case PTRACE_SETFPREGS:
55624 +#endif
55625 +#ifdef CONFIG_X86
55626 + case PTRACE_SETFPXREGS:
55627 +#endif
55628 +#ifdef CONFIG_ALTIVEC
55629 + case PTRACE_SETVRREGS:
55630 +#endif
55631 + return 1;
55632 + default:
55633 + return 0;
55634 + }
55635 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
55636 + !(current->role->roletype & GR_ROLE_GOD) &&
55637 + (current->acl != task->acl)) {
55638 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55639 + return 1;
55640 + }
55641 +
55642 + return 0;
55643 +}
55644 +
55645 +static int is_writable_mmap(const struct file *filp)
55646 +{
55647 + struct task_struct *task = current;
55648 + struct acl_object_label *obj, *obj2;
55649 +
55650 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
55651 + !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))) {
55652 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
55653 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
55654 + task->role->root_label);
55655 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
55656 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
55657 + return 1;
55658 + }
55659 + }
55660 + return 0;
55661 +}
55662 +
55663 +int
55664 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
55665 +{
55666 + __u32 mode;
55667 +
55668 + if (unlikely(!file || !(prot & PROT_EXEC)))
55669 + return 1;
55670 +
55671 + if (is_writable_mmap(file))
55672 + return 0;
55673 +
55674 + mode =
55675 + gr_search_file(file->f_path.dentry,
55676 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
55677 + file->f_path.mnt);
55678 +
55679 + if (!gr_tpe_allow(file))
55680 + return 0;
55681 +
55682 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
55683 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55684 + return 0;
55685 + } else if (unlikely(!(mode & GR_EXEC))) {
55686 + return 0;
55687 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
55688 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55689 + return 1;
55690 + }
55691 +
55692 + return 1;
55693 +}
55694 +
55695 +int
55696 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
55697 +{
55698 + __u32 mode;
55699 +
55700 + if (unlikely(!file || !(prot & PROT_EXEC)))
55701 + return 1;
55702 +
55703 + if (is_writable_mmap(file))
55704 + return 0;
55705 +
55706 + mode =
55707 + gr_search_file(file->f_path.dentry,
55708 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
55709 + file->f_path.mnt);
55710 +
55711 + if (!gr_tpe_allow(file))
55712 + return 0;
55713 +
55714 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
55715 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55716 + return 0;
55717 + } else if (unlikely(!(mode & GR_EXEC))) {
55718 + return 0;
55719 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
55720 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55721 + return 1;
55722 + }
55723 +
55724 + return 1;
55725 +}
55726 +
55727 +void
55728 +gr_acl_handle_psacct(struct task_struct *task, const long code)
55729 +{
55730 + unsigned long runtime;
55731 + unsigned long cputime;
55732 + unsigned int wday, cday;
55733 + __u8 whr, chr;
55734 + __u8 wmin, cmin;
55735 + __u8 wsec, csec;
55736 + struct timespec timeval;
55737 +
55738 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
55739 + !(task->acl->mode & GR_PROCACCT)))
55740 + return;
55741 +
55742 + do_posix_clock_monotonic_gettime(&timeval);
55743 + runtime = timeval.tv_sec - task->start_time.tv_sec;
55744 + wday = runtime / (3600 * 24);
55745 + runtime -= wday * (3600 * 24);
55746 + whr = runtime / 3600;
55747 + runtime -= whr * 3600;
55748 + wmin = runtime / 60;
55749 + runtime -= wmin * 60;
55750 + wsec = runtime;
55751 +
55752 + cputime = (task->utime + task->stime) / HZ;
55753 + cday = cputime / (3600 * 24);
55754 + cputime -= cday * (3600 * 24);
55755 + chr = cputime / 3600;
55756 + cputime -= chr * 3600;
55757 + cmin = cputime / 60;
55758 + cputime -= cmin * 60;
55759 + csec = cputime;
55760 +
55761 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
55762 +
55763 + return;
55764 +}
55765 +
55766 +void gr_set_kernel_label(struct task_struct *task)
55767 +{
55768 + if (gr_status & GR_READY) {
55769 + task->role = kernel_role;
55770 + task->acl = kernel_role->root_label;
55771 + }
55772 + return;
55773 +}
55774 +
55775 +#ifdef CONFIG_TASKSTATS
55776 +int gr_is_taskstats_denied(int pid)
55777 +{
55778 + struct task_struct *task;
55779 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55780 + const struct cred *cred;
55781 +#endif
55782 + int ret = 0;
55783 +
55784 + /* restrict taskstats viewing to un-chrooted root users
55785 + who have the 'view' subject flag if the RBAC system is enabled
55786 + */
55787 +
55788 + rcu_read_lock();
55789 + read_lock(&tasklist_lock);
55790 + task = find_task_by_vpid(pid);
55791 + if (task) {
55792 +#ifdef CONFIG_GRKERNSEC_CHROOT
55793 + if (proc_is_chrooted(task))
55794 + ret = -EACCES;
55795 +#endif
55796 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55797 + cred = __task_cred(task);
55798 +#ifdef CONFIG_GRKERNSEC_PROC_USER
55799 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID))
55800 + ret = -EACCES;
55801 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55802 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && !groups_search(cred->group_info, grsec_proc_gid))
55803 + ret = -EACCES;
55804 +#endif
55805 +#endif
55806 + if (gr_status & GR_READY) {
55807 + if (!(task->acl->mode & GR_VIEW))
55808 + ret = -EACCES;
55809 + }
55810 + } else
55811 + ret = -ENOENT;
55812 +
55813 + read_unlock(&tasklist_lock);
55814 + rcu_read_unlock();
55815 +
55816 + return ret;
55817 +}
55818 +#endif
55819 +
55820 +/* AUXV entries are filled via a descendant of search_binary_handler
55821 + after we've already applied the subject for the target
55822 +*/
55823 +int gr_acl_enable_at_secure(void)
55824 +{
55825 + if (unlikely(!(gr_status & GR_READY)))
55826 + return 0;
55827 +
55828 + if (current->acl->mode & GR_ATSECURE)
55829 + return 1;
55830 +
55831 + return 0;
55832 +}
55833 +
55834 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
55835 +{
55836 + struct task_struct *task = current;
55837 + struct dentry *dentry = file->f_path.dentry;
55838 + struct vfsmount *mnt = file->f_path.mnt;
55839 + struct acl_object_label *obj, *tmp;
55840 + struct acl_subject_label *subj;
55841 + unsigned int bufsize;
55842 + int is_not_root;
55843 + char *path;
55844 + dev_t dev = __get_dev(dentry);
55845 +
55846 + if (unlikely(!(gr_status & GR_READY)))
55847 + return 1;
55848 +
55849 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
55850 + return 1;
55851 +
55852 + /* ignore Eric Biederman */
55853 + if (IS_PRIVATE(dentry->d_inode))
55854 + return 1;
55855 +
55856 + subj = task->acl;
55857 + read_lock(&gr_inode_lock);
55858 + do {
55859 + obj = lookup_acl_obj_label(ino, dev, subj);
55860 + if (obj != NULL) {
55861 + read_unlock(&gr_inode_lock);
55862 + return (obj->mode & GR_FIND) ? 1 : 0;
55863 + }
55864 + } while ((subj = subj->parent_subject));
55865 + read_unlock(&gr_inode_lock);
55866 +
55867 + /* this is purely an optimization since we're looking for an object
55868 + for the directory we're doing a readdir on
55869 + if it's possible for any globbed object to match the entry we're
55870 + filling into the directory, then the object we find here will be
55871 + an anchor point with attached globbed objects
55872 + */
55873 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
55874 + if (obj->globbed == NULL)
55875 + return (obj->mode & GR_FIND) ? 1 : 0;
55876 +
55877 + is_not_root = ((obj->filename[0] == '/') &&
55878 + (obj->filename[1] == '\0')) ? 0 : 1;
55879 + bufsize = PAGE_SIZE - namelen - is_not_root;
55880 +
55881 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
55882 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
55883 + return 1;
55884 +
55885 + preempt_disable();
55886 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
55887 + bufsize);
55888 +
55889 + bufsize = strlen(path);
55890 +
55891 + /* if base is "/", don't append an additional slash */
55892 + if (is_not_root)
55893 + *(path + bufsize) = '/';
55894 + memcpy(path + bufsize + is_not_root, name, namelen);
55895 + *(path + bufsize + namelen + is_not_root) = '\0';
55896 +
55897 + tmp = obj->globbed;
55898 + while (tmp) {
55899 + if (!glob_match(tmp->filename, path)) {
55900 + preempt_enable();
55901 + return (tmp->mode & GR_FIND) ? 1 : 0;
55902 + }
55903 + tmp = tmp->next;
55904 + }
55905 + preempt_enable();
55906 + return (obj->mode & GR_FIND) ? 1 : 0;
55907 +}
55908 +
55909 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
55910 +EXPORT_SYMBOL(gr_acl_is_enabled);
55911 +#endif
55912 +EXPORT_SYMBOL(gr_learn_resource);
55913 +EXPORT_SYMBOL(gr_set_kernel_label);
55914 +#ifdef CONFIG_SECURITY
55915 +EXPORT_SYMBOL(gr_check_user_change);
55916 +EXPORT_SYMBOL(gr_check_group_change);
55917 +#endif
55918 +
55919 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
55920 new file mode 100644
55921 index 0000000..34fefda
55922 --- /dev/null
55923 +++ b/grsecurity/gracl_alloc.c
55924 @@ -0,0 +1,105 @@
55925 +#include <linux/kernel.h>
55926 +#include <linux/mm.h>
55927 +#include <linux/slab.h>
55928 +#include <linux/vmalloc.h>
55929 +#include <linux/gracl.h>
55930 +#include <linux/grsecurity.h>
55931 +
55932 +static unsigned long alloc_stack_next = 1;
55933 +static unsigned long alloc_stack_size = 1;
55934 +static void **alloc_stack;
55935 +
55936 +static __inline__ int
55937 +alloc_pop(void)
55938 +{
55939 + if (alloc_stack_next == 1)
55940 + return 0;
55941 +
55942 + kfree(alloc_stack[alloc_stack_next - 2]);
55943 +
55944 + alloc_stack_next--;
55945 +
55946 + return 1;
55947 +}
55948 +
55949 +static __inline__ int
55950 +alloc_push(void *buf)
55951 +{
55952 + if (alloc_stack_next >= alloc_stack_size)
55953 + return 1;
55954 +
55955 + alloc_stack[alloc_stack_next - 1] = buf;
55956 +
55957 + alloc_stack_next++;
55958 +
55959 + return 0;
55960 +}
55961 +
55962 +void *
55963 +acl_alloc(unsigned long len)
55964 +{
55965 + void *ret = NULL;
55966 +
55967 + if (!len || len > PAGE_SIZE)
55968 + goto out;
55969 +
55970 + ret = kmalloc(len, GFP_KERNEL);
55971 +
55972 + if (ret) {
55973 + if (alloc_push(ret)) {
55974 + kfree(ret);
55975 + ret = NULL;
55976 + }
55977 + }
55978 +
55979 +out:
55980 + return ret;
55981 +}
55982 +
55983 +void *
55984 +acl_alloc_num(unsigned long num, unsigned long len)
55985 +{
55986 + if (!len || (num > (PAGE_SIZE / len)))
55987 + return NULL;
55988 +
55989 + return acl_alloc(num * len);
55990 +}
55991 +
55992 +void
55993 +acl_free_all(void)
55994 +{
55995 + if (gr_acl_is_enabled() || !alloc_stack)
55996 + return;
55997 +
55998 + while (alloc_pop()) ;
55999 +
56000 + if (alloc_stack) {
56001 + if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
56002 + kfree(alloc_stack);
56003 + else
56004 + vfree(alloc_stack);
56005 + }
56006 +
56007 + alloc_stack = NULL;
56008 + alloc_stack_size = 1;
56009 + alloc_stack_next = 1;
56010 +
56011 + return;
56012 +}
56013 +
56014 +int
56015 +acl_alloc_stack_init(unsigned long size)
56016 +{
56017 + if ((size * sizeof (void *)) <= PAGE_SIZE)
56018 + alloc_stack =
56019 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
56020 + else
56021 + alloc_stack = (void **) vmalloc(size * sizeof (void *));
56022 +
56023 + alloc_stack_size = size;
56024 +
56025 + if (!alloc_stack)
56026 + return 0;
56027 + else
56028 + return 1;
56029 +}
56030 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
56031 new file mode 100644
56032 index 0000000..6d21049
56033 --- /dev/null
56034 +++ b/grsecurity/gracl_cap.c
56035 @@ -0,0 +1,110 @@
56036 +#include <linux/kernel.h>
56037 +#include <linux/module.h>
56038 +#include <linux/sched.h>
56039 +#include <linux/gracl.h>
56040 +#include <linux/grsecurity.h>
56041 +#include <linux/grinternal.h>
56042 +
56043 +extern const char *captab_log[];
56044 +extern int captab_log_entries;
56045 +
56046 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
56047 +{
56048 + struct acl_subject_label *curracl;
56049 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
56050 + kernel_cap_t cap_audit = __cap_empty_set;
56051 +
56052 + if (!gr_acl_is_enabled())
56053 + return 1;
56054 +
56055 + curracl = task->acl;
56056 +
56057 + cap_drop = curracl->cap_lower;
56058 + cap_mask = curracl->cap_mask;
56059 + cap_audit = curracl->cap_invert_audit;
56060 +
56061 + while ((curracl = curracl->parent_subject)) {
56062 + /* if the cap isn't specified in the current computed mask but is specified in the
56063 + current level subject, and is lowered in the current level subject, then add
56064 + it to the set of dropped capabilities
56065 + otherwise, add the current level subject's mask to the current computed mask
56066 + */
56067 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
56068 + cap_raise(cap_mask, cap);
56069 + if (cap_raised(curracl->cap_lower, cap))
56070 + cap_raise(cap_drop, cap);
56071 + if (cap_raised(curracl->cap_invert_audit, cap))
56072 + cap_raise(cap_audit, cap);
56073 + }
56074 + }
56075 +
56076 + if (!cap_raised(cap_drop, cap)) {
56077 + if (cap_raised(cap_audit, cap))
56078 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
56079 + return 1;
56080 + }
56081 +
56082 + curracl = task->acl;
56083 +
56084 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
56085 + && cap_raised(cred->cap_effective, cap)) {
56086 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
56087 + task->role->roletype, cred->uid,
56088 + cred->gid, task->exec_file ?
56089 + gr_to_filename(task->exec_file->f_path.dentry,
56090 + task->exec_file->f_path.mnt) : curracl->filename,
56091 + curracl->filename, 0UL,
56092 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
56093 + return 1;
56094 + }
56095 +
56096 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
56097 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
56098 +
56099 + return 0;
56100 +}
56101 +
56102 +int
56103 +gr_acl_is_capable(const int cap)
56104 +{
56105 + return gr_task_acl_is_capable(current, current_cred(), cap);
56106 +}
56107 +
56108 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
56109 +{
56110 + struct acl_subject_label *curracl;
56111 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
56112 +
56113 + if (!gr_acl_is_enabled())
56114 + return 1;
56115 +
56116 + curracl = task->acl;
56117 +
56118 + cap_drop = curracl->cap_lower;
56119 + cap_mask = curracl->cap_mask;
56120 +
56121 + while ((curracl = curracl->parent_subject)) {
56122 + /* if the cap isn't specified in the current computed mask but is specified in the
56123 + current level subject, and is lowered in the current level subject, then add
56124 + it to the set of dropped capabilities
56125 + otherwise, add the current level subject's mask to the current computed mask
56126 + */
56127 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
56128 + cap_raise(cap_mask, cap);
56129 + if (cap_raised(curracl->cap_lower, cap))
56130 + cap_raise(cap_drop, cap);
56131 + }
56132 + }
56133 +
56134 + if (!cap_raised(cap_drop, cap))
56135 + return 1;
56136 +
56137 + return 0;
56138 +}
56139 +
56140 +int
56141 +gr_acl_is_capable_nolog(const int cap)
56142 +{
56143 + return gr_task_acl_is_capable_nolog(current, cap);
56144 +}
56145 +
56146 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
56147 new file mode 100644
56148 index 0000000..d28e241
56149 --- /dev/null
56150 +++ b/grsecurity/gracl_fs.c
56151 @@ -0,0 +1,437 @@
56152 +#include <linux/kernel.h>
56153 +#include <linux/sched.h>
56154 +#include <linux/types.h>
56155 +#include <linux/fs.h>
56156 +#include <linux/file.h>
56157 +#include <linux/stat.h>
56158 +#include <linux/grsecurity.h>
56159 +#include <linux/grinternal.h>
56160 +#include <linux/gracl.h>
56161 +
56162 +umode_t
56163 +gr_acl_umask(void)
56164 +{
56165 + if (unlikely(!gr_acl_is_enabled()))
56166 + return 0;
56167 +
56168 + return current->role->umask;
56169 +}
56170 +
56171 +__u32
56172 +gr_acl_handle_hidden_file(const struct dentry * dentry,
56173 + const struct vfsmount * mnt)
56174 +{
56175 + __u32 mode;
56176 +
56177 + if (unlikely(!dentry->d_inode))
56178 + return GR_FIND;
56179 +
56180 + mode =
56181 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
56182 +
56183 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
56184 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
56185 + return mode;
56186 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
56187 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
56188 + return 0;
56189 + } else if (unlikely(!(mode & GR_FIND)))
56190 + return 0;
56191 +
56192 + return GR_FIND;
56193 +}
56194 +
56195 +__u32
56196 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
56197 + int acc_mode)
56198 +{
56199 + __u32 reqmode = GR_FIND;
56200 + __u32 mode;
56201 +
56202 + if (unlikely(!dentry->d_inode))
56203 + return reqmode;
56204 +
56205 + if (acc_mode & MAY_APPEND)
56206 + reqmode |= GR_APPEND;
56207 + else if (acc_mode & MAY_WRITE)
56208 + reqmode |= GR_WRITE;
56209 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
56210 + reqmode |= GR_READ;
56211 +
56212 + mode =
56213 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
56214 + mnt);
56215 +
56216 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
56217 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
56218 + reqmode & GR_READ ? " reading" : "",
56219 + reqmode & GR_WRITE ? " writing" : reqmode &
56220 + GR_APPEND ? " appending" : "");
56221 + return reqmode;
56222 + } else
56223 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
56224 + {
56225 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
56226 + reqmode & GR_READ ? " reading" : "",
56227 + reqmode & GR_WRITE ? " writing" : reqmode &
56228 + GR_APPEND ? " appending" : "");
56229 + return 0;
56230 + } else if (unlikely((mode & reqmode) != reqmode))
56231 + return 0;
56232 +
56233 + return reqmode;
56234 +}
56235 +
56236 +__u32
56237 +gr_acl_handle_creat(const struct dentry * dentry,
56238 + const struct dentry * p_dentry,
56239 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
56240 + const int imode)
56241 +{
56242 + __u32 reqmode = GR_WRITE | GR_CREATE;
56243 + __u32 mode;
56244 +
56245 + if (acc_mode & MAY_APPEND)
56246 + reqmode |= GR_APPEND;
56247 + // if a directory was required or the directory already exists, then
56248 + // don't count this open as a read
56249 + if ((acc_mode & MAY_READ) &&
56250 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
56251 + reqmode |= GR_READ;
56252 + if ((open_flags & O_CREAT) &&
56253 + ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
56254 + reqmode |= GR_SETID;
56255 +
56256 + mode =
56257 + gr_check_create(dentry, p_dentry, p_mnt,
56258 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
56259 +
56260 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
56261 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
56262 + reqmode & GR_READ ? " reading" : "",
56263 + reqmode & GR_WRITE ? " writing" : reqmode &
56264 + GR_APPEND ? " appending" : "");
56265 + return reqmode;
56266 + } else
56267 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
56268 + {
56269 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
56270 + reqmode & GR_READ ? " reading" : "",
56271 + reqmode & GR_WRITE ? " writing" : reqmode &
56272 + GR_APPEND ? " appending" : "");
56273 + return 0;
56274 + } else if (unlikely((mode & reqmode) != reqmode))
56275 + return 0;
56276 +
56277 + return reqmode;
56278 +}
56279 +
56280 +__u32
56281 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
56282 + const int fmode)
56283 +{
56284 + __u32 mode, reqmode = GR_FIND;
56285 +
56286 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
56287 + reqmode |= GR_EXEC;
56288 + if (fmode & S_IWOTH)
56289 + reqmode |= GR_WRITE;
56290 + if (fmode & S_IROTH)
56291 + reqmode |= GR_READ;
56292 +
56293 + mode =
56294 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
56295 + mnt);
56296 +
56297 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
56298 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
56299 + reqmode & GR_READ ? " reading" : "",
56300 + reqmode & GR_WRITE ? " writing" : "",
56301 + reqmode & GR_EXEC ? " executing" : "");
56302 + return reqmode;
56303 + } else
56304 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
56305 + {
56306 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
56307 + reqmode & GR_READ ? " reading" : "",
56308 + reqmode & GR_WRITE ? " writing" : "",
56309 + reqmode & GR_EXEC ? " executing" : "");
56310 + return 0;
56311 + } else if (unlikely((mode & reqmode) != reqmode))
56312 + return 0;
56313 +
56314 + return reqmode;
56315 +}
56316 +
56317 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
56318 +{
56319 + __u32 mode;
56320 +
56321 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
56322 +
56323 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
56324 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
56325 + return mode;
56326 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
56327 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
56328 + return 0;
56329 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
56330 + return 0;
56331 +
56332 + return (reqmode);
56333 +}
56334 +
56335 +__u32
56336 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
56337 +{
56338 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
56339 +}
56340 +
56341 +__u32
56342 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
56343 +{
56344 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
56345 +}
56346 +
56347 +__u32
56348 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
56349 +{
56350 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
56351 +}
56352 +
56353 +__u32
56354 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
56355 +{
56356 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
56357 +}
56358 +
56359 +__u32
56360 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
56361 + umode_t *modeptr)
56362 +{
56363 + umode_t mode;
56364 +
56365 + *modeptr &= ~gr_acl_umask();
56366 + mode = *modeptr;
56367 +
56368 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
56369 + return 1;
56370 +
56371 + if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
56372 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
56373 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
56374 + GR_CHMOD_ACL_MSG);
56375 + } else {
56376 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
56377 + }
56378 +}
56379 +
56380 +__u32
56381 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
56382 +{
56383 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
56384 +}
56385 +
56386 +__u32
56387 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
56388 +{
56389 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
56390 +}
56391 +
56392 +__u32
56393 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
56394 +{
56395 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
56396 +}
56397 +
56398 +__u32
56399 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
56400 +{
56401 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
56402 + GR_UNIXCONNECT_ACL_MSG);
56403 +}
56404 +
56405 +/* hardlinks require at minimum create and link permission,
56406 + any additional privilege required is based on the
56407 + privilege of the file being linked to
56408 +*/
56409 +__u32
56410 +gr_acl_handle_link(const struct dentry * new_dentry,
56411 + const struct dentry * parent_dentry,
56412 + const struct vfsmount * parent_mnt,
56413 + const struct dentry * old_dentry,
56414 + const struct vfsmount * old_mnt, const char *to)
56415 +{
56416 + __u32 mode;
56417 + __u32 needmode = GR_CREATE | GR_LINK;
56418 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
56419 +
56420 + mode =
56421 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
56422 + old_mnt);
56423 +
56424 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
56425 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
56426 + return mode;
56427 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
56428 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
56429 + return 0;
56430 + } else if (unlikely((mode & needmode) != needmode))
56431 + return 0;
56432 +
56433 + return 1;
56434 +}
56435 +
56436 +__u32
56437 +gr_acl_handle_symlink(const struct dentry * new_dentry,
56438 + const struct dentry * parent_dentry,
56439 + const struct vfsmount * parent_mnt, const char *from)
56440 +{
56441 + __u32 needmode = GR_WRITE | GR_CREATE;
56442 + __u32 mode;
56443 +
56444 + mode =
56445 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
56446 + GR_CREATE | GR_AUDIT_CREATE |
56447 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
56448 +
56449 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
56450 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
56451 + return mode;
56452 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
56453 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
56454 + return 0;
56455 + } else if (unlikely((mode & needmode) != needmode))
56456 + return 0;
56457 +
56458 + return (GR_WRITE | GR_CREATE);
56459 +}
56460 +
56461 +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)
56462 +{
56463 + __u32 mode;
56464 +
56465 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
56466 +
56467 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
56468 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
56469 + return mode;
56470 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
56471 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
56472 + return 0;
56473 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
56474 + return 0;
56475 +
56476 + return (reqmode);
56477 +}
56478 +
56479 +__u32
56480 +gr_acl_handle_mknod(const struct dentry * new_dentry,
56481 + const struct dentry * parent_dentry,
56482 + const struct vfsmount * parent_mnt,
56483 + const int mode)
56484 +{
56485 + __u32 reqmode = GR_WRITE | GR_CREATE;
56486 + if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
56487 + reqmode |= GR_SETID;
56488 +
56489 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
56490 + reqmode, GR_MKNOD_ACL_MSG);
56491 +}
56492 +
56493 +__u32
56494 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
56495 + const struct dentry *parent_dentry,
56496 + const struct vfsmount *parent_mnt)
56497 +{
56498 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
56499 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
56500 +}
56501 +
56502 +#define RENAME_CHECK_SUCCESS(old, new) \
56503 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
56504 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
56505 +
56506 +int
56507 +gr_acl_handle_rename(struct dentry *new_dentry,
56508 + struct dentry *parent_dentry,
56509 + const struct vfsmount *parent_mnt,
56510 + struct dentry *old_dentry,
56511 + struct inode *old_parent_inode,
56512 + struct vfsmount *old_mnt, const char *newname)
56513 +{
56514 + __u32 comp1, comp2;
56515 + int error = 0;
56516 +
56517 + if (unlikely(!gr_acl_is_enabled()))
56518 + return 0;
56519 +
56520 + if (!new_dentry->d_inode) {
56521 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
56522 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
56523 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
56524 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
56525 + GR_DELETE | GR_AUDIT_DELETE |
56526 + GR_AUDIT_READ | GR_AUDIT_WRITE |
56527 + GR_SUPPRESS, old_mnt);
56528 + } else {
56529 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
56530 + GR_CREATE | GR_DELETE |
56531 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
56532 + GR_AUDIT_READ | GR_AUDIT_WRITE |
56533 + GR_SUPPRESS, parent_mnt);
56534 + comp2 =
56535 + gr_search_file(old_dentry,
56536 + GR_READ | GR_WRITE | GR_AUDIT_READ |
56537 + GR_DELETE | GR_AUDIT_DELETE |
56538 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
56539 + }
56540 +
56541 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
56542 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
56543 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
56544 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
56545 + && !(comp2 & GR_SUPPRESS)) {
56546 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
56547 + error = -EACCES;
56548 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
56549 + error = -EACCES;
56550 +
56551 + return error;
56552 +}
56553 +
56554 +void
56555 +gr_acl_handle_exit(void)
56556 +{
56557 + u16 id;
56558 + char *rolename;
56559 + struct file *exec_file;
56560 +
56561 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
56562 + !(current->role->roletype & GR_ROLE_PERSIST))) {
56563 + id = current->acl_role_id;
56564 + rolename = current->role->rolename;
56565 + gr_set_acls(1);
56566 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
56567 + }
56568 +
56569 + write_lock(&grsec_exec_file_lock);
56570 + exec_file = current->exec_file;
56571 + current->exec_file = NULL;
56572 + write_unlock(&grsec_exec_file_lock);
56573 +
56574 + if (exec_file)
56575 + fput(exec_file);
56576 +}
56577 +
56578 +int
56579 +gr_acl_handle_procpidmem(const struct task_struct *task)
56580 +{
56581 + if (unlikely(!gr_acl_is_enabled()))
56582 + return 0;
56583 +
56584 + if (task != current && task->acl->mode & GR_PROTPROCFD)
56585 + return -EACCES;
56586 +
56587 + return 0;
56588 +}
56589 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
56590 new file mode 100644
56591 index 0000000..58800a7
56592 --- /dev/null
56593 +++ b/grsecurity/gracl_ip.c
56594 @@ -0,0 +1,384 @@
56595 +#include <linux/kernel.h>
56596 +#include <asm/uaccess.h>
56597 +#include <asm/errno.h>
56598 +#include <net/sock.h>
56599 +#include <linux/file.h>
56600 +#include <linux/fs.h>
56601 +#include <linux/net.h>
56602 +#include <linux/in.h>
56603 +#include <linux/skbuff.h>
56604 +#include <linux/ip.h>
56605 +#include <linux/udp.h>
56606 +#include <linux/types.h>
56607 +#include <linux/sched.h>
56608 +#include <linux/netdevice.h>
56609 +#include <linux/inetdevice.h>
56610 +#include <linux/gracl.h>
56611 +#include <linux/grsecurity.h>
56612 +#include <linux/grinternal.h>
56613 +
56614 +#define GR_BIND 0x01
56615 +#define GR_CONNECT 0x02
56616 +#define GR_INVERT 0x04
56617 +#define GR_BINDOVERRIDE 0x08
56618 +#define GR_CONNECTOVERRIDE 0x10
56619 +#define GR_SOCK_FAMILY 0x20
56620 +
56621 +static const char * gr_protocols[IPPROTO_MAX] = {
56622 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
56623 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
56624 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
56625 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
56626 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
56627 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
56628 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
56629 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
56630 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
56631 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
56632 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
56633 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
56634 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
56635 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
56636 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
56637 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
56638 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
56639 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
56640 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
56641 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
56642 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
56643 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
56644 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
56645 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
56646 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
56647 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
56648 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
56649 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
56650 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
56651 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
56652 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
56653 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
56654 + };
56655 +
56656 +static const char * gr_socktypes[SOCK_MAX] = {
56657 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
56658 + "unknown:7", "unknown:8", "unknown:9", "packet"
56659 + };
56660 +
56661 +static const char * gr_sockfamilies[AF_MAX+1] = {
56662 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
56663 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
56664 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
56665 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
56666 + };
56667 +
56668 +const char *
56669 +gr_proto_to_name(unsigned char proto)
56670 +{
56671 + return gr_protocols[proto];
56672 +}
56673 +
56674 +const char *
56675 +gr_socktype_to_name(unsigned char type)
56676 +{
56677 + return gr_socktypes[type];
56678 +}
56679 +
56680 +const char *
56681 +gr_sockfamily_to_name(unsigned char family)
56682 +{
56683 + return gr_sockfamilies[family];
56684 +}
56685 +
56686 +int
56687 +gr_search_socket(const int domain, const int type, const int protocol)
56688 +{
56689 + struct acl_subject_label *curr;
56690 + const struct cred *cred = current_cred();
56691 +
56692 + if (unlikely(!gr_acl_is_enabled()))
56693 + goto exit;
56694 +
56695 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
56696 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
56697 + goto exit; // let the kernel handle it
56698 +
56699 + curr = current->acl;
56700 +
56701 + if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
56702 + /* the family is allowed, if this is PF_INET allow it only if
56703 + the extra sock type/protocol checks pass */
56704 + if (domain == PF_INET)
56705 + goto inet_check;
56706 + goto exit;
56707 + } else {
56708 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56709 + __u32 fakeip = 0;
56710 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56711 + current->role->roletype, cred->uid,
56712 + cred->gid, current->exec_file ?
56713 + gr_to_filename(current->exec_file->f_path.dentry,
56714 + current->exec_file->f_path.mnt) :
56715 + curr->filename, curr->filename,
56716 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
56717 + &current->signal->saved_ip);
56718 + goto exit;
56719 + }
56720 + goto exit_fail;
56721 + }
56722 +
56723 +inet_check:
56724 + /* the rest of this checking is for IPv4 only */
56725 + if (!curr->ips)
56726 + goto exit;
56727 +
56728 + if ((curr->ip_type & (1 << type)) &&
56729 + (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
56730 + goto exit;
56731 +
56732 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56733 + /* we don't place acls on raw sockets , and sometimes
56734 + dgram/ip sockets are opened for ioctl and not
56735 + bind/connect, so we'll fake a bind learn log */
56736 + if (type == SOCK_RAW || type == SOCK_PACKET) {
56737 + __u32 fakeip = 0;
56738 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56739 + current->role->roletype, cred->uid,
56740 + cred->gid, current->exec_file ?
56741 + gr_to_filename(current->exec_file->f_path.dentry,
56742 + current->exec_file->f_path.mnt) :
56743 + curr->filename, curr->filename,
56744 + &fakeip, 0, type,
56745 + protocol, GR_CONNECT, &current->signal->saved_ip);
56746 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
56747 + __u32 fakeip = 0;
56748 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56749 + current->role->roletype, cred->uid,
56750 + cred->gid, current->exec_file ?
56751 + gr_to_filename(current->exec_file->f_path.dentry,
56752 + current->exec_file->f_path.mnt) :
56753 + curr->filename, curr->filename,
56754 + &fakeip, 0, type,
56755 + protocol, GR_BIND, &current->signal->saved_ip);
56756 + }
56757 + /* we'll log when they use connect or bind */
56758 + goto exit;
56759 + }
56760 +
56761 +exit_fail:
56762 + if (domain == PF_INET)
56763 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
56764 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
56765 + else
56766 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
56767 + gr_socktype_to_name(type), protocol);
56768 +
56769 + return 0;
56770 +exit:
56771 + return 1;
56772 +}
56773 +
56774 +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)
56775 +{
56776 + if ((ip->mode & mode) &&
56777 + (ip_port >= ip->low) &&
56778 + (ip_port <= ip->high) &&
56779 + ((ntohl(ip_addr) & our_netmask) ==
56780 + (ntohl(our_addr) & our_netmask))
56781 + && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
56782 + && (ip->type & (1 << type))) {
56783 + if (ip->mode & GR_INVERT)
56784 + return 2; // specifically denied
56785 + else
56786 + return 1; // allowed
56787 + }
56788 +
56789 + return 0; // not specifically allowed, may continue parsing
56790 +}
56791 +
56792 +static int
56793 +gr_search_connectbind(const int full_mode, struct sock *sk,
56794 + struct sockaddr_in *addr, const int type)
56795 +{
56796 + char iface[IFNAMSIZ] = {0};
56797 + struct acl_subject_label *curr;
56798 + struct acl_ip_label *ip;
56799 + struct inet_sock *isk;
56800 + struct net_device *dev;
56801 + struct in_device *idev;
56802 + unsigned long i;
56803 + int ret;
56804 + int mode = full_mode & (GR_BIND | GR_CONNECT);
56805 + __u32 ip_addr = 0;
56806 + __u32 our_addr;
56807 + __u32 our_netmask;
56808 + char *p;
56809 + __u16 ip_port = 0;
56810 + const struct cred *cred = current_cred();
56811 +
56812 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
56813 + return 0;
56814 +
56815 + curr = current->acl;
56816 + isk = inet_sk(sk);
56817 +
56818 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
56819 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
56820 + addr->sin_addr.s_addr = curr->inaddr_any_override;
56821 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
56822 + struct sockaddr_in saddr;
56823 + int err;
56824 +
56825 + saddr.sin_family = AF_INET;
56826 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
56827 + saddr.sin_port = isk->inet_sport;
56828 +
56829 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
56830 + if (err)
56831 + return err;
56832 +
56833 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
56834 + if (err)
56835 + return err;
56836 + }
56837 +
56838 + if (!curr->ips)
56839 + return 0;
56840 +
56841 + ip_addr = addr->sin_addr.s_addr;
56842 + ip_port = ntohs(addr->sin_port);
56843 +
56844 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56845 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56846 + current->role->roletype, cred->uid,
56847 + cred->gid, current->exec_file ?
56848 + gr_to_filename(current->exec_file->f_path.dentry,
56849 + current->exec_file->f_path.mnt) :
56850 + curr->filename, curr->filename,
56851 + &ip_addr, ip_port, type,
56852 + sk->sk_protocol, mode, &current->signal->saved_ip);
56853 + return 0;
56854 + }
56855 +
56856 + for (i = 0; i < curr->ip_num; i++) {
56857 + ip = *(curr->ips + i);
56858 + if (ip->iface != NULL) {
56859 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
56860 + p = strchr(iface, ':');
56861 + if (p != NULL)
56862 + *p = '\0';
56863 + dev = dev_get_by_name(sock_net(sk), iface);
56864 + if (dev == NULL)
56865 + continue;
56866 + idev = in_dev_get(dev);
56867 + if (idev == NULL) {
56868 + dev_put(dev);
56869 + continue;
56870 + }
56871 + rcu_read_lock();
56872 + for_ifa(idev) {
56873 + if (!strcmp(ip->iface, ifa->ifa_label)) {
56874 + our_addr = ifa->ifa_address;
56875 + our_netmask = 0xffffffff;
56876 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
56877 + if (ret == 1) {
56878 + rcu_read_unlock();
56879 + in_dev_put(idev);
56880 + dev_put(dev);
56881 + return 0;
56882 + } else if (ret == 2) {
56883 + rcu_read_unlock();
56884 + in_dev_put(idev);
56885 + dev_put(dev);
56886 + goto denied;
56887 + }
56888 + }
56889 + } endfor_ifa(idev);
56890 + rcu_read_unlock();
56891 + in_dev_put(idev);
56892 + dev_put(dev);
56893 + } else {
56894 + our_addr = ip->addr;
56895 + our_netmask = ip->netmask;
56896 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
56897 + if (ret == 1)
56898 + return 0;
56899 + else if (ret == 2)
56900 + goto denied;
56901 + }
56902 + }
56903 +
56904 +denied:
56905 + if (mode == GR_BIND)
56906 + 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));
56907 + else if (mode == GR_CONNECT)
56908 + 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));
56909 +
56910 + return -EACCES;
56911 +}
56912 +
56913 +int
56914 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
56915 +{
56916 + /* always allow disconnection of dgram sockets with connect */
56917 + if (addr->sin_family == AF_UNSPEC)
56918 + return 0;
56919 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
56920 +}
56921 +
56922 +int
56923 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
56924 +{
56925 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
56926 +}
56927 +
56928 +int gr_search_listen(struct socket *sock)
56929 +{
56930 + struct sock *sk = sock->sk;
56931 + struct sockaddr_in addr;
56932 +
56933 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56934 + addr.sin_port = inet_sk(sk)->inet_sport;
56935 +
56936 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56937 +}
56938 +
56939 +int gr_search_accept(struct socket *sock)
56940 +{
56941 + struct sock *sk = sock->sk;
56942 + struct sockaddr_in addr;
56943 +
56944 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56945 + addr.sin_port = inet_sk(sk)->inet_sport;
56946 +
56947 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56948 +}
56949 +
56950 +int
56951 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
56952 +{
56953 + if (addr)
56954 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
56955 + else {
56956 + struct sockaddr_in sin;
56957 + const struct inet_sock *inet = inet_sk(sk);
56958 +
56959 + sin.sin_addr.s_addr = inet->inet_daddr;
56960 + sin.sin_port = inet->inet_dport;
56961 +
56962 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56963 + }
56964 +}
56965 +
56966 +int
56967 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
56968 +{
56969 + struct sockaddr_in sin;
56970 +
56971 + if (unlikely(skb->len < sizeof (struct udphdr)))
56972 + return 0; // skip this packet
56973 +
56974 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
56975 + sin.sin_port = udp_hdr(skb)->source;
56976 +
56977 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56978 +}
56979 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
56980 new file mode 100644
56981 index 0000000..25f54ef
56982 --- /dev/null
56983 +++ b/grsecurity/gracl_learn.c
56984 @@ -0,0 +1,207 @@
56985 +#include <linux/kernel.h>
56986 +#include <linux/mm.h>
56987 +#include <linux/sched.h>
56988 +#include <linux/poll.h>
56989 +#include <linux/string.h>
56990 +#include <linux/file.h>
56991 +#include <linux/types.h>
56992 +#include <linux/vmalloc.h>
56993 +#include <linux/grinternal.h>
56994 +
56995 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
56996 + size_t count, loff_t *ppos);
56997 +extern int gr_acl_is_enabled(void);
56998 +
56999 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
57000 +static int gr_learn_attached;
57001 +
57002 +/* use a 512k buffer */
57003 +#define LEARN_BUFFER_SIZE (512 * 1024)
57004 +
57005 +static DEFINE_SPINLOCK(gr_learn_lock);
57006 +static DEFINE_MUTEX(gr_learn_user_mutex);
57007 +
57008 +/* we need to maintain two buffers, so that the kernel context of grlearn
57009 + uses a semaphore around the userspace copying, and the other kernel contexts
57010 + use a spinlock when copying into the buffer, since they cannot sleep
57011 +*/
57012 +static char *learn_buffer;
57013 +static char *learn_buffer_user;
57014 +static int learn_buffer_len;
57015 +static int learn_buffer_user_len;
57016 +
57017 +static ssize_t
57018 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
57019 +{
57020 + DECLARE_WAITQUEUE(wait, current);
57021 + ssize_t retval = 0;
57022 +
57023 + add_wait_queue(&learn_wait, &wait);
57024 + set_current_state(TASK_INTERRUPTIBLE);
57025 + do {
57026 + mutex_lock(&gr_learn_user_mutex);
57027 + spin_lock(&gr_learn_lock);
57028 + if (learn_buffer_len)
57029 + break;
57030 + spin_unlock(&gr_learn_lock);
57031 + mutex_unlock(&gr_learn_user_mutex);
57032 + if (file->f_flags & O_NONBLOCK) {
57033 + retval = -EAGAIN;
57034 + goto out;
57035 + }
57036 + if (signal_pending(current)) {
57037 + retval = -ERESTARTSYS;
57038 + goto out;
57039 + }
57040 +
57041 + schedule();
57042 + } while (1);
57043 +
57044 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
57045 + learn_buffer_user_len = learn_buffer_len;
57046 + retval = learn_buffer_len;
57047 + learn_buffer_len = 0;
57048 +
57049 + spin_unlock(&gr_learn_lock);
57050 +
57051 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
57052 + retval = -EFAULT;
57053 +
57054 + mutex_unlock(&gr_learn_user_mutex);
57055 +out:
57056 + set_current_state(TASK_RUNNING);
57057 + remove_wait_queue(&learn_wait, &wait);
57058 + return retval;
57059 +}
57060 +
57061 +static unsigned int
57062 +poll_learn(struct file * file, poll_table * wait)
57063 +{
57064 + poll_wait(file, &learn_wait, wait);
57065 +
57066 + if (learn_buffer_len)
57067 + return (POLLIN | POLLRDNORM);
57068 +
57069 + return 0;
57070 +}
57071 +
57072 +void
57073 +gr_clear_learn_entries(void)
57074 +{
57075 + char *tmp;
57076 +
57077 + mutex_lock(&gr_learn_user_mutex);
57078 + spin_lock(&gr_learn_lock);
57079 + tmp = learn_buffer;
57080 + learn_buffer = NULL;
57081 + spin_unlock(&gr_learn_lock);
57082 + if (tmp)
57083 + vfree(tmp);
57084 + if (learn_buffer_user != NULL) {
57085 + vfree(learn_buffer_user);
57086 + learn_buffer_user = NULL;
57087 + }
57088 + learn_buffer_len = 0;
57089 + mutex_unlock(&gr_learn_user_mutex);
57090 +
57091 + return;
57092 +}
57093 +
57094 +void
57095 +gr_add_learn_entry(const char *fmt, ...)
57096 +{
57097 + va_list args;
57098 + unsigned int len;
57099 +
57100 + if (!gr_learn_attached)
57101 + return;
57102 +
57103 + spin_lock(&gr_learn_lock);
57104 +
57105 + /* leave a gap at the end so we know when it's "full" but don't have to
57106 + compute the exact length of the string we're trying to append
57107 + */
57108 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
57109 + spin_unlock(&gr_learn_lock);
57110 + wake_up_interruptible(&learn_wait);
57111 + return;
57112 + }
57113 + if (learn_buffer == NULL) {
57114 + spin_unlock(&gr_learn_lock);
57115 + return;
57116 + }
57117 +
57118 + va_start(args, fmt);
57119 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
57120 + va_end(args);
57121 +
57122 + learn_buffer_len += len + 1;
57123 +
57124 + spin_unlock(&gr_learn_lock);
57125 + wake_up_interruptible(&learn_wait);
57126 +
57127 + return;
57128 +}
57129 +
57130 +static int
57131 +open_learn(struct inode *inode, struct file *file)
57132 +{
57133 + if (file->f_mode & FMODE_READ && gr_learn_attached)
57134 + return -EBUSY;
57135 + if (file->f_mode & FMODE_READ) {
57136 + int retval = 0;
57137 + mutex_lock(&gr_learn_user_mutex);
57138 + if (learn_buffer == NULL)
57139 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
57140 + if (learn_buffer_user == NULL)
57141 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
57142 + if (learn_buffer == NULL) {
57143 + retval = -ENOMEM;
57144 + goto out_error;
57145 + }
57146 + if (learn_buffer_user == NULL) {
57147 + retval = -ENOMEM;
57148 + goto out_error;
57149 + }
57150 + learn_buffer_len = 0;
57151 + learn_buffer_user_len = 0;
57152 + gr_learn_attached = 1;
57153 +out_error:
57154 + mutex_unlock(&gr_learn_user_mutex);
57155 + return retval;
57156 + }
57157 + return 0;
57158 +}
57159 +
57160 +static int
57161 +close_learn(struct inode *inode, struct file *file)
57162 +{
57163 + if (file->f_mode & FMODE_READ) {
57164 + char *tmp = NULL;
57165 + mutex_lock(&gr_learn_user_mutex);
57166 + spin_lock(&gr_learn_lock);
57167 + tmp = learn_buffer;
57168 + learn_buffer = NULL;
57169 + spin_unlock(&gr_learn_lock);
57170 + if (tmp)
57171 + vfree(tmp);
57172 + if (learn_buffer_user != NULL) {
57173 + vfree(learn_buffer_user);
57174 + learn_buffer_user = NULL;
57175 + }
57176 + learn_buffer_len = 0;
57177 + learn_buffer_user_len = 0;
57178 + gr_learn_attached = 0;
57179 + mutex_unlock(&gr_learn_user_mutex);
57180 + }
57181 +
57182 + return 0;
57183 +}
57184 +
57185 +const struct file_operations grsec_fops = {
57186 + .read = read_learn,
57187 + .write = write_grsec_handler,
57188 + .open = open_learn,
57189 + .release = close_learn,
57190 + .poll = poll_learn,
57191 +};
57192 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
57193 new file mode 100644
57194 index 0000000..39645c9
57195 --- /dev/null
57196 +++ b/grsecurity/gracl_res.c
57197 @@ -0,0 +1,68 @@
57198 +#include <linux/kernel.h>
57199 +#include <linux/sched.h>
57200 +#include <linux/gracl.h>
57201 +#include <linux/grinternal.h>
57202 +
57203 +static const char *restab_log[] = {
57204 + [RLIMIT_CPU] = "RLIMIT_CPU",
57205 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
57206 + [RLIMIT_DATA] = "RLIMIT_DATA",
57207 + [RLIMIT_STACK] = "RLIMIT_STACK",
57208 + [RLIMIT_CORE] = "RLIMIT_CORE",
57209 + [RLIMIT_RSS] = "RLIMIT_RSS",
57210 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
57211 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
57212 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
57213 + [RLIMIT_AS] = "RLIMIT_AS",
57214 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
57215 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
57216 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
57217 + [RLIMIT_NICE] = "RLIMIT_NICE",
57218 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
57219 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
57220 + [GR_CRASH_RES] = "RLIMIT_CRASH"
57221 +};
57222 +
57223 +void
57224 +gr_log_resource(const struct task_struct *task,
57225 + const int res, const unsigned long wanted, const int gt)
57226 +{
57227 + const struct cred *cred;
57228 + unsigned long rlim;
57229 +
57230 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
57231 + return;
57232 +
57233 + // not yet supported resource
57234 + if (unlikely(!restab_log[res]))
57235 + return;
57236 +
57237 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
57238 + rlim = task_rlimit_max(task, res);
57239 + else
57240 + rlim = task_rlimit(task, res);
57241 +
57242 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
57243 + return;
57244 +
57245 + rcu_read_lock();
57246 + cred = __task_cred(task);
57247 +
57248 + if (res == RLIMIT_NPROC &&
57249 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
57250 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
57251 + goto out_rcu_unlock;
57252 + else if (res == RLIMIT_MEMLOCK &&
57253 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
57254 + goto out_rcu_unlock;
57255 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
57256 + goto out_rcu_unlock;
57257 + rcu_read_unlock();
57258 +
57259 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
57260 +
57261 + return;
57262 +out_rcu_unlock:
57263 + rcu_read_unlock();
57264 + return;
57265 +}
57266 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
57267 new file mode 100644
57268 index 0000000..25197e9
57269 --- /dev/null
57270 +++ b/grsecurity/gracl_segv.c
57271 @@ -0,0 +1,299 @@
57272 +#include <linux/kernel.h>
57273 +#include <linux/mm.h>
57274 +#include <asm/uaccess.h>
57275 +#include <asm/errno.h>
57276 +#include <asm/mman.h>
57277 +#include <net/sock.h>
57278 +#include <linux/file.h>
57279 +#include <linux/fs.h>
57280 +#include <linux/net.h>
57281 +#include <linux/in.h>
57282 +#include <linux/slab.h>
57283 +#include <linux/types.h>
57284 +#include <linux/sched.h>
57285 +#include <linux/timer.h>
57286 +#include <linux/gracl.h>
57287 +#include <linux/grsecurity.h>
57288 +#include <linux/grinternal.h>
57289 +
57290 +static struct crash_uid *uid_set;
57291 +static unsigned short uid_used;
57292 +static DEFINE_SPINLOCK(gr_uid_lock);
57293 +extern rwlock_t gr_inode_lock;
57294 +extern struct acl_subject_label *
57295 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
57296 + struct acl_role_label *role);
57297 +
57298 +#ifdef CONFIG_BTRFS_FS
57299 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
57300 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
57301 +#endif
57302 +
57303 +static inline dev_t __get_dev(const struct dentry *dentry)
57304 +{
57305 +#ifdef CONFIG_BTRFS_FS
57306 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
57307 + return get_btrfs_dev_from_inode(dentry->d_inode);
57308 + else
57309 +#endif
57310 + return dentry->d_inode->i_sb->s_dev;
57311 +}
57312 +
57313 +int
57314 +gr_init_uidset(void)
57315 +{
57316 + uid_set =
57317 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
57318 + uid_used = 0;
57319 +
57320 + return uid_set ? 1 : 0;
57321 +}
57322 +
57323 +void
57324 +gr_free_uidset(void)
57325 +{
57326 + if (uid_set)
57327 + kfree(uid_set);
57328 +
57329 + return;
57330 +}
57331 +
57332 +int
57333 +gr_find_uid(const uid_t uid)
57334 +{
57335 + struct crash_uid *tmp = uid_set;
57336 + uid_t buid;
57337 + int low = 0, high = uid_used - 1, mid;
57338 +
57339 + while (high >= low) {
57340 + mid = (low + high) >> 1;
57341 + buid = tmp[mid].uid;
57342 + if (buid == uid)
57343 + return mid;
57344 + if (buid > uid)
57345 + high = mid - 1;
57346 + if (buid < uid)
57347 + low = mid + 1;
57348 + }
57349 +
57350 + return -1;
57351 +}
57352 +
57353 +static __inline__ void
57354 +gr_insertsort(void)
57355 +{
57356 + unsigned short i, j;
57357 + struct crash_uid index;
57358 +
57359 + for (i = 1; i < uid_used; i++) {
57360 + index = uid_set[i];
57361 + j = i;
57362 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
57363 + uid_set[j] = uid_set[j - 1];
57364 + j--;
57365 + }
57366 + uid_set[j] = index;
57367 + }
57368 +
57369 + return;
57370 +}
57371 +
57372 +static __inline__ void
57373 +gr_insert_uid(const uid_t uid, const unsigned long expires)
57374 +{
57375 + int loc;
57376 +
57377 + if (uid_used == GR_UIDTABLE_MAX)
57378 + return;
57379 +
57380 + loc = gr_find_uid(uid);
57381 +
57382 + if (loc >= 0) {
57383 + uid_set[loc].expires = expires;
57384 + return;
57385 + }
57386 +
57387 + uid_set[uid_used].uid = uid;
57388 + uid_set[uid_used].expires = expires;
57389 + uid_used++;
57390 +
57391 + gr_insertsort();
57392 +
57393 + return;
57394 +}
57395 +
57396 +void
57397 +gr_remove_uid(const unsigned short loc)
57398 +{
57399 + unsigned short i;
57400 +
57401 + for (i = loc + 1; i < uid_used; i++)
57402 + uid_set[i - 1] = uid_set[i];
57403 +
57404 + uid_used--;
57405 +
57406 + return;
57407 +}
57408 +
57409 +int
57410 +gr_check_crash_uid(const uid_t uid)
57411 +{
57412 + int loc;
57413 + int ret = 0;
57414 +
57415 + if (unlikely(!gr_acl_is_enabled()))
57416 + return 0;
57417 +
57418 + spin_lock(&gr_uid_lock);
57419 + loc = gr_find_uid(uid);
57420 +
57421 + if (loc < 0)
57422 + goto out_unlock;
57423 +
57424 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
57425 + gr_remove_uid(loc);
57426 + else
57427 + ret = 1;
57428 +
57429 +out_unlock:
57430 + spin_unlock(&gr_uid_lock);
57431 + return ret;
57432 +}
57433 +
57434 +static __inline__ int
57435 +proc_is_setxid(const struct cred *cred)
57436 +{
57437 + if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
57438 + !uid_eq(cred->uid, cred->fsuid))
57439 + return 1;
57440 + if (!uid_eq(cred->gid, cred->egid) || !uid_eq(cred->gid, cred->sgid) ||
57441 + !uid_eq(cred->gid, cred->fsgid))
57442 + return 1;
57443 +
57444 + return 0;
57445 +}
57446 +
57447 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
57448 +
57449 +void
57450 +gr_handle_crash(struct task_struct *task, const int sig)
57451 +{
57452 + struct acl_subject_label *curr;
57453 + struct task_struct *tsk, *tsk2;
57454 + const struct cred *cred;
57455 + const struct cred *cred2;
57456 +
57457 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
57458 + return;
57459 +
57460 + if (unlikely(!gr_acl_is_enabled()))
57461 + return;
57462 +
57463 + curr = task->acl;
57464 +
57465 + if (!(curr->resmask & (1 << GR_CRASH_RES)))
57466 + return;
57467 +
57468 + if (time_before_eq(curr->expires, get_seconds())) {
57469 + curr->expires = 0;
57470 + curr->crashes = 0;
57471 + }
57472 +
57473 + curr->crashes++;
57474 +
57475 + if (!curr->expires)
57476 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
57477 +
57478 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
57479 + time_after(curr->expires, get_seconds())) {
57480 + rcu_read_lock();
57481 + cred = __task_cred(task);
57482 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && proc_is_setxid(cred)) {
57483 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
57484 + spin_lock(&gr_uid_lock);
57485 + gr_insert_uid(cred->uid, curr->expires);
57486 + spin_unlock(&gr_uid_lock);
57487 + curr->expires = 0;
57488 + curr->crashes = 0;
57489 + read_lock(&tasklist_lock);
57490 + do_each_thread(tsk2, tsk) {
57491 + cred2 = __task_cred(tsk);
57492 + if (tsk != task && uid_eq(cred2->uid, cred->uid))
57493 + gr_fake_force_sig(SIGKILL, tsk);
57494 + } while_each_thread(tsk2, tsk);
57495 + read_unlock(&tasklist_lock);
57496 + } else {
57497 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
57498 + read_lock(&tasklist_lock);
57499 + read_lock(&grsec_exec_file_lock);
57500 + do_each_thread(tsk2, tsk) {
57501 + if (likely(tsk != task)) {
57502 + // if this thread has the same subject as the one that triggered
57503 + // RES_CRASH and it's the same binary, kill it
57504 + if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
57505 + gr_fake_force_sig(SIGKILL, tsk);
57506 + }
57507 + } while_each_thread(tsk2, tsk);
57508 + read_unlock(&grsec_exec_file_lock);
57509 + read_unlock(&tasklist_lock);
57510 + }
57511 + rcu_read_unlock();
57512 + }
57513 +
57514 + return;
57515 +}
57516 +
57517 +int
57518 +gr_check_crash_exec(const struct file *filp)
57519 +{
57520 + struct acl_subject_label *curr;
57521 +
57522 + if (unlikely(!gr_acl_is_enabled()))
57523 + return 0;
57524 +
57525 + read_lock(&gr_inode_lock);
57526 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
57527 + __get_dev(filp->f_path.dentry),
57528 + current->role);
57529 + read_unlock(&gr_inode_lock);
57530 +
57531 + if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
57532 + (!curr->crashes && !curr->expires))
57533 + return 0;
57534 +
57535 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
57536 + time_after(curr->expires, get_seconds()))
57537 + return 1;
57538 + else if (time_before_eq(curr->expires, get_seconds())) {
57539 + curr->crashes = 0;
57540 + curr->expires = 0;
57541 + }
57542 +
57543 + return 0;
57544 +}
57545 +
57546 +void
57547 +gr_handle_alertkill(struct task_struct *task)
57548 +{
57549 + struct acl_subject_label *curracl;
57550 + __u32 curr_ip;
57551 + struct task_struct *p, *p2;
57552 +
57553 + if (unlikely(!gr_acl_is_enabled()))
57554 + return;
57555 +
57556 + curracl = task->acl;
57557 + curr_ip = task->signal->curr_ip;
57558 +
57559 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
57560 + read_lock(&tasklist_lock);
57561 + do_each_thread(p2, p) {
57562 + if (p->signal->curr_ip == curr_ip)
57563 + gr_fake_force_sig(SIGKILL, p);
57564 + } while_each_thread(p2, p);
57565 + read_unlock(&tasklist_lock);
57566 + } else if (curracl->mode & GR_KILLPROC)
57567 + gr_fake_force_sig(SIGKILL, task);
57568 +
57569 + return;
57570 +}
57571 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
57572 new file mode 100644
57573 index 0000000..9d83a69
57574 --- /dev/null
57575 +++ b/grsecurity/gracl_shm.c
57576 @@ -0,0 +1,40 @@
57577 +#include <linux/kernel.h>
57578 +#include <linux/mm.h>
57579 +#include <linux/sched.h>
57580 +#include <linux/file.h>
57581 +#include <linux/ipc.h>
57582 +#include <linux/gracl.h>
57583 +#include <linux/grsecurity.h>
57584 +#include <linux/grinternal.h>
57585 +
57586 +int
57587 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57588 + const time_t shm_createtime, const uid_t cuid, const int shmid)
57589 +{
57590 + struct task_struct *task;
57591 +
57592 + if (!gr_acl_is_enabled())
57593 + return 1;
57594 +
57595 + rcu_read_lock();
57596 + read_lock(&tasklist_lock);
57597 +
57598 + task = find_task_by_vpid(shm_cprid);
57599 +
57600 + if (unlikely(!task))
57601 + task = find_task_by_vpid(shm_lapid);
57602 +
57603 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
57604 + (task->pid == shm_lapid)) &&
57605 + (task->acl->mode & GR_PROTSHM) &&
57606 + (task->acl != current->acl))) {
57607 + read_unlock(&tasklist_lock);
57608 + rcu_read_unlock();
57609 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
57610 + return 0;
57611 + }
57612 + read_unlock(&tasklist_lock);
57613 + rcu_read_unlock();
57614 +
57615 + return 1;
57616 +}
57617 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
57618 new file mode 100644
57619 index 0000000..bc0be01
57620 --- /dev/null
57621 +++ b/grsecurity/grsec_chdir.c
57622 @@ -0,0 +1,19 @@
57623 +#include <linux/kernel.h>
57624 +#include <linux/sched.h>
57625 +#include <linux/fs.h>
57626 +#include <linux/file.h>
57627 +#include <linux/grsecurity.h>
57628 +#include <linux/grinternal.h>
57629 +
57630 +void
57631 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
57632 +{
57633 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
57634 + if ((grsec_enable_chdir && grsec_enable_group &&
57635 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
57636 + !grsec_enable_group)) {
57637 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
57638 + }
57639 +#endif
57640 + return;
57641 +}
57642 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
57643 new file mode 100644
57644 index 0000000..9807ee2
57645 --- /dev/null
57646 +++ b/grsecurity/grsec_chroot.c
57647 @@ -0,0 +1,368 @@
57648 +#include <linux/kernel.h>
57649 +#include <linux/module.h>
57650 +#include <linux/sched.h>
57651 +#include <linux/file.h>
57652 +#include <linux/fs.h>
57653 +#include <linux/mount.h>
57654 +#include <linux/types.h>
57655 +#include "../fs/mount.h"
57656 +#include <linux/grsecurity.h>
57657 +#include <linux/grinternal.h>
57658 +
57659 +void gr_set_chroot_entries(struct task_struct *task, struct path *path)
57660 +{
57661 +#ifdef CONFIG_GRKERNSEC
57662 + if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
57663 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
57664 + task->gr_is_chrooted = 1;
57665 + else
57666 + task->gr_is_chrooted = 0;
57667 +
57668 + task->gr_chroot_dentry = path->dentry;
57669 +#endif
57670 + return;
57671 +}
57672 +
57673 +void gr_clear_chroot_entries(struct task_struct *task)
57674 +{
57675 +#ifdef CONFIG_GRKERNSEC
57676 + task->gr_is_chrooted = 0;
57677 + task->gr_chroot_dentry = NULL;
57678 +#endif
57679 + return;
57680 +}
57681 +
57682 +int
57683 +gr_handle_chroot_unix(const pid_t pid)
57684 +{
57685 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
57686 + struct task_struct *p;
57687 +
57688 + if (unlikely(!grsec_enable_chroot_unix))
57689 + return 1;
57690 +
57691 + if (likely(!proc_is_chrooted(current)))
57692 + return 1;
57693 +
57694 + rcu_read_lock();
57695 + read_lock(&tasklist_lock);
57696 + p = find_task_by_vpid_unrestricted(pid);
57697 + if (unlikely(p && !have_same_root(current, p))) {
57698 + read_unlock(&tasklist_lock);
57699 + rcu_read_unlock();
57700 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
57701 + return 0;
57702 + }
57703 + read_unlock(&tasklist_lock);
57704 + rcu_read_unlock();
57705 +#endif
57706 + return 1;
57707 +}
57708 +
57709 +int
57710 +gr_handle_chroot_nice(void)
57711 +{
57712 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57713 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
57714 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
57715 + return -EPERM;
57716 + }
57717 +#endif
57718 + return 0;
57719 +}
57720 +
57721 +int
57722 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
57723 +{
57724 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57725 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
57726 + && proc_is_chrooted(current)) {
57727 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
57728 + return -EACCES;
57729 + }
57730 +#endif
57731 + return 0;
57732 +}
57733 +
57734 +int
57735 +gr_handle_chroot_rawio(const struct inode *inode)
57736 +{
57737 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57738 + if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
57739 + inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
57740 + return 1;
57741 +#endif
57742 + return 0;
57743 +}
57744 +
57745 +int
57746 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
57747 +{
57748 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57749 + struct task_struct *p;
57750 + int ret = 0;
57751 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
57752 + return ret;
57753 +
57754 + read_lock(&tasklist_lock);
57755 + do_each_pid_task(pid, type, p) {
57756 + if (!have_same_root(current, p)) {
57757 + ret = 1;
57758 + goto out;
57759 + }
57760 + } while_each_pid_task(pid, type, p);
57761 +out:
57762 + read_unlock(&tasklist_lock);
57763 + return ret;
57764 +#endif
57765 + return 0;
57766 +}
57767 +
57768 +int
57769 +gr_pid_is_chrooted(struct task_struct *p)
57770 +{
57771 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57772 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
57773 + return 0;
57774 +
57775 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
57776 + !have_same_root(current, p)) {
57777 + return 1;
57778 + }
57779 +#endif
57780 + return 0;
57781 +}
57782 +
57783 +EXPORT_SYMBOL(gr_pid_is_chrooted);
57784 +
57785 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
57786 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
57787 +{
57788 + struct path path, currentroot;
57789 + int ret = 0;
57790 +
57791 + path.dentry = (struct dentry *)u_dentry;
57792 + path.mnt = (struct vfsmount *)u_mnt;
57793 + get_fs_root(current->fs, &currentroot);
57794 + if (path_is_under(&path, &currentroot))
57795 + ret = 1;
57796 + path_put(&currentroot);
57797 +
57798 + return ret;
57799 +}
57800 +#endif
57801 +
57802 +int
57803 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
57804 +{
57805 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
57806 + if (!grsec_enable_chroot_fchdir)
57807 + return 1;
57808 +
57809 + if (!proc_is_chrooted(current))
57810 + return 1;
57811 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
57812 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
57813 + return 0;
57814 + }
57815 +#endif
57816 + return 1;
57817 +}
57818 +
57819 +int
57820 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57821 + const time_t shm_createtime)
57822 +{
57823 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
57824 + struct task_struct *p;
57825 + time_t starttime;
57826 +
57827 + if (unlikely(!grsec_enable_chroot_shmat))
57828 + return 1;
57829 +
57830 + if (likely(!proc_is_chrooted(current)))
57831 + return 1;
57832 +
57833 + rcu_read_lock();
57834 + read_lock(&tasklist_lock);
57835 +
57836 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
57837 + starttime = p->start_time.tv_sec;
57838 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
57839 + if (have_same_root(current, p)) {
57840 + goto allow;
57841 + } else {
57842 + read_unlock(&tasklist_lock);
57843 + rcu_read_unlock();
57844 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
57845 + return 0;
57846 + }
57847 + }
57848 + /* creator exited, pid reuse, fall through to next check */
57849 + }
57850 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
57851 + if (unlikely(!have_same_root(current, p))) {
57852 + read_unlock(&tasklist_lock);
57853 + rcu_read_unlock();
57854 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
57855 + return 0;
57856 + }
57857 + }
57858 +
57859 +allow:
57860 + read_unlock(&tasklist_lock);
57861 + rcu_read_unlock();
57862 +#endif
57863 + return 1;
57864 +}
57865 +
57866 +void
57867 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
57868 +{
57869 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
57870 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
57871 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
57872 +#endif
57873 + return;
57874 +}
57875 +
57876 +int
57877 +gr_handle_chroot_mknod(const struct dentry *dentry,
57878 + const struct vfsmount *mnt, const int mode)
57879 +{
57880 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
57881 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
57882 + proc_is_chrooted(current)) {
57883 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
57884 + return -EPERM;
57885 + }
57886 +#endif
57887 + return 0;
57888 +}
57889 +
57890 +int
57891 +gr_handle_chroot_mount(const struct dentry *dentry,
57892 + const struct vfsmount *mnt, const char *dev_name)
57893 +{
57894 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
57895 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
57896 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
57897 + return -EPERM;
57898 + }
57899 +#endif
57900 + return 0;
57901 +}
57902 +
57903 +int
57904 +gr_handle_chroot_pivot(void)
57905 +{
57906 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
57907 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
57908 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
57909 + return -EPERM;
57910 + }
57911 +#endif
57912 + return 0;
57913 +}
57914 +
57915 +int
57916 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
57917 +{
57918 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
57919 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
57920 + !gr_is_outside_chroot(dentry, mnt)) {
57921 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
57922 + return -EPERM;
57923 + }
57924 +#endif
57925 + return 0;
57926 +}
57927 +
57928 +extern const char *captab_log[];
57929 +extern int captab_log_entries;
57930 +
57931 +int
57932 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
57933 +{
57934 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57935 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
57936 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
57937 + if (cap_raised(chroot_caps, cap)) {
57938 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
57939 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
57940 + }
57941 + return 0;
57942 + }
57943 + }
57944 +#endif
57945 + return 1;
57946 +}
57947 +
57948 +int
57949 +gr_chroot_is_capable(const int cap)
57950 +{
57951 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57952 + return gr_task_chroot_is_capable(current, current_cred(), cap);
57953 +#endif
57954 + return 1;
57955 +}
57956 +
57957 +int
57958 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
57959 +{
57960 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57961 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
57962 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
57963 + if (cap_raised(chroot_caps, cap)) {
57964 + return 0;
57965 + }
57966 + }
57967 +#endif
57968 + return 1;
57969 +}
57970 +
57971 +int
57972 +gr_chroot_is_capable_nolog(const int cap)
57973 +{
57974 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57975 + return gr_task_chroot_is_capable_nolog(current, cap);
57976 +#endif
57977 + return 1;
57978 +}
57979 +
57980 +int
57981 +gr_handle_chroot_sysctl(const int op)
57982 +{
57983 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
57984 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
57985 + proc_is_chrooted(current))
57986 + return -EACCES;
57987 +#endif
57988 + return 0;
57989 +}
57990 +
57991 +void
57992 +gr_handle_chroot_chdir(struct path *path)
57993 +{
57994 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
57995 + if (grsec_enable_chroot_chdir)
57996 + set_fs_pwd(current->fs, path);
57997 +#endif
57998 + return;
57999 +}
58000 +
58001 +int
58002 +gr_handle_chroot_chmod(const struct dentry *dentry,
58003 + const struct vfsmount *mnt, const int mode)
58004 +{
58005 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
58006 + /* allow chmod +s on directories, but not files */
58007 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
58008 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
58009 + proc_is_chrooted(current)) {
58010 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
58011 + return -EPERM;
58012 + }
58013 +#endif
58014 + return 0;
58015 +}
58016 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
58017 new file mode 100644
58018 index 0000000..213ad8b
58019 --- /dev/null
58020 +++ b/grsecurity/grsec_disabled.c
58021 @@ -0,0 +1,437 @@
58022 +#include <linux/kernel.h>
58023 +#include <linux/module.h>
58024 +#include <linux/sched.h>
58025 +#include <linux/file.h>
58026 +#include <linux/fs.h>
58027 +#include <linux/kdev_t.h>
58028 +#include <linux/net.h>
58029 +#include <linux/in.h>
58030 +#include <linux/ip.h>
58031 +#include <linux/skbuff.h>
58032 +#include <linux/sysctl.h>
58033 +
58034 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
58035 +void
58036 +pax_set_initial_flags(struct linux_binprm *bprm)
58037 +{
58038 + return;
58039 +}
58040 +#endif
58041 +
58042 +#ifdef CONFIG_SYSCTL
58043 +__u32
58044 +gr_handle_sysctl(const struct ctl_table * table, const int op)
58045 +{
58046 + return 0;
58047 +}
58048 +#endif
58049 +
58050 +#ifdef CONFIG_TASKSTATS
58051 +int gr_is_taskstats_denied(int pid)
58052 +{
58053 + return 0;
58054 +}
58055 +#endif
58056 +
58057 +int
58058 +gr_acl_is_enabled(void)
58059 +{
58060 + return 0;
58061 +}
58062 +
58063 +void
58064 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
58065 +{
58066 + return;
58067 +}
58068 +
58069 +int
58070 +gr_handle_rawio(const struct inode *inode)
58071 +{
58072 + return 0;
58073 +}
58074 +
58075 +void
58076 +gr_acl_handle_psacct(struct task_struct *task, const long code)
58077 +{
58078 + return;
58079 +}
58080 +
58081 +int
58082 +gr_handle_ptrace(struct task_struct *task, const long request)
58083 +{
58084 + return 0;
58085 +}
58086 +
58087 +int
58088 +gr_handle_proc_ptrace(struct task_struct *task)
58089 +{
58090 + return 0;
58091 +}
58092 +
58093 +void
58094 +gr_learn_resource(const struct task_struct *task,
58095 + const int res, const unsigned long wanted, const int gt)
58096 +{
58097 + return;
58098 +}
58099 +
58100 +int
58101 +gr_set_acls(const int type)
58102 +{
58103 + return 0;
58104 +}
58105 +
58106 +int
58107 +gr_check_hidden_task(const struct task_struct *tsk)
58108 +{
58109 + return 0;
58110 +}
58111 +
58112 +int
58113 +gr_check_protected_task(const struct task_struct *task)
58114 +{
58115 + return 0;
58116 +}
58117 +
58118 +int
58119 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
58120 +{
58121 + return 0;
58122 +}
58123 +
58124 +void
58125 +gr_copy_label(struct task_struct *tsk)
58126 +{
58127 + return;
58128 +}
58129 +
58130 +void
58131 +gr_set_pax_flags(struct task_struct *task)
58132 +{
58133 + return;
58134 +}
58135 +
58136 +int
58137 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
58138 + const int unsafe_share)
58139 +{
58140 + return 0;
58141 +}
58142 +
58143 +void
58144 +gr_handle_delete(const ino_t ino, const dev_t dev)
58145 +{
58146 + return;
58147 +}
58148 +
58149 +void
58150 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
58151 +{
58152 + return;
58153 +}
58154 +
58155 +void
58156 +gr_handle_crash(struct task_struct *task, const int sig)
58157 +{
58158 + return;
58159 +}
58160 +
58161 +int
58162 +gr_check_crash_exec(const struct file *filp)
58163 +{
58164 + return 0;
58165 +}
58166 +
58167 +int
58168 +gr_check_crash_uid(const uid_t uid)
58169 +{
58170 + return 0;
58171 +}
58172 +
58173 +void
58174 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
58175 + struct dentry *old_dentry,
58176 + struct dentry *new_dentry,
58177 + struct vfsmount *mnt, const __u8 replace)
58178 +{
58179 + return;
58180 +}
58181 +
58182 +int
58183 +gr_search_socket(const int family, const int type, const int protocol)
58184 +{
58185 + return 1;
58186 +}
58187 +
58188 +int
58189 +gr_search_connectbind(const int mode, const struct socket *sock,
58190 + const struct sockaddr_in *addr)
58191 +{
58192 + return 0;
58193 +}
58194 +
58195 +void
58196 +gr_handle_alertkill(struct task_struct *task)
58197 +{
58198 + return;
58199 +}
58200 +
58201 +__u32
58202 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
58203 +{
58204 + return 1;
58205 +}
58206 +
58207 +__u32
58208 +gr_acl_handle_hidden_file(const struct dentry * dentry,
58209 + const struct vfsmount * mnt)
58210 +{
58211 + return 1;
58212 +}
58213 +
58214 +__u32
58215 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
58216 + int acc_mode)
58217 +{
58218 + return 1;
58219 +}
58220 +
58221 +__u32
58222 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
58223 +{
58224 + return 1;
58225 +}
58226 +
58227 +__u32
58228 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
58229 +{
58230 + return 1;
58231 +}
58232 +
58233 +int
58234 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
58235 + unsigned int *vm_flags)
58236 +{
58237 + return 1;
58238 +}
58239 +
58240 +__u32
58241 +gr_acl_handle_truncate(const struct dentry * dentry,
58242 + const struct vfsmount * mnt)
58243 +{
58244 + return 1;
58245 +}
58246 +
58247 +__u32
58248 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
58249 +{
58250 + return 1;
58251 +}
58252 +
58253 +__u32
58254 +gr_acl_handle_access(const struct dentry * dentry,
58255 + const struct vfsmount * mnt, const int fmode)
58256 +{
58257 + return 1;
58258 +}
58259 +
58260 +__u32
58261 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
58262 + umode_t *mode)
58263 +{
58264 + return 1;
58265 +}
58266 +
58267 +__u32
58268 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
58269 +{
58270 + return 1;
58271 +}
58272 +
58273 +__u32
58274 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
58275 +{
58276 + return 1;
58277 +}
58278 +
58279 +void
58280 +grsecurity_init(void)
58281 +{
58282 + return;
58283 +}
58284 +
58285 +umode_t gr_acl_umask(void)
58286 +{
58287 + return 0;
58288 +}
58289 +
58290 +__u32
58291 +gr_acl_handle_mknod(const struct dentry * new_dentry,
58292 + const struct dentry * parent_dentry,
58293 + const struct vfsmount * parent_mnt,
58294 + const int mode)
58295 +{
58296 + return 1;
58297 +}
58298 +
58299 +__u32
58300 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
58301 + const struct dentry * parent_dentry,
58302 + const struct vfsmount * parent_mnt)
58303 +{
58304 + return 1;
58305 +}
58306 +
58307 +__u32
58308 +gr_acl_handle_symlink(const struct dentry * new_dentry,
58309 + const struct dentry * parent_dentry,
58310 + const struct vfsmount * parent_mnt, const char *from)
58311 +{
58312 + return 1;
58313 +}
58314 +
58315 +__u32
58316 +gr_acl_handle_link(const struct dentry * new_dentry,
58317 + const struct dentry * parent_dentry,
58318 + const struct vfsmount * parent_mnt,
58319 + const struct dentry * old_dentry,
58320 + const struct vfsmount * old_mnt, const char *to)
58321 +{
58322 + return 1;
58323 +}
58324 +
58325 +int
58326 +gr_acl_handle_rename(const struct dentry *new_dentry,
58327 + const struct dentry *parent_dentry,
58328 + const struct vfsmount *parent_mnt,
58329 + const struct dentry *old_dentry,
58330 + const struct inode *old_parent_inode,
58331 + const struct vfsmount *old_mnt, const char *newname)
58332 +{
58333 + return 0;
58334 +}
58335 +
58336 +int
58337 +gr_acl_handle_filldir(const struct file *file, const char *name,
58338 + const int namelen, const ino_t ino)
58339 +{
58340 + return 1;
58341 +}
58342 +
58343 +int
58344 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
58345 + const time_t shm_createtime, const uid_t cuid, const int shmid)
58346 +{
58347 + return 1;
58348 +}
58349 +
58350 +int
58351 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
58352 +{
58353 + return 0;
58354 +}
58355 +
58356 +int
58357 +gr_search_accept(const struct socket *sock)
58358 +{
58359 + return 0;
58360 +}
58361 +
58362 +int
58363 +gr_search_listen(const struct socket *sock)
58364 +{
58365 + return 0;
58366 +}
58367 +
58368 +int
58369 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
58370 +{
58371 + return 0;
58372 +}
58373 +
58374 +__u32
58375 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
58376 +{
58377 + return 1;
58378 +}
58379 +
58380 +__u32
58381 +gr_acl_handle_creat(const struct dentry * dentry,
58382 + const struct dentry * p_dentry,
58383 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
58384 + const int imode)
58385 +{
58386 + return 1;
58387 +}
58388 +
58389 +void
58390 +gr_acl_handle_exit(void)
58391 +{
58392 + return;
58393 +}
58394 +
58395 +int
58396 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
58397 +{
58398 + return 1;
58399 +}
58400 +
58401 +void
58402 +gr_set_role_label(const uid_t uid, const gid_t gid)
58403 +{
58404 + return;
58405 +}
58406 +
58407 +int
58408 +gr_acl_handle_procpidmem(const struct task_struct *task)
58409 +{
58410 + return 0;
58411 +}
58412 +
58413 +int
58414 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
58415 +{
58416 + return 0;
58417 +}
58418 +
58419 +int
58420 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
58421 +{
58422 + return 0;
58423 +}
58424 +
58425 +void
58426 +gr_set_kernel_label(struct task_struct *task)
58427 +{
58428 + return;
58429 +}
58430 +
58431 +int
58432 +gr_check_user_change(int real, int effective, int fs)
58433 +{
58434 + return 0;
58435 +}
58436 +
58437 +int
58438 +gr_check_group_change(int real, int effective, int fs)
58439 +{
58440 + return 0;
58441 +}
58442 +
58443 +int gr_acl_enable_at_secure(void)
58444 +{
58445 + return 0;
58446 +}
58447 +
58448 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
58449 +{
58450 + return dentry->d_inode->i_sb->s_dev;
58451 +}
58452 +
58453 +EXPORT_SYMBOL(gr_learn_resource);
58454 +EXPORT_SYMBOL(gr_set_kernel_label);
58455 +#ifdef CONFIG_SECURITY
58456 +EXPORT_SYMBOL(gr_check_user_change);
58457 +EXPORT_SYMBOL(gr_check_group_change);
58458 +#endif
58459 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
58460 new file mode 100644
58461 index 0000000..abfa971
58462 --- /dev/null
58463 +++ b/grsecurity/grsec_exec.c
58464 @@ -0,0 +1,174 @@
58465 +#include <linux/kernel.h>
58466 +#include <linux/sched.h>
58467 +#include <linux/file.h>
58468 +#include <linux/binfmts.h>
58469 +#include <linux/fs.h>
58470 +#include <linux/types.h>
58471 +#include <linux/grdefs.h>
58472 +#include <linux/grsecurity.h>
58473 +#include <linux/grinternal.h>
58474 +#include <linux/capability.h>
58475 +#include <linux/module.h>
58476 +
58477 +#include <asm/uaccess.h>
58478 +
58479 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58480 +static char gr_exec_arg_buf[132];
58481 +static DEFINE_MUTEX(gr_exec_arg_mutex);
58482 +#endif
58483 +
58484 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
58485 +
58486 +void
58487 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
58488 +{
58489 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58490 + char *grarg = gr_exec_arg_buf;
58491 + unsigned int i, x, execlen = 0;
58492 + char c;
58493 +
58494 + if (!((grsec_enable_execlog && grsec_enable_group &&
58495 + in_group_p(grsec_audit_gid))
58496 + || (grsec_enable_execlog && !grsec_enable_group)))
58497 + return;
58498 +
58499 + mutex_lock(&gr_exec_arg_mutex);
58500 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
58501 +
58502 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
58503 + const char __user *p;
58504 + unsigned int len;
58505 +
58506 + p = get_user_arg_ptr(argv, i);
58507 + if (IS_ERR(p))
58508 + goto log;
58509 +
58510 + len = strnlen_user(p, 128 - execlen);
58511 + if (len > 128 - execlen)
58512 + len = 128 - execlen;
58513 + else if (len > 0)
58514 + len--;
58515 + if (copy_from_user(grarg + execlen, p, len))
58516 + goto log;
58517 +
58518 + /* rewrite unprintable characters */
58519 + for (x = 0; x < len; x++) {
58520 + c = *(grarg + execlen + x);
58521 + if (c < 32 || c > 126)
58522 + *(grarg + execlen + x) = ' ';
58523 + }
58524 +
58525 + execlen += len;
58526 + *(grarg + execlen) = ' ';
58527 + *(grarg + execlen + 1) = '\0';
58528 + execlen++;
58529 + }
58530 +
58531 + log:
58532 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
58533 + bprm->file->f_path.mnt, grarg);
58534 + mutex_unlock(&gr_exec_arg_mutex);
58535 +#endif
58536 + return;
58537 +}
58538 +
58539 +#ifdef CONFIG_GRKERNSEC
58540 +extern int gr_acl_is_capable(const int cap);
58541 +extern int gr_acl_is_capable_nolog(const int cap);
58542 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
58543 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
58544 +extern int gr_chroot_is_capable(const int cap);
58545 +extern int gr_chroot_is_capable_nolog(const int cap);
58546 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
58547 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
58548 +#endif
58549 +
58550 +const char *captab_log[] = {
58551 + "CAP_CHOWN",
58552 + "CAP_DAC_OVERRIDE",
58553 + "CAP_DAC_READ_SEARCH",
58554 + "CAP_FOWNER",
58555 + "CAP_FSETID",
58556 + "CAP_KILL",
58557 + "CAP_SETGID",
58558 + "CAP_SETUID",
58559 + "CAP_SETPCAP",
58560 + "CAP_LINUX_IMMUTABLE",
58561 + "CAP_NET_BIND_SERVICE",
58562 + "CAP_NET_BROADCAST",
58563 + "CAP_NET_ADMIN",
58564 + "CAP_NET_RAW",
58565 + "CAP_IPC_LOCK",
58566 + "CAP_IPC_OWNER",
58567 + "CAP_SYS_MODULE",
58568 + "CAP_SYS_RAWIO",
58569 + "CAP_SYS_CHROOT",
58570 + "CAP_SYS_PTRACE",
58571 + "CAP_SYS_PACCT",
58572 + "CAP_SYS_ADMIN",
58573 + "CAP_SYS_BOOT",
58574 + "CAP_SYS_NICE",
58575 + "CAP_SYS_RESOURCE",
58576 + "CAP_SYS_TIME",
58577 + "CAP_SYS_TTY_CONFIG",
58578 + "CAP_MKNOD",
58579 + "CAP_LEASE",
58580 + "CAP_AUDIT_WRITE",
58581 + "CAP_AUDIT_CONTROL",
58582 + "CAP_SETFCAP",
58583 + "CAP_MAC_OVERRIDE",
58584 + "CAP_MAC_ADMIN",
58585 + "CAP_SYSLOG",
58586 + "CAP_WAKE_ALARM"
58587 +};
58588 +
58589 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
58590 +
58591 +int gr_is_capable(const int cap)
58592 +{
58593 +#ifdef CONFIG_GRKERNSEC
58594 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
58595 + return 1;
58596 + return 0;
58597 +#else
58598 + return 1;
58599 +#endif
58600 +}
58601 +
58602 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
58603 +{
58604 +#ifdef CONFIG_GRKERNSEC
58605 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
58606 + return 1;
58607 + return 0;
58608 +#else
58609 + return 1;
58610 +#endif
58611 +}
58612 +
58613 +int gr_is_capable_nolog(const int cap)
58614 +{
58615 +#ifdef CONFIG_GRKERNSEC
58616 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
58617 + return 1;
58618 + return 0;
58619 +#else
58620 + return 1;
58621 +#endif
58622 +}
58623 +
58624 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
58625 +{
58626 +#ifdef CONFIG_GRKERNSEC
58627 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
58628 + return 1;
58629 + return 0;
58630 +#else
58631 + return 1;
58632 +#endif
58633 +}
58634 +
58635 +EXPORT_SYMBOL(gr_is_capable);
58636 +EXPORT_SYMBOL(gr_is_capable_nolog);
58637 +EXPORT_SYMBOL(gr_task_is_capable);
58638 +EXPORT_SYMBOL(gr_task_is_capable_nolog);
58639 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
58640 new file mode 100644
58641 index 0000000..d3ee748
58642 --- /dev/null
58643 +++ b/grsecurity/grsec_fifo.c
58644 @@ -0,0 +1,24 @@
58645 +#include <linux/kernel.h>
58646 +#include <linux/sched.h>
58647 +#include <linux/fs.h>
58648 +#include <linux/file.h>
58649 +#include <linux/grinternal.h>
58650 +
58651 +int
58652 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
58653 + const struct dentry *dir, const int flag, const int acc_mode)
58654 +{
58655 +#ifdef CONFIG_GRKERNSEC_FIFO
58656 + const struct cred *cred = current_cred();
58657 +
58658 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
58659 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
58660 + (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
58661 + (cred->fsuid != dentry->d_inode->i_uid)) {
58662 + if (!inode_permission(dentry->d_inode, acc_mode))
58663 + gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
58664 + return -EACCES;
58665 + }
58666 +#endif
58667 + return 0;
58668 +}
58669 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
58670 new file mode 100644
58671 index 0000000..8ca18bf
58672 --- /dev/null
58673 +++ b/grsecurity/grsec_fork.c
58674 @@ -0,0 +1,23 @@
58675 +#include <linux/kernel.h>
58676 +#include <linux/sched.h>
58677 +#include <linux/grsecurity.h>
58678 +#include <linux/grinternal.h>
58679 +#include <linux/errno.h>
58680 +
58681 +void
58682 +gr_log_forkfail(const int retval)
58683 +{
58684 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
58685 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
58686 + switch (retval) {
58687 + case -EAGAIN:
58688 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
58689 + break;
58690 + case -ENOMEM:
58691 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
58692 + break;
58693 + }
58694 + }
58695 +#endif
58696 + return;
58697 +}
58698 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
58699 new file mode 100644
58700 index 0000000..05a6015
58701 --- /dev/null
58702 +++ b/grsecurity/grsec_init.c
58703 @@ -0,0 +1,283 @@
58704 +#include <linux/kernel.h>
58705 +#include <linux/sched.h>
58706 +#include <linux/mm.h>
58707 +#include <linux/gracl.h>
58708 +#include <linux/slab.h>
58709 +#include <linux/vmalloc.h>
58710 +#include <linux/percpu.h>
58711 +#include <linux/module.h>
58712 +
58713 +int grsec_enable_ptrace_readexec;
58714 +int grsec_enable_setxid;
58715 +int grsec_enable_symlinkown;
58716 +int grsec_symlinkown_gid;
58717 +int grsec_enable_brute;
58718 +int grsec_enable_link;
58719 +int grsec_enable_dmesg;
58720 +int grsec_enable_harden_ptrace;
58721 +int grsec_enable_fifo;
58722 +int grsec_enable_execlog;
58723 +int grsec_enable_signal;
58724 +int grsec_enable_forkfail;
58725 +int grsec_enable_audit_ptrace;
58726 +int grsec_enable_time;
58727 +int grsec_enable_audit_textrel;
58728 +int grsec_enable_group;
58729 +int grsec_audit_gid;
58730 +int grsec_enable_chdir;
58731 +int grsec_enable_mount;
58732 +int grsec_enable_rofs;
58733 +int grsec_enable_chroot_findtask;
58734 +int grsec_enable_chroot_mount;
58735 +int grsec_enable_chroot_shmat;
58736 +int grsec_enable_chroot_fchdir;
58737 +int grsec_enable_chroot_double;
58738 +int grsec_enable_chroot_pivot;
58739 +int grsec_enable_chroot_chdir;
58740 +int grsec_enable_chroot_chmod;
58741 +int grsec_enable_chroot_mknod;
58742 +int grsec_enable_chroot_nice;
58743 +int grsec_enable_chroot_execlog;
58744 +int grsec_enable_chroot_caps;
58745 +int grsec_enable_chroot_sysctl;
58746 +int grsec_enable_chroot_unix;
58747 +int grsec_enable_tpe;
58748 +int grsec_tpe_gid;
58749 +int grsec_enable_blackhole;
58750 +#ifdef CONFIG_IPV6_MODULE
58751 +EXPORT_SYMBOL(grsec_enable_blackhole);
58752 +#endif
58753 +int grsec_lastack_retries;
58754 +int grsec_enable_tpe_all;
58755 +int grsec_enable_tpe_invert;
58756 +int grsec_enable_socket_all;
58757 +int grsec_socket_all_gid;
58758 +int grsec_enable_socket_client;
58759 +int grsec_socket_client_gid;
58760 +int grsec_enable_socket_server;
58761 +int grsec_socket_server_gid;
58762 +int grsec_resource_logging;
58763 +int grsec_disable_privio;
58764 +int grsec_enable_log_rwxmaps;
58765 +int grsec_lock;
58766 +
58767 +DEFINE_SPINLOCK(grsec_alert_lock);
58768 +unsigned long grsec_alert_wtime = 0;
58769 +unsigned long grsec_alert_fyet = 0;
58770 +
58771 +DEFINE_SPINLOCK(grsec_audit_lock);
58772 +
58773 +DEFINE_RWLOCK(grsec_exec_file_lock);
58774 +
58775 +char *gr_shared_page[4];
58776 +
58777 +char *gr_alert_log_fmt;
58778 +char *gr_audit_log_fmt;
58779 +char *gr_alert_log_buf;
58780 +char *gr_audit_log_buf;
58781 +
58782 +extern struct gr_arg *gr_usermode;
58783 +extern unsigned char *gr_system_salt;
58784 +extern unsigned char *gr_system_sum;
58785 +
58786 +void __init
58787 +grsecurity_init(void)
58788 +{
58789 + int j;
58790 + /* create the per-cpu shared pages */
58791 +
58792 +#ifdef CONFIG_X86
58793 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
58794 +#endif
58795 +
58796 + for (j = 0; j < 4; j++) {
58797 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
58798 + if (gr_shared_page[j] == NULL) {
58799 + panic("Unable to allocate grsecurity shared page");
58800 + return;
58801 + }
58802 + }
58803 +
58804 + /* allocate log buffers */
58805 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
58806 + if (!gr_alert_log_fmt) {
58807 + panic("Unable to allocate grsecurity alert log format buffer");
58808 + return;
58809 + }
58810 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
58811 + if (!gr_audit_log_fmt) {
58812 + panic("Unable to allocate grsecurity audit log format buffer");
58813 + return;
58814 + }
58815 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
58816 + if (!gr_alert_log_buf) {
58817 + panic("Unable to allocate grsecurity alert log buffer");
58818 + return;
58819 + }
58820 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
58821 + if (!gr_audit_log_buf) {
58822 + panic("Unable to allocate grsecurity audit log buffer");
58823 + return;
58824 + }
58825 +
58826 + /* allocate memory for authentication structure */
58827 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
58828 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
58829 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
58830 +
58831 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
58832 + panic("Unable to allocate grsecurity authentication structure");
58833 + return;
58834 + }
58835 +
58836 +
58837 +#ifdef CONFIG_GRKERNSEC_IO
58838 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
58839 + grsec_disable_privio = 1;
58840 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
58841 + grsec_disable_privio = 1;
58842 +#else
58843 + grsec_disable_privio = 0;
58844 +#endif
58845 +#endif
58846 +
58847 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
58848 + /* for backward compatibility, tpe_invert always defaults to on if
58849 + enabled in the kernel
58850 + */
58851 + grsec_enable_tpe_invert = 1;
58852 +#endif
58853 +
58854 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
58855 +#ifndef CONFIG_GRKERNSEC_SYSCTL
58856 + grsec_lock = 1;
58857 +#endif
58858 +
58859 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
58860 + grsec_enable_audit_textrel = 1;
58861 +#endif
58862 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58863 + grsec_enable_log_rwxmaps = 1;
58864 +#endif
58865 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
58866 + grsec_enable_group = 1;
58867 + grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
58868 +#endif
58869 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
58870 + grsec_enable_ptrace_readexec = 1;
58871 +#endif
58872 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
58873 + grsec_enable_chdir = 1;
58874 +#endif
58875 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
58876 + grsec_enable_harden_ptrace = 1;
58877 +#endif
58878 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58879 + grsec_enable_mount = 1;
58880 +#endif
58881 +#ifdef CONFIG_GRKERNSEC_LINK
58882 + grsec_enable_link = 1;
58883 +#endif
58884 +#ifdef CONFIG_GRKERNSEC_BRUTE
58885 + grsec_enable_brute = 1;
58886 +#endif
58887 +#ifdef CONFIG_GRKERNSEC_DMESG
58888 + grsec_enable_dmesg = 1;
58889 +#endif
58890 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
58891 + grsec_enable_blackhole = 1;
58892 + grsec_lastack_retries = 4;
58893 +#endif
58894 +#ifdef CONFIG_GRKERNSEC_FIFO
58895 + grsec_enable_fifo = 1;
58896 +#endif
58897 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58898 + grsec_enable_execlog = 1;
58899 +#endif
58900 +#ifdef CONFIG_GRKERNSEC_SETXID
58901 + grsec_enable_setxid = 1;
58902 +#endif
58903 +#ifdef CONFIG_GRKERNSEC_SIGNAL
58904 + grsec_enable_signal = 1;
58905 +#endif
58906 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
58907 + grsec_enable_forkfail = 1;
58908 +#endif
58909 +#ifdef CONFIG_GRKERNSEC_TIME
58910 + grsec_enable_time = 1;
58911 +#endif
58912 +#ifdef CONFIG_GRKERNSEC_RESLOG
58913 + grsec_resource_logging = 1;
58914 +#endif
58915 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
58916 + grsec_enable_chroot_findtask = 1;
58917 +#endif
58918 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
58919 + grsec_enable_chroot_unix = 1;
58920 +#endif
58921 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
58922 + grsec_enable_chroot_mount = 1;
58923 +#endif
58924 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
58925 + grsec_enable_chroot_fchdir = 1;
58926 +#endif
58927 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
58928 + grsec_enable_chroot_shmat = 1;
58929 +#endif
58930 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58931 + grsec_enable_audit_ptrace = 1;
58932 +#endif
58933 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
58934 + grsec_enable_chroot_double = 1;
58935 +#endif
58936 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
58937 + grsec_enable_chroot_pivot = 1;
58938 +#endif
58939 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
58940 + grsec_enable_chroot_chdir = 1;
58941 +#endif
58942 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
58943 + grsec_enable_chroot_chmod = 1;
58944 +#endif
58945 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
58946 + grsec_enable_chroot_mknod = 1;
58947 +#endif
58948 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
58949 + grsec_enable_chroot_nice = 1;
58950 +#endif
58951 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
58952 + grsec_enable_chroot_execlog = 1;
58953 +#endif
58954 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58955 + grsec_enable_chroot_caps = 1;
58956 +#endif
58957 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
58958 + grsec_enable_chroot_sysctl = 1;
58959 +#endif
58960 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
58961 + grsec_enable_symlinkown = 1;
58962 + grsec_symlinkown_gid = CONFIG_GRKERNSEC_SYMLINKOWN_GID;
58963 +#endif
58964 +#ifdef CONFIG_GRKERNSEC_TPE
58965 + grsec_enable_tpe = 1;
58966 + grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
58967 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
58968 + grsec_enable_tpe_all = 1;
58969 +#endif
58970 +#endif
58971 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
58972 + grsec_enable_socket_all = 1;
58973 + grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
58974 +#endif
58975 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
58976 + grsec_enable_socket_client = 1;
58977 + grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
58978 +#endif
58979 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58980 + grsec_enable_socket_server = 1;
58981 + grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
58982 +#endif
58983 +#endif
58984 +
58985 + return;
58986 +}
58987 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
58988 new file mode 100644
58989 index 0000000..589481f
58990 --- /dev/null
58991 +++ b/grsecurity/grsec_link.c
58992 @@ -0,0 +1,58 @@
58993 +#include <linux/kernel.h>
58994 +#include <linux/sched.h>
58995 +#include <linux/fs.h>
58996 +#include <linux/file.h>
58997 +#include <linux/grinternal.h>
58998 +
58999 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
59000 +{
59001 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
59002 + const struct inode *link_inode = link->dentry->d_inode;
59003 +
59004 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
59005 + /* ignore root-owned links, e.g. /proc/self */
59006 + !uid_eq(link_inode->i_uid, GLOBAL_ROOT_UID) && target &&
59007 + !uid_eq(link_inode->i_uid, target->i_uid)) {
59008 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
59009 + return 1;
59010 + }
59011 +#endif
59012 + return 0;
59013 +}
59014 +
59015 +int
59016 +gr_handle_follow_link(const struct inode *parent,
59017 + const struct inode *inode,
59018 + const struct dentry *dentry, const struct vfsmount *mnt)
59019 +{
59020 +#ifdef CONFIG_GRKERNSEC_LINK
59021 + const struct cred *cred = current_cred();
59022 +
59023 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
59024 + (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
59025 + (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
59026 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
59027 + return -EACCES;
59028 + }
59029 +#endif
59030 + return 0;
59031 +}
59032 +
59033 +int
59034 +gr_handle_hardlink(const struct dentry *dentry,
59035 + const struct vfsmount *mnt,
59036 + struct inode *inode, const int mode, const char *to)
59037 +{
59038 +#ifdef CONFIG_GRKERNSEC_LINK
59039 + const struct cred *cred = current_cred();
59040 +
59041 + if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
59042 + (!S_ISREG(mode) || is_privileged_binary(dentry) ||
59043 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
59044 + !capable(CAP_FOWNER) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
59045 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
59046 + return -EPERM;
59047 + }
59048 +#endif
59049 + return 0;
59050 +}
59051 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
59052 new file mode 100644
59053 index 0000000..a45d2e9
59054 --- /dev/null
59055 +++ b/grsecurity/grsec_log.c
59056 @@ -0,0 +1,322 @@
59057 +#include <linux/kernel.h>
59058 +#include <linux/sched.h>
59059 +#include <linux/file.h>
59060 +#include <linux/tty.h>
59061 +#include <linux/fs.h>
59062 +#include <linux/grinternal.h>
59063 +
59064 +#ifdef CONFIG_TREE_PREEMPT_RCU
59065 +#define DISABLE_PREEMPT() preempt_disable()
59066 +#define ENABLE_PREEMPT() preempt_enable()
59067 +#else
59068 +#define DISABLE_PREEMPT()
59069 +#define ENABLE_PREEMPT()
59070 +#endif
59071 +
59072 +#define BEGIN_LOCKS(x) \
59073 + DISABLE_PREEMPT(); \
59074 + rcu_read_lock(); \
59075 + read_lock(&tasklist_lock); \
59076 + read_lock(&grsec_exec_file_lock); \
59077 + if (x != GR_DO_AUDIT) \
59078 + spin_lock(&grsec_alert_lock); \
59079 + else \
59080 + spin_lock(&grsec_audit_lock)
59081 +
59082 +#define END_LOCKS(x) \
59083 + if (x != GR_DO_AUDIT) \
59084 + spin_unlock(&grsec_alert_lock); \
59085 + else \
59086 + spin_unlock(&grsec_audit_lock); \
59087 + read_unlock(&grsec_exec_file_lock); \
59088 + read_unlock(&tasklist_lock); \
59089 + rcu_read_unlock(); \
59090 + ENABLE_PREEMPT(); \
59091 + if (x == GR_DONT_AUDIT) \
59092 + gr_handle_alertkill(current)
59093 +
59094 +enum {
59095 + FLOODING,
59096 + NO_FLOODING
59097 +};
59098 +
59099 +extern char *gr_alert_log_fmt;
59100 +extern char *gr_audit_log_fmt;
59101 +extern char *gr_alert_log_buf;
59102 +extern char *gr_audit_log_buf;
59103 +
59104 +static int gr_log_start(int audit)
59105 +{
59106 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
59107 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
59108 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
59109 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
59110 + unsigned long curr_secs = get_seconds();
59111 +
59112 + if (audit == GR_DO_AUDIT)
59113 + goto set_fmt;
59114 +
59115 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
59116 + grsec_alert_wtime = curr_secs;
59117 + grsec_alert_fyet = 0;
59118 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
59119 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
59120 + grsec_alert_fyet++;
59121 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
59122 + grsec_alert_wtime = curr_secs;
59123 + grsec_alert_fyet++;
59124 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
59125 + return FLOODING;
59126 + }
59127 + else return FLOODING;
59128 +
59129 +set_fmt:
59130 +#endif
59131 + memset(buf, 0, PAGE_SIZE);
59132 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
59133 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
59134 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
59135 + } else if (current->signal->curr_ip) {
59136 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
59137 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
59138 + } else if (gr_acl_is_enabled()) {
59139 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
59140 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
59141 + } else {
59142 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
59143 + strcpy(buf, fmt);
59144 + }
59145 +
59146 + return NO_FLOODING;
59147 +}
59148 +
59149 +static void gr_log_middle(int audit, const char *msg, va_list ap)
59150 + __attribute__ ((format (printf, 2, 0)));
59151 +
59152 +static void gr_log_middle(int audit, const char *msg, va_list ap)
59153 +{
59154 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
59155 + unsigned int len = strlen(buf);
59156 +
59157 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
59158 +
59159 + return;
59160 +}
59161 +
59162 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
59163 + __attribute__ ((format (printf, 2, 3)));
59164 +
59165 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
59166 +{
59167 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
59168 + unsigned int len = strlen(buf);
59169 + va_list ap;
59170 +
59171 + va_start(ap, msg);
59172 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
59173 + va_end(ap);
59174 +
59175 + return;
59176 +}
59177 +
59178 +static void gr_log_end(int audit, int append_default)
59179 +{
59180 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
59181 +
59182 + if (append_default) {
59183 + unsigned int len = strlen(buf);
59184 + snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
59185 + }
59186 +
59187 + printk("%s\n", buf);
59188 +
59189 + return;
59190 +}
59191 +
59192 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
59193 +{
59194 + int logtype;
59195 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
59196 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
59197 + void *voidptr = NULL;
59198 + int num1 = 0, num2 = 0;
59199 + unsigned long ulong1 = 0, ulong2 = 0;
59200 + struct dentry *dentry = NULL;
59201 + struct vfsmount *mnt = NULL;
59202 + struct file *file = NULL;
59203 + struct task_struct *task = NULL;
59204 + const struct cred *cred, *pcred;
59205 + va_list ap;
59206 +
59207 + BEGIN_LOCKS(audit);
59208 + logtype = gr_log_start(audit);
59209 + if (logtype == FLOODING) {
59210 + END_LOCKS(audit);
59211 + return;
59212 + }
59213 + va_start(ap, argtypes);
59214 + switch (argtypes) {
59215 + case GR_TTYSNIFF:
59216 + task = va_arg(ap, struct task_struct *);
59217 + 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);
59218 + break;
59219 + case GR_SYSCTL_HIDDEN:
59220 + str1 = va_arg(ap, char *);
59221 + gr_log_middle_varargs(audit, msg, result, str1);
59222 + break;
59223 + case GR_RBAC:
59224 + dentry = va_arg(ap, struct dentry *);
59225 + mnt = va_arg(ap, struct vfsmount *);
59226 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
59227 + break;
59228 + case GR_RBAC_STR:
59229 + dentry = va_arg(ap, struct dentry *);
59230 + mnt = va_arg(ap, struct vfsmount *);
59231 + str1 = va_arg(ap, char *);
59232 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
59233 + break;
59234 + case GR_STR_RBAC:
59235 + str1 = va_arg(ap, char *);
59236 + dentry = va_arg(ap, struct dentry *);
59237 + mnt = va_arg(ap, struct vfsmount *);
59238 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
59239 + break;
59240 + case GR_RBAC_MODE2:
59241 + dentry = va_arg(ap, struct dentry *);
59242 + mnt = va_arg(ap, struct vfsmount *);
59243 + str1 = va_arg(ap, char *);
59244 + str2 = va_arg(ap, char *);
59245 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
59246 + break;
59247 + case GR_RBAC_MODE3:
59248 + dentry = va_arg(ap, struct dentry *);
59249 + mnt = va_arg(ap, struct vfsmount *);
59250 + str1 = va_arg(ap, char *);
59251 + str2 = va_arg(ap, char *);
59252 + str3 = va_arg(ap, char *);
59253 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
59254 + break;
59255 + case GR_FILENAME:
59256 + dentry = va_arg(ap, struct dentry *);
59257 + mnt = va_arg(ap, struct vfsmount *);
59258 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
59259 + break;
59260 + case GR_STR_FILENAME:
59261 + str1 = va_arg(ap, char *);
59262 + dentry = va_arg(ap, struct dentry *);
59263 + mnt = va_arg(ap, struct vfsmount *);
59264 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
59265 + break;
59266 + case GR_FILENAME_STR:
59267 + dentry = va_arg(ap, struct dentry *);
59268 + mnt = va_arg(ap, struct vfsmount *);
59269 + str1 = va_arg(ap, char *);
59270 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
59271 + break;
59272 + case GR_FILENAME_TWO_INT:
59273 + dentry = va_arg(ap, struct dentry *);
59274 + mnt = va_arg(ap, struct vfsmount *);
59275 + num1 = va_arg(ap, int);
59276 + num2 = va_arg(ap, int);
59277 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
59278 + break;
59279 + case GR_FILENAME_TWO_INT_STR:
59280 + dentry = va_arg(ap, struct dentry *);
59281 + mnt = va_arg(ap, struct vfsmount *);
59282 + num1 = va_arg(ap, int);
59283 + num2 = va_arg(ap, int);
59284 + str1 = va_arg(ap, char *);
59285 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
59286 + break;
59287 + case GR_TEXTREL:
59288 + file = va_arg(ap, struct file *);
59289 + ulong1 = va_arg(ap, unsigned long);
59290 + ulong2 = va_arg(ap, unsigned long);
59291 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
59292 + break;
59293 + case GR_PTRACE:
59294 + task = va_arg(ap, struct task_struct *);
59295 + 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);
59296 + break;
59297 + case GR_RESOURCE:
59298 + task = va_arg(ap, struct task_struct *);
59299 + cred = __task_cred(task);
59300 + pcred = __task_cred(task->real_parent);
59301 + ulong1 = va_arg(ap, unsigned long);
59302 + str1 = va_arg(ap, char *);
59303 + ulong2 = va_arg(ap, unsigned long);
59304 + 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);
59305 + break;
59306 + case GR_CAP:
59307 + task = va_arg(ap, struct task_struct *);
59308 + cred = __task_cred(task);
59309 + pcred = __task_cred(task->real_parent);
59310 + str1 = va_arg(ap, char *);
59311 + 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);
59312 + break;
59313 + case GR_SIG:
59314 + str1 = va_arg(ap, char *);
59315 + voidptr = va_arg(ap, void *);
59316 + gr_log_middle_varargs(audit, msg, str1, voidptr);
59317 + break;
59318 + case GR_SIG2:
59319 + task = va_arg(ap, struct task_struct *);
59320 + cred = __task_cred(task);
59321 + pcred = __task_cred(task->real_parent);
59322 + num1 = va_arg(ap, int);
59323 + 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);
59324 + break;
59325 + case GR_CRASH1:
59326 + task = va_arg(ap, struct task_struct *);
59327 + cred = __task_cred(task);
59328 + pcred = __task_cred(task->real_parent);
59329 + ulong1 = va_arg(ap, unsigned long);
59330 + 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);
59331 + break;
59332 + case GR_CRASH2:
59333 + task = va_arg(ap, struct task_struct *);
59334 + cred = __task_cred(task);
59335 + pcred = __task_cred(task->real_parent);
59336 + ulong1 = va_arg(ap, unsigned long);
59337 + 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);
59338 + break;
59339 + case GR_RWXMAP:
59340 + file = va_arg(ap, struct file *);
59341 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
59342 + break;
59343 + case GR_PSACCT:
59344 + {
59345 + unsigned int wday, cday;
59346 + __u8 whr, chr;
59347 + __u8 wmin, cmin;
59348 + __u8 wsec, csec;
59349 + char cur_tty[64] = { 0 };
59350 + char parent_tty[64] = { 0 };
59351 +
59352 + task = va_arg(ap, struct task_struct *);
59353 + wday = va_arg(ap, unsigned int);
59354 + cday = va_arg(ap, unsigned int);
59355 + whr = va_arg(ap, int);
59356 + chr = va_arg(ap, int);
59357 + wmin = va_arg(ap, int);
59358 + cmin = va_arg(ap, int);
59359 + wsec = va_arg(ap, int);
59360 + csec = va_arg(ap, int);
59361 + ulong1 = va_arg(ap, unsigned long);
59362 + cred = __task_cred(task);
59363 + pcred = __task_cred(task->real_parent);
59364 +
59365 + 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);
59366 + }
59367 + break;
59368 + default:
59369 + gr_log_middle(audit, msg, ap);
59370 + }
59371 + va_end(ap);
59372 + // these don't need DEFAULTSECARGS printed on the end
59373 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
59374 + gr_log_end(audit, 0);
59375 + else
59376 + gr_log_end(audit, 1);
59377 + END_LOCKS(audit);
59378 +}
59379 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
59380 new file mode 100644
59381 index 0000000..f536303
59382 --- /dev/null
59383 +++ b/grsecurity/grsec_mem.c
59384 @@ -0,0 +1,40 @@
59385 +#include <linux/kernel.h>
59386 +#include <linux/sched.h>
59387 +#include <linux/mm.h>
59388 +#include <linux/mman.h>
59389 +#include <linux/grinternal.h>
59390 +
59391 +void
59392 +gr_handle_ioperm(void)
59393 +{
59394 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
59395 + return;
59396 +}
59397 +
59398 +void
59399 +gr_handle_iopl(void)
59400 +{
59401 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
59402 + return;
59403 +}
59404 +
59405 +void
59406 +gr_handle_mem_readwrite(u64 from, u64 to)
59407 +{
59408 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
59409 + return;
59410 +}
59411 +
59412 +void
59413 +gr_handle_vm86(void)
59414 +{
59415 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
59416 + return;
59417 +}
59418 +
59419 +void
59420 +gr_log_badprocpid(const char *entry)
59421 +{
59422 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
59423 + return;
59424 +}
59425 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
59426 new file mode 100644
59427 index 0000000..2131422
59428 --- /dev/null
59429 +++ b/grsecurity/grsec_mount.c
59430 @@ -0,0 +1,62 @@
59431 +#include <linux/kernel.h>
59432 +#include <linux/sched.h>
59433 +#include <linux/mount.h>
59434 +#include <linux/grsecurity.h>
59435 +#include <linux/grinternal.h>
59436 +
59437 +void
59438 +gr_log_remount(const char *devname, const int retval)
59439 +{
59440 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59441 + if (grsec_enable_mount && (retval >= 0))
59442 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
59443 +#endif
59444 + return;
59445 +}
59446 +
59447 +void
59448 +gr_log_unmount(const char *devname, const int retval)
59449 +{
59450 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59451 + if (grsec_enable_mount && (retval >= 0))
59452 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
59453 +#endif
59454 + return;
59455 +}
59456 +
59457 +void
59458 +gr_log_mount(const char *from, const char *to, const int retval)
59459 +{
59460 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59461 + if (grsec_enable_mount && (retval >= 0))
59462 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
59463 +#endif
59464 + return;
59465 +}
59466 +
59467 +int
59468 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
59469 +{
59470 +#ifdef CONFIG_GRKERNSEC_ROFS
59471 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
59472 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
59473 + return -EPERM;
59474 + } else
59475 + return 0;
59476 +#endif
59477 + return 0;
59478 +}
59479 +
59480 +int
59481 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
59482 +{
59483 +#ifdef CONFIG_GRKERNSEC_ROFS
59484 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
59485 + dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
59486 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
59487 + return -EPERM;
59488 + } else
59489 + return 0;
59490 +#endif
59491 + return 0;
59492 +}
59493 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
59494 new file mode 100644
59495 index 0000000..a3b12a0
59496 --- /dev/null
59497 +++ b/grsecurity/grsec_pax.c
59498 @@ -0,0 +1,36 @@
59499 +#include <linux/kernel.h>
59500 +#include <linux/sched.h>
59501 +#include <linux/mm.h>
59502 +#include <linux/file.h>
59503 +#include <linux/grinternal.h>
59504 +#include <linux/grsecurity.h>
59505 +
59506 +void
59507 +gr_log_textrel(struct vm_area_struct * vma)
59508 +{
59509 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
59510 + if (grsec_enable_audit_textrel)
59511 + gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
59512 +#endif
59513 + return;
59514 +}
59515 +
59516 +void
59517 +gr_log_rwxmmap(struct file *file)
59518 +{
59519 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59520 + if (grsec_enable_log_rwxmaps)
59521 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
59522 +#endif
59523 + return;
59524 +}
59525 +
59526 +void
59527 +gr_log_rwxmprotect(struct file *file)
59528 +{
59529 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59530 + if (grsec_enable_log_rwxmaps)
59531 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
59532 +#endif
59533 + return;
59534 +}
59535 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
59536 new file mode 100644
59537 index 0000000..f7f29aa
59538 --- /dev/null
59539 +++ b/grsecurity/grsec_ptrace.c
59540 @@ -0,0 +1,30 @@
59541 +#include <linux/kernel.h>
59542 +#include <linux/sched.h>
59543 +#include <linux/grinternal.h>
59544 +#include <linux/security.h>
59545 +
59546 +void
59547 +gr_audit_ptrace(struct task_struct *task)
59548 +{
59549 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
59550 + if (grsec_enable_audit_ptrace)
59551 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
59552 +#endif
59553 + return;
59554 +}
59555 +
59556 +int
59557 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
59558 +{
59559 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
59560 + const struct dentry *dentry = file->f_path.dentry;
59561 + const struct vfsmount *mnt = file->f_path.mnt;
59562 +
59563 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
59564 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
59565 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
59566 + return -EACCES;
59567 + }
59568 +#endif
59569 + return 0;
59570 +}
59571 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
59572 new file mode 100644
59573 index 0000000..b4ac94c
59574 --- /dev/null
59575 +++ b/grsecurity/grsec_sig.c
59576 @@ -0,0 +1,209 @@
59577 +#include <linux/kernel.h>
59578 +#include <linux/sched.h>
59579 +#include <linux/delay.h>
59580 +#include <linux/grsecurity.h>
59581 +#include <linux/grinternal.h>
59582 +#include <linux/hardirq.h>
59583 +
59584 +char *signames[] = {
59585 + [SIGSEGV] = "Segmentation fault",
59586 + [SIGILL] = "Illegal instruction",
59587 + [SIGABRT] = "Abort",
59588 + [SIGBUS] = "Invalid alignment/Bus error"
59589 +};
59590 +
59591 +void
59592 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
59593 +{
59594 +#ifdef CONFIG_GRKERNSEC_SIGNAL
59595 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
59596 + (sig == SIGABRT) || (sig == SIGBUS))) {
59597 + if (t->pid == current->pid) {
59598 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
59599 + } else {
59600 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
59601 + }
59602 + }
59603 +#endif
59604 + return;
59605 +}
59606 +
59607 +int
59608 +gr_handle_signal(const struct task_struct *p, const int sig)
59609 +{
59610 +#ifdef CONFIG_GRKERNSEC
59611 + /* ignore the 0 signal for protected task checks */
59612 + if (current->pid > 1 && sig && gr_check_protected_task(p)) {
59613 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
59614 + return -EPERM;
59615 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
59616 + return -EPERM;
59617 + }
59618 +#endif
59619 + return 0;
59620 +}
59621 +
59622 +#ifdef CONFIG_GRKERNSEC
59623 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
59624 +
59625 +int gr_fake_force_sig(int sig, struct task_struct *t)
59626 +{
59627 + unsigned long int flags;
59628 + int ret, blocked, ignored;
59629 + struct k_sigaction *action;
59630 +
59631 + spin_lock_irqsave(&t->sighand->siglock, flags);
59632 + action = &t->sighand->action[sig-1];
59633 + ignored = action->sa.sa_handler == SIG_IGN;
59634 + blocked = sigismember(&t->blocked, sig);
59635 + if (blocked || ignored) {
59636 + action->sa.sa_handler = SIG_DFL;
59637 + if (blocked) {
59638 + sigdelset(&t->blocked, sig);
59639 + recalc_sigpending_and_wake(t);
59640 + }
59641 + }
59642 + if (action->sa.sa_handler == SIG_DFL)
59643 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
59644 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
59645 +
59646 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
59647 +
59648 + return ret;
59649 +}
59650 +#endif
59651 +
59652 +#ifdef CONFIG_GRKERNSEC_BRUTE
59653 +#define GR_USER_BAN_TIME (15 * 60)
59654 +
59655 +static int __get_dumpable(unsigned long mm_flags)
59656 +{
59657 + int ret;
59658 +
59659 + ret = mm_flags & MMF_DUMPABLE_MASK;
59660 + return (ret >= 2) ? 2 : ret;
59661 +}
59662 +#endif
59663 +
59664 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
59665 +{
59666 +#ifdef CONFIG_GRKERNSEC_BRUTE
59667 + kuid_t uid = GLOBAL_ROOT_UID;
59668 +
59669 + if (!grsec_enable_brute)
59670 + return;
59671 +
59672 + rcu_read_lock();
59673 + read_lock(&tasklist_lock);
59674 + read_lock(&grsec_exec_file_lock);
59675 + if (p->real_parent && p->real_parent->exec_file == p->exec_file)
59676 + p->real_parent->brute = 1;
59677 + else {
59678 + const struct cred *cred = __task_cred(p), *cred2;
59679 + struct task_struct *tsk, *tsk2;
59680 +
59681 + if (!__get_dumpable(mm_flags) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
59682 + struct user_struct *user;
59683 +
59684 + uid = cred->uid;
59685 +
59686 + /* this is put upon execution past expiration */
59687 + user = find_user(uid);
59688 + if (user == NULL)
59689 + goto unlock;
59690 + user->banned = 1;
59691 + user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
59692 + if (user->ban_expires == ~0UL)
59693 + user->ban_expires--;
59694 +
59695 + do_each_thread(tsk2, tsk) {
59696 + cred2 = __task_cred(tsk);
59697 + if (tsk != p && uid_eq(cred2->uid, uid))
59698 + gr_fake_force_sig(SIGKILL, tsk);
59699 + } while_each_thread(tsk2, tsk);
59700 + }
59701 + }
59702 +unlock:
59703 + read_unlock(&grsec_exec_file_lock);
59704 + read_unlock(&tasklist_lock);
59705 + rcu_read_unlock();
59706 +
59707 + if (!uid_eq(uid, GLOBAL_ROOT_UID))
59708 + printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
59709 + from_kuid_munged(&init_user_ns, uid), GR_USER_BAN_TIME / 60);
59710 +
59711 +#endif
59712 + return;
59713 +}
59714 +
59715 +void gr_handle_brute_check(void)
59716 +{
59717 +#ifdef CONFIG_GRKERNSEC_BRUTE
59718 + if (current->brute)
59719 + msleep(30 * 1000);
59720 +#endif
59721 + return;
59722 +}
59723 +
59724 +void gr_handle_kernel_exploit(void)
59725 +{
59726 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
59727 + const struct cred *cred;
59728 + struct task_struct *tsk, *tsk2;
59729 + struct user_struct *user;
59730 + kuid_t uid;
59731 +
59732 + if (in_irq() || in_serving_softirq() || in_nmi())
59733 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
59734 +
59735 + uid = current_uid();
59736 +
59737 + if (uid_eq(uid, GLOBAL_ROOT_UID))
59738 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
59739 + else {
59740 + /* kill all the processes of this user, hold a reference
59741 + to their creds struct, and prevent them from creating
59742 + another process until system reset
59743 + */
59744 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
59745 + from_kuid_munged(&init_user_ns, uid));
59746 + /* we intentionally leak this ref */
59747 + user = get_uid(current->cred->user);
59748 + if (user) {
59749 + user->banned = 1;
59750 + user->ban_expires = ~0UL;
59751 + }
59752 +
59753 + read_lock(&tasklist_lock);
59754 + do_each_thread(tsk2, tsk) {
59755 + cred = __task_cred(tsk);
59756 + if (uid_eq(cred->uid, uid))
59757 + gr_fake_force_sig(SIGKILL, tsk);
59758 + } while_each_thread(tsk2, tsk);
59759 + read_unlock(&tasklist_lock);
59760 + }
59761 +#endif
59762 +}
59763 +
59764 +int __gr_process_user_ban(struct user_struct *user)
59765 +{
59766 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59767 + if (unlikely(user->banned)) {
59768 + if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
59769 + user->banned = 0;
59770 + user->ban_expires = 0;
59771 + free_uid(user);
59772 + } else
59773 + return -EPERM;
59774 + }
59775 +#endif
59776 + return 0;
59777 +}
59778 +
59779 +int gr_process_user_ban(void)
59780 +{
59781 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59782 + return __gr_process_user_ban(current->cred->user);
59783 +#endif
59784 + return 0;
59785 +}
59786 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
59787 new file mode 100644
59788 index 0000000..4030d57
59789 --- /dev/null
59790 +++ b/grsecurity/grsec_sock.c
59791 @@ -0,0 +1,244 @@
59792 +#include <linux/kernel.h>
59793 +#include <linux/module.h>
59794 +#include <linux/sched.h>
59795 +#include <linux/file.h>
59796 +#include <linux/net.h>
59797 +#include <linux/in.h>
59798 +#include <linux/ip.h>
59799 +#include <net/sock.h>
59800 +#include <net/inet_sock.h>
59801 +#include <linux/grsecurity.h>
59802 +#include <linux/grinternal.h>
59803 +#include <linux/gracl.h>
59804 +
59805 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
59806 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
59807 +
59808 +EXPORT_SYMBOL(gr_search_udp_recvmsg);
59809 +EXPORT_SYMBOL(gr_search_udp_sendmsg);
59810 +
59811 +#ifdef CONFIG_UNIX_MODULE
59812 +EXPORT_SYMBOL(gr_acl_handle_unix);
59813 +EXPORT_SYMBOL(gr_acl_handle_mknod);
59814 +EXPORT_SYMBOL(gr_handle_chroot_unix);
59815 +EXPORT_SYMBOL(gr_handle_create);
59816 +#endif
59817 +
59818 +#ifdef CONFIG_GRKERNSEC
59819 +#define gr_conn_table_size 32749
59820 +struct conn_table_entry {
59821 + struct conn_table_entry *next;
59822 + struct signal_struct *sig;
59823 +};
59824 +
59825 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
59826 +DEFINE_SPINLOCK(gr_conn_table_lock);
59827 +
59828 +extern const char * gr_socktype_to_name(unsigned char type);
59829 +extern const char * gr_proto_to_name(unsigned char proto);
59830 +extern const char * gr_sockfamily_to_name(unsigned char family);
59831 +
59832 +static __inline__ int
59833 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
59834 +{
59835 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
59836 +}
59837 +
59838 +static __inline__ int
59839 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
59840 + __u16 sport, __u16 dport)
59841 +{
59842 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
59843 + sig->gr_sport == sport && sig->gr_dport == dport))
59844 + return 1;
59845 + else
59846 + return 0;
59847 +}
59848 +
59849 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
59850 +{
59851 + struct conn_table_entry **match;
59852 + unsigned int index;
59853 +
59854 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
59855 + sig->gr_sport, sig->gr_dport,
59856 + gr_conn_table_size);
59857 +
59858 + newent->sig = sig;
59859 +
59860 + match = &gr_conn_table[index];
59861 + newent->next = *match;
59862 + *match = newent;
59863 +
59864 + return;
59865 +}
59866 +
59867 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
59868 +{
59869 + struct conn_table_entry *match, *last = NULL;
59870 + unsigned int index;
59871 +
59872 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
59873 + sig->gr_sport, sig->gr_dport,
59874 + gr_conn_table_size);
59875 +
59876 + match = gr_conn_table[index];
59877 + while (match && !conn_match(match->sig,
59878 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
59879 + sig->gr_dport)) {
59880 + last = match;
59881 + match = match->next;
59882 + }
59883 +
59884 + if (match) {
59885 + if (last)
59886 + last->next = match->next;
59887 + else
59888 + gr_conn_table[index] = NULL;
59889 + kfree(match);
59890 + }
59891 +
59892 + return;
59893 +}
59894 +
59895 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
59896 + __u16 sport, __u16 dport)
59897 +{
59898 + struct conn_table_entry *match;
59899 + unsigned int index;
59900 +
59901 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
59902 +
59903 + match = gr_conn_table[index];
59904 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
59905 + match = match->next;
59906 +
59907 + if (match)
59908 + return match->sig;
59909 + else
59910 + return NULL;
59911 +}
59912 +
59913 +#endif
59914 +
59915 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
59916 +{
59917 +#ifdef CONFIG_GRKERNSEC
59918 + struct signal_struct *sig = task->signal;
59919 + struct conn_table_entry *newent;
59920 +
59921 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
59922 + if (newent == NULL)
59923 + return;
59924 + /* no bh lock needed since we are called with bh disabled */
59925 + spin_lock(&gr_conn_table_lock);
59926 + gr_del_task_from_ip_table_nolock(sig);
59927 + sig->gr_saddr = inet->inet_rcv_saddr;
59928 + sig->gr_daddr = inet->inet_daddr;
59929 + sig->gr_sport = inet->inet_sport;
59930 + sig->gr_dport = inet->inet_dport;
59931 + gr_add_to_task_ip_table_nolock(sig, newent);
59932 + spin_unlock(&gr_conn_table_lock);
59933 +#endif
59934 + return;
59935 +}
59936 +
59937 +void gr_del_task_from_ip_table(struct task_struct *task)
59938 +{
59939 +#ifdef CONFIG_GRKERNSEC
59940 + spin_lock_bh(&gr_conn_table_lock);
59941 + gr_del_task_from_ip_table_nolock(task->signal);
59942 + spin_unlock_bh(&gr_conn_table_lock);
59943 +#endif
59944 + return;
59945 +}
59946 +
59947 +void
59948 +gr_attach_curr_ip(const struct sock *sk)
59949 +{
59950 +#ifdef CONFIG_GRKERNSEC
59951 + struct signal_struct *p, *set;
59952 + const struct inet_sock *inet = inet_sk(sk);
59953 +
59954 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
59955 + return;
59956 +
59957 + set = current->signal;
59958 +
59959 + spin_lock_bh(&gr_conn_table_lock);
59960 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
59961 + inet->inet_dport, inet->inet_sport);
59962 + if (unlikely(p != NULL)) {
59963 + set->curr_ip = p->curr_ip;
59964 + set->used_accept = 1;
59965 + gr_del_task_from_ip_table_nolock(p);
59966 + spin_unlock_bh(&gr_conn_table_lock);
59967 + return;
59968 + }
59969 + spin_unlock_bh(&gr_conn_table_lock);
59970 +
59971 + set->curr_ip = inet->inet_daddr;
59972 + set->used_accept = 1;
59973 +#endif
59974 + return;
59975 +}
59976 +
59977 +int
59978 +gr_handle_sock_all(const int family, const int type, const int protocol)
59979 +{
59980 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59981 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
59982 + (family != AF_UNIX)) {
59983 + if (family == AF_INET)
59984 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
59985 + else
59986 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
59987 + return -EACCES;
59988 + }
59989 +#endif
59990 + return 0;
59991 +}
59992 +
59993 +int
59994 +gr_handle_sock_server(const struct sockaddr *sck)
59995 +{
59996 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59997 + if (grsec_enable_socket_server &&
59998 + in_group_p(grsec_socket_server_gid) &&
59999 + sck && (sck->sa_family != AF_UNIX) &&
60000 + (sck->sa_family != AF_LOCAL)) {
60001 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
60002 + return -EACCES;
60003 + }
60004 +#endif
60005 + return 0;
60006 +}
60007 +
60008 +int
60009 +gr_handle_sock_server_other(const struct sock *sck)
60010 +{
60011 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
60012 + if (grsec_enable_socket_server &&
60013 + in_group_p(grsec_socket_server_gid) &&
60014 + sck && (sck->sk_family != AF_UNIX) &&
60015 + (sck->sk_family != AF_LOCAL)) {
60016 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
60017 + return -EACCES;
60018 + }
60019 +#endif
60020 + return 0;
60021 +}
60022 +
60023 +int
60024 +gr_handle_sock_client(const struct sockaddr *sck)
60025 +{
60026 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
60027 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
60028 + sck && (sck->sa_family != AF_UNIX) &&
60029 + (sck->sa_family != AF_LOCAL)) {
60030 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
60031 + return -EACCES;
60032 + }
60033 +#endif
60034 + return 0;
60035 +}
60036 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
60037 new file mode 100644
60038 index 0000000..f55ef0f
60039 --- /dev/null
60040 +++ b/grsecurity/grsec_sysctl.c
60041 @@ -0,0 +1,469 @@
60042 +#include <linux/kernel.h>
60043 +#include <linux/sched.h>
60044 +#include <linux/sysctl.h>
60045 +#include <linux/grsecurity.h>
60046 +#include <linux/grinternal.h>
60047 +
60048 +int
60049 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
60050 +{
60051 +#ifdef CONFIG_GRKERNSEC_SYSCTL
60052 + if (dirname == NULL || name == NULL)
60053 + return 0;
60054 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
60055 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
60056 + return -EACCES;
60057 + }
60058 +#endif
60059 + return 0;
60060 +}
60061 +
60062 +#ifdef CONFIG_GRKERNSEC_ROFS
60063 +static int __maybe_unused one = 1;
60064 +#endif
60065 +
60066 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
60067 +struct ctl_table grsecurity_table[] = {
60068 +#ifdef CONFIG_GRKERNSEC_SYSCTL
60069 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
60070 +#ifdef CONFIG_GRKERNSEC_IO
60071 + {
60072 + .procname = "disable_priv_io",
60073 + .data = &grsec_disable_privio,
60074 + .maxlen = sizeof(int),
60075 + .mode = 0600,
60076 + .proc_handler = &proc_dointvec,
60077 + },
60078 +#endif
60079 +#endif
60080 +#ifdef CONFIG_GRKERNSEC_LINK
60081 + {
60082 + .procname = "linking_restrictions",
60083 + .data = &grsec_enable_link,
60084 + .maxlen = sizeof(int),
60085 + .mode = 0600,
60086 + .proc_handler = &proc_dointvec,
60087 + },
60088 +#endif
60089 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
60090 + {
60091 + .procname = "enforce_symlinksifowner",
60092 + .data = &grsec_enable_symlinkown,
60093 + .maxlen = sizeof(int),
60094 + .mode = 0600,
60095 + .proc_handler = &proc_dointvec,
60096 + },
60097 + {
60098 + .procname = "symlinkown_gid",
60099 + .data = &grsec_symlinkown_gid,
60100 + .maxlen = sizeof(int),
60101 + .mode = 0600,
60102 + .proc_handler = &proc_dointvec,
60103 + },
60104 +#endif
60105 +#ifdef CONFIG_GRKERNSEC_BRUTE
60106 + {
60107 + .procname = "deter_bruteforce",
60108 + .data = &grsec_enable_brute,
60109 + .maxlen = sizeof(int),
60110 + .mode = 0600,
60111 + .proc_handler = &proc_dointvec,
60112 + },
60113 +#endif
60114 +#ifdef CONFIG_GRKERNSEC_FIFO
60115 + {
60116 + .procname = "fifo_restrictions",
60117 + .data = &grsec_enable_fifo,
60118 + .maxlen = sizeof(int),
60119 + .mode = 0600,
60120 + .proc_handler = &proc_dointvec,
60121 + },
60122 +#endif
60123 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
60124 + {
60125 + .procname = "ptrace_readexec",
60126 + .data = &grsec_enable_ptrace_readexec,
60127 + .maxlen = sizeof(int),
60128 + .mode = 0600,
60129 + .proc_handler = &proc_dointvec,
60130 + },
60131 +#endif
60132 +#ifdef CONFIG_GRKERNSEC_SETXID
60133 + {
60134 + .procname = "consistent_setxid",
60135 + .data = &grsec_enable_setxid,
60136 + .maxlen = sizeof(int),
60137 + .mode = 0600,
60138 + .proc_handler = &proc_dointvec,
60139 + },
60140 +#endif
60141 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
60142 + {
60143 + .procname = "ip_blackhole",
60144 + .data = &grsec_enable_blackhole,
60145 + .maxlen = sizeof(int),
60146 + .mode = 0600,
60147 + .proc_handler = &proc_dointvec,
60148 + },
60149 + {
60150 + .procname = "lastack_retries",
60151 + .data = &grsec_lastack_retries,
60152 + .maxlen = sizeof(int),
60153 + .mode = 0600,
60154 + .proc_handler = &proc_dointvec,
60155 + },
60156 +#endif
60157 +#ifdef CONFIG_GRKERNSEC_EXECLOG
60158 + {
60159 + .procname = "exec_logging",
60160 + .data = &grsec_enable_execlog,
60161 + .maxlen = sizeof(int),
60162 + .mode = 0600,
60163 + .proc_handler = &proc_dointvec,
60164 + },
60165 +#endif
60166 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
60167 + {
60168 + .procname = "rwxmap_logging",
60169 + .data = &grsec_enable_log_rwxmaps,
60170 + .maxlen = sizeof(int),
60171 + .mode = 0600,
60172 + .proc_handler = &proc_dointvec,
60173 + },
60174 +#endif
60175 +#ifdef CONFIG_GRKERNSEC_SIGNAL
60176 + {
60177 + .procname = "signal_logging",
60178 + .data = &grsec_enable_signal,
60179 + .maxlen = sizeof(int),
60180 + .mode = 0600,
60181 + .proc_handler = &proc_dointvec,
60182 + },
60183 +#endif
60184 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
60185 + {
60186 + .procname = "forkfail_logging",
60187 + .data = &grsec_enable_forkfail,
60188 + .maxlen = sizeof(int),
60189 + .mode = 0600,
60190 + .proc_handler = &proc_dointvec,
60191 + },
60192 +#endif
60193 +#ifdef CONFIG_GRKERNSEC_TIME
60194 + {
60195 + .procname = "timechange_logging",
60196 + .data = &grsec_enable_time,
60197 + .maxlen = sizeof(int),
60198 + .mode = 0600,
60199 + .proc_handler = &proc_dointvec,
60200 + },
60201 +#endif
60202 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
60203 + {
60204 + .procname = "chroot_deny_shmat",
60205 + .data = &grsec_enable_chroot_shmat,
60206 + .maxlen = sizeof(int),
60207 + .mode = 0600,
60208 + .proc_handler = &proc_dointvec,
60209 + },
60210 +#endif
60211 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
60212 + {
60213 + .procname = "chroot_deny_unix",
60214 + .data = &grsec_enable_chroot_unix,
60215 + .maxlen = sizeof(int),
60216 + .mode = 0600,
60217 + .proc_handler = &proc_dointvec,
60218 + },
60219 +#endif
60220 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
60221 + {
60222 + .procname = "chroot_deny_mount",
60223 + .data = &grsec_enable_chroot_mount,
60224 + .maxlen = sizeof(int),
60225 + .mode = 0600,
60226 + .proc_handler = &proc_dointvec,
60227 + },
60228 +#endif
60229 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
60230 + {
60231 + .procname = "chroot_deny_fchdir",
60232 + .data = &grsec_enable_chroot_fchdir,
60233 + .maxlen = sizeof(int),
60234 + .mode = 0600,
60235 + .proc_handler = &proc_dointvec,
60236 + },
60237 +#endif
60238 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
60239 + {
60240 + .procname = "chroot_deny_chroot",
60241 + .data = &grsec_enable_chroot_double,
60242 + .maxlen = sizeof(int),
60243 + .mode = 0600,
60244 + .proc_handler = &proc_dointvec,
60245 + },
60246 +#endif
60247 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
60248 + {
60249 + .procname = "chroot_deny_pivot",
60250 + .data = &grsec_enable_chroot_pivot,
60251 + .maxlen = sizeof(int),
60252 + .mode = 0600,
60253 + .proc_handler = &proc_dointvec,
60254 + },
60255 +#endif
60256 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
60257 + {
60258 + .procname = "chroot_enforce_chdir",
60259 + .data = &grsec_enable_chroot_chdir,
60260 + .maxlen = sizeof(int),
60261 + .mode = 0600,
60262 + .proc_handler = &proc_dointvec,
60263 + },
60264 +#endif
60265 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
60266 + {
60267 + .procname = "chroot_deny_chmod",
60268 + .data = &grsec_enable_chroot_chmod,
60269 + .maxlen = sizeof(int),
60270 + .mode = 0600,
60271 + .proc_handler = &proc_dointvec,
60272 + },
60273 +#endif
60274 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
60275 + {
60276 + .procname = "chroot_deny_mknod",
60277 + .data = &grsec_enable_chroot_mknod,
60278 + .maxlen = sizeof(int),
60279 + .mode = 0600,
60280 + .proc_handler = &proc_dointvec,
60281 + },
60282 +#endif
60283 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
60284 + {
60285 + .procname = "chroot_restrict_nice",
60286 + .data = &grsec_enable_chroot_nice,
60287 + .maxlen = sizeof(int),
60288 + .mode = 0600,
60289 + .proc_handler = &proc_dointvec,
60290 + },
60291 +#endif
60292 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
60293 + {
60294 + .procname = "chroot_execlog",
60295 + .data = &grsec_enable_chroot_execlog,
60296 + .maxlen = sizeof(int),
60297 + .mode = 0600,
60298 + .proc_handler = &proc_dointvec,
60299 + },
60300 +#endif
60301 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
60302 + {
60303 + .procname = "chroot_caps",
60304 + .data = &grsec_enable_chroot_caps,
60305 + .maxlen = sizeof(int),
60306 + .mode = 0600,
60307 + .proc_handler = &proc_dointvec,
60308 + },
60309 +#endif
60310 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
60311 + {
60312 + .procname = "chroot_deny_sysctl",
60313 + .data = &grsec_enable_chroot_sysctl,
60314 + .maxlen = sizeof(int),
60315 + .mode = 0600,
60316 + .proc_handler = &proc_dointvec,
60317 + },
60318 +#endif
60319 +#ifdef CONFIG_GRKERNSEC_TPE
60320 + {
60321 + .procname = "tpe",
60322 + .data = &grsec_enable_tpe,
60323 + .maxlen = sizeof(int),
60324 + .mode = 0600,
60325 + .proc_handler = &proc_dointvec,
60326 + },
60327 + {
60328 + .procname = "tpe_gid",
60329 + .data = &grsec_tpe_gid,
60330 + .maxlen = sizeof(int),
60331 + .mode = 0600,
60332 + .proc_handler = &proc_dointvec,
60333 + },
60334 +#endif
60335 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
60336 + {
60337 + .procname = "tpe_invert",
60338 + .data = &grsec_enable_tpe_invert,
60339 + .maxlen = sizeof(int),
60340 + .mode = 0600,
60341 + .proc_handler = &proc_dointvec,
60342 + },
60343 +#endif
60344 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
60345 + {
60346 + .procname = "tpe_restrict_all",
60347 + .data = &grsec_enable_tpe_all,
60348 + .maxlen = sizeof(int),
60349 + .mode = 0600,
60350 + .proc_handler = &proc_dointvec,
60351 + },
60352 +#endif
60353 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
60354 + {
60355 + .procname = "socket_all",
60356 + .data = &grsec_enable_socket_all,
60357 + .maxlen = sizeof(int),
60358 + .mode = 0600,
60359 + .proc_handler = &proc_dointvec,
60360 + },
60361 + {
60362 + .procname = "socket_all_gid",
60363 + .data = &grsec_socket_all_gid,
60364 + .maxlen = sizeof(int),
60365 + .mode = 0600,
60366 + .proc_handler = &proc_dointvec,
60367 + },
60368 +#endif
60369 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
60370 + {
60371 + .procname = "socket_client",
60372 + .data = &grsec_enable_socket_client,
60373 + .maxlen = sizeof(int),
60374 + .mode = 0600,
60375 + .proc_handler = &proc_dointvec,
60376 + },
60377 + {
60378 + .procname = "socket_client_gid",
60379 + .data = &grsec_socket_client_gid,
60380 + .maxlen = sizeof(int),
60381 + .mode = 0600,
60382 + .proc_handler = &proc_dointvec,
60383 + },
60384 +#endif
60385 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
60386 + {
60387 + .procname = "socket_server",
60388 + .data = &grsec_enable_socket_server,
60389 + .maxlen = sizeof(int),
60390 + .mode = 0600,
60391 + .proc_handler = &proc_dointvec,
60392 + },
60393 + {
60394 + .procname = "socket_server_gid",
60395 + .data = &grsec_socket_server_gid,
60396 + .maxlen = sizeof(int),
60397 + .mode = 0600,
60398 + .proc_handler = &proc_dointvec,
60399 + },
60400 +#endif
60401 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
60402 + {
60403 + .procname = "audit_group",
60404 + .data = &grsec_enable_group,
60405 + .maxlen = sizeof(int),
60406 + .mode = 0600,
60407 + .proc_handler = &proc_dointvec,
60408 + },
60409 + {
60410 + .procname = "audit_gid",
60411 + .data = &grsec_audit_gid,
60412 + .maxlen = sizeof(int),
60413 + .mode = 0600,
60414 + .proc_handler = &proc_dointvec,
60415 + },
60416 +#endif
60417 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
60418 + {
60419 + .procname = "audit_chdir",
60420 + .data = &grsec_enable_chdir,
60421 + .maxlen = sizeof(int),
60422 + .mode = 0600,
60423 + .proc_handler = &proc_dointvec,
60424 + },
60425 +#endif
60426 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
60427 + {
60428 + .procname = "audit_mount",
60429 + .data = &grsec_enable_mount,
60430 + .maxlen = sizeof(int),
60431 + .mode = 0600,
60432 + .proc_handler = &proc_dointvec,
60433 + },
60434 +#endif
60435 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
60436 + {
60437 + .procname = "audit_textrel",
60438 + .data = &grsec_enable_audit_textrel,
60439 + .maxlen = sizeof(int),
60440 + .mode = 0600,
60441 + .proc_handler = &proc_dointvec,
60442 + },
60443 +#endif
60444 +#ifdef CONFIG_GRKERNSEC_DMESG
60445 + {
60446 + .procname = "dmesg",
60447 + .data = &grsec_enable_dmesg,
60448 + .maxlen = sizeof(int),
60449 + .mode = 0600,
60450 + .proc_handler = &proc_dointvec,
60451 + },
60452 +#endif
60453 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
60454 + {
60455 + .procname = "chroot_findtask",
60456 + .data = &grsec_enable_chroot_findtask,
60457 + .maxlen = sizeof(int),
60458 + .mode = 0600,
60459 + .proc_handler = &proc_dointvec,
60460 + },
60461 +#endif
60462 +#ifdef CONFIG_GRKERNSEC_RESLOG
60463 + {
60464 + .procname = "resource_logging",
60465 + .data = &grsec_resource_logging,
60466 + .maxlen = sizeof(int),
60467 + .mode = 0600,
60468 + .proc_handler = &proc_dointvec,
60469 + },
60470 +#endif
60471 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
60472 + {
60473 + .procname = "audit_ptrace",
60474 + .data = &grsec_enable_audit_ptrace,
60475 + .maxlen = sizeof(int),
60476 + .mode = 0600,
60477 + .proc_handler = &proc_dointvec,
60478 + },
60479 +#endif
60480 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
60481 + {
60482 + .procname = "harden_ptrace",
60483 + .data = &grsec_enable_harden_ptrace,
60484 + .maxlen = sizeof(int),
60485 + .mode = 0600,
60486 + .proc_handler = &proc_dointvec,
60487 + },
60488 +#endif
60489 + {
60490 + .procname = "grsec_lock",
60491 + .data = &grsec_lock,
60492 + .maxlen = sizeof(int),
60493 + .mode = 0600,
60494 + .proc_handler = &proc_dointvec,
60495 + },
60496 +#endif
60497 +#ifdef CONFIG_GRKERNSEC_ROFS
60498 + {
60499 + .procname = "romount_protect",
60500 + .data = &grsec_enable_rofs,
60501 + .maxlen = sizeof(int),
60502 + .mode = 0600,
60503 + .proc_handler = &proc_dointvec_minmax,
60504 + .extra1 = &one,
60505 + .extra2 = &one,
60506 + },
60507 +#endif
60508 + { }
60509 +};
60510 +#endif
60511 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
60512 new file mode 100644
60513 index 0000000..0dc13c3
60514 --- /dev/null
60515 +++ b/grsecurity/grsec_time.c
60516 @@ -0,0 +1,16 @@
60517 +#include <linux/kernel.h>
60518 +#include <linux/sched.h>
60519 +#include <linux/grinternal.h>
60520 +#include <linux/module.h>
60521 +
60522 +void
60523 +gr_log_timechange(void)
60524 +{
60525 +#ifdef CONFIG_GRKERNSEC_TIME
60526 + if (grsec_enable_time)
60527 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
60528 +#endif
60529 + return;
60530 +}
60531 +
60532 +EXPORT_SYMBOL(gr_log_timechange);
60533 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
60534 new file mode 100644
60535 index 0000000..07e0dc0
60536 --- /dev/null
60537 +++ b/grsecurity/grsec_tpe.c
60538 @@ -0,0 +1,73 @@
60539 +#include <linux/kernel.h>
60540 +#include <linux/sched.h>
60541 +#include <linux/file.h>
60542 +#include <linux/fs.h>
60543 +#include <linux/grinternal.h>
60544 +
60545 +extern int gr_acl_tpe_check(void);
60546 +
60547 +int
60548 +gr_tpe_allow(const struct file *file)
60549 +{
60550 +#ifdef CONFIG_GRKERNSEC
60551 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
60552 + const struct cred *cred = current_cred();
60553 + char *msg = NULL;
60554 + char *msg2 = NULL;
60555 +
60556 + // never restrict root
60557 + if (!cred->uid)
60558 + return 1;
60559 +
60560 + if (grsec_enable_tpe) {
60561 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
60562 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
60563 + msg = "not being in trusted group";
60564 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
60565 + msg = "being in untrusted group";
60566 +#else
60567 + if (in_group_p(grsec_tpe_gid))
60568 + msg = "being in untrusted group";
60569 +#endif
60570 + }
60571 + if (!msg && gr_acl_tpe_check())
60572 + msg = "being in untrusted role";
60573 +
60574 + // not in any affected group/role
60575 + if (!msg)
60576 + goto next_check;
60577 +
60578 + if (inode->i_uid)
60579 + msg2 = "file in non-root-owned directory";
60580 + else if (inode->i_mode & S_IWOTH)
60581 + msg2 = "file in world-writable directory";
60582 + else if (inode->i_mode & S_IWGRP)
60583 + msg2 = "file in group-writable directory";
60584 +
60585 + if (msg && msg2) {
60586 + char fullmsg[70] = {0};
60587 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
60588 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
60589 + return 0;
60590 + }
60591 + msg = NULL;
60592 +next_check:
60593 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
60594 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
60595 + return 1;
60596 +
60597 + if (inode->i_uid && (inode->i_uid != cred->uid))
60598 + msg = "directory not owned by user";
60599 + else if (inode->i_mode & S_IWOTH)
60600 + msg = "file in world-writable directory";
60601 + else if (inode->i_mode & S_IWGRP)
60602 + msg = "file in group-writable directory";
60603 +
60604 + if (msg) {
60605 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
60606 + return 0;
60607 + }
60608 +#endif
60609 +#endif
60610 + return 1;
60611 +}
60612 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
60613 new file mode 100644
60614 index 0000000..9f7b1ac
60615 --- /dev/null
60616 +++ b/grsecurity/grsum.c
60617 @@ -0,0 +1,61 @@
60618 +#include <linux/err.h>
60619 +#include <linux/kernel.h>
60620 +#include <linux/sched.h>
60621 +#include <linux/mm.h>
60622 +#include <linux/scatterlist.h>
60623 +#include <linux/crypto.h>
60624 +#include <linux/gracl.h>
60625 +
60626 +
60627 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
60628 +#error "crypto and sha256 must be built into the kernel"
60629 +#endif
60630 +
60631 +int
60632 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
60633 +{
60634 + char *p;
60635 + struct crypto_hash *tfm;
60636 + struct hash_desc desc;
60637 + struct scatterlist sg;
60638 + unsigned char temp_sum[GR_SHA_LEN];
60639 + volatile int retval = 0;
60640 + volatile int dummy = 0;
60641 + unsigned int i;
60642 +
60643 + sg_init_table(&sg, 1);
60644 +
60645 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
60646 + if (IS_ERR(tfm)) {
60647 + /* should never happen, since sha256 should be built in */
60648 + return 1;
60649 + }
60650 +
60651 + desc.tfm = tfm;
60652 + desc.flags = 0;
60653 +
60654 + crypto_hash_init(&desc);
60655 +
60656 + p = salt;
60657 + sg_set_buf(&sg, p, GR_SALT_LEN);
60658 + crypto_hash_update(&desc, &sg, sg.length);
60659 +
60660 + p = entry->pw;
60661 + sg_set_buf(&sg, p, strlen(p));
60662 +
60663 + crypto_hash_update(&desc, &sg, sg.length);
60664 +
60665 + crypto_hash_final(&desc, temp_sum);
60666 +
60667 + memset(entry->pw, 0, GR_PW_LEN);
60668 +
60669 + for (i = 0; i < GR_SHA_LEN; i++)
60670 + if (sum[i] != temp_sum[i])
60671 + retval = 1;
60672 + else
60673 + dummy = 1; // waste a cycle
60674 +
60675 + crypto_free_hash(tfm);
60676 +
60677 + return retval;
60678 +}
60679 diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
60680 index bde976e..a1cc32a 100644
60681 --- a/include/acpi/acpi_bus.h
60682 +++ b/include/acpi/acpi_bus.h
60683 @@ -136,7 +136,7 @@ struct acpi_device_ops {
60684 acpi_op_bind bind;
60685 acpi_op_unbind unbind;
60686 acpi_op_notify notify;
60687 -};
60688 +} __no_const;
60689
60690 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
60691
60692 diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
60693 index 77ff547..181834f 100644
60694 --- a/include/asm-generic/4level-fixup.h
60695 +++ b/include/asm-generic/4level-fixup.h
60696 @@ -13,8 +13,10 @@
60697 #define pmd_alloc(mm, pud, address) \
60698 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
60699 NULL: pmd_offset(pud, address))
60700 +#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
60701
60702 #define pud_alloc(mm, pgd, address) (pgd)
60703 +#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
60704 #define pud_offset(pgd, start) (pgd)
60705 #define pud_none(pud) 0
60706 #define pud_bad(pud) 0
60707 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
60708 index b7babf0..3ba8aee 100644
60709 --- a/include/asm-generic/atomic-long.h
60710 +++ b/include/asm-generic/atomic-long.h
60711 @@ -22,6 +22,12 @@
60712
60713 typedef atomic64_t atomic_long_t;
60714
60715 +#ifdef CONFIG_PAX_REFCOUNT
60716 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
60717 +#else
60718 +typedef atomic64_t atomic_long_unchecked_t;
60719 +#endif
60720 +
60721 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
60722
60723 static inline long atomic_long_read(atomic_long_t *l)
60724 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
60725 return (long)atomic64_read(v);
60726 }
60727
60728 +#ifdef CONFIG_PAX_REFCOUNT
60729 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
60730 +{
60731 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60732 +
60733 + return (long)atomic64_read_unchecked(v);
60734 +}
60735 +#endif
60736 +
60737 static inline void atomic_long_set(atomic_long_t *l, long i)
60738 {
60739 atomic64_t *v = (atomic64_t *)l;
60740 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
60741 atomic64_set(v, i);
60742 }
60743
60744 +#ifdef CONFIG_PAX_REFCOUNT
60745 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
60746 +{
60747 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60748 +
60749 + atomic64_set_unchecked(v, i);
60750 +}
60751 +#endif
60752 +
60753 static inline void atomic_long_inc(atomic_long_t *l)
60754 {
60755 atomic64_t *v = (atomic64_t *)l;
60756 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
60757 atomic64_inc(v);
60758 }
60759
60760 +#ifdef CONFIG_PAX_REFCOUNT
60761 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
60762 +{
60763 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60764 +
60765 + atomic64_inc_unchecked(v);
60766 +}
60767 +#endif
60768 +
60769 static inline void atomic_long_dec(atomic_long_t *l)
60770 {
60771 atomic64_t *v = (atomic64_t *)l;
60772 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
60773 atomic64_dec(v);
60774 }
60775
60776 +#ifdef CONFIG_PAX_REFCOUNT
60777 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
60778 +{
60779 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60780 +
60781 + atomic64_dec_unchecked(v);
60782 +}
60783 +#endif
60784 +
60785 static inline void atomic_long_add(long i, atomic_long_t *l)
60786 {
60787 atomic64_t *v = (atomic64_t *)l;
60788 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
60789 atomic64_add(i, v);
60790 }
60791
60792 +#ifdef CONFIG_PAX_REFCOUNT
60793 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
60794 +{
60795 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60796 +
60797 + atomic64_add_unchecked(i, v);
60798 +}
60799 +#endif
60800 +
60801 static inline void atomic_long_sub(long i, atomic_long_t *l)
60802 {
60803 atomic64_t *v = (atomic64_t *)l;
60804 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
60805 atomic64_sub(i, v);
60806 }
60807
60808 +#ifdef CONFIG_PAX_REFCOUNT
60809 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
60810 +{
60811 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60812 +
60813 + atomic64_sub_unchecked(i, v);
60814 +}
60815 +#endif
60816 +
60817 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
60818 {
60819 atomic64_t *v = (atomic64_t *)l;
60820 @@ -115,6 +175,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
60821 return (long)atomic64_inc_return(v);
60822 }
60823
60824 +#ifdef CONFIG_PAX_REFCOUNT
60825 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
60826 +{
60827 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60828 +
60829 + return (long)atomic64_inc_return_unchecked(v);
60830 +}
60831 +#endif
60832 +
60833 static inline long atomic_long_dec_return(atomic_long_t *l)
60834 {
60835 atomic64_t *v = (atomic64_t *)l;
60836 @@ -140,6 +209,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
60837
60838 typedef atomic_t atomic_long_t;
60839
60840 +#ifdef CONFIG_PAX_REFCOUNT
60841 +typedef atomic_unchecked_t atomic_long_unchecked_t;
60842 +#else
60843 +typedef atomic_t atomic_long_unchecked_t;
60844 +#endif
60845 +
60846 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
60847 static inline long atomic_long_read(atomic_long_t *l)
60848 {
60849 @@ -148,6 +223,15 @@ static inline long atomic_long_read(atomic_long_t *l)
60850 return (long)atomic_read(v);
60851 }
60852
60853 +#ifdef CONFIG_PAX_REFCOUNT
60854 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
60855 +{
60856 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60857 +
60858 + return (long)atomic_read_unchecked(v);
60859 +}
60860 +#endif
60861 +
60862 static inline void atomic_long_set(atomic_long_t *l, long i)
60863 {
60864 atomic_t *v = (atomic_t *)l;
60865 @@ -155,6 +239,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
60866 atomic_set(v, i);
60867 }
60868
60869 +#ifdef CONFIG_PAX_REFCOUNT
60870 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
60871 +{
60872 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60873 +
60874 + atomic_set_unchecked(v, i);
60875 +}
60876 +#endif
60877 +
60878 static inline void atomic_long_inc(atomic_long_t *l)
60879 {
60880 atomic_t *v = (atomic_t *)l;
60881 @@ -162,6 +255,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
60882 atomic_inc(v);
60883 }
60884
60885 +#ifdef CONFIG_PAX_REFCOUNT
60886 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
60887 +{
60888 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60889 +
60890 + atomic_inc_unchecked(v);
60891 +}
60892 +#endif
60893 +
60894 static inline void atomic_long_dec(atomic_long_t *l)
60895 {
60896 atomic_t *v = (atomic_t *)l;
60897 @@ -169,6 +271,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
60898 atomic_dec(v);
60899 }
60900
60901 +#ifdef CONFIG_PAX_REFCOUNT
60902 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
60903 +{
60904 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60905 +
60906 + atomic_dec_unchecked(v);
60907 +}
60908 +#endif
60909 +
60910 static inline void atomic_long_add(long i, atomic_long_t *l)
60911 {
60912 atomic_t *v = (atomic_t *)l;
60913 @@ -176,6 +287,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
60914 atomic_add(i, v);
60915 }
60916
60917 +#ifdef CONFIG_PAX_REFCOUNT
60918 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
60919 +{
60920 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60921 +
60922 + atomic_add_unchecked(i, v);
60923 +}
60924 +#endif
60925 +
60926 static inline void atomic_long_sub(long i, atomic_long_t *l)
60927 {
60928 atomic_t *v = (atomic_t *)l;
60929 @@ -183,6 +303,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
60930 atomic_sub(i, v);
60931 }
60932
60933 +#ifdef CONFIG_PAX_REFCOUNT
60934 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
60935 +{
60936 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60937 +
60938 + atomic_sub_unchecked(i, v);
60939 +}
60940 +#endif
60941 +
60942 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
60943 {
60944 atomic_t *v = (atomic_t *)l;
60945 @@ -232,6 +361,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
60946 return (long)atomic_inc_return(v);
60947 }
60948
60949 +#ifdef CONFIG_PAX_REFCOUNT
60950 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
60951 +{
60952 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60953 +
60954 + return (long)atomic_inc_return_unchecked(v);
60955 +}
60956 +#endif
60957 +
60958 static inline long atomic_long_dec_return(atomic_long_t *l)
60959 {
60960 atomic_t *v = (atomic_t *)l;
60961 @@ -255,4 +393,55 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
60962
60963 #endif /* BITS_PER_LONG == 64 */
60964
60965 +#ifdef CONFIG_PAX_REFCOUNT
60966 +static inline void pax_refcount_needs_these_functions(void)
60967 +{
60968 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
60969 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
60970 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
60971 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
60972 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
60973 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
60974 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
60975 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
60976 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
60977 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
60978 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
60979 +#ifdef CONFIG_X86
60980 + atomic_clear_mask_unchecked(0, NULL);
60981 + atomic_set_mask_unchecked(0, NULL);
60982 +#endif
60983 +
60984 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
60985 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
60986 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
60987 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
60988 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
60989 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
60990 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
60991 +}
60992 +#else
60993 +#define atomic_read_unchecked(v) atomic_read(v)
60994 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
60995 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
60996 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
60997 +#define atomic_inc_unchecked(v) atomic_inc(v)
60998 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
60999 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
61000 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
61001 +#define atomic_dec_unchecked(v) atomic_dec(v)
61002 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
61003 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
61004 +#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
61005 +#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
61006 +
61007 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
61008 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
61009 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
61010 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
61011 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
61012 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
61013 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
61014 +#endif
61015 +
61016 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
61017 diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
61018 index 1ced641..c896ee8 100644
61019 --- a/include/asm-generic/atomic.h
61020 +++ b/include/asm-generic/atomic.h
61021 @@ -159,7 +159,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
61022 * Atomically clears the bits set in @mask from @v
61023 */
61024 #ifndef atomic_clear_mask
61025 -static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
61026 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
61027 {
61028 unsigned long flags;
61029
61030 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
61031 index b18ce4f..2ee2843 100644
61032 --- a/include/asm-generic/atomic64.h
61033 +++ b/include/asm-generic/atomic64.h
61034 @@ -16,6 +16,8 @@ typedef struct {
61035 long long counter;
61036 } atomic64_t;
61037
61038 +typedef atomic64_t atomic64_unchecked_t;
61039 +
61040 #define ATOMIC64_INIT(i) { (i) }
61041
61042 extern long long atomic64_read(const atomic64_t *v);
61043 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
61044 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
61045 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
61046
61047 +#define atomic64_read_unchecked(v) atomic64_read(v)
61048 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
61049 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
61050 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
61051 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
61052 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
61053 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
61054 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
61055 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
61056 +
61057 #endif /* _ASM_GENERIC_ATOMIC64_H */
61058 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
61059 index 1bfcfe5..e04c5c9 100644
61060 --- a/include/asm-generic/cache.h
61061 +++ b/include/asm-generic/cache.h
61062 @@ -6,7 +6,7 @@
61063 * cache lines need to provide their own cache.h.
61064 */
61065
61066 -#define L1_CACHE_SHIFT 5
61067 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
61068 +#define L1_CACHE_SHIFT 5UL
61069 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
61070
61071 #endif /* __ASM_GENERIC_CACHE_H */
61072 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
61073 index 0d68a1e..b74a761 100644
61074 --- a/include/asm-generic/emergency-restart.h
61075 +++ b/include/asm-generic/emergency-restart.h
61076 @@ -1,7 +1,7 @@
61077 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
61078 #define _ASM_GENERIC_EMERGENCY_RESTART_H
61079
61080 -static inline void machine_emergency_restart(void)
61081 +static inline __noreturn void machine_emergency_restart(void)
61082 {
61083 machine_restart(NULL);
61084 }
61085 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
61086 index 90f99c7..00ce236 100644
61087 --- a/include/asm-generic/kmap_types.h
61088 +++ b/include/asm-generic/kmap_types.h
61089 @@ -2,9 +2,9 @@
61090 #define _ASM_GENERIC_KMAP_TYPES_H
61091
61092 #ifdef __WITH_KM_FENCE
61093 -# define KM_TYPE_NR 41
61094 +# define KM_TYPE_NR 42
61095 #else
61096 -# define KM_TYPE_NR 20
61097 +# define KM_TYPE_NR 21
61098 #endif
61099
61100 #endif
61101 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
61102 index 9ceb03b..2efbcbd 100644
61103 --- a/include/asm-generic/local.h
61104 +++ b/include/asm-generic/local.h
61105 @@ -39,6 +39,7 @@ typedef struct
61106 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
61107 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
61108 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
61109 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
61110
61111 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
61112 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
61113 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
61114 index 725612b..9cc513a 100644
61115 --- a/include/asm-generic/pgtable-nopmd.h
61116 +++ b/include/asm-generic/pgtable-nopmd.h
61117 @@ -1,14 +1,19 @@
61118 #ifndef _PGTABLE_NOPMD_H
61119 #define _PGTABLE_NOPMD_H
61120
61121 -#ifndef __ASSEMBLY__
61122 -
61123 #include <asm-generic/pgtable-nopud.h>
61124
61125 -struct mm_struct;
61126 -
61127 #define __PAGETABLE_PMD_FOLDED
61128
61129 +#define PMD_SHIFT PUD_SHIFT
61130 +#define PTRS_PER_PMD 1
61131 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
61132 +#define PMD_MASK (~(PMD_SIZE-1))
61133 +
61134 +#ifndef __ASSEMBLY__
61135 +
61136 +struct mm_struct;
61137 +
61138 /*
61139 * Having the pmd type consist of a pud gets the size right, and allows
61140 * us to conceptually access the pud entry that this pmd is folded into
61141 @@ -16,11 +21,6 @@ struct mm_struct;
61142 */
61143 typedef struct { pud_t pud; } pmd_t;
61144
61145 -#define PMD_SHIFT PUD_SHIFT
61146 -#define PTRS_PER_PMD 1
61147 -#define PMD_SIZE (1UL << PMD_SHIFT)
61148 -#define PMD_MASK (~(PMD_SIZE-1))
61149 -
61150 /*
61151 * The "pud_xxx()" functions here are trivial for a folded two-level
61152 * setup: the pmd is never bad, and a pmd always exists (as it's folded
61153 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
61154 index 810431d..0ec4804f 100644
61155 --- a/include/asm-generic/pgtable-nopud.h
61156 +++ b/include/asm-generic/pgtable-nopud.h
61157 @@ -1,10 +1,15 @@
61158 #ifndef _PGTABLE_NOPUD_H
61159 #define _PGTABLE_NOPUD_H
61160
61161 -#ifndef __ASSEMBLY__
61162 -
61163 #define __PAGETABLE_PUD_FOLDED
61164
61165 +#define PUD_SHIFT PGDIR_SHIFT
61166 +#define PTRS_PER_PUD 1
61167 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
61168 +#define PUD_MASK (~(PUD_SIZE-1))
61169 +
61170 +#ifndef __ASSEMBLY__
61171 +
61172 /*
61173 * Having the pud type consist of a pgd gets the size right, and allows
61174 * us to conceptually access the pgd entry that this pud is folded into
61175 @@ -12,11 +17,6 @@
61176 */
61177 typedef struct { pgd_t pgd; } pud_t;
61178
61179 -#define PUD_SHIFT PGDIR_SHIFT
61180 -#define PTRS_PER_PUD 1
61181 -#define PUD_SIZE (1UL << PUD_SHIFT)
61182 -#define PUD_MASK (~(PUD_SIZE-1))
61183 -
61184 /*
61185 * The "pgd_xxx()" functions here are trivial for a folded two-level
61186 * setup: the pud is never bad, and a pud always exists (as it's folded
61187 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
61188 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
61189
61190 #define pgd_populate(mm, pgd, pud) do { } while (0)
61191 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
61192 /*
61193 * (puds are folded into pgds so this doesn't get actually called,
61194 * but the define is needed for a generic inline function.)
61195 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
61196 index ff4947b..f48183f 100644
61197 --- a/include/asm-generic/pgtable.h
61198 +++ b/include/asm-generic/pgtable.h
61199 @@ -530,6 +530,14 @@ static inline int pmd_trans_unstable(pmd_t *pmd)
61200 #endif
61201 }
61202
61203 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
61204 +static inline unsigned long pax_open_kernel(void) { return 0; }
61205 +#endif
61206 +
61207 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
61208 +static inline unsigned long pax_close_kernel(void) { return 0; }
61209 +#endif
61210 +
61211 #endif /* CONFIG_MMU */
61212
61213 #endif /* !__ASSEMBLY__ */
61214 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
61215 index 4e2e1cc..12c266b 100644
61216 --- a/include/asm-generic/vmlinux.lds.h
61217 +++ b/include/asm-generic/vmlinux.lds.h
61218 @@ -218,6 +218,7 @@
61219 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
61220 VMLINUX_SYMBOL(__start_rodata) = .; \
61221 *(.rodata) *(.rodata.*) \
61222 + *(.data..read_only) \
61223 *(__vermagic) /* Kernel version magic */ \
61224 . = ALIGN(8); \
61225 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
61226 @@ -716,17 +717,18 @@
61227 * section in the linker script will go there too. @phdr should have
61228 * a leading colon.
61229 *
61230 - * Note that this macros defines __per_cpu_load as an absolute symbol.
61231 + * Note that this macros defines per_cpu_load as an absolute symbol.
61232 * If there is no need to put the percpu section at a predetermined
61233 * address, use PERCPU_SECTION.
61234 */
61235 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
61236 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
61237 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
61238 + per_cpu_load = .; \
61239 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
61240 - LOAD_OFFSET) { \
61241 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
61242 PERCPU_INPUT(cacheline) \
61243 } phdr \
61244 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
61245 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
61246
61247 /**
61248 * PERCPU_SECTION - define output section for percpu area, simple version
61249 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
61250 index d6b67bb..a272c29 100644
61251 --- a/include/drm/drmP.h
61252 +++ b/include/drm/drmP.h
61253 @@ -72,6 +72,7 @@
61254 #include <linux/workqueue.h>
61255 #include <linux/poll.h>
61256 #include <asm/pgalloc.h>
61257 +#include <asm/local.h>
61258 #include "drm.h"
61259
61260 #include <linux/idr.h>
61261 @@ -1067,7 +1068,7 @@ struct drm_device {
61262
61263 /** \name Usage Counters */
61264 /*@{ */
61265 - int open_count; /**< Outstanding files open */
61266 + local_t open_count; /**< Outstanding files open */
61267 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
61268 atomic_t vma_count; /**< Outstanding vma areas open */
61269 int buf_use; /**< Buffers in use -- cannot alloc */
61270 @@ -1078,7 +1079,7 @@ struct drm_device {
61271 /*@{ */
61272 unsigned long counters;
61273 enum drm_stat_type types[15];
61274 - atomic_t counts[15];
61275 + atomic_unchecked_t counts[15];
61276 /*@} */
61277
61278 struct list_head filelist;
61279 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
61280 index e01cc80..319855d 100644
61281 --- a/include/drm/drm_crtc_helper.h
61282 +++ b/include/drm/drm_crtc_helper.h
61283 @@ -81,7 +81,7 @@ struct drm_crtc_helper_funcs {
61284
61285 /* disable crtc when not in use - more explicit than dpms off */
61286 void (*disable)(struct drm_crtc *crtc);
61287 -};
61288 +} __no_const;
61289
61290 /**
61291 * drm_encoder_helper_funcs - helper operations for encoders
61292 @@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
61293 struct drm_connector *connector);
61294 /* disable encoder when not in use - more explicit than dpms off */
61295 void (*disable)(struct drm_encoder *encoder);
61296 -};
61297 +} __no_const;
61298
61299 /**
61300 * drm_connector_helper_funcs - helper operations for connectors
61301 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
61302 index d6d1da4..fdd1ac5 100644
61303 --- a/include/drm/ttm/ttm_memory.h
61304 +++ b/include/drm/ttm/ttm_memory.h
61305 @@ -48,7 +48,7 @@
61306
61307 struct ttm_mem_shrink {
61308 int (*do_shrink) (struct ttm_mem_shrink *);
61309 -};
61310 +} __no_const;
61311
61312 /**
61313 * struct ttm_mem_global - Global memory accounting structure.
61314 diff --git a/include/linux/a.out.h b/include/linux/a.out.h
61315 index e86dfca..40cc55f 100644
61316 --- a/include/linux/a.out.h
61317 +++ b/include/linux/a.out.h
61318 @@ -39,6 +39,14 @@ enum machine_type {
61319 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
61320 };
61321
61322 +/* Constants for the N_FLAGS field */
61323 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
61324 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
61325 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
61326 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
61327 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
61328 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
61329 +
61330 #if !defined (N_MAGIC)
61331 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
61332 #endif
61333 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
61334 index 06fd4bb..1caec0d 100644
61335 --- a/include/linux/atmdev.h
61336 +++ b/include/linux/atmdev.h
61337 @@ -237,7 +237,7 @@ struct compat_atm_iobuf {
61338 #endif
61339
61340 struct k_atm_aal_stats {
61341 -#define __HANDLE_ITEM(i) atomic_t i
61342 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
61343 __AAL_STAT_ITEMS
61344 #undef __HANDLE_ITEM
61345 };
61346 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
61347 index 366422b..1fa7f84 100644
61348 --- a/include/linux/binfmts.h
61349 +++ b/include/linux/binfmts.h
61350 @@ -89,6 +89,7 @@ struct linux_binfmt {
61351 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
61352 int (*load_shlib)(struct file *);
61353 int (*core_dump)(struct coredump_params *cprm);
61354 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
61355 unsigned long min_coredump; /* minimal dump size */
61356 };
61357
61358 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
61359 index 4a2ab7c..a2de7a8 100644
61360 --- a/include/linux/blkdev.h
61361 +++ b/include/linux/blkdev.h
61362 @@ -1420,7 +1420,7 @@ struct block_device_operations {
61363 /* this callback is with swap_lock and sometimes page table lock held */
61364 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
61365 struct module *owner;
61366 -};
61367 +} __do_const;
61368
61369 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
61370 unsigned long);
61371 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
61372 index 4d1a074..88f929a 100644
61373 --- a/include/linux/blktrace_api.h
61374 +++ b/include/linux/blktrace_api.h
61375 @@ -162,7 +162,7 @@ struct blk_trace {
61376 struct dentry *dir;
61377 struct dentry *dropped_file;
61378 struct dentry *msg_file;
61379 - atomic_t dropped;
61380 + atomic_unchecked_t dropped;
61381 };
61382
61383 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
61384 diff --git a/include/linux/byteorder/little_endian.h b/include/linux/byteorder/little_endian.h
61385 index 83195fb..0b0f77d 100644
61386 --- a/include/linux/byteorder/little_endian.h
61387 +++ b/include/linux/byteorder/little_endian.h
61388 @@ -42,51 +42,51 @@
61389
61390 static inline __le64 __cpu_to_le64p(const __u64 *p)
61391 {
61392 - return (__force __le64)*p;
61393 + return (__force const __le64)*p;
61394 }
61395 static inline __u64 __le64_to_cpup(const __le64 *p)
61396 {
61397 - return (__force __u64)*p;
61398 + return (__force const __u64)*p;
61399 }
61400 static inline __le32 __cpu_to_le32p(const __u32 *p)
61401 {
61402 - return (__force __le32)*p;
61403 + return (__force const __le32)*p;
61404 }
61405 static inline __u32 __le32_to_cpup(const __le32 *p)
61406 {
61407 - return (__force __u32)*p;
61408 + return (__force const __u32)*p;
61409 }
61410 static inline __le16 __cpu_to_le16p(const __u16 *p)
61411 {
61412 - return (__force __le16)*p;
61413 + return (__force const __le16)*p;
61414 }
61415 static inline __u16 __le16_to_cpup(const __le16 *p)
61416 {
61417 - return (__force __u16)*p;
61418 + return (__force const __u16)*p;
61419 }
61420 static inline __be64 __cpu_to_be64p(const __u64 *p)
61421 {
61422 - return (__force __be64)__swab64p(p);
61423 + return (__force const __be64)__swab64p(p);
61424 }
61425 static inline __u64 __be64_to_cpup(const __be64 *p)
61426 {
61427 - return __swab64p((__u64 *)p);
61428 + return __swab64p((const __u64 *)p);
61429 }
61430 static inline __be32 __cpu_to_be32p(const __u32 *p)
61431 {
61432 - return (__force __be32)__swab32p(p);
61433 + return (__force const __be32)__swab32p(p);
61434 }
61435 static inline __u32 __be32_to_cpup(const __be32 *p)
61436 {
61437 - return __swab32p((__u32 *)p);
61438 + return __swab32p((const __u32 *)p);
61439 }
61440 static inline __be16 __cpu_to_be16p(const __u16 *p)
61441 {
61442 - return (__force __be16)__swab16p(p);
61443 + return (__force const __be16)__swab16p(p);
61444 }
61445 static inline __u16 __be16_to_cpup(const __be16 *p)
61446 {
61447 - return __swab16p((__u16 *)p);
61448 + return __swab16p((const __u16 *)p);
61449 }
61450 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
61451 #define __le64_to_cpus(x) do { (void)(x); } while (0)
61452 diff --git a/include/linux/cache.h b/include/linux/cache.h
61453 index 4c57065..4307975 100644
61454 --- a/include/linux/cache.h
61455 +++ b/include/linux/cache.h
61456 @@ -16,6 +16,10 @@
61457 #define __read_mostly
61458 #endif
61459
61460 +#ifndef __read_only
61461 +#define __read_only __read_mostly
61462 +#endif
61463 +
61464 #ifndef ____cacheline_aligned
61465 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
61466 #endif
61467 diff --git a/include/linux/capability.h b/include/linux/capability.h
61468 index d10b7ed..0288b79 100644
61469 --- a/include/linux/capability.h
61470 +++ b/include/linux/capability.h
61471 @@ -553,10 +553,15 @@ extern bool capable(int cap);
61472 extern bool ns_capable(struct user_namespace *ns, int cap);
61473 extern bool nsown_capable(int cap);
61474 extern bool inode_capable(const struct inode *inode, int cap);
61475 +extern bool capable_nolog(int cap);
61476 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
61477 +extern bool inode_capable_nolog(const struct inode *inode, int cap);
61478
61479 /* audit system wants to get cap info from files as well */
61480 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
61481
61482 +extern int is_privileged_binary(const struct dentry *dentry);
61483 +
61484 #endif /* __KERNEL__ */
61485
61486 #endif /* !_LINUX_CAPABILITY_H */
61487 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
61488 index 42e55de..1cd0e66 100644
61489 --- a/include/linux/cleancache.h
61490 +++ b/include/linux/cleancache.h
61491 @@ -31,7 +31,7 @@ struct cleancache_ops {
61492 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
61493 void (*invalidate_inode)(int, struct cleancache_filekey);
61494 void (*invalidate_fs)(int);
61495 -};
61496 +} __no_const;
61497
61498 extern struct cleancache_ops
61499 cleancache_register_ops(struct cleancache_ops *ops);
61500 diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
61501 index 77335fa..6cbe7dd 100644
61502 --- a/include/linux/clk-provider.h
61503 +++ b/include/linux/clk-provider.h
61504 @@ -111,6 +111,7 @@ struct clk_ops {
61505 unsigned long);
61506 void (*init)(struct clk_hw *hw);
61507 };
61508 +typedef struct clk_ops __no_const clk_ops_no_const;
61509
61510 /**
61511 * struct clk_init_data - holds init data that's common to all clocks and is
61512 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
61513 index 934bc34..1b47129 100644
61514 --- a/include/linux/compiler-gcc4.h
61515 +++ b/include/linux/compiler-gcc4.h
61516 @@ -32,6 +32,21 @@
61517 #define __linktime_error(message) __attribute__((__error__(message)))
61518
61519 #if __GNUC_MINOR__ >= 5
61520 +
61521 +#ifdef CONSTIFY_PLUGIN
61522 +#define __no_const __attribute__((no_const))
61523 +#define __do_const __attribute__((do_const))
61524 +#endif
61525 +
61526 +#ifdef SIZE_OVERFLOW_PLUGIN
61527 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
61528 +#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
61529 +#endif
61530 +
61531 +#ifdef LATENT_ENTROPY_PLUGIN
61532 +#define __latent_entropy __attribute__((latent_entropy))
61533 +#endif
61534 +
61535 /*
61536 * Mark a position in code as unreachable. This can be used to
61537 * suppress control flow warnings after asm blocks that transfer
61538 @@ -47,6 +62,11 @@
61539 #define __noclone __attribute__((__noclone__))
61540
61541 #endif
61542 +
61543 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
61544 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
61545 +#define __bos0(ptr) __bos((ptr), 0)
61546 +#define __bos1(ptr) __bos((ptr), 1)
61547 #endif
61548
61549 #if __GNUC_MINOR__ >= 6
61550 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
61551 index f430e41..38be90f 100644
61552 --- a/include/linux/compiler.h
61553 +++ b/include/linux/compiler.h
61554 @@ -5,31 +5,62 @@
61555
61556 #ifdef __CHECKER__
61557 # define __user __attribute__((noderef, address_space(1)))
61558 +# define __force_user __force __user
61559 # define __kernel __attribute__((address_space(0)))
61560 +# define __force_kernel __force __kernel
61561 # define __safe __attribute__((safe))
61562 # define __force __attribute__((force))
61563 # define __nocast __attribute__((nocast))
61564 # define __iomem __attribute__((noderef, address_space(2)))
61565 +# define __force_iomem __force __iomem
61566 # define __acquires(x) __attribute__((context(x,0,1)))
61567 # define __releases(x) __attribute__((context(x,1,0)))
61568 # define __acquire(x) __context__(x,1)
61569 # define __release(x) __context__(x,-1)
61570 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
61571 # define __percpu __attribute__((noderef, address_space(3)))
61572 +# define __force_percpu __force __percpu
61573 #ifdef CONFIG_SPARSE_RCU_POINTER
61574 # define __rcu __attribute__((noderef, address_space(4)))
61575 +# define __force_rcu __force __rcu
61576 #else
61577 # define __rcu
61578 +# define __force_rcu
61579 #endif
61580 extern void __chk_user_ptr(const volatile void __user *);
61581 extern void __chk_io_ptr(const volatile void __iomem *);
61582 +#elif defined(CHECKER_PLUGIN)
61583 +//# define __user
61584 +//# define __force_user
61585 +//# define __kernel
61586 +//# define __force_kernel
61587 +# define __safe
61588 +# define __force
61589 +# define __nocast
61590 +# define __iomem
61591 +# define __force_iomem
61592 +# define __chk_user_ptr(x) (void)0
61593 +# define __chk_io_ptr(x) (void)0
61594 +# define __builtin_warning(x, y...) (1)
61595 +# define __acquires(x)
61596 +# define __releases(x)
61597 +# define __acquire(x) (void)0
61598 +# define __release(x) (void)0
61599 +# define __cond_lock(x,c) (c)
61600 +# define __percpu
61601 +# define __force_percpu
61602 +# define __rcu
61603 +# define __force_rcu
61604 #else
61605 # define __user
61606 +# define __force_user
61607 # define __kernel
61608 +# define __force_kernel
61609 # define __safe
61610 # define __force
61611 # define __nocast
61612 # define __iomem
61613 +# define __force_iomem
61614 # define __chk_user_ptr(x) (void)0
61615 # define __chk_io_ptr(x) (void)0
61616 # define __builtin_warning(x, y...) (1)
61617 @@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
61618 # define __release(x) (void)0
61619 # define __cond_lock(x,c) (c)
61620 # define __percpu
61621 +# define __force_percpu
61622 # define __rcu
61623 +# define __force_rcu
61624 #endif
61625
61626 #ifdef __KERNEL__
61627 @@ -264,6 +297,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61628 # define __attribute_const__ /* unimplemented */
61629 #endif
61630
61631 +#ifndef __no_const
61632 +# define __no_const
61633 +#endif
61634 +
61635 +#ifndef __do_const
61636 +# define __do_const
61637 +#endif
61638 +
61639 +#ifndef __size_overflow
61640 +# define __size_overflow(...)
61641 +#endif
61642 +
61643 +#ifndef __intentional_overflow
61644 +# define __intentional_overflow(...)
61645 +#endif
61646 +
61647 +#ifndef __latent_entropy
61648 +# define __latent_entropy
61649 +#endif
61650 +
61651 /*
61652 * Tell gcc if a function is cold. The compiler will assume any path
61653 * directly leading to the call is unlikely.
61654 @@ -273,6 +326,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61655 #define __cold
61656 #endif
61657
61658 +#ifndef __alloc_size
61659 +#define __alloc_size(...)
61660 +#endif
61661 +
61662 +#ifndef __bos
61663 +#define __bos(ptr, arg)
61664 +#endif
61665 +
61666 +#ifndef __bos0
61667 +#define __bos0(ptr)
61668 +#endif
61669 +
61670 +#ifndef __bos1
61671 +#define __bos1(ptr)
61672 +#endif
61673 +
61674 /* Simple shorthand for a section definition */
61675 #ifndef __section
61676 # define __section(S) __attribute__ ((__section__(#S)))
61677 @@ -312,6 +381,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61678 * use is to mediate communication between process-level code and irq/NMI
61679 * handlers, all running on the same CPU.
61680 */
61681 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
61682 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
61683 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
61684
61685 #endif /* __LINUX_COMPILER_H */
61686 diff --git a/include/linux/cred.h b/include/linux/cred.h
61687 index ebbed2c..908cc2c 100644
61688 --- a/include/linux/cred.h
61689 +++ b/include/linux/cred.h
61690 @@ -208,6 +208,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
61691 static inline void validate_process_creds(void)
61692 {
61693 }
61694 +static inline void validate_task_creds(struct task_struct *task)
61695 +{
61696 +}
61697 #endif
61698
61699 /**
61700 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
61701 index b92eadf..b4ecdc1 100644
61702 --- a/include/linux/crypto.h
61703 +++ b/include/linux/crypto.h
61704 @@ -373,7 +373,7 @@ struct cipher_tfm {
61705 const u8 *key, unsigned int keylen);
61706 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
61707 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
61708 -};
61709 +} __no_const;
61710
61711 struct hash_tfm {
61712 int (*init)(struct hash_desc *desc);
61713 @@ -394,13 +394,13 @@ struct compress_tfm {
61714 int (*cot_decompress)(struct crypto_tfm *tfm,
61715 const u8 *src, unsigned int slen,
61716 u8 *dst, unsigned int *dlen);
61717 -};
61718 +} __no_const;
61719
61720 struct rng_tfm {
61721 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
61722 unsigned int dlen);
61723 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
61724 -};
61725 +} __no_const;
61726
61727 #define crt_ablkcipher crt_u.ablkcipher
61728 #define crt_aead crt_u.aead
61729 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
61730 index 7925bf0..d5143d2 100644
61731 --- a/include/linux/decompress/mm.h
61732 +++ b/include/linux/decompress/mm.h
61733 @@ -77,7 +77,7 @@ static void free(void *where)
61734 * warnings when not needed (indeed large_malloc / large_free are not
61735 * needed by inflate */
61736
61737 -#define malloc(a) kmalloc(a, GFP_KERNEL)
61738 +#define malloc(a) kmalloc((a), GFP_KERNEL)
61739 #define free(a) kfree(a)
61740
61741 #define large_malloc(a) vmalloc(a)
61742 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
61743 index 94af418..b1ca7a2 100644
61744 --- a/include/linux/dma-mapping.h
61745 +++ b/include/linux/dma-mapping.h
61746 @@ -54,7 +54,7 @@ struct dma_map_ops {
61747 u64 (*get_required_mask)(struct device *dev);
61748 #endif
61749 int is_phys;
61750 -};
61751 +} __do_const;
61752
61753 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
61754
61755 diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
61756 index 9c02a45..89fdd73 100644
61757 --- a/include/linux/dmaengine.h
61758 +++ b/include/linux/dmaengine.h
61759 @@ -1017,9 +1017,9 @@ struct dma_pinned_list {
61760 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
61761 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
61762
61763 -dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
61764 +dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
61765 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
61766 -dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
61767 +dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
61768 struct dma_pinned_list *pinned_list, struct page *page,
61769 unsigned int offset, size_t len);
61770
61771 diff --git a/include/linux/efi.h b/include/linux/efi.h
61772 index 5782114..e9b1ba1 100644
61773 --- a/include/linux/efi.h
61774 +++ b/include/linux/efi.h
61775 @@ -640,7 +640,7 @@ struct efivar_operations {
61776 efi_get_variable_t *get_variable;
61777 efi_get_next_variable_t *get_next_variable;
61778 efi_set_variable_t *set_variable;
61779 -};
61780 +} __no_const;
61781
61782 struct efivars {
61783 /*
61784 diff --git a/include/linux/elf.h b/include/linux/elf.h
61785 index 999b4f5..57753b4 100644
61786 --- a/include/linux/elf.h
61787 +++ b/include/linux/elf.h
61788 @@ -40,6 +40,17 @@ typedef __s64 Elf64_Sxword;
61789 #define PT_GNU_EH_FRAME 0x6474e550
61790
61791 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
61792 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
61793 +
61794 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
61795 +
61796 +/* Constants for the e_flags field */
61797 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
61798 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
61799 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
61800 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
61801 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
61802 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
61803
61804 /*
61805 * Extended Numbering
61806 @@ -97,6 +108,8 @@ typedef __s64 Elf64_Sxword;
61807 #define DT_DEBUG 21
61808 #define DT_TEXTREL 22
61809 #define DT_JMPREL 23
61810 +#define DT_FLAGS 30
61811 + #define DF_TEXTREL 0x00000004
61812 #define DT_ENCODING 32
61813 #define OLD_DT_LOOS 0x60000000
61814 #define DT_LOOS 0x6000000d
61815 @@ -243,6 +256,19 @@ typedef struct elf64_hdr {
61816 #define PF_W 0x2
61817 #define PF_X 0x1
61818
61819 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
61820 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
61821 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
61822 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
61823 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
61824 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
61825 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
61826 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
61827 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
61828 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
61829 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
61830 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
61831 +
61832 typedef struct elf32_phdr{
61833 Elf32_Word p_type;
61834 Elf32_Off p_offset;
61835 @@ -335,6 +361,8 @@ typedef struct elf64_shdr {
61836 #define EI_OSABI 7
61837 #define EI_PAD 8
61838
61839 +#define EI_PAX 14
61840 +
61841 #define ELFMAG0 0x7f /* EI_MAG */
61842 #define ELFMAG1 'E'
61843 #define ELFMAG2 'L'
61844 @@ -421,6 +449,7 @@ extern Elf32_Dyn _DYNAMIC [];
61845 #define elf_note elf32_note
61846 #define elf_addr_t Elf32_Off
61847 #define Elf_Half Elf32_Half
61848 +#define elf_dyn Elf32_Dyn
61849
61850 #else
61851
61852 @@ -431,6 +460,7 @@ extern Elf64_Dyn _DYNAMIC [];
61853 #define elf_note elf64_note
61854 #define elf_addr_t Elf64_Off
61855 #define Elf_Half Elf64_Half
61856 +#define elf_dyn Elf64_Dyn
61857
61858 #endif
61859
61860 diff --git a/include/linux/filter.h b/include/linux/filter.h
61861 index 82b0135..917914d 100644
61862 --- a/include/linux/filter.h
61863 +++ b/include/linux/filter.h
61864 @@ -146,6 +146,7 @@ struct compat_sock_fprog {
61865
61866 struct sk_buff;
61867 struct sock;
61868 +struct bpf_jit_work;
61869
61870 struct sk_filter
61871 {
61872 @@ -153,6 +154,9 @@ struct sk_filter
61873 unsigned int len; /* Number of filter blocks */
61874 unsigned int (*bpf_func)(const struct sk_buff *skb,
61875 const struct sock_filter *filter);
61876 +#ifdef CONFIG_BPF_JIT
61877 + struct bpf_jit_work *work;
61878 +#endif
61879 struct rcu_head rcu;
61880 struct sock_filter insns[0];
61881 };
61882 diff --git a/include/linux/firewire.h b/include/linux/firewire.h
61883 index db04ec5..f6ed627 100644
61884 --- a/include/linux/firewire.h
61885 +++ b/include/linux/firewire.h
61886 @@ -430,7 +430,7 @@ struct fw_iso_context {
61887 union {
61888 fw_iso_callback_t sc;
61889 fw_iso_mc_callback_t mc;
61890 - } callback;
61891 + } __no_const callback;
61892 void *callback_data;
61893 };
61894
61895 diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
61896 index 0e4e2ee..4ff4312 100644
61897 --- a/include/linux/frontswap.h
61898 +++ b/include/linux/frontswap.h
61899 @@ -11,7 +11,7 @@ struct frontswap_ops {
61900 int (*load)(unsigned, pgoff_t, struct page *);
61901 void (*invalidate_page)(unsigned, pgoff_t);
61902 void (*invalidate_area)(unsigned);
61903 -};
61904 +} __no_const;
61905
61906 extern bool frontswap_enabled;
61907 extern struct frontswap_ops
61908 diff --git a/include/linux/fs.h b/include/linux/fs.h
61909 index aa11047..7d046d0 100644
61910 --- a/include/linux/fs.h
61911 +++ b/include/linux/fs.h
61912 @@ -1802,7 +1802,8 @@ struct file_operations {
61913 int (*setlease)(struct file *, long, struct file_lock **);
61914 long (*fallocate)(struct file *file, int mode, loff_t offset,
61915 loff_t len);
61916 -};
61917 +} __do_const;
61918 +typedef struct file_operations __no_const file_operations_no_const;
61919
61920 struct inode_operations {
61921 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
61922 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
61923 index 003dc0f..3c4ea97 100644
61924 --- a/include/linux/fs_struct.h
61925 +++ b/include/linux/fs_struct.h
61926 @@ -6,7 +6,7 @@
61927 #include <linux/seqlock.h>
61928
61929 struct fs_struct {
61930 - int users;
61931 + atomic_t users;
61932 spinlock_t lock;
61933 seqcount_t seq;
61934 int umask;
61935 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
61936 index ce31408..b1ad003 100644
61937 --- a/include/linux/fscache-cache.h
61938 +++ b/include/linux/fscache-cache.h
61939 @@ -102,7 +102,7 @@ struct fscache_operation {
61940 fscache_operation_release_t release;
61941 };
61942
61943 -extern atomic_t fscache_op_debug_id;
61944 +extern atomic_unchecked_t fscache_op_debug_id;
61945 extern void fscache_op_work_func(struct work_struct *work);
61946
61947 extern void fscache_enqueue_operation(struct fscache_operation *);
61948 @@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
61949 {
61950 INIT_WORK(&op->work, fscache_op_work_func);
61951 atomic_set(&op->usage, 1);
61952 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
61953 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
61954 op->processor = processor;
61955 op->release = release;
61956 INIT_LIST_HEAD(&op->pend_link);
61957 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
61958 index a6dfe69..569586df 100644
61959 --- a/include/linux/fsnotify.h
61960 +++ b/include/linux/fsnotify.h
61961 @@ -315,7 +315,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
61962 */
61963 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
61964 {
61965 - return kstrdup(name, GFP_KERNEL);
61966 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
61967 }
61968
61969 /*
61970 diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
61971 index 63d966d..cdcb717 100644
61972 --- a/include/linux/fsnotify_backend.h
61973 +++ b/include/linux/fsnotify_backend.h
61974 @@ -105,6 +105,7 @@ struct fsnotify_ops {
61975 void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group);
61976 void (*free_event_priv)(struct fsnotify_event_private_data *priv);
61977 };
61978 +typedef struct fsnotify_ops __no_const fsnotify_ops_no_const;
61979
61980 /*
61981 * A group is a "thing" that wants to receive notification about filesystem
61982 diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
61983 index 642928c..e6c83a7 100644
61984 --- a/include/linux/ftrace_event.h
61985 +++ b/include/linux/ftrace_event.h
61986 @@ -97,7 +97,7 @@ struct trace_event_functions {
61987 trace_print_func raw;
61988 trace_print_func hex;
61989 trace_print_func binary;
61990 -};
61991 +} __no_const;
61992
61993 struct trace_event {
61994 struct hlist_node node;
61995 @@ -266,7 +266,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
61996 extern int trace_add_event_call(struct ftrace_event_call *call);
61997 extern void trace_remove_event_call(struct ftrace_event_call *call);
61998
61999 -#define is_signed_type(type) (((type)(-1)) < 0)
62000 +#define is_signed_type(type) (((type)(-1)) < (type)1)
62001
62002 int trace_set_clr_event(const char *system, const char *event, int set);
62003
62004 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
62005 index 4f440b3..342233a 100644
62006 --- a/include/linux/genhd.h
62007 +++ b/include/linux/genhd.h
62008 @@ -190,7 +190,7 @@ struct gendisk {
62009 struct kobject *slave_dir;
62010
62011 struct timer_rand_state *random;
62012 - atomic_t sync_io; /* RAID */
62013 + atomic_unchecked_t sync_io; /* RAID */
62014 struct disk_events *ev;
62015 #ifdef CONFIG_BLK_DEV_INTEGRITY
62016 struct blk_integrity *integrity;
62017 diff --git a/include/linux/gfp.h b/include/linux/gfp.h
62018 index 4883f39..26688a8 100644
62019 --- a/include/linux/gfp.h
62020 +++ b/include/linux/gfp.h
62021 @@ -39,6 +39,12 @@ struct vm_area_struct;
62022 #define ___GFP_OTHER_NODE 0x800000u
62023 #define ___GFP_WRITE 0x1000000u
62024
62025 +#ifdef CONFIG_PAX_USERCOPY_SLABS
62026 +#define ___GFP_USERCOPY 0x2000000u
62027 +#else
62028 +#define ___GFP_USERCOPY 0
62029 +#endif
62030 +
62031 /*
62032 * GFP bitmasks..
62033 *
62034 @@ -93,6 +99,7 @@ struct vm_area_struct;
62035 #define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD)
62036 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
62037 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
62038 +#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
62039
62040 /*
62041 * This may seem redundant, but it's a way of annotating false positives vs.
62042 @@ -100,7 +107,7 @@ struct vm_area_struct;
62043 */
62044 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
62045
62046 -#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
62047 +#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
62048 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
62049
62050 /* This equals 0, but use constants in case they ever change */
62051 @@ -154,6 +161,8 @@ struct vm_area_struct;
62052 /* 4GB DMA on some platforms */
62053 #define GFP_DMA32 __GFP_DMA32
62054
62055 +#define GFP_USERCOPY __GFP_USERCOPY
62056 +
62057 /* Convert GFP flags to their corresponding migrate type */
62058 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
62059 {
62060 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
62061 new file mode 100644
62062 index 0000000..c938b1f
62063 --- /dev/null
62064 +++ b/include/linux/gracl.h
62065 @@ -0,0 +1,319 @@
62066 +#ifndef GR_ACL_H
62067 +#define GR_ACL_H
62068 +
62069 +#include <linux/grdefs.h>
62070 +#include <linux/resource.h>
62071 +#include <linux/capability.h>
62072 +#include <linux/dcache.h>
62073 +#include <asm/resource.h>
62074 +
62075 +/* Major status information */
62076 +
62077 +#define GR_VERSION "grsecurity 2.9.1"
62078 +#define GRSECURITY_VERSION 0x2901
62079 +
62080 +enum {
62081 + GR_SHUTDOWN = 0,
62082 + GR_ENABLE = 1,
62083 + GR_SPROLE = 2,
62084 + GR_RELOAD = 3,
62085 + GR_SEGVMOD = 4,
62086 + GR_STATUS = 5,
62087 + GR_UNSPROLE = 6,
62088 + GR_PASSSET = 7,
62089 + GR_SPROLEPAM = 8,
62090 +};
62091 +
62092 +/* Password setup definitions
62093 + * kernel/grhash.c */
62094 +enum {
62095 + GR_PW_LEN = 128,
62096 + GR_SALT_LEN = 16,
62097 + GR_SHA_LEN = 32,
62098 +};
62099 +
62100 +enum {
62101 + GR_SPROLE_LEN = 64,
62102 +};
62103 +
62104 +enum {
62105 + GR_NO_GLOB = 0,
62106 + GR_REG_GLOB,
62107 + GR_CREATE_GLOB
62108 +};
62109 +
62110 +#define GR_NLIMITS 32
62111 +
62112 +/* Begin Data Structures */
62113 +
62114 +struct sprole_pw {
62115 + unsigned char *rolename;
62116 + unsigned char salt[GR_SALT_LEN];
62117 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
62118 +};
62119 +
62120 +struct name_entry {
62121 + __u32 key;
62122 + ino_t inode;
62123 + dev_t device;
62124 + char *name;
62125 + __u16 len;
62126 + __u8 deleted;
62127 + struct name_entry *prev;
62128 + struct name_entry *next;
62129 +};
62130 +
62131 +struct inodev_entry {
62132 + struct name_entry *nentry;
62133 + struct inodev_entry *prev;
62134 + struct inodev_entry *next;
62135 +};
62136 +
62137 +struct acl_role_db {
62138 + struct acl_role_label **r_hash;
62139 + __u32 r_size;
62140 +};
62141 +
62142 +struct inodev_db {
62143 + struct inodev_entry **i_hash;
62144 + __u32 i_size;
62145 +};
62146 +
62147 +struct name_db {
62148 + struct name_entry **n_hash;
62149 + __u32 n_size;
62150 +};
62151 +
62152 +struct crash_uid {
62153 + uid_t uid;
62154 + unsigned long expires;
62155 +};
62156 +
62157 +struct gr_hash_struct {
62158 + void **table;
62159 + void **nametable;
62160 + void *first;
62161 + __u32 table_size;
62162 + __u32 used_size;
62163 + int type;
62164 +};
62165 +
62166 +/* Userspace Grsecurity ACL data structures */
62167 +
62168 +struct acl_subject_label {
62169 + char *filename;
62170 + ino_t inode;
62171 + dev_t device;
62172 + __u32 mode;
62173 + kernel_cap_t cap_mask;
62174 + kernel_cap_t cap_lower;
62175 + kernel_cap_t cap_invert_audit;
62176 +
62177 + struct rlimit res[GR_NLIMITS];
62178 + __u32 resmask;
62179 +
62180 + __u8 user_trans_type;
62181 + __u8 group_trans_type;
62182 + uid_t *user_transitions;
62183 + gid_t *group_transitions;
62184 + __u16 user_trans_num;
62185 + __u16 group_trans_num;
62186 +
62187 + __u32 sock_families[2];
62188 + __u32 ip_proto[8];
62189 + __u32 ip_type;
62190 + struct acl_ip_label **ips;
62191 + __u32 ip_num;
62192 + __u32 inaddr_any_override;
62193 +
62194 + __u32 crashes;
62195 + unsigned long expires;
62196 +
62197 + struct acl_subject_label *parent_subject;
62198 + struct gr_hash_struct *hash;
62199 + struct acl_subject_label *prev;
62200 + struct acl_subject_label *next;
62201 +
62202 + struct acl_object_label **obj_hash;
62203 + __u32 obj_hash_size;
62204 + __u16 pax_flags;
62205 +};
62206 +
62207 +struct role_allowed_ip {
62208 + __u32 addr;
62209 + __u32 netmask;
62210 +
62211 + struct role_allowed_ip *prev;
62212 + struct role_allowed_ip *next;
62213 +};
62214 +
62215 +struct role_transition {
62216 + char *rolename;
62217 +
62218 + struct role_transition *prev;
62219 + struct role_transition *next;
62220 +};
62221 +
62222 +struct acl_role_label {
62223 + char *rolename;
62224 + uid_t uidgid;
62225 + __u16 roletype;
62226 +
62227 + __u16 auth_attempts;
62228 + unsigned long expires;
62229 +
62230 + struct acl_subject_label *root_label;
62231 + struct gr_hash_struct *hash;
62232 +
62233 + struct acl_role_label *prev;
62234 + struct acl_role_label *next;
62235 +
62236 + struct role_transition *transitions;
62237 + struct role_allowed_ip *allowed_ips;
62238 + uid_t *domain_children;
62239 + __u16 domain_child_num;
62240 +
62241 + umode_t umask;
62242 +
62243 + struct acl_subject_label **subj_hash;
62244 + __u32 subj_hash_size;
62245 +};
62246 +
62247 +struct user_acl_role_db {
62248 + struct acl_role_label **r_table;
62249 + __u32 num_pointers; /* Number of allocations to track */
62250 + __u32 num_roles; /* Number of roles */
62251 + __u32 num_domain_children; /* Number of domain children */
62252 + __u32 num_subjects; /* Number of subjects */
62253 + __u32 num_objects; /* Number of objects */
62254 +};
62255 +
62256 +struct acl_object_label {
62257 + char *filename;
62258 + ino_t inode;
62259 + dev_t device;
62260 + __u32 mode;
62261 +
62262 + struct acl_subject_label *nested;
62263 + struct acl_object_label *globbed;
62264 +
62265 + /* next two structures not used */
62266 +
62267 + struct acl_object_label *prev;
62268 + struct acl_object_label *next;
62269 +};
62270 +
62271 +struct acl_ip_label {
62272 + char *iface;
62273 + __u32 addr;
62274 + __u32 netmask;
62275 + __u16 low, high;
62276 + __u8 mode;
62277 + __u32 type;
62278 + __u32 proto[8];
62279 +
62280 + /* next two structures not used */
62281 +
62282 + struct acl_ip_label *prev;
62283 + struct acl_ip_label *next;
62284 +};
62285 +
62286 +struct gr_arg {
62287 + struct user_acl_role_db role_db;
62288 + unsigned char pw[GR_PW_LEN];
62289 + unsigned char salt[GR_SALT_LEN];
62290 + unsigned char sum[GR_SHA_LEN];
62291 + unsigned char sp_role[GR_SPROLE_LEN];
62292 + struct sprole_pw *sprole_pws;
62293 + dev_t segv_device;
62294 + ino_t segv_inode;
62295 + uid_t segv_uid;
62296 + __u16 num_sprole_pws;
62297 + __u16 mode;
62298 +};
62299 +
62300 +struct gr_arg_wrapper {
62301 + struct gr_arg *arg;
62302 + __u32 version;
62303 + __u32 size;
62304 +};
62305 +
62306 +struct subject_map {
62307 + struct acl_subject_label *user;
62308 + struct acl_subject_label *kernel;
62309 + struct subject_map *prev;
62310 + struct subject_map *next;
62311 +};
62312 +
62313 +struct acl_subj_map_db {
62314 + struct subject_map **s_hash;
62315 + __u32 s_size;
62316 +};
62317 +
62318 +/* End Data Structures Section */
62319 +
62320 +/* Hash functions generated by empirical testing by Brad Spengler
62321 + Makes good use of the low bits of the inode. Generally 0-1 times
62322 + in loop for successful match. 0-3 for unsuccessful match.
62323 + Shift/add algorithm with modulus of table size and an XOR*/
62324 +
62325 +static __inline__ unsigned int
62326 +rhash(const uid_t uid, const __u16 type, const unsigned int sz)
62327 +{
62328 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
62329 +}
62330 +
62331 + static __inline__ unsigned int
62332 +shash(const struct acl_subject_label *userp, const unsigned int sz)
62333 +{
62334 + return ((const unsigned long)userp % sz);
62335 +}
62336 +
62337 +static __inline__ unsigned int
62338 +fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
62339 +{
62340 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
62341 +}
62342 +
62343 +static __inline__ unsigned int
62344 +nhash(const char *name, const __u16 len, const unsigned int sz)
62345 +{
62346 + return full_name_hash((const unsigned char *)name, len) % sz;
62347 +}
62348 +
62349 +#define FOR_EACH_ROLE_START(role) \
62350 + role = role_list; \
62351 + while (role) {
62352 +
62353 +#define FOR_EACH_ROLE_END(role) \
62354 + role = role->prev; \
62355 + }
62356 +
62357 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
62358 + subj = NULL; \
62359 + iter = 0; \
62360 + while (iter < role->subj_hash_size) { \
62361 + if (subj == NULL) \
62362 + subj = role->subj_hash[iter]; \
62363 + if (subj == NULL) { \
62364 + iter++; \
62365 + continue; \
62366 + }
62367 +
62368 +#define FOR_EACH_SUBJECT_END(subj,iter) \
62369 + subj = subj->next; \
62370 + if (subj == NULL) \
62371 + iter++; \
62372 + }
62373 +
62374 +
62375 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
62376 + subj = role->hash->first; \
62377 + while (subj != NULL) {
62378 +
62379 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
62380 + subj = subj->next; \
62381 + }
62382 +
62383 +#endif
62384 +
62385 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
62386 new file mode 100644
62387 index 0000000..323ecf2
62388 --- /dev/null
62389 +++ b/include/linux/gralloc.h
62390 @@ -0,0 +1,9 @@
62391 +#ifndef __GRALLOC_H
62392 +#define __GRALLOC_H
62393 +
62394 +void acl_free_all(void);
62395 +int acl_alloc_stack_init(unsigned long size);
62396 +void *acl_alloc(unsigned long len);
62397 +void *acl_alloc_num(unsigned long num, unsigned long len);
62398 +
62399 +#endif
62400 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
62401 new file mode 100644
62402 index 0000000..b30e9bc
62403 --- /dev/null
62404 +++ b/include/linux/grdefs.h
62405 @@ -0,0 +1,140 @@
62406 +#ifndef GRDEFS_H
62407 +#define GRDEFS_H
62408 +
62409 +/* Begin grsecurity status declarations */
62410 +
62411 +enum {
62412 + GR_READY = 0x01,
62413 + GR_STATUS_INIT = 0x00 // disabled state
62414 +};
62415 +
62416 +/* Begin ACL declarations */
62417 +
62418 +/* Role flags */
62419 +
62420 +enum {
62421 + GR_ROLE_USER = 0x0001,
62422 + GR_ROLE_GROUP = 0x0002,
62423 + GR_ROLE_DEFAULT = 0x0004,
62424 + GR_ROLE_SPECIAL = 0x0008,
62425 + GR_ROLE_AUTH = 0x0010,
62426 + GR_ROLE_NOPW = 0x0020,
62427 + GR_ROLE_GOD = 0x0040,
62428 + GR_ROLE_LEARN = 0x0080,
62429 + GR_ROLE_TPE = 0x0100,
62430 + GR_ROLE_DOMAIN = 0x0200,
62431 + GR_ROLE_PAM = 0x0400,
62432 + GR_ROLE_PERSIST = 0x0800
62433 +};
62434 +
62435 +/* ACL Subject and Object mode flags */
62436 +enum {
62437 + GR_DELETED = 0x80000000
62438 +};
62439 +
62440 +/* ACL Object-only mode flags */
62441 +enum {
62442 + GR_READ = 0x00000001,
62443 + GR_APPEND = 0x00000002,
62444 + GR_WRITE = 0x00000004,
62445 + GR_EXEC = 0x00000008,
62446 + GR_FIND = 0x00000010,
62447 + GR_INHERIT = 0x00000020,
62448 + GR_SETID = 0x00000040,
62449 + GR_CREATE = 0x00000080,
62450 + GR_DELETE = 0x00000100,
62451 + GR_LINK = 0x00000200,
62452 + GR_AUDIT_READ = 0x00000400,
62453 + GR_AUDIT_APPEND = 0x00000800,
62454 + GR_AUDIT_WRITE = 0x00001000,
62455 + GR_AUDIT_EXEC = 0x00002000,
62456 + GR_AUDIT_FIND = 0x00004000,
62457 + GR_AUDIT_INHERIT= 0x00008000,
62458 + GR_AUDIT_SETID = 0x00010000,
62459 + GR_AUDIT_CREATE = 0x00020000,
62460 + GR_AUDIT_DELETE = 0x00040000,
62461 + GR_AUDIT_LINK = 0x00080000,
62462 + GR_PTRACERD = 0x00100000,
62463 + GR_NOPTRACE = 0x00200000,
62464 + GR_SUPPRESS = 0x00400000,
62465 + GR_NOLEARN = 0x00800000,
62466 + GR_INIT_TRANSFER= 0x01000000
62467 +};
62468 +
62469 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
62470 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
62471 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
62472 +
62473 +/* ACL subject-only mode flags */
62474 +enum {
62475 + GR_KILL = 0x00000001,
62476 + GR_VIEW = 0x00000002,
62477 + GR_PROTECTED = 0x00000004,
62478 + GR_LEARN = 0x00000008,
62479 + GR_OVERRIDE = 0x00000010,
62480 + /* just a placeholder, this mode is only used in userspace */
62481 + GR_DUMMY = 0x00000020,
62482 + GR_PROTSHM = 0x00000040,
62483 + GR_KILLPROC = 0x00000080,
62484 + GR_KILLIPPROC = 0x00000100,
62485 + /* just a placeholder, this mode is only used in userspace */
62486 + GR_NOTROJAN = 0x00000200,
62487 + GR_PROTPROCFD = 0x00000400,
62488 + GR_PROCACCT = 0x00000800,
62489 + GR_RELAXPTRACE = 0x00001000,
62490 + GR_NESTED = 0x00002000,
62491 + GR_INHERITLEARN = 0x00004000,
62492 + GR_PROCFIND = 0x00008000,
62493 + GR_POVERRIDE = 0x00010000,
62494 + GR_KERNELAUTH = 0x00020000,
62495 + GR_ATSECURE = 0x00040000,
62496 + GR_SHMEXEC = 0x00080000
62497 +};
62498 +
62499 +enum {
62500 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
62501 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
62502 + GR_PAX_ENABLE_MPROTECT = 0x0004,
62503 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
62504 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
62505 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
62506 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
62507 + GR_PAX_DISABLE_MPROTECT = 0x0400,
62508 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
62509 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
62510 +};
62511 +
62512 +enum {
62513 + GR_ID_USER = 0x01,
62514 + GR_ID_GROUP = 0x02,
62515 +};
62516 +
62517 +enum {
62518 + GR_ID_ALLOW = 0x01,
62519 + GR_ID_DENY = 0x02,
62520 +};
62521 +
62522 +#define GR_CRASH_RES 31
62523 +#define GR_UIDTABLE_MAX 500
62524 +
62525 +/* begin resource learning section */
62526 +enum {
62527 + GR_RLIM_CPU_BUMP = 60,
62528 + GR_RLIM_FSIZE_BUMP = 50000,
62529 + GR_RLIM_DATA_BUMP = 10000,
62530 + GR_RLIM_STACK_BUMP = 1000,
62531 + GR_RLIM_CORE_BUMP = 10000,
62532 + GR_RLIM_RSS_BUMP = 500000,
62533 + GR_RLIM_NPROC_BUMP = 1,
62534 + GR_RLIM_NOFILE_BUMP = 5,
62535 + GR_RLIM_MEMLOCK_BUMP = 50000,
62536 + GR_RLIM_AS_BUMP = 500000,
62537 + GR_RLIM_LOCKS_BUMP = 2,
62538 + GR_RLIM_SIGPENDING_BUMP = 5,
62539 + GR_RLIM_MSGQUEUE_BUMP = 10000,
62540 + GR_RLIM_NICE_BUMP = 1,
62541 + GR_RLIM_RTPRIO_BUMP = 1,
62542 + GR_RLIM_RTTIME_BUMP = 1000000
62543 +};
62544 +
62545 +#endif
62546 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
62547 new file mode 100644
62548 index 0000000..c9292f7
62549 --- /dev/null
62550 +++ b/include/linux/grinternal.h
62551 @@ -0,0 +1,223 @@
62552 +#ifndef __GRINTERNAL_H
62553 +#define __GRINTERNAL_H
62554 +
62555 +#ifdef CONFIG_GRKERNSEC
62556 +
62557 +#include <linux/fs.h>
62558 +#include <linux/mnt_namespace.h>
62559 +#include <linux/nsproxy.h>
62560 +#include <linux/gracl.h>
62561 +#include <linux/grdefs.h>
62562 +#include <linux/grmsg.h>
62563 +
62564 +void gr_add_learn_entry(const char *fmt, ...)
62565 + __attribute__ ((format (printf, 1, 2)));
62566 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
62567 + const struct vfsmount *mnt);
62568 +__u32 gr_check_create(const struct dentry *new_dentry,
62569 + const struct dentry *parent,
62570 + const struct vfsmount *mnt, const __u32 mode);
62571 +int gr_check_protected_task(const struct task_struct *task);
62572 +__u32 to_gr_audit(const __u32 reqmode);
62573 +int gr_set_acls(const int type);
62574 +int gr_apply_subject_to_task(struct task_struct *task);
62575 +int gr_acl_is_enabled(void);
62576 +char gr_roletype_to_char(void);
62577 +
62578 +void gr_handle_alertkill(struct task_struct *task);
62579 +char *gr_to_filename(const struct dentry *dentry,
62580 + const struct vfsmount *mnt);
62581 +char *gr_to_filename1(const struct dentry *dentry,
62582 + const struct vfsmount *mnt);
62583 +char *gr_to_filename2(const struct dentry *dentry,
62584 + const struct vfsmount *mnt);
62585 +char *gr_to_filename3(const struct dentry *dentry,
62586 + const struct vfsmount *mnt);
62587 +
62588 +extern int grsec_enable_ptrace_readexec;
62589 +extern int grsec_enable_harden_ptrace;
62590 +extern int grsec_enable_link;
62591 +extern int grsec_enable_fifo;
62592 +extern int grsec_enable_execve;
62593 +extern int grsec_enable_shm;
62594 +extern int grsec_enable_execlog;
62595 +extern int grsec_enable_signal;
62596 +extern int grsec_enable_audit_ptrace;
62597 +extern int grsec_enable_forkfail;
62598 +extern int grsec_enable_time;
62599 +extern int grsec_enable_rofs;
62600 +extern int grsec_enable_chroot_shmat;
62601 +extern int grsec_enable_chroot_mount;
62602 +extern int grsec_enable_chroot_double;
62603 +extern int grsec_enable_chroot_pivot;
62604 +extern int grsec_enable_chroot_chdir;
62605 +extern int grsec_enable_chroot_chmod;
62606 +extern int grsec_enable_chroot_mknod;
62607 +extern int grsec_enable_chroot_fchdir;
62608 +extern int grsec_enable_chroot_nice;
62609 +extern int grsec_enable_chroot_execlog;
62610 +extern int grsec_enable_chroot_caps;
62611 +extern int grsec_enable_chroot_sysctl;
62612 +extern int grsec_enable_chroot_unix;
62613 +extern int grsec_enable_symlinkown;
62614 +extern int grsec_symlinkown_gid;
62615 +extern int grsec_enable_tpe;
62616 +extern int grsec_tpe_gid;
62617 +extern int grsec_enable_tpe_all;
62618 +extern int grsec_enable_tpe_invert;
62619 +extern int grsec_enable_socket_all;
62620 +extern int grsec_socket_all_gid;
62621 +extern int grsec_enable_socket_client;
62622 +extern int grsec_socket_client_gid;
62623 +extern int grsec_enable_socket_server;
62624 +extern int grsec_socket_server_gid;
62625 +extern int grsec_audit_gid;
62626 +extern int grsec_enable_group;
62627 +extern int grsec_enable_audit_textrel;
62628 +extern int grsec_enable_log_rwxmaps;
62629 +extern int grsec_enable_mount;
62630 +extern int grsec_enable_chdir;
62631 +extern int grsec_resource_logging;
62632 +extern int grsec_enable_blackhole;
62633 +extern int grsec_lastack_retries;
62634 +extern int grsec_enable_brute;
62635 +extern int grsec_lock;
62636 +
62637 +extern spinlock_t grsec_alert_lock;
62638 +extern unsigned long grsec_alert_wtime;
62639 +extern unsigned long grsec_alert_fyet;
62640 +
62641 +extern spinlock_t grsec_audit_lock;
62642 +
62643 +extern rwlock_t grsec_exec_file_lock;
62644 +
62645 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
62646 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
62647 + (tsk)->exec_file->f_vfsmnt) : "/")
62648 +
62649 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
62650 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
62651 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
62652 +
62653 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
62654 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
62655 + (tsk)->exec_file->f_vfsmnt) : "/")
62656 +
62657 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
62658 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
62659 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
62660 +
62661 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
62662 +
62663 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
62664 +
62665 +#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
62666 + (task)->pid, (cred)->uid, \
62667 + (cred)->euid, (cred)->gid, (cred)->egid, \
62668 + gr_parent_task_fullpath(task), \
62669 + (task)->real_parent->comm, (task)->real_parent->pid, \
62670 + (pcred)->uid, (pcred)->euid, \
62671 + (pcred)->gid, (pcred)->egid
62672 +
62673 +#define GR_CHROOT_CAPS {{ \
62674 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
62675 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
62676 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
62677 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
62678 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
62679 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
62680 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
62681 +
62682 +#define security_learn(normal_msg,args...) \
62683 +({ \
62684 + read_lock(&grsec_exec_file_lock); \
62685 + gr_add_learn_entry(normal_msg "\n", ## args); \
62686 + read_unlock(&grsec_exec_file_lock); \
62687 +})
62688 +
62689 +enum {
62690 + GR_DO_AUDIT,
62691 + GR_DONT_AUDIT,
62692 + /* used for non-audit messages that we shouldn't kill the task on */
62693 + GR_DONT_AUDIT_GOOD
62694 +};
62695 +
62696 +enum {
62697 + GR_TTYSNIFF,
62698 + GR_RBAC,
62699 + GR_RBAC_STR,
62700 + GR_STR_RBAC,
62701 + GR_RBAC_MODE2,
62702 + GR_RBAC_MODE3,
62703 + GR_FILENAME,
62704 + GR_SYSCTL_HIDDEN,
62705 + GR_NOARGS,
62706 + GR_ONE_INT,
62707 + GR_ONE_INT_TWO_STR,
62708 + GR_ONE_STR,
62709 + GR_STR_INT,
62710 + GR_TWO_STR_INT,
62711 + GR_TWO_INT,
62712 + GR_TWO_U64,
62713 + GR_THREE_INT,
62714 + GR_FIVE_INT_TWO_STR,
62715 + GR_TWO_STR,
62716 + GR_THREE_STR,
62717 + GR_FOUR_STR,
62718 + GR_STR_FILENAME,
62719 + GR_FILENAME_STR,
62720 + GR_FILENAME_TWO_INT,
62721 + GR_FILENAME_TWO_INT_STR,
62722 + GR_TEXTREL,
62723 + GR_PTRACE,
62724 + GR_RESOURCE,
62725 + GR_CAP,
62726 + GR_SIG,
62727 + GR_SIG2,
62728 + GR_CRASH1,
62729 + GR_CRASH2,
62730 + GR_PSACCT,
62731 + GR_RWXMAP
62732 +};
62733 +
62734 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
62735 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
62736 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
62737 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
62738 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
62739 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
62740 +#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)
62741 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
62742 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
62743 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
62744 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
62745 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
62746 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
62747 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
62748 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
62749 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
62750 +#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)
62751 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
62752 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
62753 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
62754 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
62755 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
62756 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
62757 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
62758 +#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)
62759 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
62760 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
62761 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
62762 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
62763 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
62764 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
62765 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
62766 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
62767 +#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)
62768 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
62769 +
62770 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
62771 +
62772 +#endif
62773 +
62774 +#endif
62775 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
62776 new file mode 100644
62777 index 0000000..54f4e85
62778 --- /dev/null
62779 +++ b/include/linux/grmsg.h
62780 @@ -0,0 +1,110 @@
62781 +#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"
62782 +#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"
62783 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
62784 +#define GR_STOPMOD_MSG "denied modification of module state by "
62785 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
62786 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
62787 +#define GR_IOPERM_MSG "denied use of ioperm() by "
62788 +#define GR_IOPL_MSG "denied use of iopl() by "
62789 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
62790 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
62791 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
62792 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
62793 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
62794 +#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"
62795 +#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"
62796 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
62797 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
62798 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
62799 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
62800 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
62801 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
62802 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
62803 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
62804 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
62805 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
62806 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
62807 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
62808 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
62809 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
62810 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
62811 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
62812 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
62813 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
62814 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
62815 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
62816 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
62817 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
62818 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
62819 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
62820 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
62821 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
62822 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
62823 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
62824 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
62825 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
62826 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
62827 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
62828 +#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
62829 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
62830 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
62831 +#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"
62832 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
62833 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
62834 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
62835 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
62836 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
62837 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
62838 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
62839 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
62840 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
62841 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
62842 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
62843 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
62844 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
62845 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
62846 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
62847 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
62848 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
62849 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
62850 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
62851 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
62852 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
62853 +#define GR_NICE_CHROOT_MSG "denied priority change by "
62854 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
62855 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
62856 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
62857 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
62858 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
62859 +#define GR_TIME_MSG "time set by "
62860 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
62861 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
62862 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
62863 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
62864 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
62865 +#define GR_BIND_MSG "denied bind() by "
62866 +#define GR_CONNECT_MSG "denied connect() by "
62867 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
62868 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
62869 +#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"
62870 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
62871 +#define GR_CAP_ACL_MSG "use of %s denied for "
62872 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
62873 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
62874 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
62875 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
62876 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
62877 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
62878 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
62879 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
62880 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
62881 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
62882 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
62883 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
62884 +#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
62885 +#define GR_VM86_MSG "denied use of vm86 by "
62886 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
62887 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
62888 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
62889 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
62890 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
62891 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
62892 new file mode 100644
62893 index 0000000..f9b9a21
62894 --- /dev/null
62895 +++ b/include/linux/grsecurity.h
62896 @@ -0,0 +1,238 @@
62897 +#ifndef GR_SECURITY_H
62898 +#define GR_SECURITY_H
62899 +#include <linux/fs.h>
62900 +#include <linux/fs_struct.h>
62901 +#include <linux/binfmts.h>
62902 +#include <linux/gracl.h>
62903 +
62904 +/* notify of brain-dead configs */
62905 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62906 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
62907 +#endif
62908 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
62909 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
62910 +#endif
62911 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
62912 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
62913 +#endif
62914 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
62915 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
62916 +#endif
62917 +
62918 +#include <linux/compat.h>
62919 +
62920 +struct user_arg_ptr {
62921 +#ifdef CONFIG_COMPAT
62922 + bool is_compat;
62923 +#endif
62924 + union {
62925 + const char __user *const __user *native;
62926 +#ifdef CONFIG_COMPAT
62927 + compat_uptr_t __user *compat;
62928 +#endif
62929 + } ptr;
62930 +};
62931 +
62932 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
62933 +void gr_handle_brute_check(void);
62934 +void gr_handle_kernel_exploit(void);
62935 +int gr_process_user_ban(void);
62936 +
62937 +char gr_roletype_to_char(void);
62938 +
62939 +int gr_acl_enable_at_secure(void);
62940 +
62941 +int gr_check_user_change(int real, int effective, int fs);
62942 +int gr_check_group_change(int real, int effective, int fs);
62943 +
62944 +void gr_del_task_from_ip_table(struct task_struct *p);
62945 +
62946 +int gr_pid_is_chrooted(struct task_struct *p);
62947 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
62948 +int gr_handle_chroot_nice(void);
62949 +int gr_handle_chroot_sysctl(const int op);
62950 +int gr_handle_chroot_setpriority(struct task_struct *p,
62951 + const int niceval);
62952 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
62953 +int gr_handle_chroot_chroot(const struct dentry *dentry,
62954 + const struct vfsmount *mnt);
62955 +void gr_handle_chroot_chdir(struct path *path);
62956 +int gr_handle_chroot_chmod(const struct dentry *dentry,
62957 + const struct vfsmount *mnt, const int mode);
62958 +int gr_handle_chroot_mknod(const struct dentry *dentry,
62959 + const struct vfsmount *mnt, const int mode);
62960 +int gr_handle_chroot_mount(const struct dentry *dentry,
62961 + const struct vfsmount *mnt,
62962 + const char *dev_name);
62963 +int gr_handle_chroot_pivot(void);
62964 +int gr_handle_chroot_unix(const pid_t pid);
62965 +
62966 +int gr_handle_rawio(const struct inode *inode);
62967 +
62968 +void gr_handle_ioperm(void);
62969 +void gr_handle_iopl(void);
62970 +
62971 +umode_t gr_acl_umask(void);
62972 +
62973 +int gr_tpe_allow(const struct file *file);
62974 +
62975 +void gr_set_chroot_entries(struct task_struct *task, struct path *path);
62976 +void gr_clear_chroot_entries(struct task_struct *task);
62977 +
62978 +void gr_log_forkfail(const int retval);
62979 +void gr_log_timechange(void);
62980 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
62981 +void gr_log_chdir(const struct dentry *dentry,
62982 + const struct vfsmount *mnt);
62983 +void gr_log_chroot_exec(const struct dentry *dentry,
62984 + const struct vfsmount *mnt);
62985 +void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
62986 +void gr_log_remount(const char *devname, const int retval);
62987 +void gr_log_unmount(const char *devname, const int retval);
62988 +void gr_log_mount(const char *from, const char *to, const int retval);
62989 +void gr_log_textrel(struct vm_area_struct *vma);
62990 +void gr_log_rwxmmap(struct file *file);
62991 +void gr_log_rwxmprotect(struct file *file);
62992 +
62993 +int gr_handle_follow_link(const struct inode *parent,
62994 + const struct inode *inode,
62995 + const struct dentry *dentry,
62996 + const struct vfsmount *mnt);
62997 +int gr_handle_fifo(const struct dentry *dentry,
62998 + const struct vfsmount *mnt,
62999 + const struct dentry *dir, const int flag,
63000 + const int acc_mode);
63001 +int gr_handle_hardlink(const struct dentry *dentry,
63002 + const struct vfsmount *mnt,
63003 + struct inode *inode,
63004 + const int mode, const char *to);
63005 +
63006 +int gr_is_capable(const int cap);
63007 +int gr_is_capable_nolog(const int cap);
63008 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
63009 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
63010 +
63011 +void gr_learn_resource(const struct task_struct *task, const int limit,
63012 + const unsigned long wanted, const int gt);
63013 +void gr_copy_label(struct task_struct *tsk);
63014 +void gr_handle_crash(struct task_struct *task, const int sig);
63015 +int gr_handle_signal(const struct task_struct *p, const int sig);
63016 +int gr_check_crash_uid(const uid_t uid);
63017 +int gr_check_protected_task(const struct task_struct *task);
63018 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
63019 +int gr_acl_handle_mmap(const struct file *file,
63020 + const unsigned long prot);
63021 +int gr_acl_handle_mprotect(const struct file *file,
63022 + const unsigned long prot);
63023 +int gr_check_hidden_task(const struct task_struct *tsk);
63024 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
63025 + const struct vfsmount *mnt);
63026 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
63027 + const struct vfsmount *mnt);
63028 +__u32 gr_acl_handle_access(const struct dentry *dentry,
63029 + const struct vfsmount *mnt, const int fmode);
63030 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
63031 + const struct vfsmount *mnt, umode_t *mode);
63032 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
63033 + const struct vfsmount *mnt);
63034 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
63035 + const struct vfsmount *mnt);
63036 +int gr_handle_ptrace(struct task_struct *task, const long request);
63037 +int gr_handle_proc_ptrace(struct task_struct *task);
63038 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
63039 + const struct vfsmount *mnt);
63040 +int gr_check_crash_exec(const struct file *filp);
63041 +int gr_acl_is_enabled(void);
63042 +void gr_set_kernel_label(struct task_struct *task);
63043 +void gr_set_role_label(struct task_struct *task, const uid_t uid,
63044 + const gid_t gid);
63045 +int gr_set_proc_label(const struct dentry *dentry,
63046 + const struct vfsmount *mnt,
63047 + const int unsafe_flags);
63048 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
63049 + const struct vfsmount *mnt);
63050 +__u32 gr_acl_handle_open(const struct dentry *dentry,
63051 + const struct vfsmount *mnt, int acc_mode);
63052 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
63053 + const struct dentry *p_dentry,
63054 + const struct vfsmount *p_mnt,
63055 + int open_flags, int acc_mode, const int imode);
63056 +void gr_handle_create(const struct dentry *dentry,
63057 + const struct vfsmount *mnt);
63058 +void gr_handle_proc_create(const struct dentry *dentry,
63059 + const struct inode *inode);
63060 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
63061 + const struct dentry *parent_dentry,
63062 + const struct vfsmount *parent_mnt,
63063 + const int mode);
63064 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
63065 + const struct dentry *parent_dentry,
63066 + const struct vfsmount *parent_mnt);
63067 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
63068 + const struct vfsmount *mnt);
63069 +void gr_handle_delete(const ino_t ino, const dev_t dev);
63070 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
63071 + const struct vfsmount *mnt);
63072 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
63073 + const struct dentry *parent_dentry,
63074 + const struct vfsmount *parent_mnt,
63075 + const char *from);
63076 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
63077 + const struct dentry *parent_dentry,
63078 + const struct vfsmount *parent_mnt,
63079 + const struct dentry *old_dentry,
63080 + const struct vfsmount *old_mnt, const char *to);
63081 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
63082 +int gr_acl_handle_rename(struct dentry *new_dentry,
63083 + struct dentry *parent_dentry,
63084 + const struct vfsmount *parent_mnt,
63085 + struct dentry *old_dentry,
63086 + struct inode *old_parent_inode,
63087 + struct vfsmount *old_mnt, const char *newname);
63088 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
63089 + struct dentry *old_dentry,
63090 + struct dentry *new_dentry,
63091 + struct vfsmount *mnt, const __u8 replace);
63092 +__u32 gr_check_link(const struct dentry *new_dentry,
63093 + const struct dentry *parent_dentry,
63094 + const struct vfsmount *parent_mnt,
63095 + const struct dentry *old_dentry,
63096 + const struct vfsmount *old_mnt);
63097 +int gr_acl_handle_filldir(const struct file *file, const char *name,
63098 + const unsigned int namelen, const ino_t ino);
63099 +
63100 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
63101 + const struct vfsmount *mnt);
63102 +void gr_acl_handle_exit(void);
63103 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
63104 +int gr_acl_handle_procpidmem(const struct task_struct *task);
63105 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
63106 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
63107 +void gr_audit_ptrace(struct task_struct *task);
63108 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
63109 +
63110 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
63111 +
63112 +#ifdef CONFIG_GRKERNSEC
63113 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
63114 +void gr_handle_vm86(void);
63115 +void gr_handle_mem_readwrite(u64 from, u64 to);
63116 +
63117 +void gr_log_badprocpid(const char *entry);
63118 +
63119 +extern int grsec_enable_dmesg;
63120 +extern int grsec_disable_privio;
63121 +
63122 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63123 +extern int grsec_proc_gid;
63124 +#endif
63125 +
63126 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
63127 +extern int grsec_enable_chroot_findtask;
63128 +#endif
63129 +#ifdef CONFIG_GRKERNSEC_SETXID
63130 +extern int grsec_enable_setxid;
63131 +#endif
63132 +#endif
63133 +
63134 +#endif
63135 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
63136 new file mode 100644
63137 index 0000000..e7ffaaf
63138 --- /dev/null
63139 +++ b/include/linux/grsock.h
63140 @@ -0,0 +1,19 @@
63141 +#ifndef __GRSOCK_H
63142 +#define __GRSOCK_H
63143 +
63144 +extern void gr_attach_curr_ip(const struct sock *sk);
63145 +extern int gr_handle_sock_all(const int family, const int type,
63146 + const int protocol);
63147 +extern int gr_handle_sock_server(const struct sockaddr *sck);
63148 +extern int gr_handle_sock_server_other(const struct sock *sck);
63149 +extern int gr_handle_sock_client(const struct sockaddr *sck);
63150 +extern int gr_search_connect(struct socket * sock,
63151 + struct sockaddr_in * addr);
63152 +extern int gr_search_bind(struct socket * sock,
63153 + struct sockaddr_in * addr);
63154 +extern int gr_search_listen(struct socket * sock);
63155 +extern int gr_search_accept(struct socket * sock);
63156 +extern int gr_search_socket(const int domain, const int type,
63157 + const int protocol);
63158 +
63159 +#endif
63160 diff --git a/include/linux/hid.h b/include/linux/hid.h
63161 index 42970de..5db3c92 100644
63162 --- a/include/linux/hid.h
63163 +++ b/include/linux/hid.h
63164 @@ -705,7 +705,7 @@ struct hid_ll_driver {
63165 unsigned int code, int value);
63166
63167 int (*parse)(struct hid_device *hdev);
63168 -};
63169 +} __no_const;
63170
63171 #define PM_HINT_FULLON 1<<5
63172 #define PM_HINT_NORMAL 1<<1
63173 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
63174 index ef788b5..ac41b7b 100644
63175 --- a/include/linux/highmem.h
63176 +++ b/include/linux/highmem.h
63177 @@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
63178 kunmap_atomic(kaddr);
63179 }
63180
63181 +static inline void sanitize_highpage(struct page *page)
63182 +{
63183 + void *kaddr;
63184 + unsigned long flags;
63185 +
63186 + local_irq_save(flags);
63187 + kaddr = kmap_atomic(page);
63188 + clear_page(kaddr);
63189 + kunmap_atomic(kaddr);
63190 + local_irq_restore(flags);
63191 +}
63192 +
63193 static inline void zero_user_segments(struct page *page,
63194 unsigned start1, unsigned end1,
63195 unsigned start2, unsigned end2)
63196 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
63197 index 5970266..1c48c3b 100644
63198 --- a/include/linux/i2c.h
63199 +++ b/include/linux/i2c.h
63200 @@ -369,6 +369,7 @@ struct i2c_algorithm {
63201 /* To determine what the adapter supports */
63202 u32 (*functionality) (struct i2c_adapter *);
63203 };
63204 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
63205
63206 /*
63207 * i2c_adapter is the structure used to identify a physical i2c bus along
63208 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
63209 index d23c3c2..eb63c81 100644
63210 --- a/include/linux/i2o.h
63211 +++ b/include/linux/i2o.h
63212 @@ -565,7 +565,7 @@ struct i2o_controller {
63213 struct i2o_device *exec; /* Executive */
63214 #if BITS_PER_LONG == 64
63215 spinlock_t context_list_lock; /* lock for context_list */
63216 - atomic_t context_list_counter; /* needed for unique contexts */
63217 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
63218 struct list_head context_list; /* list of context id's
63219 and pointers */
63220 #endif
63221 diff --git a/include/linux/if_team.h b/include/linux/if_team.h
63222 index aa2e167..84024ce 100644
63223 --- a/include/linux/if_team.h
63224 +++ b/include/linux/if_team.h
63225 @@ -109,6 +109,7 @@ struct team_mode_ops {
63226 void (*port_enabled)(struct team *team, struct team_port *port);
63227 void (*port_disabled)(struct team *team, struct team_port *port);
63228 };
63229 +typedef struct team_mode_ops __no_const team_mode_ops_no_const;
63230
63231 enum team_option_type {
63232 TEAM_OPTION_TYPE_U32,
63233 @@ -181,7 +182,7 @@ struct team {
63234 struct list_head option_inst_list; /* list of option instances */
63235
63236 const struct team_mode *mode;
63237 - struct team_mode_ops ops;
63238 + team_mode_ops_no_const ops;
63239 long mode_priv[TEAM_MODE_PRIV_LONGS];
63240 };
63241
63242 diff --git a/include/linux/init.h b/include/linux/init.h
63243 index 5e664f6..0a1225c 100644
63244 --- a/include/linux/init.h
63245 +++ b/include/linux/init.h
63246 @@ -39,9 +39,15 @@
63247 * Also note, that this data cannot be "const".
63248 */
63249
63250 +#ifdef MODULE
63251 +#define add_latent_entropy
63252 +#else
63253 +#define add_latent_entropy __latent_entropy
63254 +#endif
63255 +
63256 /* These are for everybody (although not all archs will actually
63257 discard it in modules) */
63258 -#define __init __section(.init.text) __cold notrace
63259 +#define __init __section(.init.text) __cold notrace add_latent_entropy
63260 #define __initdata __section(.init.data)
63261 #define __initconst __section(.init.rodata)
63262 #define __exitdata __section(.exit.data)
63263 @@ -83,7 +89,7 @@
63264 #define __exit __section(.exit.text) __exitused __cold notrace
63265
63266 /* Used for HOTPLUG */
63267 -#define __devinit __section(.devinit.text) __cold notrace
63268 +#define __devinit __section(.devinit.text) __cold notrace add_latent_entropy
63269 #define __devinitdata __section(.devinit.data)
63270 #define __devinitconst __section(.devinit.rodata)
63271 #define __devexit __section(.devexit.text) __exitused __cold notrace
63272 @@ -91,7 +97,7 @@
63273 #define __devexitconst __section(.devexit.rodata)
63274
63275 /* Used for HOTPLUG_CPU */
63276 -#define __cpuinit __section(.cpuinit.text) __cold notrace
63277 +#define __cpuinit __section(.cpuinit.text) __cold notrace add_latent_entropy
63278 #define __cpuinitdata __section(.cpuinit.data)
63279 #define __cpuinitconst __section(.cpuinit.rodata)
63280 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
63281 @@ -99,7 +105,7 @@
63282 #define __cpuexitconst __section(.cpuexit.rodata)
63283
63284 /* Used for MEMORY_HOTPLUG */
63285 -#define __meminit __section(.meminit.text) __cold notrace
63286 +#define __meminit __section(.meminit.text) __cold notrace add_latent_entropy
63287 #define __meminitdata __section(.meminit.data)
63288 #define __meminitconst __section(.meminit.rodata)
63289 #define __memexit __section(.memexit.text) __exitused __cold notrace
63290 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
63291 index 89f1cb1..7986c0f 100644
63292 --- a/include/linux/init_task.h
63293 +++ b/include/linux/init_task.h
63294 @@ -143,6 +143,12 @@ extern struct task_group root_task_group;
63295
63296 #define INIT_TASK_COMM "swapper"
63297
63298 +#ifdef CONFIG_X86
63299 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
63300 +#else
63301 +#define INIT_TASK_THREAD_INFO
63302 +#endif
63303 +
63304 /*
63305 * INIT_TASK is used to set up the first task table, touch at
63306 * your own risk!. Base=0, limit=0x1fffff (=2MB)
63307 @@ -182,6 +188,7 @@ extern struct task_group root_task_group;
63308 RCU_POINTER_INITIALIZER(cred, &init_cred), \
63309 .comm = INIT_TASK_COMM, \
63310 .thread = INIT_THREAD, \
63311 + INIT_TASK_THREAD_INFO \
63312 .fs = &init_fs, \
63313 .files = &init_files, \
63314 .signal = &init_signals, \
63315 diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
63316 index 78e2ada..745564d 100644
63317 --- a/include/linux/intel-iommu.h
63318 +++ b/include/linux/intel-iommu.h
63319 @@ -296,7 +296,7 @@ struct iommu_flush {
63320 u8 fm, u64 type);
63321 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
63322 unsigned int size_order, u64 type);
63323 -};
63324 +} __no_const;
63325
63326 enum {
63327 SR_DMAR_FECTL_REG,
63328 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
63329 index c5f856a..d29c117 100644
63330 --- a/include/linux/interrupt.h
63331 +++ b/include/linux/interrupt.h
63332 @@ -433,7 +433,7 @@ enum
63333 /* map softirq index to softirq name. update 'softirq_to_name' in
63334 * kernel/softirq.c when adding a new softirq.
63335 */
63336 -extern char *softirq_to_name[NR_SOFTIRQS];
63337 +extern const char * const softirq_to_name[NR_SOFTIRQS];
63338
63339 /* softirq mask and active fields moved to irq_cpustat_t in
63340 * asm/hardirq.h to get better cache usage. KAO
63341 @@ -441,12 +441,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
63342
63343 struct softirq_action
63344 {
63345 - void (*action)(struct softirq_action *);
63346 + void (*action)(void);
63347 };
63348
63349 asmlinkage void do_softirq(void);
63350 asmlinkage void __do_softirq(void);
63351 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
63352 +extern void open_softirq(int nr, void (*action)(void));
63353 extern void softirq_init(void);
63354 extern void __raise_softirq_irqoff(unsigned int nr);
63355
63356 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
63357 index 6883e19..06992b1 100644
63358 --- a/include/linux/kallsyms.h
63359 +++ b/include/linux/kallsyms.h
63360 @@ -15,7 +15,8 @@
63361
63362 struct module;
63363
63364 -#ifdef CONFIG_KALLSYMS
63365 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
63366 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63367 /* Lookup the address for a symbol. Returns 0 if not found. */
63368 unsigned long kallsyms_lookup_name(const char *name);
63369
63370 @@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
63371 /* Stupid that this does nothing, but I didn't create this mess. */
63372 #define __print_symbol(fmt, addr)
63373 #endif /*CONFIG_KALLSYMS*/
63374 +#else /* when included by kallsyms.c, vsnprintf.c, or
63375 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
63376 +extern void __print_symbol(const char *fmt, unsigned long address);
63377 +extern int sprint_backtrace(char *buffer, unsigned long address);
63378 +extern int sprint_symbol(char *buffer, unsigned long address);
63379 +extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
63380 +const char *kallsyms_lookup(unsigned long addr,
63381 + unsigned long *symbolsize,
63382 + unsigned long *offset,
63383 + char **modname, char *namebuf);
63384 +#endif
63385
63386 /* This macro allows us to keep printk typechecking */
63387 static __printf(1, 2)
63388 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
63389 index c4d2fc1..5df9c19 100644
63390 --- a/include/linux/kgdb.h
63391 +++ b/include/linux/kgdb.h
63392 @@ -53,7 +53,7 @@ extern int kgdb_connected;
63393 extern int kgdb_io_module_registered;
63394
63395 extern atomic_t kgdb_setting_breakpoint;
63396 -extern atomic_t kgdb_cpu_doing_single_step;
63397 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
63398
63399 extern struct task_struct *kgdb_usethread;
63400 extern struct task_struct *kgdb_contthread;
63401 @@ -252,7 +252,7 @@ struct kgdb_arch {
63402 void (*disable_hw_break)(struct pt_regs *regs);
63403 void (*remove_all_hw_break)(void);
63404 void (*correct_hw_break)(void);
63405 -};
63406 +} __do_const;
63407
63408 /**
63409 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
63410 @@ -277,7 +277,7 @@ struct kgdb_io {
63411 void (*pre_exception) (void);
63412 void (*post_exception) (void);
63413 int is_console;
63414 -};
63415 +} __do_const;
63416
63417 extern struct kgdb_arch arch_kgdb_ops;
63418
63419 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
63420 index 5398d58..5883a34 100644
63421 --- a/include/linux/kmod.h
63422 +++ b/include/linux/kmod.h
63423 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
63424 * usually useless though. */
63425 extern __printf(2, 3)
63426 int __request_module(bool wait, const char *name, ...);
63427 +extern __printf(3, 4)
63428 +int ___request_module(bool wait, char *param_name, const char *name, ...);
63429 #define request_module(mod...) __request_module(true, mod)
63430 #define request_module_nowait(mod...) __request_module(false, mod)
63431 #define try_then_request_module(x, mod...) \
63432 diff --git a/include/linux/kref.h b/include/linux/kref.h
63433 index 65af688..0592677 100644
63434 --- a/include/linux/kref.h
63435 +++ b/include/linux/kref.h
63436 @@ -64,7 +64,7 @@ static inline void kref_get(struct kref *kref)
63437 static inline int kref_sub(struct kref *kref, unsigned int count,
63438 void (*release)(struct kref *kref))
63439 {
63440 - WARN_ON(release == NULL);
63441 + BUG_ON(release == NULL);
63442
63443 if (atomic_sub_and_test((int) count, &kref->refcount)) {
63444 release(kref);
63445 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
63446 index b70b48b..0d7153b 100644
63447 --- a/include/linux/kvm_host.h
63448 +++ b/include/linux/kvm_host.h
63449 @@ -351,7 +351,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
63450 void vcpu_load(struct kvm_vcpu *vcpu);
63451 void vcpu_put(struct kvm_vcpu *vcpu);
63452
63453 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
63454 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
63455 struct module *module);
63456 void kvm_exit(void);
63457
63458 @@ -517,7 +517,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
63459 struct kvm_guest_debug *dbg);
63460 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
63461
63462 -int kvm_arch_init(void *opaque);
63463 +int kvm_arch_init(const void *opaque);
63464 void kvm_arch_exit(void);
63465
63466 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
63467 diff --git a/include/linux/libata.h b/include/linux/libata.h
63468 index 64f90e1..32b945b 100644
63469 --- a/include/linux/libata.h
63470 +++ b/include/linux/libata.h
63471 @@ -909,7 +909,7 @@ struct ata_port_operations {
63472 * fields must be pointers.
63473 */
63474 const struct ata_port_operations *inherits;
63475 -};
63476 +} __do_const;
63477
63478 struct ata_port_info {
63479 unsigned long flags;
63480 diff --git a/include/linux/memory.h b/include/linux/memory.h
63481 index ff9a9f8..c715deb 100644
63482 --- a/include/linux/memory.h
63483 +++ b/include/linux/memory.h
63484 @@ -143,7 +143,7 @@ struct memory_accessor {
63485 size_t count);
63486 ssize_t (*write)(struct memory_accessor *, const char *buf,
63487 off_t offset, size_t count);
63488 -};
63489 +} __no_const;
63490
63491 /*
63492 * Kernel text modification mutex, used for code patching. Users of this lock
63493 diff --git a/include/linux/mfd/abx500.h b/include/linux/mfd/abx500.h
63494 index 1318ca6..7521340 100644
63495 --- a/include/linux/mfd/abx500.h
63496 +++ b/include/linux/mfd/abx500.h
63497 @@ -452,6 +452,7 @@ struct abx500_ops {
63498 int (*event_registers_startup_state_get) (struct device *, u8 *);
63499 int (*startup_irq_enabled) (struct device *, unsigned int);
63500 };
63501 +typedef struct abx500_ops __no_const abx500_ops_no_const;
63502
63503 int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
63504 void abx500_remove_ops(struct device *dev);
63505 diff --git a/include/linux/mfd/abx500/ux500_chargalg.h b/include/linux/mfd/abx500/ux500_chargalg.h
63506 index 9b07725..3d55001 100644
63507 --- a/include/linux/mfd/abx500/ux500_chargalg.h
63508 +++ b/include/linux/mfd/abx500/ux500_chargalg.h
63509 @@ -19,7 +19,7 @@ struct ux500_charger_ops {
63510 int (*enable) (struct ux500_charger *, int, int, int);
63511 int (*kick_wd) (struct ux500_charger *);
63512 int (*update_curr) (struct ux500_charger *, int);
63513 -};
63514 +} __no_const;
63515
63516 /**
63517 * struct ux500_charger - power supply ux500 charger sub class
63518 diff --git a/include/linux/mm.h b/include/linux/mm.h
63519 index 311be90..5f1638c 100644
63520 --- a/include/linux/mm.h
63521 +++ b/include/linux/mm.h
63522 @@ -116,7 +116,14 @@ extern unsigned int kobjsize(const void *objp);
63523
63524 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
63525 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
63526 +
63527 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
63528 +#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
63529 +#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
63530 +#else
63531 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
63532 +#endif
63533 +
63534 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
63535 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
63536
63537 @@ -1038,34 +1045,6 @@ int set_page_dirty(struct page *page);
63538 int set_page_dirty_lock(struct page *page);
63539 int clear_page_dirty_for_io(struct page *page);
63540
63541 -/* Is the vma a continuation of the stack vma above it? */
63542 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
63543 -{
63544 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
63545 -}
63546 -
63547 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
63548 - unsigned long addr)
63549 -{
63550 - return (vma->vm_flags & VM_GROWSDOWN) &&
63551 - (vma->vm_start == addr) &&
63552 - !vma_growsdown(vma->vm_prev, addr);
63553 -}
63554 -
63555 -/* Is the vma a continuation of the stack vma below it? */
63556 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
63557 -{
63558 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
63559 -}
63560 -
63561 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
63562 - unsigned long addr)
63563 -{
63564 - return (vma->vm_flags & VM_GROWSUP) &&
63565 - (vma->vm_end == addr) &&
63566 - !vma_growsup(vma->vm_next, addr);
63567 -}
63568 -
63569 extern pid_t
63570 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
63571
63572 @@ -1164,6 +1143,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
63573 }
63574 #endif
63575
63576 +#ifdef CONFIG_MMU
63577 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
63578 +#else
63579 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
63580 +{
63581 + return __pgprot(0);
63582 +}
63583 +#endif
63584 +
63585 int vma_wants_writenotify(struct vm_area_struct *vma);
63586
63587 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
63588 @@ -1182,8 +1170,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
63589 {
63590 return 0;
63591 }
63592 +
63593 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
63594 + unsigned long address)
63595 +{
63596 + return 0;
63597 +}
63598 #else
63599 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
63600 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
63601 #endif
63602
63603 #ifdef __PAGETABLE_PMD_FOLDED
63604 @@ -1192,8 +1187,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
63605 {
63606 return 0;
63607 }
63608 +
63609 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
63610 + unsigned long address)
63611 +{
63612 + return 0;
63613 +}
63614 #else
63615 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
63616 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
63617 #endif
63618
63619 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
63620 @@ -1211,11 +1213,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
63621 NULL: pud_offset(pgd, address);
63622 }
63623
63624 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
63625 +{
63626 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
63627 + NULL: pud_offset(pgd, address);
63628 +}
63629 +
63630 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
63631 {
63632 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
63633 NULL: pmd_offset(pud, address);
63634 }
63635 +
63636 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
63637 +{
63638 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
63639 + NULL: pmd_offset(pud, address);
63640 +}
63641 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
63642
63643 #if USE_SPLIT_PTLOCKS
63644 @@ -1426,6 +1440,7 @@ extern unsigned long do_mmap_pgoff(struct file *, unsigned long,
63645 unsigned long, unsigned long,
63646 unsigned long, unsigned long);
63647 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
63648 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
63649
63650 /* These take the mm semaphore themselves */
63651 extern unsigned long vm_brk(unsigned long, unsigned long);
63652 @@ -1489,6 +1504,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
63653 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
63654 struct vm_area_struct **pprev);
63655
63656 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
63657 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
63658 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
63659 +
63660 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
63661 NULL if none. Assume start_addr < end_addr. */
63662 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
63663 @@ -1517,15 +1536,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
63664 return vma;
63665 }
63666
63667 -#ifdef CONFIG_MMU
63668 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
63669 -#else
63670 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
63671 -{
63672 - return __pgprot(0);
63673 -}
63674 -#endif
63675 -
63676 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
63677 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
63678 unsigned long pfn, unsigned long size, pgprot_t);
63679 @@ -1631,7 +1641,7 @@ extern int unpoison_memory(unsigned long pfn);
63680 extern int sysctl_memory_failure_early_kill;
63681 extern int sysctl_memory_failure_recovery;
63682 extern void shake_page(struct page *p, int access);
63683 -extern atomic_long_t mce_bad_pages;
63684 +extern atomic_long_unchecked_t mce_bad_pages;
63685 extern int soft_offline_page(struct page *page, int flags);
63686
63687 extern void dump_page(struct page *page);
63688 @@ -1662,5 +1672,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
63689 static inline bool page_is_guard(struct page *page) { return false; }
63690 #endif /* CONFIG_DEBUG_PAGEALLOC */
63691
63692 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
63693 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
63694 +#else
63695 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
63696 +#endif
63697 +
63698 #endif /* __KERNEL__ */
63699 #endif /* _LINUX_MM_H */
63700 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
63701 index bf78672..debc693 100644
63702 --- a/include/linux/mm_types.h
63703 +++ b/include/linux/mm_types.h
63704 @@ -279,6 +279,8 @@ struct vm_area_struct {
63705 #ifdef CONFIG_NUMA
63706 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
63707 #endif
63708 +
63709 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
63710 };
63711
63712 struct core_thread {
63713 @@ -353,7 +355,7 @@ struct mm_struct {
63714 unsigned long def_flags;
63715 unsigned long nr_ptes; /* Page table pages */
63716 unsigned long start_code, end_code, start_data, end_data;
63717 - unsigned long start_brk, brk, start_stack;
63718 + unsigned long brk_gap, start_brk, brk, start_stack;
63719 unsigned long arg_start, arg_end, env_start, env_end;
63720
63721 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
63722 @@ -405,6 +407,24 @@ struct mm_struct {
63723 struct cpumask cpumask_allocation;
63724 #endif
63725 struct uprobes_state uprobes_state;
63726 +
63727 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63728 + unsigned long pax_flags;
63729 +#endif
63730 +
63731 +#ifdef CONFIG_PAX_DLRESOLVE
63732 + unsigned long call_dl_resolve;
63733 +#endif
63734 +
63735 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
63736 + unsigned long call_syscall;
63737 +#endif
63738 +
63739 +#ifdef CONFIG_PAX_ASLR
63740 + unsigned long delta_mmap; /* randomized offset */
63741 + unsigned long delta_stack; /* randomized offset */
63742 +#endif
63743 +
63744 };
63745
63746 static inline void mm_init_cpumask(struct mm_struct *mm)
63747 diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h
63748 index 1d1b1e1..2a13c78 100644
63749 --- a/include/linux/mmu_notifier.h
63750 +++ b/include/linux/mmu_notifier.h
63751 @@ -255,12 +255,12 @@ static inline void mmu_notifier_mm_destroy(struct mm_struct *mm)
63752 */
63753 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
63754 ({ \
63755 - pte_t __pte; \
63756 + pte_t ___pte; \
63757 struct vm_area_struct *___vma = __vma; \
63758 unsigned long ___address = __address; \
63759 - __pte = ptep_clear_flush(___vma, ___address, __ptep); \
63760 + ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
63761 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
63762 - __pte; \
63763 + ___pte; \
63764 })
63765
63766 #define pmdp_clear_flush_notify(__vma, __address, __pmdp) \
63767 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
63768 index 2daa54f..bfdf2f5 100644
63769 --- a/include/linux/mmzone.h
63770 +++ b/include/linux/mmzone.h
63771 @@ -414,7 +414,7 @@ struct zone {
63772 unsigned long flags; /* zone flags, see below */
63773
63774 /* Zone statistics */
63775 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63776 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63777
63778 /*
63779 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
63780 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
63781 index 6955045..ebdb7cd 100644
63782 --- a/include/linux/mod_devicetable.h
63783 +++ b/include/linux/mod_devicetable.h
63784 @@ -12,7 +12,7 @@
63785 typedef unsigned long kernel_ulong_t;
63786 #endif
63787
63788 -#define PCI_ANY_ID (~0)
63789 +#define PCI_ANY_ID ((__u16)~0)
63790
63791 struct pci_device_id {
63792 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
63793 @@ -139,7 +139,7 @@ struct usb_device_id {
63794 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
63795 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
63796
63797 -#define HID_ANY_ID (~0)
63798 +#define HID_ANY_ID (~0U)
63799 #define HID_BUS_ANY 0xffff
63800 #define HID_GROUP_ANY 0x0000
63801
63802 diff --git a/include/linux/module.h b/include/linux/module.h
63803 index fbcafe2..e5d9587 100644
63804 --- a/include/linux/module.h
63805 +++ b/include/linux/module.h
63806 @@ -17,6 +17,7 @@
63807 #include <linux/moduleparam.h>
63808 #include <linux/tracepoint.h>
63809 #include <linux/export.h>
63810 +#include <linux/fs.h>
63811
63812 #include <linux/percpu.h>
63813 #include <asm/module.h>
63814 @@ -273,19 +274,16 @@ struct module
63815 int (*init)(void);
63816
63817 /* If this is non-NULL, vfree after init() returns */
63818 - void *module_init;
63819 + void *module_init_rx, *module_init_rw;
63820
63821 /* Here is the actual code + data, vfree'd on unload. */
63822 - void *module_core;
63823 + void *module_core_rx, *module_core_rw;
63824
63825 /* Here are the sizes of the init and core sections */
63826 - unsigned int init_size, core_size;
63827 + unsigned int init_size_rw, core_size_rw;
63828
63829 /* The size of the executable code in each section. */
63830 - unsigned int init_text_size, core_text_size;
63831 -
63832 - /* Size of RO sections of the module (text+rodata) */
63833 - unsigned int init_ro_size, core_ro_size;
63834 + unsigned int init_size_rx, core_size_rx;
63835
63836 /* Arch-specific module values */
63837 struct mod_arch_specific arch;
63838 @@ -341,6 +339,10 @@ struct module
63839 #ifdef CONFIG_EVENT_TRACING
63840 struct ftrace_event_call **trace_events;
63841 unsigned int num_trace_events;
63842 + struct file_operations trace_id;
63843 + struct file_operations trace_enable;
63844 + struct file_operations trace_format;
63845 + struct file_operations trace_filter;
63846 #endif
63847 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
63848 unsigned int num_ftrace_callsites;
63849 @@ -388,16 +390,46 @@ bool is_module_address(unsigned long addr);
63850 bool is_module_percpu_address(unsigned long addr);
63851 bool is_module_text_address(unsigned long addr);
63852
63853 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
63854 +{
63855 +
63856 +#ifdef CONFIG_PAX_KERNEXEC
63857 + if (ktla_ktva(addr) >= (unsigned long)start &&
63858 + ktla_ktva(addr) < (unsigned long)start + size)
63859 + return 1;
63860 +#endif
63861 +
63862 + return ((void *)addr >= start && (void *)addr < start + size);
63863 +}
63864 +
63865 +static inline int within_module_core_rx(unsigned long addr, struct module *mod)
63866 +{
63867 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
63868 +}
63869 +
63870 +static inline int within_module_core_rw(unsigned long addr, struct module *mod)
63871 +{
63872 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
63873 +}
63874 +
63875 +static inline int within_module_init_rx(unsigned long addr, struct module *mod)
63876 +{
63877 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
63878 +}
63879 +
63880 +static inline int within_module_init_rw(unsigned long addr, struct module *mod)
63881 +{
63882 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
63883 +}
63884 +
63885 static inline int within_module_core(unsigned long addr, struct module *mod)
63886 {
63887 - return (unsigned long)mod->module_core <= addr &&
63888 - addr < (unsigned long)mod->module_core + mod->core_size;
63889 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
63890 }
63891
63892 static inline int within_module_init(unsigned long addr, struct module *mod)
63893 {
63894 - return (unsigned long)mod->module_init <= addr &&
63895 - addr < (unsigned long)mod->module_init + mod->init_size;
63896 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
63897 }
63898
63899 /* Search for module by name: must hold module_mutex. */
63900 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
63901 index b2be02e..72d2f78 100644
63902 --- a/include/linux/moduleloader.h
63903 +++ b/include/linux/moduleloader.h
63904 @@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
63905
63906 /* Allocator used for allocating struct module, core sections and init
63907 sections. Returns NULL on failure. */
63908 -void *module_alloc(unsigned long size);
63909 +void *module_alloc(unsigned long size) __size_overflow(1);
63910 +
63911 +#ifdef CONFIG_PAX_KERNEXEC
63912 +void *module_alloc_exec(unsigned long size) __size_overflow(1);
63913 +#else
63914 +#define module_alloc_exec(x) module_alloc(x)
63915 +#endif
63916
63917 /* Free memory returned from module_alloc. */
63918 void module_free(struct module *mod, void *module_region);
63919
63920 +#ifdef CONFIG_PAX_KERNEXEC
63921 +void module_free_exec(struct module *mod, void *module_region);
63922 +#else
63923 +#define module_free_exec(x, y) module_free((x), (y))
63924 +#endif
63925 +
63926 /* Apply the given relocation to the (simplified) ELF. Return -error
63927 or 0. */
63928 int apply_relocate(Elf_Shdr *sechdrs,
63929 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
63930 index d6a5806..7c13347 100644
63931 --- a/include/linux/moduleparam.h
63932 +++ b/include/linux/moduleparam.h
63933 @@ -286,7 +286,7 @@ static inline void __kernel_param_unlock(void)
63934 * @len is usually just sizeof(string).
63935 */
63936 #define module_param_string(name, string, len, perm) \
63937 - static const struct kparam_string __param_string_##name \
63938 + static const struct kparam_string __param_string_##name __used \
63939 = { len, string }; \
63940 __module_param_call(MODULE_PARAM_PREFIX, name, \
63941 &param_ops_string, \
63942 @@ -425,7 +425,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
63943 */
63944 #define module_param_array_named(name, array, type, nump, perm) \
63945 param_check_##type(name, &(array)[0]); \
63946 - static const struct kparam_array __param_arr_##name \
63947 + static const struct kparam_array __param_arr_##name __used \
63948 = { .max = ARRAY_SIZE(array), .num = nump, \
63949 .ops = &param_ops_##type, \
63950 .elemsize = sizeof(array[0]), .elem = array }; \
63951 diff --git a/include/linux/namei.h b/include/linux/namei.h
63952 index 4bf19d8..5268cea 100644
63953 --- a/include/linux/namei.h
63954 +++ b/include/linux/namei.h
63955 @@ -18,7 +18,7 @@ struct nameidata {
63956 unsigned seq;
63957 int last_type;
63958 unsigned depth;
63959 - char *saved_names[MAX_NESTED_LINKS + 1];
63960 + const char *saved_names[MAX_NESTED_LINKS + 1];
63961 };
63962
63963 /*
63964 @@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
63965
63966 extern void nd_jump_link(struct nameidata *nd, struct path *path);
63967
63968 -static inline void nd_set_link(struct nameidata *nd, char *path)
63969 +static inline void nd_set_link(struct nameidata *nd, const char *path)
63970 {
63971 nd->saved_names[nd->depth] = path;
63972 }
63973
63974 -static inline char *nd_get_link(struct nameidata *nd)
63975 +static inline const char *nd_get_link(const struct nameidata *nd)
63976 {
63977 return nd->saved_names[nd->depth];
63978 }
63979 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
63980 index 59dc05f3..c905a34 100644
63981 --- a/include/linux/netdevice.h
63982 +++ b/include/linux/netdevice.h
63983 @@ -1027,6 +1027,7 @@ struct net_device_ops {
63984 struct net_device *dev,
63985 int idx);
63986 };
63987 +typedef struct net_device_ops __no_const net_device_ops_no_const;
63988
63989 /*
63990 * The DEVICE structure.
63991 @@ -1087,7 +1088,7 @@ struct net_device {
63992 int iflink;
63993
63994 struct net_device_stats stats;
63995 - atomic_long_t rx_dropped; /* dropped packets by core network
63996 + atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
63997 * Do not use this in drivers.
63998 */
63999
64000 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
64001 new file mode 100644
64002 index 0000000..33f4af8
64003 --- /dev/null
64004 +++ b/include/linux/netfilter/xt_gradm.h
64005 @@ -0,0 +1,9 @@
64006 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
64007 +#define _LINUX_NETFILTER_XT_GRADM_H 1
64008 +
64009 +struct xt_gradm_mtinfo {
64010 + __u16 flags;
64011 + __u16 invflags;
64012 +};
64013 +
64014 +#endif
64015 diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
64016 index c65a18a..0c05f3a 100644
64017 --- a/include/linux/of_pdt.h
64018 +++ b/include/linux/of_pdt.h
64019 @@ -32,7 +32,7 @@ struct of_pdt_ops {
64020
64021 /* return 0 on success; fill in 'len' with number of bytes in path */
64022 int (*pkg2path)(phandle node, char *buf, const int buflen, int *len);
64023 -};
64024 +} __no_const;
64025
64026 extern void *prom_early_alloc(unsigned long size);
64027
64028 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
64029 index a4c5624..79d6d88 100644
64030 --- a/include/linux/oprofile.h
64031 +++ b/include/linux/oprofile.h
64032 @@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
64033 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
64034 char const * name, ulong * val);
64035
64036 -/** Create a file for read-only access to an atomic_t. */
64037 +/** Create a file for read-only access to an atomic_unchecked_t. */
64038 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
64039 - char const * name, atomic_t * val);
64040 + char const * name, atomic_unchecked_t * val);
64041
64042 /** create a directory */
64043 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
64044 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
64045 index bdb4161..f373d41 100644
64046 --- a/include/linux/perf_event.h
64047 +++ b/include/linux/perf_event.h
64048 @@ -882,8 +882,8 @@ struct perf_event {
64049
64050 enum perf_event_active_state state;
64051 unsigned int attach_state;
64052 - local64_t count;
64053 - atomic64_t child_count;
64054 + local64_t count; /* PaX: fix it one day */
64055 + atomic64_unchecked_t child_count;
64056
64057 /*
64058 * These are the total time in nanoseconds that the event
64059 @@ -934,8 +934,8 @@ struct perf_event {
64060 * These accumulate total time (in nanoseconds) that children
64061 * events have been enabled and running, respectively.
64062 */
64063 - atomic64_t child_total_time_enabled;
64064 - atomic64_t child_total_time_running;
64065 + atomic64_unchecked_t child_total_time_enabled;
64066 + atomic64_unchecked_t child_total_time_running;
64067
64068 /*
64069 * Protect attach/detach and child_list:
64070 diff --git a/include/linux/personality.h b/include/linux/personality.h
64071 index 8fc7dd1a..c19d89e 100644
64072 --- a/include/linux/personality.h
64073 +++ b/include/linux/personality.h
64074 @@ -44,6 +44,7 @@ enum {
64075 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
64076 ADDR_NO_RANDOMIZE | \
64077 ADDR_COMPAT_LAYOUT | \
64078 + ADDR_LIMIT_3GB | \
64079 MMAP_PAGE_ZERO)
64080
64081 /*
64082 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
64083 index ad1a427..6419649 100644
64084 --- a/include/linux/pipe_fs_i.h
64085 +++ b/include/linux/pipe_fs_i.h
64086 @@ -45,9 +45,9 @@ struct pipe_buffer {
64087 struct pipe_inode_info {
64088 wait_queue_head_t wait;
64089 unsigned int nrbufs, curbuf, buffers;
64090 - unsigned int readers;
64091 - unsigned int writers;
64092 - unsigned int waiting_writers;
64093 + atomic_t readers;
64094 + atomic_t writers;
64095 + atomic_t waiting_writers;
64096 unsigned int r_counter;
64097 unsigned int w_counter;
64098 struct page *tmp_page;
64099 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
64100 index f271860..6b3bec5 100644
64101 --- a/include/linux/pm_runtime.h
64102 +++ b/include/linux/pm_runtime.h
64103 @@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
64104
64105 static inline void pm_runtime_mark_last_busy(struct device *dev)
64106 {
64107 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
64108 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
64109 }
64110
64111 #else /* !CONFIG_PM_RUNTIME */
64112 diff --git a/include/linux/poison.h b/include/linux/poison.h
64113 index 2110a81..13a11bb 100644
64114 --- a/include/linux/poison.h
64115 +++ b/include/linux/poison.h
64116 @@ -19,8 +19,8 @@
64117 * under normal circumstances, used to verify that nobody uses
64118 * non-initialized list entries.
64119 */
64120 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
64121 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
64122 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
64123 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
64124
64125 /********** include/linux/timer.h **********/
64126 /*
64127 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
64128 index 5a710b9..0b0dab9 100644
64129 --- a/include/linux/preempt.h
64130 +++ b/include/linux/preempt.h
64131 @@ -126,7 +126,7 @@ struct preempt_ops {
64132 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
64133 void (*sched_out)(struct preempt_notifier *notifier,
64134 struct task_struct *next);
64135 -};
64136 +} __no_const;
64137
64138 /**
64139 * preempt_notifier - key for installing preemption notifiers
64140 diff --git a/include/linux/printk.h b/include/linux/printk.h
64141 index 9afc01e..92c32e8 100644
64142 --- a/include/linux/printk.h
64143 +++ b/include/linux/printk.h
64144 @@ -101,6 +101,8 @@ void early_printk(const char *fmt, ...);
64145 extern int printk_needs_cpu(int cpu);
64146 extern void printk_tick(void);
64147
64148 +extern int kptr_restrict;
64149 +
64150 #ifdef CONFIG_PRINTK
64151 asmlinkage __printf(5, 0)
64152 int vprintk_emit(int facility, int level,
64153 @@ -135,7 +137,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
64154
64155 extern int printk_delay_msec;
64156 extern int dmesg_restrict;
64157 -extern int kptr_restrict;
64158
64159 void log_buf_kexec_setup(void);
64160 void __init setup_log_buf(int early);
64161 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
64162 index 3fd2e87..d93a721 100644
64163 --- a/include/linux/proc_fs.h
64164 +++ b/include/linux/proc_fs.h
64165 @@ -155,6 +155,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
64166 return proc_create_data(name, mode, parent, proc_fops, NULL);
64167 }
64168
64169 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
64170 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
64171 +{
64172 +#ifdef CONFIG_GRKERNSEC_PROC_USER
64173 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
64174 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64175 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
64176 +#else
64177 + return proc_create_data(name, mode, parent, proc_fops, NULL);
64178 +#endif
64179 +}
64180 +
64181 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
64182 umode_t mode, struct proc_dir_entry *base,
64183 read_proc_t *read_proc, void * data)
64184 @@ -258,7 +270,7 @@ union proc_op {
64185 int (*proc_show)(struct seq_file *m,
64186 struct pid_namespace *ns, struct pid *pid,
64187 struct task_struct *task);
64188 -};
64189 +} __no_const;
64190
64191 struct ctl_table_header;
64192 struct ctl_table;
64193 diff --git a/include/linux/random.h b/include/linux/random.h
64194 index ac621ce..c1215f3 100644
64195 --- a/include/linux/random.h
64196 +++ b/include/linux/random.h
64197 @@ -53,6 +53,10 @@ extern void add_input_randomness(unsigned int type, unsigned int code,
64198 unsigned int value);
64199 extern void add_interrupt_randomness(int irq, int irq_flags);
64200
64201 +#ifdef CONFIG_PAX_LATENT_ENTROPY
64202 +extern void transfer_latent_entropy(void);
64203 +#endif
64204 +
64205 extern void get_random_bytes(void *buf, int nbytes);
64206 extern void get_random_bytes_arch(void *buf, int nbytes);
64207 void generate_random_uuid(unsigned char uuid_out[16]);
64208 @@ -69,12 +73,17 @@ void srandom32(u32 seed);
64209
64210 u32 prandom32(struct rnd_state *);
64211
64212 +static inline unsigned long pax_get_random_long(void)
64213 +{
64214 + return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
64215 +}
64216 +
64217 /*
64218 * Handle minimum values for seeds
64219 */
64220 static inline u32 __seed(u32 x, u32 m)
64221 {
64222 - return (x < m) ? x + m : x;
64223 + return (x <= m) ? x + m + 1 : x;
64224 }
64225
64226 /**
64227 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
64228 index e0879a7..a12f962 100644
64229 --- a/include/linux/reboot.h
64230 +++ b/include/linux/reboot.h
64231 @@ -52,9 +52,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
64232 * Architecture-specific implementations of sys_reboot commands.
64233 */
64234
64235 -extern void machine_restart(char *cmd);
64236 -extern void machine_halt(void);
64237 -extern void machine_power_off(void);
64238 +extern void machine_restart(char *cmd) __noreturn;
64239 +extern void machine_halt(void) __noreturn;
64240 +extern void machine_power_off(void) __noreturn;
64241
64242 extern void machine_shutdown(void);
64243 struct pt_regs;
64244 @@ -65,9 +65,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
64245 */
64246
64247 extern void kernel_restart_prepare(char *cmd);
64248 -extern void kernel_restart(char *cmd);
64249 -extern void kernel_halt(void);
64250 -extern void kernel_power_off(void);
64251 +extern void kernel_restart(char *cmd) __noreturn;
64252 +extern void kernel_halt(void) __noreturn;
64253 +extern void kernel_power_off(void) __noreturn;
64254
64255 extern int C_A_D; /* for sysctl */
64256 void ctrl_alt_del(void);
64257 @@ -81,7 +81,7 @@ extern int orderly_poweroff(bool force);
64258 * Emergency restart, callable from an interrupt handler.
64259 */
64260
64261 -extern void emergency_restart(void);
64262 +extern void emergency_restart(void) __noreturn;
64263 #include <asm/emergency-restart.h>
64264
64265 #endif
64266 diff --git a/include/linux/relay.h b/include/linux/relay.h
64267 index 91cacc3..b55ff74 100644
64268 --- a/include/linux/relay.h
64269 +++ b/include/linux/relay.h
64270 @@ -160,7 +160,7 @@ struct rchan_callbacks
64271 * The callback should return 0 if successful, negative if not.
64272 */
64273 int (*remove_buf_file)(struct dentry *dentry);
64274 -};
64275 +} __no_const;
64276
64277 /*
64278 * CONFIG_RELAY kernel API, kernel/relay.c
64279 diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
64280 index 6fdf027..ff72610 100644
64281 --- a/include/linux/rfkill.h
64282 +++ b/include/linux/rfkill.h
64283 @@ -147,6 +147,7 @@ struct rfkill_ops {
64284 void (*query)(struct rfkill *rfkill, void *data);
64285 int (*set_block)(void *data, bool blocked);
64286 };
64287 +typedef struct rfkill_ops __no_const rfkill_ops_no_const;
64288
64289 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
64290 /**
64291 diff --git a/include/linux/rio.h b/include/linux/rio.h
64292 index a90ebad..fd87b5d 100644
64293 --- a/include/linux/rio.h
64294 +++ b/include/linux/rio.h
64295 @@ -321,7 +321,7 @@ struct rio_ops {
64296 int mbox, void *buffer, size_t len);
64297 int (*add_inb_buffer)(struct rio_mport *mport, int mbox, void *buf);
64298 void *(*get_inb_message)(struct rio_mport *mport, int mbox);
64299 -};
64300 +} __no_const;
64301
64302 #define RIO_RESOURCE_MEM 0x00000100
64303 #define RIO_RESOURCE_DOORBELL 0x00000200
64304 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
64305 index 3fce545..b4fed6e 100644
64306 --- a/include/linux/rmap.h
64307 +++ b/include/linux/rmap.h
64308 @@ -119,9 +119,9 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
64309 void anon_vma_init(void); /* create anon_vma_cachep */
64310 int anon_vma_prepare(struct vm_area_struct *);
64311 void unlink_anon_vmas(struct vm_area_struct *);
64312 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
64313 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
64314 void anon_vma_moveto_tail(struct vm_area_struct *);
64315 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
64316 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
64317
64318 static inline void anon_vma_merge(struct vm_area_struct *vma,
64319 struct vm_area_struct *next)
64320 diff --git a/include/linux/sched.h b/include/linux/sched.h
64321 index 23bddac..5976055 100644
64322 --- a/include/linux/sched.h
64323 +++ b/include/linux/sched.h
64324 @@ -101,6 +101,7 @@ struct bio_list;
64325 struct fs_struct;
64326 struct perf_event_context;
64327 struct blk_plug;
64328 +struct linux_binprm;
64329
64330 /*
64331 * List of flags we want to share for kernel threads,
64332 @@ -384,10 +385,13 @@ struct user_namespace;
64333 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
64334
64335 extern int sysctl_max_map_count;
64336 +extern unsigned long sysctl_heap_stack_gap;
64337
64338 #include <linux/aio.h>
64339
64340 #ifdef CONFIG_MMU
64341 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
64342 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
64343 extern void arch_pick_mmap_layout(struct mm_struct *mm);
64344 extern unsigned long
64345 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
64346 @@ -651,6 +655,17 @@ struct signal_struct {
64347 #ifdef CONFIG_TASKSTATS
64348 struct taskstats *stats;
64349 #endif
64350 +
64351 +#ifdef CONFIG_GRKERNSEC
64352 + u32 curr_ip;
64353 + u32 saved_ip;
64354 + u32 gr_saddr;
64355 + u32 gr_daddr;
64356 + u16 gr_sport;
64357 + u16 gr_dport;
64358 + u8 used_accept:1;
64359 +#endif
64360 +
64361 #ifdef CONFIG_AUDIT
64362 unsigned audit_tty;
64363 struct tty_audit_buf *tty_audit_buf;
64364 @@ -734,6 +749,11 @@ struct user_struct {
64365 struct key *session_keyring; /* UID's default session keyring */
64366 #endif
64367
64368 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
64369 + unsigned int banned;
64370 + unsigned long ban_expires;
64371 +#endif
64372 +
64373 /* Hash table maintenance information */
64374 struct hlist_node uidhash_node;
64375 kuid_t uid;
64376 @@ -1356,8 +1376,8 @@ struct task_struct {
64377 struct list_head thread_group;
64378
64379 struct completion *vfork_done; /* for vfork() */
64380 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
64381 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
64382 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
64383 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
64384
64385 cputime_t utime, stime, utimescaled, stimescaled;
64386 cputime_t gtime;
64387 @@ -1373,11 +1393,6 @@ struct task_struct {
64388 struct task_cputime cputime_expires;
64389 struct list_head cpu_timers[3];
64390
64391 -/* process credentials */
64392 - const struct cred __rcu *real_cred; /* objective and real subjective task
64393 - * credentials (COW) */
64394 - const struct cred __rcu *cred; /* effective (overridable) subjective task
64395 - * credentials (COW) */
64396 char comm[TASK_COMM_LEN]; /* executable name excluding path
64397 - access with [gs]et_task_comm (which lock
64398 it with task_lock())
64399 @@ -1394,6 +1409,10 @@ struct task_struct {
64400 #endif
64401 /* CPU-specific state of this task */
64402 struct thread_struct thread;
64403 +/* thread_info moved to task_struct */
64404 +#ifdef CONFIG_X86
64405 + struct thread_info tinfo;
64406 +#endif
64407 /* filesystem information */
64408 struct fs_struct *fs;
64409 /* open file information */
64410 @@ -1467,6 +1486,10 @@ struct task_struct {
64411 gfp_t lockdep_reclaim_gfp;
64412 #endif
64413
64414 +/* process credentials */
64415 + const struct cred __rcu *real_cred; /* objective and real subjective task
64416 + * credentials (COW) */
64417 +
64418 /* journalling filesystem info */
64419 void *journal_info;
64420
64421 @@ -1505,6 +1528,10 @@ struct task_struct {
64422 /* cg_list protected by css_set_lock and tsk->alloc_lock */
64423 struct list_head cg_list;
64424 #endif
64425 +
64426 + const struct cred __rcu *cred; /* effective (overridable) subjective task
64427 + * credentials (COW) */
64428 +
64429 #ifdef CONFIG_FUTEX
64430 struct robust_list_head __user *robust_list;
64431 #ifdef CONFIG_COMPAT
64432 @@ -1589,8 +1616,74 @@ struct task_struct {
64433 #ifdef CONFIG_UPROBES
64434 struct uprobe_task *utask;
64435 #endif
64436 +
64437 +#ifdef CONFIG_GRKERNSEC
64438 + /* grsecurity */
64439 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64440 + u64 exec_id;
64441 +#endif
64442 +#ifdef CONFIG_GRKERNSEC_SETXID
64443 + const struct cred *delayed_cred;
64444 +#endif
64445 + struct dentry *gr_chroot_dentry;
64446 + struct acl_subject_label *acl;
64447 + struct acl_role_label *role;
64448 + struct file *exec_file;
64449 + u16 acl_role_id;
64450 + /* is this the task that authenticated to the special role */
64451 + u8 acl_sp_role;
64452 + u8 is_writable;
64453 + u8 brute;
64454 + u8 gr_is_chrooted;
64455 +#endif
64456 +
64457 };
64458
64459 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
64460 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
64461 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
64462 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
64463 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
64464 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
64465 +
64466 +#ifdef CONFIG_PAX_SOFTMODE
64467 +extern int pax_softmode;
64468 +#endif
64469 +
64470 +extern int pax_check_flags(unsigned long *);
64471 +
64472 +/* if tsk != current then task_lock must be held on it */
64473 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
64474 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
64475 +{
64476 + if (likely(tsk->mm))
64477 + return tsk->mm->pax_flags;
64478 + else
64479 + return 0UL;
64480 +}
64481 +
64482 +/* if tsk != current then task_lock must be held on it */
64483 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
64484 +{
64485 + if (likely(tsk->mm)) {
64486 + tsk->mm->pax_flags = flags;
64487 + return 0;
64488 + }
64489 + return -EINVAL;
64490 +}
64491 +#endif
64492 +
64493 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
64494 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
64495 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
64496 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
64497 +#endif
64498 +
64499 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
64500 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
64501 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
64502 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
64503 +
64504 /* Future-safe accessor for struct task_struct's cpus_allowed. */
64505 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
64506
64507 @@ -2125,7 +2218,9 @@ void yield(void);
64508 extern struct exec_domain default_exec_domain;
64509
64510 union thread_union {
64511 +#ifndef CONFIG_X86
64512 struct thread_info thread_info;
64513 +#endif
64514 unsigned long stack[THREAD_SIZE/sizeof(long)];
64515 };
64516
64517 @@ -2158,6 +2253,7 @@ extern struct pid_namespace init_pid_ns;
64518 */
64519
64520 extern struct task_struct *find_task_by_vpid(pid_t nr);
64521 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
64522 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
64523 struct pid_namespace *ns);
64524
64525 @@ -2314,7 +2410,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
64526 extern void exit_itimers(struct signal_struct *);
64527 extern void flush_itimer_signals(void);
64528
64529 -extern void do_group_exit(int);
64530 +extern __noreturn void do_group_exit(int);
64531
64532 extern void daemonize(const char *, ...);
64533 extern int allow_signal(int);
64534 @@ -2515,9 +2611,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
64535
64536 #endif
64537
64538 -static inline int object_is_on_stack(void *obj)
64539 +static inline int object_starts_on_stack(void *obj)
64540 {
64541 - void *stack = task_stack_page(current);
64542 + const void *stack = task_stack_page(current);
64543
64544 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
64545 }
64546 diff --git a/include/linux/screen_info.h b/include/linux/screen_info.h
64547 index 899fbb4..1cb4138 100644
64548 --- a/include/linux/screen_info.h
64549 +++ b/include/linux/screen_info.h
64550 @@ -43,7 +43,8 @@ struct screen_info {
64551 __u16 pages; /* 0x32 */
64552 __u16 vesa_attributes; /* 0x34 */
64553 __u32 capabilities; /* 0x36 */
64554 - __u8 _reserved[6]; /* 0x3a */
64555 + __u16 vesapm_size; /* 0x3a */
64556 + __u8 _reserved[4]; /* 0x3c */
64557 } __attribute__((packed));
64558
64559 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
64560 diff --git a/include/linux/security.h b/include/linux/security.h
64561 index d143b8e..9f27b95 100644
64562 --- a/include/linux/security.h
64563 +++ b/include/linux/security.h
64564 @@ -26,6 +26,7 @@
64565 #include <linux/capability.h>
64566 #include <linux/slab.h>
64567 #include <linux/err.h>
64568 +#include <linux/grsecurity.h>
64569
64570 struct linux_binprm;
64571 struct cred;
64572 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
64573 index 83c44ee..e8a9eba 100644
64574 --- a/include/linux/seq_file.h
64575 +++ b/include/linux/seq_file.h
64576 @@ -25,6 +25,9 @@ struct seq_file {
64577 struct mutex lock;
64578 const struct seq_operations *op;
64579 int poll_event;
64580 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64581 + u64 exec_id;
64582 +#endif
64583 void *private;
64584 };
64585
64586 @@ -34,6 +37,7 @@ struct seq_operations {
64587 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
64588 int (*show) (struct seq_file *m, void *v);
64589 };
64590 +typedef struct seq_operations __no_const seq_operations_no_const;
64591
64592 #define SEQ_SKIP 1
64593
64594 diff --git a/include/linux/shm.h b/include/linux/shm.h
64595 index edd0868..f98feee 100644
64596 --- a/include/linux/shm.h
64597 +++ b/include/linux/shm.h
64598 @@ -98,6 +98,10 @@ struct shmid_kernel /* private to the kernel */
64599
64600 /* The task created the shm object. NULL if the task is dead. */
64601 struct task_struct *shm_creator;
64602 +#ifdef CONFIG_GRKERNSEC
64603 + time_t shm_createtime;
64604 + pid_t shm_lapid;
64605 +#endif
64606 };
64607
64608 /* shm_mode upper byte flags */
64609 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
64610 index f3165d2..2cb3cb7 100644
64611 --- a/include/linux/skbuff.h
64612 +++ b/include/linux/skbuff.h
64613 @@ -577,7 +577,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
64614 extern struct sk_buff *__alloc_skb(unsigned int size,
64615 gfp_t priority, int flags, int node);
64616 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
64617 -static inline struct sk_buff *alloc_skb(unsigned int size,
64618 +static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
64619 gfp_t priority)
64620 {
64621 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
64622 @@ -687,7 +687,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
64623 */
64624 static inline int skb_queue_empty(const struct sk_buff_head *list)
64625 {
64626 - return list->next == (struct sk_buff *)list;
64627 + return list->next == (const struct sk_buff *)list;
64628 }
64629
64630 /**
64631 @@ -700,7 +700,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
64632 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
64633 const struct sk_buff *skb)
64634 {
64635 - return skb->next == (struct sk_buff *)list;
64636 + return skb->next == (const struct sk_buff *)list;
64637 }
64638
64639 /**
64640 @@ -713,7 +713,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
64641 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
64642 const struct sk_buff *skb)
64643 {
64644 - return skb->prev == (struct sk_buff *)list;
64645 + return skb->prev == (const struct sk_buff *)list;
64646 }
64647
64648 /**
64649 @@ -1623,7 +1623,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
64650 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
64651 */
64652 #ifndef NET_SKB_PAD
64653 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
64654 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
64655 #endif
64656
64657 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
64658 @@ -2201,7 +2201,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
64659 int noblock, int *err);
64660 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
64661 struct poll_table_struct *wait);
64662 -extern int skb_copy_datagram_iovec(const struct sk_buff *from,
64663 +extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
64664 int offset, struct iovec *to,
64665 int size);
64666 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
64667 diff --git a/include/linux/slab.h b/include/linux/slab.h
64668 index 0dd2dfa..2b8677c 100644
64669 --- a/include/linux/slab.h
64670 +++ b/include/linux/slab.h
64671 @@ -11,12 +11,20 @@
64672
64673 #include <linux/gfp.h>
64674 #include <linux/types.h>
64675 +#include <linux/err.h>
64676
64677 /*
64678 * Flags to pass to kmem_cache_create().
64679 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
64680 */
64681 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
64682 +
64683 +#ifdef CONFIG_PAX_USERCOPY_SLABS
64684 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
64685 +#else
64686 +#define SLAB_USERCOPY 0x00000000UL
64687 +#endif
64688 +
64689 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
64690 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
64691 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
64692 @@ -87,10 +95,13 @@
64693 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
64694 * Both make kfree a no-op.
64695 */
64696 -#define ZERO_SIZE_PTR ((void *)16)
64697 +#define ZERO_SIZE_PTR \
64698 +({ \
64699 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
64700 + (void *)(-MAX_ERRNO-1L); \
64701 +})
64702
64703 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
64704 - (unsigned long)ZERO_SIZE_PTR)
64705 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
64706
64707 /*
64708 * Common fields provided in kmem_cache by all slab allocators
64709 @@ -185,6 +196,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
64710 void kfree(const void *);
64711 void kzfree(const void *);
64712 size_t ksize(const void *);
64713 +const char *check_heap_object(const void *ptr, unsigned long n, bool to);
64714 +bool is_usercopy_object(const void *ptr);
64715
64716 /*
64717 * Allocator specific definitions. These are mainly used to establish optimized
64718 @@ -322,7 +335,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
64719 */
64720 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
64721 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
64722 -extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
64723 +extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
64724 #define kmalloc_track_caller(size, flags) \
64725 __kmalloc_track_caller(size, flags, _RET_IP_)
64726 #else
64727 @@ -341,7 +354,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
64728 */
64729 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
64730 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
64731 -extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
64732 +extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
64733 #define kmalloc_node_track_caller(size, flags, node) \
64734 __kmalloc_node_track_caller(size, flags, node, \
64735 _RET_IP_)
64736 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
64737 index 0c634fa..8616300 100644
64738 --- a/include/linux/slab_def.h
64739 +++ b/include/linux/slab_def.h
64740 @@ -69,10 +69,10 @@ struct kmem_cache {
64741 unsigned long node_allocs;
64742 unsigned long node_frees;
64743 unsigned long node_overflow;
64744 - atomic_t allochit;
64745 - atomic_t allocmiss;
64746 - atomic_t freehit;
64747 - atomic_t freemiss;
64748 + atomic_unchecked_t allochit;
64749 + atomic_unchecked_t allocmiss;
64750 + atomic_unchecked_t freehit;
64751 + atomic_unchecked_t freemiss;
64752
64753 /*
64754 * If debugging is enabled, then the allocator can add additional
64755 @@ -105,11 +105,16 @@ struct cache_sizes {
64756 #ifdef CONFIG_ZONE_DMA
64757 struct kmem_cache *cs_dmacachep;
64758 #endif
64759 +
64760 +#ifdef CONFIG_PAX_USERCOPY_SLABS
64761 + struct kmem_cache *cs_usercopycachep;
64762 +#endif
64763 +
64764 };
64765 extern struct cache_sizes malloc_sizes[];
64766
64767 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
64768 -void *__kmalloc(size_t size, gfp_t flags);
64769 +void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
64770
64771 #ifdef CONFIG_TRACING
64772 extern void *kmem_cache_alloc_trace(size_t size,
64773 @@ -152,6 +157,13 @@ found:
64774 cachep = malloc_sizes[i].cs_dmacachep;
64775 else
64776 #endif
64777 +
64778 +#ifdef CONFIG_PAX_USERCOPY_SLABS
64779 + if (flags & GFP_USERCOPY)
64780 + cachep = malloc_sizes[i].cs_usercopycachep;
64781 + else
64782 +#endif
64783 +
64784 cachep = malloc_sizes[i].cs_cachep;
64785
64786 ret = kmem_cache_alloc_trace(size, cachep, flags);
64787 @@ -162,7 +174,7 @@ found:
64788 }
64789
64790 #ifdef CONFIG_NUMA
64791 -extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
64792 +extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64793 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
64794
64795 #ifdef CONFIG_TRACING
64796 @@ -205,6 +217,13 @@ found:
64797 cachep = malloc_sizes[i].cs_dmacachep;
64798 else
64799 #endif
64800 +
64801 +#ifdef CONFIG_PAX_USERCOPY_SLABS
64802 + if (flags & GFP_USERCOPY)
64803 + cachep = malloc_sizes[i].cs_usercopycachep;
64804 + else
64805 +#endif
64806 +
64807 cachep = malloc_sizes[i].cs_cachep;
64808
64809 return kmem_cache_alloc_node_trace(size, cachep, flags, node);
64810 diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
64811 index 0ec00b3..22b4715 100644
64812 --- a/include/linux/slob_def.h
64813 +++ b/include/linux/slob_def.h
64814 @@ -9,7 +9,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
64815 return kmem_cache_alloc_node(cachep, flags, -1);
64816 }
64817
64818 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
64819 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64820
64821 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
64822 {
64823 @@ -29,7 +29,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
64824 return __kmalloc_node(size, flags, -1);
64825 }
64826
64827 -static __always_inline void *__kmalloc(size_t size, gfp_t flags)
64828 +static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
64829 {
64830 return kmalloc(size, flags);
64831 }
64832 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
64833 index df448ad..b99e7f6 100644
64834 --- a/include/linux/slub_def.h
64835 +++ b/include/linux/slub_def.h
64836 @@ -91,7 +91,7 @@ struct kmem_cache {
64837 struct kmem_cache_order_objects max;
64838 struct kmem_cache_order_objects min;
64839 gfp_t allocflags; /* gfp flags to use on each alloc */
64840 - int refcount; /* Refcount for slab cache destroy */
64841 + atomic_t refcount; /* Refcount for slab cache destroy */
64842 void (*ctor)(void *);
64843 int inuse; /* Offset to metadata */
64844 int align; /* Alignment */
64845 @@ -152,7 +152,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
64846 * Sorry that the following has to be that ugly but some versions of GCC
64847 * have trouble with constant propagation and loops.
64848 */
64849 -static __always_inline int kmalloc_index(size_t size)
64850 +static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
64851 {
64852 if (!size)
64853 return 0;
64854 @@ -217,7 +217,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
64855 }
64856
64857 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
64858 -void *__kmalloc(size_t size, gfp_t flags);
64859 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
64860
64861 static __always_inline void *
64862 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
64863 @@ -258,7 +258,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
64864 }
64865 #endif
64866
64867 -static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
64868 +static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
64869 {
64870 unsigned int order = get_order(size);
64871 return kmalloc_order_trace(size, flags, order);
64872 @@ -283,7 +283,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
64873 }
64874
64875 #ifdef CONFIG_NUMA
64876 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
64877 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64878 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
64879
64880 #ifdef CONFIG_TRACING
64881 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
64882 index de8832d..0147b46 100644
64883 --- a/include/linux/sonet.h
64884 +++ b/include/linux/sonet.h
64885 @@ -61,7 +61,7 @@ struct sonet_stats {
64886 #include <linux/atomic.h>
64887
64888 struct k_sonet_stats {
64889 -#define __HANDLE_ITEM(i) atomic_t i
64890 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
64891 __SONET_ITEMS
64892 #undef __HANDLE_ITEM
64893 };
64894 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
64895 index 523547e..2cb7140 100644
64896 --- a/include/linux/sunrpc/clnt.h
64897 +++ b/include/linux/sunrpc/clnt.h
64898 @@ -174,9 +174,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
64899 {
64900 switch (sap->sa_family) {
64901 case AF_INET:
64902 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
64903 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
64904 case AF_INET6:
64905 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
64906 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
64907 }
64908 return 0;
64909 }
64910 @@ -209,7 +209,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
64911 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
64912 const struct sockaddr *src)
64913 {
64914 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
64915 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
64916 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
64917
64918 dsin->sin_family = ssin->sin_family;
64919 @@ -312,7 +312,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
64920 if (sa->sa_family != AF_INET6)
64921 return 0;
64922
64923 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
64924 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
64925 }
64926
64927 #endif /* __KERNEL__ */
64928 diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h
64929 index dc0c3cc..8503fb6 100644
64930 --- a/include/linux/sunrpc/sched.h
64931 +++ b/include/linux/sunrpc/sched.h
64932 @@ -106,6 +106,7 @@ struct rpc_call_ops {
64933 void (*rpc_count_stats)(struct rpc_task *, void *);
64934 void (*rpc_release)(void *);
64935 };
64936 +typedef struct rpc_call_ops __no_const rpc_call_ops_no_const;
64937
64938 struct rpc_task_setup {
64939 struct rpc_task *task;
64940 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
64941 index 0b8e3e6..33e0a01 100644
64942 --- a/include/linux/sunrpc/svc_rdma.h
64943 +++ b/include/linux/sunrpc/svc_rdma.h
64944 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
64945 extern unsigned int svcrdma_max_requests;
64946 extern unsigned int svcrdma_max_req_size;
64947
64948 -extern atomic_t rdma_stat_recv;
64949 -extern atomic_t rdma_stat_read;
64950 -extern atomic_t rdma_stat_write;
64951 -extern atomic_t rdma_stat_sq_starve;
64952 -extern atomic_t rdma_stat_rq_starve;
64953 -extern atomic_t rdma_stat_rq_poll;
64954 -extern atomic_t rdma_stat_rq_prod;
64955 -extern atomic_t rdma_stat_sq_poll;
64956 -extern atomic_t rdma_stat_sq_prod;
64957 +extern atomic_unchecked_t rdma_stat_recv;
64958 +extern atomic_unchecked_t rdma_stat_read;
64959 +extern atomic_unchecked_t rdma_stat_write;
64960 +extern atomic_unchecked_t rdma_stat_sq_starve;
64961 +extern atomic_unchecked_t rdma_stat_rq_starve;
64962 +extern atomic_unchecked_t rdma_stat_rq_poll;
64963 +extern atomic_unchecked_t rdma_stat_rq_prod;
64964 +extern atomic_unchecked_t rdma_stat_sq_poll;
64965 +extern atomic_unchecked_t rdma_stat_sq_prod;
64966
64967 #define RPCRDMA_VERSION 1
64968
64969 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
64970 index c34b4c8..a65b67d 100644
64971 --- a/include/linux/sysctl.h
64972 +++ b/include/linux/sysctl.h
64973 @@ -155,7 +155,11 @@ enum
64974 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
64975 };
64976
64977 -
64978 +#ifdef CONFIG_PAX_SOFTMODE
64979 +enum {
64980 + PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
64981 +};
64982 +#endif
64983
64984 /* CTL_VM names: */
64985 enum
64986 @@ -948,6 +952,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
64987
64988 extern int proc_dostring(struct ctl_table *, int,
64989 void __user *, size_t *, loff_t *);
64990 +extern int proc_dostring_modpriv(struct ctl_table *, int,
64991 + void __user *, size_t *, loff_t *);
64992 extern int proc_dointvec(struct ctl_table *, int,
64993 void __user *, size_t *, loff_t *);
64994 extern int proc_dointvec_minmax(struct ctl_table *, int,
64995 diff --git a/include/linux/tty.h b/include/linux/tty.h
64996 index 9f47ab5..73da944 100644
64997 --- a/include/linux/tty.h
64998 +++ b/include/linux/tty.h
64999 @@ -225,7 +225,7 @@ struct tty_port {
65000 const struct tty_port_operations *ops; /* Port operations */
65001 spinlock_t lock; /* Lock protecting tty field */
65002 int blocked_open; /* Waiting to open */
65003 - int count; /* Usage count */
65004 + atomic_t count; /* Usage count */
65005 wait_queue_head_t open_wait; /* Open waiters */
65006 wait_queue_head_t close_wait; /* Close waiters */
65007 wait_queue_head_t delta_msr_wait; /* Modem status change */
65008 @@ -525,7 +525,7 @@ extern int tty_port_open(struct tty_port *port,
65009 struct tty_struct *tty, struct file *filp);
65010 static inline int tty_port_users(struct tty_port *port)
65011 {
65012 - return port->count + port->blocked_open;
65013 + return atomic_read(&port->count) + port->blocked_open;
65014 }
65015
65016 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
65017 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
65018 index fb79dd8d..07d4773 100644
65019 --- a/include/linux/tty_ldisc.h
65020 +++ b/include/linux/tty_ldisc.h
65021 @@ -149,7 +149,7 @@ struct tty_ldisc_ops {
65022
65023 struct module *owner;
65024
65025 - int refcount;
65026 + atomic_t refcount;
65027 };
65028
65029 struct tty_ldisc {
65030 diff --git a/include/linux/types.h b/include/linux/types.h
65031 index bf0dd75..a1f23aaa 100644
65032 --- a/include/linux/types.h
65033 +++ b/include/linux/types.h
65034 @@ -220,10 +220,26 @@ typedef struct {
65035 int counter;
65036 } atomic_t;
65037
65038 +#ifdef CONFIG_PAX_REFCOUNT
65039 +typedef struct {
65040 + int counter;
65041 +} atomic_unchecked_t;
65042 +#else
65043 +typedef atomic_t atomic_unchecked_t;
65044 +#endif
65045 +
65046 #ifdef CONFIG_64BIT
65047 typedef struct {
65048 long counter;
65049 } atomic64_t;
65050 +
65051 +#ifdef CONFIG_PAX_REFCOUNT
65052 +typedef struct {
65053 + long counter;
65054 +} atomic64_unchecked_t;
65055 +#else
65056 +typedef atomic64_t atomic64_unchecked_t;
65057 +#endif
65058 #endif
65059
65060 struct list_head {
65061 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
65062 index 5ca0951..ab496a5 100644
65063 --- a/include/linux/uaccess.h
65064 +++ b/include/linux/uaccess.h
65065 @@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
65066 long ret; \
65067 mm_segment_t old_fs = get_fs(); \
65068 \
65069 - set_fs(KERNEL_DS); \
65070 pagefault_disable(); \
65071 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
65072 - pagefault_enable(); \
65073 + set_fs(KERNEL_DS); \
65074 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
65075 set_fs(old_fs); \
65076 + pagefault_enable(); \
65077 ret; \
65078 })
65079
65080 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
65081 index 99c1b4d..bb94261 100644
65082 --- a/include/linux/unaligned/access_ok.h
65083 +++ b/include/linux/unaligned/access_ok.h
65084 @@ -6,32 +6,32 @@
65085
65086 static inline u16 get_unaligned_le16(const void *p)
65087 {
65088 - return le16_to_cpup((__le16 *)p);
65089 + return le16_to_cpup((const __le16 *)p);
65090 }
65091
65092 static inline u32 get_unaligned_le32(const void *p)
65093 {
65094 - return le32_to_cpup((__le32 *)p);
65095 + return le32_to_cpup((const __le32 *)p);
65096 }
65097
65098 static inline u64 get_unaligned_le64(const void *p)
65099 {
65100 - return le64_to_cpup((__le64 *)p);
65101 + return le64_to_cpup((const __le64 *)p);
65102 }
65103
65104 static inline u16 get_unaligned_be16(const void *p)
65105 {
65106 - return be16_to_cpup((__be16 *)p);
65107 + return be16_to_cpup((const __be16 *)p);
65108 }
65109
65110 static inline u32 get_unaligned_be32(const void *p)
65111 {
65112 - return be32_to_cpup((__be32 *)p);
65113 + return be32_to_cpup((const __be32 *)p);
65114 }
65115
65116 static inline u64 get_unaligned_be64(const void *p)
65117 {
65118 - return be64_to_cpup((__be64 *)p);
65119 + return be64_to_cpup((const __be64 *)p);
65120 }
65121
65122 static inline void put_unaligned_le16(u16 val, void *p)
65123 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
65124 index c5d36c6..8478c90 100644
65125 --- a/include/linux/usb/renesas_usbhs.h
65126 +++ b/include/linux/usb/renesas_usbhs.h
65127 @@ -39,7 +39,7 @@ enum {
65128 */
65129 struct renesas_usbhs_driver_callback {
65130 int (*notify_hotplug)(struct platform_device *pdev);
65131 -};
65132 +} __no_const;
65133
65134 /*
65135 * callback functions for platform
65136 @@ -97,7 +97,7 @@ struct renesas_usbhs_platform_callback {
65137 * VBUS control is needed for Host
65138 */
65139 int (*set_vbus)(struct platform_device *pdev, int enable);
65140 -};
65141 +} __no_const;
65142
65143 /*
65144 * parameters for renesas usbhs
65145 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
65146 index 6f8fbcf..8259001 100644
65147 --- a/include/linux/vermagic.h
65148 +++ b/include/linux/vermagic.h
65149 @@ -25,9 +25,35 @@
65150 #define MODULE_ARCH_VERMAGIC ""
65151 #endif
65152
65153 +#ifdef CONFIG_PAX_REFCOUNT
65154 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
65155 +#else
65156 +#define MODULE_PAX_REFCOUNT ""
65157 +#endif
65158 +
65159 +#ifdef CONSTIFY_PLUGIN
65160 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
65161 +#else
65162 +#define MODULE_CONSTIFY_PLUGIN ""
65163 +#endif
65164 +
65165 +#ifdef STACKLEAK_PLUGIN
65166 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
65167 +#else
65168 +#define MODULE_STACKLEAK_PLUGIN ""
65169 +#endif
65170 +
65171 +#ifdef CONFIG_GRKERNSEC
65172 +#define MODULE_GRSEC "GRSEC "
65173 +#else
65174 +#define MODULE_GRSEC ""
65175 +#endif
65176 +
65177 #define VERMAGIC_STRING \
65178 UTS_RELEASE " " \
65179 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
65180 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
65181 - MODULE_ARCH_VERMAGIC
65182 + MODULE_ARCH_VERMAGIC \
65183 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
65184 + MODULE_GRSEC
65185
65186 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
65187 index 6071e91..ca6a489 100644
65188 --- a/include/linux/vmalloc.h
65189 +++ b/include/linux/vmalloc.h
65190 @@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
65191 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
65192 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
65193 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
65194 +
65195 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
65196 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
65197 +#endif
65198 +
65199 /* bits [20..32] reserved for arch specific ioremap internals */
65200
65201 /*
65202 @@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
65203 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
65204 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
65205 unsigned long start, unsigned long end, gfp_t gfp_mask,
65206 - pgprot_t prot, int node, const void *caller);
65207 + pgprot_t prot, int node, const void *caller) __size_overflow(1);
65208 extern void vfree(const void *addr);
65209
65210 extern void *vmap(struct page **pages, unsigned int count,
65211 @@ -124,8 +129,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
65212 extern void free_vm_area(struct vm_struct *area);
65213
65214 /* for /dev/kmem */
65215 -extern long vread(char *buf, char *addr, unsigned long count);
65216 -extern long vwrite(char *buf, char *addr, unsigned long count);
65217 +extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
65218 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
65219
65220 /*
65221 * Internals. Dont't use..
65222 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
65223 index ad2cfd5..74c94ad 100644
65224 --- a/include/linux/vmstat.h
65225 +++ b/include/linux/vmstat.h
65226 @@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
65227 /*
65228 * Zone based page accounting with per cpu differentials.
65229 */
65230 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
65231 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
65232
65233 static inline void zone_page_state_add(long x, struct zone *zone,
65234 enum zone_stat_item item)
65235 {
65236 - atomic_long_add(x, &zone->vm_stat[item]);
65237 - atomic_long_add(x, &vm_stat[item]);
65238 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
65239 + atomic_long_add_unchecked(x, &vm_stat[item]);
65240 }
65241
65242 static inline unsigned long global_page_state(enum zone_stat_item item)
65243 {
65244 - long x = atomic_long_read(&vm_stat[item]);
65245 + long x = atomic_long_read_unchecked(&vm_stat[item]);
65246 #ifdef CONFIG_SMP
65247 if (x < 0)
65248 x = 0;
65249 @@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
65250 static inline unsigned long zone_page_state(struct zone *zone,
65251 enum zone_stat_item item)
65252 {
65253 - long x = atomic_long_read(&zone->vm_stat[item]);
65254 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
65255 #ifdef CONFIG_SMP
65256 if (x < 0)
65257 x = 0;
65258 @@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
65259 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
65260 enum zone_stat_item item)
65261 {
65262 - long x = atomic_long_read(&zone->vm_stat[item]);
65263 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
65264
65265 #ifdef CONFIG_SMP
65266 int cpu;
65267 @@ -216,8 +216,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
65268
65269 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
65270 {
65271 - atomic_long_inc(&zone->vm_stat[item]);
65272 - atomic_long_inc(&vm_stat[item]);
65273 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
65274 + atomic_long_inc_unchecked(&vm_stat[item]);
65275 }
65276
65277 static inline void __inc_zone_page_state(struct page *page,
65278 @@ -228,8 +228,8 @@ static inline void __inc_zone_page_state(struct page *page,
65279
65280 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
65281 {
65282 - atomic_long_dec(&zone->vm_stat[item]);
65283 - atomic_long_dec(&vm_stat[item]);
65284 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
65285 + atomic_long_dec_unchecked(&vm_stat[item]);
65286 }
65287
65288 static inline void __dec_zone_page_state(struct page *page,
65289 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
65290 index e5d1220..ef6e406 100644
65291 --- a/include/linux/xattr.h
65292 +++ b/include/linux/xattr.h
65293 @@ -57,6 +57,11 @@
65294 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
65295 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
65296
65297 +/* User namespace */
65298 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
65299 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
65300 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
65301 +
65302 #ifdef __KERNEL__
65303
65304 #include <linux/types.h>
65305 diff --git a/include/media/saa7146_vv.h b/include/media/saa7146_vv.h
65306 index 944ecdf..a3994fc 100644
65307 --- a/include/media/saa7146_vv.h
65308 +++ b/include/media/saa7146_vv.h
65309 @@ -161,8 +161,8 @@ struct saa7146_ext_vv
65310 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
65311
65312 /* the extension can override this */
65313 - struct v4l2_ioctl_ops vid_ops;
65314 - struct v4l2_ioctl_ops vbi_ops;
65315 + v4l2_ioctl_ops_no_const vid_ops;
65316 + v4l2_ioctl_ops_no_const vbi_ops;
65317 /* pointer to the saa7146 core ops */
65318 const struct v4l2_ioctl_ops *core_ops;
65319
65320 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
65321 index 5c416cd..20021aa 100644
65322 --- a/include/media/v4l2-dev.h
65323 +++ b/include/media/v4l2-dev.h
65324 @@ -73,7 +73,8 @@ struct v4l2_file_operations {
65325 int (*mmap) (struct file *, struct vm_area_struct *);
65326 int (*open) (struct file *);
65327 int (*release) (struct file *);
65328 -};
65329 +} __do_const;
65330 +typedef struct v4l2_file_operations __no_const v4l2_file_operations_no_const;
65331
65332 /*
65333 * Newer version of video_device, handled by videodev2.c
65334 diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
65335 index e614c9c..20602b7 100644
65336 --- a/include/media/v4l2-ioctl.h
65337 +++ b/include/media/v4l2-ioctl.h
65338 @@ -289,7 +289,7 @@ struct v4l2_ioctl_ops {
65339 long (*vidioc_default) (struct file *file, void *fh,
65340 bool valid_prio, int cmd, void *arg);
65341 };
65342 -
65343 +typedef struct v4l2_ioctl_ops __no_const v4l2_ioctl_ops_no_const;
65344
65345 /* v4l debugging and diagnostics */
65346
65347 diff --git a/include/net/caif/caif_hsi.h b/include/net/caif/caif_hsi.h
65348 index bcb9cc3..f4ec722e 100644
65349 --- a/include/net/caif/caif_hsi.h
65350 +++ b/include/net/caif/caif_hsi.h
65351 @@ -98,7 +98,7 @@ struct cfhsi_cb_ops {
65352 void (*rx_done_cb) (struct cfhsi_cb_ops *drv);
65353 void (*wake_up_cb) (struct cfhsi_cb_ops *drv);
65354 void (*wake_down_cb) (struct cfhsi_cb_ops *drv);
65355 -};
65356 +} __no_const;
65357
65358 /* Structure implemented by HSI device. */
65359 struct cfhsi_ops {
65360 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
65361 index 9e5425b..8136ffc 100644
65362 --- a/include/net/caif/cfctrl.h
65363 +++ b/include/net/caif/cfctrl.h
65364 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
65365 void (*radioset_rsp)(void);
65366 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
65367 struct cflayer *client_layer);
65368 -};
65369 +} __no_const;
65370
65371 /* Link Setup Parameters for CAIF-Links. */
65372 struct cfctrl_link_param {
65373 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
65374 struct cfctrl {
65375 struct cfsrvl serv;
65376 struct cfctrl_rsp res;
65377 - atomic_t req_seq_no;
65378 - atomic_t rsp_seq_no;
65379 + atomic_unchecked_t req_seq_no;
65380 + atomic_unchecked_t rsp_seq_no;
65381 struct list_head list;
65382 /* Protects from simultaneous access to first_req list */
65383 spinlock_t info_list_lock;
65384 diff --git a/include/net/flow.h b/include/net/flow.h
65385 index 628e11b..4c475df 100644
65386 --- a/include/net/flow.h
65387 +++ b/include/net/flow.h
65388 @@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
65389
65390 extern void flow_cache_flush(void);
65391 extern void flow_cache_flush_deferred(void);
65392 -extern atomic_t flow_cache_genid;
65393 +extern atomic_unchecked_t flow_cache_genid;
65394
65395 #endif
65396 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
65397 index 53f464d..ba76aaa 100644
65398 --- a/include/net/inetpeer.h
65399 +++ b/include/net/inetpeer.h
65400 @@ -47,8 +47,8 @@ struct inet_peer {
65401 */
65402 union {
65403 struct {
65404 - atomic_t rid; /* Frag reception counter */
65405 - atomic_t ip_id_count; /* IP ID for the next packet */
65406 + atomic_unchecked_t rid; /* Frag reception counter */
65407 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
65408 };
65409 struct rcu_head rcu;
65410 struct inet_peer *gc_next;
65411 @@ -182,11 +182,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
65412 more++;
65413 inet_peer_refcheck(p);
65414 do {
65415 - old = atomic_read(&p->ip_id_count);
65416 + old = atomic_read_unchecked(&p->ip_id_count);
65417 new = old + more;
65418 if (!new)
65419 new = 1;
65420 - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
65421 + } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
65422 return new;
65423 }
65424
65425 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
65426 index 9497be1..5a4fafe 100644
65427 --- a/include/net/ip_fib.h
65428 +++ b/include/net/ip_fib.h
65429 @@ -169,7 +169,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
65430
65431 #define FIB_RES_SADDR(net, res) \
65432 ((FIB_RES_NH(res).nh_saddr_genid == \
65433 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
65434 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
65435 FIB_RES_NH(res).nh_saddr : \
65436 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
65437 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
65438 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
65439 index 95374d1..2300e36 100644
65440 --- a/include/net/ip_vs.h
65441 +++ b/include/net/ip_vs.h
65442 @@ -510,7 +510,7 @@ struct ip_vs_conn {
65443 struct ip_vs_conn *control; /* Master control connection */
65444 atomic_t n_control; /* Number of controlled ones */
65445 struct ip_vs_dest *dest; /* real server */
65446 - atomic_t in_pkts; /* incoming packet counter */
65447 + atomic_unchecked_t in_pkts; /* incoming packet counter */
65448
65449 /* packet transmitter for different forwarding methods. If it
65450 mangles the packet, it must return NF_DROP or better NF_STOLEN,
65451 @@ -648,7 +648,7 @@ struct ip_vs_dest {
65452 __be16 port; /* port number of the server */
65453 union nf_inet_addr addr; /* IP address of the server */
65454 volatile unsigned int flags; /* dest status flags */
65455 - atomic_t conn_flags; /* flags to copy to conn */
65456 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
65457 atomic_t weight; /* server weight */
65458
65459 atomic_t refcnt; /* reference counter */
65460 diff --git a/include/net/irda/ircomm_core.h b/include/net/irda/ircomm_core.h
65461 index 69b610a..fe3962c 100644
65462 --- a/include/net/irda/ircomm_core.h
65463 +++ b/include/net/irda/ircomm_core.h
65464 @@ -51,7 +51,7 @@ typedef struct {
65465 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
65466 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
65467 struct ircomm_info *);
65468 -} call_t;
65469 +} __no_const call_t;
65470
65471 struct ircomm_cb {
65472 irda_queue_t queue;
65473 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
65474 index 59ba38bc..d515662 100644
65475 --- a/include/net/irda/ircomm_tty.h
65476 +++ b/include/net/irda/ircomm_tty.h
65477 @@ -35,6 +35,7 @@
65478 #include <linux/termios.h>
65479 #include <linux/timer.h>
65480 #include <linux/tty.h> /* struct tty_struct */
65481 +#include <asm/local.h>
65482
65483 #include <net/irda/irias_object.h>
65484 #include <net/irda/ircomm_core.h>
65485 @@ -105,8 +106,8 @@ struct ircomm_tty_cb {
65486 unsigned short close_delay;
65487 unsigned short closing_wait; /* time to wait before closing */
65488
65489 - int open_count;
65490 - int blocked_open; /* # of blocked opens */
65491 + local_t open_count;
65492 + local_t blocked_open; /* # of blocked opens */
65493
65494 /* Protect concurent access to :
65495 * o self->open_count
65496 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
65497 index cc7c197..9f2da2a 100644
65498 --- a/include/net/iucv/af_iucv.h
65499 +++ b/include/net/iucv/af_iucv.h
65500 @@ -141,7 +141,7 @@ struct iucv_sock {
65501 struct iucv_sock_list {
65502 struct hlist_head head;
65503 rwlock_t lock;
65504 - atomic_t autobind_name;
65505 + atomic_unchecked_t autobind_name;
65506 };
65507
65508 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
65509 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
65510 index 344d898..2ae1302 100644
65511 --- a/include/net/neighbour.h
65512 +++ b/include/net/neighbour.h
65513 @@ -123,7 +123,7 @@ struct neigh_ops {
65514 void (*error_report)(struct neighbour *, struct sk_buff *);
65515 int (*output)(struct neighbour *, struct sk_buff *);
65516 int (*connected_output)(struct neighbour *, struct sk_buff *);
65517 -};
65518 +} __do_const;
65519
65520 struct pneigh_entry {
65521 struct pneigh_entry *next;
65522 diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
65523 index fd87963..312a11f 100644
65524 --- a/include/net/net_namespace.h
65525 +++ b/include/net/net_namespace.h
65526 @@ -102,7 +102,7 @@ struct net {
65527 #endif
65528 struct netns_ipvs *ipvs;
65529 struct sock *diag_nlsk;
65530 - atomic_t rt_genid;
65531 + atomic_unchecked_t rt_genid;
65532 };
65533
65534
65535 @@ -303,12 +303,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
65536
65537 static inline int rt_genid(struct net *net)
65538 {
65539 - return atomic_read(&net->rt_genid);
65540 + return atomic_read_unchecked(&net->rt_genid);
65541 }
65542
65543 static inline void rt_genid_bump(struct net *net)
65544 {
65545 - atomic_inc(&net->rt_genid);
65546 + atomic_inc_unchecked(&net->rt_genid);
65547 }
65548
65549 #endif /* __NET_NET_NAMESPACE_H */
65550 diff --git a/include/net/netdma.h b/include/net/netdma.h
65551 index 8ba8ce2..99b7fff 100644
65552 --- a/include/net/netdma.h
65553 +++ b/include/net/netdma.h
65554 @@ -24,7 +24,7 @@
65555 #include <linux/dmaengine.h>
65556 #include <linux/skbuff.h>
65557
65558 -int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
65559 +int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
65560 struct sk_buff *skb, int offset, struct iovec *to,
65561 size_t len, struct dma_pinned_list *pinned_list);
65562
65563 diff --git a/include/net/netlink.h b/include/net/netlink.h
65564 index 785f37a..c81dc0c 100644
65565 --- a/include/net/netlink.h
65566 +++ b/include/net/netlink.h
65567 @@ -520,7 +520,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
65568 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
65569 {
65570 if (mark)
65571 - skb_trim(skb, (unsigned char *) mark - skb->data);
65572 + skb_trim(skb, (const unsigned char *) mark - skb->data);
65573 }
65574
65575 /**
65576 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
65577 index eb24dbc..567d6ed 100644
65578 --- a/include/net/netns/ipv4.h
65579 +++ b/include/net/netns/ipv4.h
65580 @@ -65,7 +65,7 @@ struct netns_ipv4 {
65581 unsigned int sysctl_ping_group_range[2];
65582 long sysctl_tcp_mem[3];
65583
65584 - atomic_t dev_addr_genid;
65585 + atomic_unchecked_t dev_addr_genid;
65586
65587 #ifdef CONFIG_IP_MROUTE
65588 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
65589 diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
65590 index ff49964..1411fee 100644
65591 --- a/include/net/sctp/sctp.h
65592 +++ b/include/net/sctp/sctp.h
65593 @@ -320,9 +320,9 @@ do { \
65594
65595 #else /* SCTP_DEBUG */
65596
65597 -#define SCTP_DEBUG_PRINTK(whatever...)
65598 -#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
65599 -#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
65600 +#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
65601 +#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
65602 +#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
65603 #define SCTP_ENABLE_DEBUG
65604 #define SCTP_DISABLE_DEBUG
65605 #define SCTP_ASSERT(expr, str, func)
65606 diff --git a/include/net/sock.h b/include/net/sock.h
65607 index adb7da2..1100002 100644
65608 --- a/include/net/sock.h
65609 +++ b/include/net/sock.h
65610 @@ -305,7 +305,7 @@ struct sock {
65611 #ifdef CONFIG_RPS
65612 __u32 sk_rxhash;
65613 #endif
65614 - atomic_t sk_drops;
65615 + atomic_unchecked_t sk_drops;
65616 int sk_rcvbuf;
65617
65618 struct sk_filter __rcu *sk_filter;
65619 @@ -1764,7 +1764,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
65620 }
65621
65622 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
65623 - char __user *from, char *to,
65624 + char __user *from, unsigned char *to,
65625 int copy, int offset)
65626 {
65627 if (skb->ip_summed == CHECKSUM_NONE) {
65628 @@ -2023,7 +2023,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
65629 }
65630 }
65631
65632 -struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
65633 +struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
65634
65635 static inline struct page *sk_stream_alloc_page(struct sock *sk)
65636 {
65637 diff --git a/include/net/tcp.h b/include/net/tcp.h
65638 index 1f000ff..e5a8dfb 100644
65639 --- a/include/net/tcp.h
65640 +++ b/include/net/tcp.h
65641 @@ -508,7 +508,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
65642 extern void tcp_xmit_retransmit_queue(struct sock *);
65643 extern void tcp_simple_retransmit(struct sock *);
65644 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
65645 -extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
65646 +extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
65647
65648 extern void tcp_send_probe0(struct sock *);
65649 extern void tcp_send_partial(struct sock *);
65650 @@ -677,8 +677,8 @@ struct tcp_skb_cb {
65651 struct inet6_skb_parm h6;
65652 #endif
65653 } header; /* For incoming frames */
65654 - __u32 seq; /* Starting sequence number */
65655 - __u32 end_seq; /* SEQ + FIN + SYN + datalen */
65656 + __u32 seq __intentional_overflow(0); /* Starting sequence number */
65657 + __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
65658 __u32 when; /* used to compute rtt's */
65659 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
65660
65661 @@ -692,7 +692,7 @@ struct tcp_skb_cb {
65662
65663 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
65664 /* 1 byte hole */
65665 - __u32 ack_seq; /* Sequence number ACK'd */
65666 + __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
65667 };
65668
65669 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
65670 @@ -1502,7 +1502,7 @@ struct tcp_seq_afinfo {
65671 char *name;
65672 sa_family_t family;
65673 const struct file_operations *seq_fops;
65674 - struct seq_operations seq_ops;
65675 + seq_operations_no_const seq_ops;
65676 };
65677
65678 struct tcp_iter_state {
65679 diff --git a/include/net/udp.h b/include/net/udp.h
65680 index 065f379..b661b40 100644
65681 --- a/include/net/udp.h
65682 +++ b/include/net/udp.h
65683 @@ -244,7 +244,7 @@ struct udp_seq_afinfo {
65684 sa_family_t family;
65685 struct udp_table *udp_table;
65686 const struct file_operations *seq_fops;
65687 - struct seq_operations seq_ops;
65688 + seq_operations_no_const seq_ops;
65689 };
65690
65691 struct udp_iter_state {
65692 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
65693 index 639dd13..15b206c 100644
65694 --- a/include/net/xfrm.h
65695 +++ b/include/net/xfrm.h
65696 @@ -514,7 +514,7 @@ struct xfrm_policy {
65697 struct timer_list timer;
65698
65699 struct flow_cache_object flo;
65700 - atomic_t genid;
65701 + atomic_unchecked_t genid;
65702 u32 priority;
65703 u32 index;
65704 struct xfrm_mark mark;
65705 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
65706 index 1a046b1..ee0bef0 100644
65707 --- a/include/rdma/iw_cm.h
65708 +++ b/include/rdma/iw_cm.h
65709 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
65710 int backlog);
65711
65712 int (*destroy_listen)(struct iw_cm_id *cm_id);
65713 -};
65714 +} __no_const;
65715
65716 /**
65717 * iw_create_cm_id - Create an IW CM identifier.
65718 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
65719 index 399162b..b337f1a 100644
65720 --- a/include/scsi/libfc.h
65721 +++ b/include/scsi/libfc.h
65722 @@ -762,6 +762,7 @@ struct libfc_function_template {
65723 */
65724 void (*disc_stop_final) (struct fc_lport *);
65725 };
65726 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
65727
65728 /**
65729 * struct fc_disc - Discovery context
65730 @@ -866,7 +867,7 @@ struct fc_lport {
65731 struct fc_vport *vport;
65732
65733 /* Operational Information */
65734 - struct libfc_function_template tt;
65735 + libfc_function_template_no_const tt;
65736 u8 link_up;
65737 u8 qfull;
65738 enum fc_lport_state state;
65739 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
65740 index 9895f69..f1418f0 100644
65741 --- a/include/scsi/scsi_device.h
65742 +++ b/include/scsi/scsi_device.h
65743 @@ -166,9 +166,9 @@ struct scsi_device {
65744 unsigned int max_device_blocked; /* what device_blocked counts down from */
65745 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
65746
65747 - atomic_t iorequest_cnt;
65748 - atomic_t iodone_cnt;
65749 - atomic_t ioerr_cnt;
65750 + atomic_unchecked_t iorequest_cnt;
65751 + atomic_unchecked_t iodone_cnt;
65752 + atomic_unchecked_t ioerr_cnt;
65753
65754 struct device sdev_gendev,
65755 sdev_dev;
65756 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
65757 index b797e8f..8e2c3aa 100644
65758 --- a/include/scsi/scsi_transport_fc.h
65759 +++ b/include/scsi/scsi_transport_fc.h
65760 @@ -751,7 +751,8 @@ struct fc_function_template {
65761 unsigned long show_host_system_hostname:1;
65762
65763 unsigned long disable_target_scan:1;
65764 -};
65765 +} __do_const;
65766 +typedef struct fc_function_template __no_const fc_function_template_no_const;
65767
65768
65769 /**
65770 diff --git a/include/sound/ak4xxx-adda.h b/include/sound/ak4xxx-adda.h
65771 index 030b87c..98a6954 100644
65772 --- a/include/sound/ak4xxx-adda.h
65773 +++ b/include/sound/ak4xxx-adda.h
65774 @@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
65775 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
65776 unsigned char val);
65777 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
65778 -};
65779 +} __no_const;
65780
65781 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
65782
65783 diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h
65784 index 8c05e47..2b5df97 100644
65785 --- a/include/sound/hwdep.h
65786 +++ b/include/sound/hwdep.h
65787 @@ -49,7 +49,7 @@ struct snd_hwdep_ops {
65788 struct snd_hwdep_dsp_status *status);
65789 int (*dsp_load)(struct snd_hwdep *hw,
65790 struct snd_hwdep_dsp_image *image);
65791 -};
65792 +} __no_const;
65793
65794 struct snd_hwdep {
65795 struct snd_card *card;
65796 diff --git a/include/sound/info.h b/include/sound/info.h
65797 index 9ca1a49..aba1728 100644
65798 --- a/include/sound/info.h
65799 +++ b/include/sound/info.h
65800 @@ -44,7 +44,7 @@ struct snd_info_entry_text {
65801 struct snd_info_buffer *buffer);
65802 void (*write)(struct snd_info_entry *entry,
65803 struct snd_info_buffer *buffer);
65804 -};
65805 +} __no_const;
65806
65807 struct snd_info_entry_ops {
65808 int (*open)(struct snd_info_entry *entry,
65809 diff --git a/include/sound/pcm.h b/include/sound/pcm.h
65810 index cdca2ab..10bbe05 100644
65811 --- a/include/sound/pcm.h
65812 +++ b/include/sound/pcm.h
65813 @@ -81,6 +81,7 @@ struct snd_pcm_ops {
65814 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
65815 int (*ack)(struct snd_pcm_substream *substream);
65816 };
65817 +typedef struct snd_pcm_ops __no_const snd_pcm_ops_no_const;
65818
65819 /*
65820 *
65821 diff --git a/include/sound/sb16_csp.h b/include/sound/sb16_csp.h
65822 index af1b49e..a5d55a5 100644
65823 --- a/include/sound/sb16_csp.h
65824 +++ b/include/sound/sb16_csp.h
65825 @@ -146,7 +146,7 @@ struct snd_sb_csp_ops {
65826 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
65827 int (*csp_stop) (struct snd_sb_csp * p);
65828 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
65829 -};
65830 +} __no_const;
65831
65832 /*
65833 * CSP private data
65834 diff --git a/include/sound/soc.h b/include/sound/soc.h
65835 index e063380..e8077d5 100644
65836 --- a/include/sound/soc.h
65837 +++ b/include/sound/soc.h
65838 @@ -801,7 +801,7 @@ struct snd_soc_platform_driver {
65839 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
65840 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
65841 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
65842 -};
65843 +} __do_const;
65844
65845 struct snd_soc_platform {
65846 const char *name;
65847 @@ -1016,7 +1016,7 @@ struct snd_soc_pcm_runtime {
65848 struct snd_soc_dai_link *dai_link;
65849 struct mutex pcm_mutex;
65850 enum snd_soc_pcm_subclass pcm_subclass;
65851 - struct snd_pcm_ops ops;
65852 + snd_pcm_ops_no_const ops;
65853
65854 unsigned int dev_registered:1;
65855
65856 diff --git a/include/sound/tea575x-tuner.h b/include/sound/tea575x-tuner.h
65857 index fe8590c..aaed363 100644
65858 --- a/include/sound/tea575x-tuner.h
65859 +++ b/include/sound/tea575x-tuner.h
65860 @@ -48,7 +48,7 @@ struct snd_tea575x_ops {
65861
65862 struct snd_tea575x {
65863 struct v4l2_device *v4l2_dev;
65864 - struct v4l2_file_operations fops;
65865 + v4l2_file_operations_no_const fops;
65866 struct video_device vd; /* video device */
65867 int radio_nr; /* radio_nr */
65868 bool tea5759; /* 5759 chip is present */
65869 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
65870 index 5be8937..a8e46e9 100644
65871 --- a/include/target/target_core_base.h
65872 +++ b/include/target/target_core_base.h
65873 @@ -434,7 +434,7 @@ struct t10_reservation_ops {
65874 int (*t10_seq_non_holder)(struct se_cmd *, unsigned char *, u32);
65875 int (*t10_pr_register)(struct se_cmd *);
65876 int (*t10_pr_clear)(struct se_cmd *);
65877 -};
65878 +} __no_const;
65879
65880 struct t10_reservation {
65881 /* Reservation effects all target ports */
65882 @@ -758,7 +758,7 @@ struct se_device {
65883 spinlock_t stats_lock;
65884 /* Active commands on this virtual SE device */
65885 atomic_t simple_cmds;
65886 - atomic_t dev_ordered_id;
65887 + atomic_unchecked_t dev_ordered_id;
65888 atomic_t dev_ordered_sync;
65889 atomic_t dev_qf_count;
65890 struct se_obj dev_obj;
65891 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
65892 new file mode 100644
65893 index 0000000..2efe49d
65894 --- /dev/null
65895 +++ b/include/trace/events/fs.h
65896 @@ -0,0 +1,53 @@
65897 +#undef TRACE_SYSTEM
65898 +#define TRACE_SYSTEM fs
65899 +
65900 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
65901 +#define _TRACE_FS_H
65902 +
65903 +#include <linux/fs.h>
65904 +#include <linux/tracepoint.h>
65905 +
65906 +TRACE_EVENT(do_sys_open,
65907 +
65908 + TP_PROTO(char *filename, int flags, int mode),
65909 +
65910 + TP_ARGS(filename, flags, mode),
65911 +
65912 + TP_STRUCT__entry(
65913 + __string( filename, filename )
65914 + __field( int, flags )
65915 + __field( int, mode )
65916 + ),
65917 +
65918 + TP_fast_assign(
65919 + __assign_str(filename, filename);
65920 + __entry->flags = flags;
65921 + __entry->mode = mode;
65922 + ),
65923 +
65924 + TP_printk("\"%s\" %x %o",
65925 + __get_str(filename), __entry->flags, __entry->mode)
65926 +);
65927 +
65928 +TRACE_EVENT(open_exec,
65929 +
65930 + TP_PROTO(const char *filename),
65931 +
65932 + TP_ARGS(filename),
65933 +
65934 + TP_STRUCT__entry(
65935 + __string( filename, filename )
65936 + ),
65937 +
65938 + TP_fast_assign(
65939 + __assign_str(filename, filename);
65940 + ),
65941 +
65942 + TP_printk("\"%s\"",
65943 + __get_str(filename))
65944 +);
65945 +
65946 +#endif /* _TRACE_FS_H */
65947 +
65948 +/* This part must be outside protection */
65949 +#include <trace/define_trace.h>
65950 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
65951 index 1c09820..7f5ec79 100644
65952 --- a/include/trace/events/irq.h
65953 +++ b/include/trace/events/irq.h
65954 @@ -36,7 +36,7 @@ struct softirq_action;
65955 */
65956 TRACE_EVENT(irq_handler_entry,
65957
65958 - TP_PROTO(int irq, struct irqaction *action),
65959 + TP_PROTO(int irq, const struct irqaction *action),
65960
65961 TP_ARGS(irq, action),
65962
65963 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
65964 */
65965 TRACE_EVENT(irq_handler_exit,
65966
65967 - TP_PROTO(int irq, struct irqaction *action, int ret),
65968 + TP_PROTO(int irq, const struct irqaction *action, int ret),
65969
65970 TP_ARGS(irq, action, ret),
65971
65972 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
65973 index f9466fa..f4e2b81 100644
65974 --- a/include/video/udlfb.h
65975 +++ b/include/video/udlfb.h
65976 @@ -53,10 +53,10 @@ struct dlfb_data {
65977 u32 pseudo_palette[256];
65978 int blank_mode; /*one of FB_BLANK_ */
65979 /* blit-only rendering path metrics, exposed through sysfs */
65980 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
65981 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
65982 - atomic_t bytes_sent; /* to usb, after compression including overhead */
65983 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
65984 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
65985 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
65986 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
65987 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
65988 };
65989
65990 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
65991 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
65992 index 0993a22..32ba2fe 100644
65993 --- a/include/video/uvesafb.h
65994 +++ b/include/video/uvesafb.h
65995 @@ -177,6 +177,7 @@ struct uvesafb_par {
65996 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
65997 u8 pmi_setpal; /* PMI for palette changes */
65998 u16 *pmi_base; /* protected mode interface location */
65999 + u8 *pmi_code; /* protected mode code location */
66000 void *pmi_start;
66001 void *pmi_pal;
66002 u8 *vbe_state_orig; /*
66003 diff --git a/init/Kconfig b/init/Kconfig
66004 index af6c7f8..5c188f8 100644
66005 --- a/init/Kconfig
66006 +++ b/init/Kconfig
66007 @@ -850,6 +850,7 @@ endif # CGROUPS
66008
66009 config CHECKPOINT_RESTORE
66010 bool "Checkpoint/restore support" if EXPERT
66011 + depends on !GRKERNSEC
66012 default n
66013 help
66014 Enables additional kernel features in a sake of checkpoint/restore.
66015 @@ -1029,6 +1030,7 @@ config UIDGID_CONVERTED
66016 # Security modules
66017 depends on SECURITY_TOMOYO = n
66018 depends on SECURITY_APPARMOR = n
66019 + depends on GRKERNSEC = n
66020
66021 config UIDGID_STRICT_TYPE_CHECKS
66022 bool "Require conversions between uid/gids and their internal representation"
66023 @@ -1416,7 +1418,7 @@ config SLUB_DEBUG
66024
66025 config COMPAT_BRK
66026 bool "Disable heap randomization"
66027 - default y
66028 + default n
66029 help
66030 Randomizing heap placement makes heap exploits harder, but it
66031 also breaks ancient binaries (including anything libc5 based).
66032 @@ -1599,7 +1601,7 @@ config INIT_ALL_POSSIBLE
66033 config STOP_MACHINE
66034 bool
66035 default y
66036 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
66037 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
66038 help
66039 Need stop_machine() primitive.
66040
66041 diff --git a/init/Makefile b/init/Makefile
66042 index 7bc47ee..6da2dc7 100644
66043 --- a/init/Makefile
66044 +++ b/init/Makefile
66045 @@ -2,6 +2,9 @@
66046 # Makefile for the linux kernel.
66047 #
66048
66049 +ccflags-y := $(GCC_PLUGINS_CFLAGS)
66050 +asflags-y := $(GCC_PLUGINS_AFLAGS)
66051 +
66052 obj-y := main.o version.o mounts.o
66053 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
66054 obj-y += noinitramfs.o
66055 diff --git a/init/do_mounts.c b/init/do_mounts.c
66056 index d3f0aee..c9322f5 100644
66057 --- a/init/do_mounts.c
66058 +++ b/init/do_mounts.c
66059 @@ -336,11 +336,11 @@ static void __init get_fs_names(char *page)
66060 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
66061 {
66062 struct super_block *s;
66063 - int err = sys_mount(name, "/root", fs, flags, data);
66064 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
66065 if (err)
66066 return err;
66067
66068 - sys_chdir("/root");
66069 + sys_chdir((const char __force_user *)"/root");
66070 s = current->fs->pwd.dentry->d_sb;
66071 ROOT_DEV = s->s_dev;
66072 printk(KERN_INFO
66073 @@ -460,18 +460,18 @@ void __init change_floppy(char *fmt, ...)
66074 va_start(args, fmt);
66075 vsprintf(buf, fmt, args);
66076 va_end(args);
66077 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
66078 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
66079 if (fd >= 0) {
66080 sys_ioctl(fd, FDEJECT, 0);
66081 sys_close(fd);
66082 }
66083 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
66084 - fd = sys_open("/dev/console", O_RDWR, 0);
66085 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
66086 if (fd >= 0) {
66087 sys_ioctl(fd, TCGETS, (long)&termios);
66088 termios.c_lflag &= ~ICANON;
66089 sys_ioctl(fd, TCSETSF, (long)&termios);
66090 - sys_read(fd, &c, 1);
66091 + sys_read(fd, (char __user *)&c, 1);
66092 termios.c_lflag |= ICANON;
66093 sys_ioctl(fd, TCSETSF, (long)&termios);
66094 sys_close(fd);
66095 @@ -565,6 +565,6 @@ void __init prepare_namespace(void)
66096 mount_root();
66097 out:
66098 devtmpfs_mount("dev");
66099 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
66100 - sys_chroot(".");
66101 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
66102 + sys_chroot((const char __force_user *)".");
66103 }
66104 diff --git a/init/do_mounts.h b/init/do_mounts.h
66105 index f5b978a..69dbfe8 100644
66106 --- a/init/do_mounts.h
66107 +++ b/init/do_mounts.h
66108 @@ -15,15 +15,15 @@ extern int root_mountflags;
66109
66110 static inline int create_dev(char *name, dev_t dev)
66111 {
66112 - sys_unlink(name);
66113 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
66114 + sys_unlink((char __force_user *)name);
66115 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
66116 }
66117
66118 #if BITS_PER_LONG == 32
66119 static inline u32 bstat(char *name)
66120 {
66121 struct stat64 stat;
66122 - if (sys_stat64(name, &stat) != 0)
66123 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
66124 return 0;
66125 if (!S_ISBLK(stat.st_mode))
66126 return 0;
66127 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
66128 static inline u32 bstat(char *name)
66129 {
66130 struct stat stat;
66131 - if (sys_newstat(name, &stat) != 0)
66132 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
66133 return 0;
66134 if (!S_ISBLK(stat.st_mode))
66135 return 0;
66136 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
66137 index 135959a2..28a3f43 100644
66138 --- a/init/do_mounts_initrd.c
66139 +++ b/init/do_mounts_initrd.c
66140 @@ -53,13 +53,13 @@ static void __init handle_initrd(void)
66141 create_dev("/dev/root.old", Root_RAM0);
66142 /* mount initrd on rootfs' /root */
66143 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
66144 - sys_mkdir("/old", 0700);
66145 - root_fd = sys_open("/", 0, 0);
66146 - old_fd = sys_open("/old", 0, 0);
66147 + sys_mkdir((const char __force_user *)"/old", 0700);
66148 + root_fd = sys_open((const char __force_user *)"/", 0, 0);
66149 + old_fd = sys_open((const char __force_user *)"/old", 0, 0);
66150 /* move initrd over / and chdir/chroot in initrd root */
66151 - sys_chdir("/root");
66152 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
66153 - sys_chroot(".");
66154 + sys_chdir((const char __force_user *)"/root");
66155 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
66156 + sys_chroot((const char __force_user *)".");
66157
66158 /*
66159 * In case that a resume from disk is carried out by linuxrc or one of
66160 @@ -76,15 +76,15 @@ static void __init handle_initrd(void)
66161
66162 /* move initrd to rootfs' /old */
66163 sys_fchdir(old_fd);
66164 - sys_mount("/", ".", NULL, MS_MOVE, NULL);
66165 + sys_mount((char __force_user *)"/", (char __force_user *)".", NULL, MS_MOVE, NULL);
66166 /* switch root and cwd back to / of rootfs */
66167 sys_fchdir(root_fd);
66168 - sys_chroot(".");
66169 + sys_chroot((const char __force_user *)".");
66170 sys_close(old_fd);
66171 sys_close(root_fd);
66172
66173 if (new_decode_dev(real_root_dev) == Root_RAM0) {
66174 - sys_chdir("/old");
66175 + sys_chdir((const char __force_user *)"/old");
66176 return;
66177 }
66178
66179 @@ -92,17 +92,17 @@ static void __init handle_initrd(void)
66180 mount_root();
66181
66182 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
66183 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
66184 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
66185 if (!error)
66186 printk("okay\n");
66187 else {
66188 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
66189 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
66190 if (error == -ENOENT)
66191 printk("/initrd does not exist. Ignored.\n");
66192 else
66193 printk("failed\n");
66194 printk(KERN_NOTICE "Unmounting old root\n");
66195 - sys_umount("/old", MNT_DETACH);
66196 + sys_umount((char __force_user *)"/old", MNT_DETACH);
66197 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
66198 if (fd < 0) {
66199 error = fd;
66200 @@ -125,11 +125,11 @@ int __init initrd_load(void)
66201 * mounted in the normal path.
66202 */
66203 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
66204 - sys_unlink("/initrd.image");
66205 + sys_unlink((const char __force_user *)"/initrd.image");
66206 handle_initrd();
66207 return 1;
66208 }
66209 }
66210 - sys_unlink("/initrd.image");
66211 + sys_unlink((const char __force_user *)"/initrd.image");
66212 return 0;
66213 }
66214 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
66215 index 8cb6db5..d729f50 100644
66216 --- a/init/do_mounts_md.c
66217 +++ b/init/do_mounts_md.c
66218 @@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
66219 partitioned ? "_d" : "", minor,
66220 md_setup_args[ent].device_names);
66221
66222 - fd = sys_open(name, 0, 0);
66223 + fd = sys_open((char __force_user *)name, 0, 0);
66224 if (fd < 0) {
66225 printk(KERN_ERR "md: open failed - cannot start "
66226 "array %s\n", name);
66227 @@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
66228 * array without it
66229 */
66230 sys_close(fd);
66231 - fd = sys_open(name, 0, 0);
66232 + fd = sys_open((char __force_user *)name, 0, 0);
66233 sys_ioctl(fd, BLKRRPART, 0);
66234 }
66235 sys_close(fd);
66236 @@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
66237
66238 wait_for_device_probe();
66239
66240 - fd = sys_open("/dev/md0", 0, 0);
66241 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
66242 if (fd >= 0) {
66243 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
66244 sys_close(fd);
66245 diff --git a/init/init_task.c b/init/init_task.c
66246 index 8b2f399..f0797c9 100644
66247 --- a/init/init_task.c
66248 +++ b/init/init_task.c
66249 @@ -20,5 +20,9 @@ EXPORT_SYMBOL(init_task);
66250 * Initial thread structure. Alignment of this is handled by a special
66251 * linker map entry.
66252 */
66253 +#ifdef CONFIG_X86
66254 +union thread_union init_thread_union __init_task_data;
66255 +#else
66256 union thread_union init_thread_union __init_task_data =
66257 { INIT_THREAD_INFO(init_task) };
66258 +#endif
66259 diff --git a/init/initramfs.c b/init/initramfs.c
66260 index 84c6bf1..8899338 100644
66261 --- a/init/initramfs.c
66262 +++ b/init/initramfs.c
66263 @@ -84,7 +84,7 @@ static void __init free_hash(void)
66264 }
66265 }
66266
66267 -static long __init do_utime(char *filename, time_t mtime)
66268 +static long __init do_utime(char __force_user *filename, time_t mtime)
66269 {
66270 struct timespec t[2];
66271
66272 @@ -119,7 +119,7 @@ static void __init dir_utime(void)
66273 struct dir_entry *de, *tmp;
66274 list_for_each_entry_safe(de, tmp, &dir_list, list) {
66275 list_del(&de->list);
66276 - do_utime(de->name, de->mtime);
66277 + do_utime((char __force_user *)de->name, de->mtime);
66278 kfree(de->name);
66279 kfree(de);
66280 }
66281 @@ -281,7 +281,7 @@ static int __init maybe_link(void)
66282 if (nlink >= 2) {
66283 char *old = find_link(major, minor, ino, mode, collected);
66284 if (old)
66285 - return (sys_link(old, collected) < 0) ? -1 : 1;
66286 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
66287 }
66288 return 0;
66289 }
66290 @@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
66291 {
66292 struct stat st;
66293
66294 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
66295 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
66296 if (S_ISDIR(st.st_mode))
66297 - sys_rmdir(path);
66298 + sys_rmdir((char __force_user *)path);
66299 else
66300 - sys_unlink(path);
66301 + sys_unlink((char __force_user *)path);
66302 }
66303 }
66304
66305 @@ -315,7 +315,7 @@ static int __init do_name(void)
66306 int openflags = O_WRONLY|O_CREAT;
66307 if (ml != 1)
66308 openflags |= O_TRUNC;
66309 - wfd = sys_open(collected, openflags, mode);
66310 + wfd = sys_open((char __force_user *)collected, openflags, mode);
66311
66312 if (wfd >= 0) {
66313 sys_fchown(wfd, uid, gid);
66314 @@ -327,17 +327,17 @@ static int __init do_name(void)
66315 }
66316 }
66317 } else if (S_ISDIR(mode)) {
66318 - sys_mkdir(collected, mode);
66319 - sys_chown(collected, uid, gid);
66320 - sys_chmod(collected, mode);
66321 + sys_mkdir((char __force_user *)collected, mode);
66322 + sys_chown((char __force_user *)collected, uid, gid);
66323 + sys_chmod((char __force_user *)collected, mode);
66324 dir_add(collected, mtime);
66325 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
66326 S_ISFIFO(mode) || S_ISSOCK(mode)) {
66327 if (maybe_link() == 0) {
66328 - sys_mknod(collected, mode, rdev);
66329 - sys_chown(collected, uid, gid);
66330 - sys_chmod(collected, mode);
66331 - do_utime(collected, mtime);
66332 + sys_mknod((char __force_user *)collected, mode, rdev);
66333 + sys_chown((char __force_user *)collected, uid, gid);
66334 + sys_chmod((char __force_user *)collected, mode);
66335 + do_utime((char __force_user *)collected, mtime);
66336 }
66337 }
66338 return 0;
66339 @@ -346,15 +346,15 @@ static int __init do_name(void)
66340 static int __init do_copy(void)
66341 {
66342 if (count >= body_len) {
66343 - sys_write(wfd, victim, body_len);
66344 + sys_write(wfd, (char __force_user *)victim, body_len);
66345 sys_close(wfd);
66346 - do_utime(vcollected, mtime);
66347 + do_utime((char __force_user *)vcollected, mtime);
66348 kfree(vcollected);
66349 eat(body_len);
66350 state = SkipIt;
66351 return 0;
66352 } else {
66353 - sys_write(wfd, victim, count);
66354 + sys_write(wfd, (char __force_user *)victim, count);
66355 body_len -= count;
66356 eat(count);
66357 return 1;
66358 @@ -365,9 +365,9 @@ static int __init do_symlink(void)
66359 {
66360 collected[N_ALIGN(name_len) + body_len] = '\0';
66361 clean_path(collected, 0);
66362 - sys_symlink(collected + N_ALIGN(name_len), collected);
66363 - sys_lchown(collected, uid, gid);
66364 - do_utime(collected, mtime);
66365 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
66366 + sys_lchown((char __force_user *)collected, uid, gid);
66367 + do_utime((char __force_user *)collected, mtime);
66368 state = SkipIt;
66369 next_state = Reset;
66370 return 0;
66371 diff --git a/init/main.c b/init/main.c
66372 index d61ec54..bd3144f 100644
66373 --- a/init/main.c
66374 +++ b/init/main.c
66375 @@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
66376 extern void tc_init(void);
66377 #endif
66378
66379 +extern void grsecurity_init(void);
66380 +
66381 /*
66382 * Debug helper: via this flag we know that we are in 'early bootup code'
66383 * where only the boot processor is running with IRQ disabled. This means
66384 @@ -149,6 +151,61 @@ static int __init set_reset_devices(char *str)
66385
66386 __setup("reset_devices", set_reset_devices);
66387
66388 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66389 +int grsec_proc_gid = CONFIG_GRKERNSEC_PROC_GID;
66390 +static int __init setup_grsec_proc_gid(char *str)
66391 +{
66392 + grsec_proc_gid = (int)simple_strtol(str, NULL, 0);
66393 + return 1;
66394 +}
66395 +__setup("grsec_proc_gid=", setup_grsec_proc_gid);
66396 +#endif
66397 +
66398 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
66399 +extern char pax_enter_kernel_user[];
66400 +extern char pax_exit_kernel_user[];
66401 +extern pgdval_t clone_pgd_mask;
66402 +#endif
66403 +
66404 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
66405 +static int __init setup_pax_nouderef(char *str)
66406 +{
66407 +#ifdef CONFIG_X86_32
66408 + unsigned int cpu;
66409 + struct desc_struct *gdt;
66410 +
66411 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
66412 + gdt = get_cpu_gdt_table(cpu);
66413 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
66414 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
66415 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
66416 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
66417 + }
66418 + loadsegment(ds, __KERNEL_DS);
66419 + loadsegment(es, __KERNEL_DS);
66420 + loadsegment(ss, __KERNEL_DS);
66421 +#else
66422 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
66423 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
66424 + clone_pgd_mask = ~(pgdval_t)0UL;
66425 +#endif
66426 +
66427 + return 0;
66428 +}
66429 +early_param("pax_nouderef", setup_pax_nouderef);
66430 +#endif
66431 +
66432 +#ifdef CONFIG_PAX_SOFTMODE
66433 +int pax_softmode;
66434 +
66435 +static int __init setup_pax_softmode(char *str)
66436 +{
66437 + get_option(&str, &pax_softmode);
66438 + return 1;
66439 +}
66440 +__setup("pax_softmode=", setup_pax_softmode);
66441 +#endif
66442 +
66443 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
66444 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
66445 static const char *panic_later, *panic_param;
66446 @@ -678,6 +735,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
66447 {
66448 int count = preempt_count();
66449 int ret;
66450 + const char *msg1 = "", *msg2 = "";
66451
66452 if (initcall_debug)
66453 ret = do_one_initcall_debug(fn);
66454 @@ -690,15 +748,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
66455 sprintf(msgbuf, "error code %d ", ret);
66456
66457 if (preempt_count() != count) {
66458 - strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
66459 + msg1 = " preemption imbalance";
66460 preempt_count() = count;
66461 }
66462 if (irqs_disabled()) {
66463 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
66464 + msg2 = " disabled interrupts";
66465 local_irq_enable();
66466 }
66467 - if (msgbuf[0]) {
66468 - printk("initcall %pF returned with %s\n", fn, msgbuf);
66469 + if (msgbuf[0] || *msg1 || *msg2) {
66470 + printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
66471 }
66472
66473 return ret;
66474 @@ -752,8 +810,14 @@ static void __init do_initcall_level(int level)
66475 level, level,
66476 &repair_env_string);
66477
66478 - for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
66479 + for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
66480 do_one_initcall(*fn);
66481 +
66482 +#ifdef CONFIG_PAX_LATENT_ENTROPY
66483 + transfer_latent_entropy();
66484 +#endif
66485 +
66486 + }
66487 }
66488
66489 static void __init do_initcalls(void)
66490 @@ -787,8 +851,14 @@ static void __init do_pre_smp_initcalls(void)
66491 {
66492 initcall_t *fn;
66493
66494 - for (fn = __initcall_start; fn < __initcall0_start; fn++)
66495 + for (fn = __initcall_start; fn < __initcall0_start; fn++) {
66496 do_one_initcall(*fn);
66497 +
66498 +#ifdef CONFIG_PAX_LATENT_ENTROPY
66499 + transfer_latent_entropy();
66500 +#endif
66501 +
66502 + }
66503 }
66504
66505 static void run_init_process(const char *init_filename)
66506 @@ -870,7 +940,7 @@ static int __init kernel_init(void * unused)
66507 do_basic_setup();
66508
66509 /* Open the /dev/console on the rootfs, this should never fail */
66510 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
66511 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
66512 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
66513
66514 (void) sys_dup(0);
66515 @@ -883,11 +953,13 @@ static int __init kernel_init(void * unused)
66516 if (!ramdisk_execute_command)
66517 ramdisk_execute_command = "/init";
66518
66519 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
66520 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
66521 ramdisk_execute_command = NULL;
66522 prepare_namespace();
66523 }
66524
66525 + grsecurity_init();
66526 +
66527 /*
66528 * Ok, we have completed the initial bootup, and
66529 * we're essentially up and running. Get rid of the
66530 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
66531 index 9a08acc..e65ebe7 100644
66532 --- a/ipc/mqueue.c
66533 +++ b/ipc/mqueue.c
66534 @@ -279,6 +279,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
66535 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
66536 info->attr.mq_msgsize);
66537
66538 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
66539 spin_lock(&mq_lock);
66540 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
66541 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
66542 diff --git a/ipc/msg.c b/ipc/msg.c
66543 index 7385de2..a8180e08 100644
66544 --- a/ipc/msg.c
66545 +++ b/ipc/msg.c
66546 @@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
66547 return security_msg_queue_associate(msq, msgflg);
66548 }
66549
66550 +static struct ipc_ops msg_ops = {
66551 + .getnew = newque,
66552 + .associate = msg_security,
66553 + .more_checks = NULL
66554 +};
66555 +
66556 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
66557 {
66558 struct ipc_namespace *ns;
66559 - struct ipc_ops msg_ops;
66560 struct ipc_params msg_params;
66561
66562 ns = current->nsproxy->ipc_ns;
66563
66564 - msg_ops.getnew = newque;
66565 - msg_ops.associate = msg_security;
66566 - msg_ops.more_checks = NULL;
66567 -
66568 msg_params.key = key;
66569 msg_params.flg = msgflg;
66570
66571 diff --git a/ipc/sem.c b/ipc/sem.c
66572 index 5215a81..cfc0cac 100644
66573 --- a/ipc/sem.c
66574 +++ b/ipc/sem.c
66575 @@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
66576 return 0;
66577 }
66578
66579 +static struct ipc_ops sem_ops = {
66580 + .getnew = newary,
66581 + .associate = sem_security,
66582 + .more_checks = sem_more_checks
66583 +};
66584 +
66585 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
66586 {
66587 struct ipc_namespace *ns;
66588 - struct ipc_ops sem_ops;
66589 struct ipc_params sem_params;
66590
66591 ns = current->nsproxy->ipc_ns;
66592 @@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
66593 if (nsems < 0 || nsems > ns->sc_semmsl)
66594 return -EINVAL;
66595
66596 - sem_ops.getnew = newary;
66597 - sem_ops.associate = sem_security;
66598 - sem_ops.more_checks = sem_more_checks;
66599 -
66600 sem_params.key = key;
66601 sem_params.flg = semflg;
66602 sem_params.u.nsems = nsems;
66603 diff --git a/ipc/shm.c b/ipc/shm.c
66604 index 00faa05..7040960 100644
66605 --- a/ipc/shm.c
66606 +++ b/ipc/shm.c
66607 @@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
66608 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
66609 #endif
66610
66611 +#ifdef CONFIG_GRKERNSEC
66612 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
66613 + const time_t shm_createtime, const uid_t cuid,
66614 + const int shmid);
66615 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
66616 + const time_t shm_createtime);
66617 +#endif
66618 +
66619 void shm_init_ns(struct ipc_namespace *ns)
66620 {
66621 ns->shm_ctlmax = SHMMAX;
66622 @@ -520,6 +528,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
66623 shp->shm_lprid = 0;
66624 shp->shm_atim = shp->shm_dtim = 0;
66625 shp->shm_ctim = get_seconds();
66626 +#ifdef CONFIG_GRKERNSEC
66627 + {
66628 + struct timespec timeval;
66629 + do_posix_clock_monotonic_gettime(&timeval);
66630 +
66631 + shp->shm_createtime = timeval.tv_sec;
66632 + }
66633 +#endif
66634 shp->shm_segsz = size;
66635 shp->shm_nattch = 0;
66636 shp->shm_file = file;
66637 @@ -571,18 +587,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
66638 return 0;
66639 }
66640
66641 +static struct ipc_ops shm_ops = {
66642 + .getnew = newseg,
66643 + .associate = shm_security,
66644 + .more_checks = shm_more_checks
66645 +};
66646 +
66647 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
66648 {
66649 struct ipc_namespace *ns;
66650 - struct ipc_ops shm_ops;
66651 struct ipc_params shm_params;
66652
66653 ns = current->nsproxy->ipc_ns;
66654
66655 - shm_ops.getnew = newseg;
66656 - shm_ops.associate = shm_security;
66657 - shm_ops.more_checks = shm_more_checks;
66658 -
66659 shm_params.key = key;
66660 shm_params.flg = shmflg;
66661 shm_params.u.size = size;
66662 @@ -1001,6 +1018,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
66663 f_mode = FMODE_READ | FMODE_WRITE;
66664 }
66665 if (shmflg & SHM_EXEC) {
66666 +
66667 +#ifdef CONFIG_PAX_MPROTECT
66668 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
66669 + goto out;
66670 +#endif
66671 +
66672 prot |= PROT_EXEC;
66673 acc_mode |= S_IXUGO;
66674 }
66675 @@ -1024,9 +1047,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
66676 if (err)
66677 goto out_unlock;
66678
66679 +#ifdef CONFIG_GRKERNSEC
66680 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
66681 + shp->shm_perm.cuid, shmid) ||
66682 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
66683 + err = -EACCES;
66684 + goto out_unlock;
66685 + }
66686 +#endif
66687 +
66688 path = shp->shm_file->f_path;
66689 path_get(&path);
66690 shp->shm_nattch++;
66691 +#ifdef CONFIG_GRKERNSEC
66692 + shp->shm_lapid = current->pid;
66693 +#endif
66694 size = i_size_read(path.dentry->d_inode);
66695 shm_unlock(shp);
66696
66697 diff --git a/kernel/acct.c b/kernel/acct.c
66698 index 02e6167..54824f7 100644
66699 --- a/kernel/acct.c
66700 +++ b/kernel/acct.c
66701 @@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
66702 */
66703 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
66704 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
66705 - file->f_op->write(file, (char *)&ac,
66706 + file->f_op->write(file, (char __force_user *)&ac,
66707 sizeof(acct_t), &file->f_pos);
66708 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
66709 set_fs(fs);
66710 diff --git a/kernel/audit.c b/kernel/audit.c
66711 index a8c84be..8bd034c 100644
66712 --- a/kernel/audit.c
66713 +++ b/kernel/audit.c
66714 @@ -115,7 +115,7 @@ u32 audit_sig_sid = 0;
66715 3) suppressed due to audit_rate_limit
66716 4) suppressed due to audit_backlog_limit
66717 */
66718 -static atomic_t audit_lost = ATOMIC_INIT(0);
66719 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
66720
66721 /* The netlink socket. */
66722 static struct sock *audit_sock;
66723 @@ -237,7 +237,7 @@ void audit_log_lost(const char *message)
66724 unsigned long now;
66725 int print;
66726
66727 - atomic_inc(&audit_lost);
66728 + atomic_inc_unchecked(&audit_lost);
66729
66730 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
66731
66732 @@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
66733 printk(KERN_WARNING
66734 "audit: audit_lost=%d audit_rate_limit=%d "
66735 "audit_backlog_limit=%d\n",
66736 - atomic_read(&audit_lost),
66737 + atomic_read_unchecked(&audit_lost),
66738 audit_rate_limit,
66739 audit_backlog_limit);
66740 audit_panic(message);
66741 @@ -690,7 +690,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
66742 status_set.pid = audit_pid;
66743 status_set.rate_limit = audit_rate_limit;
66744 status_set.backlog_limit = audit_backlog_limit;
66745 - status_set.lost = atomic_read(&audit_lost);
66746 + status_set.lost = atomic_read_unchecked(&audit_lost);
66747 status_set.backlog = skb_queue_len(&audit_skb_queue);
66748 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
66749 &status_set, sizeof(status_set));
66750 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
66751 index 4b96415..d8c16ee 100644
66752 --- a/kernel/auditsc.c
66753 +++ b/kernel/auditsc.c
66754 @@ -2289,7 +2289,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
66755 }
66756
66757 /* global counter which is incremented every time something logs in */
66758 -static atomic_t session_id = ATOMIC_INIT(0);
66759 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
66760
66761 /**
66762 * audit_set_loginuid - set current task's audit_context loginuid
66763 @@ -2313,7 +2313,7 @@ int audit_set_loginuid(uid_t loginuid)
66764 return -EPERM;
66765 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
66766
66767 - sessionid = atomic_inc_return(&session_id);
66768 + sessionid = atomic_inc_return_unchecked(&session_id);
66769 if (context && context->in_syscall) {
66770 struct audit_buffer *ab;
66771
66772 diff --git a/kernel/capability.c b/kernel/capability.c
66773 index 493d972..ea17248 100644
66774 --- a/kernel/capability.c
66775 +++ b/kernel/capability.c
66776 @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
66777 * before modification is attempted and the application
66778 * fails.
66779 */
66780 + if (tocopy > ARRAY_SIZE(kdata))
66781 + return -EFAULT;
66782 +
66783 if (copy_to_user(dataptr, kdata, tocopy
66784 * sizeof(struct __user_cap_data_struct))) {
66785 return -EFAULT;
66786 @@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
66787 int ret;
66788
66789 rcu_read_lock();
66790 - ret = security_capable(__task_cred(t), ns, cap);
66791 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
66792 + gr_task_is_capable(t, __task_cred(t), cap);
66793 rcu_read_unlock();
66794
66795 - return (ret == 0);
66796 + return ret;
66797 }
66798
66799 /**
66800 @@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
66801 int ret;
66802
66803 rcu_read_lock();
66804 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
66805 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
66806 rcu_read_unlock();
66807
66808 - return (ret == 0);
66809 + return ret;
66810 }
66811
66812 /**
66813 @@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
66814 BUG();
66815 }
66816
66817 - if (security_capable(current_cred(), ns, cap) == 0) {
66818 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
66819 current->flags |= PF_SUPERPRIV;
66820 return true;
66821 }
66822 @@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
66823 }
66824 EXPORT_SYMBOL(ns_capable);
66825
66826 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
66827 +{
66828 + if (unlikely(!cap_valid(cap))) {
66829 + printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
66830 + BUG();
66831 + }
66832 +
66833 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
66834 + current->flags |= PF_SUPERPRIV;
66835 + return true;
66836 + }
66837 + return false;
66838 +}
66839 +EXPORT_SYMBOL(ns_capable_nolog);
66840 +
66841 /**
66842 * capable - Determine if the current task has a superior capability in effect
66843 * @cap: The capability to be tested for
66844 @@ -408,6 +427,12 @@ bool capable(int cap)
66845 }
66846 EXPORT_SYMBOL(capable);
66847
66848 +bool capable_nolog(int cap)
66849 +{
66850 + return ns_capable_nolog(&init_user_ns, cap);
66851 +}
66852 +EXPORT_SYMBOL(capable_nolog);
66853 +
66854 /**
66855 * nsown_capable - Check superior capability to one's own user_ns
66856 * @cap: The capability in question
66857 @@ -440,3 +465,10 @@ bool inode_capable(const struct inode *inode, int cap)
66858
66859 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
66860 }
66861 +
66862 +bool inode_capable_nolog(const struct inode *inode, int cap)
66863 +{
66864 + struct user_namespace *ns = current_user_ns();
66865 +
66866 + return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
66867 +}
66868 diff --git a/kernel/cgroup.c b/kernel/cgroup.c
66869 index ff2bce5..a41e8f9 100644
66870 --- a/kernel/cgroup.c
66871 +++ b/kernel/cgroup.c
66872 @@ -5390,7 +5390,7 @@ static int cgroup_css_links_read(struct cgroup *cont,
66873 struct css_set *cg = link->cg;
66874 struct task_struct *task;
66875 int count = 0;
66876 - seq_printf(seq, "css_set %p\n", cg);
66877 + seq_printf(seq, "css_set %pK\n", cg);
66878 list_for_each_entry(task, &cg->tasks, cg_list) {
66879 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
66880 seq_puts(seq, " ...\n");
66881 diff --git a/kernel/compat.c b/kernel/compat.c
66882 index c28a306..b4d0cf3 100644
66883 --- a/kernel/compat.c
66884 +++ b/kernel/compat.c
66885 @@ -13,6 +13,7 @@
66886
66887 #include <linux/linkage.h>
66888 #include <linux/compat.h>
66889 +#include <linux/module.h>
66890 #include <linux/errno.h>
66891 #include <linux/time.h>
66892 #include <linux/signal.h>
66893 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
66894 mm_segment_t oldfs;
66895 long ret;
66896
66897 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
66898 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
66899 oldfs = get_fs();
66900 set_fs(KERNEL_DS);
66901 ret = hrtimer_nanosleep_restart(restart);
66902 @@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
66903 oldfs = get_fs();
66904 set_fs(KERNEL_DS);
66905 ret = hrtimer_nanosleep(&tu,
66906 - rmtp ? (struct timespec __user *)&rmt : NULL,
66907 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
66908 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
66909 set_fs(oldfs);
66910
66911 @@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
66912 mm_segment_t old_fs = get_fs();
66913
66914 set_fs(KERNEL_DS);
66915 - ret = sys_sigpending((old_sigset_t __user *) &s);
66916 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
66917 set_fs(old_fs);
66918 if (ret == 0)
66919 ret = put_user(s, set);
66920 @@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
66921 mm_segment_t old_fs = get_fs();
66922
66923 set_fs(KERNEL_DS);
66924 - ret = sys_old_getrlimit(resource, &r);
66925 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
66926 set_fs(old_fs);
66927
66928 if (!ret) {
66929 @@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
66930 mm_segment_t old_fs = get_fs();
66931
66932 set_fs(KERNEL_DS);
66933 - ret = sys_getrusage(who, (struct rusage __user *) &r);
66934 + ret = sys_getrusage(who, (struct rusage __force_user *) &r);
66935 set_fs(old_fs);
66936
66937 if (ret)
66938 @@ -550,8 +551,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
66939 set_fs (KERNEL_DS);
66940 ret = sys_wait4(pid,
66941 (stat_addr ?
66942 - (unsigned int __user *) &status : NULL),
66943 - options, (struct rusage __user *) &r);
66944 + (unsigned int __force_user *) &status : NULL),
66945 + options, (struct rusage __force_user *) &r);
66946 set_fs (old_fs);
66947
66948 if (ret > 0) {
66949 @@ -576,8 +577,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
66950 memset(&info, 0, sizeof(info));
66951
66952 set_fs(KERNEL_DS);
66953 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
66954 - uru ? (struct rusage __user *)&ru : NULL);
66955 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
66956 + uru ? (struct rusage __force_user *)&ru : NULL);
66957 set_fs(old_fs);
66958
66959 if ((ret < 0) || (info.si_signo == 0))
66960 @@ -707,8 +708,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
66961 oldfs = get_fs();
66962 set_fs(KERNEL_DS);
66963 err = sys_timer_settime(timer_id, flags,
66964 - (struct itimerspec __user *) &newts,
66965 - (struct itimerspec __user *) &oldts);
66966 + (struct itimerspec __force_user *) &newts,
66967 + (struct itimerspec __force_user *) &oldts);
66968 set_fs(oldfs);
66969 if (!err && old && put_compat_itimerspec(old, &oldts))
66970 return -EFAULT;
66971 @@ -725,7 +726,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
66972 oldfs = get_fs();
66973 set_fs(KERNEL_DS);
66974 err = sys_timer_gettime(timer_id,
66975 - (struct itimerspec __user *) &ts);
66976 + (struct itimerspec __force_user *) &ts);
66977 set_fs(oldfs);
66978 if (!err && put_compat_itimerspec(setting, &ts))
66979 return -EFAULT;
66980 @@ -744,7 +745,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
66981 oldfs = get_fs();
66982 set_fs(KERNEL_DS);
66983 err = sys_clock_settime(which_clock,
66984 - (struct timespec __user *) &ts);
66985 + (struct timespec __force_user *) &ts);
66986 set_fs(oldfs);
66987 return err;
66988 }
66989 @@ -759,7 +760,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
66990 oldfs = get_fs();
66991 set_fs(KERNEL_DS);
66992 err = sys_clock_gettime(which_clock,
66993 - (struct timespec __user *) &ts);
66994 + (struct timespec __force_user *) &ts);
66995 set_fs(oldfs);
66996 if (!err && put_compat_timespec(&ts, tp))
66997 return -EFAULT;
66998 @@ -779,7 +780,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
66999
67000 oldfs = get_fs();
67001 set_fs(KERNEL_DS);
67002 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
67003 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
67004 set_fs(oldfs);
67005
67006 err = compat_put_timex(utp, &txc);
67007 @@ -799,7 +800,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
67008 oldfs = get_fs();
67009 set_fs(KERNEL_DS);
67010 err = sys_clock_getres(which_clock,
67011 - (struct timespec __user *) &ts);
67012 + (struct timespec __force_user *) &ts);
67013 set_fs(oldfs);
67014 if (!err && tp && put_compat_timespec(&ts, tp))
67015 return -EFAULT;
67016 @@ -811,9 +812,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
67017 long err;
67018 mm_segment_t oldfs;
67019 struct timespec tu;
67020 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
67021 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
67022
67023 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
67024 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
67025 oldfs = get_fs();
67026 set_fs(KERNEL_DS);
67027 err = clock_nanosleep_restart(restart);
67028 @@ -845,8 +846,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
67029 oldfs = get_fs();
67030 set_fs(KERNEL_DS);
67031 err = sys_clock_nanosleep(which_clock, flags,
67032 - (struct timespec __user *) &in,
67033 - (struct timespec __user *) &out);
67034 + (struct timespec __force_user *) &in,
67035 + (struct timespec __force_user *) &out);
67036 set_fs(oldfs);
67037
67038 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
67039 diff --git a/kernel/configs.c b/kernel/configs.c
67040 index 42e8fa0..9e7406b 100644
67041 --- a/kernel/configs.c
67042 +++ b/kernel/configs.c
67043 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
67044 struct proc_dir_entry *entry;
67045
67046 /* create the current config file */
67047 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
67048 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
67049 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
67050 + &ikconfig_file_ops);
67051 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67052 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
67053 + &ikconfig_file_ops);
67054 +#endif
67055 +#else
67056 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
67057 &ikconfig_file_ops);
67058 +#endif
67059 +
67060 if (!entry)
67061 return -ENOMEM;
67062
67063 diff --git a/kernel/cred.c b/kernel/cred.c
67064 index de728ac..e3c267c 100644
67065 --- a/kernel/cred.c
67066 +++ b/kernel/cred.c
67067 @@ -207,6 +207,16 @@ void exit_creds(struct task_struct *tsk)
67068 validate_creds(cred);
67069 alter_cred_subscribers(cred, -1);
67070 put_cred(cred);
67071 +
67072 +#ifdef CONFIG_GRKERNSEC_SETXID
67073 + cred = (struct cred *) tsk->delayed_cred;
67074 + if (cred != NULL) {
67075 + tsk->delayed_cred = NULL;
67076 + validate_creds(cred);
67077 + alter_cred_subscribers(cred, -1);
67078 + put_cred(cred);
67079 + }
67080 +#endif
67081 }
67082
67083 /**
67084 @@ -469,7 +479,7 @@ error_put:
67085 * Always returns 0 thus allowing this function to be tail-called at the end
67086 * of, say, sys_setgid().
67087 */
67088 -int commit_creds(struct cred *new)
67089 +static int __commit_creds(struct cred *new)
67090 {
67091 struct task_struct *task = current;
67092 const struct cred *old = task->real_cred;
67093 @@ -488,6 +498,8 @@ int commit_creds(struct cred *new)
67094
67095 get_cred(new); /* we will require a ref for the subj creds too */
67096
67097 + gr_set_role_label(task, new->uid, new->gid);
67098 +
67099 /* dumpability changes */
67100 if (!uid_eq(old->euid, new->euid) ||
67101 !gid_eq(old->egid, new->egid) ||
67102 @@ -537,6 +549,101 @@ int commit_creds(struct cred *new)
67103 put_cred(old);
67104 return 0;
67105 }
67106 +#ifdef CONFIG_GRKERNSEC_SETXID
67107 +extern int set_user(struct cred *new);
67108 +
67109 +void gr_delayed_cred_worker(void)
67110 +{
67111 + const struct cred *new = current->delayed_cred;
67112 + struct cred *ncred;
67113 +
67114 + current->delayed_cred = NULL;
67115 +
67116 + if (current_uid() && new != NULL) {
67117 + // from doing get_cred on it when queueing this
67118 + put_cred(new);
67119 + return;
67120 + } else if (new == NULL)
67121 + return;
67122 +
67123 + ncred = prepare_creds();
67124 + if (!ncred)
67125 + goto die;
67126 + // uids
67127 + ncred->uid = new->uid;
67128 + ncred->euid = new->euid;
67129 + ncred->suid = new->suid;
67130 + ncred->fsuid = new->fsuid;
67131 + // gids
67132 + ncred->gid = new->gid;
67133 + ncred->egid = new->egid;
67134 + ncred->sgid = new->sgid;
67135 + ncred->fsgid = new->fsgid;
67136 + // groups
67137 + if (set_groups(ncred, new->group_info) < 0) {
67138 + abort_creds(ncred);
67139 + goto die;
67140 + }
67141 + // caps
67142 + ncred->securebits = new->securebits;
67143 + ncred->cap_inheritable = new->cap_inheritable;
67144 + ncred->cap_permitted = new->cap_permitted;
67145 + ncred->cap_effective = new->cap_effective;
67146 + ncred->cap_bset = new->cap_bset;
67147 +
67148 + if (set_user(ncred)) {
67149 + abort_creds(ncred);
67150 + goto die;
67151 + }
67152 +
67153 + // from doing get_cred on it when queueing this
67154 + put_cred(new);
67155 +
67156 + __commit_creds(ncred);
67157 + return;
67158 +die:
67159 + // from doing get_cred on it when queueing this
67160 + put_cred(new);
67161 + do_group_exit(SIGKILL);
67162 +}
67163 +#endif
67164 +
67165 +int commit_creds(struct cred *new)
67166 +{
67167 +#ifdef CONFIG_GRKERNSEC_SETXID
67168 + int ret;
67169 + int schedule_it = 0;
67170 + struct task_struct *t;
67171 +
67172 + /* we won't get called with tasklist_lock held for writing
67173 + and interrupts disabled as the cred struct in that case is
67174 + init_cred
67175 + */
67176 + if (grsec_enable_setxid && !current_is_single_threaded() &&
67177 + !current_uid() && new->uid) {
67178 + schedule_it = 1;
67179 + }
67180 + ret = __commit_creds(new);
67181 + if (schedule_it) {
67182 + rcu_read_lock();
67183 + read_lock(&tasklist_lock);
67184 + for (t = next_thread(current); t != current;
67185 + t = next_thread(t)) {
67186 + if (t->delayed_cred == NULL) {
67187 + t->delayed_cred = get_cred(new);
67188 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
67189 + set_tsk_need_resched(t);
67190 + }
67191 + }
67192 + read_unlock(&tasklist_lock);
67193 + rcu_read_unlock();
67194 + }
67195 + return ret;
67196 +#else
67197 + return __commit_creds(new);
67198 +#endif
67199 +}
67200 +
67201 EXPORT_SYMBOL(commit_creds);
67202
67203 /**
67204 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
67205 index 0557f24..1a00d9a 100644
67206 --- a/kernel/debug/debug_core.c
67207 +++ b/kernel/debug/debug_core.c
67208 @@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
67209 */
67210 static atomic_t masters_in_kgdb;
67211 static atomic_t slaves_in_kgdb;
67212 -static atomic_t kgdb_break_tasklet_var;
67213 +static atomic_unchecked_t kgdb_break_tasklet_var;
67214 atomic_t kgdb_setting_breakpoint;
67215
67216 struct task_struct *kgdb_usethread;
67217 @@ -132,7 +132,7 @@ int kgdb_single_step;
67218 static pid_t kgdb_sstep_pid;
67219
67220 /* to keep track of the CPU which is doing the single stepping*/
67221 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
67222 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
67223
67224 /*
67225 * If you are debugging a problem where roundup (the collection of
67226 @@ -540,7 +540,7 @@ return_normal:
67227 * kernel will only try for the value of sstep_tries before
67228 * giving up and continuing on.
67229 */
67230 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
67231 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
67232 (kgdb_info[cpu].task &&
67233 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
67234 atomic_set(&kgdb_active, -1);
67235 @@ -634,8 +634,8 @@ cpu_master_loop:
67236 }
67237
67238 kgdb_restore:
67239 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
67240 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
67241 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
67242 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
67243 if (kgdb_info[sstep_cpu].task)
67244 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
67245 else
67246 @@ -861,18 +861,18 @@ static void kgdb_unregister_callbacks(void)
67247 static void kgdb_tasklet_bpt(unsigned long ing)
67248 {
67249 kgdb_breakpoint();
67250 - atomic_set(&kgdb_break_tasklet_var, 0);
67251 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
67252 }
67253
67254 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
67255
67256 void kgdb_schedule_breakpoint(void)
67257 {
67258 - if (atomic_read(&kgdb_break_tasklet_var) ||
67259 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
67260 atomic_read(&kgdb_active) != -1 ||
67261 atomic_read(&kgdb_setting_breakpoint))
67262 return;
67263 - atomic_inc(&kgdb_break_tasklet_var);
67264 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
67265 tasklet_schedule(&kgdb_tasklet_breakpoint);
67266 }
67267 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
67268 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
67269 index 31df170..bc98840 100644
67270 --- a/kernel/debug/kdb/kdb_main.c
67271 +++ b/kernel/debug/kdb/kdb_main.c
67272 @@ -1971,7 +1971,7 @@ static int kdb_lsmod(int argc, const char **argv)
67273 list_for_each_entry(mod, kdb_modules, list) {
67274
67275 kdb_printf("%-20s%8u 0x%p ", mod->name,
67276 - mod->core_size, (void *)mod);
67277 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
67278 #ifdef CONFIG_MODULE_UNLOAD
67279 kdb_printf("%4ld ", module_refcount(mod));
67280 #endif
67281 @@ -1981,7 +1981,7 @@ static int kdb_lsmod(int argc, const char **argv)
67282 kdb_printf(" (Loading)");
67283 else
67284 kdb_printf(" (Live)");
67285 - kdb_printf(" 0x%p", mod->module_core);
67286 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
67287
67288 #ifdef CONFIG_MODULE_UNLOAD
67289 {
67290 diff --git a/kernel/events/core.c b/kernel/events/core.c
67291 index 7fee567..8affa2c 100644
67292 --- a/kernel/events/core.c
67293 +++ b/kernel/events/core.c
67294 @@ -181,7 +181,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
67295 return 0;
67296 }
67297
67298 -static atomic64_t perf_event_id;
67299 +static atomic64_unchecked_t perf_event_id;
67300
67301 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
67302 enum event_type_t event_type);
67303 @@ -2665,7 +2665,7 @@ static void __perf_event_read(void *info)
67304
67305 static inline u64 perf_event_count(struct perf_event *event)
67306 {
67307 - return local64_read(&event->count) + atomic64_read(&event->child_count);
67308 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
67309 }
67310
67311 static u64 perf_event_read(struct perf_event *event)
67312 @@ -2995,9 +2995,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
67313 mutex_lock(&event->child_mutex);
67314 total += perf_event_read(event);
67315 *enabled += event->total_time_enabled +
67316 - atomic64_read(&event->child_total_time_enabled);
67317 + atomic64_read_unchecked(&event->child_total_time_enabled);
67318 *running += event->total_time_running +
67319 - atomic64_read(&event->child_total_time_running);
67320 + atomic64_read_unchecked(&event->child_total_time_running);
67321
67322 list_for_each_entry(child, &event->child_list, child_list) {
67323 total += perf_event_read(child);
67324 @@ -3406,10 +3406,10 @@ void perf_event_update_userpage(struct perf_event *event)
67325 userpg->offset -= local64_read(&event->hw.prev_count);
67326
67327 userpg->time_enabled = enabled +
67328 - atomic64_read(&event->child_total_time_enabled);
67329 + atomic64_read_unchecked(&event->child_total_time_enabled);
67330
67331 userpg->time_running = running +
67332 - atomic64_read(&event->child_total_time_running);
67333 + atomic64_read_unchecked(&event->child_total_time_running);
67334
67335 arch_perf_update_userpage(userpg, now);
67336
67337 @@ -3842,11 +3842,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
67338 values[n++] = perf_event_count(event);
67339 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
67340 values[n++] = enabled +
67341 - atomic64_read(&event->child_total_time_enabled);
67342 + atomic64_read_unchecked(&event->child_total_time_enabled);
67343 }
67344 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
67345 values[n++] = running +
67346 - atomic64_read(&event->child_total_time_running);
67347 + atomic64_read_unchecked(&event->child_total_time_running);
67348 }
67349 if (read_format & PERF_FORMAT_ID)
67350 values[n++] = primary_event_id(event);
67351 @@ -4524,12 +4524,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
67352 * need to add enough zero bytes after the string to handle
67353 * the 64bit alignment we do later.
67354 */
67355 - buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
67356 + buf = kzalloc(PATH_MAX, GFP_KERNEL);
67357 if (!buf) {
67358 name = strncpy(tmp, "//enomem", sizeof(tmp));
67359 goto got_name;
67360 }
67361 - name = d_path(&file->f_path, buf, PATH_MAX);
67362 + name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
67363 if (IS_ERR(name)) {
67364 name = strncpy(tmp, "//toolong", sizeof(tmp));
67365 goto got_name;
67366 @@ -5968,7 +5968,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
67367 event->parent = parent_event;
67368
67369 event->ns = get_pid_ns(current->nsproxy->pid_ns);
67370 - event->id = atomic64_inc_return(&perf_event_id);
67371 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
67372
67373 event->state = PERF_EVENT_STATE_INACTIVE;
67374
67375 @@ -6567,10 +6567,10 @@ static void sync_child_event(struct perf_event *child_event,
67376 /*
67377 * Add back the child's count to the parent's count:
67378 */
67379 - atomic64_add(child_val, &parent_event->child_count);
67380 - atomic64_add(child_event->total_time_enabled,
67381 + atomic64_add_unchecked(child_val, &parent_event->child_count);
67382 + atomic64_add_unchecked(child_event->total_time_enabled,
67383 &parent_event->child_total_time_enabled);
67384 - atomic64_add(child_event->total_time_running,
67385 + atomic64_add_unchecked(child_event->total_time_running,
67386 &parent_event->child_total_time_running);
67387
67388 /*
67389 diff --git a/kernel/exit.c b/kernel/exit.c
67390 index f65345f9..9c28dab 100644
67391 --- a/kernel/exit.c
67392 +++ b/kernel/exit.c
67393 @@ -59,6 +59,10 @@
67394 #include <asm/pgtable.h>
67395 #include <asm/mmu_context.h>
67396
67397 +#ifdef CONFIG_GRKERNSEC
67398 +extern rwlock_t grsec_exec_file_lock;
67399 +#endif
67400 +
67401 static void exit_mm(struct task_struct * tsk);
67402
67403 static void __unhash_process(struct task_struct *p, bool group_dead)
67404 @@ -182,6 +186,10 @@ void release_task(struct task_struct * p)
67405 struct task_struct *leader;
67406 int zap_leader;
67407 repeat:
67408 +#ifdef CONFIG_NET
67409 + gr_del_task_from_ip_table(p);
67410 +#endif
67411 +
67412 /* don't need to get the RCU readlock here - the process is dead and
67413 * can't be modifying its own credentials. But shut RCU-lockdep up */
67414 rcu_read_lock();
67415 @@ -394,7 +402,7 @@ int allow_signal(int sig)
67416 * know it'll be handled, so that they don't get converted to
67417 * SIGKILL or just silently dropped.
67418 */
67419 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
67420 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
67421 recalc_sigpending();
67422 spin_unlock_irq(&current->sighand->siglock);
67423 return 0;
67424 @@ -430,6 +438,17 @@ void daemonize(const char *name, ...)
67425 vsnprintf(current->comm, sizeof(current->comm), name, args);
67426 va_end(args);
67427
67428 +#ifdef CONFIG_GRKERNSEC
67429 + write_lock(&grsec_exec_file_lock);
67430 + if (current->exec_file) {
67431 + fput(current->exec_file);
67432 + current->exec_file = NULL;
67433 + }
67434 + write_unlock(&grsec_exec_file_lock);
67435 +#endif
67436 +
67437 + gr_set_kernel_label(current);
67438 +
67439 /*
67440 * If we were started as result of loading a module, close all of the
67441 * user space pages. We don't need them, and if we didn't close them
67442 @@ -907,6 +926,8 @@ void do_exit(long code)
67443 struct task_struct *tsk = current;
67444 int group_dead;
67445
67446 + set_fs(USER_DS);
67447 +
67448 profile_task_exit(tsk);
67449
67450 WARN_ON(blk_needs_flush_plug(tsk));
67451 @@ -923,7 +944,6 @@ void do_exit(long code)
67452 * mm_release()->clear_child_tid() from writing to a user-controlled
67453 * kernel address.
67454 */
67455 - set_fs(USER_DS);
67456
67457 ptrace_event(PTRACE_EVENT_EXIT, code);
67458
67459 @@ -982,6 +1002,9 @@ void do_exit(long code)
67460 tsk->exit_code = code;
67461 taskstats_exit(tsk, group_dead);
67462
67463 + gr_acl_handle_psacct(tsk, code);
67464 + gr_acl_handle_exit();
67465 +
67466 exit_mm(tsk);
67467
67468 if (group_dead)
67469 @@ -1099,7 +1122,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
67470 * Take down every thread in the group. This is called by fatal signals
67471 * as well as by sys_exit_group (below).
67472 */
67473 -void
67474 +__noreturn void
67475 do_group_exit(int exit_code)
67476 {
67477 struct signal_struct *sig = current->signal;
67478 diff --git a/kernel/fork.c b/kernel/fork.c
67479 index 2c8857e..288c9c7 100644
67480 --- a/kernel/fork.c
67481 +++ b/kernel/fork.c
67482 @@ -318,7 +318,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
67483 *stackend = STACK_END_MAGIC; /* for overflow detection */
67484
67485 #ifdef CONFIG_CC_STACKPROTECTOR
67486 - tsk->stack_canary = get_random_int();
67487 + tsk->stack_canary = pax_get_random_long();
67488 #endif
67489
67490 /*
67491 @@ -343,13 +343,78 @@ free_tsk:
67492 }
67493
67494 #ifdef CONFIG_MMU
67495 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
67496 +{
67497 + struct vm_area_struct *tmp;
67498 + unsigned long charge;
67499 + struct mempolicy *pol;
67500 + struct file *file;
67501 +
67502 + charge = 0;
67503 + if (mpnt->vm_flags & VM_ACCOUNT) {
67504 + unsigned long len = vma_pages(mpnt);
67505 +
67506 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
67507 + goto fail_nomem;
67508 + charge = len;
67509 + }
67510 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
67511 + if (!tmp)
67512 + goto fail_nomem;
67513 + *tmp = *mpnt;
67514 + tmp->vm_mm = mm;
67515 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
67516 + pol = mpol_dup(vma_policy(mpnt));
67517 + if (IS_ERR(pol))
67518 + goto fail_nomem_policy;
67519 + vma_set_policy(tmp, pol);
67520 + if (anon_vma_fork(tmp, mpnt))
67521 + goto fail_nomem_anon_vma_fork;
67522 + tmp->vm_flags &= ~VM_LOCKED;
67523 + tmp->vm_next = tmp->vm_prev = NULL;
67524 + tmp->vm_mirror = NULL;
67525 + file = tmp->vm_file;
67526 + if (file) {
67527 + struct inode *inode = file->f_path.dentry->d_inode;
67528 + struct address_space *mapping = file->f_mapping;
67529 +
67530 + get_file(file);
67531 + if (tmp->vm_flags & VM_DENYWRITE)
67532 + atomic_dec(&inode->i_writecount);
67533 + mutex_lock(&mapping->i_mmap_mutex);
67534 + if (tmp->vm_flags & VM_SHARED)
67535 + mapping->i_mmap_writable++;
67536 + flush_dcache_mmap_lock(mapping);
67537 + /* insert tmp into the share list, just after mpnt */
67538 + vma_prio_tree_add(tmp, mpnt);
67539 + flush_dcache_mmap_unlock(mapping);
67540 + mutex_unlock(&mapping->i_mmap_mutex);
67541 + }
67542 +
67543 + /*
67544 + * Clear hugetlb-related page reserves for children. This only
67545 + * affects MAP_PRIVATE mappings. Faults generated by the child
67546 + * are not guaranteed to succeed, even if read-only
67547 + */
67548 + if (is_vm_hugetlb_page(tmp))
67549 + reset_vma_resv_huge_pages(tmp);
67550 +
67551 + return tmp;
67552 +
67553 +fail_nomem_anon_vma_fork:
67554 + mpol_put(pol);
67555 +fail_nomem_policy:
67556 + kmem_cache_free(vm_area_cachep, tmp);
67557 +fail_nomem:
67558 + vm_unacct_memory(charge);
67559 + return NULL;
67560 +}
67561 +
67562 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67563 {
67564 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
67565 struct rb_node **rb_link, *rb_parent;
67566 int retval;
67567 - unsigned long charge;
67568 - struct mempolicy *pol;
67569
67570 down_write(&oldmm->mmap_sem);
67571 flush_cache_dup_mm(oldmm);
67572 @@ -361,8 +426,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67573 mm->locked_vm = 0;
67574 mm->mmap = NULL;
67575 mm->mmap_cache = NULL;
67576 - mm->free_area_cache = oldmm->mmap_base;
67577 - mm->cached_hole_size = ~0UL;
67578 + mm->free_area_cache = oldmm->free_area_cache;
67579 + mm->cached_hole_size = oldmm->cached_hole_size;
67580 mm->map_count = 0;
67581 cpumask_clear(mm_cpumask(mm));
67582 mm->mm_rb = RB_ROOT;
67583 @@ -378,52 +443,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67584
67585 prev = NULL;
67586 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
67587 - struct file *file;
67588 -
67589 if (mpnt->vm_flags & VM_DONTCOPY) {
67590 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
67591 -vma_pages(mpnt));
67592 continue;
67593 }
67594 - charge = 0;
67595 - if (mpnt->vm_flags & VM_ACCOUNT) {
67596 - unsigned long len = vma_pages(mpnt);
67597 -
67598 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
67599 - goto fail_nomem;
67600 - charge = len;
67601 - }
67602 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
67603 - if (!tmp)
67604 - goto fail_nomem;
67605 - *tmp = *mpnt;
67606 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
67607 - pol = mpol_dup(vma_policy(mpnt));
67608 - retval = PTR_ERR(pol);
67609 - if (IS_ERR(pol))
67610 - goto fail_nomem_policy;
67611 - vma_set_policy(tmp, pol);
67612 - tmp->vm_mm = mm;
67613 - if (anon_vma_fork(tmp, mpnt))
67614 - goto fail_nomem_anon_vma_fork;
67615 - tmp->vm_flags &= ~VM_LOCKED;
67616 - tmp->vm_next = tmp->vm_prev = NULL;
67617 - file = tmp->vm_file;
67618 - if (file) {
67619 - struct inode *inode = file->f_path.dentry->d_inode;
67620 - struct address_space *mapping = file->f_mapping;
67621 -
67622 - get_file(file);
67623 - if (tmp->vm_flags & VM_DENYWRITE)
67624 - atomic_dec(&inode->i_writecount);
67625 - mutex_lock(&mapping->i_mmap_mutex);
67626 - if (tmp->vm_flags & VM_SHARED)
67627 - mapping->i_mmap_writable++;
67628 - flush_dcache_mmap_lock(mapping);
67629 - /* insert tmp into the share list, just after mpnt */
67630 - vma_prio_tree_add(tmp, mpnt);
67631 - flush_dcache_mmap_unlock(mapping);
67632 - mutex_unlock(&mapping->i_mmap_mutex);
67633 + tmp = dup_vma(mm, oldmm, mpnt);
67634 + if (!tmp) {
67635 + retval = -ENOMEM;
67636 + goto out;
67637 }
67638
67639 /*
67640 @@ -455,9 +483,34 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67641 if (retval)
67642 goto out;
67643
67644 - if (file)
67645 + if (tmp->vm_file)
67646 uprobe_mmap(tmp);
67647 }
67648 +
67649 +#ifdef CONFIG_PAX_SEGMEXEC
67650 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
67651 + struct vm_area_struct *mpnt_m;
67652 +
67653 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
67654 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
67655 +
67656 + if (!mpnt->vm_mirror)
67657 + continue;
67658 +
67659 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
67660 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
67661 + mpnt->vm_mirror = mpnt_m;
67662 + } else {
67663 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
67664 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
67665 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
67666 + mpnt->vm_mirror->vm_mirror = mpnt;
67667 + }
67668 + }
67669 + BUG_ON(mpnt_m);
67670 + }
67671 +#endif
67672 +
67673 /* a new mm has just been created */
67674 arch_dup_mmap(oldmm, mm);
67675 retval = 0;
67676 @@ -466,14 +519,6 @@ out:
67677 flush_tlb_mm(oldmm);
67678 up_write(&oldmm->mmap_sem);
67679 return retval;
67680 -fail_nomem_anon_vma_fork:
67681 - mpol_put(pol);
67682 -fail_nomem_policy:
67683 - kmem_cache_free(vm_area_cachep, tmp);
67684 -fail_nomem:
67685 - retval = -ENOMEM;
67686 - vm_unacct_memory(charge);
67687 - goto out;
67688 }
67689
67690 static inline int mm_alloc_pgd(struct mm_struct *mm)
67691 @@ -710,8 +755,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
67692 return ERR_PTR(err);
67693
67694 mm = get_task_mm(task);
67695 - if (mm && mm != current->mm &&
67696 - !ptrace_may_access(task, mode)) {
67697 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
67698 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
67699 mmput(mm);
67700 mm = ERR_PTR(-EACCES);
67701 }
67702 @@ -932,13 +977,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
67703 spin_unlock(&fs->lock);
67704 return -EAGAIN;
67705 }
67706 - fs->users++;
67707 + atomic_inc(&fs->users);
67708 spin_unlock(&fs->lock);
67709 return 0;
67710 }
67711 tsk->fs = copy_fs_struct(fs);
67712 if (!tsk->fs)
67713 return -ENOMEM;
67714 + /* Carry through gr_chroot_dentry and is_chrooted instead
67715 + of recomputing it here. Already copied when the task struct
67716 + is duplicated. This allows pivot_root to not be treated as
67717 + a chroot
67718 + */
67719 + //gr_set_chroot_entries(tsk, &tsk->fs->root);
67720 +
67721 return 0;
67722 }
67723
67724 @@ -1205,6 +1257,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
67725 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
67726 #endif
67727 retval = -EAGAIN;
67728 +
67729 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
67730 +
67731 if (atomic_read(&p->real_cred->user->processes) >=
67732 task_rlimit(p, RLIMIT_NPROC)) {
67733 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
67734 @@ -1427,6 +1482,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
67735 /* Need tasklist lock for parent etc handling! */
67736 write_lock_irq(&tasklist_lock);
67737
67738 + /* synchronizes with gr_set_acls() */
67739 + gr_copy_label(p);
67740 +
67741 /* CLONE_PARENT re-uses the old parent */
67742 if (clone_flags & (CLONE_PARENT|CLONE_THREAD)) {
67743 p->real_parent = current->real_parent;
67744 @@ -1537,6 +1595,8 @@ bad_fork_cleanup_count:
67745 bad_fork_free:
67746 free_task(p);
67747 fork_out:
67748 + gr_log_forkfail(retval);
67749 +
67750 return ERR_PTR(retval);
67751 }
67752
67753 @@ -1637,6 +1697,8 @@ long do_fork(unsigned long clone_flags,
67754 if (clone_flags & CLONE_PARENT_SETTID)
67755 put_user(nr, parent_tidptr);
67756
67757 + gr_handle_brute_check();
67758 +
67759 if (clone_flags & CLONE_VFORK) {
67760 p->vfork_done = &vfork;
67761 init_completion(&vfork);
67762 @@ -1735,7 +1797,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
67763 return 0;
67764
67765 /* don't need lock here; in the worst case we'll do useless copy */
67766 - if (fs->users == 1)
67767 + if (atomic_read(&fs->users) == 1)
67768 return 0;
67769
67770 *new_fsp = copy_fs_struct(fs);
67771 @@ -1824,7 +1886,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
67772 fs = current->fs;
67773 spin_lock(&fs->lock);
67774 current->fs = new_fs;
67775 - if (--fs->users)
67776 + gr_set_chroot_entries(current, &current->fs->root);
67777 + if (atomic_dec_return(&fs->users))
67778 new_fs = NULL;
67779 else
67780 new_fs = fs;
67781 diff --git a/kernel/futex.c b/kernel/futex.c
67782 index 20ef219..b3a0cb2 100644
67783 --- a/kernel/futex.c
67784 +++ b/kernel/futex.c
67785 @@ -54,6 +54,7 @@
67786 #include <linux/mount.h>
67787 #include <linux/pagemap.h>
67788 #include <linux/syscalls.h>
67789 +#include <linux/ptrace.h>
67790 #include <linux/signal.h>
67791 #include <linux/export.h>
67792 #include <linux/magic.h>
67793 @@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
67794 struct page *page, *page_head;
67795 int err, ro = 0;
67796
67797 +#ifdef CONFIG_PAX_SEGMEXEC
67798 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
67799 + return -EFAULT;
67800 +#endif
67801 +
67802 /*
67803 * The futex address must be "naturally" aligned.
67804 */
67805 @@ -2717,6 +2723,7 @@ static int __init futex_init(void)
67806 {
67807 u32 curval;
67808 int i;
67809 + mm_segment_t oldfs;
67810
67811 /*
67812 * This will fail and we want it. Some arch implementations do
67813 @@ -2728,8 +2735,11 @@ static int __init futex_init(void)
67814 * implementation, the non-functional ones will return
67815 * -ENOSYS.
67816 */
67817 + oldfs = get_fs();
67818 + set_fs(USER_DS);
67819 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
67820 futex_cmpxchg_enabled = 1;
67821 + set_fs(oldfs);
67822
67823 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
67824 plist_head_init(&futex_queues[i].chain);
67825 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
67826 index 9b22d03..6295b62 100644
67827 --- a/kernel/gcov/base.c
67828 +++ b/kernel/gcov/base.c
67829 @@ -102,11 +102,6 @@ void gcov_enable_events(void)
67830 }
67831
67832 #ifdef CONFIG_MODULES
67833 -static inline int within(void *addr, void *start, unsigned long size)
67834 -{
67835 - return ((addr >= start) && (addr < start + size));
67836 -}
67837 -
67838 /* Update list and generate events when modules are unloaded. */
67839 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
67840 void *data)
67841 @@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
67842 prev = NULL;
67843 /* Remove entries located in module from linked list. */
67844 for (info = gcov_info_head; info; info = info->next) {
67845 - if (within(info, mod->module_core, mod->core_size)) {
67846 + if (within_module_core_rw((unsigned long)info, mod)) {
67847 if (prev)
67848 prev->next = info->next;
67849 else
67850 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
67851 index 6db7a5e..25b6648 100644
67852 --- a/kernel/hrtimer.c
67853 +++ b/kernel/hrtimer.c
67854 @@ -1407,7 +1407,7 @@ void hrtimer_peek_ahead_timers(void)
67855 local_irq_restore(flags);
67856 }
67857
67858 -static void run_hrtimer_softirq(struct softirq_action *h)
67859 +static void run_hrtimer_softirq(void)
67860 {
67861 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
67862
67863 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
67864 index 4304919..408c4c0 100644
67865 --- a/kernel/jump_label.c
67866 +++ b/kernel/jump_label.c
67867 @@ -13,6 +13,7 @@
67868 #include <linux/sort.h>
67869 #include <linux/err.h>
67870 #include <linux/static_key.h>
67871 +#include <linux/mm.h>
67872
67873 #ifdef HAVE_JUMP_LABEL
67874
67875 @@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
67876
67877 size = (((unsigned long)stop - (unsigned long)start)
67878 / sizeof(struct jump_entry));
67879 + pax_open_kernel();
67880 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
67881 + pax_close_kernel();
67882 }
67883
67884 static void jump_label_update(struct static_key *key, int enable);
67885 @@ -356,10 +359,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
67886 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
67887 struct jump_entry *iter;
67888
67889 + pax_open_kernel();
67890 for (iter = iter_start; iter < iter_stop; iter++) {
67891 if (within_module_init(iter->code, mod))
67892 iter->code = 0;
67893 }
67894 + pax_close_kernel();
67895 }
67896
67897 static int
67898 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
67899 index 2169fee..45c017a 100644
67900 --- a/kernel/kallsyms.c
67901 +++ b/kernel/kallsyms.c
67902 @@ -11,6 +11,9 @@
67903 * Changed the compression method from stem compression to "table lookup"
67904 * compression (see scripts/kallsyms.c for a more complete description)
67905 */
67906 +#ifdef CONFIG_GRKERNSEC_HIDESYM
67907 +#define __INCLUDED_BY_HIDESYM 1
67908 +#endif
67909 #include <linux/kallsyms.h>
67910 #include <linux/module.h>
67911 #include <linux/init.h>
67912 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
67913
67914 static inline int is_kernel_inittext(unsigned long addr)
67915 {
67916 + if (system_state != SYSTEM_BOOTING)
67917 + return 0;
67918 +
67919 if (addr >= (unsigned long)_sinittext
67920 && addr <= (unsigned long)_einittext)
67921 return 1;
67922 return 0;
67923 }
67924
67925 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67926 +#ifdef CONFIG_MODULES
67927 +static inline int is_module_text(unsigned long addr)
67928 +{
67929 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
67930 + return 1;
67931 +
67932 + addr = ktla_ktva(addr);
67933 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
67934 +}
67935 +#else
67936 +static inline int is_module_text(unsigned long addr)
67937 +{
67938 + return 0;
67939 +}
67940 +#endif
67941 +#endif
67942 +
67943 static inline int is_kernel_text(unsigned long addr)
67944 {
67945 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
67946 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
67947
67948 static inline int is_kernel(unsigned long addr)
67949 {
67950 +
67951 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67952 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
67953 + return 1;
67954 +
67955 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
67956 +#else
67957 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
67958 +#endif
67959 +
67960 return 1;
67961 return in_gate_area_no_mm(addr);
67962 }
67963
67964 static int is_ksym_addr(unsigned long addr)
67965 {
67966 +
67967 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67968 + if (is_module_text(addr))
67969 + return 0;
67970 +#endif
67971 +
67972 if (all_var)
67973 return is_kernel(addr);
67974
67975 @@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
67976
67977 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
67978 {
67979 - iter->name[0] = '\0';
67980 iter->nameoff = get_symbol_offset(new_pos);
67981 iter->pos = new_pos;
67982 }
67983 @@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
67984 {
67985 struct kallsym_iter *iter = m->private;
67986
67987 +#ifdef CONFIG_GRKERNSEC_HIDESYM
67988 + if (current_uid())
67989 + return 0;
67990 +#endif
67991 +
67992 /* Some debugging symbols have no name. Ignore them. */
67993 if (!iter->name[0])
67994 return 0;
67995 @@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
67996 */
67997 type = iter->exported ? toupper(iter->type) :
67998 tolower(iter->type);
67999 +
68000 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
68001 type, iter->name, iter->module_name);
68002 } else
68003 @@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
68004 struct kallsym_iter *iter;
68005 int ret;
68006
68007 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
68008 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
68009 if (!iter)
68010 return -ENOMEM;
68011 reset_iter(iter, 0);
68012 diff --git a/kernel/kcmp.c b/kernel/kcmp.c
68013 index 30b7b22..c726387 100644
68014 --- a/kernel/kcmp.c
68015 +++ b/kernel/kcmp.c
68016 @@ -98,6 +98,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
68017 struct task_struct *task1, *task2;
68018 int ret;
68019
68020 +#ifdef CONFIG_GRKERNSEC
68021 + return -ENOSYS;
68022 +#endif
68023 +
68024 rcu_read_lock();
68025
68026 /*
68027 diff --git a/kernel/kexec.c b/kernel/kexec.c
68028 index 0668d58..591b6fc 100644
68029 --- a/kernel/kexec.c
68030 +++ b/kernel/kexec.c
68031 @@ -1046,7 +1046,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
68032 unsigned long flags)
68033 {
68034 struct compat_kexec_segment in;
68035 - struct kexec_segment out, __user *ksegments;
68036 + struct kexec_segment out;
68037 + struct kexec_segment __user *ksegments;
68038 unsigned long i, result;
68039
68040 /* Don't allow clients that don't understand the native
68041 diff --git a/kernel/kmod.c b/kernel/kmod.c
68042 index 6f99aea..eb6e3a0 100644
68043 --- a/kernel/kmod.c
68044 +++ b/kernel/kmod.c
68045 @@ -73,7 +73,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
68046 kfree(info->argv);
68047 }
68048
68049 -static int call_modprobe(char *module_name, int wait)
68050 +static int call_modprobe(char *module_name, char *module_param, int wait)
68051 {
68052 static char *envp[] = {
68053 "HOME=/",
68054 @@ -82,7 +82,7 @@ static int call_modprobe(char *module_name, int wait)
68055 NULL
68056 };
68057
68058 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
68059 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
68060 if (!argv)
68061 goto out;
68062
68063 @@ -94,7 +94,8 @@ static int call_modprobe(char *module_name, int wait)
68064 argv[1] = "-q";
68065 argv[2] = "--";
68066 argv[3] = module_name; /* check free_modprobe_argv() */
68067 - argv[4] = NULL;
68068 + argv[4] = module_param;
68069 + argv[5] = NULL;
68070
68071 return call_usermodehelper_fns(modprobe_path, argv, envp,
68072 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
68073 @@ -119,9 +120,8 @@ out:
68074 * If module auto-loading support is disabled then this function
68075 * becomes a no-operation.
68076 */
68077 -int __request_module(bool wait, const char *fmt, ...)
68078 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
68079 {
68080 - va_list args;
68081 char module_name[MODULE_NAME_LEN];
68082 unsigned int max_modprobes;
68083 int ret;
68084 @@ -129,9 +129,7 @@ int __request_module(bool wait, const char *fmt, ...)
68085 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
68086 static int kmod_loop_msg;
68087
68088 - va_start(args, fmt);
68089 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
68090 - va_end(args);
68091 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
68092 if (ret >= MODULE_NAME_LEN)
68093 return -ENAMETOOLONG;
68094
68095 @@ -139,6 +137,20 @@ int __request_module(bool wait, const char *fmt, ...)
68096 if (ret)
68097 return ret;
68098
68099 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68100 + if (!current_uid()) {
68101 + /* hack to workaround consolekit/udisks stupidity */
68102 + read_lock(&tasklist_lock);
68103 + if (!strcmp(current->comm, "mount") &&
68104 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
68105 + read_unlock(&tasklist_lock);
68106 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
68107 + return -EPERM;
68108 + }
68109 + read_unlock(&tasklist_lock);
68110 + }
68111 +#endif
68112 +
68113 /* If modprobe needs a service that is in a module, we get a recursive
68114 * loop. Limit the number of running kmod threads to max_threads/2 or
68115 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
68116 @@ -167,11 +179,52 @@ int __request_module(bool wait, const char *fmt, ...)
68117
68118 trace_module_request(module_name, wait, _RET_IP_);
68119
68120 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
68121 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
68122
68123 atomic_dec(&kmod_concurrent);
68124 return ret;
68125 }
68126 +
68127 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
68128 +{
68129 + va_list args;
68130 + int ret;
68131 +
68132 + va_start(args, fmt);
68133 + ret = ____request_module(wait, module_param, fmt, args);
68134 + va_end(args);
68135 +
68136 + return ret;
68137 +}
68138 +
68139 +int __request_module(bool wait, const char *fmt, ...)
68140 +{
68141 + va_list args;
68142 + int ret;
68143 +
68144 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68145 + if (current_uid()) {
68146 + char module_param[MODULE_NAME_LEN];
68147 +
68148 + memset(module_param, 0, sizeof(module_param));
68149 +
68150 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
68151 +
68152 + va_start(args, fmt);
68153 + ret = ____request_module(wait, module_param, fmt, args);
68154 + va_end(args);
68155 +
68156 + return ret;
68157 + }
68158 +#endif
68159 +
68160 + va_start(args, fmt);
68161 + ret = ____request_module(wait, NULL, fmt, args);
68162 + va_end(args);
68163 +
68164 + return ret;
68165 +}
68166 +
68167 EXPORT_SYMBOL(__request_module);
68168 #endif /* CONFIG_MODULES */
68169
68170 @@ -280,7 +333,7 @@ static int wait_for_helper(void *data)
68171 *
68172 * Thus the __user pointer cast is valid here.
68173 */
68174 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
68175 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
68176
68177 /*
68178 * If ret is 0, either ____call_usermodehelper failed and the
68179 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
68180 index c62b854..6fc810d 100644
68181 --- a/kernel/kprobes.c
68182 +++ b/kernel/kprobes.c
68183 @@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
68184 * kernel image and loaded module images reside. This is required
68185 * so x86_64 can correctly handle the %rip-relative fixups.
68186 */
68187 - kip->insns = module_alloc(PAGE_SIZE);
68188 + kip->insns = module_alloc_exec(PAGE_SIZE);
68189 if (!kip->insns) {
68190 kfree(kip);
68191 return NULL;
68192 @@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
68193 */
68194 if (!list_is_singular(&kip->list)) {
68195 list_del(&kip->list);
68196 - module_free(NULL, kip->insns);
68197 + module_free_exec(NULL, kip->insns);
68198 kfree(kip);
68199 }
68200 return 1;
68201 @@ -1955,7 +1955,7 @@ static int __init init_kprobes(void)
68202 {
68203 int i, err = 0;
68204 unsigned long offset = 0, size = 0;
68205 - char *modname, namebuf[128];
68206 + char *modname, namebuf[KSYM_NAME_LEN];
68207 const char *symbol_name;
68208 void *addr;
68209 struct kprobe_blackpoint *kb;
68210 @@ -2040,11 +2040,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
68211 kprobe_type = "k";
68212
68213 if (sym)
68214 - seq_printf(pi, "%p %s %s+0x%x %s ",
68215 + seq_printf(pi, "%pK %s %s+0x%x %s ",
68216 p->addr, kprobe_type, sym, offset,
68217 (modname ? modname : " "));
68218 else
68219 - seq_printf(pi, "%p %s %p ",
68220 + seq_printf(pi, "%pK %s %pK ",
68221 p->addr, kprobe_type, p->addr);
68222
68223 if (!pp)
68224 @@ -2081,7 +2081,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
68225 const char *sym = NULL;
68226 unsigned int i = *(loff_t *) v;
68227 unsigned long offset = 0;
68228 - char *modname, namebuf[128];
68229 + char *modname, namebuf[KSYM_NAME_LEN];
68230
68231 head = &kprobe_table[i];
68232 preempt_disable();
68233 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
68234 index 4e316e1..5501eef 100644
68235 --- a/kernel/ksysfs.c
68236 +++ b/kernel/ksysfs.c
68237 @@ -47,6 +47,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
68238 {
68239 if (count+1 > UEVENT_HELPER_PATH_LEN)
68240 return -ENOENT;
68241 + if (!capable(CAP_SYS_ADMIN))
68242 + return -EPERM;
68243 memcpy(uevent_helper, buf, count);
68244 uevent_helper[count] = '\0';
68245 if (count && uevent_helper[count-1] == '\n')
68246 diff --git a/kernel/lockdep.c b/kernel/lockdep.c
68247 index ea9ee45..67ebc8f 100644
68248 --- a/kernel/lockdep.c
68249 +++ b/kernel/lockdep.c
68250 @@ -590,6 +590,10 @@ static int static_obj(void *obj)
68251 end = (unsigned long) &_end,
68252 addr = (unsigned long) obj;
68253
68254 +#ifdef CONFIG_PAX_KERNEXEC
68255 + start = ktla_ktva(start);
68256 +#endif
68257 +
68258 /*
68259 * static variable?
68260 */
68261 @@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
68262 if (!static_obj(lock->key)) {
68263 debug_locks_off();
68264 printk("INFO: trying to register non-static key.\n");
68265 + printk("lock:%pS key:%pS.\n", lock, lock->key);
68266 printk("the code is fine but needs lockdep annotation.\n");
68267 printk("turning off the locking correctness validator.\n");
68268 dump_stack();
68269 @@ -3042,7 +3047,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
68270 if (!class)
68271 return 0;
68272 }
68273 - atomic_inc((atomic_t *)&class->ops);
68274 + atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
68275 if (very_verbose(class)) {
68276 printk("\nacquire class [%p] %s", class->key, class->name);
68277 if (class->name_version > 1)
68278 diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
68279 index 91c32a0..7b88d63 100644
68280 --- a/kernel/lockdep_proc.c
68281 +++ b/kernel/lockdep_proc.c
68282 @@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
68283
68284 static void print_name(struct seq_file *m, struct lock_class *class)
68285 {
68286 - char str[128];
68287 + char str[KSYM_NAME_LEN];
68288 const char *name = class->name;
68289
68290 if (!name) {
68291 @@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
68292 return 0;
68293 }
68294
68295 - seq_printf(m, "%p", class->key);
68296 + seq_printf(m, "%pK", class->key);
68297 #ifdef CONFIG_DEBUG_LOCKDEP
68298 seq_printf(m, " OPS:%8ld", class->ops);
68299 #endif
68300 @@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
68301
68302 list_for_each_entry(entry, &class->locks_after, entry) {
68303 if (entry->distance == 1) {
68304 - seq_printf(m, " -> [%p] ", entry->class->key);
68305 + seq_printf(m, " -> [%pK] ", entry->class->key);
68306 print_name(m, entry->class);
68307 seq_puts(m, "\n");
68308 }
68309 @@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
68310 if (!class->key)
68311 continue;
68312
68313 - seq_printf(m, "[%p] ", class->key);
68314 + seq_printf(m, "[%pK] ", class->key);
68315 print_name(m, class);
68316 seq_puts(m, "\n");
68317 }
68318 @@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
68319 if (!i)
68320 seq_line(m, '-', 40-namelen, namelen);
68321
68322 - snprintf(ip, sizeof(ip), "[<%p>]",
68323 + snprintf(ip, sizeof(ip), "[<%pK>]",
68324 (void *)class->contention_point[i]);
68325 seq_printf(m, "%40s %14lu %29s %pS\n",
68326 name, stats->contention_point[i],
68327 @@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
68328 if (!i)
68329 seq_line(m, '-', 40-namelen, namelen);
68330
68331 - snprintf(ip, sizeof(ip), "[<%p>]",
68332 + snprintf(ip, sizeof(ip), "[<%pK>]",
68333 (void *)class->contending_point[i]);
68334 seq_printf(m, "%40s %14lu %29s %pS\n",
68335 name, stats->contending_point[i],
68336 diff --git a/kernel/module.c b/kernel/module.c
68337 index 9ad9ee9..731c128 100644
68338 --- a/kernel/module.c
68339 +++ b/kernel/module.c
68340 @@ -58,6 +58,7 @@
68341 #include <linux/jump_label.h>
68342 #include <linux/pfn.h>
68343 #include <linux/bsearch.h>
68344 +#include <linux/grsecurity.h>
68345
68346 #define CREATE_TRACE_POINTS
68347 #include <trace/events/module.h>
68348 @@ -114,7 +115,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
68349
68350 /* Bounds of module allocation, for speeding __module_address.
68351 * Protected by module_mutex. */
68352 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
68353 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
68354 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
68355
68356 int register_module_notifier(struct notifier_block * nb)
68357 {
68358 @@ -278,7 +280,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
68359 return true;
68360
68361 list_for_each_entry_rcu(mod, &modules, list) {
68362 - struct symsearch arr[] = {
68363 + struct symsearch modarr[] = {
68364 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
68365 NOT_GPL_ONLY, false },
68366 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
68367 @@ -300,7 +302,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
68368 #endif
68369 };
68370
68371 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
68372 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
68373 return true;
68374 }
68375 return false;
68376 @@ -432,7 +434,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
68377 static int percpu_modalloc(struct module *mod,
68378 unsigned long size, unsigned long align)
68379 {
68380 - if (align > PAGE_SIZE) {
68381 + if (align-1 >= PAGE_SIZE) {
68382 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
68383 mod->name, align, PAGE_SIZE);
68384 align = PAGE_SIZE;
68385 @@ -1032,7 +1034,7 @@ struct module_attribute module_uevent =
68386 static ssize_t show_coresize(struct module_attribute *mattr,
68387 struct module_kobject *mk, char *buffer)
68388 {
68389 - return sprintf(buffer, "%u\n", mk->mod->core_size);
68390 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
68391 }
68392
68393 static struct module_attribute modinfo_coresize =
68394 @@ -1041,7 +1043,7 @@ static struct module_attribute modinfo_coresize =
68395 static ssize_t show_initsize(struct module_attribute *mattr,
68396 struct module_kobject *mk, char *buffer)
68397 {
68398 - return sprintf(buffer, "%u\n", mk->mod->init_size);
68399 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
68400 }
68401
68402 static struct module_attribute modinfo_initsize =
68403 @@ -1255,7 +1257,7 @@ resolve_symbol_wait(struct module *mod,
68404 */
68405 #ifdef CONFIG_SYSFS
68406
68407 -#ifdef CONFIG_KALLSYMS
68408 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
68409 static inline bool sect_empty(const Elf_Shdr *sect)
68410 {
68411 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
68412 @@ -1721,21 +1723,21 @@ static void set_section_ro_nx(void *base,
68413
68414 static void unset_module_core_ro_nx(struct module *mod)
68415 {
68416 - set_page_attributes(mod->module_core + mod->core_text_size,
68417 - mod->module_core + mod->core_size,
68418 + set_page_attributes(mod->module_core_rw,
68419 + mod->module_core_rw + mod->core_size_rw,
68420 set_memory_x);
68421 - set_page_attributes(mod->module_core,
68422 - mod->module_core + mod->core_ro_size,
68423 + set_page_attributes(mod->module_core_rx,
68424 + mod->module_core_rx + mod->core_size_rx,
68425 set_memory_rw);
68426 }
68427
68428 static void unset_module_init_ro_nx(struct module *mod)
68429 {
68430 - set_page_attributes(mod->module_init + mod->init_text_size,
68431 - mod->module_init + mod->init_size,
68432 + set_page_attributes(mod->module_init_rw,
68433 + mod->module_init_rw + mod->init_size_rw,
68434 set_memory_x);
68435 - set_page_attributes(mod->module_init,
68436 - mod->module_init + mod->init_ro_size,
68437 + set_page_attributes(mod->module_init_rx,
68438 + mod->module_init_rx + mod->init_size_rx,
68439 set_memory_rw);
68440 }
68441
68442 @@ -1746,14 +1748,14 @@ void set_all_modules_text_rw(void)
68443
68444 mutex_lock(&module_mutex);
68445 list_for_each_entry_rcu(mod, &modules, list) {
68446 - if ((mod->module_core) && (mod->core_text_size)) {
68447 - set_page_attributes(mod->module_core,
68448 - mod->module_core + mod->core_text_size,
68449 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
68450 + set_page_attributes(mod->module_core_rx,
68451 + mod->module_core_rx + mod->core_size_rx,
68452 set_memory_rw);
68453 }
68454 - if ((mod->module_init) && (mod->init_text_size)) {
68455 - set_page_attributes(mod->module_init,
68456 - mod->module_init + mod->init_text_size,
68457 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
68458 + set_page_attributes(mod->module_init_rx,
68459 + mod->module_init_rx + mod->init_size_rx,
68460 set_memory_rw);
68461 }
68462 }
68463 @@ -1767,14 +1769,14 @@ void set_all_modules_text_ro(void)
68464
68465 mutex_lock(&module_mutex);
68466 list_for_each_entry_rcu(mod, &modules, list) {
68467 - if ((mod->module_core) && (mod->core_text_size)) {
68468 - set_page_attributes(mod->module_core,
68469 - mod->module_core + mod->core_text_size,
68470 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
68471 + set_page_attributes(mod->module_core_rx,
68472 + mod->module_core_rx + mod->core_size_rx,
68473 set_memory_ro);
68474 }
68475 - if ((mod->module_init) && (mod->init_text_size)) {
68476 - set_page_attributes(mod->module_init,
68477 - mod->module_init + mod->init_text_size,
68478 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
68479 + set_page_attributes(mod->module_init_rx,
68480 + mod->module_init_rx + mod->init_size_rx,
68481 set_memory_ro);
68482 }
68483 }
68484 @@ -1820,16 +1822,19 @@ static void free_module(struct module *mod)
68485
68486 /* This may be NULL, but that's OK */
68487 unset_module_init_ro_nx(mod);
68488 - module_free(mod, mod->module_init);
68489 + module_free(mod, mod->module_init_rw);
68490 + module_free_exec(mod, mod->module_init_rx);
68491 kfree(mod->args);
68492 percpu_modfree(mod);
68493
68494 /* Free lock-classes: */
68495 - lockdep_free_key_range(mod->module_core, mod->core_size);
68496 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
68497 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
68498
68499 /* Finally, free the core (containing the module structure) */
68500 unset_module_core_ro_nx(mod);
68501 - module_free(mod, mod->module_core);
68502 + module_free_exec(mod, mod->module_core_rx);
68503 + module_free(mod, mod->module_core_rw);
68504
68505 #ifdef CONFIG_MPU
68506 update_protections(current->mm);
68507 @@ -1899,9 +1904,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68508 int ret = 0;
68509 const struct kernel_symbol *ksym;
68510
68511 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68512 + int is_fs_load = 0;
68513 + int register_filesystem_found = 0;
68514 + char *p;
68515 +
68516 + p = strstr(mod->args, "grsec_modharden_fs");
68517 + if (p) {
68518 + char *endptr = p + sizeof("grsec_modharden_fs") - 1;
68519 + /* copy \0 as well */
68520 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
68521 + is_fs_load = 1;
68522 + }
68523 +#endif
68524 +
68525 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
68526 const char *name = info->strtab + sym[i].st_name;
68527
68528 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68529 + /* it's a real shame this will never get ripped and copied
68530 + upstream! ;(
68531 + */
68532 + if (is_fs_load && !strcmp(name, "register_filesystem"))
68533 + register_filesystem_found = 1;
68534 +#endif
68535 +
68536 switch (sym[i].st_shndx) {
68537 case SHN_COMMON:
68538 /* We compiled with -fno-common. These are not
68539 @@ -1922,7 +1949,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68540 ksym = resolve_symbol_wait(mod, info, name);
68541 /* Ok if resolved. */
68542 if (ksym && !IS_ERR(ksym)) {
68543 + pax_open_kernel();
68544 sym[i].st_value = ksym->value;
68545 + pax_close_kernel();
68546 break;
68547 }
68548
68549 @@ -1941,11 +1970,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68550 secbase = (unsigned long)mod_percpu(mod);
68551 else
68552 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
68553 + pax_open_kernel();
68554 sym[i].st_value += secbase;
68555 + pax_close_kernel();
68556 break;
68557 }
68558 }
68559
68560 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68561 + if (is_fs_load && !register_filesystem_found) {
68562 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
68563 + ret = -EPERM;
68564 + }
68565 +#endif
68566 +
68567 return ret;
68568 }
68569
68570 @@ -2049,22 +2087,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
68571 || s->sh_entsize != ~0UL
68572 || strstarts(sname, ".init"))
68573 continue;
68574 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
68575 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
68576 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
68577 + else
68578 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
68579 pr_debug("\t%s\n", sname);
68580 }
68581 - switch (m) {
68582 - case 0: /* executable */
68583 - mod->core_size = debug_align(mod->core_size);
68584 - mod->core_text_size = mod->core_size;
68585 - break;
68586 - case 1: /* RO: text and ro-data */
68587 - mod->core_size = debug_align(mod->core_size);
68588 - mod->core_ro_size = mod->core_size;
68589 - break;
68590 - case 3: /* whole core */
68591 - mod->core_size = debug_align(mod->core_size);
68592 - break;
68593 - }
68594 }
68595
68596 pr_debug("Init section allocation order:\n");
68597 @@ -2078,23 +2106,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
68598 || s->sh_entsize != ~0UL
68599 || !strstarts(sname, ".init"))
68600 continue;
68601 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
68602 - | INIT_OFFSET_MASK);
68603 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
68604 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
68605 + else
68606 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
68607 + s->sh_entsize |= INIT_OFFSET_MASK;
68608 pr_debug("\t%s\n", sname);
68609 }
68610 - switch (m) {
68611 - case 0: /* executable */
68612 - mod->init_size = debug_align(mod->init_size);
68613 - mod->init_text_size = mod->init_size;
68614 - break;
68615 - case 1: /* RO: text and ro-data */
68616 - mod->init_size = debug_align(mod->init_size);
68617 - mod->init_ro_size = mod->init_size;
68618 - break;
68619 - case 3: /* whole init */
68620 - mod->init_size = debug_align(mod->init_size);
68621 - break;
68622 - }
68623 }
68624 }
68625
68626 @@ -2266,28 +2284,33 @@ static void layout_symtab(struct module *mod, struct load_info *info)
68627
68628 /* Put symbol section at end of init part of module. */
68629 symsect->sh_flags |= SHF_ALLOC;
68630 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
68631 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
68632 info->index.sym) | INIT_OFFSET_MASK;
68633 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
68634
68635 src = (void *)info->hdr + symsect->sh_offset;
68636 nsrc = symsect->sh_size / sizeof(*src);
68637
68638 + /* strtab always starts with a nul, so offset 0 is the empty string. */
68639 + strtab_size = 1;
68640 +
68641 /* Compute total space required for the core symbols' strtab. */
68642 - for (ndst = i = strtab_size = 1; i < nsrc; ++i, ++src)
68643 - if (is_core_symbol(src, info->sechdrs, info->hdr->e_shnum)) {
68644 - strtab_size += strlen(&info->strtab[src->st_name]) + 1;
68645 + for (ndst = i = 0; i < nsrc; i++) {
68646 + if (i == 0 ||
68647 + is_core_symbol(src+i, info->sechdrs, info->hdr->e_shnum)) {
68648 + strtab_size += strlen(&info->strtab[src[i].st_name])+1;
68649 ndst++;
68650 }
68651 + }
68652
68653 /* Append room for core symbols at end of core part. */
68654 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
68655 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
68656 - mod->core_size += strtab_size;
68657 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
68658 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
68659 + mod->core_size_rx += strtab_size;
68660
68661 /* Put string table section at end of init part of module. */
68662 strsect->sh_flags |= SHF_ALLOC;
68663 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
68664 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
68665 info->index.str) | INIT_OFFSET_MASK;
68666 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
68667 }
68668 @@ -2305,24 +2328,28 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
68669 /* Make sure we get permanent strtab: don't use info->strtab. */
68670 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
68671
68672 + pax_open_kernel();
68673 +
68674 /* Set types up while we still have access to sections. */
68675 for (i = 0; i < mod->num_symtab; i++)
68676 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
68677
68678 - mod->core_symtab = dst = mod->module_core + info->symoffs;
68679 - mod->core_strtab = s = mod->module_core + info->stroffs;
68680 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
68681 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
68682 src = mod->symtab;
68683 - *dst = *src;
68684 *s++ = 0;
68685 - for (ndst = i = 1; i < mod->num_symtab; ++i, ++src) {
68686 - if (!is_core_symbol(src, info->sechdrs, info->hdr->e_shnum))
68687 - continue;
68688 -
68689 - dst[ndst] = *src;
68690 - dst[ndst++].st_name = s - mod->core_strtab;
68691 - s += strlcpy(s, &mod->strtab[src->st_name], KSYM_NAME_LEN) + 1;
68692 + for (ndst = i = 0; i < mod->num_symtab; i++) {
68693 + if (i == 0 ||
68694 + is_core_symbol(src+i, info->sechdrs, info->hdr->e_shnum)) {
68695 + dst[ndst] = src[i];
68696 + dst[ndst++].st_name = s - mod->core_strtab;
68697 + s += strlcpy(s, &mod->strtab[src[i].st_name],
68698 + KSYM_NAME_LEN) + 1;
68699 + }
68700 }
68701 mod->core_num_syms = ndst;
68702 +
68703 + pax_close_kernel();
68704 }
68705 #else
68706 static inline void layout_symtab(struct module *mod, struct load_info *info)
68707 @@ -2356,17 +2383,33 @@ void * __weak module_alloc(unsigned long size)
68708 return size == 0 ? NULL : vmalloc_exec(size);
68709 }
68710
68711 -static void *module_alloc_update_bounds(unsigned long size)
68712 +static void *module_alloc_update_bounds_rw(unsigned long size)
68713 {
68714 void *ret = module_alloc(size);
68715
68716 if (ret) {
68717 mutex_lock(&module_mutex);
68718 /* Update module bounds. */
68719 - if ((unsigned long)ret < module_addr_min)
68720 - module_addr_min = (unsigned long)ret;
68721 - if ((unsigned long)ret + size > module_addr_max)
68722 - module_addr_max = (unsigned long)ret + size;
68723 + if ((unsigned long)ret < module_addr_min_rw)
68724 + module_addr_min_rw = (unsigned long)ret;
68725 + if ((unsigned long)ret + size > module_addr_max_rw)
68726 + module_addr_max_rw = (unsigned long)ret + size;
68727 + mutex_unlock(&module_mutex);
68728 + }
68729 + return ret;
68730 +}
68731 +
68732 +static void *module_alloc_update_bounds_rx(unsigned long size)
68733 +{
68734 + void *ret = module_alloc_exec(size);
68735 +
68736 + if (ret) {
68737 + mutex_lock(&module_mutex);
68738 + /* Update module bounds. */
68739 + if ((unsigned long)ret < module_addr_min_rx)
68740 + module_addr_min_rx = (unsigned long)ret;
68741 + if ((unsigned long)ret + size > module_addr_max_rx)
68742 + module_addr_max_rx = (unsigned long)ret + size;
68743 mutex_unlock(&module_mutex);
68744 }
68745 return ret;
68746 @@ -2544,8 +2587,14 @@ static struct module *setup_load_info(struct load_info *info)
68747 static int check_modinfo(struct module *mod, struct load_info *info)
68748 {
68749 const char *modmagic = get_modinfo(info, "vermagic");
68750 + const char *license = get_modinfo(info, "license");
68751 int err;
68752
68753 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
68754 + if (!license || !license_is_gpl_compatible(license))
68755 + return -ENOEXEC;
68756 +#endif
68757 +
68758 /* This is allowed: modprobe --force will invalidate it. */
68759 if (!modmagic) {
68760 err = try_to_force_load(mod, "bad vermagic");
68761 @@ -2568,7 +2617,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
68762 }
68763
68764 /* Set up license info based on the info section */
68765 - set_license(mod, get_modinfo(info, "license"));
68766 + set_license(mod, license);
68767
68768 return 0;
68769 }
68770 @@ -2662,7 +2711,7 @@ static int move_module(struct module *mod, struct load_info *info)
68771 void *ptr;
68772
68773 /* Do the allocs. */
68774 - ptr = module_alloc_update_bounds(mod->core_size);
68775 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
68776 /*
68777 * The pointer to this block is stored in the module structure
68778 * which is inside the block. Just mark it as not being a
68779 @@ -2672,23 +2721,50 @@ static int move_module(struct module *mod, struct load_info *info)
68780 if (!ptr)
68781 return -ENOMEM;
68782
68783 - memset(ptr, 0, mod->core_size);
68784 - mod->module_core = ptr;
68785 + memset(ptr, 0, mod->core_size_rw);
68786 + mod->module_core_rw = ptr;
68787
68788 - ptr = module_alloc_update_bounds(mod->init_size);
68789 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
68790 /*
68791 * The pointer to this block is stored in the module structure
68792 * which is inside the block. This block doesn't need to be
68793 * scanned as it contains data and code that will be freed
68794 * after the module is initialized.
68795 */
68796 - kmemleak_ignore(ptr);
68797 - if (!ptr && mod->init_size) {
68798 - module_free(mod, mod->module_core);
68799 + kmemleak_not_leak(ptr);
68800 + if (!ptr && mod->init_size_rw) {
68801 + module_free(mod, mod->module_core_rw);
68802 return -ENOMEM;
68803 }
68804 - memset(ptr, 0, mod->init_size);
68805 - mod->module_init = ptr;
68806 + memset(ptr, 0, mod->init_size_rw);
68807 + mod->module_init_rw = ptr;
68808 +
68809 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
68810 + kmemleak_not_leak(ptr);
68811 + if (!ptr) {
68812 + module_free(mod, mod->module_init_rw);
68813 + module_free(mod, mod->module_core_rw);
68814 + return -ENOMEM;
68815 + }
68816 +
68817 + pax_open_kernel();
68818 + memset(ptr, 0, mod->core_size_rx);
68819 + pax_close_kernel();
68820 + mod->module_core_rx = ptr;
68821 +
68822 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
68823 + kmemleak_not_leak(ptr);
68824 + if (!ptr && mod->init_size_rx) {
68825 + module_free_exec(mod, mod->module_core_rx);
68826 + module_free(mod, mod->module_init_rw);
68827 + module_free(mod, mod->module_core_rw);
68828 + return -ENOMEM;
68829 + }
68830 +
68831 + pax_open_kernel();
68832 + memset(ptr, 0, mod->init_size_rx);
68833 + pax_close_kernel();
68834 + mod->module_init_rx = ptr;
68835
68836 /* Transfer each section which specifies SHF_ALLOC */
68837 pr_debug("final section addresses:\n");
68838 @@ -2699,16 +2775,45 @@ static int move_module(struct module *mod, struct load_info *info)
68839 if (!(shdr->sh_flags & SHF_ALLOC))
68840 continue;
68841
68842 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
68843 - dest = mod->module_init
68844 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68845 - else
68846 - dest = mod->module_core + shdr->sh_entsize;
68847 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
68848 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
68849 + dest = mod->module_init_rw
68850 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68851 + else
68852 + dest = mod->module_init_rx
68853 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68854 + } else {
68855 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
68856 + dest = mod->module_core_rw + shdr->sh_entsize;
68857 + else
68858 + dest = mod->module_core_rx + shdr->sh_entsize;
68859 + }
68860 +
68861 + if (shdr->sh_type != SHT_NOBITS) {
68862 +
68863 +#ifdef CONFIG_PAX_KERNEXEC
68864 +#ifdef CONFIG_X86_64
68865 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
68866 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
68867 +#endif
68868 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
68869 + pax_open_kernel();
68870 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
68871 + pax_close_kernel();
68872 + } else
68873 +#endif
68874
68875 - if (shdr->sh_type != SHT_NOBITS)
68876 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
68877 + }
68878 /* Update sh_addr to point to copy in image. */
68879 - shdr->sh_addr = (unsigned long)dest;
68880 +
68881 +#ifdef CONFIG_PAX_KERNEXEC
68882 + if (shdr->sh_flags & SHF_EXECINSTR)
68883 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
68884 + else
68885 +#endif
68886 +
68887 + shdr->sh_addr = (unsigned long)dest;
68888 pr_debug("\t0x%lx %s\n",
68889 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
68890 }
68891 @@ -2763,12 +2868,12 @@ static void flush_module_icache(const struct module *mod)
68892 * Do it before processing of module parameters, so the module
68893 * can provide parameter accessor functions of its own.
68894 */
68895 - if (mod->module_init)
68896 - flush_icache_range((unsigned long)mod->module_init,
68897 - (unsigned long)mod->module_init
68898 - + mod->init_size);
68899 - flush_icache_range((unsigned long)mod->module_core,
68900 - (unsigned long)mod->module_core + mod->core_size);
68901 + if (mod->module_init_rx)
68902 + flush_icache_range((unsigned long)mod->module_init_rx,
68903 + (unsigned long)mod->module_init_rx
68904 + + mod->init_size_rx);
68905 + flush_icache_range((unsigned long)mod->module_core_rx,
68906 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
68907
68908 set_fs(old_fs);
68909 }
68910 @@ -2838,8 +2943,10 @@ out:
68911 static void module_deallocate(struct module *mod, struct load_info *info)
68912 {
68913 percpu_modfree(mod);
68914 - module_free(mod, mod->module_init);
68915 - module_free(mod, mod->module_core);
68916 + module_free_exec(mod, mod->module_init_rx);
68917 + module_free_exec(mod, mod->module_core_rx);
68918 + module_free(mod, mod->module_init_rw);
68919 + module_free(mod, mod->module_core_rw);
68920 }
68921
68922 int __weak module_finalize(const Elf_Ehdr *hdr,
68923 @@ -2852,7 +2959,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
68924 static int post_relocation(struct module *mod, const struct load_info *info)
68925 {
68926 /* Sort exception table now relocations are done. */
68927 + pax_open_kernel();
68928 sort_extable(mod->extable, mod->extable + mod->num_exentries);
68929 + pax_close_kernel();
68930
68931 /* Copy relocated percpu area over. */
68932 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
68933 @@ -2903,9 +3012,38 @@ static struct module *load_module(void __user *umod,
68934 if (err)
68935 goto free_unload;
68936
68937 + /* Now copy in args */
68938 + mod->args = strndup_user(uargs, ~0UL >> 1);
68939 + if (IS_ERR(mod->args)) {
68940 + err = PTR_ERR(mod->args);
68941 + goto free_unload;
68942 + }
68943 +
68944 /* Set up MODINFO_ATTR fields */
68945 setup_modinfo(mod, &info);
68946
68947 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68948 + {
68949 + char *p, *p2;
68950 +
68951 + if (strstr(mod->args, "grsec_modharden_netdev")) {
68952 + 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);
68953 + err = -EPERM;
68954 + goto free_modinfo;
68955 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
68956 + p += sizeof("grsec_modharden_normal") - 1;
68957 + p2 = strstr(p, "_");
68958 + if (p2) {
68959 + *p2 = '\0';
68960 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
68961 + *p2 = '_';
68962 + }
68963 + err = -EPERM;
68964 + goto free_modinfo;
68965 + }
68966 + }
68967 +#endif
68968 +
68969 /* Fix up syms, so that st_value is a pointer to location. */
68970 err = simplify_symbols(mod, &info);
68971 if (err < 0)
68972 @@ -2921,13 +3059,6 @@ static struct module *load_module(void __user *umod,
68973
68974 flush_module_icache(mod);
68975
68976 - /* Now copy in args */
68977 - mod->args = strndup_user(uargs, ~0UL >> 1);
68978 - if (IS_ERR(mod->args)) {
68979 - err = PTR_ERR(mod->args);
68980 - goto free_arch_cleanup;
68981 - }
68982 -
68983 /* Mark state as coming so strong_try_module_get() ignores us. */
68984 mod->state = MODULE_STATE_COMING;
68985
68986 @@ -2985,11 +3116,10 @@ static struct module *load_module(void __user *umod,
68987 unlock:
68988 mutex_unlock(&module_mutex);
68989 synchronize_sched();
68990 - kfree(mod->args);
68991 - free_arch_cleanup:
68992 module_arch_cleanup(mod);
68993 free_modinfo:
68994 free_modinfo(mod);
68995 + kfree(mod->args);
68996 free_unload:
68997 module_unload_free(mod);
68998 free_module:
68999 @@ -3030,16 +3160,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
69000 MODULE_STATE_COMING, mod);
69001
69002 /* Set RO and NX regions for core */
69003 - set_section_ro_nx(mod->module_core,
69004 - mod->core_text_size,
69005 - mod->core_ro_size,
69006 - mod->core_size);
69007 + set_section_ro_nx(mod->module_core_rx,
69008 + mod->core_size_rx,
69009 + mod->core_size_rx,
69010 + mod->core_size_rx);
69011
69012 /* Set RO and NX regions for init */
69013 - set_section_ro_nx(mod->module_init,
69014 - mod->init_text_size,
69015 - mod->init_ro_size,
69016 - mod->init_size);
69017 + set_section_ro_nx(mod->module_init_rx,
69018 + mod->init_size_rx,
69019 + mod->init_size_rx,
69020 + mod->init_size_rx);
69021
69022 do_mod_ctors(mod);
69023 /* Start the module */
69024 @@ -3085,11 +3215,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
69025 mod->strtab = mod->core_strtab;
69026 #endif
69027 unset_module_init_ro_nx(mod);
69028 - module_free(mod, mod->module_init);
69029 - mod->module_init = NULL;
69030 - mod->init_size = 0;
69031 - mod->init_ro_size = 0;
69032 - mod->init_text_size = 0;
69033 + module_free(mod, mod->module_init_rw);
69034 + module_free_exec(mod, mod->module_init_rx);
69035 + mod->module_init_rw = NULL;
69036 + mod->module_init_rx = NULL;
69037 + mod->init_size_rw = 0;
69038 + mod->init_size_rx = 0;
69039 mutex_unlock(&module_mutex);
69040
69041 return 0;
69042 @@ -3120,10 +3251,16 @@ static const char *get_ksymbol(struct module *mod,
69043 unsigned long nextval;
69044
69045 /* At worse, next value is at end of module */
69046 - if (within_module_init(addr, mod))
69047 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
69048 + if (within_module_init_rx(addr, mod))
69049 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
69050 + else if (within_module_init_rw(addr, mod))
69051 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
69052 + else if (within_module_core_rx(addr, mod))
69053 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
69054 + else if (within_module_core_rw(addr, mod))
69055 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
69056 else
69057 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
69058 + return NULL;
69059
69060 /* Scan for closest preceding symbol, and next symbol. (ELF
69061 starts real symbols at 1). */
69062 @@ -3358,7 +3495,7 @@ static int m_show(struct seq_file *m, void *p)
69063 char buf[8];
69064
69065 seq_printf(m, "%s %u",
69066 - mod->name, mod->init_size + mod->core_size);
69067 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
69068 print_unload_info(m, mod);
69069
69070 /* Informative for users. */
69071 @@ -3367,7 +3504,7 @@ static int m_show(struct seq_file *m, void *p)
69072 mod->state == MODULE_STATE_COMING ? "Loading":
69073 "Live");
69074 /* Used by oprofile and other similar tools. */
69075 - seq_printf(m, " 0x%pK", mod->module_core);
69076 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
69077
69078 /* Taints info */
69079 if (mod->taints)
69080 @@ -3403,7 +3540,17 @@ static const struct file_operations proc_modules_operations = {
69081
69082 static int __init proc_modules_init(void)
69083 {
69084 +#ifndef CONFIG_GRKERNSEC_HIDESYM
69085 +#ifdef CONFIG_GRKERNSEC_PROC_USER
69086 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
69087 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69088 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
69089 +#else
69090 proc_create("modules", 0, NULL, &proc_modules_operations);
69091 +#endif
69092 +#else
69093 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
69094 +#endif
69095 return 0;
69096 }
69097 module_init(proc_modules_init);
69098 @@ -3462,12 +3609,12 @@ struct module *__module_address(unsigned long addr)
69099 {
69100 struct module *mod;
69101
69102 - if (addr < module_addr_min || addr > module_addr_max)
69103 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
69104 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
69105 return NULL;
69106
69107 list_for_each_entry_rcu(mod, &modules, list)
69108 - if (within_module_core(addr, mod)
69109 - || within_module_init(addr, mod))
69110 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
69111 return mod;
69112 return NULL;
69113 }
69114 @@ -3501,11 +3648,20 @@ bool is_module_text_address(unsigned long addr)
69115 */
69116 struct module *__module_text_address(unsigned long addr)
69117 {
69118 - struct module *mod = __module_address(addr);
69119 + struct module *mod;
69120 +
69121 +#ifdef CONFIG_X86_32
69122 + addr = ktla_ktva(addr);
69123 +#endif
69124 +
69125 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
69126 + return NULL;
69127 +
69128 + mod = __module_address(addr);
69129 +
69130 if (mod) {
69131 /* Make sure it's within the text section. */
69132 - if (!within(addr, mod->module_init, mod->init_text_size)
69133 - && !within(addr, mod->module_core, mod->core_text_size))
69134 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
69135 mod = NULL;
69136 }
69137 return mod;
69138 diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
69139 index 7e3443f..b2a1e6b 100644
69140 --- a/kernel/mutex-debug.c
69141 +++ b/kernel/mutex-debug.c
69142 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
69143 }
69144
69145 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
69146 - struct thread_info *ti)
69147 + struct task_struct *task)
69148 {
69149 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
69150
69151 /* Mark the current thread as blocked on the lock: */
69152 - ti->task->blocked_on = waiter;
69153 + task->blocked_on = waiter;
69154 }
69155
69156 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
69157 - struct thread_info *ti)
69158 + struct task_struct *task)
69159 {
69160 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
69161 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
69162 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
69163 - ti->task->blocked_on = NULL;
69164 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
69165 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
69166 + task->blocked_on = NULL;
69167
69168 list_del_init(&waiter->list);
69169 waiter->task = NULL;
69170 diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
69171 index 0799fd3..d06ae3b 100644
69172 --- a/kernel/mutex-debug.h
69173 +++ b/kernel/mutex-debug.h
69174 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
69175 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
69176 extern void debug_mutex_add_waiter(struct mutex *lock,
69177 struct mutex_waiter *waiter,
69178 - struct thread_info *ti);
69179 + struct task_struct *task);
69180 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
69181 - struct thread_info *ti);
69182 + struct task_struct *task);
69183 extern void debug_mutex_unlock(struct mutex *lock);
69184 extern void debug_mutex_init(struct mutex *lock, const char *name,
69185 struct lock_class_key *key);
69186 diff --git a/kernel/mutex.c b/kernel/mutex.c
69187 index a307cc9..27fd2e9 100644
69188 --- a/kernel/mutex.c
69189 +++ b/kernel/mutex.c
69190 @@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
69191 spin_lock_mutex(&lock->wait_lock, flags);
69192
69193 debug_mutex_lock_common(lock, &waiter);
69194 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
69195 + debug_mutex_add_waiter(lock, &waiter, task);
69196
69197 /* add waiting tasks to the end of the waitqueue (FIFO): */
69198 list_add_tail(&waiter.list, &lock->wait_list);
69199 @@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
69200 * TASK_UNINTERRUPTIBLE case.)
69201 */
69202 if (unlikely(signal_pending_state(state, task))) {
69203 - mutex_remove_waiter(lock, &waiter,
69204 - task_thread_info(task));
69205 + mutex_remove_waiter(lock, &waiter, task);
69206 mutex_release(&lock->dep_map, 1, ip);
69207 spin_unlock_mutex(&lock->wait_lock, flags);
69208
69209 @@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
69210 done:
69211 lock_acquired(&lock->dep_map, ip);
69212 /* got the lock - rejoice! */
69213 - mutex_remove_waiter(lock, &waiter, current_thread_info());
69214 + mutex_remove_waiter(lock, &waiter, task);
69215 mutex_set_owner(lock);
69216
69217 /* set it to 0 if there are no waiters left: */
69218 diff --git a/kernel/panic.c b/kernel/panic.c
69219 index e1b2822..5edc1d9 100644
69220 --- a/kernel/panic.c
69221 +++ b/kernel/panic.c
69222 @@ -410,7 +410,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
69223 const char *board;
69224
69225 printk(KERN_WARNING "------------[ cut here ]------------\n");
69226 - printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
69227 + printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
69228 board = dmi_get_system_info(DMI_PRODUCT_NAME);
69229 if (board)
69230 printk(KERN_WARNING "Hardware name: %s\n", board);
69231 @@ -465,7 +465,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
69232 */
69233 void __stack_chk_fail(void)
69234 {
69235 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
69236 + dump_stack();
69237 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
69238 __builtin_return_address(0));
69239 }
69240 EXPORT_SYMBOL(__stack_chk_fail);
69241 diff --git a/kernel/pid.c b/kernel/pid.c
69242 index e86b291a..e8b0fb5 100644
69243 --- a/kernel/pid.c
69244 +++ b/kernel/pid.c
69245 @@ -33,6 +33,7 @@
69246 #include <linux/rculist.h>
69247 #include <linux/bootmem.h>
69248 #include <linux/hash.h>
69249 +#include <linux/security.h>
69250 #include <linux/pid_namespace.h>
69251 #include <linux/init_task.h>
69252 #include <linux/syscalls.h>
69253 @@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
69254
69255 int pid_max = PID_MAX_DEFAULT;
69256
69257 -#define RESERVED_PIDS 300
69258 +#define RESERVED_PIDS 500
69259
69260 int pid_max_min = RESERVED_PIDS + 1;
69261 int pid_max_max = PID_MAX_LIMIT;
69262 @@ -420,10 +421,18 @@ EXPORT_SYMBOL(pid_task);
69263 */
69264 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
69265 {
69266 + struct task_struct *task;
69267 +
69268 rcu_lockdep_assert(rcu_read_lock_held(),
69269 "find_task_by_pid_ns() needs rcu_read_lock()"
69270 " protection");
69271 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
69272 +
69273 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
69274 +
69275 + if (gr_pid_is_chrooted(task))
69276 + return NULL;
69277 +
69278 + return task;
69279 }
69280
69281 struct task_struct *find_task_by_vpid(pid_t vnr)
69282 @@ -431,6 +440,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
69283 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
69284 }
69285
69286 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
69287 +{
69288 + rcu_lockdep_assert(rcu_read_lock_held(),
69289 + "find_task_by_pid_ns() needs rcu_read_lock()"
69290 + " protection");
69291 + return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
69292 +}
69293 +
69294 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
69295 {
69296 struct pid *pid;
69297 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
69298 index 125cb67..a4d1c30 100644
69299 --- a/kernel/posix-cpu-timers.c
69300 +++ b/kernel/posix-cpu-timers.c
69301 @@ -6,6 +6,7 @@
69302 #include <linux/posix-timers.h>
69303 #include <linux/errno.h>
69304 #include <linux/math64.h>
69305 +#include <linux/security.h>
69306 #include <asm/uaccess.h>
69307 #include <linux/kernel_stat.h>
69308 #include <trace/events/timer.h>
69309 @@ -1578,14 +1579,14 @@ struct k_clock clock_posix_cpu = {
69310
69311 static __init int init_posix_cpu_timers(void)
69312 {
69313 - struct k_clock process = {
69314 + static struct k_clock process = {
69315 .clock_getres = process_cpu_clock_getres,
69316 .clock_get = process_cpu_clock_get,
69317 .timer_create = process_cpu_timer_create,
69318 .nsleep = process_cpu_nsleep,
69319 .nsleep_restart = process_cpu_nsleep_restart,
69320 };
69321 - struct k_clock thread = {
69322 + static struct k_clock thread = {
69323 .clock_getres = thread_cpu_clock_getres,
69324 .clock_get = thread_cpu_clock_get,
69325 .timer_create = thread_cpu_timer_create,
69326 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
69327 index 69185ae..cc2847a 100644
69328 --- a/kernel/posix-timers.c
69329 +++ b/kernel/posix-timers.c
69330 @@ -43,6 +43,7 @@
69331 #include <linux/idr.h>
69332 #include <linux/posix-clock.h>
69333 #include <linux/posix-timers.h>
69334 +#include <linux/grsecurity.h>
69335 #include <linux/syscalls.h>
69336 #include <linux/wait.h>
69337 #include <linux/workqueue.h>
69338 @@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
69339 * which we beg off on and pass to do_sys_settimeofday().
69340 */
69341
69342 -static struct k_clock posix_clocks[MAX_CLOCKS];
69343 +static struct k_clock *posix_clocks[MAX_CLOCKS];
69344
69345 /*
69346 * These ones are defined below.
69347 @@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
69348 */
69349 static __init int init_posix_timers(void)
69350 {
69351 - struct k_clock clock_realtime = {
69352 + static struct k_clock clock_realtime = {
69353 .clock_getres = hrtimer_get_res,
69354 .clock_get = posix_clock_realtime_get,
69355 .clock_set = posix_clock_realtime_set,
69356 @@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
69357 .timer_get = common_timer_get,
69358 .timer_del = common_timer_del,
69359 };
69360 - struct k_clock clock_monotonic = {
69361 + static struct k_clock clock_monotonic = {
69362 .clock_getres = hrtimer_get_res,
69363 .clock_get = posix_ktime_get_ts,
69364 .nsleep = common_nsleep,
69365 @@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
69366 .timer_get = common_timer_get,
69367 .timer_del = common_timer_del,
69368 };
69369 - struct k_clock clock_monotonic_raw = {
69370 + static struct k_clock clock_monotonic_raw = {
69371 .clock_getres = hrtimer_get_res,
69372 .clock_get = posix_get_monotonic_raw,
69373 };
69374 - struct k_clock clock_realtime_coarse = {
69375 + static struct k_clock clock_realtime_coarse = {
69376 .clock_getres = posix_get_coarse_res,
69377 .clock_get = posix_get_realtime_coarse,
69378 };
69379 - struct k_clock clock_monotonic_coarse = {
69380 + static struct k_clock clock_monotonic_coarse = {
69381 .clock_getres = posix_get_coarse_res,
69382 .clock_get = posix_get_monotonic_coarse,
69383 };
69384 - struct k_clock clock_boottime = {
69385 + static struct k_clock clock_boottime = {
69386 .clock_getres = hrtimer_get_res,
69387 .clock_get = posix_get_boottime,
69388 .nsleep = common_nsleep,
69389 @@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
69390 return;
69391 }
69392
69393 - posix_clocks[clock_id] = *new_clock;
69394 + posix_clocks[clock_id] = new_clock;
69395 }
69396 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
69397
69398 @@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
69399 return (id & CLOCKFD_MASK) == CLOCKFD ?
69400 &clock_posix_dynamic : &clock_posix_cpu;
69401
69402 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
69403 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
69404 return NULL;
69405 - return &posix_clocks[id];
69406 + return posix_clocks[id];
69407 }
69408
69409 static int common_timer_create(struct k_itimer *new_timer)
69410 @@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
69411 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
69412 return -EFAULT;
69413
69414 + /* only the CLOCK_REALTIME clock can be set, all other clocks
69415 + have their clock_set fptr set to a nosettime dummy function
69416 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
69417 + call common_clock_set, which calls do_sys_settimeofday, which
69418 + we hook
69419 + */
69420 +
69421 return kc->clock_set(which_clock, &new_tp);
69422 }
69423
69424 diff --git a/kernel/power/poweroff.c b/kernel/power/poweroff.c
69425 index d523593..68197a4 100644
69426 --- a/kernel/power/poweroff.c
69427 +++ b/kernel/power/poweroff.c
69428 @@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_poweroff_op = {
69429 .enable_mask = SYSRQ_ENABLE_BOOT,
69430 };
69431
69432 -static int pm_sysrq_init(void)
69433 +static int __init pm_sysrq_init(void)
69434 {
69435 register_sysrq_key('o', &sysrq_poweroff_op);
69436 return 0;
69437 diff --git a/kernel/power/process.c b/kernel/power/process.c
69438 index 19db29f..33b52b6 100644
69439 --- a/kernel/power/process.c
69440 +++ b/kernel/power/process.c
69441 @@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
69442 u64 elapsed_csecs64;
69443 unsigned int elapsed_csecs;
69444 bool wakeup = false;
69445 + bool timedout = false;
69446
69447 do_gettimeofday(&start);
69448
69449 @@ -43,6 +44,8 @@ static int try_to_freeze_tasks(bool user_only)
69450
69451 while (true) {
69452 todo = 0;
69453 + if (time_after(jiffies, end_time))
69454 + timedout = true;
69455 read_lock(&tasklist_lock);
69456 do_each_thread(g, p) {
69457 if (p == current || !freeze_task(p))
69458 @@ -58,9 +61,13 @@ static int try_to_freeze_tasks(bool user_only)
69459 * guaranteed that TASK_STOPPED/TRACED -> TASK_RUNNING
69460 * transition can't race with task state testing here.
69461 */
69462 - if (!task_is_stopped_or_traced(p) &&
69463 - !freezer_should_skip(p))
69464 + if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
69465 todo++;
69466 + if (timedout) {
69467 + printk(KERN_ERR "Task refusing to freeze:\n");
69468 + sched_show_task(p);
69469 + }
69470 + }
69471 } while_each_thread(g, p);
69472 read_unlock(&tasklist_lock);
69473
69474 @@ -69,7 +76,7 @@ static int try_to_freeze_tasks(bool user_only)
69475 todo += wq_busy;
69476 }
69477
69478 - if (!todo || time_after(jiffies, end_time))
69479 + if (!todo || timedout)
69480 break;
69481
69482 if (pm_wakeup_pending()) {
69483 diff --git a/kernel/printk.c b/kernel/printk.c
69484 index 66a2ea3..10f3a01 100644
69485 --- a/kernel/printk.c
69486 +++ b/kernel/printk.c
69487 @@ -817,6 +817,11 @@ static int check_syslog_permissions(int type, bool from_file)
69488 if (from_file && type != SYSLOG_ACTION_OPEN)
69489 return 0;
69490
69491 +#ifdef CONFIG_GRKERNSEC_DMESG
69492 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
69493 + return -EPERM;
69494 +#endif
69495 +
69496 if (syslog_action_restricted(type)) {
69497 if (capable(CAP_SYSLOG))
69498 return 0;
69499 diff --git a/kernel/profile.c b/kernel/profile.c
69500 index 76b8e77..a2930e8 100644
69501 --- a/kernel/profile.c
69502 +++ b/kernel/profile.c
69503 @@ -39,7 +39,7 @@ struct profile_hit {
69504 /* Oprofile timer tick hook */
69505 static int (*timer_hook)(struct pt_regs *) __read_mostly;
69506
69507 -static atomic_t *prof_buffer;
69508 +static atomic_unchecked_t *prof_buffer;
69509 static unsigned long prof_len, prof_shift;
69510
69511 int prof_on __read_mostly;
69512 @@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
69513 hits[i].pc = 0;
69514 continue;
69515 }
69516 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
69517 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
69518 hits[i].hits = hits[i].pc = 0;
69519 }
69520 }
69521 @@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
69522 * Add the current hit(s) and flush the write-queue out
69523 * to the global buffer:
69524 */
69525 - atomic_add(nr_hits, &prof_buffer[pc]);
69526 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
69527 for (i = 0; i < NR_PROFILE_HIT; ++i) {
69528 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
69529 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
69530 hits[i].pc = hits[i].hits = 0;
69531 }
69532 out:
69533 @@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
69534 {
69535 unsigned long pc;
69536 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
69537 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
69538 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
69539 }
69540 #endif /* !CONFIG_SMP */
69541
69542 @@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
69543 return -EFAULT;
69544 buf++; p++; count--; read++;
69545 }
69546 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
69547 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
69548 if (copy_to_user(buf, (void *)pnt, count))
69549 return -EFAULT;
69550 read += count;
69551 @@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
69552 }
69553 #endif
69554 profile_discard_flip_buffers();
69555 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
69556 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
69557 return count;
69558 }
69559
69560 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
69561 index a232bb5..2a65ef9 100644
69562 --- a/kernel/ptrace.c
69563 +++ b/kernel/ptrace.c
69564 @@ -279,7 +279,7 @@ static int ptrace_attach(struct task_struct *task, long request,
69565
69566 if (seize)
69567 flags |= PT_SEIZED;
69568 - if (ns_capable(task_user_ns(task), CAP_SYS_PTRACE))
69569 + if (ns_capable_nolog(task_user_ns(task), CAP_SYS_PTRACE))
69570 flags |= PT_PTRACE_CAP;
69571 task->ptrace = flags;
69572
69573 @@ -486,7 +486,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
69574 break;
69575 return -EIO;
69576 }
69577 - if (copy_to_user(dst, buf, retval))
69578 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
69579 return -EFAULT;
69580 copied += retval;
69581 src += retval;
69582 @@ -671,7 +671,7 @@ int ptrace_request(struct task_struct *child, long request,
69583 bool seized = child->ptrace & PT_SEIZED;
69584 int ret = -EIO;
69585 siginfo_t siginfo, *si;
69586 - void __user *datavp = (void __user *) data;
69587 + void __user *datavp = (__force void __user *) data;
69588 unsigned long __user *datalp = datavp;
69589 unsigned long flags;
69590
69591 @@ -873,14 +873,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
69592 goto out;
69593 }
69594
69595 + if (gr_handle_ptrace(child, request)) {
69596 + ret = -EPERM;
69597 + goto out_put_task_struct;
69598 + }
69599 +
69600 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
69601 ret = ptrace_attach(child, request, addr, data);
69602 /*
69603 * Some architectures need to do book-keeping after
69604 * a ptrace attach.
69605 */
69606 - if (!ret)
69607 + if (!ret) {
69608 arch_ptrace_attach(child);
69609 + gr_audit_ptrace(child);
69610 + }
69611 goto out_put_task_struct;
69612 }
69613
69614 @@ -906,7 +913,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
69615 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
69616 if (copied != sizeof(tmp))
69617 return -EIO;
69618 - return put_user(tmp, (unsigned long __user *)data);
69619 + return put_user(tmp, (__force unsigned long __user *)data);
69620 }
69621
69622 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
69623 @@ -1016,14 +1023,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
69624 goto out;
69625 }
69626
69627 + if (gr_handle_ptrace(child, request)) {
69628 + ret = -EPERM;
69629 + goto out_put_task_struct;
69630 + }
69631 +
69632 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
69633 ret = ptrace_attach(child, request, addr, data);
69634 /*
69635 * Some architectures need to do book-keeping after
69636 * a ptrace attach.
69637 */
69638 - if (!ret)
69639 + if (!ret) {
69640 arch_ptrace_attach(child);
69641 + gr_audit_ptrace(child);
69642 + }
69643 goto out_put_task_struct;
69644 }
69645
69646 diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
69647 index 547b1fe..65e874e 100644
69648 --- a/kernel/rcutiny.c
69649 +++ b/kernel/rcutiny.c
69650 @@ -46,7 +46,7 @@
69651 struct rcu_ctrlblk;
69652 static void invoke_rcu_callbacks(void);
69653 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
69654 -static void rcu_process_callbacks(struct softirq_action *unused);
69655 +static void rcu_process_callbacks(void);
69656 static void __call_rcu(struct rcu_head *head,
69657 void (*func)(struct rcu_head *rcu),
69658 struct rcu_ctrlblk *rcp);
69659 @@ -307,7 +307,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
69660 rcu_is_callbacks_kthread()));
69661 }
69662
69663 -static void rcu_process_callbacks(struct softirq_action *unused)
69664 +static void rcu_process_callbacks(void)
69665 {
69666 __rcu_process_callbacks(&rcu_sched_ctrlblk);
69667 __rcu_process_callbacks(&rcu_bh_ctrlblk);
69668 diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
69669 index 918fd1e..85089bb 100644
69670 --- a/kernel/rcutiny_plugin.h
69671 +++ b/kernel/rcutiny_plugin.h
69672 @@ -893,7 +893,7 @@ static int rcu_kthread(void *arg)
69673 have_rcu_kthread_work = morework;
69674 local_irq_restore(flags);
69675 if (work)
69676 - rcu_process_callbacks(NULL);
69677 + rcu_process_callbacks();
69678 schedule_timeout_interruptible(1); /* Leave CPU for others. */
69679 }
69680
69681 diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
69682 index 25b1503..1988a74 100644
69683 --- a/kernel/rcutorture.c
69684 +++ b/kernel/rcutorture.c
69685 @@ -162,12 +162,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
69686 { 0 };
69687 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
69688 { 0 };
69689 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
69690 -static atomic_t n_rcu_torture_alloc;
69691 -static atomic_t n_rcu_torture_alloc_fail;
69692 -static atomic_t n_rcu_torture_free;
69693 -static atomic_t n_rcu_torture_mberror;
69694 -static atomic_t n_rcu_torture_error;
69695 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
69696 +static atomic_unchecked_t n_rcu_torture_alloc;
69697 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
69698 +static atomic_unchecked_t n_rcu_torture_free;
69699 +static atomic_unchecked_t n_rcu_torture_mberror;
69700 +static atomic_unchecked_t n_rcu_torture_error;
69701 static long n_rcu_torture_barrier_error;
69702 static long n_rcu_torture_boost_ktrerror;
69703 static long n_rcu_torture_boost_rterror;
69704 @@ -265,11 +265,11 @@ rcu_torture_alloc(void)
69705
69706 spin_lock_bh(&rcu_torture_lock);
69707 if (list_empty(&rcu_torture_freelist)) {
69708 - atomic_inc(&n_rcu_torture_alloc_fail);
69709 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
69710 spin_unlock_bh(&rcu_torture_lock);
69711 return NULL;
69712 }
69713 - atomic_inc(&n_rcu_torture_alloc);
69714 + atomic_inc_unchecked(&n_rcu_torture_alloc);
69715 p = rcu_torture_freelist.next;
69716 list_del_init(p);
69717 spin_unlock_bh(&rcu_torture_lock);
69718 @@ -282,7 +282,7 @@ rcu_torture_alloc(void)
69719 static void
69720 rcu_torture_free(struct rcu_torture *p)
69721 {
69722 - atomic_inc(&n_rcu_torture_free);
69723 + atomic_inc_unchecked(&n_rcu_torture_free);
69724 spin_lock_bh(&rcu_torture_lock);
69725 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
69726 spin_unlock_bh(&rcu_torture_lock);
69727 @@ -403,7 +403,7 @@ rcu_torture_cb(struct rcu_head *p)
69728 i = rp->rtort_pipe_count;
69729 if (i > RCU_TORTURE_PIPE_LEN)
69730 i = RCU_TORTURE_PIPE_LEN;
69731 - atomic_inc(&rcu_torture_wcount[i]);
69732 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
69733 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
69734 rp->rtort_mbtest = 0;
69735 rcu_torture_free(rp);
69736 @@ -452,7 +452,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
69737 i = rp->rtort_pipe_count;
69738 if (i > RCU_TORTURE_PIPE_LEN)
69739 i = RCU_TORTURE_PIPE_LEN;
69740 - atomic_inc(&rcu_torture_wcount[i]);
69741 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
69742 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
69743 rp->rtort_mbtest = 0;
69744 list_del(&rp->rtort_free);
69745 @@ -995,7 +995,7 @@ rcu_torture_writer(void *arg)
69746 i = old_rp->rtort_pipe_count;
69747 if (i > RCU_TORTURE_PIPE_LEN)
69748 i = RCU_TORTURE_PIPE_LEN;
69749 - atomic_inc(&rcu_torture_wcount[i]);
69750 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
69751 old_rp->rtort_pipe_count++;
69752 cur_ops->deferred_free(old_rp);
69753 }
69754 @@ -1080,7 +1080,7 @@ static void rcu_torture_timer(unsigned long unused)
69755 }
69756 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
69757 if (p->rtort_mbtest == 0)
69758 - atomic_inc(&n_rcu_torture_mberror);
69759 + atomic_inc_unchecked(&n_rcu_torture_mberror);
69760 spin_lock(&rand_lock);
69761 cur_ops->read_delay(&rand);
69762 n_rcu_torture_timers++;
69763 @@ -1144,7 +1144,7 @@ rcu_torture_reader(void *arg)
69764 }
69765 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
69766 if (p->rtort_mbtest == 0)
69767 - atomic_inc(&n_rcu_torture_mberror);
69768 + atomic_inc_unchecked(&n_rcu_torture_mberror);
69769 cur_ops->read_delay(&rand);
69770 preempt_disable();
69771 pipe_count = p->rtort_pipe_count;
69772 @@ -1203,11 +1203,11 @@ rcu_torture_printk(char *page)
69773 rcu_torture_current,
69774 rcu_torture_current_version,
69775 list_empty(&rcu_torture_freelist),
69776 - atomic_read(&n_rcu_torture_alloc),
69777 - atomic_read(&n_rcu_torture_alloc_fail),
69778 - atomic_read(&n_rcu_torture_free));
69779 + atomic_read_unchecked(&n_rcu_torture_alloc),
69780 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
69781 + atomic_read_unchecked(&n_rcu_torture_free));
69782 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
69783 - atomic_read(&n_rcu_torture_mberror),
69784 + atomic_read_unchecked(&n_rcu_torture_mberror),
69785 n_rcu_torture_boost_ktrerror,
69786 n_rcu_torture_boost_rterror);
69787 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
69788 @@ -1224,14 +1224,14 @@ rcu_torture_printk(char *page)
69789 n_barrier_attempts,
69790 n_rcu_torture_barrier_error);
69791 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
69792 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
69793 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
69794 n_rcu_torture_barrier_error != 0 ||
69795 n_rcu_torture_boost_ktrerror != 0 ||
69796 n_rcu_torture_boost_rterror != 0 ||
69797 n_rcu_torture_boost_failure != 0 ||
69798 i > 1) {
69799 cnt += sprintf(&page[cnt], "!!! ");
69800 - atomic_inc(&n_rcu_torture_error);
69801 + atomic_inc_unchecked(&n_rcu_torture_error);
69802 WARN_ON_ONCE(1);
69803 }
69804 cnt += sprintf(&page[cnt], "Reader Pipe: ");
69805 @@ -1245,7 +1245,7 @@ rcu_torture_printk(char *page)
69806 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
69807 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
69808 cnt += sprintf(&page[cnt], " %d",
69809 - atomic_read(&rcu_torture_wcount[i]));
69810 + atomic_read_unchecked(&rcu_torture_wcount[i]));
69811 }
69812 cnt += sprintf(&page[cnt], "\n");
69813 if (cur_ops->stats)
69814 @@ -1905,7 +1905,7 @@ rcu_torture_cleanup(void)
69815
69816 if (cur_ops->cleanup)
69817 cur_ops->cleanup();
69818 - if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
69819 + if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
69820 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
69821 else if (n_online_successes != n_online_attempts ||
69822 n_offline_successes != n_offline_attempts)
69823 @@ -1974,18 +1974,18 @@ rcu_torture_init(void)
69824
69825 rcu_torture_current = NULL;
69826 rcu_torture_current_version = 0;
69827 - atomic_set(&n_rcu_torture_alloc, 0);
69828 - atomic_set(&n_rcu_torture_alloc_fail, 0);
69829 - atomic_set(&n_rcu_torture_free, 0);
69830 - atomic_set(&n_rcu_torture_mberror, 0);
69831 - atomic_set(&n_rcu_torture_error, 0);
69832 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
69833 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
69834 + atomic_set_unchecked(&n_rcu_torture_free, 0);
69835 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
69836 + atomic_set_unchecked(&n_rcu_torture_error, 0);
69837 n_rcu_torture_barrier_error = 0;
69838 n_rcu_torture_boost_ktrerror = 0;
69839 n_rcu_torture_boost_rterror = 0;
69840 n_rcu_torture_boost_failure = 0;
69841 n_rcu_torture_boosts = 0;
69842 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
69843 - atomic_set(&rcu_torture_wcount[i], 0);
69844 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
69845 for_each_possible_cpu(cpu) {
69846 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
69847 per_cpu(rcu_torture_count, cpu)[i] = 0;
69848 diff --git a/kernel/rcutree.c b/kernel/rcutree.c
69849 index f7bcd9e..8973e14 100644
69850 --- a/kernel/rcutree.c
69851 +++ b/kernel/rcutree.c
69852 @@ -369,9 +369,9 @@ static void rcu_idle_enter_common(struct rcu_dynticks *rdtp, long long oldval)
69853 rcu_prepare_for_idle(smp_processor_id());
69854 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
69855 smp_mb__before_atomic_inc(); /* See above. */
69856 - atomic_inc(&rdtp->dynticks);
69857 + atomic_inc_unchecked(&rdtp->dynticks);
69858 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
69859 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
69860 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
69861
69862 /*
69863 * The idle task is not permitted to enter the idle loop while
69864 @@ -460,10 +460,10 @@ void rcu_irq_exit(void)
69865 static void rcu_idle_exit_common(struct rcu_dynticks *rdtp, long long oldval)
69866 {
69867 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
69868 - atomic_inc(&rdtp->dynticks);
69869 + atomic_inc_unchecked(&rdtp->dynticks);
69870 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
69871 smp_mb__after_atomic_inc(); /* See above. */
69872 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
69873 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
69874 rcu_cleanup_after_idle(smp_processor_id());
69875 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
69876 if (!is_idle_task(current)) {
69877 @@ -557,14 +557,14 @@ void rcu_nmi_enter(void)
69878 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
69879
69880 if (rdtp->dynticks_nmi_nesting == 0 &&
69881 - (atomic_read(&rdtp->dynticks) & 0x1))
69882 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
69883 return;
69884 rdtp->dynticks_nmi_nesting++;
69885 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
69886 - atomic_inc(&rdtp->dynticks);
69887 + atomic_inc_unchecked(&rdtp->dynticks);
69888 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
69889 smp_mb__after_atomic_inc(); /* See above. */
69890 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
69891 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
69892 }
69893
69894 /**
69895 @@ -583,9 +583,9 @@ void rcu_nmi_exit(void)
69896 return;
69897 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
69898 smp_mb__before_atomic_inc(); /* See above. */
69899 - atomic_inc(&rdtp->dynticks);
69900 + atomic_inc_unchecked(&rdtp->dynticks);
69901 smp_mb__after_atomic_inc(); /* Force delay to next write. */
69902 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
69903 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
69904 }
69905
69906 /**
69907 @@ -599,7 +599,7 @@ int rcu_is_cpu_idle(void)
69908 int ret;
69909
69910 preempt_disable();
69911 - ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
69912 + ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
69913 preempt_enable();
69914 return ret;
69915 }
69916 @@ -667,7 +667,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
69917 */
69918 static int dyntick_save_progress_counter(struct rcu_data *rdp)
69919 {
69920 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
69921 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
69922 return (rdp->dynticks_snap & 0x1) == 0;
69923 }
69924
69925 @@ -682,7 +682,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
69926 unsigned int curr;
69927 unsigned int snap;
69928
69929 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
69930 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
69931 snap = (unsigned int)rdp->dynticks_snap;
69932
69933 /*
69934 @@ -712,10 +712,10 @@ static int jiffies_till_stall_check(void)
69935 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
69936 */
69937 if (till_stall_check < 3) {
69938 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
69939 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
69940 till_stall_check = 3;
69941 } else if (till_stall_check > 300) {
69942 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
69943 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
69944 till_stall_check = 300;
69945 }
69946 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
69947 @@ -1351,7 +1351,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
69948 rsp->qlen += rdp->qlen;
69949 rdp->n_cbs_orphaned += rdp->qlen;
69950 rdp->qlen_lazy = 0;
69951 - ACCESS_ONCE(rdp->qlen) = 0;
69952 + ACCESS_ONCE_RW(rdp->qlen) = 0;
69953 }
69954
69955 /*
69956 @@ -1604,7 +1604,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
69957 }
69958 smp_mb(); /* List handling before counting for rcu_barrier(). */
69959 rdp->qlen_lazy -= count_lazy;
69960 - ACCESS_ONCE(rdp->qlen) -= count;
69961 + ACCESS_ONCE_RW(rdp->qlen) -= count;
69962 rdp->n_cbs_invoked += count;
69963
69964 /* Reinstate batch limit if we have worked down the excess. */
69965 @@ -1836,7 +1836,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
69966 /*
69967 * Do RCU core processing for the current CPU.
69968 */
69969 -static void rcu_process_callbacks(struct softirq_action *unused)
69970 +static void rcu_process_callbacks(void)
69971 {
69972 struct rcu_state *rsp;
69973
69974 @@ -1943,7 +1943,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
69975 rdp = this_cpu_ptr(rsp->rda);
69976
69977 /* Add the callback to our list. */
69978 - ACCESS_ONCE(rdp->qlen)++;
69979 + ACCESS_ONCE_RW(rdp->qlen)++;
69980 if (lazy)
69981 rdp->qlen_lazy++;
69982 else
69983 @@ -2057,8 +2057,8 @@ void synchronize_rcu_bh(void)
69984 }
69985 EXPORT_SYMBOL_GPL(synchronize_rcu_bh);
69986
69987 -static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
69988 -static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
69989 +static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
69990 +static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
69991
69992 static int synchronize_sched_expedited_cpu_stop(void *data)
69993 {
69994 @@ -2119,7 +2119,7 @@ void synchronize_sched_expedited(void)
69995 int firstsnap, s, snap, trycount = 0;
69996
69997 /* Note that atomic_inc_return() implies full memory barrier. */
69998 - firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
69999 + firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
70000 get_online_cpus();
70001 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
70002
70003 @@ -2141,7 +2141,7 @@ void synchronize_sched_expedited(void)
70004 }
70005
70006 /* Check to see if someone else did our work for us. */
70007 - s = atomic_read(&sync_sched_expedited_done);
70008 + s = atomic_read_unchecked(&sync_sched_expedited_done);
70009 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
70010 smp_mb(); /* ensure test happens before caller kfree */
70011 return;
70012 @@ -2156,7 +2156,7 @@ void synchronize_sched_expedited(void)
70013 * grace period works for us.
70014 */
70015 get_online_cpus();
70016 - snap = atomic_read(&sync_sched_expedited_started);
70017 + snap = atomic_read_unchecked(&sync_sched_expedited_started);
70018 smp_mb(); /* ensure read is before try_stop_cpus(). */
70019 }
70020
70021 @@ -2167,12 +2167,12 @@ void synchronize_sched_expedited(void)
70022 * than we did beat us to the punch.
70023 */
70024 do {
70025 - s = atomic_read(&sync_sched_expedited_done);
70026 + s = atomic_read_unchecked(&sync_sched_expedited_done);
70027 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
70028 smp_mb(); /* ensure test happens before caller kfree */
70029 break;
70030 }
70031 - } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
70032 + } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
70033
70034 put_online_cpus();
70035 }
70036 @@ -2366,7 +2366,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
70037 * ACCESS_ONCE() to prevent the compiler from speculating
70038 * the increment to precede the early-exit check.
70039 */
70040 - ACCESS_ONCE(rsp->n_barrier_done)++;
70041 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
70042 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
70043 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
70044 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
70045 @@ -2448,7 +2448,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
70046
70047 /* Increment ->n_barrier_done to prevent duplicate work. */
70048 smp_mb(); /* Keep increment after above mechanism. */
70049 - ACCESS_ONCE(rsp->n_barrier_done)++;
70050 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
70051 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
70052 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
70053 smp_mb(); /* Keep increment before caller's subsequent code. */
70054 @@ -2495,10 +2495,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
70055 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
70056 init_callback_list(rdp);
70057 rdp->qlen_lazy = 0;
70058 - ACCESS_ONCE(rdp->qlen) = 0;
70059 + ACCESS_ONCE_RW(rdp->qlen) = 0;
70060 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
70061 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
70062 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
70063 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
70064 rdp->cpu = cpu;
70065 rdp->rsp = rsp;
70066 raw_spin_unlock_irqrestore(&rnp->lock, flags);
70067 @@ -2526,8 +2526,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
70068 rdp->n_force_qs_snap = rsp->n_force_qs;
70069 rdp->blimit = blimit;
70070 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
70071 - atomic_set(&rdp->dynticks->dynticks,
70072 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
70073 + atomic_set_unchecked(&rdp->dynticks->dynticks,
70074 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
70075 rcu_prepare_for_idle_init(cpu);
70076 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
70077
70078 diff --git a/kernel/rcutree.h b/kernel/rcutree.h
70079 index 4d29169..d104a3c 100644
70080 --- a/kernel/rcutree.h
70081 +++ b/kernel/rcutree.h
70082 @@ -86,7 +86,7 @@ struct rcu_dynticks {
70083 long long dynticks_nesting; /* Track irq/process nesting level. */
70084 /* Process level is worth LLONG_MAX/2. */
70085 int dynticks_nmi_nesting; /* Track NMI nesting level. */
70086 - atomic_t dynticks; /* Even value for idle, else odd. */
70087 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
70088 #ifdef CONFIG_RCU_FAST_NO_HZ
70089 int dyntick_drain; /* Prepare-for-idle state variable. */
70090 unsigned long dyntick_holdoff;
70091 diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
70092 index 7f3244c..417d606 100644
70093 --- a/kernel/rcutree_plugin.h
70094 +++ b/kernel/rcutree_plugin.h
70095 @@ -843,7 +843,7 @@ void synchronize_rcu_expedited(void)
70096
70097 /* Clean up and exit. */
70098 smp_mb(); /* ensure expedited GP seen before counter increment. */
70099 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
70100 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
70101 unlock_mb_ret:
70102 mutex_unlock(&sync_rcu_preempt_exp_mutex);
70103 mb_ret:
70104 diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
70105 index abffb48..cbfa6d3 100644
70106 --- a/kernel/rcutree_trace.c
70107 +++ b/kernel/rcutree_trace.c
70108 @@ -93,7 +93,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
70109 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
70110 rdp->qs_pending);
70111 seq_printf(m, " dt=%d/%llx/%d df=%lu",
70112 - atomic_read(&rdp->dynticks->dynticks),
70113 + atomic_read_unchecked(&rdp->dynticks->dynticks),
70114 rdp->dynticks->dynticks_nesting,
70115 rdp->dynticks->dynticks_nmi_nesting,
70116 rdp->dynticks_fqs);
70117 @@ -157,7 +157,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
70118 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
70119 rdp->qs_pending);
70120 seq_printf(m, ",%d,%llx,%d,%lu",
70121 - atomic_read(&rdp->dynticks->dynticks),
70122 + atomic_read_unchecked(&rdp->dynticks->dynticks),
70123 rdp->dynticks->dynticks_nesting,
70124 rdp->dynticks->dynticks_nmi_nesting,
70125 rdp->dynticks_fqs);
70126 diff --git a/kernel/resource.c b/kernel/resource.c
70127 index 34d4588..10baa6a 100644
70128 --- a/kernel/resource.c
70129 +++ b/kernel/resource.c
70130 @@ -143,8 +143,18 @@ static const struct file_operations proc_iomem_operations = {
70131
70132 static int __init ioresources_init(void)
70133 {
70134 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
70135 +#ifdef CONFIG_GRKERNSEC_PROC_USER
70136 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
70137 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
70138 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
70139 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
70140 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
70141 +#endif
70142 +#else
70143 proc_create("ioports", 0, NULL, &proc_ioports_operations);
70144 proc_create("iomem", 0, NULL, &proc_iomem_operations);
70145 +#endif
70146 return 0;
70147 }
70148 __initcall(ioresources_init);
70149 diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
70150 index 98ec494..4241d6d 100644
70151 --- a/kernel/rtmutex-tester.c
70152 +++ b/kernel/rtmutex-tester.c
70153 @@ -20,7 +20,7 @@
70154 #define MAX_RT_TEST_MUTEXES 8
70155
70156 static spinlock_t rttest_lock;
70157 -static atomic_t rttest_event;
70158 +static atomic_unchecked_t rttest_event;
70159
70160 struct test_thread_data {
70161 int opcode;
70162 @@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
70163
70164 case RTTEST_LOCKCONT:
70165 td->mutexes[td->opdata] = 1;
70166 - td->event = atomic_add_return(1, &rttest_event);
70167 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70168 return 0;
70169
70170 case RTTEST_RESET:
70171 @@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
70172 return 0;
70173
70174 case RTTEST_RESETEVENT:
70175 - atomic_set(&rttest_event, 0);
70176 + atomic_set_unchecked(&rttest_event, 0);
70177 return 0;
70178
70179 default:
70180 @@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
70181 return ret;
70182
70183 td->mutexes[id] = 1;
70184 - td->event = atomic_add_return(1, &rttest_event);
70185 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70186 rt_mutex_lock(&mutexes[id]);
70187 - td->event = atomic_add_return(1, &rttest_event);
70188 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70189 td->mutexes[id] = 4;
70190 return 0;
70191
70192 @@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
70193 return ret;
70194
70195 td->mutexes[id] = 1;
70196 - td->event = atomic_add_return(1, &rttest_event);
70197 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70198 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
70199 - td->event = atomic_add_return(1, &rttest_event);
70200 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70201 td->mutexes[id] = ret ? 0 : 4;
70202 return ret ? -EINTR : 0;
70203
70204 @@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
70205 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
70206 return ret;
70207
70208 - td->event = atomic_add_return(1, &rttest_event);
70209 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70210 rt_mutex_unlock(&mutexes[id]);
70211 - td->event = atomic_add_return(1, &rttest_event);
70212 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70213 td->mutexes[id] = 0;
70214 return 0;
70215
70216 @@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
70217 break;
70218
70219 td->mutexes[dat] = 2;
70220 - td->event = atomic_add_return(1, &rttest_event);
70221 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70222 break;
70223
70224 default:
70225 @@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
70226 return;
70227
70228 td->mutexes[dat] = 3;
70229 - td->event = atomic_add_return(1, &rttest_event);
70230 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70231 break;
70232
70233 case RTTEST_LOCKNOWAIT:
70234 @@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
70235 return;
70236
70237 td->mutexes[dat] = 1;
70238 - td->event = atomic_add_return(1, &rttest_event);
70239 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70240 return;
70241
70242 default:
70243 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
70244 index 0984a21..939f183 100644
70245 --- a/kernel/sched/auto_group.c
70246 +++ b/kernel/sched/auto_group.c
70247 @@ -11,7 +11,7 @@
70248
70249 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
70250 static struct autogroup autogroup_default;
70251 -static atomic_t autogroup_seq_nr;
70252 +static atomic_unchecked_t autogroup_seq_nr;
70253
70254 void __init autogroup_init(struct task_struct *init_task)
70255 {
70256 @@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
70257
70258 kref_init(&ag->kref);
70259 init_rwsem(&ag->lock);
70260 - ag->id = atomic_inc_return(&autogroup_seq_nr);
70261 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
70262 ag->tg = tg;
70263 #ifdef CONFIG_RT_GROUP_SCHED
70264 /*
70265 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
70266 index 1a48cdb..d3949ff 100644
70267 --- a/kernel/sched/core.c
70268 +++ b/kernel/sched/core.c
70269 @@ -4103,6 +4103,8 @@ int can_nice(const struct task_struct *p, const int nice)
70270 /* convert nice value [19,-20] to rlimit style value [1,40] */
70271 int nice_rlim = 20 - nice;
70272
70273 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
70274 +
70275 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
70276 capable(CAP_SYS_NICE));
70277 }
70278 @@ -4136,7 +4138,8 @@ SYSCALL_DEFINE1(nice, int, increment)
70279 if (nice > 19)
70280 nice = 19;
70281
70282 - if (increment < 0 && !can_nice(current, nice))
70283 + if (increment < 0 && (!can_nice(current, nice) ||
70284 + gr_handle_chroot_nice()))
70285 return -EPERM;
70286
70287 retval = security_task_setnice(current, nice);
70288 @@ -4290,6 +4293,7 @@ recheck:
70289 unsigned long rlim_rtprio =
70290 task_rlimit(p, RLIMIT_RTPRIO);
70291
70292 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
70293 /* can't set/change the rt policy */
70294 if (policy != p->policy && !rlim_rtprio)
70295 return -EPERM;
70296 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
70297 index 96e2b18..bb31eec 100644
70298 --- a/kernel/sched/fair.c
70299 +++ b/kernel/sched/fair.c
70300 @@ -4923,7 +4923,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
70301 * run_rebalance_domains is triggered when needed from the scheduler tick.
70302 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
70303 */
70304 -static void run_rebalance_domains(struct softirq_action *h)
70305 +static void run_rebalance_domains(void)
70306 {
70307 int this_cpu = smp_processor_id();
70308 struct rq *this_rq = cpu_rq(this_cpu);
70309 diff --git a/kernel/signal.c b/kernel/signal.c
70310 index be4f856..453401c 100644
70311 --- a/kernel/signal.c
70312 +++ b/kernel/signal.c
70313 @@ -48,12 +48,12 @@ static struct kmem_cache *sigqueue_cachep;
70314
70315 int print_fatal_signals __read_mostly;
70316
70317 -static void __user *sig_handler(struct task_struct *t, int sig)
70318 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
70319 {
70320 return t->sighand->action[sig - 1].sa.sa_handler;
70321 }
70322
70323 -static int sig_handler_ignored(void __user *handler, int sig)
70324 +static int sig_handler_ignored(__sighandler_t handler, int sig)
70325 {
70326 /* Is it explicitly or implicitly ignored? */
70327 return handler == SIG_IGN ||
70328 @@ -62,7 +62,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
70329
70330 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
70331 {
70332 - void __user *handler;
70333 + __sighandler_t handler;
70334
70335 handler = sig_handler(t, sig);
70336
70337 @@ -366,6 +366,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
70338 atomic_inc(&user->sigpending);
70339 rcu_read_unlock();
70340
70341 + if (!override_rlimit)
70342 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
70343 +
70344 if (override_rlimit ||
70345 atomic_read(&user->sigpending) <=
70346 task_rlimit(t, RLIMIT_SIGPENDING)) {
70347 @@ -490,7 +493,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
70348
70349 int unhandled_signal(struct task_struct *tsk, int sig)
70350 {
70351 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
70352 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
70353 if (is_global_init(tsk))
70354 return 1;
70355 if (handler != SIG_IGN && handler != SIG_DFL)
70356 @@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
70357 }
70358 }
70359
70360 + /* allow glibc communication via tgkill to other threads in our
70361 + thread group */
70362 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
70363 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
70364 + && gr_handle_signal(t, sig))
70365 + return -EPERM;
70366 +
70367 return security_task_kill(t, info, sig, 0);
70368 }
70369
70370 @@ -1197,7 +1207,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
70371 return send_signal(sig, info, p, 1);
70372 }
70373
70374 -static int
70375 +int
70376 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
70377 {
70378 return send_signal(sig, info, t, 0);
70379 @@ -1234,6 +1244,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
70380 unsigned long int flags;
70381 int ret, blocked, ignored;
70382 struct k_sigaction *action;
70383 + int is_unhandled = 0;
70384
70385 spin_lock_irqsave(&t->sighand->siglock, flags);
70386 action = &t->sighand->action[sig-1];
70387 @@ -1248,9 +1259,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
70388 }
70389 if (action->sa.sa_handler == SIG_DFL)
70390 t->signal->flags &= ~SIGNAL_UNKILLABLE;
70391 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
70392 + is_unhandled = 1;
70393 ret = specific_send_sig_info(sig, info, t);
70394 spin_unlock_irqrestore(&t->sighand->siglock, flags);
70395
70396 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
70397 + normal operation */
70398 + if (is_unhandled) {
70399 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
70400 + gr_handle_crash(t, sig);
70401 + }
70402 +
70403 return ret;
70404 }
70405
70406 @@ -1317,8 +1337,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
70407 ret = check_kill_permission(sig, info, p);
70408 rcu_read_unlock();
70409
70410 - if (!ret && sig)
70411 + if (!ret && sig) {
70412 ret = do_send_sig_info(sig, info, p, true);
70413 + if (!ret)
70414 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
70415 + }
70416
70417 return ret;
70418 }
70419 @@ -2873,7 +2896,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
70420 int error = -ESRCH;
70421
70422 rcu_read_lock();
70423 - p = find_task_by_vpid(pid);
70424 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
70425 + /* allow glibc communication via tgkill to other threads in our
70426 + thread group */
70427 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
70428 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
70429 + p = find_task_by_vpid_unrestricted(pid);
70430 + else
70431 +#endif
70432 + p = find_task_by_vpid(pid);
70433 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
70434 error = check_kill_permission(sig, info, p);
70435 /*
70436 diff --git a/kernel/softirq.c b/kernel/softirq.c
70437 index b73e681..645ab62 100644
70438 --- a/kernel/softirq.c
70439 +++ b/kernel/softirq.c
70440 @@ -56,7 +56,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
70441
70442 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
70443
70444 -char *softirq_to_name[NR_SOFTIRQS] = {
70445 +const char * const softirq_to_name[NR_SOFTIRQS] = {
70446 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
70447 "TASKLET", "SCHED", "HRTIMER", "RCU"
70448 };
70449 @@ -243,7 +243,7 @@ restart:
70450 kstat_incr_softirqs_this_cpu(vec_nr);
70451
70452 trace_softirq_entry(vec_nr);
70453 - h->action(h);
70454 + h->action();
70455 trace_softirq_exit(vec_nr);
70456 if (unlikely(prev_count != preempt_count())) {
70457 printk(KERN_ERR "huh, entered softirq %u %s %p"
70458 @@ -390,9 +390,11 @@ void __raise_softirq_irqoff(unsigned int nr)
70459 or_softirq_pending(1UL << nr);
70460 }
70461
70462 -void open_softirq(int nr, void (*action)(struct softirq_action *))
70463 +void open_softirq(int nr, void (*action)(void))
70464 {
70465 - softirq_vec[nr].action = action;
70466 + pax_open_kernel();
70467 + *(void **)&softirq_vec[nr].action = action;
70468 + pax_close_kernel();
70469 }
70470
70471 /*
70472 @@ -446,7 +448,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
70473
70474 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
70475
70476 -static void tasklet_action(struct softirq_action *a)
70477 +static void tasklet_action(void)
70478 {
70479 struct tasklet_struct *list;
70480
70481 @@ -481,7 +483,7 @@ static void tasklet_action(struct softirq_action *a)
70482 }
70483 }
70484
70485 -static void tasklet_hi_action(struct softirq_action *a)
70486 +static void tasklet_hi_action(void)
70487 {
70488 struct tasklet_struct *list;
70489
70490 diff --git a/kernel/srcu.c b/kernel/srcu.c
70491 index 2095be3..9a5b89d 100644
70492 --- a/kernel/srcu.c
70493 +++ b/kernel/srcu.c
70494 @@ -302,9 +302,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
70495 preempt_disable();
70496 idx = rcu_dereference_index_check(sp->completed,
70497 rcu_read_lock_sched_held()) & 0x1;
70498 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
70499 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
70500 smp_mb(); /* B */ /* Avoid leaking the critical section. */
70501 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
70502 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
70503 preempt_enable();
70504 return idx;
70505 }
70506 @@ -320,7 +320,7 @@ void __srcu_read_unlock(struct srcu_struct *sp, int idx)
70507 {
70508 preempt_disable();
70509 smp_mb(); /* C */ /* Avoid leaking the critical section. */
70510 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
70511 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
70512 preempt_enable();
70513 }
70514 EXPORT_SYMBOL_GPL(__srcu_read_unlock);
70515 diff --git a/kernel/sys.c b/kernel/sys.c
70516 index 909148a..cd51acf 100644
70517 --- a/kernel/sys.c
70518 +++ b/kernel/sys.c
70519 @@ -157,6 +157,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
70520 error = -EACCES;
70521 goto out;
70522 }
70523 +
70524 + if (gr_handle_chroot_setpriority(p, niceval)) {
70525 + error = -EACCES;
70526 + goto out;
70527 + }
70528 +
70529 no_nice = security_task_setnice(p, niceval);
70530 if (no_nice) {
70531 error = no_nice;
70532 @@ -595,6 +601,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
70533 goto error;
70534 }
70535
70536 + if (gr_check_group_change(new->gid, new->egid, -1))
70537 + goto error;
70538 +
70539 if (rgid != (gid_t) -1 ||
70540 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
70541 new->sgid = new->egid;
70542 @@ -630,6 +639,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
70543 old = current_cred();
70544
70545 retval = -EPERM;
70546 +
70547 + if (gr_check_group_change(kgid, kgid, kgid))
70548 + goto error;
70549 +
70550 if (nsown_capable(CAP_SETGID))
70551 new->gid = new->egid = new->sgid = new->fsgid = kgid;
70552 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
70553 @@ -647,7 +660,7 @@ error:
70554 /*
70555 * change the user struct in a credentials set to match the new UID
70556 */
70557 -static int set_user(struct cred *new)
70558 +int set_user(struct cred *new)
70559 {
70560 struct user_struct *new_user;
70561
70562 @@ -727,6 +740,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
70563 goto error;
70564 }
70565
70566 + if (gr_check_user_change(new->uid, new->euid, -1))
70567 + goto error;
70568 +
70569 if (!uid_eq(new->uid, old->uid)) {
70570 retval = set_user(new);
70571 if (retval < 0)
70572 @@ -777,6 +793,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
70573 old = current_cred();
70574
70575 retval = -EPERM;
70576 +
70577 + if (gr_check_crash_uid(kuid))
70578 + goto error;
70579 + if (gr_check_user_change(kuid, kuid, kuid))
70580 + goto error;
70581 +
70582 if (nsown_capable(CAP_SETUID)) {
70583 new->suid = new->uid = kuid;
70584 if (!uid_eq(kuid, old->uid)) {
70585 @@ -846,6 +868,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
70586 goto error;
70587 }
70588
70589 + if (gr_check_user_change(kruid, keuid, -1))
70590 + goto error;
70591 +
70592 if (ruid != (uid_t) -1) {
70593 new->uid = kruid;
70594 if (!uid_eq(kruid, old->uid)) {
70595 @@ -928,6 +953,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
70596 goto error;
70597 }
70598
70599 + if (gr_check_group_change(krgid, kegid, -1))
70600 + goto error;
70601 +
70602 if (rgid != (gid_t) -1)
70603 new->gid = krgid;
70604 if (egid != (gid_t) -1)
70605 @@ -981,6 +1009,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
70606 if (!uid_valid(kuid))
70607 return old_fsuid;
70608
70609 + if (gr_check_user_change(-1, -1, kuid))
70610 + goto error;
70611 +
70612 new = prepare_creds();
70613 if (!new)
70614 return old_fsuid;
70615 @@ -995,6 +1026,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
70616 }
70617 }
70618
70619 +error:
70620 abort_creds(new);
70621 return old_fsuid;
70622
70623 @@ -1027,12 +1059,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
70624 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
70625 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
70626 nsown_capable(CAP_SETGID)) {
70627 + if (gr_check_group_change(-1, -1, kgid))
70628 + goto error;
70629 +
70630 if (!gid_eq(kgid, old->fsgid)) {
70631 new->fsgid = kgid;
70632 goto change_okay;
70633 }
70634 }
70635
70636 +error:
70637 abort_creds(new);
70638 return old_fsgid;
70639
70640 @@ -1340,19 +1376,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
70641 return -EFAULT;
70642
70643 down_read(&uts_sem);
70644 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
70645 + error = __copy_to_user(name->sysname, &utsname()->sysname,
70646 __OLD_UTS_LEN);
70647 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
70648 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
70649 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
70650 __OLD_UTS_LEN);
70651 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
70652 - error |= __copy_to_user(&name->release, &utsname()->release,
70653 + error |= __copy_to_user(name->release, &utsname()->release,
70654 __OLD_UTS_LEN);
70655 error |= __put_user(0, name->release + __OLD_UTS_LEN);
70656 - error |= __copy_to_user(&name->version, &utsname()->version,
70657 + error |= __copy_to_user(name->version, &utsname()->version,
70658 __OLD_UTS_LEN);
70659 error |= __put_user(0, name->version + __OLD_UTS_LEN);
70660 - error |= __copy_to_user(&name->machine, &utsname()->machine,
70661 + error |= __copy_to_user(name->machine, &utsname()->machine,
70662 __OLD_UTS_LEN);
70663 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
70664 up_read(&uts_sem);
70665 @@ -2026,7 +2062,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
70666 error = get_dumpable(me->mm);
70667 break;
70668 case PR_SET_DUMPABLE:
70669 - if (arg2 < 0 || arg2 > 1) {
70670 + if (arg2 > 1) {
70671 error = -EINVAL;
70672 break;
70673 }
70674 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
70675 index 87174ef..68cbb82 100644
70676 --- a/kernel/sysctl.c
70677 +++ b/kernel/sysctl.c
70678 @@ -92,7 +92,6 @@
70679
70680
70681 #if defined(CONFIG_SYSCTL)
70682 -
70683 /* External variables not in a header file. */
70684 extern int sysctl_overcommit_memory;
70685 extern int sysctl_overcommit_ratio;
70686 @@ -170,10 +169,8 @@ static int proc_taint(struct ctl_table *table, int write,
70687 void __user *buffer, size_t *lenp, loff_t *ppos);
70688 #endif
70689
70690 -#ifdef CONFIG_PRINTK
70691 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
70692 void __user *buffer, size_t *lenp, loff_t *ppos);
70693 -#endif
70694
70695 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
70696 void __user *buffer, size_t *lenp, loff_t *ppos);
70697 @@ -202,6 +199,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
70698
70699 #endif
70700
70701 +extern struct ctl_table grsecurity_table[];
70702 +
70703 static struct ctl_table kern_table[];
70704 static struct ctl_table vm_table[];
70705 static struct ctl_table fs_table[];
70706 @@ -216,6 +215,20 @@ extern struct ctl_table epoll_table[];
70707 int sysctl_legacy_va_layout;
70708 #endif
70709
70710 +#ifdef CONFIG_PAX_SOFTMODE
70711 +static ctl_table pax_table[] = {
70712 + {
70713 + .procname = "softmode",
70714 + .data = &pax_softmode,
70715 + .maxlen = sizeof(unsigned int),
70716 + .mode = 0600,
70717 + .proc_handler = &proc_dointvec,
70718 + },
70719 +
70720 + { }
70721 +};
70722 +#endif
70723 +
70724 /* The default sysctl tables: */
70725
70726 static struct ctl_table sysctl_base_table[] = {
70727 @@ -262,6 +275,22 @@ static int max_extfrag_threshold = 1000;
70728 #endif
70729
70730 static struct ctl_table kern_table[] = {
70731 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
70732 + {
70733 + .procname = "grsecurity",
70734 + .mode = 0500,
70735 + .child = grsecurity_table,
70736 + },
70737 +#endif
70738 +
70739 +#ifdef CONFIG_PAX_SOFTMODE
70740 + {
70741 + .procname = "pax",
70742 + .mode = 0500,
70743 + .child = pax_table,
70744 + },
70745 +#endif
70746 +
70747 {
70748 .procname = "sched_child_runs_first",
70749 .data = &sysctl_sched_child_runs_first,
70750 @@ -546,7 +575,7 @@ static struct ctl_table kern_table[] = {
70751 .data = &modprobe_path,
70752 .maxlen = KMOD_PATH_LEN,
70753 .mode = 0644,
70754 - .proc_handler = proc_dostring,
70755 + .proc_handler = proc_dostring_modpriv,
70756 },
70757 {
70758 .procname = "modules_disabled",
70759 @@ -713,16 +742,20 @@ static struct ctl_table kern_table[] = {
70760 .extra1 = &zero,
70761 .extra2 = &one,
70762 },
70763 +#endif
70764 {
70765 .procname = "kptr_restrict",
70766 .data = &kptr_restrict,
70767 .maxlen = sizeof(int),
70768 .mode = 0644,
70769 .proc_handler = proc_dointvec_minmax_sysadmin,
70770 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70771 + .extra1 = &two,
70772 +#else
70773 .extra1 = &zero,
70774 +#endif
70775 .extra2 = &two,
70776 },
70777 -#endif
70778 {
70779 .procname = "ngroups_max",
70780 .data = &ngroups_max,
70781 @@ -1219,6 +1252,13 @@ static struct ctl_table vm_table[] = {
70782 .proc_handler = proc_dointvec_minmax,
70783 .extra1 = &zero,
70784 },
70785 + {
70786 + .procname = "heap_stack_gap",
70787 + .data = &sysctl_heap_stack_gap,
70788 + .maxlen = sizeof(sysctl_heap_stack_gap),
70789 + .mode = 0644,
70790 + .proc_handler = proc_doulongvec_minmax,
70791 + },
70792 #else
70793 {
70794 .procname = "nr_trim_pages",
70795 @@ -1670,6 +1710,16 @@ int proc_dostring(struct ctl_table *table, int write,
70796 buffer, lenp, ppos);
70797 }
70798
70799 +int proc_dostring_modpriv(struct ctl_table *table, int write,
70800 + void __user *buffer, size_t *lenp, loff_t *ppos)
70801 +{
70802 + if (write && !capable(CAP_SYS_MODULE))
70803 + return -EPERM;
70804 +
70805 + return _proc_do_string(table->data, table->maxlen, write,
70806 + buffer, lenp, ppos);
70807 +}
70808 +
70809 static size_t proc_skip_spaces(char **buf)
70810 {
70811 size_t ret;
70812 @@ -1775,6 +1825,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
70813 len = strlen(tmp);
70814 if (len > *size)
70815 len = *size;
70816 + if (len > sizeof(tmp))
70817 + len = sizeof(tmp);
70818 if (copy_to_user(*buf, tmp, len))
70819 return -EFAULT;
70820 *size -= len;
70821 @@ -1967,7 +2019,6 @@ static int proc_taint(struct ctl_table *table, int write,
70822 return err;
70823 }
70824
70825 -#ifdef CONFIG_PRINTK
70826 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
70827 void __user *buffer, size_t *lenp, loff_t *ppos)
70828 {
70829 @@ -1976,7 +2027,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
70830
70831 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
70832 }
70833 -#endif
70834
70835 struct do_proc_dointvec_minmax_conv_param {
70836 int *min;
70837 @@ -2119,8 +2169,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
70838 *i = val;
70839 } else {
70840 val = convdiv * (*i) / convmul;
70841 - if (!first)
70842 + if (!first) {
70843 err = proc_put_char(&buffer, &left, '\t');
70844 + if (err)
70845 + break;
70846 + }
70847 err = proc_put_long(&buffer, &left, val, false);
70848 if (err)
70849 break;
70850 @@ -2512,6 +2565,12 @@ int proc_dostring(struct ctl_table *table, int write,
70851 return -ENOSYS;
70852 }
70853
70854 +int proc_dostring_modpriv(struct ctl_table *table, int write,
70855 + void __user *buffer, size_t *lenp, loff_t *ppos)
70856 +{
70857 + return -ENOSYS;
70858 +}
70859 +
70860 int proc_dointvec(struct ctl_table *table, int write,
70861 void __user *buffer, size_t *lenp, loff_t *ppos)
70862 {
70863 @@ -2568,5 +2627,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
70864 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
70865 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
70866 EXPORT_SYMBOL(proc_dostring);
70867 +EXPORT_SYMBOL(proc_dostring_modpriv);
70868 EXPORT_SYMBOL(proc_doulongvec_minmax);
70869 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
70870 diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
70871 index 65bdcf1..21eb831 100644
70872 --- a/kernel/sysctl_binary.c
70873 +++ b/kernel/sysctl_binary.c
70874 @@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
70875 int i;
70876
70877 set_fs(KERNEL_DS);
70878 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
70879 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
70880 set_fs(old_fs);
70881 if (result < 0)
70882 goto out_kfree;
70883 @@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
70884 }
70885
70886 set_fs(KERNEL_DS);
70887 - result = vfs_write(file, buffer, str - buffer, &pos);
70888 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
70889 set_fs(old_fs);
70890 if (result < 0)
70891 goto out_kfree;
70892 @@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
70893 int i;
70894
70895 set_fs(KERNEL_DS);
70896 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
70897 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
70898 set_fs(old_fs);
70899 if (result < 0)
70900 goto out_kfree;
70901 @@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
70902 }
70903
70904 set_fs(KERNEL_DS);
70905 - result = vfs_write(file, buffer, str - buffer, &pos);
70906 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
70907 set_fs(old_fs);
70908 if (result < 0)
70909 goto out_kfree;
70910 @@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
70911 int i;
70912
70913 set_fs(KERNEL_DS);
70914 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
70915 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
70916 set_fs(old_fs);
70917 if (result < 0)
70918 goto out;
70919 @@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
70920 __le16 dnaddr;
70921
70922 set_fs(KERNEL_DS);
70923 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
70924 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
70925 set_fs(old_fs);
70926 if (result < 0)
70927 goto out;
70928 @@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
70929 le16_to_cpu(dnaddr) & 0x3ff);
70930
70931 set_fs(KERNEL_DS);
70932 - result = vfs_write(file, buf, len, &pos);
70933 + result = vfs_write(file, (const char __force_user *)buf, len, &pos);
70934 set_fs(old_fs);
70935 if (result < 0)
70936 goto out;
70937 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
70938 index d0a3279..db0ad99 100644
70939 --- a/kernel/taskstats.c
70940 +++ b/kernel/taskstats.c
70941 @@ -27,9 +27,12 @@
70942 #include <linux/cgroup.h>
70943 #include <linux/fs.h>
70944 #include <linux/file.h>
70945 +#include <linux/grsecurity.h>
70946 #include <net/genetlink.h>
70947 #include <linux/atomic.h>
70948
70949 +extern int gr_is_taskstats_denied(int pid);
70950 +
70951 /*
70952 * Maximum length of a cpumask that can be specified in
70953 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
70954 @@ -561,6 +564,9 @@ err:
70955
70956 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
70957 {
70958 + if (gr_is_taskstats_denied(current->pid))
70959 + return -EACCES;
70960 +
70961 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
70962 return cmd_attr_register_cpumask(info);
70963 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
70964 diff --git a/kernel/time.c b/kernel/time.c
70965 index ba744cf..267b7c5 100644
70966 --- a/kernel/time.c
70967 +++ b/kernel/time.c
70968 @@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
70969 return error;
70970
70971 if (tz) {
70972 + /* we log in do_settimeofday called below, so don't log twice
70973 + */
70974 + if (!tv)
70975 + gr_log_timechange();
70976 +
70977 sys_tz = *tz;
70978 update_vsyscall_tz();
70979 if (firsttime) {
70980 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
70981 index aa27d39..34d221c 100644
70982 --- a/kernel/time/alarmtimer.c
70983 +++ b/kernel/time/alarmtimer.c
70984 @@ -779,7 +779,7 @@ static int __init alarmtimer_init(void)
70985 struct platform_device *pdev;
70986 int error = 0;
70987 int i;
70988 - struct k_clock alarm_clock = {
70989 + static struct k_clock alarm_clock = {
70990 .clock_getres = alarm_clock_getres,
70991 .clock_get = alarm_clock_get,
70992 .timer_create = alarm_timer_create,
70993 diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
70994 index f113755..ec24223 100644
70995 --- a/kernel/time/tick-broadcast.c
70996 +++ b/kernel/time/tick-broadcast.c
70997 @@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
70998 * then clear the broadcast bit.
70999 */
71000 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
71001 - int cpu = smp_processor_id();
71002 + cpu = smp_processor_id();
71003
71004 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
71005 tick_broadcast_clear_oneshot(cpu);
71006 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
71007 index f791637..00051de 100644
71008 --- a/kernel/time/timekeeping.c
71009 +++ b/kernel/time/timekeeping.c
71010 @@ -14,6 +14,7 @@
71011 #include <linux/init.h>
71012 #include <linux/mm.h>
71013 #include <linux/sched.h>
71014 +#include <linux/grsecurity.h>
71015 #include <linux/syscore_ops.h>
71016 #include <linux/clocksource.h>
71017 #include <linux/jiffies.h>
71018 @@ -434,6 +435,8 @@ int do_settimeofday(const struct timespec *tv)
71019 if (!timespec_valid_strict(tv))
71020 return -EINVAL;
71021
71022 + gr_log_timechange();
71023 +
71024 write_seqlock_irqsave(&tk->lock, flags);
71025
71026 timekeeping_forward_now(tk);
71027 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
71028 index af5a7e9..715611a 100644
71029 --- a/kernel/time/timer_list.c
71030 +++ b/kernel/time/timer_list.c
71031 @@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
71032
71033 static void print_name_offset(struct seq_file *m, void *sym)
71034 {
71035 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71036 + SEQ_printf(m, "<%p>", NULL);
71037 +#else
71038 char symname[KSYM_NAME_LEN];
71039
71040 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
71041 SEQ_printf(m, "<%pK>", sym);
71042 else
71043 SEQ_printf(m, "%s", symname);
71044 +#endif
71045 }
71046
71047 static void
71048 @@ -112,7 +116,11 @@ next_one:
71049 static void
71050 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
71051 {
71052 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71053 + SEQ_printf(m, " .base: %p\n", NULL);
71054 +#else
71055 SEQ_printf(m, " .base: %pK\n", base);
71056 +#endif
71057 SEQ_printf(m, " .index: %d\n",
71058 base->index);
71059 SEQ_printf(m, " .resolution: %Lu nsecs\n",
71060 @@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
71061 {
71062 struct proc_dir_entry *pe;
71063
71064 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
71065 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
71066 +#else
71067 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
71068 +#endif
71069 if (!pe)
71070 return -ENOMEM;
71071 return 0;
71072 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
71073 index 0b537f2..40d6c20 100644
71074 --- a/kernel/time/timer_stats.c
71075 +++ b/kernel/time/timer_stats.c
71076 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
71077 static unsigned long nr_entries;
71078 static struct entry entries[MAX_ENTRIES];
71079
71080 -static atomic_t overflow_count;
71081 +static atomic_unchecked_t overflow_count;
71082
71083 /*
71084 * The entries are in a hash-table, for fast lookup:
71085 @@ -140,7 +140,7 @@ static void reset_entries(void)
71086 nr_entries = 0;
71087 memset(entries, 0, sizeof(entries));
71088 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
71089 - atomic_set(&overflow_count, 0);
71090 + atomic_set_unchecked(&overflow_count, 0);
71091 }
71092
71093 static struct entry *alloc_entry(void)
71094 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
71095 if (likely(entry))
71096 entry->count++;
71097 else
71098 - atomic_inc(&overflow_count);
71099 + atomic_inc_unchecked(&overflow_count);
71100
71101 out_unlock:
71102 raw_spin_unlock_irqrestore(lock, flags);
71103 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
71104
71105 static void print_name_offset(struct seq_file *m, unsigned long addr)
71106 {
71107 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71108 + seq_printf(m, "<%p>", NULL);
71109 +#else
71110 char symname[KSYM_NAME_LEN];
71111
71112 if (lookup_symbol_name(addr, symname) < 0)
71113 - seq_printf(m, "<%p>", (void *)addr);
71114 + seq_printf(m, "<%pK>", (void *)addr);
71115 else
71116 seq_printf(m, "%s", symname);
71117 +#endif
71118 }
71119
71120 static int tstats_show(struct seq_file *m, void *v)
71121 @@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
71122
71123 seq_puts(m, "Timer Stats Version: v0.2\n");
71124 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
71125 - if (atomic_read(&overflow_count))
71126 + if (atomic_read_unchecked(&overflow_count))
71127 seq_printf(m, "Overflow: %d entries\n",
71128 - atomic_read(&overflow_count));
71129 + atomic_read_unchecked(&overflow_count));
71130
71131 for (i = 0; i < nr_entries; i++) {
71132 entry = entries + i;
71133 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
71134 {
71135 struct proc_dir_entry *pe;
71136
71137 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
71138 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
71139 +#else
71140 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
71141 +#endif
71142 if (!pe)
71143 return -ENOMEM;
71144 return 0;
71145 diff --git a/kernel/timer.c b/kernel/timer.c
71146 index 46ef2b1..ad081f144 100644
71147 --- a/kernel/timer.c
71148 +++ b/kernel/timer.c
71149 @@ -1377,7 +1377,7 @@ void update_process_times(int user_tick)
71150 /*
71151 * This function runs timers and the timer-tq in bottom half context.
71152 */
71153 -static void run_timer_softirq(struct softirq_action *h)
71154 +static void run_timer_softirq(void)
71155 {
71156 struct tvec_base *base = __this_cpu_read(tvec_bases);
71157
71158 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
71159 index c0bd030..62a1927 100644
71160 --- a/kernel/trace/blktrace.c
71161 +++ b/kernel/trace/blktrace.c
71162 @@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
71163 struct blk_trace *bt = filp->private_data;
71164 char buf[16];
71165
71166 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
71167 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
71168
71169 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
71170 }
71171 @@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
71172 return 1;
71173
71174 bt = buf->chan->private_data;
71175 - atomic_inc(&bt->dropped);
71176 + atomic_inc_unchecked(&bt->dropped);
71177 return 0;
71178 }
71179
71180 @@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
71181
71182 bt->dir = dir;
71183 bt->dev = dev;
71184 - atomic_set(&bt->dropped, 0);
71185 + atomic_set_unchecked(&bt->dropped, 0);
71186
71187 ret = -EIO;
71188 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
71189 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
71190 index b4f20fb..483c5fa 100644
71191 --- a/kernel/trace/ftrace.c
71192 +++ b/kernel/trace/ftrace.c
71193 @@ -1785,12 +1785,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
71194 if (unlikely(ftrace_disabled))
71195 return 0;
71196
71197 + ret = ftrace_arch_code_modify_prepare();
71198 + FTRACE_WARN_ON(ret);
71199 + if (ret)
71200 + return 0;
71201 +
71202 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
71203 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
71204 if (ret) {
71205 ftrace_bug(ret, ip);
71206 - return 0;
71207 }
71208 - return 1;
71209 + return ret ? 0 : 1;
71210 }
71211
71212 /*
71213 @@ -2885,7 +2890,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
71214
71215 int
71216 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
71217 - void *data)
71218 + void *data)
71219 {
71220 struct ftrace_func_probe *entry;
71221 struct ftrace_page *pg;
71222 @@ -3697,8 +3702,10 @@ static int ftrace_process_locs(struct module *mod,
71223 if (!count)
71224 return 0;
71225
71226 + pax_open_kernel();
71227 sort(start, count, sizeof(*start),
71228 ftrace_cmp_ips, ftrace_swap_ips);
71229 + pax_close_kernel();
71230
71231 start_pg = ftrace_allocate_pages(count);
71232 if (!start_pg)
71233 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
71234 index 5c38c81..88012af 100644
71235 --- a/kernel/trace/trace.c
71236 +++ b/kernel/trace/trace.c
71237 @@ -4437,10 +4437,9 @@ static const struct file_operations tracing_dyn_info_fops = {
71238 };
71239 #endif
71240
71241 -static struct dentry *d_tracer;
71242 -
71243 struct dentry *tracing_init_dentry(void)
71244 {
71245 + static struct dentry *d_tracer;
71246 static int once;
71247
71248 if (d_tracer)
71249 @@ -4460,10 +4459,9 @@ struct dentry *tracing_init_dentry(void)
71250 return d_tracer;
71251 }
71252
71253 -static struct dentry *d_percpu;
71254 -
71255 struct dentry *tracing_dentry_percpu(void)
71256 {
71257 + static struct dentry *d_percpu;
71258 static int once;
71259 struct dentry *d_tracer;
71260
71261 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
71262 index 29111da..d190fe2 100644
71263 --- a/kernel/trace/trace_events.c
71264 +++ b/kernel/trace/trace_events.c
71265 @@ -1308,10 +1308,6 @@ static LIST_HEAD(ftrace_module_file_list);
71266 struct ftrace_module_file_ops {
71267 struct list_head list;
71268 struct module *mod;
71269 - struct file_operations id;
71270 - struct file_operations enable;
71271 - struct file_operations format;
71272 - struct file_operations filter;
71273 };
71274
71275 static struct ftrace_module_file_ops *
71276 @@ -1332,17 +1328,12 @@ trace_create_file_ops(struct module *mod)
71277
71278 file_ops->mod = mod;
71279
71280 - file_ops->id = ftrace_event_id_fops;
71281 - file_ops->id.owner = mod;
71282 -
71283 - file_ops->enable = ftrace_enable_fops;
71284 - file_ops->enable.owner = mod;
71285 -
71286 - file_ops->filter = ftrace_event_filter_fops;
71287 - file_ops->filter.owner = mod;
71288 -
71289 - file_ops->format = ftrace_event_format_fops;
71290 - file_ops->format.owner = mod;
71291 + pax_open_kernel();
71292 + *(void **)&mod->trace_id.owner = mod;
71293 + *(void **)&mod->trace_enable.owner = mod;
71294 + *(void **)&mod->trace_filter.owner = mod;
71295 + *(void **)&mod->trace_format.owner = mod;
71296 + pax_close_kernel();
71297
71298 list_add(&file_ops->list, &ftrace_module_file_list);
71299
71300 @@ -1366,8 +1357,8 @@ static void trace_module_add_events(struct module *mod)
71301
71302 for_each_event(call, start, end) {
71303 __trace_add_event_call(*call, mod,
71304 - &file_ops->id, &file_ops->enable,
71305 - &file_ops->filter, &file_ops->format);
71306 + &mod->trace_id, &mod->trace_enable,
71307 + &mod->trace_filter, &mod->trace_format);
71308 }
71309 }
71310
71311 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
71312 index fd3c8aa..5f324a6 100644
71313 --- a/kernel/trace/trace_mmiotrace.c
71314 +++ b/kernel/trace/trace_mmiotrace.c
71315 @@ -24,7 +24,7 @@ struct header_iter {
71316 static struct trace_array *mmio_trace_array;
71317 static bool overrun_detected;
71318 static unsigned long prev_overruns;
71319 -static atomic_t dropped_count;
71320 +static atomic_unchecked_t dropped_count;
71321
71322 static void mmio_reset_data(struct trace_array *tr)
71323 {
71324 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
71325
71326 static unsigned long count_overruns(struct trace_iterator *iter)
71327 {
71328 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
71329 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
71330 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
71331
71332 if (over > prev_overruns)
71333 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
71334 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
71335 sizeof(*entry), 0, pc);
71336 if (!event) {
71337 - atomic_inc(&dropped_count);
71338 + atomic_inc_unchecked(&dropped_count);
71339 return;
71340 }
71341 entry = ring_buffer_event_data(event);
71342 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
71343 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
71344 sizeof(*entry), 0, pc);
71345 if (!event) {
71346 - atomic_inc(&dropped_count);
71347 + atomic_inc_unchecked(&dropped_count);
71348 return;
71349 }
71350 entry = ring_buffer_event_data(event);
71351 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
71352 index 123b189..97b81f5 100644
71353 --- a/kernel/trace/trace_output.c
71354 +++ b/kernel/trace/trace_output.c
71355 @@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
71356
71357 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
71358 if (!IS_ERR(p)) {
71359 - p = mangle_path(s->buffer + s->len, p, "\n");
71360 + p = mangle_path(s->buffer + s->len, p, "\n\\");
71361 if (p) {
71362 s->len = p - s->buffer;
71363 return 1;
71364 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
71365 index d4545f4..a9010a1 100644
71366 --- a/kernel/trace/trace_stack.c
71367 +++ b/kernel/trace/trace_stack.c
71368 @@ -53,7 +53,7 @@ static inline void check_stack(void)
71369 return;
71370
71371 /* we do not handle interrupt stacks yet */
71372 - if (!object_is_on_stack(&this_size))
71373 + if (!object_starts_on_stack(&this_size))
71374 return;
71375
71376 local_irq_save(flags);
71377 diff --git a/kernel/workqueue.c b/kernel/workqueue.c
71378 index 872bd6d..31601a2 100644
71379 --- a/kernel/workqueue.c
71380 +++ b/kernel/workqueue.c
71381 @@ -1422,7 +1422,7 @@ retry:
71382 /* morph UNBOUND to REBIND atomically */
71383 worker_flags &= ~WORKER_UNBOUND;
71384 worker_flags |= WORKER_REBIND;
71385 - ACCESS_ONCE(worker->flags) = worker_flags;
71386 + ACCESS_ONCE_RW(worker->flags) = worker_flags;
71387
71388 idle_rebind.cnt++;
71389 worker->idle_rebind = &idle_rebind;
71390 @@ -1448,7 +1448,7 @@ retry:
71391 /* morph UNBOUND to REBIND atomically */
71392 worker_flags &= ~WORKER_UNBOUND;
71393 worker_flags |= WORKER_REBIND;
71394 - ACCESS_ONCE(worker->flags) = worker_flags;
71395 + ACCESS_ONCE_RW(worker->flags) = worker_flags;
71396
71397 if (test_and_set_bit(WORK_STRUCT_PENDING_BIT,
71398 work_data_bits(rebind_work)))
71399 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
71400 index 2403a63..5c4be4c 100644
71401 --- a/lib/Kconfig.debug
71402 +++ b/lib/Kconfig.debug
71403 @@ -1252,6 +1252,7 @@ config LATENCYTOP
71404 depends on DEBUG_KERNEL
71405 depends on STACKTRACE_SUPPORT
71406 depends on PROC_FS
71407 + depends on !GRKERNSEC_HIDESYM
71408 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
71409 select KALLSYMS
71410 select KALLSYMS_ALL
71411 @@ -1267,7 +1268,7 @@ source kernel/trace/Kconfig
71412
71413 config PROVIDE_OHCI1394_DMA_INIT
71414 bool "Remote debugging over FireWire early on boot"
71415 - depends on PCI && X86
71416 + depends on PCI && X86 && !GRKERNSEC
71417 help
71418 If you want to debug problems which hang or crash the kernel early
71419 on boot and the crashing machine has a FireWire port, you can use
71420 @@ -1296,7 +1297,7 @@ config PROVIDE_OHCI1394_DMA_INIT
71421
71422 config FIREWIRE_OHCI_REMOTE_DMA
71423 bool "Remote debugging over FireWire with firewire-ohci"
71424 - depends on FIREWIRE_OHCI
71425 + depends on FIREWIRE_OHCI && !GRKERNSEC
71426 help
71427 This option lets you use the FireWire bus for remote debugging
71428 with help of the firewire-ohci driver. It enables unfiltered
71429 diff --git a/lib/bitmap.c b/lib/bitmap.c
71430 index 06fdfa1..97c5c7d 100644
71431 --- a/lib/bitmap.c
71432 +++ b/lib/bitmap.c
71433 @@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
71434 {
71435 int c, old_c, totaldigits, ndigits, nchunks, nbits;
71436 u32 chunk;
71437 - const char __user __force *ubuf = (const char __user __force *)buf;
71438 + const char __user *ubuf = (const char __force_user *)buf;
71439
71440 bitmap_zero(maskp, nmaskbits);
71441
71442 @@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
71443 {
71444 if (!access_ok(VERIFY_READ, ubuf, ulen))
71445 return -EFAULT;
71446 - return __bitmap_parse((const char __force *)ubuf,
71447 + return __bitmap_parse((const char __force_kernel *)ubuf,
71448 ulen, 1, maskp, nmaskbits);
71449
71450 }
71451 @@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
71452 {
71453 unsigned a, b;
71454 int c, old_c, totaldigits;
71455 - const char __user __force *ubuf = (const char __user __force *)buf;
71456 + const char __user *ubuf = (const char __force_user *)buf;
71457 int exp_digit, in_range;
71458
71459 totaldigits = c = 0;
71460 @@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
71461 {
71462 if (!access_ok(VERIFY_READ, ubuf, ulen))
71463 return -EFAULT;
71464 - return __bitmap_parselist((const char __force *)ubuf,
71465 + return __bitmap_parselist((const char __force_kernel *)ubuf,
71466 ulen, 1, maskp, nmaskbits);
71467 }
71468 EXPORT_SYMBOL(bitmap_parselist_user);
71469 diff --git a/lib/bug.c b/lib/bug.c
71470 index a28c141..2bd3d95 100644
71471 --- a/lib/bug.c
71472 +++ b/lib/bug.c
71473 @@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
71474 return BUG_TRAP_TYPE_NONE;
71475
71476 bug = find_bug(bugaddr);
71477 + if (!bug)
71478 + return BUG_TRAP_TYPE_NONE;
71479
71480 file = NULL;
71481 line = 0;
71482 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
71483 index d11808c..dc2d6f8 100644
71484 --- a/lib/debugobjects.c
71485 +++ b/lib/debugobjects.c
71486 @@ -287,7 +287,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
71487 if (limit > 4)
71488 return;
71489
71490 - is_on_stack = object_is_on_stack(addr);
71491 + is_on_stack = object_starts_on_stack(addr);
71492 if (is_on_stack == onstack)
71493 return;
71494
71495 diff --git a/lib/devres.c b/lib/devres.c
71496 index 80b9c76..9e32279 100644
71497 --- a/lib/devres.c
71498 +++ b/lib/devres.c
71499 @@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
71500 void devm_iounmap(struct device *dev, void __iomem *addr)
71501 {
71502 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
71503 - (void *)addr));
71504 + (void __force *)addr));
71505 iounmap(addr);
71506 }
71507 EXPORT_SYMBOL(devm_iounmap);
71508 @@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
71509 {
71510 ioport_unmap(addr);
71511 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
71512 - devm_ioport_map_match, (void *)addr));
71513 + devm_ioport_map_match, (void __force *)addr));
71514 }
71515 EXPORT_SYMBOL(devm_ioport_unmap);
71516
71517 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
71518 index 66ce414..6f0a0dd 100644
71519 --- a/lib/dma-debug.c
71520 +++ b/lib/dma-debug.c
71521 @@ -924,7 +924,7 @@ out:
71522
71523 static void check_for_stack(struct device *dev, void *addr)
71524 {
71525 - if (object_is_on_stack(addr))
71526 + if (object_starts_on_stack(addr))
71527 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
71528 "stack [addr=%p]\n", addr);
71529 }
71530 diff --git a/lib/inflate.c b/lib/inflate.c
71531 index 013a761..c28f3fc 100644
71532 --- a/lib/inflate.c
71533 +++ b/lib/inflate.c
71534 @@ -269,7 +269,7 @@ static void free(void *where)
71535 malloc_ptr = free_mem_ptr;
71536 }
71537 #else
71538 -#define malloc(a) kmalloc(a, GFP_KERNEL)
71539 +#define malloc(a) kmalloc((a), GFP_KERNEL)
71540 #define free(a) kfree(a)
71541 #endif
71542
71543 diff --git a/lib/ioremap.c b/lib/ioremap.c
71544 index 0c9216c..863bd89 100644
71545 --- a/lib/ioremap.c
71546 +++ b/lib/ioremap.c
71547 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
71548 unsigned long next;
71549
71550 phys_addr -= addr;
71551 - pmd = pmd_alloc(&init_mm, pud, addr);
71552 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
71553 if (!pmd)
71554 return -ENOMEM;
71555 do {
71556 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
71557 unsigned long next;
71558
71559 phys_addr -= addr;
71560 - pud = pud_alloc(&init_mm, pgd, addr);
71561 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
71562 if (!pud)
71563 return -ENOMEM;
71564 do {
71565 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
71566 index bd2bea9..6b3c95e 100644
71567 --- a/lib/is_single_threaded.c
71568 +++ b/lib/is_single_threaded.c
71569 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
71570 struct task_struct *p, *t;
71571 bool ret;
71572
71573 + if (!mm)
71574 + return true;
71575 +
71576 if (atomic_read(&task->signal->live) != 1)
71577 return false;
71578
71579 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
71580 index e796429..6e38f9f 100644
71581 --- a/lib/radix-tree.c
71582 +++ b/lib/radix-tree.c
71583 @@ -92,7 +92,7 @@ struct radix_tree_preload {
71584 int nr;
71585 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
71586 };
71587 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
71588 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
71589
71590 static inline void *ptr_to_indirect(void *ptr)
71591 {
71592 diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
71593 index bb2b201..46abaf9 100644
71594 --- a/lib/strncpy_from_user.c
71595 +++ b/lib/strncpy_from_user.c
71596 @@ -21,7 +21,7 @@
71597 */
71598 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
71599 {
71600 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
71601 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
71602 long res = 0;
71603
71604 /*
71605 diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
71606 index a28df52..3d55877 100644
71607 --- a/lib/strnlen_user.c
71608 +++ b/lib/strnlen_user.c
71609 @@ -26,7 +26,7 @@
71610 */
71611 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
71612 {
71613 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
71614 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
71615 long align, res = 0;
71616 unsigned long c;
71617
71618 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
71619 index 0e33754..50a0e63 100644
71620 --- a/lib/vsprintf.c
71621 +++ b/lib/vsprintf.c
71622 @@ -16,6 +16,9 @@
71623 * - scnprintf and vscnprintf
71624 */
71625
71626 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71627 +#define __INCLUDED_BY_HIDESYM 1
71628 +#endif
71629 #include <stdarg.h>
71630 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
71631 #include <linux/types.h>
71632 @@ -536,7 +539,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
71633 char sym[KSYM_SYMBOL_LEN];
71634 if (ext == 'B')
71635 sprint_backtrace(sym, value);
71636 - else if (ext != 'f' && ext != 's')
71637 + else if (ext != 'f' && ext != 's' && ext != 'a')
71638 sprint_symbol(sym, value);
71639 else
71640 sprint_symbol_no_offset(sym, value);
71641 @@ -969,7 +972,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
71642 return number(buf, end, *(const netdev_features_t *)addr, spec);
71643 }
71644
71645 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71646 +int kptr_restrict __read_mostly = 2;
71647 +#else
71648 int kptr_restrict __read_mostly;
71649 +#endif
71650
71651 /*
71652 * Show a '%p' thing. A kernel extension is that the '%p' is followed
71653 @@ -983,6 +990,8 @@ int kptr_restrict __read_mostly;
71654 * - 'S' For symbolic direct pointers with offset
71655 * - 's' For symbolic direct pointers without offset
71656 * - 'B' For backtraced symbolic direct pointers with offset
71657 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
71658 + * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
71659 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
71660 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
71661 * - 'M' For a 6-byte MAC address, it prints the address in the
71662 @@ -1038,12 +1047,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71663
71664 if (!ptr && *fmt != 'K') {
71665 /*
71666 - * Print (null) with the same width as a pointer so it makes
71667 + * Print (nil) with the same width as a pointer so it makes
71668 * tabular output look nice.
71669 */
71670 if (spec.field_width == -1)
71671 spec.field_width = default_width;
71672 - return string(buf, end, "(null)", spec);
71673 + return string(buf, end, "(nil)", spec);
71674 }
71675
71676 switch (*fmt) {
71677 @@ -1053,6 +1062,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71678 /* Fallthrough */
71679 case 'S':
71680 case 's':
71681 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71682 + break;
71683 +#else
71684 + return symbol_string(buf, end, ptr, spec, *fmt);
71685 +#endif
71686 + case 'A':
71687 + case 'a':
71688 case 'B':
71689 return symbol_string(buf, end, ptr, spec, *fmt);
71690 case 'R':
71691 @@ -1093,6 +1109,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71692 va_end(va);
71693 return buf;
71694 }
71695 + case 'P':
71696 + break;
71697 case 'K':
71698 /*
71699 * %pK cannot be used in IRQ context because its test
71700 @@ -1116,6 +1134,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71701 }
71702 break;
71703 }
71704 +
71705 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71706 + /* 'P' = approved pointers to copy to userland,
71707 + as in the /proc/kallsyms case, as we make it display nothing
71708 + for non-root users, and the real contents for root users
71709 + Also ignore 'K' pointers, since we force their NULLing for non-root users
71710 + above
71711 + */
71712 + if (ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
71713 + printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
71714 + dump_stack();
71715 + ptr = NULL;
71716 + }
71717 +#endif
71718 +
71719 spec.flags |= SMALL;
71720 if (spec.field_width == -1) {
71721 spec.field_width = default_width;
71722 @@ -1831,11 +1864,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
71723 typeof(type) value; \
71724 if (sizeof(type) == 8) { \
71725 args = PTR_ALIGN(args, sizeof(u32)); \
71726 - *(u32 *)&value = *(u32 *)args; \
71727 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
71728 + *(u32 *)&value = *(const u32 *)args; \
71729 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
71730 } else { \
71731 args = PTR_ALIGN(args, sizeof(type)); \
71732 - value = *(typeof(type) *)args; \
71733 + value = *(const typeof(type) *)args; \
71734 } \
71735 args += sizeof(type); \
71736 value; \
71737 @@ -1898,7 +1931,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
71738 case FORMAT_TYPE_STR: {
71739 const char *str_arg = args;
71740 args += strlen(str_arg) + 1;
71741 - str = string(str, end, (char *)str_arg, spec);
71742 + str = string(str, end, str_arg, spec);
71743 break;
71744 }
71745
71746 diff --git a/localversion-grsec b/localversion-grsec
71747 new file mode 100644
71748 index 0000000..7cd6065
71749 --- /dev/null
71750 +++ b/localversion-grsec
71751 @@ -0,0 +1 @@
71752 +-grsec
71753 diff --git a/mm/Kconfig b/mm/Kconfig
71754 index d5c8019..f513038 100644
71755 --- a/mm/Kconfig
71756 +++ b/mm/Kconfig
71757 @@ -251,10 +251,10 @@ config KSM
71758 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
71759
71760 config DEFAULT_MMAP_MIN_ADDR
71761 - int "Low address space to protect from user allocation"
71762 + int "Low address space to protect from user allocation"
71763 depends on MMU
71764 - default 4096
71765 - help
71766 + default 65536
71767 + help
71768 This is the portion of low virtual memory which should be protected
71769 from userspace allocation. Keeping a user from writing to low pages
71770 can help reduce the impact of kernel NULL pointer bugs.
71771 @@ -285,7 +285,7 @@ config MEMORY_FAILURE
71772
71773 config HWPOISON_INJECT
71774 tristate "HWPoison pages injector"
71775 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
71776 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
71777 select PROC_PAGE_MONITOR
71778
71779 config NOMMU_INITIAL_TRIM_EXCESS
71780 diff --git a/mm/filemap.c b/mm/filemap.c
71781 index 3843445..4fe6833 100644
71782 --- a/mm/filemap.c
71783 +++ b/mm/filemap.c
71784 @@ -1746,7 +1746,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
71785 struct address_space *mapping = file->f_mapping;
71786
71787 if (!mapping->a_ops->readpage)
71788 - return -ENOEXEC;
71789 + return -ENODEV;
71790 file_accessed(file);
71791 vma->vm_ops = &generic_file_vm_ops;
71792 vma->vm_flags |= VM_CAN_NONLINEAR;
71793 @@ -2087,6 +2087,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
71794 *pos = i_size_read(inode);
71795
71796 if (limit != RLIM_INFINITY) {
71797 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
71798 if (*pos >= limit) {
71799 send_sig(SIGXFSZ, current, 0);
71800 return -EFBIG;
71801 diff --git a/mm/fremap.c b/mm/fremap.c
71802 index 9ed4fd4..c42648d 100644
71803 --- a/mm/fremap.c
71804 +++ b/mm/fremap.c
71805 @@ -155,6 +155,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
71806 retry:
71807 vma = find_vma(mm, start);
71808
71809 +#ifdef CONFIG_PAX_SEGMEXEC
71810 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
71811 + goto out;
71812 +#endif
71813 +
71814 /*
71815 * Make sure the vma is shared, that it supports prefaulting,
71816 * and that the remapped range is valid and fully within
71817 diff --git a/mm/highmem.c b/mm/highmem.c
71818 index d517cd1..006a1c5 100644
71819 --- a/mm/highmem.c
71820 +++ b/mm/highmem.c
71821 @@ -137,9 +137,10 @@ static void flush_all_zero_pkmaps(void)
71822 * So no dangers, even with speculative execution.
71823 */
71824 page = pte_page(pkmap_page_table[i]);
71825 + pax_open_kernel();
71826 pte_clear(&init_mm, (unsigned long)page_address(page),
71827 &pkmap_page_table[i]);
71828 -
71829 + pax_close_kernel();
71830 set_page_address(page, NULL);
71831 need_flush = 1;
71832 }
71833 @@ -198,9 +199,11 @@ start:
71834 }
71835 }
71836 vaddr = PKMAP_ADDR(last_pkmap_nr);
71837 +
71838 + pax_open_kernel();
71839 set_pte_at(&init_mm, vaddr,
71840 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
71841 -
71842 + pax_close_kernel();
71843 pkmap_count[last_pkmap_nr] = 1;
71844 set_page_address(page, (void *)vaddr);
71845
71846 diff --git a/mm/huge_memory.c b/mm/huge_memory.c
71847 index 141dbb6..ebff057 100644
71848 --- a/mm/huge_memory.c
71849 +++ b/mm/huge_memory.c
71850 @@ -735,7 +735,7 @@ out:
71851 * run pte_offset_map on the pmd, if an huge pmd could
71852 * materialize from under us from a different thread.
71853 */
71854 - if (unlikely(__pte_alloc(mm, vma, pmd, address)))
71855 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
71856 return VM_FAULT_OOM;
71857 /* if an huge pmd materialized from under us just retry later */
71858 if (unlikely(pmd_trans_huge(*pmd)))
71859 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
71860 index 3adceaf..dccfea3 100644
71861 --- a/mm/hugetlb.c
71862 +++ b/mm/hugetlb.c
71863 @@ -2512,6 +2512,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
71864 return 1;
71865 }
71866
71867 +#ifdef CONFIG_PAX_SEGMEXEC
71868 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
71869 +{
71870 + struct mm_struct *mm = vma->vm_mm;
71871 + struct vm_area_struct *vma_m;
71872 + unsigned long address_m;
71873 + pte_t *ptep_m;
71874 +
71875 + vma_m = pax_find_mirror_vma(vma);
71876 + if (!vma_m)
71877 + return;
71878 +
71879 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71880 + address_m = address + SEGMEXEC_TASK_SIZE;
71881 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
71882 + get_page(page_m);
71883 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
71884 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
71885 +}
71886 +#endif
71887 +
71888 /*
71889 * Hugetlb_cow() should be called with page lock of the original hugepage held.
71890 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
71891 @@ -2628,6 +2649,11 @@ retry_avoidcopy:
71892 make_huge_pte(vma, new_page, 1));
71893 page_remove_rmap(old_page);
71894 hugepage_add_new_anon_rmap(new_page, vma, address);
71895 +
71896 +#ifdef CONFIG_PAX_SEGMEXEC
71897 + pax_mirror_huge_pte(vma, address, new_page);
71898 +#endif
71899 +
71900 /* Make the old page be freed below */
71901 new_page = old_page;
71902 mmu_notifier_invalidate_range_end(mm,
71903 @@ -2786,6 +2812,10 @@ retry:
71904 && (vma->vm_flags & VM_SHARED)));
71905 set_huge_pte_at(mm, address, ptep, new_pte);
71906
71907 +#ifdef CONFIG_PAX_SEGMEXEC
71908 + pax_mirror_huge_pte(vma, address, page);
71909 +#endif
71910 +
71911 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
71912 /* Optimization, do the COW without a second fault */
71913 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
71914 @@ -2815,6 +2845,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71915 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
71916 struct hstate *h = hstate_vma(vma);
71917
71918 +#ifdef CONFIG_PAX_SEGMEXEC
71919 + struct vm_area_struct *vma_m;
71920 +#endif
71921 +
71922 address &= huge_page_mask(h);
71923
71924 ptep = huge_pte_offset(mm, address);
71925 @@ -2828,6 +2862,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71926 VM_FAULT_SET_HINDEX(hstate_index(h));
71927 }
71928
71929 +#ifdef CONFIG_PAX_SEGMEXEC
71930 + vma_m = pax_find_mirror_vma(vma);
71931 + if (vma_m) {
71932 + unsigned long address_m;
71933 +
71934 + if (vma->vm_start > vma_m->vm_start) {
71935 + address_m = address;
71936 + address -= SEGMEXEC_TASK_SIZE;
71937 + vma = vma_m;
71938 + h = hstate_vma(vma);
71939 + } else
71940 + address_m = address + SEGMEXEC_TASK_SIZE;
71941 +
71942 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
71943 + return VM_FAULT_OOM;
71944 + address_m &= HPAGE_MASK;
71945 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
71946 + }
71947 +#endif
71948 +
71949 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
71950 if (!ptep)
71951 return VM_FAULT_OOM;
71952 diff --git a/mm/internal.h b/mm/internal.h
71953 index b8c91b3..93e95a3 100644
71954 --- a/mm/internal.h
71955 +++ b/mm/internal.h
71956 @@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
71957 * in mm/page_alloc.c
71958 */
71959 extern void __free_pages_bootmem(struct page *page, unsigned int order);
71960 +extern void free_compound_page(struct page *page);
71961 extern void prep_compound_page(struct page *page, unsigned long order);
71962 #ifdef CONFIG_MEMORY_FAILURE
71963 extern bool is_free_buddy_page(struct page *page);
71964 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
71965 index 45eb621..6ccd8ea 100644
71966 --- a/mm/kmemleak.c
71967 +++ b/mm/kmemleak.c
71968 @@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
71969
71970 for (i = 0; i < object->trace_len; i++) {
71971 void *ptr = (void *)object->trace[i];
71972 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
71973 + seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
71974 }
71975 }
71976
71977 diff --git a/mm/maccess.c b/mm/maccess.c
71978 index d53adf9..03a24bf 100644
71979 --- a/mm/maccess.c
71980 +++ b/mm/maccess.c
71981 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
71982 set_fs(KERNEL_DS);
71983 pagefault_disable();
71984 ret = __copy_from_user_inatomic(dst,
71985 - (__force const void __user *)src, size);
71986 + (const void __force_user *)src, size);
71987 pagefault_enable();
71988 set_fs(old_fs);
71989
71990 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
71991
71992 set_fs(KERNEL_DS);
71993 pagefault_disable();
71994 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
71995 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
71996 pagefault_enable();
71997 set_fs(old_fs);
71998
71999 diff --git a/mm/madvise.c b/mm/madvise.c
72000 index 14d260f..b2a80fd 100644
72001 --- a/mm/madvise.c
72002 +++ b/mm/madvise.c
72003 @@ -48,6 +48,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
72004 pgoff_t pgoff;
72005 unsigned long new_flags = vma->vm_flags;
72006
72007 +#ifdef CONFIG_PAX_SEGMEXEC
72008 + struct vm_area_struct *vma_m;
72009 +#endif
72010 +
72011 switch (behavior) {
72012 case MADV_NORMAL:
72013 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
72014 @@ -119,6 +123,13 @@ success:
72015 /*
72016 * vm_flags is protected by the mmap_sem held in write mode.
72017 */
72018 +
72019 +#ifdef CONFIG_PAX_SEGMEXEC
72020 + vma_m = pax_find_mirror_vma(vma);
72021 + if (vma_m)
72022 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
72023 +#endif
72024 +
72025 vma->vm_flags = new_flags;
72026
72027 out:
72028 @@ -177,6 +188,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
72029 struct vm_area_struct ** prev,
72030 unsigned long start, unsigned long end)
72031 {
72032 +
72033 +#ifdef CONFIG_PAX_SEGMEXEC
72034 + struct vm_area_struct *vma_m;
72035 +#endif
72036 +
72037 *prev = vma;
72038 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
72039 return -EINVAL;
72040 @@ -189,6 +205,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
72041 zap_page_range(vma, start, end - start, &details);
72042 } else
72043 zap_page_range(vma, start, end - start, NULL);
72044 +
72045 +#ifdef CONFIG_PAX_SEGMEXEC
72046 + vma_m = pax_find_mirror_vma(vma);
72047 + if (vma_m) {
72048 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
72049 + struct zap_details details = {
72050 + .nonlinear_vma = vma_m,
72051 + .last_index = ULONG_MAX,
72052 + };
72053 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
72054 + } else
72055 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
72056 + }
72057 +#endif
72058 +
72059 return 0;
72060 }
72061
72062 @@ -393,6 +424,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
72063 if (end < start)
72064 goto out;
72065
72066 +#ifdef CONFIG_PAX_SEGMEXEC
72067 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
72068 + if (end > SEGMEXEC_TASK_SIZE)
72069 + goto out;
72070 + } else
72071 +#endif
72072 +
72073 + if (end > TASK_SIZE)
72074 + goto out;
72075 +
72076 error = 0;
72077 if (end == start)
72078 goto out;
72079 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
72080 index a6e2141..eaf5aad 100644
72081 --- a/mm/memory-failure.c
72082 +++ b/mm/memory-failure.c
72083 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
72084
72085 int sysctl_memory_failure_recovery __read_mostly = 1;
72086
72087 -atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
72088 +atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
72089
72090 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
72091
72092 @@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
72093 pfn, t->comm, t->pid);
72094 si.si_signo = SIGBUS;
72095 si.si_errno = 0;
72096 - si.si_addr = (void *)addr;
72097 + si.si_addr = (void __user *)addr;
72098 #ifdef __ARCH_SI_TRAPNO
72099 si.si_trapno = trapno;
72100 #endif
72101 @@ -1038,7 +1038,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
72102 }
72103
72104 nr_pages = 1 << compound_trans_order(hpage);
72105 - atomic_long_add(nr_pages, &mce_bad_pages);
72106 + atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
72107
72108 /*
72109 * We need/can do nothing about count=0 pages.
72110 @@ -1068,7 +1068,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
72111 if (!PageHWPoison(hpage)
72112 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
72113 || (p != hpage && TestSetPageHWPoison(hpage))) {
72114 - atomic_long_sub(nr_pages, &mce_bad_pages);
72115 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
72116 return 0;
72117 }
72118 set_page_hwpoison_huge_page(hpage);
72119 @@ -1126,7 +1126,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
72120 }
72121 if (hwpoison_filter(p)) {
72122 if (TestClearPageHWPoison(p))
72123 - atomic_long_sub(nr_pages, &mce_bad_pages);
72124 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
72125 unlock_page(hpage);
72126 put_page(hpage);
72127 return 0;
72128 @@ -1321,7 +1321,7 @@ int unpoison_memory(unsigned long pfn)
72129 return 0;
72130 }
72131 if (TestClearPageHWPoison(p))
72132 - atomic_long_sub(nr_pages, &mce_bad_pages);
72133 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
72134 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
72135 return 0;
72136 }
72137 @@ -1335,7 +1335,7 @@ int unpoison_memory(unsigned long pfn)
72138 */
72139 if (TestClearPageHWPoison(page)) {
72140 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
72141 - atomic_long_sub(nr_pages, &mce_bad_pages);
72142 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
72143 freeit = 1;
72144 if (PageHuge(page))
72145 clear_page_hwpoison_huge_page(page);
72146 @@ -1440,7 +1440,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
72147 }
72148 done:
72149 if (!PageHWPoison(hpage))
72150 - atomic_long_add(1 << compound_trans_order(hpage),
72151 + atomic_long_add_unchecked(1 << compound_trans_order(hpage),
72152 &mce_bad_pages);
72153 set_page_hwpoison_huge_page(hpage);
72154 dequeue_hwpoisoned_huge_page(hpage);
72155 @@ -1572,7 +1572,7 @@ int soft_offline_page(struct page *page, int flags)
72156 return ret;
72157
72158 done:
72159 - atomic_long_add(1, &mce_bad_pages);
72160 + atomic_long_add_unchecked(1, &mce_bad_pages);
72161 SetPageHWPoison(page);
72162 /* keep elevated page count for bad page */
72163 return ret;
72164 diff --git a/mm/memory.c b/mm/memory.c
72165 index 5736170..8e04800 100644
72166 --- a/mm/memory.c
72167 +++ b/mm/memory.c
72168 @@ -426,6 +426,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
72169 free_pte_range(tlb, pmd, addr);
72170 } while (pmd++, addr = next, addr != end);
72171
72172 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
72173 start &= PUD_MASK;
72174 if (start < floor)
72175 return;
72176 @@ -440,6 +441,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
72177 pmd = pmd_offset(pud, start);
72178 pud_clear(pud);
72179 pmd_free_tlb(tlb, pmd, start);
72180 +#endif
72181 +
72182 }
72183
72184 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
72185 @@ -459,6 +462,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
72186 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
72187 } while (pud++, addr = next, addr != end);
72188
72189 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
72190 start &= PGDIR_MASK;
72191 if (start < floor)
72192 return;
72193 @@ -473,6 +477,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
72194 pud = pud_offset(pgd, start);
72195 pgd_clear(pgd);
72196 pud_free_tlb(tlb, pud, start);
72197 +#endif
72198 +
72199 }
72200
72201 /*
72202 @@ -1614,12 +1620,6 @@ no_page_table:
72203 return page;
72204 }
72205
72206 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
72207 -{
72208 - return stack_guard_page_start(vma, addr) ||
72209 - stack_guard_page_end(vma, addr+PAGE_SIZE);
72210 -}
72211 -
72212 /**
72213 * __get_user_pages() - pin user pages in memory
72214 * @tsk: task_struct of target task
72215 @@ -1692,10 +1692,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
72216 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
72217 i = 0;
72218
72219 - do {
72220 + while (nr_pages) {
72221 struct vm_area_struct *vma;
72222
72223 - vma = find_extend_vma(mm, start);
72224 + vma = find_vma(mm, start);
72225 if (!vma && in_gate_area(mm, start)) {
72226 unsigned long pg = start & PAGE_MASK;
72227 pgd_t *pgd;
72228 @@ -1743,7 +1743,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
72229 goto next_page;
72230 }
72231
72232 - if (!vma ||
72233 + if (!vma || start < vma->vm_start ||
72234 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
72235 !(vm_flags & vma->vm_flags))
72236 return i ? : -EFAULT;
72237 @@ -1770,11 +1770,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
72238 int ret;
72239 unsigned int fault_flags = 0;
72240
72241 - /* For mlock, just skip the stack guard page. */
72242 - if (foll_flags & FOLL_MLOCK) {
72243 - if (stack_guard_page(vma, start))
72244 - goto next_page;
72245 - }
72246 if (foll_flags & FOLL_WRITE)
72247 fault_flags |= FAULT_FLAG_WRITE;
72248 if (nonblocking)
72249 @@ -1848,7 +1843,7 @@ next_page:
72250 start += PAGE_SIZE;
72251 nr_pages--;
72252 } while (nr_pages && start < vma->vm_end);
72253 - } while (nr_pages);
72254 + }
72255 return i;
72256 }
72257 EXPORT_SYMBOL(__get_user_pages);
72258 @@ -2055,6 +2050,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
72259 page_add_file_rmap(page);
72260 set_pte_at(mm, addr, pte, mk_pte(page, prot));
72261
72262 +#ifdef CONFIG_PAX_SEGMEXEC
72263 + pax_mirror_file_pte(vma, addr, page, ptl);
72264 +#endif
72265 +
72266 retval = 0;
72267 pte_unmap_unlock(pte, ptl);
72268 return retval;
72269 @@ -2089,10 +2088,22 @@ out:
72270 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
72271 struct page *page)
72272 {
72273 +
72274 +#ifdef CONFIG_PAX_SEGMEXEC
72275 + struct vm_area_struct *vma_m;
72276 +#endif
72277 +
72278 if (addr < vma->vm_start || addr >= vma->vm_end)
72279 return -EFAULT;
72280 if (!page_count(page))
72281 return -EINVAL;
72282 +
72283 +#ifdef CONFIG_PAX_SEGMEXEC
72284 + vma_m = pax_find_mirror_vma(vma);
72285 + if (vma_m)
72286 + vma_m->vm_flags |= VM_INSERTPAGE;
72287 +#endif
72288 +
72289 vma->vm_flags |= VM_INSERTPAGE;
72290 return insert_page(vma, addr, page, vma->vm_page_prot);
72291 }
72292 @@ -2178,6 +2189,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
72293 unsigned long pfn)
72294 {
72295 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
72296 + BUG_ON(vma->vm_mirror);
72297
72298 if (addr < vma->vm_start || addr >= vma->vm_end)
72299 return -EFAULT;
72300 @@ -2385,7 +2397,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
72301
72302 BUG_ON(pud_huge(*pud));
72303
72304 - pmd = pmd_alloc(mm, pud, addr);
72305 + pmd = (mm == &init_mm) ?
72306 + pmd_alloc_kernel(mm, pud, addr) :
72307 + pmd_alloc(mm, pud, addr);
72308 if (!pmd)
72309 return -ENOMEM;
72310 do {
72311 @@ -2405,7 +2419,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
72312 unsigned long next;
72313 int err;
72314
72315 - pud = pud_alloc(mm, pgd, addr);
72316 + pud = (mm == &init_mm) ?
72317 + pud_alloc_kernel(mm, pgd, addr) :
72318 + pud_alloc(mm, pgd, addr);
72319 if (!pud)
72320 return -ENOMEM;
72321 do {
72322 @@ -2493,6 +2509,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
72323 copy_user_highpage(dst, src, va, vma);
72324 }
72325
72326 +#ifdef CONFIG_PAX_SEGMEXEC
72327 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
72328 +{
72329 + struct mm_struct *mm = vma->vm_mm;
72330 + spinlock_t *ptl;
72331 + pte_t *pte, entry;
72332 +
72333 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
72334 + entry = *pte;
72335 + if (!pte_present(entry)) {
72336 + if (!pte_none(entry)) {
72337 + BUG_ON(pte_file(entry));
72338 + free_swap_and_cache(pte_to_swp_entry(entry));
72339 + pte_clear_not_present_full(mm, address, pte, 0);
72340 + }
72341 + } else {
72342 + struct page *page;
72343 +
72344 + flush_cache_page(vma, address, pte_pfn(entry));
72345 + entry = ptep_clear_flush(vma, address, pte);
72346 + BUG_ON(pte_dirty(entry));
72347 + page = vm_normal_page(vma, address, entry);
72348 + if (page) {
72349 + update_hiwater_rss(mm);
72350 + if (PageAnon(page))
72351 + dec_mm_counter_fast(mm, MM_ANONPAGES);
72352 + else
72353 + dec_mm_counter_fast(mm, MM_FILEPAGES);
72354 + page_remove_rmap(page);
72355 + page_cache_release(page);
72356 + }
72357 + }
72358 + pte_unmap_unlock(pte, ptl);
72359 +}
72360 +
72361 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
72362 + *
72363 + * the ptl of the lower mapped page is held on entry and is not released on exit
72364 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
72365 + */
72366 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
72367 +{
72368 + struct mm_struct *mm = vma->vm_mm;
72369 + unsigned long address_m;
72370 + spinlock_t *ptl_m;
72371 + struct vm_area_struct *vma_m;
72372 + pmd_t *pmd_m;
72373 + pte_t *pte_m, entry_m;
72374 +
72375 + BUG_ON(!page_m || !PageAnon(page_m));
72376 +
72377 + vma_m = pax_find_mirror_vma(vma);
72378 + if (!vma_m)
72379 + return;
72380 +
72381 + BUG_ON(!PageLocked(page_m));
72382 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72383 + address_m = address + SEGMEXEC_TASK_SIZE;
72384 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
72385 + pte_m = pte_offset_map(pmd_m, address_m);
72386 + ptl_m = pte_lockptr(mm, pmd_m);
72387 + if (ptl != ptl_m) {
72388 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
72389 + if (!pte_none(*pte_m))
72390 + goto out;
72391 + }
72392 +
72393 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
72394 + page_cache_get(page_m);
72395 + page_add_anon_rmap(page_m, vma_m, address_m);
72396 + inc_mm_counter_fast(mm, MM_ANONPAGES);
72397 + set_pte_at(mm, address_m, pte_m, entry_m);
72398 + update_mmu_cache(vma_m, address_m, entry_m);
72399 +out:
72400 + if (ptl != ptl_m)
72401 + spin_unlock(ptl_m);
72402 + pte_unmap(pte_m);
72403 + unlock_page(page_m);
72404 +}
72405 +
72406 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
72407 +{
72408 + struct mm_struct *mm = vma->vm_mm;
72409 + unsigned long address_m;
72410 + spinlock_t *ptl_m;
72411 + struct vm_area_struct *vma_m;
72412 + pmd_t *pmd_m;
72413 + pte_t *pte_m, entry_m;
72414 +
72415 + BUG_ON(!page_m || PageAnon(page_m));
72416 +
72417 + vma_m = pax_find_mirror_vma(vma);
72418 + if (!vma_m)
72419 + return;
72420 +
72421 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72422 + address_m = address + SEGMEXEC_TASK_SIZE;
72423 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
72424 + pte_m = pte_offset_map(pmd_m, address_m);
72425 + ptl_m = pte_lockptr(mm, pmd_m);
72426 + if (ptl != ptl_m) {
72427 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
72428 + if (!pte_none(*pte_m))
72429 + goto out;
72430 + }
72431 +
72432 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
72433 + page_cache_get(page_m);
72434 + page_add_file_rmap(page_m);
72435 + inc_mm_counter_fast(mm, MM_FILEPAGES);
72436 + set_pte_at(mm, address_m, pte_m, entry_m);
72437 + update_mmu_cache(vma_m, address_m, entry_m);
72438 +out:
72439 + if (ptl != ptl_m)
72440 + spin_unlock(ptl_m);
72441 + pte_unmap(pte_m);
72442 +}
72443 +
72444 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
72445 +{
72446 + struct mm_struct *mm = vma->vm_mm;
72447 + unsigned long address_m;
72448 + spinlock_t *ptl_m;
72449 + struct vm_area_struct *vma_m;
72450 + pmd_t *pmd_m;
72451 + pte_t *pte_m, entry_m;
72452 +
72453 + vma_m = pax_find_mirror_vma(vma);
72454 + if (!vma_m)
72455 + return;
72456 +
72457 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72458 + address_m = address + SEGMEXEC_TASK_SIZE;
72459 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
72460 + pte_m = pte_offset_map(pmd_m, address_m);
72461 + ptl_m = pte_lockptr(mm, pmd_m);
72462 + if (ptl != ptl_m) {
72463 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
72464 + if (!pte_none(*pte_m))
72465 + goto out;
72466 + }
72467 +
72468 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
72469 + set_pte_at(mm, address_m, pte_m, entry_m);
72470 +out:
72471 + if (ptl != ptl_m)
72472 + spin_unlock(ptl_m);
72473 + pte_unmap(pte_m);
72474 +}
72475 +
72476 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
72477 +{
72478 + struct page *page_m;
72479 + pte_t entry;
72480 +
72481 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
72482 + goto out;
72483 +
72484 + entry = *pte;
72485 + page_m = vm_normal_page(vma, address, entry);
72486 + if (!page_m)
72487 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
72488 + else if (PageAnon(page_m)) {
72489 + if (pax_find_mirror_vma(vma)) {
72490 + pte_unmap_unlock(pte, ptl);
72491 + lock_page(page_m);
72492 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
72493 + if (pte_same(entry, *pte))
72494 + pax_mirror_anon_pte(vma, address, page_m, ptl);
72495 + else
72496 + unlock_page(page_m);
72497 + }
72498 + } else
72499 + pax_mirror_file_pte(vma, address, page_m, ptl);
72500 +
72501 +out:
72502 + pte_unmap_unlock(pte, ptl);
72503 +}
72504 +#endif
72505 +
72506 /*
72507 * This routine handles present pages, when users try to write
72508 * to a shared page. It is done by copying the page to a new address
72509 @@ -2703,6 +2899,12 @@ gotten:
72510 */
72511 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
72512 if (likely(pte_same(*page_table, orig_pte))) {
72513 +
72514 +#ifdef CONFIG_PAX_SEGMEXEC
72515 + if (pax_find_mirror_vma(vma))
72516 + BUG_ON(!trylock_page(new_page));
72517 +#endif
72518 +
72519 if (old_page) {
72520 if (!PageAnon(old_page)) {
72521 dec_mm_counter_fast(mm, MM_FILEPAGES);
72522 @@ -2754,6 +2956,10 @@ gotten:
72523 page_remove_rmap(old_page);
72524 }
72525
72526 +#ifdef CONFIG_PAX_SEGMEXEC
72527 + pax_mirror_anon_pte(vma, address, new_page, ptl);
72528 +#endif
72529 +
72530 /* Free the old page.. */
72531 new_page = old_page;
72532 ret |= VM_FAULT_WRITE;
72533 @@ -3033,6 +3239,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
72534 swap_free(entry);
72535 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
72536 try_to_free_swap(page);
72537 +
72538 +#ifdef CONFIG_PAX_SEGMEXEC
72539 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
72540 +#endif
72541 +
72542 unlock_page(page);
72543 if (swapcache) {
72544 /*
72545 @@ -3056,6 +3267,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
72546
72547 /* No need to invalidate - it was non-present before */
72548 update_mmu_cache(vma, address, page_table);
72549 +
72550 +#ifdef CONFIG_PAX_SEGMEXEC
72551 + pax_mirror_anon_pte(vma, address, page, ptl);
72552 +#endif
72553 +
72554 unlock:
72555 pte_unmap_unlock(page_table, ptl);
72556 out:
72557 @@ -3075,40 +3291,6 @@ out_release:
72558 }
72559
72560 /*
72561 - * This is like a special single-page "expand_{down|up}wards()",
72562 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
72563 - * doesn't hit another vma.
72564 - */
72565 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
72566 -{
72567 - address &= PAGE_MASK;
72568 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
72569 - struct vm_area_struct *prev = vma->vm_prev;
72570 -
72571 - /*
72572 - * Is there a mapping abutting this one below?
72573 - *
72574 - * That's only ok if it's the same stack mapping
72575 - * that has gotten split..
72576 - */
72577 - if (prev && prev->vm_end == address)
72578 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
72579 -
72580 - expand_downwards(vma, address - PAGE_SIZE);
72581 - }
72582 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
72583 - struct vm_area_struct *next = vma->vm_next;
72584 -
72585 - /* As VM_GROWSDOWN but s/below/above/ */
72586 - if (next && next->vm_start == address + PAGE_SIZE)
72587 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
72588 -
72589 - expand_upwards(vma, address + PAGE_SIZE);
72590 - }
72591 - return 0;
72592 -}
72593 -
72594 -/*
72595 * We enter with non-exclusive mmap_sem (to exclude vma changes,
72596 * but allow concurrent faults), and pte mapped but not yet locked.
72597 * We return with mmap_sem still held, but pte unmapped and unlocked.
72598 @@ -3117,27 +3299,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
72599 unsigned long address, pte_t *page_table, pmd_t *pmd,
72600 unsigned int flags)
72601 {
72602 - struct page *page;
72603 + struct page *page = NULL;
72604 spinlock_t *ptl;
72605 pte_t entry;
72606
72607 - pte_unmap(page_table);
72608 -
72609 - /* Check if we need to add a guard page to the stack */
72610 - if (check_stack_guard_page(vma, address) < 0)
72611 - return VM_FAULT_SIGBUS;
72612 -
72613 - /* Use the zero-page for reads */
72614 if (!(flags & FAULT_FLAG_WRITE)) {
72615 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
72616 vma->vm_page_prot));
72617 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
72618 + ptl = pte_lockptr(mm, pmd);
72619 + spin_lock(ptl);
72620 if (!pte_none(*page_table))
72621 goto unlock;
72622 goto setpte;
72623 }
72624
72625 /* Allocate our own private page. */
72626 + pte_unmap(page_table);
72627 +
72628 if (unlikely(anon_vma_prepare(vma)))
72629 goto oom;
72630 page = alloc_zeroed_user_highpage_movable(vma, address);
72631 @@ -3156,6 +3334,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
72632 if (!pte_none(*page_table))
72633 goto release;
72634
72635 +#ifdef CONFIG_PAX_SEGMEXEC
72636 + if (pax_find_mirror_vma(vma))
72637 + BUG_ON(!trylock_page(page));
72638 +#endif
72639 +
72640 inc_mm_counter_fast(mm, MM_ANONPAGES);
72641 page_add_new_anon_rmap(page, vma, address);
72642 setpte:
72643 @@ -3163,6 +3346,12 @@ setpte:
72644
72645 /* No need to invalidate - it was non-present before */
72646 update_mmu_cache(vma, address, page_table);
72647 +
72648 +#ifdef CONFIG_PAX_SEGMEXEC
72649 + if (page)
72650 + pax_mirror_anon_pte(vma, address, page, ptl);
72651 +#endif
72652 +
72653 unlock:
72654 pte_unmap_unlock(page_table, ptl);
72655 return 0;
72656 @@ -3306,6 +3495,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72657 */
72658 /* Only go through if we didn't race with anybody else... */
72659 if (likely(pte_same(*page_table, orig_pte))) {
72660 +
72661 +#ifdef CONFIG_PAX_SEGMEXEC
72662 + if (anon && pax_find_mirror_vma(vma))
72663 + BUG_ON(!trylock_page(page));
72664 +#endif
72665 +
72666 flush_icache_page(vma, page);
72667 entry = mk_pte(page, vma->vm_page_prot);
72668 if (flags & FAULT_FLAG_WRITE)
72669 @@ -3325,6 +3520,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72670
72671 /* no need to invalidate: a not-present page won't be cached */
72672 update_mmu_cache(vma, address, page_table);
72673 +
72674 +#ifdef CONFIG_PAX_SEGMEXEC
72675 + if (anon)
72676 + pax_mirror_anon_pte(vma, address, page, ptl);
72677 + else
72678 + pax_mirror_file_pte(vma, address, page, ptl);
72679 +#endif
72680 +
72681 } else {
72682 if (cow_page)
72683 mem_cgroup_uncharge_page(cow_page);
72684 @@ -3479,6 +3682,12 @@ int handle_pte_fault(struct mm_struct *mm,
72685 if (flags & FAULT_FLAG_WRITE)
72686 flush_tlb_fix_spurious_fault(vma, address);
72687 }
72688 +
72689 +#ifdef CONFIG_PAX_SEGMEXEC
72690 + pax_mirror_pte(vma, address, pte, pmd, ptl);
72691 + return 0;
72692 +#endif
72693 +
72694 unlock:
72695 pte_unmap_unlock(pte, ptl);
72696 return 0;
72697 @@ -3495,6 +3704,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72698 pmd_t *pmd;
72699 pte_t *pte;
72700
72701 +#ifdef CONFIG_PAX_SEGMEXEC
72702 + struct vm_area_struct *vma_m;
72703 +#endif
72704 +
72705 __set_current_state(TASK_RUNNING);
72706
72707 count_vm_event(PGFAULT);
72708 @@ -3506,6 +3719,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72709 if (unlikely(is_vm_hugetlb_page(vma)))
72710 return hugetlb_fault(mm, vma, address, flags);
72711
72712 +#ifdef CONFIG_PAX_SEGMEXEC
72713 + vma_m = pax_find_mirror_vma(vma);
72714 + if (vma_m) {
72715 + unsigned long address_m;
72716 + pgd_t *pgd_m;
72717 + pud_t *pud_m;
72718 + pmd_t *pmd_m;
72719 +
72720 + if (vma->vm_start > vma_m->vm_start) {
72721 + address_m = address;
72722 + address -= SEGMEXEC_TASK_SIZE;
72723 + vma = vma_m;
72724 + } else
72725 + address_m = address + SEGMEXEC_TASK_SIZE;
72726 +
72727 + pgd_m = pgd_offset(mm, address_m);
72728 + pud_m = pud_alloc(mm, pgd_m, address_m);
72729 + if (!pud_m)
72730 + return VM_FAULT_OOM;
72731 + pmd_m = pmd_alloc(mm, pud_m, address_m);
72732 + if (!pmd_m)
72733 + return VM_FAULT_OOM;
72734 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
72735 + return VM_FAULT_OOM;
72736 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
72737 + }
72738 +#endif
72739 +
72740 retry:
72741 pgd = pgd_offset(mm, address);
72742 pud = pud_alloc(mm, pgd, address);
72743 @@ -3547,7 +3788,7 @@ retry:
72744 * run pte_offset_map on the pmd, if an huge pmd could
72745 * materialize from under us from a different thread.
72746 */
72747 - if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
72748 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
72749 return VM_FAULT_OOM;
72750 /* if an huge pmd materialized from under us just retry later */
72751 if (unlikely(pmd_trans_huge(*pmd)))
72752 @@ -3584,6 +3825,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
72753 spin_unlock(&mm->page_table_lock);
72754 return 0;
72755 }
72756 +
72757 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
72758 +{
72759 + pud_t *new = pud_alloc_one(mm, address);
72760 + if (!new)
72761 + return -ENOMEM;
72762 +
72763 + smp_wmb(); /* See comment in __pte_alloc */
72764 +
72765 + spin_lock(&mm->page_table_lock);
72766 + if (pgd_present(*pgd)) /* Another has populated it */
72767 + pud_free(mm, new);
72768 + else
72769 + pgd_populate_kernel(mm, pgd, new);
72770 + spin_unlock(&mm->page_table_lock);
72771 + return 0;
72772 +}
72773 #endif /* __PAGETABLE_PUD_FOLDED */
72774
72775 #ifndef __PAGETABLE_PMD_FOLDED
72776 @@ -3614,6 +3872,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
72777 spin_unlock(&mm->page_table_lock);
72778 return 0;
72779 }
72780 +
72781 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
72782 +{
72783 + pmd_t *new = pmd_alloc_one(mm, address);
72784 + if (!new)
72785 + return -ENOMEM;
72786 +
72787 + smp_wmb(); /* See comment in __pte_alloc */
72788 +
72789 + spin_lock(&mm->page_table_lock);
72790 +#ifndef __ARCH_HAS_4LEVEL_HACK
72791 + if (pud_present(*pud)) /* Another has populated it */
72792 + pmd_free(mm, new);
72793 + else
72794 + pud_populate_kernel(mm, pud, new);
72795 +#else
72796 + if (pgd_present(*pud)) /* Another has populated it */
72797 + pmd_free(mm, new);
72798 + else
72799 + pgd_populate_kernel(mm, pud, new);
72800 +#endif /* __ARCH_HAS_4LEVEL_HACK */
72801 + spin_unlock(&mm->page_table_lock);
72802 + return 0;
72803 +}
72804 #endif /* __PAGETABLE_PMD_FOLDED */
72805
72806 int make_pages_present(unsigned long addr, unsigned long end)
72807 @@ -3651,7 +3933,7 @@ static int __init gate_vma_init(void)
72808 gate_vma.vm_start = FIXADDR_USER_START;
72809 gate_vma.vm_end = FIXADDR_USER_END;
72810 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
72811 - gate_vma.vm_page_prot = __P101;
72812 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
72813
72814 return 0;
72815 }
72816 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
72817 index 3d64b36..c6ab69c 100644
72818 --- a/mm/mempolicy.c
72819 +++ b/mm/mempolicy.c
72820 @@ -655,6 +655,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
72821 unsigned long vmstart;
72822 unsigned long vmend;
72823
72824 +#ifdef CONFIG_PAX_SEGMEXEC
72825 + struct vm_area_struct *vma_m;
72826 +#endif
72827 +
72828 vma = find_vma(mm, start);
72829 if (!vma || vma->vm_start > start)
72830 return -EFAULT;
72831 @@ -691,9 +695,20 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
72832 if (err)
72833 goto out;
72834 }
72835 +
72836 err = vma_replace_policy(vma, new_pol);
72837 if (err)
72838 goto out;
72839 +
72840 +#ifdef CONFIG_PAX_SEGMEXEC
72841 + vma_m = pax_find_mirror_vma(vma);
72842 + if (vma_m) {
72843 + err = vma_replace_policy(vma_m, new_pol);
72844 + if (err)
72845 + goto out;
72846 + }
72847 +#endif
72848 +
72849 }
72850
72851 out:
72852 @@ -1147,6 +1162,17 @@ static long do_mbind(unsigned long start, unsigned long len,
72853
72854 if (end < start)
72855 return -EINVAL;
72856 +
72857 +#ifdef CONFIG_PAX_SEGMEXEC
72858 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
72859 + if (end > SEGMEXEC_TASK_SIZE)
72860 + return -EINVAL;
72861 + } else
72862 +#endif
72863 +
72864 + if (end > TASK_SIZE)
72865 + return -EINVAL;
72866 +
72867 if (end == start)
72868 return 0;
72869
72870 @@ -1370,8 +1396,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
72871 */
72872 tcred = __task_cred(task);
72873 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
72874 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
72875 - !capable(CAP_SYS_NICE)) {
72876 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
72877 rcu_read_unlock();
72878 err = -EPERM;
72879 goto out_put;
72880 @@ -1402,6 +1427,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
72881 goto out;
72882 }
72883
72884 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
72885 + if (mm != current->mm &&
72886 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
72887 + mmput(mm);
72888 + err = -EPERM;
72889 + goto out;
72890 + }
72891 +#endif
72892 +
72893 err = do_migrate_pages(mm, old, new,
72894 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
72895
72896 diff --git a/mm/migrate.c b/mm/migrate.c
72897 index 77ed2d7..317d528 100644
72898 --- a/mm/migrate.c
72899 +++ b/mm/migrate.c
72900 @@ -1350,8 +1350,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
72901 */
72902 tcred = __task_cred(task);
72903 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
72904 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
72905 - !capable(CAP_SYS_NICE)) {
72906 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
72907 rcu_read_unlock();
72908 err = -EPERM;
72909 goto out;
72910 diff --git a/mm/mlock.c b/mm/mlock.c
72911 index ef726e8..cd7f1ec 100644
72912 --- a/mm/mlock.c
72913 +++ b/mm/mlock.c
72914 @@ -13,6 +13,7 @@
72915 #include <linux/pagemap.h>
72916 #include <linux/mempolicy.h>
72917 #include <linux/syscalls.h>
72918 +#include <linux/security.h>
72919 #include <linux/sched.h>
72920 #include <linux/export.h>
72921 #include <linux/rmap.h>
72922 @@ -376,7 +377,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
72923 {
72924 unsigned long nstart, end, tmp;
72925 struct vm_area_struct * vma, * prev;
72926 - int error;
72927 + int error = 0;
72928
72929 VM_BUG_ON(start & ~PAGE_MASK);
72930 VM_BUG_ON(len != PAGE_ALIGN(len));
72931 @@ -385,6 +386,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
72932 return -EINVAL;
72933 if (end == start)
72934 return 0;
72935 + if (end > TASK_SIZE)
72936 + return -EINVAL;
72937 +
72938 vma = find_vma(current->mm, start);
72939 if (!vma || vma->vm_start > start)
72940 return -ENOMEM;
72941 @@ -396,6 +400,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
72942 for (nstart = start ; ; ) {
72943 vm_flags_t newflags;
72944
72945 +#ifdef CONFIG_PAX_SEGMEXEC
72946 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
72947 + break;
72948 +#endif
72949 +
72950 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
72951
72952 newflags = vma->vm_flags | VM_LOCKED;
72953 @@ -501,6 +510,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
72954 lock_limit >>= PAGE_SHIFT;
72955
72956 /* check against resource limits */
72957 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
72958 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
72959 error = do_mlock(start, len, 1);
72960 up_write(&current->mm->mmap_sem);
72961 @@ -524,17 +534,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
72962 static int do_mlockall(int flags)
72963 {
72964 struct vm_area_struct * vma, * prev = NULL;
72965 - unsigned int def_flags = 0;
72966
72967 if (flags & MCL_FUTURE)
72968 - def_flags = VM_LOCKED;
72969 - current->mm->def_flags = def_flags;
72970 + current->mm->def_flags |= VM_LOCKED;
72971 + else
72972 + current->mm->def_flags &= ~VM_LOCKED;
72973 if (flags == MCL_FUTURE)
72974 goto out;
72975
72976 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
72977 vm_flags_t newflags;
72978
72979 +#ifdef CONFIG_PAX_SEGMEXEC
72980 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
72981 + break;
72982 +#endif
72983 +
72984 + BUG_ON(vma->vm_end > TASK_SIZE);
72985 newflags = vma->vm_flags | VM_LOCKED;
72986 if (!(flags & MCL_CURRENT))
72987 newflags &= ~VM_LOCKED;
72988 @@ -567,6 +583,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
72989 lock_limit >>= PAGE_SHIFT;
72990
72991 ret = -ENOMEM;
72992 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
72993 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
72994 capable(CAP_IPC_LOCK))
72995 ret = do_mlockall(flags);
72996 diff --git a/mm/mmap.c b/mm/mmap.c
72997 index ae18a48..86cf99e 100644
72998 --- a/mm/mmap.c
72999 +++ b/mm/mmap.c
73000 @@ -47,6 +47,16 @@
73001 #define arch_rebalance_pgtables(addr, len) (addr)
73002 #endif
73003
73004 +static inline void verify_mm_writelocked(struct mm_struct *mm)
73005 +{
73006 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
73007 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
73008 + up_read(&mm->mmap_sem);
73009 + BUG();
73010 + }
73011 +#endif
73012 +}
73013 +
73014 static void unmap_region(struct mm_struct *mm,
73015 struct vm_area_struct *vma, struct vm_area_struct *prev,
73016 unsigned long start, unsigned long end);
73017 @@ -72,22 +82,32 @@ static void unmap_region(struct mm_struct *mm,
73018 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
73019 *
73020 */
73021 -pgprot_t protection_map[16] = {
73022 +pgprot_t protection_map[16] __read_only = {
73023 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
73024 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
73025 };
73026
73027 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
73028 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
73029 {
73030 - return __pgprot(pgprot_val(protection_map[vm_flags &
73031 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
73032 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
73033 pgprot_val(arch_vm_get_page_prot(vm_flags)));
73034 +
73035 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
73036 + if (!(__supported_pte_mask & _PAGE_NX) &&
73037 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
73038 + (vm_flags & (VM_READ | VM_WRITE)))
73039 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
73040 +#endif
73041 +
73042 + return prot;
73043 }
73044 EXPORT_SYMBOL(vm_get_page_prot);
73045
73046 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
73047 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
73048 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
73049 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
73050 /*
73051 * Make sure vm_committed_as in one cacheline and not cacheline shared with
73052 * other variables. It can be updated by several CPUs frequently.
73053 @@ -229,6 +249,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
73054 struct vm_area_struct *next = vma->vm_next;
73055
73056 might_sleep();
73057 + BUG_ON(vma->vm_mirror);
73058 if (vma->vm_ops && vma->vm_ops->close)
73059 vma->vm_ops->close(vma);
73060 if (vma->vm_file) {
73061 @@ -275,6 +296,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
73062 * not page aligned -Ram Gupta
73063 */
73064 rlim = rlimit(RLIMIT_DATA);
73065 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
73066 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
73067 (mm->end_data - mm->start_data) > rlim)
73068 goto out;
73069 @@ -708,6 +730,12 @@ static int
73070 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
73071 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
73072 {
73073 +
73074 +#ifdef CONFIG_PAX_SEGMEXEC
73075 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
73076 + return 0;
73077 +#endif
73078 +
73079 if (is_mergeable_vma(vma, file, vm_flags) &&
73080 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
73081 if (vma->vm_pgoff == vm_pgoff)
73082 @@ -727,6 +755,12 @@ static int
73083 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
73084 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
73085 {
73086 +
73087 +#ifdef CONFIG_PAX_SEGMEXEC
73088 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
73089 + return 0;
73090 +#endif
73091 +
73092 if (is_mergeable_vma(vma, file, vm_flags) &&
73093 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
73094 pgoff_t vm_pglen;
73095 @@ -769,13 +803,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
73096 struct vm_area_struct *vma_merge(struct mm_struct *mm,
73097 struct vm_area_struct *prev, unsigned long addr,
73098 unsigned long end, unsigned long vm_flags,
73099 - struct anon_vma *anon_vma, struct file *file,
73100 + struct anon_vma *anon_vma, struct file *file,
73101 pgoff_t pgoff, struct mempolicy *policy)
73102 {
73103 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
73104 struct vm_area_struct *area, *next;
73105 int err;
73106
73107 +#ifdef CONFIG_PAX_SEGMEXEC
73108 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
73109 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
73110 +
73111 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
73112 +#endif
73113 +
73114 /*
73115 * We later require that vma->vm_flags == vm_flags,
73116 * so this tests vma->vm_flags & VM_SPECIAL, too.
73117 @@ -791,6 +832,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
73118 if (next && next->vm_end == end) /* cases 6, 7, 8 */
73119 next = next->vm_next;
73120
73121 +#ifdef CONFIG_PAX_SEGMEXEC
73122 + if (prev)
73123 + prev_m = pax_find_mirror_vma(prev);
73124 + if (area)
73125 + area_m = pax_find_mirror_vma(area);
73126 + if (next)
73127 + next_m = pax_find_mirror_vma(next);
73128 +#endif
73129 +
73130 /*
73131 * Can it merge with the predecessor?
73132 */
73133 @@ -810,9 +860,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
73134 /* cases 1, 6 */
73135 err = vma_adjust(prev, prev->vm_start,
73136 next->vm_end, prev->vm_pgoff, NULL);
73137 - } else /* cases 2, 5, 7 */
73138 +
73139 +#ifdef CONFIG_PAX_SEGMEXEC
73140 + if (!err && prev_m)
73141 + err = vma_adjust(prev_m, prev_m->vm_start,
73142 + next_m->vm_end, prev_m->vm_pgoff, NULL);
73143 +#endif
73144 +
73145 + } else { /* cases 2, 5, 7 */
73146 err = vma_adjust(prev, prev->vm_start,
73147 end, prev->vm_pgoff, NULL);
73148 +
73149 +#ifdef CONFIG_PAX_SEGMEXEC
73150 + if (!err && prev_m)
73151 + err = vma_adjust(prev_m, prev_m->vm_start,
73152 + end_m, prev_m->vm_pgoff, NULL);
73153 +#endif
73154 +
73155 + }
73156 if (err)
73157 return NULL;
73158 khugepaged_enter_vma_merge(prev);
73159 @@ -826,12 +891,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
73160 mpol_equal(policy, vma_policy(next)) &&
73161 can_vma_merge_before(next, vm_flags,
73162 anon_vma, file, pgoff+pglen)) {
73163 - if (prev && addr < prev->vm_end) /* case 4 */
73164 + if (prev && addr < prev->vm_end) { /* case 4 */
73165 err = vma_adjust(prev, prev->vm_start,
73166 addr, prev->vm_pgoff, NULL);
73167 - else /* cases 3, 8 */
73168 +
73169 +#ifdef CONFIG_PAX_SEGMEXEC
73170 + if (!err && prev_m)
73171 + err = vma_adjust(prev_m, prev_m->vm_start,
73172 + addr_m, prev_m->vm_pgoff, NULL);
73173 +#endif
73174 +
73175 + } else { /* cases 3, 8 */
73176 err = vma_adjust(area, addr, next->vm_end,
73177 next->vm_pgoff - pglen, NULL);
73178 +
73179 +#ifdef CONFIG_PAX_SEGMEXEC
73180 + if (!err && area_m)
73181 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
73182 + next_m->vm_pgoff - pglen, NULL);
73183 +#endif
73184 +
73185 + }
73186 if (err)
73187 return NULL;
73188 khugepaged_enter_vma_merge(area);
73189 @@ -940,16 +1020,13 @@ none:
73190 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
73191 struct file *file, long pages)
73192 {
73193 - const unsigned long stack_flags
73194 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
73195 -
73196 mm->total_vm += pages;
73197
73198 if (file) {
73199 mm->shared_vm += pages;
73200 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
73201 mm->exec_vm += pages;
73202 - } else if (flags & stack_flags)
73203 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
73204 mm->stack_vm += pages;
73205 if (flags & (VM_RESERVED|VM_IO))
73206 mm->reserved_vm += pages;
73207 @@ -987,7 +1064,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73208 * (the exception is when the underlying filesystem is noexec
73209 * mounted, in which case we dont add PROT_EXEC.)
73210 */
73211 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
73212 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
73213 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
73214 prot |= PROT_EXEC;
73215
73216 @@ -1013,7 +1090,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73217 /* Obtain the address to map to. we verify (or select) it and ensure
73218 * that it represents a valid section of the address space.
73219 */
73220 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
73221 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
73222 if (addr & ~PAGE_MASK)
73223 return addr;
73224
73225 @@ -1024,6 +1101,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73226 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
73227 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
73228
73229 +#ifdef CONFIG_PAX_MPROTECT
73230 + if (mm->pax_flags & MF_PAX_MPROTECT) {
73231 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
73232 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
73233 + gr_log_rwxmmap(file);
73234 +
73235 +#ifdef CONFIG_PAX_EMUPLT
73236 + vm_flags &= ~VM_EXEC;
73237 +#else
73238 + return -EPERM;
73239 +#endif
73240 +
73241 + }
73242 +
73243 + if (!(vm_flags & VM_EXEC))
73244 + vm_flags &= ~VM_MAYEXEC;
73245 +#else
73246 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
73247 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
73248 +#endif
73249 + else
73250 + vm_flags &= ~VM_MAYWRITE;
73251 + }
73252 +#endif
73253 +
73254 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
73255 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
73256 + vm_flags &= ~VM_PAGEEXEC;
73257 +#endif
73258 +
73259 if (flags & MAP_LOCKED)
73260 if (!can_do_mlock())
73261 return -EPERM;
73262 @@ -1035,6 +1142,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73263 locked += mm->locked_vm;
73264 lock_limit = rlimit(RLIMIT_MEMLOCK);
73265 lock_limit >>= PAGE_SHIFT;
73266 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
73267 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
73268 return -EAGAIN;
73269 }
73270 @@ -1101,6 +1209,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73271 }
73272 }
73273
73274 + if (!gr_acl_handle_mmap(file, prot))
73275 + return -EACCES;
73276 +
73277 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
73278 }
73279
73280 @@ -1177,7 +1288,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
73281 vm_flags_t vm_flags = vma->vm_flags;
73282
73283 /* If it was private or non-writable, the write bit is already clear */
73284 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
73285 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
73286 return 0;
73287
73288 /* The backer wishes to know when pages are first written to? */
73289 @@ -1226,14 +1337,24 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
73290 unsigned long charged = 0;
73291 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
73292
73293 +#ifdef CONFIG_PAX_SEGMEXEC
73294 + struct vm_area_struct *vma_m = NULL;
73295 +#endif
73296 +
73297 + /*
73298 + * mm->mmap_sem is required to protect against another thread
73299 + * changing the mappings in case we sleep.
73300 + */
73301 + verify_mm_writelocked(mm);
73302 +
73303 /* Clear old maps */
73304 error = -ENOMEM;
73305 -munmap_back:
73306 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73307 if (vma && vma->vm_start < addr + len) {
73308 if (do_munmap(mm, addr, len))
73309 return -ENOMEM;
73310 - goto munmap_back;
73311 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73312 + BUG_ON(vma && vma->vm_start < addr + len);
73313 }
73314
73315 /* Check against address space limit. */
73316 @@ -1282,6 +1403,16 @@ munmap_back:
73317 goto unacct_error;
73318 }
73319
73320 +#ifdef CONFIG_PAX_SEGMEXEC
73321 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
73322 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73323 + if (!vma_m) {
73324 + error = -ENOMEM;
73325 + goto free_vma;
73326 + }
73327 + }
73328 +#endif
73329 +
73330 vma->vm_mm = mm;
73331 vma->vm_start = addr;
73332 vma->vm_end = addr + len;
73333 @@ -1306,6 +1437,19 @@ munmap_back:
73334 error = file->f_op->mmap(file, vma);
73335 if (error)
73336 goto unmap_and_free_vma;
73337 +
73338 +#ifdef CONFIG_PAX_SEGMEXEC
73339 + if (vma_m && (vm_flags & VM_EXECUTABLE))
73340 + added_exe_file_vma(mm);
73341 +#endif
73342 +
73343 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
73344 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
73345 + vma->vm_flags |= VM_PAGEEXEC;
73346 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
73347 + }
73348 +#endif
73349 +
73350 if (vm_flags & VM_EXECUTABLE)
73351 added_exe_file_vma(mm);
73352
73353 @@ -1343,6 +1487,11 @@ munmap_back:
73354 vma_link(mm, vma, prev, rb_link, rb_parent);
73355 file = vma->vm_file;
73356
73357 +#ifdef CONFIG_PAX_SEGMEXEC
73358 + if (vma_m)
73359 + BUG_ON(pax_mirror_vma(vma_m, vma));
73360 +#endif
73361 +
73362 /* Once vma denies write, undo our temporary denial count */
73363 if (correct_wcount)
73364 atomic_inc(&inode->i_writecount);
73365 @@ -1350,6 +1499,7 @@ out:
73366 perf_event_mmap(vma);
73367
73368 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
73369 + track_exec_limit(mm, addr, addr + len, vm_flags);
73370 if (vm_flags & VM_LOCKED) {
73371 if (!mlock_vma_pages_range(vma, addr, addr + len))
73372 mm->locked_vm += (len >> PAGE_SHIFT);
73373 @@ -1371,6 +1521,12 @@ unmap_and_free_vma:
73374 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
73375 charged = 0;
73376 free_vma:
73377 +
73378 +#ifdef CONFIG_PAX_SEGMEXEC
73379 + if (vma_m)
73380 + kmem_cache_free(vm_area_cachep, vma_m);
73381 +#endif
73382 +
73383 kmem_cache_free(vm_area_cachep, vma);
73384 unacct_error:
73385 if (charged)
73386 @@ -1378,6 +1534,44 @@ unacct_error:
73387 return error;
73388 }
73389
73390 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
73391 +{
73392 + if (!vma) {
73393 +#ifdef CONFIG_STACK_GROWSUP
73394 + if (addr > sysctl_heap_stack_gap)
73395 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
73396 + else
73397 + vma = find_vma(current->mm, 0);
73398 + if (vma && (vma->vm_flags & VM_GROWSUP))
73399 + return false;
73400 +#endif
73401 + return true;
73402 + }
73403 +
73404 + if (addr + len > vma->vm_start)
73405 + return false;
73406 +
73407 + if (vma->vm_flags & VM_GROWSDOWN)
73408 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
73409 +#ifdef CONFIG_STACK_GROWSUP
73410 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
73411 + return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
73412 +#endif
73413 +
73414 + return true;
73415 +}
73416 +
73417 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
73418 +{
73419 + if (vma->vm_start < len)
73420 + return -ENOMEM;
73421 + if (!(vma->vm_flags & VM_GROWSDOWN))
73422 + return vma->vm_start - len;
73423 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
73424 + return vma->vm_start - len - sysctl_heap_stack_gap;
73425 + return -ENOMEM;
73426 +}
73427 +
73428 /* Get an address range which is currently unmapped.
73429 * For shmat() with addr=0.
73430 *
73431 @@ -1404,18 +1598,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
73432 if (flags & MAP_FIXED)
73433 return addr;
73434
73435 +#ifdef CONFIG_PAX_RANDMMAP
73436 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
73437 +#endif
73438 +
73439 if (addr) {
73440 addr = PAGE_ALIGN(addr);
73441 - vma = find_vma(mm, addr);
73442 - if (TASK_SIZE - len >= addr &&
73443 - (!vma || addr + len <= vma->vm_start))
73444 - return addr;
73445 + if (TASK_SIZE - len >= addr) {
73446 + vma = find_vma(mm, addr);
73447 + if (check_heap_stack_gap(vma, addr, len))
73448 + return addr;
73449 + }
73450 }
73451 if (len > mm->cached_hole_size) {
73452 - start_addr = addr = mm->free_area_cache;
73453 + start_addr = addr = mm->free_area_cache;
73454 } else {
73455 - start_addr = addr = TASK_UNMAPPED_BASE;
73456 - mm->cached_hole_size = 0;
73457 + start_addr = addr = mm->mmap_base;
73458 + mm->cached_hole_size = 0;
73459 }
73460
73461 full_search:
73462 @@ -1426,34 +1625,40 @@ full_search:
73463 * Start a new search - just in case we missed
73464 * some holes.
73465 */
73466 - if (start_addr != TASK_UNMAPPED_BASE) {
73467 - addr = TASK_UNMAPPED_BASE;
73468 - start_addr = addr;
73469 + if (start_addr != mm->mmap_base) {
73470 + start_addr = addr = mm->mmap_base;
73471 mm->cached_hole_size = 0;
73472 goto full_search;
73473 }
73474 return -ENOMEM;
73475 }
73476 - if (!vma || addr + len <= vma->vm_start) {
73477 - /*
73478 - * Remember the place where we stopped the search:
73479 - */
73480 - mm->free_area_cache = addr + len;
73481 - return addr;
73482 - }
73483 + if (check_heap_stack_gap(vma, addr, len))
73484 + break;
73485 if (addr + mm->cached_hole_size < vma->vm_start)
73486 mm->cached_hole_size = vma->vm_start - addr;
73487 addr = vma->vm_end;
73488 }
73489 +
73490 + /*
73491 + * Remember the place where we stopped the search:
73492 + */
73493 + mm->free_area_cache = addr + len;
73494 + return addr;
73495 }
73496 #endif
73497
73498 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
73499 {
73500 +
73501 +#ifdef CONFIG_PAX_SEGMEXEC
73502 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
73503 + return;
73504 +#endif
73505 +
73506 /*
73507 * Is this a new hole at the lowest possible address?
73508 */
73509 - if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
73510 + if (addr >= mm->mmap_base && addr < mm->free_area_cache)
73511 mm->free_area_cache = addr;
73512 }
73513
73514 @@ -1469,7 +1674,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
73515 {
73516 struct vm_area_struct *vma;
73517 struct mm_struct *mm = current->mm;
73518 - unsigned long addr = addr0, start_addr;
73519 + unsigned long base = mm->mmap_base, addr = addr0, start_addr;
73520
73521 /* requested length too big for entire address space */
73522 if (len > TASK_SIZE)
73523 @@ -1478,13 +1683,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
73524 if (flags & MAP_FIXED)
73525 return addr;
73526
73527 +#ifdef CONFIG_PAX_RANDMMAP
73528 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
73529 +#endif
73530 +
73531 /* requesting a specific address */
73532 if (addr) {
73533 addr = PAGE_ALIGN(addr);
73534 - vma = find_vma(mm, addr);
73535 - if (TASK_SIZE - len >= addr &&
73536 - (!vma || addr + len <= vma->vm_start))
73537 - return addr;
73538 + if (TASK_SIZE - len >= addr) {
73539 + vma = find_vma(mm, addr);
73540 + if (check_heap_stack_gap(vma, addr, len))
73541 + return addr;
73542 + }
73543 }
73544
73545 /* check if free_area_cache is useful for us */
73546 @@ -1508,7 +1718,7 @@ try_again:
73547 * return with success:
73548 */
73549 vma = find_vma(mm, addr);
73550 - if (!vma || addr+len <= vma->vm_start)
73551 + if (check_heap_stack_gap(vma, addr, len))
73552 /* remember the address as a hint for next time */
73553 return (mm->free_area_cache = addr);
73554
73555 @@ -1517,8 +1727,8 @@ try_again:
73556 mm->cached_hole_size = vma->vm_start - addr;
73557
73558 /* try just below the current vma->vm_start */
73559 - addr = vma->vm_start-len;
73560 - } while (len < vma->vm_start);
73561 + addr = skip_heap_stack_gap(vma, len);
73562 + } while (!IS_ERR_VALUE(addr));
73563
73564 fail:
73565 /*
73566 @@ -1541,13 +1751,21 @@ fail:
73567 * can happen with large stack limits and large mmap()
73568 * allocations.
73569 */
73570 + mm->mmap_base = TASK_UNMAPPED_BASE;
73571 +
73572 +#ifdef CONFIG_PAX_RANDMMAP
73573 + if (mm->pax_flags & MF_PAX_RANDMMAP)
73574 + mm->mmap_base += mm->delta_mmap;
73575 +#endif
73576 +
73577 + mm->free_area_cache = mm->mmap_base;
73578 mm->cached_hole_size = ~0UL;
73579 - mm->free_area_cache = TASK_UNMAPPED_BASE;
73580 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
73581 /*
73582 * Restore the topdown base:
73583 */
73584 - mm->free_area_cache = mm->mmap_base;
73585 + mm->mmap_base = base;
73586 + mm->free_area_cache = base;
73587 mm->cached_hole_size = ~0UL;
73588
73589 return addr;
73590 @@ -1556,6 +1774,12 @@ fail:
73591
73592 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
73593 {
73594 +
73595 +#ifdef CONFIG_PAX_SEGMEXEC
73596 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
73597 + return;
73598 +#endif
73599 +
73600 /*
73601 * Is this a new hole at the highest possible address?
73602 */
73603 @@ -1563,8 +1787,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
73604 mm->free_area_cache = addr;
73605
73606 /* dont allow allocations above current base */
73607 - if (mm->free_area_cache > mm->mmap_base)
73608 + if (mm->free_area_cache > mm->mmap_base) {
73609 mm->free_area_cache = mm->mmap_base;
73610 + mm->cached_hole_size = ~0UL;
73611 + }
73612 }
73613
73614 unsigned long
73615 @@ -1663,6 +1889,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
73616 return vma;
73617 }
73618
73619 +#ifdef CONFIG_PAX_SEGMEXEC
73620 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
73621 +{
73622 + struct vm_area_struct *vma_m;
73623 +
73624 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
73625 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
73626 + BUG_ON(vma->vm_mirror);
73627 + return NULL;
73628 + }
73629 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
73630 + vma_m = vma->vm_mirror;
73631 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
73632 + BUG_ON(vma->vm_file != vma_m->vm_file);
73633 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
73634 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
73635 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
73636 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
73637 + return vma_m;
73638 +}
73639 +#endif
73640 +
73641 /*
73642 * Verify that the stack growth is acceptable and
73643 * update accounting. This is shared with both the
73644 @@ -1679,6 +1927,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
73645 return -ENOMEM;
73646
73647 /* Stack limit test */
73648 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
73649 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
73650 return -ENOMEM;
73651
73652 @@ -1689,6 +1938,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
73653 locked = mm->locked_vm + grow;
73654 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
73655 limit >>= PAGE_SHIFT;
73656 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
73657 if (locked > limit && !capable(CAP_IPC_LOCK))
73658 return -ENOMEM;
73659 }
73660 @@ -1718,37 +1968,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
73661 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
73662 * vma is the last one with address > vma->vm_end. Have to extend vma.
73663 */
73664 +#ifndef CONFIG_IA64
73665 +static
73666 +#endif
73667 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
73668 {
73669 int error;
73670 + bool locknext;
73671
73672 if (!(vma->vm_flags & VM_GROWSUP))
73673 return -EFAULT;
73674
73675 + /* Also guard against wrapping around to address 0. */
73676 + if (address < PAGE_ALIGN(address+1))
73677 + address = PAGE_ALIGN(address+1);
73678 + else
73679 + return -ENOMEM;
73680 +
73681 /*
73682 * We must make sure the anon_vma is allocated
73683 * so that the anon_vma locking is not a noop.
73684 */
73685 if (unlikely(anon_vma_prepare(vma)))
73686 return -ENOMEM;
73687 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
73688 + if (locknext && anon_vma_prepare(vma->vm_next))
73689 + return -ENOMEM;
73690 vma_lock_anon_vma(vma);
73691 + if (locknext)
73692 + vma_lock_anon_vma(vma->vm_next);
73693
73694 /*
73695 * vma->vm_start/vm_end cannot change under us because the caller
73696 * is required to hold the mmap_sem in read mode. We need the
73697 - * anon_vma lock to serialize against concurrent expand_stacks.
73698 - * Also guard against wrapping around to address 0.
73699 + * anon_vma locks to serialize against concurrent expand_stacks
73700 + * and expand_upwards.
73701 */
73702 - if (address < PAGE_ALIGN(address+4))
73703 - address = PAGE_ALIGN(address+4);
73704 - else {
73705 - vma_unlock_anon_vma(vma);
73706 - return -ENOMEM;
73707 - }
73708 error = 0;
73709
73710 /* Somebody else might have raced and expanded it already */
73711 - if (address > vma->vm_end) {
73712 + 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)
73713 + error = -ENOMEM;
73714 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
73715 unsigned long size, grow;
73716
73717 size = address - vma->vm_start;
73718 @@ -1763,6 +2024,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
73719 }
73720 }
73721 }
73722 + if (locknext)
73723 + vma_unlock_anon_vma(vma->vm_next);
73724 vma_unlock_anon_vma(vma);
73725 khugepaged_enter_vma_merge(vma);
73726 return error;
73727 @@ -1776,6 +2039,8 @@ int expand_downwards(struct vm_area_struct *vma,
73728 unsigned long address)
73729 {
73730 int error;
73731 + bool lockprev = false;
73732 + struct vm_area_struct *prev;
73733
73734 /*
73735 * We must make sure the anon_vma is allocated
73736 @@ -1789,6 +2054,15 @@ int expand_downwards(struct vm_area_struct *vma,
73737 if (error)
73738 return error;
73739
73740 + prev = vma->vm_prev;
73741 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
73742 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
73743 +#endif
73744 + if (lockprev && anon_vma_prepare(prev))
73745 + return -ENOMEM;
73746 + if (lockprev)
73747 + vma_lock_anon_vma(prev);
73748 +
73749 vma_lock_anon_vma(vma);
73750
73751 /*
73752 @@ -1798,9 +2072,17 @@ int expand_downwards(struct vm_area_struct *vma,
73753 */
73754
73755 /* Somebody else might have raced and expanded it already */
73756 - if (address < vma->vm_start) {
73757 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
73758 + error = -ENOMEM;
73759 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
73760 unsigned long size, grow;
73761
73762 +#ifdef CONFIG_PAX_SEGMEXEC
73763 + struct vm_area_struct *vma_m;
73764 +
73765 + vma_m = pax_find_mirror_vma(vma);
73766 +#endif
73767 +
73768 size = vma->vm_end - address;
73769 grow = (vma->vm_start - address) >> PAGE_SHIFT;
73770
73771 @@ -1810,11 +2092,22 @@ int expand_downwards(struct vm_area_struct *vma,
73772 if (!error) {
73773 vma->vm_start = address;
73774 vma->vm_pgoff -= grow;
73775 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
73776 +
73777 +#ifdef CONFIG_PAX_SEGMEXEC
73778 + if (vma_m) {
73779 + vma_m->vm_start -= grow << PAGE_SHIFT;
73780 + vma_m->vm_pgoff -= grow;
73781 + }
73782 +#endif
73783 +
73784 perf_event_mmap(vma);
73785 }
73786 }
73787 }
73788 vma_unlock_anon_vma(vma);
73789 + if (lockprev)
73790 + vma_unlock_anon_vma(prev);
73791 khugepaged_enter_vma_merge(vma);
73792 return error;
73793 }
73794 @@ -1886,6 +2179,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
73795 do {
73796 long nrpages = vma_pages(vma);
73797
73798 +#ifdef CONFIG_PAX_SEGMEXEC
73799 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
73800 + vma = remove_vma(vma);
73801 + continue;
73802 + }
73803 +#endif
73804 +
73805 if (vma->vm_flags & VM_ACCOUNT)
73806 nr_accounted += nrpages;
73807 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
73808 @@ -1931,6 +2231,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
73809 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
73810 vma->vm_prev = NULL;
73811 do {
73812 +
73813 +#ifdef CONFIG_PAX_SEGMEXEC
73814 + if (vma->vm_mirror) {
73815 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
73816 + vma->vm_mirror->vm_mirror = NULL;
73817 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
73818 + vma->vm_mirror = NULL;
73819 + }
73820 +#endif
73821 +
73822 rb_erase(&vma->vm_rb, &mm->mm_rb);
73823 mm->map_count--;
73824 tail_vma = vma;
73825 @@ -1959,14 +2269,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73826 struct vm_area_struct *new;
73827 int err = -ENOMEM;
73828
73829 +#ifdef CONFIG_PAX_SEGMEXEC
73830 + struct vm_area_struct *vma_m, *new_m = NULL;
73831 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
73832 +#endif
73833 +
73834 if (is_vm_hugetlb_page(vma) && (addr &
73835 ~(huge_page_mask(hstate_vma(vma)))))
73836 return -EINVAL;
73837
73838 +#ifdef CONFIG_PAX_SEGMEXEC
73839 + vma_m = pax_find_mirror_vma(vma);
73840 +#endif
73841 +
73842 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
73843 if (!new)
73844 goto out_err;
73845
73846 +#ifdef CONFIG_PAX_SEGMEXEC
73847 + if (vma_m) {
73848 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
73849 + if (!new_m) {
73850 + kmem_cache_free(vm_area_cachep, new);
73851 + goto out_err;
73852 + }
73853 + }
73854 +#endif
73855 +
73856 /* most fields are the same, copy all, and then fixup */
73857 *new = *vma;
73858
73859 @@ -1979,6 +2308,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73860 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
73861 }
73862
73863 +#ifdef CONFIG_PAX_SEGMEXEC
73864 + if (vma_m) {
73865 + *new_m = *vma_m;
73866 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
73867 + new_m->vm_mirror = new;
73868 + new->vm_mirror = new_m;
73869 +
73870 + if (new_below)
73871 + new_m->vm_end = addr_m;
73872 + else {
73873 + new_m->vm_start = addr_m;
73874 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
73875 + }
73876 + }
73877 +#endif
73878 +
73879 pol = mpol_dup(vma_policy(vma));
73880 if (IS_ERR(pol)) {
73881 err = PTR_ERR(pol);
73882 @@ -2004,6 +2349,42 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73883 else
73884 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
73885
73886 +#ifdef CONFIG_PAX_SEGMEXEC
73887 + if (!err && vma_m) {
73888 + if (anon_vma_clone(new_m, vma_m))
73889 + goto out_free_mpol;
73890 +
73891 + mpol_get(pol);
73892 + vma_set_policy(new_m, pol);
73893 +
73894 + if (new_m->vm_file) {
73895 + get_file(new_m->vm_file);
73896 + if (vma_m->vm_flags & VM_EXECUTABLE)
73897 + added_exe_file_vma(mm);
73898 + }
73899 +
73900 + if (new_m->vm_ops && new_m->vm_ops->open)
73901 + new_m->vm_ops->open(new_m);
73902 +
73903 + if (new_below)
73904 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
73905 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
73906 + else
73907 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
73908 +
73909 + if (err) {
73910 + if (new_m->vm_ops && new_m->vm_ops->close)
73911 + new_m->vm_ops->close(new_m);
73912 + if (new_m->vm_file) {
73913 + if (vma_m->vm_flags & VM_EXECUTABLE)
73914 + removed_exe_file_vma(mm);
73915 + fput(new_m->vm_file);
73916 + }
73917 + mpol_put(pol);
73918 + }
73919 + }
73920 +#endif
73921 +
73922 /* Success. */
73923 if (!err)
73924 return 0;
73925 @@ -2016,10 +2397,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73926 removed_exe_file_vma(mm);
73927 fput(new->vm_file);
73928 }
73929 - unlink_anon_vmas(new);
73930 out_free_mpol:
73931 mpol_put(pol);
73932 out_free_vma:
73933 +
73934 +#ifdef CONFIG_PAX_SEGMEXEC
73935 + if (new_m) {
73936 + unlink_anon_vmas(new_m);
73937 + kmem_cache_free(vm_area_cachep, new_m);
73938 + }
73939 +#endif
73940 +
73941 + unlink_anon_vmas(new);
73942 kmem_cache_free(vm_area_cachep, new);
73943 out_err:
73944 return err;
73945 @@ -2032,6 +2421,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73946 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
73947 unsigned long addr, int new_below)
73948 {
73949 +
73950 +#ifdef CONFIG_PAX_SEGMEXEC
73951 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
73952 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
73953 + if (mm->map_count >= sysctl_max_map_count-1)
73954 + return -ENOMEM;
73955 + } else
73956 +#endif
73957 +
73958 if (mm->map_count >= sysctl_max_map_count)
73959 return -ENOMEM;
73960
73961 @@ -2043,11 +2441,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
73962 * work. This now handles partial unmappings.
73963 * Jeremy Fitzhardinge <jeremy@goop.org>
73964 */
73965 +#ifdef CONFIG_PAX_SEGMEXEC
73966 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73967 {
73968 + int ret = __do_munmap(mm, start, len);
73969 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
73970 + return ret;
73971 +
73972 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
73973 +}
73974 +
73975 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73976 +#else
73977 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73978 +#endif
73979 +{
73980 unsigned long end;
73981 struct vm_area_struct *vma, *prev, *last;
73982
73983 + /*
73984 + * mm->mmap_sem is required to protect against another thread
73985 + * changing the mappings in case we sleep.
73986 + */
73987 + verify_mm_writelocked(mm);
73988 +
73989 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
73990 return -EINVAL;
73991
73992 @@ -2122,6 +2539,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73993 /* Fix up all other VM information */
73994 remove_vma_list(mm, vma);
73995
73996 + track_exec_limit(mm, start, end, 0UL);
73997 +
73998 return 0;
73999 }
74000
74001 @@ -2130,6 +2549,13 @@ int vm_munmap(unsigned long start, size_t len)
74002 int ret;
74003 struct mm_struct *mm = current->mm;
74004
74005 +
74006 +#ifdef CONFIG_PAX_SEGMEXEC
74007 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
74008 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
74009 + return -EINVAL;
74010 +#endif
74011 +
74012 down_write(&mm->mmap_sem);
74013 ret = do_munmap(mm, start, len);
74014 up_write(&mm->mmap_sem);
74015 @@ -2143,16 +2569,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
74016 return vm_munmap(addr, len);
74017 }
74018
74019 -static inline void verify_mm_writelocked(struct mm_struct *mm)
74020 -{
74021 -#ifdef CONFIG_DEBUG_VM
74022 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
74023 - WARN_ON(1);
74024 - up_read(&mm->mmap_sem);
74025 - }
74026 -#endif
74027 -}
74028 -
74029 /*
74030 * this is really a simplified "do_mmap". it only handles
74031 * anonymous maps. eventually we may be able to do some
74032 @@ -2166,6 +2582,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
74033 struct rb_node ** rb_link, * rb_parent;
74034 pgoff_t pgoff = addr >> PAGE_SHIFT;
74035 int error;
74036 + unsigned long charged;
74037
74038 len = PAGE_ALIGN(len);
74039 if (!len)
74040 @@ -2173,16 +2590,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
74041
74042 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
74043
74044 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
74045 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
74046 + flags &= ~VM_EXEC;
74047 +
74048 +#ifdef CONFIG_PAX_MPROTECT
74049 + if (mm->pax_flags & MF_PAX_MPROTECT)
74050 + flags &= ~VM_MAYEXEC;
74051 +#endif
74052 +
74053 + }
74054 +#endif
74055 +
74056 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
74057 if (error & ~PAGE_MASK)
74058 return error;
74059
74060 + charged = len >> PAGE_SHIFT;
74061 +
74062 /*
74063 * mlock MCL_FUTURE?
74064 */
74065 if (mm->def_flags & VM_LOCKED) {
74066 unsigned long locked, lock_limit;
74067 - locked = len >> PAGE_SHIFT;
74068 + locked = charged;
74069 locked += mm->locked_vm;
74070 lock_limit = rlimit(RLIMIT_MEMLOCK);
74071 lock_limit >>= PAGE_SHIFT;
74072 @@ -2199,22 +2630,22 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
74073 /*
74074 * Clear old maps. this also does some error checking for us
74075 */
74076 - munmap_back:
74077 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
74078 if (vma && vma->vm_start < addr + len) {
74079 if (do_munmap(mm, addr, len))
74080 return -ENOMEM;
74081 - goto munmap_back;
74082 - }
74083 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
74084 + BUG_ON(vma && vma->vm_start < addr + len);
74085 + }
74086
74087 /* Check against address space limits *after* clearing old maps... */
74088 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
74089 + if (!may_expand_vm(mm, charged))
74090 return -ENOMEM;
74091
74092 if (mm->map_count > sysctl_max_map_count)
74093 return -ENOMEM;
74094
74095 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
74096 + if (security_vm_enough_memory_mm(mm, charged))
74097 return -ENOMEM;
74098
74099 /* Can we just expand an old private anonymous mapping? */
74100 @@ -2228,7 +2659,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
74101 */
74102 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
74103 if (!vma) {
74104 - vm_unacct_memory(len >> PAGE_SHIFT);
74105 + vm_unacct_memory(charged);
74106 return -ENOMEM;
74107 }
74108
74109 @@ -2242,11 +2673,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
74110 vma_link(mm, vma, prev, rb_link, rb_parent);
74111 out:
74112 perf_event_mmap(vma);
74113 - mm->total_vm += len >> PAGE_SHIFT;
74114 + mm->total_vm += charged;
74115 if (flags & VM_LOCKED) {
74116 if (!mlock_vma_pages_range(vma, addr, addr + len))
74117 - mm->locked_vm += (len >> PAGE_SHIFT);
74118 + mm->locked_vm += charged;
74119 }
74120 + track_exec_limit(mm, addr, addr + len, flags);
74121 return addr;
74122 }
74123
74124 @@ -2304,6 +2736,7 @@ void exit_mmap(struct mm_struct *mm)
74125 while (vma) {
74126 if (vma->vm_flags & VM_ACCOUNT)
74127 nr_accounted += vma_pages(vma);
74128 + vma->vm_mirror = NULL;
74129 vma = remove_vma(vma);
74130 }
74131 vm_unacct_memory(nr_accounted);
74132 @@ -2320,6 +2753,13 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
74133 struct vm_area_struct * __vma, * prev;
74134 struct rb_node ** rb_link, * rb_parent;
74135
74136 +#ifdef CONFIG_PAX_SEGMEXEC
74137 + struct vm_area_struct *vma_m = NULL;
74138 +#endif
74139 +
74140 + if (security_mmap_addr(vma->vm_start))
74141 + return -EPERM;
74142 +
74143 /*
74144 * The vm_pgoff of a purely anonymous vma should be irrelevant
74145 * until its first write fault, when page's anon_vma and index
74146 @@ -2343,7 +2783,21 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
74147 security_vm_enough_memory_mm(mm, vma_pages(vma)))
74148 return -ENOMEM;
74149
74150 +#ifdef CONFIG_PAX_SEGMEXEC
74151 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
74152 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
74153 + if (!vma_m)
74154 + return -ENOMEM;
74155 + }
74156 +#endif
74157 +
74158 vma_link(mm, vma, prev, rb_link, rb_parent);
74159 +
74160 +#ifdef CONFIG_PAX_SEGMEXEC
74161 + if (vma_m)
74162 + BUG_ON(pax_mirror_vma(vma_m, vma));
74163 +#endif
74164 +
74165 return 0;
74166 }
74167
74168 @@ -2362,6 +2816,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
74169 struct mempolicy *pol;
74170 bool faulted_in_anon_vma = true;
74171
74172 + BUG_ON(vma->vm_mirror);
74173 +
74174 /*
74175 * If anonymous vma has not yet been faulted, update new pgoff
74176 * to match new location, to increase its chance of merging.
74177 @@ -2430,6 +2886,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
74178 return NULL;
74179 }
74180
74181 +#ifdef CONFIG_PAX_SEGMEXEC
74182 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
74183 +{
74184 + struct vm_area_struct *prev_m;
74185 + struct rb_node **rb_link_m, *rb_parent_m;
74186 + struct mempolicy *pol_m;
74187 +
74188 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
74189 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
74190 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
74191 + *vma_m = *vma;
74192 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
74193 + if (anon_vma_clone(vma_m, vma))
74194 + return -ENOMEM;
74195 + pol_m = vma_policy(vma_m);
74196 + mpol_get(pol_m);
74197 + vma_set_policy(vma_m, pol_m);
74198 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
74199 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
74200 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
74201 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
74202 + if (vma_m->vm_file)
74203 + get_file(vma_m->vm_file);
74204 + if (vma_m->vm_ops && vma_m->vm_ops->open)
74205 + vma_m->vm_ops->open(vma_m);
74206 + find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
74207 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
74208 + vma_m->vm_mirror = vma;
74209 + vma->vm_mirror = vma_m;
74210 + return 0;
74211 +}
74212 +#endif
74213 +
74214 /*
74215 * Return true if the calling process may expand its vm space by the passed
74216 * number of pages
74217 @@ -2441,6 +2930,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
74218
74219 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
74220
74221 +#ifdef CONFIG_PAX_RANDMMAP
74222 + if (mm->pax_flags & MF_PAX_RANDMMAP)
74223 + cur -= mm->brk_gap;
74224 +#endif
74225 +
74226 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
74227 if (cur + npages > lim)
74228 return 0;
74229 return 1;
74230 @@ -2511,6 +3006,22 @@ int install_special_mapping(struct mm_struct *mm,
74231 vma->vm_start = addr;
74232 vma->vm_end = addr + len;
74233
74234 +#ifdef CONFIG_PAX_MPROTECT
74235 + if (mm->pax_flags & MF_PAX_MPROTECT) {
74236 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
74237 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
74238 + return -EPERM;
74239 + if (!(vm_flags & VM_EXEC))
74240 + vm_flags &= ~VM_MAYEXEC;
74241 +#else
74242 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
74243 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
74244 +#endif
74245 + else
74246 + vm_flags &= ~VM_MAYWRITE;
74247 + }
74248 +#endif
74249 +
74250 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
74251 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
74252
74253 diff --git a/mm/mprotect.c b/mm/mprotect.c
74254 index a409926..8b32e6d 100644
74255 --- a/mm/mprotect.c
74256 +++ b/mm/mprotect.c
74257 @@ -23,10 +23,17 @@
74258 #include <linux/mmu_notifier.h>
74259 #include <linux/migrate.h>
74260 #include <linux/perf_event.h>
74261 +
74262 +#ifdef CONFIG_PAX_MPROTECT
74263 +#include <linux/elf.h>
74264 +#include <linux/binfmts.h>
74265 +#endif
74266 +
74267 #include <asm/uaccess.h>
74268 #include <asm/pgtable.h>
74269 #include <asm/cacheflush.h>
74270 #include <asm/tlbflush.h>
74271 +#include <asm/mmu_context.h>
74272
74273 #ifndef pgprot_modify
74274 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
74275 @@ -141,6 +148,48 @@ static void change_protection(struct vm_area_struct *vma,
74276 flush_tlb_range(vma, start, end);
74277 }
74278
74279 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
74280 +/* called while holding the mmap semaphor for writing except stack expansion */
74281 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
74282 +{
74283 + unsigned long oldlimit, newlimit = 0UL;
74284 +
74285 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
74286 + return;
74287 +
74288 + spin_lock(&mm->page_table_lock);
74289 + oldlimit = mm->context.user_cs_limit;
74290 + if ((prot & VM_EXEC) && oldlimit < end)
74291 + /* USER_CS limit moved up */
74292 + newlimit = end;
74293 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
74294 + /* USER_CS limit moved down */
74295 + newlimit = start;
74296 +
74297 + if (newlimit) {
74298 + mm->context.user_cs_limit = newlimit;
74299 +
74300 +#ifdef CONFIG_SMP
74301 + wmb();
74302 + cpus_clear(mm->context.cpu_user_cs_mask);
74303 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
74304 +#endif
74305 +
74306 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
74307 + }
74308 + spin_unlock(&mm->page_table_lock);
74309 + if (newlimit == end) {
74310 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
74311 +
74312 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
74313 + if (is_vm_hugetlb_page(vma))
74314 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
74315 + else
74316 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
74317 + }
74318 +}
74319 +#endif
74320 +
74321 int
74322 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
74323 unsigned long start, unsigned long end, unsigned long newflags)
74324 @@ -153,11 +202,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
74325 int error;
74326 int dirty_accountable = 0;
74327
74328 +#ifdef CONFIG_PAX_SEGMEXEC
74329 + struct vm_area_struct *vma_m = NULL;
74330 + unsigned long start_m, end_m;
74331 +
74332 + start_m = start + SEGMEXEC_TASK_SIZE;
74333 + end_m = end + SEGMEXEC_TASK_SIZE;
74334 +#endif
74335 +
74336 if (newflags == oldflags) {
74337 *pprev = vma;
74338 return 0;
74339 }
74340
74341 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
74342 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
74343 +
74344 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
74345 + return -ENOMEM;
74346 +
74347 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
74348 + return -ENOMEM;
74349 + }
74350 +
74351 /*
74352 * If we make a private mapping writable we increase our commit;
74353 * but (without finer accounting) cannot reduce our commit if we
74354 @@ -174,6 +241,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
74355 }
74356 }
74357
74358 +#ifdef CONFIG_PAX_SEGMEXEC
74359 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
74360 + if (start != vma->vm_start) {
74361 + error = split_vma(mm, vma, start, 1);
74362 + if (error)
74363 + goto fail;
74364 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
74365 + *pprev = (*pprev)->vm_next;
74366 + }
74367 +
74368 + if (end != vma->vm_end) {
74369 + error = split_vma(mm, vma, end, 0);
74370 + if (error)
74371 + goto fail;
74372 + }
74373 +
74374 + if (pax_find_mirror_vma(vma)) {
74375 + error = __do_munmap(mm, start_m, end_m - start_m);
74376 + if (error)
74377 + goto fail;
74378 + } else {
74379 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
74380 + if (!vma_m) {
74381 + error = -ENOMEM;
74382 + goto fail;
74383 + }
74384 + vma->vm_flags = newflags;
74385 + error = pax_mirror_vma(vma_m, vma);
74386 + if (error) {
74387 + vma->vm_flags = oldflags;
74388 + goto fail;
74389 + }
74390 + }
74391 + }
74392 +#endif
74393 +
74394 /*
74395 * First try to merge with previous and/or next vma.
74396 */
74397 @@ -204,9 +307,21 @@ success:
74398 * vm_flags and vm_page_prot are protected by the mmap_sem
74399 * held in write mode.
74400 */
74401 +
74402 +#ifdef CONFIG_PAX_SEGMEXEC
74403 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
74404 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
74405 +#endif
74406 +
74407 vma->vm_flags = newflags;
74408 +
74409 +#ifdef CONFIG_PAX_MPROTECT
74410 + if (mm->binfmt && mm->binfmt->handle_mprotect)
74411 + mm->binfmt->handle_mprotect(vma, newflags);
74412 +#endif
74413 +
74414 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
74415 - vm_get_page_prot(newflags));
74416 + vm_get_page_prot(vma->vm_flags));
74417
74418 if (vma_wants_writenotify(vma)) {
74419 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
74420 @@ -248,6 +363,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74421 end = start + len;
74422 if (end <= start)
74423 return -ENOMEM;
74424 +
74425 +#ifdef CONFIG_PAX_SEGMEXEC
74426 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
74427 + if (end > SEGMEXEC_TASK_SIZE)
74428 + return -EINVAL;
74429 + } else
74430 +#endif
74431 +
74432 + if (end > TASK_SIZE)
74433 + return -EINVAL;
74434 +
74435 if (!arch_validate_prot(prot))
74436 return -EINVAL;
74437
74438 @@ -255,7 +381,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74439 /*
74440 * Does the application expect PROT_READ to imply PROT_EXEC:
74441 */
74442 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
74443 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
74444 prot |= PROT_EXEC;
74445
74446 vm_flags = calc_vm_prot_bits(prot);
74447 @@ -288,6 +414,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74448 if (start > vma->vm_start)
74449 prev = vma;
74450
74451 +#ifdef CONFIG_PAX_MPROTECT
74452 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
74453 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
74454 +#endif
74455 +
74456 for (nstart = start ; ; ) {
74457 unsigned long newflags;
74458
74459 @@ -297,6 +428,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74460
74461 /* newflags >> 4 shift VM_MAY% in place of VM_% */
74462 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
74463 + if (prot & (PROT_WRITE | PROT_EXEC))
74464 + gr_log_rwxmprotect(vma->vm_file);
74465 +
74466 + error = -EACCES;
74467 + goto out;
74468 + }
74469 +
74470 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
74471 error = -EACCES;
74472 goto out;
74473 }
74474 @@ -311,6 +450,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74475 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
74476 if (error)
74477 goto out;
74478 +
74479 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
74480 +
74481 nstart = tmp;
74482
74483 if (nstart < prev->vm_end)
74484 diff --git a/mm/mremap.c b/mm/mremap.c
74485 index cc06d0e..40b5d18 100644
74486 --- a/mm/mremap.c
74487 +++ b/mm/mremap.c
74488 @@ -106,6 +106,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
74489 continue;
74490 pte = ptep_get_and_clear(mm, old_addr, old_pte);
74491 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
74492 +
74493 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
74494 + if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
74495 + pte = pte_exprotect(pte);
74496 +#endif
74497 +
74498 set_pte_at(mm, new_addr, new_pte, pte);
74499 }
74500
74501 @@ -298,6 +304,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
74502 if (is_vm_hugetlb_page(vma))
74503 goto Einval;
74504
74505 +#ifdef CONFIG_PAX_SEGMEXEC
74506 + if (pax_find_mirror_vma(vma))
74507 + goto Einval;
74508 +#endif
74509 +
74510 /* We can't remap across vm area boundaries */
74511 if (old_len > vma->vm_end - addr)
74512 goto Efault;
74513 @@ -354,20 +365,25 @@ static unsigned long mremap_to(unsigned long addr,
74514 unsigned long ret = -EINVAL;
74515 unsigned long charged = 0;
74516 unsigned long map_flags;
74517 + unsigned long pax_task_size = TASK_SIZE;
74518
74519 if (new_addr & ~PAGE_MASK)
74520 goto out;
74521
74522 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
74523 +#ifdef CONFIG_PAX_SEGMEXEC
74524 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
74525 + pax_task_size = SEGMEXEC_TASK_SIZE;
74526 +#endif
74527 +
74528 + pax_task_size -= PAGE_SIZE;
74529 +
74530 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
74531 goto out;
74532
74533 /* Check if the location we're moving into overlaps the
74534 * old location at all, and fail if it does.
74535 */
74536 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
74537 - goto out;
74538 -
74539 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
74540 + if (addr + old_len > new_addr && new_addr + new_len > addr)
74541 goto out;
74542
74543 ret = do_munmap(mm, new_addr, new_len);
74544 @@ -435,6 +451,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74545 struct vm_area_struct *vma;
74546 unsigned long ret = -EINVAL;
74547 unsigned long charged = 0;
74548 + unsigned long pax_task_size = TASK_SIZE;
74549
74550 down_write(&current->mm->mmap_sem);
74551
74552 @@ -455,6 +472,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74553 if (!new_len)
74554 goto out;
74555
74556 +#ifdef CONFIG_PAX_SEGMEXEC
74557 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
74558 + pax_task_size = SEGMEXEC_TASK_SIZE;
74559 +#endif
74560 +
74561 + pax_task_size -= PAGE_SIZE;
74562 +
74563 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
74564 + old_len > pax_task_size || addr > pax_task_size-old_len)
74565 + goto out;
74566 +
74567 if (flags & MREMAP_FIXED) {
74568 if (flags & MREMAP_MAYMOVE)
74569 ret = mremap_to(addr, old_len, new_addr, new_len);
74570 @@ -503,6 +531,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74571 addr + new_len);
74572 }
74573 ret = addr;
74574 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
74575 goto out;
74576 }
74577 }
74578 @@ -526,7 +555,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74579 goto out;
74580 }
74581
74582 + map_flags = vma->vm_flags;
74583 ret = move_vma(vma, addr, old_len, new_len, new_addr);
74584 + if (!(ret & ~PAGE_MASK)) {
74585 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
74586 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
74587 + }
74588 }
74589 out:
74590 if (ret & ~PAGE_MASK)
74591 diff --git a/mm/nommu.c b/mm/nommu.c
74592 index d4b0c10..ed421b5 100644
74593 --- a/mm/nommu.c
74594 +++ b/mm/nommu.c
74595 @@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
74596 int sysctl_overcommit_ratio = 50; /* default is 50% */
74597 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
74598 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
74599 -int heap_stack_gap = 0;
74600
74601 atomic_long_t mmap_pages_allocated;
74602
74603 @@ -827,15 +826,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
74604 EXPORT_SYMBOL(find_vma);
74605
74606 /*
74607 - * find a VMA
74608 - * - we don't extend stack VMAs under NOMMU conditions
74609 - */
74610 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
74611 -{
74612 - return find_vma(mm, addr);
74613 -}
74614 -
74615 -/*
74616 * expand a stack to a given address
74617 * - not supported under NOMMU conditions
74618 */
74619 @@ -1551,6 +1541,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
74620
74621 /* most fields are the same, copy all, and then fixup */
74622 *new = *vma;
74623 + INIT_LIST_HEAD(&new->anon_vma_chain);
74624 *region = *vma->vm_region;
74625 new->vm_region = region;
74626
74627 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
74628 index c13ea75..081ab2c 100644
74629 --- a/mm/page_alloc.c
74630 +++ b/mm/page_alloc.c
74631 @@ -340,7 +340,7 @@ out:
74632 * This usage means that zero-order pages may not be compound.
74633 */
74634
74635 -static void free_compound_page(struct page *page)
74636 +void free_compound_page(struct page *page)
74637 {
74638 __free_pages_ok(page, compound_order(page));
74639 }
74640 @@ -697,6 +697,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
74641 int i;
74642 int bad = 0;
74643
74644 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
74645 + unsigned long index = 1UL << order;
74646 +#endif
74647 +
74648 trace_mm_page_free(page, order);
74649 kmemcheck_free_shadow(page, order);
74650
74651 @@ -712,6 +716,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
74652 debug_check_no_obj_freed(page_address(page),
74653 PAGE_SIZE << order);
74654 }
74655 +
74656 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
74657 + for (; index; --index)
74658 + sanitize_highpage(page + index - 1);
74659 +#endif
74660 +
74661 arch_free_page(page, order);
74662 kernel_map_pages(page, 1 << order, 0);
74663
74664 @@ -853,8 +863,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
74665 arch_alloc_page(page, order);
74666 kernel_map_pages(page, 1 << order, 1);
74667
74668 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
74669 if (gfp_flags & __GFP_ZERO)
74670 prep_zero_page(page, order, gfp_flags);
74671 +#endif
74672
74673 if (order && (gfp_flags & __GFP_COMP))
74674 prep_compound_page(page, order);
74675 @@ -3648,7 +3660,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
74676 unsigned long pfn;
74677
74678 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
74679 +#ifdef CONFIG_X86_32
74680 + /* boot failures in VMware 8 on 32bit vanilla since
74681 + this change */
74682 + if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
74683 +#else
74684 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
74685 +#endif
74686 return 1;
74687 }
74688 return 0;
74689 diff --git a/mm/percpu.c b/mm/percpu.c
74690 index bb4be74..a43ea85 100644
74691 --- a/mm/percpu.c
74692 +++ b/mm/percpu.c
74693 @@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
74694 static unsigned int pcpu_high_unit_cpu __read_mostly;
74695
74696 /* the address of the first chunk which starts with the kernel static area */
74697 -void *pcpu_base_addr __read_mostly;
74698 +void *pcpu_base_addr __read_only;
74699 EXPORT_SYMBOL_GPL(pcpu_base_addr);
74700
74701 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
74702 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
74703 index 926b466..b23df53 100644
74704 --- a/mm/process_vm_access.c
74705 +++ b/mm/process_vm_access.c
74706 @@ -13,6 +13,7 @@
74707 #include <linux/uio.h>
74708 #include <linux/sched.h>
74709 #include <linux/highmem.h>
74710 +#include <linux/security.h>
74711 #include <linux/ptrace.h>
74712 #include <linux/slab.h>
74713 #include <linux/syscalls.h>
74714 @@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
74715 size_t iov_l_curr_offset = 0;
74716 ssize_t iov_len;
74717
74718 + return -ENOSYS; // PaX: until properly audited
74719 +
74720 /*
74721 * Work out how many pages of struct pages we're going to need
74722 * when eventually calling get_user_pages
74723 */
74724 for (i = 0; i < riovcnt; i++) {
74725 iov_len = rvec[i].iov_len;
74726 - if (iov_len > 0) {
74727 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
74728 - + iov_len)
74729 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
74730 - / PAGE_SIZE + 1;
74731 - nr_pages = max(nr_pages, nr_pages_iov);
74732 - }
74733 + if (iov_len <= 0)
74734 + continue;
74735 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
74736 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
74737 + nr_pages = max(nr_pages, nr_pages_iov);
74738 }
74739
74740 if (nr_pages == 0)
74741 @@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
74742 goto free_proc_pages;
74743 }
74744
74745 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
74746 + rc = -EPERM;
74747 + goto put_task_struct;
74748 + }
74749 +
74750 mm = mm_access(task, PTRACE_MODE_ATTACH);
74751 if (!mm || IS_ERR(mm)) {
74752 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
74753 diff --git a/mm/rmap.c b/mm/rmap.c
74754 index aa95e59..b681a63 100644
74755 --- a/mm/rmap.c
74756 +++ b/mm/rmap.c
74757 @@ -168,6 +168,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74758 struct anon_vma *anon_vma = vma->anon_vma;
74759 struct anon_vma_chain *avc;
74760
74761 +#ifdef CONFIG_PAX_SEGMEXEC
74762 + struct anon_vma_chain *avc_m = NULL;
74763 +#endif
74764 +
74765 might_sleep();
74766 if (unlikely(!anon_vma)) {
74767 struct mm_struct *mm = vma->vm_mm;
74768 @@ -177,6 +181,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74769 if (!avc)
74770 goto out_enomem;
74771
74772 +#ifdef CONFIG_PAX_SEGMEXEC
74773 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
74774 + if (!avc_m)
74775 + goto out_enomem_free_avc;
74776 +#endif
74777 +
74778 anon_vma = find_mergeable_anon_vma(vma);
74779 allocated = NULL;
74780 if (!anon_vma) {
74781 @@ -190,6 +200,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74782 /* page_table_lock to protect against threads */
74783 spin_lock(&mm->page_table_lock);
74784 if (likely(!vma->anon_vma)) {
74785 +
74786 +#ifdef CONFIG_PAX_SEGMEXEC
74787 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
74788 +
74789 + if (vma_m) {
74790 + BUG_ON(vma_m->anon_vma);
74791 + vma_m->anon_vma = anon_vma;
74792 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
74793 + avc_m = NULL;
74794 + }
74795 +#endif
74796 +
74797 vma->anon_vma = anon_vma;
74798 anon_vma_chain_link(vma, avc, anon_vma);
74799 allocated = NULL;
74800 @@ -200,12 +222,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74801
74802 if (unlikely(allocated))
74803 put_anon_vma(allocated);
74804 +
74805 +#ifdef CONFIG_PAX_SEGMEXEC
74806 + if (unlikely(avc_m))
74807 + anon_vma_chain_free(avc_m);
74808 +#endif
74809 +
74810 if (unlikely(avc))
74811 anon_vma_chain_free(avc);
74812 }
74813 return 0;
74814
74815 out_enomem_free_avc:
74816 +
74817 +#ifdef CONFIG_PAX_SEGMEXEC
74818 + if (avc_m)
74819 + anon_vma_chain_free(avc_m);
74820 +#endif
74821 +
74822 anon_vma_chain_free(avc);
74823 out_enomem:
74824 return -ENOMEM;
74825 @@ -241,7 +275,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
74826 * Attach the anon_vmas from src to dst.
74827 * Returns 0 on success, -ENOMEM on failure.
74828 */
74829 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
74830 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
74831 {
74832 struct anon_vma_chain *avc, *pavc;
74833 struct anon_vma *root = NULL;
74834 @@ -319,7 +353,7 @@ void anon_vma_moveto_tail(struct vm_area_struct *dst)
74835 * the corresponding VMA in the parent process is attached to.
74836 * Returns 0 on success, non-zero on failure.
74837 */
74838 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
74839 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
74840 {
74841 struct anon_vma_chain *avc;
74842 struct anon_vma *anon_vma;
74843 diff --git a/mm/shmem.c b/mm/shmem.c
74844 index d2eeca1..3f160be 100644
74845 --- a/mm/shmem.c
74846 +++ b/mm/shmem.c
74847 @@ -31,7 +31,7 @@
74848 #include <linux/export.h>
74849 #include <linux/swap.h>
74850
74851 -static struct vfsmount *shm_mnt;
74852 +struct vfsmount *shm_mnt;
74853
74854 #ifdef CONFIG_SHMEM
74855 /*
74856 @@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
74857 #define BOGO_DIRENT_SIZE 20
74858
74859 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
74860 -#define SHORT_SYMLINK_LEN 128
74861 +#define SHORT_SYMLINK_LEN 64
74862
74863 struct shmem_xattr {
74864 struct list_head list; /* anchored by shmem_inode_info->xattr_list */
74865 @@ -2594,8 +2594,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
74866 int err = -ENOMEM;
74867
74868 /* Round up to L1_CACHE_BYTES to resist false sharing */
74869 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
74870 - L1_CACHE_BYTES), GFP_KERNEL);
74871 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
74872 if (!sbinfo)
74873 return -ENOMEM;
74874
74875 diff --git a/mm/slab.c b/mm/slab.c
74876 index d066037..5bb78d9 100644
74877 --- a/mm/slab.c
74878 +++ b/mm/slab.c
74879 @@ -164,7 +164,7 @@ static bool pfmemalloc_active __read_mostly;
74880
74881 /* Legal flag mask for kmem_cache_create(). */
74882 #if DEBUG
74883 -# define CREATE_MASK (SLAB_RED_ZONE | \
74884 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
74885 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
74886 SLAB_CACHE_DMA | \
74887 SLAB_STORE_USER | \
74888 @@ -172,7 +172,7 @@ static bool pfmemalloc_active __read_mostly;
74889 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
74890 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
74891 #else
74892 -# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
74893 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
74894 SLAB_CACHE_DMA | \
74895 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
74896 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
74897 @@ -322,7 +322,7 @@ struct kmem_list3 {
74898 * Need this for bootstrapping a per node allocator.
74899 */
74900 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
74901 -static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
74902 +static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
74903 #define CACHE_CACHE 0
74904 #define SIZE_AC MAX_NUMNODES
74905 #define SIZE_L3 (2 * MAX_NUMNODES)
74906 @@ -423,10 +423,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
74907 if ((x)->max_freeable < i) \
74908 (x)->max_freeable = i; \
74909 } while (0)
74910 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
74911 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
74912 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
74913 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
74914 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
74915 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
74916 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
74917 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
74918 #else
74919 #define STATS_INC_ACTIVE(x) do { } while (0)
74920 #define STATS_DEC_ACTIVE(x) do { } while (0)
74921 @@ -549,7 +549,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
74922 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
74923 */
74924 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
74925 - const struct slab *slab, void *obj)
74926 + const struct slab *slab, const void *obj)
74927 {
74928 u32 offset = (obj - slab->s_mem);
74929 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
74930 @@ -570,12 +570,13 @@ EXPORT_SYMBOL(malloc_sizes);
74931 struct cache_names {
74932 char *name;
74933 char *name_dma;
74934 + char *name_usercopy;
74935 };
74936
74937 static struct cache_names __initdata cache_names[] = {
74938 -#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
74939 +#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
74940 #include <linux/kmalloc_sizes.h>
74941 - {NULL,}
74942 + {NULL}
74943 #undef CACHE
74944 };
74945
74946 @@ -736,6 +737,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
74947 if (unlikely(gfpflags & GFP_DMA))
74948 return csizep->cs_dmacachep;
74949 #endif
74950 +
74951 +#ifdef CONFIG_PAX_USERCOPY_SLABS
74952 + if (unlikely(gfpflags & GFP_USERCOPY))
74953 + return csizep->cs_usercopycachep;
74954 +#endif
74955 +
74956 return csizep->cs_cachep;
74957 }
74958
74959 @@ -1684,7 +1691,7 @@ void __init kmem_cache_init(void)
74960 sizes[INDEX_AC].cs_cachep = __kmem_cache_create(names[INDEX_AC].name,
74961 sizes[INDEX_AC].cs_size,
74962 ARCH_KMALLOC_MINALIGN,
74963 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74964 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74965 NULL);
74966
74967 if (INDEX_AC != INDEX_L3) {
74968 @@ -1692,7 +1699,7 @@ void __init kmem_cache_init(void)
74969 __kmem_cache_create(names[INDEX_L3].name,
74970 sizes[INDEX_L3].cs_size,
74971 ARCH_KMALLOC_MINALIGN,
74972 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74973 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74974 NULL);
74975 }
74976
74977 @@ -1710,7 +1717,7 @@ void __init kmem_cache_init(void)
74978 sizes->cs_cachep = __kmem_cache_create(names->name,
74979 sizes->cs_size,
74980 ARCH_KMALLOC_MINALIGN,
74981 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74982 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74983 NULL);
74984 }
74985 #ifdef CONFIG_ZONE_DMA
74986 @@ -1722,6 +1729,16 @@ void __init kmem_cache_init(void)
74987 SLAB_PANIC,
74988 NULL);
74989 #endif
74990 +
74991 +#ifdef CONFIG_PAX_USERCOPY_SLABS
74992 + sizes->cs_usercopycachep = kmem_cache_create(
74993 + names->name_usercopy,
74994 + sizes->cs_size,
74995 + ARCH_KMALLOC_MINALIGN,
74996 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74997 + NULL);
74998 +#endif
74999 +
75000 sizes++;
75001 names++;
75002 }
75003 @@ -4467,10 +4484,10 @@ static int s_show(struct seq_file *m, void *p)
75004 }
75005 /* cpu stats */
75006 {
75007 - unsigned long allochit = atomic_read(&cachep->allochit);
75008 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
75009 - unsigned long freehit = atomic_read(&cachep->freehit);
75010 - unsigned long freemiss = atomic_read(&cachep->freemiss);
75011 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
75012 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
75013 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
75014 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
75015
75016 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
75017 allochit, allocmiss, freehit, freemiss);
75018 @@ -4729,13 +4746,71 @@ static int __init slab_proc_init(void)
75019 {
75020 proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);
75021 #ifdef CONFIG_DEBUG_SLAB_LEAK
75022 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
75023 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
75024 #endif
75025 return 0;
75026 }
75027 module_init(slab_proc_init);
75028 #endif
75029
75030 +bool is_usercopy_object(const void *ptr)
75031 +{
75032 + struct page *page;
75033 + struct kmem_cache *cachep;
75034 +
75035 + if (ZERO_OR_NULL_PTR(ptr))
75036 + return false;
75037 +
75038 + if (!slab_is_available())
75039 + return false;
75040 +
75041 + if (!virt_addr_valid(ptr))
75042 + return false;
75043 +
75044 + page = virt_to_head_page(ptr);
75045 +
75046 + if (!PageSlab(page))
75047 + return false;
75048 +
75049 + cachep = page_get_cache(page);
75050 + return cachep->flags & SLAB_USERCOPY;
75051 +}
75052 +
75053 +#ifdef CONFIG_PAX_USERCOPY
75054 +const char *check_heap_object(const void *ptr, unsigned long n, bool to)
75055 +{
75056 + struct page *page;
75057 + struct kmem_cache *cachep;
75058 + struct slab *slabp;
75059 + unsigned int objnr;
75060 + unsigned long offset;
75061 +
75062 + if (ZERO_OR_NULL_PTR(ptr))
75063 + return "<null>";
75064 +
75065 + if (!virt_addr_valid(ptr))
75066 + return NULL;
75067 +
75068 + page = virt_to_head_page(ptr);
75069 +
75070 + if (!PageSlab(page))
75071 + return NULL;
75072 +
75073 + cachep = page_get_cache(page);
75074 + if (!(cachep->flags & SLAB_USERCOPY))
75075 + return cachep->name;
75076 +
75077 + slabp = page->slab_page;
75078 + objnr = obj_to_index(cachep, slabp, ptr);
75079 + BUG_ON(objnr >= cachep->num);
75080 + offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
75081 + if (offset <= cachep->object_size && n <= cachep->object_size - offset)
75082 + return NULL;
75083 +
75084 + return cachep->name;
75085 +}
75086 +#endif
75087 +
75088 /**
75089 * ksize - get the actual amount of memory allocated for a given object
75090 * @objp: Pointer to the object
75091 diff --git a/mm/slob.c b/mm/slob.c
75092 index 45d4ca7..88943c1 100644
75093 --- a/mm/slob.c
75094 +++ b/mm/slob.c
75095 @@ -159,7 +159,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
75096 /*
75097 * Return the size of a slob block.
75098 */
75099 -static slobidx_t slob_units(slob_t *s)
75100 +static slobidx_t slob_units(const slob_t *s)
75101 {
75102 if (s->units > 0)
75103 return s->units;
75104 @@ -169,7 +169,7 @@ static slobidx_t slob_units(slob_t *s)
75105 /*
75106 * Return the next free slob block pointer after this one.
75107 */
75108 -static slob_t *slob_next(slob_t *s)
75109 +static slob_t *slob_next(const slob_t *s)
75110 {
75111 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
75112 slobidx_t next;
75113 @@ -184,14 +184,14 @@ static slob_t *slob_next(slob_t *s)
75114 /*
75115 * Returns true if s is the last free block in its page.
75116 */
75117 -static int slob_last(slob_t *s)
75118 +static int slob_last(const slob_t *s)
75119 {
75120 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
75121 }
75122
75123 -static void *slob_new_pages(gfp_t gfp, int order, int node)
75124 +static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
75125 {
75126 - void *page;
75127 + struct page *page;
75128
75129 #ifdef CONFIG_NUMA
75130 if (node != -1)
75131 @@ -203,14 +203,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
75132 if (!page)
75133 return NULL;
75134
75135 - return page_address(page);
75136 + __SetPageSlab(page);
75137 + return page;
75138 }
75139
75140 -static void slob_free_pages(void *b, int order)
75141 +static void slob_free_pages(struct page *sp, int order)
75142 {
75143 if (current->reclaim_state)
75144 current->reclaim_state->reclaimed_slab += 1 << order;
75145 - free_pages((unsigned long)b, order);
75146 + __ClearPageSlab(sp);
75147 + reset_page_mapcount(sp);
75148 + sp->private = 0;
75149 + __free_pages(sp, order);
75150 }
75151
75152 /*
75153 @@ -315,15 +319,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
75154
75155 /* Not enough space: must allocate a new page */
75156 if (!b) {
75157 - b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
75158 - if (!b)
75159 + sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
75160 + if (!sp)
75161 return NULL;
75162 - sp = virt_to_page(b);
75163 - __SetPageSlab(sp);
75164 + b = page_address(sp);
75165
75166 spin_lock_irqsave(&slob_lock, flags);
75167 sp->units = SLOB_UNITS(PAGE_SIZE);
75168 sp->freelist = b;
75169 + sp->private = 0;
75170 INIT_LIST_HEAD(&sp->list);
75171 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
75172 set_slob_page_free(sp, slob_list);
75173 @@ -361,9 +365,7 @@ static void slob_free(void *block, int size)
75174 if (slob_page_free(sp))
75175 clear_slob_page_free(sp);
75176 spin_unlock_irqrestore(&slob_lock, flags);
75177 - __ClearPageSlab(sp);
75178 - reset_page_mapcount(sp);
75179 - slob_free_pages(b, 0);
75180 + slob_free_pages(sp, 0);
75181 return;
75182 }
75183
75184 @@ -425,11 +427,10 @@ out:
75185 * End of slob allocator proper. Begin kmem_cache_alloc and kmalloc frontend.
75186 */
75187
75188 -void *__kmalloc_node(size_t size, gfp_t gfp, int node)
75189 +static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
75190 {
75191 - unsigned int *m;
75192 - int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
75193 - void *ret;
75194 + slob_t *m;
75195 + void *ret = NULL;
75196
75197 gfp &= gfp_allowed_mask;
75198
75199 @@ -443,20 +444,23 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
75200
75201 if (!m)
75202 return NULL;
75203 - *m = size;
75204 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
75205 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
75206 + m[0].units = size;
75207 + m[1].units = align;
75208 ret = (void *)m + align;
75209
75210 trace_kmalloc_node(_RET_IP_, ret,
75211 size, size + align, gfp, node);
75212 } else {
75213 unsigned int order = get_order(size);
75214 + struct page *page;
75215
75216 if (likely(order))
75217 gfp |= __GFP_COMP;
75218 - ret = slob_new_pages(gfp, order, node);
75219 - if (ret) {
75220 - struct page *page;
75221 - page = virt_to_page(ret);
75222 + page = slob_new_pages(gfp, order, node);
75223 + if (page) {
75224 + ret = page_address(page);
75225 page->private = size;
75226 }
75227
75228 @@ -464,7 +468,16 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
75229 size, PAGE_SIZE << order, gfp, node);
75230 }
75231
75232 - kmemleak_alloc(ret, size, 1, gfp);
75233 + return ret;
75234 +}
75235 +
75236 +void *__kmalloc_node(size_t size, gfp_t gfp, int node)
75237 +{
75238 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
75239 + void *ret = __kmalloc_node_align(size, gfp, node, align);
75240 +
75241 + if (!ZERO_OR_NULL_PTR(ret))
75242 + kmemleak_alloc(ret, size, 1, gfp);
75243 return ret;
75244 }
75245 EXPORT_SYMBOL(__kmalloc_node);
75246 @@ -480,15 +493,91 @@ void kfree(const void *block)
75247 kmemleak_free(block);
75248
75249 sp = virt_to_page(block);
75250 - if (PageSlab(sp)) {
75251 + VM_BUG_ON(!PageSlab(sp));
75252 + if (!sp->private) {
75253 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
75254 - unsigned int *m = (unsigned int *)(block - align);
75255 - slob_free(m, *m + align);
75256 - } else
75257 + slob_t *m = (slob_t *)(block - align);
75258 + slob_free(m, m[0].units + align);
75259 + } else {
75260 + __ClearPageSlab(sp);
75261 + reset_page_mapcount(sp);
75262 + sp->private = 0;
75263 put_page(sp);
75264 + }
75265 }
75266 EXPORT_SYMBOL(kfree);
75267
75268 +bool is_usercopy_object(const void *ptr)
75269 +{
75270 + if (!slab_is_available())
75271 + return false;
75272 +
75273 + // PAX: TODO
75274 +
75275 + return false;
75276 +}
75277 +
75278 +#ifdef CONFIG_PAX_USERCOPY
75279 +const char *check_heap_object(const void *ptr, unsigned long n, bool to)
75280 +{
75281 + struct page *page;
75282 + const slob_t *free;
75283 + const void *base;
75284 + unsigned long flags;
75285 +
75286 + if (ZERO_OR_NULL_PTR(ptr))
75287 + return "<null>";
75288 +
75289 + if (!virt_addr_valid(ptr))
75290 + return NULL;
75291 +
75292 + page = virt_to_head_page(ptr);
75293 + if (!PageSlab(page))
75294 + return NULL;
75295 +
75296 + if (page->private) {
75297 + base = page;
75298 + if (base <= ptr && n <= page->private - (ptr - base))
75299 + return NULL;
75300 + return "<slob>";
75301 + }
75302 +
75303 + /* some tricky double walking to find the chunk */
75304 + spin_lock_irqsave(&slob_lock, flags);
75305 + base = (void *)((unsigned long)ptr & PAGE_MASK);
75306 + free = page->freelist;
75307 +
75308 + while (!slob_last(free) && (void *)free <= ptr) {
75309 + base = free + slob_units(free);
75310 + free = slob_next(free);
75311 + }
75312 +
75313 + while (base < (void *)free) {
75314 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
75315 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
75316 + int offset;
75317 +
75318 + if (ptr < base + align)
75319 + break;
75320 +
75321 + offset = ptr - base - align;
75322 + if (offset >= m) {
75323 + base += size;
75324 + continue;
75325 + }
75326 +
75327 + if (n > m - offset)
75328 + break;
75329 +
75330 + spin_unlock_irqrestore(&slob_lock, flags);
75331 + return NULL;
75332 + }
75333 +
75334 + spin_unlock_irqrestore(&slob_lock, flags);
75335 + return "<slob>";
75336 +}
75337 +#endif
75338 +
75339 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
75340 size_t ksize(const void *block)
75341 {
75342 @@ -499,10 +588,11 @@ size_t ksize(const void *block)
75343 return 0;
75344
75345 sp = virt_to_page(block);
75346 - if (PageSlab(sp)) {
75347 + VM_BUG_ON(!PageSlab(sp));
75348 + if (!sp->private) {
75349 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
75350 - unsigned int *m = (unsigned int *)(block - align);
75351 - return SLOB_UNITS(*m) * SLOB_UNIT;
75352 + slob_t *m = (slob_t *)(block - align);
75353 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
75354 } else
75355 return sp->private;
75356 }
75357 @@ -513,8 +603,13 @@ struct kmem_cache *__kmem_cache_create(const char *name, size_t size,
75358 {
75359 struct kmem_cache *c;
75360
75361 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75362 + c = __kmalloc_node_align(sizeof(struct kmem_cache),
75363 + GFP_KERNEL, -1, ARCH_KMALLOC_MINALIGN);
75364 +#else
75365 c = slob_alloc(sizeof(struct kmem_cache),
75366 GFP_KERNEL, ARCH_KMALLOC_MINALIGN, -1);
75367 +#endif
75368
75369 if (c) {
75370 c->name = name;
75371 @@ -549,23 +644,33 @@ EXPORT_SYMBOL(kmem_cache_destroy);
75372
75373 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
75374 {
75375 - void *b;
75376 + void *b = NULL;
75377
75378 flags &= gfp_allowed_mask;
75379
75380 lockdep_trace_alloc(flags);
75381
75382 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75383 + b = __kmalloc_node_align(c->size, flags, node, c->align);
75384 +#else
75385 if (c->size < PAGE_SIZE) {
75386 b = slob_alloc(c->size, flags, c->align, node);
75387 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
75388 SLOB_UNITS(c->size) * SLOB_UNIT,
75389 flags, node);
75390 } else {
75391 - b = slob_new_pages(flags, get_order(c->size), node);
75392 + struct page *sp;
75393 +
75394 + sp = slob_new_pages(flags, get_order(c->size), node);
75395 + if (sp) {
75396 + b = page_address(sp);
75397 + sp->private = c->size;
75398 + }
75399 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
75400 PAGE_SIZE << get_order(c->size),
75401 flags, node);
75402 }
75403 +#endif
75404
75405 if (c->ctor)
75406 c->ctor(b);
75407 @@ -577,10 +682,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
75408
75409 static void __kmem_cache_free(void *b, int size)
75410 {
75411 - if (size < PAGE_SIZE)
75412 + struct page *sp;
75413 +
75414 + sp = virt_to_page(b);
75415 + BUG_ON(!PageSlab(sp));
75416 + if (!sp->private)
75417 slob_free(b, size);
75418 else
75419 - slob_free_pages(b, get_order(size));
75420 + slob_free_pages(sp, get_order(size));
75421 }
75422
75423 static void kmem_rcu_free(struct rcu_head *head)
75424 @@ -593,17 +702,31 @@ static void kmem_rcu_free(struct rcu_head *head)
75425
75426 void kmem_cache_free(struct kmem_cache *c, void *b)
75427 {
75428 + int size = c->size;
75429 +
75430 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75431 + if (size + c->align < PAGE_SIZE) {
75432 + size += c->align;
75433 + b -= c->align;
75434 + }
75435 +#endif
75436 +
75437 kmemleak_free_recursive(b, c->flags);
75438 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
75439 struct slob_rcu *slob_rcu;
75440 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
75441 - slob_rcu->size = c->size;
75442 + slob_rcu = b + (size - sizeof(struct slob_rcu));
75443 + slob_rcu->size = size;
75444 call_rcu(&slob_rcu->head, kmem_rcu_free);
75445 } else {
75446 - __kmem_cache_free(b, c->size);
75447 + __kmem_cache_free(b, size);
75448 }
75449
75450 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75451 + trace_kfree(_RET_IP_, b);
75452 +#else
75453 trace_kmem_cache_free(_RET_IP_, b);
75454 +#endif
75455 +
75456 }
75457 EXPORT_SYMBOL(kmem_cache_free);
75458
75459 diff --git a/mm/slub.c b/mm/slub.c
75460 index 2fdd96f..1e2f893 100644
75461 --- a/mm/slub.c
75462 +++ b/mm/slub.c
75463 @@ -201,7 +201,7 @@ struct track {
75464
75465 enum track_item { TRACK_ALLOC, TRACK_FREE };
75466
75467 -#ifdef CONFIG_SYSFS
75468 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75469 static int sysfs_slab_add(struct kmem_cache *);
75470 static int sysfs_slab_alias(struct kmem_cache *, const char *);
75471 static void sysfs_slab_remove(struct kmem_cache *);
75472 @@ -525,7 +525,7 @@ static void print_track(const char *s, struct track *t)
75473 if (!t->addr)
75474 return;
75475
75476 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
75477 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
75478 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
75479 #ifdef CONFIG_STACKTRACE
75480 {
75481 @@ -2612,6 +2612,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
75482
75483 page = virt_to_head_page(x);
75484
75485 + BUG_ON(!PageSlab(page));
75486 +
75487 slab_free(s, page, x, _RET_IP_);
75488
75489 trace_kmem_cache_free(_RET_IP_, x);
75490 @@ -2645,7 +2647,7 @@ static int slub_min_objects;
75491 * Merge control. If this is set then no merging of slab caches will occur.
75492 * (Could be removed. This was introduced to pacify the merge skeptics.)
75493 */
75494 -static int slub_nomerge;
75495 +static int slub_nomerge = 1;
75496
75497 /*
75498 * Calculate the order of allocation given an slab object size.
75499 @@ -3098,7 +3100,7 @@ static int kmem_cache_open(struct kmem_cache *s,
75500 else
75501 s->cpu_partial = 30;
75502
75503 - s->refcount = 1;
75504 + atomic_set(&s->refcount, 1);
75505 #ifdef CONFIG_NUMA
75506 s->remote_node_defrag_ratio = 1000;
75507 #endif
75508 @@ -3202,8 +3204,7 @@ static inline int kmem_cache_close(struct kmem_cache *s)
75509 void kmem_cache_destroy(struct kmem_cache *s)
75510 {
75511 mutex_lock(&slab_mutex);
75512 - s->refcount--;
75513 - if (!s->refcount) {
75514 + if (atomic_dec_and_test(&s->refcount)) {
75515 list_del(&s->list);
75516 mutex_unlock(&slab_mutex);
75517 if (kmem_cache_close(s)) {
75518 @@ -3232,6 +3233,10 @@ static struct kmem_cache *kmem_cache;
75519 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
75520 #endif
75521
75522 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75523 +static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
75524 +#endif
75525 +
75526 static int __init setup_slub_min_order(char *str)
75527 {
75528 get_option(&str, &slub_min_order);
75529 @@ -3346,6 +3351,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
75530 return kmalloc_dma_caches[index];
75531
75532 #endif
75533 +
75534 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75535 + if (flags & SLAB_USERCOPY)
75536 + return kmalloc_usercopy_caches[index];
75537 +
75538 +#endif
75539 +
75540 return kmalloc_caches[index];
75541 }
75542
75543 @@ -3414,6 +3426,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
75544 EXPORT_SYMBOL(__kmalloc_node);
75545 #endif
75546
75547 +bool is_usercopy_object(const void *ptr)
75548 +{
75549 + struct page *page;
75550 + struct kmem_cache *s;
75551 +
75552 + if (ZERO_OR_NULL_PTR(ptr))
75553 + return false;
75554 +
75555 + if (!slab_is_available())
75556 + return false;
75557 +
75558 + if (!virt_addr_valid(ptr))
75559 + return false;
75560 +
75561 + page = virt_to_head_page(ptr);
75562 +
75563 + if (!PageSlab(page))
75564 + return false;
75565 +
75566 + s = page->slab;
75567 + return s->flags & SLAB_USERCOPY;
75568 +}
75569 +
75570 +#ifdef CONFIG_PAX_USERCOPY
75571 +const char *check_heap_object(const void *ptr, unsigned long n, bool to)
75572 +{
75573 + struct page *page;
75574 + struct kmem_cache *s;
75575 + unsigned long offset;
75576 +
75577 + if (ZERO_OR_NULL_PTR(ptr))
75578 + return "<null>";
75579 +
75580 + if (!virt_addr_valid(ptr))
75581 + return NULL;
75582 +
75583 + page = virt_to_head_page(ptr);
75584 +
75585 + if (!PageSlab(page))
75586 + return NULL;
75587 +
75588 + s = page->slab;
75589 + if (!(s->flags & SLAB_USERCOPY))
75590 + return s->name;
75591 +
75592 + offset = (ptr - page_address(page)) % s->size;
75593 + if (offset <= s->object_size && n <= s->object_size - offset)
75594 + return NULL;
75595 +
75596 + return s->name;
75597 +}
75598 +#endif
75599 +
75600 size_t ksize(const void *object)
75601 {
75602 struct page *page;
75603 @@ -3688,7 +3753,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
75604 int node;
75605
75606 list_add(&s->list, &slab_caches);
75607 - s->refcount = -1;
75608 + atomic_set(&s->refcount, -1);
75609
75610 for_each_node_state(node, N_NORMAL_MEMORY) {
75611 struct kmem_cache_node *n = get_node(s, node);
75612 @@ -3808,17 +3873,17 @@ void __init kmem_cache_init(void)
75613
75614 /* Caches that are not of the two-to-the-power-of size */
75615 if (KMALLOC_MIN_SIZE <= 32) {
75616 - kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
75617 + kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
75618 caches++;
75619 }
75620
75621 if (KMALLOC_MIN_SIZE <= 64) {
75622 - kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
75623 + kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
75624 caches++;
75625 }
75626
75627 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
75628 - kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
75629 + kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
75630 caches++;
75631 }
75632
75633 @@ -3860,6 +3925,22 @@ void __init kmem_cache_init(void)
75634 }
75635 }
75636 #endif
75637 +
75638 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75639 + for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
75640 + struct kmem_cache *s = kmalloc_caches[i];
75641 +
75642 + if (s && s->size) {
75643 + char *name = kasprintf(GFP_NOWAIT,
75644 + "usercopy-kmalloc-%d", s->object_size);
75645 +
75646 + BUG_ON(!name);
75647 + kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
75648 + s->object_size, SLAB_USERCOPY);
75649 + }
75650 + }
75651 +#endif
75652 +
75653 printk(KERN_INFO
75654 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
75655 " CPUs=%d, Nodes=%d\n",
75656 @@ -3886,7 +3967,7 @@ static int slab_unmergeable(struct kmem_cache *s)
75657 /*
75658 * We may have set a slab to be unmergeable during bootstrap.
75659 */
75660 - if (s->refcount < 0)
75661 + if (atomic_read(&s->refcount) < 0)
75662 return 1;
75663
75664 return 0;
75665 @@ -3941,7 +4022,7 @@ struct kmem_cache *__kmem_cache_create(const char *name, size_t size,
75666
75667 s = find_mergeable(size, align, flags, name, ctor);
75668 if (s) {
75669 - s->refcount++;
75670 + atomic_inc(&s->refcount);
75671 /*
75672 * Adjust the object sizes so that we clear
75673 * the complete object on kzalloc.
75674 @@ -3950,7 +4031,7 @@ struct kmem_cache *__kmem_cache_create(const char *name, size_t size,
75675 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
75676
75677 if (sysfs_slab_alias(s, name)) {
75678 - s->refcount--;
75679 + atomic_dec(&s->refcount);
75680 return NULL;
75681 }
75682 return s;
75683 @@ -4072,7 +4153,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
75684 }
75685 #endif
75686
75687 -#ifdef CONFIG_SYSFS
75688 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75689 static int count_inuse(struct page *page)
75690 {
75691 return page->inuse;
75692 @@ -4459,12 +4540,12 @@ static void resiliency_test(void)
75693 validate_slab_cache(kmalloc_caches[9]);
75694 }
75695 #else
75696 -#ifdef CONFIG_SYSFS
75697 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75698 static void resiliency_test(void) {};
75699 #endif
75700 #endif
75701
75702 -#ifdef CONFIG_SYSFS
75703 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75704 enum slab_stat_type {
75705 SL_ALL, /* All slabs */
75706 SL_PARTIAL, /* Only partially allocated slabs */
75707 @@ -4708,7 +4789,7 @@ SLAB_ATTR_RO(ctor);
75708
75709 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
75710 {
75711 - return sprintf(buf, "%d\n", s->refcount - 1);
75712 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
75713 }
75714 SLAB_ATTR_RO(aliases);
75715
75716 @@ -5279,6 +5360,7 @@ static char *create_unique_id(struct kmem_cache *s)
75717 return name;
75718 }
75719
75720 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75721 static int sysfs_slab_add(struct kmem_cache *s)
75722 {
75723 int err;
75724 @@ -5341,6 +5423,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
75725 kobject_del(&s->kobj);
75726 kobject_put(&s->kobj);
75727 }
75728 +#endif
75729
75730 /*
75731 * Need to buffer aliases during bootup until sysfs becomes
75732 @@ -5354,6 +5437,7 @@ struct saved_alias {
75733
75734 static struct saved_alias *alias_list;
75735
75736 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75737 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
75738 {
75739 struct saved_alias *al;
75740 @@ -5376,6 +5460,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
75741 alias_list = al;
75742 return 0;
75743 }
75744 +#endif
75745
75746 static int __init slab_sysfs_init(void)
75747 {
75748 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
75749 index 1b7e22a..3fcd4f3 100644
75750 --- a/mm/sparse-vmemmap.c
75751 +++ b/mm/sparse-vmemmap.c
75752 @@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
75753 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
75754 if (!p)
75755 return NULL;
75756 - pud_populate(&init_mm, pud, p);
75757 + pud_populate_kernel(&init_mm, pud, p);
75758 }
75759 return pud;
75760 }
75761 @@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
75762 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
75763 if (!p)
75764 return NULL;
75765 - pgd_populate(&init_mm, pgd, p);
75766 + pgd_populate_kernel(&init_mm, pgd, p);
75767 }
75768 return pgd;
75769 }
75770 diff --git a/mm/swap.c b/mm/swap.c
75771 index 7782588..228c784 100644
75772 --- a/mm/swap.c
75773 +++ b/mm/swap.c
75774 @@ -30,6 +30,7 @@
75775 #include <linux/backing-dev.h>
75776 #include <linux/memcontrol.h>
75777 #include <linux/gfp.h>
75778 +#include <linux/hugetlb.h>
75779
75780 #include "internal.h"
75781
75782 @@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
75783
75784 __page_cache_release(page);
75785 dtor = get_compound_page_dtor(page);
75786 + if (!PageHuge(page))
75787 + BUG_ON(dtor != free_compound_page);
75788 (*dtor)(page);
75789 }
75790
75791 diff --git a/mm/swapfile.c b/mm/swapfile.c
75792 index 14e254c..a6af32c 100644
75793 --- a/mm/swapfile.c
75794 +++ b/mm/swapfile.c
75795 @@ -64,7 +64,7 @@ static DEFINE_MUTEX(swapon_mutex);
75796
75797 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
75798 /* Activity counter to indicate that a swapon or swapoff has occurred */
75799 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
75800 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
75801
75802 static inline unsigned char swap_count(unsigned char ent)
75803 {
75804 @@ -1603,7 +1603,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
75805 }
75806 filp_close(swap_file, NULL);
75807 err = 0;
75808 - atomic_inc(&proc_poll_event);
75809 + atomic_inc_unchecked(&proc_poll_event);
75810 wake_up_interruptible(&proc_poll_wait);
75811
75812 out_dput:
75813 @@ -1619,8 +1619,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
75814
75815 poll_wait(file, &proc_poll_wait, wait);
75816
75817 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
75818 - seq->poll_event = atomic_read(&proc_poll_event);
75819 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
75820 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
75821 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
75822 }
75823
75824 @@ -1718,7 +1718,7 @@ static int swaps_open(struct inode *inode, struct file *file)
75825 return ret;
75826
75827 seq = file->private_data;
75828 - seq->poll_event = atomic_read(&proc_poll_event);
75829 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
75830 return 0;
75831 }
75832
75833 @@ -2060,7 +2060,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
75834 (frontswap_map) ? "FS" : "");
75835
75836 mutex_unlock(&swapon_mutex);
75837 - atomic_inc(&proc_poll_event);
75838 + atomic_inc_unchecked(&proc_poll_event);
75839 wake_up_interruptible(&proc_poll_wait);
75840
75841 if (S_ISREG(inode->i_mode))
75842 diff --git a/mm/util.c b/mm/util.c
75843 index 8c7265a..c96d884 100644
75844 --- a/mm/util.c
75845 +++ b/mm/util.c
75846 @@ -285,6 +285,12 @@ done:
75847 void arch_pick_mmap_layout(struct mm_struct *mm)
75848 {
75849 mm->mmap_base = TASK_UNMAPPED_BASE;
75850 +
75851 +#ifdef CONFIG_PAX_RANDMMAP
75852 + if (mm->pax_flags & MF_PAX_RANDMMAP)
75853 + mm->mmap_base += mm->delta_mmap;
75854 +#endif
75855 +
75856 mm->get_unmapped_area = arch_get_unmapped_area;
75857 mm->unmap_area = arch_unmap_area;
75858 }
75859 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
75860 index 2bb90b1..ed47e53 100644
75861 --- a/mm/vmalloc.c
75862 +++ b/mm/vmalloc.c
75863 @@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
75864
75865 pte = pte_offset_kernel(pmd, addr);
75866 do {
75867 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
75868 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
75869 +
75870 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75871 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
75872 + BUG_ON(!pte_exec(*pte));
75873 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
75874 + continue;
75875 + }
75876 +#endif
75877 +
75878 + {
75879 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
75880 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
75881 + }
75882 } while (pte++, addr += PAGE_SIZE, addr != end);
75883 }
75884
75885 @@ -91,6 +102,7 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
75886 unsigned long end, pgprot_t prot, struct page **pages, int *nr)
75887 {
75888 pte_t *pte;
75889 + int ret = -ENOMEM;
75890
75891 /*
75892 * nr is a running index into the array which helps higher level
75893 @@ -100,17 +112,30 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
75894 pte = pte_alloc_kernel(pmd, addr);
75895 if (!pte)
75896 return -ENOMEM;
75897 +
75898 + pax_open_kernel();
75899 do {
75900 struct page *page = pages[*nr];
75901
75902 - if (WARN_ON(!pte_none(*pte)))
75903 - return -EBUSY;
75904 - if (WARN_ON(!page))
75905 - return -ENOMEM;
75906 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75907 + if (pgprot_val(prot) & _PAGE_NX)
75908 +#endif
75909 +
75910 + if (WARN_ON(!pte_none(*pte))) {
75911 + ret = -EBUSY;
75912 + goto out;
75913 + }
75914 + if (WARN_ON(!page)) {
75915 + ret = -ENOMEM;
75916 + goto out;
75917 + }
75918 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
75919 (*nr)++;
75920 } while (pte++, addr += PAGE_SIZE, addr != end);
75921 - return 0;
75922 + ret = 0;
75923 +out:
75924 + pax_close_kernel();
75925 + return ret;
75926 }
75927
75928 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
75929 @@ -119,7 +144,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
75930 pmd_t *pmd;
75931 unsigned long next;
75932
75933 - pmd = pmd_alloc(&init_mm, pud, addr);
75934 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
75935 if (!pmd)
75936 return -ENOMEM;
75937 do {
75938 @@ -136,7 +161,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
75939 pud_t *pud;
75940 unsigned long next;
75941
75942 - pud = pud_alloc(&init_mm, pgd, addr);
75943 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
75944 if (!pud)
75945 return -ENOMEM;
75946 do {
75947 @@ -191,11 +216,20 @@ int is_vmalloc_or_module_addr(const void *x)
75948 * and fall back on vmalloc() if that fails. Others
75949 * just put it in the vmalloc space.
75950 */
75951 -#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
75952 +#ifdef CONFIG_MODULES
75953 +#ifdef MODULES_VADDR
75954 unsigned long addr = (unsigned long)x;
75955 if (addr >= MODULES_VADDR && addr < MODULES_END)
75956 return 1;
75957 #endif
75958 +
75959 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75960 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
75961 + return 1;
75962 +#endif
75963 +
75964 +#endif
75965 +
75966 return is_vmalloc_addr(x);
75967 }
75968
75969 @@ -216,8 +250,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
75970
75971 if (!pgd_none(*pgd)) {
75972 pud_t *pud = pud_offset(pgd, addr);
75973 +#ifdef CONFIG_X86
75974 + if (!pud_large(*pud))
75975 +#endif
75976 if (!pud_none(*pud)) {
75977 pmd_t *pmd = pmd_offset(pud, addr);
75978 +#ifdef CONFIG_X86
75979 + if (!pmd_large(*pmd))
75980 +#endif
75981 if (!pmd_none(*pmd)) {
75982 pte_t *ptep, pte;
75983
75984 @@ -329,7 +369,7 @@ static void purge_vmap_area_lazy(void);
75985 * Allocate a region of KVA of the specified size and alignment, within the
75986 * vstart and vend.
75987 */
75988 -static struct vmap_area *alloc_vmap_area(unsigned long size,
75989 +static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
75990 unsigned long align,
75991 unsigned long vstart, unsigned long vend,
75992 int node, gfp_t gfp_mask)
75993 @@ -1328,6 +1368,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
75994 struct vm_struct *area;
75995
75996 BUG_ON(in_interrupt());
75997 +
75998 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75999 + if (flags & VM_KERNEXEC) {
76000 + if (start != VMALLOC_START || end != VMALLOC_END)
76001 + return NULL;
76002 + start = (unsigned long)MODULES_EXEC_VADDR;
76003 + end = (unsigned long)MODULES_EXEC_END;
76004 + }
76005 +#endif
76006 +
76007 if (flags & VM_IOREMAP) {
76008 int bit = fls(size);
76009
76010 @@ -1568,6 +1618,11 @@ void *vmap(struct page **pages, unsigned int count,
76011 if (count > totalram_pages)
76012 return NULL;
76013
76014 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
76015 + if (!(pgprot_val(prot) & _PAGE_NX))
76016 + flags |= VM_KERNEXEC;
76017 +#endif
76018 +
76019 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
76020 __builtin_return_address(0));
76021 if (!area)
76022 @@ -1669,6 +1724,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
76023 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
76024 goto fail;
76025
76026 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
76027 + if (!(pgprot_val(prot) & _PAGE_NX))
76028 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
76029 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
76030 + else
76031 +#endif
76032 +
76033 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
76034 start, end, node, gfp_mask, caller);
76035 if (!area)
76036 @@ -1842,10 +1904,9 @@ EXPORT_SYMBOL(vzalloc_node);
76037 * For tight control over page level allocator and protection flags
76038 * use __vmalloc() instead.
76039 */
76040 -
76041 void *vmalloc_exec(unsigned long size)
76042 {
76043 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
76044 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
76045 -1, __builtin_return_address(0));
76046 }
76047
76048 @@ -2136,6 +2197,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
76049 unsigned long uaddr = vma->vm_start;
76050 unsigned long usize = vma->vm_end - vma->vm_start;
76051
76052 + BUG_ON(vma->vm_mirror);
76053 +
76054 if ((PAGE_SIZE-1) & (unsigned long)addr)
76055 return -EINVAL;
76056
76057 @@ -2572,7 +2635,7 @@ static int s_show(struct seq_file *m, void *p)
76058 {
76059 struct vm_struct *v = p;
76060
76061 - seq_printf(m, "0x%p-0x%p %7ld",
76062 + seq_printf(m, "0x%pK-0x%pK %7ld",
76063 v->addr, v->addr + v->size, v->size);
76064
76065 if (v->caller)
76066 diff --git a/mm/vmscan.c b/mm/vmscan.c
76067 index 99b434b..a018dfc 100644
76068 --- a/mm/vmscan.c
76069 +++ b/mm/vmscan.c
76070 @@ -2953,6 +2953,8 @@ static int kswapd(void *p)
76071 &balanced_classzone_idx);
76072 }
76073 }
76074 +
76075 + current->reclaim_state = NULL;
76076 return 0;
76077 }
76078
76079 diff --git a/mm/vmstat.c b/mm/vmstat.c
76080 index df7a674..8b4a4f3 100644
76081 --- a/mm/vmstat.c
76082 +++ b/mm/vmstat.c
76083 @@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
76084 *
76085 * vm_stat contains the global counters
76086 */
76087 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
76088 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
76089 EXPORT_SYMBOL(vm_stat);
76090
76091 #ifdef CONFIG_SMP
76092 @@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
76093 v = p->vm_stat_diff[i];
76094 p->vm_stat_diff[i] = 0;
76095 local_irq_restore(flags);
76096 - atomic_long_add(v, &zone->vm_stat[i]);
76097 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
76098 global_diff[i] += v;
76099 #ifdef CONFIG_NUMA
76100 /* 3 seconds idle till flush */
76101 @@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
76102
76103 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
76104 if (global_diff[i])
76105 - atomic_long_add(global_diff[i], &vm_stat[i]);
76106 + atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
76107 }
76108
76109 #endif
76110 @@ -1212,10 +1212,20 @@ static int __init setup_vmstat(void)
76111 start_cpu_timer(cpu);
76112 #endif
76113 #ifdef CONFIG_PROC_FS
76114 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
76115 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
76116 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
76117 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
76118 + {
76119 + mode_t gr_mode = S_IRUGO;
76120 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
76121 + gr_mode = S_IRUSR;
76122 +#endif
76123 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
76124 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
76125 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
76126 + proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
76127 +#else
76128 + proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
76129 +#endif
76130 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
76131 + }
76132 #endif
76133 return 0;
76134 }
76135 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
76136 index 9096bcb..43ed7bb 100644
76137 --- a/net/8021q/vlan.c
76138 +++ b/net/8021q/vlan.c
76139 @@ -557,8 +557,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
76140 err = -EPERM;
76141 if (!capable(CAP_NET_ADMIN))
76142 break;
76143 - if ((args.u.name_type >= 0) &&
76144 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
76145 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
76146 struct vlan_net *vn;
76147
76148 vn = net_generic(net, vlan_net_id);
76149 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
76150 index 6449bae..8c1f454 100644
76151 --- a/net/9p/trans_fd.c
76152 +++ b/net/9p/trans_fd.c
76153 @@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
76154 oldfs = get_fs();
76155 set_fs(get_ds());
76156 /* The cast to a user pointer is valid due to the set_fs() */
76157 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
76158 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
76159 set_fs(oldfs);
76160
76161 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
76162 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
76163 index 876fbe8..8bbea9f 100644
76164 --- a/net/atm/atm_misc.c
76165 +++ b/net/atm/atm_misc.c
76166 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
76167 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
76168 return 1;
76169 atm_return(vcc, truesize);
76170 - atomic_inc(&vcc->stats->rx_drop);
76171 + atomic_inc_unchecked(&vcc->stats->rx_drop);
76172 return 0;
76173 }
76174 EXPORT_SYMBOL(atm_charge);
76175 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
76176 }
76177 }
76178 atm_return(vcc, guess);
76179 - atomic_inc(&vcc->stats->rx_drop);
76180 + atomic_inc_unchecked(&vcc->stats->rx_drop);
76181 return NULL;
76182 }
76183 EXPORT_SYMBOL(atm_alloc_charge);
76184 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
76185
76186 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
76187 {
76188 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
76189 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
76190 __SONET_ITEMS
76191 #undef __HANDLE_ITEM
76192 }
76193 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
76194
76195 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
76196 {
76197 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
76198 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
76199 __SONET_ITEMS
76200 #undef __HANDLE_ITEM
76201 }
76202 diff --git a/net/atm/lec.h b/net/atm/lec.h
76203 index a86aff9..3a0d6f6 100644
76204 --- a/net/atm/lec.h
76205 +++ b/net/atm/lec.h
76206 @@ -48,7 +48,7 @@ struct lane2_ops {
76207 const u8 *tlvs, u32 sizeoftlvs);
76208 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
76209 const u8 *tlvs, u32 sizeoftlvs);
76210 -};
76211 +} __no_const;
76212
76213 /*
76214 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
76215 diff --git a/net/atm/mpc.h b/net/atm/mpc.h
76216 index 0919a88..a23d54e 100644
76217 --- a/net/atm/mpc.h
76218 +++ b/net/atm/mpc.h
76219 @@ -33,7 +33,7 @@ struct mpoa_client {
76220 struct mpc_parameters parameters; /* parameters for this client */
76221
76222 const struct net_device_ops *old_ops;
76223 - struct net_device_ops new_ops;
76224 + net_device_ops_no_const new_ops;
76225 };
76226
76227
76228 diff --git a/net/atm/proc.c b/net/atm/proc.c
76229 index 0d020de..011c7bb 100644
76230 --- a/net/atm/proc.c
76231 +++ b/net/atm/proc.c
76232 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
76233 const struct k_atm_aal_stats *stats)
76234 {
76235 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
76236 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
76237 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
76238 - atomic_read(&stats->rx_drop));
76239 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
76240 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
76241 + atomic_read_unchecked(&stats->rx_drop));
76242 }
76243
76244 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
76245 diff --git a/net/atm/resources.c b/net/atm/resources.c
76246 index 23f45ce..c748f1a 100644
76247 --- a/net/atm/resources.c
76248 +++ b/net/atm/resources.c
76249 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
76250 static void copy_aal_stats(struct k_atm_aal_stats *from,
76251 struct atm_aal_stats *to)
76252 {
76253 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
76254 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
76255 __AAL_STAT_ITEMS
76256 #undef __HANDLE_ITEM
76257 }
76258 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
76259 static void subtract_aal_stats(struct k_atm_aal_stats *from,
76260 struct atm_aal_stats *to)
76261 {
76262 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
76263 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
76264 __AAL_STAT_ITEMS
76265 #undef __HANDLE_ITEM
76266 }
76267 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
76268 index 469daab..262851c 100644
76269 --- a/net/batman-adv/bat_iv_ogm.c
76270 +++ b/net/batman-adv/bat_iv_ogm.c
76271 @@ -62,7 +62,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
76272
76273 /* randomize initial seqno to avoid collision */
76274 get_random_bytes(&random_seqno, sizeof(random_seqno));
76275 - atomic_set(&hard_iface->seqno, random_seqno);
76276 + atomic_set_unchecked(&hard_iface->seqno, random_seqno);
76277
76278 hard_iface->packet_len = BATADV_OGM_HLEN;
76279 hard_iface->packet_buff = kmalloc(hard_iface->packet_len, GFP_ATOMIC);
76280 @@ -600,8 +600,8 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
76281
76282 /* change sequence number to network order */
76283 batadv_ogm_packet->seqno =
76284 - htonl((uint32_t)atomic_read(&hard_iface->seqno));
76285 - atomic_inc(&hard_iface->seqno);
76286 + htonl((uint32_t)atomic_read_unchecked(&hard_iface->seqno));
76287 + atomic_inc_unchecked(&hard_iface->seqno);
76288
76289 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->ttvn);
76290 batadv_ogm_packet->tt_crc = htons(bat_priv->tt_crc);
76291 @@ -1001,7 +1001,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
76292 return;
76293
76294 /* could be changed by schedule_own_packet() */
76295 - if_incoming_seqno = atomic_read(&if_incoming->seqno);
76296 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
76297
76298 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
76299 has_directlink_flag = 1;
76300 diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
76301 index 282bf6e..4b2603d 100644
76302 --- a/net/batman-adv/hard-interface.c
76303 +++ b/net/batman-adv/hard-interface.c
76304 @@ -320,7 +320,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
76305 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
76306 dev_add_pack(&hard_iface->batman_adv_ptype);
76307
76308 - atomic_set(&hard_iface->frag_seqno, 1);
76309 + atomic_set_unchecked(&hard_iface->frag_seqno, 1);
76310 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
76311 hard_iface->net_dev->name);
76312
76313 @@ -443,7 +443,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
76314 /* This can't be called via a bat_priv callback because
76315 * we have no bat_priv yet.
76316 */
76317 - atomic_set(&hard_iface->seqno, 1);
76318 + atomic_set_unchecked(&hard_iface->seqno, 1);
76319 hard_iface->packet_buff = NULL;
76320
76321 return hard_iface;
76322 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
76323 index 21c5357..768be1a 100644
76324 --- a/net/batman-adv/soft-interface.c
76325 +++ b/net/batman-adv/soft-interface.c
76326 @@ -227,7 +227,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
76327
76328 /* set broadcast sequence number */
76329 bcast_packet->seqno =
76330 - htonl(atomic_inc_return(&bat_priv->bcast_seqno));
76331 + htonl(atomic_inc_return_unchecked(&bat_priv->bcast_seqno));
76332
76333 batadv_add_bcast_packet_to_list(bat_priv, skb, 1);
76334
76335 @@ -407,7 +407,7 @@ struct net_device *batadv_softif_create(const char *name)
76336 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
76337
76338 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
76339 - atomic_set(&bat_priv->bcast_seqno, 1);
76340 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
76341 atomic_set(&bat_priv->ttvn, 0);
76342 atomic_set(&bat_priv->tt_local_changes, 0);
76343 atomic_set(&bat_priv->tt_ogm_append_cnt, 0);
76344 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
76345 index 12635fd..d99d837 100644
76346 --- a/net/batman-adv/types.h
76347 +++ b/net/batman-adv/types.h
76348 @@ -33,8 +33,8 @@ struct batadv_hard_iface {
76349 int16_t if_num;
76350 char if_status;
76351 struct net_device *net_dev;
76352 - atomic_t seqno;
76353 - atomic_t frag_seqno;
76354 + atomic_unchecked_t seqno;
76355 + atomic_unchecked_t frag_seqno;
76356 unsigned char *packet_buff;
76357 int packet_len;
76358 struct kobject *hardif_obj;
76359 @@ -176,7 +176,7 @@ struct batadv_priv {
76360 atomic_t orig_interval; /* uint */
76361 atomic_t hop_penalty; /* uint */
76362 atomic_t log_level; /* uint */
76363 - atomic_t bcast_seqno;
76364 + atomic_unchecked_t bcast_seqno;
76365 atomic_t bcast_queue_left;
76366 atomic_t batman_queue_left;
76367 atomic_t ttvn; /* translation table version number */
76368 diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
76369 index 0016464..0ef3e53 100644
76370 --- a/net/batman-adv/unicast.c
76371 +++ b/net/batman-adv/unicast.c
76372 @@ -269,7 +269,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
76373 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
76374 frag2->flags = large_tail;
76375
76376 - seqno = atomic_add_return(2, &hard_iface->frag_seqno);
76377 + seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
76378 frag1->seqno = htons(seqno - 1);
76379 frag2->seqno = htons(seqno);
76380
76381 diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
76382 index d5ace1e..231c4bf 100644
76383 --- a/net/bluetooth/hci_sock.c
76384 +++ b/net/bluetooth/hci_sock.c
76385 @@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
76386 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
76387 }
76388
76389 - len = min_t(unsigned int, len, sizeof(uf));
76390 + len = min((size_t)len, sizeof(uf));
76391 if (copy_from_user(&uf, optval, len)) {
76392 err = -EFAULT;
76393 break;
76394 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
76395 index 38c00f1..e9d566e 100644
76396 --- a/net/bluetooth/l2cap_core.c
76397 +++ b/net/bluetooth/l2cap_core.c
76398 @@ -3165,8 +3165,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
76399 break;
76400
76401 case L2CAP_CONF_RFC:
76402 - if (olen == sizeof(rfc))
76403 - memcpy(&rfc, (void *)val, olen);
76404 + if (olen != sizeof(rfc))
76405 + break;
76406 +
76407 + memcpy(&rfc, (void *)val, olen);
76408
76409 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
76410 rfc.mode != chan->mode)
76411 diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
76412 index 34bbe1c..451c19b 100644
76413 --- a/net/bluetooth/l2cap_sock.c
76414 +++ b/net/bluetooth/l2cap_sock.c
76415 @@ -467,7 +467,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
76416 struct sock *sk = sock->sk;
76417 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
76418 struct l2cap_options opts;
76419 - int len, err = 0;
76420 + int err = 0;
76421 + size_t len = optlen;
76422 u32 opt;
76423
76424 BT_DBG("sk %p", sk);
76425 @@ -489,7 +490,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
76426 opts.max_tx = chan->max_tx;
76427 opts.txwin_size = chan->tx_win;
76428
76429 - len = min_t(unsigned int, sizeof(opts), optlen);
76430 + len = min(sizeof(opts), len);
76431 if (copy_from_user((char *) &opts, optval, len)) {
76432 err = -EFAULT;
76433 break;
76434 @@ -567,7 +568,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
76435 struct bt_security sec;
76436 struct bt_power pwr;
76437 struct l2cap_conn *conn;
76438 - int len, err = 0;
76439 + int err = 0;
76440 + size_t len = optlen;
76441 u32 opt;
76442
76443 BT_DBG("sk %p", sk);
76444 @@ -590,7 +592,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
76445
76446 sec.level = BT_SECURITY_LOW;
76447
76448 - len = min_t(unsigned int, sizeof(sec), optlen);
76449 + len = min(sizeof(sec), len);
76450 if (copy_from_user((char *) &sec, optval, len)) {
76451 err = -EFAULT;
76452 break;
76453 @@ -687,7 +689,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
76454
76455 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
76456
76457 - len = min_t(unsigned int, sizeof(pwr), optlen);
76458 + len = min(sizeof(pwr), len);
76459 if (copy_from_user((char *) &pwr, optval, len)) {
76460 err = -EFAULT;
76461 break;
76462 diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
76463 index 1a17850..65a3129 100644
76464 --- a/net/bluetooth/rfcomm/sock.c
76465 +++ b/net/bluetooth/rfcomm/sock.c
76466 @@ -667,7 +667,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
76467 struct sock *sk = sock->sk;
76468 struct bt_security sec;
76469 int err = 0;
76470 - size_t len;
76471 + size_t len = optlen;
76472 u32 opt;
76473
76474 BT_DBG("sk %p", sk);
76475 @@ -689,7 +689,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
76476
76477 sec.level = BT_SECURITY_LOW;
76478
76479 - len = min_t(unsigned int, sizeof(sec), optlen);
76480 + len = min(sizeof(sec), len);
76481 if (copy_from_user((char *) &sec, optval, len)) {
76482 err = -EFAULT;
76483 break;
76484 diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
76485 index 56f1823..da44330 100644
76486 --- a/net/bluetooth/rfcomm/tty.c
76487 +++ b/net/bluetooth/rfcomm/tty.c
76488 @@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
76489 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
76490
76491 spin_lock_irqsave(&dev->port.lock, flags);
76492 - if (dev->port.count > 0) {
76493 + if (atomic_read(&dev->port.count) > 0) {
76494 spin_unlock_irqrestore(&dev->port.lock, flags);
76495 return;
76496 }
76497 @@ -664,10 +664,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
76498 return -ENODEV;
76499
76500 BT_DBG("dev %p dst %s channel %d opened %d", dev, batostr(&dev->dst),
76501 - dev->channel, dev->port.count);
76502 + dev->channel, atomic_read(&dev->port.count));
76503
76504 spin_lock_irqsave(&dev->port.lock, flags);
76505 - if (++dev->port.count > 1) {
76506 + if (atomic_inc_return(&dev->port.count) > 1) {
76507 spin_unlock_irqrestore(&dev->port.lock, flags);
76508 return 0;
76509 }
76510 @@ -732,10 +732,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
76511 return;
76512
76513 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
76514 - dev->port.count);
76515 + atomic_read(&dev->port.count));
76516
76517 spin_lock_irqsave(&dev->port.lock, flags);
76518 - if (!--dev->port.count) {
76519 + if (!atomic_dec_return(&dev->port.count)) {
76520 spin_unlock_irqrestore(&dev->port.lock, flags);
76521 if (dev->tty_dev->parent)
76522 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
76523 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
76524 index 5fe2ff3..121d696 100644
76525 --- a/net/bridge/netfilter/ebtables.c
76526 +++ b/net/bridge/netfilter/ebtables.c
76527 @@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
76528 tmp.valid_hooks = t->table->valid_hooks;
76529 }
76530 mutex_unlock(&ebt_mutex);
76531 - if (copy_to_user(user, &tmp, *len) != 0){
76532 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
76533 BUGPRINT("c2u Didn't work\n");
76534 ret = -EFAULT;
76535 break;
76536 @@ -2327,7 +2327,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
76537 goto out;
76538 tmp.valid_hooks = t->valid_hooks;
76539
76540 - if (copy_to_user(user, &tmp, *len) != 0) {
76541 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
76542 ret = -EFAULT;
76543 break;
76544 }
76545 @@ -2338,7 +2338,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
76546 tmp.entries_size = t->table->entries_size;
76547 tmp.valid_hooks = t->table->valid_hooks;
76548
76549 - if (copy_to_user(user, &tmp, *len) != 0) {
76550 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
76551 ret = -EFAULT;
76552 break;
76553 }
76554 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
76555 index 44f270f..1f5602d 100644
76556 --- a/net/caif/cfctrl.c
76557 +++ b/net/caif/cfctrl.c
76558 @@ -10,6 +10,7 @@
76559 #include <linux/spinlock.h>
76560 #include <linux/slab.h>
76561 #include <linux/pkt_sched.h>
76562 +#include <linux/sched.h>
76563 #include <net/caif/caif_layer.h>
76564 #include <net/caif/cfpkt.h>
76565 #include <net/caif/cfctrl.h>
76566 @@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
76567 memset(&dev_info, 0, sizeof(dev_info));
76568 dev_info.id = 0xff;
76569 cfsrvl_init(&this->serv, 0, &dev_info, false);
76570 - atomic_set(&this->req_seq_no, 1);
76571 - atomic_set(&this->rsp_seq_no, 1);
76572 + atomic_set_unchecked(&this->req_seq_no, 1);
76573 + atomic_set_unchecked(&this->rsp_seq_no, 1);
76574 this->serv.layer.receive = cfctrl_recv;
76575 sprintf(this->serv.layer.name, "ctrl");
76576 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
76577 @@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
76578 struct cfctrl_request_info *req)
76579 {
76580 spin_lock_bh(&ctrl->info_list_lock);
76581 - atomic_inc(&ctrl->req_seq_no);
76582 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
76583 + atomic_inc_unchecked(&ctrl->req_seq_no);
76584 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
76585 list_add_tail(&req->list, &ctrl->list);
76586 spin_unlock_bh(&ctrl->info_list_lock);
76587 }
76588 @@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
76589 if (p != first)
76590 pr_warn("Requests are not received in order\n");
76591
76592 - atomic_set(&ctrl->rsp_seq_no,
76593 + atomic_set_unchecked(&ctrl->rsp_seq_no,
76594 p->sequence_no);
76595 list_del(&p->list);
76596 goto out;
76597 diff --git a/net/can/gw.c b/net/can/gw.c
76598 index b54d5e6..91c3b25 100644
76599 --- a/net/can/gw.c
76600 +++ b/net/can/gw.c
76601 @@ -96,7 +96,7 @@ struct cf_mod {
76602 struct {
76603 void (*xor)(struct can_frame *cf, struct cgw_csum_xor *xor);
76604 void (*crc8)(struct can_frame *cf, struct cgw_csum_crc8 *crc8);
76605 - } csumfunc;
76606 + } __no_const csumfunc;
76607 };
76608
76609
76610 diff --git a/net/compat.c b/net/compat.c
76611 index 74ed1d7..3695bd9 100644
76612 --- a/net/compat.c
76613 +++ b/net/compat.c
76614 @@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
76615 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
76616 __get_user(kmsg->msg_flags, &umsg->msg_flags))
76617 return -EFAULT;
76618 - kmsg->msg_name = compat_ptr(tmp1);
76619 - kmsg->msg_iov = compat_ptr(tmp2);
76620 - kmsg->msg_control = compat_ptr(tmp3);
76621 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
76622 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
76623 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
76624 return 0;
76625 }
76626
76627 @@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
76628
76629 if (kern_msg->msg_namelen) {
76630 if (mode == VERIFY_READ) {
76631 - int err = move_addr_to_kernel(kern_msg->msg_name,
76632 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
76633 kern_msg->msg_namelen,
76634 kern_address);
76635 if (err < 0)
76636 @@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
76637 kern_msg->msg_name = NULL;
76638
76639 tot_len = iov_from_user_compat_to_kern(kern_iov,
76640 - (struct compat_iovec __user *)kern_msg->msg_iov,
76641 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
76642 kern_msg->msg_iovlen);
76643 if (tot_len >= 0)
76644 kern_msg->msg_iov = kern_iov;
76645 @@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
76646
76647 #define CMSG_COMPAT_FIRSTHDR(msg) \
76648 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
76649 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
76650 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
76651 (struct compat_cmsghdr __user *)NULL)
76652
76653 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
76654 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
76655 (ucmlen) <= (unsigned long) \
76656 ((mhdr)->msg_controllen - \
76657 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
76658 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
76659
76660 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
76661 struct compat_cmsghdr __user *cmsg, int cmsg_len)
76662 {
76663 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
76664 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
76665 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
76666 msg->msg_controllen)
76667 return NULL;
76668 return (struct compat_cmsghdr __user *)ptr;
76669 @@ -219,7 +219,7 @@ Efault:
76670
76671 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
76672 {
76673 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
76674 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
76675 struct compat_cmsghdr cmhdr;
76676 struct compat_timeval ctv;
76677 struct compat_timespec cts[3];
76678 @@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
76679
76680 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
76681 {
76682 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
76683 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
76684 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
76685 int fdnum = scm->fp->count;
76686 struct file **fp = scm->fp->fp;
76687 @@ -364,7 +364,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
76688 return -EFAULT;
76689 old_fs = get_fs();
76690 set_fs(KERNEL_DS);
76691 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
76692 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
76693 set_fs(old_fs);
76694
76695 return err;
76696 @@ -425,7 +425,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
76697 len = sizeof(ktime);
76698 old_fs = get_fs();
76699 set_fs(KERNEL_DS);
76700 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
76701 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
76702 set_fs(old_fs);
76703
76704 if (!err) {
76705 @@ -568,7 +568,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
76706 case MCAST_JOIN_GROUP:
76707 case MCAST_LEAVE_GROUP:
76708 {
76709 - struct compat_group_req __user *gr32 = (void *)optval;
76710 + struct compat_group_req __user *gr32 = (void __user *)optval;
76711 struct group_req __user *kgr =
76712 compat_alloc_user_space(sizeof(struct group_req));
76713 u32 interface;
76714 @@ -589,7 +589,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
76715 case MCAST_BLOCK_SOURCE:
76716 case MCAST_UNBLOCK_SOURCE:
76717 {
76718 - struct compat_group_source_req __user *gsr32 = (void *)optval;
76719 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
76720 struct group_source_req __user *kgsr = compat_alloc_user_space(
76721 sizeof(struct group_source_req));
76722 u32 interface;
76723 @@ -610,7 +610,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
76724 }
76725 case MCAST_MSFILTER:
76726 {
76727 - struct compat_group_filter __user *gf32 = (void *)optval;
76728 + struct compat_group_filter __user *gf32 = (void __user *)optval;
76729 struct group_filter __user *kgf;
76730 u32 interface, fmode, numsrc;
76731
76732 @@ -648,7 +648,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
76733 char __user *optval, int __user *optlen,
76734 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
76735 {
76736 - struct compat_group_filter __user *gf32 = (void *)optval;
76737 + struct compat_group_filter __user *gf32 = (void __user *)optval;
76738 struct group_filter __user *kgf;
76739 int __user *koptlen;
76740 u32 interface, fmode, numsrc;
76741 @@ -797,7 +797,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
76742
76743 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
76744 return -EINVAL;
76745 - if (copy_from_user(a, args, nas[call]))
76746 + if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
76747 return -EFAULT;
76748 a0 = a[0];
76749 a1 = a[1];
76750 diff --git a/net/core/datagram.c b/net/core/datagram.c
76751 index 0337e2b..47914a0 100644
76752 --- a/net/core/datagram.c
76753 +++ b/net/core/datagram.c
76754 @@ -289,7 +289,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
76755 }
76756
76757 kfree_skb(skb);
76758 - atomic_inc(&sk->sk_drops);
76759 + atomic_inc_unchecked(&sk->sk_drops);
76760 sk_mem_reclaim_partial(sk);
76761
76762 return err;
76763 diff --git a/net/core/dev.c b/net/core/dev.c
76764 index aed87a4..72cc526 100644
76765 --- a/net/core/dev.c
76766 +++ b/net/core/dev.c
76767 @@ -1138,9 +1138,13 @@ void dev_load(struct net *net, const char *name)
76768 if (no_module && capable(CAP_NET_ADMIN))
76769 no_module = request_module("netdev-%s", name);
76770 if (no_module && capable(CAP_SYS_MODULE)) {
76771 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
76772 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
76773 +#else
76774 if (!request_module("%s", name))
76775 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
76776 name);
76777 +#endif
76778 }
76779 }
76780 EXPORT_SYMBOL(dev_load);
76781 @@ -1605,7 +1609,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
76782 {
76783 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
76784 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
76785 - atomic_long_inc(&dev->rx_dropped);
76786 + atomic_long_inc_unchecked(&dev->rx_dropped);
76787 kfree_skb(skb);
76788 return NET_RX_DROP;
76789 }
76790 @@ -1615,7 +1619,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
76791 nf_reset(skb);
76792
76793 if (unlikely(!is_skb_forwardable(dev, skb))) {
76794 - atomic_long_inc(&dev->rx_dropped);
76795 + atomic_long_inc_unchecked(&dev->rx_dropped);
76796 kfree_skb(skb);
76797 return NET_RX_DROP;
76798 }
76799 @@ -2071,7 +2075,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
76800
76801 struct dev_gso_cb {
76802 void (*destructor)(struct sk_buff *skb);
76803 -};
76804 +} __no_const;
76805
76806 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
76807
76808 @@ -2928,7 +2932,7 @@ enqueue:
76809
76810 local_irq_restore(flags);
76811
76812 - atomic_long_inc(&skb->dev->rx_dropped);
76813 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
76814 kfree_skb(skb);
76815 return NET_RX_DROP;
76816 }
76817 @@ -3000,7 +3004,7 @@ int netif_rx_ni(struct sk_buff *skb)
76818 }
76819 EXPORT_SYMBOL(netif_rx_ni);
76820
76821 -static void net_tx_action(struct softirq_action *h)
76822 +static void net_tx_action(void)
76823 {
76824 struct softnet_data *sd = &__get_cpu_var(softnet_data);
76825
76826 @@ -3331,7 +3335,7 @@ ncls:
76827 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
76828 } else {
76829 drop:
76830 - atomic_long_inc(&skb->dev->rx_dropped);
76831 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
76832 kfree_skb(skb);
76833 /* Jamal, now you will not able to escape explaining
76834 * me how you were going to use this. :-)
76835 @@ -3898,7 +3902,7 @@ void netif_napi_del(struct napi_struct *napi)
76836 }
76837 EXPORT_SYMBOL(netif_napi_del);
76838
76839 -static void net_rx_action(struct softirq_action *h)
76840 +static void net_rx_action(void)
76841 {
76842 struct softnet_data *sd = &__get_cpu_var(softnet_data);
76843 unsigned long time_limit = jiffies + 2;
76844 @@ -4368,8 +4372,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
76845 else
76846 seq_printf(seq, "%04x", ntohs(pt->type));
76847
76848 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76849 + seq_printf(seq, " %-8s %p\n",
76850 + pt->dev ? pt->dev->name : "", NULL);
76851 +#else
76852 seq_printf(seq, " %-8s %pF\n",
76853 pt->dev ? pt->dev->name : "", pt->func);
76854 +#endif
76855 }
76856
76857 return 0;
76858 @@ -5922,7 +5931,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
76859 } else {
76860 netdev_stats_to_stats64(storage, &dev->stats);
76861 }
76862 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
76863 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
76864 return storage;
76865 }
76866 EXPORT_SYMBOL(dev_get_stats);
76867 diff --git a/net/core/flow.c b/net/core/flow.c
76868 index e318c7e..168b1d0 100644
76869 --- a/net/core/flow.c
76870 +++ b/net/core/flow.c
76871 @@ -61,7 +61,7 @@ struct flow_cache {
76872 struct timer_list rnd_timer;
76873 };
76874
76875 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
76876 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
76877 EXPORT_SYMBOL(flow_cache_genid);
76878 static struct flow_cache flow_cache_global;
76879 static struct kmem_cache *flow_cachep __read_mostly;
76880 @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
76881
76882 static int flow_entry_valid(struct flow_cache_entry *fle)
76883 {
76884 - if (atomic_read(&flow_cache_genid) != fle->genid)
76885 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
76886 return 0;
76887 if (fle->object && !fle->object->ops->check(fle->object))
76888 return 0;
76889 @@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
76890 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
76891 fcp->hash_count++;
76892 }
76893 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
76894 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
76895 flo = fle->object;
76896 if (!flo)
76897 goto ret_object;
76898 @@ -280,7 +280,7 @@ nocache:
76899 }
76900 flo = resolver(net, key, family, dir, flo, ctx);
76901 if (fle) {
76902 - fle->genid = atomic_read(&flow_cache_genid);
76903 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
76904 if (!IS_ERR(flo))
76905 fle->object = flo;
76906 else
76907 diff --git a/net/core/iovec.c b/net/core/iovec.c
76908 index 7e7aeb0..2a998cb 100644
76909 --- a/net/core/iovec.c
76910 +++ b/net/core/iovec.c
76911 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
76912 if (m->msg_namelen) {
76913 if (mode == VERIFY_READ) {
76914 void __user *namep;
76915 - namep = (void __user __force *) m->msg_name;
76916 + namep = (void __force_user *) m->msg_name;
76917 err = move_addr_to_kernel(namep, m->msg_namelen,
76918 address);
76919 if (err < 0)
76920 @@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
76921 }
76922
76923 size = m->msg_iovlen * sizeof(struct iovec);
76924 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
76925 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
76926 return -EFAULT;
76927
76928 m->msg_iov = iov;
76929 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
76930 index 2c5a0a0..a45f90c 100644
76931 --- a/net/core/rtnetlink.c
76932 +++ b/net/core/rtnetlink.c
76933 @@ -58,7 +58,7 @@ struct rtnl_link {
76934 rtnl_doit_func doit;
76935 rtnl_dumpit_func dumpit;
76936 rtnl_calcit_func calcit;
76937 -};
76938 +} __no_const;
76939
76940 static DEFINE_MUTEX(rtnl_mutex);
76941
76942 diff --git a/net/core/scm.c b/net/core/scm.c
76943 index 040cebe..5b1e312 100644
76944 --- a/net/core/scm.c
76945 +++ b/net/core/scm.c
76946 @@ -203,7 +203,7 @@ EXPORT_SYMBOL(__scm_send);
76947 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
76948 {
76949 struct cmsghdr __user *cm
76950 - = (__force struct cmsghdr __user *)msg->msg_control;
76951 + = (struct cmsghdr __force_user *)msg->msg_control;
76952 struct cmsghdr cmhdr;
76953 int cmlen = CMSG_LEN(len);
76954 int err;
76955 @@ -226,7 +226,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
76956 err = -EFAULT;
76957 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
76958 goto out;
76959 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
76960 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
76961 goto out;
76962 cmlen = CMSG_SPACE(len);
76963 if (msg->msg_controllen < cmlen)
76964 @@ -242,7 +242,7 @@ EXPORT_SYMBOL(put_cmsg);
76965 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
76966 {
76967 struct cmsghdr __user *cm
76968 - = (__force struct cmsghdr __user*)msg->msg_control;
76969 + = (struct cmsghdr __force_user *)msg->msg_control;
76970
76971 int fdmax = 0;
76972 int fdnum = scm->fp->count;
76973 @@ -262,7 +262,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
76974 if (fdnum < fdmax)
76975 fdmax = fdnum;
76976
76977 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
76978 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
76979 i++, cmfptr++)
76980 {
76981 struct socket *sock;
76982 diff --git a/net/core/sock.c b/net/core/sock.c
76983 index a6000fb..d4aee72 100644
76984 --- a/net/core/sock.c
76985 +++ b/net/core/sock.c
76986 @@ -399,7 +399,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76987 struct sk_buff_head *list = &sk->sk_receive_queue;
76988
76989 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
76990 - atomic_inc(&sk->sk_drops);
76991 + atomic_inc_unchecked(&sk->sk_drops);
76992 trace_sock_rcvqueue_full(sk, skb);
76993 return -ENOMEM;
76994 }
76995 @@ -409,7 +409,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76996 return err;
76997
76998 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
76999 - atomic_inc(&sk->sk_drops);
77000 + atomic_inc_unchecked(&sk->sk_drops);
77001 return -ENOBUFS;
77002 }
77003
77004 @@ -429,7 +429,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
77005 skb_dst_force(skb);
77006
77007 spin_lock_irqsave(&list->lock, flags);
77008 - skb->dropcount = atomic_read(&sk->sk_drops);
77009 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
77010 __skb_queue_tail(list, skb);
77011 spin_unlock_irqrestore(&list->lock, flags);
77012
77013 @@ -449,7 +449,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
77014 skb->dev = NULL;
77015
77016 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
77017 - atomic_inc(&sk->sk_drops);
77018 + atomic_inc_unchecked(&sk->sk_drops);
77019 goto discard_and_relse;
77020 }
77021 if (nested)
77022 @@ -467,7 +467,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
77023 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
77024 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
77025 bh_unlock_sock(sk);
77026 - atomic_inc(&sk->sk_drops);
77027 + atomic_inc_unchecked(&sk->sk_drops);
77028 goto discard_and_relse;
77029 }
77030
77031 @@ -886,12 +886,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
77032 struct timeval tm;
77033 } v;
77034
77035 - int lv = sizeof(int);
77036 - int len;
77037 + unsigned int lv = sizeof(int);
77038 + unsigned int len;
77039
77040 if (get_user(len, optlen))
77041 return -EFAULT;
77042 - if (len < 0)
77043 + if (len > INT_MAX)
77044 return -EINVAL;
77045
77046 memset(&v, 0, sizeof(v));
77047 @@ -1039,11 +1039,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
77048
77049 case SO_PEERNAME:
77050 {
77051 - char address[128];
77052 + char address[_K_SS_MAXSIZE];
77053
77054 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
77055 return -ENOTCONN;
77056 - if (lv < len)
77057 + if (lv < len || sizeof address < len)
77058 return -EINVAL;
77059 if (copy_to_user(optval, address, len))
77060 return -EFAULT;
77061 @@ -1091,7 +1091,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
77062
77063 if (len > lv)
77064 len = lv;
77065 - if (copy_to_user(optval, &v, len))
77066 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
77067 return -EFAULT;
77068 lenout:
77069 if (put_user(len, optlen))
77070 @@ -2193,7 +2193,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
77071 */
77072 smp_wmb();
77073 atomic_set(&sk->sk_refcnt, 1);
77074 - atomic_set(&sk->sk_drops, 0);
77075 + atomic_set_unchecked(&sk->sk_drops, 0);
77076 }
77077 EXPORT_SYMBOL(sock_init_data);
77078
77079 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
77080 index 9d8755e..26de8bc 100644
77081 --- a/net/core/sock_diag.c
77082 +++ b/net/core/sock_diag.c
77083 @@ -15,20 +15,27 @@ static DEFINE_MUTEX(sock_diag_table_mutex);
77084
77085 int sock_diag_check_cookie(void *sk, __u32 *cookie)
77086 {
77087 +#ifndef CONFIG_GRKERNSEC_HIDESYM
77088 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
77089 cookie[1] != INET_DIAG_NOCOOKIE) &&
77090 ((u32)(unsigned long)sk != cookie[0] ||
77091 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
77092 return -ESTALE;
77093 else
77094 +#endif
77095 return 0;
77096 }
77097 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
77098
77099 void sock_diag_save_cookie(void *sk, __u32 *cookie)
77100 {
77101 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77102 + cookie[0] = 0;
77103 + cookie[1] = 0;
77104 +#else
77105 cookie[0] = (u32)(unsigned long)sk;
77106 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
77107 +#endif
77108 }
77109 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
77110
77111 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
77112 index a55eecc..dd8428c 100644
77113 --- a/net/decnet/sysctl_net_decnet.c
77114 +++ b/net/decnet/sysctl_net_decnet.c
77115 @@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
77116
77117 if (len > *lenp) len = *lenp;
77118
77119 - if (copy_to_user(buffer, addr, len))
77120 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
77121 return -EFAULT;
77122
77123 *lenp = len;
77124 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
77125
77126 if (len > *lenp) len = *lenp;
77127
77128 - if (copy_to_user(buffer, devname, len))
77129 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
77130 return -EFAULT;
77131
77132 *lenp = len;
77133 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
77134 index f444ac7..b7bdda9 100644
77135 --- a/net/ipv4/fib_frontend.c
77136 +++ b/net/ipv4/fib_frontend.c
77137 @@ -1020,12 +1020,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
77138 #ifdef CONFIG_IP_ROUTE_MULTIPATH
77139 fib_sync_up(dev);
77140 #endif
77141 - atomic_inc(&net->ipv4.dev_addr_genid);
77142 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
77143 rt_cache_flush(dev_net(dev));
77144 break;
77145 case NETDEV_DOWN:
77146 fib_del_ifaddr(ifa, NULL);
77147 - atomic_inc(&net->ipv4.dev_addr_genid);
77148 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
77149 if (ifa->ifa_dev->ifa_list == NULL) {
77150 /* Last address was deleted from this interface.
77151 * Disable IP.
77152 @@ -1062,7 +1062,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
77153 #ifdef CONFIG_IP_ROUTE_MULTIPATH
77154 fib_sync_up(dev);
77155 #endif
77156 - atomic_inc(&net->ipv4.dev_addr_genid);
77157 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
77158 rt_cache_flush(dev_net(dev));
77159 break;
77160 case NETDEV_DOWN:
77161 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
77162 index 9633661..4e0bc08 100644
77163 --- a/net/ipv4/fib_semantics.c
77164 +++ b/net/ipv4/fib_semantics.c
77165 @@ -767,7 +767,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
77166 nh->nh_saddr = inet_select_addr(nh->nh_dev,
77167 nh->nh_gw,
77168 nh->nh_parent->fib_scope);
77169 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
77170 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
77171
77172 return nh->nh_saddr;
77173 }
77174 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
77175 index 7880af9..70f92a3 100644
77176 --- a/net/ipv4/inet_hashtables.c
77177 +++ b/net/ipv4/inet_hashtables.c
77178 @@ -18,12 +18,15 @@
77179 #include <linux/sched.h>
77180 #include <linux/slab.h>
77181 #include <linux/wait.h>
77182 +#include <linux/security.h>
77183
77184 #include <net/inet_connection_sock.h>
77185 #include <net/inet_hashtables.h>
77186 #include <net/secure_seq.h>
77187 #include <net/ip.h>
77188
77189 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
77190 +
77191 /*
77192 * Allocate and initialize a new local port bind bucket.
77193 * The bindhash mutex for snum's hash chain must be held here.
77194 @@ -530,6 +533,8 @@ ok:
77195 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
77196 spin_unlock(&head->lock);
77197
77198 + gr_update_task_in_ip_table(current, inet_sk(sk));
77199 +
77200 if (tw) {
77201 inet_twsk_deschedule(tw, death_row);
77202 while (twrefcnt) {
77203 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
77204 index c7527f6..d8bba61 100644
77205 --- a/net/ipv4/inetpeer.c
77206 +++ b/net/ipv4/inetpeer.c
77207 @@ -503,8 +503,8 @@ relookup:
77208 if (p) {
77209 p->daddr = *daddr;
77210 atomic_set(&p->refcnt, 1);
77211 - atomic_set(&p->rid, 0);
77212 - atomic_set(&p->ip_id_count,
77213 + atomic_set_unchecked(&p->rid, 0);
77214 + atomic_set_unchecked(&p->ip_id_count,
77215 (daddr->family == AF_INET) ?
77216 secure_ip_id(daddr->addr.a4) :
77217 secure_ipv6_id(daddr->addr.a6));
77218 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
77219 index 8d07c97..d0812ef 100644
77220 --- a/net/ipv4/ip_fragment.c
77221 +++ b/net/ipv4/ip_fragment.c
77222 @@ -322,7 +322,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
77223 return 0;
77224
77225 start = qp->rid;
77226 - end = atomic_inc_return(&peer->rid);
77227 + end = atomic_inc_return_unchecked(&peer->rid);
77228 qp->rid = end;
77229
77230 rc = qp->q.fragments && (end - start) > max;
77231 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
77232 index 5eea4a8..49819c2 100644
77233 --- a/net/ipv4/ip_sockglue.c
77234 +++ b/net/ipv4/ip_sockglue.c
77235 @@ -1142,7 +1142,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
77236 len = min_t(unsigned int, len, opt->optlen);
77237 if (put_user(len, optlen))
77238 return -EFAULT;
77239 - if (copy_to_user(optval, opt->__data, len))
77240 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
77241 + copy_to_user(optval, opt->__data, len))
77242 return -EFAULT;
77243 return 0;
77244 }
77245 @@ -1273,7 +1274,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
77246 if (sk->sk_type != SOCK_STREAM)
77247 return -ENOPROTOOPT;
77248
77249 - msg.msg_control = optval;
77250 + msg.msg_control = (void __force_kernel *)optval;
77251 msg.msg_controllen = len;
77252 msg.msg_flags = flags;
77253
77254 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
77255 index 67e8a6b..386764d 100644
77256 --- a/net/ipv4/ipconfig.c
77257 +++ b/net/ipv4/ipconfig.c
77258 @@ -321,7 +321,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
77259
77260 mm_segment_t oldfs = get_fs();
77261 set_fs(get_ds());
77262 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
77263 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
77264 set_fs(oldfs);
77265 return res;
77266 }
77267 @@ -332,7 +332,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
77268
77269 mm_segment_t oldfs = get_fs();
77270 set_fs(get_ds());
77271 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
77272 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
77273 set_fs(oldfs);
77274 return res;
77275 }
77276 @@ -343,7 +343,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
77277
77278 mm_segment_t oldfs = get_fs();
77279 set_fs(get_ds());
77280 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
77281 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
77282 set_fs(oldfs);
77283 return res;
77284 }
77285 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
77286 index 97e61ea..cac1bbb 100644
77287 --- a/net/ipv4/netfilter/arp_tables.c
77288 +++ b/net/ipv4/netfilter/arp_tables.c
77289 @@ -879,14 +879,14 @@ static int compat_table_info(const struct xt_table_info *info,
77290 #endif
77291
77292 static int get_info(struct net *net, void __user *user,
77293 - const int *len, int compat)
77294 + int len, int compat)
77295 {
77296 char name[XT_TABLE_MAXNAMELEN];
77297 struct xt_table *t;
77298 int ret;
77299
77300 - if (*len != sizeof(struct arpt_getinfo)) {
77301 - duprintf("length %u != %Zu\n", *len,
77302 + if (len != sizeof(struct arpt_getinfo)) {
77303 + duprintf("length %u != %Zu\n", len,
77304 sizeof(struct arpt_getinfo));
77305 return -EINVAL;
77306 }
77307 @@ -923,7 +923,7 @@ static int get_info(struct net *net, void __user *user,
77308 info.size = private->size;
77309 strcpy(info.name, name);
77310
77311 - if (copy_to_user(user, &info, *len) != 0)
77312 + if (copy_to_user(user, &info, len) != 0)
77313 ret = -EFAULT;
77314 else
77315 ret = 0;
77316 @@ -1682,7 +1682,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
77317
77318 switch (cmd) {
77319 case ARPT_SO_GET_INFO:
77320 - ret = get_info(sock_net(sk), user, len, 1);
77321 + ret = get_info(sock_net(sk), user, *len, 1);
77322 break;
77323 case ARPT_SO_GET_ENTRIES:
77324 ret = compat_get_entries(sock_net(sk), user, len);
77325 @@ -1727,7 +1727,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
77326
77327 switch (cmd) {
77328 case ARPT_SO_GET_INFO:
77329 - ret = get_info(sock_net(sk), user, len, 0);
77330 + ret = get_info(sock_net(sk), user, *len, 0);
77331 break;
77332
77333 case ARPT_SO_GET_ENTRIES:
77334 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
77335 index 170b1fd..6105b91 100644
77336 --- a/net/ipv4/netfilter/ip_tables.c
77337 +++ b/net/ipv4/netfilter/ip_tables.c
77338 @@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
77339 #endif
77340
77341 static int get_info(struct net *net, void __user *user,
77342 - const int *len, int compat)
77343 + int len, int compat)
77344 {
77345 char name[XT_TABLE_MAXNAMELEN];
77346 struct xt_table *t;
77347 int ret;
77348
77349 - if (*len != sizeof(struct ipt_getinfo)) {
77350 - duprintf("length %u != %zu\n", *len,
77351 + if (len != sizeof(struct ipt_getinfo)) {
77352 + duprintf("length %u != %zu\n", len,
77353 sizeof(struct ipt_getinfo));
77354 return -EINVAL;
77355 }
77356 @@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
77357 info.size = private->size;
77358 strcpy(info.name, name);
77359
77360 - if (copy_to_user(user, &info, *len) != 0)
77361 + if (copy_to_user(user, &info, len) != 0)
77362 ret = -EFAULT;
77363 else
77364 ret = 0;
77365 @@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77366
77367 switch (cmd) {
77368 case IPT_SO_GET_INFO:
77369 - ret = get_info(sock_net(sk), user, len, 1);
77370 + ret = get_info(sock_net(sk), user, *len, 1);
77371 break;
77372 case IPT_SO_GET_ENTRIES:
77373 ret = compat_get_entries(sock_net(sk), user, len);
77374 @@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77375
77376 switch (cmd) {
77377 case IPT_SO_GET_INFO:
77378 - ret = get_info(sock_net(sk), user, len, 0);
77379 + ret = get_info(sock_net(sk), user, *len, 0);
77380 break;
77381
77382 case IPT_SO_GET_ENTRIES:
77383 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
77384 index 6232d47..6b88607 100644
77385 --- a/net/ipv4/ping.c
77386 +++ b/net/ipv4/ping.c
77387 @@ -847,7 +847,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
77388 sk_rmem_alloc_get(sp),
77389 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
77390 atomic_read(&sp->sk_refcnt), sp,
77391 - atomic_read(&sp->sk_drops), len);
77392 + atomic_read_unchecked(&sp->sk_drops), len);
77393 }
77394
77395 static int ping_seq_show(struct seq_file *seq, void *v)
77396 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
77397 index d23c657..cb69cc2 100644
77398 --- a/net/ipv4/raw.c
77399 +++ b/net/ipv4/raw.c
77400 @@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
77401 int raw_rcv(struct sock *sk, struct sk_buff *skb)
77402 {
77403 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
77404 - atomic_inc(&sk->sk_drops);
77405 + atomic_inc_unchecked(&sk->sk_drops);
77406 kfree_skb(skb);
77407 return NET_RX_DROP;
77408 }
77409 @@ -747,16 +747,20 @@ static int raw_init(struct sock *sk)
77410
77411 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
77412 {
77413 + struct icmp_filter filter;
77414 +
77415 if (optlen > sizeof(struct icmp_filter))
77416 optlen = sizeof(struct icmp_filter);
77417 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
77418 + if (copy_from_user(&filter, optval, optlen))
77419 return -EFAULT;
77420 + raw_sk(sk)->filter = filter;
77421 return 0;
77422 }
77423
77424 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
77425 {
77426 int len, ret = -EFAULT;
77427 + struct icmp_filter filter;
77428
77429 if (get_user(len, optlen))
77430 goto out;
77431 @@ -766,8 +770,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
77432 if (len > sizeof(struct icmp_filter))
77433 len = sizeof(struct icmp_filter);
77434 ret = -EFAULT;
77435 - if (put_user(len, optlen) ||
77436 - copy_to_user(optval, &raw_sk(sk)->filter, len))
77437 + filter = raw_sk(sk)->filter;
77438 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
77439 goto out;
77440 ret = 0;
77441 out: return ret;
77442 @@ -995,7 +999,13 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
77443 sk_wmem_alloc_get(sp),
77444 sk_rmem_alloc_get(sp),
77445 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
77446 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
77447 + atomic_read(&sp->sk_refcnt),
77448 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77449 + NULL,
77450 +#else
77451 + sp,
77452 +#endif
77453 + atomic_read_unchecked(&sp->sk_drops));
77454 }
77455
77456 static int raw_seq_show(struct seq_file *seq, void *v)
77457 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
77458 index c017cb1..9eb15b7d 100644
77459 --- a/net/ipv4/route.c
77460 +++ b/net/ipv4/route.c
77461 @@ -2526,7 +2526,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
77462
77463 static __net_init int rt_genid_init(struct net *net)
77464 {
77465 - atomic_set(&net->rt_genid, 0);
77466 + atomic_set_unchecked(&net->rt_genid, 0);
77467 get_random_bytes(&net->ipv4.dev_addr_genid,
77468 sizeof(net->ipv4.dev_addr_genid));
77469 return 0;
77470 diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
77471 index c92c4da..f19e3ec 100644
77472 --- a/net/ipv4/tcp_input.c
77473 +++ b/net/ipv4/tcp_input.c
77474 @@ -4731,7 +4731,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
77475 * simplifies code)
77476 */
77477 static void
77478 -tcp_collapse(struct sock *sk, struct sk_buff_head *list,
77479 +__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
77480 struct sk_buff *head, struct sk_buff *tail,
77481 u32 start, u32 end)
77482 {
77483 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
77484 index db7bfad..bfea796 100644
77485 --- a/net/ipv4/tcp_ipv4.c
77486 +++ b/net/ipv4/tcp_ipv4.c
77487 @@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
77488 EXPORT_SYMBOL(sysctl_tcp_low_latency);
77489
77490
77491 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77492 +extern int grsec_enable_blackhole;
77493 +#endif
77494 +
77495 #ifdef CONFIG_TCP_MD5SIG
77496 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
77497 __be32 daddr, __be32 saddr, const struct tcphdr *th);
77498 @@ -1664,6 +1668,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
77499 return 0;
77500
77501 reset:
77502 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77503 + if (!grsec_enable_blackhole)
77504 +#endif
77505 tcp_v4_send_reset(rsk, skb);
77506 discard:
77507 kfree_skb(skb);
77508 @@ -1764,12 +1771,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
77509 TCP_SKB_CB(skb)->sacked = 0;
77510
77511 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
77512 - if (!sk)
77513 + if (!sk) {
77514 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77515 + ret = 1;
77516 +#endif
77517 goto no_tcp_socket;
77518 -
77519 + }
77520 process:
77521 - if (sk->sk_state == TCP_TIME_WAIT)
77522 + if (sk->sk_state == TCP_TIME_WAIT) {
77523 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77524 + ret = 2;
77525 +#endif
77526 goto do_time_wait;
77527 + }
77528
77529 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
77530 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
77531 @@ -1820,6 +1834,10 @@ no_tcp_socket:
77532 bad_packet:
77533 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
77534 } else {
77535 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77536 + if (!grsec_enable_blackhole || (ret == 1 &&
77537 + (skb->dev->flags & IFF_LOOPBACK)))
77538 +#endif
77539 tcp_v4_send_reset(NULL, skb);
77540 }
77541
77542 @@ -2415,7 +2433,11 @@ static void get_openreq4(const struct sock *sk, const struct request_sock *req,
77543 0, /* non standard timer */
77544 0, /* open_requests have no inode */
77545 atomic_read(&sk->sk_refcnt),
77546 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77547 + NULL,
77548 +#else
77549 req,
77550 +#endif
77551 len);
77552 }
77553
77554 @@ -2465,7 +2487,12 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
77555 sock_i_uid(sk),
77556 icsk->icsk_probes_out,
77557 sock_i_ino(sk),
77558 - atomic_read(&sk->sk_refcnt), sk,
77559 + atomic_read(&sk->sk_refcnt),
77560 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77561 + NULL,
77562 +#else
77563 + sk,
77564 +#endif
77565 jiffies_to_clock_t(icsk->icsk_rto),
77566 jiffies_to_clock_t(icsk->icsk_ack.ato),
77567 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
77568 @@ -2493,7 +2520,13 @@ static void get_timewait4_sock(const struct inet_timewait_sock *tw,
77569 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK%n",
77570 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
77571 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
77572 - atomic_read(&tw->tw_refcnt), tw, len);
77573 + atomic_read(&tw->tw_refcnt),
77574 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77575 + NULL,
77576 +#else
77577 + tw,
77578 +#endif
77579 + len);
77580 }
77581
77582 #define TMPSZ 150
77583 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
77584 index 6ff7f10..38de56e 100644
77585 --- a/net/ipv4/tcp_minisocks.c
77586 +++ b/net/ipv4/tcp_minisocks.c
77587 @@ -27,6 +27,10 @@
77588 #include <net/inet_common.h>
77589 #include <net/xfrm.h>
77590
77591 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77592 +extern int grsec_enable_blackhole;
77593 +#endif
77594 +
77595 int sysctl_tcp_syncookies __read_mostly = 1;
77596 EXPORT_SYMBOL(sysctl_tcp_syncookies);
77597
77598 @@ -707,6 +711,10 @@ listen_overflow:
77599
77600 embryonic_reset:
77601 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
77602 +
77603 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77604 + if (!grsec_enable_blackhole)
77605 +#endif
77606 if (!(flg & TCP_FLAG_RST))
77607 req->rsk_ops->send_reset(sk, skb);
77608
77609 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
77610 index 4526fe6..1a34e43 100644
77611 --- a/net/ipv4/tcp_probe.c
77612 +++ b/net/ipv4/tcp_probe.c
77613 @@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
77614 if (cnt + width >= len)
77615 break;
77616
77617 - if (copy_to_user(buf + cnt, tbuf, width))
77618 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
77619 return -EFAULT;
77620 cnt += width;
77621 }
77622 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
77623 index b774a03..3873efe 100644
77624 --- a/net/ipv4/tcp_timer.c
77625 +++ b/net/ipv4/tcp_timer.c
77626 @@ -22,6 +22,10 @@
77627 #include <linux/gfp.h>
77628 #include <net/tcp.h>
77629
77630 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77631 +extern int grsec_lastack_retries;
77632 +#endif
77633 +
77634 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
77635 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
77636 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
77637 @@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
77638 }
77639 }
77640
77641 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77642 + if ((sk->sk_state == TCP_LAST_ACK) &&
77643 + (grsec_lastack_retries > 0) &&
77644 + (grsec_lastack_retries < retry_until))
77645 + retry_until = grsec_lastack_retries;
77646 +#endif
77647 +
77648 if (retransmits_timed_out(sk, retry_until,
77649 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
77650 /* Has it gone just too far? */
77651 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
77652 index 2814f66..fa2b223 100644
77653 --- a/net/ipv4/udp.c
77654 +++ b/net/ipv4/udp.c
77655 @@ -87,6 +87,7 @@
77656 #include <linux/types.h>
77657 #include <linux/fcntl.h>
77658 #include <linux/module.h>
77659 +#include <linux/security.h>
77660 #include <linux/socket.h>
77661 #include <linux/sockios.h>
77662 #include <linux/igmp.h>
77663 @@ -111,6 +112,10 @@
77664 #include <trace/events/skb.h>
77665 #include "udp_impl.h"
77666
77667 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77668 +extern int grsec_enable_blackhole;
77669 +#endif
77670 +
77671 struct udp_table udp_table __read_mostly;
77672 EXPORT_SYMBOL(udp_table);
77673
77674 @@ -569,6 +574,9 @@ found:
77675 return s;
77676 }
77677
77678 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
77679 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
77680 +
77681 /*
77682 * This routine is called by the ICMP module when it gets some
77683 * sort of error condition. If err < 0 then the socket should
77684 @@ -864,9 +872,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
77685 dport = usin->sin_port;
77686 if (dport == 0)
77687 return -EINVAL;
77688 +
77689 + err = gr_search_udp_sendmsg(sk, usin);
77690 + if (err)
77691 + return err;
77692 } else {
77693 if (sk->sk_state != TCP_ESTABLISHED)
77694 return -EDESTADDRREQ;
77695 +
77696 + err = gr_search_udp_sendmsg(sk, NULL);
77697 + if (err)
77698 + return err;
77699 +
77700 daddr = inet->inet_daddr;
77701 dport = inet->inet_dport;
77702 /* Open fast path for connected socket.
77703 @@ -1108,7 +1125,7 @@ static unsigned int first_packet_length(struct sock *sk)
77704 udp_lib_checksum_complete(skb)) {
77705 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
77706 IS_UDPLITE(sk));
77707 - atomic_inc(&sk->sk_drops);
77708 + atomic_inc_unchecked(&sk->sk_drops);
77709 __skb_unlink(skb, rcvq);
77710 __skb_queue_tail(&list_kill, skb);
77711 }
77712 @@ -1194,6 +1211,10 @@ try_again:
77713 if (!skb)
77714 goto out;
77715
77716 + err = gr_search_udp_recvmsg(sk, skb);
77717 + if (err)
77718 + goto out_free;
77719 +
77720 ulen = skb->len - sizeof(struct udphdr);
77721 copied = len;
77722 if (copied > ulen)
77723 @@ -1227,7 +1248,7 @@ try_again:
77724 if (unlikely(err)) {
77725 trace_kfree_skb(skb, udp_recvmsg);
77726 if (!peeked) {
77727 - atomic_inc(&sk->sk_drops);
77728 + atomic_inc_unchecked(&sk->sk_drops);
77729 UDP_INC_STATS_USER(sock_net(sk),
77730 UDP_MIB_INERRORS, is_udplite);
77731 }
77732 @@ -1510,7 +1531,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
77733
77734 drop:
77735 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
77736 - atomic_inc(&sk->sk_drops);
77737 + atomic_inc_unchecked(&sk->sk_drops);
77738 kfree_skb(skb);
77739 return -1;
77740 }
77741 @@ -1529,7 +1550,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
77742 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
77743
77744 if (!skb1) {
77745 - atomic_inc(&sk->sk_drops);
77746 + atomic_inc_unchecked(&sk->sk_drops);
77747 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
77748 IS_UDPLITE(sk));
77749 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
77750 @@ -1698,6 +1719,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
77751 goto csum_error;
77752
77753 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
77754 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77755 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
77756 +#endif
77757 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
77758
77759 /*
77760 @@ -2116,8 +2140,13 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
77761 sk_wmem_alloc_get(sp),
77762 sk_rmem_alloc_get(sp),
77763 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
77764 - atomic_read(&sp->sk_refcnt), sp,
77765 - atomic_read(&sp->sk_drops), len);
77766 + atomic_read(&sp->sk_refcnt),
77767 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77768 + NULL,
77769 +#else
77770 + sp,
77771 +#endif
77772 + atomic_read_unchecked(&sp->sk_drops), len);
77773 }
77774
77775 int udp4_seq_show(struct seq_file *seq, void *v)
77776 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
77777 index b10374d..0baa1f9 100644
77778 --- a/net/ipv6/addrconf.c
77779 +++ b/net/ipv6/addrconf.c
77780 @@ -2144,7 +2144,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
77781 p.iph.ihl = 5;
77782 p.iph.protocol = IPPROTO_IPV6;
77783 p.iph.ttl = 64;
77784 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
77785 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
77786
77787 if (ops->ndo_do_ioctl) {
77788 mm_segment_t oldfs = get_fs();
77789 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
77790 index ba6d13d..6899122 100644
77791 --- a/net/ipv6/ipv6_sockglue.c
77792 +++ b/net/ipv6/ipv6_sockglue.c
77793 @@ -989,7 +989,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
77794 if (sk->sk_type != SOCK_STREAM)
77795 return -ENOPROTOOPT;
77796
77797 - msg.msg_control = optval;
77798 + msg.msg_control = (void __force_kernel *)optval;
77799 msg.msg_controllen = len;
77800 msg.msg_flags = flags;
77801
77802 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
77803 index d7cb045..8c0ded6 100644
77804 --- a/net/ipv6/netfilter/ip6_tables.c
77805 +++ b/net/ipv6/netfilter/ip6_tables.c
77806 @@ -1078,14 +1078,14 @@ static int compat_table_info(const struct xt_table_info *info,
77807 #endif
77808
77809 static int get_info(struct net *net, void __user *user,
77810 - const int *len, int compat)
77811 + int len, int compat)
77812 {
77813 char name[XT_TABLE_MAXNAMELEN];
77814 struct xt_table *t;
77815 int ret;
77816
77817 - if (*len != sizeof(struct ip6t_getinfo)) {
77818 - duprintf("length %u != %zu\n", *len,
77819 + if (len != sizeof(struct ip6t_getinfo)) {
77820 + duprintf("length %u != %zu\n", len,
77821 sizeof(struct ip6t_getinfo));
77822 return -EINVAL;
77823 }
77824 @@ -1122,7 +1122,7 @@ static int get_info(struct net *net, void __user *user,
77825 info.size = private->size;
77826 strcpy(info.name, name);
77827
77828 - if (copy_to_user(user, &info, *len) != 0)
77829 + if (copy_to_user(user, &info, len) != 0)
77830 ret = -EFAULT;
77831 else
77832 ret = 0;
77833 @@ -1976,7 +1976,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77834
77835 switch (cmd) {
77836 case IP6T_SO_GET_INFO:
77837 - ret = get_info(sock_net(sk), user, len, 1);
77838 + ret = get_info(sock_net(sk), user, *len, 1);
77839 break;
77840 case IP6T_SO_GET_ENTRIES:
77841 ret = compat_get_entries(sock_net(sk), user, len);
77842 @@ -2023,7 +2023,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77843
77844 switch (cmd) {
77845 case IP6T_SO_GET_INFO:
77846 - ret = get_info(sock_net(sk), user, len, 0);
77847 + ret = get_info(sock_net(sk), user, *len, 0);
77848 break;
77849
77850 case IP6T_SO_GET_ENTRIES:
77851 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
77852 index 4a5f78b..3f22ebe 100644
77853 --- a/net/ipv6/raw.c
77854 +++ b/net/ipv6/raw.c
77855 @@ -379,7 +379,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
77856 {
77857 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
77858 skb_checksum_complete(skb)) {
77859 - atomic_inc(&sk->sk_drops);
77860 + atomic_inc_unchecked(&sk->sk_drops);
77861 kfree_skb(skb);
77862 return NET_RX_DROP;
77863 }
77864 @@ -407,7 +407,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
77865 struct raw6_sock *rp = raw6_sk(sk);
77866
77867 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
77868 - atomic_inc(&sk->sk_drops);
77869 + atomic_inc_unchecked(&sk->sk_drops);
77870 kfree_skb(skb);
77871 return NET_RX_DROP;
77872 }
77873 @@ -431,7 +431,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
77874
77875 if (inet->hdrincl) {
77876 if (skb_checksum_complete(skb)) {
77877 - atomic_inc(&sk->sk_drops);
77878 + atomic_inc_unchecked(&sk->sk_drops);
77879 kfree_skb(skb);
77880 return NET_RX_DROP;
77881 }
77882 @@ -604,7 +604,7 @@ out:
77883 return err;
77884 }
77885
77886 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
77887 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
77888 struct flowi6 *fl6, struct dst_entry **dstp,
77889 unsigned int flags)
77890 {
77891 @@ -916,12 +916,15 @@ do_confirm:
77892 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
77893 char __user *optval, int optlen)
77894 {
77895 + struct icmp6_filter filter;
77896 +
77897 switch (optname) {
77898 case ICMPV6_FILTER:
77899 if (optlen > sizeof(struct icmp6_filter))
77900 optlen = sizeof(struct icmp6_filter);
77901 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
77902 + if (copy_from_user(&filter, optval, optlen))
77903 return -EFAULT;
77904 + raw6_sk(sk)->filter = filter;
77905 return 0;
77906 default:
77907 return -ENOPROTOOPT;
77908 @@ -934,6 +937,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
77909 char __user *optval, int __user *optlen)
77910 {
77911 int len;
77912 + struct icmp6_filter filter;
77913
77914 switch (optname) {
77915 case ICMPV6_FILTER:
77916 @@ -945,7 +949,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
77917 len = sizeof(struct icmp6_filter);
77918 if (put_user(len, optlen))
77919 return -EFAULT;
77920 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
77921 + filter = raw6_sk(sk)->filter;
77922 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
77923 return -EFAULT;
77924 return 0;
77925 default:
77926 @@ -1252,7 +1257,13 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
77927 0, 0L, 0,
77928 sock_i_uid(sp), 0,
77929 sock_i_ino(sp),
77930 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
77931 + atomic_read(&sp->sk_refcnt),
77932 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77933 + NULL,
77934 +#else
77935 + sp,
77936 +#endif
77937 + atomic_read_unchecked(&sp->sk_drops));
77938 }
77939
77940 static int raw6_seq_show(struct seq_file *seq, void *v)
77941 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
77942 index 7e32d42..5d975ba 100644
77943 --- a/net/ipv6/tcp_ipv6.c
77944 +++ b/net/ipv6/tcp_ipv6.c
77945 @@ -106,6 +106,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
77946 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
77947 }
77948
77949 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77950 +extern int grsec_enable_blackhole;
77951 +#endif
77952 +
77953 static void tcp_v6_hash(struct sock *sk)
77954 {
77955 if (sk->sk_state != TCP_CLOSE) {
77956 @@ -1511,6 +1515,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
77957 return 0;
77958
77959 reset:
77960 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77961 + if (!grsec_enable_blackhole)
77962 +#endif
77963 tcp_v6_send_reset(sk, skb);
77964 discard:
77965 if (opt_skb)
77966 @@ -1592,12 +1599,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
77967 TCP_SKB_CB(skb)->sacked = 0;
77968
77969 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
77970 - if (!sk)
77971 + if (!sk) {
77972 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77973 + ret = 1;
77974 +#endif
77975 goto no_tcp_socket;
77976 + }
77977
77978 process:
77979 - if (sk->sk_state == TCP_TIME_WAIT)
77980 + if (sk->sk_state == TCP_TIME_WAIT) {
77981 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77982 + ret = 2;
77983 +#endif
77984 goto do_time_wait;
77985 + }
77986
77987 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
77988 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
77989 @@ -1646,6 +1661,10 @@ no_tcp_socket:
77990 bad_packet:
77991 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
77992 } else {
77993 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77994 + if (!grsec_enable_blackhole || (ret == 1 &&
77995 + (skb->dev->flags & IFF_LOOPBACK)))
77996 +#endif
77997 tcp_v6_send_reset(NULL, skb);
77998 }
77999
78000 @@ -1857,7 +1876,13 @@ static void get_openreq6(struct seq_file *seq,
78001 uid,
78002 0, /* non standard timer */
78003 0, /* open_requests have no inode */
78004 - 0, req);
78005 + 0,
78006 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78007 + NULL
78008 +#else
78009 + req
78010 +#endif
78011 + );
78012 }
78013
78014 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
78015 @@ -1907,7 +1932,12 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
78016 sock_i_uid(sp),
78017 icsk->icsk_probes_out,
78018 sock_i_ino(sp),
78019 - atomic_read(&sp->sk_refcnt), sp,
78020 + atomic_read(&sp->sk_refcnt),
78021 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78022 + NULL,
78023 +#else
78024 + sp,
78025 +#endif
78026 jiffies_to_clock_t(icsk->icsk_rto),
78027 jiffies_to_clock_t(icsk->icsk_ack.ato),
78028 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
78029 @@ -1942,7 +1972,13 @@ static void get_timewait6_sock(struct seq_file *seq,
78030 dest->s6_addr32[2], dest->s6_addr32[3], destp,
78031 tw->tw_substate, 0, 0,
78032 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
78033 - atomic_read(&tw->tw_refcnt), tw);
78034 + atomic_read(&tw->tw_refcnt),
78035 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78036 + NULL
78037 +#else
78038 + tw
78039 +#endif
78040 + );
78041 }
78042
78043 static int tcp6_seq_show(struct seq_file *seq, void *v)
78044 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
78045 index 07e2bfe..328dae8 100644
78046 --- a/net/ipv6/udp.c
78047 +++ b/net/ipv6/udp.c
78048 @@ -51,6 +51,10 @@
78049 #include <trace/events/skb.h>
78050 #include "udp_impl.h"
78051
78052 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78053 +extern int grsec_enable_blackhole;
78054 +#endif
78055 +
78056 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
78057 {
78058 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
78059 @@ -395,7 +399,7 @@ try_again:
78060 if (unlikely(err)) {
78061 trace_kfree_skb(skb, udpv6_recvmsg);
78062 if (!peeked) {
78063 - atomic_inc(&sk->sk_drops);
78064 + atomic_inc_unchecked(&sk->sk_drops);
78065 if (is_udp4)
78066 UDP_INC_STATS_USER(sock_net(sk),
78067 UDP_MIB_INERRORS,
78068 @@ -633,7 +637,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
78069 return rc;
78070 drop:
78071 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
78072 - atomic_inc(&sk->sk_drops);
78073 + atomic_inc_unchecked(&sk->sk_drops);
78074 kfree_skb(skb);
78075 return -1;
78076 }
78077 @@ -691,7 +695,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
78078 if (likely(skb1 == NULL))
78079 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
78080 if (!skb1) {
78081 - atomic_inc(&sk->sk_drops);
78082 + atomic_inc_unchecked(&sk->sk_drops);
78083 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
78084 IS_UDPLITE(sk));
78085 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
78086 @@ -862,6 +866,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
78087 goto discard;
78088
78089 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
78090 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78091 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
78092 +#endif
78093 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
78094
78095 kfree_skb(skb);
78096 @@ -1471,8 +1478,13 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
78097 0, 0L, 0,
78098 sock_i_uid(sp), 0,
78099 sock_i_ino(sp),
78100 - atomic_read(&sp->sk_refcnt), sp,
78101 - atomic_read(&sp->sk_drops));
78102 + atomic_read(&sp->sk_refcnt),
78103 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78104 + NULL,
78105 +#else
78106 + sp,
78107 +#endif
78108 + atomic_read_unchecked(&sp->sk_drops));
78109 }
78110
78111 int udp6_seq_show(struct seq_file *seq, void *v)
78112 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
78113 index 6b9d5a0..4dffaf1 100644
78114 --- a/net/irda/ircomm/ircomm_tty.c
78115 +++ b/net/irda/ircomm/ircomm_tty.c
78116 @@ -281,16 +281,16 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
78117 add_wait_queue(&self->open_wait, &wait);
78118
78119 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
78120 - __FILE__,__LINE__, tty->driver->name, self->open_count );
78121 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
78122
78123 /* As far as I can see, we protect open_count - Jean II */
78124 spin_lock_irqsave(&self->spinlock, flags);
78125 if (!tty_hung_up_p(filp)) {
78126 extra_count = 1;
78127 - self->open_count--;
78128 + local_dec(&self->open_count);
78129 }
78130 spin_unlock_irqrestore(&self->spinlock, flags);
78131 - self->blocked_open++;
78132 + local_inc(&self->blocked_open);
78133
78134 while (1) {
78135 if (tty->termios->c_cflag & CBAUD) {
78136 @@ -330,7 +330,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
78137 }
78138
78139 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
78140 - __FILE__,__LINE__, tty->driver->name, self->open_count );
78141 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
78142
78143 schedule();
78144 }
78145 @@ -341,13 +341,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
78146 if (extra_count) {
78147 /* ++ is not atomic, so this should be protected - Jean II */
78148 spin_lock_irqsave(&self->spinlock, flags);
78149 - self->open_count++;
78150 + local_inc(&self->open_count);
78151 spin_unlock_irqrestore(&self->spinlock, flags);
78152 }
78153 - self->blocked_open--;
78154 + local_dec(&self->blocked_open);
78155
78156 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
78157 - __FILE__,__LINE__, tty->driver->name, self->open_count);
78158 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
78159
78160 if (!retval)
78161 self->flags |= ASYNC_NORMAL_ACTIVE;
78162 @@ -412,14 +412,14 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
78163 }
78164 /* ++ is not atomic, so this should be protected - Jean II */
78165 spin_lock_irqsave(&self->spinlock, flags);
78166 - self->open_count++;
78167 + local_inc(&self->open_count);
78168
78169 tty->driver_data = self;
78170 self->tty = tty;
78171 spin_unlock_irqrestore(&self->spinlock, flags);
78172
78173 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
78174 - self->line, self->open_count);
78175 + self->line, local_read(&self->open_count));
78176
78177 /* Not really used by us, but lets do it anyway */
78178 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
78179 @@ -505,7 +505,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
78180 return;
78181 }
78182
78183 - if ((tty->count == 1) && (self->open_count != 1)) {
78184 + if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
78185 /*
78186 * Uh, oh. tty->count is 1, which means that the tty
78187 * structure will be freed. state->count should always
78188 @@ -515,16 +515,16 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
78189 */
78190 IRDA_DEBUG(0, "%s(), bad serial port count; "
78191 "tty->count is 1, state->count is %d\n", __func__ ,
78192 - self->open_count);
78193 - self->open_count = 1;
78194 + local_read(&self->open_count));
78195 + local_set(&self->open_count, 1);
78196 }
78197
78198 - if (--self->open_count < 0) {
78199 + if (local_dec_return(&self->open_count) < 0) {
78200 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
78201 - __func__, self->line, self->open_count);
78202 - self->open_count = 0;
78203 + __func__, self->line, local_read(&self->open_count));
78204 + local_set(&self->open_count, 0);
78205 }
78206 - if (self->open_count) {
78207 + if (local_read(&self->open_count)) {
78208 spin_unlock_irqrestore(&self->spinlock, flags);
78209
78210 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
78211 @@ -556,7 +556,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
78212 tty->closing = 0;
78213 self->tty = NULL;
78214
78215 - if (self->blocked_open) {
78216 + if (local_read(&self->blocked_open)) {
78217 if (self->close_delay)
78218 schedule_timeout_interruptible(self->close_delay);
78219 wake_up_interruptible(&self->open_wait);
78220 @@ -1008,7 +1008,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
78221 spin_lock_irqsave(&self->spinlock, flags);
78222 self->flags &= ~ASYNC_NORMAL_ACTIVE;
78223 self->tty = NULL;
78224 - self->open_count = 0;
78225 + local_set(&self->open_count, 0);
78226 spin_unlock_irqrestore(&self->spinlock, flags);
78227
78228 wake_up_interruptible(&self->open_wait);
78229 @@ -1355,7 +1355,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
78230 seq_putc(m, '\n');
78231
78232 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
78233 - seq_printf(m, "Open count: %d\n", self->open_count);
78234 + seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
78235 seq_printf(m, "Max data size: %d\n", self->max_data_size);
78236 seq_printf(m, "Max header size: %d\n", self->max_header_size);
78237
78238 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
78239 index cd6f7a9..e63fe89 100644
78240 --- a/net/iucv/af_iucv.c
78241 +++ b/net/iucv/af_iucv.c
78242 @@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
78243
78244 write_lock_bh(&iucv_sk_list.lock);
78245
78246 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
78247 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
78248 while (__iucv_get_sock_by_name(name)) {
78249 sprintf(name, "%08x",
78250 - atomic_inc_return(&iucv_sk_list.autobind_name));
78251 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
78252 }
78253
78254 write_unlock_bh(&iucv_sk_list.lock);
78255 diff --git a/net/key/af_key.c b/net/key/af_key.c
78256 index 34e4185..8823368 100644
78257 --- a/net/key/af_key.c
78258 +++ b/net/key/af_key.c
78259 @@ -3016,10 +3016,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
78260 static u32 get_acqseq(void)
78261 {
78262 u32 res;
78263 - static atomic_t acqseq;
78264 + static atomic_unchecked_t acqseq;
78265
78266 do {
78267 - res = atomic_inc_return(&acqseq);
78268 + res = atomic_inc_return_unchecked(&acqseq);
78269 } while (!res);
78270 return res;
78271 }
78272 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
78273 index bb61f77..3788d63 100644
78274 --- a/net/mac80211/ieee80211_i.h
78275 +++ b/net/mac80211/ieee80211_i.h
78276 @@ -28,6 +28,7 @@
78277 #include <net/ieee80211_radiotap.h>
78278 #include <net/cfg80211.h>
78279 #include <net/mac80211.h>
78280 +#include <asm/local.h>
78281 #include "key.h"
78282 #include "sta_info.h"
78283 #include "debug.h"
78284 @@ -840,7 +841,7 @@ struct ieee80211_local {
78285 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
78286 spinlock_t queue_stop_reason_lock;
78287
78288 - int open_count;
78289 + local_t open_count;
78290 int monitors, cooked_mntrs;
78291 /* number of interfaces with corresponding FIF_ flags */
78292 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
78293 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
78294 index c93d395..a305570 100644
78295 --- a/net/mac80211/iface.c
78296 +++ b/net/mac80211/iface.c
78297 @@ -454,7 +454,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
78298 break;
78299 }
78300
78301 - if (local->open_count == 0) {
78302 + if (local_read(&local->open_count) == 0) {
78303 res = drv_start(local);
78304 if (res)
78305 goto err_del_bss;
78306 @@ -497,7 +497,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
78307 break;
78308 }
78309
78310 - if (local->monitors == 0 && local->open_count == 0) {
78311 + if (local->monitors == 0 && local_read(&local->open_count) == 0) {
78312 res = ieee80211_add_virtual_monitor(local);
78313 if (res)
78314 goto err_stop;
78315 @@ -594,7 +594,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
78316 mutex_unlock(&local->mtx);
78317
78318 if (coming_up)
78319 - local->open_count++;
78320 + local_inc(&local->open_count);
78321
78322 if (hw_reconf_flags)
78323 ieee80211_hw_config(local, hw_reconf_flags);
78324 @@ -607,7 +607,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
78325 err_del_interface:
78326 drv_remove_interface(local, sdata);
78327 err_stop:
78328 - if (!local->open_count)
78329 + if (!local_read(&local->open_count))
78330 drv_stop(local);
78331 err_del_bss:
78332 sdata->bss = NULL;
78333 @@ -736,7 +736,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
78334 }
78335
78336 if (going_down)
78337 - local->open_count--;
78338 + local_dec(&local->open_count);
78339
78340 switch (sdata->vif.type) {
78341 case NL80211_IFTYPE_AP_VLAN:
78342 @@ -796,7 +796,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
78343
78344 ieee80211_recalc_ps(local, -1);
78345
78346 - if (local->open_count == 0) {
78347 + if (local_read(&local->open_count) == 0) {
78348 if (local->ops->napi_poll)
78349 napi_disable(&local->napi);
78350 ieee80211_clear_tx_pending(local);
78351 @@ -828,7 +828,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
78352 }
78353 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
78354
78355 - if (local->monitors == local->open_count && local->monitors > 0)
78356 + if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
78357 ieee80211_add_virtual_monitor(local);
78358 }
78359
78360 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
78361 index c26e231..8916637 100644
78362 --- a/net/mac80211/main.c
78363 +++ b/net/mac80211/main.c
78364 @@ -166,7 +166,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
78365 local->hw.conf.power_level = power;
78366 }
78367
78368 - if (changed && local->open_count) {
78369 + if (changed && local_read(&local->open_count)) {
78370 ret = drv_config(local, changed);
78371 /*
78372 * Goal:
78373 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
78374 index 5c572e7..ecf75ce 100644
78375 --- a/net/mac80211/pm.c
78376 +++ b/net/mac80211/pm.c
78377 @@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
78378 struct ieee80211_sub_if_data *sdata;
78379 struct sta_info *sta;
78380
78381 - if (!local->open_count)
78382 + if (!local_read(&local->open_count))
78383 goto suspend;
78384
78385 ieee80211_scan_cancel(local);
78386 @@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
78387 cancel_work_sync(&local->dynamic_ps_enable_work);
78388 del_timer_sync(&local->dynamic_ps_timer);
78389
78390 - local->wowlan = wowlan && local->open_count;
78391 + local->wowlan = wowlan && local_read(&local->open_count);
78392 if (local->wowlan) {
78393 int err = drv_suspend(local, wowlan);
78394 if (err < 0) {
78395 @@ -143,7 +143,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
78396 drv_remove_interface(local, sdata);
78397
78398 /* stop hardware - this must stop RX */
78399 - if (local->open_count)
78400 + if (local_read(&local->open_count))
78401 ieee80211_stop_device(local);
78402
78403 suspend:
78404 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
78405 index 3313c11..bec9f17 100644
78406 --- a/net/mac80211/rate.c
78407 +++ b/net/mac80211/rate.c
78408 @@ -494,7 +494,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
78409
78410 ASSERT_RTNL();
78411
78412 - if (local->open_count)
78413 + if (local_read(&local->open_count))
78414 return -EBUSY;
78415
78416 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
78417 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
78418 index c97a065..ff61928 100644
78419 --- a/net/mac80211/rc80211_pid_debugfs.c
78420 +++ b/net/mac80211/rc80211_pid_debugfs.c
78421 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
78422
78423 spin_unlock_irqrestore(&events->lock, status);
78424
78425 - if (copy_to_user(buf, pb, p))
78426 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
78427 return -EFAULT;
78428
78429 return p;
78430 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
78431 index 1cfe6d5..c428ba3 100644
78432 --- a/net/mac80211/util.c
78433 +++ b/net/mac80211/util.c
78434 @@ -1279,7 +1279,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
78435 }
78436 #endif
78437 /* everything else happens only if HW was up & running */
78438 - if (!local->open_count)
78439 + if (!local_read(&local->open_count))
78440 goto wake_up;
78441
78442 /*
78443 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
78444 index c19b214..471fad1 100644
78445 --- a/net/netfilter/Kconfig
78446 +++ b/net/netfilter/Kconfig
78447 @@ -872,6 +872,16 @@ config NETFILTER_XT_MATCH_ESP
78448
78449 To compile it as a module, choose M here. If unsure, say N.
78450
78451 +config NETFILTER_XT_MATCH_GRADM
78452 + tristate '"gradm" match support'
78453 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
78454 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
78455 + ---help---
78456 + The gradm match allows to match on grsecurity RBAC being enabled.
78457 + It is useful when iptables rules are applied early on bootup to
78458 + prevent connections to the machine (except from a trusted host)
78459 + while the RBAC system is disabled.
78460 +
78461 config NETFILTER_XT_MATCH_HASHLIMIT
78462 tristate '"hashlimit" match support'
78463 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
78464 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
78465 index 1c5160f..145ae21 100644
78466 --- a/net/netfilter/Makefile
78467 +++ b/net/netfilter/Makefile
78468 @@ -90,6 +90,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
78469 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
78470 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
78471 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
78472 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
78473 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
78474 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
78475 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
78476 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
78477 index 1548df9..98ad9b4 100644
78478 --- a/net/netfilter/ipvs/ip_vs_conn.c
78479 +++ b/net/netfilter/ipvs/ip_vs_conn.c
78480 @@ -557,7 +557,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
78481 /* Increase the refcnt counter of the dest */
78482 atomic_inc(&dest->refcnt);
78483
78484 - conn_flags = atomic_read(&dest->conn_flags);
78485 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
78486 if (cp->protocol != IPPROTO_UDP)
78487 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
78488 flags = cp->flags;
78489 @@ -902,7 +902,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
78490 atomic_set(&cp->refcnt, 1);
78491
78492 atomic_set(&cp->n_control, 0);
78493 - atomic_set(&cp->in_pkts, 0);
78494 + atomic_set_unchecked(&cp->in_pkts, 0);
78495
78496 atomic_inc(&ipvs->conn_count);
78497 if (flags & IP_VS_CONN_F_NO_CPORT)
78498 @@ -1183,7 +1183,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
78499
78500 /* Don't drop the entry if its number of incoming packets is not
78501 located in [0, 8] */
78502 - i = atomic_read(&cp->in_pkts);
78503 + i = atomic_read_unchecked(&cp->in_pkts);
78504 if (i > 8 || i < 0) return 0;
78505
78506 if (!todrop_rate[i]) return 0;
78507 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
78508 index b54ecce..fc5f6cf 100644
78509 --- a/net/netfilter/ipvs/ip_vs_core.c
78510 +++ b/net/netfilter/ipvs/ip_vs_core.c
78511 @@ -562,7 +562,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
78512 ret = cp->packet_xmit(skb, cp, pd->pp);
78513 /* do not touch skb anymore */
78514
78515 - atomic_inc(&cp->in_pkts);
78516 + atomic_inc_unchecked(&cp->in_pkts);
78517 ip_vs_conn_put(cp);
78518 return ret;
78519 }
78520 @@ -1611,7 +1611,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
78521 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
78522 pkts = sysctl_sync_threshold(ipvs);
78523 else
78524 - pkts = atomic_add_return(1, &cp->in_pkts);
78525 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
78526
78527 if (ipvs->sync_state & IP_VS_STATE_MASTER)
78528 ip_vs_sync_conn(net, cp, pkts);
78529 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
78530 index f51013c..c99ee52 100644
78531 --- a/net/netfilter/ipvs/ip_vs_ctl.c
78532 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
78533 @@ -788,7 +788,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
78534 ip_vs_rs_hash(ipvs, dest);
78535 write_unlock_bh(&ipvs->rs_lock);
78536 }
78537 - atomic_set(&dest->conn_flags, conn_flags);
78538 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
78539
78540 /* bind the service */
78541 if (!dest->svc) {
78542 @@ -2076,7 +2076,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
78543 " %-7s %-6d %-10d %-10d\n",
78544 &dest->addr.in6,
78545 ntohs(dest->port),
78546 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
78547 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
78548 atomic_read(&dest->weight),
78549 atomic_read(&dest->activeconns),
78550 atomic_read(&dest->inactconns));
78551 @@ -2087,7 +2087,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
78552 "%-7s %-6d %-10d %-10d\n",
78553 ntohl(dest->addr.ip),
78554 ntohs(dest->port),
78555 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
78556 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
78557 atomic_read(&dest->weight),
78558 atomic_read(&dest->activeconns),
78559 atomic_read(&dest->inactconns));
78560 @@ -2557,7 +2557,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
78561
78562 entry.addr = dest->addr.ip;
78563 entry.port = dest->port;
78564 - entry.conn_flags = atomic_read(&dest->conn_flags);
78565 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
78566 entry.weight = atomic_read(&dest->weight);
78567 entry.u_threshold = dest->u_threshold;
78568 entry.l_threshold = dest->l_threshold;
78569 @@ -3092,7 +3092,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
78570 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
78571 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
78572 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
78573 - (atomic_read(&dest->conn_flags) &
78574 + (atomic_read_unchecked(&dest->conn_flags) &
78575 IP_VS_CONN_F_FWD_MASK)) ||
78576 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
78577 atomic_read(&dest->weight)) ||
78578 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
78579 index effa10c..9058928 100644
78580 --- a/net/netfilter/ipvs/ip_vs_sync.c
78581 +++ b/net/netfilter/ipvs/ip_vs_sync.c
78582 @@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
78583 cp = cp->control;
78584 if (cp) {
78585 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
78586 - pkts = atomic_add_return(1, &cp->in_pkts);
78587 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
78588 else
78589 pkts = sysctl_sync_threshold(ipvs);
78590 ip_vs_sync_conn(net, cp->control, pkts);
78591 @@ -758,7 +758,7 @@ control:
78592 if (!cp)
78593 return;
78594 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
78595 - pkts = atomic_add_return(1, &cp->in_pkts);
78596 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
78597 else
78598 pkts = sysctl_sync_threshold(ipvs);
78599 goto sloop;
78600 @@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
78601
78602 if (opt)
78603 memcpy(&cp->in_seq, opt, sizeof(*opt));
78604 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
78605 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
78606 cp->state = state;
78607 cp->old_state = cp->state;
78608 /*
78609 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
78610 index c3c6291..3376d73 100644
78611 --- a/net/netfilter/ipvs/ip_vs_xmit.c
78612 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
78613 @@ -1157,7 +1157,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
78614 else
78615 rc = NF_ACCEPT;
78616 /* do not touch skb anymore */
78617 - atomic_inc(&cp->in_pkts);
78618 + atomic_inc_unchecked(&cp->in_pkts);
78619 goto out;
78620 }
78621
78622 @@ -1278,7 +1278,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
78623 else
78624 rc = NF_ACCEPT;
78625 /* do not touch skb anymore */
78626 - atomic_inc(&cp->in_pkts);
78627 + atomic_inc_unchecked(&cp->in_pkts);
78628 goto out;
78629 }
78630
78631 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
78632 index 2ceec64..a5b8a61 100644
78633 --- a/net/netfilter/nf_conntrack_core.c
78634 +++ b/net/netfilter/nf_conntrack_core.c
78635 @@ -1529,6 +1529,10 @@ err_extend:
78636 #define UNCONFIRMED_NULLS_VAL ((1<<30)+0)
78637 #define DYING_NULLS_VAL ((1<<30)+1)
78638
78639 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78640 +static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
78641 +#endif
78642 +
78643 static int nf_conntrack_init_net(struct net *net)
78644 {
78645 int ret;
78646 @@ -1542,7 +1546,11 @@ static int nf_conntrack_init_net(struct net *net)
78647 goto err_stat;
78648 }
78649
78650 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78651 + net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
78652 +#else
78653 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
78654 +#endif
78655 if (!net->ct.slabname) {
78656 ret = -ENOMEM;
78657 goto err_slabname;
78658 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
78659 index 5cfb5be..217c6d8 100644
78660 --- a/net/netfilter/nfnetlink_log.c
78661 +++ b/net/netfilter/nfnetlink_log.c
78662 @@ -70,7 +70,7 @@ struct nfulnl_instance {
78663 };
78664
78665 static DEFINE_SPINLOCK(instances_lock);
78666 -static atomic_t global_seq;
78667 +static atomic_unchecked_t global_seq;
78668
78669 #define INSTANCE_BUCKETS 16
78670 static struct hlist_head instance_table[INSTANCE_BUCKETS];
78671 @@ -523,7 +523,7 @@ __build_packet_message(struct nfulnl_instance *inst,
78672 /* global sequence number */
78673 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
78674 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
78675 - htonl(atomic_inc_return(&global_seq))))
78676 + htonl(atomic_inc_return_unchecked(&global_seq))))
78677 goto nla_put_failure;
78678
78679 if (data_len) {
78680 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
78681 new file mode 100644
78682 index 0000000..c566332
78683 --- /dev/null
78684 +++ b/net/netfilter/xt_gradm.c
78685 @@ -0,0 +1,51 @@
78686 +/*
78687 + * gradm match for netfilter
78688 + * Copyright © Zbigniew Krzystolik, 2010
78689 + *
78690 + * This program is free software; you can redistribute it and/or modify
78691 + * it under the terms of the GNU General Public License; either version
78692 + * 2 or 3 as published by the Free Software Foundation.
78693 + */
78694 +#include <linux/module.h>
78695 +#include <linux/moduleparam.h>
78696 +#include <linux/skbuff.h>
78697 +#include <linux/netfilter/x_tables.h>
78698 +#include <linux/grsecurity.h>
78699 +#include <linux/netfilter/xt_gradm.h>
78700 +
78701 +static bool
78702 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
78703 +{
78704 + const struct xt_gradm_mtinfo *info = par->matchinfo;
78705 + bool retval = false;
78706 + if (gr_acl_is_enabled())
78707 + retval = true;
78708 + return retval ^ info->invflags;
78709 +}
78710 +
78711 +static struct xt_match gradm_mt_reg __read_mostly = {
78712 + .name = "gradm",
78713 + .revision = 0,
78714 + .family = NFPROTO_UNSPEC,
78715 + .match = gradm_mt,
78716 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
78717 + .me = THIS_MODULE,
78718 +};
78719 +
78720 +static int __init gradm_mt_init(void)
78721 +{
78722 + return xt_register_match(&gradm_mt_reg);
78723 +}
78724 +
78725 +static void __exit gradm_mt_exit(void)
78726 +{
78727 + xt_unregister_match(&gradm_mt_reg);
78728 +}
78729 +
78730 +module_init(gradm_mt_init);
78731 +module_exit(gradm_mt_exit);
78732 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
78733 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
78734 +MODULE_LICENSE("GPL");
78735 +MODULE_ALIAS("ipt_gradm");
78736 +MODULE_ALIAS("ip6t_gradm");
78737 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
78738 index 4fe4fb4..87a89e5 100644
78739 --- a/net/netfilter/xt_statistic.c
78740 +++ b/net/netfilter/xt_statistic.c
78741 @@ -19,7 +19,7 @@
78742 #include <linux/module.h>
78743
78744 struct xt_statistic_priv {
78745 - atomic_t count;
78746 + atomic_unchecked_t count;
78747 } ____cacheline_aligned_in_smp;
78748
78749 MODULE_LICENSE("GPL");
78750 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
78751 break;
78752 case XT_STATISTIC_MODE_NTH:
78753 do {
78754 - oval = atomic_read(&info->master->count);
78755 + oval = atomic_read_unchecked(&info->master->count);
78756 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
78757 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
78758 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
78759 if (nval == 0)
78760 ret = !ret;
78761 break;
78762 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
78763 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
78764 if (info->master == NULL)
78765 return -ENOMEM;
78766 - atomic_set(&info->master->count, info->u.nth.count);
78767 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
78768
78769 return 0;
78770 }
78771 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
78772 index 0426b67..d6ddaca 100644
78773 --- a/net/netlink/af_netlink.c
78774 +++ b/net/netlink/af_netlink.c
78775 @@ -780,7 +780,7 @@ static void netlink_overrun(struct sock *sk)
78776 sk->sk_error_report(sk);
78777 }
78778 }
78779 - atomic_inc(&sk->sk_drops);
78780 + atomic_inc_unchecked(&sk->sk_drops);
78781 }
78782
78783 static struct sock *netlink_getsockbypid(struct sock *ssk, u32 pid)
78784 @@ -2070,7 +2070,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
78785 sk_wmem_alloc_get(s),
78786 nlk->cb,
78787 atomic_read(&s->sk_refcnt),
78788 - atomic_read(&s->sk_drops),
78789 + atomic_read_unchecked(&s->sk_drops),
78790 sock_i_ino(s)
78791 );
78792
78793 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
78794 index 7261eb8..44e8ac6 100644
78795 --- a/net/netrom/af_netrom.c
78796 +++ b/net/netrom/af_netrom.c
78797 @@ -838,6 +838,7 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
78798 struct sock *sk = sock->sk;
78799 struct nr_sock *nr = nr_sk(sk);
78800
78801 + memset(sax, 0, sizeof(*sax));
78802 lock_sock(sk);
78803 if (peer != 0) {
78804 if (sk->sk_state != TCP_ESTABLISHED) {
78805 @@ -852,7 +853,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
78806 *uaddr_len = sizeof(struct full_sockaddr_ax25);
78807 } else {
78808 sax->fsa_ax25.sax25_family = AF_NETROM;
78809 - sax->fsa_ax25.sax25_ndigis = 0;
78810 sax->fsa_ax25.sax25_call = nr->source_addr;
78811 *uaddr_len = sizeof(struct sockaddr_ax25);
78812 }
78813 diff --git a/net/nfc/llcp/sock.c b/net/nfc/llcp/sock.c
78814 index ddeb9aa..e18fffd 100644
78815 --- a/net/nfc/llcp/sock.c
78816 +++ b/net/nfc/llcp/sock.c
78817 @@ -443,15 +443,11 @@ static int llcp_sock_connect(struct socket *sock, struct sockaddr *_addr,
78818 pr_debug("sock %p sk %p flags 0x%x\n", sock, sk, flags);
78819
78820 if (!addr || len < sizeof(struct sockaddr_nfc) ||
78821 - addr->sa_family != AF_NFC) {
78822 - pr_err("Invalid socket\n");
78823 + addr->sa_family != AF_NFC)
78824 return -EINVAL;
78825 - }
78826
78827 - if (addr->service_name_len == 0 && addr->dsap == 0) {
78828 - pr_err("Missing service name or dsap\n");
78829 + if (addr->service_name_len == 0 && addr->dsap == 0)
78830 return -EINVAL;
78831 - }
78832
78833 pr_debug("addr dev_idx=%u target_idx=%u protocol=%u\n", addr->dev_idx,
78834 addr->target_idx, addr->nfc_protocol);
78835 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
78836 index c5c9e2a..4814ab1 100644
78837 --- a/net/packet/af_packet.c
78838 +++ b/net/packet/af_packet.c
78839 @@ -1689,7 +1689,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
78840
78841 spin_lock(&sk->sk_receive_queue.lock);
78842 po->stats.tp_packets++;
78843 - skb->dropcount = atomic_read(&sk->sk_drops);
78844 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
78845 __skb_queue_tail(&sk->sk_receive_queue, skb);
78846 spin_unlock(&sk->sk_receive_queue.lock);
78847 sk->sk_data_ready(sk, skb->len);
78848 @@ -1698,7 +1698,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
78849 drop_n_acct:
78850 spin_lock(&sk->sk_receive_queue.lock);
78851 po->stats.tp_drops++;
78852 - atomic_inc(&sk->sk_drops);
78853 + atomic_inc_unchecked(&sk->sk_drops);
78854 spin_unlock(&sk->sk_receive_queue.lock);
78855
78856 drop_n_restore:
78857 @@ -2642,6 +2642,7 @@ out:
78858
78859 static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
78860 {
78861 + struct sock_extended_err ee;
78862 struct sock_exterr_skb *serr;
78863 struct sk_buff *skb, *skb2;
78864 int copied, err;
78865 @@ -2663,8 +2664,9 @@ static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
78866 sock_recv_timestamp(msg, sk, skb);
78867
78868 serr = SKB_EXT_ERR(skb);
78869 + ee = serr->ee;
78870 put_cmsg(msg, SOL_PACKET, PACKET_TX_TIMESTAMP,
78871 - sizeof(serr->ee), &serr->ee);
78872 + sizeof ee, &ee);
78873
78874 msg->msg_flags |= MSG_ERRQUEUE;
78875 err = copied;
78876 @@ -3276,7 +3278,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
78877 case PACKET_HDRLEN:
78878 if (len > sizeof(int))
78879 len = sizeof(int);
78880 - if (copy_from_user(&val, optval, len))
78881 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
78882 return -EFAULT;
78883 switch (val) {
78884 case TPACKET_V1:
78885 @@ -3315,7 +3317,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
78886 len = lv;
78887 if (put_user(len, optlen))
78888 return -EFAULT;
78889 - if (copy_to_user(optval, data, len))
78890 + if (len > sizeof(st) || copy_to_user(optval, data, len))
78891 return -EFAULT;
78892 return 0;
78893 }
78894 diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
78895 index 5a940db..f0b9c12 100644
78896 --- a/net/phonet/af_phonet.c
78897 +++ b/net/phonet/af_phonet.c
78898 @@ -41,7 +41,7 @@ static struct phonet_protocol *phonet_proto_get(unsigned int protocol)
78899 {
78900 struct phonet_protocol *pp;
78901
78902 - if (protocol >= PHONET_NPROTO)
78903 + if (protocol < 0 || protocol >= PHONET_NPROTO)
78904 return NULL;
78905
78906 rcu_read_lock();
78907 @@ -469,7 +469,7 @@ int __init_or_module phonet_proto_register(unsigned int protocol,
78908 {
78909 int err = 0;
78910
78911 - if (protocol >= PHONET_NPROTO)
78912 + if (protocol < 0 || protocol >= PHONET_NPROTO)
78913 return -EINVAL;
78914
78915 err = proto_register(pp->prot, 1);
78916 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
78917 index 576f22c..bc7a71b 100644
78918 --- a/net/phonet/pep.c
78919 +++ b/net/phonet/pep.c
78920 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
78921
78922 case PNS_PEP_CTRL_REQ:
78923 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
78924 - atomic_inc(&sk->sk_drops);
78925 + atomic_inc_unchecked(&sk->sk_drops);
78926 break;
78927 }
78928 __skb_pull(skb, 4);
78929 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
78930 }
78931
78932 if (pn->rx_credits == 0) {
78933 - atomic_inc(&sk->sk_drops);
78934 + atomic_inc_unchecked(&sk->sk_drops);
78935 err = -ENOBUFS;
78936 break;
78937 }
78938 @@ -580,7 +580,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
78939 }
78940
78941 if (pn->rx_credits == 0) {
78942 - atomic_inc(&sk->sk_drops);
78943 + atomic_inc_unchecked(&sk->sk_drops);
78944 err = NET_RX_DROP;
78945 break;
78946 }
78947 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
78948 index 0acc943..c727611 100644
78949 --- a/net/phonet/socket.c
78950 +++ b/net/phonet/socket.c
78951 @@ -613,8 +613,13 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
78952 pn->resource, sk->sk_state,
78953 sk_wmem_alloc_get(sk), sk_rmem_alloc_get(sk),
78954 sock_i_uid(sk), sock_i_ino(sk),
78955 - atomic_read(&sk->sk_refcnt), sk,
78956 - atomic_read(&sk->sk_drops), &len);
78957 + atomic_read(&sk->sk_refcnt),
78958 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78959 + NULL,
78960 +#else
78961 + sk,
78962 +#endif
78963 + atomic_read_unchecked(&sk->sk_drops), &len);
78964 }
78965 seq_printf(seq, "%*s\n", 127 - len, "");
78966 return 0;
78967 diff --git a/net/rds/cong.c b/net/rds/cong.c
78968 index e5b65ac..f3b6fb7 100644
78969 --- a/net/rds/cong.c
78970 +++ b/net/rds/cong.c
78971 @@ -78,7 +78,7 @@
78972 * finds that the saved generation number is smaller than the global generation
78973 * number, it wakes up the process.
78974 */
78975 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
78976 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
78977
78978 /*
78979 * Congestion monitoring
78980 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
78981 rdsdebug("waking map %p for %pI4\n",
78982 map, &map->m_addr);
78983 rds_stats_inc(s_cong_update_received);
78984 - atomic_inc(&rds_cong_generation);
78985 + atomic_inc_unchecked(&rds_cong_generation);
78986 if (waitqueue_active(&map->m_waitq))
78987 wake_up(&map->m_waitq);
78988 if (waitqueue_active(&rds_poll_waitq))
78989 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
78990
78991 int rds_cong_updated_since(unsigned long *recent)
78992 {
78993 - unsigned long gen = atomic_read(&rds_cong_generation);
78994 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
78995
78996 if (likely(*recent == gen))
78997 return 0;
78998 diff --git a/net/rds/ib.h b/net/rds/ib.h
78999 index 8d2b3d5..227ec5b 100644
79000 --- a/net/rds/ib.h
79001 +++ b/net/rds/ib.h
79002 @@ -128,7 +128,7 @@ struct rds_ib_connection {
79003 /* sending acks */
79004 unsigned long i_ack_flags;
79005 #ifdef KERNEL_HAS_ATOMIC64
79006 - atomic64_t i_ack_next; /* next ACK to send */
79007 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
79008 #else
79009 spinlock_t i_ack_lock; /* protect i_ack_next */
79010 u64 i_ack_next; /* next ACK to send */
79011 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
79012 index a1e1162..265e129 100644
79013 --- a/net/rds/ib_cm.c
79014 +++ b/net/rds/ib_cm.c
79015 @@ -718,7 +718,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
79016 /* Clear the ACK state */
79017 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
79018 #ifdef KERNEL_HAS_ATOMIC64
79019 - atomic64_set(&ic->i_ack_next, 0);
79020 + atomic64_set_unchecked(&ic->i_ack_next, 0);
79021 #else
79022 ic->i_ack_next = 0;
79023 #endif
79024 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
79025 index 8d19491..05a3e65 100644
79026 --- a/net/rds/ib_recv.c
79027 +++ b/net/rds/ib_recv.c
79028 @@ -592,7 +592,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
79029 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
79030 int ack_required)
79031 {
79032 - atomic64_set(&ic->i_ack_next, seq);
79033 + atomic64_set_unchecked(&ic->i_ack_next, seq);
79034 if (ack_required) {
79035 smp_mb__before_clear_bit();
79036 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
79037 @@ -604,7 +604,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
79038 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
79039 smp_mb__after_clear_bit();
79040
79041 - return atomic64_read(&ic->i_ack_next);
79042 + return atomic64_read_unchecked(&ic->i_ack_next);
79043 }
79044 #endif
79045
79046 diff --git a/net/rds/iw.h b/net/rds/iw.h
79047 index 04ce3b1..48119a6 100644
79048 --- a/net/rds/iw.h
79049 +++ b/net/rds/iw.h
79050 @@ -134,7 +134,7 @@ struct rds_iw_connection {
79051 /* sending acks */
79052 unsigned long i_ack_flags;
79053 #ifdef KERNEL_HAS_ATOMIC64
79054 - atomic64_t i_ack_next; /* next ACK to send */
79055 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
79056 #else
79057 spinlock_t i_ack_lock; /* protect i_ack_next */
79058 u64 i_ack_next; /* next ACK to send */
79059 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
79060 index a91e1db..cf3053f 100644
79061 --- a/net/rds/iw_cm.c
79062 +++ b/net/rds/iw_cm.c
79063 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
79064 /* Clear the ACK state */
79065 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
79066 #ifdef KERNEL_HAS_ATOMIC64
79067 - atomic64_set(&ic->i_ack_next, 0);
79068 + atomic64_set_unchecked(&ic->i_ack_next, 0);
79069 #else
79070 ic->i_ack_next = 0;
79071 #endif
79072 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
79073 index 4503335..db566b4 100644
79074 --- a/net/rds/iw_recv.c
79075 +++ b/net/rds/iw_recv.c
79076 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
79077 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
79078 int ack_required)
79079 {
79080 - atomic64_set(&ic->i_ack_next, seq);
79081 + atomic64_set_unchecked(&ic->i_ack_next, seq);
79082 if (ack_required) {
79083 smp_mb__before_clear_bit();
79084 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
79085 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
79086 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
79087 smp_mb__after_clear_bit();
79088
79089 - return atomic64_read(&ic->i_ack_next);
79090 + return atomic64_read_unchecked(&ic->i_ack_next);
79091 }
79092 #endif
79093
79094 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
79095 index edac9ef..16bcb98 100644
79096 --- a/net/rds/tcp.c
79097 +++ b/net/rds/tcp.c
79098 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
79099 int val = 1;
79100
79101 set_fs(KERNEL_DS);
79102 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
79103 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
79104 sizeof(val));
79105 set_fs(oldfs);
79106 }
79107 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
79108 index 1b4fd68..2234175 100644
79109 --- a/net/rds/tcp_send.c
79110 +++ b/net/rds/tcp_send.c
79111 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
79112
79113 oldfs = get_fs();
79114 set_fs(KERNEL_DS);
79115 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
79116 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
79117 sizeof(val));
79118 set_fs(oldfs);
79119 }
79120 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
79121 index 05996d0..5a1dfe0 100644
79122 --- a/net/rxrpc/af_rxrpc.c
79123 +++ b/net/rxrpc/af_rxrpc.c
79124 @@ -39,7 +39,7 @@ static const struct proto_ops rxrpc_rpc_ops;
79125 __be32 rxrpc_epoch;
79126
79127 /* current debugging ID */
79128 -atomic_t rxrpc_debug_id;
79129 +atomic_unchecked_t rxrpc_debug_id;
79130
79131 /* count of skbs currently in use */
79132 atomic_t rxrpc_n_skbs;
79133 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
79134 index e4d9cbc..b229649 100644
79135 --- a/net/rxrpc/ar-ack.c
79136 +++ b/net/rxrpc/ar-ack.c
79137 @@ -175,7 +175,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
79138
79139 _enter("{%d,%d,%d,%d},",
79140 call->acks_hard, call->acks_unacked,
79141 - atomic_read(&call->sequence),
79142 + atomic_read_unchecked(&call->sequence),
79143 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
79144
79145 stop = 0;
79146 @@ -199,7 +199,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
79147
79148 /* each Tx packet has a new serial number */
79149 sp->hdr.serial =
79150 - htonl(atomic_inc_return(&call->conn->serial));
79151 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
79152
79153 hdr = (struct rxrpc_header *) txb->head;
79154 hdr->serial = sp->hdr.serial;
79155 @@ -403,7 +403,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
79156 */
79157 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
79158 {
79159 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
79160 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
79161 }
79162
79163 /*
79164 @@ -629,7 +629,7 @@ process_further:
79165
79166 latest = ntohl(sp->hdr.serial);
79167 hard = ntohl(ack.firstPacket);
79168 - tx = atomic_read(&call->sequence);
79169 + tx = atomic_read_unchecked(&call->sequence);
79170
79171 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
79172 latest,
79173 @@ -1161,7 +1161,7 @@ void rxrpc_process_call(struct work_struct *work)
79174 goto maybe_reschedule;
79175
79176 send_ACK_with_skew:
79177 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
79178 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
79179 ntohl(ack.serial));
79180 send_ACK:
79181 mtu = call->conn->trans->peer->if_mtu;
79182 @@ -1173,7 +1173,7 @@ send_ACK:
79183 ackinfo.rxMTU = htonl(5692);
79184 ackinfo.jumbo_max = htonl(4);
79185
79186 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
79187 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
79188 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
79189 ntohl(hdr.serial),
79190 ntohs(ack.maxSkew),
79191 @@ -1191,7 +1191,7 @@ send_ACK:
79192 send_message:
79193 _debug("send message");
79194
79195 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
79196 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
79197 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
79198 send_message_2:
79199
79200 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
79201 index a3bbb36..3341fb9 100644
79202 --- a/net/rxrpc/ar-call.c
79203 +++ b/net/rxrpc/ar-call.c
79204 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
79205 spin_lock_init(&call->lock);
79206 rwlock_init(&call->state_lock);
79207 atomic_set(&call->usage, 1);
79208 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
79209 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
79210 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
79211
79212 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
79213 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
79214 index 4106ca9..a338d7a 100644
79215 --- a/net/rxrpc/ar-connection.c
79216 +++ b/net/rxrpc/ar-connection.c
79217 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
79218 rwlock_init(&conn->lock);
79219 spin_lock_init(&conn->state_lock);
79220 atomic_set(&conn->usage, 1);
79221 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
79222 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
79223 conn->avail_calls = RXRPC_MAXCALLS;
79224 conn->size_align = 4;
79225 conn->header_size = sizeof(struct rxrpc_header);
79226 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
79227 index e7ed43a..6afa140 100644
79228 --- a/net/rxrpc/ar-connevent.c
79229 +++ b/net/rxrpc/ar-connevent.c
79230 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
79231
79232 len = iov[0].iov_len + iov[1].iov_len;
79233
79234 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
79235 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
79236 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
79237
79238 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
79239 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
79240 index 529572f..c758ca7 100644
79241 --- a/net/rxrpc/ar-input.c
79242 +++ b/net/rxrpc/ar-input.c
79243 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
79244 /* track the latest serial number on this connection for ACK packet
79245 * information */
79246 serial = ntohl(sp->hdr.serial);
79247 - hi_serial = atomic_read(&call->conn->hi_serial);
79248 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
79249 while (serial > hi_serial)
79250 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
79251 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
79252 serial);
79253
79254 /* request ACK generation for any ACK or DATA packet that requests
79255 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
79256 index a693aca..81e7293 100644
79257 --- a/net/rxrpc/ar-internal.h
79258 +++ b/net/rxrpc/ar-internal.h
79259 @@ -272,8 +272,8 @@ struct rxrpc_connection {
79260 int error; /* error code for local abort */
79261 int debug_id; /* debug ID for printks */
79262 unsigned int call_counter; /* call ID counter */
79263 - atomic_t serial; /* packet serial number counter */
79264 - atomic_t hi_serial; /* highest serial number received */
79265 + atomic_unchecked_t serial; /* packet serial number counter */
79266 + atomic_unchecked_t hi_serial; /* highest serial number received */
79267 u8 avail_calls; /* number of calls available */
79268 u8 size_align; /* data size alignment (for security) */
79269 u8 header_size; /* rxrpc + security header size */
79270 @@ -346,7 +346,7 @@ struct rxrpc_call {
79271 spinlock_t lock;
79272 rwlock_t state_lock; /* lock for state transition */
79273 atomic_t usage;
79274 - atomic_t sequence; /* Tx data packet sequence counter */
79275 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
79276 u32 abort_code; /* local/remote abort code */
79277 enum { /* current state of call */
79278 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
79279 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
79280 */
79281 extern atomic_t rxrpc_n_skbs;
79282 extern __be32 rxrpc_epoch;
79283 -extern atomic_t rxrpc_debug_id;
79284 +extern atomic_unchecked_t rxrpc_debug_id;
79285 extern struct workqueue_struct *rxrpc_workqueue;
79286
79287 /*
79288 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
79289 index 87f7135..74d3703 100644
79290 --- a/net/rxrpc/ar-local.c
79291 +++ b/net/rxrpc/ar-local.c
79292 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
79293 spin_lock_init(&local->lock);
79294 rwlock_init(&local->services_lock);
79295 atomic_set(&local->usage, 1);
79296 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
79297 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
79298 memcpy(&local->srx, srx, sizeof(*srx));
79299 }
79300
79301 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
79302 index e1ac183..b43e10e 100644
79303 --- a/net/rxrpc/ar-output.c
79304 +++ b/net/rxrpc/ar-output.c
79305 @@ -682,9 +682,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
79306 sp->hdr.cid = call->cid;
79307 sp->hdr.callNumber = call->call_id;
79308 sp->hdr.seq =
79309 - htonl(atomic_inc_return(&call->sequence));
79310 + htonl(atomic_inc_return_unchecked(&call->sequence));
79311 sp->hdr.serial =
79312 - htonl(atomic_inc_return(&conn->serial));
79313 + htonl(atomic_inc_return_unchecked(&conn->serial));
79314 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
79315 sp->hdr.userStatus = 0;
79316 sp->hdr.securityIndex = conn->security_ix;
79317 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
79318 index bebaa43..2644591 100644
79319 --- a/net/rxrpc/ar-peer.c
79320 +++ b/net/rxrpc/ar-peer.c
79321 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
79322 INIT_LIST_HEAD(&peer->error_targets);
79323 spin_lock_init(&peer->lock);
79324 atomic_set(&peer->usage, 1);
79325 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
79326 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
79327 memcpy(&peer->srx, srx, sizeof(*srx));
79328
79329 rxrpc_assess_MTU_size(peer);
79330 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
79331 index 38047f7..9f48511 100644
79332 --- a/net/rxrpc/ar-proc.c
79333 +++ b/net/rxrpc/ar-proc.c
79334 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
79335 atomic_read(&conn->usage),
79336 rxrpc_conn_states[conn->state],
79337 key_serial(conn->key),
79338 - atomic_read(&conn->serial),
79339 - atomic_read(&conn->hi_serial));
79340 + atomic_read_unchecked(&conn->serial),
79341 + atomic_read_unchecked(&conn->hi_serial));
79342
79343 return 0;
79344 }
79345 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
79346 index 92df566..87ec1bf 100644
79347 --- a/net/rxrpc/ar-transport.c
79348 +++ b/net/rxrpc/ar-transport.c
79349 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
79350 spin_lock_init(&trans->client_lock);
79351 rwlock_init(&trans->conn_lock);
79352 atomic_set(&trans->usage, 1);
79353 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
79354 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
79355
79356 if (peer->srx.transport.family == AF_INET) {
79357 switch (peer->srx.transport_type) {
79358 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
79359 index f226709..0e735a8 100644
79360 --- a/net/rxrpc/rxkad.c
79361 +++ b/net/rxrpc/rxkad.c
79362 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
79363
79364 len = iov[0].iov_len + iov[1].iov_len;
79365
79366 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
79367 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
79368 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
79369
79370 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
79371 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
79372
79373 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
79374
79375 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
79376 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
79377 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
79378
79379 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
79380 diff --git a/net/sctp/proc.c b/net/sctp/proc.c
79381 index 1e2eee8..ce3967e 100644
79382 --- a/net/sctp/proc.c
79383 +++ b/net/sctp/proc.c
79384 @@ -319,7 +319,8 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
79385 seq_printf(seq,
79386 "%8pK %8pK %-3d %-3d %-2d %-4d "
79387 "%4d %8d %8d %7d %5lu %-5d %5d ",
79388 - assoc, sk, sctp_sk(sk)->type, sk->sk_state,
79389 + assoc, sk,
79390 + sctp_sk(sk)->type, sk->sk_state,
79391 assoc->state, hash,
79392 assoc->assoc_id,
79393 assoc->sndbuf_used,
79394 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
79395 index 5e25981..dbda919 100644
79396 --- a/net/sctp/socket.c
79397 +++ b/net/sctp/socket.c
79398 @@ -4630,6 +4630,8 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
79399 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
79400 if (space_left < addrlen)
79401 return -ENOMEM;
79402 + if (addrlen > sizeof(temp) || addrlen < 0)
79403 + return -EFAULT;
79404 if (copy_to_user(to, &temp, addrlen))
79405 return -EFAULT;
79406 to += addrlen;
79407 diff --git a/net/socket.c b/net/socket.c
79408 index edc3c4a..4b4e4a8 100644
79409 --- a/net/socket.c
79410 +++ b/net/socket.c
79411 @@ -88,6 +88,7 @@
79412 #include <linux/nsproxy.h>
79413 #include <linux/magic.h>
79414 #include <linux/slab.h>
79415 +#include <linux/in.h>
79416
79417 #include <asm/uaccess.h>
79418 #include <asm/unistd.h>
79419 @@ -105,6 +106,8 @@
79420 #include <linux/sockios.h>
79421 #include <linux/atalk.h>
79422
79423 +#include <linux/grsock.h>
79424 +
79425 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
79426 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
79427 unsigned long nr_segs, loff_t pos);
79428 @@ -321,7 +324,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
79429 &sockfs_dentry_operations, SOCKFS_MAGIC);
79430 }
79431
79432 -static struct vfsmount *sock_mnt __read_mostly;
79433 +struct vfsmount *sock_mnt __read_mostly;
79434
79435 static struct file_system_type sock_fs_type = {
79436 .name = "sockfs",
79437 @@ -1209,6 +1212,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
79438 return -EAFNOSUPPORT;
79439 if (type < 0 || type >= SOCK_MAX)
79440 return -EINVAL;
79441 + if (protocol < 0)
79442 + return -EINVAL;
79443
79444 /* Compatibility.
79445
79446 @@ -1340,6 +1345,16 @@ SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)
79447 if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
79448 flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
79449
79450 + if(!gr_search_socket(family, type, protocol)) {
79451 + retval = -EACCES;
79452 + goto out;
79453 + }
79454 +
79455 + if (gr_handle_sock_all(family, type, protocol)) {
79456 + retval = -EACCES;
79457 + goto out;
79458 + }
79459 +
79460 retval = sock_create(family, type, protocol, &sock);
79461 if (retval < 0)
79462 goto out;
79463 @@ -1452,6 +1467,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
79464 if (sock) {
79465 err = move_addr_to_kernel(umyaddr, addrlen, &address);
79466 if (err >= 0) {
79467 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
79468 + err = -EACCES;
79469 + goto error;
79470 + }
79471 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
79472 + if (err)
79473 + goto error;
79474 +
79475 err = security_socket_bind(sock,
79476 (struct sockaddr *)&address,
79477 addrlen);
79478 @@ -1460,6 +1483,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
79479 (struct sockaddr *)
79480 &address, addrlen);
79481 }
79482 +error:
79483 fput_light(sock->file, fput_needed);
79484 }
79485 return err;
79486 @@ -1483,10 +1507,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
79487 if ((unsigned int)backlog > somaxconn)
79488 backlog = somaxconn;
79489
79490 + if (gr_handle_sock_server_other(sock->sk)) {
79491 + err = -EPERM;
79492 + goto error;
79493 + }
79494 +
79495 + err = gr_search_listen(sock);
79496 + if (err)
79497 + goto error;
79498 +
79499 err = security_socket_listen(sock, backlog);
79500 if (!err)
79501 err = sock->ops->listen(sock, backlog);
79502
79503 +error:
79504 fput_light(sock->file, fput_needed);
79505 }
79506 return err;
79507 @@ -1530,6 +1564,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
79508 newsock->type = sock->type;
79509 newsock->ops = sock->ops;
79510
79511 + if (gr_handle_sock_server_other(sock->sk)) {
79512 + err = -EPERM;
79513 + sock_release(newsock);
79514 + goto out_put;
79515 + }
79516 +
79517 + err = gr_search_accept(sock);
79518 + if (err) {
79519 + sock_release(newsock);
79520 + goto out_put;
79521 + }
79522 +
79523 /*
79524 * We don't need try_module_get here, as the listening socket (sock)
79525 * has the protocol module (sock->ops->owner) held.
79526 @@ -1568,6 +1614,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
79527 fd_install(newfd, newfile);
79528 err = newfd;
79529
79530 + gr_attach_curr_ip(newsock->sk);
79531 +
79532 out_put:
79533 fput_light(sock->file, fput_needed);
79534 out:
79535 @@ -1600,6 +1648,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
79536 int, addrlen)
79537 {
79538 struct socket *sock;
79539 + struct sockaddr *sck;
79540 struct sockaddr_storage address;
79541 int err, fput_needed;
79542
79543 @@ -1610,6 +1659,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
79544 if (err < 0)
79545 goto out_put;
79546
79547 + sck = (struct sockaddr *)&address;
79548 +
79549 + if (gr_handle_sock_client(sck)) {
79550 + err = -EACCES;
79551 + goto out_put;
79552 + }
79553 +
79554 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
79555 + if (err)
79556 + goto out_put;
79557 +
79558 err =
79559 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
79560 if (err)
79561 @@ -1964,7 +2024,7 @@ static int __sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
79562 * checking falls down on this.
79563 */
79564 if (copy_from_user(ctl_buf,
79565 - (void __user __force *)msg_sys->msg_control,
79566 + (void __force_user *)msg_sys->msg_control,
79567 ctl_len))
79568 goto out_freectl;
79569 msg_sys->msg_control = ctl_buf;
79570 @@ -2132,7 +2192,7 @@ static int __sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
79571 * kernel msghdr to use the kernel address space)
79572 */
79573
79574 - uaddr = (__force void __user *)msg_sys->msg_name;
79575 + uaddr = (void __force_user *)msg_sys->msg_name;
79576 uaddr_len = COMPAT_NAMELEN(msg);
79577 if (MSG_CMSG_COMPAT & flags) {
79578 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
79579 @@ -2761,7 +2821,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
79580 }
79581
79582 ifr = compat_alloc_user_space(buf_size);
79583 - rxnfc = (void *)ifr + ALIGN(sizeof(struct ifreq), 8);
79584 + rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
79585
79586 if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
79587 return -EFAULT;
79588 @@ -2785,12 +2845,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
79589 offsetof(struct ethtool_rxnfc, fs.ring_cookie));
79590
79591 if (copy_in_user(rxnfc, compat_rxnfc,
79592 - (void *)(&rxnfc->fs.m_ext + 1) -
79593 - (void *)rxnfc) ||
79594 + (void __user *)(&rxnfc->fs.m_ext + 1) -
79595 + (void __user *)rxnfc) ||
79596 copy_in_user(&rxnfc->fs.ring_cookie,
79597 &compat_rxnfc->fs.ring_cookie,
79598 - (void *)(&rxnfc->fs.location + 1) -
79599 - (void *)&rxnfc->fs.ring_cookie) ||
79600 + (void __user *)(&rxnfc->fs.location + 1) -
79601 + (void __user *)&rxnfc->fs.ring_cookie) ||
79602 copy_in_user(&rxnfc->rule_cnt, &compat_rxnfc->rule_cnt,
79603 sizeof(rxnfc->rule_cnt)))
79604 return -EFAULT;
79605 @@ -2802,12 +2862,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
79606
79607 if (convert_out) {
79608 if (copy_in_user(compat_rxnfc, rxnfc,
79609 - (const void *)(&rxnfc->fs.m_ext + 1) -
79610 - (const void *)rxnfc) ||
79611 + (const void __user *)(&rxnfc->fs.m_ext + 1) -
79612 + (const void __user *)rxnfc) ||
79613 copy_in_user(&compat_rxnfc->fs.ring_cookie,
79614 &rxnfc->fs.ring_cookie,
79615 - (const void *)(&rxnfc->fs.location + 1) -
79616 - (const void *)&rxnfc->fs.ring_cookie) ||
79617 + (const void __user *)(&rxnfc->fs.location + 1) -
79618 + (const void __user *)&rxnfc->fs.ring_cookie) ||
79619 copy_in_user(&compat_rxnfc->rule_cnt, &rxnfc->rule_cnt,
79620 sizeof(rxnfc->rule_cnt)))
79621 return -EFAULT;
79622 @@ -2877,7 +2937,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
79623 old_fs = get_fs();
79624 set_fs(KERNEL_DS);
79625 err = dev_ioctl(net, cmd,
79626 - (struct ifreq __user __force *) &kifr);
79627 + (struct ifreq __force_user *) &kifr);
79628 set_fs(old_fs);
79629
79630 return err;
79631 @@ -2986,7 +3046,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
79632
79633 old_fs = get_fs();
79634 set_fs(KERNEL_DS);
79635 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
79636 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
79637 set_fs(old_fs);
79638
79639 if (cmd == SIOCGIFMAP && !err) {
79640 @@ -3091,7 +3151,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
79641 ret |= __get_user(rtdev, &(ur4->rt_dev));
79642 if (rtdev) {
79643 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
79644 - r4.rt_dev = (char __user __force *)devname;
79645 + r4.rt_dev = (char __force_user *)devname;
79646 devname[15] = 0;
79647 } else
79648 r4.rt_dev = NULL;
79649 @@ -3317,8 +3377,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
79650 int __user *uoptlen;
79651 int err;
79652
79653 - uoptval = (char __user __force *) optval;
79654 - uoptlen = (int __user __force *) optlen;
79655 + uoptval = (char __force_user *) optval;
79656 + uoptlen = (int __force_user *) optlen;
79657
79658 set_fs(KERNEL_DS);
79659 if (level == SOL_SOCKET)
79660 @@ -3338,7 +3398,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
79661 char __user *uoptval;
79662 int err;
79663
79664 - uoptval = (char __user __force *) optval;
79665 + uoptval = (char __force_user *) optval;
79666
79667 set_fs(KERNEL_DS);
79668 if (level == SOL_SOCKET)
79669 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
79670 index 128494e..775d0e0 100644
79671 --- a/net/sunrpc/sched.c
79672 +++ b/net/sunrpc/sched.c
79673 @@ -240,9 +240,9 @@ static int rpc_wait_bit_killable(void *word)
79674 #ifdef RPC_DEBUG
79675 static void rpc_task_set_debuginfo(struct rpc_task *task)
79676 {
79677 - static atomic_t rpc_pid;
79678 + static atomic_unchecked_t rpc_pid;
79679
79680 - task->tk_pid = atomic_inc_return(&rpc_pid);
79681 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
79682 }
79683 #else
79684 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
79685 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
79686 index 8343737..677025e 100644
79687 --- a/net/sunrpc/xprtrdma/svc_rdma.c
79688 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
79689 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
79690 static unsigned int min_max_inline = 4096;
79691 static unsigned int max_max_inline = 65536;
79692
79693 -atomic_t rdma_stat_recv;
79694 -atomic_t rdma_stat_read;
79695 -atomic_t rdma_stat_write;
79696 -atomic_t rdma_stat_sq_starve;
79697 -atomic_t rdma_stat_rq_starve;
79698 -atomic_t rdma_stat_rq_poll;
79699 -atomic_t rdma_stat_rq_prod;
79700 -atomic_t rdma_stat_sq_poll;
79701 -atomic_t rdma_stat_sq_prod;
79702 +atomic_unchecked_t rdma_stat_recv;
79703 +atomic_unchecked_t rdma_stat_read;
79704 +atomic_unchecked_t rdma_stat_write;
79705 +atomic_unchecked_t rdma_stat_sq_starve;
79706 +atomic_unchecked_t rdma_stat_rq_starve;
79707 +atomic_unchecked_t rdma_stat_rq_poll;
79708 +atomic_unchecked_t rdma_stat_rq_prod;
79709 +atomic_unchecked_t rdma_stat_sq_poll;
79710 +atomic_unchecked_t rdma_stat_sq_prod;
79711
79712 /* Temporary NFS request map and context caches */
79713 struct kmem_cache *svc_rdma_map_cachep;
79714 @@ -110,7 +110,7 @@ static int read_reset_stat(ctl_table *table, int write,
79715 len -= *ppos;
79716 if (len > *lenp)
79717 len = *lenp;
79718 - if (len && copy_to_user(buffer, str_buf, len))
79719 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
79720 return -EFAULT;
79721 *lenp = len;
79722 *ppos += len;
79723 @@ -151,63 +151,63 @@ static ctl_table svcrdma_parm_table[] = {
79724 {
79725 .procname = "rdma_stat_read",
79726 .data = &rdma_stat_read,
79727 - .maxlen = sizeof(atomic_t),
79728 + .maxlen = sizeof(atomic_unchecked_t),
79729 .mode = 0644,
79730 .proc_handler = read_reset_stat,
79731 },
79732 {
79733 .procname = "rdma_stat_recv",
79734 .data = &rdma_stat_recv,
79735 - .maxlen = sizeof(atomic_t),
79736 + .maxlen = sizeof(atomic_unchecked_t),
79737 .mode = 0644,
79738 .proc_handler = read_reset_stat,
79739 },
79740 {
79741 .procname = "rdma_stat_write",
79742 .data = &rdma_stat_write,
79743 - .maxlen = sizeof(atomic_t),
79744 + .maxlen = sizeof(atomic_unchecked_t),
79745 .mode = 0644,
79746 .proc_handler = read_reset_stat,
79747 },
79748 {
79749 .procname = "rdma_stat_sq_starve",
79750 .data = &rdma_stat_sq_starve,
79751 - .maxlen = sizeof(atomic_t),
79752 + .maxlen = sizeof(atomic_unchecked_t),
79753 .mode = 0644,
79754 .proc_handler = read_reset_stat,
79755 },
79756 {
79757 .procname = "rdma_stat_rq_starve",
79758 .data = &rdma_stat_rq_starve,
79759 - .maxlen = sizeof(atomic_t),
79760 + .maxlen = sizeof(atomic_unchecked_t),
79761 .mode = 0644,
79762 .proc_handler = read_reset_stat,
79763 },
79764 {
79765 .procname = "rdma_stat_rq_poll",
79766 .data = &rdma_stat_rq_poll,
79767 - .maxlen = sizeof(atomic_t),
79768 + .maxlen = sizeof(atomic_unchecked_t),
79769 .mode = 0644,
79770 .proc_handler = read_reset_stat,
79771 },
79772 {
79773 .procname = "rdma_stat_rq_prod",
79774 .data = &rdma_stat_rq_prod,
79775 - .maxlen = sizeof(atomic_t),
79776 + .maxlen = sizeof(atomic_unchecked_t),
79777 .mode = 0644,
79778 .proc_handler = read_reset_stat,
79779 },
79780 {
79781 .procname = "rdma_stat_sq_poll",
79782 .data = &rdma_stat_sq_poll,
79783 - .maxlen = sizeof(atomic_t),
79784 + .maxlen = sizeof(atomic_unchecked_t),
79785 .mode = 0644,
79786 .proc_handler = read_reset_stat,
79787 },
79788 {
79789 .procname = "rdma_stat_sq_prod",
79790 .data = &rdma_stat_sq_prod,
79791 - .maxlen = sizeof(atomic_t),
79792 + .maxlen = sizeof(atomic_unchecked_t),
79793 .mode = 0644,
79794 .proc_handler = read_reset_stat,
79795 },
79796 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
79797 index 41cb63b..c4a1489 100644
79798 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
79799 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
79800 @@ -501,7 +501,7 @@ next_sge:
79801 svc_rdma_put_context(ctxt, 0);
79802 goto out;
79803 }
79804 - atomic_inc(&rdma_stat_read);
79805 + atomic_inc_unchecked(&rdma_stat_read);
79806
79807 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
79808 chl_map->ch[ch_no].count -= read_wr.num_sge;
79809 @@ -611,7 +611,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
79810 dto_q);
79811 list_del_init(&ctxt->dto_q);
79812 } else {
79813 - atomic_inc(&rdma_stat_rq_starve);
79814 + atomic_inc_unchecked(&rdma_stat_rq_starve);
79815 clear_bit(XPT_DATA, &xprt->xpt_flags);
79816 ctxt = NULL;
79817 }
79818 @@ -631,7 +631,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
79819 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
79820 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
79821 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
79822 - atomic_inc(&rdma_stat_recv);
79823 + atomic_inc_unchecked(&rdma_stat_recv);
79824
79825 /* Build up the XDR from the receive buffers. */
79826 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
79827 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
79828 index 42eb7ba..c887c45 100644
79829 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
79830 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
79831 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
79832 write_wr.wr.rdma.remote_addr = to;
79833
79834 /* Post It */
79835 - atomic_inc(&rdma_stat_write);
79836 + atomic_inc_unchecked(&rdma_stat_write);
79837 if (svc_rdma_send(xprt, &write_wr))
79838 goto err;
79839 return 0;
79840 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
79841 index 73b428b..5f3f8f3 100644
79842 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
79843 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
79844 @@ -292,7 +292,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
79845 return;
79846
79847 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
79848 - atomic_inc(&rdma_stat_rq_poll);
79849 + atomic_inc_unchecked(&rdma_stat_rq_poll);
79850
79851 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
79852 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
79853 @@ -314,7 +314,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
79854 }
79855
79856 if (ctxt)
79857 - atomic_inc(&rdma_stat_rq_prod);
79858 + atomic_inc_unchecked(&rdma_stat_rq_prod);
79859
79860 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
79861 /*
79862 @@ -386,7 +386,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
79863 return;
79864
79865 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
79866 - atomic_inc(&rdma_stat_sq_poll);
79867 + atomic_inc_unchecked(&rdma_stat_sq_poll);
79868 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
79869 if (wc.status != IB_WC_SUCCESS)
79870 /* Close the transport */
79871 @@ -404,7 +404,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
79872 }
79873
79874 if (ctxt)
79875 - atomic_inc(&rdma_stat_sq_prod);
79876 + atomic_inc_unchecked(&rdma_stat_sq_prod);
79877 }
79878
79879 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
79880 @@ -1266,7 +1266,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
79881 spin_lock_bh(&xprt->sc_lock);
79882 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
79883 spin_unlock_bh(&xprt->sc_lock);
79884 - atomic_inc(&rdma_stat_sq_starve);
79885 + atomic_inc_unchecked(&rdma_stat_sq_starve);
79886
79887 /* See if we can opportunistically reap SQ WR to make room */
79888 sq_cq_reap(xprt);
79889 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
79890 index e3a6e37..be2ea77 100644
79891 --- a/net/sysctl_net.c
79892 +++ b/net/sysctl_net.c
79893 @@ -43,7 +43,7 @@ static int net_ctl_permissions(struct ctl_table_root *root,
79894 struct ctl_table *table)
79895 {
79896 /* Allow network administrator to have same access as root. */
79897 - if (capable(CAP_NET_ADMIN)) {
79898 + if (capable_nolog(CAP_NET_ADMIN)) {
79899 int mode = (table->mode >> 6) & 7;
79900 return (mode << 6) | (mode << 3) | mode;
79901 }
79902 diff --git a/net/tipc/link.c b/net/tipc/link.c
79903 index 1c1e615..113e0ae 100644
79904 --- a/net/tipc/link.c
79905 +++ b/net/tipc/link.c
79906 @@ -1171,7 +1171,7 @@ static int link_send_sections_long(struct tipc_port *sender,
79907 struct tipc_msg fragm_hdr;
79908 struct sk_buff *buf, *buf_chain, *prev;
79909 u32 fragm_crs, fragm_rest, hsz, sect_rest;
79910 - const unchar *sect_crs;
79911 + const unchar __user *sect_crs;
79912 int curr_sect;
79913 u32 fragm_no;
79914
79915 @@ -1212,7 +1212,7 @@ again:
79916
79917 if (!sect_rest) {
79918 sect_rest = msg_sect[++curr_sect].iov_len;
79919 - sect_crs = (const unchar *)msg_sect[curr_sect].iov_base;
79920 + sect_crs = (const unchar __user *)msg_sect[curr_sect].iov_base;
79921 }
79922
79923 if (sect_rest < fragm_rest)
79924 @@ -1231,7 +1231,7 @@ error:
79925 }
79926 } else
79927 skb_copy_to_linear_data_offset(buf, fragm_crs,
79928 - sect_crs, sz);
79929 + (const void __force_kernel *)sect_crs, sz);
79930 sect_crs += sz;
79931 sect_rest -= sz;
79932 fragm_crs += sz;
79933 diff --git a/net/tipc/msg.c b/net/tipc/msg.c
79934 index f2db8a8..9245aa4 100644
79935 --- a/net/tipc/msg.c
79936 +++ b/net/tipc/msg.c
79937 @@ -98,7 +98,7 @@ int tipc_msg_build(struct tipc_msg *hdr, struct iovec const *msg_sect,
79938 msg_sect[cnt].iov_len);
79939 else
79940 skb_copy_to_linear_data_offset(*buf, pos,
79941 - msg_sect[cnt].iov_base,
79942 + (const void __force_kernel *)msg_sect[cnt].iov_base,
79943 msg_sect[cnt].iov_len);
79944 pos += msg_sect[cnt].iov_len;
79945 }
79946 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
79947 index 5ed5965..90abe34 100644
79948 --- a/net/tipc/subscr.c
79949 +++ b/net/tipc/subscr.c
79950 @@ -96,7 +96,7 @@ static void subscr_send_event(struct tipc_subscription *sub,
79951 {
79952 struct iovec msg_sect;
79953
79954 - msg_sect.iov_base = (void *)&sub->evt;
79955 + msg_sect.iov_base = (void __force_user *)&sub->evt;
79956 msg_sect.iov_len = sizeof(struct tipc_event);
79957
79958 sub->evt.event = htohl(event, sub->swap);
79959 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
79960 index c5ee4ff..e905948 100644
79961 --- a/net/unix/af_unix.c
79962 +++ b/net/unix/af_unix.c
79963 @@ -789,6 +789,12 @@ static struct sock *unix_find_other(struct net *net,
79964 err = -ECONNREFUSED;
79965 if (!S_ISSOCK(inode->i_mode))
79966 goto put_fail;
79967 +
79968 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
79969 + err = -EACCES;
79970 + goto put_fail;
79971 + }
79972 +
79973 u = unix_find_socket_byinode(inode);
79974 if (!u)
79975 goto put_fail;
79976 @@ -809,6 +815,13 @@ static struct sock *unix_find_other(struct net *net,
79977 if (u) {
79978 struct dentry *dentry;
79979 dentry = unix_sk(u)->path.dentry;
79980 +
79981 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
79982 + err = -EPERM;
79983 + sock_put(u);
79984 + goto fail;
79985 + }
79986 +
79987 if (dentry)
79988 touch_atime(&unix_sk(u)->path);
79989 } else
79990 @@ -842,12 +855,18 @@ static int unix_mknod(const char *sun_path, umode_t mode, struct path *res)
79991 */
79992 err = security_path_mknod(&path, dentry, mode, 0);
79993 if (!err) {
79994 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
79995 + err = -EACCES;
79996 + goto out;
79997 + }
79998 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
79999 if (!err) {
80000 res->mnt = mntget(path.mnt);
80001 res->dentry = dget(dentry);
80002 + gr_handle_create(dentry, path.mnt);
80003 }
80004 }
80005 +out:
80006 done_path_create(&path, dentry);
80007 return err;
80008 }
80009 diff --git a/net/wireless/core.h b/net/wireless/core.h
80010 index bc7430b..35349de 100644
80011 --- a/net/wireless/core.h
80012 +++ b/net/wireless/core.h
80013 @@ -28,7 +28,7 @@ struct cfg80211_registered_device {
80014 struct mutex mtx;
80015
80016 /* rfkill support */
80017 - struct rfkill_ops rfkill_ops;
80018 + rfkill_ops_no_const rfkill_ops;
80019 struct rfkill *rfkill;
80020 struct work_struct rfkill_sync;
80021
80022 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
80023 index b0eb7aa..7d73e82 100644
80024 --- a/net/wireless/wext-core.c
80025 +++ b/net/wireless/wext-core.c
80026 @@ -748,8 +748,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
80027 */
80028
80029 /* Support for very large requests */
80030 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
80031 - (user_length > descr->max_tokens)) {
80032 + if (user_length > descr->max_tokens) {
80033 /* Allow userspace to GET more than max so
80034 * we can support any size GET requests.
80035 * There is still a limit : -ENOMEM.
80036 @@ -788,22 +787,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
80037 }
80038 }
80039
80040 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
80041 - /*
80042 - * If this is a GET, but not NOMAX, it means that the extra
80043 - * data is not bounded by userspace, but by max_tokens. Thus
80044 - * set the length to max_tokens. This matches the extra data
80045 - * allocation.
80046 - * The driver should fill it with the number of tokens it
80047 - * provided, and it may check iwp->length rather than having
80048 - * knowledge of max_tokens. If the driver doesn't change the
80049 - * iwp->length, this ioctl just copies back max_token tokens
80050 - * filled with zeroes. Hopefully the driver isn't claiming
80051 - * them to be valid data.
80052 - */
80053 - iwp->length = descr->max_tokens;
80054 - }
80055 -
80056 err = handler(dev, info, (union iwreq_data *) iwp, extra);
80057
80058 iwp->length += essid_compat;
80059 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
80060 index 387848e..a6667a2 100644
80061 --- a/net/xfrm/xfrm_policy.c
80062 +++ b/net/xfrm/xfrm_policy.c
80063 @@ -300,7 +300,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
80064 {
80065 policy->walk.dead = 1;
80066
80067 - atomic_inc(&policy->genid);
80068 + atomic_inc_unchecked(&policy->genid);
80069
80070 if (del_timer(&policy->timer))
80071 xfrm_pol_put(policy);
80072 @@ -584,7 +584,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
80073 hlist_add_head(&policy->bydst, chain);
80074 xfrm_pol_hold(policy);
80075 net->xfrm.policy_count[dir]++;
80076 - atomic_inc(&flow_cache_genid);
80077 + atomic_inc_unchecked(&flow_cache_genid);
80078 rt_genid_bump(net);
80079 if (delpol)
80080 __xfrm_policy_unlink(delpol, dir);
80081 @@ -1533,7 +1533,7 @@ free_dst:
80082 goto out;
80083 }
80084
80085 -static int inline
80086 +static inline int
80087 xfrm_dst_alloc_copy(void **target, const void *src, int size)
80088 {
80089 if (!*target) {
80090 @@ -1545,7 +1545,7 @@ xfrm_dst_alloc_copy(void **target, const void *src, int size)
80091 return 0;
80092 }
80093
80094 -static int inline
80095 +static inline int
80096 xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
80097 {
80098 #ifdef CONFIG_XFRM_SUB_POLICY
80099 @@ -1557,7 +1557,7 @@ xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
80100 #endif
80101 }
80102
80103 -static int inline
80104 +static inline int
80105 xfrm_dst_update_origin(struct dst_entry *dst, const struct flowi *fl)
80106 {
80107 #ifdef CONFIG_XFRM_SUB_POLICY
80108 @@ -1651,7 +1651,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
80109
80110 xdst->num_pols = num_pols;
80111 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols);
80112 - xdst->policy_genid = atomic_read(&pols[0]->genid);
80113 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
80114
80115 return xdst;
80116 }
80117 @@ -2352,7 +2352,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
80118 if (xdst->xfrm_genid != dst->xfrm->genid)
80119 return 0;
80120 if (xdst->num_pols > 0 &&
80121 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
80122 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
80123 return 0;
80124
80125 mtu = dst_mtu(dst->child);
80126 @@ -2891,7 +2891,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
80127 sizeof(pol->xfrm_vec[i].saddr));
80128 pol->xfrm_vec[i].encap_family = mp->new_family;
80129 /* flush bundles */
80130 - atomic_inc(&pol->genid);
80131 + atomic_inc_unchecked(&pol->genid);
80132 }
80133 }
80134
80135 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
80136 index ff1720d..ed8475e 100644
80137 --- a/scripts/Makefile.build
80138 +++ b/scripts/Makefile.build
80139 @@ -111,7 +111,7 @@ endif
80140 endif
80141
80142 # Do not include host rules unless needed
80143 -ifneq ($(hostprogs-y)$(hostprogs-m),)
80144 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
80145 include scripts/Makefile.host
80146 endif
80147
80148 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
80149 index 686cb0d..9d653bf 100644
80150 --- a/scripts/Makefile.clean
80151 +++ b/scripts/Makefile.clean
80152 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
80153 __clean-files := $(extra-y) $(always) \
80154 $(targets) $(clean-files) \
80155 $(host-progs) \
80156 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
80157 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
80158 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
80159
80160 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
80161
80162 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
80163 index 1ac414f..38575f7 100644
80164 --- a/scripts/Makefile.host
80165 +++ b/scripts/Makefile.host
80166 @@ -31,6 +31,8 @@
80167 # Note: Shared libraries consisting of C++ files are not supported
80168
80169 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
80170 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
80171 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
80172
80173 # C code
80174 # Executables compiled from a single .c file
80175 @@ -54,11 +56,15 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
80176 # Shared libaries (only .c supported)
80177 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
80178 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
80179 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
80180 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
80181 # Remove .so files from "xxx-objs"
80182 host-cobjs := $(filter-out %.so,$(host-cobjs))
80183 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
80184
80185 -#Object (.o) files used by the shared libaries
80186 +# Object (.o) files used by the shared libaries
80187 host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
80188 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
80189
80190 # output directory for programs/.o files
80191 # hostprogs-y := tools/build may have been specified. Retrieve directory
80192 @@ -82,7 +88,9 @@ host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
80193 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
80194 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
80195 host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
80196 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
80197 host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
80198 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
80199 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
80200
80201 obj-dirs += $(host-objdirs)
80202 @@ -156,6 +164,13 @@ quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
80203 $(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
80204 $(call if_changed_dep,host-cshobjs)
80205
80206 +# Compile .c file, create position independent .o file
80207 +# host-cxxshobjs -> .o
80208 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
80209 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
80210 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
80211 + $(call if_changed_dep,host-cxxshobjs)
80212 +
80213 # Link a shared library, based on position independent .o files
80214 # *.o -> .so shared library (host-cshlib)
80215 quiet_cmd_host-cshlib = HOSTLLD -shared $@
80216 @@ -165,6 +180,15 @@ quiet_cmd_host-cshlib = HOSTLLD -shared $@
80217 $(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
80218 $(call if_changed,host-cshlib)
80219
80220 +# Link a shared library, based on position independent .o files
80221 +# *.o -> .so shared library (host-cxxshlib)
80222 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
80223 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
80224 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
80225 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
80226 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
80227 + $(call if_changed,host-cxxshlib)
80228 +
80229 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
80230 - $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs)
80231 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
80232
80233 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
80234 index cb1f50c..cef2a7c 100644
80235 --- a/scripts/basic/fixdep.c
80236 +++ b/scripts/basic/fixdep.c
80237 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
80238 /*
80239 * Lookup a value in the configuration string.
80240 */
80241 -static int is_defined_config(const char *name, int len, unsigned int hash)
80242 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
80243 {
80244 struct item *aux;
80245
80246 @@ -211,10 +211,10 @@ static void clear_config(void)
80247 /*
80248 * Record the use of a CONFIG_* word.
80249 */
80250 -static void use_config(const char *m, int slen)
80251 +static void use_config(const char *m, unsigned int slen)
80252 {
80253 unsigned int hash = strhash(m, slen);
80254 - int c, i;
80255 + unsigned int c, i;
80256
80257 if (is_defined_config(m, slen, hash))
80258 return;
80259 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
80260
80261 static void parse_config_file(const char *map, size_t len)
80262 {
80263 - const int *end = (const int *) (map + len);
80264 + const unsigned int *end = (const unsigned int *) (map + len);
80265 /* start at +1, so that p can never be < map */
80266 - const int *m = (const int *) map + 1;
80267 + const unsigned int *m = (const unsigned int *) map + 1;
80268 const char *p, *q;
80269
80270 for (; m < end; m++) {
80271 @@ -406,7 +406,7 @@ static void print_deps(void)
80272 static void traps(void)
80273 {
80274 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
80275 - int *p = (int *)test;
80276 + unsigned int *p = (unsigned int *)test;
80277
80278 if (*p != INT_CONF) {
80279 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
80280 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
80281 new file mode 100644
80282 index 0000000..008ac1a
80283 --- /dev/null
80284 +++ b/scripts/gcc-plugin.sh
80285 @@ -0,0 +1,17 @@
80286 +#!/bin/bash
80287 +plugincc=`$1 -x c -shared - -o /dev/null -I\`$3 -print-file-name=plugin\`/include 2>&1 <<EOF
80288 +#include "gcc-plugin.h"
80289 +#include "tree.h"
80290 +#include "tm.h"
80291 +#include "rtl.h"
80292 +#ifdef ENABLE_BUILD_WITH_CXX
80293 +#warning $2
80294 +#else
80295 +#warning $1
80296 +#endif
80297 +EOF`
80298 +if [ $? -eq 0 ]
80299 +then
80300 + [[ "$plugincc" =~ "$1" ]] && echo "$1"
80301 + [[ "$plugincc" =~ "$2" ]] && echo "$2"
80302 +fi
80303 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
80304 index b3d907e..a4782ab 100644
80305 --- a/scripts/link-vmlinux.sh
80306 +++ b/scripts/link-vmlinux.sh
80307 @@ -152,7 +152,7 @@ else
80308 fi;
80309
80310 # final build of init/
80311 -${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
80312 +${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}" GCC_PLUGINS_AFLAGS="${GCC_PLUGINS_AFLAGS}"
80313
80314 kallsymso=""
80315 kallsyms_vmlinux=""
80316 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
80317 index 7ed6864..b6e90e6 100644
80318 --- a/scripts/mod/file2alias.c
80319 +++ b/scripts/mod/file2alias.c
80320 @@ -128,7 +128,7 @@ static void device_id_check(const char *modname, const char *device_id,
80321 unsigned long size, unsigned long id_size,
80322 void *symval)
80323 {
80324 - int i;
80325 + unsigned int i;
80326
80327 if (size % id_size || size < id_size) {
80328 if (cross_build != 0)
80329 @@ -158,7 +158,7 @@ static void device_id_check(const char *modname, const char *device_id,
80330 /* USB is special because the bcdDevice can be matched against a numeric range */
80331 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */
80332 static void do_usb_entry(struct usb_device_id *id,
80333 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
80334 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
80335 unsigned char range_lo, unsigned char range_hi,
80336 unsigned char max, struct module *mod)
80337 {
80338 @@ -262,7 +262,7 @@ static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod)
80339 {
80340 unsigned int devlo, devhi;
80341 unsigned char chi, clo, max;
80342 - int ndigits;
80343 + unsigned int ndigits;
80344
80345 id->match_flags = TO_NATIVE(id->match_flags);
80346 id->idVendor = TO_NATIVE(id->idVendor);
80347 @@ -507,7 +507,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
80348 for (i = 0; i < count; i++) {
80349 const char *id = (char *)devs[i].id;
80350 char acpi_id[sizeof(devs[0].id)];
80351 - int j;
80352 + unsigned int j;
80353
80354 buf_printf(&mod->dev_table_buf,
80355 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
80356 @@ -537,7 +537,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
80357
80358 for (j = 0; j < PNP_MAX_DEVICES; j++) {
80359 const char *id = (char *)card->devs[j].id;
80360 - int i2, j2;
80361 + unsigned int i2, j2;
80362 int dup = 0;
80363
80364 if (!id[0])
80365 @@ -563,7 +563,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
80366 /* add an individual alias for every device entry */
80367 if (!dup) {
80368 char acpi_id[sizeof(card->devs[0].id)];
80369 - int k;
80370 + unsigned int k;
80371
80372 buf_printf(&mod->dev_table_buf,
80373 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
80374 @@ -888,7 +888,7 @@ static void dmi_ascii_filter(char *d, const char *s)
80375 static int do_dmi_entry(const char *filename, struct dmi_system_id *id,
80376 char *alias)
80377 {
80378 - int i, j;
80379 + unsigned int i, j;
80380
80381 sprintf(alias, "dmi*");
80382
80383 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
80384 index 68e9f5e..ac7759b 100644
80385 --- a/scripts/mod/modpost.c
80386 +++ b/scripts/mod/modpost.c
80387 @@ -930,6 +930,7 @@ enum mismatch {
80388 ANY_INIT_TO_ANY_EXIT,
80389 ANY_EXIT_TO_ANY_INIT,
80390 EXPORT_TO_INIT_EXIT,
80391 + DATA_TO_TEXT
80392 };
80393
80394 struct sectioncheck {
80395 @@ -1044,6 +1045,12 @@ const struct sectioncheck sectioncheck[] = {
80396 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
80397 .mismatch = EXPORT_TO_INIT_EXIT,
80398 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
80399 +},
80400 +/* Do not reference code from writable data */
80401 +{
80402 + .fromsec = { DATA_SECTIONS, NULL },
80403 + .tosec = { TEXT_SECTIONS, NULL },
80404 + .mismatch = DATA_TO_TEXT
80405 }
80406 };
80407
80408 @@ -1166,10 +1173,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
80409 continue;
80410 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
80411 continue;
80412 - if (sym->st_value == addr)
80413 - return sym;
80414 /* Find a symbol nearby - addr are maybe negative */
80415 d = sym->st_value - addr;
80416 + if (d == 0)
80417 + return sym;
80418 if (d < 0)
80419 d = addr - sym->st_value;
80420 if (d < distance) {
80421 @@ -1448,6 +1455,14 @@ static void report_sec_mismatch(const char *modname,
80422 tosym, prl_to, prl_to, tosym);
80423 free(prl_to);
80424 break;
80425 + case DATA_TO_TEXT:
80426 +#if 0
80427 + fprintf(stderr,
80428 + "The %s %s:%s references\n"
80429 + "the %s %s:%s%s\n",
80430 + from, fromsec, fromsym, to, tosec, tosym, to_p);
80431 +#endif
80432 + break;
80433 }
80434 fprintf(stderr, "\n");
80435 }
80436 @@ -1682,7 +1697,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
80437 static void check_sec_ref(struct module *mod, const char *modname,
80438 struct elf_info *elf)
80439 {
80440 - int i;
80441 + unsigned int i;
80442 Elf_Shdr *sechdrs = elf->sechdrs;
80443
80444 /* Walk through all sections */
80445 @@ -1780,7 +1795,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
80446 va_end(ap);
80447 }
80448
80449 -void buf_write(struct buffer *buf, const char *s, int len)
80450 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
80451 {
80452 if (buf->size - buf->pos < len) {
80453 buf->size += len + SZ;
80454 @@ -1998,7 +2013,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
80455 if (fstat(fileno(file), &st) < 0)
80456 goto close_write;
80457
80458 - if (st.st_size != b->pos)
80459 + if (st.st_size != (off_t)b->pos)
80460 goto close_write;
80461
80462 tmp = NOFAIL(malloc(b->pos));
80463 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
80464 index 51207e4..f7d603d 100644
80465 --- a/scripts/mod/modpost.h
80466 +++ b/scripts/mod/modpost.h
80467 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
80468
80469 struct buffer {
80470 char *p;
80471 - int pos;
80472 - int size;
80473 + unsigned int pos;
80474 + unsigned int size;
80475 };
80476
80477 void __attribute__((format(printf, 2, 3)))
80478 buf_printf(struct buffer *buf, const char *fmt, ...);
80479
80480 void
80481 -buf_write(struct buffer *buf, const char *s, int len);
80482 +buf_write(struct buffer *buf, const char *s, unsigned int len);
80483
80484 struct module {
80485 struct module *next;
80486 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
80487 index 9dfcd6d..099068e 100644
80488 --- a/scripts/mod/sumversion.c
80489 +++ b/scripts/mod/sumversion.c
80490 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
80491 goto out;
80492 }
80493
80494 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
80495 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
80496 warn("writing sum in %s failed: %s\n",
80497 filename, strerror(errno));
80498 goto out;
80499 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
80500 index 5c11312..72742b5 100644
80501 --- a/scripts/pnmtologo.c
80502 +++ b/scripts/pnmtologo.c
80503 @@ -237,14 +237,14 @@ static void write_header(void)
80504 fprintf(out, " * Linux logo %s\n", logoname);
80505 fputs(" */\n\n", out);
80506 fputs("#include <linux/linux_logo.h>\n\n", out);
80507 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
80508 + fprintf(out, "static unsigned char %s_data[] = {\n",
80509 logoname);
80510 }
80511
80512 static void write_footer(void)
80513 {
80514 fputs("\n};\n\n", out);
80515 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
80516 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
80517 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
80518 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
80519 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
80520 @@ -374,7 +374,7 @@ static void write_logo_clut224(void)
80521 fputs("\n};\n\n", out);
80522
80523 /* write logo clut */
80524 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
80525 + fprintf(out, "static unsigned char %s_clut[] = {\n",
80526 logoname);
80527 write_hex_cnt = 0;
80528 for (i = 0; i < logo_clutsize; i++) {
80529 diff --git a/security/Kconfig b/security/Kconfig
80530 index e9c6ac7..e7feb0d 100644
80531 --- a/security/Kconfig
80532 +++ b/security/Kconfig
80533 @@ -4,6 +4,896 @@
80534
80535 menu "Security options"
80536
80537 +menu "Grsecurity"
80538 +
80539 + config ARCH_TRACK_EXEC_LIMIT
80540 + bool
80541 +
80542 + config PAX_KERNEXEC_PLUGIN
80543 + bool
80544 +
80545 + config PAX_PER_CPU_PGD
80546 + bool
80547 +
80548 + config TASK_SIZE_MAX_SHIFT
80549 + int
80550 + depends on X86_64
80551 + default 47 if !PAX_PER_CPU_PGD
80552 + default 42 if PAX_PER_CPU_PGD
80553 +
80554 + config PAX_ENABLE_PAE
80555 + bool
80556 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
80557 +
80558 + config PAX_USERCOPY_SLABS
80559 + bool
80560 +
80561 +config GRKERNSEC
80562 + bool "Grsecurity"
80563 + select CRYPTO
80564 + select CRYPTO_SHA256
80565 + select PROC_FS
80566 + select STOP_MACHINE
80567 + help
80568 + If you say Y here, you will be able to configure many features
80569 + that will enhance the security of your system. It is highly
80570 + recommended that you say Y here and read through the help
80571 + for each option so that you fully understand the features and
80572 + can evaluate their usefulness for your machine.
80573 +
80574 +choice
80575 + prompt "Configuration Method"
80576 + depends on GRKERNSEC
80577 + default GRKERNSEC_CONFIG_CUSTOM
80578 + help
80579 +
80580 +config GRKERNSEC_CONFIG_AUTO
80581 + bool "Automatic"
80582 + help
80583 + If you choose this configuration method, you'll be able to answer a small
80584 + number of simple questions about how you plan to use this kernel.
80585 + The settings of grsecurity and PaX will be automatically configured for
80586 + the highest commonly-used settings within the provided constraints.
80587 +
80588 + If you require additional configuration, custom changes can still be made
80589 + from the "custom configuration" menu.
80590 +
80591 +config GRKERNSEC_CONFIG_CUSTOM
80592 + bool "Custom"
80593 + help
80594 + If you choose this configuration method, you'll be able to configure all
80595 + grsecurity and PaX settings manually. Via this method, no options are
80596 + automatically enabled.
80597 +
80598 +endchoice
80599 +
80600 +choice
80601 + prompt "Usage Type"
80602 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
80603 + default GRKERNSEC_CONFIG_SERVER
80604 + help
80605 +
80606 +config GRKERNSEC_CONFIG_SERVER
80607 + bool "Server"
80608 + help
80609 + Choose this option if you plan to use this kernel on a server.
80610 +
80611 +config GRKERNSEC_CONFIG_DESKTOP
80612 + bool "Desktop"
80613 + help
80614 + Choose this option if you plan to use this kernel on a desktop.
80615 +
80616 +endchoice
80617 +
80618 +choice
80619 + prompt "Virtualization Type"
80620 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
80621 + default GRKERNSEC_CONFIG_VIRT_NONE
80622 + help
80623 +
80624 +config GRKERNSEC_CONFIG_VIRT_NONE
80625 + bool "None"
80626 + help
80627 + Choose this option if this kernel will be run on bare metal.
80628 +
80629 +config GRKERNSEC_CONFIG_VIRT_GUEST
80630 + bool "Guest"
80631 + help
80632 + Choose this option if this kernel will be run as a VM guest.
80633 +
80634 +config GRKERNSEC_CONFIG_VIRT_HOST
80635 + bool "Host"
80636 + help
80637 + Choose this option if this kernel will be run as a VM host.
80638 +
80639 +endchoice
80640 +
80641 +choice
80642 + prompt "Virtualization Hardware"
80643 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
80644 + help
80645 +
80646 +config GRKERNSEC_CONFIG_VIRT_EPT
80647 + bool "EPT/RVI Processor Support"
80648 + depends on X86
80649 + help
80650 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
80651 + hardware virtualization. This allows for additional kernel hardening protections
80652 + to operate without additional performance impact.
80653 +
80654 + To see if your Intel processor supports EPT, see:
80655 + http://ark.intel.com/Products/VirtualizationTechnology
80656 + (Most Core i3/5/7 support EPT)
80657 +
80658 + To see if your AMD processor supports RVI, see:
80659 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
80660 +
80661 +config GRKERNSEC_CONFIG_VIRT_SOFT
80662 + bool "First-gen/No Hardware Virtualization"
80663 + help
80664 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
80665 + support hardware virtualization or doesn't support the EPT/RVI extensions.
80666 +
80667 +endchoice
80668 +
80669 +choice
80670 + prompt "Virtualization Software"
80671 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
80672 + help
80673 +
80674 +config GRKERNSEC_CONFIG_VIRT_XEN
80675 + bool "Xen"
80676 + help
80677 + Choose this option if this kernel is running as a Xen guest or host.
80678 +
80679 +config GRKERNSEC_CONFIG_VIRT_VMWARE
80680 + bool "VMWare"
80681 + help
80682 + Choose this option if this kernel is running as a VMWare guest or host.
80683 +
80684 +config GRKERNSEC_CONFIG_VIRT_KVM
80685 + bool "KVM"
80686 + help
80687 + Choose this option if this kernel is running as a KVM guest or host.
80688 +
80689 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
80690 + bool "VirtualBox"
80691 + help
80692 + Choose this option if this kernel is running as a VirtualBox guest or host.
80693 +
80694 +endchoice
80695 +
80696 +choice
80697 + prompt "Required Priorities"
80698 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
80699 + default GRKERNSEC_CONFIG_PRIORITY_PERF
80700 + help
80701 +
80702 +config GRKERNSEC_CONFIG_PRIORITY_PERF
80703 + bool "Performance"
80704 + help
80705 + Choose this option if performance is of highest priority for this deployment
80706 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
80707 + and freed memory sanitizing will be disabled.
80708 +
80709 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
80710 + bool "Security"
80711 + help
80712 + Choose this option if security is of highest priority for this deployment of
80713 + grsecurity. UDEREF, kernel stack clearing, and freed memory sanitizing will
80714 + be enabled for this kernel. In a worst-case scenario, these features can
80715 + introduce a 20% performance hit (UDEREF on x64 contributing half of this hit).
80716 +
80717 +endchoice
80718 +
80719 +menu "Default Special Groups"
80720 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
80721 +
80722 +config GRKERNSEC_PROC_GID
80723 + int "GID exempted from /proc restrictions"
80724 + default 1001
80725 + help
80726 + Setting this GID determines which group will be exempted from
80727 + grsecurity's /proc restrictions, allowing users of the specified
80728 + group to view network statistics and the existence of other users'
80729 + processes on the system. This GID may also be chosen at boot time
80730 + via "grsec_proc_gid=" on the kernel commandline.
80731 +
80732 +config GRKERNSEC_TPE_UNTRUSTED_GID
80733 + int "GID for TPE-untrusted users"
80734 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
80735 + default 1005
80736 + help
80737 + Setting this GID determines which group untrusted users should
80738 + be added to. These users will be placed under grsecurity's Trusted Path
80739 + Execution mechanism, preventing them from executing their own binaries.
80740 + The users will only be able to execute binaries in directories owned and
80741 + writable only by the root user. If the sysctl option is enabled, a sysctl
80742 + option with name "tpe_gid" is created.
80743 +
80744 +config GRKERNSEC_TPE_TRUSTED_GID
80745 + int "GID for TPE-trusted users"
80746 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
80747 + default 1005
80748 + help
80749 + Setting this GID determines what group TPE restrictions will be
80750 + *disabled* for. If the sysctl option is enabled, a sysctl option
80751 + with name "tpe_gid" is created.
80752 +
80753 +config GRKERNSEC_SYMLINKOWN_GID
80754 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
80755 + depends on GRKERNSEC_CONFIG_SERVER
80756 + default 1006
80757 + help
80758 + Setting this GID determines what group kernel-enforced
80759 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
80760 + is enabled, a sysctl option with name "symlinkown_gid" is created.
80761 +
80762 +
80763 +endmenu
80764 +
80765 +menu "Customize Configuration"
80766 +depends on GRKERNSEC
80767 +
80768 +menu "PaX"
80769 +
80770 +config PAX
80771 + bool "Enable various PaX features"
80772 + default y if GRKERNSEC_CONFIG_AUTO
80773 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
80774 + help
80775 + This allows you to enable various PaX features. PaX adds
80776 + intrusion prevention mechanisms to the kernel that reduce
80777 + the risks posed by exploitable memory corruption bugs.
80778 +
80779 +menu "PaX Control"
80780 + depends on PAX
80781 +
80782 +config PAX_SOFTMODE
80783 + bool 'Support soft mode'
80784 + help
80785 + Enabling this option will allow you to run PaX in soft mode, that
80786 + is, PaX features will not be enforced by default, only on executables
80787 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
80788 + support as they are the only way to mark executables for soft mode use.
80789 +
80790 + Soft mode can be activated by using the "pax_softmode=1" kernel command
80791 + line option on boot. Furthermore you can control various PaX features
80792 + at runtime via the entries in /proc/sys/kernel/pax.
80793 +
80794 +config PAX_EI_PAX
80795 + bool 'Use legacy ELF header marking'
80796 + default y if GRKERNSEC_CONFIG_AUTO
80797 + help
80798 + Enabling this option will allow you to control PaX features on
80799 + a per executable basis via the 'chpax' utility available at
80800 + http://pax.grsecurity.net/. The control flags will be read from
80801 + an otherwise reserved part of the ELF header. This marking has
80802 + numerous drawbacks (no support for soft-mode, toolchain does not
80803 + know about the non-standard use of the ELF header) therefore it
80804 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
80805 + support.
80806 +
80807 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
80808 + support as well, they will override the legacy EI_PAX marks.
80809 +
80810 + If you enable none of the marking options then all applications
80811 + will run with PaX enabled on them by default.
80812 +
80813 +config PAX_PT_PAX_FLAGS
80814 + bool 'Use ELF program header marking'
80815 + default y if GRKERNSEC_CONFIG_AUTO
80816 + help
80817 + Enabling this option will allow you to control PaX features on
80818 + a per executable basis via the 'paxctl' utility available at
80819 + http://pax.grsecurity.net/. The control flags will be read from
80820 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
80821 + has the benefits of supporting both soft mode and being fully
80822 + integrated into the toolchain (the binutils patch is available
80823 + from http://pax.grsecurity.net).
80824 +
80825 + Note that if you enable the legacy EI_PAX marking support as well,
80826 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
80827 +
80828 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
80829 + must make sure that the marks are the same if a binary has both marks.
80830 +
80831 + If you enable none of the marking options then all applications
80832 + will run with PaX enabled on them by default.
80833 +
80834 +config PAX_XATTR_PAX_FLAGS
80835 + bool 'Use filesystem extended attributes marking'
80836 + default y if GRKERNSEC_CONFIG_AUTO
80837 + select CIFS_XATTR if CIFS
80838 + select EXT2_FS_XATTR if EXT2_FS
80839 + select EXT3_FS_XATTR if EXT3_FS
80840 + select EXT4_FS_XATTR if EXT4_FS
80841 + select JFFS2_FS_XATTR if JFFS2_FS
80842 + select REISERFS_FS_XATTR if REISERFS_FS
80843 + select SQUASHFS_XATTR if SQUASHFS
80844 + select TMPFS_XATTR if TMPFS
80845 + select UBIFS_FS_XATTR if UBIFS_FS
80846 + help
80847 + Enabling this option will allow you to control PaX features on
80848 + a per executable basis via the 'setfattr' utility. The control
80849 + flags will be read from the user.pax.flags extended attribute of
80850 + the file. This marking has the benefit of supporting binary-only
80851 + applications that self-check themselves (e.g., skype) and would
80852 + not tolerate chpax/paxctl changes. The main drawback is that
80853 + extended attributes are not supported by some filesystems (e.g.,
80854 + isofs, udf, vfat) so copying files through such filesystems will
80855 + lose the extended attributes and these PaX markings.
80856 +
80857 + Note that if you enable the legacy EI_PAX marking support as well,
80858 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
80859 +
80860 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
80861 + must make sure that the marks are the same if a binary has both marks.
80862 +
80863 + If you enable none of the marking options then all applications
80864 + will run with PaX enabled on them by default.
80865 +
80866 +choice
80867 + prompt 'MAC system integration'
80868 + default PAX_HAVE_ACL_FLAGS
80869 + help
80870 + Mandatory Access Control systems have the option of controlling
80871 + PaX flags on a per executable basis, choose the method supported
80872 + by your particular system.
80873 +
80874 + - "none": if your MAC system does not interact with PaX,
80875 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
80876 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
80877 +
80878 + NOTE: this option is for developers/integrators only.
80879 +
80880 + config PAX_NO_ACL_FLAGS
80881 + bool 'none'
80882 +
80883 + config PAX_HAVE_ACL_FLAGS
80884 + bool 'direct'
80885 +
80886 + config PAX_HOOK_ACL_FLAGS
80887 + bool 'hook'
80888 +endchoice
80889 +
80890 +endmenu
80891 +
80892 +menu "Non-executable pages"
80893 + depends on PAX
80894 +
80895 +config PAX_NOEXEC
80896 + bool "Enforce non-executable pages"
80897 + default y if GRKERNSEC_CONFIG_AUTO
80898 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
80899 + help
80900 + By design some architectures do not allow for protecting memory
80901 + pages against execution or even if they do, Linux does not make
80902 + use of this feature. In practice this means that if a page is
80903 + readable (such as the stack or heap) it is also executable.
80904 +
80905 + There is a well known exploit technique that makes use of this
80906 + fact and a common programming mistake where an attacker can
80907 + introduce code of his choice somewhere in the attacked program's
80908 + memory (typically the stack or the heap) and then execute it.
80909 +
80910 + If the attacked program was running with different (typically
80911 + higher) privileges than that of the attacker, then he can elevate
80912 + his own privilege level (e.g. get a root shell, write to files for
80913 + which he does not have write access to, etc).
80914 +
80915 + Enabling this option will let you choose from various features
80916 + that prevent the injection and execution of 'foreign' code in
80917 + a program.
80918 +
80919 + This will also break programs that rely on the old behaviour and
80920 + expect that dynamically allocated memory via the malloc() family
80921 + of functions is executable (which it is not). Notable examples
80922 + are the XFree86 4.x server, the java runtime and wine.
80923 +
80924 +config PAX_PAGEEXEC
80925 + bool "Paging based non-executable pages"
80926 + default y if GRKERNSEC_CONFIG_AUTO
80927 + 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)
80928 + select S390_SWITCH_AMODE if S390
80929 + select S390_EXEC_PROTECT if S390
80930 + select ARCH_TRACK_EXEC_LIMIT if X86_32
80931 + help
80932 + This implementation is based on the paging feature of the CPU.
80933 + On i386 without hardware non-executable bit support there is a
80934 + variable but usually low performance impact, however on Intel's
80935 + P4 core based CPUs it is very high so you should not enable this
80936 + for kernels meant to be used on such CPUs.
80937 +
80938 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
80939 + with hardware non-executable bit support there is no performance
80940 + impact, on ppc the impact is negligible.
80941 +
80942 + Note that several architectures require various emulations due to
80943 + badly designed userland ABIs, this will cause a performance impact
80944 + but will disappear as soon as userland is fixed. For example, ppc
80945 + userland MUST have been built with secure-plt by a recent toolchain.
80946 +
80947 +config PAX_SEGMEXEC
80948 + bool "Segmentation based non-executable pages"
80949 + default y if GRKERNSEC_CONFIG_AUTO
80950 + depends on PAX_NOEXEC && X86_32
80951 + help
80952 + This implementation is based on the segmentation feature of the
80953 + CPU and has a very small performance impact, however applications
80954 + will be limited to a 1.5 GB address space instead of the normal
80955 + 3 GB.
80956 +
80957 +config PAX_EMUTRAMP
80958 + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
80959 + default y if PARISC
80960 + help
80961 + There are some programs and libraries that for one reason or
80962 + another attempt to execute special small code snippets from
80963 + non-executable memory pages. Most notable examples are the
80964 + signal handler return code generated by the kernel itself and
80965 + the GCC trampolines.
80966 +
80967 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
80968 + such programs will no longer work under your kernel.
80969 +
80970 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
80971 + utilities to enable trampoline emulation for the affected programs
80972 + yet still have the protection provided by the non-executable pages.
80973 +
80974 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
80975 + your system will not even boot.
80976 +
80977 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
80978 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
80979 + for the affected files.
80980 +
80981 + NOTE: enabling this feature *may* open up a loophole in the
80982 + protection provided by non-executable pages that an attacker
80983 + could abuse. Therefore the best solution is to not have any
80984 + files on your system that would require this option. This can
80985 + be achieved by not using libc5 (which relies on the kernel
80986 + signal handler return code) and not using or rewriting programs
80987 + that make use of the nested function implementation of GCC.
80988 + Skilled users can just fix GCC itself so that it implements
80989 + nested function calls in a way that does not interfere with PaX.
80990 +
80991 +config PAX_EMUSIGRT
80992 + bool "Automatically emulate sigreturn trampolines"
80993 + depends on PAX_EMUTRAMP && PARISC
80994 + default y
80995 + help
80996 + Enabling this option will have the kernel automatically detect
80997 + and emulate signal return trampolines executing on the stack
80998 + that would otherwise lead to task termination.
80999 +
81000 + This solution is intended as a temporary one for users with
81001 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
81002 + Modula-3 runtime, etc) or executables linked to such, basically
81003 + everything that does not specify its own SA_RESTORER function in
81004 + normal executable memory like glibc 2.1+ does.
81005 +
81006 + On parisc you MUST enable this option, otherwise your system will
81007 + not even boot.
81008 +
81009 + NOTE: this feature cannot be disabled on a per executable basis
81010 + and since it *does* open up a loophole in the protection provided
81011 + by non-executable pages, the best solution is to not have any
81012 + files on your system that would require this option.
81013 +
81014 +config PAX_MPROTECT
81015 + bool "Restrict mprotect()"
81016 + default y if GRKERNSEC_CONFIG_AUTO
81017 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
81018 + help
81019 + Enabling this option will prevent programs from
81020 + - changing the executable status of memory pages that were
81021 + not originally created as executable,
81022 + - making read-only executable pages writable again,
81023 + - creating executable pages from anonymous memory,
81024 + - making read-only-after-relocations (RELRO) data pages writable again.
81025 +
81026 + You should say Y here to complete the protection provided by
81027 + the enforcement of non-executable pages.
81028 +
81029 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
81030 + this feature on a per file basis.
81031 +
81032 +config PAX_MPROTECT_COMPAT
81033 + bool "Use legacy/compat protection demoting (read help)"
81034 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
81035 + depends on PAX_MPROTECT
81036 + help
81037 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
81038 + by sending the proper error code to the application. For some broken
81039 + userland, this can cause problems with Python or other applications. The
81040 + current implementation however allows for applications like clamav to
81041 + detect if JIT compilation/execution is allowed and to fall back gracefully
81042 + to an interpreter-based mode if it does not. While we encourage everyone
81043 + to use the current implementation as-is and push upstream to fix broken
81044 + userland (note that the RWX logging option can assist with this), in some
81045 + environments this may not be possible. Having to disable MPROTECT
81046 + completely on certain binaries reduces the security benefit of PaX,
81047 + so this option is provided for those environments to revert to the old
81048 + behavior.
81049 +
81050 +config PAX_ELFRELOCS
81051 + bool "Allow ELF text relocations (read help)"
81052 + depends on PAX_MPROTECT
81053 + default n
81054 + help
81055 + Non-executable pages and mprotect() restrictions are effective
81056 + in preventing the introduction of new executable code into an
81057 + attacked task's address space. There remain only two venues
81058 + for this kind of attack: if the attacker can execute already
81059 + existing code in the attacked task then he can either have it
81060 + create and mmap() a file containing his code or have it mmap()
81061 + an already existing ELF library that does not have position
81062 + independent code in it and use mprotect() on it to make it
81063 + writable and copy his code there. While protecting against
81064 + the former approach is beyond PaX, the latter can be prevented
81065 + by having only PIC ELF libraries on one's system (which do not
81066 + need to relocate their code). If you are sure this is your case,
81067 + as is the case with all modern Linux distributions, then leave
81068 + this option disabled. You should say 'n' here.
81069 +
81070 +config PAX_ETEXECRELOCS
81071 + bool "Allow ELF ET_EXEC text relocations"
81072 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
81073 + select PAX_ELFRELOCS
81074 + default y
81075 + help
81076 + On some architectures there are incorrectly created applications
81077 + that require text relocations and would not work without enabling
81078 + this option. If you are an alpha, ia64 or parisc user, you should
81079 + enable this option and disable it once you have made sure that
81080 + none of your applications need it.
81081 +
81082 +config PAX_EMUPLT
81083 + bool "Automatically emulate ELF PLT"
81084 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
81085 + default y
81086 + help
81087 + Enabling this option will have the kernel automatically detect
81088 + and emulate the Procedure Linkage Table entries in ELF files.
81089 + On some architectures such entries are in writable memory, and
81090 + become non-executable leading to task termination. Therefore
81091 + it is mandatory that you enable this option on alpha, parisc,
81092 + sparc and sparc64, otherwise your system would not even boot.
81093 +
81094 + NOTE: this feature *does* open up a loophole in the protection
81095 + provided by the non-executable pages, therefore the proper
81096 + solution is to modify the toolchain to produce a PLT that does
81097 + not need to be writable.
81098 +
81099 +config PAX_DLRESOLVE
81100 + bool 'Emulate old glibc resolver stub'
81101 + depends on PAX_EMUPLT && SPARC
81102 + default n
81103 + help
81104 + This option is needed if userland has an old glibc (before 2.4)
81105 + that puts a 'save' instruction into the runtime generated resolver
81106 + stub that needs special emulation.
81107 +
81108 +config PAX_KERNEXEC
81109 + bool "Enforce non-executable kernel pages"
81110 + 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))
81111 + depends on (PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN
81112 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
81113 + select PAX_KERNEXEC_PLUGIN if X86_64
81114 + help
81115 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
81116 + that is, enabling this option will make it harder to inject
81117 + and execute 'foreign' code in kernel memory itself.
81118 +
81119 +choice
81120 + prompt "Return Address Instrumentation Method"
81121 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
81122 + depends on PAX_KERNEXEC_PLUGIN
81123 + help
81124 + Select the method used to instrument function pointer dereferences.
81125 + Note that binary modules cannot be instrumented by this approach.
81126 +
81127 + Note that the implementation requires a gcc with plugin support,
81128 + i.e., gcc 4.5 or newer. You may need to install the supporting
81129 + headers explicitly in addition to the normal gcc package.
81130 +
81131 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
81132 + bool "bts"
81133 + help
81134 + This method is compatible with binary only modules but has
81135 + a higher runtime overhead.
81136 +
81137 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
81138 + bool "or"
81139 + depends on !PARAVIRT
81140 + help
81141 + This method is incompatible with binary only modules but has
81142 + a lower runtime overhead.
81143 +endchoice
81144 +
81145 +config PAX_KERNEXEC_PLUGIN_METHOD
81146 + string
81147 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
81148 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
81149 + default ""
81150 +
81151 +config PAX_KERNEXEC_MODULE_TEXT
81152 + int "Minimum amount of memory reserved for module code"
81153 + default "4" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
81154 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
81155 + depends on PAX_KERNEXEC && X86_32 && MODULES
81156 + help
81157 + Due to implementation details the kernel must reserve a fixed
81158 + amount of memory for module code at compile time that cannot be
81159 + changed at runtime. Here you can specify the minimum amount
81160 + in MB that will be reserved. Due to the same implementation
81161 + details this size will always be rounded up to the next 2/4 MB
81162 + boundary (depends on PAE) so the actually available memory for
81163 + module code will usually be more than this minimum.
81164 +
81165 + The default 4 MB should be enough for most users but if you have
81166 + an excessive number of modules (e.g., most distribution configs
81167 + compile many drivers as modules) or use huge modules such as
81168 + nvidia's kernel driver, you will need to adjust this amount.
81169 + A good rule of thumb is to look at your currently loaded kernel
81170 + modules and add up their sizes.
81171 +
81172 +endmenu
81173 +
81174 +menu "Address Space Layout Randomization"
81175 + depends on PAX
81176 +
81177 +config PAX_ASLR
81178 + bool "Address Space Layout Randomization"
81179 + default y if GRKERNSEC_CONFIG_AUTO
81180 + help
81181 + Many if not most exploit techniques rely on the knowledge of
81182 + certain addresses in the attacked program. The following options
81183 + will allow the kernel to apply a certain amount of randomization
81184 + to specific parts of the program thereby forcing an attacker to
81185 + guess them in most cases. Any failed guess will most likely crash
81186 + the attacked program which allows the kernel to detect such attempts
81187 + and react on them. PaX itself provides no reaction mechanisms,
81188 + instead it is strongly encouraged that you make use of Nergal's
81189 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
81190 + (http://www.grsecurity.net/) built-in crash detection features or
81191 + develop one yourself.
81192 +
81193 + By saying Y here you can choose to randomize the following areas:
81194 + - top of the task's kernel stack
81195 + - top of the task's userland stack
81196 + - base address for mmap() requests that do not specify one
81197 + (this includes all libraries)
81198 + - base address of the main executable
81199 +
81200 + It is strongly recommended to say Y here as address space layout
81201 + randomization has negligible impact on performance yet it provides
81202 + a very effective protection.
81203 +
81204 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
81205 + this feature on a per file basis.
81206 +
81207 +config PAX_RANDKSTACK
81208 + bool "Randomize kernel stack base"
81209 + default y if GRKERNSEC_CONFIG_AUTO
81210 + depends on X86_TSC && X86
81211 + help
81212 + By saying Y here the kernel will randomize every task's kernel
81213 + stack on every system call. This will not only force an attacker
81214 + to guess it but also prevent him from making use of possible
81215 + leaked information about it.
81216 +
81217 + Since the kernel stack is a rather scarce resource, randomization
81218 + may cause unexpected stack overflows, therefore you should very
81219 + carefully test your system. Note that once enabled in the kernel
81220 + configuration, this feature cannot be disabled on a per file basis.
81221 +
81222 +config PAX_RANDUSTACK
81223 + bool "Randomize user stack base"
81224 + default y if GRKERNSEC_CONFIG_AUTO
81225 + depends on PAX_ASLR
81226 + help
81227 + By saying Y here the kernel will randomize every task's userland
81228 + stack. The randomization is done in two steps where the second
81229 + one may apply a big amount of shift to the top of the stack and
81230 + cause problems for programs that want to use lots of memory (more
81231 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
81232 + For this reason the second step can be controlled by 'chpax' or
81233 + 'paxctl' on a per file basis.
81234 +
81235 +config PAX_RANDMMAP
81236 + bool "Randomize mmap() base"
81237 + default y if GRKERNSEC_CONFIG_AUTO
81238 + depends on PAX_ASLR
81239 + help
81240 + By saying Y here the kernel will use a randomized base address for
81241 + mmap() requests that do not specify one themselves. As a result
81242 + all dynamically loaded libraries will appear at random addresses
81243 + and therefore be harder to exploit by a technique where an attacker
81244 + attempts to execute library code for his purposes (e.g. spawn a
81245 + shell from an exploited program that is running at an elevated
81246 + privilege level).
81247 +
81248 + Furthermore, if a program is relinked as a dynamic ELF file, its
81249 + base address will be randomized as well, completing the full
81250 + randomization of the address space layout. Attacking such programs
81251 + becomes a guess game. You can find an example of doing this at
81252 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
81253 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
81254 +
81255 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
81256 + feature on a per file basis.
81257 +
81258 +endmenu
81259 +
81260 +menu "Miscellaneous hardening features"
81261 +
81262 +config PAX_MEMORY_SANITIZE
81263 + bool "Sanitize all freed memory"
81264 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
81265 + depends on !HIBERNATION
81266 + help
81267 + By saying Y here the kernel will erase memory pages as soon as they
81268 + are freed. This in turn reduces the lifetime of data stored in the
81269 + pages, making it less likely that sensitive information such as
81270 + passwords, cryptographic secrets, etc stay in memory for too long.
81271 +
81272 + This is especially useful for programs whose runtime is short, long
81273 + lived processes and the kernel itself benefit from this as long as
81274 + they operate on whole memory pages and ensure timely freeing of pages
81275 + that may hold sensitive information.
81276 +
81277 + The tradeoff is performance impact, on a single CPU system kernel
81278 + compilation sees a 3% slowdown, other systems and workloads may vary
81279 + and you are advised to test this feature on your expected workload
81280 + before deploying it.
81281 +
81282 + Note that this feature does not protect data stored in live pages,
81283 + e.g., process memory swapped to disk may stay there for a long time.
81284 +
81285 +config PAX_MEMORY_STACKLEAK
81286 + bool "Sanitize kernel stack"
81287 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
81288 + depends on X86
81289 + help
81290 + By saying Y here the kernel will erase the kernel stack before it
81291 + returns from a system call. This in turn reduces the information
81292 + that a kernel stack leak bug can reveal.
81293 +
81294 + Note that such a bug can still leak information that was put on
81295 + the stack by the current system call (the one eventually triggering
81296 + the bug) but traces of earlier system calls on the kernel stack
81297 + cannot leak anymore.
81298 +
81299 + The tradeoff is performance impact: on a single CPU system kernel
81300 + compilation sees a 1% slowdown, other systems and workloads may vary
81301 + and you are advised to test this feature on your expected workload
81302 + before deploying it.
81303 +
81304 + Note that the full feature requires a gcc with plugin support,
81305 + i.e., gcc 4.5 or newer. You may need to install the supporting
81306 + headers explicitly in addition to the normal gcc package. Using
81307 + older gcc versions means that functions with large enough stack
81308 + frames may leave uninitialized memory behind that may be exposed
81309 + to a later syscall leaking the stack.
81310 +
81311 +config PAX_MEMORY_UDEREF
81312 + bool "Prevent invalid userland pointer dereference"
81313 + default y if GRKERNSEC_CONFIG_AUTO && (X86_32 || (X86_64 && GRKERNSEC_CONFIG_PRIORITY_SECURITY)) && (GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
81314 + depends on X86 && !UML_X86 && !XEN
81315 + select PAX_PER_CPU_PGD if X86_64
81316 + help
81317 + By saying Y here the kernel will be prevented from dereferencing
81318 + userland pointers in contexts where the kernel expects only kernel
81319 + pointers. This is both a useful runtime debugging feature and a
81320 + security measure that prevents exploiting a class of kernel bugs.
81321 +
81322 + The tradeoff is that some virtualization solutions may experience
81323 + a huge slowdown and therefore you should not enable this feature
81324 + for kernels meant to run in such environments. Whether a given VM
81325 + solution is affected or not is best determined by simply trying it
81326 + out, the performance impact will be obvious right on boot as this
81327 + mechanism engages from very early on. A good rule of thumb is that
81328 + VMs running on CPUs without hardware virtualization support (i.e.,
81329 + the majority of IA-32 CPUs) will likely experience the slowdown.
81330 +
81331 +config PAX_REFCOUNT
81332 + bool "Prevent various kernel object reference counter overflows"
81333 + default y if GRKERNSEC_CONFIG_AUTO
81334 + depends on GRKERNSEC && ((ARM && (CPU_32v6 || CPU_32v6K || CPU_32v7)) || SPARC64 || X86)
81335 + help
81336 + By saying Y here the kernel will detect and prevent overflowing
81337 + various (but not all) kinds of object reference counters. Such
81338 + overflows can normally occur due to bugs only and are often, if
81339 + not always, exploitable.
81340 +
81341 + The tradeoff is that data structures protected by an overflowed
81342 + refcount will never be freed and therefore will leak memory. Note
81343 + that this leak also happens even without this protection but in
81344 + that case the overflow can eventually trigger the freeing of the
81345 + data structure while it is still being used elsewhere, resulting
81346 + in the exploitable situation that this feature prevents.
81347 +
81348 + Since this has a negligible performance impact, you should enable
81349 + this feature.
81350 +
81351 +config PAX_USERCOPY
81352 + bool "Harden heap object copies between kernel and userland"
81353 + default y if GRKERNSEC_CONFIG_AUTO
81354 + depends on X86 || PPC || SPARC || ARM
81355 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
81356 + select PAX_USERCOPY_SLABS
81357 + help
81358 + By saying Y here the kernel will enforce the size of heap objects
81359 + when they are copied in either direction between the kernel and
81360 + userland, even if only a part of the heap object is copied.
81361 +
81362 + Specifically, this checking prevents information leaking from the
81363 + kernel heap during kernel to userland copies (if the kernel heap
81364 + object is otherwise fully initialized) and prevents kernel heap
81365 + overflows during userland to kernel copies.
81366 +
81367 + Note that the current implementation provides the strictest bounds
81368 + checks for the SLUB allocator.
81369 +
81370 + Enabling this option also enables per-slab cache protection against
81371 + data in a given cache being copied into/out of via userland
81372 + accessors. Though the whitelist of regions will be reduced over
81373 + time, it notably protects important data structures like task structs.
81374 +
81375 + If frame pointers are enabled on x86, this option will also restrict
81376 + copies into and out of the kernel stack to local variables within a
81377 + single frame.
81378 +
81379 + Since this has a negligible performance impact, you should enable
81380 + this feature.
81381 +
81382 +config PAX_SIZE_OVERFLOW
81383 + bool "Prevent various integer overflows in function size parameters"
81384 + default y if GRKERNSEC_CONFIG_AUTO
81385 + depends on X86
81386 + help
81387 + By saying Y here the kernel recomputes expressions of function
81388 + arguments marked by a size_overflow attribute with double integer
81389 + precision (DImode/TImode for 32/64 bit integer types).
81390 +
81391 + The recomputed argument is checked against TYPE_MAX and an event
81392 + is logged on overflow and the triggering process is killed.
81393 +
81394 + Homepage: http://www.grsecurity.net/~ephox/overflow_plugin/
81395 +
81396 + Note that the implementation requires a gcc with plugin support,
81397 + i.e., gcc 4.5 or newer. You may need to install the supporting
81398 + headers explicitly in addition to the normal gcc package.
81399 +
81400 +config PAX_LATENT_ENTROPY
81401 + bool "Generate some entropy during boot"
81402 + default y if GRKERNSEC_CONFIG_AUTO
81403 + help
81404 + By saying Y here the kernel will instrument early boot code to
81405 + extract some entropy from both original and artificially created
81406 + program state. This will help especially embedded systems where
81407 + there is little 'natural' source of entropy normally. The cost
81408 + is some slowdown of the boot process.
81409 +
81410 + Note that the implementation requires a gcc with plugin support,
81411 + i.e., gcc 4.5 or newer. You may need to install the supporting
81412 + headers explicitly in addition to the normal gcc package.
81413 +
81414 + Note that entropy extracted this way is not cryptographically
81415 + secure!
81416 +
81417 +endmenu
81418 +
81419 +endmenu
81420 +
81421 +source grsecurity/Kconfig
81422 +
81423 +endmenu
81424 +
81425 +endmenu
81426 +
81427 source security/keys/Kconfig
81428
81429 config SECURITY_DMESG_RESTRICT
81430 @@ -103,7 +993,7 @@ config INTEL_TXT
81431 config LSM_MMAP_MIN_ADDR
81432 int "Low address space for LSM to protect from user allocation"
81433 depends on SECURITY && SECURITY_SELINUX
81434 - default 32768 if ARM
81435 + default 32768 if ALPHA || ARM || PARISC || SPARC32
81436 default 65536
81437 help
81438 This is the portion of low virtual memory which should be protected
81439 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
81440 index 8ea39aa..8569ac5 100644
81441 --- a/security/apparmor/lsm.c
81442 +++ b/security/apparmor/lsm.c
81443 @@ -614,7 +614,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
81444 return error;
81445 }
81446
81447 -static struct security_operations apparmor_ops = {
81448 +static struct security_operations apparmor_ops __read_only = {
81449 .name = "apparmor",
81450
81451 .ptrace_access_check = apparmor_ptrace_access_check,
81452 diff --git a/security/commoncap.c b/security/commoncap.c
81453 index 6dbae46..d5611fd 100644
81454 --- a/security/commoncap.c
81455 +++ b/security/commoncap.c
81456 @@ -415,6 +415,32 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data
81457 return 0;
81458 }
81459
81460 +/* returns:
81461 + 1 for suid privilege
81462 + 2 for sgid privilege
81463 + 3 for fscap privilege
81464 +*/
81465 +int is_privileged_binary(const struct dentry *dentry)
81466 +{
81467 + struct cpu_vfs_cap_data capdata;
81468 + struct inode *inode = dentry->d_inode;
81469 +
81470 + if (!inode || S_ISDIR(inode->i_mode))
81471 + return 0;
81472 +
81473 + if (inode->i_mode & S_ISUID)
81474 + return 1;
81475 + if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
81476 + return 2;
81477 +
81478 + if (!get_vfs_caps_from_disk(dentry, &capdata)) {
81479 + if (!cap_isclear(capdata.inheritable) || !cap_isclear(capdata.permitted))
81480 + return 3;
81481 + }
81482 +
81483 + return 0;
81484 +}
81485 +
81486 /*
81487 * Attempt to get the on-exec apply capability sets for an executable file from
81488 * its xattrs and, if present, apply them to the proposed credentials being
81489 @@ -583,6 +609,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
81490 const struct cred *cred = current_cred();
81491 kuid_t root_uid = make_kuid(cred->user_ns, 0);
81492
81493 + if (gr_acl_enable_at_secure())
81494 + return 1;
81495 +
81496 if (!uid_eq(cred->uid, root_uid)) {
81497 if (bprm->cap_effective)
81498 return 1;
81499 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
81500 index e7c99fd..5b2fa24 100644
81501 --- a/security/integrity/ima/ima.h
81502 +++ b/security/integrity/ima/ima.h
81503 @@ -95,8 +95,8 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
81504 extern spinlock_t ima_queue_lock;
81505
81506 struct ima_h_table {
81507 - atomic_long_t len; /* number of stored measurements in the list */
81508 - atomic_long_t violations;
81509 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
81510 + atomic_long_unchecked_t violations;
81511 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
81512 };
81513 extern struct ima_h_table ima_htable;
81514 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
81515 index 032ff03..c428a74 100644
81516 --- a/security/integrity/ima/ima_api.c
81517 +++ b/security/integrity/ima/ima_api.c
81518 @@ -75,7 +75,7 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
81519 int result;
81520
81521 /* can overflow, only indicator */
81522 - atomic_long_inc(&ima_htable.violations);
81523 + atomic_long_inc_unchecked(&ima_htable.violations);
81524
81525 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
81526 if (!entry) {
81527 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
81528 index 38477c9..87a60c7 100644
81529 --- a/security/integrity/ima/ima_fs.c
81530 +++ b/security/integrity/ima/ima_fs.c
81531 @@ -28,12 +28,12 @@
81532 static int valid_policy = 1;
81533 #define TMPBUFLEN 12
81534 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
81535 - loff_t *ppos, atomic_long_t *val)
81536 + loff_t *ppos, atomic_long_unchecked_t *val)
81537 {
81538 char tmpbuf[TMPBUFLEN];
81539 ssize_t len;
81540
81541 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
81542 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
81543 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
81544 }
81545
81546 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
81547 index 55a6271..ad829c3 100644
81548 --- a/security/integrity/ima/ima_queue.c
81549 +++ b/security/integrity/ima/ima_queue.c
81550 @@ -81,7 +81,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
81551 INIT_LIST_HEAD(&qe->later);
81552 list_add_tail_rcu(&qe->later, &ima_measurements);
81553
81554 - atomic_long_inc(&ima_htable.len);
81555 + atomic_long_inc_unchecked(&ima_htable.len);
81556 key = ima_hash_key(entry->digest);
81557 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
81558 return 0;
81559 diff --git a/security/keys/compat.c b/security/keys/compat.c
81560 index 1c26176..64a1ba2 100644
81561 --- a/security/keys/compat.c
81562 +++ b/security/keys/compat.c
81563 @@ -44,7 +44,7 @@ static long compat_keyctl_instantiate_key_iov(
81564 if (ret == 0)
81565 goto no_payload_free;
81566
81567 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
81568 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
81569
81570 if (iov != iovstack)
81571 kfree(iov);
81572 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
81573 index 3364fbf..1f10f31 100644
81574 --- a/security/keys/keyctl.c
81575 +++ b/security/keys/keyctl.c
81576 @@ -966,7 +966,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
81577 /*
81578 * Copy the iovec data from userspace
81579 */
81580 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
81581 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
81582 unsigned ioc)
81583 {
81584 for (; ioc > 0; ioc--) {
81585 @@ -988,7 +988,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
81586 * If successful, 0 will be returned.
81587 */
81588 long keyctl_instantiate_key_common(key_serial_t id,
81589 - const struct iovec *payload_iov,
81590 + const struct iovec __user *payload_iov,
81591 unsigned ioc,
81592 size_t plen,
81593 key_serial_t ringid)
81594 @@ -1083,7 +1083,7 @@ long keyctl_instantiate_key(key_serial_t id,
81595 [0].iov_len = plen
81596 };
81597
81598 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
81599 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
81600 }
81601
81602 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
81603 @@ -1116,7 +1116,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
81604 if (ret == 0)
81605 goto no_payload_free;
81606
81607 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
81608 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
81609
81610 if (iov != iovstack)
81611 kfree(iov);
81612 diff --git a/security/keys/keyring.c b/security/keys/keyring.c
81613 index 81e7852..2b2ecc3 100644
81614 --- a/security/keys/keyring.c
81615 +++ b/security/keys/keyring.c
81616 @@ -227,16 +227,16 @@ static long keyring_read(const struct key *keyring,
81617 ret = -EFAULT;
81618
81619 for (loop = 0; loop < klist->nkeys; loop++) {
81620 + key_serial_t serial;
81621 key = rcu_deref_link_locked(klist, loop,
81622 keyring);
81623 + serial = key->serial;
81624
81625 tmp = sizeof(key_serial_t);
81626 if (tmp > buflen)
81627 tmp = buflen;
81628
81629 - if (copy_to_user(buffer,
81630 - &key->serial,
81631 - tmp) != 0)
81632 + if (copy_to_user(buffer, &serial, tmp))
81633 goto error;
81634
81635 buflen -= tmp;
81636 diff --git a/security/min_addr.c b/security/min_addr.c
81637 index f728728..6457a0c 100644
81638 --- a/security/min_addr.c
81639 +++ b/security/min_addr.c
81640 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
81641 */
81642 static void update_mmap_min_addr(void)
81643 {
81644 +#ifndef SPARC
81645 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
81646 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
81647 mmap_min_addr = dac_mmap_min_addr;
81648 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
81649 #else
81650 mmap_min_addr = dac_mmap_min_addr;
81651 #endif
81652 +#endif
81653 }
81654
81655 /*
81656 diff --git a/security/security.c b/security/security.c
81657 index 860aeb3..45765c0 100644
81658 --- a/security/security.c
81659 +++ b/security/security.c
81660 @@ -20,6 +20,7 @@
81661 #include <linux/ima.h>
81662 #include <linux/evm.h>
81663 #include <linux/fsnotify.h>
81664 +#include <linux/mm.h>
81665 #include <linux/mman.h>
81666 #include <linux/mount.h>
81667 #include <linux/personality.h>
81668 @@ -32,8 +33,8 @@
81669 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
81670 CONFIG_DEFAULT_SECURITY;
81671
81672 -static struct security_operations *security_ops;
81673 -static struct security_operations default_security_ops = {
81674 +static struct security_operations *security_ops __read_only;
81675 +static struct security_operations default_security_ops __read_only = {
81676 .name = "default",
81677 };
81678
81679 @@ -74,7 +75,9 @@ int __init security_init(void)
81680
81681 void reset_security_ops(void)
81682 {
81683 + pax_open_kernel();
81684 security_ops = &default_security_ops;
81685 + pax_close_kernel();
81686 }
81687
81688 /* Save user chosen LSM */
81689 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
81690 index 6c77f63..7496c76 100644
81691 --- a/security/selinux/hooks.c
81692 +++ b/security/selinux/hooks.c
81693 @@ -95,8 +95,6 @@
81694
81695 #define NUM_SEL_MNT_OPTS 5
81696
81697 -extern struct security_operations *security_ops;
81698 -
81699 /* SECMARK reference count */
81700 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
81701
81702 @@ -5511,7 +5509,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
81703
81704 #endif
81705
81706 -static struct security_operations selinux_ops = {
81707 +static struct security_operations selinux_ops __read_only = {
81708 .name = "selinux",
81709
81710 .ptrace_access_check = selinux_ptrace_access_check,
81711 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
81712 index 65f67cb..3f141ef 100644
81713 --- a/security/selinux/include/xfrm.h
81714 +++ b/security/selinux/include/xfrm.h
81715 @@ -50,7 +50,7 @@ int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall);
81716
81717 static inline void selinux_xfrm_notify_policyload(void)
81718 {
81719 - atomic_inc(&flow_cache_genid);
81720 + atomic_inc_unchecked(&flow_cache_genid);
81721 rt_genid_bump(&init_net);
81722 }
81723 #else
81724 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
81725 index 8221514..5c4775f 100644
81726 --- a/security/smack/smack_lsm.c
81727 +++ b/security/smack/smack_lsm.c
81728 @@ -3429,7 +3429,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
81729 return 0;
81730 }
81731
81732 -struct security_operations smack_ops = {
81733 +struct security_operations smack_ops __read_only = {
81734 .name = "smack",
81735
81736 .ptrace_access_check = smack_ptrace_access_check,
81737 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
81738 index c2d04a5..e6a1aeb 100644
81739 --- a/security/tomoyo/tomoyo.c
81740 +++ b/security/tomoyo/tomoyo.c
81741 @@ -501,7 +501,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
81742 * tomoyo_security_ops is a "struct security_operations" which is used for
81743 * registering TOMOYO.
81744 */
81745 -static struct security_operations tomoyo_security_ops = {
81746 +static struct security_operations tomoyo_security_ops __read_only = {
81747 .name = "tomoyo",
81748 .cred_alloc_blank = tomoyo_cred_alloc_blank,
81749 .cred_prepare = tomoyo_cred_prepare,
81750 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
81751 index 51d6709..1f3dbe2 100644
81752 --- a/security/yama/Kconfig
81753 +++ b/security/yama/Kconfig
81754 @@ -1,6 +1,6 @@
81755 config SECURITY_YAMA
81756 bool "Yama support"
81757 - depends on SECURITY
81758 + depends on SECURITY && !GRKERNSEC
81759 select SECURITYFS
81760 select SECURITY_PATH
81761 default n
81762 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
81763 index 4cedc69..e59d8a3 100644
81764 --- a/sound/aoa/codecs/onyx.c
81765 +++ b/sound/aoa/codecs/onyx.c
81766 @@ -54,7 +54,7 @@ struct onyx {
81767 spdif_locked:1,
81768 analog_locked:1,
81769 original_mute:2;
81770 - int open_count;
81771 + local_t open_count;
81772 struct codec_info *codec_info;
81773
81774 /* mutex serializes concurrent access to the device
81775 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
81776 struct onyx *onyx = cii->codec_data;
81777
81778 mutex_lock(&onyx->mutex);
81779 - onyx->open_count++;
81780 + local_inc(&onyx->open_count);
81781 mutex_unlock(&onyx->mutex);
81782
81783 return 0;
81784 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
81785 struct onyx *onyx = cii->codec_data;
81786
81787 mutex_lock(&onyx->mutex);
81788 - onyx->open_count--;
81789 - if (!onyx->open_count)
81790 + if (local_dec_and_test(&onyx->open_count))
81791 onyx->spdif_locked = onyx->analog_locked = 0;
81792 mutex_unlock(&onyx->mutex);
81793
81794 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
81795 index ffd2025..df062c9 100644
81796 --- a/sound/aoa/codecs/onyx.h
81797 +++ b/sound/aoa/codecs/onyx.h
81798 @@ -11,6 +11,7 @@
81799 #include <linux/i2c.h>
81800 #include <asm/pmac_low_i2c.h>
81801 #include <asm/prom.h>
81802 +#include <asm/local.h>
81803
81804 /* PCM3052 register definitions */
81805
81806 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
81807 index 4c1cc51..16040040 100644
81808 --- a/sound/core/oss/pcm_oss.c
81809 +++ b/sound/core/oss/pcm_oss.c
81810 @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
81811 if (in_kernel) {
81812 mm_segment_t fs;
81813 fs = snd_enter_user();
81814 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
81815 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
81816 snd_leave_user(fs);
81817 } else {
81818 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
81819 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
81820 }
81821 if (ret != -EPIPE && ret != -ESTRPIPE)
81822 break;
81823 @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
81824 if (in_kernel) {
81825 mm_segment_t fs;
81826 fs = snd_enter_user();
81827 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
81828 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
81829 snd_leave_user(fs);
81830 } else {
81831 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
81832 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
81833 }
81834 if (ret == -EPIPE) {
81835 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
81836 @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
81837 struct snd_pcm_plugin_channel *channels;
81838 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
81839 if (!in_kernel) {
81840 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
81841 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
81842 return -EFAULT;
81843 buf = runtime->oss.buffer;
81844 }
81845 @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
81846 }
81847 } else {
81848 tmp = snd_pcm_oss_write2(substream,
81849 - (const char __force *)buf,
81850 + (const char __force_kernel *)buf,
81851 runtime->oss.period_bytes, 0);
81852 if (tmp <= 0)
81853 goto err;
81854 @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
81855 struct snd_pcm_runtime *runtime = substream->runtime;
81856 snd_pcm_sframes_t frames, frames1;
81857 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
81858 - char __user *final_dst = (char __force __user *)buf;
81859 + char __user *final_dst = (char __force_user *)buf;
81860 if (runtime->oss.plugin_first) {
81861 struct snd_pcm_plugin_channel *channels;
81862 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
81863 @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
81864 xfer += tmp;
81865 runtime->oss.buffer_used -= tmp;
81866 } else {
81867 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
81868 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
81869 runtime->oss.period_bytes, 0);
81870 if (tmp <= 0)
81871 goto err;
81872 @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
81873 size1);
81874 size1 /= runtime->channels; /* frames */
81875 fs = snd_enter_user();
81876 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
81877 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
81878 snd_leave_user(fs);
81879 }
81880 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
81881 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
81882 index 91cdf94..4085161 100644
81883 --- a/sound/core/pcm_compat.c
81884 +++ b/sound/core/pcm_compat.c
81885 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
81886 int err;
81887
81888 fs = snd_enter_user();
81889 - err = snd_pcm_delay(substream, &delay);
81890 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
81891 snd_leave_user(fs);
81892 if (err < 0)
81893 return err;
81894 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
81895 index bf3bf43..3826cbc 100644
81896 --- a/sound/core/pcm_native.c
81897 +++ b/sound/core/pcm_native.c
81898 @@ -2803,11 +2803,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
81899 switch (substream->stream) {
81900 case SNDRV_PCM_STREAM_PLAYBACK:
81901 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
81902 - (void __user *)arg);
81903 + (void __force_user *)arg);
81904 break;
81905 case SNDRV_PCM_STREAM_CAPTURE:
81906 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
81907 - (void __user *)arg);
81908 + (void __force_user *)arg);
81909 break;
81910 default:
81911 result = -EINVAL;
81912 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
81913 index 5cf8d65..912a79c 100644
81914 --- a/sound/core/seq/seq_device.c
81915 +++ b/sound/core/seq/seq_device.c
81916 @@ -64,7 +64,7 @@ struct ops_list {
81917 int argsize; /* argument size */
81918
81919 /* operators */
81920 - struct snd_seq_dev_ops ops;
81921 + struct snd_seq_dev_ops *ops;
81922
81923 /* registred devices */
81924 struct list_head dev_list; /* list of devices */
81925 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
81926
81927 mutex_lock(&ops->reg_mutex);
81928 /* copy driver operators */
81929 - ops->ops = *entry;
81930 + ops->ops = entry;
81931 ops->driver |= DRIVER_LOADED;
81932 ops->argsize = argsize;
81933
81934 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
81935 dev->name, ops->id, ops->argsize, dev->argsize);
81936 return -EINVAL;
81937 }
81938 - if (ops->ops.init_device(dev) >= 0) {
81939 + if (ops->ops->init_device(dev) >= 0) {
81940 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
81941 ops->num_init_devices++;
81942 } else {
81943 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
81944 dev->name, ops->id, ops->argsize, dev->argsize);
81945 return -EINVAL;
81946 }
81947 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
81948 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
81949 dev->status = SNDRV_SEQ_DEVICE_FREE;
81950 dev->driver_data = NULL;
81951 ops->num_init_devices--;
81952 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
81953 index 2d5514b..3afae9c 100644
81954 --- a/sound/drivers/mts64.c
81955 +++ b/sound/drivers/mts64.c
81956 @@ -29,6 +29,7 @@
81957 #include <sound/initval.h>
81958 #include <sound/rawmidi.h>
81959 #include <sound/control.h>
81960 +#include <asm/local.h>
81961
81962 #define CARD_NAME "Miditerminal 4140"
81963 #define DRIVER_NAME "MTS64"
81964 @@ -67,7 +68,7 @@ struct mts64 {
81965 struct pardevice *pardev;
81966 int pardev_claimed;
81967
81968 - int open_count;
81969 + local_t open_count;
81970 int current_midi_output_port;
81971 int current_midi_input_port;
81972 u8 mode[MTS64_NUM_INPUT_PORTS];
81973 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
81974 {
81975 struct mts64 *mts = substream->rmidi->private_data;
81976
81977 - if (mts->open_count == 0) {
81978 + if (local_read(&mts->open_count) == 0) {
81979 /* We don't need a spinlock here, because this is just called
81980 if the device has not been opened before.
81981 So there aren't any IRQs from the device */
81982 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
81983
81984 msleep(50);
81985 }
81986 - ++(mts->open_count);
81987 + local_inc(&mts->open_count);
81988
81989 return 0;
81990 }
81991 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
81992 struct mts64 *mts = substream->rmidi->private_data;
81993 unsigned long flags;
81994
81995 - --(mts->open_count);
81996 - if (mts->open_count == 0) {
81997 + if (local_dec_return(&mts->open_count) == 0) {
81998 /* We need the spinlock_irqsave here because we can still
81999 have IRQs at this point */
82000 spin_lock_irqsave(&mts->lock, flags);
82001 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
82002
82003 msleep(500);
82004
82005 - } else if (mts->open_count < 0)
82006 - mts->open_count = 0;
82007 + } else if (local_read(&mts->open_count) < 0)
82008 + local_set(&mts->open_count, 0);
82009
82010 return 0;
82011 }
82012 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
82013 index b953fb4..1999c01 100644
82014 --- a/sound/drivers/opl4/opl4_lib.c
82015 +++ b/sound/drivers/opl4/opl4_lib.c
82016 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
82017 MODULE_DESCRIPTION("OPL4 driver");
82018 MODULE_LICENSE("GPL");
82019
82020 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
82021 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
82022 {
82023 int timeout = 10;
82024 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
82025 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
82026 index 8364855..59f2e2b 100644
82027 --- a/sound/drivers/portman2x4.c
82028 +++ b/sound/drivers/portman2x4.c
82029 @@ -48,6 +48,7 @@
82030 #include <sound/initval.h>
82031 #include <sound/rawmidi.h>
82032 #include <sound/control.h>
82033 +#include <asm/local.h>
82034
82035 #define CARD_NAME "Portman 2x4"
82036 #define DRIVER_NAME "portman"
82037 @@ -85,7 +86,7 @@ struct portman {
82038 struct pardevice *pardev;
82039 int pardev_claimed;
82040
82041 - int open_count;
82042 + local_t open_count;
82043 int mode[PORTMAN_NUM_INPUT_PORTS];
82044 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
82045 };
82046 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
82047 index ea995af..f1bfa37 100644
82048 --- a/sound/firewire/amdtp.c
82049 +++ b/sound/firewire/amdtp.c
82050 @@ -389,7 +389,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
82051 ptr = s->pcm_buffer_pointer + data_blocks;
82052 if (ptr >= pcm->runtime->buffer_size)
82053 ptr -= pcm->runtime->buffer_size;
82054 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
82055 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
82056
82057 s->pcm_period_pointer += data_blocks;
82058 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
82059 @@ -557,7 +557,7 @@ EXPORT_SYMBOL(amdtp_out_stream_pcm_pointer);
82060 */
82061 void amdtp_out_stream_update(struct amdtp_out_stream *s)
82062 {
82063 - ACCESS_ONCE(s->source_node_id_field) =
82064 + ACCESS_ONCE_RW(s->source_node_id_field) =
82065 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
82066 }
82067 EXPORT_SYMBOL(amdtp_out_stream_update);
82068 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
82069 index b680c5e..061b7a0 100644
82070 --- a/sound/firewire/amdtp.h
82071 +++ b/sound/firewire/amdtp.h
82072 @@ -139,7 +139,7 @@ static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s)
82073 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
82074 struct snd_pcm_substream *pcm)
82075 {
82076 - ACCESS_ONCE(s->pcm) = pcm;
82077 + ACCESS_ONCE_RW(s->pcm) = pcm;
82078 }
82079
82080 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
82081 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
82082 index d428ffe..751ef78 100644
82083 --- a/sound/firewire/isight.c
82084 +++ b/sound/firewire/isight.c
82085 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
82086 ptr += count;
82087 if (ptr >= runtime->buffer_size)
82088 ptr -= runtime->buffer_size;
82089 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
82090 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
82091
82092 isight->period_counter += count;
82093 if (isight->period_counter >= runtime->period_size) {
82094 @@ -307,7 +307,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
82095 if (err < 0)
82096 return err;
82097
82098 - ACCESS_ONCE(isight->pcm_active) = true;
82099 + ACCESS_ONCE_RW(isight->pcm_active) = true;
82100
82101 return 0;
82102 }
82103 @@ -340,7 +340,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
82104 {
82105 struct isight *isight = substream->private_data;
82106
82107 - ACCESS_ONCE(isight->pcm_active) = false;
82108 + ACCESS_ONCE_RW(isight->pcm_active) = false;
82109
82110 mutex_lock(&isight->mutex);
82111 isight_stop_streaming(isight);
82112 @@ -433,10 +433,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
82113
82114 switch (cmd) {
82115 case SNDRV_PCM_TRIGGER_START:
82116 - ACCESS_ONCE(isight->pcm_running) = true;
82117 + ACCESS_ONCE_RW(isight->pcm_running) = true;
82118 break;
82119 case SNDRV_PCM_TRIGGER_STOP:
82120 - ACCESS_ONCE(isight->pcm_running) = false;
82121 + ACCESS_ONCE_RW(isight->pcm_running) = false;
82122 break;
82123 default:
82124 return -EINVAL;
82125 diff --git a/sound/isa/cmi8330.c b/sound/isa/cmi8330.c
82126 index 7bd5e33..1fcab12 100644
82127 --- a/sound/isa/cmi8330.c
82128 +++ b/sound/isa/cmi8330.c
82129 @@ -172,7 +172,7 @@ struct snd_cmi8330 {
82130
82131 struct snd_pcm *pcm;
82132 struct snd_cmi8330_stream {
82133 - struct snd_pcm_ops ops;
82134 + snd_pcm_ops_no_const ops;
82135 snd_pcm_open_callback_t open;
82136 void *private_data; /* sb or wss */
82137 } streams[2];
82138 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
82139 index b2b3c01..e1c1e1f 100644
82140 --- a/sound/oss/sb_audio.c
82141 +++ b/sound/oss/sb_audio.c
82142 @@ -903,7 +903,7 @@ sb16_copy_from_user(int dev,
82143 buf16 = (signed short *)(localbuf + localoffs);
82144 while (c)
82145 {
82146 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
82147 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
82148 if (copy_from_user(lbuf8,
82149 userbuf+useroffs + p,
82150 locallen))
82151 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
82152 index 7d8803a..559f8d0 100644
82153 --- a/sound/oss/swarm_cs4297a.c
82154 +++ b/sound/oss/swarm_cs4297a.c
82155 @@ -2621,7 +2621,6 @@ static int __init cs4297a_init(void)
82156 {
82157 struct cs4297a_state *s;
82158 u32 pwr, id;
82159 - mm_segment_t fs;
82160 int rval;
82161 #ifndef CONFIG_BCM_CS4297A_CSWARM
82162 u64 cfg;
82163 @@ -2711,22 +2710,23 @@ static int __init cs4297a_init(void)
82164 if (!rval) {
82165 char *sb1250_duart_present;
82166
82167 +#if 0
82168 + mm_segment_t fs;
82169 fs = get_fs();
82170 set_fs(KERNEL_DS);
82171 -#if 0
82172 val = SOUND_MASK_LINE;
82173 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
82174 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
82175 val = initvol[i].vol;
82176 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
82177 }
82178 + set_fs(fs);
82179 // cs4297a_write_ac97(s, 0x18, 0x0808);
82180 #else
82181 // cs4297a_write_ac97(s, 0x5e, 0x180);
82182 cs4297a_write_ac97(s, 0x02, 0x0808);
82183 cs4297a_write_ac97(s, 0x18, 0x0808);
82184 #endif
82185 - set_fs(fs);
82186
82187 list_add(&s->list, &cs4297a_devs);
82188
82189 diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
82190 index e5a7e19..4049063 100644
82191 --- a/sound/pci/hda/hda_codec.h
82192 +++ b/sound/pci/hda/hda_codec.h
82193 @@ -614,7 +614,7 @@ struct hda_bus_ops {
82194 /* notify power-up/down from codec to controller */
82195 void (*pm_notify)(struct hda_bus *bus);
82196 #endif
82197 -};
82198 +} __no_const;
82199
82200 /* template to pass to the bus constructor */
82201 struct hda_bus_template {
82202 @@ -714,6 +714,7 @@ struct hda_codec_ops {
82203 #endif
82204 void (*reboot_notify)(struct hda_codec *codec);
82205 };
82206 +typedef struct hda_codec_ops __no_const hda_codec_ops_no_const;
82207
82208 /* record for amp information cache */
82209 struct hda_cache_head {
82210 @@ -744,7 +745,7 @@ struct hda_pcm_ops {
82211 struct snd_pcm_substream *substream);
82212 int (*cleanup)(struct hda_pcm_stream *info, struct hda_codec *codec,
82213 struct snd_pcm_substream *substream);
82214 -};
82215 +} __no_const;
82216
82217 /* PCM information for each substream */
82218 struct hda_pcm_stream {
82219 @@ -802,7 +803,7 @@ struct hda_codec {
82220 const char *modelname; /* model name for preset */
82221
82222 /* set by patch */
82223 - struct hda_codec_ops patch_ops;
82224 + hda_codec_ops_no_const patch_ops;
82225
82226 /* PCM to create, set by patch_ops.build_pcms callback */
82227 unsigned int num_pcms;
82228 diff --git a/sound/pci/ice1712/ice1712.h b/sound/pci/ice1712/ice1712.h
82229 index 0da778a..bc38b84 100644
82230 --- a/sound/pci/ice1712/ice1712.h
82231 +++ b/sound/pci/ice1712/ice1712.h
82232 @@ -269,7 +269,7 @@ struct snd_ak4xxx_private {
82233 unsigned int mask_flags; /* total mask bits */
82234 struct snd_akm4xxx_ops {
82235 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
82236 - } ops;
82237 + } __no_const ops;
82238 };
82239
82240 struct snd_ice1712_spdif {
82241 @@ -285,7 +285,7 @@ struct snd_ice1712_spdif {
82242 int (*default_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
82243 void (*stream_get)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
82244 int (*stream_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
82245 - } ops;
82246 + } __no_const ops;
82247 };
82248
82249
82250 diff --git a/sound/pci/ymfpci/ymfpci.h b/sound/pci/ymfpci/ymfpci.h
82251 index bddc405..2c0733c 100644
82252 --- a/sound/pci/ymfpci/ymfpci.h
82253 +++ b/sound/pci/ymfpci/ymfpci.h
82254 @@ -358,7 +358,7 @@ struct snd_ymfpci {
82255 spinlock_t reg_lock;
82256 spinlock_t voice_lock;
82257 wait_queue_head_t interrupt_sleep;
82258 - atomic_t interrupt_sleep_count;
82259 + atomic_unchecked_t interrupt_sleep_count;
82260 struct snd_info_entry *proc_entry;
82261 const struct firmware *dsp_microcode;
82262 const struct firmware *controller_microcode;
82263 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
82264 index 62b2363..ee77972 100644
82265 --- a/sound/pci/ymfpci/ymfpci_main.c
82266 +++ b/sound/pci/ymfpci/ymfpci_main.c
82267 @@ -203,8 +203,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
82268 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
82269 break;
82270 }
82271 - if (atomic_read(&chip->interrupt_sleep_count)) {
82272 - atomic_set(&chip->interrupt_sleep_count, 0);
82273 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
82274 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
82275 wake_up(&chip->interrupt_sleep);
82276 }
82277 __end:
82278 @@ -788,7 +788,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
82279 continue;
82280 init_waitqueue_entry(&wait, current);
82281 add_wait_queue(&chip->interrupt_sleep, &wait);
82282 - atomic_inc(&chip->interrupt_sleep_count);
82283 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
82284 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
82285 remove_wait_queue(&chip->interrupt_sleep, &wait);
82286 }
82287 @@ -826,8 +826,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
82288 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
82289 spin_unlock(&chip->reg_lock);
82290
82291 - if (atomic_read(&chip->interrupt_sleep_count)) {
82292 - atomic_set(&chip->interrupt_sleep_count, 0);
82293 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
82294 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
82295 wake_up(&chip->interrupt_sleep);
82296 }
82297 }
82298 @@ -2402,7 +2402,7 @@ int __devinit snd_ymfpci_create(struct snd_card *card,
82299 spin_lock_init(&chip->reg_lock);
82300 spin_lock_init(&chip->voice_lock);
82301 init_waitqueue_head(&chip->interrupt_sleep);
82302 - atomic_set(&chip->interrupt_sleep_count, 0);
82303 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
82304 chip->card = card;
82305 chip->pci = pci;
82306 chip->irq = -1;
82307 diff --git a/tools/gcc/.gitignore b/tools/gcc/.gitignore
82308 new file mode 100644
82309 index 0000000..50f2f2f
82310 --- /dev/null
82311 +++ b/tools/gcc/.gitignore
82312 @@ -0,0 +1 @@
82313 +size_overflow_hash.h
82314 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
82315 new file mode 100644
82316 index 0000000..1d09b7e
82317 --- /dev/null
82318 +++ b/tools/gcc/Makefile
82319 @@ -0,0 +1,43 @@
82320 +#CC := gcc
82321 +#PLUGIN_SOURCE_FILES := pax_plugin.c
82322 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
82323 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
82324 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
82325 +
82326 +ifeq ($(PLUGINCC),$(HOSTCC))
82327 +HOSTLIBS := hostlibs
82328 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu99 -ggdb
82329 +else
82330 +HOSTLIBS := hostcxxlibs
82331 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu++98 -ggdb -Wno-unused-parameter
82332 +endif
82333 +
82334 +$(HOSTLIBS)-y := constify_plugin.so
82335 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
82336 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
82337 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
82338 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
82339 +$(HOSTLIBS)-y += colorize_plugin.so
82340 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
82341 +$(HOSTLIBS)-$(CONFIG_PAX_LATENT_ENTROPY) += latent_entropy_plugin.so
82342 +
82343 +always := $($(HOSTLIBS)-y)
82344 +
82345 +constify_plugin-objs := constify_plugin.o
82346 +stackleak_plugin-objs := stackleak_plugin.o
82347 +kallocstat_plugin-objs := kallocstat_plugin.o
82348 +kernexec_plugin-objs := kernexec_plugin.o
82349 +checker_plugin-objs := checker_plugin.o
82350 +colorize_plugin-objs := colorize_plugin.o
82351 +size_overflow_plugin-objs := size_overflow_plugin.o
82352 +latent_entropy_plugin-objs := latent_entropy_plugin.o
82353 +
82354 +$(obj)/size_overflow_plugin.o: $(objtree)/$(obj)/size_overflow_hash.h
82355 +
82356 +quiet_cmd_build_size_overflow_hash = GENHASH $@
82357 + cmd_build_size_overflow_hash = \
82358 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -d $< -o $@
82359 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
82360 + $(call if_changed,build_size_overflow_hash)
82361 +
82362 +targets += size_overflow_hash.h
82363 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
82364 new file mode 100644
82365 index 0000000..d41b5af
82366 --- /dev/null
82367 +++ b/tools/gcc/checker_plugin.c
82368 @@ -0,0 +1,171 @@
82369 +/*
82370 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
82371 + * Licensed under the GPL v2
82372 + *
82373 + * Note: the choice of the license means that the compilation process is
82374 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
82375 + * but for the kernel it doesn't matter since it doesn't link against
82376 + * any of the gcc libraries
82377 + *
82378 + * gcc plugin to implement various sparse (source code checker) features
82379 + *
82380 + * TODO:
82381 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
82382 + *
82383 + * BUGS:
82384 + * - none known
82385 + */
82386 +#include "gcc-plugin.h"
82387 +#include "config.h"
82388 +#include "system.h"
82389 +#include "coretypes.h"
82390 +#include "tree.h"
82391 +#include "tree-pass.h"
82392 +#include "flags.h"
82393 +#include "intl.h"
82394 +#include "toplev.h"
82395 +#include "plugin.h"
82396 +//#include "expr.h" where are you...
82397 +#include "diagnostic.h"
82398 +#include "plugin-version.h"
82399 +#include "tm.h"
82400 +#include "function.h"
82401 +#include "basic-block.h"
82402 +#include "gimple.h"
82403 +#include "rtl.h"
82404 +#include "emit-rtl.h"
82405 +#include "tree-flow.h"
82406 +#include "target.h"
82407 +
82408 +extern void c_register_addr_space (const char *str, addr_space_t as);
82409 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
82410 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
82411 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
82412 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
82413 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
82414 +
82415 +extern void print_gimple_stmt(FILE *, gimple, int, int);
82416 +extern rtx emit_move_insn(rtx x, rtx y);
82417 +
82418 +int plugin_is_GPL_compatible;
82419 +
82420 +static struct plugin_info checker_plugin_info = {
82421 + .version = "201111150100",
82422 +};
82423 +
82424 +#define ADDR_SPACE_KERNEL 0
82425 +#define ADDR_SPACE_FORCE_KERNEL 1
82426 +#define ADDR_SPACE_USER 2
82427 +#define ADDR_SPACE_FORCE_USER 3
82428 +#define ADDR_SPACE_IOMEM 0
82429 +#define ADDR_SPACE_FORCE_IOMEM 0
82430 +#define ADDR_SPACE_PERCPU 0
82431 +#define ADDR_SPACE_FORCE_PERCPU 0
82432 +#define ADDR_SPACE_RCU 0
82433 +#define ADDR_SPACE_FORCE_RCU 0
82434 +
82435 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
82436 +{
82437 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
82438 +}
82439 +
82440 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
82441 +{
82442 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
82443 +}
82444 +
82445 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
82446 +{
82447 + return default_addr_space_valid_pointer_mode(mode, as);
82448 +}
82449 +
82450 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
82451 +{
82452 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
82453 +}
82454 +
82455 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
82456 +{
82457 + return default_addr_space_legitimize_address(x, oldx, mode, as);
82458 +}
82459 +
82460 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
82461 +{
82462 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
82463 + return true;
82464 +
82465 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
82466 + return true;
82467 +
82468 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
82469 + return true;
82470 +
82471 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
82472 + return true;
82473 +
82474 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
82475 + return true;
82476 +
82477 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
82478 + return true;
82479 +
82480 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
82481 + return true;
82482 +
82483 + return subset == superset;
82484 +}
82485 +
82486 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
82487 +{
82488 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
82489 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
82490 +
82491 + return op;
82492 +}
82493 +
82494 +static void register_checker_address_spaces(void *event_data, void *data)
82495 +{
82496 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
82497 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
82498 + c_register_addr_space("__user", ADDR_SPACE_USER);
82499 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
82500 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
82501 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
82502 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
82503 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
82504 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
82505 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
82506 +
82507 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
82508 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
82509 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
82510 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
82511 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
82512 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
82513 + targetm.addr_space.convert = checker_addr_space_convert;
82514 +}
82515 +
82516 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
82517 +{
82518 + const char * const plugin_name = plugin_info->base_name;
82519 + const int argc = plugin_info->argc;
82520 + const struct plugin_argument * const argv = plugin_info->argv;
82521 + int i;
82522 +
82523 + if (!plugin_default_version_check(version, &gcc_version)) {
82524 + error(G_("incompatible gcc/plugin versions"));
82525 + return 1;
82526 + }
82527 +
82528 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
82529 +
82530 + for (i = 0; i < argc; ++i)
82531 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
82532 +
82533 + if (TARGET_64BIT == 0)
82534 + return 0;
82535 +
82536 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
82537 +
82538 + return 0;
82539 +}
82540 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
82541 new file mode 100644
82542 index 0000000..846aeb0
82543 --- /dev/null
82544 +++ b/tools/gcc/colorize_plugin.c
82545 @@ -0,0 +1,148 @@
82546 +/*
82547 + * Copyright 2012 by PaX Team <pageexec@freemail.hu>
82548 + * Licensed under the GPL v2
82549 + *
82550 + * Note: the choice of the license means that the compilation process is
82551 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
82552 + * but for the kernel it doesn't matter since it doesn't link against
82553 + * any of the gcc libraries
82554 + *
82555 + * gcc plugin to colorize diagnostic output
82556 + *
82557 + */
82558 +
82559 +#include "gcc-plugin.h"
82560 +#include "config.h"
82561 +#include "system.h"
82562 +#include "coretypes.h"
82563 +#include "tree.h"
82564 +#include "tree-pass.h"
82565 +#include "flags.h"
82566 +#include "intl.h"
82567 +#include "toplev.h"
82568 +#include "plugin.h"
82569 +#include "diagnostic.h"
82570 +#include "plugin-version.h"
82571 +#include "tm.h"
82572 +
82573 +int plugin_is_GPL_compatible;
82574 +
82575 +static struct plugin_info colorize_plugin_info = {
82576 + .version = "201203092200",
82577 + .help = NULL,
82578 +};
82579 +
82580 +#define GREEN "\033[32m\033[2m"
82581 +#define LIGHTGREEN "\033[32m\033[1m"
82582 +#define YELLOW "\033[33m\033[2m"
82583 +#define LIGHTYELLOW "\033[33m\033[1m"
82584 +#define RED "\033[31m\033[2m"
82585 +#define LIGHTRED "\033[31m\033[1m"
82586 +#define BLUE "\033[34m\033[2m"
82587 +#define LIGHTBLUE "\033[34m\033[1m"
82588 +#define BRIGHT "\033[m\033[1m"
82589 +#define NORMAL "\033[m"
82590 +
82591 +static diagnostic_starter_fn old_starter;
82592 +static diagnostic_finalizer_fn old_finalizer;
82593 +
82594 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
82595 +{
82596 + const char *color;
82597 + char *newprefix;
82598 +
82599 + switch (diagnostic->kind) {
82600 + case DK_NOTE:
82601 + color = LIGHTBLUE;
82602 + break;
82603 +
82604 + case DK_PEDWARN:
82605 + case DK_WARNING:
82606 + color = LIGHTYELLOW;
82607 + break;
82608 +
82609 + case DK_ERROR:
82610 + case DK_FATAL:
82611 + case DK_ICE:
82612 + case DK_PERMERROR:
82613 + case DK_SORRY:
82614 + color = LIGHTRED;
82615 + break;
82616 +
82617 + default:
82618 + color = NORMAL;
82619 + }
82620 +
82621 + old_starter(context, diagnostic);
82622 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
82623 + return;
82624 + pp_destroy_prefix(context->printer);
82625 + pp_set_prefix(context->printer, newprefix);
82626 +}
82627 +
82628 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
82629 +{
82630 + old_finalizer(context, diagnostic);
82631 +}
82632 +
82633 +static void colorize_arm(void)
82634 +{
82635 + old_starter = diagnostic_starter(global_dc);
82636 + old_finalizer = diagnostic_finalizer(global_dc);
82637 +
82638 + diagnostic_starter(global_dc) = start_colorize;
82639 + diagnostic_finalizer(global_dc) = finalize_colorize;
82640 +}
82641 +
82642 +static unsigned int execute_colorize_rearm(void)
82643 +{
82644 + if (diagnostic_starter(global_dc) == start_colorize)
82645 + return 0;
82646 +
82647 + colorize_arm();
82648 + return 0;
82649 +}
82650 +
82651 +struct simple_ipa_opt_pass pass_ipa_colorize_rearm = {
82652 + .pass = {
82653 + .type = SIMPLE_IPA_PASS,
82654 + .name = "colorize_rearm",
82655 + .gate = NULL,
82656 + .execute = execute_colorize_rearm,
82657 + .sub = NULL,
82658 + .next = NULL,
82659 + .static_pass_number = 0,
82660 + .tv_id = TV_NONE,
82661 + .properties_required = 0,
82662 + .properties_provided = 0,
82663 + .properties_destroyed = 0,
82664 + .todo_flags_start = 0,
82665 + .todo_flags_finish = 0
82666 + }
82667 +};
82668 +
82669 +static void colorize_start_unit(void *gcc_data, void *user_data)
82670 +{
82671 + colorize_arm();
82672 +}
82673 +
82674 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
82675 +{
82676 + const char * const plugin_name = plugin_info->base_name;
82677 + struct register_pass_info colorize_rearm_pass_info = {
82678 + .pass = &pass_ipa_colorize_rearm.pass,
82679 + .reference_pass_name = "*free_lang_data",
82680 + .ref_pass_instance_number = 1,
82681 + .pos_op = PASS_POS_INSERT_AFTER
82682 + };
82683 +
82684 + if (!plugin_default_version_check(version, &gcc_version)) {
82685 + error(G_("incompatible gcc/plugin versions"));
82686 + return 1;
82687 + }
82688 +
82689 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
82690 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
82691 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
82692 + return 0;
82693 +}
82694 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
82695 new file mode 100644
82696 index 0000000..92ed719
82697 --- /dev/null
82698 +++ b/tools/gcc/constify_plugin.c
82699 @@ -0,0 +1,331 @@
82700 +/*
82701 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
82702 + * Copyright 2011 by PaX Team <pageexec@freemail.hu>
82703 + * Licensed under the GPL v2, or (at your option) v3
82704 + *
82705 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
82706 + *
82707 + * Homepage:
82708 + * http://www.grsecurity.net/~ephox/const_plugin/
82709 + *
82710 + * Usage:
82711 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
82712 + * $ gcc -fplugin=constify_plugin.so test.c -O2
82713 + */
82714 +
82715 +#include "gcc-plugin.h"
82716 +#include "config.h"
82717 +#include "system.h"
82718 +#include "coretypes.h"
82719 +#include "tree.h"
82720 +#include "tree-pass.h"
82721 +#include "flags.h"
82722 +#include "intl.h"
82723 +#include "toplev.h"
82724 +#include "plugin.h"
82725 +#include "diagnostic.h"
82726 +#include "plugin-version.h"
82727 +#include "tm.h"
82728 +#include "function.h"
82729 +#include "basic-block.h"
82730 +#include "gimple.h"
82731 +#include "rtl.h"
82732 +#include "emit-rtl.h"
82733 +#include "tree-flow.h"
82734 +
82735 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
82736 +
82737 +int plugin_is_GPL_compatible;
82738 +
82739 +static struct plugin_info const_plugin_info = {
82740 + .version = "201205300030",
82741 + .help = "no-constify\tturn off constification\n",
82742 +};
82743 +
82744 +static void deconstify_tree(tree node);
82745 +
82746 +static void deconstify_type(tree type)
82747 +{
82748 + tree field;
82749 +
82750 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
82751 + tree type = TREE_TYPE(field);
82752 +
82753 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
82754 + continue;
82755 + if (!TYPE_READONLY(type))
82756 + continue;
82757 +
82758 + deconstify_tree(field);
82759 + }
82760 + TYPE_READONLY(type) = 0;
82761 + C_TYPE_FIELDS_READONLY(type) = 0;
82762 +}
82763 +
82764 +static void deconstify_tree(tree node)
82765 +{
82766 + tree old_type, new_type, field;
82767 +
82768 + old_type = TREE_TYPE(node);
82769 +
82770 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
82771 +
82772 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
82773 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
82774 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
82775 + DECL_FIELD_CONTEXT(field) = new_type;
82776 +
82777 + deconstify_type(new_type);
82778 +
82779 + TREE_READONLY(node) = 0;
82780 + TREE_TYPE(node) = new_type;
82781 +}
82782 +
82783 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
82784 +{
82785 + tree type;
82786 +
82787 + *no_add_attrs = true;
82788 + if (TREE_CODE(*node) == FUNCTION_DECL) {
82789 + error("%qE attribute does not apply to functions", name);
82790 + return NULL_TREE;
82791 + }
82792 +
82793 + if (TREE_CODE(*node) == VAR_DECL) {
82794 + error("%qE attribute does not apply to variables", name);
82795 + return NULL_TREE;
82796 + }
82797 +
82798 + if (TYPE_P(*node)) {
82799 + if (TREE_CODE(*node) == RECORD_TYPE || TREE_CODE(*node) == UNION_TYPE)
82800 + *no_add_attrs = false;
82801 + else
82802 + error("%qE attribute applies to struct and union types only", name);
82803 + return NULL_TREE;
82804 + }
82805 +
82806 + type = TREE_TYPE(*node);
82807 +
82808 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
82809 + error("%qE attribute applies to struct and union types only", name);
82810 + return NULL_TREE;
82811 + }
82812 +
82813 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
82814 + error("%qE attribute is already applied to the type", name);
82815 + return NULL_TREE;
82816 + }
82817 +
82818 + if (TREE_CODE(*node) == TYPE_DECL && !TYPE_READONLY(type)) {
82819 + error("%qE attribute used on type that is not constified", name);
82820 + return NULL_TREE;
82821 + }
82822 +
82823 + if (TREE_CODE(*node) == TYPE_DECL) {
82824 + deconstify_tree(*node);
82825 + return NULL_TREE;
82826 + }
82827 +
82828 + return NULL_TREE;
82829 +}
82830 +
82831 +static void constify_type(tree type)
82832 +{
82833 + TYPE_READONLY(type) = 1;
82834 + C_TYPE_FIELDS_READONLY(type) = 1;
82835 +}
82836 +
82837 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
82838 +{
82839 + *no_add_attrs = true;
82840 + if (!TYPE_P(*node)) {
82841 + error("%qE attribute applies to types only", name);
82842 + return NULL_TREE;
82843 + }
82844 +
82845 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
82846 + error("%qE attribute applies to struct and union types only", name);
82847 + return NULL_TREE;
82848 + }
82849 +
82850 + *no_add_attrs = false;
82851 + constify_type(*node);
82852 + return NULL_TREE;
82853 +}
82854 +
82855 +static struct attribute_spec no_const_attr = {
82856 + .name = "no_const",
82857 + .min_length = 0,
82858 + .max_length = 0,
82859 + .decl_required = false,
82860 + .type_required = false,
82861 + .function_type_required = false,
82862 + .handler = handle_no_const_attribute,
82863 +#if BUILDING_GCC_VERSION >= 4007
82864 + .affects_type_identity = true
82865 +#endif
82866 +};
82867 +
82868 +static struct attribute_spec do_const_attr = {
82869 + .name = "do_const",
82870 + .min_length = 0,
82871 + .max_length = 0,
82872 + .decl_required = false,
82873 + .type_required = false,
82874 + .function_type_required = false,
82875 + .handler = handle_do_const_attribute,
82876 +#if BUILDING_GCC_VERSION >= 4007
82877 + .affects_type_identity = true
82878 +#endif
82879 +};
82880 +
82881 +static void register_attributes(void *event_data, void *data)
82882 +{
82883 + register_attribute(&no_const_attr);
82884 + register_attribute(&do_const_attr);
82885 +}
82886 +
82887 +static bool is_fptr(tree field)
82888 +{
82889 + tree ptr = TREE_TYPE(field);
82890 +
82891 + if (TREE_CODE(ptr) != POINTER_TYPE)
82892 + return false;
82893 +
82894 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
82895 +}
82896 +
82897 +static bool walk_struct(tree node)
82898 +{
82899 + tree field;
82900 +
82901 + if (TYPE_FIELDS(node) == NULL_TREE)
82902 + return false;
82903 +
82904 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
82905 + gcc_assert(!TYPE_READONLY(node));
82906 + deconstify_type(node);
82907 + return false;
82908 + }
82909 +
82910 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
82911 + tree type = TREE_TYPE(field);
82912 + enum tree_code code = TREE_CODE(type);
82913 +
82914 + if (node == type)
82915 + return false;
82916 + if (code == RECORD_TYPE || code == UNION_TYPE) {
82917 + if (!(walk_struct(type)))
82918 + return false;
82919 + } else if (!is_fptr(field) && !TREE_READONLY(field))
82920 + return false;
82921 + }
82922 + return true;
82923 +}
82924 +
82925 +static void finish_type(void *event_data, void *data)
82926 +{
82927 + tree type = (tree)event_data;
82928 +
82929 + if (type == NULL_TREE || type == error_mark_node)
82930 + return;
82931 +
82932 + if (TYPE_READONLY(type))
82933 + return;
82934 +
82935 + if (walk_struct(type))
82936 + constify_type(type);
82937 +}
82938 +
82939 +static unsigned int check_local_variables(void);
82940 +
82941 +struct gimple_opt_pass pass_local_variable = {
82942 + {
82943 + .type = GIMPLE_PASS,
82944 + .name = "check_local_variables",
82945 + .gate = NULL,
82946 + .execute = check_local_variables,
82947 + .sub = NULL,
82948 + .next = NULL,
82949 + .static_pass_number = 0,
82950 + .tv_id = TV_NONE,
82951 + .properties_required = 0,
82952 + .properties_provided = 0,
82953 + .properties_destroyed = 0,
82954 + .todo_flags_start = 0,
82955 + .todo_flags_finish = 0
82956 + }
82957 +};
82958 +
82959 +static unsigned int check_local_variables(void)
82960 +{
82961 + tree var;
82962 + referenced_var_iterator rvi;
82963 +
82964 +#if BUILDING_GCC_VERSION == 4005
82965 + FOR_EACH_REFERENCED_VAR(var, rvi) {
82966 +#else
82967 + FOR_EACH_REFERENCED_VAR(cfun, var, rvi) {
82968 +#endif
82969 + tree type = TREE_TYPE(var);
82970 +
82971 + if (!DECL_P(var) || TREE_STATIC(var) || DECL_EXTERNAL(var))
82972 + continue;
82973 +
82974 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
82975 + continue;
82976 +
82977 + if (!TYPE_READONLY(type))
82978 + continue;
82979 +
82980 +// if (lookup_attribute("no_const", DECL_ATTRIBUTES(var)))
82981 +// continue;
82982 +
82983 +// if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
82984 +// continue;
82985 +
82986 + if (walk_struct(type)) {
82987 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
82988 + return 1;
82989 + }
82990 + }
82991 + return 0;
82992 +}
82993 +
82994 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
82995 +{
82996 + const char * const plugin_name = plugin_info->base_name;
82997 + const int argc = plugin_info->argc;
82998 + const struct plugin_argument * const argv = plugin_info->argv;
82999 + int i;
83000 + bool constify = true;
83001 +
83002 + struct register_pass_info local_variable_pass_info = {
83003 + .pass = &pass_local_variable.pass,
83004 + .reference_pass_name = "*referenced_vars",
83005 + .ref_pass_instance_number = 1,
83006 + .pos_op = PASS_POS_INSERT_AFTER
83007 + };
83008 +
83009 + if (!plugin_default_version_check(version, &gcc_version)) {
83010 + error(G_("incompatible gcc/plugin versions"));
83011 + return 1;
83012 + }
83013 +
83014 + for (i = 0; i < argc; ++i) {
83015 + if (!(strcmp(argv[i].key, "no-constify"))) {
83016 + constify = false;
83017 + continue;
83018 + }
83019 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
83020 + }
83021 +
83022 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
83023 + if (constify) {
83024 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
83025 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &local_variable_pass_info);
83026 + }
83027 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
83028 +
83029 + return 0;
83030 +}
83031 diff --git a/tools/gcc/generate_size_overflow_hash.sh b/tools/gcc/generate_size_overflow_hash.sh
83032 new file mode 100644
83033 index 0000000..02c6bec
83034 --- /dev/null
83035 +++ b/tools/gcc/generate_size_overflow_hash.sh
83036 @@ -0,0 +1,94 @@
83037 +#!/bin/bash
83038 +
83039 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
83040 +
83041 +header1="size_overflow_hash.h"
83042 +database="size_overflow_hash.data"
83043 +n=65536
83044 +
83045 +usage() {
83046 +cat <<EOF
83047 +usage: $0 options
83048 +OPTIONS:
83049 + -h|--help help
83050 + -o header file
83051 + -d database file
83052 + -n hash array size
83053 +EOF
83054 + return 0
83055 +}
83056 +
83057 +while true
83058 +do
83059 + case "$1" in
83060 + -h|--help) usage && exit 0;;
83061 + -n) n=$2; shift 2;;
83062 + -o) header1="$2"; shift 2;;
83063 + -d) database="$2"; shift 2;;
83064 + --) shift 1; break ;;
83065 + *) break ;;
83066 + esac
83067 +done
83068 +
83069 +create_defines() {
83070 + for i in `seq 1 32`
83071 + do
83072 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
83073 + done
83074 + echo >> "$header1"
83075 +}
83076 +
83077 +create_structs () {
83078 + rm -f "$header1"
83079 +
83080 + create_defines
83081 +
83082 + cat "$database" | while read data
83083 + do
83084 + data_array=($data)
83085 + struct_hash_name="${data_array[0]}"
83086 + funcn="${data_array[1]}"
83087 + params="${data_array[2]}"
83088 + next="${data_array[5]}"
83089 +
83090 + echo "const struct size_overflow_hash $struct_hash_name = {" >> "$header1"
83091 +
83092 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
83093 + echo -en "\t.param\t= " >> "$header1"
83094 + line=
83095 + for param_num in ${params//-/ };
83096 + do
83097 + line="${line}PARAM"$param_num"|"
83098 + done
83099 +
83100 + echo -e "${line%?},\n};\n" >> "$header1"
83101 + done
83102 +}
83103 +
83104 +create_headers () {
83105 + echo "const struct size_overflow_hash * const size_overflow_hash[$n] = {" >> "$header1"
83106 +}
83107 +
83108 +create_array_elements () {
83109 + index=0
83110 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
83111 + do
83112 + data_array=($data)
83113 + i="${data_array[3]}"
83114 + hash="${data_array[4]}"
83115 + while [[ $index -lt $i ]]
83116 + do
83117 + echo -e "\t["$index"]\t= NULL," >> "$header1"
83118 + index=$(($index + 1))
83119 + done
83120 + index=$(($index + 1))
83121 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
83122 + done
83123 + echo '};' >> $header1
83124 +}
83125 +
83126 +create_structs
83127 +create_headers
83128 +create_array_elements
83129 +
83130 +exit 0
83131 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
83132 new file mode 100644
83133 index 0000000..a86e422
83134 --- /dev/null
83135 +++ b/tools/gcc/kallocstat_plugin.c
83136 @@ -0,0 +1,167 @@
83137 +/*
83138 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
83139 + * Licensed under the GPL v2
83140 + *
83141 + * Note: the choice of the license means that the compilation process is
83142 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
83143 + * but for the kernel it doesn't matter since it doesn't link against
83144 + * any of the gcc libraries
83145 + *
83146 + * gcc plugin to find the distribution of k*alloc sizes
83147 + *
83148 + * TODO:
83149 + *
83150 + * BUGS:
83151 + * - none known
83152 + */
83153 +#include "gcc-plugin.h"
83154 +#include "config.h"
83155 +#include "system.h"
83156 +#include "coretypes.h"
83157 +#include "tree.h"
83158 +#include "tree-pass.h"
83159 +#include "flags.h"
83160 +#include "intl.h"
83161 +#include "toplev.h"
83162 +#include "plugin.h"
83163 +//#include "expr.h" where are you...
83164 +#include "diagnostic.h"
83165 +#include "plugin-version.h"
83166 +#include "tm.h"
83167 +#include "function.h"
83168 +#include "basic-block.h"
83169 +#include "gimple.h"
83170 +#include "rtl.h"
83171 +#include "emit-rtl.h"
83172 +
83173 +extern void print_gimple_stmt(FILE *, gimple, int, int);
83174 +
83175 +int plugin_is_GPL_compatible;
83176 +
83177 +static const char * const kalloc_functions[] = {
83178 + "__kmalloc",
83179 + "kmalloc",
83180 + "kmalloc_large",
83181 + "kmalloc_node",
83182 + "kmalloc_order",
83183 + "kmalloc_order_trace",
83184 + "kmalloc_slab",
83185 + "kzalloc",
83186 + "kzalloc_node",
83187 +};
83188 +
83189 +static struct plugin_info kallocstat_plugin_info = {
83190 + .version = "201111150100",
83191 +};
83192 +
83193 +static unsigned int execute_kallocstat(void);
83194 +
83195 +static struct gimple_opt_pass kallocstat_pass = {
83196 + .pass = {
83197 + .type = GIMPLE_PASS,
83198 + .name = "kallocstat",
83199 + .gate = NULL,
83200 + .execute = execute_kallocstat,
83201 + .sub = NULL,
83202 + .next = NULL,
83203 + .static_pass_number = 0,
83204 + .tv_id = TV_NONE,
83205 + .properties_required = 0,
83206 + .properties_provided = 0,
83207 + .properties_destroyed = 0,
83208 + .todo_flags_start = 0,
83209 + .todo_flags_finish = 0
83210 + }
83211 +};
83212 +
83213 +static bool is_kalloc(const char *fnname)
83214 +{
83215 + size_t i;
83216 +
83217 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
83218 + if (!strcmp(fnname, kalloc_functions[i]))
83219 + return true;
83220 + return false;
83221 +}
83222 +
83223 +static unsigned int execute_kallocstat(void)
83224 +{
83225 + basic_block bb;
83226 +
83227 + // 1. loop through BBs and GIMPLE statements
83228 + FOR_EACH_BB(bb) {
83229 + gimple_stmt_iterator gsi;
83230 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
83231 + // gimple match:
83232 + tree fndecl, size;
83233 + gimple call_stmt;
83234 + const char *fnname;
83235 +
83236 + // is it a call
83237 + call_stmt = gsi_stmt(gsi);
83238 + if (!is_gimple_call(call_stmt))
83239 + continue;
83240 + fndecl = gimple_call_fndecl(call_stmt);
83241 + if (fndecl == NULL_TREE)
83242 + continue;
83243 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
83244 + continue;
83245 +
83246 + // is it a call to k*alloc
83247 + fnname = IDENTIFIER_POINTER(DECL_NAME(fndecl));
83248 + if (!is_kalloc(fnname))
83249 + continue;
83250 +
83251 + // is the size arg the result of a simple const assignment
83252 + size = gimple_call_arg(call_stmt, 0);
83253 + while (true) {
83254 + gimple def_stmt;
83255 + expanded_location xloc;
83256 + size_t size_val;
83257 +
83258 + if (TREE_CODE(size) != SSA_NAME)
83259 + break;
83260 + def_stmt = SSA_NAME_DEF_STMT(size);
83261 + if (!def_stmt || !is_gimple_assign(def_stmt))
83262 + break;
83263 + if (gimple_num_ops(def_stmt) != 2)
83264 + break;
83265 + size = gimple_assign_rhs1(def_stmt);
83266 + if (!TREE_CONSTANT(size))
83267 + continue;
83268 + xloc = expand_location(gimple_location(def_stmt));
83269 + if (!xloc.file)
83270 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
83271 + size_val = TREE_INT_CST_LOW(size);
83272 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
83273 + break;
83274 + }
83275 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
83276 +//debug_tree(gimple_call_fn(call_stmt));
83277 +//print_node(stderr, "pax", fndecl, 4);
83278 + }
83279 + }
83280 +
83281 + return 0;
83282 +}
83283 +
83284 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
83285 +{
83286 + const char * const plugin_name = plugin_info->base_name;
83287 + struct register_pass_info kallocstat_pass_info = {
83288 + .pass = &kallocstat_pass.pass,
83289 + .reference_pass_name = "ssa",
83290 + .ref_pass_instance_number = 1,
83291 + .pos_op = PASS_POS_INSERT_AFTER
83292 + };
83293 +
83294 + if (!plugin_default_version_check(version, &gcc_version)) {
83295 + error(G_("incompatible gcc/plugin versions"));
83296 + return 1;
83297 + }
83298 +
83299 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
83300 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
83301 +
83302 + return 0;
83303 +}
83304 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
83305 new file mode 100644
83306 index 0000000..98011fa
83307 --- /dev/null
83308 +++ b/tools/gcc/kernexec_plugin.c
83309 @@ -0,0 +1,427 @@
83310 +/*
83311 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
83312 + * Licensed under the GPL v2
83313 + *
83314 + * Note: the choice of the license means that the compilation process is
83315 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
83316 + * but for the kernel it doesn't matter since it doesn't link against
83317 + * any of the gcc libraries
83318 + *
83319 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
83320 + *
83321 + * TODO:
83322 + *
83323 + * BUGS:
83324 + * - none known
83325 + */
83326 +#include "gcc-plugin.h"
83327 +#include "config.h"
83328 +#include "system.h"
83329 +#include "coretypes.h"
83330 +#include "tree.h"
83331 +#include "tree-pass.h"
83332 +#include "flags.h"
83333 +#include "intl.h"
83334 +#include "toplev.h"
83335 +#include "plugin.h"
83336 +//#include "expr.h" where are you...
83337 +#include "diagnostic.h"
83338 +#include "plugin-version.h"
83339 +#include "tm.h"
83340 +#include "function.h"
83341 +#include "basic-block.h"
83342 +#include "gimple.h"
83343 +#include "rtl.h"
83344 +#include "emit-rtl.h"
83345 +#include "tree-flow.h"
83346 +
83347 +extern void print_gimple_stmt(FILE *, gimple, int, int);
83348 +extern rtx emit_move_insn(rtx x, rtx y);
83349 +
83350 +int plugin_is_GPL_compatible;
83351 +
83352 +static struct plugin_info kernexec_plugin_info = {
83353 + .version = "201111291120",
83354 + .help = "method=[bts|or]\tinstrumentation method\n"
83355 +};
83356 +
83357 +static unsigned int execute_kernexec_reload(void);
83358 +static unsigned int execute_kernexec_fptr(void);
83359 +static unsigned int execute_kernexec_retaddr(void);
83360 +static bool kernexec_cmodel_check(void);
83361 +
83362 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
83363 +static void (*kernexec_instrument_retaddr)(rtx);
83364 +
83365 +static struct gimple_opt_pass kernexec_reload_pass = {
83366 + .pass = {
83367 + .type = GIMPLE_PASS,
83368 + .name = "kernexec_reload",
83369 + .gate = kernexec_cmodel_check,
83370 + .execute = execute_kernexec_reload,
83371 + .sub = NULL,
83372 + .next = NULL,
83373 + .static_pass_number = 0,
83374 + .tv_id = TV_NONE,
83375 + .properties_required = 0,
83376 + .properties_provided = 0,
83377 + .properties_destroyed = 0,
83378 + .todo_flags_start = 0,
83379 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
83380 + }
83381 +};
83382 +
83383 +static struct gimple_opt_pass kernexec_fptr_pass = {
83384 + .pass = {
83385 + .type = GIMPLE_PASS,
83386 + .name = "kernexec_fptr",
83387 + .gate = kernexec_cmodel_check,
83388 + .execute = execute_kernexec_fptr,
83389 + .sub = NULL,
83390 + .next = NULL,
83391 + .static_pass_number = 0,
83392 + .tv_id = TV_NONE,
83393 + .properties_required = 0,
83394 + .properties_provided = 0,
83395 + .properties_destroyed = 0,
83396 + .todo_flags_start = 0,
83397 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
83398 + }
83399 +};
83400 +
83401 +static struct rtl_opt_pass kernexec_retaddr_pass = {
83402 + .pass = {
83403 + .type = RTL_PASS,
83404 + .name = "kernexec_retaddr",
83405 + .gate = kernexec_cmodel_check,
83406 + .execute = execute_kernexec_retaddr,
83407 + .sub = NULL,
83408 + .next = NULL,
83409 + .static_pass_number = 0,
83410 + .tv_id = TV_NONE,
83411 + .properties_required = 0,
83412 + .properties_provided = 0,
83413 + .properties_destroyed = 0,
83414 + .todo_flags_start = 0,
83415 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
83416 + }
83417 +};
83418 +
83419 +static bool kernexec_cmodel_check(void)
83420 +{
83421 + tree section;
83422 +
83423 + if (ix86_cmodel != CM_KERNEL)
83424 + return false;
83425 +
83426 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
83427 + if (!section || !TREE_VALUE(section))
83428 + return true;
83429 +
83430 + section = TREE_VALUE(TREE_VALUE(section));
83431 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
83432 + return true;
83433 +
83434 + return false;
83435 +}
83436 +
83437 +/*
83438 + * add special KERNEXEC instrumentation: reload %r10 after it has been clobbered
83439 + */
83440 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
83441 +{
83442 + gimple asm_movabs_stmt;
83443 +
83444 + // build asm volatile("movabs $0x8000000000000000, %%r10\n\t" : : : );
83445 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r10\n\t", NULL, NULL, NULL, NULL);
83446 + gimple_asm_set_volatile(asm_movabs_stmt, true);
83447 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
83448 + update_stmt(asm_movabs_stmt);
83449 +}
83450 +
83451 +/*
83452 + * find all asm() stmts that clobber r10 and add a reload of r10
83453 + */
83454 +static unsigned int execute_kernexec_reload(void)
83455 +{
83456 + basic_block bb;
83457 +
83458 + // 1. loop through BBs and GIMPLE statements
83459 + FOR_EACH_BB(bb) {
83460 + gimple_stmt_iterator gsi;
83461 +
83462 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
83463 + // gimple match: __asm__ ("" : : : "r10");
83464 + gimple asm_stmt;
83465 + size_t nclobbers;
83466 +
83467 + // is it an asm ...
83468 + asm_stmt = gsi_stmt(gsi);
83469 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
83470 + continue;
83471 +
83472 + // ... clobbering r10
83473 + nclobbers = gimple_asm_nclobbers(asm_stmt);
83474 + while (nclobbers--) {
83475 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
83476 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r10"))
83477 + continue;
83478 + kernexec_reload_fptr_mask(&gsi);
83479 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
83480 + break;
83481 + }
83482 + }
83483 + }
83484 +
83485 + return 0;
83486 +}
83487 +
83488 +/*
83489 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
83490 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
83491 + */
83492 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
83493 +{
83494 + gimple assign_intptr, assign_new_fptr, call_stmt;
83495 + tree intptr, old_fptr, new_fptr, kernexec_mask;
83496 +
83497 + call_stmt = gsi_stmt(*gsi);
83498 + old_fptr = gimple_call_fn(call_stmt);
83499 +
83500 + // create temporary unsigned long variable used for bitops and cast fptr to it
83501 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
83502 + add_referenced_var(intptr);
83503 + mark_sym_for_renaming(intptr);
83504 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
83505 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
83506 + update_stmt(assign_intptr);
83507 +
83508 + // apply logical or to temporary unsigned long and bitmask
83509 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
83510 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
83511 + assign_intptr = gimple_build_assign(intptr, fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask));
83512 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
83513 + update_stmt(assign_intptr);
83514 +
83515 + // cast temporary unsigned long back to a temporary fptr variable
83516 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
83517 + add_referenced_var(new_fptr);
83518 + mark_sym_for_renaming(new_fptr);
83519 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
83520 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
83521 + update_stmt(assign_new_fptr);
83522 +
83523 + // replace call stmt fn with the new fptr
83524 + gimple_call_set_fn(call_stmt, new_fptr);
83525 + update_stmt(call_stmt);
83526 +}
83527 +
83528 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
83529 +{
83530 + gimple asm_or_stmt, call_stmt;
83531 + tree old_fptr, new_fptr, input, output;
83532 + VEC(tree, gc) *inputs = NULL;
83533 + VEC(tree, gc) *outputs = NULL;
83534 +
83535 + call_stmt = gsi_stmt(*gsi);
83536 + old_fptr = gimple_call_fn(call_stmt);
83537 +
83538 + // create temporary fptr variable
83539 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
83540 + add_referenced_var(new_fptr);
83541 + mark_sym_for_renaming(new_fptr);
83542 +
83543 + // build asm volatile("orq %%r10, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
83544 + input = build_tree_list(NULL_TREE, build_string(2, "0"));
83545 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
83546 + output = build_tree_list(NULL_TREE, build_string(3, "=r"));
83547 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
83548 + VEC_safe_push(tree, gc, inputs, input);
83549 + VEC_safe_push(tree, gc, outputs, output);
83550 + asm_or_stmt = gimple_build_asm_vec("orq %%r10, %0\n\t", inputs, outputs, NULL, NULL);
83551 + gimple_asm_set_volatile(asm_or_stmt, true);
83552 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
83553 + update_stmt(asm_or_stmt);
83554 +
83555 + // replace call stmt fn with the new fptr
83556 + gimple_call_set_fn(call_stmt, new_fptr);
83557 + update_stmt(call_stmt);
83558 +}
83559 +
83560 +/*
83561 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
83562 + */
83563 +static unsigned int execute_kernexec_fptr(void)
83564 +{
83565 + basic_block bb;
83566 +
83567 + // 1. loop through BBs and GIMPLE statements
83568 + FOR_EACH_BB(bb) {
83569 + gimple_stmt_iterator gsi;
83570 +
83571 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
83572 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
83573 + tree fn;
83574 + gimple call_stmt;
83575 +
83576 + // is it a call ...
83577 + call_stmt = gsi_stmt(gsi);
83578 + if (!is_gimple_call(call_stmt))
83579 + continue;
83580 + fn = gimple_call_fn(call_stmt);
83581 + if (TREE_CODE(fn) == ADDR_EXPR)
83582 + continue;
83583 + if (TREE_CODE(fn) != SSA_NAME)
83584 + gcc_unreachable();
83585 +
83586 + // ... through a function pointer
83587 + fn = SSA_NAME_VAR(fn);
83588 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL)
83589 + continue;
83590 + fn = TREE_TYPE(fn);
83591 + if (TREE_CODE(fn) != POINTER_TYPE)
83592 + continue;
83593 + fn = TREE_TYPE(fn);
83594 + if (TREE_CODE(fn) != FUNCTION_TYPE)
83595 + continue;
83596 +
83597 + kernexec_instrument_fptr(&gsi);
83598 +
83599 +//debug_tree(gimple_call_fn(call_stmt));
83600 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
83601 + }
83602 + }
83603 +
83604 + return 0;
83605 +}
83606 +
83607 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
83608 +static void kernexec_instrument_retaddr_bts(rtx insn)
83609 +{
83610 + rtx btsq;
83611 + rtvec argvec, constraintvec, labelvec;
83612 + int line;
83613 +
83614 + // create asm volatile("btsq $63,(%%rsp)":::)
83615 + argvec = rtvec_alloc(0);
83616 + constraintvec = rtvec_alloc(0);
83617 + labelvec = rtvec_alloc(0);
83618 + line = expand_location(RTL_LOCATION(insn)).line;
83619 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
83620 + MEM_VOLATILE_P(btsq) = 1;
83621 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
83622 + emit_insn_before(btsq, insn);
83623 +}
83624 +
83625 +// add special KERNEXEC instrumentation: orq %r10,(%rsp) just before retn
83626 +static void kernexec_instrument_retaddr_or(rtx insn)
83627 +{
83628 + rtx orq;
83629 + rtvec argvec, constraintvec, labelvec;
83630 + int line;
83631 +
83632 + // create asm volatile("orq %%r10,(%%rsp)":::)
83633 + argvec = rtvec_alloc(0);
83634 + constraintvec = rtvec_alloc(0);
83635 + labelvec = rtvec_alloc(0);
83636 + line = expand_location(RTL_LOCATION(insn)).line;
83637 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r10,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
83638 + MEM_VOLATILE_P(orq) = 1;
83639 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
83640 + emit_insn_before(orq, insn);
83641 +}
83642 +
83643 +/*
83644 + * find all asm level function returns and forcibly set the highest bit of the return address
83645 + */
83646 +static unsigned int execute_kernexec_retaddr(void)
83647 +{
83648 + rtx insn;
83649 +
83650 + // 1. find function returns
83651 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
83652 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
83653 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
83654 + rtx body;
83655 +
83656 + // is it a retn
83657 + if (!JUMP_P(insn))
83658 + continue;
83659 + body = PATTERN(insn);
83660 + if (GET_CODE(body) == PARALLEL)
83661 + body = XVECEXP(body, 0, 0);
83662 + if (GET_CODE(body) != RETURN)
83663 + continue;
83664 + kernexec_instrument_retaddr(insn);
83665 + }
83666 +
83667 +// print_simple_rtl(stderr, get_insns());
83668 +// print_rtl(stderr, get_insns());
83669 +
83670 + return 0;
83671 +}
83672 +
83673 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
83674 +{
83675 + const char * const plugin_name = plugin_info->base_name;
83676 + const int argc = plugin_info->argc;
83677 + const struct plugin_argument * const argv = plugin_info->argv;
83678 + int i;
83679 + struct register_pass_info kernexec_reload_pass_info = {
83680 + .pass = &kernexec_reload_pass.pass,
83681 + .reference_pass_name = "ssa",
83682 + .ref_pass_instance_number = 1,
83683 + .pos_op = PASS_POS_INSERT_AFTER
83684 + };
83685 + struct register_pass_info kernexec_fptr_pass_info = {
83686 + .pass = &kernexec_fptr_pass.pass,
83687 + .reference_pass_name = "ssa",
83688 + .ref_pass_instance_number = 1,
83689 + .pos_op = PASS_POS_INSERT_AFTER
83690 + };
83691 + struct register_pass_info kernexec_retaddr_pass_info = {
83692 + .pass = &kernexec_retaddr_pass.pass,
83693 + .reference_pass_name = "pro_and_epilogue",
83694 + .ref_pass_instance_number = 1,
83695 + .pos_op = PASS_POS_INSERT_AFTER
83696 + };
83697 +
83698 + if (!plugin_default_version_check(version, &gcc_version)) {
83699 + error(G_("incompatible gcc/plugin versions"));
83700 + return 1;
83701 + }
83702 +
83703 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
83704 +
83705 + if (TARGET_64BIT == 0)
83706 + return 0;
83707 +
83708 + for (i = 0; i < argc; ++i) {
83709 + if (!strcmp(argv[i].key, "method")) {
83710 + if (!argv[i].value) {
83711 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
83712 + continue;
83713 + }
83714 + if (!strcmp(argv[i].value, "bts")) {
83715 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
83716 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
83717 + } else if (!strcmp(argv[i].value, "or")) {
83718 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
83719 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
83720 + fix_register("r10", 1, 1);
83721 + } else
83722 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
83723 + continue;
83724 + }
83725 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
83726 + }
83727 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
83728 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
83729 +
83730 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
83731 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
83732 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
83733 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
83734 +
83735 + return 0;
83736 +}
83737 diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
83738 new file mode 100644
83739 index 0000000..b8008f7
83740 --- /dev/null
83741 +++ b/tools/gcc/latent_entropy_plugin.c
83742 @@ -0,0 +1,295 @@
83743 +/*
83744 + * Copyright 2012 by the PaX Team <pageexec@freemail.hu>
83745 + * Licensed under the GPL v2
83746 + *
83747 + * Note: the choice of the license means that the compilation process is
83748 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
83749 + * but for the kernel it doesn't matter since it doesn't link against
83750 + * any of the gcc libraries
83751 + *
83752 + * gcc plugin to help generate a little bit of entropy from program state,
83753 + * used during boot in the kernel
83754 + *
83755 + * TODO:
83756 + * - add ipa pass to identify not explicitly marked candidate functions
83757 + * - mix in more program state (function arguments/return values, loop variables, etc)
83758 + * - more instrumentation control via attribute parameters
83759 + *
83760 + * BUGS:
83761 + * - LTO needs -flto-partition=none for now
83762 + */
83763 +#include "gcc-plugin.h"
83764 +#include "config.h"
83765 +#include "system.h"
83766 +#include "coretypes.h"
83767 +#include "tree.h"
83768 +#include "tree-pass.h"
83769 +#include "flags.h"
83770 +#include "intl.h"
83771 +#include "toplev.h"
83772 +#include "plugin.h"
83773 +//#include "expr.h" where are you...
83774 +#include "diagnostic.h"
83775 +#include "plugin-version.h"
83776 +#include "tm.h"
83777 +#include "function.h"
83778 +#include "basic-block.h"
83779 +#include "gimple.h"
83780 +#include "rtl.h"
83781 +#include "emit-rtl.h"
83782 +#include "tree-flow.h"
83783 +
83784 +int plugin_is_GPL_compatible;
83785 +
83786 +static tree latent_entropy_decl;
83787 +
83788 +static struct plugin_info latent_entropy_plugin_info = {
83789 + .version = "201207271820",
83790 + .help = NULL
83791 +};
83792 +
83793 +static unsigned int execute_latent_entropy(void);
83794 +static bool gate_latent_entropy(void);
83795 +
83796 +static struct gimple_opt_pass latent_entropy_pass = {
83797 + .pass = {
83798 + .type = GIMPLE_PASS,
83799 + .name = "latent_entropy",
83800 + .gate = gate_latent_entropy,
83801 + .execute = execute_latent_entropy,
83802 + .sub = NULL,
83803 + .next = NULL,
83804 + .static_pass_number = 0,
83805 + .tv_id = TV_NONE,
83806 + .properties_required = PROP_gimple_leh | PROP_cfg,
83807 + .properties_provided = 0,
83808 + .properties_destroyed = 0,
83809 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
83810 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
83811 + }
83812 +};
83813 +
83814 +static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
83815 +{
83816 + if (TREE_CODE(*node) != FUNCTION_DECL) {
83817 + *no_add_attrs = true;
83818 + error("%qE attribute only applies to functions", name);
83819 + }
83820 + return NULL_TREE;
83821 +}
83822 +
83823 +static struct attribute_spec latent_entropy_attr = {
83824 + .name = "latent_entropy",
83825 + .min_length = 0,
83826 + .max_length = 0,
83827 + .decl_required = true,
83828 + .type_required = false,
83829 + .function_type_required = false,
83830 + .handler = handle_latent_entropy_attribute,
83831 +#if BUILDING_GCC_VERSION >= 4007
83832 + .affects_type_identity = false
83833 +#endif
83834 +};
83835 +
83836 +static void register_attributes(void *event_data, void *data)
83837 +{
83838 + register_attribute(&latent_entropy_attr);
83839 +}
83840 +
83841 +static bool gate_latent_entropy(void)
83842 +{
83843 + tree latent_entropy_attr;
83844 +
83845 + latent_entropy_attr = lookup_attribute("latent_entropy", DECL_ATTRIBUTES(current_function_decl));
83846 + return latent_entropy_attr != NULL_TREE;
83847 +}
83848 +
83849 +static unsigned HOST_WIDE_INT seed;
83850 +static unsigned HOST_WIDE_INT get_random_const(void)
83851 +{
83852 + seed = (seed >> 1U) ^ (-(seed & 1ULL) & 0xD800000000000000ULL);
83853 + return seed;
83854 +}
83855 +
83856 +static enum tree_code get_op(tree *rhs)
83857 +{
83858 + static enum tree_code op;
83859 + unsigned HOST_WIDE_INT random_const;
83860 +
83861 + random_const = get_random_const();
83862 +
83863 + switch (op) {
83864 + case BIT_XOR_EXPR:
83865 + op = PLUS_EXPR;
83866 + break;
83867 +
83868 + case PLUS_EXPR:
83869 + if (rhs) {
83870 + op = LROTATE_EXPR;
83871 + random_const &= HOST_BITS_PER_WIDE_INT - 1;
83872 + break;
83873 + }
83874 +
83875 + case LROTATE_EXPR:
83876 + default:
83877 + op = BIT_XOR_EXPR;
83878 + break;
83879 + }
83880 + if (rhs)
83881 + *rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
83882 + return op;
83883 +}
83884 +
83885 +static void perturb_local_entropy(basic_block bb, tree local_entropy)
83886 +{
83887 + gimple_stmt_iterator gsi;
83888 + gimple assign;
83889 + tree addxorrol, rhs;
83890 + enum tree_code op;
83891 +
83892 + op = get_op(&rhs);
83893 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, op, unsigned_intDI_type_node, local_entropy, rhs);
83894 + assign = gimple_build_assign(local_entropy, addxorrol);
83895 + find_referenced_vars_in(assign);
83896 +//debug_bb(bb);
83897 + gsi = gsi_after_labels(bb);
83898 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
83899 + update_stmt(assign);
83900 +}
83901 +
83902 +static void perturb_latent_entropy(basic_block bb, tree rhs)
83903 +{
83904 + gimple_stmt_iterator gsi;
83905 + gimple assign;
83906 + tree addxorrol, temp;
83907 +
83908 + // 1. create temporary copy of latent_entropy
83909 + temp = create_tmp_var(unsigned_intDI_type_node, "temp_latent_entropy");
83910 + add_referenced_var(temp);
83911 + mark_sym_for_renaming(temp);
83912 +
83913 + // 2. read...
83914 + assign = gimple_build_assign(temp, latent_entropy_decl);
83915 + find_referenced_vars_in(assign);
83916 + gsi = gsi_after_labels(bb);
83917 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
83918 + update_stmt(assign);
83919 +
83920 + // 3. ...modify...
83921 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, get_op(NULL), unsigned_intDI_type_node, temp, rhs);
83922 + assign = gimple_build_assign(temp, addxorrol);
83923 + find_referenced_vars_in(assign);
83924 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
83925 + update_stmt(assign);
83926 +
83927 + // 4. ...write latent_entropy
83928 + assign = gimple_build_assign(latent_entropy_decl, temp);
83929 + find_referenced_vars_in(assign);
83930 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
83931 + update_stmt(assign);
83932 +}
83933 +
83934 +static unsigned int execute_latent_entropy(void)
83935 +{
83936 + basic_block bb;
83937 + gimple assign;
83938 + gimple_stmt_iterator gsi;
83939 + tree local_entropy;
83940 +
83941 + if (!latent_entropy_decl) {
83942 + struct varpool_node *node;
83943 +
83944 + for (node = varpool_nodes; node; node = node->next) {
83945 + tree var = node->decl;
83946 + if (strcmp(IDENTIFIER_POINTER(DECL_NAME(var)), "latent_entropy"))
83947 + continue;
83948 + latent_entropy_decl = var;
83949 +// debug_tree(var);
83950 + break;
83951 + }
83952 + if (!latent_entropy_decl) {
83953 +// debug_tree(current_function_decl);
83954 + return 0;
83955 + }
83956 + }
83957 +
83958 +//fprintf(stderr, "latent_entropy: %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
83959 +
83960 + // 1. create local entropy variable
83961 + local_entropy = create_tmp_var(unsigned_intDI_type_node, "local_entropy");
83962 + add_referenced_var(local_entropy);
83963 + mark_sym_for_renaming(local_entropy);
83964 +
83965 + // 2. initialize local entropy variable
83966 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
83967 + if (dom_info_available_p(CDI_DOMINATORS))
83968 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
83969 + gsi = gsi_start_bb(bb);
83970 +
83971 + assign = gimple_build_assign(local_entropy, build_int_cstu(unsigned_intDI_type_node, get_random_const()));
83972 +// gimple_set_location(assign, loc);
83973 + find_referenced_vars_in(assign);
83974 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
83975 + update_stmt(assign);
83976 + bb = bb->next_bb;
83977 +
83978 + // 3. instrument each BB with an operation on the local entropy variable
83979 + while (bb != EXIT_BLOCK_PTR) {
83980 + perturb_local_entropy(bb, local_entropy);
83981 + bb = bb->next_bb;
83982 + };
83983 +
83984 + // 4. mix local entropy into the global entropy variable
83985 + perturb_latent_entropy(EXIT_BLOCK_PTR->prev_bb, local_entropy);
83986 + return 0;
83987 +}
83988 +
83989 +static void start_unit_callback(void *gcc_data, void *user_data)
83990 +{
83991 +#if BUILDING_GCC_VERSION >= 4007
83992 + seed = get_random_seed(false);
83993 +#else
83994 + sscanf(get_random_seed(false), "%" HOST_WIDE_INT_PRINT "x", &seed);
83995 + seed *= seed;
83996 +#endif
83997 +
83998 + if (in_lto_p)
83999 + return;
84000 +
84001 + // extern u64 latent_entropy
84002 + latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("latent_entropy"), unsigned_intDI_type_node);
84003 +
84004 + TREE_STATIC(latent_entropy_decl) = 1;
84005 + TREE_PUBLIC(latent_entropy_decl) = 1;
84006 + TREE_USED(latent_entropy_decl) = 1;
84007 + TREE_THIS_VOLATILE(latent_entropy_decl) = 1;
84008 + DECL_EXTERNAL(latent_entropy_decl) = 1;
84009 + DECL_ARTIFICIAL(latent_entropy_decl) = 0;
84010 + DECL_INITIAL(latent_entropy_decl) = NULL;
84011 +// DECL_ASSEMBLER_NAME(latent_entropy_decl);
84012 +// varpool_finalize_decl(latent_entropy_decl);
84013 +// varpool_mark_needed_node(latent_entropy_decl);
84014 +}
84015 +
84016 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
84017 +{
84018 + const char * const plugin_name = plugin_info->base_name;
84019 + struct register_pass_info latent_entropy_pass_info = {
84020 + .pass = &latent_entropy_pass.pass,
84021 + .reference_pass_name = "optimized",
84022 + .ref_pass_instance_number = 1,
84023 + .pos_op = PASS_POS_INSERT_BEFORE
84024 + };
84025 +
84026 + if (!plugin_default_version_check(version, &gcc_version)) {
84027 + error(G_("incompatible gcc/plugin versions"));
84028 + return 1;
84029 + }
84030 +
84031 + register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
84032 + register_callback ("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
84033 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
84034 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
84035 +
84036 + return 0;
84037 +}
84038 diff --git a/tools/gcc/size_overflow_hash.data b/tools/gcc/size_overflow_hash.data
84039 new file mode 100644
84040 index 0000000..9332f17
84041 --- /dev/null
84042 +++ b/tools/gcc/size_overflow_hash.data
84043 @@ -0,0 +1,3597 @@
84044 +_000001_hash alloc_dr 2 65495 _000001_hash NULL
84045 +_000002_hash __copy_from_user 3 10918 _000002_hash NULL
84046 +_000003_hash copy_from_user 3 17559 _000003_hash NULL
84047 +_000004_hash __copy_from_user_inatomic 3 4365 _000004_hash NULL
84048 +_000005_hash __copy_from_user_nocache 3 39351 _000005_hash NULL
84049 +_000006_hash __copy_to_user_inatomic 3 19214 _000006_hash NULL
84050 +_000007_hash do_xip_mapping_read 5 60297 _000007_hash NULL
84051 +_000008_hash hugetlbfs_read 3 11268 _000008_hash NULL
84052 +_000009_hash kmalloc 1 60432 _003302_hash NULL nohasharray
84053 +_000010_hash kmalloc_array 1-2 9444 _000010_hash NULL
84054 +_000012_hash __kmalloc_reserve 1 17080 _000012_hash NULL
84055 +_000013_hash kmalloc_slab 1 11917 _000013_hash NULL
84056 +_000014_hash kmemdup 2 64015 _000014_hash NULL
84057 +_000015_hash __krealloc 2 14857 _000340_hash NULL nohasharray
84058 +_000016_hash memdup_user 2 59590 _000016_hash NULL
84059 +_000017_hash module_alloc 1 63630 _000017_hash NULL
84060 +_000018_hash read_default_ldt 2 14302 _000018_hash NULL
84061 +_000019_hash read_kcore 3 63488 _000019_hash NULL
84062 +_000020_hash read_ldt 2 47570 _000020_hash NULL
84063 +_000021_hash read_zero 3 19366 _000021_hash NULL
84064 +_000022_hash __vmalloc_node 1 39308 _000022_hash NULL
84065 +_000023_hash aac_convert_sgraw2 4 51598 _000023_hash NULL
84066 +_000024_hash aa_simple_write_to_buffer 4-3 49683 _000024_hash NULL
84067 +_000025_hash ablkcipher_copy_iv 3 64140 _000025_hash NULL
84068 +_000026_hash ablkcipher_next_slow 3-4 47274 _000026_hash NULL
84069 +_000028_hash acpi_battery_write_alarm 3 1240 _000028_hash NULL
84070 +_000029_hash acpi_os_allocate 1 14892 _000029_hash NULL
84071 +_000030_hash acpi_system_write_wakeup_device 3 34853 _000030_hash NULL
84072 +_000031_hash adu_write 3 30487 _000031_hash NULL
84073 +_000032_hash aer_inject_write 3 52399 _000032_hash NULL
84074 +_000033_hash afs_alloc_flat_call 2-3 36399 _000033_hash NULL
84075 +_000035_hash afs_proc_cells_write 3 61139 _000035_hash NULL
84076 +_000036_hash afs_proc_rootcell_write 3 15822 _000036_hash NULL
84077 +_000037_hash agp_3_5_isochronous_node_enable 3 49465 _000037_hash NULL
84078 +_000038_hash agp_alloc_page_array 1 22554 _000038_hash NULL
84079 +_000039_hash ah_alloc_tmp 2-3 54378 _000039_hash NULL
84080 +_000041_hash ahash_setkey_unaligned 3 33521 _000041_hash NULL
84081 +_000042_hash alg_setkey 3 31485 _000042_hash NULL
84082 +_000043_hash aligned_kmalloc 1 3628 _000043_hash NULL
84083 +_000044_hash alloc_context 1 3194 _000044_hash NULL
84084 +_000045_hash alloc_ep_req 2 54860 _000045_hash NULL
84085 +_000046_hash alloc_fdmem 1 27083 _000046_hash NULL
84086 +_000047_hash alloc_flex_gd 1 57259 _000047_hash NULL
84087 +_000048_hash alloc_sglist 1-3-2 22960 _000048_hash NULL
84088 +_000049_hash __alloc_skb 1 23940 _000049_hash NULL
84089 +_000050_hash aoedev_flush 2 44398 _000050_hash NULL
84090 +_000051_hash append_to_buffer 3 63550 _000051_hash NULL
84091 +_000052_hash asix_read_cmd 5 13245 _000052_hash NULL
84092 +_000053_hash asix_write_cmd 5 58192 _000053_hash NULL
84093 +_000054_hash at76_set_card_command 4 4471 _000054_hash NULL
84094 +_000055_hash ath6kl_add_bss_if_needed 6 24317 _000055_hash NULL
84095 +_000056_hash ath6kl_debug_roam_tbl_event 3 5224 _000056_hash NULL
84096 +_000057_hash ath6kl_mgmt_powersave_ap 6 13791 _000057_hash NULL
84097 +_000058_hash ath6kl_send_go_probe_resp 3 21113 _000058_hash NULL
84098 +_000059_hash ath6kl_set_ap_probe_resp_ies 3 50539 _000059_hash NULL
84099 +_000060_hash ath6kl_set_assoc_req_ies 3 43185 _000060_hash NULL
84100 +_000061_hash ath6kl_wmi_bssinfo_event_rx 3 2275 _000061_hash NULL
84101 +_000062_hash ath6kl_wmi_send_action_cmd 7 58860 _000062_hash NULL
84102 +_000063_hash __ath6kl_wmi_send_mgmt_cmd 7 38971 _000063_hash NULL
84103 +_000064_hash attach_hdlc_protocol 3 19986 _000064_hash NULL
84104 +_000065_hash audio_write 4 54261 _001782_hash NULL nohasharray
84105 +_000066_hash audit_unpack_string 3 13748 _000066_hash NULL
84106 +_000067_hash ax25_setsockopt 5 42740 _000067_hash NULL
84107 +_000068_hash b43_debugfs_write 3 34838 _000068_hash NULL
84108 +_000069_hash b43legacy_debugfs_write 3 28556 _000069_hash NULL
84109 +_000070_hash batadv_hash_new 1 40491 _000070_hash NULL
84110 +_000071_hash batadv_orig_node_add_if 2 18433 _000071_hash NULL
84111 +_000072_hash batadv_orig_node_del_if 2 4 _000072_hash NULL
84112 +_000073_hash batadv_tt_changes_fill_buff 4 40323 _000073_hash NULL
84113 +_000074_hash batadv_tt_realloc_packet_buff 4 49960 _000074_hash NULL
84114 +_000075_hash bch_alloc 1 4593 _000075_hash NULL
84115 +_000076_hash befs_nls2utf 3 17163 _000076_hash NULL
84116 +_000077_hash befs_utf2nls 3 25628 _000077_hash NULL
84117 +_000078_hash bfad_debugfs_write_regrd 3 15218 _000078_hash NULL
84118 +_000079_hash bfad_debugfs_write_regwr 3 61841 _000079_hash NULL
84119 +_000080_hash bio_alloc_map_data 1-2 50782 _000080_hash NULL
84120 +_000082_hash bio_kmalloc 2 54672 _000082_hash NULL
84121 +_000083_hash bitmap_storage_alloc 2 55077 _000083_hash NULL
84122 +_000084_hash blkcipher_copy_iv 3 24075 _000084_hash NULL
84123 +_000085_hash blkcipher_next_slow 3-4 52733 _000085_hash NULL
84124 +_000087_hash bl_pipe_downcall 3 34264 _000087_hash NULL
84125 +_000088_hash bnad_debugfs_write_regrd 3 6706 _000088_hash NULL
84126 +_000089_hash bnad_debugfs_write_regwr 3 57500 _000089_hash NULL
84127 +_000090_hash bnx2fc_cmd_mgr_alloc 2-3 24873 _000090_hash NULL
84128 +_000092_hash bnx2fc_process_unsol_compl 2 15576 _000092_hash NULL
84129 +_000093_hash bnx2_nvram_write 2-4 7790 _000093_hash NULL
84130 +_000095_hash btmrvl_gpiogap_write 3 35053 _000095_hash NULL
84131 +_000096_hash btmrvl_hscfgcmd_write 3 27143 _000096_hash NULL
84132 +_000097_hash btmrvl_hscmd_write 3 27089 _000097_hash NULL
84133 +_000098_hash btmrvl_hsmode_write 3 42252 _000098_hash NULL
84134 +_000099_hash btmrvl_pscmd_write 3 29504 _000099_hash NULL
84135 +_000100_hash btmrvl_psmode_write 3 3703 _000100_hash NULL
84136 +_000101_hash btrfs_alloc_delayed_item 1 11678 _000101_hash NULL
84137 +_000102_hash c4iw_id_table_alloc 3 48163 _000102_hash NULL
84138 +_000103_hash cache_do_downcall 3 6926 _000103_hash NULL
84139 +_000104_hash cachefiles_cook_key 2 33274 _000104_hash NULL
84140 +_000105_hash cachefiles_daemon_write 3 43535 _000105_hash NULL
84141 +_000106_hash capi_write 3 35104 _003607_hash NULL nohasharray
84142 +_000107_hash carl9170_debugfs_write 3 50857 _000107_hash NULL
84143 +_000108_hash cciss_allocate_sg_chain_blocks 2-3 5368 _000108_hash NULL
84144 +_000110_hash cciss_proc_write 3 10259 _000110_hash NULL
84145 +_000111_hash cdrom_read_cdda_old 4 27664 _000111_hash NULL
84146 +_000112_hash ceph_alloc_page_vector 1 18710 _000112_hash NULL
84147 +_000113_hash ceph_buffer_new 1 35974 _000113_hash NULL
84148 +_000114_hash ceph_copy_user_to_page_vector 3-4 656 _000114_hash NULL
84149 +_000116_hash ceph_get_direct_page_vector 2 41917 _000116_hash NULL
84150 +_000117_hash ceph_msg_new 2 5846 _000117_hash NULL
84151 +_000118_hash ceph_setxattr 4 18913 _000118_hash NULL
84152 +_000119_hash cfi_read_pri 3 24366 _000119_hash NULL
84153 +_000120_hash cgroup_write_string 5 10900 _000120_hash NULL
84154 +_000121_hash cgroup_write_X64 5 54514 _000121_hash NULL
84155 +_000122_hash change_xattr 5 61390 _000122_hash NULL
84156 +_000123_hash check_load_and_stores 2 2143 _000123_hash NULL
84157 +_000124_hash cifs_idmap_key_instantiate 3 54503 _000124_hash NULL
84158 +_000125_hash cifs_security_flags_proc_write 3 5484 _000125_hash NULL
84159 +_000126_hash cifs_setxattr 4 23957 _000126_hash NULL
84160 +_000127_hash cifs_spnego_key_instantiate 3 23588 _000127_hash NULL
84161 +_000128_hash cld_pipe_downcall 3 15058 _000128_hash NULL
84162 +_000129_hash clear_refs_write 3 61904 _000129_hash NULL
84163 +_000130_hash clusterip_proc_write 3 44729 _000130_hash NULL
84164 +_000131_hash cm4040_write 3 58079 _000131_hash NULL
84165 +_000132_hash cm_copy_private_data 2 3649 _000132_hash NULL
84166 +_000133_hash cmm_write 3 2896 _000133_hash NULL
84167 +_000134_hash cm_write 3 36858 _000134_hash NULL
84168 +_000135_hash coda_psdev_write 3 1711 _000135_hash NULL
84169 +_000136_hash codec_reg_read_file 3 36280 _000136_hash NULL
84170 +_000137_hash command_file_write 3 31318 _000137_hash NULL
84171 +_000138_hash command_write 3 58841 _000138_hash NULL
84172 +_000139_hash comm_write 3 44537 _001714_hash NULL nohasharray
84173 +_000140_hash concat_writev 3 21451 _000140_hash NULL
84174 +_000141_hash copy_and_check 3 19089 _000141_hash NULL
84175 +_000142_hash copy_from_user_toio 3 31966 _000142_hash NULL
84176 +_000143_hash copy_items 6 50140 _000143_hash NULL
84177 +_000144_hash copy_macs 4 45534 _000144_hash NULL
84178 +_000145_hash __copy_to_user 3 17551 _000145_hash NULL
84179 +_000146_hash copy_vm86_regs_from_user 3 45340 _000146_hash NULL
84180 +_000147_hash core_sys_select 1 47494 _000147_hash NULL
84181 +_000148_hash cosa_write 3 1774 _000148_hash NULL
84182 +_000149_hash cp210x_set_config 4 46447 _000149_hash NULL
84183 +_000150_hash create_entry 2 33479 _000150_hash NULL
84184 +_000151_hash create_queues 2-3 9088 _000151_hash NULL
84185 +_000153_hash create_xattr 5 54106 _000153_hash NULL
84186 +_000154_hash create_xattr_datum 5 33356 _003443_hash NULL nohasharray
84187 +_000155_hash csum_partial_copy_fromiovecend 3-4 9957 _000155_hash NULL
84188 +_000157_hash ctrl_out 3-5 8712 _000157_hash NULL
84189 +_000159_hash cxacru_cm_get_array 4 4412 _000159_hash NULL
84190 +_000160_hash cxgbi_alloc_big_mem 1 4707 _000160_hash NULL
84191 +_000161_hash dac960_user_command_proc_write 3 3071 _000161_hash NULL
84192 +_000162_hash datablob_format 2 39571 _002490_hash NULL nohasharray
84193 +_000163_hash dccp_feat_clone_sp_val 3 11942 _000163_hash NULL
84194 +_000164_hash dccp_setsockopt_ccid 4 30701 _000164_hash NULL
84195 +_000165_hash dccp_setsockopt_cscov 2 37766 _000165_hash NULL
84196 +_000166_hash dccp_setsockopt_service 4 65336 _000166_hash NULL
84197 +_000167_hash ddebug_proc_write 3 18055 _000167_hash NULL
84198 +_000168_hash dev_config 3 8506 _000168_hash NULL
84199 +_000169_hash device_write 3 45156 _000169_hash NULL
84200 +_000170_hash devm_kzalloc 2 4966 _000170_hash NULL
84201 +_000171_hash devres_alloc 2 551 _000171_hash NULL
84202 +_000172_hash dfs_file_write 3 41196 _000172_hash NULL
84203 +_000173_hash direct_entry 3 38836 _000173_hash NULL
84204 +_000174_hash dispatch_ioctl 2 32357 _000174_hash NULL
84205 +_000175_hash dispatch_proc_write 3 44320 _000175_hash NULL
84206 +_000176_hash diva_os_copy_from_user 4 7792 _000176_hash NULL
84207 +_000177_hash dlm_alloc_pagevec 1 54296 _000177_hash NULL
84208 +_000178_hash dlmfs_file_read 3 28385 _000178_hash NULL
84209 +_000179_hash dlmfs_file_write 3 6892 _000179_hash NULL
84210 +_000180_hash dm_read 3 15674 _000180_hash NULL
84211 +_000181_hash dm_write 3 2513 _000181_hash NULL
84212 +_000182_hash __dn_setsockopt 5 13060 _000182_hash NULL
84213 +_000183_hash dns_query 3 9676 _000183_hash NULL
84214 +_000184_hash dns_resolver_instantiate 3 63314 _000184_hash NULL
84215 +_000185_hash do_add_counters 3 3992 _000185_hash NULL
84216 +_000186_hash __do_config_autodelink 3 58763 _000186_hash NULL
84217 +_000187_hash do_ip_setsockopt 5 41852 _000187_hash NULL
84218 +_000188_hash do_ipv6_setsockopt 5 18215 _000188_hash NULL
84219 +_000189_hash do_ip_vs_set_ctl 4 48641 _000189_hash NULL
84220 +_000190_hash do_kimage_alloc 3 64827 _000190_hash NULL
84221 +_000191_hash do_register_entry 4 29478 _000191_hash NULL
84222 +_000192_hash do_tty_write 5 44896 _000192_hash NULL
84223 +_000193_hash do_update_counters 4 2259 _000193_hash NULL
84224 +_000194_hash dsp_write 2 46218 _000194_hash NULL
84225 +_000195_hash dup_to_netobj 3 26363 _000195_hash NULL
84226 +_000196_hash dwc3_link_state_write 3 12641 _000196_hash NULL
84227 +_000197_hash dwc3_mode_write 3 51997 _000197_hash NULL
84228 +_000198_hash dwc3_testmode_write 3 30516 _000198_hash NULL
84229 +_000199_hash ecryptfs_copy_filename 4 11868 _000199_hash NULL
84230 +_000200_hash ecryptfs_miscdev_write 3 26847 _000200_hash NULL
84231 +_000201_hash ecryptfs_send_miscdev 2 64816 _000201_hash NULL
84232 +_000202_hash efx_tsoh_heap_alloc 2 58545 _000202_hash NULL
84233 +_000203_hash emi26_writememory 4 57908 _000203_hash NULL
84234 +_000204_hash emi62_writememory 4 29731 _000204_hash NULL
84235 +_000205_hash encrypted_instantiate 3 3168 _000205_hash NULL
84236 +_000206_hash encrypted_update 3 13414 _000206_hash NULL
84237 +_000207_hash ep0_write 3 14536 _001422_hash NULL nohasharray
84238 +_000208_hash ep_read 3 58813 _000208_hash NULL
84239 +_000209_hash ep_write 3 59008 _000209_hash NULL
84240 +_000210_hash erst_dbg_write 3 46715 _000210_hash NULL
84241 +_000211_hash esp_alloc_tmp 2-3 40558 _000211_hash NULL
84242 +_000213_hash evdev_do_ioctl 2 24459 _000213_hash NULL
84243 +_000214_hash exofs_read_lookup_dev_table 3 17733 _000214_hash NULL
84244 +_000215_hash ext4_kvmalloc 1 14796 _000215_hash NULL
84245 +_000216_hash ezusb_writememory 4 45976 _000216_hash NULL
84246 +_000217_hash fanotify_write 3 64623 _000217_hash NULL
84247 +_000218_hash fd_copyin 3 56247 _000218_hash NULL
84248 +_000219_hash ffs_epfile_io 3 64886 _000219_hash NULL
84249 +_000220_hash ffs_prepare_buffer 2 59892 _000220_hash NULL
84250 +_000221_hash f_hidg_write 3 7932 _000221_hash NULL
84251 +_000222_hash file_read_actor 4 1401 _000222_hash NULL
84252 +_000223_hash fill_write_buffer 3 3142 _000223_hash NULL
84253 +_000224_hash __find_xattr 6 2117 _002425_hash NULL nohasharray
84254 +_000225_hash fl_create 5 56435 _000225_hash NULL
84255 +_000226_hash fs_path_ensure_buf 2 59445 _000226_hash NULL
84256 +_000227_hash ftdi_elan_write 3 57309 _000227_hash NULL
84257 +_000228_hash fw_iso_buffer_alloc 2 13704 _000228_hash NULL
84258 +_000229_hash garmin_write_bulk 3 58191 _000229_hash NULL
84259 +_000230_hash garp_attr_create 3 3883 _000230_hash NULL
84260 +_000231_hash get_arg 3 5694 _000231_hash NULL
84261 +_000232_hash getdqbuf 1 62908 _000232_hash NULL
84262 +_000233_hash get_fdb_entries 3 41916 _000233_hash NULL
84263 +_000234_hash get_fd_set 1 3866 _000234_hash NULL
84264 +_000235_hash get_indirect_ea 4 51869 _000235_hash NULL
84265 +_000236_hash get_registers 3 26187 _000236_hash NULL
84266 +_000237_hash get_scq 2 10897 _000237_hash NULL
84267 +_000238_hash get_server_iovec 2 16804 _000238_hash NULL
84268 +_000239_hash get_ucode_user 3 38202 _000239_hash NULL
84269 +_000240_hash get_user_cpu_mask 2 14861 _000240_hash NULL
84270 +_000241_hash gfs2_alloc_sort_buffer 1 18275 _000241_hash NULL
84271 +_000242_hash gfs2_glock_nq_m 1 20347 _000242_hash NULL
84272 +_000243_hash gigaset_initcs 2 43753 _000243_hash NULL
84273 +_000244_hash gigaset_initdriver 2 1060 _000244_hash NULL
84274 +_000245_hash groups_alloc 1 7614 _000245_hash NULL
84275 +_000246_hash gs_alloc_req 2 58883 _000246_hash NULL
84276 +_000247_hash gs_buf_alloc 2 25067 _000247_hash NULL
84277 +_000248_hash gsm_data_alloc 3 42437 _000248_hash NULL
84278 +_000249_hash gss_pipe_downcall 3 23182 _000249_hash NULL
84279 +_000250_hash handle_request 9 10024 _000250_hash NULL
84280 +_000251_hash hashtab_create 3 33769 _000251_hash NULL
84281 +_000252_hash hcd_buffer_alloc 2 27495 _000252_hash NULL
84282 +_000253_hash hci_sock_setsockopt 5 28993 _000253_hash NULL
84283 +_000254_hash heap_init 2 49617 _000254_hash NULL
84284 +_000255_hash hest_ghes_dev_register 1 46766 _000255_hash NULL
84285 +_000256_hash hidg_alloc_ep_req 2 10159 _000256_hash NULL
84286 +_000257_hash hid_parse_report 3 51737 _000257_hash NULL
84287 +_000258_hash hidraw_get_report 3 45609 _000258_hash NULL
84288 +_000259_hash hidraw_report_event 3 20503 _000259_hash NULL
84289 +_000260_hash hidraw_send_report 3 23449 _000260_hash NULL
84290 +_000261_hash hpfs_translate_name 3 41497 _000261_hash NULL
84291 +_000262_hash hysdn_conf_write 3 52145 _000262_hash NULL
84292 +_000263_hash __i2400mu_send_barker 3 23652 _000263_hash NULL
84293 +_000264_hash i2cdev_read 3 1206 _000264_hash NULL
84294 +_000265_hash i2cdev_write 3 23310 _000265_hash NULL
84295 +_000266_hash i2o_parm_field_get 5 34477 _000266_hash NULL
84296 +_000267_hash i2o_parm_table_get 6 61635 _000267_hash NULL
84297 +_000268_hash ib_copy_from_udata 3 59502 _000268_hash NULL
84298 +_000269_hash ib_ucm_alloc_data 3 36885 _000269_hash NULL
84299 +_000270_hash ib_umad_write 3 47993 _000270_hash NULL
84300 +_000271_hash ib_uverbs_unmarshall_recv 5 12251 _000271_hash NULL
84301 +_000272_hash icn_writecmd 2 38629 _000272_hash NULL
84302 +_000273_hash ide_driver_proc_write 3 32493 _000273_hash NULL
84303 +_000274_hash ide_settings_proc_write 3 35110 _000274_hash NULL
84304 +_000275_hash idetape_chrdev_write 3 53976 _000275_hash NULL
84305 +_000276_hash idmap_pipe_downcall 3 14591 _000276_hash NULL
84306 +_000277_hash ieee80211_build_probe_req 7-5 27660 _000277_hash NULL
84307 +_000278_hash ieee80211_if_write 3 34894 _000278_hash NULL
84308 +_000279_hash if_write 3 51756 _000279_hash NULL
84309 +_000280_hash ilo_write 3 64378 _000280_hash NULL
84310 +_000281_hash ima_write_policy 3 40548 _000281_hash NULL
84311 +_000282_hash init_data_container 1 60709 _000282_hash NULL
84312 +_000283_hash init_send_hfcd 1 34586 _000283_hash NULL
84313 +_000284_hash insert_dent 7 65034 _000284_hash NULL
84314 +_000285_hash interpret_user_input 2 19393 _000285_hash NULL
84315 +_000286_hash int_proc_write 3 39542 _000286_hash NULL
84316 +_000287_hash ioctl_private_iw_point 7 1273 _000287_hash NULL
84317 +_000288_hash iov_iter_copy_from_user 4 31942 _000288_hash NULL
84318 +_000289_hash iov_iter_copy_from_user_atomic 4 56368 _000289_hash NULL
84319 +_000290_hash iowarrior_write 3 18604 _000290_hash NULL
84320 +_000291_hash ipc_alloc 1 1192 _000291_hash NULL
84321 +_000292_hash ipc_rcu_alloc 1 21208 _000292_hash NULL
84322 +_000293_hash ip_options_get_from_user 4 64958 _000293_hash NULL
84323 +_000294_hash ipv6_renew_option 3 38813 _000294_hash NULL
84324 +_000295_hash ip_vs_conn_fill_param_sync 6 29771 _001898_hash NULL nohasharray
84325 +_000296_hash ip_vs_create_timeout_table 2 64478 _000296_hash NULL
84326 +_000297_hash ipw_queue_tx_init 3 49161 _000297_hash NULL
84327 +_000298_hash irda_setsockopt 5 19824 _000298_hash NULL
84328 +_000299_hash irias_new_octseq_value 2 13596 _003821_hash NULL nohasharray
84329 +_000300_hash irnet_ctrl_write 3 24139 _000300_hash NULL
84330 +_000301_hash isdn_add_channels 3 40905 _000301_hash NULL
84331 +_000302_hash isdn_ppp_fill_rq 2 41428 _000302_hash NULL
84332 +_000303_hash isdn_ppp_write 4 29109 _000303_hash NULL
84333 +_000304_hash isdn_read 3 50021 _000304_hash NULL
84334 +_000305_hash isdn_v110_open 3 2418 _000305_hash NULL
84335 +_000306_hash isdn_writebuf_stub 4 52383 _000306_hash NULL
84336 +_000307_hash islpci_mgt_transmit 5 34133 _000307_hash NULL
84337 +_000308_hash iso_callback 3 43208 _000308_hash NULL
84338 +_000309_hash iso_packets_buffer_init 3-4 29061 _000309_hash NULL
84339 +_000310_hash it821x_firmware_command 3 8628 _000310_hash NULL
84340 +_000311_hash iwch_alloc_fastreg_pbl 2 40153 _000311_hash NULL
84341 +_000312_hash iwl_calib_set 3 34400 _003754_hash NULL nohasharray
84342 +_000313_hash jbd2_journal_init_revoke_table 1 36336 _000313_hash NULL
84343 +_000314_hash jffs2_alloc_full_dirent 1 60179 _001158_hash NULL nohasharray
84344 +_000315_hash journal_init_revoke_table 1 56331 _000315_hash NULL
84345 +_000316_hash kcalloc 1-2 27770 _000316_hash NULL
84346 +_000318_hash keyctl_instantiate_key_common 4 47889 _000318_hash NULL
84347 +_000319_hash keyctl_update_key 3 26061 _000319_hash NULL
84348 +_000320_hash __kfifo_alloc 2-3 22173 _000320_hash NULL
84349 +_000322_hash kfifo_copy_from_user 3 5091 _000322_hash NULL
84350 +_000323_hash kmalloc_node 1 50163 _003818_hash NULL nohasharray
84351 +_000324_hash kmalloc_parameter 1 65279 _000324_hash NULL
84352 +_000325_hash kmem_alloc 1 31920 _000325_hash NULL
84353 +_000326_hash kobj_map 2-3 9566 _000326_hash NULL
84354 +_000328_hash kone_receive 4 4690 _000328_hash NULL
84355 +_000329_hash kone_send 4 63435 _000329_hash NULL
84356 +_000330_hash krealloc 2 14908 _000330_hash NULL
84357 +_000331_hash kvmalloc 1 32646 _000331_hash NULL
84358 +_000332_hash kvm_read_guest_atomic 4 10765 _000332_hash NULL
84359 +_000333_hash kvm_read_guest_cached 4 39666 _000333_hash NULL
84360 +_000334_hash kvm_read_guest_page 5 18074 _000334_hash NULL
84361 +_000335_hash kzalloc 1 54740 _000335_hash NULL
84362 +_000336_hash l2cap_sock_setsockopt 5 50207 _000336_hash NULL
84363 +_000337_hash l2cap_sock_setsockopt_old 4 29346 _000337_hash NULL
84364 +_000338_hash lane2_associate_req 4 45398 _000338_hash NULL
84365 +_000339_hash lbs_debugfs_write 3 48413 _000339_hash NULL
84366 +_000340_hash lcd_write 3 14857 _000340_hash &_000015_hash
84367 +_000341_hash ldm_frag_add 2 5611 _000341_hash NULL
84368 +_000342_hash __lgread 4 31668 _000342_hash NULL
84369 +_000343_hash libipw_alloc_txb 1-3-2 27579 _000343_hash NULL
84370 +_000344_hash link_send_sections_long 4 46556 _000344_hash NULL
84371 +_000345_hash listxattr 3 12769 _000345_hash NULL
84372 +_000346_hash load_msg 2 95 _000346_hash NULL
84373 +_000347_hash lpfc_debugfs_dif_err_write 3 17424 _000347_hash NULL
84374 +_000348_hash lp_write 3 9511 _000348_hash NULL
84375 +_000349_hash mb_cache_create 2 17307 _000349_hash NULL
84376 +_000350_hash mce_write 3 26201 _000350_hash NULL
84377 +_000351_hash mcs7830_get_reg 3 33308 _000351_hash NULL
84378 +_000352_hash mcs7830_set_reg 3 31413 _000352_hash NULL
84379 +_000353_hash memcpy_fromiovec 3 55247 _000353_hash NULL
84380 +_000354_hash memcpy_fromiovecend 3-4 2707 _000354_hash NULL
84381 +_000356_hash mempool_resize 2 47983 _002039_hash NULL nohasharray
84382 +_000357_hash mem_rw 3 22085 _000357_hash NULL
84383 +_000358_hash mgmt_control 3 7349 _000358_hash NULL
84384 +_000359_hash mgmt_pending_add 5 46976 _000359_hash NULL
84385 +_000360_hash mlx4_ib_alloc_fast_reg_page_list 2 46119 _000360_hash NULL
84386 +_000361_hash mmc_alloc_sg 1 21504 _000361_hash NULL
84387 +_000362_hash mmc_send_bus_test 4 18285 _000362_hash NULL
84388 +_000363_hash mmc_send_cxd_data 5 38655 _000363_hash NULL
84389 +_000364_hash module_alloc_update_bounds 1 47205 _000364_hash NULL
84390 +_000365_hash move_addr_to_kernel 2 32673 _000365_hash NULL
84391 +_000366_hash mpi_alloc_limb_space 1 23190 _000366_hash NULL
84392 +_000367_hash mpi_resize 2 44674 _000367_hash NULL
84393 +_000368_hash mptctl_getiocinfo 2 28545 _000368_hash NULL
84394 +_000369_hash mtdchar_readoob 4 31200 _000369_hash NULL
84395 +_000370_hash mtdchar_write 3 56831 _002122_hash NULL nohasharray
84396 +_000371_hash mtdchar_writeoob 4 3393 _000371_hash NULL
84397 +_000372_hash mtd_device_parse_register 5 5024 _000372_hash NULL
84398 +_000373_hash mtf_test_write 3 18844 _000373_hash NULL
84399 +_000374_hash mthca_alloc_icm_table 3-4 38268 _002459_hash NULL nohasharray
84400 +_000376_hash mthca_alloc_init 2 21754 _000376_hash NULL
84401 +_000377_hash mthca_array_init 2 39987 _000377_hash NULL
84402 +_000378_hash mthca_buf_alloc 2 35861 _000378_hash NULL
84403 +_000379_hash mtrr_write 3 59622 _000379_hash NULL
84404 +_000380_hash musb_test_mode_write 3 33518 _000380_hash NULL
84405 +_000381_hash mwifiex_get_common_rates 3 17131 _000381_hash NULL
84406 +_000382_hash __mxt_write_reg 3 57326 _000382_hash NULL
84407 +_000383_hash nand_bch_init 2-3 16280 _001439_hash NULL nohasharray
84408 +_000385_hash ncp_file_write 3 3813 _000385_hash NULL
84409 +_000386_hash ncp__vol2io 5 4804 _000386_hash NULL
84410 +_000387_hash nes_alloc_fast_reg_page_list 2 33523 _000387_hash NULL
84411 +_000388_hash nfc_targets_found 3 29886 _000388_hash NULL
84412 +_000389_hash __nf_ct_ext_add_length 3 12364 _000389_hash NULL
84413 +_000390_hash nfs4_acl_new 1 49806 _000390_hash NULL
84414 +_000391_hash nfs4_write_cached_acl 4 15070 _000391_hash NULL
84415 +_000392_hash nfsd_symlink 6 63442 _000392_hash NULL
84416 +_000393_hash nfs_idmap_get_desc 2-4 42990 _000393_hash NULL
84417 +_000395_hash nfs_readdir_make_qstr 3 12509 _000395_hash NULL
84418 +_000396_hash note_last_dentry 3 12285 _000396_hash NULL
84419 +_000397_hash ntfs_copy_from_user 3-5 15072 _000397_hash NULL
84420 +_000399_hash __ntfs_copy_from_user_iovec_inatomic 3-4 38153 _000399_hash NULL
84421 +_000401_hash ntfs_ucstonls 3-5 23097 _000401_hash NULL
84422 +_000403_hash nvme_alloc_iod 1 56027 _000403_hash NULL
84423 +_000404_hash nvram_write 3 3894 _000404_hash NULL
84424 +_000405_hash o2hb_debug_create 4 18744 _000405_hash NULL
84425 +_000406_hash o2net_send_message_vec 4 879 _002013_hash NULL nohasharray
84426 +_000407_hash ocfs2_control_cfu 2 37750 _000407_hash NULL
84427 +_000408_hash oom_adjust_write 3 41116 _000408_hash NULL
84428 +_000409_hash oom_score_adj_write 3 42594 _000409_hash NULL
84429 +_000410_hash oprofilefs_ulong_from_user 3 57251 _000410_hash NULL
84430 +_000411_hash opticon_write 4 60775 _000411_hash NULL
84431 +_000412_hash p9_check_zc_errors 4 15534 _000412_hash NULL
84432 +_000413_hash packet_buffer_init 2 1607 _000413_hash NULL
84433 +_000414_hash packet_setsockopt 5 17662 _000414_hash NULL
84434 +_000415_hash parse_command 2 37079 _000415_hash NULL
84435 +_000416_hash pcbit_writecmd 2 12332 _000416_hash NULL
84436 +_000417_hash pcmcia_replace_cis 3 57066 _000417_hash NULL
84437 +_000418_hash pgctrl_write 3 50453 _000418_hash NULL
84438 +_000419_hash pg_write 3 40766 _000419_hash NULL
84439 +_000420_hash pidlist_allocate 1 64404 _000420_hash NULL
84440 +_000421_hash pipe_iov_copy_from_user 3 23102 _000421_hash NULL
84441 +_000422_hash pipe_iov_copy_to_user 3 3447 _000422_hash NULL
84442 +_000423_hash pkt_add 3 39897 _000423_hash NULL
84443 +_000424_hash pktgen_if_write 3 55628 _000424_hash NULL
84444 +_000425_hash platform_device_add_data 3 310 _000425_hash NULL
84445 +_000426_hash platform_device_add_resources 3 13289 _000426_hash NULL
84446 +_000427_hash pmcraid_copy_sglist 3 38431 _000427_hash NULL
84447 +_000428_hash pm_qos_power_write 3 52513 _000428_hash NULL
84448 +_000429_hash pnpbios_proc_write 3 19758 _000429_hash NULL
84449 +_000430_hash pool_allocate 3 42012 _000430_hash NULL
84450 +_000431_hash posix_acl_alloc 1 48063 _000431_hash NULL
84451 +_000432_hash ppp_cp_parse_cr 4 5214 _000432_hash NULL
84452 +_000433_hash ppp_write 3 34034 _000433_hash NULL
84453 +_000434_hash pp_read 3 33210 _000434_hash NULL
84454 +_000435_hash pp_write 3 39554 _000435_hash NULL
84455 +_000436_hash printer_req_alloc 2 62687 _000436_hash NULL
84456 +_000437_hash printer_write 3 60276 _000437_hash NULL
84457 +_000438_hash prism2_info_scanresults 3 59729 _000438_hash NULL
84458 +_000439_hash prism2_set_genericelement 3 29277 _000439_hash NULL
84459 +_000440_hash __probe_kernel_read 3 61119 _000440_hash NULL
84460 +_000441_hash __probe_kernel_write 3 29842 _000441_hash NULL
84461 +_000442_hash proc_coredump_filter_write 3 25625 _000442_hash NULL
84462 +_000443_hash _proc_do_string 2 6376 _000443_hash NULL
84463 +_000444_hash process_vm_rw_pages 5-6 15954 _000444_hash NULL
84464 +_000446_hash proc_loginuid_write 3 63648 _000446_hash NULL
84465 +_000447_hash proc_pid_attr_write 3 63845 _000447_hash NULL
84466 +_000448_hash proc_scsi_devinfo_write 3 32064 _000448_hash NULL
84467 +_000449_hash proc_scsi_write 3 29142 _000449_hash NULL
84468 +_000450_hash proc_scsi_write_proc 3 267 _000450_hash NULL
84469 +_000451_hash pskb_expand_head 2-3 42881 _000451_hash NULL
84470 +_000453_hash pstore_mkfile 5 50830 _000453_hash NULL
84471 +_000454_hash pti_char_write 3 60960 _000454_hash NULL
84472 +_000455_hash ptrace_writedata 4 45021 _000455_hash NULL
84473 +_000456_hash pt_write 3 40159 _000456_hash NULL
84474 +_000457_hash qdisc_class_hash_alloc 1 18262 _000457_hash NULL
84475 +_000458_hash r3964_write 4 57662 _000458_hash NULL
84476 +_000459_hash raw_seticmpfilter 3 6888 _000459_hash NULL
84477 +_000460_hash raw_setsockopt 5 45800 _000460_hash NULL
84478 +_000461_hash rawv6_seticmpfilter 5 12137 _000461_hash NULL
84479 +_000462_hash ray_cs_essid_proc_write 3 17875 _000462_hash NULL
84480 +_000463_hash rbd_add 3 16366 _000463_hash NULL
84481 +_000464_hash rbd_snap_add 4 19678 _000464_hash NULL
84482 +_000465_hash rdma_set_ib_paths 3 45592 _000465_hash NULL
84483 +_000466_hash rds_page_copy_user 4 35691 _000466_hash NULL
84484 +_000467_hash read 3 9397 _000467_hash NULL
84485 +_000468_hash read_buf 2 20469 _000468_hash NULL
84486 +_000469_hash read_cis_cache 4 29735 _000469_hash NULL
84487 +_000470_hash realloc_buffer 2 25816 _000470_hash NULL
84488 +_000471_hash receive_DataRequest 3 9904 _000471_hash NULL
84489 +_000472_hash recent_mt_proc_write 3 8206 _000472_hash NULL
84490 +_000473_hash regmap_access_read_file 3 37223 _000473_hash NULL
84491 +_000474_hash regmap_bulk_write 4 59049 _000474_hash NULL
84492 +_000475_hash regmap_map_read_file 3 37685 _000475_hash NULL
84493 +_000476_hash regset_tls_set 4 18459 _000476_hash NULL
84494 +_000477_hash reiserfs_add_entry 4 23062 _002792_hash NULL nohasharray
84495 +_000478_hash remote_settings_file_write 3 22987 _000478_hash NULL
84496 +_000479_hash request_key_auth_new 3 38092 _000479_hash NULL
84497 +_000480_hash restore_i387_fxsave 2 17528 _000480_hash NULL
84498 +_000481_hash revalidate 2 19043 _000481_hash NULL
84499 +_000482_hash rfcomm_sock_setsockopt 5 18254 _000482_hash NULL
84500 +_000483_hash rndis_add_response 2 58544 _000483_hash NULL
84501 +_000484_hash rndis_set_oid 4 6547 _000484_hash NULL
84502 +_000485_hash rngapi_reset 3 34366 _002137_hash NULL nohasharray
84503 +_000486_hash roccat_common2_receive 4 50369 _000486_hash NULL
84504 +_000487_hash roccat_common2_send 4 2422 _000487_hash NULL
84505 +_000488_hash rpc_malloc 2 43573 _000488_hash NULL
84506 +_000489_hash rt2x00debug_write_bbp 3 8212 _000489_hash NULL
84507 +_000490_hash rt2x00debug_write_csr 3 64753 _000490_hash NULL
84508 +_000491_hash rt2x00debug_write_eeprom 3 23091 _000491_hash NULL
84509 +_000492_hash rt2x00debug_write_rf 3 38195 _000492_hash NULL
84510 +_000493_hash rt2x00debug_write_rfcsr 3 41473 _000493_hash NULL
84511 +_000494_hash rts51x_read_mem 4 26577 _002730_hash NULL nohasharray
84512 +_000495_hash rts51x_read_status 4 11830 _000495_hash NULL
84513 +_000496_hash rts51x_write_mem 4 17598 _000496_hash NULL
84514 +_000497_hash rw_copy_check_uvector 3 45748 _003716_hash NULL nohasharray
84515 +_000498_hash rxrpc_request_key 3 27235 _000498_hash NULL
84516 +_000499_hash rxrpc_server_keyring 3 16431 _000499_hash NULL
84517 +_000500_hash savemem 3 58129 _000500_hash NULL
84518 +_000501_hash sb16_copy_from_user 10-7-6 55836 _000501_hash NULL
84519 +_000504_hash sched_autogroup_write 3 10984 _000504_hash NULL
84520 +_000505_hash scsi_mode_select 6 37330 _000505_hash NULL
84521 +_000506_hash scsi_tgt_copy_sense 3 26933 _000506_hash NULL
84522 +_000507_hash sctp_auth_create_key 1 51641 _000507_hash NULL
84523 +_000508_hash sctp_getsockopt_delayed_ack 2 9232 _000508_hash NULL
84524 +_000509_hash sctp_getsockopt_local_addrs 2 25178 _000509_hash NULL
84525 +_000510_hash sctp_make_abort_user 3 29654 _000510_hash NULL
84526 +_000511_hash sctp_setsockopt_active_key 3 43755 _000511_hash NULL
84527 +_000512_hash sctp_setsockopt_adaptation_layer 3 26935 _003246_hash NULL nohasharray
84528 +_000513_hash sctp_setsockopt_associnfo 3 51684 _000513_hash NULL
84529 +_000514_hash sctp_setsockopt_auth_chunk 3 30843 _000514_hash NULL
84530 +_000515_hash sctp_setsockopt_auth_key 3 3793 _000515_hash NULL
84531 +_000516_hash sctp_setsockopt_autoclose 3 5775 _000516_hash NULL
84532 +_000517_hash sctp_setsockopt_bindx 3 49870 _000517_hash NULL
84533 +_000518_hash __sctp_setsockopt_connectx 3 46949 _000518_hash NULL
84534 +_000519_hash sctp_setsockopt_context 3 31091 _000519_hash NULL
84535 +_000520_hash sctp_setsockopt_default_send_param 3 49578 _000520_hash NULL
84536 +_000521_hash sctp_setsockopt_delayed_ack 3 40129 _000521_hash NULL
84537 +_000522_hash sctp_setsockopt_del_key 3 42304 _002709_hash NULL nohasharray
84538 +_000523_hash sctp_setsockopt_events 3 18862 _000523_hash NULL
84539 +_000524_hash sctp_setsockopt_hmac_ident 3 11687 _000524_hash NULL
84540 +_000525_hash sctp_setsockopt_initmsg 3 1383 _000525_hash NULL
84541 +_000526_hash sctp_setsockopt_maxburst 3 28041 _000526_hash NULL
84542 +_000527_hash sctp_setsockopt_maxseg 3 11829 _000527_hash NULL
84543 +_000528_hash sctp_setsockopt_peer_addr_params 3 734 _000528_hash NULL
84544 +_000529_hash sctp_setsockopt_peer_primary_addr 3 13440 _000529_hash NULL
84545 +_000530_hash sctp_setsockopt_rtoinfo 3 30941 _000530_hash NULL
84546 +_000531_hash security_context_to_sid_core 2 29248 _000531_hash NULL
84547 +_000532_hash sel_commit_bools_write 3 46077 _000532_hash NULL
84548 +_000533_hash sel_write_avc_cache_threshold 3 2256 _000533_hash NULL
84549 +_000534_hash sel_write_bool 3 46996 _000534_hash NULL
84550 +_000535_hash sel_write_checkreqprot 3 60774 _000535_hash NULL
84551 +_000536_hash sel_write_disable 3 10511 _000536_hash NULL
84552 +_000537_hash sel_write_enforce 3 48998 _000537_hash NULL
84553 +_000538_hash sel_write_load 3 63830 _000538_hash NULL
84554 +_000539_hash send_bulk_static_data 3 61932 _000539_hash NULL
84555 +_000540_hash set_aoe_iflist 2 42737 _000540_hash NULL
84556 +_000541_hash setkey_unaligned 3 39474 _000541_hash NULL
84557 +_000542_hash set_registers 3 53582 _000542_hash NULL
84558 +_000543_hash setsockopt 5 54539 _000543_hash NULL
84559 +_000544_hash setup_req 3 5848 _000544_hash NULL
84560 +_000545_hash setxattr 4 37006 _000545_hash NULL
84561 +_000546_hash sfq_alloc 1 2861 _000546_hash NULL
84562 +_000547_hash sg_kmalloc 1 50240 _000547_hash NULL
84563 +_000548_hash sgl_map_user_pages 2 30610 _000548_hash NULL
84564 +_000549_hash shash_setkey_unaligned 3 8620 _000549_hash NULL
84565 +_000550_hash shmem_xattr_alloc 2 61190 _000550_hash NULL
84566 +_000551_hash sierra_setup_urb 5 46029 _000551_hash NULL
84567 +_000552_hash simple_transaction_get 3 50633 _000552_hash NULL
84568 +_000553_hash simple_write_to_buffer 2-5 3122 _000553_hash NULL
84569 +_000555_hash sisusb_send_bulk_msg 3 17864 _000555_hash NULL
84570 +_000556_hash skb_add_data 3 48363 _000556_hash NULL
84571 +_000557_hash skb_do_copy_data_nocache 5 12465 _000557_hash NULL
84572 +_000558_hash sl_alloc_bufs 2 50380 _000558_hash NULL
84573 +_000559_hash sl_realloc_bufs 2 64086 _000559_hash NULL
84574 +_000560_hash smk_set_cipso 3 20379 _000560_hash NULL
84575 +_000561_hash smk_write_ambient 3 45691 _000561_hash NULL
84576 +_000562_hash smk_write_direct 3 46363 _000562_hash NULL
84577 +_000563_hash smk_write_doi 3 49621 _000563_hash NULL
84578 +_000564_hash smk_write_logging 3 2618 _000564_hash NULL
84579 +_000565_hash smk_write_mapped 3 13519 _000565_hash NULL
84580 +_000566_hash smk_write_netlbladdr 3 42525 _000566_hash NULL
84581 +_000567_hash smk_write_onlycap 3 14400 _000567_hash NULL
84582 +_000568_hash smk_write_rules_list 3 18565 _000568_hash NULL
84583 +_000569_hash snd_ctl_elem_user_tlv 3 11695 _000569_hash NULL
84584 +_000570_hash snd_emu10k1_fx8010_read 5 9605 _000570_hash NULL
84585 +_000571_hash snd_emu10k1_synth_copy_from_user 3-5 9061 _000571_hash NULL
84586 +_000573_hash snd_gus_dram_poke 4 18525 _000573_hash NULL
84587 +_000574_hash snd_hdsp_playback_copy 5 20676 _000574_hash NULL
84588 +_000575_hash snd_info_entry_write 3 63474 _000575_hash NULL
84589 +_000576_hash snd_korg1212_copy_from 6 36169 _000576_hash NULL
84590 +_000577_hash snd_mem_proc_write 3 9786 _000577_hash NULL
84591 +_000578_hash snd_midi_channel_init_set 1 30092 _000578_hash NULL
84592 +_000579_hash snd_midi_event_new 1 9893 _000764_hash NULL nohasharray
84593 +_000580_hash snd_opl4_mem_proc_write 5 9670 _000580_hash NULL
84594 +_000581_hash snd_pcm_aio_read 3 13900 _000581_hash NULL
84595 +_000582_hash snd_pcm_aio_write 3 28738 _000582_hash NULL
84596 +_000583_hash snd_pcm_oss_write1 3 10872 _000583_hash NULL
84597 +_000584_hash snd_pcm_oss_write2 3 27332 _000584_hash NULL
84598 +_000585_hash snd_rawmidi_kernel_write1 4 56847 _000585_hash NULL
84599 +_000586_hash snd_rme9652_playback_copy 5 20970 _000586_hash NULL
84600 +_000587_hash snd_sb_csp_load_user 3 45190 _000587_hash NULL
84601 +_000588_hash snd_usb_ctl_msg 8 8436 _000588_hash NULL
84602 +_000589_hash sock_bindtodevice 3 50942 _000589_hash NULL
84603 +_000590_hash sock_kmalloc 2 62205 _000590_hash NULL
84604 +_000591_hash spidev_ioctl 2 12846 _000591_hash NULL
84605 +_000592_hash spidev_write 3 44510 _000592_hash NULL
84606 +_000593_hash squashfs_read_table 3 16945 _000593_hash NULL
84607 +_000594_hash srpt_alloc_ioctx 2-3 51042 _000594_hash NULL
84608 +_000596_hash srpt_alloc_ioctx_ring 2-4-3 49330 _000596_hash NULL
84609 +_000597_hash st5481_setup_isocpipes 6-4 61340 _000597_hash NULL
84610 +_000598_hash sta_agg_status_write 3 45164 _000598_hash NULL
84611 +_000599_hash svc_setsockopt 5 36876 _000599_hash NULL
84612 +_000600_hash sys_add_key 4 61288 _000600_hash NULL
84613 +_000601_hash sys_modify_ldt 3 18824 _000601_hash NULL
84614 +_000602_hash sys_semtimedop 3 4486 _000602_hash NULL
84615 +_000603_hash sys_setdomainname 2 4373 _000603_hash NULL
84616 +_000604_hash sys_sethostname 2 42962 _000604_hash NULL
84617 +_000605_hash tomoyo_write_self 3 45161 _000605_hash NULL
84618 +_000606_hash tower_write 3 8580 _000606_hash NULL
84619 +_000607_hash tpm_write 3 50798 _000607_hash NULL
84620 +_000608_hash trusted_instantiate 3 4710 _000608_hash NULL
84621 +_000609_hash trusted_update 3 12664 _000609_hash NULL
84622 +_000610_hash tty_buffer_alloc 2 45437 _000610_hash NULL
84623 +_000611_hash __tun_chr_ioctl 4 22300 _000611_hash NULL
84624 +_000612_hash ubi_more_leb_change_data 4 63534 _000612_hash NULL
84625 +_000613_hash ubi_more_update_data 4 39189 _000613_hash NULL
84626 +_000614_hash ubi_resize_volume 2 50172 _000614_hash NULL
84627 +_000615_hash udf_alloc_i_data 2 35786 _000615_hash NULL
84628 +_000616_hash uea_idma_write 3 64139 _000616_hash NULL
84629 +_000617_hash uea_request 4 47613 _000617_hash NULL
84630 +_000618_hash uea_send_modem_cmd 3 3888 _000618_hash NULL
84631 +_000619_hash uio_write 3 43202 _000619_hash NULL
84632 +_000620_hash um_idi_write 3 18293 _000620_hash NULL
84633 +_000621_hash us122l_ctl_msg 8 13330 _000621_hash NULL
84634 +_000622_hash usb_alloc_urb 1 43436 _000622_hash NULL
84635 +_000623_hash usblp_new_writeurb 2 22894 _000623_hash NULL
84636 +_000624_hash usblp_write 3 23178 _000624_hash NULL
84637 +_000625_hash usbtest_alloc_urb 3-5 34446 _000625_hash NULL
84638 +_000627_hash usbtmc_write 3 64340 _000627_hash NULL
84639 +_000628_hash user_instantiate 3 26131 _000628_hash NULL
84640 +_000629_hash user_update 3 41332 _000629_hash NULL
84641 +_000630_hash uwb_rc_cmd_done 4 35892 _000630_hash NULL
84642 +_000631_hash uwb_rc_neh_grok_event 3 55799 _000631_hash NULL
84643 +_000632_hash v9fs_alloc_rdir_buf 2 42150 _000632_hash NULL
84644 +_000633_hash vc_do_resize 3-4 48842 _000633_hash NULL
84645 +_000635_hash vcs_write 3 3910 _000635_hash NULL
84646 +_000636_hash vga_arb_write 3 36112 _000636_hash NULL
84647 +_000637_hash vga_switcheroo_debugfs_write 3 33984 _000637_hash NULL
84648 +_000638_hash vhci_get_user 3 45039 _000638_hash NULL
84649 +_000639_hash video_proc_write 3 6724 _000639_hash NULL
84650 +_000640_hash vlsi_alloc_ring 3-4 57003 _000640_hash NULL
84651 +_000642_hash __vmalloc 1 61168 _000642_hash NULL
84652 +_000643_hash vmalloc_32 1 1135 _000643_hash NULL
84653 +_000644_hash vmalloc_32_user 1 37519 _000644_hash NULL
84654 +_000645_hash vmalloc_exec 1 36132 _000645_hash NULL
84655 +_000646_hash vmalloc_node 1 58700 _000646_hash NULL
84656 +_000647_hash __vmalloc_node_flags 1 30352 _000647_hash NULL
84657 +_000648_hash vmalloc_user 1 32308 _000648_hash NULL
84658 +_000649_hash vol_cdev_direct_write 3 20751 _000649_hash NULL
84659 +_000650_hash vp_request_msix_vectors 2 28849 _000650_hash NULL
84660 +_000651_hash vring_add_indirect 3-4 20737 _000651_hash NULL
84661 +_000653_hash vring_new_virtqueue 1 9671 _000653_hash NULL
84662 +_000654_hash vxge_os_dma_malloc 2 46184 _000654_hash NULL
84663 +_000655_hash vxge_os_dma_malloc_async 3 56348 _000655_hash NULL
84664 +_000656_hash wdm_write 3 53735 _000656_hash NULL
84665 +_000657_hash wiimote_hid_send 3 48528 _000657_hash NULL
84666 +_000658_hash wlc_phy_loadsampletable_nphy 3 64367 _000658_hash NULL
84667 +_000659_hash write 3 62671 _000659_hash NULL
84668 +_000660_hash write_flush 3 50803 _000660_hash NULL
84669 +_000661_hash write_rio 3 54837 _000661_hash NULL
84670 +_000662_hash x25_asy_change_mtu 2 26928 _000662_hash NULL
84671 +_000663_hash xdi_copy_from_user 4 8395 _000663_hash NULL
84672 +_000664_hash xfrm_dst_alloc_copy 3 3034 _000664_hash NULL
84673 +_000665_hash xfrm_user_policy 4 62573 _000665_hash NULL
84674 +_000666_hash xfs_attrmulti_attr_set 4 59346 _000666_hash NULL
84675 +_000667_hash xfs_handle_to_dentry 3 12135 _000667_hash NULL
84676 +_000668_hash xip_file_read 3 58592 _000668_hash NULL
84677 +_000669_hash __xip_file_write 3-4 2733 _000669_hash NULL
84678 +_000671_hash xprt_rdma_allocate 2 31372 _000671_hash NULL
84679 +_000672_hash zd_usb_iowrite16v_async 3 23984 _000672_hash NULL
84680 +_000673_hash zd_usb_read_fw 4 22049 _000673_hash NULL
84681 +_000674_hash zerocopy_sg_from_iovec 3 11828 _000674_hash NULL
84682 +_000675_hash __a2mp_build 3 60987 _000675_hash NULL
84683 +_000677_hash acpi_ex_allocate_name_string 2-1 7685 _001169_hash NULL nohasharray
84684 +_000678_hash acpi_os_allocate_zeroed 1 37422 _000678_hash NULL
84685 +_000679_hash acpi_ut_initialize_buffer 2 47143 _002830_hash NULL nohasharray
84686 +_000680_hash ad7879_spi_xfer 3 36311 _000680_hash NULL
84687 +_000681_hash add_new_gdb 3 27643 _000681_hash NULL
84688 +_000682_hash add_numbered_child 5 14273 _000682_hash NULL
84689 +_000683_hash add_res_range 4 21310 _000683_hash NULL
84690 +_000684_hash addtgt 3 54703 _000684_hash NULL
84691 +_000685_hash add_uuid 4 49831 _000685_hash NULL
84692 +_000686_hash afs_cell_alloc 2 24052 _000686_hash NULL
84693 +_000687_hash aggr_recv_addba_req_evt 4 38037 _000687_hash NULL
84694 +_000688_hash agp_create_memory 1 1075 _000688_hash NULL
84695 +_000689_hash agp_create_user_memory 1 62955 _000689_hash NULL
84696 +_000690_hash alg_setsockopt 5 20985 _000690_hash NULL
84697 +_000691_hash alloc_async 1 14208 _000691_hash NULL
84698 +_000692_hash ___alloc_bootmem_nopanic 1 53626 _000692_hash NULL
84699 +_000693_hash alloc_buf 1 34532 _000693_hash NULL
84700 +_000694_hash alloc_chunk 1 49575 _000694_hash NULL
84701 +_000695_hash alloc_context 1 41283 _000695_hash NULL
84702 +_000696_hash alloc_ctrl_packet 1 44667 _000696_hash NULL
84703 +_000697_hash alloc_data_packet 1 46698 _000697_hash NULL
84704 +_000698_hash alloc_dca_provider 2 59670 _000698_hash NULL
84705 +_000699_hash __alloc_dev_table 2 54343 _000699_hash NULL
84706 +_000700_hash alloc_ep 1 17269 _000700_hash NULL
84707 +_000701_hash __alloc_extent_buffer 3 15093 _000701_hash NULL
84708 +_000702_hash alloc_group_attrs 2 9194 _000727_hash NULL nohasharray
84709 +_000703_hash alloc_large_system_hash 2 22391 _000703_hash NULL
84710 +_000704_hash alloc_netdev_mqs 1 30030 _000704_hash NULL
84711 +_000705_hash __alloc_objio_seg 1 7203 _000705_hash NULL
84712 +_000706_hash alloc_ring 2-4 15345 _000706_hash NULL
84713 +_000707_hash alloc_ring 2-4 39151 _000707_hash NULL
84714 +_000710_hash alloc_session 1-2 64171 _000710_hash NULL
84715 +_000714_hash alloc_skb 1 55439 _000714_hash NULL
84716 +_000715_hash alloc_skb_fclone 1 3467 _000715_hash NULL
84717 +_000716_hash alloc_smp_req 1 51337 _000716_hash NULL
84718 +_000717_hash alloc_smp_resp 1 3566 _000717_hash NULL
84719 +_000718_hash alloc_ts_config 1 45775 _000718_hash NULL
84720 +_000719_hash alloc_upcall 2 62186 _000719_hash NULL
84721 +_000720_hash altera_drscan 2 48698 _000720_hash NULL
84722 +_000721_hash altera_irscan 2 62396 _000721_hash NULL
84723 +_000722_hash altera_set_dr_post 2 54291 _000722_hash NULL
84724 +_000723_hash altera_set_dr_pre 2 64862 _000723_hash NULL
84725 +_000724_hash altera_set_ir_post 2 20948 _000724_hash NULL
84726 +_000725_hash altera_set_ir_pre 2 54103 _000725_hash NULL
84727 +_000726_hash altera_swap_dr 2 50090 _000726_hash NULL
84728 +_000727_hash altera_swap_ir 2 9194 _000727_hash &_000702_hash
84729 +_000728_hash amd_create_gatt_pages 1 20537 _000728_hash NULL
84730 +_000729_hash aoechr_write 3 62883 _003674_hash NULL nohasharray
84731 +_000730_hash applesmc_create_nodes 2 49392 _000730_hash NULL
84732 +_000731_hash array_zalloc 1-2 7519 _000731_hash NULL
84733 +_000733_hash arvo_sysfs_read 6 31617 _000733_hash NULL
84734 +_000734_hash arvo_sysfs_write 6 3311 _000734_hash NULL
84735 +_000735_hash asd_store_update_bios 4 10165 _000735_hash NULL
84736 +_000736_hash ata_host_alloc 2 46094 _000736_hash NULL
84737 +_000737_hash atalk_sendmsg 4 21677 _000737_hash NULL
84738 +_000738_hash ath6kl_cfg80211_connect_event 7-9-8 13443 _000738_hash NULL
84739 +_000739_hash ath6kl_mgmt_tx 9 21153 _000739_hash NULL
84740 +_000740_hash ath6kl_wmi_proc_events_vif 5 42549 _003190_hash NULL nohasharray
84741 +_000741_hash ath6kl_wmi_roam_tbl_event_rx 3 43440 _000741_hash NULL
84742 +_000742_hash ath6kl_wmi_send_mgmt_cmd 7 17347 _000742_hash NULL
84743 +_000743_hash ath_descdma_setup 5 12257 _000743_hash NULL
84744 +_000744_hash ath_rx_edma_init 2 65483 _000744_hash NULL
84745 +_000745_hash ati_create_gatt_pages 1 4722 _003275_hash NULL nohasharray
84746 +_000746_hash audit_expand 2 2098 _000746_hash NULL
84747 +_000747_hash audit_init_entry 1 38644 _000747_hash NULL
84748 +_000748_hash ax25_sendmsg 4 62770 _000748_hash NULL
84749 +_000749_hash b1_alloc_card 1 36155 _000749_hash NULL
84750 +_000750_hash b43_nphy_load_samples 3 36481 _000750_hash NULL
84751 +_000751_hash batadv_orig_hash_add_if 2 10033 _000751_hash NULL
84752 +_000752_hash batadv_orig_hash_del_if 2 48972 _000752_hash NULL
84753 +_000753_hash batadv_tt_append_diff 4 20588 _000753_hash NULL
84754 +_000754_hash batadv_tt_commit_changes 4 2008 _000754_hash NULL
84755 +_000755_hash batadv_tt_prepare_packet_buff 4 1280 _000755_hash NULL
84756 +_000756_hash bio_copy_user_iov 4 37660 _000756_hash NULL
84757 +_000757_hash __bio_map_kern 3 47379 _000757_hash NULL
84758 +_000758_hash bitmap_resize 2 33054 _000758_hash NULL
84759 +_000759_hash blk_check_plugged 3 50736 _000759_hash NULL
84760 +_000760_hash blk_register_region 1-2 51424 _000760_hash NULL
84761 +_000762_hash bm_entry_write 3 28338 _000762_hash NULL
84762 +_000763_hash bm_realloc_pages 2 9431 _000763_hash NULL
84763 +_000764_hash bm_register_write 3 9893 _000764_hash &_000579_hash
84764 +_000765_hash bm_status_write 3 12964 _000765_hash NULL
84765 +_000766_hash br_mdb_rehash 2 42643 _000766_hash NULL
84766 +_000767_hash btmrvl_sdio_host_to_card 3 12152 _000767_hash NULL
84767 +_000768_hash btrfs_copy_from_user 1-3 43806 _000768_hash NULL
84768 +_000770_hash btrfs_insert_delayed_dir_index 4 63720 _000770_hash NULL
84769 +_000771_hash __btrfs_map_block 3 49839 _000771_hash NULL
84770 +_000772_hash c4iw_init_resource 2-3 30393 _000772_hash NULL
84771 +_000774_hash cache_downcall 3 13666 _000774_hash NULL
84772 +_000775_hash cache_slow_downcall 2 8570 _000775_hash NULL
84773 +_000776_hash caif_seqpkt_sendmsg 4 22961 _000776_hash NULL
84774 +_000777_hash caif_stream_sendmsg 4 9110 _000777_hash NULL
84775 +_000778_hash carl9170_cmd_buf 3 950 _000778_hash NULL
84776 +_000779_hash cdev_add 2-3 38176 _000779_hash NULL
84777 +_000781_hash cdrom_read_cdda 4 50478 _000781_hash NULL
84778 +_000782_hash ceph_dns_resolve_name 2 62488 _000782_hash NULL
84779 +_000783_hash ceph_msgpool_get 2 54258 _000783_hash NULL
84780 +_000784_hash cfg80211_connect_result 4-6 56515 _000784_hash NULL
84781 +_000786_hash cfg80211_disconnected 4 57 _000786_hash NULL
84782 +_000787_hash cfg80211_inform_bss 8 19332 _000787_hash NULL
84783 +_000788_hash cfg80211_inform_bss_frame 4 41078 _000788_hash NULL
84784 +_000789_hash cfg80211_mlme_register_mgmt 5 19852 _000789_hash NULL
84785 +_000790_hash cfg80211_roamed_bss 4-6 50198 _000790_hash NULL
84786 +_000792_hash cgroup_file_write 3 52417 _000792_hash NULL
84787 +_000793_hash cifs_readdata_alloc 1 26360 _000793_hash NULL
84788 +_000794_hash cifs_readv_from_socket 3 19109 _000794_hash NULL
84789 +_000795_hash cifs_writedata_alloc 1 32880 _003097_hash NULL nohasharray
84790 +_000796_hash cnic_alloc_dma 3 34641 _000796_hash NULL
84791 +_000797_hash cnic_init_id_tbl 2 41354 _000797_hash NULL
84792 +_000798_hash configfs_write_file 3 61621 _000798_hash NULL
84793 +_000799_hash construct_key 3 11329 _000799_hash NULL
84794 +_000800_hash context_alloc 3 24645 _000800_hash NULL
84795 +_000801_hash copy_to_user 3 57835 _000801_hash NULL
84796 +_000802_hash cp210x_get_config 4 56229 _000802_hash NULL
84797 +_000803_hash create_attr_set 1 22861 _000803_hash NULL
84798 +_000804_hash create_bounce_buffer 3 39155 _000804_hash NULL
84799 +_000805_hash create_gpadl_header 2 19064 _000805_hash NULL
84800 +_000806_hash _create_sg_bios 4 31244 _000806_hash NULL
84801 +_000807_hash cryptd_alloc_instance 2-3 18048 _000807_hash NULL
84802 +_000809_hash crypto_ahash_setkey 3 55134 _000809_hash NULL
84803 +_000810_hash crypto_alloc_instance2 3 25277 _000810_hash NULL
84804 +_000811_hash crypto_shash_setkey 3 60483 _000811_hash NULL
84805 +_000812_hash cxgb_alloc_mem 1 24007 _000812_hash NULL
84806 +_000813_hash cxgbi_device_portmap_create 3 25747 _000813_hash NULL
84807 +_000814_hash cxgbi_device_register 1-2 36746 _000814_hash NULL
84808 +_000816_hash __cxio_init_resource_fifo 3 23447 _000816_hash NULL
84809 +_000817_hash dccp_sendmsg 4 56058 _000817_hash NULL
84810 +_000818_hash ddp_make_gl 1 12179 _000818_hash NULL
84811 +_000819_hash depth_write 3 3021 _000819_hash NULL
84812 +_000820_hash dev_irnet_write 3 11398 _000820_hash NULL
84813 +_000821_hash dev_set_alias 3 50084 _000821_hash NULL
84814 +_000822_hash dev_write 3 7708 _000822_hash NULL
84815 +_000823_hash dfs_global_file_write 3 6112 _000823_hash NULL
84816 +_000824_hash dgram_sendmsg 4 45679 _000824_hash NULL
84817 +_000825_hash disconnect 4 32521 _000825_hash NULL
84818 +_000826_hash dma_attach 6-7 50831 _000826_hash NULL
84819 +_000828_hash dma_declare_coherent_memory 4-2 14244 _000828_hash NULL
84820 +_000829_hash dn_sendmsg 4 38390 _000829_hash NULL
84821 +_000830_hash dn_setsockopt 5 314 _000830_hash NULL
84822 +_000831_hash do_arpt_set_ctl 4 51053 _000831_hash NULL
84823 +_000832_hash do_dccp_setsockopt 5 54377 _003195_hash NULL nohasharray
84824 +_000833_hash do_ip6t_set_ctl 4 60040 _000833_hash NULL
84825 +_000834_hash do_ipt_set_ctl 4 56238 _000834_hash NULL
84826 +_000835_hash do_jffs2_setxattr 5 25910 _000835_hash NULL
84827 +_000836_hash do_msgsnd 4 1387 _000836_hash NULL
84828 +_000837_hash do_pselect 1 62061 _000837_hash NULL
84829 +_000838_hash do_raw_setsockopt 5 55215 _000838_hash NULL
84830 +_000839_hash do_readv_writev 4 51849 _000839_hash NULL
84831 +_000840_hash do_sync 1 9604 _000840_hash NULL
84832 +_000841_hash dup_array 3 33551 _000841_hash NULL
84833 +_000842_hash ecryptfs_decode_and_decrypt_filename 5 10379 _000842_hash NULL
84834 +_000843_hash ecryptfs_encrypt_and_encode_filename 6 2109 _000843_hash NULL
84835 +_000844_hash ecryptfs_send_message_locked 2 31801 _000844_hash NULL
84836 +_000845_hash edac_device_alloc_ctl_info 1 5941 _000845_hash NULL
84837 +_000846_hash edac_mc_alloc 4 3611 _000846_hash NULL
84838 +_000847_hash edac_pci_alloc_ctl_info 1 63388 _000847_hash NULL
84839 +_000848_hash efivar_create_sysfs_entry 2 19485 _000848_hash NULL
84840 +_000849_hash enable_write 3 30456 _000849_hash NULL
84841 +_000850_hash enclosure_register 3 57412 _000850_hash NULL
84842 +_000851_hash enlarge_skb 2 44248 _002839_hash NULL nohasharray
84843 +_000852_hash evdev_ioctl_handler 2 21705 _000852_hash NULL
84844 +_000853_hash ext4_kvzalloc 1 47605 _000853_hash NULL
84845 +_000854_hash extend_netdev_table 2 21453 _000854_hash NULL
84846 +_000855_hash fcoe_ctlr_device_add 3 1793 _000855_hash NULL
84847 +_000856_hash fd_do_readv 3 51297 _000856_hash NULL
84848 +_000857_hash fd_do_writev 3 29329 _000857_hash NULL
84849 +_000858_hash __feat_register_sp 6 64712 _000858_hash NULL
84850 +_000859_hash __ffs_ep0_read_events 3 48868 _000859_hash NULL
84851 +_000860_hash ffs_ep0_write 3 9438 _000860_hash NULL
84852 +_000861_hash ffs_epfile_read 3 18775 _000861_hash NULL
84853 +_000862_hash ffs_epfile_write 3 48014 _000862_hash NULL
84854 +_000863_hash fib_info_hash_alloc 1 9075 _000863_hash NULL
84855 +_000864_hash fillonedir 3 41746 _000864_hash NULL
84856 +_000865_hash fs_devrw_entry 3 11924 _000865_hash NULL
84857 +_000866_hash fs_path_prepare_for_add 2 61854 _000866_hash NULL
84858 +_000867_hash fuse_fill_write_pages 4 53682 _000867_hash NULL
84859 +_000868_hash fw_device_op_ioctl 2 11595 _000868_hash NULL
84860 +_000869_hash fw_iso_buffer_init 3 54582 _000869_hash NULL
84861 +_000870_hash fw_node_create 2 9559 _000870_hash NULL
84862 +_000871_hash garmin_read_process 3 27509 _000871_hash NULL
84863 +_000872_hash garp_request_join 4 7471 _000872_hash NULL
84864 +_000873_hash generic_perform_write 3 54832 _000873_hash NULL
84865 +_000874_hash gen_pool_add_virt 4 39913 _000874_hash NULL
84866 +_000875_hash get_derived_key 4 61100 _000875_hash NULL
84867 +_000876_hash get_new_cssid 2 51665 _000876_hash NULL
84868 +_000877_hash getxattr 4 24398 _003758_hash NULL nohasharray
84869 +_000878_hash gsm_control_reply 4 53333 _000878_hash NULL
84870 +_000879_hash hcd_alloc_coherent 5 55862 _000879_hash NULL
84871 +_000880_hash hci_sock_sendmsg 4 37420 _000880_hash NULL
84872 +_000881_hash hidraw_ioctl 2 63658 _000881_hash NULL
84873 +_000882_hash hidraw_write 3 31536 _000882_hash NULL
84874 +_000883_hash hid_register_field 2-3 4874 _000883_hash NULL
84875 +_000885_hash hid_report_raw_event 4 2762 _000885_hash NULL
84876 +_000886_hash hpi_alloc_control_cache 1 35351 _000886_hash NULL
84877 +_000887_hash hugetlbfs_read_actor 2-5-4 34547 _000887_hash NULL
84878 +_000890_hash hvc_alloc 4 12579 _000890_hash NULL
84879 +_000891_hash __hwahc_dev_set_key 5 46328 _000891_hash NULL
84880 +_000892_hash i2400m_zrealloc_2x 3 54166 _001549_hash NULL nohasharray
84881 +_000893_hash ib_alloc_device 1 26483 _000893_hash NULL
84882 +_000894_hash ib_create_send_mad 5 1196 _000894_hash NULL
84883 +_000895_hash ibmasm_new_command 2 25714 _000895_hash NULL
84884 +_000896_hash ib_send_cm_drep 3 50186 _000896_hash NULL
84885 +_000897_hash ib_send_cm_mra 4 60202 _003063_hash NULL nohasharray
84886 +_000898_hash ib_send_cm_rtu 3 63138 _000898_hash NULL
84887 +_000899_hash ide_core_cp_entry 3 22636 _000899_hash NULL
84888 +_000900_hash ieee80211_if_write_smps 3 35550 _000900_hash NULL
84889 +_000901_hash ieee80211_if_write_tkip_mic_test 3 58748 _000901_hash NULL
84890 +_000902_hash ieee80211_if_write_tsf 3 36077 _000902_hash NULL
84891 +_000903_hash ieee80211_if_write_uapsd_max_sp_len 3 14233 _000903_hash NULL
84892 +_000904_hash ieee80211_if_write_uapsd_queues 3 51526 _000904_hash NULL
84893 +_000905_hash ieee80211_key_alloc 3 19065 _000905_hash NULL
84894 +_000906_hash ieee80211_send_probe_req 6-4 6924 _000906_hash NULL
84895 +_000907_hash ieee80211_skb_resize 3 50211 _000907_hash NULL
84896 +_000908_hash if_spi_host_to_card 4 62890 _000908_hash NULL
84897 +_000909_hash if_writecmd 2 815 _000909_hash NULL
84898 +_000910_hash init_bch 1-2 64130 _000910_hash NULL
84899 +_000912_hash init_ipath 1 48187 _000912_hash NULL
84900 +_000913_hash init_list_set 2-3 39188 _000913_hash NULL
84901 +_000915_hash init_q 4 132 _000915_hash NULL
84902 +_000916_hash init_state 2 60165 _000916_hash NULL
84903 +_000917_hash init_tag_map 3 57515 _000917_hash NULL
84904 +_000918_hash input_ff_create 2 21240 _000918_hash NULL
84905 +_000919_hash input_mt_init_slots 2 31183 _000919_hash NULL
84906 +_000920_hash interfaces 2 38859 _000920_hash NULL
84907 +_000921_hash int_hardware_entry 3 36833 _000921_hash NULL
84908 +_000922_hash int_hw_irq_en 3 46776 _000922_hash NULL
84909 +_000923_hash int_tasklet_entry 3 52500 _000923_hash NULL
84910 +_000924_hash ioat2_alloc_ring 2 11172 _000924_hash NULL
84911 +_000925_hash ip_generic_getfrag 3-4 12187 _000925_hash NULL
84912 +_000927_hash ip_options_get_alloc 1 7448 _000927_hash NULL
84913 +_000928_hash ipr_alloc_ucode_buffer 1 40199 _000928_hash NULL
84914 +_000929_hash ip_set_alloc 1 57953 _000929_hash NULL
84915 +_000930_hash ip_setsockopt 5 33487 _000930_hash NULL
84916 +_000931_hash ipv6_flowlabel_opt 3 58135 _001179_hash NULL nohasharray
84917 +_000932_hash ipv6_renew_options 5 28867 _000932_hash NULL
84918 +_000933_hash ipv6_setsockopt 5 29871 _000933_hash NULL
84919 +_000934_hash ipxrtr_route_packet 4 54036 _000934_hash NULL
84920 +_000935_hash irda_sendmsg 4 4388 _000935_hash NULL
84921 +_000936_hash irda_sendmsg_dgram 4 38563 _000936_hash NULL
84922 +_000937_hash irda_sendmsg_ultra 4 42047 _000937_hash NULL
84923 +_000938_hash irias_add_octseq_attrib 4 29983 _000938_hash NULL
84924 +_000939_hash irq_alloc_generic_chip 2 26650 _000939_hash NULL
84925 +_000940_hash iscsi_alloc_session 3 49390 _000940_hash NULL
84926 +_000941_hash iscsi_create_conn 2 50425 _000941_hash NULL
84927 +_000942_hash iscsi_create_endpoint 1 15193 _000942_hash NULL
84928 +_000943_hash iscsi_create_iface 5 38510 _000943_hash NULL
84929 +_000944_hash iscsi_decode_text_input 4 58292 _000944_hash NULL
84930 +_000945_hash iscsi_pool_init 2-4 54913 _000945_hash NULL
84931 +_000947_hash iscsit_dump_data_payload 2 38683 _000947_hash NULL
84932 +_000948_hash isdn_write 3 45863 _000948_hash NULL
84933 +_000949_hash isku_receive 4 54130 _000949_hash NULL
84934 +_000950_hash islpci_mgt_transaction 5 23610 _000950_hash NULL
84935 +_000951_hash iso_alloc_urb 4-5 45206 _000951_hash NULL
84936 +_000952_hash iso_sched_alloc 1 13377 _003325_hash NULL nohasharray
84937 +_000953_hash iwl_trans_txq_alloc 3 36147 _000953_hash NULL
84938 +_000954_hash ixgbe_alloc_q_vector 4-6 24439 _000954_hash NULL
84939 +_000956_hash jbd2_journal_init_revoke 2 51088 _000956_hash NULL
84940 +_000957_hash jffs2_write_dirent 5 37311 _000957_hash NULL
84941 +_000958_hash journal_init_revoke 2 56933 _000958_hash NULL
84942 +_000959_hash keyctl_instantiate_key 3 41855 _000959_hash NULL
84943 +_000960_hash keyctl_instantiate_key_iov 3 16969 _000960_hash NULL
84944 +_000961_hash __kfifo_from_user 3 20399 _000961_hash NULL
84945 +_000962_hash kimage_crash_alloc 3 3233 _000962_hash NULL
84946 +_000963_hash kimage_normal_alloc 3 31140 _000963_hash NULL
84947 +_000964_hash kmem_realloc 2 37489 _000964_hash NULL
84948 +_000965_hash kmem_zalloc 1 11510 _000965_hash NULL
84949 +_000966_hash koneplus_sysfs_read 6 42792 _000966_hash NULL
84950 +_000967_hash kvm_kvzalloc 1 52894 _000967_hash NULL
84951 +_000968_hash kvm_read_guest_page_mmu 6 37611 _000968_hash NULL
84952 +_000969_hash kvm_set_irq_routing 3 48704 _000969_hash NULL
84953 +_000970_hash kvm_write_guest_cached 4 11106 _000970_hash NULL
84954 +_000971_hash kvm_write_guest_page 5 63555 _002812_hash NULL nohasharray
84955 +_000972_hash kzalloc_node 1 24352 _000972_hash NULL
84956 +_000973_hash l2cap_skbuff_fromiovec 3-4 35003 _000973_hash NULL
84957 +_000975_hash l2tp_ip_sendmsg 4 50411 _000975_hash NULL
84958 +_000976_hash l2tp_session_create 1 25286 _000976_hash NULL
84959 +_000977_hash lc_create 3 48662 _000977_hash NULL
84960 +_000978_hash leaf_dealloc 3 29566 _000978_hash NULL
84961 +_000979_hash linear_conf 2 23485 _003837_hash NULL nohasharray
84962 +_000980_hash llc_ui_sendmsg 4 24987 _000980_hash NULL
84963 +_000981_hash load_module 2 60056 _003010_hash NULL nohasharray
84964 +_000982_hash lpfc_sli4_queue_alloc 3 62646 _000982_hash NULL
84965 +_000983_hash mdiobus_alloc_size 1 52259 _000983_hash NULL
84966 +_000984_hash mempool_create_node 1 3191 _000984_hash NULL
84967 +_000985_hash mem_read 3 57631 _000985_hash NULL
84968 +_000986_hash memstick_alloc_host 1 142 _000986_hash NULL
84969 +_000987_hash mem_swapout_entry 3 32586 _000987_hash NULL
84970 +_000988_hash mem_write 3 22232 _000988_hash NULL
84971 +_000989_hash mesh_table_alloc 1 22305 _000989_hash NULL
84972 +_000990_hash mfd_add_devices 4 16668 _000990_hash NULL
84973 +_000991_hash mISDN_sock_sendmsg 4 41035 _000991_hash NULL
84974 +_000992_hash mlx4_init_icm_table 4-5 2151 _000992_hash NULL
84975 +_000994_hash mmc_alloc_host 1 48097 _000994_hash NULL
84976 +_000995_hash mmc_test_alloc_mem 2-3 28102 _000995_hash NULL
84977 +_000997_hash mon_bin_ioctl 3 2771 _000997_hash NULL
84978 +_000998_hash mpi_alloc 1 18094 _000998_hash NULL
84979 +_000999_hash mpihelp_mul_karatsuba_case 5-3 23918 _003061_hash NULL nohasharray
84980 +_001000_hash __mptctl_ioctl 2 15875 _001000_hash NULL
84981 +_001001_hash mtd_concat_create 2 14416 _001001_hash NULL
84982 +_001002_hash mthca_alloc_cq_buf 3 46512 _001002_hash NULL
84983 +_001003_hash mvumi_alloc_mem_resource 3 47750 _001003_hash NULL
84984 +_001004_hash mwifiex_11n_create_rx_reorder_tbl 4 63806 _001004_hash NULL
84985 +_001005_hash mwifiex_alloc_sdio_mpa_buffers 2-3 60961 _001005_hash NULL
84986 +_001007_hash mwl8k_cmd_set_beacon 4 23110 _001007_hash NULL
84987 +_001008_hash neigh_hash_alloc 1 17595 _001008_hash NULL
84988 +_001009_hash __netdev_alloc_skb 2 18595 _001009_hash NULL
84989 +_001010_hash __netlink_change_ngroups 2 46156 _001010_hash NULL
84990 +_001011_hash netlink_sendmsg 4 33708 _001236_hash NULL nohasharray
84991 +_001012_hash netxen_alloc_sds_rings 2 13417 _001012_hash NULL
84992 +_001013_hash new_bind_ctl 2 35324 _001013_hash NULL
84993 +_001014_hash new_dir 3 31919 _001014_hash NULL
84994 +_001015_hash new_tape_buffer 2 32866 _001015_hash NULL
84995 +_001016_hash nfc_llcp_build_tlv 3 19536 _001016_hash NULL
84996 +_001017_hash nfc_llcp_send_i_frame 3 59130 _001017_hash NULL
84997 +_001018_hash nf_ct_ext_create 3 51232 _001018_hash NULL
84998 +_001019_hash nfs4_alloc_pages 1 48426 _001019_hash NULL
84999 +_001020_hash nfs4_alloc_slots 1 2454 _003345_hash NULL nohasharray
85000 +_001021_hash nfsctl_transaction_write 3 64800 _001021_hash NULL
85001 +_001022_hash nfs_fscache_get_super_cookie 3 44355 _001850_hash NULL nohasharray
85002 +_001023_hash nfs_idmap_request_key 3 30208 _001023_hash NULL
85003 +_001024_hash nfs_pgarray_set 2 1085 _001024_hash NULL
85004 +_001025_hash nl_pid_hash_zalloc 1 23314 _001025_hash NULL
85005 +_001026_hash nr_sendmsg 4 53656 _001026_hash NULL
85006 +_001027_hash nsm_create_handle 4 38060 _001027_hash NULL
85007 +_001028_hash ntfs_copy_from_user_iovec 3-6 49829 _001028_hash NULL
85008 +_001030_hash ntfs_file_buffered_write 4-6 41442 _001030_hash NULL
85009 +_001032_hash __ntfs_malloc 1 34022 _001032_hash NULL
85010 +_001033_hash nvme_alloc_queue 3 46865 _001033_hash NULL
85011 +_001034_hash nvme_map_user_pages 3-4 41093 _001639_hash NULL nohasharray
85012 +_001036_hash ocfs2_acl_from_xattr 2 21604 _001036_hash NULL
85013 +_001037_hash ocfs2_control_message 3 19564 _001037_hash NULL
85014 +_001038_hash _ore_get_io_state 3-5-4 2166 _001038_hash NULL
85015 +_001041_hash orinoco_set_key 5-7 17878 _001041_hash NULL
85016 +_001043_hash osdmap_set_max_osd 2 57630 _002267_hash NULL nohasharray
85017 +_001044_hash _osd_realloc_seg 3 54352 _001044_hash NULL
85018 +_001045_hash osst_execute 7-6 17607 _001045_hash NULL
85019 +_001046_hash osst_write 3 31581 _001046_hash NULL
85020 +_001047_hash otp_read 2-5-4 10594 _001047_hash NULL
85021 +_001050_hash ovs_vport_alloc 1 33475 _001050_hash NULL
85022 +_001051_hash p54_parse_rssical 3 64493 _001051_hash NULL
85023 +_001052_hash p9_client_zc_rpc 7 14345 _001052_hash NULL
85024 +_001053_hash packet_sendmsg_spkt 4 28885 _001053_hash NULL
85025 +_001054_hash pair_device 4 61175 _003161_hash NULL nohasharray
85026 +_001055_hash pccard_store_cis 6 18176 _001055_hash NULL
85027 +_001056_hash pci_add_cap_save_buffer 3 3426 _001056_hash NULL
85028 +_001057_hash pcnet32_realloc_rx_ring 3 36598 _001057_hash NULL
85029 +_001058_hash pcnet32_realloc_tx_ring 3 38428 _001058_hash NULL
85030 +_001059_hash pcpu_mem_zalloc 1 22948 _001059_hash NULL
85031 +_001060_hash pep_sendmsg 4 62524 _001060_hash NULL
85032 +_001061_hash pfkey_sendmsg 4 47394 _001061_hash NULL
85033 +_001062_hash pidlist_resize 2 496 _001062_hash NULL
85034 +_001063_hash pin_code_reply 4 46510 _001063_hash NULL
85035 +_001064_hash ping_getfrag 3-4 8360 _001064_hash NULL
85036 +_001066_hash pipe_set_size 2 5204 _001066_hash NULL
85037 +_001067_hash pkt_bio_alloc 1 48284 _001067_hash NULL
85038 +_001068_hash platform_create_bundle 4-6 12785 _001068_hash NULL
85039 +_001070_hash pm8001_store_update_fw 4 55716 _001070_hash NULL
85040 +_001071_hash pmcraid_alloc_sglist 1 9864 _001071_hash NULL
85041 +_001072_hash pn533_dep_link_up 5 22154 _001072_hash NULL
85042 +_001073_hash pn533_init_target_frame 3 65438 _001073_hash NULL
85043 +_001074_hash pnp_alloc 1 24869 _001538_hash NULL nohasharray
85044 +_001075_hash pn_sendmsg 4 12640 _001075_hash NULL
85045 +_001076_hash pppoe_sendmsg 4 48039 _001076_hash NULL
85046 +_001077_hash pppol2tp_sendmsg 4 56420 _001077_hash NULL
85047 +_001078_hash prism2_info_hostscanresults 3 39657 _001078_hash NULL
85048 +_001079_hash process_vm_rw 3-5 47533 _001079_hash NULL
85049 +_001081_hash process_vm_rw_single_vec 1-2 26213 _001081_hash NULL
85050 +_001083_hash proc_write 3 51003 _001083_hash NULL
85051 +_001084_hash profile_load 3 58267 _001084_hash NULL
85052 +_001085_hash profile_remove 3 8556 _001085_hash NULL
85053 +_001086_hash profile_replace 3 14652 _001086_hash NULL
85054 +_001087_hash pscsi_get_bio 1 56103 _001087_hash NULL
85055 +_001088_hash __pskb_copy 2 9038 _001088_hash NULL
85056 +_001089_hash __pskb_pull_tail 2 60287 _001089_hash NULL
85057 +_001090_hash qla4xxx_alloc_work 2 44813 _001090_hash NULL
85058 +_001091_hash qlcnic_alloc_msix_entries 2 46160 _001091_hash NULL
85059 +_001092_hash qlcnic_alloc_sds_rings 2 26795 _001092_hash NULL
85060 +_001093_hash queue_received_packet 5 9657 _001093_hash NULL
85061 +_001094_hash raw_send_hdrinc 4 58803 _001094_hash NULL
85062 +_001095_hash raw_sendmsg 4 23078 _003316_hash NULL nohasharray
85063 +_001096_hash rawsock_sendmsg 4 60010 _001096_hash NULL
85064 +_001097_hash rawv6_send_hdrinc 3 35425 _001097_hash NULL
85065 +_001098_hash rawv6_setsockopt 5 56165 _001098_hash NULL
85066 +_001099_hash rb_alloc 1 3102 _001099_hash NULL
85067 +_001100_hash rbd_alloc_coll 1 33678 _001100_hash NULL
85068 +_001101_hash rbd_create_rw_ops 1 55297 _001101_hash NULL
85069 +_001102_hash rds_ib_inc_copy_to_user 3 55007 _001102_hash NULL
85070 +_001103_hash rds_iw_inc_copy_to_user 3 29214 _001103_hash NULL
85071 +_001104_hash rds_message_alloc 1 10517 _001104_hash NULL
85072 +_001105_hash rds_message_copy_from_user 3 45510 _001105_hash NULL
85073 +_001106_hash rds_message_inc_copy_to_user 3 26540 _001106_hash NULL
85074 +_001107_hash regcache_rbtree_insert_to_block 5 58009 _001107_hash NULL
85075 +_001108_hash _regmap_raw_write 4 42652 _001108_hash NULL
85076 +_001109_hash regmap_register_patch 3 21681 _001109_hash NULL
85077 +_001110_hash relay_alloc_page_array 1 52735 _001110_hash NULL
85078 +_001111_hash remove_uuid 4 64505 _001111_hash NULL
85079 +_001112_hash reshape_ring 2 29147 _001112_hash NULL
85080 +_001113_hash RESIZE_IF_NEEDED 2 56286 _001113_hash NULL
85081 +_001114_hash resize_info_buffer 2 62889 _001114_hash NULL
85082 +_001115_hash resize_stripes 2 61650 _001115_hash NULL
85083 +_001116_hash rfcomm_sock_sendmsg 4 37661 _003661_hash NULL nohasharray
85084 +_001117_hash roccat_common2_send_with_status 4 50343 _001117_hash NULL
85085 +_001118_hash rose_sendmsg 4 20249 _001118_hash NULL
85086 +_001119_hash rsc_mgr_init 3 16299 _001119_hash NULL
85087 +_001120_hash rxrpc_send_data 5 21553 _001120_hash NULL
85088 +_001121_hash rxrpc_setsockopt 5 50286 _001121_hash NULL
85089 +_001122_hash savu_sysfs_read 6 49473 _001122_hash NULL
85090 +_001124_hash sco_send_frame 3 41815 _001124_hash NULL
85091 +_001125_hash scsi_dispatch_cmd_entry 3 49848 _001125_hash NULL
85092 +_001126_hash scsi_host_alloc 2 63041 _001126_hash NULL
85093 +_001127_hash scsi_tgt_kspace_exec 8 9522 _001127_hash NULL
85094 +_001128_hash sctp_sendmsg 4 61919 _001128_hash NULL
85095 +_001129_hash sctp_setsockopt 5 44788 _001129_hash NULL
85096 +_001130_hash sctp_setsockopt_connectx 3 6073 _001130_hash NULL
85097 +_001131_hash sctp_setsockopt_connectx_old 3 22631 _001131_hash NULL
85098 +_001132_hash sctp_tsnmap_grow 2 32784 _001132_hash NULL
85099 +_001133_hash sctp_tsnmap_init 2 36446 _001133_hash NULL
85100 +_001134_hash sctp_user_addto_chunk 2-3 62047 _001134_hash NULL
85101 +_001136_hash security_context_to_sid 2 19839 _001136_hash NULL
85102 +_001137_hash security_context_to_sid_default 2 3492 _003841_hash NULL nohasharray
85103 +_001138_hash security_context_to_sid_force 2 20724 _001138_hash NULL
85104 +_001139_hash self_check_write 5 50856 _001139_hash NULL
85105 +_001140_hash selinux_transaction_write 3 59038 _001140_hash NULL
85106 +_001141_hash sel_write_access 3 51704 _001141_hash NULL
85107 +_001142_hash sel_write_create 3 11353 _001142_hash NULL
85108 +_001143_hash sel_write_member 3 28800 _001143_hash NULL
85109 +_001144_hash sel_write_relabel 3 55195 _001144_hash NULL
85110 +_001145_hash sel_write_user 3 45060 _001145_hash NULL
85111 +_001146_hash __seq_open_private 3 40715 _001146_hash NULL
85112 +_001147_hash serverworks_create_gatt_pages 1 46582 _001147_hash NULL
85113 +_001148_hash set_connectable 4 56458 _001148_hash NULL
85114 +_001149_hash set_dev_class 4 39645 _001921_hash NULL nohasharray
85115 +_001150_hash set_discoverable 4 48141 _001150_hash NULL
85116 +_001151_hash set_fd_set 1 35249 _001151_hash NULL
85117 +_001152_hash setkey 3 14987 _001152_hash NULL
85118 +_001153_hash set_le 4 30581 _001153_hash NULL
85119 +_001154_hash set_link_security 4 4502 _001154_hash NULL
85120 +_001155_hash set_local_name 4 55757 _001155_hash NULL
85121 +_001156_hash set_powered 4 12129 _001156_hash NULL
85122 +_001157_hash set_ssp 4 62411 _001157_hash NULL
85123 +_001158_hash sg_build_sgat 3 60179 _001158_hash &_000314_hash
85124 +_001159_hash sg_read_oxfer 3 51724 _001159_hash NULL
85125 +_001160_hash shmem_xattr_set 4 11843 _001160_hash NULL
85126 +_001161_hash simple_alloc_urb 3 60420 _001161_hash NULL
85127 +_001162_hash sisusb_send_bridge_packet 2 11649 _001162_hash NULL
85128 +_001163_hash sisusb_send_packet 2 20891 _001163_hash NULL
85129 +_001164_hash sisusb_write_mem_bulk 4 29678 _001164_hash NULL
85130 +_001165_hash skb_add_data_nocache 4 4682 _001165_hash NULL
85131 +_001166_hash skb_copy_datagram_from_iovec 2-5-4 52014 _001166_hash NULL
85132 +_001169_hash skb_copy_expand 2-3 7685 _001169_hash &_000677_hash
85133 +_001171_hash skb_copy_to_page_nocache 6 58624 _001171_hash NULL
85134 +_001172_hash __skb_cow 2 39254 _001172_hash NULL
85135 +_001173_hash skb_cow_data 2 11565 _001173_hash NULL
85136 +_001174_hash skb_pad 2 17302 _001174_hash NULL
85137 +_001175_hash skb_realloc_headroom 2 19516 _001175_hash NULL
85138 +_001176_hash sk_chk_filter 2 42095 _001176_hash NULL
85139 +_001177_hash skcipher_sendmsg 4 30290 _001177_hash NULL
85140 +_001178_hash sl_change_mtu 2 7396 _001178_hash NULL
85141 +_001179_hash slhc_init 1-2 58135 _001179_hash &_000931_hash
85142 +_001181_hash sm501_create_subdev 3-4 48668 _001245_hash NULL nohasharray
85143 +_001183_hash smk_user_access 3 24440 _001183_hash NULL
85144 +_001184_hash smk_write_cipso2 3 1021 _001184_hash NULL
85145 +_001185_hash smk_write_cipso 3 17989 _001185_hash NULL
85146 +_001186_hash smk_write_load2 3 52155 _001186_hash NULL
85147 +_001187_hash smk_write_load 3 26829 _001187_hash NULL
85148 +_001188_hash smk_write_load_self2 3 591 _001188_hash NULL
85149 +_001189_hash smk_write_load_self 3 7958 _001189_hash NULL
85150 +_001190_hash snapshot_write 3 28351 _001190_hash NULL
85151 +_001191_hash snd_ac97_pcm_assign 2 30218 _001191_hash NULL
85152 +_001192_hash snd_card_create 4 64418 _001529_hash NULL nohasharray
85153 +_001193_hash snd_emux_create_port 3 42533 _001193_hash NULL
85154 +_001194_hash snd_gus_dram_write 4 38784 _001194_hash NULL
85155 +_001195_hash snd_midi_channel_alloc_set 1 28153 _001195_hash NULL
85156 +_001196_hash _snd_pcm_lib_alloc_vmalloc_buffer 2 17820 _001196_hash NULL
85157 +_001197_hash snd_pcm_oss_sync1 2 45298 _001197_hash NULL
85158 +_001198_hash snd_pcm_oss_write 3 38108 _001198_hash NULL
85159 +_001199_hash snd_pcm_plugin_build 5 25505 _001199_hash NULL
85160 +_001200_hash snd_rawmidi_kernel_write 3 25106 _001200_hash NULL
85161 +_001201_hash snd_rawmidi_write 3 28008 _001201_hash NULL
85162 +_001202_hash snd_rme32_playback_copy 5 43732 _001202_hash NULL
85163 +_001203_hash snd_rme96_playback_copy 5 13111 _001203_hash NULL
85164 +_001204_hash snd_seq_device_new 4 31753 _001204_hash NULL
85165 +_001205_hash snd_seq_oss_readq_new 2 14283 _001205_hash NULL
85166 +_001206_hash snd_vx_create 4 40948 _001206_hash NULL
85167 +_001207_hash sock_setsockopt 5 50088 _001207_hash NULL
85168 +_001208_hash sound_write 3 5102 _001208_hash NULL
85169 +_001209_hash _sp2d_alloc 1-3-2 16944 _001209_hash NULL
85170 +_001212_hash spi_alloc_master 2 45223 _001212_hash NULL
85171 +_001213_hash spidev_message 3 5518 _001213_hash NULL
85172 +_001214_hash spi_register_board_info 2 35651 _001214_hash NULL
85173 +_001215_hash squashfs_cache_init 2 41656 _001215_hash NULL
85174 +_001216_hash squashfs_read_data 6 59440 _001216_hash NULL
85175 +_001217_hash squashfs_read_fragment_index_table 4 2506 _001217_hash NULL
85176 +_001218_hash squashfs_read_id_index_table 4 61961 _001218_hash NULL
85177 +_001219_hash squashfs_read_inode_lookup_table 4 64739 _001219_hash NULL
85178 +_001220_hash srp_alloc_iu 2 44227 _001220_hash NULL
85179 +_001221_hash srp_iu_pool_alloc 2 17920 _001221_hash NULL
85180 +_001222_hash srp_ring_alloc 2 26760 _001222_hash NULL
85181 +_001226_hash start_isoc_chain 2 565 _001226_hash NULL
85182 +_001227_hash st_write 3 16874 _001227_hash NULL
85183 +_001228_hash svc_pool_map_alloc_arrays 2 47181 _001228_hash NULL
85184 +_001229_hash symtab_init 2 61050 _001229_hash NULL
85185 +_001230_hash sys_bind 3 10799 _001230_hash NULL
85186 +_001231_hash sys_connect 3 15291 _003816_hash NULL nohasharray
85187 +_001232_hash sys_flistxattr 3 41407 _001232_hash NULL
85188 +_001233_hash sys_fsetxattr 4 49736 _001233_hash NULL
85189 +_001234_hash sysfs_write_file 3 57116 _001234_hash NULL
85190 +_001235_hash sys_ipc 3 4889 _001235_hash NULL
85191 +_001236_hash sys_keyctl 4 33708 _001236_hash &_001011_hash
85192 +_001237_hash sys_listxattr 3 27833 _001237_hash NULL
85193 +_001238_hash sys_llistxattr 3 4532 _001238_hash NULL
85194 +_001239_hash sys_lsetxattr 4 61177 _001239_hash NULL
85195 +_001240_hash sys_mq_timedsend 3 57661 _001240_hash NULL
85196 +_001241_hash sys_sched_setaffinity 2 32046 _001241_hash NULL
85197 +_001242_hash sys_select 1 38827 _001242_hash NULL
85198 +_001243_hash sys_semop 3 39457 _001243_hash NULL
85199 +_001244_hash sys_sendto 6 20809 _001244_hash NULL
85200 +_001245_hash sys_setgroups 1 48668 _001245_hash &_001181_hash
85201 +_001246_hash sys_setgroups16 1 48882 _001246_hash NULL
85202 +_001247_hash sys_setxattr 4 37880 _001247_hash NULL
85203 +_001248_hash t4_alloc_mem 1 32342 _001248_hash NULL
85204 +_001249_hash tcf_hash_create 4 54360 _001249_hash NULL
85205 +_001250_hash tcp_send_rcvq 3 11316 _001250_hash NULL
85206 +_001251_hash __team_options_register 3 63941 _001251_hash NULL
85207 +_001252_hash test_unaligned_bulk 3 52333 _001252_hash NULL
85208 +_001253_hash tifm_alloc_adapter 1 10903 _001253_hash NULL
85209 +_001254_hash timeout_write 3 50991 _001254_hash NULL
85210 +_001255_hash timeradd_entry 3 49850 _001255_hash NULL
85211 +_001256_hash tipc_link_send_sections_fast 4 37920 _001256_hash NULL
85212 +_001257_hash tipc_subseq_alloc 1 5957 _001257_hash NULL
85213 +_001258_hash tnode_alloc 1 49407 _001258_hash NULL
85214 +_001259_hash tomoyo_commit_ok 2 20167 _001259_hash NULL
85215 +_001260_hash tomoyo_scan_bprm 2-4 15642 _003488_hash NULL nohasharray
85216 +_001262_hash tps6586x_writes 3 58689 _001262_hash NULL
85217 +_001263_hash tty_buffer_find 2 2443 _001263_hash NULL
85218 +_001264_hash tty_write 3 5494 _001264_hash NULL
85219 +_001265_hash ubifs_setxattr 4 59650 _001477_hash NULL nohasharray
85220 +_001266_hash ubi_self_check_all_ff 4 41959 _001266_hash NULL
85221 +_001267_hash udf_sb_alloc_partition_maps 2 62313 _001267_hash NULL
85222 +_001268_hash udplite_getfrag 3-4 14479 _001268_hash NULL
85223 +_001270_hash ulong_write_file 3 26485 _001270_hash NULL
85224 +_001271_hash unix_stream_sendmsg 4 61455 _001271_hash NULL
85225 +_001272_hash unlink_queued 3-4 645 _001272_hash NULL
85226 +_001273_hash update_pmkid 4 2481 _001273_hash NULL
85227 +_001274_hash usb_alloc_coherent 2 65444 _001274_hash NULL
85228 +_001275_hash vc_resize 2-3 3585 _001275_hash NULL
85229 +_001277_hash vhci_write 3 2224 _001277_hash NULL
85230 +_001278_hash __vhost_add_used_n 3 26554 _001278_hash NULL
85231 +_001279_hash virtqueue_add_buf 3-4 59470 _001279_hash NULL
85232 +_001281_hash vmalloc 1 15464 _001281_hash NULL
85233 +_001282_hash vol_cdev_write 3 40915 _001282_hash NULL
85234 +_001283_hash vxge_device_register 4 7752 _001283_hash NULL
85235 +_001284_hash __vxge_hw_blockpool_malloc 2 5786 _001284_hash NULL
85236 +_001285_hash __vxge_hw_channel_allocate 3 55462 _001285_hash NULL
85237 +_001286_hash vzalloc 1 47421 _001286_hash NULL
85238 +_001287_hash vzalloc_node 1 23424 _001287_hash NULL
85239 +_001288_hash wa_nep_queue 2 8858 _001288_hash NULL
85240 +_001289_hash __wa_xfer_setup_segs 2 56725 _001289_hash NULL
85241 +_001290_hash wiphy_new 2 2482 _001290_hash NULL
85242 +_001291_hash wm8350_block_write 3 19727 _001291_hash NULL
85243 +_001292_hash wpan_phy_alloc 1 48056 _001292_hash NULL
85244 +_001293_hash write_flush_pipefs 3 2021 _001293_hash NULL
85245 +_001294_hash write_flush_procfs 3 44011 _001294_hash NULL
85246 +_001295_hash wusb_ccm_mac 7 32199 _001295_hash NULL
85247 +_001296_hash x25_sendmsg 4 12487 _001296_hash NULL
85248 +_001297_hash xfrm_hash_alloc 1 10997 _001297_hash NULL
85249 +_001298_hash _xfs_buf_get_pages 2 46811 _001298_hash NULL
85250 +_001299_hash xfs_da_grow_inode_int 3 21785 _001299_hash NULL
85251 +_001300_hash xfs_dir_cilookup_result 3 64288 _003160_hash NULL nohasharray
85252 +_001301_hash xfs_idata_realloc 2 26199 _001301_hash NULL
85253 +_001302_hash xfs_iext_add_indirect_multi 3 32400 _001302_hash NULL
85254 +_001303_hash xfs_iext_inline_to_direct 2 12384 _001303_hash NULL
85255 +_001304_hash xfs_iformat_local 4 49472 _001304_hash NULL
85256 +_001305_hash xfs_iroot_realloc 2 46826 _001305_hash NULL
85257 +_001306_hash xhci_alloc_stream_info 3 63902 _001306_hash NULL
85258 +_001307_hash xlog_recover_add_to_trans 4 62839 _001307_hash NULL
85259 +_001308_hash xprt_alloc 2 1475 _001308_hash NULL
85260 +_001309_hash xt_alloc_table_info 1 57903 _001309_hash NULL
85261 +_001310_hash _zd_iowrite32v_async_locked 3 39034 _001310_hash NULL
85262 +_001311_hash zd_usb_iowrite16v 3 49744 _001311_hash NULL
85263 +_001312_hash a2mp_send 4 41615 _001312_hash NULL
85264 +_001313_hash acpi_ds_build_internal_package_obj 3 58271 _001313_hash NULL
85265 +_001314_hash acpi_system_read_event 3 55362 _001314_hash NULL
85266 +_001315_hash acpi_ut_create_buffer_object 1 42030 _001315_hash NULL
85267 +_001316_hash acpi_ut_create_package_object 1 17594 _001316_hash NULL
85268 +_001317_hash acpi_ut_create_string_object 1 15360 _001317_hash NULL
85269 +_001318_hash ad7879_spi_multi_read 3 8218 _001318_hash NULL
85270 +_001319_hash add_child 4 45201 _001319_hash NULL
85271 +_001320_hash add_port 2 54941 _001320_hash NULL
85272 +_001321_hash adu_read 3 24177 _001321_hash NULL
85273 +_001322_hash afs_cell_create 2 27346 _001322_hash NULL
85274 +_001323_hash agp_allocate_memory 2 58761 _001323_hash NULL
85275 +_001324_hash agp_generic_alloc_user 1 9470 _001324_hash NULL
85276 +_001325_hash alc_auto_create_extra_outs 2 18975 _001325_hash NULL
85277 +_001326_hash alloc_agpphysmem_i8xx 1 39427 _001326_hash NULL
85278 +_001327_hash allocate_cnodes 1 5329 _001327_hash NULL
85279 +_001328_hash ___alloc_bootmem 1 11410 _001328_hash NULL
85280 +_001329_hash __alloc_bootmem_low_node 2 25726 _001662_hash NULL nohasharray
85281 +_001330_hash __alloc_bootmem_node 2 1992 _001330_hash NULL
85282 +_001331_hash __alloc_bootmem_node_nopanic 2 6432 _001331_hash NULL
85283 +_001332_hash __alloc_bootmem_nopanic 1 65397 _001332_hash NULL
85284 +_001333_hash alloc_candev 1-2 7776 _001333_hash NULL
85285 +_001335_hash _alloc_cdb_cont 2 23609 _001335_hash NULL
85286 +_001336_hash alloc_dummy_extent_buffer 2 56374 _001336_hash NULL
85287 +_001337_hash ____alloc_ei_netdev 1 51475 _001337_hash NULL
85288 +_001338_hash alloc_etherdev_mqs 1 36450 _001338_hash NULL
85289 +_001339_hash alloc_extent_buffer 3 52824 _001339_hash NULL
85290 +_001340_hash alloc_fcdev 1 18780 _001340_hash NULL
85291 +_001341_hash alloc_fddidev 1 15382 _001341_hash NULL
85292 +_001342_hash _alloc_get_attr_desc 2 470 _001342_hash NULL
85293 +_001343_hash alloc_hippi_dev 1 51320 _001343_hash NULL
85294 +_001344_hash alloc_irdadev 1 19140 _001344_hash NULL
85295 +_001345_hash alloc_ldt 2 21972 _001345_hash NULL
85296 +_001346_hash alloc_ltalkdev 1 38071 _001346_hash NULL
85297 +_001347_hash alloc_one_pg_vec_page 1 10747 _001347_hash NULL
85298 +_001348_hash alloc_orinocodev 1 21371 _001348_hash NULL
85299 +_001349_hash alloc_ring 2-4 18278 _001349_hash NULL
85300 +_001351_hash _alloc_set_attr_list 4 48991 _001351_hash NULL
85301 +_001353_hash alloc_tx 2 32143 _001353_hash NULL
85302 +_001354_hash alloc_wr 1-2 24635 _001354_hash NULL
85303 +_001356_hash async_setkey 3 35521 _001356_hash NULL
85304 +_001357_hash ata_host_alloc_pinfo 3 17325 _001357_hash NULL
85305 +_001360_hash ath6kl_connect_event 7-9-8 14267 _001360_hash NULL
85306 +_001361_hash ath6kl_fwlog_block_read 3 49836 _001361_hash NULL
85307 +_001362_hash ath6kl_fwlog_read 3 32101 _001362_hash NULL
85308 +_001363_hash ath9k_wmi_cmd 4 327 _001363_hash NULL
85309 +_001364_hash ath_rx_init 2 43564 _001364_hash NULL
85310 +_001365_hash ath_tx_init 2 60515 _001365_hash NULL
85311 +_001366_hash atm_alloc_charge 2 19517 _001914_hash NULL nohasharray
85312 +_001367_hash atm_get_addr 3 31221 _001367_hash NULL
85313 +_001368_hash audit_log_n_hex 3 45617 _001368_hash NULL
85314 +_001369_hash audit_log_n_string 3 31705 _001369_hash NULL
85315 +_001370_hash ax25_output 2 22736 _001370_hash NULL
85316 +_001371_hash bcsp_prepare_pkt 3 12961 _001371_hash NULL
85317 +_001372_hash bdx_rxdb_create 1 46525 _001372_hash NULL
85318 +_001373_hash bdx_tx_db_init 2 41719 _001373_hash NULL
85319 +_001374_hash bio_map_kern 3 64751 _001374_hash NULL
85320 +_001375_hash bits_to_user 2-3 47733 _001375_hash NULL
85321 +_001377_hash __blk_queue_init_tags 2 9778 _001377_hash NULL
85322 +_001378_hash blk_queue_resize_tags 2 28670 _001378_hash NULL
85323 +_001379_hash blk_rq_map_user_iov 5 16772 _001379_hash NULL
85324 +_001380_hash bm_init 2 13529 _001380_hash NULL
85325 +_001381_hash brcmf_alloc_wdev 1 60347 _001381_hash NULL
85326 +_001382_hash __btrfs_buffered_write 3 35311 _002735_hash NULL nohasharray
85327 +_001383_hash btrfs_insert_dir_item 4 59304 _001383_hash NULL
85328 +_001384_hash btrfs_map_block 3 64379 _001384_hash NULL
85329 +_001385_hash bt_skb_alloc 1 6404 _001385_hash NULL
85330 +_001386_hash c4_add_card 3 54968 _001386_hash NULL
85331 +_001387_hash cache_read 3 24790 _001387_hash NULL
85332 +_001388_hash cache_write 3 13589 _001388_hash NULL
85333 +_001389_hash calc_hmac 3 32010 _001389_hash NULL
85334 +_001390_hash capinc_tty_write 3 28539 _001390_hash NULL
85335 +_001391_hash ccid_getsockopt_builtin_ccids 2 53634 _001391_hash NULL
85336 +_001392_hash ceph_copy_page_vector_to_user 3-4 31270 _001392_hash NULL
85337 +_001394_hash ceph_parse_server_name 2 60318 _001394_hash NULL
85338 +_001395_hash ceph_read_dir 3 17005 _001395_hash NULL
85339 +_001396_hash cfg80211_roamed 5-7 32632 _001396_hash NULL
85340 +_001398_hash cfpkt_add_body 3 44630 _001398_hash NULL
85341 +_001399_hash cfpkt_create_pfx 1-2 23594 _001399_hash NULL
85342 +_001401_hash cmd_complete 6 51629 _001401_hash NULL
85343 +_001402_hash cmtp_add_msgpart 4 9252 _001402_hash NULL
85344 +_001403_hash cmtp_send_interopmsg 7 376 _001403_hash NULL
85345 +_001404_hash coda_psdev_read 3 35029 _001404_hash NULL
85346 +_001405_hash construct_key_and_link 4 8321 _001405_hash NULL
85347 +_001406_hash copy_counters_to_user 5 17027 _001406_hash NULL
85348 +_001407_hash copy_entries_to_user 1 52367 _001407_hash NULL
85349 +_001408_hash copy_from_buf 2-4 27308 _001408_hash NULL
85350 +_001410_hash copy_oldmem_page 3-1 26164 _001410_hash NULL
85351 +_001411_hash copy_to_user_fromio 3 57432 _001411_hash NULL
85352 +_001412_hash cryptd_hash_setkey 3 42781 _001412_hash NULL
85353 +_001413_hash crypto_authenc_esn_setkey 3 6985 _001413_hash NULL
85354 +_001414_hash crypto_authenc_setkey 3 80 _001414_hash NULL
85355 +_001415_hash cxgb3_get_cpl_reply_skb 2 10620 _001415_hash NULL
85356 +_001416_hash cxgbi_ddp_reserve 4 30091 _001416_hash NULL
85357 +_001417_hash cxio_init_resource_fifo 3 28764 _001417_hash NULL
85358 +_001418_hash cxio_init_resource_fifo_random 3 47151 _001418_hash NULL
85359 +_001419_hash datablob_hmac_append 3 40038 _001419_hash NULL
85360 +_001420_hash datablob_hmac_verify 4 24786 _001420_hash NULL
85361 +_001421_hash dataflash_read_fact_otp 3-2 33204 _001421_hash NULL
85362 +_001422_hash dataflash_read_user_otp 3-2 14536 _001422_hash &_000207_hash
85363 +_001423_hash dccp_feat_register_sp 5 17914 _001423_hash NULL
85364 +_001424_hash dccp_setsockopt 5 60367 _001424_hash NULL
85365 +_001425_hash __dev_alloc_skb 1 28681 _001425_hash NULL
85366 +_001426_hash disk_expand_part_tbl 2 30561 _001426_hash NULL
85367 +_001427_hash diva_os_alloc_message_buffer 1 64568 _001427_hash NULL
85368 +_001428_hash diva_os_copy_to_user 4 48508 _001428_hash NULL
85369 +_001429_hash diva_os_malloc 2 16406 _001429_hash NULL
85370 +_001430_hash dmam_declare_coherent_memory 4-2 43679 _001430_hash NULL
85371 +_001431_hash dm_vcalloc 1-2 16814 _001431_hash NULL
85372 +_001433_hash dn_alloc_skb 2 6631 _001433_hash NULL
85373 +_001434_hash do_proc_readlink 3 14096 _001434_hash NULL
85374 +_001435_hash do_readlink 2 43518 _001435_hash NULL
85375 +_001436_hash __do_replace 5 37227 _001436_hash NULL
85376 +_001437_hash do_sigpending 2 9766 _001437_hash NULL
85377 +_001438_hash drbd_bm_resize 2 20522 _001438_hash NULL
85378 +_001439_hash drbd_setsockopt 5 16280 _001439_hash &_000383_hash
85379 +_001440_hash dump_midi 3 51040 _001440_hash NULL
85380 +_001441_hash ecryptfs_filldir 3 6622 _001441_hash NULL
85381 +_001442_hash ecryptfs_send_message 2 18322 _001442_hash NULL
85382 +_001443_hash ep0_read 3 38095 _001443_hash NULL
85383 +_001444_hash evdev_ioctl 2 22371 _001444_hash NULL
85384 +_001445_hash ext4_add_new_descs 3 19509 _001445_hash NULL
85385 +_001446_hash fat_ioctl_filldir 3 36621 _001446_hash NULL
85386 +_001447_hash _fc_frame_alloc 1 43568 _001447_hash NULL
85387 +_001448_hash fc_host_post_vendor_event 3 30903 _001448_hash NULL
85388 +_001449_hash fd_copyout 3 59323 _001449_hash NULL
85389 +_001450_hash f_hidg_read 3 6238 _001450_hash NULL
85390 +_001451_hash filldir 3 55137 _001451_hash NULL
85391 +_001452_hash filldir64 3 46469 _001452_hash NULL
85392 +_001453_hash find_skb 2 20431 _001453_hash NULL
85393 +_001454_hash from_buffer 3 18625 _001454_hash NULL
85394 +_001455_hash fsm_init 2 16134 _001455_hash NULL
85395 +_001456_hash fs_path_add 3 15648 _001456_hash NULL
85396 +_001457_hash fs_path_add_from_extent_buffer 4 27702 _001457_hash NULL
85397 +_001458_hash fuse_perform_write 4 18457 _001458_hash NULL
85398 +_001459_hash gem_alloc_skb 2 51715 _001459_hash NULL
85399 +_001460_hash generic_file_buffered_write 4 25464 _001460_hash NULL
85400 +_001461_hash gen_pool_add 3 21776 _001461_hash NULL
85401 +_001462_hash get_packet 3 41914 _001462_hash NULL
85402 +_001463_hash get_packet 3 5747 _001463_hash NULL
85403 +_001464_hash get_packet_pg 4 28023 _001464_hash NULL
85404 +_001465_hash get_skb 2 63008 _001465_hash NULL
85405 +_001466_hash get_subdir 3 62581 _001466_hash NULL
85406 +_001467_hash gsm_control_message 4 18209 _001467_hash NULL
85407 +_001468_hash gsm_control_modem 3 55303 _001468_hash NULL
85408 +_001469_hash gsm_control_rls 3 3353 _001469_hash NULL
85409 +_001470_hash handle_received_packet 3 22457 _001470_hash NULL
85410 +_001471_hash hash_setkey 3 48310 _001471_hash NULL
85411 +_001472_hash hdlcdrv_register 2 6792 _001472_hash NULL
85412 +_001473_hash hiddev_ioctl 2 36816 _001473_hash NULL
85413 +_001474_hash hid_input_report 4 32458 _001474_hash NULL
85414 +_001475_hash hidp_queue_report 3 1881 _001475_hash NULL
85415 +_001476_hash __hidp_send_ctrl_message 4 28303 _001476_hash NULL
85416 +_001477_hash hidraw_read 3 59650 _001477_hash &_001265_hash
85417 +_001478_hash HiSax_readstatus 2 15752 _001478_hash NULL
85418 +_001480_hash __hwahc_op_set_gtk 4 42038 _001480_hash NULL
85419 +_001481_hash __hwahc_op_set_ptk 5 36510 _001481_hash NULL
85420 +_001482_hash hycapi_rx_capipkt 3 11602 _001482_hash NULL
85421 +_001483_hash i2400m_net_rx 5 27170 _001483_hash NULL
85422 +_001484_hash ib_copy_to_udata 3 27525 _001484_hash NULL
85423 +_001485_hash idetape_chrdev_read 3 2097 _001485_hash NULL
85424 +_001486_hash ieee80211_alloc_hw 1 43829 _001486_hash NULL
85425 +_001487_hash ieee80211_bss_info_update 4 13991 _001487_hash NULL
85426 +_001488_hash igmpv3_newpack 2 35912 _001488_hash NULL
85427 +_001489_hash ilo_read 3 32531 _001489_hash NULL
85428 +_001490_hash init_map_ipmac 3-4 63896 _001490_hash NULL
85429 +_001492_hash init_tid_tabs 2-4-3 13252 _001492_hash NULL
85430 +_001495_hash iowarrior_read 3 53483 _001495_hash NULL
85431 +_001496_hash ip_options_get 4 56538 _001496_hash NULL
85432 +_001497_hash ipv6_getsockopt_sticky 5 56711 _001497_hash NULL
85433 +_001498_hash ipwireless_send_packet 4 8328 _001498_hash NULL
85434 +_001499_hash ipx_sendmsg 4 1362 _001499_hash NULL
85435 +_001500_hash irq_domain_add_linear 2 29236 _001500_hash NULL
85436 +_001501_hash iscsi_conn_setup 2 35159 _001501_hash NULL
85437 +_001502_hash iscsi_create_session 3 51647 _001502_hash NULL
85438 +_001503_hash iscsi_host_alloc 2 36671 _001503_hash NULL
85439 +_001504_hash iscsi_if_send_reply 7 52219 _001504_hash NULL
85440 +_001505_hash iscsi_offload_mesg 5 58425 _001505_hash NULL
85441 +_001506_hash iscsi_ping_comp_event 5 38263 _001506_hash NULL
85442 +_001507_hash iscsi_post_host_event 4 13473 _001507_hash NULL
85443 +_001508_hash iscsi_recv_pdu 4 16755 _001508_hash NULL
85444 +_001509_hash iscsi_session_setup 4-5 196 _001509_hash NULL
85445 +_001511_hash iscsit_find_cmd_from_itt_or_dump 3 17194 _003122_hash NULL nohasharray
85446 +_001512_hash isdn_net_ciscohdlck_alloc_skb 2 55209 _001951_hash NULL nohasharray
85447 +_001513_hash isdn_ppp_ccp_xmit_reset 6 63297 _001513_hash NULL
85448 +_001514_hash isdn_ppp_read 4 50356 _001514_hash NULL
85449 +_001515_hash isdn_ppp_skb_push 2 5236 _001515_hash NULL
85450 +_001516_hash isku_sysfs_read 6 58806 _001516_hash NULL
85451 +_001517_hash isku_sysfs_write 6 49767 _001517_hash NULL
85452 +_001520_hash jbd2_alloc 1 41359 _001520_hash NULL
85453 +_001521_hash jffs2_do_link 6 42048 _001521_hash NULL
85454 +_001522_hash jffs2_do_unlink 4 62020 _001522_hash NULL
85455 +_001523_hash jffs2_security_setxattr 4 62107 _001523_hash NULL
85456 +_001524_hash jffs2_trusted_setxattr 4 17048 _001524_hash NULL
85457 +_001525_hash jffs2_user_setxattr 4 10182 _001525_hash NULL
85458 +_001526_hash joydev_ioctl_common 2 49359 _001526_hash NULL
85459 +_001527_hash kernel_setsockopt 5 35913 _001527_hash NULL
85460 +_001528_hash keyctl_describe_key 3 36853 _001528_hash NULL
85461 +_001529_hash keyctl_get_security 3 64418 _001529_hash &_001192_hash
85462 +_001530_hash keyring_read 3 13438 _001530_hash NULL
85463 +_001531_hash kfifo_copy_to_user 3 20646 _001531_hash NULL
85464 +_001532_hash kmem_zalloc_large 1 56128 _001532_hash NULL
85465 +_001533_hash kmp_init 2 41373 _001533_hash NULL
85466 +_001534_hash koneplus_sysfs_write 6 35993 _001534_hash NULL
85467 +_001535_hash kvm_clear_guest_page 4 2308 _001535_hash NULL
85468 +_001536_hash kvm_read_nested_guest_page 5 13337 _001536_hash NULL
85469 +_001537_hash _l2_alloc_skb 1 11883 _001537_hash NULL
85470 +_001538_hash l2cap_create_basic_pdu 3 24869 _001538_hash &_001074_hash
85471 +_001539_hash l2cap_create_connless_pdu 3 37327 _001539_hash NULL
85472 +_001540_hash l2cap_create_iframe_pdu 3 40055 _001540_hash NULL
85473 +_001541_hash l3_alloc_skb 1 32289 _001541_hash NULL
85474 +_001542_hash __lgwrite 4 57669 _001542_hash NULL
85475 +_001543_hash libfc_host_alloc 2 7917 _001543_hash NULL
85476 +_001544_hash llc_alloc_frame 4 64366 _001544_hash NULL
85477 +_001545_hash llcp_sock_sendmsg 4 1092 _001545_hash NULL
85478 +_001546_hash mac_drv_rx_init 2 48898 _001546_hash NULL
85479 +_001547_hash macvtap_get_user 4 28185 _001547_hash NULL
85480 +_001548_hash mdc800_device_read 3 22896 _001548_hash NULL
85481 +_001549_hash memcpy_toiovec 3 54166 _001549_hash &_000892_hash
85482 +_001550_hash memcpy_toiovecend 3-4 19736 _001550_hash NULL
85483 +_001552_hash mempool_create 1 29437 _001552_hash NULL
85484 +_001553_hash mgmt_event 4 12810 _001553_hash NULL
85485 +_001554_hash mgt_set_varlen 4 60916 _001554_hash NULL
85486 +_001555_hash mI_alloc_skb 1 24770 _001555_hash NULL
85487 +_001556_hash mlx4_en_create_rx_ring 3 62498 _001556_hash NULL
85488 +_001557_hash mlx4_en_create_tx_ring 4 48501 _001557_hash NULL
85489 +_001558_hash mlx4_init_cmpt_table 3 11569 _001558_hash NULL
85490 +_001559_hash mon_bin_get_event 4 52863 _001559_hash NULL
85491 +_001560_hash mousedev_read 3 47123 _001560_hash NULL
85492 +_001561_hash move_addr_to_user 2 2868 _001561_hash NULL
85493 +_001562_hash mpihelp_mul 5-3 27805 _001562_hash NULL
85494 +_001564_hash mpi_set_buffer 3 65294 _001564_hash NULL
85495 +_001565_hash mptctl_ioctl 2 12355 _001565_hash NULL
85496 +_001566_hash msnd_fifo_alloc 2 23179 _001566_hash NULL
85497 +_001567_hash mtdswap_init 2 55719 _001567_hash NULL
85498 +_001568_hash mthca_alloc_resize_buf 3 60394 _001568_hash NULL
85499 +_001569_hash mthca_init_cq 2 60011 _001569_hash NULL
85500 +_001570_hash nci_skb_alloc 2 49757 _001570_hash NULL
85501 +_001571_hash neigh_hash_grow 2 17283 _001571_hash NULL
85502 +_001572_hash netdev_alloc_skb 2 62437 _001572_hash NULL
85503 +_001573_hash __netdev_alloc_skb_ip_align 2 55067 _001573_hash NULL
85504 +_001574_hash netlink_change_ngroups 2 16457 _001574_hash NULL
85505 +_001575_hash new_skb 1 21148 _001575_hash NULL
85506 +_001576_hash nfc_alloc_recv_skb 1 10244 _001576_hash NULL
85507 +_001577_hash nfcwilink_skb_alloc 1 16167 _001577_hash NULL
85508 +_001578_hash __nf_nat_mangle_tcp_packet 5-7 8190 _001578_hash NULL
85509 +_001580_hash nf_nat_mangle_udp_packet 5-7 13321 _001580_hash NULL
85510 +_001582_hash nfqnl_mangle 4-2 36226 _001582_hash NULL
85511 +_001583_hash nfs4_realloc_slot_table 2 22859 _001583_hash NULL
85512 +_001584_hash nfs_idmap_get_key 2 39616 _001584_hash NULL
85513 +_001585_hash nfs_readdata_alloc 2 65015 _001585_hash NULL
85514 +_001586_hash nfs_writedata_alloc 2 12133 _001586_hash NULL
85515 +_001587_hash nfulnl_alloc_skb 2 65207 _001587_hash NULL
85516 +_001588_hash ni65_alloc_mem 3 10664 _001588_hash NULL
85517 +_001589_hash nsm_get_handle 4 52089 _001589_hash NULL
85518 +_001590_hash ntfs_malloc_nofs 1 49572 _001590_hash NULL
85519 +_001591_hash ntfs_malloc_nofs_nofail 1 63631 _001591_hash NULL
85520 +_001592_hash nvme_create_queue 3 170 _001592_hash NULL
85521 +_001593_hash ocfs2_control_write 3 54737 _001593_hash NULL
85522 +_001595_hash orinoco_add_extscan_result 3 18207 _001595_hash NULL
85523 +_001596_hash osd_req_read_sg_kern 5 6378 _001596_hash NULL
85524 +_001597_hash osd_req_write_sg_kern 5 10514 _001597_hash NULL
85525 +_001599_hash override_release 2 52032 _001599_hash NULL
85526 +_001600_hash p9_client_read 5 19750 _001600_hash NULL
85527 +_001601_hash packet_snd 3 13634 _001601_hash NULL
85528 +_001602_hash pcbit_stat 2 27364 _001602_hash NULL
85529 +_001603_hash pcpu_extend_area_map 2 12589 _001603_hash NULL
85530 +_001604_hash pep_alloc_skb 3 46303 _001604_hash NULL
85531 +_001605_hash pg_read 3 17276 _001605_hash NULL
85532 +_001606_hash picolcd_debug_eeprom_read 3 14549 _001606_hash NULL
85533 +_001607_hash pkt_alloc_packet_data 1 37928 _001607_hash NULL
85534 +_001608_hash pmcraid_build_passthrough_ioadls 2 62034 _001608_hash NULL
85535 +_001609_hash pn_raw_send 2 54330 _001609_hash NULL
85536 +_001610_hash posix_clock_register 2 5662 _001610_hash NULL
85537 +_001611_hash printer_read 3 54851 _001611_hash NULL
85538 +_001612_hash __proc_file_read 3 54978 _001612_hash NULL
85539 +_001613_hash pskb_may_pull 2 22546 _001613_hash NULL
85540 +_001614_hash __pskb_pull 2 42602 _001614_hash NULL
85541 +_001615_hash ptp_read 4 63251 _001615_hash NULL
85542 +_001616_hash pt_read 3 49136 _001616_hash NULL
85543 +_001617_hash put_cmsg 4 36589 _001617_hash NULL
85544 +_001618_hash px_raw_event 4 49371 _001618_hash NULL
85545 +_001619_hash qla4xxx_post_aen_work 3 46953 _001619_hash NULL
85546 +_001620_hash qla4xxx_post_ping_evt_work 4 8074 _001819_hash NULL nohasharray
85547 +_001621_hash raid5_resize 2 63306 _001621_hash NULL
85548 +_001622_hash rawv6_sendmsg 4 20080 _001622_hash NULL
85549 +_001623_hash rds_message_map_pages 2 31487 _001623_hash NULL
85550 +_001624_hash rds_sendmsg 4 40976 _001624_hash NULL
85551 +_001625_hash read_flush 3 43851 _001625_hash NULL
85552 +_001626_hash read_profile 3 27859 _001626_hash NULL
85553 +_001627_hash read_vmcore 3 26501 _001627_hash NULL
85554 +_001628_hash redirected_tty_write 3 65297 _001628_hash NULL
85555 +_001629_hash refill_pool 2 19477 _001629_hash NULL
85556 +_001630_hash __register_chrdev 2-3 54223 _001630_hash NULL
85557 +_001632_hash regmap_raw_write 4 53803 _001632_hash NULL
85558 +_001633_hash reiserfs_allocate_list_bitmaps 3 21732 _001633_hash NULL
85559 +_001634_hash reiserfs_resize 2 34377 _001634_hash NULL
85560 +_001635_hash request_key_auth_read 3 24109 _001635_hash NULL
85561 +_001636_hash rfcomm_wmalloc 2 58090 _001636_hash NULL
85562 +_001637_hash rfkill_fop_read 3 54711 _001637_hash NULL
85563 +_001638_hash rng_dev_read 3 41581 _001638_hash NULL
85564 +_001639_hash roccat_read 3 41093 _001639_hash &_001034_hash
85565 +_001640_hash rx 4 57944 _001640_hash NULL
85566 +_001641_hash rxrpc_client_sendmsg 5 23236 _001641_hash NULL
85567 +_001642_hash rxrpc_kernel_send_data 3 60083 _001642_hash NULL
85568 +_001643_hash rxrpc_server_sendmsg 4 37331 _001643_hash NULL
85569 +_001644_hash savu_sysfs_write 6 42273 _001644_hash NULL
85570 +_001645_hash sco_sock_sendmsg 4 62542 _001645_hash NULL
85571 +_001646_hash scsi_nl_send_vendor_msg 5 16394 _001646_hash NULL
85572 +_001647_hash scsi_register 2 49094 _001647_hash NULL
85573 +_001648_hash sctp_datamsg_from_user 4 55342 _001648_hash NULL
85574 +_001649_hash sctp_getsockopt_events 2 3607 _001649_hash NULL
85575 +_001650_hash sctp_getsockopt_maxburst 2 42941 _001650_hash NULL
85576 +_001651_hash sctp_getsockopt_maxseg 2 10737 _001651_hash NULL
85577 +_001652_hash sctp_make_chunk 4 12986 _001652_hash NULL
85578 +_001653_hash sctpprobe_read 3 17741 _001653_hash NULL
85579 +_001654_hash sctp_tsnmap_mark 2 35929 _001654_hash NULL
85580 +_001655_hash sctp_ulpevent_new 1 33377 _001655_hash NULL
85581 +_001656_hash sdhci_alloc_host 2 7509 _001656_hash NULL
85582 +_001657_hash selinux_inode_post_setxattr 4 26037 _001657_hash NULL
85583 +_001658_hash selinux_inode_setsecurity 4 18148 _001658_hash NULL
85584 +_001659_hash selinux_inode_setxattr 4 10708 _001659_hash NULL
85585 +_001660_hash selinux_secctx_to_secid 2 63744 _001660_hash NULL
85586 +_001661_hash selinux_setprocattr 4 55611 _001661_hash NULL
85587 +_001662_hash sel_write_context 3 25726 _001662_hash &_001329_hash
85588 +_001663_hash send_command 4 10832 _001663_hash NULL
85589 +_001664_hash seq_copy_in_user 3 18543 _001664_hash NULL
85590 +_001665_hash seq_open_net 4 8968 _001779_hash NULL nohasharray
85591 +_001666_hash seq_open_private 3 61589 _001666_hash NULL
85592 +_001667_hash set_arg 3 42824 _001667_hash NULL
85593 +_001668_hash sg_read 3 25799 _001668_hash NULL
85594 +_001669_hash shash_async_setkey 3 10720 _003506_hash NULL nohasharray
85595 +_001670_hash shash_compat_setkey 3 12267 _001670_hash NULL
85596 +_001671_hash shmem_setxattr 4 55867 _001671_hash NULL
85597 +_001672_hash simple_read_from_buffer 2-5 55957 _001672_hash NULL
85598 +_001674_hash sisusb_clear_vram 2-3 57466 _001674_hash NULL
85599 +_001676_hash sisusbcon_do_font_op 9 52271 _001676_hash NULL
85600 +_001677_hash sisusb_copy_memory 4 35016 _001677_hash NULL
85601 +_001678_hash sisusb_write 3 44834 _001678_hash NULL
85602 +_001680_hash skb_cow 2 26138 _001680_hash NULL
85603 +_001681_hash skb_cow_head 2 52495 _001681_hash NULL
85604 +_001682_hash skb_make_writable 2 24783 _001682_hash NULL
85605 +_001683_hash skb_padto 2 50759 _001683_hash NULL
85606 +_001684_hash sk_stream_alloc_skb 2 57622 _001684_hash NULL
85607 +_001685_hash smk_write_access2 3 19170 _001685_hash NULL
85608 +_001686_hash smk_write_access 3 49561 _001686_hash NULL
85609 +_001687_hash snd_es1938_capture_copy 5 25930 _001687_hash NULL
85610 +_001688_hash snd_gus_dram_peek 4 9062 _001688_hash NULL
85611 +_001689_hash snd_hdsp_capture_copy 5 4011 _001689_hash NULL
85612 +_001690_hash snd_korg1212_copy_to 6 92 _001690_hash NULL
85613 +_001691_hash snd_opl4_mem_proc_read 5 63774 _001691_hash NULL
85614 +_001692_hash snd_pcm_oss_read1 3 63771 _001692_hash NULL
85615 +_001693_hash snd_pcm_plugin_alloc 2 12580 _001693_hash NULL
85616 +_001694_hash snd_rawmidi_kernel_read1 4 36740 _001694_hash NULL
85617 +_001695_hash snd_rme9652_capture_copy 5 10287 _001695_hash NULL
85618 +_001696_hash sock_alloc_send_pskb 2 21246 _001696_hash NULL
85619 +_001697_hash sock_rmalloc 2 59740 _002491_hash NULL nohasharray
85620 +_001698_hash sock_wmalloc 2 16472 _001698_hash NULL
85621 +_001699_hash solos_param_store 4 34755 _001699_hash NULL
85622 +_001702_hash srp_target_alloc 3 37288 _001702_hash NULL
85623 +_001703_hash store_ifalias 4 35088 _001703_hash NULL
85624 +_001704_hash store_msg 3 56417 _001704_hash NULL
85625 +_001705_hash str_to_user 2 11411 _001705_hash NULL
85626 +_001706_hash subbuf_read_actor 3 2071 _001706_hash NULL
85627 +_001707_hash sys_fgetxattr 4 25166 _001707_hash NULL
85628 +_001708_hash sys_gethostname 2 49698 _001708_hash NULL
85629 +_001709_hash sys_getxattr 4 37418 _001709_hash NULL
85630 +_001710_hash sys_init_module 2 36047 _001710_hash NULL
85631 +_001711_hash sys_kexec_load 2 14222 _001711_hash NULL
85632 +_001712_hash sys_lgetxattr 4 45531 _001712_hash NULL
85633 +_001713_hash syslog_print 2 307 _001713_hash NULL
85634 +_001714_hash sys_msgsnd 3 44537 _001714_hash &_000139_hash
85635 +_001715_hash sys_process_vm_readv 3-5 19090 _003104_hash NULL nohasharray
85636 +_001717_hash sys_process_vm_writev 3-5 4928 _001717_hash NULL
85637 +_001719_hash sys_pselect6 1 57449 _001719_hash NULL
85638 +_001720_hash sys_sched_getaffinity 2 60033 _001720_hash NULL
85639 +_001721_hash sys_setsockopt 5 35320 _001721_hash NULL
85640 +_001722_hash t3_init_l2t 1 8261 _001722_hash NULL
85641 +_001723_hash t4vf_pktgl_to_skb 2 39005 _001723_hash NULL
85642 +_001724_hash tcp_collapse 5-6 63294 _001724_hash NULL
85643 +_001726_hash tcp_sendmsg 4 30296 _001726_hash NULL
85644 +_001727_hash team_options_register 3 20091 _001727_hash NULL
85645 +_001728_hash tipc_buf_acquire 1 60437 _001728_hash NULL
85646 +_001729_hash tipc_cfg_reply_alloc 1 27606 _001729_hash NULL
85647 +_001730_hash tipc_send2name 6 16809 _001730_hash NULL
85648 +_001731_hash tipc_send2port 5 63935 _001731_hash NULL
85649 +_001732_hash tipc_send 4 51238 _001732_hash NULL
85650 +_001733_hash tnode_new 3 44757 _002769_hash NULL nohasharray
85651 +_001734_hash tomoyo_read_self 3 33539 _001734_hash NULL
85652 +_001735_hash tomoyo_update_domain 2 5498 _001735_hash NULL
85653 +_001736_hash tomoyo_update_policy 2 40458 _001736_hash NULL
85654 +_001737_hash tpm_read 3 50344 _001737_hash NULL
85655 +_001738_hash TSS_rawhmac 3 17486 _001738_hash NULL
85656 +_001739_hash __tty_buffer_request_room 2 27700 _001739_hash NULL
85657 +_001740_hash tun_get_user 4 39099 _001740_hash NULL
85658 +_001741_hash ubi_dump_flash 4 46381 _001741_hash NULL
85659 +_001742_hash ubi_io_write 4-5 15870 _003453_hash NULL nohasharray
85660 +_001744_hash udp_setsockopt 5 25985 _001744_hash NULL
85661 +_001745_hash udpv6_setsockopt 5 18487 _001745_hash NULL
85662 +_001746_hash uio_read 3 49300 _001746_hash NULL
85663 +_001747_hash ulog_alloc_skb 1 23427 _001747_hash NULL
85664 +_001748_hash unix_dgram_sendmsg 4 45699 _001748_hash NULL
85665 +_001749_hash unlink1 3 63059 _001749_hash NULL
85666 +_001751_hash usbdev_read 3 45114 _001751_hash NULL
85667 +_001752_hash usblp_ioctl 2 30203 _001752_hash NULL
85668 +_001753_hash usblp_read 3 57342 _003832_hash NULL nohasharray
85669 +_001754_hash usbtmc_read 3 32377 _001754_hash NULL
85670 +_001755_hash _usb_writeN_sync 4 31682 _001755_hash NULL
85671 +_001756_hash user_read 3 51881 _001756_hash NULL
85672 +_001757_hash vcs_read 3 8017 _001757_hash NULL
85673 +_001758_hash vdma_mem_alloc 1 6171 _001758_hash NULL
85674 +_001759_hash venus_create 4 20555 _001759_hash NULL
85675 +_001760_hash venus_link 5 32165 _001760_hash NULL
85676 +_001761_hash venus_lookup 4 8121 _001761_hash NULL
85677 +_001762_hash venus_mkdir 4 8967 _001762_hash NULL
85678 +_001763_hash venus_remove 4 59781 _001763_hash NULL
85679 +_001764_hash venus_rename 4-5 17707 _003784_hash NULL nohasharray
85680 +_001766_hash venus_rmdir 4 45564 _001766_hash NULL
85681 +_001767_hash venus_symlink 4-6 23570 _001767_hash NULL
85682 +_001769_hash vfs_readlink 3 54368 _001769_hash NULL
85683 +_001770_hash vfs_readv 3 38011 _001770_hash NULL
85684 +_001771_hash vfs_writev 3 25278 _001771_hash NULL
85685 +_001772_hash vga_arb_read 3 4886 _001772_hash NULL
85686 +_001773_hash vgacon_adjust_height 2 28124 _001773_hash NULL
85687 +_001774_hash vhci_put_user 4 12604 _001774_hash NULL
85688 +_001775_hash vhost_add_used_n 3 10760 _001775_hash NULL
85689 +_001776_hash virtnet_send_command 5-6 61993 _001776_hash NULL
85690 +_001778_hash vmbus_establish_gpadl 3 4495 _001778_hash NULL
85691 +_001779_hash vol_cdev_read 3 8968 _001779_hash &_001665_hash
85692 +_001780_hash wdm_read 3 6549 _001780_hash NULL
85693 +_001781_hash write_adapter_mem 3 3234 _001781_hash NULL
85694 +_001782_hash wusb_prf 7 54261 _001782_hash &_000065_hash
85695 +_001783_hash xdi_copy_to_user 4 48900 _001783_hash NULL
85696 +_001784_hash xfs_buf_associate_memory 3 17915 _001784_hash NULL
85697 +_001785_hash xfs_buf_get_maps 2 4581 _001785_hash NULL
85698 +_001786_hash xfs_buf_get_uncached 2 51477 _001786_hash NULL
85699 +_001787_hash xfs_buf_item_get_format 2 189 _001787_hash NULL
85700 +_001788_hash xfs_buf_map_from_irec 5 2368 _002641_hash NULL nohasharray
85701 +_001789_hash xfs_dir2_block_to_sf 3 37868 _001789_hash NULL
85702 +_001790_hash xfs_dir2_leaf_getdents 3 23841 _001790_hash NULL
85703 +_001791_hash xfs_dir2_sf_addname_hard 3 54254 _001791_hash NULL
85704 +_001792_hash xfs_efd_init 3 5463 _001792_hash NULL
85705 +_001793_hash xfs_efi_init 2 5476 _001793_hash NULL
85706 +_001794_hash xfs_iext_realloc_direct 2 20521 _001794_hash NULL
85707 +_001795_hash xfs_iext_realloc_indirect 2 59211 _001795_hash NULL
85708 +_001796_hash xfs_inumbers_fmt 3 12817 _001796_hash NULL
85709 +_001797_hash xhci_alloc_streams 5 37586 _001797_hash NULL
85710 +_001798_hash xlog_recover_add_to_cont_trans 4 44102 _001798_hash NULL
85711 +_001799_hash xz_dec_lzma2_create 2 36353 _002713_hash NULL nohasharray
85712 +_001800_hash _zd_iowrite32v_locked 3 44725 _001800_hash NULL
85713 +_001801_hash a2mp_chan_alloc_skb_cb 2 27159 _001801_hash NULL
85714 +_001802_hash aat2870_reg_read_file 3 12221 _001802_hash NULL
85715 +_001803_hash add_partition 2 55588 _001803_hash NULL
85716 +_001804_hash add_sctp_bind_addr 3 12269 _001804_hash NULL
85717 +_001805_hash _add_sg_continuation_descriptor 3 54721 _001805_hash NULL
85718 +_001806_hash afs_cell_lookup 2 8482 _001806_hash NULL
85719 +_001807_hash afs_send_simple_reply 3 63940 _001807_hash NULL
85720 +_001808_hash agp_allocate_memory_wrap 1 16576 _001808_hash NULL
85721 +_001809_hash __alloc_bootmem 1 31498 _001809_hash NULL
85722 +_001810_hash __alloc_bootmem_low 1 43423 _003425_hash NULL nohasharray
85723 +_001811_hash __alloc_bootmem_node_high 2 65076 _001811_hash NULL
85724 +_001812_hash alloc_cc770dev 1 48186 _001812_hash NULL
85725 +_001813_hash __alloc_ei_netdev 1 29338 _001813_hash NULL
85726 +_001814_hash __alloc_eip_netdev 1 51549 _001814_hash NULL
85727 +_001815_hash alloc_libipw 1 22708 _001815_hash NULL
85728 +_001816_hash _alloc_mISDN_skb 3 52232 _001816_hash NULL
85729 +_001817_hash alloc_pg_vec 2 8533 _001817_hash NULL
85730 +_001818_hash alloc_sja1000dev 1 17868 _001818_hash NULL
85731 +_001819_hash alloc_targets 2 8074 _001819_hash &_001620_hash
85732 +_001822_hash ath6kl_disconnect_timeout_read 3 3650 _001822_hash NULL
85733 +_001823_hash ath6kl_endpoint_stats_read 3 41554 _001823_hash NULL
85734 +_001824_hash ath6kl_fwlog_mask_read 3 2050 _001824_hash NULL
85735 +_001825_hash ath6kl_keepalive_read 3 44303 _001825_hash NULL
85736 +_001826_hash ath6kl_listen_int_read 3 10355 _001826_hash NULL
85737 +_001827_hash ath6kl_lrssi_roam_read 3 61022 _001827_hash NULL
85738 +_001828_hash ath6kl_regdump_read 3 14393 _001828_hash NULL
85739 +_001829_hash ath6kl_regread_read 3 25884 _001829_hash NULL
85740 +_001830_hash ath6kl_regwrite_read 3 48747 _001830_hash NULL
85741 +_001831_hash ath6kl_roam_table_read 3 26166 _001831_hash NULL
85742 +_001832_hash ath9k_debugfs_read_buf 3 25316 _001832_hash NULL
85743 +_001833_hash ath9k_multi_regread 4 65056 _001833_hash NULL
85744 +_001834_hash ath_rxbuf_alloc 2 24745 _001834_hash NULL
85745 +_001835_hash atk_debugfs_ggrp_read 3 29522 _001835_hash NULL
85746 +_001836_hash audit_log_n_untrustedstring 3 9548 _001836_hash NULL
85747 +_001837_hash ax25_send_frame 2 19964 _001837_hash NULL
85748 +_001838_hash b43_debugfs_read 3 24425 _001838_hash NULL
85749 +_001839_hash b43legacy_debugfs_read 3 2473 _001839_hash NULL
85750 +_001840_hash batadv_bla_is_backbone_gw 3 58488 _001840_hash NULL
85751 +_001841_hash batadv_check_management_packet 3 52993 _001841_hash NULL
85752 +_001842_hash batadv_check_unicast_packet 2 10866 _001842_hash NULL
85753 +_001843_hash batadv_interface_rx 4 8568 _001843_hash NULL
85754 +_001844_hash batadv_skb_head_push 2 11360 _001844_hash NULL
85755 +_001845_hash bchannel_get_rxbuf 2 37213 _001845_hash NULL
85756 +_001846_hash bcm_recvmsg 4 43992 _001846_hash NULL
85757 +_001847_hash bfad_debugfs_read 3 13119 _001847_hash NULL
85758 +_001848_hash bfad_debugfs_read_regrd 3 57830 _001848_hash NULL
85759 +_001849_hash blk_init_tags 1 30592 _001849_hash NULL
85760 +_001850_hash blk_queue_init_tags 2 44355 _001850_hash &_001022_hash
85761 +_001851_hash blk_rq_map_kern 4 47004 _001851_hash NULL
85762 +_001852_hash bm_entry_read 3 10976 _001852_hash NULL
85763 +_001853_hash bm_status_read 3 19583 _001853_hash NULL
85764 +_001854_hash bnad_debugfs_read 3 50665 _001854_hash NULL
85765 +_001855_hash bnad_debugfs_read_regrd 3 51308 _001855_hash NULL
85766 +_001856_hash bnx2i_send_nl_mesg 4 53353 _001856_hash NULL
85767 +_001857_hash brcmf_debugfs_sdio_counter_read 3 58369 _001857_hash NULL
85768 +_001858_hash brcmf_sdio_assert_info 4 52653 _001858_hash NULL
85769 +_001859_hash brcmf_sdio_dump_console 4 37455 _001859_hash NULL
85770 +_001860_hash brcmf_sdio_trap_info 4 48510 _001860_hash NULL
85771 +_001861_hash btmrvl_curpsmode_read 3 46939 _001861_hash NULL
85772 +_001862_hash btmrvl_gpiogap_read 3 4718 _001862_hash NULL
85773 +_001863_hash btmrvl_hscfgcmd_read 3 56303 _001863_hash NULL
85774 +_001864_hash btmrvl_hscmd_read 3 1614 _001864_hash NULL
85775 +_001865_hash btmrvl_hsmode_read 3 1647 _001865_hash NULL
85776 +_001866_hash btmrvl_hsstate_read 3 920 _001866_hash NULL
85777 +_001867_hash btmrvl_pscmd_read 3 24308 _001867_hash NULL
85778 +_001868_hash btmrvl_psmode_read 3 22395 _001868_hash NULL
85779 +_001869_hash btmrvl_psstate_read 3 50683 _001869_hash NULL
85780 +_001870_hash btmrvl_txdnldready_read 3 413 _001870_hash NULL
85781 +_001871_hash btrfs_add_link 5 9973 _001871_hash NULL
85782 +_001872_hash __btrfs_direct_write 4 22273 _001872_hash NULL
85783 +_001873_hash btrfs_discard_extent 2 38547 _001873_hash NULL
85784 +_001874_hash btrfs_file_aio_write 4 21520 _001874_hash NULL
85785 +_001875_hash btrfs_find_create_tree_block 3 55812 _001875_hash NULL
85786 +_001876_hash btrfsic_map_block 2 56751 _001876_hash NULL
85787 +_001877_hash cache_read_pipefs 3 47615 _001877_hash NULL
85788 +_001878_hash cache_read_procfs 3 52882 _001878_hash NULL
85789 +_001879_hash cache_write_pipefs 3 48270 _001879_hash NULL
85790 +_001880_hash cache_write_procfs 3 22491 _001880_hash NULL
85791 +_001881_hash caif_stream_recvmsg 4 13173 _001881_hash NULL
85792 +_001882_hash carl9170_alloc 1 27 _001882_hash NULL
85793 +_001883_hash carl9170_debugfs_read 3 47738 _001883_hash NULL
85794 +_001884_hash ceph_msgpool_init 4 34599 _001884_hash NULL
85795 +_001885_hash cfpkt_add_trail 3 27260 _001885_hash NULL
85796 +_001886_hash cfpkt_create 1 18197 _001886_hash NULL
85797 +_001887_hash cfpkt_pad_trail 2 55511 _003606_hash NULL nohasharray
85798 +_001888_hash cfpkt_split 2 47541 _001888_hash NULL
85799 +_001889_hash cgroup_read_s64 5 19570 _001889_hash NULL
85800 +_001890_hash cgroup_read_u64 5 45532 _001890_hash NULL
85801 +_001891_hash channel_type_read 3 47308 _001891_hash NULL
85802 +_001892_hash check_header 2 56930 _001892_hash NULL
85803 +_001893_hash codec_list_read_file 3 24910 _001893_hash NULL
85804 +_001894_hash configfs_read_file 3 1683 _001894_hash NULL
85805 +_001895_hash console_store 4 36007 _001895_hash NULL
85806 +_001896_hash cpuset_common_file_read 5 8800 _001896_hash NULL
85807 +_001897_hash create_subvol 4 30836 _001897_hash NULL
85808 +_001898_hash cxio_hal_init_resource 2-7-6 29771 _001898_hash &_000295_hash
85809 +_001901_hash cxio_hal_init_rhdl_resource 1 25104 _001901_hash NULL
85810 +_001902_hash dai_list_read_file 3 25421 _001902_hash NULL
85811 +_001903_hash dapm_bias_read_file 3 64715 _001903_hash NULL
85812 +_001904_hash dapm_widget_power_read_file 3 59950 _001983_hash NULL nohasharray
85813 +_001907_hash dbgfs_frame 3 45917 _001907_hash NULL
85814 +_001908_hash dbgfs_state 3 38894 _001908_hash NULL
85815 +_001909_hash dccp_manip_pkt 2 30229 _001909_hash NULL
85816 +_001910_hash ddp_ppod_write_idata 5 25610 _001910_hash NULL
85817 +_001911_hash debugfs_read 3 62535 _001911_hash NULL
85818 +_001912_hash debug_output 3 18575 _001912_hash NULL
85819 +_001913_hash debug_read 3 19322 _001913_hash NULL
85820 +_001914_hash dev_alloc_skb 1 19517 _001914_hash &_001366_hash
85821 +_001915_hash dfs_file_read 3 18116 _001915_hash NULL
85822 +_001916_hash diva_alloc_dma_map 2 23798 _001916_hash NULL
85823 +_001917_hash diva_xdi_write 4 63975 _001917_hash NULL
85824 +_001918_hash dma_memcpy_pg_to_iovec 6 1725 _001918_hash NULL
85825 +_001919_hash dma_memcpy_to_iovec 5 12173 _001919_hash NULL
85826 +_001920_hash dma_show_regs 3 35266 _001920_hash NULL
85827 +_001921_hash dm_exception_table_init 2 39645 _001921_hash &_001149_hash
85828 +_001922_hash dn_nsp_do_disc 2-6 49474 _001922_hash NULL
85829 +_001924_hash dn_recvmsg 4 17213 _001924_hash NULL
85830 +_001925_hash dns_resolver_read 3 54658 _001925_hash NULL
85831 +_001926_hash do_msgrcv 4 5590 _001926_hash NULL
85832 +_001927_hash do_syslog 3 56807 _001927_hash NULL
85833 +_001928_hash dpcm_state_read_file 3 65489 _001928_hash NULL
85834 +_001929_hash dsp_cmx_send_member 2 15625 _001929_hash NULL
85835 +_001930_hash fallback_on_nodma_alloc 2 35332 _001930_hash NULL
85836 +_001931_hash fc_frame_alloc 2 1596 _001931_hash NULL
85837 +_001932_hash fc_frame_alloc_fill 2 59394 _001932_hash NULL
85838 +_001933_hash filter_read 3 61692 _001933_hash NULL
85839 +_001934_hash __finish_unordered_dir 4 33198 _001934_hash NULL
85840 +_001935_hash format_devstat_counter 3 32550 _001935_hash NULL
85841 +_001936_hash fragmentation_threshold_read 3 61718 _001936_hash NULL
85842 +_001937_hash fuse_conn_limit_read 3 20084 _001937_hash NULL
85843 +_001938_hash fuse_conn_waiting_read 3 49762 _001938_hash NULL
85844 +_001939_hash fuse_file_aio_write 4 46399 _001939_hash NULL
85845 +_001940_hash generic_readlink 3 32654 _001940_hash NULL
85846 +_001941_hash gre_manip_pkt 2 38785 _001941_hash NULL
85847 +_001942_hash handle_eviocgbit 3 44193 _001942_hash NULL
85848 +_001943_hash handle_response 5 55951 _001943_hash NULL
85849 +_001944_hash handle_response_icmp 7 39574 _001944_hash NULL
85850 +_001945_hash hash_recvmsg 4 50924 _001945_hash NULL
85851 +_001946_hash hci_send_cmd 3 43810 _001946_hash NULL
85852 +_001947_hash hci_si_event 3 1404 _001947_hash NULL
85853 +_001948_hash help 4 14971 _001948_hash NULL
85854 +_001949_hash hfcpci_empty_bfifo 4 62323 _001949_hash NULL
85855 +_001950_hash hidp_send_ctrl_message 4 43702 _001950_hash NULL
85856 +_001951_hash ht40allow_map_read 3 55209 _001951_hash &_001512_hash
85857 +_001952_hash hwflags_read 3 52318 _001952_hash NULL
85858 +_001953_hash hysdn_conf_read 3 42324 _001953_hash NULL
85859 +_001954_hash hysdn_sched_rx 3 60533 _001954_hash NULL
85860 +_001955_hash i2400m_rx_stats_read 3 57706 _001955_hash NULL
85861 +_001956_hash i2400m_tx_stats_read 3 28527 _001956_hash NULL
85862 +_001957_hash icmp_manip_pkt 2 48801 _001957_hash NULL
85863 +_001958_hash idmouse_read 3 63374 _001958_hash NULL
85864 +_001959_hash ieee80211_if_read 3 6785 _001959_hash NULL
85865 +_001960_hash ieee80211_rx_bss_info 3 61630 _001960_hash NULL
85866 +_001961_hash ikconfig_read_current 3 1658 _001961_hash NULL
85867 +_001962_hash il3945_sta_dbgfs_stats_table_read 3 48802 _001962_hash NULL
85868 +_001963_hash il3945_ucode_general_stats_read 3 46111 _001963_hash NULL
85869 +_001964_hash il3945_ucode_rx_stats_read 3 3048 _001964_hash NULL
85870 +_001965_hash il3945_ucode_tx_stats_read 3 36016 _001965_hash NULL
85871 +_001966_hash il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 _001966_hash NULL
85872 +_001967_hash il4965_rs_sta_dbgfs_scale_table_read 3 38564 _001967_hash NULL
85873 +_001968_hash il4965_rs_sta_dbgfs_stats_table_read 3 49206 _001968_hash NULL
85874 +_001969_hash il4965_ucode_general_stats_read 3 56277 _001969_hash NULL
85875 +_001970_hash il4965_ucode_rx_stats_read 3 61948 _001970_hash NULL
85876 +_001971_hash il4965_ucode_tx_stats_read 3 12064 _001971_hash NULL
85877 +_001972_hash il_dbgfs_chain_noise_read 3 38044 _001972_hash NULL
85878 +_001973_hash il_dbgfs_channels_read 3 25005 _001973_hash NULL
85879 +_001974_hash il_dbgfs_disable_ht40_read 3 42386 _001974_hash NULL
85880 +_001975_hash il_dbgfs_fh_reg_read 3 40993 _001975_hash NULL
85881 +_001976_hash il_dbgfs_force_reset_read 3 57517 _001976_hash NULL
85882 +_001977_hash il_dbgfs_interrupt_read 3 3351 _001977_hash NULL
85883 +_001978_hash il_dbgfs_missed_beacon_read 3 59956 _001978_hash NULL
85884 +_001979_hash il_dbgfs_nvm_read 3 12288 _001979_hash NULL
85885 +_001980_hash il_dbgfs_power_save_status_read 3 43165 _001980_hash NULL
85886 +_001981_hash il_dbgfs_qos_read 3 33615 _001981_hash NULL
85887 +_001982_hash il_dbgfs_rxon_filter_flags_read 3 19281 _001982_hash NULL
85888 +_001983_hash il_dbgfs_rxon_flags_read 3 59950 _001983_hash &_001904_hash
85889 +_001984_hash il_dbgfs_rx_queue_read 3 11221 _001984_hash NULL
85890 +_001985_hash il_dbgfs_rx_stats_read 3 15243 _001985_hash NULL
85891 +_001986_hash il_dbgfs_sensitivity_read 3 2370 _001986_hash NULL
85892 +_001987_hash il_dbgfs_sram_read 3 62296 _001987_hash NULL
85893 +_001988_hash il_dbgfs_stations_read 3 21532 _001988_hash NULL
85894 +_001989_hash il_dbgfs_status_read 3 58388 _001989_hash NULL
85895 +_001990_hash il_dbgfs_tx_queue_read 3 55668 _001990_hash NULL
85896 +_001991_hash il_dbgfs_tx_stats_read 3 32913 _001991_hash NULL
85897 +_001992_hash ima_show_htable_value 2 57136 _001992_hash NULL
85898 +_001994_hash intel_fake_agp_alloc_by_type 1 1 _001994_hash NULL
85899 +_001995_hash ip4ip6_err 5 36772 _001995_hash NULL
85900 +_001996_hash ip6_append_data 4-5 36490 _003601_hash NULL nohasharray
85901 +_001997_hash ip6ip6_err 5 18308 _001997_hash NULL
85902 +_001998_hash __ip_append_data 7-8 36191 _001998_hash NULL
85903 +_001999_hash ip_vs_icmp_xmit 4 59624 _001999_hash NULL
85904 +_002000_hash ip_vs_icmp_xmit_v6 4 20464 _002000_hash NULL
85905 +_002001_hash ipw_write 3 59807 _002001_hash NULL
85906 +_002002_hash irda_recvmsg_stream 4 35280 _002002_hash NULL
85907 +_002003_hash irq_domain_add_simple 2 46734 _002003_hash NULL
85908 +_002004_hash __iscsi_complete_pdu 4 10726 _002004_hash NULL
85909 +_002005_hash iscsi_nop_out_rsp 4 51117 _002005_hash NULL
85910 +_002006_hash iscsi_tcp_conn_setup 2 16376 _002006_hash NULL
85911 +_002007_hash iwl_dbgfs_bt_traffic_read 3 35534 _002007_hash NULL
85912 +_002008_hash iwl_dbgfs_calib_disabled_read 3 22649 _002008_hash NULL
85913 +_002009_hash iwl_dbgfs_chain_noise_read 3 46355 _002009_hash NULL
85914 +_002010_hash iwl_dbgfs_channels_read 3 6784 _002010_hash NULL
85915 +_002011_hash iwl_dbgfs_current_sleep_command_read 3 2081 _002011_hash NULL
85916 +_002012_hash iwl_dbgfs_disable_ht40_read 3 35761 _002012_hash NULL
85917 +_002013_hash iwl_dbgfs_fh_reg_read 3 879 _002013_hash &_000406_hash
85918 +_002014_hash iwl_dbgfs_interrupt_read 3 23574 _002014_hash NULL
85919 +_002015_hash iwl_dbgfs_log_event_read 3 2107 _002015_hash NULL
85920 +_002016_hash iwl_dbgfs_missed_beacon_read 3 50584 _002016_hash NULL
85921 +_002017_hash iwl_dbgfs_nvm_read 3 23845 _002017_hash NULL
85922 +_002018_hash iwl_dbgfs_plcp_delta_read 3 55407 _002018_hash NULL
85923 +_002019_hash iwl_dbgfs_power_save_status_read 3 54392 _002019_hash NULL
85924 +_002020_hash iwl_dbgfs_protection_mode_read 3 13943 _002020_hash NULL
85925 +_002021_hash iwl_dbgfs_qos_read 3 11753 _002021_hash NULL
85926 +_002022_hash iwl_dbgfs_reply_tx_error_read 3 19205 _002022_hash NULL
85927 +_002023_hash iwl_dbgfs_rf_reset_read 3 26512 _002023_hash NULL
85928 +_002024_hash iwl_dbgfs_rx_handlers_read 3 18708 _002024_hash NULL
85929 +_002025_hash iwl_dbgfs_rxon_filter_flags_read 3 28832 _002025_hash NULL
85930 +_002026_hash iwl_dbgfs_rxon_flags_read 3 20795 _002026_hash NULL
85931 +_002027_hash iwl_dbgfs_rx_queue_read 3 19943 _002027_hash NULL
85932 +_002028_hash iwl_dbgfs_sensitivity_read 3 63116 _002731_hash NULL nohasharray
85933 +_002029_hash iwl_dbgfs_sleep_level_override_read 3 3038 _002029_hash NULL
85934 +_002030_hash iwl_dbgfs_sram_read 3 44505 _002030_hash NULL
85935 +_002031_hash iwl_dbgfs_stations_read 3 9309 _002031_hash NULL
85936 +_002032_hash iwl_dbgfs_status_read 3 5171 _002032_hash NULL
85937 +_002033_hash iwl_dbgfs_temperature_read 3 29224 _002033_hash NULL
85938 +_002034_hash iwl_dbgfs_thermal_throttling_read 3 38779 _002034_hash NULL
85939 +_002035_hash iwl_dbgfs_tx_queue_read 3 4635 _002035_hash NULL
85940 +_002036_hash iwl_dbgfs_ucode_bt_stats_read 3 42820 _002036_hash NULL
85941 +_002037_hash iwl_dbgfs_ucode_general_stats_read 3 49199 _002037_hash NULL
85942 +_002038_hash iwl_dbgfs_ucode_rx_stats_read 3 58023 _002038_hash NULL
85943 +_002039_hash iwl_dbgfs_ucode_tracing_read 3 47983 _002039_hash &_000356_hash
85944 +_002040_hash iwl_dbgfs_ucode_tx_stats_read 3 31611 _002040_hash NULL
85945 +_002041_hash iwl_dbgfs_wowlan_sram_read 3 540 _002041_hash NULL
85946 +_002042_hash joydev_ioctl 2 33343 _002042_hash NULL
85947 +_002043_hash kernel_readv 3 35617 _002043_hash NULL
85948 +_002044_hash key_algorithm_read 3 57946 _002044_hash NULL
85949 +_002045_hash key_icverrors_read 3 20895 _002045_hash NULL
85950 +_002046_hash key_key_read 3 3241 _002046_hash NULL
85951 +_002047_hash key_replays_read 3 62746 _002047_hash NULL
85952 +_002048_hash key_rx_spec_read 3 12736 _002048_hash NULL
85953 +_002049_hash key_tx_spec_read 3 4862 _002049_hash NULL
85954 +_002050_hash __kfifo_to_user 3 36555 _002568_hash NULL nohasharray
85955 +_002051_hash __kfifo_to_user_r 3 39123 _002051_hash NULL
85956 +_002052_hash kmem_zalloc_greedy 2-3 65268 _002052_hash NULL
85957 +_002054_hash l1oip_socket_recv 6 56537 _002054_hash NULL
85958 +_002055_hash l2cap_build_cmd 4 48676 _002055_hash NULL
85959 +_002056_hash l2cap_chan_send 3 49995 _002056_hash NULL
85960 +_002057_hash l2cap_segment_sdu 4 48772 _002057_hash NULL
85961 +_002058_hash l2down_create 4 21755 _002058_hash NULL
85962 +_002059_hash l2tp_xmit_skb 3 42672 _002059_hash NULL
85963 +_002060_hash l2up_create 3 6430 _002060_hash NULL
85964 +_002061_hash lbs_debugfs_read 3 30721 _002061_hash NULL
85965 +_002062_hash lbs_dev_info 3 51023 _002062_hash NULL
85966 +_002063_hash lbs_host_sleep_read 3 31013 _002063_hash NULL
85967 +_002064_hash lbs_rdbbp_read 3 45805 _002064_hash NULL
85968 +_002065_hash lbs_rdmac_read 3 418 _002065_hash NULL
85969 +_002066_hash lbs_rdrf_read 3 41431 _002066_hash NULL
85970 +_002067_hash lbs_sleepparams_read 3 10840 _002067_hash NULL
85971 +_002068_hash lbs_threshold_read 5 21046 _002068_hash NULL
85972 +_002069_hash ldisc_receive 4 41516 _002069_hash NULL
85973 +_002070_hash libfc_vport_create 2 4415 _002070_hash NULL
85974 +_002073_hash lkdtm_debugfs_read 3 45752 _002073_hash NULL
85975 +_002074_hash llcp_sock_recvmsg 4 13556 _002074_hash NULL
85976 +_002075_hash long_retry_limit_read 3 59766 _002075_hash NULL
85977 +_002076_hash lpfc_debugfs_dif_err_read 3 36303 _002076_hash NULL
85978 +_002077_hash lpfc_debugfs_read 3 16566 _002077_hash NULL
85979 +_002078_hash lpfc_idiag_baracc_read 3 58466 _002972_hash NULL nohasharray
85980 +_002079_hash lpfc_idiag_ctlacc_read 3 33943 _002079_hash NULL
85981 +_002080_hash lpfc_idiag_drbacc_read 3 15948 _002080_hash NULL
85982 +_002081_hash lpfc_idiag_extacc_read 3 48301 _002081_hash NULL
85983 +_002082_hash lpfc_idiag_mbxacc_read 3 28061 _002082_hash NULL
85984 +_002083_hash lpfc_idiag_pcicfg_read 3 50334 _002083_hash NULL
85985 +_002084_hash lpfc_idiag_queacc_read 3 13950 _002084_hash NULL
85986 +_002085_hash lpfc_idiag_queinfo_read 3 55662 _002085_hash NULL
85987 +_002086_hash lro_gen_skb 6 2644 _002086_hash NULL
85988 +_002087_hash mac80211_format_buffer 2 41010 _002087_hash NULL
85989 +_002088_hash macvtap_alloc_skb 2-4-3 50629 _002088_hash NULL
85990 +_002091_hash macvtap_put_user 4 55609 _002091_hash NULL
85991 +_002092_hash macvtap_sendmsg 4 30629 _002092_hash NULL
85992 +_002093_hash mangle_packet 6-8 27864 _002093_hash NULL
85993 +_002095_hash manip_pkt 3 7741 _002095_hash NULL
85994 +_002096_hash mempool_create_kmalloc_pool 1 41650 _002096_hash NULL
85995 +_002097_hash mempool_create_page_pool 1 30189 _002097_hash NULL
85996 +_002098_hash mempool_create_slab_pool 1 62907 _002098_hash NULL
85997 +_002099_hash mgmt_device_found 10 14146 _002099_hash NULL
85998 +_002100_hash minstrel_stats_read 3 17290 _002100_hash NULL
85999 +_002101_hash mmc_ext_csd_read 3 13205 _002101_hash NULL
86000 +_002102_hash mon_bin_read 3 6841 _002102_hash NULL
86001 +_002103_hash mon_stat_read 3 25238 _002103_hash NULL
86002 +_002105_hash mqueue_read_file 3 6228 _002105_hash NULL
86003 +_002106_hash mwifiex_debug_read 3 53074 _002106_hash NULL
86004 +_002107_hash mwifiex_getlog_read 3 54269 _002107_hash NULL
86005 +_002108_hash mwifiex_info_read 3 53447 _002108_hash NULL
86006 +_002109_hash mwifiex_rdeeprom_read 3 51429 _002109_hash NULL
86007 +_002110_hash mwifiex_regrdwr_read 3 34472 _002110_hash NULL
86008 +_002111_hash named_prepare_buf 2 24532 _002111_hash NULL
86009 +_002112_hash nci_send_cmd 3 58206 _002112_hash NULL
86010 +_002113_hash netdev_alloc_skb_ip_align 2 40811 _002113_hash NULL
86011 +_002114_hash netpoll_send_udp 3 58955 _002114_hash NULL
86012 +_002115_hash nfcwilink_send_bts_cmd 3 10802 _002115_hash NULL
86013 +_002116_hash nf_nat_mangle_tcp_packet 5-7 8643 _002116_hash NULL
86014 +_002119_hash nfsd_vfs_read 6 62605 _002616_hash NULL nohasharray
86015 +_002120_hash nfsd_vfs_write 6 54577 _002120_hash NULL
86016 +_002121_hash nfs_idmap_lookup_id 2 10660 _002121_hash NULL
86017 +_002122_hash ntfs_rl_realloc 3 56831 _002122_hash &_000370_hash
86018 +_002123_hash ntfs_rl_realloc_nofail 3 32173 _002123_hash NULL
86019 +_002124_hash o2hb_debug_read 3 37851 _002124_hash NULL
86020 +_002125_hash o2net_debug_read 3 52105 _002125_hash NULL
86021 +_002126_hash ocfs2_control_read 3 56405 _002126_hash NULL
86022 +_002127_hash ocfs2_debug_read 3 14507 _002127_hash NULL
86023 +_002128_hash oom_adjust_read 3 25127 _002128_hash NULL
86024 +_002129_hash oom_score_adj_read 3 39921 _002426_hash NULL nohasharray
86025 +_002130_hash oprofilefs_str_to_user 3 42182 _002130_hash NULL
86026 +_002131_hash oprofilefs_ulong_to_user 3 11582 _002131_hash NULL
86027 +_002132_hash osd_req_add_get_attr_list 3 49278 _002132_hash NULL
86028 +_002133_hash _osd_req_list_objects 6 4204 _002133_hash NULL
86029 +_002134_hash osd_req_read_kern 5 59990 _002134_hash NULL
86030 +_002135_hash osd_req_write_kern 5 53486 _002135_hash NULL
86031 +_002136_hash osst_read 3 40237 _002136_hash NULL
86032 +_002137_hash p54_alloc_skb 3 34366 _002137_hash &_000485_hash
86033 +_002138_hash p54_init_common 1 23850 _002138_hash NULL
86034 +_002139_hash packet_alloc_skb 2-5-4 62602 _002139_hash NULL
86035 +_002142_hash packet_sendmsg 4 24954 _002142_hash NULL
86036 +_002143_hash page_readlink 3 23346 _002143_hash NULL
86037 +_002144_hash pcf50633_write_block 3 2124 _002144_hash NULL
86038 +_002145_hash pcpu_alloc_alloc_info 1-2 45813 _002145_hash NULL
86039 +_002147_hash pep_indicate 5 38611 _002147_hash NULL
86040 +_002148_hash pep_reply 5 50582 _002148_hash NULL
86041 +_002149_hash pipe_handler_request 5 50774 _003582_hash NULL nohasharray
86042 +_002150_hash platform_list_read_file 3 34734 _002150_hash NULL
86043 +_002151_hash pm860x_bulk_write 3 43875 _002151_hash NULL
86044 +_002152_hash pm_qos_power_read 3 55891 _002152_hash NULL
86045 +_002153_hash port_show_regs 3 5904 _002153_hash NULL
86046 +_002154_hash proc_coredump_filter_read 3 39153 _002154_hash NULL
86047 +_002155_hash proc_fdinfo_read 3 62043 _002155_hash NULL
86048 +_002156_hash proc_file_read 3 53905 _002156_hash NULL
86049 +_002157_hash proc_info_read 3 63344 _002157_hash NULL
86050 +_002158_hash proc_loginuid_read 3 15631 _002158_hash NULL
86051 +_002159_hash proc_pid_attr_read 3 10173 _002159_hash NULL
86052 +_002160_hash proc_pid_readlink 3 52186 _002160_hash NULL
86053 +_002161_hash proc_read 3 43614 _002161_hash NULL
86054 +_002162_hash proc_self_readlink 3 38094 _002162_hash NULL
86055 +_002163_hash proc_sessionid_read 3 6911 _002299_hash NULL nohasharray
86056 +_002164_hash provide_user_output 3 41105 _002164_hash NULL
86057 +_002165_hash pskb_network_may_pull 2 35336 _002165_hash NULL
86058 +_002166_hash pskb_pull 2 65005 _002166_hash NULL
86059 +_002167_hash pstore_file_read 3 57288 _002167_hash NULL
86060 +_002168_hash ql_process_mac_rx_page 4 15543 _002168_hash NULL
86061 +_002169_hash ql_process_mac_rx_skb 4 6689 _002169_hash NULL
86062 +_002170_hash queues_read 3 24877 _002170_hash NULL
86063 +_002171_hash raw_recvmsg 4 17277 _002171_hash NULL
86064 +_002172_hash rcname_read 3 25919 _002172_hash NULL
86065 +_002173_hash read_4k_modal_eeprom 3 30212 _002173_hash NULL
86066 +_002174_hash read_9287_modal_eeprom 3 59327 _002174_hash NULL
86067 +_002175_hash reada_find_extent 2 63486 _002175_hash NULL
86068 +_002176_hash read_def_modal_eeprom 3 14041 _002176_hash NULL
86069 +_002177_hash read_enabled_file_bool 3 37744 _002177_hash NULL
86070 +_002178_hash read_file_ani 3 23161 _002178_hash NULL
86071 +_002179_hash read_file_antenna 3 13574 _002179_hash NULL
86072 +_002180_hash read_file_base_eeprom 3 42168 _002180_hash NULL
86073 +_002181_hash read_file_beacon 3 32595 _002181_hash NULL
86074 +_002182_hash read_file_blob 3 57406 _002182_hash NULL
86075 +_002183_hash read_file_bool 3 4180 _002183_hash NULL
86076 +_002184_hash read_file_credit_dist_stats 3 54367 _002184_hash NULL
86077 +_002185_hash read_file_debug 3 58256 _002185_hash NULL
86078 +_002186_hash read_file_disable_ani 3 6536 _002186_hash NULL
86079 +_002187_hash read_file_dma 3 9530 _002187_hash NULL
86080 +_002188_hash read_file_dump_nfcal 3 18766 _002188_hash NULL
86081 +_002189_hash read_file_frameerrors 3 64001 _002189_hash NULL
86082 +_002190_hash read_file_interrupt 3 61742 _002197_hash NULL nohasharray
86083 +_002191_hash read_file_misc 3 9948 _002191_hash NULL
86084 +_002192_hash read_file_modal_eeprom 3 39909 _002192_hash NULL
86085 +_002193_hash read_file_queue 3 40895 _002193_hash NULL
86086 +_002194_hash read_file_rcstat 3 22854 _002194_hash NULL
86087 +_002195_hash read_file_recv 3 48232 _002195_hash NULL
86088 +_002196_hash read_file_regidx 3 33370 _002196_hash NULL
86089 +_002197_hash read_file_regval 3 61742 _002197_hash &_002190_hash
86090 +_002198_hash read_file_reset 3 52310 _002198_hash NULL
86091 +_002199_hash read_file_rx_chainmask 3 41605 _002199_hash NULL
86092 +_002200_hash read_file_slot 3 50111 _002200_hash NULL
86093 +_002201_hash read_file_stations 3 35795 _002201_hash NULL
86094 +_002202_hash read_file_tgt_int_stats 3 20697 _002202_hash NULL
86095 +_002203_hash read_file_tgt_rx_stats 3 33944 _002203_hash NULL
86096 +_002204_hash read_file_tgt_stats 3 8959 _002204_hash NULL
86097 +_002205_hash read_file_tgt_tx_stats 3 51847 _002205_hash NULL
86098 +_002206_hash read_file_tx_chainmask 3 3829 _002206_hash NULL
86099 +_002207_hash read_file_war_stats 3 292 _002207_hash NULL
86100 +_002208_hash read_file_xmit 3 21487 _002208_hash NULL
86101 +_002209_hash read_flush_pipefs 3 20171 _002209_hash NULL
86102 +_002210_hash read_flush_procfs 3 27642 _002210_hash NULL
86103 +_002211_hash read_from_oldmem 2 3337 _002211_hash NULL
86104 +_002212_hash read_oldmem 3 55658 _002212_hash NULL
86105 +_002213_hash receive_packet 2 12367 _002213_hash NULL
86106 +_002214_hash regmap_name_read_file 3 39379 _002214_hash NULL
86107 +_002215_hash repair_io_failure 4 4815 _002215_hash NULL
86108 +_002216_hash request_key_and_link 4 42693 _002216_hash NULL
86109 +_002217_hash res_counter_read 4 33499 _002217_hash NULL
86110 +_002218_hash rfcomm_tty_write 3 51603 _002218_hash NULL
86111 +_002219_hash rs_sta_dbgfs_rate_scale_data_read 3 47165 _002219_hash NULL
86112 +_002220_hash rs_sta_dbgfs_scale_table_read 3 40262 _002220_hash NULL
86113 +_002221_hash rs_sta_dbgfs_stats_table_read 3 56573 _002221_hash NULL
86114 +_002222_hash rts_threshold_read 3 44384 _002222_hash NULL
86115 +_002223_hash rxrpc_sendmsg 4 29049 _002223_hash NULL
86116 +_002224_hash scrub_setup_recheck_block 3-4 56245 _002224_hash NULL
86117 +_002226_hash scsi_adjust_queue_depth 3 12802 _002226_hash NULL
86118 +_002227_hash sctp_make_abort 3 34459 _002227_hash NULL
86119 +_002228_hash sctp_make_asconf 3 4078 _002228_hash NULL
86120 +_002229_hash sctp_make_asconf_ack 3 31726 _002229_hash NULL
86121 +_002230_hash sctp_make_datafrag_empty 3 34737 _002230_hash NULL
86122 +_002231_hash sctp_make_fwdtsn 3 53265 _002231_hash NULL
86123 +_002232_hash sctp_make_heartbeat_ack 4 34411 _002232_hash NULL
86124 +_002233_hash sctp_make_init 4 58401 _002233_hash NULL
86125 +_002234_hash sctp_make_init_ack 4 3335 _002234_hash NULL
86126 +_002235_hash sctp_make_op_error_space 3 5528 _002235_hash NULL
86127 +_002236_hash sctp_manip_pkt 2 40620 _002236_hash NULL
86128 +_002237_hash selinux_inode_notifysecctx 3 36896 _002237_hash NULL
86129 +_002238_hash sel_read_avc_cache_threshold 3 33942 _002238_hash NULL
86130 +_002239_hash sel_read_avc_hash_stats 3 1984 _002239_hash NULL
86131 +_002240_hash sel_read_bool 3 24236 _002240_hash NULL
86132 +_002241_hash sel_read_checkreqprot 3 33068 _002241_hash NULL
86133 +_002242_hash sel_read_class 3 12669 _002960_hash NULL nohasharray
86134 +_002243_hash sel_read_enforce 3 2828 _002243_hash NULL
86135 +_002244_hash sel_read_handle_status 3 56139 _002244_hash NULL
86136 +_002245_hash sel_read_handle_unknown 3 57933 _002245_hash NULL
86137 +_002246_hash sel_read_initcon 3 32362 _002246_hash NULL
86138 +_002247_hash sel_read_mls 3 25369 _002247_hash NULL
86139 +_002248_hash sel_read_perm 3 42302 _002248_hash NULL
86140 +_002249_hash sel_read_policy 3 55947 _002249_hash NULL
86141 +_002250_hash sel_read_policycap 3 28544 _002250_hash NULL
86142 +_002251_hash sel_read_policyvers 3 55 _002827_hash NULL nohasharray
86143 +_002252_hash send_mpa_reject 3 7135 _002252_hash NULL
86144 +_002253_hash send_mpa_reply 3 32372 _002253_hash NULL
86145 +_002254_hash send_msg 4 37323 _002254_hash NULL
86146 +_002255_hash send_packet 4 52960 _002255_hash NULL
86147 +_002256_hash set_rxd_buffer_pointer 8 9950 _002256_hash NULL
86148 +_002257_hash sge_rx 3 50594 _002257_hash NULL
86149 +_002258_hash short_retry_limit_read 3 4687 _002258_hash NULL
86150 +_002259_hash simple_attr_read 3 24738 _002259_hash NULL
86151 +_002260_hash simple_transaction_read 3 17076 _002260_hash NULL
86152 +_002261_hash sisusbcon_bmove 5-7-6 21873 _002261_hash NULL
86153 +_002264_hash sisusbcon_clear 3-5-4 64329 _002264_hash NULL
86154 +_002267_hash sisusbcon_putcs 3 57630 _002267_hash &_001043_hash
86155 +_002268_hash sisusbcon_scroll 5-3-2 31315 _002268_hash NULL
86156 +_002269_hash sisusbcon_scroll_area 3-4 25899 _002269_hash NULL
86157 +_002271_hash skb_copy_datagram_const_iovec 2-5-4 48102 _002271_hash NULL
86158 +_002274_hash skb_copy_datagram_iovec 2-4 5806 _002274_hash NULL
86159 +_002276_hash skb_gro_header_slow 2 34958 _002276_hash NULL
86160 +_002277_hash smk_read_ambient 3 61220 _002277_hash NULL
86161 +_002278_hash smk_read_direct 3 15803 _002278_hash NULL
86162 +_002279_hash smk_read_doi 3 30813 _002279_hash NULL
86163 +_002280_hash smk_read_logging 3 37804 _002280_hash NULL
86164 +_002281_hash smk_read_mapped 3 7562 _002281_hash NULL
86165 +_002282_hash smk_read_onlycap 3 3855 _002282_hash NULL
86166 +_002283_hash smp_build_cmd 3 45853 _002283_hash NULL
86167 +_002284_hash snapshot_read 3 22601 _002284_hash NULL
86168 +_002285_hash snd_cs4281_BA0_read 5 6847 _002285_hash NULL
86169 +_002286_hash snd_cs4281_BA1_read 5 20323 _002286_hash NULL
86170 +_002287_hash snd_cs46xx_io_read 5 45734 _002287_hash NULL
86171 +_002288_hash snd_gus_dram_read 4 56686 _002288_hash NULL
86172 +_002289_hash snd_mixart_BA0_read 5 45069 _002289_hash NULL
86173 +_002290_hash snd_mixart_BA1_read 5 5082 _002290_hash NULL
86174 +_002291_hash snd_pcm_oss_read 3 28317 _002291_hash NULL
86175 +_002292_hash snd_pcm_plug_alloc 2 42339 _002292_hash NULL
86176 +_002293_hash snd_rawmidi_kernel_read 3 4328 _002293_hash NULL
86177 +_002294_hash snd_rawmidi_read 3 56337 _002294_hash NULL
86178 +_002295_hash snd_rme32_capture_copy 5 39653 _002295_hash NULL
86179 +_002296_hash snd_rme96_capture_copy 5 58484 _002296_hash NULL
86180 +_002297_hash snd_soc_hw_bulk_write_raw 4 14245 _002297_hash NULL
86181 +_002298_hash sock_alloc_send_skb 2 23720 _002298_hash NULL
86182 +_002299_hash spi_show_regs 3 6911 _002299_hash &_002163_hash
86183 +_002300_hash sta_agg_status_read 3 14058 _002300_hash NULL
86184 +_002301_hash sta_connected_time_read 3 17435 _002301_hash NULL
86185 +_002302_hash sta_flags_read 3 56710 _002302_hash NULL
86186 +_002303_hash sta_ht_capa_read 3 10366 _002303_hash NULL
86187 +_002304_hash sta_last_seq_ctrl_read 3 19106 _002304_hash NULL
86188 +_002305_hash sta_num_ps_buf_frames_read 3 1488 _002305_hash NULL
86189 +_002306_hash st_read 3 51251 _002306_hash NULL
86190 +_002307_hash supply_map_read_file 3 10608 _002307_hash NULL
86191 +_002308_hash sysfs_read_file 3 42113 _002308_hash NULL
86192 +_002309_hash sys_preadv 3 17100 _002309_hash NULL
86193 +_002310_hash sys_pwritev 3 41722 _002310_hash NULL
86194 +_002311_hash sys_readv 3 50664 _002311_hash NULL
86195 +_002312_hash sys_rt_sigpending 2 24961 _002312_hash NULL
86196 +_002313_hash sys_writev 3 28384 _002313_hash NULL
86197 +_002314_hash tcf_csum_skb_nextlayer 3 64025 _002314_hash NULL
86198 +_002315_hash tcp_fragment 3 20436 _002315_hash NULL
86199 +_002316_hash tcp_manip_pkt 2 14202 _002316_hash NULL
86200 +_002317_hash teiup_create 3 43201 _002317_hash NULL
86201 +_002318_hash test_iso_queue 5 62534 _002318_hash NULL
86202 +_002319_hash tg3_run_loopback 2 30093 _002319_hash NULL
86203 +_002320_hash tipc_msg_build 4 12326 _002320_hash NULL
86204 +_002321_hash TSS_authhmac 3 12839 _002321_hash NULL
86205 +_002322_hash TSS_checkhmac1 5 31429 _002322_hash NULL
86206 +_002323_hash TSS_checkhmac2 5-7 40520 _002323_hash NULL
86207 +_002325_hash tty_audit_log 8 47280 _002325_hash NULL
86208 +_002326_hash tty_buffer_request_room 2 23228 _002326_hash NULL
86209 +_002327_hash tty_insert_flip_string_fixed_flag 4 37428 _002327_hash NULL
86210 +_002328_hash tty_insert_flip_string_flags 4 30969 _002328_hash NULL
86211 +_002329_hash tty_prepare_flip_string 3 39955 _002329_hash NULL
86212 +_002330_hash tty_prepare_flip_string_flags 4 59240 _002330_hash NULL
86213 +_002331_hash tun_alloc_skb 2-4-3 41216 _002331_hash NULL
86214 +_002334_hash tun_sendmsg 4 10337 _002334_hash NULL
86215 +_002335_hash u32_array_read 3 2219 _002335_hash NULL
86216 +_002336_hash ubi_io_write_data 4-5 40305 _002336_hash NULL
86217 +_002338_hash udplite_manip_pkt 2 62433 _002338_hash NULL
86218 +_002339_hash udp_manip_pkt 2 50770 _002339_hash NULL
86219 +_002340_hash uhci_debug_read 3 5911 _002340_hash NULL
86220 +_002341_hash um_idi_read 3 850 _002341_hash NULL
86221 +_002342_hash unix_seqpacket_sendmsg 4 27893 _002342_hash NULL
86222 +_002343_hash unix_stream_recvmsg 4 35210 _002343_hash NULL
86223 +_002344_hash unlink_simple 3 47506 _002344_hash NULL
86224 +_002345_hash use_pool 2 64607 _002345_hash NULL
86225 +_002346_hash v9fs_fid_readn 4 60544 _002346_hash NULL
86226 +_002347_hash v9fs_file_read 3 40858 _002347_hash NULL
86227 +_002348_hash vhci_read 3 47878 _002348_hash NULL
86228 +_002349_hash vhost_add_used_and_signal_n 4 8038 _002349_hash NULL
86229 +_002350_hash vmbus_open 2-3 12154 _002350_hash NULL
86230 +_002352_hash vxge_rx_alloc 3 52024 _002352_hash NULL
86231 +_002353_hash waiters_read 3 40902 _002353_hash NULL
86232 +_002354_hash wm8994_bulk_write 3 13615 _002354_hash NULL
86233 +_002355_hash write_pbl 4 59583 _002355_hash NULL
86234 +_002356_hash wusb_prf_256 7 29203 _002356_hash NULL
86235 +_002357_hash wusb_prf_64 7 51065 _002357_hash NULL
86236 +_002358_hash _xfs_buf_alloc 3 38058 _002358_hash NULL
86237 +_002359_hash xfs_buf_read_uncached 3 42844 _002359_hash NULL
86238 +_002360_hash xfs_file_buffered_aio_write 4 11492 _002360_hash NULL
86239 +_002361_hash xfs_iext_add 3 41422 _002361_hash NULL
86240 +_002362_hash xfs_iext_remove_direct 3 40744 _002362_hash NULL
86241 +_002363_hash xfs_readdir 3 41200 _002363_hash NULL
86242 +_002364_hash xfs_trans_get_efd 3 51148 _002364_hash NULL
86243 +_002365_hash xfs_trans_get_efi 2 7898 _002365_hash NULL
86244 +_002366_hash xlog_bread_offset 3 60030 _002366_hash NULL
86245 +_002367_hash xlog_get_bp 2 23229 _002367_hash NULL
86246 +_002368_hash xz_dec_init 2 29029 _002368_hash NULL
86247 +_002369_hash aac_change_queue_depth 2 825 _002369_hash NULL
86248 +_002370_hash add_rx_skb 3 8257 _002370_hash NULL
86249 +_002371_hash afs_extract_data 5 50261 _002371_hash NULL
86250 +_002372_hash arcmsr_adjust_disk_queue_depth 2 16756 _002372_hash NULL
86251 +_002373_hash atalk_recvmsg 4 22053 _002373_hash NULL
86252 +_002374_hash ath6kl_buf_alloc 1 57304 _002374_hash NULL
86253 +_002376_hash atomic_read_file 3 16227 _002376_hash NULL
86254 +_002377_hash ax25_recvmsg 4 64441 _002377_hash NULL
86255 +_002378_hash batadv_add_packet 3 12136 _002378_hash NULL
86256 +_002379_hash batadv_iv_ogm_aggregate_new 2 54761 _002379_hash NULL
86257 +_002380_hash batadv_tt_response_fill_table 1 39236 _002380_hash NULL
86258 +_002381_hash beiscsi_process_async_pdu 7 39834 _002381_hash NULL
86259 +_002382_hash bioset_create 1 5580 _002382_hash NULL
86260 +_002383_hash bioset_integrity_create 2 62708 _002383_hash NULL
86261 +_002384_hash biovec_create_pools 2 9575 _002384_hash NULL
86262 +_002385_hash bnx2fc_process_l2_frame_compl 3 65072 _002385_hash NULL
86263 +_002386_hash brcmf_sdbrcm_died_dump 3 15841 _002386_hash NULL
86264 +_002387_hash brcmu_pkt_buf_get_skb 1 5556 _002387_hash NULL
86265 +_002388_hash br_send_bpdu 3 29669 _002388_hash NULL
86266 +_002389_hash btrfs_error_discard_extent 2 50444 _002389_hash NULL
86267 +_002390_hash __btrfs_free_reserved_extent 2 31207 _002390_hash NULL
86268 +_002391_hash btrfsic_cmp_log_and_dev_bytenr 2 49628 _002391_hash NULL
86269 +_002392_hash btrfsic_create_link_to_next_block 4 58246 _002392_hash NULL
86270 +_002393_hash btrfs_init_new_buffer 4 55761 _002393_hash NULL
86271 +_002394_hash btrfs_mksubvol 3 58240 _002394_hash NULL
86272 +_002395_hash bt_skb_send_alloc 2 6581 _002395_hash NULL
86273 +_002396_hash bt_sock_recvmsg 4 12316 _002396_hash NULL
86274 +_002397_hash bt_sock_stream_recvmsg 4 52518 _002397_hash NULL
86275 +_002398_hash c4iw_reject_cr 3 28174 _002398_hash NULL
86276 +_002399_hash caif_seqpkt_recvmsg 4 32241 _002399_hash NULL
86277 +_002400_hash carl9170_rx_copy_data 2 21656 _002400_hash NULL
86278 +_002401_hash cfpkt_append 3 61206 _002401_hash NULL
86279 +_002402_hash cfpkt_setlen 2 49343 _002402_hash NULL
86280 +_002403_hash cgroup_file_read 3 28804 _002403_hash NULL
86281 +_002404_hash cosa_net_setup_rx 2 38594 _002404_hash NULL
86282 +_002405_hash cpu_type_read 3 36540 _002405_hash NULL
86283 +_002406_hash cxgb4_pktgl_to_skb 2 61899 _002406_hash NULL
86284 +_002408_hash dccp_recvmsg 4 16056 _002408_hash NULL
86285 +_002409_hash ddp_clear_map 4 46152 _002409_hash NULL
86286 +_002410_hash ddp_set_map 4 751 _002410_hash NULL
86287 +_002411_hash depth_read 3 31112 _002411_hash NULL
86288 +_002412_hash dfs_global_file_read 3 7787 _002412_hash NULL
86289 +_002413_hash dgram_recvmsg 4 23104 _002413_hash NULL
86290 +_002414_hash diva_init_dma_map 3 58336 _002414_hash NULL
86291 +_002415_hash divas_write 3 63901 _002415_hash NULL
86292 +_002416_hash dma_push_rx 2 39973 _002416_hash NULL
86293 +_002417_hash dma_skb_copy_datagram_iovec 3-5 21516 _002417_hash NULL
86294 +_002419_hash dm_table_create 3 35687 _002419_hash NULL
86295 +_002420_hash dn_alloc_send_pskb 2 4465 _002420_hash NULL
86296 +_002421_hash dn_nsp_return_disc 2 60296 _002421_hash NULL
86297 +_002422_hash dn_nsp_send_disc 2 23469 _002422_hash NULL
86298 +_002423_hash dsp_tone_hw_message 3 17678 _002423_hash NULL
86299 +_002424_hash e1000_check_copybreak 3 62448 _002424_hash NULL
86300 +_002425_hash enable_read 3 2117 _002425_hash &_000224_hash
86301 +_002426_hash exofs_read_kern 6 39921 _002426_hash &_002129_hash
86302 +_002427_hash fast_rx_path 3 59214 _002427_hash NULL
86303 +_002428_hash fc_change_queue_depth 2 36841 _002428_hash NULL
86304 +_002429_hash fc_fcp_frame_alloc 2 12624 _002429_hash NULL
86305 +_002430_hash fcoe_ctlr_send_keep_alive 3 15308 _002430_hash NULL
86306 +_002431_hash frequency_read 3 64031 _003698_hash NULL nohasharray
86307 +_002432_hash ftdi_process_packet 5 45005 _002432_hash NULL
86308 +_002433_hash fuse_conn_congestion_threshold_read 3 51028 _002433_hash NULL
86309 +_002434_hash fuse_conn_max_background_read 3 10855 _002434_hash NULL
86310 +_002435_hash fwnet_incoming_packet 3 40380 _002435_hash NULL
86311 +_002436_hash fwnet_pd_new 4 39947 _003402_hash NULL nohasharray
86312 +_002437_hash get_alua_req 3 4166 _002437_hash NULL
86313 +_002438_hash get_rdac_req 3 45882 _002438_hash NULL
86314 +_002439_hash got_frame 2 16028 _002439_hash NULL
86315 +_002440_hash gsm_mux_rx_netchar 3 33336 _002440_hash NULL
86316 +_002441_hash hci_sock_recvmsg 4 7072 _002441_hash NULL
86317 +_002442_hash hdlcdev_rx 3 997 _002442_hash NULL
86318 +_002443_hash hdlc_empty_fifo 2 18397 _002443_hash NULL
86319 +_002444_hash hfc_empty_fifo 2 57972 _002444_hash NULL
86320 +_002445_hash hfcpci_empty_fifo 4 2427 _002445_hash NULL
86321 +_002446_hash hfcsusb_rx_frame 3 52745 _002446_hash NULL
86322 +_002447_hash hidp_output_raw_report 3 5629 _002447_hash NULL
86323 +_002448_hash hpsa_change_queue_depth 2 15449 _002448_hash NULL
86324 +_002449_hash hptiop_adjust_disk_queue_depth 2 20122 _002449_hash NULL
86325 +_002450_hash hscx_empty_fifo 2 13360 _002450_hash NULL
86326 +_002451_hash hysdn_rx_netpkt 3 16136 _002451_hash NULL
86327 +_002452_hash i2o_pool_alloc 4 55485 _002452_hash NULL
86328 +_002453_hash ide_queue_pc_tail 5 11673 _002453_hash NULL
86329 +_002454_hash ide_raw_taskfile 4 42355 _002454_hash NULL
86330 +_002455_hash idetape_queue_rw_tail 3 29562 _002455_hash NULL
86331 +_002456_hash ieee80211_amsdu_to_8023s 5 15561 _002456_hash NULL
86332 +_002457_hash ieee80211_fragment 4 33112 _002457_hash NULL
86333 +_002458_hash ieee80211_if_read_aid 3 9705 _002458_hash NULL
86334 +_002459_hash ieee80211_if_read_auto_open_plinks 3 38268 _002459_hash &_000374_hash
86335 +_002460_hash ieee80211_if_read_ave_beacon 3 64924 _002460_hash NULL
86336 +_002461_hash ieee80211_if_read_bssid 3 35161 _002461_hash NULL
86337 +_002462_hash ieee80211_if_read_channel_type 3 23884 _002462_hash NULL
86338 +_002463_hash ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 _002463_hash NULL
86339 +_002464_hash ieee80211_if_read_dot11MeshForwarding 3 13940 _002464_hash NULL
86340 +_002465_hash ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 _002465_hash NULL
86341 +_002466_hash ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 _002466_hash NULL
86342 +_002467_hash ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 _002467_hash NULL
86343 +_002468_hash ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout 3 17618 _002468_hash NULL
86344 +_002469_hash ieee80211_if_read_dot11MeshHWMPconfirmationInterval 3 57722 _002469_hash NULL
86345 +_002470_hash ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 _002470_hash NULL
86346 +_002471_hash ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 _002471_hash NULL
86347 +_002472_hash ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 _002472_hash NULL
86348 +_002473_hash ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 _002473_hash NULL
86349 +_002474_hash ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 _002474_hash NULL
86350 +_002475_hash ieee80211_if_read_dot11MeshHWMProotInterval 3 27873 _002475_hash NULL
86351 +_002476_hash ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 _002476_hash NULL
86352 +_002477_hash ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 _002477_hash NULL
86353 +_002478_hash ieee80211_if_read_dot11MeshMaxRetries 3 12756 _002478_hash NULL
86354 +_002479_hash ieee80211_if_read_dot11MeshRetryTimeout 3 52168 _002479_hash NULL
86355 +_002480_hash ieee80211_if_read_dot11MeshTTL 3 58307 _002480_hash NULL
86356 +_002481_hash ieee80211_if_read_dropped_frames_congestion 3 32603 _002481_hash NULL
86357 +_002482_hash ieee80211_if_read_dropped_frames_no_route 3 33383 _002482_hash NULL
86358 +_002483_hash ieee80211_if_read_dropped_frames_ttl 3 44500 _002483_hash NULL
86359 +_002484_hash ieee80211_if_read_drop_unencrypted 3 37053 _002484_hash NULL
86360 +_002485_hash ieee80211_if_read_dtim_count 3 38419 _002485_hash NULL
86361 +_002486_hash ieee80211_if_read_element_ttl 3 18869 _002486_hash NULL
86362 +_002487_hash ieee80211_if_read_estab_plinks 3 32533 _002487_hash NULL
86363 +_002488_hash ieee80211_if_read_flags 3 57470 _002919_hash NULL nohasharray
86364 +_002489_hash ieee80211_if_read_fwded_frames 3 36520 _002489_hash NULL
86365 +_002490_hash ieee80211_if_read_fwded_mcast 3 39571 _002490_hash &_000162_hash
86366 +_002491_hash ieee80211_if_read_fwded_unicast 3 59740 _002491_hash &_001697_hash
86367 +_002492_hash ieee80211_if_read_ht_opmode 3 29044 _002492_hash NULL
86368 +_002493_hash ieee80211_if_read_last_beacon 3 31257 _002493_hash NULL
86369 +_002494_hash ieee80211_if_read_min_discovery_timeout 3 13946 _002494_hash NULL
86370 +_002495_hash ieee80211_if_read_num_buffered_multicast 3 12716 _002495_hash NULL
86371 +_002496_hash ieee80211_if_read_num_mcast_sta 3 12419 _002496_hash NULL
86372 +_002497_hash ieee80211_if_read_num_sta_ps 3 34722 _002497_hash NULL
86373 +_002498_hash ieee80211_if_read_path_refresh_time 3 25545 _002498_hash NULL
86374 +_002499_hash ieee80211_if_read_peer 3 45233 _002499_hash NULL
86375 +_002500_hash ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 _002500_hash NULL
86376 +_002501_hash ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 _002501_hash NULL
86377 +_002502_hash ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 _002502_hash NULL
86378 +_002503_hash ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 _002503_hash NULL
86379 +_002504_hash ieee80211_if_read_rssi_threshold 3 49260 _002504_hash NULL
86380 +_002505_hash ieee80211_if_read_smps 3 27416 _002505_hash NULL
86381 +_002506_hash ieee80211_if_read_state 3 9813 _002707_hash NULL nohasharray
86382 +_002507_hash ieee80211_if_read_tkip_mic_test 3 19565 _002507_hash NULL
86383 +_002508_hash ieee80211_if_read_tsf 3 16420 _002508_hash NULL
86384 +_002509_hash ieee80211_if_read_uapsd_max_sp_len 3 15067 _002509_hash NULL
86385 +_002510_hash ieee80211_if_read_uapsd_queues 3 55150 _002510_hash NULL
86386 +_002511_hash ieee80211_mgmt_tx 9 46860 _002511_hash NULL
86387 +_002512_hash ieee80211_probereq_get 4-6 29069 _002512_hash NULL
86388 +_002514_hash ieee80211_rx_mgmt_beacon 3 24430 _002514_hash NULL
86389 +_002515_hash ieee80211_rx_mgmt_probe_resp 3 6918 _002515_hash NULL
86390 +_002516_hash ieee80211_send_auth 5 24121 _002516_hash NULL
86391 +_002517_hash ieee80211_set_probe_resp 3 10077 _002517_hash NULL
86392 +_002518_hash ieee80211_tdls_mgmt 8 9581 _002518_hash NULL
86393 +_002519_hash ima_show_htable_violations 3 10619 _002519_hash NULL
86394 +_002520_hash ima_show_measurements_count 3 23536 _002520_hash NULL
86395 +_002521_hash insert_one_name 7 61668 _002521_hash NULL
86396 +_002522_hash ip6_ufo_append_data 5-7-6 4780 _002522_hash NULL
86397 +_002525_hash ip_append_data 5-6 16942 _002525_hash NULL
86398 +_002526_hash ip_make_skb 5-6 13129 _002526_hash NULL
86399 +_002527_hash ip_nat_sdp_port 6 52938 _002527_hash NULL
86400 +_002528_hash ip_nat_sip_expect 7 45693 _002528_hash NULL
86401 +_002529_hash ipr_change_queue_depth 2 6431 _002529_hash NULL
86402 +_002530_hash ip_recv_error 3 23109 _002530_hash NULL
86403 +_002531_hash ip_ufo_append_data 6-8-7 12775 _002531_hash NULL
86404 +_002534_hash ipv6_recv_error 3 56347 _002534_hash NULL
86405 +_002535_hash ipv6_recv_rxpmtu 3 7142 _002535_hash NULL
86406 +_002536_hash ipw_packet_received_skb 2 1230 _002536_hash NULL
86407 +_002537_hash ipx_recvmsg 4 44366 _002537_hash NULL
86408 +_002538_hash irda_recvmsg_dgram 4 32631 _002538_hash NULL
86409 +_002539_hash iscsi_change_queue_depth 2 23416 _002539_hash NULL
86410 +_002540_hash iscsi_complete_pdu 4 48372 _002540_hash NULL
86411 +_002541_hash iwch_reject_cr 3 23901 _002541_hash NULL
86412 +_002542_hash ixgb_check_copybreak 3 5847 _002542_hash NULL
86413 +_002543_hash key_conf_hw_key_idx_read 3 25003 _002543_hash NULL
86414 +_002544_hash key_conf_keyidx_read 3 42443 _002544_hash NULL
86415 +_002545_hash key_conf_keylen_read 3 49758 _002545_hash NULL
86416 +_002546_hash key_flags_read 3 25931 _002546_hash NULL
86417 +_002547_hash key_ifindex_read 3 31411 _002547_hash NULL
86418 +_002548_hash key_tx_rx_count_read 3 44742 _002548_hash NULL
86419 +_002549_hash kmsg_read 3 46514 _002549_hash NULL
86420 +_002550_hash l1oip_socket_parse 4 4507 _002550_hash NULL
86421 +_002551_hash l2cap_send_cmd 4 14548 _002551_hash NULL
86422 +_002552_hash l2cap_sock_sendmsg 4 63427 _002552_hash NULL
86423 +_002553_hash l2tp_ip6_recvmsg 4 62874 _002553_hash NULL
86424 +_002554_hash l2tp_ip6_sendmsg 4 7461 _002554_hash NULL
86425 +_002555_hash l2tp_ip_recvmsg 4 22681 _002555_hash NULL
86426 +_002556_hash lbs_bcnmiss_read 3 8678 _002556_hash NULL
86427 +_002557_hash lbs_failcount_read 3 31063 _002557_hash NULL
86428 +_002558_hash lbs_highrssi_read 3 64089 _002558_hash NULL
86429 +_002559_hash lbs_highsnr_read 3 5931 _002559_hash NULL
86430 +_002560_hash lbs_lowrssi_read 3 32242 _002560_hash NULL
86431 +_002561_hash lbs_lowsnr_read 3 29571 _002561_hash NULL
86432 +_002563_hash llc_ui_recvmsg 4 3826 _002563_hash NULL
86433 +_002564_hash lowpan_fragment_xmit 3-4 22095 _002564_hash NULL
86434 +_002566_hash lpfc_change_queue_depth 2 25905 _002566_hash NULL
86435 +_002568_hash macvtap_do_read 4 36555 _002568_hash &_002050_hash
86436 +_002569_hash mangle_sdp_packet 9 36279 _002569_hash NULL
86437 +_002570_hash map_addr 6 4666 _002570_hash NULL
86438 +_002571_hash mcs_unwrap_fir 3 25733 _002571_hash NULL
86439 +_002572_hash mcs_unwrap_mir 3 9455 _002572_hash NULL
86440 +_002573_hash megaraid_change_queue_depth 2 64815 _002573_hash NULL
86441 +_002574_hash megasas_change_queue_depth 2 32747 _002574_hash NULL
86442 +_002575_hash mld_newpack 2 50950 _002575_hash NULL
86443 +_002576_hash mptscsih_change_queue_depth 2 26036 _002576_hash NULL
86444 +_002577_hash named_distribute 4 48544 _002577_hash NULL
86445 +_002578_hash NCR_700_change_queue_depth 2 31742 _002578_hash NULL
86446 +_002579_hash netlink_recvmsg 4 61600 _002579_hash NULL
86447 +_002580_hash nfc_alloc_send_skb 4 3167 _002580_hash NULL
86448 +_002581_hash nf_nat_ftp 5 47948 _002581_hash NULL
86449 +_002582_hash nfsctl_transaction_read 3 48250 _002582_hash NULL
86450 +_002583_hash nfsd_read 5 19568 _002583_hash NULL
86451 +_002584_hash nfsd_read_file 6 62241 _002584_hash NULL
86452 +_002585_hash nfsd_write 6 54809 _002585_hash NULL
86453 +_002586_hash nfs_map_group_to_gid 3 15892 _002586_hash NULL
86454 +_002587_hash nfs_map_name_to_uid 3 51132 _002587_hash NULL
86455 +_002588_hash nr_recvmsg 4 12649 _002588_hash NULL
86456 +_002589_hash ntfs_rl_append 2-4 6037 _002589_hash NULL
86457 +_002591_hash ntfs_rl_insert 2-4 4931 _002591_hash NULL
86458 +_002593_hash ntfs_rl_replace 2-4 14136 _002593_hash NULL
86459 +_002595_hash ntfs_rl_split 2-4 52328 _002595_hash NULL
86460 +_002597_hash osd_req_list_collection_objects 5 36664 _002597_hash NULL
86461 +_002598_hash osd_req_list_partition_objects 5 56464 _002598_hash NULL
86462 +_002599_hash osd_req_read_sg 5 47905 _002599_hash NULL
86463 +_002600_hash osd_req_write_sg 5 50908 _002600_hash NULL
86464 +_002602_hash p54_download_eeprom 4 43842 _002602_hash NULL
86465 +_002604_hash packet_recv_error 3 16669 _002604_hash NULL
86466 +_002605_hash packet_recvmsg 4 47700 _002605_hash NULL
86467 +_002606_hash pep_recvmsg 4 19402 _002606_hash NULL
86468 +_002607_hash pfkey_recvmsg 4 53604 _002607_hash NULL
86469 +_002608_hash ping_recvmsg 4 25597 _002608_hash NULL
86470 +_002609_hash pmcraid_change_queue_depth 2 9116 _002609_hash NULL
86471 +_002610_hash pn_recvmsg 4 30887 _002610_hash NULL
86472 +_002611_hash pointer_size_read 3 51863 _002611_hash NULL
86473 +_002612_hash power_read 3 15939 _002612_hash NULL
86474 +_002613_hash pppoe_recvmsg 4 15073 _002613_hash NULL
86475 +_002614_hash pppol2tp_recvmsg 4 57742 _002993_hash NULL nohasharray
86476 +_002615_hash ppp_tx_cp 5 62044 _002615_hash NULL
86477 +_002616_hash prism2_send_mgmt 4 62605 _002616_hash &_002119_hash
86478 +_002617_hash prism2_sta_send_mgmt 5 43916 _002617_hash NULL
86479 +_002618_hash prison_create 1 43623 _002618_hash NULL
86480 +_002619_hash qla2x00_adjust_sdev_qdepth_up 2 20097 _002619_hash NULL
86481 +_002620_hash qla2x00_change_queue_depth 2 24742 _002620_hash NULL
86482 +_002621_hash _queue_data 4 54983 _002621_hash NULL
86483 +_002622_hash raw_recvmsg 4 52529 _002622_hash NULL
86484 +_002623_hash rawsock_recvmsg 4 12144 _002623_hash NULL
86485 +_002624_hash rawv6_recvmsg 4 30265 _002624_hash NULL
86486 +_002625_hash rds_tcp_data_recv 3 53476 _002625_hash NULL
86487 +_002626_hash reada_add_block 2 54247 _002626_hash NULL
86488 +_002627_hash readahead_tree_block 3 36285 _002627_hash NULL
86489 +_002628_hash reada_tree_block_flagged 3 18402 _002628_hash NULL
86490 +_002629_hash read_dma 3 55086 _002629_hash NULL
86491 +_002630_hash read_fifo 3 826 _002630_hash NULL
86492 +_002631_hash read_tree_block 3 841 _002631_hash NULL
86493 +_002632_hash receive_copy 3 12216 _002632_hash NULL
86494 +_002633_hash recover_peb 6-7 29238 _002633_hash NULL
86495 +_002635_hash recv_msg 4 48709 _002635_hash NULL
86496 +_002636_hash recv_stream 4 30138 _002636_hash NULL
86497 +_002637_hash _req_append_segment 2 41031 _002637_hash NULL
86498 +_002638_hash request_key_async 4 6990 _002638_hash NULL
86499 +_002639_hash request_key_async_with_auxdata 4 46624 _002639_hash NULL
86500 +_002640_hash request_key_with_auxdata 4 24515 _002640_hash NULL
86501 +_002641_hash rose_recvmsg 4 2368 _002641_hash &_001788_hash
86502 +_002642_hash rtl8169_try_rx_copy 3 705 _002642_hash NULL
86503 +_002643_hash _rtl92s_firmware_downloadcode 3 14021 _002643_hash NULL
86504 +_002644_hash rx_data 4 60442 _002644_hash NULL
86505 +_002645_hash rxrpc_recvmsg 4 26233 _002645_hash NULL
86506 +_002646_hash sas_change_queue_depth 2 18555 _002646_hash NULL
86507 +_002647_hash scsi_activate_tcq 2 42640 _002647_hash NULL
86508 +_002648_hash scsi_deactivate_tcq 2 47086 _002648_hash NULL
86509 +_002649_hash scsi_execute 5 33596 _002649_hash NULL
86510 +_002650_hash _scsih_adjust_queue_depth 2 1083 _002650_hash NULL
86511 +_002651_hash scsi_init_shared_tag_map 2 59812 _002651_hash NULL
86512 +_002652_hash scsi_track_queue_full 2 44239 _002652_hash NULL
86513 +_002653_hash sctp_abort_pkt_new 5 55218 _002653_hash NULL
86514 +_002654_hash sctp_make_abort_violation 4 27959 _002654_hash NULL
86515 +_002655_hash sctp_make_op_error 5-6 7057 _002655_hash NULL
86516 +_002657_hash sctp_recvmsg 4 23265 _002657_hash NULL
86517 +_002658_hash send_stream 4 3397 _002658_hash NULL
86518 +_002659_hash sis190_try_rx_copy 3 57069 _002659_hash NULL
86519 +_002664_hash skb_copy_and_csum_datagram_iovec 2 24466 _002664_hash NULL
86520 +_002666_hash skge_rx_get 3 40598 _002666_hash NULL
86521 +_002667_hash smp_send_cmd 3 512 _002667_hash NULL
86522 +_002668_hash snd_gf1_mem_proc_dump 5 16926 _003499_hash NULL nohasharray
86523 +_002669_hash sta_dev_read 3 14782 _002669_hash NULL
86524 +_002670_hash sta_inactive_ms_read 3 25690 _002670_hash NULL
86525 +_002671_hash sta_last_signal_read 3 31818 _002671_hash NULL
86526 +_002672_hash stats_dot11ACKFailureCount_read 3 45558 _002672_hash NULL
86527 +_002673_hash stats_dot11FCSErrorCount_read 3 28154 _002673_hash NULL
86528 +_002674_hash stats_dot11RTSFailureCount_read 3 43948 _002674_hash NULL
86529 +_002675_hash stats_dot11RTSSuccessCount_read 3 33065 _002675_hash NULL
86530 +_002676_hash storvsc_connect_to_vsp 2 22 _002676_hash NULL
86531 +_002677_hash sys_msgrcv 3 959 _002677_hash NULL
86532 +_002678_hash sys_syslog 3 10746 _002678_hash NULL
86533 +_002679_hash tcf_csum_ipv4_icmp 3 9258 _002679_hash NULL
86534 +_002680_hash tcf_csum_ipv4_igmp 3 60446 _002680_hash NULL
86535 +_002681_hash tcf_csum_ipv4_tcp 4 39713 _002681_hash NULL
86536 +_002682_hash tcf_csum_ipv4_udp 4 30777 _002682_hash NULL
86537 +_002683_hash tcf_csum_ipv6_icmp 4 11738 _002683_hash NULL
86538 +_002684_hash tcf_csum_ipv6_tcp 4 54877 _002684_hash NULL
86539 +_002685_hash tcf_csum_ipv6_udp 4 25241 _002685_hash NULL
86540 +_002686_hash tcm_loop_change_queue_depth 2 42454 _002686_hash NULL
86541 +_002687_hash tcp_copy_to_iovec 3 28344 _002687_hash NULL
86542 +_002688_hash tcp_mark_head_lost 2 35895 _002688_hash NULL
86543 +_002689_hash tcp_match_skb_to_sack 4 23568 _002689_hash NULL
86544 +_002690_hash timeout_read 3 47915 _002690_hash NULL
86545 +_002691_hash tipc_multicast 5 49144 _002691_hash NULL
86546 +_002692_hash tipc_port_recv_sections 4 42890 _002692_hash NULL
86547 +_002693_hash tipc_port_reject_sections 5 55229 _002693_hash NULL
86548 +_002694_hash total_ps_buffered_read 3 16365 _002694_hash NULL
86549 +_002695_hash tso_fragment 3 29050 _002695_hash NULL
86550 +_002696_hash tty_insert_flip_string 3 34042 _002696_hash NULL
86551 +_002698_hash tun_put_user 4 59849 _002698_hash NULL
86552 +_002699_hash twa_change_queue_depth 2 48808 _002699_hash NULL
86553 +_002700_hash tw_change_queue_depth 2 11116 _002700_hash NULL
86554 +_002701_hash twl_change_queue_depth 2 41342 _002701_hash NULL
86555 +_002702_hash ubi_eba_atomic_leb_change 5 60379 _002702_hash NULL
86556 +_002703_hash ubi_eba_write_leb 5-6 36029 _002703_hash NULL
86557 +_002705_hash ubi_eba_write_leb_st 5 44343 _002705_hash NULL
86558 +_002706_hash udp_recvmsg 4 42558 _002706_hash NULL
86559 +_002707_hash udpv6_recvmsg 4 9813 _002707_hash &_002506_hash
86560 +_002708_hash udpv6_sendmsg 4 22316 _002708_hash NULL
86561 +_002709_hash ulong_read_file 3 42304 _002709_hash &_000522_hash
86562 +_002710_hash unix_dgram_recvmsg 4 14952 _002710_hash NULL
86563 +_002711_hash user_power_read 3 39414 _002711_hash NULL
86564 +_002712_hash v9fs_direct_read 3 45546 _002712_hash NULL
86565 +_002713_hash v9fs_file_readn 4 36353 _002713_hash &_001799_hash
86566 +_002714_hash vcc_recvmsg 4 37198 _002714_hash NULL
86567 +_002715_hash velocity_rx_copy 2 34583 _002715_hash NULL
86568 +_002716_hash W6692_empty_Bfifo 2 47804 _002716_hash NULL
86569 +_002717_hash wep_iv_read 3 54744 _002717_hash NULL
86570 +_002718_hash x25_recvmsg 4 42777 _002718_hash NULL
86571 +_002719_hash xfs_buf_get_map 3 24522 _002719_hash NULL
86572 +_002720_hash xfs_file_aio_write 4 33234 _002720_hash NULL
86573 +_002721_hash xfs_iext_insert 3 18667 _002741_hash NULL nohasharray
86574 +_002722_hash xfs_iext_remove 3 50909 _002722_hash NULL
86575 +_002723_hash xlog_do_recovery_pass 3 21618 _002723_hash NULL
86576 +_002724_hash xlog_find_verify_log_record 2 18870 _002724_hash NULL
86577 +_002725_hash zd_mac_rx 3 38296 _002725_hash NULL
86578 +_002726_hash aircable_process_packet 5 46639 _002726_hash NULL
86579 +_002727_hash ath6kl_wmi_get_new_buf 1 52304 _002727_hash NULL
86580 +_002728_hash batadv_iv_ogm_queue_add 3 46319 _002728_hash NULL
86581 +_002729_hash batadv_receive_client_update_packet 3 41578 _002729_hash NULL
86582 +_002730_hash batadv_receive_server_sync_packet 3 26577 _002730_hash &_000494_hash
86583 +_002731_hash brcmf_alloc_pkt_and_read 2 63116 _002731_hash &_002028_hash
86584 +_002732_hash brcmf_sdcard_recv_buf 6 38179 _002732_hash NULL
86585 +_002733_hash brcmf_sdcard_rwdata 5 65041 _002733_hash NULL
86586 +_002734_hash brcmf_sdcard_send_buf 6 7713 _002734_hash NULL
86587 +_002735_hash brcmf_sdio_forensic_read 3 35311 _002735_hash &_001382_hash
86588 +_002736_hash btrfs_alloc_free_block 3 8986 _002736_hash NULL
86589 +_002737_hash btrfs_free_and_pin_reserved_extent 2 53016 _002737_hash NULL
86590 +_002738_hash btrfs_free_reserved_extent 2 9867 _002738_hash NULL
86591 +_002739_hash carl9170_handle_mpdu 3 11056 _002739_hash NULL
86592 +_002740_hash do_trimming 3 26952 _002740_hash NULL
86593 +_002741_hash edge_tty_recv 4 18667 _002741_hash &_002721_hash
86594 +_002742_hash fwnet_receive_packet 9 50537 _002742_hash NULL
86595 +_002743_hash gigaset_if_receive 3 4861 _002743_hash NULL
86596 +_002744_hash gsm_dlci_data 3 14155 _002744_hash NULL
86597 +_002745_hash handle_rx_packet 3 58993 _002745_hash NULL
86598 +_002746_hash HDLC_irq 2 8709 _002746_hash NULL
86599 +_002747_hash hdlc_rpr_irq 2 10240 _002747_hash NULL
86600 +_002749_hash ifx_spi_insert_flip_string 3 51752 _002749_hash NULL
86601 +_002753_hash ip_nat_sdp_media 8 23386 _002753_hash NULL
86602 +_002754_hash ip_send_unicast_reply 6 38714 _002754_hash NULL
86603 +_002756_hash ipwireless_network_packet_received 4 51277 _002756_hash NULL
86604 +_002757_hash ipwireless_tty_received 3 49154 _002757_hash NULL
86605 +_002758_hash iscsi_iser_recv 4 41948 _002758_hash NULL
86606 +_002759_hash l2cap_bredr_sig_cmd 3 49065 _002759_hash NULL
86607 +_002760_hash l2cap_sock_alloc_skb_cb 2 33532 _002760_hash NULL
86608 +_002761_hash l2cap_sock_recvmsg 4 59886 _002761_hash NULL
86609 +_002762_hash llcp_allocate_pdu 3 19866 _002762_hash NULL
86610 +_002763_hash macvtap_recvmsg 4 63949 _002763_hash NULL
86611 +_002764_hash osd_req_list_dev_partitions 4 60027 _002764_hash NULL
86612 +_002765_hash osd_req_list_partition_collections 5 38223 _002765_hash NULL
86613 +_002766_hash osst_do_scsi 4 44410 _002766_hash NULL
86614 +_002767_hash ping_sendmsg 4 3782 _002767_hash NULL
86615 +_002768_hash ppp_cp_event 6 2965 _002768_hash NULL
86616 +_002769_hash pty_write 3 44757 _002769_hash &_001733_hash
86617 +_002770_hash push_rx 3 28939 _002770_hash NULL
86618 +_002772_hash qla2x00_handle_queue_full 2 24365 _002772_hash NULL
86619 +_002773_hash qla4xxx_change_queue_depth 2 1268 _002773_hash NULL
86620 +_002774_hash rfcomm_sock_recvmsg 4 22227 _002774_hash NULL
86621 +_002775_hash scsi_execute_req 5 42088 _002775_hash NULL
86622 +_002776_hash _scsih_change_queue_depth 2 26230 _002776_hash NULL
86623 +_002777_hash sctp_sf_abort_violation 6 38380 _002777_hash NULL
86624 +_002778_hash send_to_tty 3 45141 _002778_hash NULL
86625 +_002780_hash sky2_receive 2 13407 _002780_hash NULL
86626 +_002781_hash spi_execute 5 28736 _002781_hash NULL
86627 +_002782_hash submit_inquiry 3 42108 _002782_hash NULL
86628 +_002783_hash tcp_dma_try_early_copy 3 4457 _002783_hash NULL
86629 +_002784_hash tcp_sacktag_walk 6 49703 _002784_hash NULL
86630 +_002785_hash tcp_write_xmit 2 64602 _002785_hash NULL
86631 +_002786_hash ti_recv 4 22027 _002786_hash NULL
86632 +_002787_hash tun_do_read 4 50800 _002787_hash NULL
86633 +_002788_hash ubi_leb_change 4 10289 _002788_hash NULL
86634 +_002789_hash ubi_leb_write 4-5 5478 _002789_hash NULL
86635 +_002791_hash udp_sendmsg 4 4492 _002791_hash NULL
86636 +_002792_hash unix_seqpacket_recvmsg 4 23062 _002792_hash &_000477_hash
86637 +_002793_hash v9fs_cached_file_read 3 2514 _002793_hash NULL
86638 +_002794_hash write_leb 5 36957 _002794_hash NULL
86639 +_002795_hash xfs_buf_read_map 3 40226 _002795_hash NULL
86640 +_002796_hash xfs_trans_get_buf_map 4 2927 _002796_hash NULL
86641 +_002797_hash xlog_do_log_recovery 3 17550 _002797_hash NULL
86642 +_002798_hash ath6kl_wmi_add_wow_pattern_cmd 4 12842 _002798_hash NULL
86643 +_002799_hash ath6kl_wmi_beginscan_cmd 8 25462 _002799_hash NULL
86644 +_002800_hash ath6kl_wmi_send_probe_response_cmd 6 31728 _002800_hash NULL
86645 +_002801_hash ath6kl_wmi_set_appie_cmd 5 39266 _002801_hash NULL
86646 +_002802_hash ath6kl_wmi_set_ie_cmd 6 37260 _002802_hash NULL
86647 +_002803_hash ath6kl_wmi_startscan_cmd 8 33674 _002803_hash NULL
86648 +_002804_hash ath6kl_wmi_test_cmd 3 27312 _002804_hash NULL
86649 +_002805_hash brcmf_sdbrcm_membytes 3-5 37324 _002805_hash NULL
86650 +_002807_hash brcmf_sdbrcm_read_control 3 22721 _002807_hash NULL
86651 +_002808_hash brcmf_tx_frame 3 20978 _002808_hash NULL
86652 +_002809_hash __carl9170_rx 3 56784 _002809_hash NULL
86653 +_002810_hash ch_do_scsi 4 31171 _002810_hash NULL
86654 +_002811_hash dbg_leb_change 4 23555 _002811_hash NULL
86655 +_002812_hash dbg_leb_write 4-5 63555 _002812_hash &_000971_hash
86656 +_002814_hash gluebi_write 3 27905 _002814_hash NULL
86657 +_002815_hash hdlc_irq_one 2 3944 _002815_hash NULL
86658 +_002819_hash iser_rcv_completion 2 8048 _002819_hash NULL
86659 +_002820_hash lock_loop 1 61681 _002820_hash NULL
86660 +_002821_hash process_rcvd_data 3 6679 _002821_hash NULL
86661 +_002822_hash brcmf_sdbrcm_bus_txctl 3 42492 _002822_hash NULL
86662 +_002823_hash carl9170_rx 3 13272 _002823_hash NULL
86663 +_002824_hash carl9170_rx_stream 3 1334 _002824_hash NULL
86664 +_002826_hash mpt_lan_receive_post_turbo 2 13592 _002826_hash NULL
86665 +_002827_hash padzero 1 55 _002827_hash &_002251_hash
86666 +_002828_hash scsi_mode_sense 5 16835 _002828_hash NULL
86667 +_002829_hash scsi_vpd_inquiry 4 30040 _002829_hash NULL
86668 +_002830_hash ses_recv_diag 4 47143 _002830_hash &_000679_hash
86669 +_002831_hash ses_send_diag 4 64527 _002831_hash NULL
86670 +_002832_hash tcp_push_one 2 48816 _002832_hash NULL
86671 +_002833_hash __tcp_push_pending_frames 2 48148 _002833_hash NULL
86672 +_002834_hash trim_bitmaps 3 24158 _002834_hash NULL
86673 +_002835_hash tun_recvmsg 4 48463 _002835_hash NULL
86674 +_002836_hash ubifs_leb_change 4 17789 _002836_hash NULL
86675 +_002837_hash ubifs_leb_write 4-5 22679 _002837_hash NULL
86676 +_002839_hash xfs_buf_readahead_map 3 44248 _002839_hash &_000851_hash
86677 +_002840_hash xfs_trans_read_buf_map 5 37487 _002840_hash NULL
86678 +_002841_hash xlog_do_recover 3 59789 _002841_hash NULL
86679 +_002842_hash btrfs_trim_block_group 3 28963 _002842_hash NULL
86680 +_002843_hash do_write_orph_node 2 64343 _002843_hash NULL
86681 +_002844_hash fix_unclean_leb 3 23188 _002844_hash NULL
86682 +_002845_hash fixup_leb 3 43256 _002845_hash NULL
86683 +_002846_hash recover_head 3 17904 _002846_hash NULL
86684 +_002847_hash scsi_get_vpd_page 4 51951 _002847_hash NULL
86685 +_002848_hash sd_do_mode_sense 5 11507 _002848_hash NULL
86686 +_002849_hash tcp_push 3 10680 _002849_hash NULL
86687 +_002850_hash ubifs_wbuf_write_nolock 3 64946 _002850_hash NULL
86688 +_002851_hash ubifs_write_node 3-5 11258 _002851_hash NULL
86689 +_002852_hash ubifs_recover_leb 3 60639 _002852_hash NULL
86690 +_002853_hash write_head 4 30481 _002853_hash NULL
86691 +_002854_hash write_node 4 33121 _002854_hash NULL
86692 +_002855_hash ubifs_recover_log_leb 3 12079 _002855_hash NULL
86693 +_002856_hash replay_log_leb 3 18704 _002856_hash NULL
86694 +_002857_hash alloc_cpu_rmap 1 65363 _002857_hash NULL
86695 +_002858_hash alloc_ebda_hpc 1-2 50046 _002858_hash NULL
86696 +_002860_hash alloc_sched_domains 1 28972 _002860_hash NULL
86697 +_002861_hash amthi_read 4 45831 _002861_hash NULL
86698 +_002862_hash bcm_char_read 3 31750 _002862_hash NULL
86699 +_002863_hash BcmCopySection 5 2035 _002863_hash NULL
86700 +_002864_hash buffer_from_user 3 51826 _002864_hash NULL
86701 +_002865_hash buffer_to_user 3 35439 _002865_hash NULL
86702 +_002866_hash card_send_command 3 40757 _002866_hash NULL
86703 +_002867_hash chd_dec_fetch_cdata 3 50926 _002867_hash NULL
86704 +_002868_hash copy_nodes_to_user 2 63807 _002868_hash NULL
86705 +_002869_hash create_log 2 8225 _002869_hash NULL
86706 +_002870_hash crystalhd_create_dio_pool 2 3427 _002870_hash NULL
86707 +_002871_hash crystalhd_user_data 3 18407 _002871_hash NULL
86708 +_002872_hash do_pages_stat 2 4437 _002872_hash NULL
86709 +_002873_hash do_read_log_to_user 4 3236 _002873_hash NULL
86710 +_002874_hash do_write_log_from_user 3 39362 _002874_hash NULL
86711 +_002875_hash evm_read_key 3 54674 _002875_hash NULL
86712 +_002876_hash evm_write_key 3 27715 _002876_hash NULL
86713 +_002877_hash fir16_create 3 5574 _002877_hash NULL
86714 +_002878_hash get_nodes 3 39012 _002878_hash NULL
86715 +_002879_hash __iio_allocate_kfifo 2-3 55738 _002879_hash NULL
86716 +_002881_hash __iio_allocate_sw_ring_buffer 3 4843 _002881_hash NULL
86717 +_002882_hash iio_debugfs_read_reg 3 60908 _002882_hash NULL
86718 +_002883_hash iio_debugfs_write_reg 3 22742 _002883_hash NULL
86719 +_002884_hash iio_device_alloc 1 41440 _002884_hash NULL
86720 +_002885_hash iio_event_chrdev_read 3 54757 _002885_hash NULL
86721 +_002886_hash iio_read_first_n_kfifo 2 57910 _002886_hash NULL
86722 +_002887_hash iio_read_first_n_sw_rb 2 51911 _002887_hash NULL
86723 +_002888_hash ioapic_setup_resources 1 35255 _002888_hash NULL
86724 +_002889_hash keymap_store 4 45406 _002889_hash NULL
86725 +_002890_hash line6_alloc_sysex_buffer 4 28225 _002890_hash NULL
86726 +_002891_hash line6_dumpreq_initbuf 3 53123 _002891_hash NULL
86727 +_002892_hash line6_midibuf_init 2 52425 _002892_hash NULL
86728 +_002893_hash _malloc 1 54077 _002893_hash NULL
86729 +_002894_hash mei_read 3 6507 _002894_hash NULL
86730 +_002895_hash mei_write 3 4005 _002895_hash NULL
86731 +_002896_hash msg_set 3 51725 _002896_hash NULL
86732 +_002897_hash newpart 6 47485 _002897_hash NULL
86733 +_002898_hash OS_kmalloc 1 36909 _002898_hash NULL
86734 +_002899_hash OS_mem_token_alloc 1 14276 _002899_hash NULL
86735 +_002900_hash packet_came 3 18072 _002900_hash NULL
86736 +_002901_hash pcpu_alloc_bootmem 2 62074 _002901_hash NULL
86737 +_002902_hash pcpu_build_alloc_info 1-3-2 41443 _002902_hash NULL
86738 +_002905_hash pcpu_get_vm_areas 3 50085 _002905_hash NULL
86739 +_002906_hash resource_from_user 3 30341 _002906_hash NULL
86740 +_002907_hash rtsx_read_cfg_seq 3-5 48139 _002907_hash NULL
86741 +_002909_hash rtsx_write_cfg_seq 3-5 27485 _002909_hash NULL
86742 +_002911_hash sca3000_read_data 4 57064 _002911_hash NULL
86743 +_002912_hash sca3000_read_first_n_hw_rb 2 11479 _002912_hash NULL
86744 +_002913_hash send_midi_async 3 57463 _002913_hash NULL
86745 +_002914_hash sep_create_dcb_dmatables_context 6 37551 _002914_hash NULL
86746 +_002915_hash sep_create_dcb_dmatables_context_kernel 6 49728 _002915_hash NULL
86747 +_002916_hash sep_create_msgarea_context 4 33829 _002916_hash NULL
86748 +_002917_hash sep_lli_table_secure_dma 2-3 64042 _002917_hash NULL
86749 +_002919_hash sep_lock_user_pages 2-3 57470 _002919_hash &_002488_hash
86750 +_002921_hash sep_prepare_input_output_dma_table_in_dcb 4-5-2-3 63087 _002921_hash NULL
86751 +_002923_hash sep_read 3 17161 _002923_hash NULL
86752 +_002924_hash TransmitTcb 4 12989 _002924_hash NULL
86753 +_002925_hash ValidateDSDParamsChecksum 3 63654 _002925_hash NULL
86754 +_002926_hash Wb35Reg_BurstWrite 4 62327 _002926_hash NULL
86755 +_002927_hash alloc_irq_cpu_rmap 1 28459 _002927_hash NULL
86756 +_002928_hash InterfaceTransmitPacket 3 42058 _002928_hash NULL
86757 +_002929_hash line6_dumpreq_init 3 34473 _002929_hash NULL
86758 +_002931_hash pcpu_embed_first_chunk 1-3-2 24224 _002931_hash NULL
86759 +_002933_hash pcpu_fc_alloc 2 11818 _002933_hash NULL
86760 +_002934_hash pcpu_page_first_chunk 1 20712 _002934_hash NULL
86761 +_002935_hash pod_alloc_sysex_buffer 3 31651 _002935_hash NULL
86762 +_002936_hash r8712_usbctrl_vendorreq 6 48489 _002936_hash NULL
86763 +_002937_hash r871x_set_wpa_ie 3 7000 _002937_hash NULL
86764 +_002938_hash sep_prepare_input_dma_table 2-3 2009 _002938_hash NULL
86765 +_002940_hash sep_prepare_input_output_dma_table 2-4-3 63429 _002940_hash NULL
86766 +_002943_hash sys_get_mempolicy 3 30379 _002943_hash NULL
86767 +_002944_hash sys_mbind 5 7990 _002944_hash NULL
86768 +_002945_hash sys_migrate_pages 2 39825 _002945_hash NULL
86769 +_002946_hash sys_move_pages 2 42626 _002946_hash NULL
86770 +_002947_hash sys_set_mempolicy 3 32608 _002947_hash NULL
86771 +_002948_hash variax_alloc_sysex_buffer 3 15237 _002948_hash NULL
86772 +_002949_hash vme_user_read 3 55338 _002949_hash NULL
86773 +_002950_hash vme_user_write 3 15587 _002950_hash NULL
86774 +_002954_hash variax_set_raw2 4 32374 _002954_hash NULL
86775 +_002955_hash copy_in_user 3 57502 _002955_hash NULL
86776 +_002956_hash __earlyonly_bootmem_alloc 2 23824 _002956_hash NULL
86777 +_002957_hash rfc4106_set_key 3 54519 _002957_hash NULL
86778 +_002958_hash sparse_early_usemaps_alloc_pgdat_section 2 62304 _002958_hash NULL
86779 +_002959_hash sparse_early_usemaps_alloc_node 4 9269 _002959_hash NULL
86780 +_002960_hash sparse_mem_maps_populate_node 4 12669 _002960_hash &_002242_hash
86781 +_002961_hash vmemmap_alloc_block 1 43245 _002961_hash NULL
86782 +_002962_hash sparse_early_mem_maps_alloc_node 4 36971 _002962_hash NULL
86783 +_002963_hash vmemmap_alloc_block_buf 1 61126 _002963_hash NULL
86784 +_002964_hash alloc_mr 1 45935 _002964_hash NULL
86785 +_002965_hash atomic_counters_read 3 48827 _002965_hash NULL
86786 +_002966_hash atomic_stats_read 3 36228 _002966_hash NULL
86787 +_002967_hash capabilities_read 3 58457 _002967_hash NULL
86788 +_002968_hash compat_core_sys_select 1 65285 _002968_hash NULL
86789 +_002969_hash compat_dccp_setsockopt 5 51263 _002969_hash NULL
86790 +_002970_hash compat_do_arpt_set_ctl 4 12184 _002970_hash NULL
86791 +_002971_hash compat_do_ip6t_set_ctl 4 3184 _002971_hash NULL
86792 +_002972_hash compat_do_ipt_set_ctl 4 58466 _002972_hash &_002078_hash
86793 +_002973_hash compat_filldir 3 32999 _002973_hash NULL
86794 +_002974_hash compat_filldir64 3 35354 _002974_hash NULL
86795 +_002975_hash compat_fillonedir 3 15620 _002975_hash NULL
86796 +_002976_hash compat_ip_setsockopt 5 13870 _003094_hash NULL nohasharray
86797 +_002977_hash compat_ipv6_setsockopt 5 20468 _002977_hash NULL
86798 +_002978_hash compat_mpctl_ioctl 2 45671 _002978_hash NULL
86799 +_002979_hash compat_raw_setsockopt 5 30634 _002979_hash NULL
86800 +_002980_hash compat_rawv6_setsockopt 5 4967 _002980_hash NULL
86801 +_002981_hash compat_rw_copy_check_uvector 3 22001 _003263_hash NULL nohasharray
86802 +_002982_hash compat_sock_setsockopt 5 23 _002982_hash NULL
86803 +_002983_hash compat_sys_get_mempolicy 3 31109 _002983_hash NULL
86804 +_002984_hash compat_sys_kexec_load 2 35674 _002984_hash NULL
86805 +_002985_hash compat_sys_keyctl 4 9639 _002985_hash NULL
86806 +_002986_hash compat_sys_mbind 5 36256 _002986_hash NULL
86807 +_002987_hash compat_sys_migrate_pages 2 3157 _002987_hash NULL
86808 +_002988_hash compat_sys_move_pages 2 5861 _002988_hash NULL
86809 +_002989_hash compat_sys_mq_timedsend 3 31060 _002989_hash NULL
86810 +_002990_hash compat_sys_msgrcv 2 7482 _002990_hash NULL
86811 +_002991_hash compat_sys_msgsnd 2 10738 _002991_hash NULL
86812 +_002992_hash compat_sys_semtimedop 3 3606 _002992_hash NULL
86813 +_002993_hash compat_sys_set_mempolicy 3 57742 _002993_hash &_002614_hash
86814 +_002994_hash __copy_in_user 3 34790 _002994_hash NULL
86815 +_002995_hash dev_counters_read 3 19216 _002995_hash NULL
86816 +_002996_hash dev_names_read 3 38509 _002996_hash NULL
86817 +_002997_hash driver_names_read 3 60399 _002997_hash NULL
86818 +_002998_hash driver_stats_read 3 8944 _002998_hash NULL
86819 +_002999_hash evdev_ioctl_compat 2 13851 _002999_hash NULL
86820 +_003000_hash evtchn_read 3 3569 _003000_hash NULL
86821 +_003001_hash evtchn_write 3 43278 _003001_hash NULL
86822 +_003002_hash fat_compat_ioctl_filldir 3 36328 _003002_hash NULL
86823 +_003003_hash flash_read 3 57843 _003003_hash NULL
86824 +_003004_hash flash_write 3 62354 _003004_hash NULL
86825 +_003005_hash fw_device_op_compat_ioctl 2 42804 _003005_hash NULL
86826 +_003006_hash gather_array 3 56641 _003006_hash NULL
86827 +_003007_hash ghash_async_setkey 3 60001 _003007_hash NULL
86828 +_003008_hash gntdev_alloc_map 2 35145 _003008_hash NULL
86829 +_003009_hash gnttab_map 2 56439 _003009_hash NULL
86830 +_003010_hash gru_alloc_gts 2-3 60056 _003010_hash &_000981_hash
86831 +_003012_hash hiddev_compat_ioctl 2 41255 _003012_hash NULL
86832 +_003013_hash init_cdev 1 8274 _003013_hash NULL
86833 +_003014_hash init_per_cpu 1 17880 _003014_hash NULL
86834 +_003015_hash ipath_create_cq 2 45586 _003015_hash NULL
86835 +_003016_hash ipath_get_base_info 3 7043 _003016_hash NULL
86836 +_003017_hash ipath_init_qp_table 2 25167 _003017_hash NULL
86837 +_003018_hash ipath_resize_cq 2 712 _003018_hash NULL
86838 +_003019_hash joydev_compat_ioctl 2 8765 _003019_hash NULL
86839 +_003020_hash mon_bin_compat_ioctl 3 50234 _003020_hash NULL
86840 +_003021_hash options_write 3 47243 _003021_hash NULL
86841 +_003022_hash portcntrs_1_read 3 47253 _003022_hash NULL
86842 +_003023_hash portcntrs_2_read 3 56586 _003023_hash NULL
86843 +_003024_hash portnames_read 3 41958 _003024_hash NULL
86844 +_003025_hash ptc_proc_write 3 12076 _003025_hash NULL
86845 +_003026_hash put_cmsg_compat 4 35937 _003026_hash NULL
86846 +_003027_hash qib_alloc_devdata 2 51819 _003027_hash NULL
86847 +_003028_hash qib_alloc_fast_reg_page_list 2 10507 _003028_hash NULL
86848 +_003029_hash qib_cdev_init 1 34778 _003029_hash NULL
86849 +_003030_hash qib_create_cq 2 27497 _003030_hash NULL
86850 +_003031_hash qib_diag_write 3 62133 _003031_hash NULL
86851 +_003032_hash qib_get_base_info 3 11369 _003032_hash NULL
86852 +_003033_hash qib_resize_cq 2 53090 _003033_hash NULL
86853 +_003034_hash qsfp_1_read 3 21915 _003034_hash NULL
86854 +_003035_hash qsfp_2_read 3 31491 _003035_hash NULL
86855 +_003036_hash queue_reply 3 22416 _003036_hash NULL
86856 +_003037_hash spidev_compat_ioctl 2 63778 _003037_hash NULL
86857 +_003038_hash split 2 11691 _003038_hash NULL
86858 +_003039_hash stats_read_ul 3 32751 _003039_hash NULL
86859 +_003040_hash sys32_ipc 3 7238 _003040_hash NULL
86860 +_003041_hash sys32_rt_sigpending 2 25814 _003041_hash NULL
86861 +_003042_hash tunables_read 3 36385 _003042_hash NULL
86862 +_003043_hash tunables_write 3 59563 _003043_hash NULL
86863 +_003044_hash xenbus_file_write 3 6282 _003044_hash NULL
86864 +_003045_hash xlbd_reserve_minors 1-2 18365 _003045_hash NULL
86865 +_003047_hash xpc_kmalloc_cacheline_aligned 1 42895 _003047_hash NULL
86866 +_003048_hash xpc_kzalloc_cacheline_aligned 1 65433 _003048_hash NULL
86867 +_003049_hash xsd_read 3 15653 _003049_hash NULL
86868 +_003050_hash compat_do_readv_writev 4 49102 _003050_hash NULL
86869 +_003051_hash compat_keyctl_instantiate_key_iov 3 57431 _003088_hash NULL nohasharray
86870 +_003052_hash compat_process_vm_rw 3-5 22254 _003052_hash NULL
86871 +_003054_hash compat_sys_select 1 16131 _003054_hash NULL
86872 +_003055_hash compat_sys_setsockopt 5 3326 _003055_hash NULL
86873 +_003056_hash compat_udp_setsockopt 5 38840 _003056_hash NULL
86874 +_003057_hash compat_udpv6_setsockopt 5 42981 _003057_hash NULL
86875 +_003058_hash do_compat_pselect 1 10398 _003058_hash NULL
86876 +_003059_hash gnttab_expand 1 15817 _003059_hash NULL
86877 +_003060_hash ipath_cdev_init 1 37752 _003060_hash NULL
86878 +_003061_hash ipath_reg_phys_mr 3 23918 _003061_hash &_000999_hash
86879 +_003062_hash qib_alloc_fast_reg_mr 2 12526 _003062_hash NULL
86880 +_003063_hash qib_reg_phys_mr 3 60202 _003063_hash &_000897_hash
86881 +_003064_hash compat_readv 3 30273 _003064_hash NULL
86882 +_003065_hash compat_sys_process_vm_readv 3-5 15374 _003065_hash NULL
86883 +_003067_hash compat_sys_process_vm_writev 3-5 41194 _003067_hash NULL
86884 +_003069_hash compat_sys_pselect6 1 14105 _003069_hash NULL
86885 +_003070_hash compat_writev 3 60063 _003070_hash NULL
86886 +_003071_hash get_free_entries 1 46030 _003071_hash NULL
86887 +_003072_hash compat_sys_preadv64 3 24283 _003072_hash NULL
86888 +_003073_hash compat_sys_pwritev64 3 51151 _003073_hash NULL
86889 +_003074_hash compat_sys_readv 3 20911 _003074_hash NULL
86890 +_003075_hash compat_sys_writev 3 5784 _003075_hash NULL
86891 +_003076_hash gnttab_alloc_grant_references 1 18240 _003076_hash NULL
86892 +_003077_hash compat_sys_preadv 3 583 _003077_hash NULL
86893 +_003078_hash compat_sys_pwritev 3 17886 _003078_hash NULL
86894 +_003079_hash aes_decrypt_fail_read 3 54815 _003079_hash NULL
86895 +_003080_hash aes_decrypt_interrupt_read 3 19910 _003080_hash NULL
86896 +_003081_hash aes_decrypt_packets_read 3 10155 _003081_hash NULL
86897 +_003082_hash aes_encrypt_fail_read 3 32562 _003082_hash NULL
86898 +_003083_hash aes_encrypt_interrupt_read 3 39919 _003083_hash NULL
86899 +_003084_hash aes_encrypt_packets_read 3 48666 _003084_hash NULL
86900 +_003085_hash agp_remap 2 30665 _003085_hash NULL
86901 +_003086_hash alloc_apertures 1 56561 _003086_hash NULL
86902 +_003087_hash allocate_probes 1 40204 _003087_hash NULL
86903 +_003088_hash alloc_ftrace_hash 1 57431 _003088_hash &_003051_hash
86904 +_003089_hash alloc_page_cgroup 1 2919 _003089_hash NULL
86905 +_003090_hash __alloc_preds 2 9492 _003090_hash NULL
86906 +_003091_hash __alloc_pred_stack 2 26687 _003091_hash NULL
86907 +_003092_hash alloc_sched_domains 1 47756 _003092_hash NULL
86908 +_003093_hash alloc_trace_probe 6 38720 _003093_hash NULL
86909 +_003094_hash alloc_trace_uprobe 3 13870 _003094_hash &_002976_hash
86910 +_003095_hash ath6kl_sdio_alloc_prep_scat_req 2 51986 _003095_hash NULL
86911 +_003096_hash ath6kl_usb_post_recv_transfers 2 32892 _003096_hash NULL
86912 +_003097_hash ath6kl_usb_submit_ctrl_in 6 32880 _003097_hash &_000795_hash
86913 +_003098_hash ath6kl_usb_submit_ctrl_out 6 9978 _003098_hash NULL
86914 +_003099_hash av7110_ipack_init 2 46655 _003099_hash NULL
86915 +_003100_hash av7110_vbi_write 3 34384 _003100_hash NULL
86916 +_003101_hash bin_uuid 3 28999 _003101_hash NULL
86917 +_003102_hash blk_dropped_read 3 4168 _003102_hash NULL
86918 +_003103_hash blk_msg_write 3 13655 _003103_hash NULL
86919 +_003104_hash brcmf_usbdev_qinit 2 19090 _003104_hash &_001715_hash
86920 +_003105_hash brcmf_usb_dl_cmd 4 53130 _003105_hash NULL
86921 +_003106_hash ci_ll_init 3 12930 _003106_hash NULL
86922 +_003107_hash ci_ll_write 4 3740 _003107_hash NULL
86923 +_003108_hash conf_read 3 55786 _003108_hash NULL
86924 +_003109_hash __copy_from_user_inatomic_nocache 3 49921 _003109_hash NULL
86925 +_003110_hash cx24116_writeregN 4 41975 _003110_hash NULL
86926 +_003111_hash cyttsp_probe 4 1940 _003111_hash NULL
86927 +_003112_hash dccpprobe_read 3 52549 _003112_hash NULL
86928 +_003113_hash ddb_input_read 3 9743 _003113_hash NULL
86929 +_003114_hash ddb_output_write 3 31902 _003114_hash NULL
86930 +_003115_hash __devres_alloc 2 25598 _003115_hash NULL
86931 +_003116_hash dma_rx_errors_read 3 52045 _003116_hash NULL
86932 +_003117_hash dma_rx_requested_read 3 65354 _003117_hash NULL
86933 +_003118_hash dma_tx_errors_read 3 46060 _003118_hash NULL
86934 +_003119_hash dma_tx_requested_read 3 16110 _003203_hash NULL nohasharray
86935 +_003120_hash do_dmabuf_dirty_sou 7 3017 _003120_hash NULL
86936 +_003121_hash do_surface_dirty_sou 7 39678 _003121_hash NULL
86937 +_003122_hash driver_state_read 3 17194 _003122_hash &_001511_hash
86938 +_003123_hash drm_agp_bind_pages 3 56748 _003123_hash NULL
86939 +_003124_hash drm_buffer_alloc 2 44405 _003124_hash NULL
86940 +_003125_hash drm_calloc_large 1-2 65421 _003125_hash NULL
86941 +_003127_hash drm_fb_helper_init 3-4 19044 _003127_hash NULL
86942 +_003129_hash drm_ht_create 2 18853 _003129_hash NULL
86943 +_003130_hash drm_ioctl 2 42813 _003130_hash NULL
86944 +_003131_hash drm_malloc_ab 1-2 16831 _003131_hash NULL
86945 +_003133_hash drm_mode_crtc_set_gamma_size 2 31881 _003133_hash NULL
86946 +_003134_hash drm_plane_init 6 28731 _003134_hash NULL
86947 +_003135_hash drm_property_create 4 51239 _003135_hash NULL
86948 +_003136_hash drm_property_create_blob 2 7414 _003136_hash NULL
86949 +_003137_hash drm_vblank_init 2 11362 _003137_hash NULL
86950 +_003138_hash drm_vmalloc_dma 1 14550 _003138_hash NULL
86951 +_003139_hash dvb_aplay 3 56296 _003139_hash NULL
86952 +_003140_hash dvb_ca_en50221_init 4 45718 _003140_hash NULL
86953 +_003141_hash dvb_ca_en50221_io_write 3 43533 _003141_hash NULL
86954 +_003142_hash dvb_dmxdev_set_buffer_size 2 55643 _003142_hash NULL
86955 +_003143_hash dvbdmx_write 3 19423 _003143_hash NULL
86956 +_003144_hash dvb_dvr_set_buffer_size 2 9840 _003144_hash NULL
86957 +_003145_hash dvb_net_sec 3 37884 _003145_hash NULL
86958 +_003146_hash dvb_play 3 50814 _003146_hash NULL
86959 +_003147_hash dvb_ringbuffer_pkt_read_user 2-5-3 4303 _003147_hash NULL
86960 +_003150_hash dvb_ringbuffer_read_user 3 56702 _003150_hash NULL
86961 +_003151_hash dvb_usercopy 2 14036 _003151_hash NULL
86962 +_003152_hash dw210x_op_rw 6 39915 _003152_hash NULL
86963 +_003153_hash edt_ft5x06_debugfs_raw_data_read 3 28002 _003153_hash NULL
86964 +_003154_hash em_canid_change 3 14150 _003154_hash NULL
86965 +_003155_hash event_calibration_read 3 21083 _003155_hash NULL
86966 +_003156_hash event_enable_read 3 7074 _003156_hash NULL
86967 +_003157_hash event_filter_read 3 23494 _003157_hash NULL
86968 +_003158_hash event_filter_write 3 56609 _003158_hash NULL
86969 +_003159_hash event_heart_beat_read 3 48961 _003159_hash NULL
86970 +_003160_hash event_id_read 3 64288 _003160_hash &_001300_hash
86971 +_003161_hash event_oom_late_read 3 61175 _003161_hash &_001054_hash
86972 +_003162_hash event_phy_transmit_error_read 3 10471 _003162_hash NULL
86973 +_003163_hash event_rx_mem_empty_read 3 40363 _003163_hash NULL
86974 +_003164_hash event_rx_mismatch_read 3 38518 _003164_hash NULL
86975 +_003165_hash event_rx_pool_read 3 25792 _003165_hash NULL
86976 +_003166_hash event_tx_stuck_read 3 19305 _003166_hash NULL
86977 +_003167_hash excessive_retries_read 3 60425 _003167_hash NULL
86978 +_003168_hash flexcop_device_kmalloc 1 54793 _003168_hash NULL
86979 +_003169_hash fm_send_cmd 5 39639 _003169_hash NULL
86980 +_003170_hash __fprog_create 2 41263 _003170_hash NULL
86981 +_003171_hash fq_codel_zalloc 1 15378 _003171_hash NULL
86982 +_003172_hash ftrace_pid_write 3 39710 _003172_hash NULL
86983 +_003173_hash ftrace_profile_read 3 21327 _003173_hash NULL
86984 +_003174_hash fw_stats_raw_read 3 1369 _003174_hash NULL
86985 +_003175_hash get_info 3 55681 _003175_hash NULL
86986 +_003176_hash __get_vm_area_node 1 55305 _003176_hash NULL
86987 +_003177_hash gpio_power_read 3 36059 _003177_hash NULL
86988 +_003178_hash h5_prepare_pkt 4 12085 _003178_hash NULL
86989 +_003179_hash hsc_msg_alloc 1 60990 _003179_hash NULL
86990 +_003180_hash hsc_write 3 55875 _003180_hash NULL
86991 +_003181_hash hsi_alloc_controller 1 41802 _003181_hash NULL
86992 +_003182_hash hsi_register_board_info 2 13820 _003182_hash NULL
86993 +_003183_hash hugetlb_cgroup_read 5 49259 _003183_hash NULL
86994 +_003184_hash i915_cache_sharing_read 3 24775 _003184_hash NULL
86995 +_003185_hash i915_cache_sharing_write 3 57961 _003185_hash NULL
86996 +_003186_hash i915_max_freq_read 3 20581 _003186_hash NULL
86997 +_003187_hash i915_max_freq_write 3 11350 _003187_hash NULL
86998 +_003188_hash i915_min_freq_read 3 38470 _003188_hash NULL
86999 +_003189_hash i915_min_freq_write 3 10981 _003189_hash NULL
87000 +_003190_hash i915_ring_stop_read 3 42549 _003190_hash &_000740_hash
87001 +_003191_hash i915_ring_stop_write 3 59010 _003191_hash NULL
87002 +_003192_hash i915_wedged_read 3 35474 _003192_hash NULL
87003 +_003193_hash i915_wedged_write 3 47771 _003193_hash NULL
87004 +_003194_hash ieee802154_alloc_device 1 13767 _003194_hash NULL
87005 +_003195_hash intel_sdvo_write_cmd 4 54377 _003195_hash &_000832_hash
87006 +_003196_hash isr_cmd_cmplt_read 3 53439 _003196_hash NULL
87007 +_003197_hash isr_commands_read 3 41398 _003197_hash NULL
87008 +_003198_hash isr_decrypt_done_read 3 49490 _003198_hash NULL
87009 +_003199_hash isr_dma0_done_read 3 8574 _003199_hash NULL
87010 +_003200_hash isr_dma1_done_read 3 48159 _003200_hash NULL
87011 +_003201_hash isr_fiqs_read 3 34687 _003201_hash NULL
87012 +_003202_hash isr_host_acknowledges_read 3 54136 _003202_hash NULL
87013 +_003203_hash isr_hw_pm_mode_changes_read 3 16110 _003203_hash &_003119_hash
87014 +_003204_hash isr_irqs_read 3 9181 _003204_hash NULL
87015 +_003205_hash isr_low_rssi_read 3 64789 _003205_hash NULL
87016 +_003206_hash isr_pci_pm_read 3 30271 _003206_hash NULL
87017 +_003207_hash isr_rx_headers_read 3 38325 _003207_hash NULL
87018 +_003208_hash isr_rx_mem_overflow_read 3 43025 _003208_hash NULL
87019 +_003209_hash isr_rx_procs_read 3 31804 _003209_hash NULL
87020 +_003210_hash isr_rx_rdys_read 3 35283 _003210_hash NULL
87021 +_003211_hash isr_tx_exch_complete_read 3 16103 _003211_hash NULL
87022 +_003212_hash isr_tx_procs_read 3 23084 _003212_hash NULL
87023 +_003213_hash isr_wakeups_read 3 49607 _003213_hash NULL
87024 +_003214_hash LoadBitmap 2 19658 _003214_hash NULL
87025 +_003215_hash mem_cgroup_read 5 22461 _003215_hash NULL
87026 +_003216_hash mic_calc_failure_read 3 59700 _003216_hash NULL
87027 +_003217_hash mic_rx_pkts_read 3 27972 _003217_hash NULL
87028 +_003218_hash __module_alloc 1 50004 _003218_hash NULL
87029 +_003219_hash module_alloc_update_bounds_rw 1 63233 _003219_hash NULL
87030 +_003220_hash module_alloc_update_bounds_rx 1 58634 _003220_hash NULL
87031 +_003221_hash mwifiex_usb_submit_rx_urb 2 54558 _003221_hash NULL
87032 +_003222_hash nfc_hci_hcp_message_tx 6 14534 _003222_hash NULL
87033 +_003223_hash nfc_hci_set_param 5 40697 _003223_hash NULL
87034 +_003224_hash nfc_shdlc_alloc_skb 2 12741 _003224_hash NULL
87035 +_003225_hash opera1_xilinx_rw 5 31453 _003225_hash NULL
87036 +_003226_hash persistent_ram_vmap 1-2 709 _003226_hash NULL
87037 +_003228_hash prctl_set_mm 3 64538 _003228_hash NULL
87038 +_003229_hash probe_kernel_write 3 17481 _003229_hash NULL
87039 +_003230_hash proc_fault_inject_read 3 36802 _003230_hash NULL
87040 +_003231_hash proc_fault_inject_write 3 21058 _003231_hash NULL
87041 +_003232_hash ps_pspoll_max_apturn_read 3 6699 _003232_hash NULL
87042 +_003233_hash ps_pspoll_timeouts_read 3 11776 _003233_hash NULL
87043 +_003234_hash ps_pspoll_utilization_read 3 5361 _003234_hash NULL
87044 +_003235_hash ps_upsd_max_apturn_read 3 19918 _003235_hash NULL
87045 +_003236_hash ps_upsd_max_sptime_read 3 63362 _003236_hash NULL
87046 +_003237_hash ps_upsd_timeouts_read 3 28924 _003237_hash NULL
87047 +_003238_hash ps_upsd_utilization_read 3 51669 _003238_hash NULL
87048 +_003239_hash ptp_filter_init 2 36780 _003239_hash NULL
87049 +_003240_hash pwr_disable_ps_read 3 13176 _003240_hash NULL
87050 +_003241_hash pwr_elp_enter_read 3 5324 _003241_hash NULL
87051 +_003242_hash pwr_enable_ps_read 3 17686 _003242_hash NULL
87052 +_003243_hash pwr_fix_tsf_ps_read 3 26627 _003243_hash NULL
87053 +_003244_hash pwr_missing_bcns_read 3 25824 _003244_hash NULL
87054 +_003245_hash pwr_power_save_off_read 3 18355 _003245_hash NULL
87055 +_003246_hash pwr_ps_enter_read 3 26935 _003246_hash &_000512_hash
87056 +_003247_hash pwr_rcvd_awake_beacons_read 3 50505 _003247_hash NULL
87057 +_003248_hash pwr_rcvd_beacons_read 3 52836 _003248_hash NULL
87058 +_003249_hash pwr_tx_without_ps_read 3 48423 _003249_hash NULL
87059 +_003250_hash pwr_tx_with_ps_read 3 60851 _003250_hash NULL
87060 +_003251_hash pwr_wake_on_host_read 3 26321 _003251_hash NULL
87061 +_003252_hash pwr_wake_on_timer_exp_read 3 22640 _003252_hash NULL
87062 +_003253_hash rb_simple_read 3 45972 _003253_hash NULL
87063 +_003254_hash read_file_dfs 3 43145 _003254_hash NULL
87064 +_003255_hash retry_count_read 3 52129 _003255_hash NULL
87065 +_003256_hash rx_dropped_read 3 44799 _003256_hash NULL
87066 +_003257_hash rx_fcs_err_read 3 62844 _003257_hash NULL
87067 +_003258_hash rx_hdr_overflow_read 3 64407 _003258_hash NULL
87068 +_003259_hash rx_hw_stuck_read 3 57179 _003259_hash NULL
87069 +_003260_hash rx_out_of_mem_read 3 10157 _003260_hash NULL
87070 +_003261_hash rx_path_reset_read 3 23801 _003261_hash NULL
87071 +_003262_hash rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 _003262_hash NULL
87072 +_003263_hash rxpipe_descr_host_int_trig_rx_data_read 3 22001 _003263_hash &_002981_hash
87073 +_003264_hash rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 _003264_hash NULL
87074 +_003265_hash rxpipe_rx_prep_beacon_drop_read 3 2403 _003265_hash NULL
87075 +_003266_hash rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 _003266_hash NULL
87076 +_003267_hash rx_reset_counter_read 3 58001 _003267_hash NULL
87077 +_003268_hash rx_xfr_hint_trig_read 3 40283 _003268_hash NULL
87078 +_003269_hash saa7146_vmalloc_build_pgtable 2 19780 _003269_hash NULL
87079 +_003270_hash sched_feat_write 3 55202 _003270_hash NULL
87080 +_003271_hash sd_alloc_ctl_entry 1 29708 _003271_hash NULL
87081 +_003272_hash shmem_pread_fast 3 34147 _003272_hash NULL
87082 +_003273_hash shmem_pread_slow 3 3198 _003273_hash NULL
87083 +_003274_hash shmem_pwrite_slow 3 31741 _003274_hash NULL
87084 +_003275_hash show_header 3 4722 _003275_hash &_000745_hash
87085 +_003276_hash stack_max_size_read 3 1445 _003276_hash NULL
87086 +_003277_hash subsystem_filter_read 3 62310 _003277_hash NULL
87087 +_003278_hash subsystem_filter_write 3 13022 _003278_hash NULL
87088 +_003279_hash swap_cgroup_swapon 2 13614 _003279_hash NULL
87089 +_003280_hash system_enable_read 3 25815 _003280_hash NULL
87090 +_003281_hash tda10048_writeregbulk 4 11050 _003281_hash NULL
87091 +_003282_hash tlbflush_read_file 3 64661 _003282_hash NULL
87092 +_003283_hash trace_options_core_read 3 47390 _003283_hash NULL
87093 +_003284_hash trace_options_read 3 11419 _003284_hash NULL
87094 +_003285_hash trace_parser_get_init 2 31379 _003285_hash NULL
87095 +_003286_hash traceprobe_probes_write 3 64969 _003286_hash NULL
87096 +_003287_hash trace_seq_to_user 3 65398 _003287_hash NULL
87097 +_003288_hash tracing_buffers_read 3 11124 _003288_hash NULL
87098 +_003289_hash tracing_clock_write 3 27961 _003289_hash NULL
87099 +_003290_hash tracing_cpumask_read 3 7010 _003290_hash NULL
87100 +_003291_hash tracing_ctrl_read 3 46922 _003291_hash NULL
87101 +_003292_hash tracing_entries_read 3 8345 _003292_hash NULL
87102 +_003293_hash tracing_max_lat_read 3 8890 _003293_hash NULL
87103 +_003294_hash tracing_read_dyn_info 3 45468 _003294_hash NULL
87104 +_003295_hash tracing_readme_read 3 16493 _003295_hash NULL
87105 +_003296_hash tracing_saved_cmdlines_read 3 21434 _003296_hash NULL
87106 +_003297_hash tracing_set_trace_read 3 44122 _003297_hash NULL
87107 +_003298_hash tracing_set_trace_write 3 57096 _003298_hash NULL
87108 +_003299_hash tracing_stats_read 3 34537 _003299_hash NULL
87109 +_003300_hash tracing_total_entries_read 3 62817 _003300_hash NULL
87110 +_003301_hash tracing_trace_options_write 3 153 _003301_hash NULL
87111 +_003302_hash tstats_write 3 60432 _003302_hash &_000009_hash
87112 +_003303_hash ttm_bo_fbdev_io 4 9805 _003303_hash NULL
87113 +_003304_hash ttm_bo_io 5 47000 _003304_hash NULL
87114 +_003305_hash ttm_dma_page_pool_free 2 34135 _003305_hash NULL
87115 +_003306_hash ttm_page_pool_free 2 61661 _003306_hash NULL
87116 +_003307_hash ttusb2_msg 4 3100 _003307_hash NULL
87117 +_003308_hash tx_internal_desc_overflow_read 3 47300 _003308_hash NULL
87118 +_003309_hash tx_queue_len_read 3 1463 _003309_hash NULL
87119 +_003310_hash tx_queue_status_read 3 44978 _003310_hash NULL
87120 +_003311_hash u_memcpya 2-3 30139 _003311_hash NULL
87121 +_003313_hash usb_allocate_stream_buffers 3 8964 _003313_hash NULL
87122 +_003314_hash vifs_state_read 3 33762 _003314_hash NULL
87123 +_003315_hash vmalloc_to_sg 2 58354 _003315_hash NULL
87124 +_003316_hash vm_map_ram 2 23078 _003316_hash &_001095_hash
87125 +_003317_hash vmw_execbuf_process 5 22885 _003317_hash NULL
87126 +_003318_hash vmw_fifo_reserve 2 12141 _003318_hash NULL
87127 +_003319_hash vmw_kms_present 9 38130 _003319_hash NULL
87128 +_003320_hash vmw_kms_readback 6 5727 _003320_hash NULL
87129 +_003321_hash wep_addr_key_count_read 3 20174 _003321_hash NULL
87130 +_003322_hash wep_decrypt_fail_read 3 58567 _003322_hash NULL
87131 +_003323_hash wep_default_key_count_read 3 43035 _003323_hash NULL
87132 +_003324_hash wep_interrupt_read 3 41492 _003324_hash NULL
87133 +_003325_hash wep_key_not_found_read 3 13377 _003325_hash &_000952_hash
87134 +_003326_hash wep_packets_read 3 18751 _003326_hash NULL
87135 +_003327_hash wl1251_cmd_template_set 4 6172 _003327_hash NULL
87136 +_003328_hash wl1271_format_buffer 2 20834 _003328_hash NULL
87137 +_003329_hash wl1271_rx_filter_alloc_field 5 46721 _003329_hash NULL
87138 +_003330_hash wl12xx_cmd_build_probe_req 6-8 54946 _003330_hash NULL
87139 +_003332_hash wlcore_alloc_hw 1 7785 _003332_hash NULL
87140 +_003333_hash aggr_size_rx_size_read 3 33526 _003333_hash NULL
87141 +_003334_hash aggr_size_tx_agg_vs_rate_read 3 21438 _003334_hash NULL
87142 +_003335_hash alloc_and_copy_ftrace_hash 1 29368 _003335_hash NULL
87143 +_003336_hash alloc_bulk_urbs_generic 5 12127 _003336_hash NULL
87144 +_003337_hash alloc_ieee80211 1 20063 _003337_hash NULL
87145 +_003338_hash alloc_ieee80211_rsl 1 34564 _003338_hash NULL
87146 +_003339_hash alloc_perm_bits 2 1532 _003339_hash NULL
87147 +_003340_hash alloc_private 2 22399 _003340_hash NULL
87148 +_003341_hash alloc_rtllib 1 51136 _003341_hash NULL
87149 +_003342_hash alloc_rx_desc_ring 2 18016 _003342_hash NULL
87150 +_003343_hash arcfb_write 3 8702 _003343_hash NULL
87151 +_003344_hash ath6kl_usb_bmi_read 3 48745 _003344_hash NULL
87152 +_003345_hash ath6kl_usb_bmi_write 3 2454 _003345_hash &_001020_hash
87153 +_003346_hash ath6kl_usb_ctrl_msg_exchange 4 33327 _003346_hash NULL
87154 +_003347_hash au0828_init_isoc 2-3 61917 _003347_hash NULL
87155 +_003349_hash auok190xfb_write 3 37001 _003349_hash NULL
87156 +_003350_hash beacon_interval_read 3 7091 _003350_hash NULL
87157 +_003351_hash brcmf_usb_attach 1-2 44656 _003351_hash NULL
87158 +_003353_hash broadsheetfb_write 3 39976 _003353_hash NULL
87159 +_003354_hash broadsheet_spiflash_rewrite_sector 2 54864 _003354_hash NULL
87160 +_003355_hash ci13xxx_add_device 3 14456 _003355_hash NULL
87161 +_003356_hash cmpk_message_handle_tx 4 54024 _003356_hash NULL
87162 +_003357_hash comedi_alloc_subdevices 2 29207 _003357_hash NULL
87163 +_003358_hash comedi_buf_alloc 3 24822 _003358_hash NULL
87164 +_003359_hash comedi_read 3 13199 _003359_hash NULL
87165 +_003360_hash comedi_write 3 47926 _003360_hash NULL
87166 +_003361_hash create_trace_probe 1 20175 _003361_hash NULL
87167 +_003362_hash create_trace_uprobe 1 13184 _003362_hash NULL
87168 +_003363_hash cx18_copy_buf_to_user 4 22735 _003363_hash NULL
87169 +_003364_hash cx231xx_init_bulk 2-3 47024 _003364_hash NULL
87170 +_003366_hash cx231xx_init_isoc 2-3 56453 _003366_hash NULL
87171 +_003368_hash cx231xx_init_vbi_isoc 2-3 28053 _003368_hash NULL
87172 +_003370_hash da9052_group_write 3 4534 _003370_hash NULL
87173 +_003371_hash debug_debug1_read 3 8856 _003371_hash NULL
87174 +_003372_hash debug_debug2_read 3 30526 _003372_hash NULL
87175 +_003373_hash debug_debug3_read 3 56894 _003373_hash NULL
87176 +_003374_hash debug_debug4_read 3 61367 _003374_hash NULL
87177 +_003375_hash debug_debug5_read 3 2291 _003375_hash NULL
87178 +_003376_hash debug_debug6_read 3 33168 _003376_hash NULL
87179 +_003377_hash dev_read 3 56369 _003377_hash NULL
87180 +_003378_hash do_dmabuf_dirty_ldu 6 52241 _003378_hash NULL
87181 +_003379_hash drm_compat_ioctl 2 51717 _003379_hash NULL
87182 +_003380_hash drm_mode_create_tv_properties 2 23122 _003380_hash NULL
87183 +_003381_hash drm_property_create_bitmask 5 30195 _003381_hash NULL
87184 +_003382_hash drm_property_create_enum 5 29201 _003382_hash NULL
87185 +_003383_hash dsp_buffer_alloc 2 11684 _003383_hash NULL
87186 +_003384_hash dt3155_alloc_coherent 2 58073 _003384_hash NULL
87187 +_003385_hash dtim_interval_read 3 654 _003385_hash NULL
87188 +_003386_hash dvb_audio_write 3 51275 _003386_hash NULL
87189 +_003387_hash dvb_ca_en50221_io_ioctl 2 26490 _003387_hash NULL
87190 +_003388_hash dvb_ca_write 3 41171 _003388_hash NULL
87191 +_003389_hash dvb_demux_ioctl 2 42733 _003389_hash NULL
87192 +_003390_hash dvb_dmxdev_buffer_read 4 20682 _003390_hash NULL
87193 +_003391_hash dvb_dvr_ioctl 2 49182 _003391_hash NULL
87194 +_003392_hash dvb_generic_ioctl 2 21810 _003392_hash NULL
87195 +_003393_hash dvb_net_ioctl 2 61559 _003393_hash NULL
87196 +_003394_hash dvb_net_sec_callback 2 28786 _003394_hash NULL
87197 +_003396_hash dvb_video_write 3 754 _003396_hash NULL
87198 +_003397_hash dynamic_ps_timeout_read 3 10110 _003397_hash NULL
87199 +_003398_hash easycap_alsa_vmalloc 2 14426 _003398_hash NULL
87200 +_003399_hash em28xx_alloc_isoc 4 46892 _003399_hash NULL
87201 +_003400_hash error_error_bar_retry_read 3 64305 _003400_hash NULL
87202 +_003401_hash error_error_frame_cts_nul_flid_read 3 17262 _003401_hash NULL
87203 +_003402_hash error_error_frame_read 3 39947 _003402_hash &_002436_hash
87204 +_003403_hash error_error_null_Frame_tx_start_read 3 55024 _003403_hash NULL
87205 +_003404_hash error_error_numll_frame_cts_start_read 3 47781 _003404_hash NULL
87206 +_003405_hash ext_sd_execute_read_data 9 48589 _003405_hash NULL
87207 +_003406_hash ext_sd_execute_write_data 9 8175 _003406_hash NULL
87208 +_003407_hash fast_user_write 5 20494 _003407_hash NULL
87209 +_003408_hash f_audio_buffer_alloc 1 41110 _003408_hash NULL
87210 +_003409_hash fb_alloc_cmap_gfp 2 20792 _003409_hash NULL
87211 +_003410_hash fbcon_do_set_font 2-3 4079 _003410_hash NULL
87212 +_003412_hash fb_read 3 33506 _003412_hash NULL
87213 +_003413_hash fb_sys_read 3 13778 _003413_hash NULL
87214 +_003414_hash fb_sys_write 3 33130 _003414_hash NULL
87215 +_003415_hash fb_write 3 46924 _003415_hash NULL
87216 +_003416_hash firmwareUpload 3 32794 _003416_hash NULL
87217 +_003417_hash fmc_send_cmd 5 20435 _003417_hash NULL
87218 +_003418_hash fops_read 3 40672 _003418_hash NULL
87219 +_003419_hash forced_ps_read 3 31685 _003419_hash NULL
87220 +_003420_hash frame_alloc 4 15981 _003420_hash NULL
87221 +_003421_hash framebuffer_alloc 1 59145 _003421_hash NULL
87222 +_003422_hash ftrace_write 3 29551 _003422_hash NULL
87223 +_003423_hash fw_download_code 3 13249 _003423_hash NULL
87224 +_003424_hash fwSendNullPacket 2 54618 _003424_hash NULL
87225 +_003425_hash gdm_wimax_netif_rx 3 43423 _003425_hash &_001810_hash
87226 +_003426_hash get_vm_area 1 18080 _003426_hash NULL
87227 +_003427_hash __get_vm_area 1 61599 _003427_hash NULL
87228 +_003428_hash get_vm_area_caller 1 10527 _003428_hash NULL
87229 +_003429_hash __get_vm_area_caller 1 56416 _003828_hash NULL nohasharray
87230 +_003430_hash gspca_dev_probe2 4 59833 _003430_hash NULL
87231 +_003431_hash hdpvr_read 3 9273 _003431_hash NULL
87232 +_003432_hash hecubafb_write 3 26942 _003432_hash NULL
87233 +_003433_hash i915_compat_ioctl 2 3656 _003433_hash NULL
87234 +_003434_hash i915_gem_execbuffer_relocate_slow 7 25355 _003434_hash NULL
87235 +_003435_hash ieee80211_alloc_txb 1-2 52477 _003435_hash NULL
87236 +_003437_hash ieee80211_authentication_req 3 63973 _003437_hash NULL
87237 +_003438_hash ieee80211_wx_set_gen_ie 3 51399 _003438_hash NULL
87238 +_003439_hash ieee80211_wx_set_gen_ie_rsl 3 3521 _003458_hash NULL nohasharray
87239 +_003440_hash intel_sdvo_set_value 4 2311 _003440_hash NULL
87240 +_003441_hash ir_lirc_transmit_ir 3 64403 _003441_hash NULL
87241 +_003442_hash irq_blk_threshold_read 3 33666 _003442_hash NULL
87242 +_003443_hash irq_pkt_threshold_read 3 33356 _003443_hash &_000154_hash
87243 +_003444_hash irq_timeout_read 3 54653 _003444_hash NULL
87244 +_003445_hash ivtv_buf_copy_from_user 4 25502 _003445_hash NULL
87245 +_003446_hash ivtv_copy_buf_to_user 4 6159 _003446_hash NULL
87246 +_003447_hash ivtvfb_write 3 40023 _003447_hash NULL
87247 +_003448_hash kgdb_hex2mem 3 24755 _003448_hash NULL
87248 +_003449_hash lirc_buffer_init 2-3 53282 _003449_hash NULL
87249 +_003451_hash lirc_write 3 20604 _003451_hash NULL
87250 +_003452_hash mce_request_packet 3 1073 _003452_hash NULL
87251 +_003453_hash media_entity_init 2-4 15870 _003453_hash &_001742_hash
87252 +_003455_hash mem_fw_gen_free_mem_blks_read 3 11413 _003455_hash NULL
87253 +_003456_hash mem_fwlog_free_mem_blks_read 3 59616 _003456_hash NULL
87254 +_003457_hash mem_rx_free_mem_blks_read 3 675 _003457_hash NULL
87255 +_003458_hash mem_tx_free_mem_blks_read 3 3521 _003458_hash &_003439_hash
87256 +_003459_hash metronomefb_write 3 8823 _003459_hash NULL
87257 +_003460_hash mga_compat_ioctl 2 52170 _003460_hash NULL
87258 +_003461_hash mmio_read 4 40348 _003461_hash NULL
87259 +_003462_hash netlink_send 5 38434 _003462_hash NULL
87260 +_003463_hash nfc_hci_execute_cmd 5 43882 _003463_hash NULL
87261 +_003464_hash nfc_hci_send_event 5 21452 _003464_hash NULL
87262 +_003465_hash nfc_hci_send_response 5 56462 _003465_hash NULL
87263 +_003466_hash ni_gpct_device_construct 5 610 _003466_hash NULL
87264 +_003467_hash nouveau_compat_ioctl 2 28305 _003467_hash NULL
87265 +_003468_hash odev_update 2 50169 _003468_hash NULL
87266 +_003469_hash opera1_usb_i2c_msgxfer 4 64521 _003469_hash NULL
87267 +_003470_hash OSDSetBlock 2-4 38986 _003470_hash NULL
87268 +_003472_hash oz_add_farewell 5 20652 _003472_hash NULL
87269 +_003473_hash oz_cdev_read 3 20659 _003473_hash NULL
87270 +_003474_hash oz_cdev_write 3 33852 _003474_hash NULL
87271 +_003475_hash oz_ep_alloc 2 5587 _003475_hash NULL
87272 +_003476_hash oz_events_read 3 47535 _003476_hash NULL
87273 +_003477_hash persistent_ram_buffer_map 1-2 11332 _003477_hash NULL
87274 +_003479_hash pipeline_cs_rx_packet_in_read 3 37089 _003479_hash NULL
87275 +_003480_hash pipeline_cs_rx_packet_out_read 3 58926 _003480_hash NULL
87276 +_003481_hash pipeline_csum_to_rx_xfer_swi_read 3 15403 _003481_hash NULL
87277 +_003482_hash pipeline_dec_packet_in_fifo_full_read 3 33052 _003482_hash NULL
87278 +_003483_hash pipeline_dec_packet_in_read 3 47076 _003483_hash NULL
87279 +_003484_hash pipeline_dec_packet_out_read 3 54052 _003484_hash NULL
87280 +_003485_hash pipeline_defrag_to_csum_swi_read 3 63037 _003485_hash NULL
87281 +_003486_hash pipeline_enc_rx_stat_fifo_int_read 3 7107 _003486_hash NULL
87282 +_003487_hash pipeline_enc_tx_stat_fifo_int_read 3 14680 _003487_hash NULL
87283 +_003488_hash pipeline_hs_tx_stat_fifo_int_read 3 15642 _003488_hash &_001260_hash
87284 +_003489_hash pipeline_pipeline_fifo_full_read 3 34095 _003489_hash NULL
87285 +_003490_hash pipeline_post_proc_swi_read 3 24108 _003490_hash NULL
87286 +_003491_hash pipeline_pre_proc_swi_read 3 3898 _003491_hash NULL
87287 +_003492_hash pipeline_pre_to_defrag_swi_read 3 56321 _003492_hash NULL
87288 +_003493_hash pipeline_rx_complete_stat_fifo_int_read 3 40671 _003493_hash NULL
87289 +_003494_hash pipeline_sec_frag_swi_read 3 30294 _003494_hash NULL
87290 +_003495_hash pipeline_tcp_rx_stat_fifo_int_read 3 26745 _003495_hash NULL
87291 +_003496_hash pipeline_tcp_tx_stat_fifo_int_read 3 32589 _003496_hash NULL
87292 +_003497_hash play_iframe 3 8219 _003497_hash NULL
87293 +_003498_hash probes_write 3 29711 _003498_hash NULL
87294 +_003499_hash psb_unlocked_ioctl 2 16926 _003499_hash &_002668_hash
87295 +_003500_hash ps_poll_ps_poll_max_ap_turn_read 3 53140 _003500_hash NULL
87296 +_003501_hash ps_poll_ps_poll_timeouts_read 3 5934 _003501_hash NULL
87297 +_003502_hash ps_poll_ps_poll_utilization_read 3 39383 _003502_hash NULL
87298 +_003503_hash ps_poll_upsd_max_ap_turn_read 3 42050 _003503_hash NULL
87299 +_003504_hash ps_poll_upsd_timeouts_read 3 36755 _003504_hash NULL
87300 +_003505_hash ps_poll_upsd_utilization_read 3 28519 _003505_hash NULL
87301 +_003506_hash pvr2_ioread_read 3 10720 _003506_hash &_001669_hash
87302 +_003507_hash pvr2_ioread_set_sync_key 3 59882 _003507_hash NULL
87303 +_003508_hash pvr2_stream_buffer_count 2 33719 _003508_hash NULL
87304 +_003509_hash pwr_connection_out_of_sync_read 3 35061 _003509_hash NULL
87305 +_003510_hash pwr_cont_miss_bcns_spread_read 3 39250 _003515_hash NULL nohasharray
87306 +_003511_hash pwr_missing_bcns_cnt_read 3 45113 _003511_hash NULL
87307 +_003512_hash pwr_rcvd_awake_bcns_cnt_read 3 12632 _003512_hash NULL
87308 +_003513_hash pwr_rcvd_bcns_cnt_read 3 4774 _003513_hash NULL
87309 +_003514_hash qc_capture 3 19298 _003514_hash NULL
87310 +_003515_hash r128_compat_ioctl 2 39250 _003515_hash &_003510_hash
87311 +_003516_hash radeon_compat_ioctl 2 59150 _003516_hash NULL
87312 +_003517_hash radeon_kms_compat_ioctl 2 51371 _003517_hash NULL
87313 +_003518_hash Realloc 2 34961 _003518_hash NULL
87314 +_003519_hash redrat3_transmit_ir 3 64244 _003519_hash NULL
87315 +_003520_hash reg_w_buf 3 27724 _003520_hash NULL
87316 +_003521_hash reg_w_ixbuf 4 34736 _003521_hash NULL
87317 +_003522_hash rtllib_alloc_txb 1-2 21687 _003522_hash NULL
87318 +_003524_hash rtllib_authentication_req 3 26713 _003524_hash NULL
87319 +_003525_hash rtllib_wx_set_gen_ie 3 59808 _003525_hash NULL
87320 +_003526_hash rts51x_transfer_data_partial 6 5735 _003526_hash NULL
87321 +_003527_hash rvmalloc 1 46873 _003527_hash NULL
87322 +_003528_hash rx_decrypt_key_not_found_read 3 37820 _003528_hash NULL
87323 +_003529_hash rx_defrag_called_read 3 1897 _003529_hash NULL
87324 +_003530_hash rx_defrag_decrypt_failed_read 3 41411 _003530_hash NULL
87325 +_003531_hash rx_defrag_init_called_read 3 35935 _003531_hash NULL
87326 +_003532_hash rx_defrag_in_process_called_read 3 59338 _003532_hash NULL
87327 +_003533_hash rx_defrag_need_decrypt_read 3 42253 _003533_hash NULL
87328 +_003534_hash rx_defrag_need_defrag_read 3 28117 _003534_hash NULL
87329 +_003535_hash rx_defrag_tkip_called_read 3 21031 _003535_hash NULL
87330 +_003536_hash rx_filter_accum_arp_pend_requests_read 3 11003 _003536_hash NULL
87331 +_003537_hash rx_filter_arp_filter_read 3 61914 _003537_hash NULL
87332 +_003538_hash rx_filter_beacon_filter_read 3 49279 _003538_hash NULL
87333 +_003539_hash rx_filter_data_filter_read 3 30098 _003539_hash NULL
87334 +_003540_hash rx_filter_dup_filter_read 3 37238 _003540_hash NULL
87335 +_003541_hash rx_filter_ibss_filter_read 3 50167 _003541_hash NULL
87336 +_003542_hash rx_filter_max_arp_queue_dep_read 3 5851 _003542_hash NULL
87337 +_003543_hash rx_filter_mc_filter_read 3 25712 _003543_hash NULL
87338 +_003544_hash rx_filter_protection_filter_read 3 39282 _003544_hash NULL
87339 +_003545_hash rx_rate_rx_frames_per_rates_read 3 7282 _003545_hash NULL
87340 +_003546_hash rx_rx_beacon_early_term_read 3 21559 _003546_hash NULL
87341 +_003547_hash rx_rx_checksum_result_read 3 50617 _003547_hash NULL
87342 +_003548_hash rx_rx_cmplt_read 3 14753 _003548_hash NULL
87343 +_003549_hash rx_rx_cmplt_task_read 3 35226 _003549_hash NULL
87344 +_003550_hash rx_rx_defrag_end_read 3 505 _003550_hash NULL
87345 +_003551_hash rx_rx_defrag_read 3 2010 _003551_hash NULL
87346 +_003552_hash rx_rx_done_read 3 65217 _003552_hash NULL
87347 +_003553_hash rx_rx_dropped_frame_read 3 23748 _003553_hash NULL
87348 +_003554_hash rx_rx_frame_checksum_read 3 40140 _003554_hash NULL
87349 +_003555_hash rx_rx_hdr_overflow_read 3 35002 _003555_hash NULL
87350 +_003556_hash rx_rx_out_of_mpdu_nodes_read 3 64668 _003556_hash NULL
87351 +_003557_hash rx_rx_phy_hdr_read 3 20950 _003557_hash NULL
87352 +_003558_hash rx_rx_pre_complt_read 3 41653 _003558_hash NULL
87353 +_003559_hash rx_rx_timeout_read 3 62389 _003559_hash NULL
87354 +_003560_hash rx_rx_timeout_wa_read 3 50204 _003560_hash NULL
87355 +_003561_hash rx_rx_tkip_replays_read 3 60193 _003561_hash NULL
87356 +_003562_hash rx_rx_wa_ba_not_expected_read 3 61341 _003562_hash NULL
87357 +_003563_hash rx_rx_wa_density_dropped_frame_read 3 26095 _003563_hash NULL
87358 +_003564_hash rx_streaming_always_read 3 49401 _003564_hash NULL
87359 +_003565_hash rx_streaming_interval_read 3 55291 _003565_hash NULL
87360 +_003566_hash saa7164_buffer_alloc_user 2 9627 _003566_hash NULL
87361 +_003567_hash send_control_msg 6 48498 _003567_hash NULL
87362 +_003568_hash SendTxCommandPacket 3 42901 _003568_hash NULL
87363 +_003569_hash setup_window 2-7-5-4 59178 _003569_hash NULL
87364 +_003573_hash shmem_pwrite_fast 3 46842 _003573_hash NULL
87365 +_003574_hash sleep_auth_read 3 19159 _003574_hash NULL
87366 +_003575_hash sn9c102_read 3 29305 _003575_hash NULL
87367 +_003576_hash snd_pcm_alloc_vmalloc_buffer 2 44595 _003576_hash NULL
87368 +_003577_hash split_scan_timeout_read 3 20029 _003577_hash NULL
87369 +_003578_hash stk_prepare_sio_buffers 2 57168 _003578_hash NULL
87370 +_003579_hash store_debug_level 3 35652 _003579_hash NULL
87371 +_003580_hash suspend_dtim_interval_read 3 64971 _003580_hash NULL
87372 +_003581_hash sys_prctl 4 8766 _003581_hash NULL
87373 +_003582_hash tm6000_read_write_usb 7 50774 _003582_hash &_002149_hash
87374 +_003583_hash tracing_read_pipe 3 35312 _003583_hash NULL
87375 +_003584_hash ts_read 3 44687 _003584_hash NULL
87376 +_003585_hash ts_write 3 64336 _003585_hash NULL
87377 +_003586_hash tt3650_ci_msg 4 57219 _003586_hash NULL
87378 +_003587_hash ttm_object_device_init 2 10321 _003587_hash NULL
87379 +_003588_hash ttm_object_file_init 2 27804 _003588_hash NULL
87380 +_003589_hash tx_frag_bad_mblk_num_read 3 28064 _003589_hash NULL
87381 +_003590_hash tx_frag_cache_hit_read 3 29639 _003590_hash NULL
87382 +_003591_hash tx_frag_cache_miss_read 3 28394 _003591_hash NULL
87383 +_003592_hash tx_frag_called_read 3 1748 _003592_hash NULL
87384 +_003593_hash tx_frag_failed_read 3 43540 _003593_hash NULL
87385 +_003594_hash tx_frag_init_called_read 3 48377 _003594_hash NULL
87386 +_003595_hash tx_frag_in_process_called_read 3 1290 _003595_hash NULL
87387 +_003596_hash tx_frag_key_not_found_read 3 22971 _003596_hash NULL
87388 +_003597_hash tx_frag_mpdu_alloc_failed_read 3 41167 _003597_hash NULL
87389 +_003598_hash tx_frag_need_fragmentation_read 3 50153 _003598_hash NULL
87390 +_003599_hash tx_frag_tkip_called_read 3 31575 _003599_hash NULL
87391 +_003600_hash tx_tx_burst_programmed_read 3 20320 _003600_hash NULL
87392 +_003601_hash tx_tx_checksum_result_read 3 36490 _003601_hash &_001996_hash
87393 +_003602_hash tx_tx_cmplt_read 3 35854 _003602_hash NULL
87394 +_003603_hash tx_tx_data_prepared_read 3 43497 _003603_hash NULL
87395 +_003604_hash tx_tx_data_programmed_read 3 36871 _003604_hash NULL
87396 +_003605_hash tx_tx_done_data_read 3 6799 _003605_hash NULL
87397 +_003606_hash tx_tx_done_int_template_read 3 55511 _003606_hash &_001887_hash
87398 +_003607_hash tx_tx_done_template_read 3 35104 _003607_hash &_000106_hash
87399 +_003608_hash tx_tx_exch_expiry_read 3 8749 _003608_hash NULL
87400 +_003609_hash tx_tx_exch_pending_read 3 53018 _003609_hash NULL
87401 +_003610_hash tx_tx_exch_read 3 52986 _003610_hash NULL
87402 +_003611_hash tx_tx_frame_checksum_read 3 41553 _003611_hash NULL
87403 +_003612_hash tx_tx_imm_resp_read 3 55964 _003612_hash NULL
87404 +_003613_hash tx_tx_prepared_descs_read 3 9221 _003613_hash NULL
87405 +_003614_hash tx_tx_retry_data_read 3 1926 _003614_hash NULL
87406 +_003615_hash tx_tx_retry_template_read 3 57623 _003615_hash NULL
87407 +_003616_hash tx_tx_start_data_read 3 53219 _003616_hash NULL
87408 +_003617_hash tx_tx_start_fw_gen_read 3 58648 _003617_hash NULL
87409 +_003618_hash tx_tx_start_int_templates_read 3 58324 _003618_hash NULL
87410 +_003619_hash tx_tx_start_null_frame_read 3 6281 _003619_hash NULL
87411 +_003620_hash tx_tx_starts_read 3 3617 _003620_hash NULL
87412 +_003621_hash tx_tx_start_templates_read 3 17164 _003621_hash NULL
87413 +_003622_hash tx_tx_template_prepared_read 3 30424 _003622_hash NULL
87414 +_003623_hash tx_tx_template_programmed_read 3 30461 _003623_hash NULL
87415 +_003624_hash udi_log_event 3 58105 _003624_hash NULL
87416 +_003625_hash udl_prime_create 2 57159 _003625_hash NULL
87417 +_003626_hash uf_create_device_nodes 2 24948 _003626_hash NULL
87418 +_003627_hash uf_sme_queue_message 3 15697 _003627_hash NULL
87419 +_003628_hash ufx_alloc_urb_list 3 10349 _003628_hash NULL
87420 +_003629_hash unifi_net_data_malloc 3 24716 _003629_hash NULL
87421 +_003630_hash unifi_read 3 14899 _003630_hash NULL
87422 +_003631_hash unifi_write 3 65012 _003631_hash NULL
87423 +_003632_hash usb_buffer_alloc 2 36276 _003632_hash NULL
87424 +_003633_hash usbvision_rvmalloc 1 19655 _003633_hash NULL
87425 +_003634_hash usbvision_v4l2_read 3 34386 _003634_hash NULL
87426 +_003635_hash uvc_alloc_buffers 2-3 9656 _003635_hash NULL
87427 +_003637_hash uvc_alloc_entity 3-4 20836 _003637_hash NULL
87428 +_003639_hash uvc_debugfs_stats_read 3 56651 _003639_hash NULL
87429 +_003640_hash uvc_simplify_fraction 3 31303 _003640_hash NULL
87430 +_003641_hash v4l2_ctrl_new 7 24927 _003641_hash NULL
87431 +_003642_hash v4l2_event_subscribe 3 53687 _003642_hash NULL
87432 +_003643_hash v4l_stk_read 3 39672 _003643_hash NULL
87433 +_003644_hash __vb2_perform_fileio 3 63033 _003644_hash NULL
87434 +_003645_hash vfd_write 3 14717 _003645_hash NULL
87435 +_003646_hash vfio_config_do_rw 3 46091 _003646_hash NULL
87436 +_003647_hash vfio_msi_enable 2 20906 _003647_hash NULL
87437 +_003648_hash viafb_dvp0_proc_write 3 23023 _003648_hash NULL
87438 +_003649_hash viafb_dvp1_proc_write 3 48864 _003649_hash NULL
87439 +_003650_hash viafb_vt1636_proc_write 3 16018 _003650_hash NULL
87440 +_003651_hash __videobuf_alloc_vb 1 27062 _003651_hash NULL
87441 +_003652_hash __videobuf_alloc_vb 1 5665 _003652_hash NULL
87442 +_003653_hash __videobuf_copy_to_user 4 15423 _003653_hash NULL
87443 +_003654_hash videobuf_dma_init_kernel 3 6963 _003654_hash NULL
87444 +_003655_hash videobuf_pages_to_sg 2 3708 _003655_hash NULL
87445 +_003656_hash videobuf_vmalloc_to_sg 2 4548 _003656_hash NULL
87446 +_003657_hash video_usercopy 2 62151 _003657_hash NULL
87447 +_003658_hash virtscsi_alloc_tgt 2 6643 _003658_hash NULL
87448 +_003659_hash vmw_cursor_update_image 3-4 16332 _003659_hash NULL
87449 +_003661_hash vmw_framebuffer_dmabuf_dirty 6 37661 _003661_hash &_001116_hash
87450 +_003662_hash vmw_framebuffer_surface_dirty 6 48132 _003662_hash NULL
87451 +_003663_hash vmw_gmr2_bind 3 21305 _003663_hash NULL
87452 +_003664_hash vmw_unlocked_ioctl 2 19212 _003664_hash NULL
87453 +_003665_hash w9966_v4l_read 3 31148 _003665_hash NULL
87454 +_003666_hash wl1273_fm_fops_write 3 60621 _003666_hash NULL
87455 +_003667_hash zoran_write 3 22404 _003667_hash NULL
87456 +_003668_hash alloc_vm_area 1 15989 _003668_hash NULL
87457 +_003669_hash cx18_copy_mdl_to_user 4 45549 _003669_hash NULL
87458 +_003670_hash dlfb_ops_write 3 64150 _003670_hash NULL
87459 +_003671_hash dvb_demux_read 3 13981 _003671_hash NULL
87460 +_003672_hash dvb_dmxdev_read_sec 4 7892 _003672_hash NULL
87461 +_003673_hash dvb_dvr_read 3 17073 _003673_hash NULL
87462 +_003674_hash em28xx_init_isoc 4 62883 _003674_hash &_000729_hash
87463 +_003675_hash fb_alloc_cmap 2 6554 _003675_hash NULL
87464 +_003676_hash gspca_dev_probe 4 2570 _003676_hash NULL
87465 +_003677_hash ieee80211_auth_challenge 3 18810 _003677_hash NULL
87466 +_003678_hash ieee80211_rtl_auth_challenge 3 61897 _003678_hash NULL
87467 +_003679_hash init_pci_cap_msi_perm 2 59033 _003679_hash NULL
87468 +_003680_hash __ioremap_caller 1-2 21800 _003680_hash NULL
87469 +_003682_hash ivtv_read 3 57796 _003682_hash NULL
87470 +_003683_hash ivtv_v4l2_write 3 39226 _003683_hash NULL
87471 +_003684_hash mce_async_out 3 58056 _003684_hash NULL
87472 +_003685_hash mce_flush_rx_buffer 2 14976 _003685_hash NULL
87473 +_003686_hash ms_read_multiple_pages 4-5 8052 _003686_hash NULL
87474 +_003688_hash ms_write_multiple_pages 5-6 10362 _003688_hash NULL
87475 +_003690_hash nfc_hci_send_cmd 5 55714 _003690_hash NULL
87476 +_003691_hash persistent_ram_new 1-2 40501 _003691_hash NULL
87477 +_003693_hash picolcd_fb_write 3 2318 _003693_hash NULL
87478 +_003694_hash process_bulk_data_command 4 38906 _003694_hash NULL
87479 +_003695_hash pvr2_v4l2_read 3 18006 _003695_hash NULL
87480 +_003696_hash qcam_read 3 13977 _003696_hash NULL
87481 +_003697_hash register_unifi_sdio 2 55239 _003697_hash NULL
87482 +_003698_hash resize_async_buffer 4 64031 _003698_hash &_002431_hash
87483 +_003699_hash rtllib_auth_challenge 3 12493 _003699_hash NULL
87484 +_003702_hash stk_allocate_buffers 2 16291 _003702_hash NULL
87485 +_003703_hash subdev_ioctl 2 28417 _003703_hash NULL
87486 +_003704_hash _sys_packet_req 4 46793 _003704_hash NULL
87487 +_003705_hash tm6000_i2c_recv_regs16 5 2949 _003705_hash NULL
87488 +_003706_hash tm6000_i2c_recv_regs 5 46215 _003706_hash NULL
87489 +_003707_hash tm6000_i2c_send_regs 5 20250 _003707_hash NULL
87490 +_003708_hash tt3650_ci_msg_locked 4 8013 _003708_hash NULL
87491 +_003709_hash ufx_ops_write 3 54848 _003709_hash NULL
87492 +_003710_hash update_macheader 7 1775 _003710_hash NULL
87493 +_003711_hash usbdux_attach_common 4 51764 _003750_hash NULL nohasharray
87494 +_003712_hash usbduxfast_attach_common 4 52538 _003712_hash NULL
87495 +_003713_hash usbduxsigma_attach_common 4 40847 _003713_hash NULL
87496 +_003714_hash uvc_v4l2_ioctl 2 8411 _003714_hash NULL
87497 +_003715_hash v4l2_ctrl_new_int_menu 4 41151 _003715_hash NULL
87498 +_003716_hash v4l2_ctrl_new_std 5 45748 _003716_hash &_000497_hash
87499 +_003717_hash v4l2_ctrl_new_std_menu 4 6221 _003717_hash NULL
87500 +_003718_hash vb2_read 3 42703 _003718_hash NULL
87501 +_003719_hash vb2_write 3 31948 _003719_hash NULL
87502 +_003720_hash vfio_pci_set_msi_trigger 3-4 26507 _003720_hash NULL
87503 +_003722_hash viafb_iga1_odev_proc_write 3 36241 _003722_hash NULL
87504 +_003723_hash viafb_iga2_odev_proc_write 3 2363 _003723_hash NULL
87505 +_003724_hash __videobuf_alloc_cached 1 12740 _003724_hash NULL
87506 +_003725_hash __videobuf_alloc_uncached 1 55711 _003725_hash NULL
87507 +_003726_hash __videobuf_copy_stream 4 44769 _003726_hash NULL
87508 +_003727_hash videobuf_read_one 3 31637 _003727_hash NULL
87509 +_003728_hash video_ioctl2 2 21380 _003728_hash NULL
87510 +_003729_hash vmap 2 15025 _003729_hash NULL
87511 +_003730_hash vmw_cursor_update_dmabuf 3-4 32045 _003730_hash NULL
87512 +_003732_hash vmw_gmr_bind 3 44130 _003732_hash NULL
87513 +_003733_hash xd_read_multiple_pages 4-5 11422 _003733_hash NULL
87514 +_003735_hash xd_write_multiple_pages 5-6 53633 _003735_hash NULL
87515 +_003737_hash xenfb_write 3 43412 _003737_hash NULL
87516 +_003738_hash arch_gnttab_map_shared 3 41306 _003738_hash NULL
87517 +_003739_hash arch_gnttab_map_status 3 49812 _003739_hash NULL
87518 +_003740_hash bttv_read 3 11432 _003740_hash NULL
87519 +_003741_hash cx18_read 3 23699 _003741_hash NULL
87520 +_003742_hash cx2341x_ctrl_new_menu 3 49700 _003742_hash NULL
87521 +_003743_hash cx2341x_ctrl_new_std 4 57061 _003743_hash NULL
87522 +_003744_hash cx25821_video_ioctl 2 30188 _003744_hash NULL
87523 +_003745_hash dt3155_read 3 59226 _003745_hash NULL
87524 +_003746_hash ioremap_cache 1-2 47189 _003746_hash NULL
87525 +_003748_hash ioremap_nocache 1-2 2439 _003748_hash NULL
87526 +_003750_hash ioremap_prot 1-2 51764 _003750_hash &_003711_hash
87527 +_003752_hash ioremap_wc 1-2 62695 _003752_hash NULL
87528 +_003754_hash ivtv_read_pos 3 34400 _003754_hash &_000312_hash
87529 +_003755_hash mcam_v4l_read 3 36513 _003755_hash NULL
87530 +_003756_hash ms_rw_multi_sector 3-4 7459 _003756_hash NULL
87531 +_003758_hash pvr2_v4l2_ioctl 2 24398 _003758_hash &_000877_hash
87532 +_003759_hash ramoops_init_prz 5 12134 _003759_hash NULL
87533 +_003761_hash ttm_bo_kmap_ttm 3 5922 _003761_hash NULL
87534 +_003762_hash uf_ap_process_data_pdu 7 25860 _003762_hash NULL
87535 +_003763_hash vb2_fop_read 3 24080 _003763_hash NULL
87536 +_003764_hash vb2_fop_write 3 30420 _003764_hash NULL
87537 +_003765_hash videobuf_read_stream 3 14956 _003765_hash NULL
87538 +_003766_hash video_read 3 28148 _003766_hash NULL
87539 +_003767_hash vmw_du_crtc_cursor_set 4-5 28479 _003767_hash NULL
87540 +_003769_hash xd_rw 3-4 49020 _003769_hash NULL
87541 +_003771_hash zoran_ioctl 2 30465 _003771_hash NULL
87542 +_003772_hash zr364xx_read 3 2354 _003772_hash NULL
87543 +_003773_hash acpi_os_ioremap 1-2 49523 _003773_hash NULL
87544 +_003775_hash au0828_v4l2_read 3 40220 _003775_hash NULL
87545 +_003776_hash ca91cx42_alloc_resource 2 10502 _003776_hash NULL
87546 +_003778_hash cx18_read_pos 3 4683 _003778_hash NULL
87547 +_003779_hash cx18_v4l2_read 3 21196 _003779_hash NULL
87548 +_003780_hash cx231xx_v4l2_read 3 55014 _003780_hash NULL
87549 +_003781_hash devm_ioremap_nocache 2-3 2036 _003781_hash NULL
87550 +_003783_hash do_test 1 15766 _003783_hash NULL
87551 +_003784_hash __einj_error_trigger 1 17707 _003784_hash &_001764_hash
87552 +_003785_hash em28xx_v4l2_read 3 16701 _003785_hash NULL
87553 +_003786_hash init_chip_wc_pat 2 62768 _003786_hash NULL
87554 +_003787_hash intel_render_ring_init_dri 2-3 45446 _003787_hash NULL
87555 +_003789_hash io_mapping_create_wc 1-2 1354 _003789_hash NULL
87556 +_003791_hash iommu_map_mmio_space 1 30919 _003791_hash NULL
87557 +_003792_hash ioremap 1-2 23172 _003792_hash NULL
87558 +_003794_hash ivtv_v4l2_read 3 1964 _003794_hash NULL
87559 +_003795_hash mga_ioremap 1-2 8571 _003795_hash NULL
87560 +_003797_hash mpeg_read 3 6708 _003797_hash NULL
87561 +_003798_hash msix_map_region 3 3411 _003798_hash NULL
87562 +_003799_hash ms_rw 3-4 17220 _003799_hash NULL
87563 +_003801_hash pci_iomap 3 47575 _003801_hash NULL
87564 +_003802_hash pd_video_read 3 24510 _003802_hash NULL
87565 +_003803_hash sfi_map_memory 1-2 5183 _003803_hash NULL
87566 +_003805_hash solo_enc_read 3 33553 _003805_hash NULL
87567 +_003806_hash solo_v4l2_read 3 59247 _003806_hash NULL
87568 +_003807_hash timblogiw_read 3 48305 _003807_hash NULL
87569 +_003808_hash tm6000_read 3 4151 _003808_hash NULL
87570 +_003809_hash tsi148_alloc_resource 2 24563 _003809_hash NULL
87571 +_003810_hash ttm_bo_ioremap 2-3 31082 _003810_hash NULL
87572 +_003812_hash ttm_bo_kmap 3-2 60118 _003812_hash NULL
87573 +_003813_hash vb2_vmalloc_get_userptr 3 31374 _003813_hash NULL
87574 +_003814_hash vbi_read 3 63673 _003814_hash NULL
87575 +_003815_hash viacam_read 3 54526 _003815_hash NULL
87576 +_003816_hash xlate_dev_mem_ptr 1 15291 _003816_hash &_001231_hash
87577 +_003817_hash a4t_cs_init 3 27734 _003817_hash NULL
87578 +_003818_hash aac_nark_ioremap 2 50163 _003818_hash &_000323_hash
87579 +_003819_hash aac_rkt_ioremap 2 3333 _003819_hash NULL
87580 +_003820_hash aac_rx_ioremap 2 52410 _003820_hash NULL
87581 +_003821_hash aac_sa_ioremap 2 13596 _003821_hash &_000299_hash
87582 +_003822_hash aac_src_ioremap 2 41688 _003822_hash NULL
87583 +_003823_hash aac_srcv_ioremap 2 6659 _003823_hash NULL
87584 +_003824_hash acpi_map 1-2 58725 _003824_hash NULL
87585 +_003826_hash acpi_os_read_memory 1-3 54186 _003826_hash NULL
87586 +_003828_hash acpi_os_write_memory 1-3 56416 _003828_hash &_003429_hash
87587 +_003830_hash atyfb_setup_generic 3 49151 _003830_hash NULL
87588 +_003831_hash ca91cx42_master_set 4 23146 _003831_hash NULL
87589 +_003832_hash check_mirror 1-2 57342 _003832_hash &_001753_hash
87590 +_003834_hash cycx_setup 4 47562 _003834_hash NULL
87591 +_003835_hash devm_ioremap 2-3 29235 _003835_hash NULL
87592 +_003837_hash divasa_remap_pci_bar 3-4 23485 _003837_hash &_000979_hash
87593 +_003839_hash doc_probe 1 23285 _003839_hash NULL
87594 +_003840_hash DoC_Probe 1 57534 _003840_hash NULL
87595 +_003841_hash efi_ioremap 1-2 3492 _003841_hash &_001137_hash
87596 +_003843_hash ems_pcmcia_add_card 2 62627 _003843_hash NULL
87597 +_003844_hash isp1760_register 1-2 628 _003844_hash NULL
87598 +_003846_hash mid_get_vbt_data_r0 2 10876 _003846_hash NULL
87599 +_003847_hash mid_get_vbt_data_r10 2 6308 _003847_hash NULL
87600 +_003848_hash mid_get_vbt_data_r1 2 26170 _003848_hash NULL
87601 +_003849_hash mthca_map_reg 2-3 5664 _003849_hash NULL
87602 +_003851_hash mthca_setup_cmd_doorbells 2 53954 _003851_hash NULL
87603 +_003852_hash netxen_nic_map_indirect_address_128M 2 42257 _003852_hash NULL
87604 +_003853_hash pcim_iomap 3 58334 _003853_hash NULL
87605 +_003854_hash persistent_ram_iomap 1-2 47156 _003854_hash NULL
87606 +_003856_hash read_vbt_r0 1 503 _003856_hash NULL
87607 +_003857_hash read_vbt_r10 1 60679 _003857_hash NULL
87608 +_003858_hash register_device 2-3 60015 _003858_hash NULL
87609 +_003860_hash remap_pci_mem 1-2 15966 _003860_hash NULL
87610 +_003862_hash rtl_port_map 1-2 2385 _003862_hash NULL
87611 +_003864_hash sfi_map_table 1 5462 _003864_hash NULL
87612 +_003865_hash sriov_enable_migration 2 14889 _003865_hash NULL
87613 +_003866_hash ssb_bus_scan 2 36578 _003866_hash NULL
87614 +_003867_hash ssb_ioremap 2 5228 _003867_hash NULL
87615 +_003868_hash tpci200_slot_map_space 2 3848 _003868_hash NULL
87616 +_003869_hash tpm_tis_init 2-3 15304 _003869_hash NULL
87617 +_003871_hash tsi148_master_set 4 14685 _003871_hash NULL
87618 +_003872_hash acpi_os_map_memory 1-2 11161 _003872_hash NULL
87619 +_003874_hash com90xx_found 3 13974 _003874_hash NULL
87620 +_003875_hash netxen_nic_hw_read_wx_128M 2 26858 _003875_hash NULL
87621 +_003876_hash netxen_nic_hw_write_wx_128M 2 33488 _003876_hash NULL
87622 +_003877_hash sfi_check_table 1 6772 _003877_hash NULL
87623 +_003878_hash sfi_sysfs_install_table 1 51688 _003878_hash NULL
87624 +_003879_hash sriov_enable 2 59689 _003879_hash NULL
87625 +_003880_hash ssb_bus_register 3 65183 _003880_hash NULL
87626 +_003881_hash acpi_ex_system_memory_space_handler 2 31192 _003881_hash NULL
87627 +_003882_hash acpi_tb_check_xsdt 1 21862 _003882_hash NULL
87628 +_003883_hash acpi_tb_install_table 1 12988 _003883_hash NULL
87629 +_003884_hash acpi_tb_parse_root_table 1 53455 _003884_hash NULL
87630 +_003885_hash check_vendor_extension 1 3254 _003885_hash NULL
87631 +_003886_hash pci_enable_sriov 2 35745 _003886_hash NULL
87632 +_003887_hash ssb_bus_pcmciabus_register 3 56020 _003887_hash NULL
87633 +_003888_hash ssb_bus_ssbbus_register 2 2217 _003888_hash NULL
87634 +_003889_hash lpfc_sli_probe_sriov_nr_virtfn 2 26004 _003889_hash NULL
87635 +_003890_hash alloc_vm_area 1 36149 _003890_hash NULL
87636 +_003891_hash cma_create_area 2 38642 _003891_hash NULL
87637 +_003893_hash fbcon_prepare_logo 5 6246 _003893_hash NULL
87638 +_003894_hash io_mapping_map_wc 2 19284 _003894_hash NULL
87639 +_003895_hash nfs_dns_resolve_name 3 25036 _003895_hash NULL
87640 +_003896_hash nfs_parse_server_name 2 1899 _003896_hash NULL
87641 diff --git a/tools/gcc/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin.c
87642 new file mode 100644
87643 index 0000000..244559e
87644 --- /dev/null
87645 +++ b/tools/gcc/size_overflow_plugin.c
87646 @@ -0,0 +1,1879 @@
87647 +/*
87648 + * Copyright 2011, 2012 by Emese Revfy <re.emese@gmail.com>
87649 + * Licensed under the GPL v2, or (at your option) v3
87650 + *
87651 + * Homepage:
87652 + * http://www.grsecurity.net/~ephox/overflow_plugin/
87653 + *
87654 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
87655 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
87656 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
87657 + *
87658 + * Usage:
87659 + * $ 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
87660 + * $ gcc -fplugin=size_overflow_plugin.so test.c -O2
87661 + */
87662 +
87663 +#include "gcc-plugin.h"
87664 +#include "config.h"
87665 +#include "system.h"
87666 +#include "coretypes.h"
87667 +#include "tree.h"
87668 +#include "tree-pass.h"
87669 +#include "intl.h"
87670 +#include "plugin-version.h"
87671 +#include "tm.h"
87672 +#include "toplev.h"
87673 +#include "function.h"
87674 +#include "tree-flow.h"
87675 +#include "plugin.h"
87676 +#include "gimple.h"
87677 +#include "c-common.h"
87678 +#include "diagnostic.h"
87679 +#include "cfgloop.h"
87680 +
87681 +#if BUILDING_GCC_VERSION >= 4007
87682 +#include "c-tree.h"
87683 +#else
87684 +#define C_DECL_IMPLICIT(EXP) DECL_LANG_FLAG_2 (EXP)
87685 +#endif
87686 +
87687 +struct size_overflow_hash {
87688 + const struct size_overflow_hash * const next;
87689 + const char * const name;
87690 + const unsigned int param;
87691 +};
87692 +
87693 +#include "size_overflow_hash.h"
87694 +
87695 +enum marked {
87696 + MARKED_NO, MARKED_YES, MARKED_NOT_INTENTIONAL
87697 +};
87698 +
87699 +#define __unused __attribute__((__unused__))
87700 +#define NAME(node) IDENTIFIER_POINTER(DECL_NAME(node))
87701 +#define NAME_LEN(node) IDENTIFIER_LENGTH(DECL_NAME(node))
87702 +#define BEFORE_STMT true
87703 +#define AFTER_STMT false
87704 +#define CREATE_NEW_VAR NULL_TREE
87705 +#define CODES_LIMIT 32
87706 +#define MAX_PARAM 32
87707 +#define MY_STMT GF_PLF_1
87708 +#define NO_CAST_CHECK GF_PLF_2
87709 +
87710 +#if BUILDING_GCC_VERSION == 4005
87711 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
87712 +#endif
87713 +
87714 +int plugin_is_GPL_compatible;
87715 +void debug_gimple_stmt(gimple gs);
87716 +
87717 +static tree expand(struct pointer_set_t *visited, tree lhs);
87718 +static bool pre_expand(struct pointer_set_t *visited, const_tree lhs);
87719 +static tree report_size_overflow_decl;
87720 +static const_tree const_char_ptr_type_node;
87721 +static unsigned int handle_function(void);
87722 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before);
87723 +static tree get_size_overflow_type(gimple stmt, const_tree node);
87724 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, tree size_overflow_type, tree rhs1, tree rhs2, tree __unused rhs3);
87725 +
87726 +static struct plugin_info size_overflow_plugin_info = {
87727 + .version = "20120930beta",
87728 + .help = "no-size-overflow\tturn off size overflow checking\n",
87729 +};
87730 +
87731 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
87732 +{
87733 + unsigned int arg_count;
87734 + enum tree_code code = TREE_CODE(*node);
87735 +
87736 + switch (code) {
87737 + case FUNCTION_DECL:
87738 + arg_count = type_num_arguments(TREE_TYPE(*node));
87739 + break;
87740 + case FUNCTION_TYPE:
87741 + case METHOD_TYPE:
87742 + arg_count = type_num_arguments(*node);
87743 + break;
87744 + default:
87745 + *no_add_attrs = true;
87746 + error("%s: %qE attribute only applies to functions", __func__, name);
87747 + return NULL_TREE;
87748 + }
87749 +
87750 + for (; args; args = TREE_CHAIN(args)) {
87751 + tree position = TREE_VALUE(args);
87752 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) < 1 || TREE_INT_CST_LOW(position) > arg_count ) {
87753 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
87754 + *no_add_attrs = true;
87755 + }
87756 + }
87757 + return NULL_TREE;
87758 +}
87759 +
87760 +static const char* get_asm_name(tree node)
87761 +{
87762 + return IDENTIFIER_POINTER(DECL_ASSEMBLER_NAME(node));
87763 +}
87764 +
87765 +static tree handle_intentional_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
87766 +{
87767 + unsigned int arg_count, arg_num;
87768 + enum tree_code code = TREE_CODE(*node);
87769 +
87770 + switch (code) {
87771 + case FUNCTION_DECL:
87772 + arg_count = type_num_arguments(TREE_TYPE(*node));
87773 + break;
87774 + case FUNCTION_TYPE:
87775 + case METHOD_TYPE:
87776 + arg_count = type_num_arguments(*node);
87777 + break;
87778 + case FIELD_DECL:
87779 + arg_num = TREE_INT_CST_LOW(TREE_VALUE(args));
87780 + if (arg_num != 0) {
87781 + *no_add_attrs = true;
87782 + error("%s: %qE attribute parameter can only be 0 in structure fields", __func__, name);
87783 + }
87784 + return NULL_TREE;
87785 + default:
87786 + *no_add_attrs = true;
87787 + error("%qE attribute only applies to functions", name);
87788 + return NULL_TREE;
87789 + }
87790 +
87791 + for (; args; args = TREE_CHAIN(args)) {
87792 + tree position = TREE_VALUE(args);
87793 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) > arg_count ) {
87794 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
87795 + *no_add_attrs = true;
87796 + }
87797 + }
87798 + return NULL_TREE;
87799 +}
87800 +
87801 +static struct attribute_spec size_overflow_attr = {
87802 + .name = "size_overflow",
87803 + .min_length = 1,
87804 + .max_length = -1,
87805 + .decl_required = true,
87806 + .type_required = false,
87807 + .function_type_required = false,
87808 + .handler = handle_size_overflow_attribute,
87809 +#if BUILDING_GCC_VERSION >= 4007
87810 + .affects_type_identity = false
87811 +#endif
87812 +};
87813 +
87814 +static struct attribute_spec intentional_overflow_attr = {
87815 + .name = "intentional_overflow",
87816 + .min_length = 1,
87817 + .max_length = -1,
87818 + .decl_required = true,
87819 + .type_required = false,
87820 + .function_type_required = false,
87821 + .handler = handle_intentional_overflow_attribute,
87822 +#if BUILDING_GCC_VERSION >= 4007
87823 + .affects_type_identity = false
87824 +#endif
87825 +};
87826 +
87827 +static void register_attributes(void __unused *event_data, void __unused *data)
87828 +{
87829 + register_attribute(&size_overflow_attr);
87830 + register_attribute(&intentional_overflow_attr);
87831 +}
87832 +
87833 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
87834 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
87835 +{
87836 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
87837 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
87838 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
87839 +
87840 + unsigned int m = 0x57559429;
87841 + unsigned int n = 0x5052acdb;
87842 + const unsigned int *key4 = (const unsigned int *)key;
87843 + unsigned int h = len;
87844 + unsigned int k = len + seed + n;
87845 + unsigned long long p;
87846 +
87847 + while (len >= 8) {
87848 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
87849 + len -= 8;
87850 + }
87851 + if (len >= 4) {
87852 + cwmixb(key4[0]) key4 += 1;
87853 + len -= 4;
87854 + }
87855 + if (len)
87856 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
87857 + cwmixb(h ^ (k + n));
87858 + return k ^ h;
87859 +
87860 +#undef cwfold
87861 +#undef cwmixa
87862 +#undef cwmixb
87863 +}
87864 +
87865 +static inline unsigned int get_hash_num(const char *fndecl, const char *tree_codes, unsigned int len, unsigned int seed)
87866 +{
87867 + unsigned int fn = CrapWow(fndecl, strlen(fndecl), seed) & 0xffff;
87868 + unsigned int codes = CrapWow(tree_codes, len, seed) & 0xffff;
87869 + return fn ^ codes;
87870 +}
87871 +
87872 +static inline tree get_original_function_decl(tree fndecl)
87873 +{
87874 + if (DECL_ABSTRACT_ORIGIN(fndecl))
87875 + return DECL_ABSTRACT_ORIGIN(fndecl);
87876 + return fndecl;
87877 +}
87878 +
87879 +static inline gimple get_def_stmt(const_tree node)
87880 +{
87881 + gcc_assert(node != NULL_TREE);
87882 + gcc_assert(TREE_CODE(node) == SSA_NAME);
87883 + return SSA_NAME_DEF_STMT(node);
87884 +}
87885 +
87886 +static unsigned char get_tree_code(const_tree type)
87887 +{
87888 + switch (TREE_CODE(type)) {
87889 + case ARRAY_TYPE:
87890 + return 0;
87891 + case BOOLEAN_TYPE:
87892 + return 1;
87893 + case ENUMERAL_TYPE:
87894 + return 2;
87895 + case FUNCTION_TYPE:
87896 + return 3;
87897 + case INTEGER_TYPE:
87898 + return 4;
87899 + case POINTER_TYPE:
87900 + return 5;
87901 + case RECORD_TYPE:
87902 + return 6;
87903 + case UNION_TYPE:
87904 + return 7;
87905 + case VOID_TYPE:
87906 + return 8;
87907 + case REAL_TYPE:
87908 + return 9;
87909 + case VECTOR_TYPE:
87910 + return 10;
87911 + case REFERENCE_TYPE:
87912 + return 11;
87913 + case OFFSET_TYPE:
87914 + return 12;
87915 + case COMPLEX_TYPE:
87916 + return 13;
87917 + default:
87918 + debug_tree((tree)type);
87919 + gcc_unreachable();
87920 + }
87921 +}
87922 +
87923 +static size_t add_type_codes(const_tree type, unsigned char *tree_codes, size_t len)
87924 +{
87925 + gcc_assert(type != NULL_TREE);
87926 +
87927 + while (type && len < CODES_LIMIT) {
87928 + tree_codes[len] = get_tree_code(type);
87929 + len++;
87930 + type = TREE_TYPE(type);
87931 + }
87932 + return len;
87933 +}
87934 +
87935 +static unsigned int get_function_decl(const_tree fndecl, unsigned char *tree_codes)
87936 +{
87937 + const_tree arg, result, arg_field, type = TREE_TYPE(fndecl);
87938 + enum tree_code code = TREE_CODE(type);
87939 + size_t len = 0;
87940 +
87941 + gcc_assert(code == FUNCTION_TYPE || code == METHOD_TYPE);
87942 +
87943 + arg = TYPE_ARG_TYPES(type);
87944 + // skip builtins __builtin_constant_p
87945 + if (!arg && DECL_BUILT_IN(fndecl))
87946 + return 0;
87947 +
87948 + if (TREE_CODE_CLASS(code) == tcc_type)
87949 + result = type;
87950 + else
87951 + result = DECL_RESULT(fndecl);
87952 +
87953 + gcc_assert(result != NULL_TREE);
87954 + len = add_type_codes(TREE_TYPE(result), tree_codes, len);
87955 +
87956 + if (arg == NULL_TREE) {
87957 + gcc_assert(CODE_CONTAINS_STRUCT(TREE_CODE(fndecl), TS_DECL_NON_COMMON));
87958 + arg_field = DECL_ARGUMENT_FLD(fndecl);
87959 + if (arg_field == NULL_TREE)
87960 + return 0;
87961 + arg = TREE_TYPE(arg_field);
87962 + len = add_type_codes(arg, tree_codes, len);
87963 + gcc_assert(len != 0);
87964 + return len;
87965 + }
87966 +
87967 + gcc_assert(arg != NULL_TREE && TREE_CODE(arg) == TREE_LIST);
87968 + while (arg && len < CODES_LIMIT) {
87969 + len = add_type_codes(TREE_VALUE(arg), tree_codes, len);
87970 + arg = TREE_CHAIN(arg);
87971 + }
87972 +
87973 + gcc_assert(len != 0);
87974 + return len;
87975 +}
87976 +
87977 +static const struct size_overflow_hash *get_function_hash(tree fndecl)
87978 +{
87979 + unsigned int hash;
87980 + const struct size_overflow_hash *entry;
87981 + unsigned char tree_codes[CODES_LIMIT];
87982 + size_t len;
87983 + const char *func_name = get_asm_name(fndecl);
87984 +
87985 + len = get_function_decl(fndecl, tree_codes);
87986 + if (len == 0)
87987 + return NULL;
87988 +
87989 + hash = get_hash_num(func_name, (const char*) tree_codes, len, 0);
87990 +
87991 + entry = size_overflow_hash[hash];
87992 + while (entry) {
87993 + if (!strcmp(entry->name, func_name))
87994 + return entry;
87995 + entry = entry->next;
87996 + }
87997 +
87998 + return NULL;
87999 +}
88000 +
88001 +static void check_arg_type(const_tree arg)
88002 +{
88003 + const_tree type = TREE_TYPE(arg);
88004 + enum tree_code code = TREE_CODE(type);
88005 +
88006 + gcc_assert(code == INTEGER_TYPE || code == ENUMERAL_TYPE ||
88007 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == VOID_TYPE) ||
88008 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == INTEGER_TYPE));
88009 +}
88010 +
88011 +static int find_arg_number(const_tree arg, tree func)
88012 +{
88013 + tree var;
88014 + unsigned int argnum = 1;
88015 +
88016 + if (TREE_CODE(arg) == SSA_NAME)
88017 + arg = SSA_NAME_VAR(arg);
88018 +
88019 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var)) {
88020 + if (strcmp(NAME(arg), NAME(var))) {
88021 + argnum++;
88022 + continue;
88023 + }
88024 + check_arg_type(var);
88025 + return argnum;
88026 + }
88027 + gcc_unreachable();
88028 +}
88029 +
88030 +static tree create_new_var(tree type)
88031 +{
88032 + tree new_var = create_tmp_var(type, "cicus");
88033 +
88034 + add_referenced_var(new_var);
88035 + mark_sym_for_renaming(new_var);
88036 + return new_var;
88037 +}
88038 +
88039 +static gimple create_binary_assign(enum tree_code code, gimple stmt, tree rhs1, tree rhs2)
88040 +{
88041 + gimple assign;
88042 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
88043 + tree type = TREE_TYPE(rhs1);
88044 + tree lhs = create_new_var(type);
88045 +
88046 + assign = gimple_build_assign_with_ops(code, lhs, rhs1, rhs2);
88047 + gimple_set_lhs(assign, make_ssa_name(lhs, assign));
88048 +
88049 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
88050 + update_stmt(assign);
88051 + gimple_set_plf(assign, MY_STMT, true);
88052 + return assign;
88053 +}
88054 +
88055 +static bool is_bool(const_tree node)
88056 +{
88057 + const_tree type;
88058 +
88059 + if (node == NULL_TREE)
88060 + return false;
88061 +
88062 + type = TREE_TYPE(node);
88063 + if (!INTEGRAL_TYPE_P(type))
88064 + return false;
88065 + if (TREE_CODE(type) == BOOLEAN_TYPE)
88066 + return true;
88067 + if (TYPE_PRECISION(type) == 1)
88068 + return true;
88069 + return false;
88070 +}
88071 +
88072 +static tree cast_a_tree(tree type, tree var)
88073 +{
88074 + gcc_assert(type != NULL_TREE);
88075 + gcc_assert(var != NULL_TREE);
88076 + gcc_assert(fold_convertible_p(type, var));
88077 +
88078 + return fold_convert(type, var);
88079 +}
88080 +
88081 +static gimple build_cast_stmt(tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before)
88082 +{
88083 + gimple assign;
88084 +
88085 + gcc_assert(dst_type != NULL_TREE && rhs != NULL_TREE);
88086 + if (gsi_end_p(*gsi) && before == AFTER_STMT)
88087 + gcc_unreachable();
88088 +
88089 + if (lhs == CREATE_NEW_VAR)
88090 + lhs = create_new_var(dst_type);
88091 +
88092 + assign = gimple_build_assign(lhs, cast_a_tree(dst_type, rhs));
88093 +
88094 + if (!gsi_end_p(*gsi)) {
88095 + location_t loc = gimple_location(gsi_stmt(*gsi));
88096 + gimple_set_location(assign, loc);
88097 + }
88098 +
88099 + gimple_set_lhs(assign, make_ssa_name(lhs, assign));
88100 +
88101 + if (before)
88102 + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
88103 + else
88104 + gsi_insert_after(gsi, assign, GSI_NEW_STMT);
88105 + update_stmt(assign);
88106 + gimple_set_plf(assign, MY_STMT, true);
88107 +
88108 + return assign;
88109 +}
88110 +
88111 +static tree cast_to_new_size_overflow_type(gimple stmt, tree new_rhs1, tree size_overflow_type, bool before)
88112 +{
88113 + const_gimple assign;
88114 + gimple_stmt_iterator gsi;
88115 +
88116 + if (new_rhs1 == NULL_TREE)
88117 + return NULL_TREE;
88118 +
88119 + if (!useless_type_conversion_p(TREE_TYPE(new_rhs1), size_overflow_type)) {
88120 + gsi = gsi_for_stmt(stmt);
88121 + assign = build_cast_stmt(size_overflow_type, new_rhs1, CREATE_NEW_VAR, &gsi, before);
88122 + return gimple_get_lhs(assign);
88123 + }
88124 + return new_rhs1;
88125 +}
88126 +
88127 +static tree follow_overflow_type_and_dup(struct pointer_set_t *visited, gimple stmt, const_tree node, tree new_rhs1, tree new_rhs2, tree new_rhs3)
88128 +{
88129 + tree size_overflow_type = get_size_overflow_type(stmt, node);
88130 +
88131 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
88132 +
88133 + if (new_rhs2 != NULL_TREE)
88134 + new_rhs2 = cast_to_new_size_overflow_type(stmt, new_rhs2, size_overflow_type, BEFORE_STMT);
88135 +
88136 + if (new_rhs3 != NULL_TREE)
88137 + new_rhs3 = cast_to_new_size_overflow_type(stmt, new_rhs3, size_overflow_type, BEFORE_STMT);
88138 +
88139 + return dup_assign(visited, stmt, size_overflow_type, new_rhs1, new_rhs2, new_rhs3);
88140 +}
88141 +
88142 +
88143 +static tree create_assign(struct pointer_set_t *visited, gimple oldstmt, tree rhs1, bool before)
88144 +{
88145 + tree size_overflow_type, lhs;
88146 + gimple stmt;
88147 + gimple_stmt_iterator gsi;
88148 +
88149 + if (rhs1 == NULL_TREE) {
88150 + debug_gimple_stmt(oldstmt);
88151 + error("%s: rhs1 is NULL_TREE", __func__);
88152 + gcc_unreachable();
88153 + }
88154 +
88155 + if (gimple_code(oldstmt) == GIMPLE_ASM)
88156 + lhs = rhs1;
88157 + else
88158 + lhs = gimple_get_lhs(oldstmt);
88159 +
88160 + gsi = gsi_for_stmt(oldstmt);
88161 + pointer_set_insert(visited, oldstmt);
88162 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
88163 + basic_block next_bb, cur_bb;
88164 + const_edge e;
88165 +
88166 + gcc_assert(before == false);
88167 + gcc_assert(stmt_can_throw_internal(oldstmt));
88168 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
88169 + gcc_assert(!gsi_end_p(gsi));
88170 +
88171 + cur_bb = gimple_bb(oldstmt);
88172 + next_bb = cur_bb->next_bb;
88173 + e = find_edge(cur_bb, next_bb);
88174 + gcc_assert(e != NULL);
88175 + gcc_assert(e->flags & EDGE_FALLTHRU);
88176 +
88177 + gsi = gsi_after_labels(next_bb);
88178 + gcc_assert(!gsi_end_p(gsi));
88179 +
88180 + before = true;
88181 + oldstmt = gsi_stmt(gsi);
88182 + }
88183 +
88184 + size_overflow_type = get_size_overflow_type(oldstmt, lhs);
88185 +
88186 + stmt = build_cast_stmt(size_overflow_type, rhs1, CREATE_NEW_VAR, &gsi, before);
88187 + gimple_set_plf(stmt, MY_STMT, true);
88188 + return gimple_get_lhs(stmt);
88189 +}
88190 +
88191 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, tree size_overflow_type, tree rhs1, tree rhs2, tree __unused rhs3)
88192 +{
88193 + gimple stmt;
88194 + gimple_stmt_iterator gsi;
88195 + tree new_var, lhs = gimple_get_lhs(oldstmt);
88196 +
88197 + if (gimple_plf(oldstmt, MY_STMT))
88198 + return lhs;
88199 +
88200 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
88201 + rhs1 = gimple_assign_rhs1(oldstmt);
88202 + rhs1 = create_assign(visited, oldstmt, rhs1, BEFORE_STMT);
88203 + }
88204 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
88205 + rhs2 = gimple_assign_rhs2(oldstmt);
88206 + rhs2 = create_assign(visited, oldstmt, rhs2, BEFORE_STMT);
88207 + }
88208 +
88209 + stmt = gimple_copy(oldstmt);
88210 + gimple_set_location(stmt, gimple_location(oldstmt));
88211 + gimple_set_plf(stmt, MY_STMT, true);
88212 +
88213 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
88214 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
88215 +
88216 + if (is_bool(lhs))
88217 + new_var = SSA_NAME_VAR(lhs);
88218 + else
88219 + new_var = create_new_var(size_overflow_type);
88220 + new_var = make_ssa_name(new_var, stmt);
88221 + gimple_set_lhs(stmt, new_var);
88222 +
88223 + if (rhs1 != NULL_TREE) {
88224 + if (!gimple_assign_cast_p(oldstmt))
88225 + rhs1 = cast_a_tree(size_overflow_type, rhs1);
88226 + gimple_assign_set_rhs1(stmt, rhs1);
88227 + }
88228 +
88229 + if (rhs2 != NULL_TREE)
88230 + gimple_assign_set_rhs2(stmt, rhs2);
88231 +#if BUILDING_GCC_VERSION >= 4007
88232 + if (rhs3 != NULL_TREE)
88233 + gimple_assign_set_rhs3(stmt, rhs3);
88234 +#endif
88235 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
88236 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
88237 +
88238 + gsi = gsi_for_stmt(oldstmt);
88239 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
88240 + update_stmt(stmt);
88241 + pointer_set_insert(visited, oldstmt);
88242 + return gimple_get_lhs(stmt);
88243 +}
88244 +
88245 +static gimple overflow_create_phi_node(gimple oldstmt, tree result)
88246 +{
88247 + basic_block bb;
88248 + gimple phi;
88249 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
88250 +
88251 + bb = gsi_bb(gsi);
88252 +
88253 + phi = create_phi_node(result, bb);
88254 + gsi = gsi_last(phi_nodes(bb));
88255 + gsi_remove(&gsi, false);
88256 +
88257 + gsi = gsi_for_stmt(oldstmt);
88258 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
88259 + gimple_set_bb(phi, bb);
88260 + gimple_set_plf(phi, MY_STMT, true);
88261 + return phi;
88262 +}
88263 +
88264 +static basic_block create_a_first_bb(void)
88265 +{
88266 + basic_block first_bb;
88267 +
88268 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
88269 + if (dom_info_available_p(CDI_DOMINATORS))
88270 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR);
88271 + return first_bb;
88272 +}
88273 +
88274 +static tree cast_old_phi_arg(gimple oldstmt, tree size_overflow_type, tree arg, tree new_var, unsigned int i)
88275 +{
88276 + basic_block bb;
88277 + const_gimple newstmt;
88278 + gimple_stmt_iterator gsi;
88279 + bool before = BEFORE_STMT;
88280 +
88281 + if (TREE_CODE(arg) == SSA_NAME && gimple_code(get_def_stmt(arg)) != GIMPLE_NOP) {
88282 + gsi = gsi_for_stmt(get_def_stmt(arg));
88283 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, AFTER_STMT);
88284 + return gimple_get_lhs(newstmt);
88285 + }
88286 +
88287 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
88288 + gsi = gsi_after_labels(bb);
88289 + if (bb->index == 0) {
88290 + bb = create_a_first_bb();
88291 + gsi = gsi_start_bb(bb);
88292 + }
88293 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, before);
88294 + return gimple_get_lhs(newstmt);
88295 +}
88296 +
88297 +static const_gimple handle_new_phi_arg(const_tree arg, tree new_var, tree new_rhs)
88298 +{
88299 + gimple newstmt;
88300 + gimple_stmt_iterator gsi;
88301 + void (*gsi_insert)(gimple_stmt_iterator *, gimple, enum gsi_iterator_update);
88302 + gimple def_newstmt = get_def_stmt(new_rhs);
88303 +
88304 + gsi_insert = gsi_insert_after;
88305 + gsi = gsi_for_stmt(def_newstmt);
88306 +
88307 + switch (gimple_code(get_def_stmt(arg))) {
88308 + case GIMPLE_PHI:
88309 + newstmt = gimple_build_assign(new_var, new_rhs);
88310 + gsi = gsi_after_labels(gimple_bb(def_newstmt));
88311 + gsi_insert = gsi_insert_before;
88312 + break;
88313 + case GIMPLE_ASM:
88314 + case GIMPLE_CALL:
88315 + newstmt = gimple_build_assign(new_var, new_rhs);
88316 + break;
88317 + case GIMPLE_ASSIGN:
88318 + newstmt = gimple_build_assign(new_var, gimple_get_lhs(def_newstmt));
88319 + break;
88320 + default:
88321 + /* unknown gimple_code (handle_build_new_phi_arg) */
88322 + gcc_unreachable();
88323 + }
88324 +
88325 + gimple_set_lhs(newstmt, make_ssa_name(new_var, newstmt));
88326 + gsi_insert(&gsi, newstmt, GSI_NEW_STMT);
88327 + gimple_set_plf(newstmt, MY_STMT, true);
88328 + update_stmt(newstmt);
88329 + return newstmt;
88330 +}
88331 +
88332 +static tree build_new_phi_arg(struct pointer_set_t *visited, tree size_overflow_type, tree arg, tree new_var)
88333 +{
88334 + const_gimple newstmt;
88335 + gimple def_stmt;
88336 + tree new_rhs;
88337 +
88338 + new_rhs = expand(visited, arg);
88339 + if (new_rhs == NULL_TREE)
88340 + return NULL_TREE;
88341 +
88342 + def_stmt = get_def_stmt(new_rhs);
88343 + if (gimple_code(def_stmt) == GIMPLE_NOP)
88344 + return NULL_TREE;
88345 + new_rhs = cast_to_new_size_overflow_type(def_stmt, new_rhs, size_overflow_type, AFTER_STMT);
88346 +
88347 + newstmt = handle_new_phi_arg(arg, new_var, new_rhs);
88348 + return gimple_get_lhs(newstmt);
88349 +}
88350 +
88351 +static tree build_new_phi(struct pointer_set_t *visited, tree orig_result)
88352 +{
88353 + gimple phi, oldstmt = get_def_stmt(orig_result);
88354 + tree new_result, size_overflow_type;
88355 + unsigned int i;
88356 + unsigned int n = gimple_phi_num_args(oldstmt);
88357 +
88358 + size_overflow_type = get_size_overflow_type(oldstmt, orig_result);
88359 +
88360 + new_result = create_new_var(size_overflow_type);
88361 +
88362 + pointer_set_insert(visited, oldstmt);
88363 + phi = overflow_create_phi_node(oldstmt, new_result);
88364 + for (i = 0; i < n; i++) {
88365 + tree arg, lhs;
88366 +
88367 + arg = gimple_phi_arg_def(oldstmt, i);
88368 + if (is_gimple_constant(arg))
88369 + arg = cast_a_tree(size_overflow_type, arg);
88370 + lhs = build_new_phi_arg(visited, size_overflow_type, arg, new_result);
88371 + if (lhs == NULL_TREE)
88372 + lhs = cast_old_phi_arg(oldstmt, size_overflow_type, arg, new_result, i);
88373 + add_phi_arg(phi, lhs, gimple_phi_arg_edge(oldstmt, i), gimple_location(oldstmt));
88374 + }
88375 +
88376 + update_stmt(phi);
88377 + return gimple_phi_result(phi);
88378 +}
88379 +
88380 +static tree change_assign_rhs(gimple stmt, const_tree orig_rhs, tree new_rhs)
88381 +{
88382 + const_gimple assign;
88383 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
88384 + tree origtype = TREE_TYPE(orig_rhs);
88385 +
88386 + gcc_assert(gimple_code(stmt) == GIMPLE_ASSIGN);
88387 +
88388 + assign = build_cast_stmt(origtype, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
88389 + return gimple_get_lhs(assign);
88390 +}
88391 +
88392 +static void change_rhs1(gimple stmt, tree new_rhs1)
88393 +{
88394 + tree assign_rhs;
88395 + const_tree rhs = gimple_assign_rhs1(stmt);
88396 +
88397 + assign_rhs = change_assign_rhs(stmt, rhs, new_rhs1);
88398 + gimple_assign_set_rhs1(stmt, assign_rhs);
88399 + update_stmt(stmt);
88400 +}
88401 +
88402 +static bool check_mode_type(const_gimple stmt)
88403 +{
88404 + const_tree lhs = gimple_get_lhs(stmt);
88405 + const_tree lhs_type = TREE_TYPE(lhs);
88406 + const_tree rhs_type = TREE_TYPE(gimple_assign_rhs1(stmt));
88407 + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
88408 + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
88409 +
88410 + if (rhs_mode == lhs_mode && TYPE_UNSIGNED(rhs_type) == TYPE_UNSIGNED(lhs_type))
88411 + return false;
88412 +
88413 + if (rhs_mode == SImode && lhs_mode == DImode && (TYPE_UNSIGNED(rhs_type) || !TYPE_UNSIGNED(lhs_type)))
88414 + return false;
88415 +
88416 + return true;
88417 +}
88418 +
88419 +static bool check_undefined_integer_operation(const_gimple stmt)
88420 +{
88421 + const_gimple def_stmt;
88422 + const_tree lhs = gimple_get_lhs(stmt);
88423 + const_tree rhs1 = gimple_assign_rhs1(stmt);
88424 + const_tree rhs1_type = TREE_TYPE(rhs1);
88425 + const_tree lhs_type = TREE_TYPE(lhs);
88426 +
88427 + if (TYPE_MODE(rhs1_type) != TYPE_MODE(lhs_type) || TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
88428 + return false;
88429 +
88430 + def_stmt = get_def_stmt(rhs1);
88431 + if (gimple_code(def_stmt) != GIMPLE_ASSIGN)
88432 + return false;
88433 +
88434 + if (gimple_assign_rhs_code(def_stmt) != MINUS_EXPR)
88435 + return false;
88436 + return true;
88437 +}
88438 +
88439 +static bool is_a_cast_and_const_overflow(const_tree no_const_rhs)
88440 +{
88441 + const_tree rhs1, lhs, rhs1_type, lhs_type;
88442 + enum machine_mode lhs_mode, rhs_mode;
88443 + gimple def_stmt = get_def_stmt(no_const_rhs);
88444 +
88445 + if (!gimple_assign_cast_p(def_stmt))
88446 + return false;
88447 +
88448 + rhs1 = gimple_assign_rhs1(def_stmt);
88449 + lhs = gimple_get_lhs(def_stmt);
88450 + rhs1_type = TREE_TYPE(rhs1);
88451 + lhs_type = TREE_TYPE(lhs);
88452 + rhs_mode = TYPE_MODE(rhs1_type);
88453 + lhs_mode = TYPE_MODE(lhs_type);
88454 + if (TYPE_UNSIGNED(lhs_type) == TYPE_UNSIGNED(rhs1_type) || lhs_mode != rhs_mode)
88455 + return false;
88456 +
88457 + return true;
88458 +}
88459 +
88460 +static tree handle_unary_rhs(struct pointer_set_t *visited, gimple stmt)
88461 +{
88462 + tree size_overflow_type, lhs = gimple_get_lhs(stmt);
88463 + tree new_rhs1, rhs1 = gimple_assign_rhs1(stmt);
88464 + const_tree rhs1_type = TREE_TYPE(rhs1);
88465 + const_tree lhs_type = TREE_TYPE(lhs);
88466 +
88467 + new_rhs1 = expand(visited, rhs1);
88468 +
88469 + if (new_rhs1 == NULL_TREE || TREE_CODE(rhs1_type) == POINTER_TYPE)
88470 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88471 +
88472 + if (gimple_plf(stmt, MY_STMT))
88473 + return lhs;
88474 +
88475 + if (gimple_plf(stmt, NO_CAST_CHECK))
88476 + return follow_overflow_type_and_dup(visited, stmt, rhs1, new_rhs1, NULL_TREE, NULL_TREE);
88477 +
88478 + if (gimple_assign_rhs_code(stmt) == BIT_NOT_EXPR) {
88479 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
88480 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
88481 + check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
88482 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88483 + }
88484 +
88485 + if (!gimple_assign_cast_p(stmt) || check_undefined_integer_operation(stmt))
88486 + return follow_overflow_type_and_dup(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
88487 +
88488 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
88489 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
88490 +
88491 + change_rhs1(stmt, new_rhs1);
88492 + check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
88493 +
88494 + rhs1 = gimple_assign_rhs1(stmt);
88495 + rhs1_type = TREE_TYPE(rhs1);
88496 + if (TYPE_UNSIGNED(rhs1_type) != TYPE_UNSIGNED(lhs_type))
88497 + return create_assign(visited, stmt, rhs1, AFTER_STMT);
88498 +
88499 + if (!check_mode_type(stmt))
88500 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88501 +
88502 + size_overflow_type = get_size_overflow_type(stmt, lhs);
88503 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
88504 +
88505 + check_size_overflow(stmt, size_overflow_type, new_rhs1, lhs, BEFORE_STMT);
88506 +
88507 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88508 +}
88509 +
88510 +static tree handle_unary_ops(struct pointer_set_t *visited, tree lhs)
88511 +{
88512 + gimple def_stmt = get_def_stmt(lhs);
88513 + tree rhs1 = gimple_assign_rhs1(def_stmt);
88514 +
88515 + if (is_gimple_constant(rhs1))
88516 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
88517 +
88518 + gcc_assert(TREE_CODE(rhs1) != COND_EXPR);
88519 + switch (TREE_CODE(rhs1)) {
88520 + case SSA_NAME:
88521 + return handle_unary_rhs(visited, def_stmt);
88522 + case ARRAY_REF:
88523 + case BIT_FIELD_REF:
88524 + case ADDR_EXPR:
88525 + case COMPONENT_REF:
88526 + case INDIRECT_REF:
88527 +#if BUILDING_GCC_VERSION >= 4006
88528 + case MEM_REF:
88529 +#endif
88530 + case PARM_DECL:
88531 + case TARGET_MEM_REF:
88532 + case VAR_DECL:
88533 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
88534 +
88535 + default:
88536 + debug_gimple_stmt(def_stmt);
88537 + debug_tree(rhs1);
88538 + gcc_unreachable();
88539 + }
88540 +}
88541 +
88542 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
88543 +{
88544 + gimple cond_stmt;
88545 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
88546 +
88547 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
88548 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
88549 + update_stmt(cond_stmt);
88550 +}
88551 +
88552 +static tree create_string_param(tree string)
88553 +{
88554 + tree i_type, a_type;
88555 + const int length = TREE_STRING_LENGTH(string);
88556 +
88557 + gcc_assert(length > 0);
88558 +
88559 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
88560 + a_type = build_array_type(char_type_node, i_type);
88561 +
88562 + TREE_TYPE(string) = a_type;
88563 + TREE_CONSTANT(string) = 1;
88564 + TREE_READONLY(string) = 1;
88565 +
88566 + return build1(ADDR_EXPR, ptr_type_node, string);
88567 +}
88568 +
88569 +static void insert_cond_result(basic_block bb_true, const_gimple stmt, const_tree arg, bool min)
88570 +{
88571 + gimple func_stmt;
88572 + const_gimple def_stmt;
88573 + const_tree loc_line;
88574 + tree loc_file, ssa_name, current_func;
88575 + expanded_location xloc;
88576 + char ssa_name_buf[256];
88577 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
88578 +
88579 + def_stmt = get_def_stmt(arg);
88580 + xloc = expand_location(gimple_location(def_stmt));
88581 +
88582 + if (!gimple_has_location(def_stmt)) {
88583 + xloc = expand_location(gimple_location(stmt));
88584 + if (!gimple_has_location(stmt))
88585 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
88586 + }
88587 +
88588 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
88589 +
88590 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
88591 + loc_file = create_string_param(loc_file);
88592 +
88593 + current_func = build_string(NAME_LEN(current_function_decl) + 1, NAME(current_function_decl));
88594 + current_func = create_string_param(current_func);
88595 +
88596 + snprintf(ssa_name_buf, 256, "%s_%u (%s)\n", NAME(SSA_NAME_VAR(arg)), SSA_NAME_VERSION(arg), min ? "min" : "max");
88597 + ssa_name = build_string(256, ssa_name_buf);
88598 + ssa_name = create_string_param(ssa_name);
88599 +
88600 + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
88601 + func_stmt = gimple_build_call(report_size_overflow_decl, 4, loc_file, loc_line, current_func, ssa_name);
88602 +
88603 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
88604 +}
88605 +
88606 +static void __unused print_the_code_insertions(const_gimple stmt)
88607 +{
88608 + location_t loc = gimple_location(stmt);
88609 +
88610 + inform(loc, "Integer size_overflow check applied here.");
88611 +}
88612 +
88613 +static void insert_check_size_overflow(gimple stmt, enum tree_code cond_code, tree arg, tree type_value, bool before, bool min)
88614 +{
88615 + basic_block cond_bb, join_bb, bb_true;
88616 + edge e;
88617 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
88618 +
88619 + cond_bb = gimple_bb(stmt);
88620 + if (before)
88621 + gsi_prev(&gsi);
88622 + if (gsi_end_p(gsi))
88623 + e = split_block_after_labels(cond_bb);
88624 + else
88625 + e = split_block(cond_bb, gsi_stmt(gsi));
88626 + cond_bb = e->src;
88627 + join_bb = e->dest;
88628 + e->flags = EDGE_FALSE_VALUE;
88629 + e->probability = REG_BR_PROB_BASE;
88630 +
88631 + bb_true = create_empty_bb(cond_bb);
88632 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
88633 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
88634 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
88635 +
88636 + if (dom_info_available_p(CDI_DOMINATORS)) {
88637 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
88638 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
88639 + }
88640 +
88641 + if (current_loops != NULL) {
88642 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
88643 + add_bb_to_loop(bb_true, cond_bb->loop_father);
88644 + }
88645 +
88646 + insert_cond(cond_bb, arg, cond_code, type_value);
88647 + insert_cond_result(bb_true, stmt, arg, min);
88648 +
88649 +// print_the_code_insertions(stmt);
88650 +}
88651 +
88652 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before)
88653 +{
88654 + const_tree rhs_type = TREE_TYPE(rhs);
88655 + tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min;
88656 +
88657 + gcc_assert(rhs_type != NULL_TREE);
88658 + if (TREE_CODE(rhs_type) == POINTER_TYPE)
88659 + return;
88660 +
88661 + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == BOOLEAN_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
88662 +
88663 + type_max = cast_a_tree(size_overflow_type, TYPE_MAX_VALUE(rhs_type));
88664 + type_min = cast_a_tree(size_overflow_type, TYPE_MIN_VALUE(rhs_type));
88665 +
88666 + gcc_assert(!TREE_OVERFLOW(type_max));
88667 +
88668 + cast_rhs_type = TREE_TYPE(cast_rhs);
88669 + type_max_type = TREE_TYPE(type_max);
88670 + type_min_type = TREE_TYPE(type_min);
88671 + gcc_assert(useless_type_conversion_p(cast_rhs_type, type_max_type));
88672 + gcc_assert(useless_type_conversion_p(type_max_type, type_min_type));
88673 +
88674 + insert_check_size_overflow(stmt, GT_EXPR, cast_rhs, type_max, before, false);
88675 + insert_check_size_overflow(stmt, LT_EXPR, cast_rhs, type_min, before, true);
88676 +}
88677 +
88678 +static tree get_size_overflow_type_for_intentional_overflow(gimple def_stmt, tree change_rhs)
88679 +{
88680 + gimple change_rhs_def_stmt;
88681 + tree lhs = gimple_get_lhs(def_stmt);
88682 + tree lhs_type = TREE_TYPE(lhs);
88683 + tree rhs1_type = TREE_TYPE(gimple_assign_rhs1(def_stmt));
88684 + tree rhs2_type = TREE_TYPE(gimple_assign_rhs2(def_stmt));
88685 +
88686 + if (change_rhs == NULL_TREE)
88687 + return get_size_overflow_type(def_stmt, lhs);
88688 +
88689 + change_rhs_def_stmt = get_def_stmt(change_rhs);
88690 +
88691 + if (TREE_CODE_CLASS(gimple_assign_rhs_code(def_stmt)) == tcc_comparison)
88692 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
88693 +
88694 + if (gimple_assign_rhs_code(def_stmt) == LSHIFT_EXPR)
88695 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
88696 +
88697 + if (gimple_assign_rhs_code(def_stmt) == RSHIFT_EXPR)
88698 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
88699 +
88700 + if (!useless_type_conversion_p(lhs_type, rhs1_type) || !useless_type_conversion_p(rhs1_type, rhs2_type)) {
88701 + debug_gimple_stmt(def_stmt);
88702 + gcc_unreachable();
88703 + }
88704 +
88705 + return get_size_overflow_type(def_stmt, lhs);
88706 +}
88707 +
88708 +static bool is_a_constant_overflow(const_gimple stmt, const_tree rhs)
88709 +{
88710 + if (gimple_assign_rhs_code(stmt) == MIN_EXPR)
88711 + return false;
88712 + if (!is_gimple_constant(rhs))
88713 + return false;
88714 + return true;
88715 +}
88716 +
88717 +static tree get_cast_def_stmt_rhs(const_tree new_rhs)
88718 +{
88719 + gimple def_stmt;
88720 +
88721 + def_stmt = get_def_stmt(new_rhs);
88722 + // get_size_overflow_type
88723 + if (LONG_TYPE_SIZE != GET_MODE_BITSIZE(SImode))
88724 + gcc_assert(gimple_assign_cast_p(def_stmt));
88725 + return gimple_assign_rhs1(def_stmt);
88726 +}
88727 +
88728 +static tree cast_to_int_TI_type_and_check(gimple stmt, tree new_rhs)
88729 +{
88730 + gimple_stmt_iterator gsi;
88731 + const_gimple cast_stmt;
88732 + gimple def_stmt;
88733 + enum machine_mode mode = TYPE_MODE(TREE_TYPE(new_rhs));
88734 +
88735 + if (mode != TImode && mode != DImode) {
88736 + def_stmt = get_def_stmt(new_rhs);
88737 + gcc_assert(gimple_assign_cast_p(def_stmt));
88738 + new_rhs = gimple_assign_rhs1(def_stmt);
88739 + mode = TYPE_MODE(TREE_TYPE(new_rhs));
88740 + }
88741 +
88742 + gcc_assert(mode == TImode || mode == DImode);
88743 +
88744 + if (mode == TYPE_MODE(intTI_type_node) && useless_type_conversion_p(TREE_TYPE(new_rhs), intTI_type_node))
88745 + return new_rhs;
88746 +
88747 + gsi = gsi_for_stmt(stmt);
88748 + cast_stmt = build_cast_stmt(intTI_type_node, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
88749 + new_rhs = gimple_get_lhs(cast_stmt);
88750 +
88751 + if (mode == DImode)
88752 + return new_rhs;
88753 +
88754 + check_size_overflow(stmt, intTI_type_node, new_rhs, new_rhs, BEFORE_STMT);
88755 +
88756 + return new_rhs;
88757 +}
88758 +
88759 +static bool is_an_integer_trunction(const_gimple stmt)
88760 +{
88761 + gimple rhs1_def_stmt, rhs2_def_stmt;
88762 + const_tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1;
88763 + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode;
88764 + const_tree rhs1 = gimple_assign_rhs1(stmt);
88765 + const_tree rhs2 = gimple_assign_rhs2(stmt);
88766 + enum machine_mode rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1));
88767 + enum machine_mode rhs2_mode = TYPE_MODE(TREE_TYPE(rhs2));
88768 +
88769 + if (is_gimple_constant(rhs1) || is_gimple_constant(rhs2))
88770 + return false;
88771 +
88772 + gcc_assert(TREE_CODE(rhs1) == SSA_NAME && TREE_CODE(rhs2) == SSA_NAME);
88773 +
88774 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR || rhs1_mode != SImode || rhs2_mode != SImode)
88775 + return false;
88776 +
88777 + rhs1_def_stmt = get_def_stmt(rhs1);
88778 + rhs2_def_stmt = get_def_stmt(rhs2);
88779 + if (!gimple_assign_cast_p(rhs1_def_stmt) || !gimple_assign_cast_p(rhs2_def_stmt))
88780 + return false;
88781 +
88782 + rhs1_def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
88783 + rhs2_def_stmt_rhs1 = gimple_assign_rhs1(rhs2_def_stmt);
88784 + rhs1_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_rhs1));
88785 + rhs2_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_rhs1));
88786 + if (rhs1_def_stmt_rhs1_mode != DImode || rhs2_def_stmt_rhs1_mode != DImode)
88787 + return false;
88788 +
88789 + gimple_set_plf(rhs1_def_stmt, NO_CAST_CHECK, true);
88790 + gimple_set_plf(rhs2_def_stmt, NO_CAST_CHECK, true);
88791 + return true;
88792 +}
88793 +
88794 +static tree handle_integer_truncation(struct pointer_set_t *visited, const_tree lhs)
88795 +{
88796 + tree new_rhs1, new_rhs2;
88797 + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
88798 + tree new_rhs1_def_stmt_rhs1_type, new_rhs2_def_stmt_rhs1_type;
88799 + gimple assign, stmt = get_def_stmt(lhs);
88800 + tree rhs1 = gimple_assign_rhs1(stmt);
88801 + tree rhs2 = gimple_assign_rhs2(stmt);
88802 +
88803 + if (!is_an_integer_trunction(stmt))
88804 + return NULL_TREE;
88805 +
88806 + new_rhs1 = expand(visited, rhs1);
88807 + new_rhs2 = expand(visited, rhs2);
88808 +
88809 + new_rhs1_def_stmt_rhs1 = get_cast_def_stmt_rhs(new_rhs1);
88810 + new_rhs2_def_stmt_rhs1 = get_cast_def_stmt_rhs(new_rhs2);
88811 +
88812 + new_rhs1_def_stmt_rhs1_type = TREE_TYPE(new_rhs1_def_stmt_rhs1);
88813 + new_rhs2_def_stmt_rhs1_type = TREE_TYPE(new_rhs2_def_stmt_rhs1);
88814 +
88815 + if (!useless_type_conversion_p(new_rhs1_def_stmt_rhs1_type, new_rhs2_def_stmt_rhs1_type)) {
88816 + new_rhs1_def_stmt_rhs1 = cast_to_int_TI_type_and_check(stmt, new_rhs1_def_stmt_rhs1);
88817 + new_rhs2_def_stmt_rhs1 = cast_to_int_TI_type_and_check(stmt, new_rhs2_def_stmt_rhs1);
88818 + }
88819 +
88820 + assign = create_binary_assign(MINUS_EXPR, stmt, new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1);
88821 + new_lhs = gimple_get_lhs(assign);
88822 + check_size_overflow(assign, TREE_TYPE(new_lhs), new_lhs, rhs1, AFTER_STMT);
88823 +
88824 + return follow_overflow_type_and_dup(visited, stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
88825 +}
88826 +
88827 +static bool is_a_neg_overflow(const_gimple stmt, const_tree rhs)
88828 +{
88829 + const_gimple def_stmt;
88830 +
88831 + if (TREE_CODE(rhs) != SSA_NAME)
88832 + return false;
88833 +
88834 + if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
88835 + return false;
88836 +
88837 + def_stmt = get_def_stmt(rhs);
88838 + if (gimple_code(def_stmt) != GIMPLE_ASSIGN || gimple_assign_rhs_code(def_stmt) != BIT_NOT_EXPR)
88839 + return false;
88840 +
88841 + return true;
88842 +}
88843 +
88844 +static tree handle_intentional_overflow(struct pointer_set_t *visited, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs1, tree new_rhs2)
88845 +{
88846 + tree new_rhs, size_overflow_type, orig_rhs;
88847 + void (*gimple_assign_set_rhs)(gimple, tree);
88848 + tree rhs1 = gimple_assign_rhs1(stmt);
88849 + tree rhs2 = gimple_assign_rhs2(stmt);
88850 + tree lhs = gimple_get_lhs(stmt);
88851 +
88852 + if (change_rhs == NULL_TREE)
88853 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88854 +
88855 + if (new_rhs2 == NULL_TREE) {
88856 + size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs1);
88857 + new_rhs2 = cast_a_tree(size_overflow_type, rhs2);
88858 + orig_rhs = rhs1;
88859 + gimple_assign_set_rhs = &gimple_assign_set_rhs1;
88860 + } else {
88861 + size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs2);
88862 + new_rhs1 = cast_a_tree(size_overflow_type, rhs1);
88863 + orig_rhs = rhs2;
88864 + gimple_assign_set_rhs = &gimple_assign_set_rhs2;
88865 + }
88866 +
88867 + change_rhs = cast_to_new_size_overflow_type(stmt, change_rhs, size_overflow_type, BEFORE_STMT);
88868 +
88869 + if (check_overflow)
88870 + check_size_overflow(stmt, size_overflow_type, change_rhs, orig_rhs, BEFORE_STMT);
88871 +
88872 + new_rhs = change_assign_rhs(stmt, orig_rhs, change_rhs);
88873 + gimple_assign_set_rhs(stmt, new_rhs);
88874 + update_stmt(stmt);
88875 +
88876 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88877 +}
88878 +
88879 +static tree handle_binary_ops(struct pointer_set_t *visited, tree lhs)
88880 +{
88881 + tree rhs1, rhs2, new_lhs;
88882 + gimple def_stmt = get_def_stmt(lhs);
88883 + tree new_rhs1 = NULL_TREE;
88884 + tree new_rhs2 = NULL_TREE;
88885 +
88886 + rhs1 = gimple_assign_rhs1(def_stmt);
88887 + rhs2 = gimple_assign_rhs2(def_stmt);
88888 +
88889 + /* no DImode/TImode division in the 32/64 bit kernel */
88890 + switch (gimple_assign_rhs_code(def_stmt)) {
88891 + case RDIV_EXPR:
88892 + case TRUNC_DIV_EXPR:
88893 + case CEIL_DIV_EXPR:
88894 + case FLOOR_DIV_EXPR:
88895 + case ROUND_DIV_EXPR:
88896 + case TRUNC_MOD_EXPR:
88897 + case CEIL_MOD_EXPR:
88898 + case FLOOR_MOD_EXPR:
88899 + case ROUND_MOD_EXPR:
88900 + case EXACT_DIV_EXPR:
88901 + case POINTER_PLUS_EXPR:
88902 + case BIT_AND_EXPR:
88903 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
88904 + default:
88905 + break;
88906 + }
88907 +
88908 + new_lhs = handle_integer_truncation(visited, lhs);
88909 + if (new_lhs != NULL_TREE)
88910 + return new_lhs;
88911 +
88912 + if (TREE_CODE(rhs1) == SSA_NAME)
88913 + new_rhs1 = expand(visited, rhs1);
88914 + if (TREE_CODE(rhs2) == SSA_NAME)
88915 + new_rhs2 = expand(visited, rhs2);
88916 +
88917 + if (is_a_neg_overflow(def_stmt, rhs2))
88918 + return handle_intentional_overflow(visited, true, def_stmt, new_rhs1, new_rhs1, NULL_TREE);
88919 + if (is_a_neg_overflow(def_stmt, rhs1))
88920 + return handle_intentional_overflow(visited, true, def_stmt, new_rhs2, NULL_TREE, new_rhs2);
88921 +
88922 + if (is_a_constant_overflow(def_stmt, rhs2))
88923 + return handle_intentional_overflow(visited, !is_a_cast_and_const_overflow(rhs1), def_stmt, new_rhs1, new_rhs1, NULL_TREE);
88924 + if (is_a_constant_overflow(def_stmt, rhs1))
88925 + return handle_intentional_overflow(visited, !is_a_cast_and_const_overflow(rhs2), def_stmt, new_rhs2, NULL_TREE, new_rhs2);
88926 +
88927 + return follow_overflow_type_and_dup(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
88928 +}
88929 +
88930 +#if BUILDING_GCC_VERSION >= 4007
88931 +static tree get_new_rhs(struct pointer_set_t *visited, tree size_overflow_type, tree rhs)
88932 +{
88933 + if (is_gimple_constant(rhs))
88934 + return cast_a_tree(size_overflow_type, rhs);
88935 + if (TREE_CODE(rhs) != SSA_NAME)
88936 + return NULL_TREE;
88937 + return expand(visited, rhs);
88938 +}
88939 +
88940 +static tree handle_ternary_ops(struct pointer_set_t *visited, tree lhs)
88941 +{
88942 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
88943 + gimple def_stmt = get_def_stmt(lhs);
88944 +
88945 + size_overflow_type = get_size_overflow_type(def_stmt, lhs);
88946 +
88947 + rhs1 = gimple_assign_rhs1(def_stmt);
88948 + rhs2 = gimple_assign_rhs2(def_stmt);
88949 + rhs3 = gimple_assign_rhs3(def_stmt);
88950 + new_rhs1 = get_new_rhs(visited, size_overflow_type, rhs1);
88951 + new_rhs2 = get_new_rhs(visited, size_overflow_type, rhs2);
88952 + new_rhs3 = get_new_rhs(visited, size_overflow_type, rhs3);
88953 +
88954 + return follow_overflow_type_and_dup(visited, def_stmt, lhs, new_rhs1, new_rhs2, new_rhs3);
88955 +}
88956 +#endif
88957 +
88958 +static tree get_size_overflow_type(gimple stmt, const_tree node)
88959 +{
88960 + const_tree type;
88961 +
88962 + gcc_assert(node != NULL_TREE);
88963 +
88964 + type = TREE_TYPE(node);
88965 +
88966 + if (gimple_plf(stmt, MY_STMT))
88967 + return TREE_TYPE(node);
88968 +
88969 + switch (TYPE_MODE(type)) {
88970 + case QImode:
88971 + return (TYPE_UNSIGNED(type)) ? unsigned_intHI_type_node : intHI_type_node;
88972 + case HImode:
88973 + return (TYPE_UNSIGNED(type)) ? unsigned_intSI_type_node : intSI_type_node;
88974 + case SImode:
88975 + return (TYPE_UNSIGNED(type)) ? unsigned_intDI_type_node : intDI_type_node;
88976 + case DImode:
88977 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
88978 + return (TYPE_UNSIGNED(type)) ? unsigned_intDI_type_node : intDI_type_node;
88979 + return (TYPE_UNSIGNED(type)) ? unsigned_intTI_type_node : intTI_type_node;
88980 + default:
88981 + debug_tree((tree)node);
88982 + error("%s: unsupported gcc configuration.", __func__);
88983 + gcc_unreachable();
88984 + }
88985 +}
88986 +
88987 +static tree expand_visited(gimple def_stmt)
88988 +{
88989 + const_gimple next_stmt;
88990 + gimple_stmt_iterator gsi = gsi_for_stmt(def_stmt);
88991 +
88992 + gsi_next(&gsi);
88993 + next_stmt = gsi_stmt(gsi);
88994 +
88995 + gcc_assert(gimple_plf((gimple)next_stmt, MY_STMT));
88996 +
88997 + switch (gimple_code(next_stmt)) {
88998 + case GIMPLE_ASSIGN:
88999 + return gimple_get_lhs(next_stmt);
89000 + case GIMPLE_PHI:
89001 + return gimple_phi_result(next_stmt);
89002 + case GIMPLE_CALL:
89003 + return gimple_call_lhs(next_stmt);
89004 + default:
89005 + return NULL_TREE;
89006 + }
89007 +}
89008 +
89009 +static tree expand(struct pointer_set_t *visited, tree lhs)
89010 +{
89011 + gimple def_stmt;
89012 + enum tree_code code = TREE_CODE(TREE_TYPE(lhs));
89013 +
89014 + if (is_gimple_constant(lhs))
89015 + return NULL_TREE;
89016 +
89017 + if (TREE_CODE(lhs) == ADDR_EXPR)
89018 + return NULL_TREE;
89019 +
89020 + if (code == REAL_TYPE)
89021 + return NULL_TREE;
89022 +
89023 + gcc_assert(code == INTEGER_TYPE || code == POINTER_TYPE || code == BOOLEAN_TYPE || code == ENUMERAL_TYPE);
89024 +
89025 +
89026 + def_stmt = get_def_stmt(lhs);
89027 +
89028 + if (!def_stmt)
89029 + return NULL_TREE;
89030 +
89031 + if (gimple_plf(def_stmt, MY_STMT))
89032 + return lhs;
89033 +
89034 + if (pointer_set_contains(visited, def_stmt))
89035 + return expand_visited(def_stmt);
89036 +
89037 + switch (gimple_code(def_stmt)) {
89038 + case GIMPLE_NOP:
89039 + return NULL_TREE;
89040 + case GIMPLE_PHI:
89041 + return build_new_phi(visited, lhs);
89042 + case GIMPLE_CALL:
89043 + case GIMPLE_ASM:
89044 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
89045 + case GIMPLE_ASSIGN:
89046 + switch (gimple_num_ops(def_stmt)) {
89047 + case 2:
89048 + return handle_unary_ops(visited, lhs);
89049 + case 3:
89050 + return handle_binary_ops(visited, lhs);
89051 +#if BUILDING_GCC_VERSION >= 4007
89052 + case 4:
89053 + return handle_ternary_ops(visited, lhs);
89054 +#endif
89055 + }
89056 + default:
89057 + debug_gimple_stmt(def_stmt);
89058 + error("%s: unknown gimple code", __func__);
89059 + gcc_unreachable();
89060 + }
89061 +}
89062 +
89063 +static void change_function_arg(gimple stmt, const_tree origarg, unsigned int argnum, tree newarg)
89064 +{
89065 + const_gimple assign;
89066 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
89067 + tree origtype = TREE_TYPE(origarg);
89068 +
89069 + gcc_assert(gimple_code(stmt) == GIMPLE_CALL);
89070 +
89071 + assign = build_cast_stmt(origtype, newarg, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
89072 +
89073 + gimple_call_set_arg(stmt, argnum, gimple_get_lhs(assign));
89074 + update_stmt(stmt);
89075 +}
89076 +
89077 +static bool get_function_arg(unsigned int* argnum, const_tree fndecl)
89078 +{
89079 + const char *origid;
89080 + tree arg;
89081 + const_tree origarg;
89082 +
89083 + if (!DECL_ABSTRACT_ORIGIN(fndecl))
89084 + return true;
89085 +
89086 + origarg = DECL_ARGUMENTS(DECL_ABSTRACT_ORIGIN(fndecl));
89087 + while (origarg && *argnum) {
89088 + (*argnum)--;
89089 + origarg = TREE_CHAIN(origarg);
89090 + }
89091 +
89092 + gcc_assert(*argnum == 0);
89093 +
89094 + gcc_assert(origarg != NULL_TREE);
89095 + origid = NAME(origarg);
89096 + *argnum = 0;
89097 + for (arg = DECL_ARGUMENTS(fndecl); arg; arg = TREE_CHAIN(arg)) {
89098 + if (!strcmp(origid, NAME(arg)))
89099 + return true;
89100 + (*argnum)++;
89101 + }
89102 + return false;
89103 +}
89104 +
89105 +static bool skip_types(const_tree var)
89106 +{
89107 + switch (TREE_CODE(var)) {
89108 + case ADDR_EXPR:
89109 +#if BUILDING_GCC_VERSION >= 4006
89110 + case MEM_REF:
89111 +#endif
89112 + case ARRAY_REF:
89113 + case BIT_FIELD_REF:
89114 + case INDIRECT_REF:
89115 + case TARGET_MEM_REF:
89116 + case VAR_DECL:
89117 + return true;
89118 + default:
89119 + break;
89120 + }
89121 + return false;
89122 +}
89123 +
89124 +static bool walk_phi(struct pointer_set_t *visited, const_tree result)
89125 +{
89126 + gimple phi = get_def_stmt(result);
89127 + unsigned int i, n = gimple_phi_num_args(phi);
89128 +
89129 + if (!phi)
89130 + return false;
89131 +
89132 + pointer_set_insert(visited, phi);
89133 + for (i = 0; i < n; i++) {
89134 + const_tree arg = gimple_phi_arg_def(phi, i);
89135 + if (pre_expand(visited, arg))
89136 + return true;
89137 + }
89138 + return false;
89139 +}
89140 +
89141 +static bool walk_unary_ops(struct pointer_set_t *visited, const_tree lhs)
89142 +{
89143 + gimple def_stmt = get_def_stmt(lhs);
89144 + const_tree rhs;
89145 +
89146 + if (!def_stmt)
89147 + return false;
89148 +
89149 + rhs = gimple_assign_rhs1(def_stmt);
89150 + if (pre_expand(visited, rhs))
89151 + return true;
89152 + return false;
89153 +}
89154 +
89155 +static bool walk_binary_ops(struct pointer_set_t *visited, const_tree lhs)
89156 +{
89157 + bool rhs1_found, rhs2_found;
89158 + gimple def_stmt = get_def_stmt(lhs);
89159 + const_tree rhs1, rhs2;
89160 +
89161 + if (!def_stmt)
89162 + return false;
89163 +
89164 + rhs1 = gimple_assign_rhs1(def_stmt);
89165 + rhs2 = gimple_assign_rhs2(def_stmt);
89166 + rhs1_found = pre_expand(visited, rhs1);
89167 + rhs2_found = pre_expand(visited, rhs2);
89168 +
89169 + return rhs1_found || rhs2_found;
89170 +}
89171 +
89172 +static const_tree search_field_decl(const_tree comp_ref)
89173 +{
89174 + const_tree field = NULL_TREE;
89175 + unsigned int i, len = TREE_OPERAND_LENGTH(comp_ref);
89176 +
89177 + for (i = 0; i < len; i++) {
89178 + field = TREE_OPERAND(comp_ref, i);
89179 + if (TREE_CODE(field) == FIELD_DECL)
89180 + break;
89181 + }
89182 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
89183 + return field;
89184 +}
89185 +
89186 +static enum marked mark_status(const_tree fndecl, unsigned int argnum)
89187 +{
89188 + const_tree attr, p;
89189 +
89190 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(fndecl));
89191 + if (!attr || !TREE_VALUE(attr))
89192 + return MARKED_NO;
89193 +
89194 + p = TREE_VALUE(attr);
89195 + if (!TREE_INT_CST_LOW(TREE_VALUE(p)))
89196 + return MARKED_NOT_INTENTIONAL;
89197 +
89198 + do {
89199 + if (argnum == TREE_INT_CST_LOW(TREE_VALUE(p)))
89200 + return MARKED_YES;
89201 + p = TREE_CHAIN(p);
89202 + } while (p);
89203 +
89204 + return MARKED_NO;
89205 +}
89206 +
89207 +static void print_missing_msg(tree func, unsigned int argnum)
89208 +{
89209 + unsigned int new_hash;
89210 + size_t len;
89211 + unsigned char tree_codes[CODES_LIMIT];
89212 + location_t loc = DECL_SOURCE_LOCATION(func);
89213 + const char *curfunc = get_asm_name(func);
89214 +
89215 + len = get_function_decl(func, tree_codes);
89216 + new_hash = get_hash_num(curfunc, (const char *) tree_codes, len, 0);
89217 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%u+%u+", curfunc, curfunc, argnum, new_hash);
89218 +}
89219 +
89220 +static unsigned int search_missing_attribute(const_tree arg)
89221 +{
89222 + const_tree type = TREE_TYPE(arg);
89223 + tree func = get_original_function_decl(current_function_decl);
89224 + unsigned int argnum;
89225 + const struct size_overflow_hash *hash;
89226 +
89227 + gcc_assert(TREE_CODE(arg) != COMPONENT_REF);
89228 +
89229 + if (TREE_CODE(type) == POINTER_TYPE)
89230 + return 0;
89231 +
89232 + argnum = find_arg_number(arg, func);
89233 + if (argnum == 0)
89234 + return 0;
89235 +
89236 + if (lookup_attribute("size_overflow", DECL_ATTRIBUTES(func)))
89237 + return argnum;
89238 +
89239 + hash = get_function_hash(func);
89240 + if (!hash || !(hash->param & (1U << argnum))) {
89241 + print_missing_msg(func, argnum);
89242 + return 0;
89243 + }
89244 + return argnum;
89245 +}
89246 +
89247 +static bool is_already_marked(const_tree lhs)
89248 +{
89249 + unsigned int argnum;
89250 + const_tree fndecl;
89251 +
89252 + argnum = search_missing_attribute(lhs);
89253 + fndecl = get_original_function_decl(current_function_decl);
89254 + if (argnum && mark_status(fndecl, argnum) == MARKED_YES)
89255 + return true;
89256 + return false;
89257 +}
89258 +
89259 +static bool pre_expand(struct pointer_set_t *visited, const_tree lhs)
89260 +{
89261 + const_gimple def_stmt;
89262 +
89263 + if (is_gimple_constant(lhs))
89264 + return false;
89265 +
89266 + if (skip_types(lhs))
89267 + return false;
89268 +
89269 + if (TREE_CODE(lhs) == PARM_DECL)
89270 + return is_already_marked(lhs);
89271 +
89272 + if (TREE_CODE(lhs) == COMPONENT_REF) {
89273 + const_tree field, attr;
89274 +
89275 + field = search_field_decl(lhs);
89276 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(field));
89277 + if (!attr || !TREE_VALUE(attr))
89278 + return false;
89279 + return true;
89280 + }
89281 +
89282 + def_stmt = get_def_stmt(lhs);
89283 +
89284 + if (!def_stmt)
89285 + return false;
89286 +
89287 + if (pointer_set_contains(visited, def_stmt))
89288 + return false;
89289 +
89290 + switch (gimple_code(def_stmt)) {
89291 + case GIMPLE_NOP:
89292 + if (TREE_CODE(SSA_NAME_VAR(lhs)) == PARM_DECL)
89293 + return is_already_marked(lhs);
89294 + return false;
89295 + case GIMPLE_PHI:
89296 + return walk_phi(visited, lhs);
89297 + case GIMPLE_CALL:
89298 + case GIMPLE_ASM:
89299 + return false;
89300 + case GIMPLE_ASSIGN:
89301 + switch (gimple_num_ops(def_stmt)) {
89302 + case 2:
89303 + return walk_unary_ops(visited, lhs);
89304 + case 3:
89305 + return walk_binary_ops(visited, lhs);
89306 + }
89307 + default:
89308 + debug_gimple_stmt((gimple)def_stmt);
89309 + error("%s: unknown gimple code", __func__);
89310 + gcc_unreachable();
89311 + }
89312 +}
89313 +
89314 +static bool search_attributes(tree fndecl, const_tree arg, unsigned int argnum)
89315 +{
89316 + struct pointer_set_t *visited;
89317 + bool is_found;
89318 + enum marked is_marked;
89319 + location_t loc;
89320 +
89321 + visited = pointer_set_create();
89322 + is_found = pre_expand(visited, arg);
89323 + pointer_set_destroy(visited);
89324 +
89325 + is_marked = mark_status(fndecl, argnum + 1);
89326 + if ((is_found && is_marked == MARKED_YES) || is_marked == MARKED_NOT_INTENTIONAL)
89327 + return true;
89328 +
89329 + if (is_found) {
89330 + loc = DECL_SOURCE_LOCATION(fndecl);
89331 + inform(loc, "The intentional_overflow attribute is missing from +%s+%u+", get_asm_name(fndecl), argnum + 1);
89332 + return true;
89333 + }
89334 + return false;
89335 +}
89336 +
89337 +static void handle_function_arg(gimple stmt, tree fndecl, unsigned int argnum)
89338 +{
89339 + struct pointer_set_t *visited;
89340 + tree arg, newarg;
89341 + bool match;
89342 +
89343 + match = get_function_arg(&argnum, fndecl);
89344 + if (!match)
89345 + return;
89346 + gcc_assert(gimple_call_num_args(stmt) > argnum);
89347 + arg = gimple_call_arg(stmt, argnum);
89348 + if (arg == NULL_TREE)
89349 + return;
89350 +
89351 + if (is_gimple_constant(arg))
89352 + return;
89353 +
89354 + if (search_attributes(fndecl, arg, argnum))
89355 + return;
89356 +
89357 + if (TREE_CODE(arg) != SSA_NAME)
89358 + return;
89359 +
89360 + check_arg_type(arg);
89361 +
89362 + visited = pointer_set_create();
89363 + newarg = expand(visited, arg);
89364 + pointer_set_destroy(visited);
89365 +
89366 + if (newarg == NULL_TREE)
89367 + return;
89368 +
89369 + change_function_arg(stmt, arg, argnum, newarg);
89370 +
89371 + check_size_overflow(stmt, TREE_TYPE(newarg), newarg, arg, BEFORE_STMT);
89372 +}
89373 +
89374 +static void handle_function_by_attribute(gimple stmt, const_tree attr, tree fndecl)
89375 +{
89376 + tree p = TREE_VALUE(attr);
89377 + do {
89378 + handle_function_arg(stmt, fndecl, TREE_INT_CST_LOW(TREE_VALUE(p))-1);
89379 + p = TREE_CHAIN(p);
89380 + } while (p);
89381 +}
89382 +
89383 +static void handle_function_by_hash(gimple stmt, tree fndecl)
89384 +{
89385 + tree orig_fndecl;
89386 + unsigned int num;
89387 + const struct size_overflow_hash *hash;
89388 +
89389 + orig_fndecl = get_original_function_decl(fndecl);
89390 + if (C_DECL_IMPLICIT(orig_fndecl))
89391 + return;
89392 + hash = get_function_hash(orig_fndecl);
89393 + if (!hash)
89394 + return;
89395 +
89396 + for (num = 1; num <= MAX_PARAM; num++)
89397 + if (hash->param & (1U << num))
89398 + handle_function_arg(stmt, fndecl, num - 1);
89399 +}
89400 +
89401 +static void set_plf_false(void)
89402 +{
89403 + basic_block bb;
89404 +
89405 + FOR_ALL_BB(bb) {
89406 + gimple_stmt_iterator si;
89407 +
89408 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
89409 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
89410 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
89411 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
89412 + }
89413 +}
89414 +
89415 +static unsigned int handle_function(void)
89416 +{
89417 + basic_block next, bb = ENTRY_BLOCK_PTR->next_bb;
89418 +
89419 + set_plf_false();
89420 +
89421 + do {
89422 + gimple_stmt_iterator gsi;
89423 + next = bb->next_bb;
89424 +
89425 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
89426 + tree fndecl, attr;
89427 + gimple stmt = gsi_stmt(gsi);
89428 +
89429 + if (!(is_gimple_call(stmt)))
89430 + continue;
89431 + fndecl = gimple_call_fndecl(stmt);
89432 + if (fndecl == NULL_TREE)
89433 + continue;
89434 + if (gimple_call_num_args(stmt) == 0)
89435 + continue;
89436 + attr = lookup_attribute("size_overflow", DECL_ATTRIBUTES(fndecl));
89437 + if (!attr || !TREE_VALUE(attr))
89438 + handle_function_by_hash(stmt, fndecl);
89439 + else
89440 + handle_function_by_attribute(stmt, attr, fndecl);
89441 + gsi = gsi_for_stmt(stmt);
89442 + next = gimple_bb(stmt)->next_bb;
89443 + }
89444 + bb = next;
89445 + } while (bb);
89446 + return 0;
89447 +}
89448 +
89449 +static struct gimple_opt_pass size_overflow_pass = {
89450 + .pass = {
89451 + .type = GIMPLE_PASS,
89452 + .name = "size_overflow",
89453 + .gate = NULL,
89454 + .execute = handle_function,
89455 + .sub = NULL,
89456 + .next = NULL,
89457 + .static_pass_number = 0,
89458 + .tv_id = TV_NONE,
89459 + .properties_required = PROP_cfg | PROP_referenced_vars,
89460 + .properties_provided = 0,
89461 + .properties_destroyed = 0,
89462 + .todo_flags_start = 0,
89463 + .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
89464 + }
89465 +};
89466 +
89467 +static void start_unit_callback(void __unused *gcc_data, void __unused *user_data)
89468 +{
89469 + tree fntype;
89470 +
89471 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
89472 +
89473 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func, const char *ssa_var)
89474 + fntype = build_function_type_list(void_type_node,
89475 + const_char_ptr_type_node,
89476 + unsigned_type_node,
89477 + const_char_ptr_type_node,
89478 + const_char_ptr_type_node,
89479 + NULL_TREE);
89480 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
89481 +
89482 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
89483 + TREE_PUBLIC(report_size_overflow_decl) = 1;
89484 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
89485 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
89486 + TREE_THIS_VOLATILE(report_size_overflow_decl) = 1;
89487 +}
89488 +
89489 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
89490 +{
89491 + int i;
89492 + const char * const plugin_name = plugin_info->base_name;
89493 + const int argc = plugin_info->argc;
89494 + const struct plugin_argument * const argv = plugin_info->argv;
89495 + bool enable = true;
89496 +
89497 + struct register_pass_info size_overflow_pass_info = {
89498 + .pass = &size_overflow_pass.pass,
89499 + .reference_pass_name = "ssa",
89500 + .ref_pass_instance_number = 1,
89501 + .pos_op = PASS_POS_INSERT_AFTER
89502 + };
89503 +
89504 + if (!plugin_default_version_check(version, &gcc_version)) {
89505 + error(G_("incompatible gcc/plugin versions"));
89506 + return 1;
89507 + }
89508 +
89509 + for (i = 0; i < argc; ++i) {
89510 + if (!strcmp(argv[i].key, "no-size-overflow")) {
89511 + enable = false;
89512 + continue;
89513 + }
89514 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
89515 + }
89516 +
89517 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
89518 + if (enable) {
89519 + register_callback("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
89520 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &size_overflow_pass_info);
89521 + }
89522 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
89523 +
89524 + return 0;
89525 +}
89526 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
89527 new file mode 100644
89528 index 0000000..38d2014
89529 --- /dev/null
89530 +++ b/tools/gcc/stackleak_plugin.c
89531 @@ -0,0 +1,313 @@
89532 +/*
89533 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
89534 + * Licensed under the GPL v2
89535 + *
89536 + * Note: the choice of the license means that the compilation process is
89537 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
89538 + * but for the kernel it doesn't matter since it doesn't link against
89539 + * any of the gcc libraries
89540 + *
89541 + * gcc plugin to help implement various PaX features
89542 + *
89543 + * - track lowest stack pointer
89544 + *
89545 + * TODO:
89546 + * - initialize all local variables
89547 + *
89548 + * BUGS:
89549 + * - none known
89550 + */
89551 +#include "gcc-plugin.h"
89552 +#include "config.h"
89553 +#include "system.h"
89554 +#include "coretypes.h"
89555 +#include "tree.h"
89556 +#include "tree-pass.h"
89557 +#include "flags.h"
89558 +#include "intl.h"
89559 +#include "toplev.h"
89560 +#include "plugin.h"
89561 +//#include "expr.h" where are you...
89562 +#include "diagnostic.h"
89563 +#include "plugin-version.h"
89564 +#include "tm.h"
89565 +#include "function.h"
89566 +#include "basic-block.h"
89567 +#include "gimple.h"
89568 +#include "rtl.h"
89569 +#include "emit-rtl.h"
89570 +
89571 +extern void print_gimple_stmt(FILE *, gimple, int, int);
89572 +
89573 +int plugin_is_GPL_compatible;
89574 +
89575 +static int track_frame_size = -1;
89576 +static const char track_function[] = "pax_track_stack";
89577 +static const char check_function[] = "pax_check_alloca";
89578 +static bool init_locals;
89579 +
89580 +static struct plugin_info stackleak_plugin_info = {
89581 + .version = "201203140940",
89582 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
89583 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
89584 +};
89585 +
89586 +static bool gate_stackleak_track_stack(void);
89587 +static unsigned int execute_stackleak_tree_instrument(void);
89588 +static unsigned int execute_stackleak_final(void);
89589 +
89590 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
89591 + .pass = {
89592 + .type = GIMPLE_PASS,
89593 + .name = "stackleak_tree_instrument",
89594 + .gate = gate_stackleak_track_stack,
89595 + .execute = execute_stackleak_tree_instrument,
89596 + .sub = NULL,
89597 + .next = NULL,
89598 + .static_pass_number = 0,
89599 + .tv_id = TV_NONE,
89600 + .properties_required = PROP_gimple_leh | PROP_cfg,
89601 + .properties_provided = 0,
89602 + .properties_destroyed = 0,
89603 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
89604 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
89605 + }
89606 +};
89607 +
89608 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
89609 + .pass = {
89610 + .type = RTL_PASS,
89611 + .name = "stackleak_final",
89612 + .gate = gate_stackleak_track_stack,
89613 + .execute = execute_stackleak_final,
89614 + .sub = NULL,
89615 + .next = NULL,
89616 + .static_pass_number = 0,
89617 + .tv_id = TV_NONE,
89618 + .properties_required = 0,
89619 + .properties_provided = 0,
89620 + .properties_destroyed = 0,
89621 + .todo_flags_start = 0,
89622 + .todo_flags_finish = TODO_dump_func
89623 + }
89624 +};
89625 +
89626 +static bool gate_stackleak_track_stack(void)
89627 +{
89628 + return track_frame_size >= 0;
89629 +}
89630 +
89631 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
89632 +{
89633 + gimple check_alloca;
89634 + tree fntype, fndecl, alloca_size;
89635 +
89636 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
89637 + fndecl = build_fn_decl(check_function, fntype);
89638 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
89639 +
89640 + // insert call to void pax_check_alloca(unsigned long size)
89641 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
89642 + check_alloca = gimple_build_call(fndecl, 1, alloca_size);
89643 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
89644 +}
89645 +
89646 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
89647 +{
89648 + gimple track_stack;
89649 + tree fntype, fndecl;
89650 +
89651 + fntype = build_function_type_list(void_type_node, NULL_TREE);
89652 + fndecl = build_fn_decl(track_function, fntype);
89653 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
89654 +
89655 + // insert call to void pax_track_stack(void)
89656 + track_stack = gimple_build_call(fndecl, 0);
89657 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
89658 +}
89659 +
89660 +#if BUILDING_GCC_VERSION == 4005
89661 +static bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
89662 +{
89663 + tree fndecl;
89664 +
89665 + if (!is_gimple_call(stmt))
89666 + return false;
89667 + fndecl = gimple_call_fndecl(stmt);
89668 + if (!fndecl)
89669 + return false;
89670 + if (DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
89671 + return false;
89672 +// print_node(stderr, "pax", fndecl, 4);
89673 + return DECL_FUNCTION_CODE(fndecl) == code;
89674 +}
89675 +#endif
89676 +
89677 +static bool is_alloca(gimple stmt)
89678 +{
89679 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
89680 + return true;
89681 +
89682 +#if BUILDING_GCC_VERSION >= 4007
89683 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
89684 + return true;
89685 +#endif
89686 +
89687 + return false;
89688 +}
89689 +
89690 +static unsigned int execute_stackleak_tree_instrument(void)
89691 +{
89692 + basic_block bb, entry_bb;
89693 + bool prologue_instrumented = false, is_leaf = true;
89694 +
89695 + entry_bb = ENTRY_BLOCK_PTR_FOR_FUNCTION(cfun)->next_bb;
89696 +
89697 + // 1. loop through BBs and GIMPLE statements
89698 + FOR_EACH_BB(bb) {
89699 + gimple_stmt_iterator gsi;
89700 +
89701 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
89702 + gimple stmt;
89703 +
89704 + stmt = gsi_stmt(gsi);
89705 +
89706 + if (is_gimple_call(stmt))
89707 + is_leaf = false;
89708 +
89709 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
89710 + if (!is_alloca(stmt))
89711 + continue;
89712 +
89713 + // 2. insert stack overflow check before each __builtin_alloca call
89714 + stackleak_check_alloca(&gsi);
89715 +
89716 + // 3. insert track call after each __builtin_alloca call
89717 + stackleak_add_instrumentation(&gsi);
89718 + if (bb == entry_bb)
89719 + prologue_instrumented = true;
89720 + }
89721 + }
89722 +
89723 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
89724 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
89725 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
89726 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
89727 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
89728 + return 0;
89729 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
89730 + return 0;
89731 +
89732 + // 4. insert track call at the beginning
89733 + if (!prologue_instrumented) {
89734 + gimple_stmt_iterator gsi;
89735 +
89736 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
89737 + if (dom_info_available_p(CDI_DOMINATORS))
89738 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
89739 + gsi = gsi_start_bb(bb);
89740 + stackleak_add_instrumentation(&gsi);
89741 + }
89742 +
89743 + return 0;
89744 +}
89745 +
89746 +static unsigned int execute_stackleak_final(void)
89747 +{
89748 + rtx insn;
89749 +
89750 + if (cfun->calls_alloca)
89751 + return 0;
89752 +
89753 + // keep calls only if function frame is big enough
89754 + if (get_frame_size() >= track_frame_size)
89755 + return 0;
89756 +
89757 + // 1. find pax_track_stack calls
89758 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
89759 + // 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))
89760 + rtx body;
89761 +
89762 + if (!CALL_P(insn))
89763 + continue;
89764 + body = PATTERN(insn);
89765 + if (GET_CODE(body) != CALL)
89766 + continue;
89767 + body = XEXP(body, 0);
89768 + if (GET_CODE(body) != MEM)
89769 + continue;
89770 + body = XEXP(body, 0);
89771 + if (GET_CODE(body) != SYMBOL_REF)
89772 + continue;
89773 + if (strcmp(XSTR(body, 0), track_function))
89774 + continue;
89775 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
89776 + // 2. delete call
89777 + insn = delete_insn_and_edges(insn);
89778 +#if BUILDING_GCC_VERSION >= 4007
89779 + if (GET_CODE(insn) == NOTE && NOTE_KIND(insn) == NOTE_INSN_CALL_ARG_LOCATION)
89780 + insn = delete_insn_and_edges(insn);
89781 +#endif
89782 + }
89783 +
89784 +// print_simple_rtl(stderr, get_insns());
89785 +// print_rtl(stderr, get_insns());
89786 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
89787 +
89788 + return 0;
89789 +}
89790 +
89791 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
89792 +{
89793 + const char * const plugin_name = plugin_info->base_name;
89794 + const int argc = plugin_info->argc;
89795 + const struct plugin_argument * const argv = plugin_info->argv;
89796 + int i;
89797 + struct register_pass_info stackleak_tree_instrument_pass_info = {
89798 + .pass = &stackleak_tree_instrument_pass.pass,
89799 +// .reference_pass_name = "tree_profile",
89800 + .reference_pass_name = "optimized",
89801 + .ref_pass_instance_number = 1,
89802 + .pos_op = PASS_POS_INSERT_BEFORE
89803 + };
89804 + struct register_pass_info stackleak_final_pass_info = {
89805 + .pass = &stackleak_final_rtl_opt_pass.pass,
89806 + .reference_pass_name = "final",
89807 + .ref_pass_instance_number = 1,
89808 + .pos_op = PASS_POS_INSERT_BEFORE
89809 + };
89810 +
89811 + if (!plugin_default_version_check(version, &gcc_version)) {
89812 + error(G_("incompatible gcc/plugin versions"));
89813 + return 1;
89814 + }
89815 +
89816 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
89817 +
89818 + for (i = 0; i < argc; ++i) {
89819 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
89820 + if (!argv[i].value) {
89821 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
89822 + continue;
89823 + }
89824 + track_frame_size = atoi(argv[i].value);
89825 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
89826 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
89827 + continue;
89828 + }
89829 + if (!strcmp(argv[i].key, "initialize-locals")) {
89830 + if (argv[i].value) {
89831 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
89832 + continue;
89833 + }
89834 + init_locals = true;
89835 + continue;
89836 + }
89837 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
89838 + }
89839 +
89840 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
89841 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
89842 +
89843 + return 0;
89844 +}
89845 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
89846 index 6789d78..4afd019e 100644
89847 --- a/tools/perf/util/include/asm/alternative-asm.h
89848 +++ b/tools/perf/util/include/asm/alternative-asm.h
89849 @@ -5,4 +5,7 @@
89850
89851 #define altinstruction_entry #
89852
89853 + .macro pax_force_retaddr rip=0, reload=0
89854 + .endm
89855 +
89856 #endif
89857 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
89858 index d617f69..6b445d2 100644
89859 --- a/virt/kvm/kvm_main.c
89860 +++ b/virt/kvm/kvm_main.c
89861 @@ -75,7 +75,7 @@ LIST_HEAD(vm_list);
89862
89863 static cpumask_var_t cpus_hardware_enabled;
89864 static int kvm_usage_count = 0;
89865 -static atomic_t hardware_enable_failed;
89866 +static atomic_unchecked_t hardware_enable_failed;
89867
89868 struct kmem_cache *kvm_vcpu_cache;
89869 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
89870 @@ -715,7 +715,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
89871 /* We can read the guest memory with __xxx_user() later on. */
89872 if (user_alloc &&
89873 ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
89874 - !access_ok(VERIFY_WRITE,
89875 + !__access_ok(VERIFY_WRITE,
89876 (void __user *)(unsigned long)mem->userspace_addr,
89877 mem->memory_size)))
89878 goto out;
89879 @@ -2304,7 +2304,7 @@ static void hardware_enable_nolock(void *junk)
89880
89881 if (r) {
89882 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
89883 - atomic_inc(&hardware_enable_failed);
89884 + atomic_inc_unchecked(&hardware_enable_failed);
89885 printk(KERN_INFO "kvm: enabling virtualization on "
89886 "CPU%d failed\n", cpu);
89887 }
89888 @@ -2358,10 +2358,10 @@ static int hardware_enable_all(void)
89889
89890 kvm_usage_count++;
89891 if (kvm_usage_count == 1) {
89892 - atomic_set(&hardware_enable_failed, 0);
89893 + atomic_set_unchecked(&hardware_enable_failed, 0);
89894 on_each_cpu(hardware_enable_nolock, NULL, 1);
89895
89896 - if (atomic_read(&hardware_enable_failed)) {
89897 + if (atomic_read_unchecked(&hardware_enable_failed)) {
89898 hardware_disable_all_nolock();
89899 r = -EBUSY;
89900 }
89901 @@ -2722,7 +2722,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
89902 kvm_arch_vcpu_put(vcpu);
89903 }
89904
89905 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
89906 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
89907 struct module *module)
89908 {
89909 int r;
89910 @@ -2785,7 +2785,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
89911 if (!vcpu_align)
89912 vcpu_align = __alignof__(struct kvm_vcpu);
89913 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
89914 - 0, NULL);
89915 + SLAB_USERCOPY, NULL);
89916 if (!kvm_vcpu_cache) {
89917 r = -ENOMEM;
89918 goto out_free_3;
89919 @@ -2795,9 +2795,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
89920 if (r)
89921 goto out_free;
89922
89923 - kvm_chardev_ops.owner = module;
89924 - kvm_vm_fops.owner = module;
89925 - kvm_vcpu_fops.owner = module;
89926 + pax_open_kernel();
89927 + *(void **)&kvm_chardev_ops.owner = module;
89928 + *(void **)&kvm_vm_fops.owner = module;
89929 + *(void **)&kvm_vcpu_fops.owner = module;
89930 + pax_close_kernel();
89931
89932 r = misc_register(&kvm_dev);
89933 if (r) {