]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-2.9.1-3.6.9-201212031851.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.6.9-201212031851.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 978af72..1121485 100644
255 --- a/Makefile
256 +++ b/Makefile
257 @@ -241,8 +241,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
258
259 HOSTCC = gcc
260 HOSTCXX = g++
261 -HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
262 -HOSTCXXFLAGS = -O2
263 +HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
264 +HOSTCLFAGS += $(call cc-option, -Wno-empty-body)
265 +HOSTCXXFLAGS = -O2 -Wall -W -fno-delete-null-pointer-checks
266
267 # Decide whether to build built-in, modular, or both.
268 # Normally, just do built-in.
269 @@ -404,8 +405,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
270 # Rules shared between *config targets and build targets
271
272 # Basic helpers built in scripts/
273 -PHONY += scripts_basic
274 -scripts_basic:
275 +PHONY += scripts_basic gcc-plugins
276 +scripts_basic: gcc-plugins
277 $(Q)$(MAKE) $(build)=scripts/basic
278 $(Q)rm -f .tmp_quiet_recordmcount
279
280 @@ -561,6 +562,60 @@ else
281 KBUILD_CFLAGS += -O2
282 endif
283
284 +ifndef DISABLE_PAX_PLUGINS
285 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
286 +ifneq ($(PLUGINCC),)
287 +ifndef DISABLE_PAX_CONSTIFY_PLUGIN
288 +ifndef CONFIG_UML
289 +CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
290 +endif
291 +endif
292 +ifdef CONFIG_PAX_MEMORY_STACKLEAK
293 +STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
294 +STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
295 +endif
296 +ifdef CONFIG_KALLOCSTAT_PLUGIN
297 +KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
298 +endif
299 +ifdef CONFIG_PAX_KERNEXEC_PLUGIN
300 +KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
301 +KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
302 +KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
303 +endif
304 +ifdef CONFIG_CHECKER_PLUGIN
305 +ifeq ($(call cc-ifversion, -ge, 0406, y), y)
306 +CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
307 +endif
308 +endif
309 +COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
310 +ifdef CONFIG_PAX_SIZE_OVERFLOW
311 +SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
312 +endif
313 +ifdef CONFIG_PAX_LATENT_ENTROPY
314 +LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
315 +endif
316 +GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
317 +GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
318 +GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS)
319 +GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
320 +export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN
321 +ifeq ($(KBUILD_EXTMOD),)
322 +gcc-plugins:
323 + $(Q)$(MAKE) $(build)=tools/gcc
324 +else
325 +gcc-plugins: ;
326 +endif
327 +else
328 +gcc-plugins:
329 +ifeq ($(call cc-ifversion, -ge, 0405, y), y)
330 + $(error Your gcc installation does not support plugins. If the necessary headers for plugin support are missing, they should be installed. On Debian, apt-get install gcc-<ver>-plugin-dev. If you choose to ignore this error and lessen the improvements provided by this patch, re-run make with the DISABLE_PAX_PLUGINS=y argument.))
331 +else
332 + $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
333 +endif
334 + $(Q)echo "PAX_MEMORY_STACKLEAK and other features will be less secure"
335 +endif
336 +endif
337 +
338 include $(srctree)/arch/$(SRCARCH)/Makefile
339
340 ifdef CONFIG_READABLE_ASM
341 @@ -715,7 +770,7 @@ export mod_strip_cmd
342
343
344 ifeq ($(KBUILD_EXTMOD),)
345 -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
346 +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
347
348 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
349 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
350 @@ -762,6 +817,8 @@ endif
351
352 # The actual objects are generated when descending,
353 # make sure no implicit rule kicks in
354 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
355 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
356 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
357
358 # Handle descending into subdirectories listed in $(vmlinux-dirs)
359 @@ -771,7 +828,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
360 # Error messages still appears in the original language
361
362 PHONY += $(vmlinux-dirs)
363 -$(vmlinux-dirs): prepare scripts
364 +$(vmlinux-dirs): gcc-plugins prepare scripts
365 $(Q)$(MAKE) $(build)=$@
366
367 # Store (new) KERNELRELASE string in include/config/kernel.release
368 @@ -815,6 +872,7 @@ prepare0: archprepare FORCE
369 $(Q)$(MAKE) $(build)=.
370
371 # All the preparing..
372 +prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
373 prepare: prepare0
374
375 # Generate some files
376 @@ -922,6 +980,8 @@ all: modules
377 # using awk while concatenating to the final file.
378
379 PHONY += modules
380 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
381 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
382 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
383 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
384 @$(kecho) ' Building modules, stage 2.';
385 @@ -937,7 +997,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
386
387 # Target to prepare building external modules
388 PHONY += modules_prepare
389 -modules_prepare: prepare scripts
390 +modules_prepare: gcc-plugins prepare scripts
391
392 # Target to install modules
393 PHONY += modules_install
394 @@ -994,7 +1054,7 @@ CLEAN_DIRS += $(MODVERDIR)
395 MRPROPER_DIRS += include/config usr/include include/generated \
396 arch/*/include/generated
397 MRPROPER_FILES += .config .config.old .version .old_version \
398 - include/linux/version.h \
399 + include/linux/version.h tools/gcc/size_overflow_hash.h\
400 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS
401
402 # clean - Delete most, but leave enough to build external modules
403 @@ -1032,6 +1092,7 @@ distclean: mrproper
404 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
405 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
406 -o -name '.*.rej' \
407 + -o -name '.*.rej' -o -name '*.so' \
408 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
409 -type f -print | xargs rm -f
410
411 @@ -1192,6 +1253,8 @@ PHONY += $(module-dirs) modules
412 $(module-dirs): crmodverdir $(objtree)/Module.symvers
413 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
414
415 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
416 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
417 modules: $(module-dirs)
418 @$(kecho) ' Building modules, stage 2.';
419 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
420 @@ -1326,17 +1389,21 @@ else
421 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
422 endif
423
424 -%.s: %.c prepare scripts FORCE
425 +%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
426 +%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
427 +%.s: %.c gcc-plugins prepare scripts FORCE
428 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
429 %.i: %.c prepare scripts FORCE
430 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
431 -%.o: %.c prepare scripts FORCE
432 +%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
433 +%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
434 +%.o: %.c gcc-plugins prepare scripts FORCE
435 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
436 %.lst: %.c prepare scripts FORCE
437 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
438 -%.s: %.S prepare scripts FORCE
439 +%.s: %.S gcc-plugins prepare scripts FORCE
440 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
441 -%.o: %.S prepare scripts FORCE
442 +%.o: %.S gcc-plugins prepare scripts FORCE
443 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
444 %.symtypes: %.c prepare scripts FORCE
445 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
446 @@ -1346,11 +1413,15 @@ endif
447 $(cmd_crmodverdir)
448 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
449 $(build)=$(build-dir)
450 -%/: prepare scripts FORCE
451 +%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
452 +%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
453 +%/: gcc-plugins prepare scripts FORCE
454 $(cmd_crmodverdir)
455 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
456 $(build)=$(build-dir)
457 -%.ko: prepare scripts FORCE
458 +%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
459 +%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
460 +%.ko: gcc-plugins prepare scripts FORCE
461 $(cmd_crmodverdir)
462 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
463 $(build)=$(build-dir) $(@:.ko=.o)
464 diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
465 index c2cbe4f..f7264b4 100644
466 --- a/arch/alpha/include/asm/atomic.h
467 +++ b/arch/alpha/include/asm/atomic.h
468 @@ -250,6 +250,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
469 #define atomic_dec(v) atomic_sub(1,(v))
470 #define atomic64_dec(v) atomic64_sub(1,(v))
471
472 +#define atomic64_read_unchecked(v) atomic64_read(v)
473 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
474 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
475 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
476 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
477 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
478 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
479 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
480 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
481 +
482 #define smp_mb__before_atomic_dec() smp_mb()
483 #define smp_mb__after_atomic_dec() smp_mb()
484 #define smp_mb__before_atomic_inc() smp_mb()
485 diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
486 index ad368a9..fbe0f25 100644
487 --- a/arch/alpha/include/asm/cache.h
488 +++ b/arch/alpha/include/asm/cache.h
489 @@ -4,19 +4,19 @@
490 #ifndef __ARCH_ALPHA_CACHE_H
491 #define __ARCH_ALPHA_CACHE_H
492
493 +#include <linux/const.h>
494
495 /* Bytes per L1 (data) cache line. */
496 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
497 -# define L1_CACHE_BYTES 64
498 # define L1_CACHE_SHIFT 6
499 #else
500 /* Both EV4 and EV5 are write-through, read-allocate,
501 direct-mapped, physical.
502 */
503 -# define L1_CACHE_BYTES 32
504 # define L1_CACHE_SHIFT 5
505 #endif
506
507 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
508 #define SMP_CACHE_BYTES L1_CACHE_BYTES
509
510 #endif
511 diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
512 index 968d999..d36b2df 100644
513 --- a/arch/alpha/include/asm/elf.h
514 +++ b/arch/alpha/include/asm/elf.h
515 @@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
516
517 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
518
519 +#ifdef CONFIG_PAX_ASLR
520 +#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
521 +
522 +#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
523 +#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
524 +#endif
525 +
526 /* $0 is set by ld.so to a pointer to a function which might be
527 registered using atexit. This provides a mean for the dynamic
528 linker to call DT_FINI functions for shared libraries that have
529 diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
530 index bc2a0da..8ad11ee 100644
531 --- a/arch/alpha/include/asm/pgalloc.h
532 +++ b/arch/alpha/include/asm/pgalloc.h
533 @@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
534 pgd_set(pgd, pmd);
535 }
536
537 +static inline void
538 +pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
539 +{
540 + pgd_populate(mm, pgd, pmd);
541 +}
542 +
543 extern pgd_t *pgd_alloc(struct mm_struct *mm);
544
545 static inline void
546 diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
547 index 81a4342..348b927 100644
548 --- a/arch/alpha/include/asm/pgtable.h
549 +++ b/arch/alpha/include/asm/pgtable.h
550 @@ -102,6 +102,17 @@ struct vm_area_struct;
551 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
552 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
553 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
554 +
555 +#ifdef CONFIG_PAX_PAGEEXEC
556 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
557 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
558 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
559 +#else
560 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
561 +# define PAGE_COPY_NOEXEC PAGE_COPY
562 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
563 +#endif
564 +
565 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
566
567 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
568 diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
569 index 2fd00b7..cfd5069 100644
570 --- a/arch/alpha/kernel/module.c
571 +++ b/arch/alpha/kernel/module.c
572 @@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
573
574 /* The small sections were sorted to the end of the segment.
575 The following should definitely cover them. */
576 - gp = (u64)me->module_core + me->core_size - 0x8000;
577 + gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
578 got = sechdrs[me->arch.gotsecindex].sh_addr;
579
580 for (i = 0; i < n; i++) {
581 diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
582 index bc1acdd..a922a6d 100644
583 --- a/arch/alpha/kernel/osf_sys.c
584 +++ b/arch/alpha/kernel/osf_sys.c
585 @@ -1312,7 +1312,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
586 /* At this point: (!vma || addr < vma->vm_end). */
587 if (limit - len < addr)
588 return -ENOMEM;
589 - if (!vma || addr + len <= vma->vm_start)
590 + if (check_heap_stack_gap(vma, addr, len))
591 return addr;
592 addr = vma->vm_end;
593 vma = vma->vm_next;
594 @@ -1348,6 +1348,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
595 merely specific addresses, but regions of memory -- perhaps
596 this feature should be incorporated into all ports? */
597
598 +#ifdef CONFIG_PAX_RANDMMAP
599 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
600 +#endif
601 +
602 if (addr) {
603 addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
604 if (addr != (unsigned long) -ENOMEM)
605 @@ -1355,8 +1359,8 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
606 }
607
608 /* Next, try allocating at TASK_UNMAPPED_BASE. */
609 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
610 - len, limit);
611 + addr = arch_get_unmapped_area_1 (PAGE_ALIGN(current->mm->mmap_base), len, limit);
612 +
613 if (addr != (unsigned long) -ENOMEM)
614 return addr;
615
616 diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
617 index 0c4132d..88f0d53 100644
618 --- a/arch/alpha/mm/fault.c
619 +++ b/arch/alpha/mm/fault.c
620 @@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
621 __reload_thread(pcb);
622 }
623
624 +#ifdef CONFIG_PAX_PAGEEXEC
625 +/*
626 + * PaX: decide what to do with offenders (regs->pc = fault address)
627 + *
628 + * returns 1 when task should be killed
629 + * 2 when patched PLT trampoline was detected
630 + * 3 when unpatched PLT trampoline was detected
631 + */
632 +static int pax_handle_fetch_fault(struct pt_regs *regs)
633 +{
634 +
635 +#ifdef CONFIG_PAX_EMUPLT
636 + int err;
637 +
638 + do { /* PaX: patched PLT emulation #1 */
639 + unsigned int ldah, ldq, jmp;
640 +
641 + err = get_user(ldah, (unsigned int *)regs->pc);
642 + err |= get_user(ldq, (unsigned int *)(regs->pc+4));
643 + err |= get_user(jmp, (unsigned int *)(regs->pc+8));
644 +
645 + if (err)
646 + break;
647 +
648 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
649 + (ldq & 0xFFFF0000U) == 0xA77B0000U &&
650 + jmp == 0x6BFB0000U)
651 + {
652 + unsigned long r27, addr;
653 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
654 + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
655 +
656 + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
657 + err = get_user(r27, (unsigned long *)addr);
658 + if (err)
659 + break;
660 +
661 + regs->r27 = r27;
662 + regs->pc = r27;
663 + return 2;
664 + }
665 + } while (0);
666 +
667 + do { /* PaX: patched PLT emulation #2 */
668 + unsigned int ldah, lda, br;
669 +
670 + err = get_user(ldah, (unsigned int *)regs->pc);
671 + err |= get_user(lda, (unsigned int *)(regs->pc+4));
672 + err |= get_user(br, (unsigned int *)(regs->pc+8));
673 +
674 + if (err)
675 + break;
676 +
677 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
678 + (lda & 0xFFFF0000U) == 0xA77B0000U &&
679 + (br & 0xFFE00000U) == 0xC3E00000U)
680 + {
681 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
682 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
683 + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
684 +
685 + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
686 + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
687 + return 2;
688 + }
689 + } while (0);
690 +
691 + do { /* PaX: unpatched PLT emulation */
692 + unsigned int br;
693 +
694 + err = get_user(br, (unsigned int *)regs->pc);
695 +
696 + if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
697 + unsigned int br2, ldq, nop, jmp;
698 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
699 +
700 + addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
701 + err = get_user(br2, (unsigned int *)addr);
702 + err |= get_user(ldq, (unsigned int *)(addr+4));
703 + err |= get_user(nop, (unsigned int *)(addr+8));
704 + err |= get_user(jmp, (unsigned int *)(addr+12));
705 + err |= get_user(resolver, (unsigned long *)(addr+16));
706 +
707 + if (err)
708 + break;
709 +
710 + if (br2 == 0xC3600000U &&
711 + ldq == 0xA77B000CU &&
712 + nop == 0x47FF041FU &&
713 + jmp == 0x6B7B0000U)
714 + {
715 + regs->r28 = regs->pc+4;
716 + regs->r27 = addr+16;
717 + regs->pc = resolver;
718 + return 3;
719 + }
720 + }
721 + } while (0);
722 +#endif
723 +
724 + return 1;
725 +}
726 +
727 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
728 +{
729 + unsigned long i;
730 +
731 + printk(KERN_ERR "PAX: bytes at PC: ");
732 + for (i = 0; i < 5; i++) {
733 + unsigned int c;
734 + if (get_user(c, (unsigned int *)pc+i))
735 + printk(KERN_CONT "???????? ");
736 + else
737 + printk(KERN_CONT "%08x ", c);
738 + }
739 + printk("\n");
740 +}
741 +#endif
742
743 /*
744 * This routine handles page faults. It determines the address,
745 @@ -133,8 +251,29 @@ retry:
746 good_area:
747 si_code = SEGV_ACCERR;
748 if (cause < 0) {
749 - if (!(vma->vm_flags & VM_EXEC))
750 + if (!(vma->vm_flags & VM_EXEC)) {
751 +
752 +#ifdef CONFIG_PAX_PAGEEXEC
753 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
754 + goto bad_area;
755 +
756 + up_read(&mm->mmap_sem);
757 + switch (pax_handle_fetch_fault(regs)) {
758 +
759 +#ifdef CONFIG_PAX_EMUPLT
760 + case 2:
761 + case 3:
762 + return;
763 +#endif
764 +
765 + }
766 + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
767 + do_group_exit(SIGKILL);
768 +#else
769 goto bad_area;
770 +#endif
771 +
772 + }
773 } else if (!cause) {
774 /* Allow reads even for write-only mappings */
775 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
776 diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
777 index c79f61f..9ac0642 100644
778 --- a/arch/arm/include/asm/atomic.h
779 +++ b/arch/arm/include/asm/atomic.h
780 @@ -17,17 +17,35 @@
781 #include <asm/barrier.h>
782 #include <asm/cmpxchg.h>
783
784 +#ifdef CONFIG_GENERIC_ATOMIC64
785 +#include <asm-generic/atomic64.h>
786 +#endif
787 +
788 #define ATOMIC_INIT(i) { (i) }
789
790 #ifdef __KERNEL__
791
792 +#define _ASM_EXTABLE(from, to) \
793 +" .pushsection __ex_table,\"a\"\n"\
794 +" .align 3\n" \
795 +" .long " #from ", " #to"\n" \
796 +" .popsection"
797 +
798 /*
799 * On ARM, ordinary assignment (str instruction) doesn't clear the local
800 * strex/ldrex monitor on some implementations. The reason we can use it for
801 * atomic_set() is the clrex or dummy strex done on every exception return.
802 */
803 #define atomic_read(v) (*(volatile int *)&(v)->counter)
804 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
805 +{
806 + return v->counter;
807 +}
808 #define atomic_set(v,i) (((v)->counter) = (i))
809 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
810 +{
811 + v->counter = i;
812 +}
813
814 #if __LINUX_ARM_ARCH__ >= 6
815
816 @@ -42,6 +60,35 @@ static inline void atomic_add(int i, atomic_t *v)
817 int result;
818
819 __asm__ __volatile__("@ atomic_add\n"
820 +"1: ldrex %1, [%3]\n"
821 +" adds %0, %1, %4\n"
822 +
823 +#ifdef CONFIG_PAX_REFCOUNT
824 +" bvc 3f\n"
825 +"2: bkpt 0xf103\n"
826 +"3:\n"
827 +#endif
828 +
829 +" strex %1, %0, [%3]\n"
830 +" teq %1, #0\n"
831 +" bne 1b"
832 +
833 +#ifdef CONFIG_PAX_REFCOUNT
834 +"\n4:\n"
835 + _ASM_EXTABLE(2b, 4b)
836 +#endif
837 +
838 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
839 + : "r" (&v->counter), "Ir" (i)
840 + : "cc");
841 +}
842 +
843 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
844 +{
845 + unsigned long tmp;
846 + int result;
847 +
848 + __asm__ __volatile__("@ atomic_add_unchecked\n"
849 "1: ldrex %0, [%3]\n"
850 " add %0, %0, %4\n"
851 " strex %1, %0, [%3]\n"
852 @@ -60,6 +107,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
853 smp_mb();
854
855 __asm__ __volatile__("@ atomic_add_return\n"
856 +"1: ldrex %1, [%3]\n"
857 +" adds %0, %1, %4\n"
858 +
859 +#ifdef CONFIG_PAX_REFCOUNT
860 +" bvc 3f\n"
861 +" mov %0, %1\n"
862 +"2: bkpt 0xf103\n"
863 +"3:\n"
864 +#endif
865 +
866 +" strex %1, %0, [%3]\n"
867 +" teq %1, #0\n"
868 +" bne 1b"
869 +
870 +#ifdef CONFIG_PAX_REFCOUNT
871 +"\n4:\n"
872 + _ASM_EXTABLE(2b, 4b)
873 +#endif
874 +
875 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
876 + : "r" (&v->counter), "Ir" (i)
877 + : "cc");
878 +
879 + smp_mb();
880 +
881 + return result;
882 +}
883 +
884 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
885 +{
886 + unsigned long tmp;
887 + int result;
888 +
889 + smp_mb();
890 +
891 + __asm__ __volatile__("@ atomic_add_return_unchecked\n"
892 "1: ldrex %0, [%3]\n"
893 " add %0, %0, %4\n"
894 " strex %1, %0, [%3]\n"
895 @@ -80,6 +163,35 @@ static inline void atomic_sub(int i, atomic_t *v)
896 int result;
897
898 __asm__ __volatile__("@ atomic_sub\n"
899 +"1: ldrex %1, [%3]\n"
900 +" subs %0, %1, %4\n"
901 +
902 +#ifdef CONFIG_PAX_REFCOUNT
903 +" bvc 3f\n"
904 +"2: bkpt 0xf103\n"
905 +"3:\n"
906 +#endif
907 +
908 +" strex %1, %0, [%3]\n"
909 +" teq %1, #0\n"
910 +" bne 1b"
911 +
912 +#ifdef CONFIG_PAX_REFCOUNT
913 +"\n4:\n"
914 + _ASM_EXTABLE(2b, 4b)
915 +#endif
916 +
917 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
918 + : "r" (&v->counter), "Ir" (i)
919 + : "cc");
920 +}
921 +
922 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
923 +{
924 + unsigned long tmp;
925 + int result;
926 +
927 + __asm__ __volatile__("@ atomic_sub_unchecked\n"
928 "1: ldrex %0, [%3]\n"
929 " sub %0, %0, %4\n"
930 " strex %1, %0, [%3]\n"
931 @@ -98,11 +210,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
932 smp_mb();
933
934 __asm__ __volatile__("@ atomic_sub_return\n"
935 -"1: ldrex %0, [%3]\n"
936 -" sub %0, %0, %4\n"
937 +"1: ldrex %1, [%3]\n"
938 +" subs %0, %1, %4\n"
939 +
940 +#ifdef CONFIG_PAX_REFCOUNT
941 +" bvc 3f\n"
942 +" mov %0, %1\n"
943 +"2: bkpt 0xf103\n"
944 +"3:\n"
945 +#endif
946 +
947 " strex %1, %0, [%3]\n"
948 " teq %1, #0\n"
949 " bne 1b"
950 +
951 +#ifdef CONFIG_PAX_REFCOUNT
952 +"\n4:\n"
953 + _ASM_EXTABLE(2b, 4b)
954 +#endif
955 +
956 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
957 : "r" (&v->counter), "Ir" (i)
958 : "cc");
959 @@ -134,6 +260,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
960 return oldval;
961 }
962
963 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
964 +{
965 + unsigned long oldval, res;
966 +
967 + smp_mb();
968 +
969 + do {
970 + __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
971 + "ldrex %1, [%3]\n"
972 + "mov %0, #0\n"
973 + "teq %1, %4\n"
974 + "strexeq %0, %5, [%3]\n"
975 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
976 + : "r" (&ptr->counter), "Ir" (old), "r" (new)
977 + : "cc");
978 + } while (res);
979 +
980 + smp_mb();
981 +
982 + return oldval;
983 +}
984 +
985 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
986 {
987 unsigned long tmp, tmp2;
988 @@ -167,7 +315,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
989
990 return val;
991 }
992 +
993 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
994 +{
995 + return atomic_add_return(i, v);
996 +}
997 +
998 #define atomic_add(i, v) (void) atomic_add_return(i, v)
999 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1000 +{
1001 + (void) atomic_add_return(i, v);
1002 +}
1003
1004 static inline int atomic_sub_return(int i, atomic_t *v)
1005 {
1006 @@ -182,6 +340,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1007 return val;
1008 }
1009 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1010 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1011 +{
1012 + (void) atomic_sub_return(i, v);
1013 +}
1014
1015 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1016 {
1017 @@ -197,6 +359,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1018 return ret;
1019 }
1020
1021 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1022 +{
1023 + return atomic_cmpxchg(v, old, new);
1024 +}
1025 +
1026 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1027 {
1028 unsigned long flags;
1029 @@ -209,6 +376,10 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1030 #endif /* __LINUX_ARM_ARCH__ */
1031
1032 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1033 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1034 +{
1035 + return xchg(&v->counter, new);
1036 +}
1037
1038 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1039 {
1040 @@ -221,11 +392,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1041 }
1042
1043 #define atomic_inc(v) atomic_add(1, v)
1044 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1045 +{
1046 + atomic_add_unchecked(1, v);
1047 +}
1048 #define atomic_dec(v) atomic_sub(1, v)
1049 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1050 +{
1051 + atomic_sub_unchecked(1, v);
1052 +}
1053
1054 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1055 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1056 +{
1057 + return atomic_add_return_unchecked(1, v) == 0;
1058 +}
1059 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1060 #define atomic_inc_return(v) (atomic_add_return(1, v))
1061 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1062 +{
1063 + return atomic_add_return_unchecked(1, v);
1064 +}
1065 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1066 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1067
1068 @@ -241,6 +428,14 @@ typedef struct {
1069 u64 __aligned(8) counter;
1070 } atomic64_t;
1071
1072 +#ifdef CONFIG_PAX_REFCOUNT
1073 +typedef struct {
1074 + u64 __aligned(8) counter;
1075 +} atomic64_unchecked_t;
1076 +#else
1077 +typedef atomic64_t atomic64_unchecked_t;
1078 +#endif
1079 +
1080 #define ATOMIC64_INIT(i) { (i) }
1081
1082 static inline u64 atomic64_read(const atomic64_t *v)
1083 @@ -256,6 +451,19 @@ static inline u64 atomic64_read(const atomic64_t *v)
1084 return result;
1085 }
1086
1087 +static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *v)
1088 +{
1089 + u64 result;
1090 +
1091 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1092 +" ldrexd %0, %H0, [%1]"
1093 + : "=&r" (result)
1094 + : "r" (&v->counter), "Qo" (v->counter)
1095 + );
1096 +
1097 + return result;
1098 +}
1099 +
1100 static inline void atomic64_set(atomic64_t *v, u64 i)
1101 {
1102 u64 tmp;
1103 @@ -270,6 +478,20 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1104 : "cc");
1105 }
1106
1107 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1108 +{
1109 + u64 tmp;
1110 +
1111 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1112 +"1: ldrexd %0, %H0, [%2]\n"
1113 +" strexd %0, %3, %H3, [%2]\n"
1114 +" teq %0, #0\n"
1115 +" bne 1b"
1116 + : "=&r" (tmp), "=Qo" (v->counter)
1117 + : "r" (&v->counter), "r" (i)
1118 + : "cc");
1119 +}
1120 +
1121 static inline void atomic64_add(u64 i, atomic64_t *v)
1122 {
1123 u64 result;
1124 @@ -278,6 +500,36 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1125 __asm__ __volatile__("@ atomic64_add\n"
1126 "1: ldrexd %0, %H0, [%3]\n"
1127 " adds %0, %0, %4\n"
1128 +" adcs %H0, %H0, %H4\n"
1129 +
1130 +#ifdef CONFIG_PAX_REFCOUNT
1131 +" bvc 3f\n"
1132 +"2: bkpt 0xf103\n"
1133 +"3:\n"
1134 +#endif
1135 +
1136 +" strexd %1, %0, %H0, [%3]\n"
1137 +" teq %1, #0\n"
1138 +" bne 1b"
1139 +
1140 +#ifdef CONFIG_PAX_REFCOUNT
1141 +"\n4:\n"
1142 + _ASM_EXTABLE(2b, 4b)
1143 +#endif
1144 +
1145 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1146 + : "r" (&v->counter), "r" (i)
1147 + : "cc");
1148 +}
1149 +
1150 +static inline void atomic64_add_unchecked(u64 i, atomic64_unchecked_t *v)
1151 +{
1152 + u64 result;
1153 + unsigned long tmp;
1154 +
1155 + __asm__ __volatile__("@ atomic64_add_unchecked\n"
1156 +"1: ldrexd %0, %H0, [%3]\n"
1157 +" adds %0, %0, %4\n"
1158 " adc %H0, %H0, %H4\n"
1159 " strexd %1, %0, %H0, [%3]\n"
1160 " teq %1, #0\n"
1161 @@ -289,12 +541,49 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1162
1163 static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
1164 {
1165 - u64 result;
1166 - unsigned long tmp;
1167 + u64 result, tmp;
1168
1169 smp_mb();
1170
1171 __asm__ __volatile__("@ atomic64_add_return\n"
1172 +"1: ldrexd %1, %H1, [%3]\n"
1173 +" adds %0, %1, %4\n"
1174 +" adcs %H0, %H1, %H4\n"
1175 +
1176 +#ifdef CONFIG_PAX_REFCOUNT
1177 +" bvc 3f\n"
1178 +" mov %0, %1\n"
1179 +" mov %H0, %H1\n"
1180 +"2: bkpt 0xf103\n"
1181 +"3:\n"
1182 +#endif
1183 +
1184 +" strexd %1, %0, %H0, [%3]\n"
1185 +" teq %1, #0\n"
1186 +" bne 1b"
1187 +
1188 +#ifdef CONFIG_PAX_REFCOUNT
1189 +"\n4:\n"
1190 + _ASM_EXTABLE(2b, 4b)
1191 +#endif
1192 +
1193 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1194 + : "r" (&v->counter), "r" (i)
1195 + : "cc");
1196 +
1197 + smp_mb();
1198 +
1199 + return result;
1200 +}
1201 +
1202 +static inline u64 atomic64_add_return_unchecked(u64 i, atomic64_unchecked_t *v)
1203 +{
1204 + u64 result;
1205 + unsigned long tmp;
1206 +
1207 + smp_mb();
1208 +
1209 + __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1210 "1: ldrexd %0, %H0, [%3]\n"
1211 " adds %0, %0, %4\n"
1212 " adc %H0, %H0, %H4\n"
1213 @@ -318,6 +607,36 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1214 __asm__ __volatile__("@ atomic64_sub\n"
1215 "1: ldrexd %0, %H0, [%3]\n"
1216 " subs %0, %0, %4\n"
1217 +" sbcs %H0, %H0, %H4\n"
1218 +
1219 +#ifdef CONFIG_PAX_REFCOUNT
1220 +" bvc 3f\n"
1221 +"2: bkpt 0xf103\n"
1222 +"3:\n"
1223 +#endif
1224 +
1225 +" strexd %1, %0, %H0, [%3]\n"
1226 +" teq %1, #0\n"
1227 +" bne 1b"
1228 +
1229 +#ifdef CONFIG_PAX_REFCOUNT
1230 +"\n4:\n"
1231 + _ASM_EXTABLE(2b, 4b)
1232 +#endif
1233 +
1234 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1235 + : "r" (&v->counter), "r" (i)
1236 + : "cc");
1237 +}
1238 +
1239 +static inline void atomic64_sub_unchecked(u64 i, atomic64_unchecked_t *v)
1240 +{
1241 + u64 result;
1242 + unsigned long tmp;
1243 +
1244 + __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1245 +"1: ldrexd %0, %H0, [%3]\n"
1246 +" subs %0, %0, %4\n"
1247 " sbc %H0, %H0, %H4\n"
1248 " strexd %1, %0, %H0, [%3]\n"
1249 " teq %1, #0\n"
1250 @@ -329,18 +648,32 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1251
1252 static inline u64 atomic64_sub_return(u64 i, atomic64_t *v)
1253 {
1254 - u64 result;
1255 - unsigned long tmp;
1256 + u64 result, tmp;
1257
1258 smp_mb();
1259
1260 __asm__ __volatile__("@ atomic64_sub_return\n"
1261 -"1: ldrexd %0, %H0, [%3]\n"
1262 -" subs %0, %0, %4\n"
1263 -" sbc %H0, %H0, %H4\n"
1264 +"1: ldrexd %1, %H1, [%3]\n"
1265 +" subs %0, %1, %4\n"
1266 +" sbcs %H0, %H1, %H4\n"
1267 +
1268 +#ifdef CONFIG_PAX_REFCOUNT
1269 +" bvc 3f\n"
1270 +" mov %0, %1\n"
1271 +" mov %H0, %H1\n"
1272 +"2: bkpt 0xf103\n"
1273 +"3:\n"
1274 +#endif
1275 +
1276 " strexd %1, %0, %H0, [%3]\n"
1277 " teq %1, #0\n"
1278 " bne 1b"
1279 +
1280 +#ifdef CONFIG_PAX_REFCOUNT
1281 +"\n4:\n"
1282 + _ASM_EXTABLE(2b, 4b)
1283 +#endif
1284 +
1285 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1286 : "r" (&v->counter), "r" (i)
1287 : "cc");
1288 @@ -374,6 +707,30 @@ static inline u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old, u64 new)
1289 return oldval;
1290 }
1291
1292 +static inline u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old, u64 new)
1293 +{
1294 + u64 oldval;
1295 + unsigned long res;
1296 +
1297 + smp_mb();
1298 +
1299 + do {
1300 + __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1301 + "ldrexd %1, %H1, [%3]\n"
1302 + "mov %0, #0\n"
1303 + "teq %1, %4\n"
1304 + "teqeq %H1, %H4\n"
1305 + "strexdeq %0, %5, %H5, [%3]"
1306 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1307 + : "r" (&ptr->counter), "r" (old), "r" (new)
1308 + : "cc");
1309 + } while (res);
1310 +
1311 + smp_mb();
1312 +
1313 + return oldval;
1314 +}
1315 +
1316 static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1317 {
1318 u64 result;
1319 @@ -397,21 +754,34 @@ static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1320
1321 static inline u64 atomic64_dec_if_positive(atomic64_t *v)
1322 {
1323 - u64 result;
1324 - unsigned long tmp;
1325 + u64 result, tmp;
1326
1327 smp_mb();
1328
1329 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1330 -"1: ldrexd %0, %H0, [%3]\n"
1331 -" subs %0, %0, #1\n"
1332 -" sbc %H0, %H0, #0\n"
1333 +"1: ldrexd %1, %H1, [%3]\n"
1334 +" subs %0, %1, #1\n"
1335 +" sbcs %H0, %H1, #0\n"
1336 +
1337 +#ifdef CONFIG_PAX_REFCOUNT
1338 +" bvc 3f\n"
1339 +" mov %0, %1\n"
1340 +" mov %H0, %H1\n"
1341 +"2: bkpt 0xf103\n"
1342 +"3:\n"
1343 +#endif
1344 +
1345 " teq %H0, #0\n"
1346 -" bmi 2f\n"
1347 +" bmi 4f\n"
1348 " strexd %1, %0, %H0, [%3]\n"
1349 " teq %1, #0\n"
1350 " bne 1b\n"
1351 -"2:"
1352 +"4:\n"
1353 +
1354 +#ifdef CONFIG_PAX_REFCOUNT
1355 + _ASM_EXTABLE(2b, 4b)
1356 +#endif
1357 +
1358 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1359 : "r" (&v->counter)
1360 : "cc");
1361 @@ -434,13 +804,25 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1362 " teq %0, %5\n"
1363 " teqeq %H0, %H5\n"
1364 " moveq %1, #0\n"
1365 -" beq 2f\n"
1366 +" beq 4f\n"
1367 " adds %0, %0, %6\n"
1368 -" adc %H0, %H0, %H6\n"
1369 +" adcs %H0, %H0, %H6\n"
1370 +
1371 +#ifdef CONFIG_PAX_REFCOUNT
1372 +" bvc 3f\n"
1373 +"2: bkpt 0xf103\n"
1374 +"3:\n"
1375 +#endif
1376 +
1377 " strexd %2, %0, %H0, [%4]\n"
1378 " teq %2, #0\n"
1379 " bne 1b\n"
1380 -"2:"
1381 +"4:\n"
1382 +
1383 +#ifdef CONFIG_PAX_REFCOUNT
1384 + _ASM_EXTABLE(2b, 4b)
1385 +#endif
1386 +
1387 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1388 : "r" (&v->counter), "r" (u), "r" (a)
1389 : "cc");
1390 @@ -453,10 +835,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1391
1392 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1393 #define atomic64_inc(v) atomic64_add(1LL, (v))
1394 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1395 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1396 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1397 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1398 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1399 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1400 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1401 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1402 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1403 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1404 diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1405 index 75fe66b..2255c86 100644
1406 --- a/arch/arm/include/asm/cache.h
1407 +++ b/arch/arm/include/asm/cache.h
1408 @@ -4,8 +4,10 @@
1409 #ifndef __ASMARM_CACHE_H
1410 #define __ASMARM_CACHE_H
1411
1412 +#include <linux/const.h>
1413 +
1414 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1415 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1416 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1417
1418 /*
1419 * Memory returned by kmalloc() may be used for DMA, so we must make
1420 diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1421 index e4448e1..7bc86b7 100644
1422 --- a/arch/arm/include/asm/cacheflush.h
1423 +++ b/arch/arm/include/asm/cacheflush.h
1424 @@ -108,7 +108,7 @@ struct cpu_cache_fns {
1425 void (*dma_unmap_area)(const void *, size_t, int);
1426
1427 void (*dma_flush_range)(const void *, const void *);
1428 -};
1429 +} __no_const;
1430
1431 /*
1432 * Select the calling method
1433 diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1434 index 7eb18c1..e38b6d2 100644
1435 --- a/arch/arm/include/asm/cmpxchg.h
1436 +++ b/arch/arm/include/asm/cmpxchg.h
1437 @@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1438
1439 #define xchg(ptr,x) \
1440 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1441 +#define xchg_unchecked(ptr,x) \
1442 + ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1443
1444 #include <asm-generic/cmpxchg-local.h>
1445
1446 diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1447 index 38050b1..9d90e8b 100644
1448 --- a/arch/arm/include/asm/elf.h
1449 +++ b/arch/arm/include/asm/elf.h
1450 @@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1451 the loader. We need to make sure that it is out of the way of the program
1452 that it will "exec", and that there is sufficient room for the brk. */
1453
1454 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1455 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1456 +
1457 +#ifdef CONFIG_PAX_ASLR
1458 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1459 +
1460 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1461 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1462 +#endif
1463
1464 /* When the program starts, a1 contains a pointer to a function to be
1465 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1466 @@ -126,8 +133,4 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1467 extern void elf_set_personality(const struct elf32_hdr *);
1468 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1469
1470 -struct mm_struct;
1471 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1472 -#define arch_randomize_brk arch_randomize_brk
1473 -
1474 #endif
1475 diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1476 index 83eb2f7..ed77159 100644
1477 --- a/arch/arm/include/asm/kmap_types.h
1478 +++ b/arch/arm/include/asm/kmap_types.h
1479 @@ -4,6 +4,6 @@
1480 /*
1481 * This is the "bare minimum". AIO seems to require this.
1482 */
1483 -#define KM_TYPE_NR 16
1484 +#define KM_TYPE_NR 17
1485
1486 #endif
1487 diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1488 index 53426c6..c7baff3 100644
1489 --- a/arch/arm/include/asm/outercache.h
1490 +++ b/arch/arm/include/asm/outercache.h
1491 @@ -35,7 +35,7 @@ struct outer_cache_fns {
1492 #endif
1493 void (*set_debug)(unsigned long);
1494 void (*resume)(void);
1495 -};
1496 +} __no_const;
1497
1498 #ifdef CONFIG_OUTER_CACHE
1499
1500 diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1501 index ecf9019..b71d9a1 100644
1502 --- a/arch/arm/include/asm/page.h
1503 +++ b/arch/arm/include/asm/page.h
1504 @@ -114,7 +114,7 @@ struct cpu_user_fns {
1505 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1506 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1507 unsigned long vaddr, struct vm_area_struct *vma);
1508 -};
1509 +} __no_const;
1510
1511 #ifdef MULTI_USER
1512 extern struct cpu_user_fns cpu_user;
1513 diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1514 index 943504f..bf8d667 100644
1515 --- a/arch/arm/include/asm/pgalloc.h
1516 +++ b/arch/arm/include/asm/pgalloc.h
1517 @@ -43,6 +43,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1518 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1519 }
1520
1521 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1522 +{
1523 + pud_populate(mm, pud, pmd);
1524 +}
1525 +
1526 #else /* !CONFIG_ARM_LPAE */
1527
1528 /*
1529 @@ -51,6 +56,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1530 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1531 #define pmd_free(mm, pmd) do { } while (0)
1532 #define pud_populate(mm,pmd,pte) BUG()
1533 +#define pud_populate_kernel(mm,pmd,pte) BUG()
1534
1535 #endif /* CONFIG_ARM_LPAE */
1536
1537 diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
1538 index af7b0bd..6750a8c 100644
1539 --- a/arch/arm/include/asm/thread_info.h
1540 +++ b/arch/arm/include/asm/thread_info.h
1541 @@ -148,6 +148,12 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1542 #define TIF_NOTIFY_RESUME 2 /* callback before returning to user */
1543 #define TIF_SYSCALL_TRACE 8
1544 #define TIF_SYSCALL_AUDIT 9
1545 +
1546 +/* within 8 bits of TIF_SYSCALL_TRACE
1547 + to meet flexible second operand requirements
1548 +*/
1549 +#define TIF_GRSEC_SETXID 10
1550 +
1551 #define TIF_POLLING_NRFLAG 16
1552 #define TIF_USING_IWMMXT 17
1553 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
1554 @@ -163,9 +169,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1555 #define _TIF_POLLING_NRFLAG (1 << TIF_POLLING_NRFLAG)
1556 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
1557 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
1558 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
1559
1560 /* Checks for any syscall work in entry-common.S */
1561 -#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
1562 +#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
1563 + _TIF_GRSEC_SETXID)
1564
1565 /*
1566 * Change these and you break ASM code in entry-common.S
1567 diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
1568 index 77bd79f..ad4cd27 100644
1569 --- a/arch/arm/include/asm/uaccess.h
1570 +++ b/arch/arm/include/asm/uaccess.h
1571 @@ -22,6 +22,8 @@
1572 #define VERIFY_READ 0
1573 #define VERIFY_WRITE 1
1574
1575 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
1576 +
1577 /*
1578 * The exception table consists of pairs of addresses: the first is the
1579 * address of an instruction that is allowed to fault, and the second is
1580 @@ -418,8 +420,23 @@ do { \
1581
1582
1583 #ifdef CONFIG_MMU
1584 -extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
1585 -extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
1586 +extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
1587 +extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
1588 +
1589 +static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
1590 +{
1591 + if (!__builtin_constant_p(n))
1592 + check_object_size(to, n, false);
1593 + return ___copy_from_user(to, from, n);
1594 +}
1595 +
1596 +static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
1597 +{
1598 + if (!__builtin_constant_p(n))
1599 + check_object_size(from, n, true);
1600 + return ___copy_to_user(to, from, n);
1601 +}
1602 +
1603 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
1604 extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
1605 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
1606 @@ -431,6 +448,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
1607
1608 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
1609 {
1610 + if ((long)n < 0)
1611 + return n;
1612 +
1613 if (access_ok(VERIFY_READ, from, n))
1614 n = __copy_from_user(to, from, n);
1615 else /* security hole - plug it */
1616 @@ -440,6 +460,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
1617
1618 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
1619 {
1620 + if ((long)n < 0)
1621 + return n;
1622 +
1623 if (access_ok(VERIFY_WRITE, to, n))
1624 n = __copy_to_user(to, from, n);
1625 return n;
1626 diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
1627 index 60d3b73..9168db0 100644
1628 --- a/arch/arm/kernel/armksyms.c
1629 +++ b/arch/arm/kernel/armksyms.c
1630 @@ -89,8 +89,8 @@ EXPORT_SYMBOL(__memzero);
1631 #ifdef CONFIG_MMU
1632 EXPORT_SYMBOL(copy_page);
1633
1634 -EXPORT_SYMBOL(__copy_from_user);
1635 -EXPORT_SYMBOL(__copy_to_user);
1636 +EXPORT_SYMBOL(___copy_from_user);
1637 +EXPORT_SYMBOL(___copy_to_user);
1638 EXPORT_SYMBOL(__clear_user);
1639
1640 EXPORT_SYMBOL(__get_user_1);
1641 diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
1642 index 693b744..e684262 100644
1643 --- a/arch/arm/kernel/process.c
1644 +++ b/arch/arm/kernel/process.c
1645 @@ -28,7 +28,6 @@
1646 #include <linux/tick.h>
1647 #include <linux/utsname.h>
1648 #include <linux/uaccess.h>
1649 -#include <linux/random.h>
1650 #include <linux/hw_breakpoint.h>
1651 #include <linux/cpuidle.h>
1652
1653 @@ -256,9 +255,10 @@ void machine_power_off(void)
1654 machine_shutdown();
1655 if (pm_power_off)
1656 pm_power_off();
1657 + BUG();
1658 }
1659
1660 -void machine_restart(char *cmd)
1661 +__noreturn void machine_restart(char *cmd)
1662 {
1663 machine_shutdown();
1664
1665 @@ -501,12 +501,6 @@ unsigned long get_wchan(struct task_struct *p)
1666 return 0;
1667 }
1668
1669 -unsigned long arch_randomize_brk(struct mm_struct *mm)
1670 -{
1671 - unsigned long range_end = mm->brk + 0x02000000;
1672 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
1673 -}
1674 -
1675 #ifdef CONFIG_MMU
1676 /*
1677 * The vectors page is always readable from user space for the
1678 diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
1679 index 3e0fc5f..a42d2ec 100644
1680 --- a/arch/arm/kernel/ptrace.c
1681 +++ b/arch/arm/kernel/ptrace.c
1682 @@ -913,11 +913,20 @@ enum ptrace_syscall_dir {
1683 PTRACE_SYSCALL_EXIT,
1684 };
1685
1686 +#ifdef CONFIG_GRKERNSEC_SETXID
1687 +extern void gr_delayed_cred_worker(void);
1688 +#endif
1689 +
1690 static int ptrace_syscall_trace(struct pt_regs *regs, int scno,
1691 enum ptrace_syscall_dir dir)
1692 {
1693 unsigned long ip;
1694
1695 +#ifdef CONFIG_GRKERNSEC_SETXID
1696 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
1697 + gr_delayed_cred_worker();
1698 +#endif
1699 +
1700 if (!test_thread_flag(TIF_SYSCALL_TRACE))
1701 return scno;
1702
1703 diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
1704 index a81dcec..ac42f0f 100644
1705 --- a/arch/arm/kernel/setup.c
1706 +++ b/arch/arm/kernel/setup.c
1707 @@ -112,13 +112,13 @@ struct processor processor __read_mostly;
1708 struct cpu_tlb_fns cpu_tlb __read_mostly;
1709 #endif
1710 #ifdef MULTI_USER
1711 -struct cpu_user_fns cpu_user __read_mostly;
1712 +struct cpu_user_fns cpu_user __read_only;
1713 #endif
1714 #ifdef MULTI_CACHE
1715 -struct cpu_cache_fns cpu_cache __read_mostly;
1716 +struct cpu_cache_fns cpu_cache __read_only;
1717 #endif
1718 #ifdef CONFIG_OUTER_CACHE
1719 -struct outer_cache_fns outer_cache __read_mostly;
1720 +struct outer_cache_fns outer_cache __read_only;
1721 EXPORT_SYMBOL(outer_cache);
1722 #endif
1723
1724 diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
1725 index b0179b8..b54c6c1 100644
1726 --- a/arch/arm/kernel/traps.c
1727 +++ b/arch/arm/kernel/traps.c
1728 @@ -266,6 +266,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
1729 static int die_owner = -1;
1730 static unsigned int die_nest_count;
1731
1732 +extern void gr_handle_kernel_exploit(void);
1733 +
1734 static unsigned long oops_begin(void)
1735 {
1736 int cpu;
1737 @@ -308,6 +310,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
1738 panic("Fatal exception in interrupt");
1739 if (panic_on_oops)
1740 panic("Fatal exception");
1741 +
1742 + gr_handle_kernel_exploit();
1743 +
1744 if (signr)
1745 do_exit(signr);
1746 }
1747 diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
1748 index 66a477a..bee61d3 100644
1749 --- a/arch/arm/lib/copy_from_user.S
1750 +++ b/arch/arm/lib/copy_from_user.S
1751 @@ -16,7 +16,7 @@
1752 /*
1753 * Prototype:
1754 *
1755 - * size_t __copy_from_user(void *to, const void *from, size_t n)
1756 + * size_t ___copy_from_user(void *to, const void *from, size_t n)
1757 *
1758 * Purpose:
1759 *
1760 @@ -84,11 +84,11 @@
1761
1762 .text
1763
1764 -ENTRY(__copy_from_user)
1765 +ENTRY(___copy_from_user)
1766
1767 #include "copy_template.S"
1768
1769 -ENDPROC(__copy_from_user)
1770 +ENDPROC(___copy_from_user)
1771
1772 .pushsection .fixup,"ax"
1773 .align 0
1774 diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
1775 index 6ee2f67..d1cce76 100644
1776 --- a/arch/arm/lib/copy_page.S
1777 +++ b/arch/arm/lib/copy_page.S
1778 @@ -10,6 +10,7 @@
1779 * ASM optimised string functions
1780 */
1781 #include <linux/linkage.h>
1782 +#include <linux/const.h>
1783 #include <asm/assembler.h>
1784 #include <asm/asm-offsets.h>
1785 #include <asm/cache.h>
1786 diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
1787 index d066df6..df28194 100644
1788 --- a/arch/arm/lib/copy_to_user.S
1789 +++ b/arch/arm/lib/copy_to_user.S
1790 @@ -16,7 +16,7 @@
1791 /*
1792 * Prototype:
1793 *
1794 - * size_t __copy_to_user(void *to, const void *from, size_t n)
1795 + * size_t ___copy_to_user(void *to, const void *from, size_t n)
1796 *
1797 * Purpose:
1798 *
1799 @@ -88,11 +88,11 @@
1800 .text
1801
1802 ENTRY(__copy_to_user_std)
1803 -WEAK(__copy_to_user)
1804 +WEAK(___copy_to_user)
1805
1806 #include "copy_template.S"
1807
1808 -ENDPROC(__copy_to_user)
1809 +ENDPROC(___copy_to_user)
1810 ENDPROC(__copy_to_user_std)
1811
1812 .pushsection .fixup,"ax"
1813 diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
1814 index 025f742..8432b08 100644
1815 --- a/arch/arm/lib/uaccess_with_memcpy.c
1816 +++ b/arch/arm/lib/uaccess_with_memcpy.c
1817 @@ -104,7 +104,7 @@ out:
1818 }
1819
1820 unsigned long
1821 -__copy_to_user(void __user *to, const void *from, unsigned long n)
1822 +___copy_to_user(void __user *to, const void *from, unsigned long n)
1823 {
1824 /*
1825 * This test is stubbed out of the main function above to keep
1826 diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
1827 index 1201191..eabbb2c 100644
1828 --- a/arch/arm/mach-kirkwood/common.c
1829 +++ b/arch/arm/mach-kirkwood/common.c
1830 @@ -160,7 +160,7 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
1831 clk_gate_ops.disable(hw);
1832 }
1833
1834 -static struct clk_ops clk_gate_fn_ops;
1835 +static clk_ops_no_const clk_gate_fn_ops;
1836
1837 static struct clk __init *clk_register_gate_fn(struct device *dev,
1838 const char *name,
1839 diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
1840 index 677357f..8828dda 100644
1841 --- a/arch/arm/mach-omap2/board-n8x0.c
1842 +++ b/arch/arm/mach-omap2/board-n8x0.c
1843 @@ -593,7 +593,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
1844 }
1845 #endif
1846
1847 -static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
1848 +static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
1849 .late_init = n8x0_menelaus_late_init,
1850 };
1851
1852 diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
1853 index 37afbd1..c22ad7c 100644
1854 --- a/arch/arm/mach-omap2/omap_hwmod.c
1855 +++ b/arch/arm/mach-omap2/omap_hwmod.c
1856 @@ -187,10 +187,10 @@ struct omap_hwmod_soc_ops {
1857 int (*is_hardreset_asserted)(struct omap_hwmod *oh,
1858 struct omap_hwmod_rst_info *ohri);
1859 int (*init_clkdm)(struct omap_hwmod *oh);
1860 -};
1861 +} __no_const;
1862
1863 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
1864 -static struct omap_hwmod_soc_ops soc_ops;
1865 +static struct omap_hwmod_soc_ops soc_ops __read_only;
1866
1867 /* omap_hwmod_list contains all registered struct omap_hwmods */
1868 static LIST_HEAD(omap_hwmod_list);
1869 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
1870 index c3bd834..e81ef02 100644
1871 --- a/arch/arm/mm/fault.c
1872 +++ b/arch/arm/mm/fault.c
1873 @@ -174,6 +174,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
1874 }
1875 #endif
1876
1877 +#ifdef CONFIG_PAX_PAGEEXEC
1878 + if (fsr & FSR_LNX_PF) {
1879 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
1880 + do_group_exit(SIGKILL);
1881 + }
1882 +#endif
1883 +
1884 tsk->thread.address = addr;
1885 tsk->thread.error_code = fsr;
1886 tsk->thread.trap_no = 14;
1887 @@ -397,6 +404,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
1888 }
1889 #endif /* CONFIG_MMU */
1890
1891 +#ifdef CONFIG_PAX_PAGEEXEC
1892 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
1893 +{
1894 + long i;
1895 +
1896 + printk(KERN_ERR "PAX: bytes at PC: ");
1897 + for (i = 0; i < 20; i++) {
1898 + unsigned char c;
1899 + if (get_user(c, (__force unsigned char __user *)pc+i))
1900 + printk(KERN_CONT "?? ");
1901 + else
1902 + printk(KERN_CONT "%02x ", c);
1903 + }
1904 + printk("\n");
1905 +
1906 + printk(KERN_ERR "PAX: bytes at SP-4: ");
1907 + for (i = -1; i < 20; i++) {
1908 + unsigned long c;
1909 + if (get_user(c, (__force unsigned long __user *)sp+i))
1910 + printk(KERN_CONT "???????? ");
1911 + else
1912 + printk(KERN_CONT "%08lx ", c);
1913 + }
1914 + printk("\n");
1915 +}
1916 +#endif
1917 +
1918 /*
1919 * First Level Translation Fault Handler
1920 *
1921 @@ -574,6 +608,20 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
1922 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
1923 struct siginfo info;
1924
1925 +#ifdef CONFIG_PAX_REFCOUNT
1926 + if (fsr_fs(ifsr) == 2) {
1927 + unsigned int bkpt;
1928 +
1929 + if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
1930 + current->thread.error_code = ifsr;
1931 + current->thread.trap_no = 0;
1932 + pax_report_refcount_overflow(regs);
1933 + fixup_exception(regs);
1934 + return;
1935 + }
1936 + }
1937 +#endif
1938 +
1939 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
1940 return;
1941
1942 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
1943 index ce8cb19..3ec539d 100644
1944 --- a/arch/arm/mm/mmap.c
1945 +++ b/arch/arm/mm/mmap.c
1946 @@ -93,6 +93,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1947 if (len > TASK_SIZE)
1948 return -ENOMEM;
1949
1950 +#ifdef CONFIG_PAX_RANDMMAP
1951 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
1952 +#endif
1953 +
1954 if (addr) {
1955 if (do_align)
1956 addr = COLOUR_ALIGN(addr, pgoff);
1957 @@ -100,15 +104,14 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1958 addr = PAGE_ALIGN(addr);
1959
1960 vma = find_vma(mm, addr);
1961 - if (TASK_SIZE - len >= addr &&
1962 - (!vma || addr + len <= vma->vm_start))
1963 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
1964 return addr;
1965 }
1966 if (len > mm->cached_hole_size) {
1967 - start_addr = addr = mm->free_area_cache;
1968 + start_addr = addr = mm->free_area_cache;
1969 } else {
1970 - start_addr = addr = mm->mmap_base;
1971 - mm->cached_hole_size = 0;
1972 + start_addr = addr = mm->mmap_base;
1973 + mm->cached_hole_size = 0;
1974 }
1975
1976 full_search:
1977 @@ -124,14 +127,14 @@ full_search:
1978 * Start a new search - just in case we missed
1979 * some holes.
1980 */
1981 - if (start_addr != TASK_UNMAPPED_BASE) {
1982 - start_addr = addr = TASK_UNMAPPED_BASE;
1983 + if (start_addr != mm->mmap_base) {
1984 + start_addr = addr = mm->mmap_base;
1985 mm->cached_hole_size = 0;
1986 goto full_search;
1987 }
1988 return -ENOMEM;
1989 }
1990 - if (!vma || addr + len <= vma->vm_start) {
1991 + if (check_heap_stack_gap(vma, addr, len)) {
1992 /*
1993 * Remember the place where we stopped the search:
1994 */
1995 @@ -266,10 +269,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
1996
1997 if (mmap_is_legacy()) {
1998 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
1999 +
2000 +#ifdef CONFIG_PAX_RANDMMAP
2001 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2002 + mm->mmap_base += mm->delta_mmap;
2003 +#endif
2004 +
2005 mm->get_unmapped_area = arch_get_unmapped_area;
2006 mm->unmap_area = arch_unmap_area;
2007 } else {
2008 mm->mmap_base = mmap_base(random_factor);
2009 +
2010 +#ifdef CONFIG_PAX_RANDMMAP
2011 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2012 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
2013 +#endif
2014 +
2015 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
2016 mm->unmap_area = arch_unmap_area_topdown;
2017 }
2018 diff --git a/arch/arm/plat-orion/include/plat/addr-map.h b/arch/arm/plat-orion/include/plat/addr-map.h
2019 index fd556f7..af2e7d2 100644
2020 --- a/arch/arm/plat-orion/include/plat/addr-map.h
2021 +++ b/arch/arm/plat-orion/include/plat/addr-map.h
2022 @@ -26,7 +26,7 @@ struct orion_addr_map_cfg {
2023 value in bridge_virt_base */
2024 void __iomem *(*win_cfg_base) (const struct orion_addr_map_cfg *cfg,
2025 const int win);
2026 -};
2027 +} __no_const;
2028
2029 /*
2030 * Information needed to setup one address mapping.
2031 diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
2032 index f5144cd..71f6d1f 100644
2033 --- a/arch/arm/plat-samsung/include/plat/dma-ops.h
2034 +++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
2035 @@ -47,7 +47,7 @@ struct samsung_dma_ops {
2036 int (*started)(unsigned ch);
2037 int (*flush)(unsigned ch);
2038 int (*stop)(unsigned ch);
2039 -};
2040 +} __no_const;
2041
2042 extern void *samsung_dmadev_get_ops(void);
2043 extern void *s3c_dma_get_ops(void);
2044 diff --git a/arch/arm/plat-samsung/include/plat/ehci.h b/arch/arm/plat-samsung/include/plat/ehci.h
2045 index 5f28cae..3d23723 100644
2046 --- a/arch/arm/plat-samsung/include/plat/ehci.h
2047 +++ b/arch/arm/plat-samsung/include/plat/ehci.h
2048 @@ -14,7 +14,7 @@
2049 struct s5p_ehci_platdata {
2050 int (*phy_init)(struct platform_device *pdev, int type);
2051 int (*phy_exit)(struct platform_device *pdev, int type);
2052 -};
2053 +} __no_const;
2054
2055 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
2056
2057 diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
2058 index c3a58a1..78fbf54 100644
2059 --- a/arch/avr32/include/asm/cache.h
2060 +++ b/arch/avr32/include/asm/cache.h
2061 @@ -1,8 +1,10 @@
2062 #ifndef __ASM_AVR32_CACHE_H
2063 #define __ASM_AVR32_CACHE_H
2064
2065 +#include <linux/const.h>
2066 +
2067 #define L1_CACHE_SHIFT 5
2068 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2069 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2070
2071 /*
2072 * Memory returned by kmalloc() may be used for DMA, so we must make
2073 diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
2074 index 3b3159b..425ea94 100644
2075 --- a/arch/avr32/include/asm/elf.h
2076 +++ b/arch/avr32/include/asm/elf.h
2077 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
2078 the loader. We need to make sure that it is out of the way of the program
2079 that it will "exec", and that there is sufficient room for the brk. */
2080
2081 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
2082 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2083
2084 +#ifdef CONFIG_PAX_ASLR
2085 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
2086 +
2087 +#define PAX_DELTA_MMAP_LEN 15
2088 +#define PAX_DELTA_STACK_LEN 15
2089 +#endif
2090
2091 /* This yields a mask that user programs can use to figure out what
2092 instruction set this CPU supports. This could be done in user space,
2093 diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
2094 index 479330b..53717a8 100644
2095 --- a/arch/avr32/include/asm/kmap_types.h
2096 +++ b/arch/avr32/include/asm/kmap_types.h
2097 @@ -2,9 +2,9 @@
2098 #define __ASM_AVR32_KMAP_TYPES_H
2099
2100 #ifdef CONFIG_DEBUG_HIGHMEM
2101 -# define KM_TYPE_NR 29
2102 +# define KM_TYPE_NR 30
2103 #else
2104 -# define KM_TYPE_NR 14
2105 +# define KM_TYPE_NR 15
2106 #endif
2107
2108 #endif /* __ASM_AVR32_KMAP_TYPES_H */
2109 diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
2110 index b92e609..b69c101 100644
2111 --- a/arch/avr32/mm/fault.c
2112 +++ b/arch/avr32/mm/fault.c
2113 @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
2114
2115 int exception_trace = 1;
2116
2117 +#ifdef CONFIG_PAX_PAGEEXEC
2118 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2119 +{
2120 + unsigned long i;
2121 +
2122 + printk(KERN_ERR "PAX: bytes at PC: ");
2123 + for (i = 0; i < 20; i++) {
2124 + unsigned char c;
2125 + if (get_user(c, (unsigned char *)pc+i))
2126 + printk(KERN_CONT "???????? ");
2127 + else
2128 + printk(KERN_CONT "%02x ", c);
2129 + }
2130 + printk("\n");
2131 +}
2132 +#endif
2133 +
2134 /*
2135 * This routine handles page faults. It determines the address and the
2136 * problem, and then passes it off to one of the appropriate routines.
2137 @@ -173,6 +190,16 @@ bad_area:
2138 up_read(&mm->mmap_sem);
2139
2140 if (user_mode(regs)) {
2141 +
2142 +#ifdef CONFIG_PAX_PAGEEXEC
2143 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
2144 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
2145 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
2146 + do_group_exit(SIGKILL);
2147 + }
2148 + }
2149 +#endif
2150 +
2151 if (exception_trace && printk_ratelimit())
2152 printk("%s%s[%d]: segfault at %08lx pc %08lx "
2153 "sp %08lx ecr %lu\n",
2154 diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
2155 index 568885a..f8008df 100644
2156 --- a/arch/blackfin/include/asm/cache.h
2157 +++ b/arch/blackfin/include/asm/cache.h
2158 @@ -7,6 +7,7 @@
2159 #ifndef __ARCH_BLACKFIN_CACHE_H
2160 #define __ARCH_BLACKFIN_CACHE_H
2161
2162 +#include <linux/const.h>
2163 #include <linux/linkage.h> /* for asmlinkage */
2164
2165 /*
2166 @@ -14,7 +15,7 @@
2167 * Blackfin loads 32 bytes for cache
2168 */
2169 #define L1_CACHE_SHIFT 5
2170 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2171 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2172 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2173
2174 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2175 diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
2176 index aea2718..3639a60 100644
2177 --- a/arch/cris/include/arch-v10/arch/cache.h
2178 +++ b/arch/cris/include/arch-v10/arch/cache.h
2179 @@ -1,8 +1,9 @@
2180 #ifndef _ASM_ARCH_CACHE_H
2181 #define _ASM_ARCH_CACHE_H
2182
2183 +#include <linux/const.h>
2184 /* Etrax 100LX have 32-byte cache-lines. */
2185 -#define L1_CACHE_BYTES 32
2186 #define L1_CACHE_SHIFT 5
2187 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2188
2189 #endif /* _ASM_ARCH_CACHE_H */
2190 diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
2191 index 7caf25d..ee65ac5 100644
2192 --- a/arch/cris/include/arch-v32/arch/cache.h
2193 +++ b/arch/cris/include/arch-v32/arch/cache.h
2194 @@ -1,11 +1,12 @@
2195 #ifndef _ASM_CRIS_ARCH_CACHE_H
2196 #define _ASM_CRIS_ARCH_CACHE_H
2197
2198 +#include <linux/const.h>
2199 #include <arch/hwregs/dma.h>
2200
2201 /* A cache-line is 32 bytes. */
2202 -#define L1_CACHE_BYTES 32
2203 #define L1_CACHE_SHIFT 5
2204 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2205
2206 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
2207
2208 diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
2209 index b86329d..6709906 100644
2210 --- a/arch/frv/include/asm/atomic.h
2211 +++ b/arch/frv/include/asm/atomic.h
2212 @@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
2213 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
2214 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
2215
2216 +#define atomic64_read_unchecked(v) atomic64_read(v)
2217 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2218 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2219 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2220 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2221 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2222 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2223 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2224 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2225 +
2226 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
2227 {
2228 int c, old;
2229 diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
2230 index 2797163..c2a401d 100644
2231 --- a/arch/frv/include/asm/cache.h
2232 +++ b/arch/frv/include/asm/cache.h
2233 @@ -12,10 +12,11 @@
2234 #ifndef __ASM_CACHE_H
2235 #define __ASM_CACHE_H
2236
2237 +#include <linux/const.h>
2238
2239 /* bytes per L1 cache line */
2240 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
2241 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2242 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2243
2244 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2245 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2246 diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
2247 index 43901f2..0d8b865 100644
2248 --- a/arch/frv/include/asm/kmap_types.h
2249 +++ b/arch/frv/include/asm/kmap_types.h
2250 @@ -2,6 +2,6 @@
2251 #ifndef _ASM_KMAP_TYPES_H
2252 #define _ASM_KMAP_TYPES_H
2253
2254 -#define KM_TYPE_NR 17
2255 +#define KM_TYPE_NR 18
2256
2257 #endif
2258 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
2259 index 385fd30..6c3d97e 100644
2260 --- a/arch/frv/mm/elf-fdpic.c
2261 +++ b/arch/frv/mm/elf-fdpic.c
2262 @@ -73,8 +73,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2263 if (addr) {
2264 addr = PAGE_ALIGN(addr);
2265 vma = find_vma(current->mm, addr);
2266 - if (TASK_SIZE - len >= addr &&
2267 - (!vma || addr + len <= vma->vm_start))
2268 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
2269 goto success;
2270 }
2271
2272 @@ -89,7 +88,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2273 for (; vma; vma = vma->vm_next) {
2274 if (addr > limit)
2275 break;
2276 - if (addr + len <= vma->vm_start)
2277 + if (check_heap_stack_gap(vma, addr, len))
2278 goto success;
2279 addr = vma->vm_end;
2280 }
2281 @@ -104,7 +103,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2282 for (; vma; vma = vma->vm_next) {
2283 if (addr > limit)
2284 break;
2285 - if (addr + len <= vma->vm_start)
2286 + if (check_heap_stack_gap(vma, addr, len))
2287 goto success;
2288 addr = vma->vm_end;
2289 }
2290 diff --git a/arch/h8300/include/asm/cache.h b/arch/h8300/include/asm/cache.h
2291 index c635028..6d9445a 100644
2292 --- a/arch/h8300/include/asm/cache.h
2293 +++ b/arch/h8300/include/asm/cache.h
2294 @@ -1,8 +1,10 @@
2295 #ifndef __ARCH_H8300_CACHE_H
2296 #define __ARCH_H8300_CACHE_H
2297
2298 +#include <linux/const.h>
2299 +
2300 /* bytes per L1 cache line */
2301 -#define L1_CACHE_BYTES 4
2302 +#define L1_CACHE_BYTES _AC(4,UL)
2303
2304 /* m68k-elf-gcc 2.95.2 doesn't like these */
2305
2306 diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
2307 index 0f01de2..d37d309 100644
2308 --- a/arch/hexagon/include/asm/cache.h
2309 +++ b/arch/hexagon/include/asm/cache.h
2310 @@ -21,9 +21,11 @@
2311 #ifndef __ASM_CACHE_H
2312 #define __ASM_CACHE_H
2313
2314 +#include <linux/const.h>
2315 +
2316 /* Bytes per L1 cache line */
2317 -#define L1_CACHE_SHIFT (5)
2318 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2319 +#define L1_CACHE_SHIFT 5
2320 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2321
2322 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
2323 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
2324 diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
2325 index 6e6fe18..a6ae668 100644
2326 --- a/arch/ia64/include/asm/atomic.h
2327 +++ b/arch/ia64/include/asm/atomic.h
2328 @@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
2329 #define atomic64_inc(v) atomic64_add(1, (v))
2330 #define atomic64_dec(v) atomic64_sub(1, (v))
2331
2332 +#define atomic64_read_unchecked(v) atomic64_read(v)
2333 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2334 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2335 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2336 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2337 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2338 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2339 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2340 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2341 +
2342 /* Atomic operations are already serializing */
2343 #define smp_mb__before_atomic_dec() barrier()
2344 #define smp_mb__after_atomic_dec() barrier()
2345 diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
2346 index 988254a..e1ee885 100644
2347 --- a/arch/ia64/include/asm/cache.h
2348 +++ b/arch/ia64/include/asm/cache.h
2349 @@ -1,6 +1,7 @@
2350 #ifndef _ASM_IA64_CACHE_H
2351 #define _ASM_IA64_CACHE_H
2352
2353 +#include <linux/const.h>
2354
2355 /*
2356 * Copyright (C) 1998-2000 Hewlett-Packard Co
2357 @@ -9,7 +10,7 @@
2358
2359 /* Bytes per L1 (data) cache line. */
2360 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
2361 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2362 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2363
2364 #ifdef CONFIG_SMP
2365 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2366 diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
2367 index b5298eb..67c6e62 100644
2368 --- a/arch/ia64/include/asm/elf.h
2369 +++ b/arch/ia64/include/asm/elf.h
2370 @@ -42,6 +42,13 @@
2371 */
2372 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
2373
2374 +#ifdef CONFIG_PAX_ASLR
2375 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
2376 +
2377 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2378 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2379 +#endif
2380 +
2381 #define PT_IA_64_UNWIND 0x70000001
2382
2383 /* IA-64 relocations: */
2384 diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
2385 index 96a8d92..617a1cf 100644
2386 --- a/arch/ia64/include/asm/pgalloc.h
2387 +++ b/arch/ia64/include/asm/pgalloc.h
2388 @@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
2389 pgd_val(*pgd_entry) = __pa(pud);
2390 }
2391
2392 +static inline void
2393 +pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
2394 +{
2395 + pgd_populate(mm, pgd_entry, pud);
2396 +}
2397 +
2398 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
2399 {
2400 return quicklist_alloc(0, GFP_KERNEL, NULL);
2401 @@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
2402 pud_val(*pud_entry) = __pa(pmd);
2403 }
2404
2405 +static inline void
2406 +pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
2407 +{
2408 + pud_populate(mm, pud_entry, pmd);
2409 +}
2410 +
2411 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
2412 {
2413 return quicklist_alloc(0, GFP_KERNEL, NULL);
2414 diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
2415 index 815810c..d60bd4c 100644
2416 --- a/arch/ia64/include/asm/pgtable.h
2417 +++ b/arch/ia64/include/asm/pgtable.h
2418 @@ -12,7 +12,7 @@
2419 * David Mosberger-Tang <davidm@hpl.hp.com>
2420 */
2421
2422 -
2423 +#include <linux/const.h>
2424 #include <asm/mman.h>
2425 #include <asm/page.h>
2426 #include <asm/processor.h>
2427 @@ -142,6 +142,17 @@
2428 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2429 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2430 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
2431 +
2432 +#ifdef CONFIG_PAX_PAGEEXEC
2433 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
2434 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2435 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2436 +#else
2437 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
2438 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
2439 +# define PAGE_COPY_NOEXEC PAGE_COPY
2440 +#endif
2441 +
2442 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
2443 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
2444 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
2445 diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
2446 index 54ff557..70c88b7 100644
2447 --- a/arch/ia64/include/asm/spinlock.h
2448 +++ b/arch/ia64/include/asm/spinlock.h
2449 @@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
2450 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
2451
2452 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
2453 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
2454 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
2455 }
2456
2457 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
2458 diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
2459 index 449c8c0..432a3d2 100644
2460 --- a/arch/ia64/include/asm/uaccess.h
2461 +++ b/arch/ia64/include/asm/uaccess.h
2462 @@ -257,7 +257,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2463 const void *__cu_from = (from); \
2464 long __cu_len = (n); \
2465 \
2466 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
2467 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) \
2468 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
2469 __cu_len; \
2470 })
2471 @@ -269,7 +269,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2472 long __cu_len = (n); \
2473 \
2474 __chk_user_ptr(__cu_from); \
2475 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
2476 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) \
2477 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
2478 __cu_len; \
2479 })
2480 diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
2481 index 24603be..948052d 100644
2482 --- a/arch/ia64/kernel/module.c
2483 +++ b/arch/ia64/kernel/module.c
2484 @@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
2485 void
2486 module_free (struct module *mod, void *module_region)
2487 {
2488 - if (mod && mod->arch.init_unw_table &&
2489 - module_region == mod->module_init) {
2490 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
2491 unw_remove_unwind_table(mod->arch.init_unw_table);
2492 mod->arch.init_unw_table = NULL;
2493 }
2494 @@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
2495 }
2496
2497 static inline int
2498 +in_init_rx (const struct module *mod, uint64_t addr)
2499 +{
2500 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
2501 +}
2502 +
2503 +static inline int
2504 +in_init_rw (const struct module *mod, uint64_t addr)
2505 +{
2506 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
2507 +}
2508 +
2509 +static inline int
2510 in_init (const struct module *mod, uint64_t addr)
2511 {
2512 - return addr - (uint64_t) mod->module_init < mod->init_size;
2513 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
2514 +}
2515 +
2516 +static inline int
2517 +in_core_rx (const struct module *mod, uint64_t addr)
2518 +{
2519 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
2520 +}
2521 +
2522 +static inline int
2523 +in_core_rw (const struct module *mod, uint64_t addr)
2524 +{
2525 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
2526 }
2527
2528 static inline int
2529 in_core (const struct module *mod, uint64_t addr)
2530 {
2531 - return addr - (uint64_t) mod->module_core < mod->core_size;
2532 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
2533 }
2534
2535 static inline int
2536 @@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
2537 break;
2538
2539 case RV_BDREL:
2540 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
2541 + if (in_init_rx(mod, val))
2542 + val -= (uint64_t) mod->module_init_rx;
2543 + else if (in_init_rw(mod, val))
2544 + val -= (uint64_t) mod->module_init_rw;
2545 + else if (in_core_rx(mod, val))
2546 + val -= (uint64_t) mod->module_core_rx;
2547 + else if (in_core_rw(mod, val))
2548 + val -= (uint64_t) mod->module_core_rw;
2549 break;
2550
2551 case RV_LTV:
2552 @@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
2553 * addresses have been selected...
2554 */
2555 uint64_t gp;
2556 - if (mod->core_size > MAX_LTOFF)
2557 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
2558 /*
2559 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
2560 * at the end of the module.
2561 */
2562 - gp = mod->core_size - MAX_LTOFF / 2;
2563 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
2564 else
2565 - gp = mod->core_size / 2;
2566 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
2567 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
2568 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
2569 mod->arch.gp = gp;
2570 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
2571 }
2572 diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
2573 index d9439ef..b9a4303 100644
2574 --- a/arch/ia64/kernel/sys_ia64.c
2575 +++ b/arch/ia64/kernel/sys_ia64.c
2576 @@ -43,6 +43,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2577 if (REGION_NUMBER(addr) == RGN_HPAGE)
2578 addr = 0;
2579 #endif
2580 +
2581 +#ifdef CONFIG_PAX_RANDMMAP
2582 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2583 + addr = mm->free_area_cache;
2584 + else
2585 +#endif
2586 +
2587 if (!addr)
2588 addr = mm->free_area_cache;
2589
2590 @@ -61,14 +68,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2591 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
2592 /* At this point: (!vma || addr < vma->vm_end). */
2593 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
2594 - if (start_addr != TASK_UNMAPPED_BASE) {
2595 + if (start_addr != mm->mmap_base) {
2596 /* Start a new search --- just in case we missed some holes. */
2597 - addr = TASK_UNMAPPED_BASE;
2598 + addr = mm->mmap_base;
2599 goto full_search;
2600 }
2601 return -ENOMEM;
2602 }
2603 - if (!vma || addr + len <= vma->vm_start) {
2604 + if (check_heap_stack_gap(vma, addr, len)) {
2605 /* Remember the address where we stopped this search: */
2606 mm->free_area_cache = addr + len;
2607 return addr;
2608 diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
2609 index 0ccb28f..8992469 100644
2610 --- a/arch/ia64/kernel/vmlinux.lds.S
2611 +++ b/arch/ia64/kernel/vmlinux.lds.S
2612 @@ -198,7 +198,7 @@ SECTIONS {
2613 /* Per-cpu data: */
2614 . = ALIGN(PERCPU_PAGE_SIZE);
2615 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
2616 - __phys_per_cpu_start = __per_cpu_load;
2617 + __phys_per_cpu_start = per_cpu_load;
2618 /*
2619 * ensure percpu data fits
2620 * into percpu page size
2621 diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
2622 index 8443daf..0a01e30 100644
2623 --- a/arch/ia64/mm/fault.c
2624 +++ b/arch/ia64/mm/fault.c
2625 @@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
2626 return pte_present(pte);
2627 }
2628
2629 +#ifdef CONFIG_PAX_PAGEEXEC
2630 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2631 +{
2632 + unsigned long i;
2633 +
2634 + printk(KERN_ERR "PAX: bytes at PC: ");
2635 + for (i = 0; i < 8; i++) {
2636 + unsigned int c;
2637 + if (get_user(c, (unsigned int *)pc+i))
2638 + printk(KERN_CONT "???????? ");
2639 + else
2640 + printk(KERN_CONT "%08x ", c);
2641 + }
2642 + printk("\n");
2643 +}
2644 +#endif
2645 +
2646 # define VM_READ_BIT 0
2647 # define VM_WRITE_BIT 1
2648 # define VM_EXEC_BIT 2
2649 @@ -149,8 +166,21 @@ retry:
2650 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
2651 goto bad_area;
2652
2653 - if ((vma->vm_flags & mask) != mask)
2654 + if ((vma->vm_flags & mask) != mask) {
2655 +
2656 +#ifdef CONFIG_PAX_PAGEEXEC
2657 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
2658 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
2659 + goto bad_area;
2660 +
2661 + up_read(&mm->mmap_sem);
2662 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
2663 + do_group_exit(SIGKILL);
2664 + }
2665 +#endif
2666 +
2667 goto bad_area;
2668 + }
2669
2670 /*
2671 * If for any reason at all we couldn't handle the fault, make
2672 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
2673 index 5ca674b..e0e1b70 100644
2674 --- a/arch/ia64/mm/hugetlbpage.c
2675 +++ b/arch/ia64/mm/hugetlbpage.c
2676 @@ -171,7 +171,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
2677 /* At this point: (!vmm || addr < vmm->vm_end). */
2678 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
2679 return -ENOMEM;
2680 - if (!vmm || (addr + len) <= vmm->vm_start)
2681 + if (check_heap_stack_gap(vmm, addr, len))
2682 return addr;
2683 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
2684 }
2685 diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
2686 index 0eab454..bd794f2 100644
2687 --- a/arch/ia64/mm/init.c
2688 +++ b/arch/ia64/mm/init.c
2689 @@ -120,6 +120,19 @@ ia64_init_addr_space (void)
2690 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
2691 vma->vm_end = vma->vm_start + PAGE_SIZE;
2692 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
2693 +
2694 +#ifdef CONFIG_PAX_PAGEEXEC
2695 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
2696 + vma->vm_flags &= ~VM_EXEC;
2697 +
2698 +#ifdef CONFIG_PAX_MPROTECT
2699 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
2700 + vma->vm_flags &= ~VM_MAYEXEC;
2701 +#endif
2702 +
2703 + }
2704 +#endif
2705 +
2706 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
2707 down_write(&current->mm->mmap_sem);
2708 if (insert_vm_struct(current->mm, vma)) {
2709 diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
2710 index 40b3ee9..8c2c112 100644
2711 --- a/arch/m32r/include/asm/cache.h
2712 +++ b/arch/m32r/include/asm/cache.h
2713 @@ -1,8 +1,10 @@
2714 #ifndef _ASM_M32R_CACHE_H
2715 #define _ASM_M32R_CACHE_H
2716
2717 +#include <linux/const.h>
2718 +
2719 /* L1 cache line size */
2720 #define L1_CACHE_SHIFT 4
2721 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2722 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2723
2724 #endif /* _ASM_M32R_CACHE_H */
2725 diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
2726 index 82abd15..d95ae5d 100644
2727 --- a/arch/m32r/lib/usercopy.c
2728 +++ b/arch/m32r/lib/usercopy.c
2729 @@ -14,6 +14,9 @@
2730 unsigned long
2731 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2732 {
2733 + if ((long)n < 0)
2734 + return n;
2735 +
2736 prefetch(from);
2737 if (access_ok(VERIFY_WRITE, to, n))
2738 __copy_user(to,from,n);
2739 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2740 unsigned long
2741 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
2742 {
2743 + if ((long)n < 0)
2744 + return n;
2745 +
2746 prefetchw(to);
2747 if (access_ok(VERIFY_READ, from, n))
2748 __copy_user_zeroing(to,from,n);
2749 diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
2750 index 0395c51..5f26031 100644
2751 --- a/arch/m68k/include/asm/cache.h
2752 +++ b/arch/m68k/include/asm/cache.h
2753 @@ -4,9 +4,11 @@
2754 #ifndef __ARCH_M68K_CACHE_H
2755 #define __ARCH_M68K_CACHE_H
2756
2757 +#include <linux/const.h>
2758 +
2759 /* bytes per L1 cache line */
2760 #define L1_CACHE_SHIFT 4
2761 -#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
2762 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2763
2764 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2765
2766 diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
2767 index 4efe96a..60e8699 100644
2768 --- a/arch/microblaze/include/asm/cache.h
2769 +++ b/arch/microblaze/include/asm/cache.h
2770 @@ -13,11 +13,12 @@
2771 #ifndef _ASM_MICROBLAZE_CACHE_H
2772 #define _ASM_MICROBLAZE_CACHE_H
2773
2774 +#include <linux/const.h>
2775 #include <asm/registers.h>
2776
2777 #define L1_CACHE_SHIFT 5
2778 /* word-granular cache in microblaze */
2779 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2780 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2781
2782 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2783
2784 diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
2785 index 3f4c5cb..3439c6e 100644
2786 --- a/arch/mips/include/asm/atomic.h
2787 +++ b/arch/mips/include/asm/atomic.h
2788 @@ -21,6 +21,10 @@
2789 #include <asm/cmpxchg.h>
2790 #include <asm/war.h>
2791
2792 +#ifdef CONFIG_GENERIC_ATOMIC64
2793 +#include <asm-generic/atomic64.h>
2794 +#endif
2795 +
2796 #define ATOMIC_INIT(i) { (i) }
2797
2798 /*
2799 @@ -765,6 +769,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
2800 */
2801 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
2802
2803 +#define atomic64_read_unchecked(v) atomic64_read(v)
2804 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2805 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2806 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2807 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2808 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2809 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2810 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2811 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2812 +
2813 #endif /* CONFIG_64BIT */
2814
2815 /*
2816 diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
2817 index b4db69f..8f3b093 100644
2818 --- a/arch/mips/include/asm/cache.h
2819 +++ b/arch/mips/include/asm/cache.h
2820 @@ -9,10 +9,11 @@
2821 #ifndef _ASM_CACHE_H
2822 #define _ASM_CACHE_H
2823
2824 +#include <linux/const.h>
2825 #include <kmalloc.h>
2826
2827 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
2828 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2829 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2830
2831 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2832 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2833 diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
2834 index 455c0ac..ad65fbe 100644
2835 --- a/arch/mips/include/asm/elf.h
2836 +++ b/arch/mips/include/asm/elf.h
2837 @@ -372,13 +372,16 @@ extern const char *__elf_platform;
2838 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2839 #endif
2840
2841 +#ifdef CONFIG_PAX_ASLR
2842 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2843 +
2844 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2845 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2846 +#endif
2847 +
2848 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
2849 struct linux_binprm;
2850 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
2851 int uses_interp);
2852
2853 -struct mm_struct;
2854 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
2855 -#define arch_randomize_brk arch_randomize_brk
2856 -
2857 #endif /* _ASM_ELF_H */
2858 diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
2859 index c1f6afa..38cc6e9 100644
2860 --- a/arch/mips/include/asm/exec.h
2861 +++ b/arch/mips/include/asm/exec.h
2862 @@ -12,6 +12,6 @@
2863 #ifndef _ASM_EXEC_H
2864 #define _ASM_EXEC_H
2865
2866 -extern unsigned long arch_align_stack(unsigned long sp);
2867 +#define arch_align_stack(x) ((x) & ~0xfUL)
2868
2869 #endif /* _ASM_EXEC_H */
2870 diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
2871 index da9bd7d..91aa7ab 100644
2872 --- a/arch/mips/include/asm/page.h
2873 +++ b/arch/mips/include/asm/page.h
2874 @@ -98,7 +98,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
2875 #ifdef CONFIG_CPU_MIPS32
2876 typedef struct { unsigned long pte_low, pte_high; } pte_t;
2877 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
2878 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
2879 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
2880 #else
2881 typedef struct { unsigned long long pte; } pte_t;
2882 #define pte_val(x) ((x).pte)
2883 diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
2884 index 881d18b..cea38bc 100644
2885 --- a/arch/mips/include/asm/pgalloc.h
2886 +++ b/arch/mips/include/asm/pgalloc.h
2887 @@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2888 {
2889 set_pud(pud, __pud((unsigned long)pmd));
2890 }
2891 +
2892 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2893 +{
2894 + pud_populate(mm, pud, pmd);
2895 +}
2896 #endif
2897
2898 /*
2899 diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
2900 index ca97e0e..cd08920 100644
2901 --- a/arch/mips/include/asm/thread_info.h
2902 +++ b/arch/mips/include/asm/thread_info.h
2903 @@ -111,6 +111,8 @@ register struct thread_info *__current_thread_info __asm__("$28");
2904 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
2905 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
2906 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
2907 +/* li takes a 32bit immediate */
2908 +#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
2909 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
2910
2911 #ifdef CONFIG_MIPS32_O32
2912 @@ -134,15 +136,18 @@ register struct thread_info *__current_thread_info __asm__("$28");
2913 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
2914 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
2915 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
2916 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
2917 +
2918 +#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
2919
2920 /* work to do in syscall_trace_leave() */
2921 -#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
2922 +#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
2923
2924 /* work to do on interrupt/exception return */
2925 #define _TIF_WORK_MASK (0x0000ffef & \
2926 ~(_TIF_SECCOMP | _TIF_SYSCALL_AUDIT))
2927 /* work to do on any return to u-space */
2928 -#define _TIF_ALLWORK_MASK (0x8000ffff & ~_TIF_SECCOMP)
2929 +#define _TIF_ALLWORK_MASK ((0x8000ffff & ~_TIF_SECCOMP) | _TIF_GRSEC_SETXID)
2930
2931 #endif /* __KERNEL__ */
2932
2933 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
2934 index 9fdd8bc..4bd7f1a 100644
2935 --- a/arch/mips/kernel/binfmt_elfn32.c
2936 +++ b/arch/mips/kernel/binfmt_elfn32.c
2937 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2938 #undef ELF_ET_DYN_BASE
2939 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2940
2941 +#ifdef CONFIG_PAX_ASLR
2942 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2943 +
2944 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2945 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2946 +#endif
2947 +
2948 #include <asm/processor.h>
2949 #include <linux/module.h>
2950 #include <linux/elfcore.h>
2951 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
2952 index ff44823..97f8906 100644
2953 --- a/arch/mips/kernel/binfmt_elfo32.c
2954 +++ b/arch/mips/kernel/binfmt_elfo32.c
2955 @@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2956 #undef ELF_ET_DYN_BASE
2957 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2958
2959 +#ifdef CONFIG_PAX_ASLR
2960 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2961 +
2962 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2963 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2964 +#endif
2965 +
2966 #include <asm/processor.h>
2967
2968 /*
2969 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
2970 index e9a5fd7..378809a 100644
2971 --- a/arch/mips/kernel/process.c
2972 +++ b/arch/mips/kernel/process.c
2973 @@ -480,15 +480,3 @@ unsigned long get_wchan(struct task_struct *task)
2974 out:
2975 return pc;
2976 }
2977 -
2978 -/*
2979 - * Don't forget that the stack pointer must be aligned on a 8 bytes
2980 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
2981 - */
2982 -unsigned long arch_align_stack(unsigned long sp)
2983 -{
2984 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
2985 - sp -= get_random_int() & ~PAGE_MASK;
2986 -
2987 - return sp & ALMASK;
2988 -}
2989 diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
2990 index 4812c6d..2069554 100644
2991 --- a/arch/mips/kernel/ptrace.c
2992 +++ b/arch/mips/kernel/ptrace.c
2993 @@ -528,6 +528,10 @@ static inline int audit_arch(void)
2994 return arch;
2995 }
2996
2997 +#ifdef CONFIG_GRKERNSEC_SETXID
2998 +extern void gr_delayed_cred_worker(void);
2999 +#endif
3000 +
3001 /*
3002 * Notification of system call entry/exit
3003 * - triggered by current->work.syscall_trace
3004 @@ -537,6 +541,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
3005 /* do the secure computing check first */
3006 secure_computing_strict(regs->regs[2]);
3007
3008 +#ifdef CONFIG_GRKERNSEC_SETXID
3009 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
3010 + gr_delayed_cred_worker();
3011 +#endif
3012 +
3013 if (!(current->ptrace & PT_PTRACED))
3014 goto out;
3015
3016 diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
3017 index a632bc1..0b77c7c 100644
3018 --- a/arch/mips/kernel/scall32-o32.S
3019 +++ b/arch/mips/kernel/scall32-o32.S
3020 @@ -52,7 +52,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3021
3022 stack_done:
3023 lw t0, TI_FLAGS($28) # syscall tracing enabled?
3024 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3025 + li t1, _TIF_SYSCALL_WORK
3026 and t0, t1
3027 bnez t0, syscall_trace_entry # -> yes
3028
3029 diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
3030 index 3b5a5e9..e1ee86d 100644
3031 --- a/arch/mips/kernel/scall64-64.S
3032 +++ b/arch/mips/kernel/scall64-64.S
3033 @@ -54,7 +54,7 @@ NESTED(handle_sys64, PT_SIZE, sp)
3034
3035 sd a3, PT_R26(sp) # save a3 for syscall restarting
3036
3037 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3038 + li t1, _TIF_SYSCALL_WORK
3039 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3040 and t0, t1, t0
3041 bnez t0, syscall_trace_entry
3042 diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
3043 index 6be6f70..1859577 100644
3044 --- a/arch/mips/kernel/scall64-n32.S
3045 +++ b/arch/mips/kernel/scall64-n32.S
3046 @@ -53,7 +53,7 @@ NESTED(handle_sysn32, PT_SIZE, sp)
3047
3048 sd a3, PT_R26(sp) # save a3 for syscall restarting
3049
3050 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3051 + li t1, _TIF_SYSCALL_WORK
3052 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3053 and t0, t1, t0
3054 bnez t0, n32_syscall_trace_entry
3055 diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
3056 index 5422855..74e63a3 100644
3057 --- a/arch/mips/kernel/scall64-o32.S
3058 +++ b/arch/mips/kernel/scall64-o32.S
3059 @@ -81,7 +81,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3060 PTR 4b, bad_stack
3061 .previous
3062
3063 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3064 + li t1, _TIF_SYSCALL_WORK
3065 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3066 and t0, t1, t0
3067 bnez t0, trace_a_syscall
3068 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
3069 index c14f6df..537e729 100644
3070 --- a/arch/mips/mm/fault.c
3071 +++ b/arch/mips/mm/fault.c
3072 @@ -27,6 +27,23 @@
3073 #include <asm/highmem.h> /* For VMALLOC_END */
3074 #include <linux/kdebug.h>
3075
3076 +#ifdef CONFIG_PAX_PAGEEXEC
3077 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3078 +{
3079 + unsigned long i;
3080 +
3081 + printk(KERN_ERR "PAX: bytes at PC: ");
3082 + for (i = 0; i < 5; i++) {
3083 + unsigned int c;
3084 + if (get_user(c, (unsigned int *)pc+i))
3085 + printk(KERN_CONT "???????? ");
3086 + else
3087 + printk(KERN_CONT "%08x ", c);
3088 + }
3089 + printk("\n");
3090 +}
3091 +#endif
3092 +
3093 /*
3094 * This routine handles page faults. It determines the address,
3095 * and the problem, and then passes it off to one of the appropriate
3096 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
3097 index 302d779..7d35bf8 100644
3098 --- a/arch/mips/mm/mmap.c
3099 +++ b/arch/mips/mm/mmap.c
3100 @@ -95,6 +95,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3101 do_color_align = 1;
3102
3103 /* requesting a specific address */
3104 +
3105 +#ifdef CONFIG_PAX_RANDMMAP
3106 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
3107 +#endif
3108 +
3109 if (addr) {
3110 if (do_color_align)
3111 addr = COLOUR_ALIGN(addr, pgoff);
3112 @@ -102,8 +107,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3113 addr = PAGE_ALIGN(addr);
3114
3115 vma = find_vma(mm, addr);
3116 - if (TASK_SIZE - len >= addr &&
3117 - (!vma || addr + len <= vma->vm_start))
3118 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len))
3119 return addr;
3120 }
3121
3122 @@ -118,7 +122,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3123 /* At this point: (!vma || addr < vma->vm_end). */
3124 if (TASK_SIZE - len < addr)
3125 return -ENOMEM;
3126 - if (!vma || addr + len <= vma->vm_start)
3127 + if (check_heap_stack_gap(vmm, addr, len))
3128 return addr;
3129 addr = vma->vm_end;
3130 if (do_color_align)
3131 @@ -145,7 +149,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3132 /* make sure it can fit in the remaining address space */
3133 if (likely(addr > len)) {
3134 vma = find_vma(mm, addr - len);
3135 - if (!vma || addr <= vma->vm_start) {
3136 + if (check_heap_stack_gap(vmm, addr - len, len))
3137 /* cache the address as a hint for next time */
3138 return mm->free_area_cache = addr - len;
3139 }
3140 @@ -165,7 +169,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3141 * return with success:
3142 */
3143 vma = find_vma(mm, addr);
3144 - if (likely(!vma || addr + len <= vma->vm_start)) {
3145 + if (check_heap_stack_gap(vmm, addr, len)) {
3146 /* cache the address as a hint for next time */
3147 return mm->free_area_cache = addr;
3148 }
3149 @@ -242,30 +246,3 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3150 mm->unmap_area = arch_unmap_area_topdown;
3151 }
3152 }
3153 -
3154 -static inline unsigned long brk_rnd(void)
3155 -{
3156 - unsigned long rnd = get_random_int();
3157 -
3158 - rnd = rnd << PAGE_SHIFT;
3159 - /* 8MB for 32bit, 256MB for 64bit */
3160 - if (TASK_IS_32BIT_ADDR)
3161 - rnd = rnd & 0x7ffffful;
3162 - else
3163 - rnd = rnd & 0xffffffful;
3164 -
3165 - return rnd;
3166 -}
3167 -
3168 -unsigned long arch_randomize_brk(struct mm_struct *mm)
3169 -{
3170 - unsigned long base = mm->brk;
3171 - unsigned long ret;
3172 -
3173 - ret = PAGE_ALIGN(base + brk_rnd());
3174 -
3175 - if (ret < mm->brk)
3176 - return mm->brk;
3177 -
3178 - return ret;
3179 -}
3180 diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
3181 index 967d144..db12197 100644
3182 --- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
3183 +++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
3184 @@ -11,12 +11,14 @@
3185 #ifndef _ASM_PROC_CACHE_H
3186 #define _ASM_PROC_CACHE_H
3187
3188 +#include <linux/const.h>
3189 +
3190 /* L1 cache */
3191
3192 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
3193 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
3194 -#define L1_CACHE_BYTES 16 /* bytes per entry */
3195 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
3196 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
3197 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
3198
3199 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
3200 diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3201 index bcb5df2..84fabd2 100644
3202 --- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3203 +++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3204 @@ -16,13 +16,15 @@
3205 #ifndef _ASM_PROC_CACHE_H
3206 #define _ASM_PROC_CACHE_H
3207
3208 +#include <linux/const.h>
3209 +
3210 /*
3211 * L1 cache
3212 */
3213 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
3214 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
3215 -#define L1_CACHE_BYTES 32 /* bytes per entry */
3216 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
3217 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
3218 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
3219
3220 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
3221 diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
3222 index 4ce7a01..449202a 100644
3223 --- a/arch/openrisc/include/asm/cache.h
3224 +++ b/arch/openrisc/include/asm/cache.h
3225 @@ -19,11 +19,13 @@
3226 #ifndef __ASM_OPENRISC_CACHE_H
3227 #define __ASM_OPENRISC_CACHE_H
3228
3229 +#include <linux/const.h>
3230 +
3231 /* FIXME: How can we replace these with values from the CPU...
3232 * they shouldn't be hard-coded!
3233 */
3234
3235 -#define L1_CACHE_BYTES 16
3236 #define L1_CACHE_SHIFT 4
3237 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3238
3239 #endif /* __ASM_OPENRISC_CACHE_H */
3240 diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
3241 index af9cf30..2aae9b2 100644
3242 --- a/arch/parisc/include/asm/atomic.h
3243 +++ b/arch/parisc/include/asm/atomic.h
3244 @@ -229,6 +229,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
3245
3246 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
3247
3248 +#define atomic64_read_unchecked(v) atomic64_read(v)
3249 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3250 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3251 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3252 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3253 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3254 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3255 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3256 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3257 +
3258 #endif /* !CONFIG_64BIT */
3259
3260
3261 diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
3262 index 47f11c7..3420df2 100644
3263 --- a/arch/parisc/include/asm/cache.h
3264 +++ b/arch/parisc/include/asm/cache.h
3265 @@ -5,6 +5,7 @@
3266 #ifndef __ARCH_PARISC_CACHE_H
3267 #define __ARCH_PARISC_CACHE_H
3268
3269 +#include <linux/const.h>
3270
3271 /*
3272 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
3273 @@ -15,13 +16,13 @@
3274 * just ruin performance.
3275 */
3276 #ifdef CONFIG_PA20
3277 -#define L1_CACHE_BYTES 64
3278 #define L1_CACHE_SHIFT 6
3279 #else
3280 -#define L1_CACHE_BYTES 32
3281 #define L1_CACHE_SHIFT 5
3282 #endif
3283
3284 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3285 +
3286 #ifndef __ASSEMBLY__
3287
3288 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3289 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
3290 index 19f6cb1..6c78cf2 100644
3291 --- a/arch/parisc/include/asm/elf.h
3292 +++ b/arch/parisc/include/asm/elf.h
3293 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
3294
3295 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
3296
3297 +#ifdef CONFIG_PAX_ASLR
3298 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
3299 +
3300 +#define PAX_DELTA_MMAP_LEN 16
3301 +#define PAX_DELTA_STACK_LEN 16
3302 +#endif
3303 +
3304 /* This yields a mask that user programs can use to figure out what
3305 instruction set this CPU supports. This could be done in user space,
3306 but it's not easy, and we've already done it here. */
3307 diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
3308 index fc987a1..6e068ef 100644
3309 --- a/arch/parisc/include/asm/pgalloc.h
3310 +++ b/arch/parisc/include/asm/pgalloc.h
3311 @@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
3312 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
3313 }
3314
3315 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
3316 +{
3317 + pgd_populate(mm, pgd, pmd);
3318 +}
3319 +
3320 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
3321 {
3322 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
3323 @@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
3324 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
3325 #define pmd_free(mm, x) do { } while (0)
3326 #define pgd_populate(mm, pmd, pte) BUG()
3327 +#define pgd_populate_kernel(mm, pmd, pte) BUG()
3328
3329 #endif
3330
3331 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
3332 index ee99f23..802b0a1 100644
3333 --- a/arch/parisc/include/asm/pgtable.h
3334 +++ b/arch/parisc/include/asm/pgtable.h
3335 @@ -212,6 +212,17 @@ struct vm_area_struct;
3336 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
3337 #define PAGE_COPY PAGE_EXECREAD
3338 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
3339 +
3340 +#ifdef CONFIG_PAX_PAGEEXEC
3341 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
3342 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3343 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3344 +#else
3345 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
3346 +# define PAGE_COPY_NOEXEC PAGE_COPY
3347 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
3348 +#endif
3349 +
3350 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
3351 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
3352 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
3353 diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
3354 index 4ba2c93..f5e3974 100644
3355 --- a/arch/parisc/include/asm/uaccess.h
3356 +++ b/arch/parisc/include/asm/uaccess.h
3357 @@ -251,10 +251,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
3358 const void __user *from,
3359 unsigned long n)
3360 {
3361 - int sz = __compiletime_object_size(to);
3362 + size_t sz = __compiletime_object_size(to);
3363 int ret = -EFAULT;
3364
3365 - if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
3366 + if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
3367 ret = __copy_from_user(to, from, n);
3368 else
3369 copy_from_user_overflow();
3370 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
3371 index 5e34ccf..672bc9c 100644
3372 --- a/arch/parisc/kernel/module.c
3373 +++ b/arch/parisc/kernel/module.c
3374 @@ -98,16 +98,38 @@
3375
3376 /* three functions to determine where in the module core
3377 * or init pieces the location is */
3378 +static inline int in_init_rx(struct module *me, void *loc)
3379 +{
3380 + return (loc >= me->module_init_rx &&
3381 + loc < (me->module_init_rx + me->init_size_rx));
3382 +}
3383 +
3384 +static inline int in_init_rw(struct module *me, void *loc)
3385 +{
3386 + return (loc >= me->module_init_rw &&
3387 + loc < (me->module_init_rw + me->init_size_rw));
3388 +}
3389 +
3390 static inline int in_init(struct module *me, void *loc)
3391 {
3392 - return (loc >= me->module_init &&
3393 - loc <= (me->module_init + me->init_size));
3394 + return in_init_rx(me, loc) || in_init_rw(me, loc);
3395 +}
3396 +
3397 +static inline int in_core_rx(struct module *me, void *loc)
3398 +{
3399 + return (loc >= me->module_core_rx &&
3400 + loc < (me->module_core_rx + me->core_size_rx));
3401 +}
3402 +
3403 +static inline int in_core_rw(struct module *me, void *loc)
3404 +{
3405 + return (loc >= me->module_core_rw &&
3406 + loc < (me->module_core_rw + me->core_size_rw));
3407 }
3408
3409 static inline int in_core(struct module *me, void *loc)
3410 {
3411 - return (loc >= me->module_core &&
3412 - loc <= (me->module_core + me->core_size));
3413 + return in_core_rx(me, loc) || in_core_rw(me, loc);
3414 }
3415
3416 static inline int in_local(struct module *me, void *loc)
3417 @@ -373,13 +395,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
3418 }
3419
3420 /* align things a bit */
3421 - me->core_size = ALIGN(me->core_size, 16);
3422 - me->arch.got_offset = me->core_size;
3423 - me->core_size += gots * sizeof(struct got_entry);
3424 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
3425 + me->arch.got_offset = me->core_size_rw;
3426 + me->core_size_rw += gots * sizeof(struct got_entry);
3427
3428 - me->core_size = ALIGN(me->core_size, 16);
3429 - me->arch.fdesc_offset = me->core_size;
3430 - me->core_size += fdescs * sizeof(Elf_Fdesc);
3431 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
3432 + me->arch.fdesc_offset = me->core_size_rw;
3433 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
3434
3435 me->arch.got_max = gots;
3436 me->arch.fdesc_max = fdescs;
3437 @@ -397,7 +419,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3438
3439 BUG_ON(value == 0);
3440
3441 - got = me->module_core + me->arch.got_offset;
3442 + got = me->module_core_rw + me->arch.got_offset;
3443 for (i = 0; got[i].addr; i++)
3444 if (got[i].addr == value)
3445 goto out;
3446 @@ -415,7 +437,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3447 #ifdef CONFIG_64BIT
3448 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3449 {
3450 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
3451 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
3452
3453 if (!value) {
3454 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
3455 @@ -433,7 +455,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3456
3457 /* Create new one */
3458 fdesc->addr = value;
3459 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3460 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3461 return (Elf_Addr)fdesc;
3462 }
3463 #endif /* CONFIG_64BIT */
3464 @@ -845,7 +867,7 @@ register_unwind_table(struct module *me,
3465
3466 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
3467 end = table + sechdrs[me->arch.unwind_section].sh_size;
3468 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3469 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3470
3471 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
3472 me->arch.unwind_section, table, end, gp);
3473 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
3474 index f76c108..8117482 100644
3475 --- a/arch/parisc/kernel/sys_parisc.c
3476 +++ b/arch/parisc/kernel/sys_parisc.c
3477 @@ -43,7 +43,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
3478 /* At this point: (!vma || addr < vma->vm_end). */
3479 if (TASK_SIZE - len < addr)
3480 return -ENOMEM;
3481 - if (!vma || addr + len <= vma->vm_start)
3482 + if (check_heap_stack_gap(vma, addr, len))
3483 return addr;
3484 addr = vma->vm_end;
3485 }
3486 @@ -81,7 +81,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
3487 /* At this point: (!vma || addr < vma->vm_end). */
3488 if (TASK_SIZE - len < addr)
3489 return -ENOMEM;
3490 - if (!vma || addr + len <= vma->vm_start)
3491 + if (check_heap_stack_gap(vma, addr, len))
3492 return addr;
3493 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
3494 if (addr < vma->vm_end) /* handle wraparound */
3495 @@ -100,7 +100,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
3496 if (flags & MAP_FIXED)
3497 return addr;
3498 if (!addr)
3499 - addr = TASK_UNMAPPED_BASE;
3500 + addr = current->mm->mmap_base;
3501
3502 if (filp) {
3503 addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
3504 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
3505 index 45ba99f..8e22c33 100644
3506 --- a/arch/parisc/kernel/traps.c
3507 +++ b/arch/parisc/kernel/traps.c
3508 @@ -732,9 +732,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
3509
3510 down_read(&current->mm->mmap_sem);
3511 vma = find_vma(current->mm,regs->iaoq[0]);
3512 - if (vma && (regs->iaoq[0] >= vma->vm_start)
3513 - && (vma->vm_flags & VM_EXEC)) {
3514 -
3515 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
3516 fault_address = regs->iaoq[0];
3517 fault_space = regs->iasq[0];
3518
3519 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
3520 index 18162ce..94de376 100644
3521 --- a/arch/parisc/mm/fault.c
3522 +++ b/arch/parisc/mm/fault.c
3523 @@ -15,6 +15,7 @@
3524 #include <linux/sched.h>
3525 #include <linux/interrupt.h>
3526 #include <linux/module.h>
3527 +#include <linux/unistd.h>
3528
3529 #include <asm/uaccess.h>
3530 #include <asm/traps.h>
3531 @@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
3532 static unsigned long
3533 parisc_acctyp(unsigned long code, unsigned int inst)
3534 {
3535 - if (code == 6 || code == 16)
3536 + if (code == 6 || code == 7 || code == 16)
3537 return VM_EXEC;
3538
3539 switch (inst & 0xf0000000) {
3540 @@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
3541 }
3542 #endif
3543
3544 +#ifdef CONFIG_PAX_PAGEEXEC
3545 +/*
3546 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
3547 + *
3548 + * returns 1 when task should be killed
3549 + * 2 when rt_sigreturn trampoline was detected
3550 + * 3 when unpatched PLT trampoline was detected
3551 + */
3552 +static int pax_handle_fetch_fault(struct pt_regs *regs)
3553 +{
3554 +
3555 +#ifdef CONFIG_PAX_EMUPLT
3556 + int err;
3557 +
3558 + do { /* PaX: unpatched PLT emulation */
3559 + unsigned int bl, depwi;
3560 +
3561 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
3562 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
3563 +
3564 + if (err)
3565 + break;
3566 +
3567 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
3568 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
3569 +
3570 + err = get_user(ldw, (unsigned int *)addr);
3571 + err |= get_user(bv, (unsigned int *)(addr+4));
3572 + err |= get_user(ldw2, (unsigned int *)(addr+8));
3573 +
3574 + if (err)
3575 + break;
3576 +
3577 + if (ldw == 0x0E801096U &&
3578 + bv == 0xEAC0C000U &&
3579 + ldw2 == 0x0E881095U)
3580 + {
3581 + unsigned int resolver, map;
3582 +
3583 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
3584 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
3585 + if (err)
3586 + break;
3587 +
3588 + regs->gr[20] = instruction_pointer(regs)+8;
3589 + regs->gr[21] = map;
3590 + regs->gr[22] = resolver;
3591 + regs->iaoq[0] = resolver | 3UL;
3592 + regs->iaoq[1] = regs->iaoq[0] + 4;
3593 + return 3;
3594 + }
3595 + }
3596 + } while (0);
3597 +#endif
3598 +
3599 +#ifdef CONFIG_PAX_EMUTRAMP
3600 +
3601 +#ifndef CONFIG_PAX_EMUSIGRT
3602 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
3603 + return 1;
3604 +#endif
3605 +
3606 + do { /* PaX: rt_sigreturn emulation */
3607 + unsigned int ldi1, ldi2, bel, nop;
3608 +
3609 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
3610 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
3611 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
3612 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
3613 +
3614 + if (err)
3615 + break;
3616 +
3617 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
3618 + ldi2 == 0x3414015AU &&
3619 + bel == 0xE4008200U &&
3620 + nop == 0x08000240U)
3621 + {
3622 + regs->gr[25] = (ldi1 & 2) >> 1;
3623 + regs->gr[20] = __NR_rt_sigreturn;
3624 + regs->gr[31] = regs->iaoq[1] + 16;
3625 + regs->sr[0] = regs->iasq[1];
3626 + regs->iaoq[0] = 0x100UL;
3627 + regs->iaoq[1] = regs->iaoq[0] + 4;
3628 + regs->iasq[0] = regs->sr[2];
3629 + regs->iasq[1] = regs->sr[2];
3630 + return 2;
3631 + }
3632 + } while (0);
3633 +#endif
3634 +
3635 + return 1;
3636 +}
3637 +
3638 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3639 +{
3640 + unsigned long i;
3641 +
3642 + printk(KERN_ERR "PAX: bytes at PC: ");
3643 + for (i = 0; i < 5; i++) {
3644 + unsigned int c;
3645 + if (get_user(c, (unsigned int *)pc+i))
3646 + printk(KERN_CONT "???????? ");
3647 + else
3648 + printk(KERN_CONT "%08x ", c);
3649 + }
3650 + printk("\n");
3651 +}
3652 +#endif
3653 +
3654 int fixup_exception(struct pt_regs *regs)
3655 {
3656 const struct exception_table_entry *fix;
3657 @@ -192,8 +303,33 @@ good_area:
3658
3659 acc_type = parisc_acctyp(code,regs->iir);
3660
3661 - if ((vma->vm_flags & acc_type) != acc_type)
3662 + if ((vma->vm_flags & acc_type) != acc_type) {
3663 +
3664 +#ifdef CONFIG_PAX_PAGEEXEC
3665 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
3666 + (address & ~3UL) == instruction_pointer(regs))
3667 + {
3668 + up_read(&mm->mmap_sem);
3669 + switch (pax_handle_fetch_fault(regs)) {
3670 +
3671 +#ifdef CONFIG_PAX_EMUPLT
3672 + case 3:
3673 + return;
3674 +#endif
3675 +
3676 +#ifdef CONFIG_PAX_EMUTRAMP
3677 + case 2:
3678 + return;
3679 +#endif
3680 +
3681 + }
3682 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
3683 + do_group_exit(SIGKILL);
3684 + }
3685 +#endif
3686 +
3687 goto bad_area;
3688 + }
3689
3690 /*
3691 * If for any reason at all we couldn't handle the fault, make
3692 diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
3693 index da29032..f76c24c 100644
3694 --- a/arch/powerpc/include/asm/atomic.h
3695 +++ b/arch/powerpc/include/asm/atomic.h
3696 @@ -522,6 +522,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
3697 return t1;
3698 }
3699
3700 +#define atomic64_read_unchecked(v) atomic64_read(v)
3701 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3702 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3703 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3704 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3705 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3706 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3707 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3708 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3709 +
3710 #endif /* __powerpc64__ */
3711
3712 #endif /* __KERNEL__ */
3713 diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
3714 index 9e495c9..b6878e5 100644
3715 --- a/arch/powerpc/include/asm/cache.h
3716 +++ b/arch/powerpc/include/asm/cache.h
3717 @@ -3,6 +3,7 @@
3718
3719 #ifdef __KERNEL__
3720
3721 +#include <linux/const.h>
3722
3723 /* bytes per L1 cache line */
3724 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
3725 @@ -22,7 +23,7 @@
3726 #define L1_CACHE_SHIFT 7
3727 #endif
3728
3729 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3730 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3731
3732 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3733
3734 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
3735 index 3bf9cca..e7457d0 100644
3736 --- a/arch/powerpc/include/asm/elf.h
3737 +++ b/arch/powerpc/include/asm/elf.h
3738 @@ -178,8 +178,19 @@ typedef elf_fpreg_t elf_vsrreghalf_t32[ELF_NVSRHALFREG];
3739 the loader. We need to make sure that it is out of the way of the program
3740 that it will "exec", and that there is sufficient room for the brk. */
3741
3742 -extern unsigned long randomize_et_dyn(unsigned long base);
3743 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
3744 +#define ELF_ET_DYN_BASE (0x20000000)
3745 +
3746 +#ifdef CONFIG_PAX_ASLR
3747 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
3748 +
3749 +#ifdef __powerpc64__
3750 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
3751 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
3752 +#else
3753 +#define PAX_DELTA_MMAP_LEN 15
3754 +#define PAX_DELTA_STACK_LEN 15
3755 +#endif
3756 +#endif
3757
3758 /*
3759 * Our registers are always unsigned longs, whether we're a 32 bit
3760 @@ -274,9 +285,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
3761 (0x7ff >> (PAGE_SHIFT - 12)) : \
3762 (0x3ffff >> (PAGE_SHIFT - 12)))
3763
3764 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
3765 -#define arch_randomize_brk arch_randomize_brk
3766 -
3767 #endif /* __KERNEL__ */
3768
3769 /*
3770 diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
3771 index 8196e9c..d83a9f3 100644
3772 --- a/arch/powerpc/include/asm/exec.h
3773 +++ b/arch/powerpc/include/asm/exec.h
3774 @@ -4,6 +4,6 @@
3775 #ifndef _ASM_POWERPC_EXEC_H
3776 #define _ASM_POWERPC_EXEC_H
3777
3778 -extern unsigned long arch_align_stack(unsigned long sp);
3779 +#define arch_align_stack(x) ((x) & ~0xfUL)
3780
3781 #endif /* _ASM_POWERPC_EXEC_H */
3782 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
3783 index 5acabbd..7ea14fa 100644
3784 --- a/arch/powerpc/include/asm/kmap_types.h
3785 +++ b/arch/powerpc/include/asm/kmap_types.h
3786 @@ -10,7 +10,7 @@
3787 * 2 of the License, or (at your option) any later version.
3788 */
3789
3790 -#define KM_TYPE_NR 16
3791 +#define KM_TYPE_NR 17
3792
3793 #endif /* __KERNEL__ */
3794 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
3795 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
3796 index d4a7f64..451de1c 100644
3797 --- a/arch/powerpc/include/asm/mman.h
3798 +++ b/arch/powerpc/include/asm/mman.h
3799 @@ -44,7 +44,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
3800 }
3801 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
3802
3803 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
3804 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
3805 {
3806 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
3807 }
3808 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
3809 index f072e97..b436dee 100644
3810 --- a/arch/powerpc/include/asm/page.h
3811 +++ b/arch/powerpc/include/asm/page.h
3812 @@ -220,8 +220,9 @@ extern long long virt_phys_offset;
3813 * and needs to be executable. This means the whole heap ends
3814 * up being executable.
3815 */
3816 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3817 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3818 +#define VM_DATA_DEFAULT_FLAGS32 \
3819 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3820 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3821
3822 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3823 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3824 @@ -249,6 +250,9 @@ extern long long virt_phys_offset;
3825 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
3826 #endif
3827
3828 +#define ktla_ktva(addr) (addr)
3829 +#define ktva_ktla(addr) (addr)
3830 +
3831 /*
3832 * Use the top bit of the higher-level page table entries to indicate whether
3833 * the entries we point to contain hugepages. This works because we know that
3834 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
3835 index fed85e6..da5c71b 100644
3836 --- a/arch/powerpc/include/asm/page_64.h
3837 +++ b/arch/powerpc/include/asm/page_64.h
3838 @@ -146,15 +146,18 @@ do { \
3839 * stack by default, so in the absence of a PT_GNU_STACK program header
3840 * we turn execute permission off.
3841 */
3842 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3843 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3844 +#define VM_STACK_DEFAULT_FLAGS32 \
3845 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3846 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3847
3848 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3849 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3850
3851 +#ifndef CONFIG_PAX_PAGEEXEC
3852 #define VM_STACK_DEFAULT_FLAGS \
3853 (is_32bit_task() ? \
3854 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
3855 +#endif
3856
3857 #include <asm-generic/getorder.h>
3858
3859 diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
3860 index 292725c..f87ae14 100644
3861 --- a/arch/powerpc/include/asm/pgalloc-64.h
3862 +++ b/arch/powerpc/include/asm/pgalloc-64.h
3863 @@ -50,6 +50,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
3864 #ifndef CONFIG_PPC_64K_PAGES
3865
3866 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
3867 +#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
3868
3869 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
3870 {
3871 @@ -67,6 +68,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3872 pud_set(pud, (unsigned long)pmd);
3873 }
3874
3875 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3876 +{
3877 + pud_populate(mm, pud, pmd);
3878 +}
3879 +
3880 #define pmd_populate(mm, pmd, pte_page) \
3881 pmd_populate_kernel(mm, pmd, page_address(pte_page))
3882 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
3883 @@ -76,6 +82,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3884 #else /* CONFIG_PPC_64K_PAGES */
3885
3886 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
3887 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
3888
3889 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
3890 pte_t *pte)
3891 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
3892 index 2e0e411..7899c68 100644
3893 --- a/arch/powerpc/include/asm/pgtable.h
3894 +++ b/arch/powerpc/include/asm/pgtable.h
3895 @@ -2,6 +2,7 @@
3896 #define _ASM_POWERPC_PGTABLE_H
3897 #ifdef __KERNEL__
3898
3899 +#include <linux/const.h>
3900 #ifndef __ASSEMBLY__
3901 #include <asm/processor.h> /* For TASK_SIZE */
3902 #include <asm/mmu.h>
3903 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
3904 index 4aad413..85d86bf 100644
3905 --- a/arch/powerpc/include/asm/pte-hash32.h
3906 +++ b/arch/powerpc/include/asm/pte-hash32.h
3907 @@ -21,6 +21,7 @@
3908 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
3909 #define _PAGE_USER 0x004 /* usermode access allowed */
3910 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
3911 +#define _PAGE_EXEC _PAGE_GUARDED
3912 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
3913 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
3914 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
3915 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
3916 index 6386086..6982225 100644
3917 --- a/arch/powerpc/include/asm/reg.h
3918 +++ b/arch/powerpc/include/asm/reg.h
3919 @@ -212,6 +212,7 @@
3920 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
3921 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
3922 #define DSISR_NOHPTE 0x40000000 /* no translation found */
3923 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
3924 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
3925 #define DSISR_ISSTORE 0x02000000 /* access was a store */
3926 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
3927 diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
3928 index faf9352..ab2ccec 100644
3929 --- a/arch/powerpc/include/asm/thread_info.h
3930 +++ b/arch/powerpc/include/asm/thread_info.h
3931 @@ -97,12 +97,14 @@ static inline struct thread_info *current_thread_info(void)
3932 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
3933 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
3934 #define TIF_SINGLESTEP 8 /* singlestepping active */
3935 -#define TIF_MEMDIE 9 /* is terminating due to OOM killer */
3936 #define TIF_SECCOMP 10 /* secure computing */
3937 #define TIF_RESTOREALL 11 /* Restore all regs (implies NOERROR) */
3938 #define TIF_NOERROR 12 /* Force successful syscall return */
3939 #define TIF_NOTIFY_RESUME 13 /* callback before returning to user */
3940 #define TIF_SYSCALL_TRACEPOINT 15 /* syscall tracepoint instrumentation */
3941 +#define TIF_MEMDIE 16 /* is terminating due to OOM killer */
3942 +/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
3943 +#define TIF_GRSEC_SETXID 9 /* update credentials on syscall entry/exit */
3944
3945 /* as above, but as bit values */
3946 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
3947 @@ -119,8 +121,10 @@ static inline struct thread_info *current_thread_info(void)
3948 #define _TIF_NOERROR (1<<TIF_NOERROR)
3949 #define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME)
3950 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
3951 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
3952 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
3953 - _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT)
3954 + _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
3955 + _TIF_GRSEC_SETXID)
3956
3957 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
3958 _TIF_NOTIFY_RESUME)
3959 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
3960 index 17bb40c..353c98b 100644
3961 --- a/arch/powerpc/include/asm/uaccess.h
3962 +++ b/arch/powerpc/include/asm/uaccess.h
3963 @@ -13,6 +13,8 @@
3964 #define VERIFY_READ 0
3965 #define VERIFY_WRITE 1
3966
3967 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
3968 +
3969 /*
3970 * The fs value determines whether argument validity checking should be
3971 * performed or not. If get_fs() == USER_DS, checking is performed, with
3972 @@ -329,52 +331,6 @@ do { \
3973 extern unsigned long __copy_tofrom_user(void __user *to,
3974 const void __user *from, unsigned long size);
3975
3976 -#ifndef __powerpc64__
3977 -
3978 -static inline unsigned long copy_from_user(void *to,
3979 - const void __user *from, unsigned long n)
3980 -{
3981 - unsigned long over;
3982 -
3983 - if (access_ok(VERIFY_READ, from, n))
3984 - return __copy_tofrom_user((__force void __user *)to, from, n);
3985 - if ((unsigned long)from < TASK_SIZE) {
3986 - over = (unsigned long)from + n - TASK_SIZE;
3987 - return __copy_tofrom_user((__force void __user *)to, from,
3988 - n - over) + over;
3989 - }
3990 - return n;
3991 -}
3992 -
3993 -static inline unsigned long copy_to_user(void __user *to,
3994 - const void *from, unsigned long n)
3995 -{
3996 - unsigned long over;
3997 -
3998 - if (access_ok(VERIFY_WRITE, to, n))
3999 - return __copy_tofrom_user(to, (__force void __user *)from, n);
4000 - if ((unsigned long)to < TASK_SIZE) {
4001 - over = (unsigned long)to + n - TASK_SIZE;
4002 - return __copy_tofrom_user(to, (__force void __user *)from,
4003 - n - over) + over;
4004 - }
4005 - return n;
4006 -}
4007 -
4008 -#else /* __powerpc64__ */
4009 -
4010 -#define __copy_in_user(to, from, size) \
4011 - __copy_tofrom_user((to), (from), (size))
4012 -
4013 -extern unsigned long copy_from_user(void *to, const void __user *from,
4014 - unsigned long n);
4015 -extern unsigned long copy_to_user(void __user *to, const void *from,
4016 - unsigned long n);
4017 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
4018 - unsigned long n);
4019 -
4020 -#endif /* __powerpc64__ */
4021 -
4022 static inline unsigned long __copy_from_user_inatomic(void *to,
4023 const void __user *from, unsigned long n)
4024 {
4025 @@ -398,6 +354,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
4026 if (ret == 0)
4027 return 0;
4028 }
4029 +
4030 + if (!__builtin_constant_p(n))
4031 + check_object_size(to, n, false);
4032 +
4033 return __copy_tofrom_user((__force void __user *)to, from, n);
4034 }
4035
4036 @@ -424,6 +384,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
4037 if (ret == 0)
4038 return 0;
4039 }
4040 +
4041 + if (!__builtin_constant_p(n))
4042 + check_object_size(from, n, true);
4043 +
4044 return __copy_tofrom_user(to, (__force const void __user *)from, n);
4045 }
4046
4047 @@ -441,6 +405,92 @@ static inline unsigned long __copy_to_user(void __user *to,
4048 return __copy_to_user_inatomic(to, from, size);
4049 }
4050
4051 +#ifndef __powerpc64__
4052 +
4053 +static inline unsigned long __must_check copy_from_user(void *to,
4054 + const void __user *from, unsigned long n)
4055 +{
4056 + unsigned long over;
4057 +
4058 + if ((long)n < 0)
4059 + return n;
4060 +
4061 + if (access_ok(VERIFY_READ, from, n)) {
4062 + if (!__builtin_constant_p(n))
4063 + check_object_size(to, n, false);
4064 + return __copy_tofrom_user((__force void __user *)to, from, n);
4065 + }
4066 + if ((unsigned long)from < TASK_SIZE) {
4067 + over = (unsigned long)from + n - TASK_SIZE;
4068 + if (!__builtin_constant_p(n - over))
4069 + check_object_size(to, n - over, false);
4070 + return __copy_tofrom_user((__force void __user *)to, from,
4071 + n - over) + over;
4072 + }
4073 + return n;
4074 +}
4075 +
4076 +static inline unsigned long __must_check copy_to_user(void __user *to,
4077 + const void *from, unsigned long n)
4078 +{
4079 + unsigned long over;
4080 +
4081 + if ((long)n < 0)
4082 + return n;
4083 +
4084 + if (access_ok(VERIFY_WRITE, to, n)) {
4085 + if (!__builtin_constant_p(n))
4086 + check_object_size(from, n, true);
4087 + return __copy_tofrom_user(to, (__force void __user *)from, n);
4088 + }
4089 + if ((unsigned long)to < TASK_SIZE) {
4090 + over = (unsigned long)to + n - TASK_SIZE;
4091 + if (!__builtin_constant_p(n))
4092 + check_object_size(from, n - over, true);
4093 + return __copy_tofrom_user(to, (__force void __user *)from,
4094 + n - over) + over;
4095 + }
4096 + return n;
4097 +}
4098 +
4099 +#else /* __powerpc64__ */
4100 +
4101 +#define __copy_in_user(to, from, size) \
4102 + __copy_tofrom_user((to), (from), (size))
4103 +
4104 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
4105 +{
4106 + if ((long)n < 0 || n > INT_MAX)
4107 + return n;
4108 +
4109 + if (!__builtin_constant_p(n))
4110 + check_object_size(to, n, false);
4111 +
4112 + if (likely(access_ok(VERIFY_READ, from, n)))
4113 + n = __copy_from_user(to, from, n);
4114 + else
4115 + memset(to, 0, n);
4116 + return n;
4117 +}
4118 +
4119 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
4120 +{
4121 + if ((long)n < 0 || n > INT_MAX)
4122 + return n;
4123 +
4124 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
4125 + if (!__builtin_constant_p(n))
4126 + check_object_size(from, n, true);
4127 + n = __copy_to_user(to, from, n);
4128 + }
4129 + return n;
4130 +}
4131 +
4132 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
4133 + unsigned long n);
4134 +
4135 +#endif /* __powerpc64__ */
4136 +
4137 extern unsigned long __clear_user(void __user *addr, unsigned long size);
4138
4139 static inline unsigned long clear_user(void __user *addr, unsigned long size)
4140 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
4141 index 98be7f0..8ef62de 100644
4142 --- a/arch/powerpc/kernel/exceptions-64e.S
4143 +++ b/arch/powerpc/kernel/exceptions-64e.S
4144 @@ -661,6 +661,7 @@ storage_fault_common:
4145 std r14,_DAR(r1)
4146 std r15,_DSISR(r1)
4147 addi r3,r1,STACK_FRAME_OVERHEAD
4148 + bl .save_nvgprs
4149 mr r4,r14
4150 mr r5,r15
4151 ld r14,PACA_EXGEN+EX_R14(r13)
4152 @@ -669,8 +670,7 @@ storage_fault_common:
4153 cmpdi r3,0
4154 bne- 1f
4155 b .ret_from_except_lite
4156 -1: bl .save_nvgprs
4157 - mr r5,r3
4158 +1: mr r5,r3
4159 addi r3,r1,STACK_FRAME_OVERHEAD
4160 ld r4,_DAR(r1)
4161 bl .bad_page_fault
4162 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
4163 index 39aa97d..dc916ee 100644
4164 --- a/arch/powerpc/kernel/exceptions-64s.S
4165 +++ b/arch/powerpc/kernel/exceptions-64s.S
4166 @@ -890,10 +890,10 @@ handle_page_fault:
4167 11: ld r4,_DAR(r1)
4168 ld r5,_DSISR(r1)
4169 addi r3,r1,STACK_FRAME_OVERHEAD
4170 + bl .save_nvgprs
4171 bl .do_page_fault
4172 cmpdi r3,0
4173 beq+ 12f
4174 - bl .save_nvgprs
4175 mr r5,r3
4176 addi r3,r1,STACK_FRAME_OVERHEAD
4177 lwz r4,_DAR(r1)
4178 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
4179 index 2e3200c..72095ce 100644
4180 --- a/arch/powerpc/kernel/module_32.c
4181 +++ b/arch/powerpc/kernel/module_32.c
4182 @@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
4183 me->arch.core_plt_section = i;
4184 }
4185 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
4186 - printk("Module doesn't contain .plt or .init.plt sections.\n");
4187 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
4188 return -ENOEXEC;
4189 }
4190
4191 @@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
4192
4193 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
4194 /* Init, or core PLT? */
4195 - if (location >= mod->module_core
4196 - && location < mod->module_core + mod->core_size)
4197 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
4198 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
4199 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
4200 - else
4201 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
4202 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
4203 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
4204 + else {
4205 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
4206 + return ~0UL;
4207 + }
4208
4209 /* Find this entry, or if that fails, the next avail. entry */
4210 while (entry->jump[0]) {
4211 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
4212 index 1a1f2dd..f4d1bb4 100644
4213 --- a/arch/powerpc/kernel/process.c
4214 +++ b/arch/powerpc/kernel/process.c
4215 @@ -681,8 +681,8 @@ void show_regs(struct pt_regs * regs)
4216 * Lookup NIP late so we have the best change of getting the
4217 * above info out without failing
4218 */
4219 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
4220 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
4221 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
4222 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
4223 #endif
4224 show_stack(current, (unsigned long *) regs->gpr[1]);
4225 if (!user_mode(regs))
4226 @@ -1181,10 +1181,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
4227 newsp = stack[0];
4228 ip = stack[STACK_FRAME_LR_SAVE];
4229 if (!firstframe || ip != lr) {
4230 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
4231 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
4232 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
4233 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
4234 - printk(" (%pS)",
4235 + printk(" (%pA)",
4236 (void *)current->ret_stack[curr_frame].ret);
4237 curr_frame--;
4238 }
4239 @@ -1204,7 +1204,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
4240 struct pt_regs *regs = (struct pt_regs *)
4241 (sp + STACK_FRAME_OVERHEAD);
4242 lr = regs->link;
4243 - printk("--- Exception: %lx at %pS\n LR = %pS\n",
4244 + printk("--- Exception: %lx at %pA\n LR = %pA\n",
4245 regs->trap, (void *)regs->nip, (void *)lr);
4246 firstframe = 1;
4247 }
4248 @@ -1246,58 +1246,3 @@ void __ppc64_runlatch_off(void)
4249 mtspr(SPRN_CTRLT, ctrl);
4250 }
4251 #endif /* CONFIG_PPC64 */
4252 -
4253 -unsigned long arch_align_stack(unsigned long sp)
4254 -{
4255 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4256 - sp -= get_random_int() & ~PAGE_MASK;
4257 - return sp & ~0xf;
4258 -}
4259 -
4260 -static inline unsigned long brk_rnd(void)
4261 -{
4262 - unsigned long rnd = 0;
4263 -
4264 - /* 8MB for 32bit, 1GB for 64bit */
4265 - if (is_32bit_task())
4266 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
4267 - else
4268 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
4269 -
4270 - return rnd << PAGE_SHIFT;
4271 -}
4272 -
4273 -unsigned long arch_randomize_brk(struct mm_struct *mm)
4274 -{
4275 - unsigned long base = mm->brk;
4276 - unsigned long ret;
4277 -
4278 -#ifdef CONFIG_PPC_STD_MMU_64
4279 - /*
4280 - * If we are using 1TB segments and we are allowed to randomise
4281 - * the heap, we can put it above 1TB so it is backed by a 1TB
4282 - * segment. Otherwise the heap will be in the bottom 1TB
4283 - * which always uses 256MB segments and this may result in a
4284 - * performance penalty.
4285 - */
4286 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
4287 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
4288 -#endif
4289 -
4290 - ret = PAGE_ALIGN(base + brk_rnd());
4291 -
4292 - if (ret < mm->brk)
4293 - return mm->brk;
4294 -
4295 - return ret;
4296 -}
4297 -
4298 -unsigned long randomize_et_dyn(unsigned long base)
4299 -{
4300 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4301 -
4302 - if (ret < base)
4303 - return base;
4304 -
4305 - return ret;
4306 -}
4307 diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
4308 index c10fc28..c4ef063 100644
4309 --- a/arch/powerpc/kernel/ptrace.c
4310 +++ b/arch/powerpc/kernel/ptrace.c
4311 @@ -1660,6 +1660,10 @@ long arch_ptrace(struct task_struct *child, long request,
4312 return ret;
4313 }
4314
4315 +#ifdef CONFIG_GRKERNSEC_SETXID
4316 +extern void gr_delayed_cred_worker(void);
4317 +#endif
4318 +
4319 /*
4320 * We must return the syscall number to actually look up in the table.
4321 * This can be -1L to skip running any syscall at all.
4322 @@ -1670,6 +1674,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
4323
4324 secure_computing_strict(regs->gpr[0]);
4325
4326 +#ifdef CONFIG_GRKERNSEC_SETXID
4327 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
4328 + gr_delayed_cred_worker();
4329 +#endif
4330 +
4331 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
4332 tracehook_report_syscall_entry(regs))
4333 /*
4334 @@ -1704,6 +1713,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
4335 {
4336 int step;
4337
4338 +#ifdef CONFIG_GRKERNSEC_SETXID
4339 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
4340 + gr_delayed_cred_worker();
4341 +#endif
4342 +
4343 audit_syscall_exit(regs);
4344
4345 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
4346 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
4347 index 8b4c049..dcd6ef3 100644
4348 --- a/arch/powerpc/kernel/signal_32.c
4349 +++ b/arch/powerpc/kernel/signal_32.c
4350 @@ -852,7 +852,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
4351 /* Save user registers on the stack */
4352 frame = &rt_sf->uc.uc_mcontext;
4353 addr = frame;
4354 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
4355 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4356 if (save_user_regs(regs, frame, 0, 1))
4357 goto badframe;
4358 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
4359 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
4360 index d183f87..1867f1a 100644
4361 --- a/arch/powerpc/kernel/signal_64.c
4362 +++ b/arch/powerpc/kernel/signal_64.c
4363 @@ -430,7 +430,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
4364 current->thread.fpscr.val = 0;
4365
4366 /* Set up to return from userspace. */
4367 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
4368 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4369 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
4370 } else {
4371 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
4372 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
4373 index ae0843f..f16372c 100644
4374 --- a/arch/powerpc/kernel/traps.c
4375 +++ b/arch/powerpc/kernel/traps.c
4376 @@ -133,6 +133,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
4377 return flags;
4378 }
4379
4380 +extern void gr_handle_kernel_exploit(void);
4381 +
4382 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
4383 int signr)
4384 {
4385 @@ -182,6 +184,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
4386 panic("Fatal exception in interrupt");
4387 if (panic_on_oops)
4388 panic("Fatal exception");
4389 +
4390 + gr_handle_kernel_exploit();
4391 +
4392 do_exit(signr);
4393 }
4394
4395 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
4396 index b67db22..38825d2 100644
4397 --- a/arch/powerpc/kernel/vdso.c
4398 +++ b/arch/powerpc/kernel/vdso.c
4399 @@ -34,6 +34,7 @@
4400 #include <asm/firmware.h>
4401 #include <asm/vdso.h>
4402 #include <asm/vdso_datapage.h>
4403 +#include <asm/mman.h>
4404
4405 #include "setup.h"
4406
4407 @@ -218,7 +219,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
4408 vdso_base = VDSO32_MBASE;
4409 #endif
4410
4411 - current->mm->context.vdso_base = 0;
4412 + current->mm->context.vdso_base = ~0UL;
4413
4414 /* vDSO has a problem and was disabled, just don't "enable" it for the
4415 * process
4416 @@ -238,7 +239,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
4417 vdso_base = get_unmapped_area(NULL, vdso_base,
4418 (vdso_pages << PAGE_SHIFT) +
4419 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
4420 - 0, 0);
4421 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
4422 if (IS_ERR_VALUE(vdso_base)) {
4423 rc = vdso_base;
4424 goto fail_mmapsem;
4425 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
4426 index 5eea6f3..5d10396 100644
4427 --- a/arch/powerpc/lib/usercopy_64.c
4428 +++ b/arch/powerpc/lib/usercopy_64.c
4429 @@ -9,22 +9,6 @@
4430 #include <linux/module.h>
4431 #include <asm/uaccess.h>
4432
4433 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
4434 -{
4435 - if (likely(access_ok(VERIFY_READ, from, n)))
4436 - n = __copy_from_user(to, from, n);
4437 - else
4438 - memset(to, 0, n);
4439 - return n;
4440 -}
4441 -
4442 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
4443 -{
4444 - if (likely(access_ok(VERIFY_WRITE, to, n)))
4445 - n = __copy_to_user(to, from, n);
4446 - return n;
4447 -}
4448 -
4449 unsigned long copy_in_user(void __user *to, const void __user *from,
4450 unsigned long n)
4451 {
4452 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
4453 return n;
4454 }
4455
4456 -EXPORT_SYMBOL(copy_from_user);
4457 -EXPORT_SYMBOL(copy_to_user);
4458 EXPORT_SYMBOL(copy_in_user);
4459
4460 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
4461 index 08ffcf5..a0ab912 100644
4462 --- a/arch/powerpc/mm/fault.c
4463 +++ b/arch/powerpc/mm/fault.c
4464 @@ -32,6 +32,10 @@
4465 #include <linux/perf_event.h>
4466 #include <linux/magic.h>
4467 #include <linux/ratelimit.h>
4468 +#include <linux/slab.h>
4469 +#include <linux/pagemap.h>
4470 +#include <linux/compiler.h>
4471 +#include <linux/unistd.h>
4472
4473 #include <asm/firmware.h>
4474 #include <asm/page.h>
4475 @@ -68,6 +72,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
4476 }
4477 #endif
4478
4479 +#ifdef CONFIG_PAX_PAGEEXEC
4480 +/*
4481 + * PaX: decide what to do with offenders (regs->nip = fault address)
4482 + *
4483 + * returns 1 when task should be killed
4484 + */
4485 +static int pax_handle_fetch_fault(struct pt_regs *regs)
4486 +{
4487 + return 1;
4488 +}
4489 +
4490 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4491 +{
4492 + unsigned long i;
4493 +
4494 + printk(KERN_ERR "PAX: bytes at PC: ");
4495 + for (i = 0; i < 5; i++) {
4496 + unsigned int c;
4497 + if (get_user(c, (unsigned int __user *)pc+i))
4498 + printk(KERN_CONT "???????? ");
4499 + else
4500 + printk(KERN_CONT "%08x ", c);
4501 + }
4502 + printk("\n");
4503 +}
4504 +#endif
4505 +
4506 /*
4507 * Check whether the instruction at regs->nip is a store using
4508 * an update addressing form which will update r1.
4509 @@ -215,7 +246,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
4510 * indicate errors in DSISR but can validly be set in SRR1.
4511 */
4512 if (trap == 0x400)
4513 - error_code &= 0x48200000;
4514 + error_code &= 0x58200000;
4515 else
4516 is_write = error_code & DSISR_ISSTORE;
4517 #else
4518 @@ -366,7 +397,7 @@ good_area:
4519 * "undefined". Of those that can be set, this is the only
4520 * one which seems bad.
4521 */
4522 - if (error_code & 0x10000000)
4523 + if (error_code & DSISR_GUARDED)
4524 /* Guarded storage error. */
4525 goto bad_area;
4526 #endif /* CONFIG_8xx */
4527 @@ -381,7 +412,7 @@ good_area:
4528 * processors use the same I/D cache coherency mechanism
4529 * as embedded.
4530 */
4531 - if (error_code & DSISR_PROTFAULT)
4532 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
4533 goto bad_area;
4534 #endif /* CONFIG_PPC_STD_MMU */
4535
4536 @@ -463,6 +494,23 @@ bad_area:
4537 bad_area_nosemaphore:
4538 /* User mode accesses cause a SIGSEGV */
4539 if (user_mode(regs)) {
4540 +
4541 +#ifdef CONFIG_PAX_PAGEEXEC
4542 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4543 +#ifdef CONFIG_PPC_STD_MMU
4544 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
4545 +#else
4546 + if (is_exec && regs->nip == address) {
4547 +#endif
4548 + switch (pax_handle_fetch_fault(regs)) {
4549 + }
4550 +
4551 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
4552 + do_group_exit(SIGKILL);
4553 + }
4554 + }
4555 +#endif
4556 +
4557 _exception(SIGSEGV, regs, code, address);
4558 return 0;
4559 }
4560 diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
4561 index 67a42ed..1c7210c 100644
4562 --- a/arch/powerpc/mm/mmap_64.c
4563 +++ b/arch/powerpc/mm/mmap_64.c
4564 @@ -91,10 +91,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4565 */
4566 if (mmap_is_legacy()) {
4567 mm->mmap_base = TASK_UNMAPPED_BASE;
4568 +
4569 +#ifdef CONFIG_PAX_RANDMMAP
4570 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4571 + mm->mmap_base += mm->delta_mmap;
4572 +#endif
4573 +
4574 mm->get_unmapped_area = arch_get_unmapped_area;
4575 mm->unmap_area = arch_unmap_area;
4576 } else {
4577 mm->mmap_base = mmap_base();
4578 +
4579 +#ifdef CONFIG_PAX_RANDMMAP
4580 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4581 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4582 +#endif
4583 +
4584 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4585 mm->unmap_area = arch_unmap_area_topdown;
4586 }
4587 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
4588 index 73709f7..6b90313 100644
4589 --- a/arch/powerpc/mm/slice.c
4590 +++ b/arch/powerpc/mm/slice.c
4591 @@ -98,7 +98,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
4592 if ((mm->task_size - len) < addr)
4593 return 0;
4594 vma = find_vma(mm, addr);
4595 - return (!vma || (addr + len) <= vma->vm_start);
4596 + return check_heap_stack_gap(vma, addr, len);
4597 }
4598
4599 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
4600 @@ -256,7 +256,7 @@ full_search:
4601 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
4602 continue;
4603 }
4604 - if (!vma || addr + len <= vma->vm_start) {
4605 + if (check_heap_stack_gap(vma, addr, len)) {
4606 /*
4607 * Remember the place where we stopped the search:
4608 */
4609 @@ -313,10 +313,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4610 }
4611 }
4612
4613 - addr = mm->mmap_base;
4614 - while (addr > len) {
4615 + if (mm->mmap_base < len)
4616 + addr = -ENOMEM;
4617 + else
4618 + addr = mm->mmap_base - len;
4619 +
4620 + while (!IS_ERR_VALUE(addr)) {
4621 /* Go down by chunk size */
4622 - addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
4623 + addr = _ALIGN_DOWN(addr, 1ul << pshift);
4624
4625 /* Check for hit with different page size */
4626 mask = slice_range_to_mask(addr, len);
4627 @@ -336,7 +340,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4628 * return with success:
4629 */
4630 vma = find_vma(mm, addr);
4631 - if (!vma || (addr + len) <= vma->vm_start) {
4632 + if (check_heap_stack_gap(vma, addr, len)) {
4633 /* remember the address as a hint for next time */
4634 if (use_cache)
4635 mm->free_area_cache = addr;
4636 @@ -348,7 +352,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4637 mm->cached_hole_size = vma->vm_start - addr;
4638
4639 /* try just below the current vma->vm_start */
4640 - addr = vma->vm_start;
4641 + addr = skip_heap_stack_gap(vma, len);
4642 }
4643
4644 /*
4645 @@ -426,6 +430,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
4646 if (fixed && addr > (mm->task_size - len))
4647 return -EINVAL;
4648
4649 +#ifdef CONFIG_PAX_RANDMMAP
4650 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
4651 + addr = 0;
4652 +#endif
4653 +
4654 /* If hint, make sure it matches our alignment restrictions */
4655 if (!fixed && addr) {
4656 addr = _ALIGN_UP(addr, 1ul << pshift);
4657 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
4658 index c797832..ce575c8 100644
4659 --- a/arch/s390/include/asm/atomic.h
4660 +++ b/arch/s390/include/asm/atomic.h
4661 @@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
4662 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
4663 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
4664
4665 +#define atomic64_read_unchecked(v) atomic64_read(v)
4666 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4667 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4668 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4669 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4670 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4671 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4672 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4673 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4674 +
4675 #define smp_mb__before_atomic_dec() smp_mb()
4676 #define smp_mb__after_atomic_dec() smp_mb()
4677 #define smp_mb__before_atomic_inc() smp_mb()
4678 diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
4679 index 4d7ccac..d03d0ad 100644
4680 --- a/arch/s390/include/asm/cache.h
4681 +++ b/arch/s390/include/asm/cache.h
4682 @@ -9,8 +9,10 @@
4683 #ifndef __ARCH_S390_CACHE_H
4684 #define __ARCH_S390_CACHE_H
4685
4686 -#define L1_CACHE_BYTES 256
4687 +#include <linux/const.h>
4688 +
4689 #define L1_CACHE_SHIFT 8
4690 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4691 #define NET_SKB_PAD 32
4692
4693 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4694 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
4695 index 9b94a16..63d4034 100644
4696 --- a/arch/s390/include/asm/elf.h
4697 +++ b/arch/s390/include/asm/elf.h
4698 @@ -159,8 +159,14 @@ extern unsigned int vdso_enabled;
4699 the loader. We need to make sure that it is out of the way of the program
4700 that it will "exec", and that there is sufficient room for the brk. */
4701
4702 -extern unsigned long randomize_et_dyn(unsigned long base);
4703 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
4704 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
4705 +
4706 +#ifdef CONFIG_PAX_ASLR
4707 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
4708 +
4709 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4710 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4711 +#endif
4712
4713 /* This yields a mask that user programs can use to figure out what
4714 instruction set this CPU supports. */
4715 @@ -209,7 +215,4 @@ struct linux_binprm;
4716 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
4717 int arch_setup_additional_pages(struct linux_binprm *, int);
4718
4719 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
4720 -#define arch_randomize_brk arch_randomize_brk
4721 -
4722 #endif
4723 diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
4724 index c4a93d6..4d2a9b4 100644
4725 --- a/arch/s390/include/asm/exec.h
4726 +++ b/arch/s390/include/asm/exec.h
4727 @@ -7,6 +7,6 @@
4728 #ifndef __ASM_EXEC_H
4729 #define __ASM_EXEC_H
4730
4731 -extern unsigned long arch_align_stack(unsigned long sp);
4732 +#define arch_align_stack(x) ((x) & ~0xfUL)
4733
4734 #endif /* __ASM_EXEC_H */
4735 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
4736 index a8ab18b..75ddbf0 100644
4737 --- a/arch/s390/include/asm/uaccess.h
4738 +++ b/arch/s390/include/asm/uaccess.h
4739 @@ -239,6 +239,10 @@ static inline unsigned long __must_check
4740 copy_to_user(void __user *to, const void *from, unsigned long n)
4741 {
4742 might_fault();
4743 +
4744 + if ((long)n < 0)
4745 + return n;
4746 +
4747 if (access_ok(VERIFY_WRITE, to, n))
4748 n = __copy_to_user(to, from, n);
4749 return n;
4750 @@ -264,6 +268,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
4751 static inline unsigned long __must_check
4752 __copy_from_user(void *to, const void __user *from, unsigned long n)
4753 {
4754 + if ((long)n < 0)
4755 + return n;
4756 +
4757 if (__builtin_constant_p(n) && (n <= 256))
4758 return uaccess.copy_from_user_small(n, from, to);
4759 else
4760 @@ -295,10 +302,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
4761 static inline unsigned long __must_check
4762 copy_from_user(void *to, const void __user *from, unsigned long n)
4763 {
4764 - unsigned int sz = __compiletime_object_size(to);
4765 + size_t sz = __compiletime_object_size(to);
4766
4767 might_fault();
4768 - if (unlikely(sz != -1 && sz < n)) {
4769 +
4770 + if ((long)n < 0)
4771 + return n;
4772 +
4773 + if (unlikely(sz != (size_t)-1 && sz < n)) {
4774 copy_from_user_overflow();
4775 return n;
4776 }
4777 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
4778 index 46412b1..e32874f 100644
4779 --- a/arch/s390/kernel/module.c
4780 +++ b/arch/s390/kernel/module.c
4781 @@ -160,11 +160,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
4782
4783 /* Increase core size by size of got & plt and set start
4784 offsets for got and plt. */
4785 - me->core_size = ALIGN(me->core_size, 4);
4786 - me->arch.got_offset = me->core_size;
4787 - me->core_size += me->arch.got_size;
4788 - me->arch.plt_offset = me->core_size;
4789 - me->core_size += me->arch.plt_size;
4790 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
4791 + me->arch.got_offset = me->core_size_rw;
4792 + me->core_size_rw += me->arch.got_size;
4793 + me->arch.plt_offset = me->core_size_rx;
4794 + me->core_size_rx += me->arch.plt_size;
4795 return 0;
4796 }
4797
4798 @@ -241,7 +241,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4799 if (info->got_initialized == 0) {
4800 Elf_Addr *gotent;
4801
4802 - gotent = me->module_core + me->arch.got_offset +
4803 + gotent = me->module_core_rw + me->arch.got_offset +
4804 info->got_offset;
4805 *gotent = val;
4806 info->got_initialized = 1;
4807 @@ -265,7 +265,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4808 else if (r_type == R_390_GOTENT ||
4809 r_type == R_390_GOTPLTENT)
4810 *(unsigned int *) loc =
4811 - (val + (Elf_Addr) me->module_core - loc) >> 1;
4812 + (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
4813 else if (r_type == R_390_GOT64 ||
4814 r_type == R_390_GOTPLT64)
4815 *(unsigned long *) loc = val;
4816 @@ -279,7 +279,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4817 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
4818 if (info->plt_initialized == 0) {
4819 unsigned int *ip;
4820 - ip = me->module_core + me->arch.plt_offset +
4821 + ip = me->module_core_rx + me->arch.plt_offset +
4822 info->plt_offset;
4823 #ifndef CONFIG_64BIT
4824 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
4825 @@ -304,7 +304,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4826 val - loc + 0xffffUL < 0x1ffffeUL) ||
4827 (r_type == R_390_PLT32DBL &&
4828 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
4829 - val = (Elf_Addr) me->module_core +
4830 + val = (Elf_Addr) me->module_core_rx +
4831 me->arch.plt_offset +
4832 info->plt_offset;
4833 val += rela->r_addend - loc;
4834 @@ -326,7 +326,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4835 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
4836 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
4837 val = val + rela->r_addend -
4838 - ((Elf_Addr) me->module_core + me->arch.got_offset);
4839 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
4840 if (r_type == R_390_GOTOFF16)
4841 *(unsigned short *) loc = val;
4842 else if (r_type == R_390_GOTOFF32)
4843 @@ -336,7 +336,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4844 break;
4845 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
4846 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
4847 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
4848 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
4849 rela->r_addend - loc;
4850 if (r_type == R_390_GOTPC)
4851 *(unsigned int *) loc = val;
4852 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
4853 index 7331753..dd71de4 100644
4854 --- a/arch/s390/kernel/process.c
4855 +++ b/arch/s390/kernel/process.c
4856 @@ -316,39 +316,3 @@ unsigned long get_wchan(struct task_struct *p)
4857 }
4858 return 0;
4859 }
4860 -
4861 -unsigned long arch_align_stack(unsigned long sp)
4862 -{
4863 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4864 - sp -= get_random_int() & ~PAGE_MASK;
4865 - return sp & ~0xf;
4866 -}
4867 -
4868 -static inline unsigned long brk_rnd(void)
4869 -{
4870 - /* 8MB for 32bit, 1GB for 64bit */
4871 - if (is_32bit_task())
4872 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
4873 - else
4874 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
4875 -}
4876 -
4877 -unsigned long arch_randomize_brk(struct mm_struct *mm)
4878 -{
4879 - unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
4880 -
4881 - if (ret < mm->brk)
4882 - return mm->brk;
4883 - return ret;
4884 -}
4885 -
4886 -unsigned long randomize_et_dyn(unsigned long base)
4887 -{
4888 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4889 -
4890 - if (!(current->flags & PF_RANDOMIZE))
4891 - return base;
4892 - if (ret < base)
4893 - return base;
4894 - return ret;
4895 -}
4896 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
4897 index c59a5ef..3fae59c 100644
4898 --- a/arch/s390/mm/mmap.c
4899 +++ b/arch/s390/mm/mmap.c
4900 @@ -90,10 +90,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4901 */
4902 if (mmap_is_legacy()) {
4903 mm->mmap_base = TASK_UNMAPPED_BASE;
4904 +
4905 +#ifdef CONFIG_PAX_RANDMMAP
4906 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4907 + mm->mmap_base += mm->delta_mmap;
4908 +#endif
4909 +
4910 mm->get_unmapped_area = arch_get_unmapped_area;
4911 mm->unmap_area = arch_unmap_area;
4912 } else {
4913 mm->mmap_base = mmap_base();
4914 +
4915 +#ifdef CONFIG_PAX_RANDMMAP
4916 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4917 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4918 +#endif
4919 +
4920 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4921 mm->unmap_area = arch_unmap_area_topdown;
4922 }
4923 @@ -172,10 +184,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4924 */
4925 if (mmap_is_legacy()) {
4926 mm->mmap_base = TASK_UNMAPPED_BASE;
4927 +
4928 +#ifdef CONFIG_PAX_RANDMMAP
4929 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4930 + mm->mmap_base += mm->delta_mmap;
4931 +#endif
4932 +
4933 mm->get_unmapped_area = s390_get_unmapped_area;
4934 mm->unmap_area = arch_unmap_area;
4935 } else {
4936 mm->mmap_base = mmap_base();
4937 +
4938 +#ifdef CONFIG_PAX_RANDMMAP
4939 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4940 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4941 +#endif
4942 +
4943 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
4944 mm->unmap_area = arch_unmap_area_topdown;
4945 }
4946 diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
4947 index ae3d59f..f65f075 100644
4948 --- a/arch/score/include/asm/cache.h
4949 +++ b/arch/score/include/asm/cache.h
4950 @@ -1,7 +1,9 @@
4951 #ifndef _ASM_SCORE_CACHE_H
4952 #define _ASM_SCORE_CACHE_H
4953
4954 +#include <linux/const.h>
4955 +
4956 #define L1_CACHE_SHIFT 4
4957 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4958 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4959
4960 #endif /* _ASM_SCORE_CACHE_H */
4961 diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
4962 index f9f3cd5..58ff438 100644
4963 --- a/arch/score/include/asm/exec.h
4964 +++ b/arch/score/include/asm/exec.h
4965 @@ -1,6 +1,6 @@
4966 #ifndef _ASM_SCORE_EXEC_H
4967 #define _ASM_SCORE_EXEC_H
4968
4969 -extern unsigned long arch_align_stack(unsigned long sp);
4970 +#define arch_align_stack(x) (x)
4971
4972 #endif /* _ASM_SCORE_EXEC_H */
4973 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
4974 index 637970c..0b6556b 100644
4975 --- a/arch/score/kernel/process.c
4976 +++ b/arch/score/kernel/process.c
4977 @@ -161,8 +161,3 @@ unsigned long get_wchan(struct task_struct *task)
4978
4979 return task_pt_regs(task)->cp0_epc;
4980 }
4981 -
4982 -unsigned long arch_align_stack(unsigned long sp)
4983 -{
4984 - return sp;
4985 -}
4986 diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
4987 index ef9e555..331bd29 100644
4988 --- a/arch/sh/include/asm/cache.h
4989 +++ b/arch/sh/include/asm/cache.h
4990 @@ -9,10 +9,11 @@
4991 #define __ASM_SH_CACHE_H
4992 #ifdef __KERNEL__
4993
4994 +#include <linux/const.h>
4995 #include <linux/init.h>
4996 #include <cpu/cache.h>
4997
4998 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4999 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5000
5001 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
5002
5003 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
5004 index afeb710..d1d1289 100644
5005 --- a/arch/sh/mm/mmap.c
5006 +++ b/arch/sh/mm/mmap.c
5007 @@ -74,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
5008 addr = PAGE_ALIGN(addr);
5009
5010 vma = find_vma(mm, addr);
5011 - if (TASK_SIZE - len >= addr &&
5012 - (!vma || addr + len <= vma->vm_start))
5013 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
5014 return addr;
5015 }
5016
5017 @@ -106,7 +105,7 @@ full_search:
5018 }
5019 return -ENOMEM;
5020 }
5021 - if (likely(!vma || addr + len <= vma->vm_start)) {
5022 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5023 /*
5024 * Remember the place where we stopped the search:
5025 */
5026 @@ -157,8 +156,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5027 addr = PAGE_ALIGN(addr);
5028
5029 vma = find_vma(mm, addr);
5030 - if (TASK_SIZE - len >= addr &&
5031 - (!vma || addr + len <= vma->vm_start))
5032 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
5033 return addr;
5034 }
5035
5036 @@ -179,7 +177,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5037 /* make sure it can fit in the remaining address space */
5038 if (likely(addr > len)) {
5039 vma = find_vma(mm, addr-len);
5040 - if (!vma || addr <= vma->vm_start) {
5041 + if (check_heap_stack_gap(vma, addr - len, len)) {
5042 /* remember the address as a hint for next time */
5043 return (mm->free_area_cache = addr-len);
5044 }
5045 @@ -188,18 +186,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5046 if (unlikely(mm->mmap_base < len))
5047 goto bottomup;
5048
5049 - addr = mm->mmap_base-len;
5050 - if (do_colour_align)
5051 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5052 + addr = mm->mmap_base - len;
5053
5054 do {
5055 + if (do_colour_align)
5056 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5057 /*
5058 * Lookup failure means no vma is above this address,
5059 * else if new region fits below vma->vm_start,
5060 * return with success:
5061 */
5062 vma = find_vma(mm, addr);
5063 - if (likely(!vma || addr+len <= vma->vm_start)) {
5064 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5065 /* remember the address as a hint for next time */
5066 return (mm->free_area_cache = addr);
5067 }
5068 @@ -209,10 +207,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5069 mm->cached_hole_size = vma->vm_start - addr;
5070
5071 /* try just below the current vma->vm_start */
5072 - addr = vma->vm_start-len;
5073 - if (do_colour_align)
5074 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5075 - } while (likely(len < vma->vm_start));
5076 + addr = skip_heap_stack_gap(vma, len);
5077 + } while (!IS_ERR_VALUE(addr));
5078
5079 bottomup:
5080 /*
5081 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
5082 index ce35a1c..2e7b8f9 100644
5083 --- a/arch/sparc/include/asm/atomic_64.h
5084 +++ b/arch/sparc/include/asm/atomic_64.h
5085 @@ -14,18 +14,40 @@
5086 #define ATOMIC64_INIT(i) { (i) }
5087
5088 #define atomic_read(v) (*(volatile int *)&(v)->counter)
5089 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5090 +{
5091 + return v->counter;
5092 +}
5093 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
5094 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
5095 +{
5096 + return v->counter;
5097 +}
5098
5099 #define atomic_set(v, i) (((v)->counter) = i)
5100 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5101 +{
5102 + v->counter = i;
5103 +}
5104 #define atomic64_set(v, i) (((v)->counter) = i)
5105 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
5106 +{
5107 + v->counter = i;
5108 +}
5109
5110 extern void atomic_add(int, atomic_t *);
5111 +extern void atomic_add_unchecked(int, atomic_unchecked_t *);
5112 extern void atomic64_add(long, atomic64_t *);
5113 +extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
5114 extern void atomic_sub(int, atomic_t *);
5115 +extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
5116 extern void atomic64_sub(long, atomic64_t *);
5117 +extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
5118
5119 extern int atomic_add_ret(int, atomic_t *);
5120 +extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
5121 extern long atomic64_add_ret(long, atomic64_t *);
5122 +extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
5123 extern int atomic_sub_ret(int, atomic_t *);
5124 extern long atomic64_sub_ret(long, atomic64_t *);
5125
5126 @@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5127 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
5128
5129 #define atomic_inc_return(v) atomic_add_ret(1, v)
5130 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5131 +{
5132 + return atomic_add_ret_unchecked(1, v);
5133 +}
5134 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
5135 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
5136 +{
5137 + return atomic64_add_ret_unchecked(1, v);
5138 +}
5139
5140 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
5141 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
5142
5143 #define atomic_add_return(i, v) atomic_add_ret(i, v)
5144 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5145 +{
5146 + return atomic_add_ret_unchecked(i, v);
5147 +}
5148 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
5149 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
5150 +{
5151 + return atomic64_add_ret_unchecked(i, v);
5152 +}
5153
5154 /*
5155 * atomic_inc_and_test - increment and test
5156 @@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5157 * other cases.
5158 */
5159 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5160 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
5161 +{
5162 + return atomic_inc_return_unchecked(v) == 0;
5163 +}
5164 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
5165
5166 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
5167 @@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5168 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
5169
5170 #define atomic_inc(v) atomic_add(1, v)
5171 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
5172 +{
5173 + atomic_add_unchecked(1, v);
5174 +}
5175 #define atomic64_inc(v) atomic64_add(1, v)
5176 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
5177 +{
5178 + atomic64_add_unchecked(1, v);
5179 +}
5180
5181 #define atomic_dec(v) atomic_sub(1, v)
5182 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
5183 +{
5184 + atomic_sub_unchecked(1, v);
5185 +}
5186 #define atomic64_dec(v) atomic64_sub(1, v)
5187 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
5188 +{
5189 + atomic64_sub_unchecked(1, v);
5190 +}
5191
5192 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
5193 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
5194
5195 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5196 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
5197 +{
5198 + return cmpxchg(&v->counter, old, new);
5199 +}
5200 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
5201 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5202 +{
5203 + return xchg(&v->counter, new);
5204 +}
5205
5206 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
5207 {
5208 - int c, old;
5209 + int c, old, new;
5210 c = atomic_read(v);
5211 for (;;) {
5212 - if (unlikely(c == (u)))
5213 + if (unlikely(c == u))
5214 break;
5215 - old = atomic_cmpxchg((v), c, c + (a));
5216 +
5217 + asm volatile("addcc %2, %0, %0\n"
5218 +
5219 +#ifdef CONFIG_PAX_REFCOUNT
5220 + "tvs %%icc, 6\n"
5221 +#endif
5222 +
5223 + : "=r" (new)
5224 + : "0" (c), "ir" (a)
5225 + : "cc");
5226 +
5227 + old = atomic_cmpxchg(v, c, new);
5228 if (likely(old == c))
5229 break;
5230 c = old;
5231 @@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
5232 #define atomic64_cmpxchg(v, o, n) \
5233 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
5234 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
5235 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
5236 +{
5237 + return xchg(&v->counter, new);
5238 +}
5239
5240 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
5241 {
5242 - long c, old;
5243 + long c, old, new;
5244 c = atomic64_read(v);
5245 for (;;) {
5246 - if (unlikely(c == (u)))
5247 + if (unlikely(c == u))
5248 break;
5249 - old = atomic64_cmpxchg((v), c, c + (a));
5250 +
5251 + asm volatile("addcc %2, %0, %0\n"
5252 +
5253 +#ifdef CONFIG_PAX_REFCOUNT
5254 + "tvs %%xcc, 6\n"
5255 +#endif
5256 +
5257 + : "=r" (new)
5258 + : "0" (c), "ir" (a)
5259 + : "cc");
5260 +
5261 + old = atomic64_cmpxchg(v, c, new);
5262 if (likely(old == c))
5263 break;
5264 c = old;
5265 }
5266 - return c != (u);
5267 + return c != u;
5268 }
5269
5270 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5271 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
5272 index 5bb6991..5c2132e 100644
5273 --- a/arch/sparc/include/asm/cache.h
5274 +++ b/arch/sparc/include/asm/cache.h
5275 @@ -7,10 +7,12 @@
5276 #ifndef _SPARC_CACHE_H
5277 #define _SPARC_CACHE_H
5278
5279 +#include <linux/const.h>
5280 +
5281 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
5282
5283 #define L1_CACHE_SHIFT 5
5284 -#define L1_CACHE_BYTES 32
5285 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5286
5287 #ifdef CONFIG_SPARC32
5288 #define SMP_CACHE_BYTES_SHIFT 5
5289 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
5290 index 2d4d755..81b6662 100644
5291 --- a/arch/sparc/include/asm/elf_32.h
5292 +++ b/arch/sparc/include/asm/elf_32.h
5293 @@ -114,6 +114,13 @@ typedef struct {
5294
5295 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
5296
5297 +#ifdef CONFIG_PAX_ASLR
5298 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
5299 +
5300 +#define PAX_DELTA_MMAP_LEN 16
5301 +#define PAX_DELTA_STACK_LEN 16
5302 +#endif
5303 +
5304 /* This yields a mask that user programs can use to figure out what
5305 instruction set this cpu supports. This can NOT be done in userspace
5306 on Sparc. */
5307 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
5308 index 7df8b7f..4946269 100644
5309 --- a/arch/sparc/include/asm/elf_64.h
5310 +++ b/arch/sparc/include/asm/elf_64.h
5311 @@ -180,6 +180,13 @@ typedef struct {
5312 #define ELF_ET_DYN_BASE 0x0000010000000000UL
5313 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
5314
5315 +#ifdef CONFIG_PAX_ASLR
5316 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
5317 +
5318 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
5319 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
5320 +#endif
5321 +
5322 extern unsigned long sparc64_elf_hwcap;
5323 #define ELF_HWCAP sparc64_elf_hwcap
5324
5325 diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
5326 index 9b1c36d..209298b 100644
5327 --- a/arch/sparc/include/asm/pgalloc_32.h
5328 +++ b/arch/sparc/include/asm/pgalloc_32.h
5329 @@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
5330 }
5331
5332 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
5333 +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
5334
5335 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
5336 unsigned long address)
5337 diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
5338 index 40b2d7a..22a665b 100644
5339 --- a/arch/sparc/include/asm/pgalloc_64.h
5340 +++ b/arch/sparc/include/asm/pgalloc_64.h
5341 @@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
5342 }
5343
5344 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
5345 +#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
5346
5347 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5348 {
5349 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
5350 index 6fc1348..390c50a 100644
5351 --- a/arch/sparc/include/asm/pgtable_32.h
5352 +++ b/arch/sparc/include/asm/pgtable_32.h
5353 @@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
5354 #define PAGE_SHARED SRMMU_PAGE_SHARED
5355 #define PAGE_COPY SRMMU_PAGE_COPY
5356 #define PAGE_READONLY SRMMU_PAGE_RDONLY
5357 +#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
5358 +#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
5359 +#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
5360 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
5361
5362 /* Top-level page directory - dummy used by init-mm.
5363 @@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
5364
5365 /* xwr */
5366 #define __P000 PAGE_NONE
5367 -#define __P001 PAGE_READONLY
5368 -#define __P010 PAGE_COPY
5369 -#define __P011 PAGE_COPY
5370 +#define __P001 PAGE_READONLY_NOEXEC
5371 +#define __P010 PAGE_COPY_NOEXEC
5372 +#define __P011 PAGE_COPY_NOEXEC
5373 #define __P100 PAGE_READONLY
5374 #define __P101 PAGE_READONLY
5375 #define __P110 PAGE_COPY
5376 #define __P111 PAGE_COPY
5377
5378 #define __S000 PAGE_NONE
5379 -#define __S001 PAGE_READONLY
5380 -#define __S010 PAGE_SHARED
5381 -#define __S011 PAGE_SHARED
5382 +#define __S001 PAGE_READONLY_NOEXEC
5383 +#define __S010 PAGE_SHARED_NOEXEC
5384 +#define __S011 PAGE_SHARED_NOEXEC
5385 #define __S100 PAGE_READONLY
5386 #define __S101 PAGE_READONLY
5387 #define __S110 PAGE_SHARED
5388 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
5389 index 79da178..c2eede8 100644
5390 --- a/arch/sparc/include/asm/pgtsrmmu.h
5391 +++ b/arch/sparc/include/asm/pgtsrmmu.h
5392 @@ -115,6 +115,11 @@
5393 SRMMU_EXEC | SRMMU_REF)
5394 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
5395 SRMMU_EXEC | SRMMU_REF)
5396 +
5397 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
5398 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5399 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5400 +
5401 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
5402 SRMMU_DIRTY | SRMMU_REF)
5403
5404 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
5405 index 9689176..63c18ea 100644
5406 --- a/arch/sparc/include/asm/spinlock_64.h
5407 +++ b/arch/sparc/include/asm/spinlock_64.h
5408 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
5409
5410 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
5411
5412 -static void inline arch_read_lock(arch_rwlock_t *lock)
5413 +static inline void arch_read_lock(arch_rwlock_t *lock)
5414 {
5415 unsigned long tmp1, tmp2;
5416
5417 __asm__ __volatile__ (
5418 "1: ldsw [%2], %0\n"
5419 " brlz,pn %0, 2f\n"
5420 -"4: add %0, 1, %1\n"
5421 +"4: addcc %0, 1, %1\n"
5422 +
5423 +#ifdef CONFIG_PAX_REFCOUNT
5424 +" tvs %%icc, 6\n"
5425 +#endif
5426 +
5427 " cas [%2], %0, %1\n"
5428 " cmp %0, %1\n"
5429 " bne,pn %%icc, 1b\n"
5430 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
5431 " .previous"
5432 : "=&r" (tmp1), "=&r" (tmp2)
5433 : "r" (lock)
5434 - : "memory");
5435 + : "memory", "cc");
5436 }
5437
5438 -static int inline arch_read_trylock(arch_rwlock_t *lock)
5439 +static inline int arch_read_trylock(arch_rwlock_t *lock)
5440 {
5441 int tmp1, tmp2;
5442
5443 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5444 "1: ldsw [%2], %0\n"
5445 " brlz,a,pn %0, 2f\n"
5446 " mov 0, %0\n"
5447 -" add %0, 1, %1\n"
5448 +" addcc %0, 1, %1\n"
5449 +
5450 +#ifdef CONFIG_PAX_REFCOUNT
5451 +" tvs %%icc, 6\n"
5452 +#endif
5453 +
5454 " cas [%2], %0, %1\n"
5455 " cmp %0, %1\n"
5456 " bne,pn %%icc, 1b\n"
5457 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5458 return tmp1;
5459 }
5460
5461 -static void inline arch_read_unlock(arch_rwlock_t *lock)
5462 +static inline void arch_read_unlock(arch_rwlock_t *lock)
5463 {
5464 unsigned long tmp1, tmp2;
5465
5466 __asm__ __volatile__(
5467 "1: lduw [%2], %0\n"
5468 -" sub %0, 1, %1\n"
5469 +" subcc %0, 1, %1\n"
5470 +
5471 +#ifdef CONFIG_PAX_REFCOUNT
5472 +" tvs %%icc, 6\n"
5473 +#endif
5474 +
5475 " cas [%2], %0, %1\n"
5476 " cmp %0, %1\n"
5477 " bne,pn %%xcc, 1b\n"
5478 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
5479 : "memory");
5480 }
5481
5482 -static void inline arch_write_lock(arch_rwlock_t *lock)
5483 +static inline void arch_write_lock(arch_rwlock_t *lock)
5484 {
5485 unsigned long mask, tmp1, tmp2;
5486
5487 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
5488 : "memory");
5489 }
5490
5491 -static void inline arch_write_unlock(arch_rwlock_t *lock)
5492 +static inline void arch_write_unlock(arch_rwlock_t *lock)
5493 {
5494 __asm__ __volatile__(
5495 " stw %%g0, [%0]"
5496 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
5497 : "memory");
5498 }
5499
5500 -static int inline arch_write_trylock(arch_rwlock_t *lock)
5501 +static inline int arch_write_trylock(arch_rwlock_t *lock)
5502 {
5503 unsigned long mask, tmp1, tmp2, result;
5504
5505 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
5506 index e6cd224..3a71793 100644
5507 --- a/arch/sparc/include/asm/thread_info_32.h
5508 +++ b/arch/sparc/include/asm/thread_info_32.h
5509 @@ -49,6 +49,8 @@ struct thread_info {
5510 unsigned long w_saved;
5511
5512 struct restart_block restart_block;
5513 +
5514 + unsigned long lowest_stack;
5515 };
5516
5517 /*
5518 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
5519 index cfa8c38..13f30d3 100644
5520 --- a/arch/sparc/include/asm/thread_info_64.h
5521 +++ b/arch/sparc/include/asm/thread_info_64.h
5522 @@ -63,6 +63,8 @@ struct thread_info {
5523 struct pt_regs *kern_una_regs;
5524 unsigned int kern_una_insn;
5525
5526 + unsigned long lowest_stack;
5527 +
5528 unsigned long fpregs[0] __attribute__ ((aligned(64)));
5529 };
5530
5531 @@ -193,10 +195,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
5532 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
5533 /* flag bit 6 is available */
5534 #define TIF_32BIT 7 /* 32-bit binary */
5535 -/* flag bit 8 is available */
5536 +#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
5537 #define TIF_SECCOMP 9 /* secure computing */
5538 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
5539 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
5540 +
5541 /* NOTE: Thread flags >= 12 should be ones we have no interest
5542 * in using in assembly, else we can't use the mask as
5543 * an immediate value in instructions such as andcc.
5544 @@ -215,12 +218,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
5545 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
5546 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
5547 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
5548 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
5549
5550 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
5551 _TIF_DO_NOTIFY_RESUME_MASK | \
5552 _TIF_NEED_RESCHED)
5553 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
5554
5555 +#define _TIF_WORK_SYSCALL \
5556 + (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
5557 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
5558 +
5559 +
5560 /*
5561 * Thread-synchronous status.
5562 *
5563 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
5564 index 0167d26..9acd8ed 100644
5565 --- a/arch/sparc/include/asm/uaccess.h
5566 +++ b/arch/sparc/include/asm/uaccess.h
5567 @@ -1,5 +1,13 @@
5568 #ifndef ___ASM_SPARC_UACCESS_H
5569 #define ___ASM_SPARC_UACCESS_H
5570 +
5571 +#ifdef __KERNEL__
5572 +#ifndef __ASSEMBLY__
5573 +#include <linux/types.h>
5574 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
5575 +#endif
5576 +#endif
5577 +
5578 #if defined(__sparc__) && defined(__arch64__)
5579 #include <asm/uaccess_64.h>
5580 #else
5581 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
5582 index 53a28dd..50c38c3 100644
5583 --- a/arch/sparc/include/asm/uaccess_32.h
5584 +++ b/arch/sparc/include/asm/uaccess_32.h
5585 @@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
5586
5587 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
5588 {
5589 - if (n && __access_ok((unsigned long) to, n))
5590 + if ((long)n < 0)
5591 + return n;
5592 +
5593 + if (n && __access_ok((unsigned long) to, n)) {
5594 + if (!__builtin_constant_p(n))
5595 + check_object_size(from, n, true);
5596 return __copy_user(to, (__force void __user *) from, n);
5597 - else
5598 + } else
5599 return n;
5600 }
5601
5602 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
5603 {
5604 + if ((long)n < 0)
5605 + return n;
5606 +
5607 + if (!__builtin_constant_p(n))
5608 + check_object_size(from, n, true);
5609 +
5610 return __copy_user(to, (__force void __user *) from, n);
5611 }
5612
5613 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
5614 {
5615 - if (n && __access_ok((unsigned long) from, n))
5616 + if ((long)n < 0)
5617 + return n;
5618 +
5619 + if (n && __access_ok((unsigned long) from, n)) {
5620 + if (!__builtin_constant_p(n))
5621 + check_object_size(to, n, false);
5622 return __copy_user((__force void __user *) to, from, n);
5623 - else
5624 + } else
5625 return n;
5626 }
5627
5628 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
5629 {
5630 + if ((long)n < 0)
5631 + return n;
5632 +
5633 return __copy_user((__force void __user *) to, from, n);
5634 }
5635
5636 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
5637 index 7c831d8..d440ca7 100644
5638 --- a/arch/sparc/include/asm/uaccess_64.h
5639 +++ b/arch/sparc/include/asm/uaccess_64.h
5640 @@ -10,6 +10,7 @@
5641 #include <linux/compiler.h>
5642 #include <linux/string.h>
5643 #include <linux/thread_info.h>
5644 +#include <linux/kernel.h>
5645 #include <asm/asi.h>
5646 #include <asm/spitfire.h>
5647 #include <asm-generic/uaccess-unaligned.h>
5648 @@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
5649 static inline unsigned long __must_check
5650 copy_from_user(void *to, const void __user *from, unsigned long size)
5651 {
5652 - unsigned long ret = ___copy_from_user(to, from, size);
5653 + unsigned long ret;
5654
5655 + if ((long)size < 0 || size > INT_MAX)
5656 + return size;
5657 +
5658 + if (!__builtin_constant_p(size))
5659 + check_object_size(to, size, false);
5660 +
5661 + ret = ___copy_from_user(to, from, size);
5662 if (unlikely(ret))
5663 ret = copy_from_user_fixup(to, from, size);
5664
5665 @@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
5666 static inline unsigned long __must_check
5667 copy_to_user(void __user *to, const void *from, unsigned long size)
5668 {
5669 - unsigned long ret = ___copy_to_user(to, from, size);
5670 + unsigned long ret;
5671
5672 + if ((long)size < 0 || size > INT_MAX)
5673 + return size;
5674 +
5675 + if (!__builtin_constant_p(size))
5676 + check_object_size(from, size, true);
5677 +
5678 + ret = ___copy_to_user(to, from, size);
5679 if (unlikely(ret))
5680 ret = copy_to_user_fixup(to, from, size);
5681 return ret;
5682 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
5683 index 6cf591b..b49e65a 100644
5684 --- a/arch/sparc/kernel/Makefile
5685 +++ b/arch/sparc/kernel/Makefile
5686 @@ -3,7 +3,7 @@
5687 #
5688
5689 asflags-y := -ansi
5690 -ccflags-y := -Werror
5691 +#ccflags-y := -Werror
5692
5693 extra-y := head_$(BITS).o
5694
5695 diff --git a/arch/sparc/kernel/leon_kernel.c b/arch/sparc/kernel/leon_kernel.c
5696 index f8b6eee..87f60ee 100644
5697 --- a/arch/sparc/kernel/leon_kernel.c
5698 +++ b/arch/sparc/kernel/leon_kernel.c
5699 @@ -56,11 +56,13 @@ static inline unsigned int leon_eirq_get(int cpu)
5700 static void leon_handle_ext_irq(unsigned int irq, struct irq_desc *desc)
5701 {
5702 unsigned int eirq;
5703 + struct irq_bucket *p;
5704 int cpu = sparc_leon3_cpuid();
5705
5706 eirq = leon_eirq_get(cpu);
5707 - if ((eirq & 0x10) && irq_map[eirq]->irq) /* bit4 tells if IRQ happened */
5708 - generic_handle_irq(irq_map[eirq]->irq);
5709 + p = irq_map[eirq];
5710 + if ((eirq & 0x10) && p && p->irq) /* bit4 tells if IRQ happened */
5711 + generic_handle_irq(p->irq);
5712 }
5713
5714 /* The extended IRQ controller has been found, this function registers it */
5715 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
5716 index 14006d8..8146238 100644
5717 --- a/arch/sparc/kernel/process_32.c
5718 +++ b/arch/sparc/kernel/process_32.c
5719 @@ -126,14 +126,14 @@ void show_regs(struct pt_regs *r)
5720
5721 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
5722 r->psr, r->pc, r->npc, r->y, print_tainted());
5723 - printk("PC: <%pS>\n", (void *) r->pc);
5724 + printk("PC: <%pA>\n", (void *) r->pc);
5725 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5726 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
5727 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
5728 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5729 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
5730 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
5731 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
5732 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
5733
5734 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5735 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
5736 @@ -168,7 +168,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
5737 rw = (struct reg_window32 *) fp;
5738 pc = rw->ins[7];
5739 printk("[%08lx : ", pc);
5740 - printk("%pS ] ", (void *) pc);
5741 + printk("%pA ] ", (void *) pc);
5742 fp = rw->ins[6];
5743 } while (++count < 16);
5744 printk("\n");
5745 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
5746 index aff0c72..9067b39 100644
5747 --- a/arch/sparc/kernel/process_64.c
5748 +++ b/arch/sparc/kernel/process_64.c
5749 @@ -179,14 +179,14 @@ static void show_regwindow(struct pt_regs *regs)
5750 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
5751 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
5752 if (regs->tstate & TSTATE_PRIV)
5753 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
5754 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
5755 }
5756
5757 void show_regs(struct pt_regs *regs)
5758 {
5759 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
5760 regs->tpc, regs->tnpc, regs->y, print_tainted());
5761 - printk("TPC: <%pS>\n", (void *) regs->tpc);
5762 + printk("TPC: <%pA>\n", (void *) regs->tpc);
5763 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
5764 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
5765 regs->u_regs[3]);
5766 @@ -199,7 +199,7 @@ void show_regs(struct pt_regs *regs)
5767 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
5768 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
5769 regs->u_regs[15]);
5770 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
5771 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
5772 show_regwindow(regs);
5773 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
5774 }
5775 @@ -284,7 +284,7 @@ void arch_trigger_all_cpu_backtrace(void)
5776 ((tp && tp->task) ? tp->task->pid : -1));
5777
5778 if (gp->tstate & TSTATE_PRIV) {
5779 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
5780 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
5781 (void *) gp->tpc,
5782 (void *) gp->o7,
5783 (void *) gp->i7,
5784 diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
5785 index 484daba..0674139 100644
5786 --- a/arch/sparc/kernel/ptrace_64.c
5787 +++ b/arch/sparc/kernel/ptrace_64.c
5788 @@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
5789 return ret;
5790 }
5791
5792 +#ifdef CONFIG_GRKERNSEC_SETXID
5793 +extern void gr_delayed_cred_worker(void);
5794 +#endif
5795 +
5796 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5797 {
5798 int ret = 0;
5799 @@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5800 /* do the secure computing check first */
5801 secure_computing_strict(regs->u_regs[UREG_G1]);
5802
5803 +#ifdef CONFIG_GRKERNSEC_SETXID
5804 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5805 + gr_delayed_cred_worker();
5806 +#endif
5807 +
5808 if (test_thread_flag(TIF_SYSCALL_TRACE))
5809 ret = tracehook_report_syscall_entry(regs);
5810
5811 @@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5812
5813 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
5814 {
5815 +#ifdef CONFIG_GRKERNSEC_SETXID
5816 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5817 + gr_delayed_cred_worker();
5818 +#endif
5819 +
5820 audit_syscall_exit(regs);
5821
5822 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
5823 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
5824 index 0c9b31b..7cb7aee 100644
5825 --- a/arch/sparc/kernel/sys_sparc_32.c
5826 +++ b/arch/sparc/kernel/sys_sparc_32.c
5827 @@ -54,7 +54,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5828 if (len > TASK_SIZE - PAGE_SIZE)
5829 return -ENOMEM;
5830 if (!addr)
5831 - addr = TASK_UNMAPPED_BASE;
5832 + addr = current->mm->mmap_base;
5833
5834 if (flags & MAP_SHARED)
5835 addr = COLOUR_ALIGN(addr);
5836 @@ -65,7 +65,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5837 /* At this point: (!vmm || addr < vmm->vm_end). */
5838 if (TASK_SIZE - PAGE_SIZE - len < addr)
5839 return -ENOMEM;
5840 - if (!vmm || addr + len <= vmm->vm_start)
5841 + if (check_heap_stack_gap(vmm, addr, len))
5842 return addr;
5843 addr = vmm->vm_end;
5844 if (flags & MAP_SHARED)
5845 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
5846 index 11c6c96..3ec33e8 100644
5847 --- a/arch/sparc/kernel/sys_sparc_64.c
5848 +++ b/arch/sparc/kernel/sys_sparc_64.c
5849 @@ -107,7 +107,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5850 /* We do not accept a shared mapping if it would violate
5851 * cache aliasing constraints.
5852 */
5853 - if ((flags & MAP_SHARED) &&
5854 + if ((filp || (flags & MAP_SHARED)) &&
5855 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5856 return -EINVAL;
5857 return addr;
5858 @@ -122,6 +122,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5859 if (filp || (flags & MAP_SHARED))
5860 do_color_align = 1;
5861
5862 +#ifdef CONFIG_PAX_RANDMMAP
5863 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5864 +#endif
5865 +
5866 if (addr) {
5867 if (do_color_align)
5868 addr = COLOUR_ALIGN(addr, pgoff);
5869 @@ -129,15 +133,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5870 addr = PAGE_ALIGN(addr);
5871
5872 vma = find_vma(mm, addr);
5873 - if (task_size - len >= addr &&
5874 - (!vma || addr + len <= vma->vm_start))
5875 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5876 return addr;
5877 }
5878
5879 if (len > mm->cached_hole_size) {
5880 - start_addr = addr = mm->free_area_cache;
5881 + start_addr = addr = mm->free_area_cache;
5882 } else {
5883 - start_addr = addr = TASK_UNMAPPED_BASE;
5884 + start_addr = addr = mm->mmap_base;
5885 mm->cached_hole_size = 0;
5886 }
5887
5888 @@ -157,14 +160,14 @@ full_search:
5889 vma = find_vma(mm, VA_EXCLUDE_END);
5890 }
5891 if (unlikely(task_size < addr)) {
5892 - if (start_addr != TASK_UNMAPPED_BASE) {
5893 - start_addr = addr = TASK_UNMAPPED_BASE;
5894 + if (start_addr != mm->mmap_base) {
5895 + start_addr = addr = mm->mmap_base;
5896 mm->cached_hole_size = 0;
5897 goto full_search;
5898 }
5899 return -ENOMEM;
5900 }
5901 - if (likely(!vma || addr + len <= vma->vm_start)) {
5902 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5903 /*
5904 * Remember the place where we stopped the search:
5905 */
5906 @@ -198,7 +201,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5907 /* We do not accept a shared mapping if it would violate
5908 * cache aliasing constraints.
5909 */
5910 - if ((flags & MAP_SHARED) &&
5911 + if ((filp || (flags & MAP_SHARED)) &&
5912 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5913 return -EINVAL;
5914 return addr;
5915 @@ -219,8 +222,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5916 addr = PAGE_ALIGN(addr);
5917
5918 vma = find_vma(mm, addr);
5919 - if (task_size - len >= addr &&
5920 - (!vma || addr + len <= vma->vm_start))
5921 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5922 return addr;
5923 }
5924
5925 @@ -241,7 +243,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5926 /* make sure it can fit in the remaining address space */
5927 if (likely(addr > len)) {
5928 vma = find_vma(mm, addr-len);
5929 - if (!vma || addr <= vma->vm_start) {
5930 + if (check_heap_stack_gap(vma, addr - len, len)) {
5931 /* remember the address as a hint for next time */
5932 return (mm->free_area_cache = addr-len);
5933 }
5934 @@ -250,18 +252,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5935 if (unlikely(mm->mmap_base < len))
5936 goto bottomup;
5937
5938 - addr = mm->mmap_base-len;
5939 - if (do_color_align)
5940 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5941 + addr = mm->mmap_base - len;
5942
5943 do {
5944 + if (do_color_align)
5945 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5946 /*
5947 * Lookup failure means no vma is above this address,
5948 * else if new region fits below vma->vm_start,
5949 * return with success:
5950 */
5951 vma = find_vma(mm, addr);
5952 - if (likely(!vma || addr+len <= vma->vm_start)) {
5953 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5954 /* remember the address as a hint for next time */
5955 return (mm->free_area_cache = addr);
5956 }
5957 @@ -271,10 +273,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5958 mm->cached_hole_size = vma->vm_start - addr;
5959
5960 /* try just below the current vma->vm_start */
5961 - addr = vma->vm_start-len;
5962 - if (do_color_align)
5963 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5964 - } while (likely(len < vma->vm_start));
5965 + addr = skip_heap_stack_gap(vma, len);
5966 + } while (!IS_ERR_VALUE(addr));
5967
5968 bottomup:
5969 /*
5970 @@ -373,6 +373,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5971 gap == RLIM_INFINITY ||
5972 sysctl_legacy_va_layout) {
5973 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
5974 +
5975 +#ifdef CONFIG_PAX_RANDMMAP
5976 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5977 + mm->mmap_base += mm->delta_mmap;
5978 +#endif
5979 +
5980 mm->get_unmapped_area = arch_get_unmapped_area;
5981 mm->unmap_area = arch_unmap_area;
5982 } else {
5983 @@ -385,6 +391,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5984 gap = (task_size / 6 * 5);
5985
5986 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
5987 +
5988 +#ifdef CONFIG_PAX_RANDMMAP
5989 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5990 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5991 +#endif
5992 +
5993 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5994 mm->unmap_area = arch_unmap_area_topdown;
5995 }
5996 diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
5997 index 7f5f65d..3308382 100644
5998 --- a/arch/sparc/kernel/syscalls.S
5999 +++ b/arch/sparc/kernel/syscalls.S
6000 @@ -62,7 +62,7 @@ sys32_rt_sigreturn:
6001 #endif
6002 .align 32
6003 1: ldx [%g6 + TI_FLAGS], %l5
6004 - andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6005 + andcc %l5, _TIF_WORK_SYSCALL, %g0
6006 be,pt %icc, rtrap
6007 nop
6008 call syscall_trace_leave
6009 @@ -179,7 +179,7 @@ linux_sparc_syscall32:
6010
6011 srl %i5, 0, %o5 ! IEU1
6012 srl %i2, 0, %o2 ! IEU0 Group
6013 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6014 + andcc %l0, _TIF_WORK_SYSCALL, %g0
6015 bne,pn %icc, linux_syscall_trace32 ! CTI
6016 mov %i0, %l5 ! IEU1
6017 call %l7 ! CTI Group brk forced
6018 @@ -202,7 +202,7 @@ linux_sparc_syscall:
6019
6020 mov %i3, %o3 ! IEU1
6021 mov %i4, %o4 ! IEU0 Group
6022 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6023 + andcc %l0, _TIF_WORK_SYSCALL, %g0
6024 bne,pn %icc, linux_syscall_trace ! CTI Group
6025 mov %i0, %l5 ! IEU0
6026 2: call %l7 ! CTI Group brk forced
6027 @@ -218,7 +218,7 @@ ret_sys_call:
6028
6029 cmp %o0, -ERESTART_RESTARTBLOCK
6030 bgeu,pn %xcc, 1f
6031 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6032 + andcc %l0, _TIF_WORK_SYSCALL, %g0
6033 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
6034
6035 2:
6036 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
6037 index a5785ea..405c5f7 100644
6038 --- a/arch/sparc/kernel/traps_32.c
6039 +++ b/arch/sparc/kernel/traps_32.c
6040 @@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
6041 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
6042 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
6043
6044 +extern void gr_handle_kernel_exploit(void);
6045 +
6046 void die_if_kernel(char *str, struct pt_regs *regs)
6047 {
6048 static int die_counter;
6049 @@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6050 count++ < 30 &&
6051 (((unsigned long) rw) >= PAGE_OFFSET) &&
6052 !(((unsigned long) rw) & 0x7)) {
6053 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
6054 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
6055 (void *) rw->ins[7]);
6056 rw = (struct reg_window32 *)rw->ins[6];
6057 }
6058 }
6059 printk("Instruction DUMP:");
6060 instruction_dump ((unsigned long *) regs->pc);
6061 - if(regs->psr & PSR_PS)
6062 + if(regs->psr & PSR_PS) {
6063 + gr_handle_kernel_exploit();
6064 do_exit(SIGKILL);
6065 + }
6066 do_exit(SIGSEGV);
6067 }
6068
6069 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
6070 index 3b05e66..6ea2917 100644
6071 --- a/arch/sparc/kernel/traps_64.c
6072 +++ b/arch/sparc/kernel/traps_64.c
6073 @@ -75,7 +75,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
6074 i + 1,
6075 p->trapstack[i].tstate, p->trapstack[i].tpc,
6076 p->trapstack[i].tnpc, p->trapstack[i].tt);
6077 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
6078 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
6079 }
6080 }
6081
6082 @@ -95,6 +95,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
6083
6084 lvl -= 0x100;
6085 if (regs->tstate & TSTATE_PRIV) {
6086 +
6087 +#ifdef CONFIG_PAX_REFCOUNT
6088 + if (lvl == 6)
6089 + pax_report_refcount_overflow(regs);
6090 +#endif
6091 +
6092 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
6093 die_if_kernel(buffer, regs);
6094 }
6095 @@ -113,11 +119,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
6096 void bad_trap_tl1(struct pt_regs *regs, long lvl)
6097 {
6098 char buffer[32];
6099 -
6100 +
6101 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
6102 0, lvl, SIGTRAP) == NOTIFY_STOP)
6103 return;
6104
6105 +#ifdef CONFIG_PAX_REFCOUNT
6106 + if (lvl == 6)
6107 + pax_report_refcount_overflow(regs);
6108 +#endif
6109 +
6110 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
6111
6112 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
6113 @@ -1141,7 +1152,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
6114 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
6115 printk("%s" "ERROR(%d): ",
6116 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
6117 - printk("TPC<%pS>\n", (void *) regs->tpc);
6118 + printk("TPC<%pA>\n", (void *) regs->tpc);
6119 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
6120 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
6121 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
6122 @@ -1748,7 +1759,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6123 smp_processor_id(),
6124 (type & 0x1) ? 'I' : 'D',
6125 regs->tpc);
6126 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
6127 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
6128 panic("Irrecoverable Cheetah+ parity error.");
6129 }
6130
6131 @@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6132 smp_processor_id(),
6133 (type & 0x1) ? 'I' : 'D',
6134 regs->tpc);
6135 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
6136 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
6137 }
6138
6139 struct sun4v_error_entry {
6140 @@ -1963,9 +1974,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
6141
6142 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
6143 regs->tpc, tl);
6144 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
6145 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
6146 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6147 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
6148 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
6149 (void *) regs->u_regs[UREG_I7]);
6150 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
6151 "pte[%lx] error[%lx]\n",
6152 @@ -1987,9 +1998,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
6153
6154 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
6155 regs->tpc, tl);
6156 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
6157 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
6158 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6159 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
6160 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
6161 (void *) regs->u_regs[UREG_I7]);
6162 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
6163 "pte[%lx] error[%lx]\n",
6164 @@ -2195,13 +2206,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
6165 fp = (unsigned long)sf->fp + STACK_BIAS;
6166 }
6167
6168 - printk(" [%016lx] %pS\n", pc, (void *) pc);
6169 + printk(" [%016lx] %pA\n", pc, (void *) pc);
6170 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
6171 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
6172 int index = tsk->curr_ret_stack;
6173 if (tsk->ret_stack && index >= graph) {
6174 pc = tsk->ret_stack[index - graph].ret;
6175 - printk(" [%016lx] %pS\n", pc, (void *) pc);
6176 + printk(" [%016lx] %pA\n", pc, (void *) pc);
6177 graph++;
6178 }
6179 }
6180 @@ -2226,6 +2237,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
6181 return (struct reg_window *) (fp + STACK_BIAS);
6182 }
6183
6184 +extern void gr_handle_kernel_exploit(void);
6185 +
6186 void die_if_kernel(char *str, struct pt_regs *regs)
6187 {
6188 static int die_counter;
6189 @@ -2254,7 +2267,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6190 while (rw &&
6191 count++ < 30 &&
6192 kstack_valid(tp, (unsigned long) rw)) {
6193 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
6194 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
6195 (void *) rw->ins[7]);
6196
6197 rw = kernel_stack_up(rw);
6198 @@ -2267,8 +2280,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6199 }
6200 user_instruction_dump ((unsigned int __user *) regs->tpc);
6201 }
6202 - if (regs->tstate & TSTATE_PRIV)
6203 + if (regs->tstate & TSTATE_PRIV) {
6204 + gr_handle_kernel_exploit();
6205 do_exit(SIGKILL);
6206 + }
6207 do_exit(SIGSEGV);
6208 }
6209 EXPORT_SYMBOL(die_if_kernel);
6210 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
6211 index f81d038..e7a4680 100644
6212 --- a/arch/sparc/kernel/unaligned_64.c
6213 +++ b/arch/sparc/kernel/unaligned_64.c
6214 @@ -278,7 +278,7 @@ static void log_unaligned(struct pt_regs *regs)
6215 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
6216
6217 if (__ratelimit(&ratelimit)) {
6218 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
6219 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
6220 regs->tpc, (void *) regs->tpc);
6221 }
6222 }
6223 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
6224 index dff4096..bd9a388 100644
6225 --- a/arch/sparc/lib/Makefile
6226 +++ b/arch/sparc/lib/Makefile
6227 @@ -2,7 +2,7 @@
6228 #
6229
6230 asflags-y := -ansi -DST_DIV0=0x02
6231 -ccflags-y := -Werror
6232 +#ccflags-y := -Werror
6233
6234 lib-$(CONFIG_SPARC32) += ashrdi3.o
6235 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
6236 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
6237 index 4d502da..527c48d 100644
6238 --- a/arch/sparc/lib/atomic_64.S
6239 +++ b/arch/sparc/lib/atomic_64.S
6240 @@ -17,7 +17,12 @@
6241 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
6242 BACKOFF_SETUP(%o2)
6243 1: lduw [%o1], %g1
6244 - add %g1, %o0, %g7
6245 + addcc %g1, %o0, %g7
6246 +
6247 +#ifdef CONFIG_PAX_REFCOUNT
6248 + tvs %icc, 6
6249 +#endif
6250 +
6251 cas [%o1], %g1, %g7
6252 cmp %g1, %g7
6253 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6254 @@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
6255 2: BACKOFF_SPIN(%o2, %o3, 1b)
6256 ENDPROC(atomic_add)
6257
6258 +ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6259 + BACKOFF_SETUP(%o2)
6260 +1: lduw [%o1], %g1
6261 + add %g1, %o0, %g7
6262 + cas [%o1], %g1, %g7
6263 + cmp %g1, %g7
6264 + bne,pn %icc, 2f
6265 + nop
6266 + retl
6267 + nop
6268 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6269 +ENDPROC(atomic_add_unchecked)
6270 +
6271 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6272 BACKOFF_SETUP(%o2)
6273 1: lduw [%o1], %g1
6274 - sub %g1, %o0, %g7
6275 + subcc %g1, %o0, %g7
6276 +
6277 +#ifdef CONFIG_PAX_REFCOUNT
6278 + tvs %icc, 6
6279 +#endif
6280 +
6281 cas [%o1], %g1, %g7
6282 cmp %g1, %g7
6283 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6284 @@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6285 2: BACKOFF_SPIN(%o2, %o3, 1b)
6286 ENDPROC(atomic_sub)
6287
6288 +ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
6289 + BACKOFF_SETUP(%o2)
6290 +1: lduw [%o1], %g1
6291 + sub %g1, %o0, %g7
6292 + cas [%o1], %g1, %g7
6293 + cmp %g1, %g7
6294 + bne,pn %icc, 2f
6295 + nop
6296 + retl
6297 + nop
6298 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6299 +ENDPROC(atomic_sub_unchecked)
6300 +
6301 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6302 BACKOFF_SETUP(%o2)
6303 1: lduw [%o1], %g1
6304 - add %g1, %o0, %g7
6305 + addcc %g1, %o0, %g7
6306 +
6307 +#ifdef CONFIG_PAX_REFCOUNT
6308 + tvs %icc, 6
6309 +#endif
6310 +
6311 cas [%o1], %g1, %g7
6312 cmp %g1, %g7
6313 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6314 @@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6315 2: BACKOFF_SPIN(%o2, %o3, 1b)
6316 ENDPROC(atomic_add_ret)
6317
6318 +ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6319 + BACKOFF_SETUP(%o2)
6320 +1: lduw [%o1], %g1
6321 + addcc %g1, %o0, %g7
6322 + cas [%o1], %g1, %g7
6323 + cmp %g1, %g7
6324 + bne,pn %icc, 2f
6325 + add %g7, %o0, %g7
6326 + sra %g7, 0, %o0
6327 + retl
6328 + nop
6329 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6330 +ENDPROC(atomic_add_ret_unchecked)
6331 +
6332 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
6333 BACKOFF_SETUP(%o2)
6334 1: lduw [%o1], %g1
6335 - sub %g1, %o0, %g7
6336 + subcc %g1, %o0, %g7
6337 +
6338 +#ifdef CONFIG_PAX_REFCOUNT
6339 + tvs %icc, 6
6340 +#endif
6341 +
6342 cas [%o1], %g1, %g7
6343 cmp %g1, %g7
6344 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6345 @@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
6346 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
6347 BACKOFF_SETUP(%o2)
6348 1: ldx [%o1], %g1
6349 - add %g1, %o0, %g7
6350 + addcc %g1, %o0, %g7
6351 +
6352 +#ifdef CONFIG_PAX_REFCOUNT
6353 + tvs %xcc, 6
6354 +#endif
6355 +
6356 casx [%o1], %g1, %g7
6357 cmp %g1, %g7
6358 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6359 @@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
6360 2: BACKOFF_SPIN(%o2, %o3, 1b)
6361 ENDPROC(atomic64_add)
6362
6363 +ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6364 + BACKOFF_SETUP(%o2)
6365 +1: ldx [%o1], %g1
6366 + addcc %g1, %o0, %g7
6367 + casx [%o1], %g1, %g7
6368 + cmp %g1, %g7
6369 + bne,pn %xcc, 2f
6370 + nop
6371 + retl
6372 + nop
6373 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6374 +ENDPROC(atomic64_add_unchecked)
6375 +
6376 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6377 BACKOFF_SETUP(%o2)
6378 1: ldx [%o1], %g1
6379 - sub %g1, %o0, %g7
6380 + subcc %g1, %o0, %g7
6381 +
6382 +#ifdef CONFIG_PAX_REFCOUNT
6383 + tvs %xcc, 6
6384 +#endif
6385 +
6386 casx [%o1], %g1, %g7
6387 cmp %g1, %g7
6388 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6389 @@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6390 2: BACKOFF_SPIN(%o2, %o3, 1b)
6391 ENDPROC(atomic64_sub)
6392
6393 +ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
6394 + BACKOFF_SETUP(%o2)
6395 +1: ldx [%o1], %g1
6396 + subcc %g1, %o0, %g7
6397 + casx [%o1], %g1, %g7
6398 + cmp %g1, %g7
6399 + bne,pn %xcc, 2f
6400 + nop
6401 + retl
6402 + nop
6403 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6404 +ENDPROC(atomic64_sub_unchecked)
6405 +
6406 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6407 BACKOFF_SETUP(%o2)
6408 1: ldx [%o1], %g1
6409 - add %g1, %o0, %g7
6410 + addcc %g1, %o0, %g7
6411 +
6412 +#ifdef CONFIG_PAX_REFCOUNT
6413 + tvs %xcc, 6
6414 +#endif
6415 +
6416 casx [%o1], %g1, %g7
6417 cmp %g1, %g7
6418 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6419 @@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6420 2: BACKOFF_SPIN(%o2, %o3, 1b)
6421 ENDPROC(atomic64_add_ret)
6422
6423 +ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6424 + BACKOFF_SETUP(%o2)
6425 +1: ldx [%o1], %g1
6426 + addcc %g1, %o0, %g7
6427 + casx [%o1], %g1, %g7
6428 + cmp %g1, %g7
6429 + bne,pn %xcc, 2f
6430 + add %g7, %o0, %g7
6431 + mov %g7, %o0
6432 + retl
6433 + nop
6434 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6435 +ENDPROC(atomic64_add_ret_unchecked)
6436 +
6437 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
6438 BACKOFF_SETUP(%o2)
6439 1: ldx [%o1], %g1
6440 - sub %g1, %o0, %g7
6441 + subcc %g1, %o0, %g7
6442 +
6443 +#ifdef CONFIG_PAX_REFCOUNT
6444 + tvs %xcc, 6
6445 +#endif
6446 +
6447 casx [%o1], %g1, %g7
6448 cmp %g1, %g7
6449 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6450 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
6451 index 3b31218..345c609 100644
6452 --- a/arch/sparc/lib/ksyms.c
6453 +++ b/arch/sparc/lib/ksyms.c
6454 @@ -109,12 +109,18 @@ EXPORT_SYMBOL(__downgrade_write);
6455
6456 /* Atomic counter implementation. */
6457 EXPORT_SYMBOL(atomic_add);
6458 +EXPORT_SYMBOL(atomic_add_unchecked);
6459 EXPORT_SYMBOL(atomic_add_ret);
6460 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
6461 EXPORT_SYMBOL(atomic_sub);
6462 +EXPORT_SYMBOL(atomic_sub_unchecked);
6463 EXPORT_SYMBOL(atomic_sub_ret);
6464 EXPORT_SYMBOL(atomic64_add);
6465 +EXPORT_SYMBOL(atomic64_add_unchecked);
6466 EXPORT_SYMBOL(atomic64_add_ret);
6467 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
6468 EXPORT_SYMBOL(atomic64_sub);
6469 +EXPORT_SYMBOL(atomic64_sub_unchecked);
6470 EXPORT_SYMBOL(atomic64_sub_ret);
6471
6472 /* Atomic bit operations. */
6473 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
6474 index 30c3ecc..736f015 100644
6475 --- a/arch/sparc/mm/Makefile
6476 +++ b/arch/sparc/mm/Makefile
6477 @@ -2,7 +2,7 @@
6478 #
6479
6480 asflags-y := -ansi
6481 -ccflags-y := -Werror
6482 +#ccflags-y := -Werror
6483
6484 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
6485 obj-y += fault_$(BITS).o
6486 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
6487 index 77ac917..baf45db 100644
6488 --- a/arch/sparc/mm/fault_32.c
6489 +++ b/arch/sparc/mm/fault_32.c
6490 @@ -21,6 +21,9 @@
6491 #include <linux/perf_event.h>
6492 #include <linux/interrupt.h>
6493 #include <linux/kdebug.h>
6494 +#include <linux/slab.h>
6495 +#include <linux/pagemap.h>
6496 +#include <linux/compiler.h>
6497
6498 #include <asm/page.h>
6499 #include <asm/pgtable.h>
6500 @@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
6501 return safe_compute_effective_address(regs, insn);
6502 }
6503
6504 +#ifdef CONFIG_PAX_PAGEEXEC
6505 +#ifdef CONFIG_PAX_DLRESOLVE
6506 +static void pax_emuplt_close(struct vm_area_struct *vma)
6507 +{
6508 + vma->vm_mm->call_dl_resolve = 0UL;
6509 +}
6510 +
6511 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6512 +{
6513 + unsigned int *kaddr;
6514 +
6515 + vmf->page = alloc_page(GFP_HIGHUSER);
6516 + if (!vmf->page)
6517 + return VM_FAULT_OOM;
6518 +
6519 + kaddr = kmap(vmf->page);
6520 + memset(kaddr, 0, PAGE_SIZE);
6521 + kaddr[0] = 0x9DE3BFA8U; /* save */
6522 + flush_dcache_page(vmf->page);
6523 + kunmap(vmf->page);
6524 + return VM_FAULT_MAJOR;
6525 +}
6526 +
6527 +static const struct vm_operations_struct pax_vm_ops = {
6528 + .close = pax_emuplt_close,
6529 + .fault = pax_emuplt_fault
6530 +};
6531 +
6532 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6533 +{
6534 + int ret;
6535 +
6536 + INIT_LIST_HEAD(&vma->anon_vma_chain);
6537 + vma->vm_mm = current->mm;
6538 + vma->vm_start = addr;
6539 + vma->vm_end = addr + PAGE_SIZE;
6540 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6541 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6542 + vma->vm_ops = &pax_vm_ops;
6543 +
6544 + ret = insert_vm_struct(current->mm, vma);
6545 + if (ret)
6546 + return ret;
6547 +
6548 + ++current->mm->total_vm;
6549 + return 0;
6550 +}
6551 +#endif
6552 +
6553 +/*
6554 + * PaX: decide what to do with offenders (regs->pc = fault address)
6555 + *
6556 + * returns 1 when task should be killed
6557 + * 2 when patched PLT trampoline was detected
6558 + * 3 when unpatched PLT trampoline was detected
6559 + */
6560 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6561 +{
6562 +
6563 +#ifdef CONFIG_PAX_EMUPLT
6564 + int err;
6565 +
6566 + do { /* PaX: patched PLT emulation #1 */
6567 + unsigned int sethi1, sethi2, jmpl;
6568 +
6569 + err = get_user(sethi1, (unsigned int *)regs->pc);
6570 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
6571 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
6572 +
6573 + if (err)
6574 + break;
6575 +
6576 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6577 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
6578 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
6579 + {
6580 + unsigned int addr;
6581 +
6582 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6583 + addr = regs->u_regs[UREG_G1];
6584 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6585 + regs->pc = addr;
6586 + regs->npc = addr+4;
6587 + return 2;
6588 + }
6589 + } while (0);
6590 +
6591 + do { /* PaX: patched PLT emulation #2 */
6592 + unsigned int ba;
6593 +
6594 + err = get_user(ba, (unsigned int *)regs->pc);
6595 +
6596 + if (err)
6597 + break;
6598 +
6599 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
6600 + unsigned int addr;
6601 +
6602 + if ((ba & 0xFFC00000U) == 0x30800000U)
6603 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6604 + else
6605 + addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6606 + regs->pc = addr;
6607 + regs->npc = addr+4;
6608 + return 2;
6609 + }
6610 + } while (0);
6611 +
6612 + do { /* PaX: patched PLT emulation #3 */
6613 + unsigned int sethi, bajmpl, nop;
6614 +
6615 + err = get_user(sethi, (unsigned int *)regs->pc);
6616 + err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
6617 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
6618 +
6619 + if (err)
6620 + break;
6621 +
6622 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6623 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
6624 + nop == 0x01000000U)
6625 + {
6626 + unsigned int addr;
6627 +
6628 + addr = (sethi & 0x003FFFFFU) << 10;
6629 + regs->u_regs[UREG_G1] = addr;
6630 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
6631 + addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6632 + else
6633 + addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6634 + regs->pc = addr;
6635 + regs->npc = addr+4;
6636 + return 2;
6637 + }
6638 + } while (0);
6639 +
6640 + do { /* PaX: unpatched PLT emulation step 1 */
6641 + unsigned int sethi, ba, nop;
6642 +
6643 + err = get_user(sethi, (unsigned int *)regs->pc);
6644 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
6645 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
6646 +
6647 + if (err)
6648 + break;
6649 +
6650 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6651 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
6652 + nop == 0x01000000U)
6653 + {
6654 + unsigned int addr, save, call;
6655 +
6656 + if ((ba & 0xFFC00000U) == 0x30800000U)
6657 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6658 + else
6659 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6660 +
6661 + err = get_user(save, (unsigned int *)addr);
6662 + err |= get_user(call, (unsigned int *)(addr+4));
6663 + err |= get_user(nop, (unsigned int *)(addr+8));
6664 + if (err)
6665 + break;
6666 +
6667 +#ifdef CONFIG_PAX_DLRESOLVE
6668 + if (save == 0x9DE3BFA8U &&
6669 + (call & 0xC0000000U) == 0x40000000U &&
6670 + nop == 0x01000000U)
6671 + {
6672 + struct vm_area_struct *vma;
6673 + unsigned long call_dl_resolve;
6674 +
6675 + down_read(&current->mm->mmap_sem);
6676 + call_dl_resolve = current->mm->call_dl_resolve;
6677 + up_read(&current->mm->mmap_sem);
6678 + if (likely(call_dl_resolve))
6679 + goto emulate;
6680 +
6681 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
6682 +
6683 + down_write(&current->mm->mmap_sem);
6684 + if (current->mm->call_dl_resolve) {
6685 + call_dl_resolve = current->mm->call_dl_resolve;
6686 + up_write(&current->mm->mmap_sem);
6687 + if (vma)
6688 + kmem_cache_free(vm_area_cachep, vma);
6689 + goto emulate;
6690 + }
6691 +
6692 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
6693 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
6694 + up_write(&current->mm->mmap_sem);
6695 + if (vma)
6696 + kmem_cache_free(vm_area_cachep, vma);
6697 + return 1;
6698 + }
6699 +
6700 + if (pax_insert_vma(vma, call_dl_resolve)) {
6701 + up_write(&current->mm->mmap_sem);
6702 + kmem_cache_free(vm_area_cachep, vma);
6703 + return 1;
6704 + }
6705 +
6706 + current->mm->call_dl_resolve = call_dl_resolve;
6707 + up_write(&current->mm->mmap_sem);
6708 +
6709 +emulate:
6710 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6711 + regs->pc = call_dl_resolve;
6712 + regs->npc = addr+4;
6713 + return 3;
6714 + }
6715 +#endif
6716 +
6717 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
6718 + if ((save & 0xFFC00000U) == 0x05000000U &&
6719 + (call & 0xFFFFE000U) == 0x85C0A000U &&
6720 + nop == 0x01000000U)
6721 + {
6722 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6723 + regs->u_regs[UREG_G2] = addr + 4;
6724 + addr = (save & 0x003FFFFFU) << 10;
6725 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6726 + regs->pc = addr;
6727 + regs->npc = addr+4;
6728 + return 3;
6729 + }
6730 + }
6731 + } while (0);
6732 +
6733 + do { /* PaX: unpatched PLT emulation step 2 */
6734 + unsigned int save, call, nop;
6735 +
6736 + err = get_user(save, (unsigned int *)(regs->pc-4));
6737 + err |= get_user(call, (unsigned int *)regs->pc);
6738 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
6739 + if (err)
6740 + break;
6741 +
6742 + if (save == 0x9DE3BFA8U &&
6743 + (call & 0xC0000000U) == 0x40000000U &&
6744 + nop == 0x01000000U)
6745 + {
6746 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
6747 +
6748 + regs->u_regs[UREG_RETPC] = regs->pc;
6749 + regs->pc = dl_resolve;
6750 + regs->npc = dl_resolve+4;
6751 + return 3;
6752 + }
6753 + } while (0);
6754 +#endif
6755 +
6756 + return 1;
6757 +}
6758 +
6759 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6760 +{
6761 + unsigned long i;
6762 +
6763 + printk(KERN_ERR "PAX: bytes at PC: ");
6764 + for (i = 0; i < 8; i++) {
6765 + unsigned int c;
6766 + if (get_user(c, (unsigned int *)pc+i))
6767 + printk(KERN_CONT "???????? ");
6768 + else
6769 + printk(KERN_CONT "%08x ", c);
6770 + }
6771 + printk("\n");
6772 +}
6773 +#endif
6774 +
6775 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
6776 int text_fault)
6777 {
6778 @@ -230,6 +504,24 @@ good_area:
6779 if (!(vma->vm_flags & VM_WRITE))
6780 goto bad_area;
6781 } else {
6782 +
6783 +#ifdef CONFIG_PAX_PAGEEXEC
6784 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
6785 + up_read(&mm->mmap_sem);
6786 + switch (pax_handle_fetch_fault(regs)) {
6787 +
6788 +#ifdef CONFIG_PAX_EMUPLT
6789 + case 2:
6790 + case 3:
6791 + return;
6792 +#endif
6793 +
6794 + }
6795 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
6796 + do_group_exit(SIGKILL);
6797 + }
6798 +#endif
6799 +
6800 /* Allow reads even for write-only mappings */
6801 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
6802 goto bad_area;
6803 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
6804 index 1fe0429..8dd5dd5 100644
6805 --- a/arch/sparc/mm/fault_64.c
6806 +++ b/arch/sparc/mm/fault_64.c
6807 @@ -21,6 +21,9 @@
6808 #include <linux/kprobes.h>
6809 #include <linux/kdebug.h>
6810 #include <linux/percpu.h>
6811 +#include <linux/slab.h>
6812 +#include <linux/pagemap.h>
6813 +#include <linux/compiler.h>
6814
6815 #include <asm/page.h>
6816 #include <asm/pgtable.h>
6817 @@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
6818 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
6819 regs->tpc);
6820 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
6821 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
6822 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
6823 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
6824 dump_stack();
6825 unhandled_fault(regs->tpc, current, regs);
6826 @@ -272,6 +275,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
6827 show_regs(regs);
6828 }
6829
6830 +#ifdef CONFIG_PAX_PAGEEXEC
6831 +#ifdef CONFIG_PAX_DLRESOLVE
6832 +static void pax_emuplt_close(struct vm_area_struct *vma)
6833 +{
6834 + vma->vm_mm->call_dl_resolve = 0UL;
6835 +}
6836 +
6837 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6838 +{
6839 + unsigned int *kaddr;
6840 +
6841 + vmf->page = alloc_page(GFP_HIGHUSER);
6842 + if (!vmf->page)
6843 + return VM_FAULT_OOM;
6844 +
6845 + kaddr = kmap(vmf->page);
6846 + memset(kaddr, 0, PAGE_SIZE);
6847 + kaddr[0] = 0x9DE3BFA8U; /* save */
6848 + flush_dcache_page(vmf->page);
6849 + kunmap(vmf->page);
6850 + return VM_FAULT_MAJOR;
6851 +}
6852 +
6853 +static const struct vm_operations_struct pax_vm_ops = {
6854 + .close = pax_emuplt_close,
6855 + .fault = pax_emuplt_fault
6856 +};
6857 +
6858 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6859 +{
6860 + int ret;
6861 +
6862 + INIT_LIST_HEAD(&vma->anon_vma_chain);
6863 + vma->vm_mm = current->mm;
6864 + vma->vm_start = addr;
6865 + vma->vm_end = addr + PAGE_SIZE;
6866 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6867 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6868 + vma->vm_ops = &pax_vm_ops;
6869 +
6870 + ret = insert_vm_struct(current->mm, vma);
6871 + if (ret)
6872 + return ret;
6873 +
6874 + ++current->mm->total_vm;
6875 + return 0;
6876 +}
6877 +#endif
6878 +
6879 +/*
6880 + * PaX: decide what to do with offenders (regs->tpc = fault address)
6881 + *
6882 + * returns 1 when task should be killed
6883 + * 2 when patched PLT trampoline was detected
6884 + * 3 when unpatched PLT trampoline was detected
6885 + */
6886 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6887 +{
6888 +
6889 +#ifdef CONFIG_PAX_EMUPLT
6890 + int err;
6891 +
6892 + do { /* PaX: patched PLT emulation #1 */
6893 + unsigned int sethi1, sethi2, jmpl;
6894 +
6895 + err = get_user(sethi1, (unsigned int *)regs->tpc);
6896 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
6897 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
6898 +
6899 + if (err)
6900 + break;
6901 +
6902 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6903 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
6904 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
6905 + {
6906 + unsigned long addr;
6907 +
6908 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6909 + addr = regs->u_regs[UREG_G1];
6910 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6911 +
6912 + if (test_thread_flag(TIF_32BIT))
6913 + addr &= 0xFFFFFFFFUL;
6914 +
6915 + regs->tpc = addr;
6916 + regs->tnpc = addr+4;
6917 + return 2;
6918 + }
6919 + } while (0);
6920 +
6921 + do { /* PaX: patched PLT emulation #2 */
6922 + unsigned int ba;
6923 +
6924 + err = get_user(ba, (unsigned int *)regs->tpc);
6925 +
6926 + if (err)
6927 + break;
6928 +
6929 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
6930 + unsigned long addr;
6931 +
6932 + if ((ba & 0xFFC00000U) == 0x30800000U)
6933 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
6934 + else
6935 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6936 +
6937 + if (test_thread_flag(TIF_32BIT))
6938 + addr &= 0xFFFFFFFFUL;
6939 +
6940 + regs->tpc = addr;
6941 + regs->tnpc = addr+4;
6942 + return 2;
6943 + }
6944 + } while (0);
6945 +
6946 + do { /* PaX: patched PLT emulation #3 */
6947 + unsigned int sethi, bajmpl, nop;
6948 +
6949 + err = get_user(sethi, (unsigned int *)regs->tpc);
6950 + err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
6951 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6952 +
6953 + if (err)
6954 + break;
6955 +
6956 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6957 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
6958 + nop == 0x01000000U)
6959 + {
6960 + unsigned long addr;
6961 +
6962 + addr = (sethi & 0x003FFFFFU) << 10;
6963 + regs->u_regs[UREG_G1] = addr;
6964 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
6965 + addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6966 + else
6967 + addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6968 +
6969 + if (test_thread_flag(TIF_32BIT))
6970 + addr &= 0xFFFFFFFFUL;
6971 +
6972 + regs->tpc = addr;
6973 + regs->tnpc = addr+4;
6974 + return 2;
6975 + }
6976 + } while (0);
6977 +
6978 + do { /* PaX: patched PLT emulation #4 */
6979 + unsigned int sethi, mov1, call, mov2;
6980 +
6981 + err = get_user(sethi, (unsigned int *)regs->tpc);
6982 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
6983 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
6984 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
6985 +
6986 + if (err)
6987 + break;
6988 +
6989 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6990 + mov1 == 0x8210000FU &&
6991 + (call & 0xC0000000U) == 0x40000000U &&
6992 + mov2 == 0x9E100001U)
6993 + {
6994 + unsigned long addr;
6995 +
6996 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
6997 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
6998 +
6999 + if (test_thread_flag(TIF_32BIT))
7000 + addr &= 0xFFFFFFFFUL;
7001 +
7002 + regs->tpc = addr;
7003 + regs->tnpc = addr+4;
7004 + return 2;
7005 + }
7006 + } while (0);
7007 +
7008 + do { /* PaX: patched PLT emulation #5 */
7009 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
7010 +
7011 + err = get_user(sethi, (unsigned int *)regs->tpc);
7012 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
7013 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
7014 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
7015 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
7016 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
7017 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
7018 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
7019 +
7020 + if (err)
7021 + break;
7022 +
7023 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7024 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
7025 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7026 + (or1 & 0xFFFFE000U) == 0x82106000U &&
7027 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
7028 + sllx == 0x83287020U &&
7029 + jmpl == 0x81C04005U &&
7030 + nop == 0x01000000U)
7031 + {
7032 + unsigned long addr;
7033 +
7034 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7035 + regs->u_regs[UREG_G1] <<= 32;
7036 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7037 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7038 + regs->tpc = addr;
7039 + regs->tnpc = addr+4;
7040 + return 2;
7041 + }
7042 + } while (0);
7043 +
7044 + do { /* PaX: patched PLT emulation #6 */
7045 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
7046 +
7047 + err = get_user(sethi, (unsigned int *)regs->tpc);
7048 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
7049 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
7050 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
7051 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
7052 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
7053 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
7054 +
7055 + if (err)
7056 + break;
7057 +
7058 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7059 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
7060 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7061 + sllx == 0x83287020U &&
7062 + (or & 0xFFFFE000U) == 0x8A116000U &&
7063 + jmpl == 0x81C04005U &&
7064 + nop == 0x01000000U)
7065 + {
7066 + unsigned long addr;
7067 +
7068 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
7069 + regs->u_regs[UREG_G1] <<= 32;
7070 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
7071 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7072 + regs->tpc = addr;
7073 + regs->tnpc = addr+4;
7074 + return 2;
7075 + }
7076 + } while (0);
7077 +
7078 + do { /* PaX: unpatched PLT emulation step 1 */
7079 + unsigned int sethi, ba, nop;
7080 +
7081 + err = get_user(sethi, (unsigned int *)regs->tpc);
7082 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7083 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7084 +
7085 + if (err)
7086 + break;
7087 +
7088 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7089 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
7090 + nop == 0x01000000U)
7091 + {
7092 + unsigned long addr;
7093 + unsigned int save, call;
7094 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
7095 +
7096 + if ((ba & 0xFFC00000U) == 0x30800000U)
7097 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
7098 + else
7099 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7100 +
7101 + if (test_thread_flag(TIF_32BIT))
7102 + addr &= 0xFFFFFFFFUL;
7103 +
7104 + err = get_user(save, (unsigned int *)addr);
7105 + err |= get_user(call, (unsigned int *)(addr+4));
7106 + err |= get_user(nop, (unsigned int *)(addr+8));
7107 + if (err)
7108 + break;
7109 +
7110 +#ifdef CONFIG_PAX_DLRESOLVE
7111 + if (save == 0x9DE3BFA8U &&
7112 + (call & 0xC0000000U) == 0x40000000U &&
7113 + nop == 0x01000000U)
7114 + {
7115 + struct vm_area_struct *vma;
7116 + unsigned long call_dl_resolve;
7117 +
7118 + down_read(&current->mm->mmap_sem);
7119 + call_dl_resolve = current->mm->call_dl_resolve;
7120 + up_read(&current->mm->mmap_sem);
7121 + if (likely(call_dl_resolve))
7122 + goto emulate;
7123 +
7124 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
7125 +
7126 + down_write(&current->mm->mmap_sem);
7127 + if (current->mm->call_dl_resolve) {
7128 + call_dl_resolve = current->mm->call_dl_resolve;
7129 + up_write(&current->mm->mmap_sem);
7130 + if (vma)
7131 + kmem_cache_free(vm_area_cachep, vma);
7132 + goto emulate;
7133 + }
7134 +
7135 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
7136 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
7137 + up_write(&current->mm->mmap_sem);
7138 + if (vma)
7139 + kmem_cache_free(vm_area_cachep, vma);
7140 + return 1;
7141 + }
7142 +
7143 + if (pax_insert_vma(vma, call_dl_resolve)) {
7144 + up_write(&current->mm->mmap_sem);
7145 + kmem_cache_free(vm_area_cachep, vma);
7146 + return 1;
7147 + }
7148 +
7149 + current->mm->call_dl_resolve = call_dl_resolve;
7150 + up_write(&current->mm->mmap_sem);
7151 +
7152 +emulate:
7153 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7154 + regs->tpc = call_dl_resolve;
7155 + regs->tnpc = addr+4;
7156 + return 3;
7157 + }
7158 +#endif
7159 +
7160 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
7161 + if ((save & 0xFFC00000U) == 0x05000000U &&
7162 + (call & 0xFFFFE000U) == 0x85C0A000U &&
7163 + nop == 0x01000000U)
7164 + {
7165 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7166 + regs->u_regs[UREG_G2] = addr + 4;
7167 + addr = (save & 0x003FFFFFU) << 10;
7168 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
7169 +
7170 + if (test_thread_flag(TIF_32BIT))
7171 + addr &= 0xFFFFFFFFUL;
7172 +
7173 + regs->tpc = addr;
7174 + regs->tnpc = addr+4;
7175 + return 3;
7176 + }
7177 +
7178 + /* PaX: 64-bit PLT stub */
7179 + err = get_user(sethi1, (unsigned int *)addr);
7180 + err |= get_user(sethi2, (unsigned int *)(addr+4));
7181 + err |= get_user(or1, (unsigned int *)(addr+8));
7182 + err |= get_user(or2, (unsigned int *)(addr+12));
7183 + err |= get_user(sllx, (unsigned int *)(addr+16));
7184 + err |= get_user(add, (unsigned int *)(addr+20));
7185 + err |= get_user(jmpl, (unsigned int *)(addr+24));
7186 + err |= get_user(nop, (unsigned int *)(addr+28));
7187 + if (err)
7188 + break;
7189 +
7190 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
7191 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7192 + (or1 & 0xFFFFE000U) == 0x88112000U &&
7193 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
7194 + sllx == 0x89293020U &&
7195 + add == 0x8A010005U &&
7196 + jmpl == 0x89C14000U &&
7197 + nop == 0x01000000U)
7198 + {
7199 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7200 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7201 + regs->u_regs[UREG_G4] <<= 32;
7202 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7203 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
7204 + regs->u_regs[UREG_G4] = addr + 24;
7205 + addr = regs->u_regs[UREG_G5];
7206 + regs->tpc = addr;
7207 + regs->tnpc = addr+4;
7208 + return 3;
7209 + }
7210 + }
7211 + } while (0);
7212 +
7213 +#ifdef CONFIG_PAX_DLRESOLVE
7214 + do { /* PaX: unpatched PLT emulation step 2 */
7215 + unsigned int save, call, nop;
7216 +
7217 + err = get_user(save, (unsigned int *)(regs->tpc-4));
7218 + err |= get_user(call, (unsigned int *)regs->tpc);
7219 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
7220 + if (err)
7221 + break;
7222 +
7223 + if (save == 0x9DE3BFA8U &&
7224 + (call & 0xC0000000U) == 0x40000000U &&
7225 + nop == 0x01000000U)
7226 + {
7227 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
7228 +
7229 + if (test_thread_flag(TIF_32BIT))
7230 + dl_resolve &= 0xFFFFFFFFUL;
7231 +
7232 + regs->u_regs[UREG_RETPC] = regs->tpc;
7233 + regs->tpc = dl_resolve;
7234 + regs->tnpc = dl_resolve+4;
7235 + return 3;
7236 + }
7237 + } while (0);
7238 +#endif
7239 +
7240 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
7241 + unsigned int sethi, ba, nop;
7242 +
7243 + err = get_user(sethi, (unsigned int *)regs->tpc);
7244 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7245 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7246 +
7247 + if (err)
7248 + break;
7249 +
7250 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7251 + (ba & 0xFFF00000U) == 0x30600000U &&
7252 + nop == 0x01000000U)
7253 + {
7254 + unsigned long addr;
7255 +
7256 + addr = (sethi & 0x003FFFFFU) << 10;
7257 + regs->u_regs[UREG_G1] = addr;
7258 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7259 +
7260 + if (test_thread_flag(TIF_32BIT))
7261 + addr &= 0xFFFFFFFFUL;
7262 +
7263 + regs->tpc = addr;
7264 + regs->tnpc = addr+4;
7265 + return 2;
7266 + }
7267 + } while (0);
7268 +
7269 +#endif
7270 +
7271 + return 1;
7272 +}
7273 +
7274 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7275 +{
7276 + unsigned long i;
7277 +
7278 + printk(KERN_ERR "PAX: bytes at PC: ");
7279 + for (i = 0; i < 8; i++) {
7280 + unsigned int c;
7281 + if (get_user(c, (unsigned int *)pc+i))
7282 + printk(KERN_CONT "???????? ");
7283 + else
7284 + printk(KERN_CONT "%08x ", c);
7285 + }
7286 + printk("\n");
7287 +}
7288 +#endif
7289 +
7290 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
7291 {
7292 struct mm_struct *mm = current->mm;
7293 @@ -343,6 +806,29 @@ retry:
7294 if (!vma)
7295 goto bad_area;
7296
7297 +#ifdef CONFIG_PAX_PAGEEXEC
7298 + /* PaX: detect ITLB misses on non-exec pages */
7299 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
7300 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
7301 + {
7302 + if (address != regs->tpc)
7303 + goto good_area;
7304 +
7305 + up_read(&mm->mmap_sem);
7306 + switch (pax_handle_fetch_fault(regs)) {
7307 +
7308 +#ifdef CONFIG_PAX_EMUPLT
7309 + case 2:
7310 + case 3:
7311 + return;
7312 +#endif
7313 +
7314 + }
7315 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
7316 + do_group_exit(SIGKILL);
7317 + }
7318 +#endif
7319 +
7320 /* Pure DTLB misses do not tell us whether the fault causing
7321 * load/store/atomic was a write or not, it only says that there
7322 * was no match. So in such a case we (carefully) read the
7323 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
7324 index 07e1453..0a7d9e9 100644
7325 --- a/arch/sparc/mm/hugetlbpage.c
7326 +++ b/arch/sparc/mm/hugetlbpage.c
7327 @@ -67,7 +67,7 @@ full_search:
7328 }
7329 return -ENOMEM;
7330 }
7331 - if (likely(!vma || addr + len <= vma->vm_start)) {
7332 + if (likely(check_heap_stack_gap(vma, addr, len))) {
7333 /*
7334 * Remember the place where we stopped the search:
7335 */
7336 @@ -106,7 +106,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7337 /* make sure it can fit in the remaining address space */
7338 if (likely(addr > len)) {
7339 vma = find_vma(mm, addr-len);
7340 - if (!vma || addr <= vma->vm_start) {
7341 + if (check_heap_stack_gap(vma, addr - len, len)) {
7342 /* remember the address as a hint for next time */
7343 return (mm->free_area_cache = addr-len);
7344 }
7345 @@ -115,16 +115,17 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7346 if (unlikely(mm->mmap_base < len))
7347 goto bottomup;
7348
7349 - addr = (mm->mmap_base-len) & HPAGE_MASK;
7350 + addr = mm->mmap_base - len;
7351
7352 do {
7353 + addr &= HPAGE_MASK;
7354 /*
7355 * Lookup failure means no vma is above this address,
7356 * else if new region fits below vma->vm_start,
7357 * return with success:
7358 */
7359 vma = find_vma(mm, addr);
7360 - if (likely(!vma || addr+len <= vma->vm_start)) {
7361 + if (likely(check_heap_stack_gap(vma, addr, len))) {
7362 /* remember the address as a hint for next time */
7363 return (mm->free_area_cache = addr);
7364 }
7365 @@ -134,8 +135,8 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7366 mm->cached_hole_size = vma->vm_start - addr;
7367
7368 /* try just below the current vma->vm_start */
7369 - addr = (vma->vm_start-len) & HPAGE_MASK;
7370 - } while (likely(len < vma->vm_start));
7371 + addr = skip_heap_stack_gap(vma, len);
7372 + } while (!IS_ERR_VALUE(addr));
7373
7374 bottomup:
7375 /*
7376 @@ -181,8 +182,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
7377 if (addr) {
7378 addr = ALIGN(addr, HPAGE_SIZE);
7379 vma = find_vma(mm, addr);
7380 - if (task_size - len >= addr &&
7381 - (!vma || addr + len <= vma->vm_start))
7382 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
7383 return addr;
7384 }
7385 if (mm->get_unmapped_area == arch_get_unmapped_area)
7386 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
7387 index f4500c6..889656c 100644
7388 --- a/arch/tile/include/asm/atomic_64.h
7389 +++ b/arch/tile/include/asm/atomic_64.h
7390 @@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
7391
7392 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7393
7394 +#define atomic64_read_unchecked(v) atomic64_read(v)
7395 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7396 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7397 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7398 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7399 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
7400 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7401 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
7402 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7403 +
7404 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
7405 #define smp_mb__before_atomic_dec() smp_mb()
7406 #define smp_mb__after_atomic_dec() smp_mb()
7407 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
7408 index a9a5299..0fce79e 100644
7409 --- a/arch/tile/include/asm/cache.h
7410 +++ b/arch/tile/include/asm/cache.h
7411 @@ -15,11 +15,12 @@
7412 #ifndef _ASM_TILE_CACHE_H
7413 #define _ASM_TILE_CACHE_H
7414
7415 +#include <linux/const.h>
7416 #include <arch/chip.h>
7417
7418 /* bytes per L1 data cache line */
7419 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
7420 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7421 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7422
7423 /* bytes per L2 cache line */
7424 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
7425 diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
7426 index 9ab078a..d6635c2 100644
7427 --- a/arch/tile/include/asm/uaccess.h
7428 +++ b/arch/tile/include/asm/uaccess.h
7429 @@ -403,9 +403,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
7430 const void __user *from,
7431 unsigned long n)
7432 {
7433 - int sz = __compiletime_object_size(to);
7434 + size_t sz = __compiletime_object_size(to);
7435
7436 - if (likely(sz == -1 || sz >= n))
7437 + if (likely(sz == (size_t)-1 || sz >= n))
7438 n = _copy_from_user(to, from, n);
7439 else
7440 copy_from_user_overflow();
7441 diff --git a/arch/um/Makefile b/arch/um/Makefile
7442 index 0970910..9f65c40 100644
7443 --- a/arch/um/Makefile
7444 +++ b/arch/um/Makefile
7445 @@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
7446 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
7447 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
7448
7449 +ifdef CONSTIFY_PLUGIN
7450 +USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
7451 +endif
7452 +
7453 #This will adjust *FLAGS accordingly to the platform.
7454 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
7455
7456 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
7457 index 19e1bdd..3665b77 100644
7458 --- a/arch/um/include/asm/cache.h
7459 +++ b/arch/um/include/asm/cache.h
7460 @@ -1,6 +1,7 @@
7461 #ifndef __UM_CACHE_H
7462 #define __UM_CACHE_H
7463
7464 +#include <linux/const.h>
7465
7466 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
7467 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
7468 @@ -12,6 +13,6 @@
7469 # define L1_CACHE_SHIFT 5
7470 #endif
7471
7472 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7473 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7474
7475 #endif
7476 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
7477 index 2e0a6b1..a64d0f5 100644
7478 --- a/arch/um/include/asm/kmap_types.h
7479 +++ b/arch/um/include/asm/kmap_types.h
7480 @@ -8,6 +8,6 @@
7481
7482 /* No more #include "asm/arch/kmap_types.h" ! */
7483
7484 -#define KM_TYPE_NR 14
7485 +#define KM_TYPE_NR 15
7486
7487 #endif
7488 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
7489 index 7cfc3ce..cbd1a58 100644
7490 --- a/arch/um/include/asm/page.h
7491 +++ b/arch/um/include/asm/page.h
7492 @@ -14,6 +14,9 @@
7493 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
7494 #define PAGE_MASK (~(PAGE_SIZE-1))
7495
7496 +#define ktla_ktva(addr) (addr)
7497 +#define ktva_ktla(addr) (addr)
7498 +
7499 #ifndef __ASSEMBLY__
7500
7501 struct page;
7502 diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
7503 index 0032f92..cd151e0 100644
7504 --- a/arch/um/include/asm/pgtable-3level.h
7505 +++ b/arch/um/include/asm/pgtable-3level.h
7506 @@ -58,6 +58,7 @@
7507 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
7508 #define pud_populate(mm, pud, pmd) \
7509 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
7510 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
7511
7512 #ifdef CONFIG_64BIT
7513 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
7514 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
7515 index c5f5afa..6abce4b 100644
7516 --- a/arch/um/kernel/process.c
7517 +++ b/arch/um/kernel/process.c
7518 @@ -402,22 +402,6 @@ int singlestepping(void * t)
7519 return 2;
7520 }
7521
7522 -/*
7523 - * Only x86 and x86_64 have an arch_align_stack().
7524 - * All other arches have "#define arch_align_stack(x) (x)"
7525 - * in their asm/system.h
7526 - * As this is included in UML from asm-um/system-generic.h,
7527 - * we can use it to behave as the subarch does.
7528 - */
7529 -#ifndef arch_align_stack
7530 -unsigned long arch_align_stack(unsigned long sp)
7531 -{
7532 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7533 - sp -= get_random_int() % 8192;
7534 - return sp & ~0xf;
7535 -}
7536 -#endif
7537 -
7538 unsigned long get_wchan(struct task_struct *p)
7539 {
7540 unsigned long stack_page, sp, ip;
7541 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
7542 index ad8f795..2c7eec6 100644
7543 --- a/arch/unicore32/include/asm/cache.h
7544 +++ b/arch/unicore32/include/asm/cache.h
7545 @@ -12,8 +12,10 @@
7546 #ifndef __UNICORE_CACHE_H__
7547 #define __UNICORE_CACHE_H__
7548
7549 -#define L1_CACHE_SHIFT (5)
7550 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7551 +#include <linux/const.h>
7552 +
7553 +#define L1_CACHE_SHIFT 5
7554 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7555
7556 /*
7557 * Memory returned by kmalloc() may be used for DMA, so we must make
7558 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
7559 index 50a1d1f..c26369f 100644
7560 --- a/arch/x86/Kconfig
7561 +++ b/arch/x86/Kconfig
7562 @@ -220,7 +220,7 @@ config X86_HT
7563
7564 config X86_32_LAZY_GS
7565 def_bool y
7566 - depends on X86_32 && !CC_STACKPROTECTOR
7567 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
7568
7569 config ARCH_HWEIGHT_CFLAGS
7570 string
7571 @@ -1049,7 +1049,7 @@ choice
7572
7573 config NOHIGHMEM
7574 bool "off"
7575 - depends on !X86_NUMAQ
7576 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7577 ---help---
7578 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
7579 However, the address space of 32-bit x86 processors is only 4
7580 @@ -1086,7 +1086,7 @@ config NOHIGHMEM
7581
7582 config HIGHMEM4G
7583 bool "4GB"
7584 - depends on !X86_NUMAQ
7585 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7586 ---help---
7587 Select this if you have a 32-bit processor and between 1 and 4
7588 gigabytes of physical RAM.
7589 @@ -1140,7 +1140,7 @@ config PAGE_OFFSET
7590 hex
7591 default 0xB0000000 if VMSPLIT_3G_OPT
7592 default 0x80000000 if VMSPLIT_2G
7593 - default 0x78000000 if VMSPLIT_2G_OPT
7594 + default 0x70000000 if VMSPLIT_2G_OPT
7595 default 0x40000000 if VMSPLIT_1G
7596 default 0xC0000000
7597 depends on X86_32
7598 @@ -1528,6 +1528,7 @@ config SECCOMP
7599
7600 config CC_STACKPROTECTOR
7601 bool "Enable -fstack-protector buffer overflow detection"
7602 + depends on X86_64 || !PAX_MEMORY_UDEREF
7603 ---help---
7604 This option turns on the -fstack-protector GCC feature. This
7605 feature puts, at the beginning of functions, a canary value on
7606 @@ -1585,6 +1586,7 @@ config KEXEC_JUMP
7607 config PHYSICAL_START
7608 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
7609 default "0x1000000"
7610 + range 0x400000 0x40000000
7611 ---help---
7612 This gives the physical address where the kernel is loaded.
7613
7614 @@ -1648,6 +1650,7 @@ config X86_NEED_RELOCS
7615 config PHYSICAL_ALIGN
7616 hex "Alignment value to which kernel should be aligned" if X86_32
7617 default "0x1000000"
7618 + range 0x400000 0x1000000 if PAX_KERNEXEC
7619 range 0x2000 0x1000000
7620 ---help---
7621 This value puts the alignment restrictions on physical address
7622 @@ -1679,9 +1682,10 @@ config HOTPLUG_CPU
7623 Say N if you want to disable CPU hotplug.
7624
7625 config COMPAT_VDSO
7626 - def_bool y
7627 + def_bool n
7628 prompt "Compat VDSO support"
7629 depends on X86_32 || IA32_EMULATION
7630 + depends on !PAX_NOEXEC && !PAX_MEMORY_UDEREF
7631 ---help---
7632 Map the 32-bit VDSO to the predictable old-style address too.
7633
7634 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
7635 index 706e12e..62e4feb 100644
7636 --- a/arch/x86/Kconfig.cpu
7637 +++ b/arch/x86/Kconfig.cpu
7638 @@ -334,7 +334,7 @@ config X86_PPRO_FENCE
7639
7640 config X86_F00F_BUG
7641 def_bool y
7642 - depends on M586MMX || M586TSC || M586 || M486 || M386
7643 + depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
7644
7645 config X86_INVD_BUG
7646 def_bool y
7647 @@ -358,7 +358,7 @@ config X86_POPAD_OK
7648
7649 config X86_ALIGNMENT_16
7650 def_bool y
7651 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7652 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7653
7654 config X86_INTEL_USERCOPY
7655 def_bool y
7656 @@ -404,7 +404,7 @@ config X86_CMPXCHG64
7657 # generates cmov.
7658 config X86_CMOV
7659 def_bool y
7660 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7661 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7662
7663 config X86_MINIMUM_CPU_FAMILY
7664 int
7665 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
7666 index b322f12..652d0d9 100644
7667 --- a/arch/x86/Kconfig.debug
7668 +++ b/arch/x86/Kconfig.debug
7669 @@ -84,7 +84,7 @@ config X86_PTDUMP
7670 config DEBUG_RODATA
7671 bool "Write protect kernel read-only data structures"
7672 default y
7673 - depends on DEBUG_KERNEL
7674 + depends on DEBUG_KERNEL && BROKEN
7675 ---help---
7676 Mark the kernel read-only data as write-protected in the pagetables,
7677 in order to catch accidental (and incorrect) writes to such const
7678 @@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
7679
7680 config DEBUG_SET_MODULE_RONX
7681 bool "Set loadable kernel module data as NX and text as RO"
7682 - depends on MODULES
7683 + depends on MODULES && BROKEN
7684 ---help---
7685 This option helps catch unintended modifications to loadable
7686 kernel module's text and read-only data. It also prevents execution
7687 @@ -294,7 +294,7 @@ config OPTIMIZE_INLINING
7688
7689 config DEBUG_STRICT_USER_COPY_CHECKS
7690 bool "Strict copy size checks"
7691 - depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
7692 + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
7693 ---help---
7694 Enabling this option turns a certain set of sanity checks for user
7695 copy operations into compile time failures.
7696 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
7697 index 05afcca..b6ecb51 100644
7698 --- a/arch/x86/Makefile
7699 +++ b/arch/x86/Makefile
7700 @@ -50,6 +50,7 @@ else
7701 UTS_MACHINE := x86_64
7702 CHECKFLAGS += -D__x86_64__ -m64
7703
7704 + biarch := $(call cc-option,-m64)
7705 KBUILD_AFLAGS += -m64
7706 KBUILD_CFLAGS += -m64
7707
7708 @@ -229,3 +230,12 @@ define archhelp
7709 echo ' FDARGS="..." arguments for the booted kernel'
7710 echo ' FDINITRD=file initrd for the booted kernel'
7711 endef
7712 +
7713 +define OLD_LD
7714 +
7715 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
7716 +*** Please upgrade your binutils to 2.18 or newer
7717 +endef
7718 +
7719 +archprepare:
7720 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
7721 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
7722 index f7535be..37db2d1 100644
7723 --- a/arch/x86/boot/Makefile
7724 +++ b/arch/x86/boot/Makefile
7725 @@ -64,6 +64,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
7726 $(call cc-option, -fno-stack-protector) \
7727 $(call cc-option, -mpreferred-stack-boundary=2)
7728 KBUILD_CFLAGS += $(call cc-option, -m32)
7729 +ifdef CONSTIFY_PLUGIN
7730 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
7731 +endif
7732 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7733 GCOV_PROFILE := n
7734
7735 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
7736 index 878e4b9..20537ab 100644
7737 --- a/arch/x86/boot/bitops.h
7738 +++ b/arch/x86/boot/bitops.h
7739 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7740 u8 v;
7741 const u32 *p = (const u32 *)addr;
7742
7743 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7744 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7745 return v;
7746 }
7747
7748 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7749
7750 static inline void set_bit(int nr, void *addr)
7751 {
7752 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7753 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7754 }
7755
7756 #endif /* BOOT_BITOPS_H */
7757 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
7758 index 18997e5..83d9c67 100644
7759 --- a/arch/x86/boot/boot.h
7760 +++ b/arch/x86/boot/boot.h
7761 @@ -85,7 +85,7 @@ static inline void io_delay(void)
7762 static inline u16 ds(void)
7763 {
7764 u16 seg;
7765 - asm("movw %%ds,%0" : "=rm" (seg));
7766 + asm volatile("movw %%ds,%0" : "=rm" (seg));
7767 return seg;
7768 }
7769
7770 @@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
7771 static inline int memcmp(const void *s1, const void *s2, size_t len)
7772 {
7773 u8 diff;
7774 - asm("repe; cmpsb; setnz %0"
7775 + asm volatile("repe; cmpsb; setnz %0"
7776 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
7777 return diff;
7778 }
7779 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
7780 index 8a84501..b2d165f 100644
7781 --- a/arch/x86/boot/compressed/Makefile
7782 +++ b/arch/x86/boot/compressed/Makefile
7783 @@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
7784 KBUILD_CFLAGS += $(cflags-y)
7785 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
7786 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
7787 +ifdef CONSTIFY_PLUGIN
7788 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
7789 +endif
7790
7791 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7792 GCOV_PROFILE := n
7793 diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
7794 index 90201aa..be1de62 100644
7795 --- a/arch/x86/boot/compressed/eboot.c
7796 +++ b/arch/x86/boot/compressed/eboot.c
7797 @@ -144,7 +144,6 @@ again:
7798 *addr = max_addr;
7799 }
7800
7801 -free_pool:
7802 efi_call_phys1(sys_table->boottime->free_pool, map);
7803
7804 fail:
7805 @@ -208,7 +207,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
7806 if (i == map_size / desc_size)
7807 status = EFI_NOT_FOUND;
7808
7809 -free_pool:
7810 efi_call_phys1(sys_table->boottime->free_pool, map);
7811 fail:
7812 return status;
7813 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
7814 index aa4aaf1..6656f2f 100644
7815 --- a/arch/x86/boot/compressed/head_32.S
7816 +++ b/arch/x86/boot/compressed/head_32.S
7817 @@ -116,7 +116,7 @@ preferred_addr:
7818 notl %eax
7819 andl %eax, %ebx
7820 #else
7821 - movl $LOAD_PHYSICAL_ADDR, %ebx
7822 + movl $____LOAD_PHYSICAL_ADDR, %ebx
7823 #endif
7824
7825 /* Target address to relocate to for decompression */
7826 @@ -202,7 +202,7 @@ relocated:
7827 * and where it was actually loaded.
7828 */
7829 movl %ebp, %ebx
7830 - subl $LOAD_PHYSICAL_ADDR, %ebx
7831 + subl $____LOAD_PHYSICAL_ADDR, %ebx
7832 jz 2f /* Nothing to be done if loaded at compiled addr. */
7833 /*
7834 * Process relocations.
7835 @@ -210,8 +210,7 @@ relocated:
7836
7837 1: subl $4, %edi
7838 movl (%edi), %ecx
7839 - testl %ecx, %ecx
7840 - jz 2f
7841 + jecxz 2f
7842 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
7843 jmp 1b
7844 2:
7845 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
7846 index 2c4b171..e1fa5b1 100644
7847 --- a/arch/x86/boot/compressed/head_64.S
7848 +++ b/arch/x86/boot/compressed/head_64.S
7849 @@ -91,7 +91,7 @@ ENTRY(startup_32)
7850 notl %eax
7851 andl %eax, %ebx
7852 #else
7853 - movl $LOAD_PHYSICAL_ADDR, %ebx
7854 + movl $____LOAD_PHYSICAL_ADDR, %ebx
7855 #endif
7856
7857 /* Target address to relocate to for decompression */
7858 @@ -273,7 +273,7 @@ preferred_addr:
7859 notq %rax
7860 andq %rax, %rbp
7861 #else
7862 - movq $LOAD_PHYSICAL_ADDR, %rbp
7863 + movq $____LOAD_PHYSICAL_ADDR, %rbp
7864 #endif
7865
7866 /* Target address to relocate to for decompression */
7867 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
7868 index 88f7ff6..ed695dd 100644
7869 --- a/arch/x86/boot/compressed/misc.c
7870 +++ b/arch/x86/boot/compressed/misc.c
7871 @@ -303,7 +303,7 @@ static void parse_elf(void *output)
7872 case PT_LOAD:
7873 #ifdef CONFIG_RELOCATABLE
7874 dest = output;
7875 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
7876 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
7877 #else
7878 dest = (void *)(phdr->p_paddr);
7879 #endif
7880 @@ -352,7 +352,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
7881 error("Destination address too large");
7882 #endif
7883 #ifndef CONFIG_RELOCATABLE
7884 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
7885 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
7886 error("Wrong destination address");
7887 #endif
7888
7889 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
7890 index 4d3ff03..e4972ff 100644
7891 --- a/arch/x86/boot/cpucheck.c
7892 +++ b/arch/x86/boot/cpucheck.c
7893 @@ -74,7 +74,7 @@ static int has_fpu(void)
7894 u16 fcw = -1, fsw = -1;
7895 u32 cr0;
7896
7897 - asm("movl %%cr0,%0" : "=r" (cr0));
7898 + asm volatile("movl %%cr0,%0" : "=r" (cr0));
7899 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
7900 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
7901 asm volatile("movl %0,%%cr0" : : "r" (cr0));
7902 @@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
7903 {
7904 u32 f0, f1;
7905
7906 - asm("pushfl ; "
7907 + asm volatile("pushfl ; "
7908 "pushfl ; "
7909 "popl %0 ; "
7910 "movl %0,%1 ; "
7911 @@ -115,7 +115,7 @@ static void get_flags(void)
7912 set_bit(X86_FEATURE_FPU, cpu.flags);
7913
7914 if (has_eflag(X86_EFLAGS_ID)) {
7915 - asm("cpuid"
7916 + asm volatile("cpuid"
7917 : "=a" (max_intel_level),
7918 "=b" (cpu_vendor[0]),
7919 "=d" (cpu_vendor[1]),
7920 @@ -124,7 +124,7 @@ static void get_flags(void)
7921
7922 if (max_intel_level >= 0x00000001 &&
7923 max_intel_level <= 0x0000ffff) {
7924 - asm("cpuid"
7925 + asm volatile("cpuid"
7926 : "=a" (tfms),
7927 "=c" (cpu.flags[4]),
7928 "=d" (cpu.flags[0])
7929 @@ -136,7 +136,7 @@ static void get_flags(void)
7930 cpu.model += ((tfms >> 16) & 0xf) << 4;
7931 }
7932
7933 - asm("cpuid"
7934 + asm volatile("cpuid"
7935 : "=a" (max_amd_level)
7936 : "a" (0x80000000)
7937 : "ebx", "ecx", "edx");
7938 @@ -144,7 +144,7 @@ static void get_flags(void)
7939 if (max_amd_level >= 0x80000001 &&
7940 max_amd_level <= 0x8000ffff) {
7941 u32 eax = 0x80000001;
7942 - asm("cpuid"
7943 + asm volatile("cpuid"
7944 : "+a" (eax),
7945 "=c" (cpu.flags[6]),
7946 "=d" (cpu.flags[1])
7947 @@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7948 u32 ecx = MSR_K7_HWCR;
7949 u32 eax, edx;
7950
7951 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7952 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7953 eax &= ~(1 << 15);
7954 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7955 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7956
7957 get_flags(); /* Make sure it really did something */
7958 err = check_flags();
7959 @@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7960 u32 ecx = MSR_VIA_FCR;
7961 u32 eax, edx;
7962
7963 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7964 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7965 eax |= (1<<1)|(1<<7);
7966 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7967 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7968
7969 set_bit(X86_FEATURE_CX8, cpu.flags);
7970 err = check_flags();
7971 @@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7972 u32 eax, edx;
7973 u32 level = 1;
7974
7975 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7976 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7977 - asm("cpuid"
7978 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7979 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7980 + asm volatile("cpuid"
7981 : "+a" (level), "=d" (cpu.flags[0])
7982 : : "ecx", "ebx");
7983 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7984 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7985
7986 err = check_flags();
7987 }
7988 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
7989 index b4e15dd..8ac59ce 100644
7990 --- a/arch/x86/boot/header.S
7991 +++ b/arch/x86/boot/header.S
7992 @@ -391,10 +391,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
7993 # single linked list of
7994 # struct setup_data
7995
7996 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
7997 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
7998
7999 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
8000 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
8001 +#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
8002 +#else
8003 #define VO_INIT_SIZE (VO__end - VO__text)
8004 +#endif
8005 #if ZO_INIT_SIZE > VO_INIT_SIZE
8006 #define INIT_SIZE ZO_INIT_SIZE
8007 #else
8008 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
8009 index db75d07..8e6d0af 100644
8010 --- a/arch/x86/boot/memory.c
8011 +++ b/arch/x86/boot/memory.c
8012 @@ -19,7 +19,7 @@
8013
8014 static int detect_memory_e820(void)
8015 {
8016 - int count = 0;
8017 + unsigned int count = 0;
8018 struct biosregs ireg, oreg;
8019 struct e820entry *desc = boot_params.e820_map;
8020 static struct e820entry buf; /* static so it is zeroed */
8021 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
8022 index 11e8c6e..fdbb1ed 100644
8023 --- a/arch/x86/boot/video-vesa.c
8024 +++ b/arch/x86/boot/video-vesa.c
8025 @@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
8026
8027 boot_params.screen_info.vesapm_seg = oreg.es;
8028 boot_params.screen_info.vesapm_off = oreg.di;
8029 + boot_params.screen_info.vesapm_size = oreg.cx;
8030 }
8031
8032 /*
8033 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
8034 index 43eda28..5ab5fdb 100644
8035 --- a/arch/x86/boot/video.c
8036 +++ b/arch/x86/boot/video.c
8037 @@ -96,7 +96,7 @@ static void store_mode_params(void)
8038 static unsigned int get_entry(void)
8039 {
8040 char entry_buf[4];
8041 - int i, len = 0;
8042 + unsigned int i, len = 0;
8043 int key;
8044 unsigned int v;
8045
8046 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
8047 index 5b577d5..3c1fed4 100644
8048 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
8049 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
8050 @@ -8,6 +8,8 @@
8051 * including this sentence is retained in full.
8052 */
8053
8054 +#include <asm/alternative-asm.h>
8055 +
8056 .extern crypto_ft_tab
8057 .extern crypto_it_tab
8058 .extern crypto_fl_tab
8059 @@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
8060 je B192; \
8061 leaq 32(r9),r9;
8062
8063 +#define ret pax_force_retaddr 0, 1; ret
8064 +
8065 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
8066 movq r1,r2; \
8067 movq r3,r4; \
8068 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
8069 index 3470624..201259d 100644
8070 --- a/arch/x86/crypto/aesni-intel_asm.S
8071 +++ b/arch/x86/crypto/aesni-intel_asm.S
8072 @@ -31,6 +31,7 @@
8073
8074 #include <linux/linkage.h>
8075 #include <asm/inst.h>
8076 +#include <asm/alternative-asm.h>
8077
8078 #ifdef __x86_64__
8079 .data
8080 @@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
8081 pop %r14
8082 pop %r13
8083 pop %r12
8084 + pax_force_retaddr 0, 1
8085 ret
8086 +ENDPROC(aesni_gcm_dec)
8087
8088
8089 /*****************************************************************************
8090 @@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
8091 pop %r14
8092 pop %r13
8093 pop %r12
8094 + pax_force_retaddr 0, 1
8095 ret
8096 +ENDPROC(aesni_gcm_enc)
8097
8098 #endif
8099
8100 @@ -1714,6 +1719,7 @@ _key_expansion_256a:
8101 pxor %xmm1, %xmm0
8102 movaps %xmm0, (TKEYP)
8103 add $0x10, TKEYP
8104 + pax_force_retaddr_bts
8105 ret
8106
8107 .align 4
8108 @@ -1738,6 +1744,7 @@ _key_expansion_192a:
8109 shufps $0b01001110, %xmm2, %xmm1
8110 movaps %xmm1, 0x10(TKEYP)
8111 add $0x20, TKEYP
8112 + pax_force_retaddr_bts
8113 ret
8114
8115 .align 4
8116 @@ -1757,6 +1764,7 @@ _key_expansion_192b:
8117
8118 movaps %xmm0, (TKEYP)
8119 add $0x10, TKEYP
8120 + pax_force_retaddr_bts
8121 ret
8122
8123 .align 4
8124 @@ -1769,6 +1777,7 @@ _key_expansion_256b:
8125 pxor %xmm1, %xmm2
8126 movaps %xmm2, (TKEYP)
8127 add $0x10, TKEYP
8128 + pax_force_retaddr_bts
8129 ret
8130
8131 /*
8132 @@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
8133 #ifndef __x86_64__
8134 popl KEYP
8135 #endif
8136 + pax_force_retaddr 0, 1
8137 ret
8138 +ENDPROC(aesni_set_key)
8139
8140 /*
8141 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
8142 @@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
8143 popl KLEN
8144 popl KEYP
8145 #endif
8146 + pax_force_retaddr 0, 1
8147 ret
8148 +ENDPROC(aesni_enc)
8149
8150 /*
8151 * _aesni_enc1: internal ABI
8152 @@ -1959,6 +1972,7 @@ _aesni_enc1:
8153 AESENC KEY STATE
8154 movaps 0x70(TKEYP), KEY
8155 AESENCLAST KEY STATE
8156 + pax_force_retaddr_bts
8157 ret
8158
8159 /*
8160 @@ -2067,6 +2081,7 @@ _aesni_enc4:
8161 AESENCLAST KEY STATE2
8162 AESENCLAST KEY STATE3
8163 AESENCLAST KEY STATE4
8164 + pax_force_retaddr_bts
8165 ret
8166
8167 /*
8168 @@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
8169 popl KLEN
8170 popl KEYP
8171 #endif
8172 + pax_force_retaddr 0, 1
8173 ret
8174 +ENDPROC(aesni_dec)
8175
8176 /*
8177 * _aesni_dec1: internal ABI
8178 @@ -2146,6 +2163,7 @@ _aesni_dec1:
8179 AESDEC KEY STATE
8180 movaps 0x70(TKEYP), KEY
8181 AESDECLAST KEY STATE
8182 + pax_force_retaddr_bts
8183 ret
8184
8185 /*
8186 @@ -2254,6 +2272,7 @@ _aesni_dec4:
8187 AESDECLAST KEY STATE2
8188 AESDECLAST KEY STATE3
8189 AESDECLAST KEY STATE4
8190 + pax_force_retaddr_bts
8191 ret
8192
8193 /*
8194 @@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
8195 popl KEYP
8196 popl LEN
8197 #endif
8198 + pax_force_retaddr 0, 1
8199 ret
8200 +ENDPROC(aesni_ecb_enc)
8201
8202 /*
8203 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8204 @@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
8205 popl KEYP
8206 popl LEN
8207 #endif
8208 + pax_force_retaddr 0, 1
8209 ret
8210 +ENDPROC(aesni_ecb_dec)
8211
8212 /*
8213 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8214 @@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
8215 popl LEN
8216 popl IVP
8217 #endif
8218 + pax_force_retaddr 0, 1
8219 ret
8220 +ENDPROC(aesni_cbc_enc)
8221
8222 /*
8223 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8224 @@ -2500,7 +2525,9 @@ ENTRY(aesni_cbc_dec)
8225 popl LEN
8226 popl IVP
8227 #endif
8228 + pax_force_retaddr 0, 1
8229 ret
8230 +ENDPROC(aesni_cbc_dec)
8231
8232 #ifdef __x86_64__
8233 .align 16
8234 @@ -2526,6 +2553,7 @@ _aesni_inc_init:
8235 mov $1, TCTR_LOW
8236 MOVQ_R64_XMM TCTR_LOW INC
8237 MOVQ_R64_XMM CTR TCTR_LOW
8238 + pax_force_retaddr_bts
8239 ret
8240
8241 /*
8242 @@ -2554,6 +2582,7 @@ _aesni_inc:
8243 .Linc_low:
8244 movaps CTR, IV
8245 PSHUFB_XMM BSWAP_MASK IV
8246 + pax_force_retaddr_bts
8247 ret
8248
8249 /*
8250 @@ -2614,5 +2643,7 @@ ENTRY(aesni_ctr_enc)
8251 .Lctr_enc_ret:
8252 movups IV, (IVP)
8253 .Lctr_enc_just_ret:
8254 + pax_force_retaddr 0, 1
8255 ret
8256 +ENDPROC(aesni_ctr_enc)
8257 #endif
8258 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8259 index 391d245..67f35c2 100644
8260 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
8261 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8262 @@ -20,6 +20,8 @@
8263 *
8264 */
8265
8266 +#include <asm/alternative-asm.h>
8267 +
8268 .file "blowfish-x86_64-asm.S"
8269 .text
8270
8271 @@ -151,9 +153,11 @@ __blowfish_enc_blk:
8272 jnz __enc_xor;
8273
8274 write_block();
8275 + pax_force_retaddr 0, 1
8276 ret;
8277 __enc_xor:
8278 xor_block();
8279 + pax_force_retaddr 0, 1
8280 ret;
8281
8282 .align 8
8283 @@ -188,6 +192,7 @@ blowfish_dec_blk:
8284
8285 movq %r11, %rbp;
8286
8287 + pax_force_retaddr 0, 1
8288 ret;
8289
8290 /**********************************************************************
8291 @@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
8292
8293 popq %rbx;
8294 popq %rbp;
8295 + pax_force_retaddr 0, 1
8296 ret;
8297
8298 __enc_xor4:
8299 @@ -349,6 +355,7 @@ __enc_xor4:
8300
8301 popq %rbx;
8302 popq %rbp;
8303 + pax_force_retaddr 0, 1
8304 ret;
8305
8306 .align 8
8307 @@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
8308 popq %rbx;
8309 popq %rbp;
8310
8311 + pax_force_retaddr 0, 1
8312 ret;
8313
8314 diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
8315 index 0b33743..7a56206 100644
8316 --- a/arch/x86/crypto/camellia-x86_64-asm_64.S
8317 +++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
8318 @@ -20,6 +20,8 @@
8319 *
8320 */
8321
8322 +#include <asm/alternative-asm.h>
8323 +
8324 .file "camellia-x86_64-asm_64.S"
8325 .text
8326
8327 @@ -229,12 +231,14 @@ __enc_done:
8328 enc_outunpack(mov, RT1);
8329
8330 movq RRBP, %rbp;
8331 + pax_force_retaddr 0, 1
8332 ret;
8333
8334 __enc_xor:
8335 enc_outunpack(xor, RT1);
8336
8337 movq RRBP, %rbp;
8338 + pax_force_retaddr 0, 1
8339 ret;
8340
8341 .global camellia_dec_blk;
8342 @@ -275,6 +279,7 @@ __dec_rounds16:
8343 dec_outunpack();
8344
8345 movq RRBP, %rbp;
8346 + pax_force_retaddr 0, 1
8347 ret;
8348
8349 /**********************************************************************
8350 @@ -468,6 +473,7 @@ __enc2_done:
8351
8352 movq RRBP, %rbp;
8353 popq %rbx;
8354 + pax_force_retaddr 0, 1
8355 ret;
8356
8357 __enc2_xor:
8358 @@ -475,6 +481,7 @@ __enc2_xor:
8359
8360 movq RRBP, %rbp;
8361 popq %rbx;
8362 + pax_force_retaddr 0, 1
8363 ret;
8364
8365 .global camellia_dec_blk_2way;
8366 @@ -517,4 +524,5 @@ __dec2_rounds16:
8367
8368 movq RRBP, %rbp;
8369 movq RXOR, %rbx;
8370 + pax_force_retaddr 0, 1
8371 ret;
8372 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8373 index 6214a9b..1f4fc9a 100644
8374 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
8375 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8376 @@ -1,3 +1,5 @@
8377 +#include <asm/alternative-asm.h>
8378 +
8379 # enter ECRYPT_encrypt_bytes
8380 .text
8381 .p2align 5
8382 @@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
8383 add %r11,%rsp
8384 mov %rdi,%rax
8385 mov %rsi,%rdx
8386 + pax_force_retaddr 0, 1
8387 ret
8388 # bytesatleast65:
8389 ._bytesatleast65:
8390 @@ -891,6 +894,7 @@ ECRYPT_keysetup:
8391 add %r11,%rsp
8392 mov %rdi,%rax
8393 mov %rsi,%rdx
8394 + pax_force_retaddr
8395 ret
8396 # enter ECRYPT_ivsetup
8397 .text
8398 @@ -917,4 +921,5 @@ ECRYPT_ivsetup:
8399 add %r11,%rsp
8400 mov %rdi,%rax
8401 mov %rsi,%rdx
8402 + pax_force_retaddr
8403 ret
8404 diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
8405 index 504106b..4e50951 100644
8406 --- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
8407 +++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
8408 @@ -24,6 +24,8 @@
8409 *
8410 */
8411
8412 +#include <asm/alternative-asm.h>
8413 +
8414 .file "serpent-avx-x86_64-asm_64.S"
8415 .text
8416
8417 @@ -638,12 +640,14 @@ __serpent_enc_blk_8way_avx:
8418 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8419 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8420
8421 + pax_force_retaddr
8422 ret;
8423
8424 __enc_xor8:
8425 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8426 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8427
8428 + pax_force_retaddr
8429 ret;
8430
8431 .align 8
8432 @@ -701,4 +705,5 @@ serpent_dec_blk_8way_avx:
8433 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
8434 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
8435
8436 + pax_force_retaddr
8437 ret;
8438 diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8439 index 3ee1ff0..cbc568b 100644
8440 --- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8441 +++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8442 @@ -24,6 +24,8 @@
8443 *
8444 */
8445
8446 +#include <asm/alternative-asm.h>
8447 +
8448 .file "serpent-sse2-x86_64-asm_64.S"
8449 .text
8450
8451 @@ -692,12 +694,14 @@ __serpent_enc_blk_8way:
8452 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8453 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8454
8455 + pax_force_retaddr
8456 ret;
8457
8458 __enc_xor8:
8459 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8460 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8461
8462 + pax_force_retaddr
8463 ret;
8464
8465 .align 8
8466 @@ -755,4 +759,5 @@ serpent_dec_blk_8way:
8467 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
8468 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
8469
8470 + pax_force_retaddr
8471 ret;
8472 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
8473 index 49d6987..df66bd4 100644
8474 --- a/arch/x86/crypto/sha1_ssse3_asm.S
8475 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
8476 @@ -28,6 +28,8 @@
8477 * (at your option) any later version.
8478 */
8479
8480 +#include <asm/alternative-asm.h>
8481 +
8482 #define CTX %rdi // arg1
8483 #define BUF %rsi // arg2
8484 #define CNT %rdx // arg3
8485 @@ -104,6 +106,7 @@
8486 pop %r12
8487 pop %rbp
8488 pop %rbx
8489 + pax_force_retaddr 0, 1
8490 ret
8491
8492 .size \name, .-\name
8493 diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
8494 index 35f4557..16b379f 100644
8495 --- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
8496 +++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
8497 @@ -21,6 +21,8 @@
8498 *
8499 */
8500
8501 +#include <asm/alternative-asm.h>
8502 +
8503 .file "twofish-avx-x86_64-asm_64.S"
8504 .text
8505
8506 @@ -250,12 +252,14 @@ __twofish_enc_blk_8way:
8507 outunpack_blocks(%rsi, RC1, RD1, RA1, RB1, RK1, RX, RY, RK2);
8508 outunpack_blocks(%rax, RC2, RD2, RA2, RB2, RK1, RX, RY, RK2);
8509
8510 + pax_force_retaddr
8511 ret;
8512
8513 __enc_xor8:
8514 outunpack_xor_blocks(%rsi, RC1, RD1, RA1, RB1, RK1, RX, RY, RK2);
8515 outunpack_xor_blocks(%rax, RC2, RD2, RA2, RB2, RK1, RX, RY, RK2);
8516
8517 + pax_force_retaddr
8518 ret;
8519
8520 .align 8
8521 @@ -297,4 +301,5 @@ twofish_dec_blk_8way:
8522 outunpack_blocks(%rsi, RA1, RB1, RC1, RD1, RK1, RX, RY, RK2);
8523 outunpack_blocks(%rax, RA2, RB2, RC2, RD2, RK1, RX, RY, RK2);
8524
8525 + pax_force_retaddr
8526 ret;
8527 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8528 index 5b012a2..36d5364 100644
8529 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8530 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8531 @@ -20,6 +20,8 @@
8532 *
8533 */
8534
8535 +#include <asm/alternative-asm.h>
8536 +
8537 .file "twofish-x86_64-asm-3way.S"
8538 .text
8539
8540 @@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
8541 popq %r13;
8542 popq %r14;
8543 popq %r15;
8544 + pax_force_retaddr 0, 1
8545 ret;
8546
8547 __enc_xor3:
8548 @@ -271,6 +274,7 @@ __enc_xor3:
8549 popq %r13;
8550 popq %r14;
8551 popq %r15;
8552 + pax_force_retaddr 0, 1
8553 ret;
8554
8555 .global twofish_dec_blk_3way
8556 @@ -312,5 +316,6 @@ twofish_dec_blk_3way:
8557 popq %r13;
8558 popq %r14;
8559 popq %r15;
8560 + pax_force_retaddr 0, 1
8561 ret;
8562
8563 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
8564 index 7bcf3fc..f53832f 100644
8565 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
8566 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
8567 @@ -21,6 +21,7 @@
8568 .text
8569
8570 #include <asm/asm-offsets.h>
8571 +#include <asm/alternative-asm.h>
8572
8573 #define a_offset 0
8574 #define b_offset 4
8575 @@ -268,6 +269,7 @@ twofish_enc_blk:
8576
8577 popq R1
8578 movq $1,%rax
8579 + pax_force_retaddr 0, 1
8580 ret
8581
8582 twofish_dec_blk:
8583 @@ -319,4 +321,5 @@ twofish_dec_blk:
8584
8585 popq R1
8586 movq $1,%rax
8587 + pax_force_retaddr 0, 1
8588 ret
8589 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
8590 index 07b3a68..bd2a388 100644
8591 --- a/arch/x86/ia32/ia32_aout.c
8592 +++ b/arch/x86/ia32/ia32_aout.c
8593 @@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
8594 unsigned long dump_start, dump_size;
8595 struct user32 dump;
8596
8597 + memset(&dump, 0, sizeof(dump));
8598 +
8599 fs = get_fs();
8600 set_fs(KERNEL_DS);
8601 has_dumped = 1;
8602 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
8603 index 673ac9b..7a8c5df 100644
8604 --- a/arch/x86/ia32/ia32_signal.c
8605 +++ b/arch/x86/ia32/ia32_signal.c
8606 @@ -162,7 +162,7 @@ asmlinkage long sys32_sigaltstack(const stack_ia32_t __user *uss_ptr,
8607 }
8608 seg = get_fs();
8609 set_fs(KERNEL_DS);
8610 - ret = do_sigaltstack(uss_ptr ? &uss : NULL, &uoss, regs->sp);
8611 + ret = do_sigaltstack(uss_ptr ? (const stack_t __force_user *)&uss : NULL, (stack_t __force_user *)&uoss, regs->sp);
8612 set_fs(seg);
8613 if (ret >= 0 && uoss_ptr) {
8614 if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(stack_ia32_t)))
8615 @@ -361,7 +361,7 @@ static int ia32_setup_sigcontext(struct sigcontext_ia32 __user *sc,
8616 */
8617 static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8618 size_t frame_size,
8619 - void **fpstate)
8620 + void __user **fpstate)
8621 {
8622 unsigned long sp;
8623
8624 @@ -382,7 +382,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8625
8626 if (used_math()) {
8627 sp = sp - sig_xstate_ia32_size;
8628 - *fpstate = (struct _fpstate_ia32 *) sp;
8629 + *fpstate = (struct _fpstate_ia32 __user *) sp;
8630 if (save_i387_xstate_ia32(*fpstate) < 0)
8631 return (void __user *) -1L;
8632 }
8633 @@ -390,7 +390,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8634 sp -= frame_size;
8635 /* Align the stack pointer according to the i386 ABI,
8636 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
8637 - sp = ((sp + 4) & -16ul) - 4;
8638 + sp = ((sp - 12) & -16ul) - 4;
8639 return (void __user *) sp;
8640 }
8641
8642 @@ -448,7 +448,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
8643 * These are actually not used anymore, but left because some
8644 * gdb versions depend on them as a marker.
8645 */
8646 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8647 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8648 } put_user_catch(err);
8649
8650 if (err)
8651 @@ -490,7 +490,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8652 0xb8,
8653 __NR_ia32_rt_sigreturn,
8654 0x80cd,
8655 - 0,
8656 + 0
8657 };
8658
8659 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
8660 @@ -520,16 +520,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8661
8662 if (ka->sa.sa_flags & SA_RESTORER)
8663 restorer = ka->sa.sa_restorer;
8664 + else if (current->mm->context.vdso)
8665 + /* Return stub is in 32bit vsyscall page */
8666 + restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
8667 else
8668 - restorer = VDSO32_SYMBOL(current->mm->context.vdso,
8669 - rt_sigreturn);
8670 + restorer = &frame->retcode;
8671 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
8672
8673 /*
8674 * Not actually used anymore, but left because some gdb
8675 * versions need it.
8676 */
8677 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8678 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8679 } put_user_catch(err);
8680
8681 if (err)
8682 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
8683 index 20e5f7b..f33c779 100644
8684 --- a/arch/x86/ia32/ia32entry.S
8685 +++ b/arch/x86/ia32/ia32entry.S
8686 @@ -14,8 +14,10 @@
8687 #include <asm/segment.h>
8688 #include <asm/irqflags.h>
8689 #include <asm/asm.h>
8690 +#include <asm/pgtable.h>
8691 #include <linux/linkage.h>
8692 #include <linux/err.h>
8693 +#include <asm/alternative-asm.h>
8694
8695 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
8696 #include <linux/elf-em.h>
8697 @@ -95,6 +97,32 @@ ENTRY(native_irq_enable_sysexit)
8698 ENDPROC(native_irq_enable_sysexit)
8699 #endif
8700
8701 + .macro pax_enter_kernel_user
8702 + pax_set_fptr_mask
8703 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8704 + call pax_enter_kernel_user
8705 +#endif
8706 + .endm
8707 +
8708 + .macro pax_exit_kernel_user
8709 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8710 + call pax_exit_kernel_user
8711 +#endif
8712 +#ifdef CONFIG_PAX_RANDKSTACK
8713 + pushq %rax
8714 + pushq %r11
8715 + call pax_randomize_kstack
8716 + popq %r11
8717 + popq %rax
8718 +#endif
8719 + .endm
8720 +
8721 +.macro pax_erase_kstack
8722 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
8723 + call pax_erase_kstack
8724 +#endif
8725 +.endm
8726 +
8727 /*
8728 * 32bit SYSENTER instruction entry.
8729 *
8730 @@ -121,12 +149,6 @@ ENTRY(ia32_sysenter_target)
8731 CFI_REGISTER rsp,rbp
8732 SWAPGS_UNSAFE_STACK
8733 movq PER_CPU_VAR(kernel_stack), %rsp
8734 - addq $(KERNEL_STACK_OFFSET),%rsp
8735 - /*
8736 - * No need to follow this irqs on/off section: the syscall
8737 - * disabled irqs, here we enable it straight after entry:
8738 - */
8739 - ENABLE_INTERRUPTS(CLBR_NONE)
8740 movl %ebp,%ebp /* zero extension */
8741 pushq_cfi $__USER32_DS
8742 /*CFI_REL_OFFSET ss,0*/
8743 @@ -134,22 +156,42 @@ ENTRY(ia32_sysenter_target)
8744 CFI_REL_OFFSET rsp,0
8745 pushfq_cfi
8746 /*CFI_REL_OFFSET rflags,0*/
8747 - movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
8748 - CFI_REGISTER rip,r10
8749 + orl $X86_EFLAGS_IF,(%rsp)
8750 + GET_THREAD_INFO(%r11)
8751 + movl TI_sysenter_return(%r11), %r11d
8752 + CFI_REGISTER rip,r11
8753 pushq_cfi $__USER32_CS
8754 /*CFI_REL_OFFSET cs,0*/
8755 movl %eax, %eax
8756 - pushq_cfi %r10
8757 + pushq_cfi %r11
8758 CFI_REL_OFFSET rip,0
8759 pushq_cfi %rax
8760 cld
8761 SAVE_ARGS 0,1,0
8762 + pax_enter_kernel_user
8763 +
8764 +#ifdef CONFIG_PAX_RANDKSTACK
8765 + pax_erase_kstack
8766 +#endif
8767 +
8768 + /*
8769 + * No need to follow this irqs on/off section: the syscall
8770 + * disabled irqs, here we enable it straight after entry:
8771 + */
8772 + ENABLE_INTERRUPTS(CLBR_NONE)
8773 /* no need to do an access_ok check here because rbp has been
8774 32bit zero extended */
8775 +
8776 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8777 + mov $PAX_USER_SHADOW_BASE,%r11
8778 + add %r11,%rbp
8779 +#endif
8780 +
8781 1: movl (%rbp),%ebp
8782 _ASM_EXTABLE(1b,ia32_badarg)
8783 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8784 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8785 + GET_THREAD_INFO(%r11)
8786 + orl $TS_COMPAT,TI_status(%r11)
8787 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8788 CFI_REMEMBER_STATE
8789 jnz sysenter_tracesys
8790 cmpq $(IA32_NR_syscalls-1),%rax
8791 @@ -159,12 +201,15 @@ sysenter_do_call:
8792 sysenter_dispatch:
8793 call *ia32_sys_call_table(,%rax,8)
8794 movq %rax,RAX-ARGOFFSET(%rsp)
8795 + GET_THREAD_INFO(%r11)
8796 DISABLE_INTERRUPTS(CLBR_NONE)
8797 TRACE_IRQS_OFF
8798 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8799 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8800 jnz sysexit_audit
8801 sysexit_from_sys_call:
8802 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8803 + pax_exit_kernel_user
8804 + pax_erase_kstack
8805 + andl $~TS_COMPAT,TI_status(%r11)
8806 /* clear IF, that popfq doesn't enable interrupts early */
8807 andl $~0x200,EFLAGS-R11(%rsp)
8808 movl RIP-R11(%rsp),%edx /* User %eip */
8809 @@ -190,6 +235,9 @@ sysexit_from_sys_call:
8810 movl %eax,%esi /* 2nd arg: syscall number */
8811 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
8812 call __audit_syscall_entry
8813 +
8814 + pax_erase_kstack
8815 +
8816 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
8817 cmpq $(IA32_NR_syscalls-1),%rax
8818 ja ia32_badsys
8819 @@ -201,7 +249,7 @@ sysexit_from_sys_call:
8820 .endm
8821
8822 .macro auditsys_exit exit
8823 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8824 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8825 jnz ia32_ret_from_sys_call
8826 TRACE_IRQS_ON
8827 sti
8828 @@ -212,11 +260,12 @@ sysexit_from_sys_call:
8829 1: setbe %al /* 1 if error, 0 if not */
8830 movzbl %al,%edi /* zero-extend that into %edi */
8831 call __audit_syscall_exit
8832 + GET_THREAD_INFO(%r11)
8833 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
8834 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
8835 cli
8836 TRACE_IRQS_OFF
8837 - testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8838 + testl %edi,TI_flags(%r11)
8839 jz \exit
8840 CLEAR_RREGS -ARGOFFSET
8841 jmp int_with_check
8842 @@ -234,7 +283,7 @@ sysexit_audit:
8843
8844 sysenter_tracesys:
8845 #ifdef CONFIG_AUDITSYSCALL
8846 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8847 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8848 jz sysenter_auditsys
8849 #endif
8850 SAVE_REST
8851 @@ -246,6 +295,9 @@ sysenter_tracesys:
8852 RESTORE_REST
8853 cmpq $(IA32_NR_syscalls-1),%rax
8854 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
8855 +
8856 + pax_erase_kstack
8857 +
8858 jmp sysenter_do_call
8859 CFI_ENDPROC
8860 ENDPROC(ia32_sysenter_target)
8861 @@ -273,19 +325,25 @@ ENDPROC(ia32_sysenter_target)
8862 ENTRY(ia32_cstar_target)
8863 CFI_STARTPROC32 simple
8864 CFI_SIGNAL_FRAME
8865 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
8866 + CFI_DEF_CFA rsp,0
8867 CFI_REGISTER rip,rcx
8868 /*CFI_REGISTER rflags,r11*/
8869 SWAPGS_UNSAFE_STACK
8870 movl %esp,%r8d
8871 CFI_REGISTER rsp,r8
8872 movq PER_CPU_VAR(kernel_stack),%rsp
8873 + SAVE_ARGS 8*6,0,0
8874 + pax_enter_kernel_user
8875 +
8876 +#ifdef CONFIG_PAX_RANDKSTACK
8877 + pax_erase_kstack
8878 +#endif
8879 +
8880 /*
8881 * No need to follow this irqs on/off section: the syscall
8882 * disabled irqs and here we enable it straight after entry:
8883 */
8884 ENABLE_INTERRUPTS(CLBR_NONE)
8885 - SAVE_ARGS 8,0,0
8886 movl %eax,%eax /* zero extension */
8887 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
8888 movq %rcx,RIP-ARGOFFSET(%rsp)
8889 @@ -301,10 +359,17 @@ ENTRY(ia32_cstar_target)
8890 /* no need to do an access_ok check here because r8 has been
8891 32bit zero extended */
8892 /* hardware stack frame is complete now */
8893 +
8894 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8895 + mov $PAX_USER_SHADOW_BASE,%r11
8896 + add %r11,%r8
8897 +#endif
8898 +
8899 1: movl (%r8),%r9d
8900 _ASM_EXTABLE(1b,ia32_badarg)
8901 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8902 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8903 + GET_THREAD_INFO(%r11)
8904 + orl $TS_COMPAT,TI_status(%r11)
8905 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8906 CFI_REMEMBER_STATE
8907 jnz cstar_tracesys
8908 cmpq $IA32_NR_syscalls-1,%rax
8909 @@ -314,12 +379,15 @@ cstar_do_call:
8910 cstar_dispatch:
8911 call *ia32_sys_call_table(,%rax,8)
8912 movq %rax,RAX-ARGOFFSET(%rsp)
8913 + GET_THREAD_INFO(%r11)
8914 DISABLE_INTERRUPTS(CLBR_NONE)
8915 TRACE_IRQS_OFF
8916 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8917 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8918 jnz sysretl_audit
8919 sysretl_from_sys_call:
8920 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8921 + pax_exit_kernel_user
8922 + pax_erase_kstack
8923 + andl $~TS_COMPAT,TI_status(%r11)
8924 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
8925 movl RIP-ARGOFFSET(%rsp),%ecx
8926 CFI_REGISTER rip,rcx
8927 @@ -347,7 +415,7 @@ sysretl_audit:
8928
8929 cstar_tracesys:
8930 #ifdef CONFIG_AUDITSYSCALL
8931 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8932 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8933 jz cstar_auditsys
8934 #endif
8935 xchgl %r9d,%ebp
8936 @@ -361,6 +429,9 @@ cstar_tracesys:
8937 xchgl %ebp,%r9d
8938 cmpq $(IA32_NR_syscalls-1),%rax
8939 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
8940 +
8941 + pax_erase_kstack
8942 +
8943 jmp cstar_do_call
8944 END(ia32_cstar_target)
8945
8946 @@ -401,19 +472,26 @@ ENTRY(ia32_syscall)
8947 CFI_REL_OFFSET rip,RIP-RIP
8948 PARAVIRT_ADJUST_EXCEPTION_FRAME
8949 SWAPGS
8950 - /*
8951 - * No need to follow this irqs on/off section: the syscall
8952 - * disabled irqs and here we enable it straight after entry:
8953 - */
8954 - ENABLE_INTERRUPTS(CLBR_NONE)
8955 movl %eax,%eax
8956 pushq_cfi %rax
8957 cld
8958 /* note the registers are not zero extended to the sf.
8959 this could be a problem. */
8960 SAVE_ARGS 0,1,0
8961 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8962 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8963 + pax_enter_kernel_user
8964 +
8965 +#ifdef CONFIG_PAX_RANDKSTACK
8966 + pax_erase_kstack
8967 +#endif
8968 +
8969 + /*
8970 + * No need to follow this irqs on/off section: the syscall
8971 + * disabled irqs and here we enable it straight after entry:
8972 + */
8973 + ENABLE_INTERRUPTS(CLBR_NONE)
8974 + GET_THREAD_INFO(%r11)
8975 + orl $TS_COMPAT,TI_status(%r11)
8976 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8977 jnz ia32_tracesys
8978 cmpq $(IA32_NR_syscalls-1),%rax
8979 ja ia32_badsys
8980 @@ -436,6 +514,9 @@ ia32_tracesys:
8981 RESTORE_REST
8982 cmpq $(IA32_NR_syscalls-1),%rax
8983 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
8984 +
8985 + pax_erase_kstack
8986 +
8987 jmp ia32_do_call
8988 END(ia32_syscall)
8989
8990 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
8991 index 4540bec..714d913 100644
8992 --- a/arch/x86/ia32/sys_ia32.c
8993 +++ b/arch/x86/ia32/sys_ia32.c
8994 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
8995 */
8996 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
8997 {
8998 - typeof(ubuf->st_uid) uid = 0;
8999 - typeof(ubuf->st_gid) gid = 0;
9000 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
9001 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
9002 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
9003 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
9004 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
9005 @@ -287,7 +287,7 @@ asmlinkage long sys32_sigaction(int sig, struct old_sigaction32 __user *act,
9006 return ret;
9007 }
9008
9009 -asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr,
9010 +asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int __user *stat_addr,
9011 int options)
9012 {
9013 return compat_sys_wait4(pid, stat_addr, options, NULL);
9014 @@ -303,7 +303,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
9015 mm_segment_t old_fs = get_fs();
9016
9017 set_fs(KERNEL_DS);
9018 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
9019 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
9020 set_fs(old_fs);
9021 if (put_compat_timespec(&t, interval))
9022 return -EFAULT;
9023 @@ -319,7 +319,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
9024 mm_segment_t old_fs = get_fs();
9025
9026 set_fs(KERNEL_DS);
9027 - ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
9028 + ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
9029 set_fs(old_fs);
9030 if (!ret) {
9031 switch (_NSIG_WORDS) {
9032 @@ -344,7 +344,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
9033 if (copy_siginfo_from_user32(&info, uinfo))
9034 return -EFAULT;
9035 set_fs(KERNEL_DS);
9036 - ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
9037 + ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
9038 set_fs(old_fs);
9039 return ret;
9040 }
9041 @@ -376,7 +376,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
9042 return -EFAULT;
9043
9044 set_fs(KERNEL_DS);
9045 - ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
9046 + ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
9047 count);
9048 set_fs(old_fs);
9049
9050 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
9051 index 952bd01..7692c6f 100644
9052 --- a/arch/x86/include/asm/alternative-asm.h
9053 +++ b/arch/x86/include/asm/alternative-asm.h
9054 @@ -15,6 +15,45 @@
9055 .endm
9056 #endif
9057
9058 +#ifdef KERNEXEC_PLUGIN
9059 + .macro pax_force_retaddr_bts rip=0
9060 + btsq $63,\rip(%rsp)
9061 + .endm
9062 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
9063 + .macro pax_force_retaddr rip=0, reload=0
9064 + btsq $63,\rip(%rsp)
9065 + .endm
9066 + .macro pax_force_fptr ptr
9067 + btsq $63,\ptr
9068 + .endm
9069 + .macro pax_set_fptr_mask
9070 + .endm
9071 +#endif
9072 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
9073 + .macro pax_force_retaddr rip=0, reload=0
9074 + .if \reload
9075 + pax_set_fptr_mask
9076 + .endif
9077 + orq %r10,\rip(%rsp)
9078 + .endm
9079 + .macro pax_force_fptr ptr
9080 + orq %r10,\ptr
9081 + .endm
9082 + .macro pax_set_fptr_mask
9083 + movabs $0x8000000000000000,%r10
9084 + .endm
9085 +#endif
9086 +#else
9087 + .macro pax_force_retaddr rip=0, reload=0
9088 + .endm
9089 + .macro pax_force_fptr ptr
9090 + .endm
9091 + .macro pax_force_retaddr_bts rip=0
9092 + .endm
9093 + .macro pax_set_fptr_mask
9094 + .endm
9095 +#endif
9096 +
9097 .macro altinstruction_entry orig alt feature orig_len alt_len
9098 .long \orig - .
9099 .long \alt - .
9100 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
9101 index 7078068..f58bcda 100644
9102 --- a/arch/x86/include/asm/alternative.h
9103 +++ b/arch/x86/include/asm/alternative.h
9104 @@ -105,7 +105,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
9105 ".section .discard,\"aw\",@progbits\n" \
9106 DISCARD_ENTRY(1) \
9107 ".previous\n" \
9108 - ".section .altinstr_replacement, \"ax\"\n" \
9109 + ".section .altinstr_replacement, \"a\"\n" \
9110 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
9111 ".previous"
9112
9113 @@ -119,7 +119,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
9114 DISCARD_ENTRY(1) \
9115 DISCARD_ENTRY(2) \
9116 ".previous\n" \
9117 - ".section .altinstr_replacement, \"ax\"\n" \
9118 + ".section .altinstr_replacement, \"a\"\n" \
9119 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
9120 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
9121 ".previous"
9122 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
9123 index f342612..b3fe911 100644
9124 --- a/arch/x86/include/asm/apic.h
9125 +++ b/arch/x86/include/asm/apic.h
9126 @@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
9127
9128 #ifdef CONFIG_X86_LOCAL_APIC
9129
9130 -extern unsigned int apic_verbosity;
9131 +extern int apic_verbosity;
9132 extern int local_apic_timer_c2_ok;
9133
9134 extern int disable_apic;
9135 @@ -391,7 +391,7 @@ struct apic {
9136 */
9137 int (*x86_32_numa_cpu_node)(int cpu);
9138 #endif
9139 -};
9140 +} __do_const;
9141
9142 /*
9143 * Pointer to the local APIC driver in use on this system (there's
9144 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
9145 index 20370c6..a2eb9b0 100644
9146 --- a/arch/x86/include/asm/apm.h
9147 +++ b/arch/x86/include/asm/apm.h
9148 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
9149 __asm__ __volatile__(APM_DO_ZERO_SEGS
9150 "pushl %%edi\n\t"
9151 "pushl %%ebp\n\t"
9152 - "lcall *%%cs:apm_bios_entry\n\t"
9153 + "lcall *%%ss:apm_bios_entry\n\t"
9154 "setc %%al\n\t"
9155 "popl %%ebp\n\t"
9156 "popl %%edi\n\t"
9157 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
9158 __asm__ __volatile__(APM_DO_ZERO_SEGS
9159 "pushl %%edi\n\t"
9160 "pushl %%ebp\n\t"
9161 - "lcall *%%cs:apm_bios_entry\n\t"
9162 + "lcall *%%ss:apm_bios_entry\n\t"
9163 "setc %%bl\n\t"
9164 "popl %%ebp\n\t"
9165 "popl %%edi\n\t"
9166 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
9167 index 58cb6d4..a4b806c 100644
9168 --- a/arch/x86/include/asm/atomic.h
9169 +++ b/arch/x86/include/asm/atomic.h
9170 @@ -22,7 +22,18 @@
9171 */
9172 static inline int atomic_read(const atomic_t *v)
9173 {
9174 - return (*(volatile int *)&(v)->counter);
9175 + return (*(volatile const int *)&(v)->counter);
9176 +}
9177 +
9178 +/**
9179 + * atomic_read_unchecked - read atomic variable
9180 + * @v: pointer of type atomic_unchecked_t
9181 + *
9182 + * Atomically reads the value of @v.
9183 + */
9184 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9185 +{
9186 + return (*(volatile const int *)&(v)->counter);
9187 }
9188
9189 /**
9190 @@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
9191 }
9192
9193 /**
9194 + * atomic_set_unchecked - set atomic variable
9195 + * @v: pointer of type atomic_unchecked_t
9196 + * @i: required value
9197 + *
9198 + * Atomically sets the value of @v to @i.
9199 + */
9200 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9201 +{
9202 + v->counter = i;
9203 +}
9204 +
9205 +/**
9206 * atomic_add - add integer to atomic variable
9207 * @i: integer value to add
9208 * @v: pointer of type atomic_t
9209 @@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
9210 */
9211 static inline void atomic_add(int i, atomic_t *v)
9212 {
9213 - asm volatile(LOCK_PREFIX "addl %1,%0"
9214 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
9215 +
9216 +#ifdef CONFIG_PAX_REFCOUNT
9217 + "jno 0f\n"
9218 + LOCK_PREFIX "subl %1,%0\n"
9219 + "int $4\n0:\n"
9220 + _ASM_EXTABLE(0b, 0b)
9221 +#endif
9222 +
9223 + : "+m" (v->counter)
9224 + : "ir" (i));
9225 +}
9226 +
9227 +/**
9228 + * atomic_add_unchecked - add integer to atomic variable
9229 + * @i: integer value to add
9230 + * @v: pointer of type atomic_unchecked_t
9231 + *
9232 + * Atomically adds @i to @v.
9233 + */
9234 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
9235 +{
9236 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
9237 : "+m" (v->counter)
9238 : "ir" (i));
9239 }
9240 @@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
9241 */
9242 static inline void atomic_sub(int i, atomic_t *v)
9243 {
9244 - asm volatile(LOCK_PREFIX "subl %1,%0"
9245 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
9246 +
9247 +#ifdef CONFIG_PAX_REFCOUNT
9248 + "jno 0f\n"
9249 + LOCK_PREFIX "addl %1,%0\n"
9250 + "int $4\n0:\n"
9251 + _ASM_EXTABLE(0b, 0b)
9252 +#endif
9253 +
9254 + : "+m" (v->counter)
9255 + : "ir" (i));
9256 +}
9257 +
9258 +/**
9259 + * atomic_sub_unchecked - subtract integer from atomic variable
9260 + * @i: integer value to subtract
9261 + * @v: pointer of type atomic_unchecked_t
9262 + *
9263 + * Atomically subtracts @i from @v.
9264 + */
9265 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
9266 +{
9267 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
9268 : "+m" (v->counter)
9269 : "ir" (i));
9270 }
9271 @@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9272 {
9273 unsigned char c;
9274
9275 - asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
9276 + asm volatile(LOCK_PREFIX "subl %2,%0\n"
9277 +
9278 +#ifdef CONFIG_PAX_REFCOUNT
9279 + "jno 0f\n"
9280 + LOCK_PREFIX "addl %2,%0\n"
9281 + "int $4\n0:\n"
9282 + _ASM_EXTABLE(0b, 0b)
9283 +#endif
9284 +
9285 + "sete %1\n"
9286 : "+m" (v->counter), "=qm" (c)
9287 : "ir" (i) : "memory");
9288 return c;
9289 @@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9290 */
9291 static inline void atomic_inc(atomic_t *v)
9292 {
9293 - asm volatile(LOCK_PREFIX "incl %0"
9294 + asm volatile(LOCK_PREFIX "incl %0\n"
9295 +
9296 +#ifdef CONFIG_PAX_REFCOUNT
9297 + "jno 0f\n"
9298 + LOCK_PREFIX "decl %0\n"
9299 + "int $4\n0:\n"
9300 + _ASM_EXTABLE(0b, 0b)
9301 +#endif
9302 +
9303 + : "+m" (v->counter));
9304 +}
9305 +
9306 +/**
9307 + * atomic_inc_unchecked - increment atomic variable
9308 + * @v: pointer of type atomic_unchecked_t
9309 + *
9310 + * Atomically increments @v by 1.
9311 + */
9312 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9313 +{
9314 + asm volatile(LOCK_PREFIX "incl %0\n"
9315 : "+m" (v->counter));
9316 }
9317
9318 @@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
9319 */
9320 static inline void atomic_dec(atomic_t *v)
9321 {
9322 - asm volatile(LOCK_PREFIX "decl %0"
9323 + asm volatile(LOCK_PREFIX "decl %0\n"
9324 +
9325 +#ifdef CONFIG_PAX_REFCOUNT
9326 + "jno 0f\n"
9327 + LOCK_PREFIX "incl %0\n"
9328 + "int $4\n0:\n"
9329 + _ASM_EXTABLE(0b, 0b)
9330 +#endif
9331 +
9332 + : "+m" (v->counter));
9333 +}
9334 +
9335 +/**
9336 + * atomic_dec_unchecked - decrement atomic variable
9337 + * @v: pointer of type atomic_unchecked_t
9338 + *
9339 + * Atomically decrements @v by 1.
9340 + */
9341 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9342 +{
9343 + asm volatile(LOCK_PREFIX "decl %0\n"
9344 : "+m" (v->counter));
9345 }
9346
9347 @@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
9348 {
9349 unsigned char c;
9350
9351 - asm volatile(LOCK_PREFIX "decl %0; sete %1"
9352 + asm volatile(LOCK_PREFIX "decl %0\n"
9353 +
9354 +#ifdef CONFIG_PAX_REFCOUNT
9355 + "jno 0f\n"
9356 + LOCK_PREFIX "incl %0\n"
9357 + "int $4\n0:\n"
9358 + _ASM_EXTABLE(0b, 0b)
9359 +#endif
9360 +
9361 + "sete %1\n"
9362 : "+m" (v->counter), "=qm" (c)
9363 : : "memory");
9364 return c != 0;
9365 @@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
9366 {
9367 unsigned char c;
9368
9369 - asm volatile(LOCK_PREFIX "incl %0; sete %1"
9370 + asm volatile(LOCK_PREFIX "incl %0\n"
9371 +
9372 +#ifdef CONFIG_PAX_REFCOUNT
9373 + "jno 0f\n"
9374 + LOCK_PREFIX "decl %0\n"
9375 + "int $4\n0:\n"
9376 + _ASM_EXTABLE(0b, 0b)
9377 +#endif
9378 +
9379 + "sete %1\n"
9380 + : "+m" (v->counter), "=qm" (c)
9381 + : : "memory");
9382 + return c != 0;
9383 +}
9384 +
9385 +/**
9386 + * atomic_inc_and_test_unchecked - increment and test
9387 + * @v: pointer of type atomic_unchecked_t
9388 + *
9389 + * Atomically increments @v by 1
9390 + * and returns true if the result is zero, or false for all
9391 + * other cases.
9392 + */
9393 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9394 +{
9395 + unsigned char c;
9396 +
9397 + asm volatile(LOCK_PREFIX "incl %0\n"
9398 + "sete %1\n"
9399 : "+m" (v->counter), "=qm" (c)
9400 : : "memory");
9401 return c != 0;
9402 @@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
9403 {
9404 unsigned char c;
9405
9406 - asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
9407 + asm volatile(LOCK_PREFIX "addl %2,%0\n"
9408 +
9409 +#ifdef CONFIG_PAX_REFCOUNT
9410 + "jno 0f\n"
9411 + LOCK_PREFIX "subl %2,%0\n"
9412 + "int $4\n0:\n"
9413 + _ASM_EXTABLE(0b, 0b)
9414 +#endif
9415 +
9416 + "sets %1\n"
9417 : "+m" (v->counter), "=qm" (c)
9418 : "ir" (i) : "memory");
9419 return c;
9420 @@ -179,7 +341,7 @@ static inline int atomic_add_return(int i, atomic_t *v)
9421 goto no_xadd;
9422 #endif
9423 /* Modern 486+ processor */
9424 - return i + xadd(&v->counter, i);
9425 + return i + xadd_check_overflow(&v->counter, i);
9426
9427 #ifdef CONFIG_M386
9428 no_xadd: /* Legacy 386 processor */
9429 @@ -192,6 +354,34 @@ no_xadd: /* Legacy 386 processor */
9430 }
9431
9432 /**
9433 + * atomic_add_return_unchecked - add integer and return
9434 + * @i: integer value to add
9435 + * @v: pointer of type atomic_unchecked_t
9436 + *
9437 + * Atomically adds @i to @v and returns @i + @v
9438 + */
9439 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9440 +{
9441 +#ifdef CONFIG_M386
9442 + int __i;
9443 + unsigned long flags;
9444 + if (unlikely(boot_cpu_data.x86 <= 3))
9445 + goto no_xadd;
9446 +#endif
9447 + /* Modern 486+ processor */
9448 + return i + xadd(&v->counter, i);
9449 +
9450 +#ifdef CONFIG_M386
9451 +no_xadd: /* Legacy 386 processor */
9452 + raw_local_irq_save(flags);
9453 + __i = atomic_read_unchecked(v);
9454 + atomic_set_unchecked(v, i + __i);
9455 + raw_local_irq_restore(flags);
9456 + return i + __i;
9457 +#endif
9458 +}
9459 +
9460 +/**
9461 * atomic_sub_return - subtract integer and return
9462 * @v: pointer of type atomic_t
9463 * @i: integer value to subtract
9464 @@ -204,6 +394,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
9465 }
9466
9467 #define atomic_inc_return(v) (atomic_add_return(1, v))
9468 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9469 +{
9470 + return atomic_add_return_unchecked(1, v);
9471 +}
9472 #define atomic_dec_return(v) (atomic_sub_return(1, v))
9473
9474 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9475 @@ -211,11 +405,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9476 return cmpxchg(&v->counter, old, new);
9477 }
9478
9479 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9480 +{
9481 + return cmpxchg(&v->counter, old, new);
9482 +}
9483 +
9484 static inline int atomic_xchg(atomic_t *v, int new)
9485 {
9486 return xchg(&v->counter, new);
9487 }
9488
9489 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9490 +{
9491 + return xchg(&v->counter, new);
9492 +}
9493 +
9494 /**
9495 * __atomic_add_unless - add unless the number is already a given value
9496 * @v: pointer of type atomic_t
9497 @@ -227,12 +431,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
9498 */
9499 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9500 {
9501 - int c, old;
9502 + int c, old, new;
9503 c = atomic_read(v);
9504 for (;;) {
9505 - if (unlikely(c == (u)))
9506 + if (unlikely(c == u))
9507 break;
9508 - old = atomic_cmpxchg((v), c, c + (a));
9509 +
9510 + asm volatile("addl %2,%0\n"
9511 +
9512 +#ifdef CONFIG_PAX_REFCOUNT
9513 + "jno 0f\n"
9514 + "subl %2,%0\n"
9515 + "int $4\n0:\n"
9516 + _ASM_EXTABLE(0b, 0b)
9517 +#endif
9518 +
9519 + : "=r" (new)
9520 + : "0" (c), "ir" (a));
9521 +
9522 + old = atomic_cmpxchg(v, c, new);
9523 if (likely(old == c))
9524 break;
9525 c = old;
9526 @@ -240,6 +457,48 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9527 return c;
9528 }
9529
9530 +/**
9531 + * atomic_inc_not_zero_hint - increment if not null
9532 + * @v: pointer of type atomic_t
9533 + * @hint: probable value of the atomic before the increment
9534 + *
9535 + * This version of atomic_inc_not_zero() gives a hint of probable
9536 + * value of the atomic. This helps processor to not read the memory
9537 + * before doing the atomic read/modify/write cycle, lowering
9538 + * number of bus transactions on some arches.
9539 + *
9540 + * Returns: 0 if increment was not done, 1 otherwise.
9541 + */
9542 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
9543 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
9544 +{
9545 + int val, c = hint, new;
9546 +
9547 + /* sanity test, should be removed by compiler if hint is a constant */
9548 + if (!hint)
9549 + return __atomic_add_unless(v, 1, 0);
9550 +
9551 + do {
9552 + asm volatile("incl %0\n"
9553 +
9554 +#ifdef CONFIG_PAX_REFCOUNT
9555 + "jno 0f\n"
9556 + "decl %0\n"
9557 + "int $4\n0:\n"
9558 + _ASM_EXTABLE(0b, 0b)
9559 +#endif
9560 +
9561 + : "=r" (new)
9562 + : "0" (c));
9563 +
9564 + val = atomic_cmpxchg(v, c, new);
9565 + if (val == c)
9566 + return 1;
9567 + c = val;
9568 + } while (c);
9569 +
9570 + return 0;
9571 +}
9572
9573 /*
9574 * atomic_dec_if_positive - decrement by 1 if old value positive
9575 @@ -293,14 +552,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
9576 #endif
9577
9578 /* These are x86-specific, used by some header files */
9579 -#define atomic_clear_mask(mask, addr) \
9580 - asm volatile(LOCK_PREFIX "andl %0,%1" \
9581 - : : "r" (~(mask)), "m" (*(addr)) : "memory")
9582 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
9583 +{
9584 + asm volatile(LOCK_PREFIX "andl %1,%0"
9585 + : "+m" (v->counter)
9586 + : "r" (~(mask))
9587 + : "memory");
9588 +}
9589
9590 -#define atomic_set_mask(mask, addr) \
9591 - asm volatile(LOCK_PREFIX "orl %0,%1" \
9592 - : : "r" ((unsigned)(mask)), "m" (*(addr)) \
9593 - : "memory")
9594 +static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
9595 +{
9596 + asm volatile(LOCK_PREFIX "andl %1,%0"
9597 + : "+m" (v->counter)
9598 + : "r" (~(mask))
9599 + : "memory");
9600 +}
9601 +
9602 +static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
9603 +{
9604 + asm volatile(LOCK_PREFIX "orl %1,%0"
9605 + : "+m" (v->counter)
9606 + : "r" (mask)
9607 + : "memory");
9608 +}
9609 +
9610 +static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
9611 +{
9612 + asm volatile(LOCK_PREFIX "orl %1,%0"
9613 + : "+m" (v->counter)
9614 + : "r" (mask)
9615 + : "memory");
9616 +}
9617
9618 /* Atomic operations are already serializing on x86 */
9619 #define smp_mb__before_atomic_dec() barrier()
9620 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
9621 index b154de7..aadebd8 100644
9622 --- a/arch/x86/include/asm/atomic64_32.h
9623 +++ b/arch/x86/include/asm/atomic64_32.h
9624 @@ -12,6 +12,14 @@ typedef struct {
9625 u64 __aligned(8) counter;
9626 } atomic64_t;
9627
9628 +#ifdef CONFIG_PAX_REFCOUNT
9629 +typedef struct {
9630 + u64 __aligned(8) counter;
9631 +} atomic64_unchecked_t;
9632 +#else
9633 +typedef atomic64_t atomic64_unchecked_t;
9634 +#endif
9635 +
9636 #define ATOMIC64_INIT(val) { (val) }
9637
9638 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
9639 @@ -37,21 +45,31 @@ typedef struct {
9640 ATOMIC64_DECL_ONE(sym##_386)
9641
9642 ATOMIC64_DECL_ONE(add_386);
9643 +ATOMIC64_DECL_ONE(add_unchecked_386);
9644 ATOMIC64_DECL_ONE(sub_386);
9645 +ATOMIC64_DECL_ONE(sub_unchecked_386);
9646 ATOMIC64_DECL_ONE(inc_386);
9647 +ATOMIC64_DECL_ONE(inc_unchecked_386);
9648 ATOMIC64_DECL_ONE(dec_386);
9649 +ATOMIC64_DECL_ONE(dec_unchecked_386);
9650 #endif
9651
9652 #define alternative_atomic64(f, out, in...) \
9653 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
9654
9655 ATOMIC64_DECL(read);
9656 +ATOMIC64_DECL(read_unchecked);
9657 ATOMIC64_DECL(set);
9658 +ATOMIC64_DECL(set_unchecked);
9659 ATOMIC64_DECL(xchg);
9660 ATOMIC64_DECL(add_return);
9661 +ATOMIC64_DECL(add_return_unchecked);
9662 ATOMIC64_DECL(sub_return);
9663 +ATOMIC64_DECL(sub_return_unchecked);
9664 ATOMIC64_DECL(inc_return);
9665 +ATOMIC64_DECL(inc_return_unchecked);
9666 ATOMIC64_DECL(dec_return);
9667 +ATOMIC64_DECL(dec_return_unchecked);
9668 ATOMIC64_DECL(dec_if_positive);
9669 ATOMIC64_DECL(inc_not_zero);
9670 ATOMIC64_DECL(add_unless);
9671 @@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
9672 }
9673
9674 /**
9675 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
9676 + * @p: pointer to type atomic64_unchecked_t
9677 + * @o: expected value
9678 + * @n: new value
9679 + *
9680 + * Atomically sets @v to @n if it was equal to @o and returns
9681 + * the old value.
9682 + */
9683 +
9684 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
9685 +{
9686 + return cmpxchg64(&v->counter, o, n);
9687 +}
9688 +
9689 +/**
9690 * atomic64_xchg - xchg atomic64 variable
9691 * @v: pointer to type atomic64_t
9692 * @n: value to assign
9693 @@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
9694 }
9695
9696 /**
9697 + * atomic64_set_unchecked - set atomic64 variable
9698 + * @v: pointer to type atomic64_unchecked_t
9699 + * @n: value to assign
9700 + *
9701 + * Atomically sets the value of @v to @n.
9702 + */
9703 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
9704 +{
9705 + unsigned high = (unsigned)(i >> 32);
9706 + unsigned low = (unsigned)i;
9707 + alternative_atomic64(set, /* no output */,
9708 + "S" (v), "b" (low), "c" (high)
9709 + : "eax", "edx", "memory");
9710 +}
9711 +
9712 +/**
9713 * atomic64_read - read atomic64 variable
9714 * @v: pointer to type atomic64_t
9715 *
9716 @@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
9717 }
9718
9719 /**
9720 + * atomic64_read_unchecked - read atomic64 variable
9721 + * @v: pointer to type atomic64_unchecked_t
9722 + *
9723 + * Atomically reads the value of @v and returns it.
9724 + */
9725 +static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
9726 +{
9727 + long long r;
9728 + alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
9729 + return r;
9730 + }
9731 +
9732 +/**
9733 * atomic64_add_return - add and return
9734 * @i: integer value to add
9735 * @v: pointer to type atomic64_t
9736 @@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
9737 return i;
9738 }
9739
9740 +/**
9741 + * atomic64_add_return_unchecked - add and return
9742 + * @i: integer value to add
9743 + * @v: pointer to type atomic64_unchecked_t
9744 + *
9745 + * Atomically adds @i to @v and returns @i + *@v
9746 + */
9747 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
9748 +{
9749 + alternative_atomic64(add_return_unchecked,
9750 + ASM_OUTPUT2("+A" (i), "+c" (v)),
9751 + ASM_NO_INPUT_CLOBBER("memory"));
9752 + return i;
9753 +}
9754 +
9755 /*
9756 * Other variants with different arithmetic operators:
9757 */
9758 @@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
9759 return a;
9760 }
9761
9762 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9763 +{
9764 + long long a;
9765 + alternative_atomic64(inc_return_unchecked, "=&A" (a),
9766 + "S" (v) : "memory", "ecx");
9767 + return a;
9768 +}
9769 +
9770 static inline long long atomic64_dec_return(atomic64_t *v)
9771 {
9772 long long a;
9773 @@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
9774 }
9775
9776 /**
9777 + * atomic64_add_unchecked - add integer to atomic64 variable
9778 + * @i: integer value to add
9779 + * @v: pointer to type atomic64_unchecked_t
9780 + *
9781 + * Atomically adds @i to @v.
9782 + */
9783 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
9784 +{
9785 + __alternative_atomic64(add_unchecked, add_return_unchecked,
9786 + ASM_OUTPUT2("+A" (i), "+c" (v)),
9787 + ASM_NO_INPUT_CLOBBER("memory"));
9788 + return i;
9789 +}
9790 +
9791 +/**
9792 * atomic64_sub - subtract the atomic64 variable
9793 * @i: integer value to subtract
9794 * @v: pointer to type atomic64_t
9795 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
9796 index 0e1cbfc..5623683 100644
9797 --- a/arch/x86/include/asm/atomic64_64.h
9798 +++ b/arch/x86/include/asm/atomic64_64.h
9799 @@ -18,7 +18,19 @@
9800 */
9801 static inline long atomic64_read(const atomic64_t *v)
9802 {
9803 - return (*(volatile long *)&(v)->counter);
9804 + return (*(volatile const long *)&(v)->counter);
9805 +}
9806 +
9807 +/**
9808 + * atomic64_read_unchecked - read atomic64 variable
9809 + * @v: pointer of type atomic64_unchecked_t
9810 + *
9811 + * Atomically reads the value of @v.
9812 + * Doesn't imply a read memory barrier.
9813 + */
9814 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9815 +{
9816 + return (*(volatile const long *)&(v)->counter);
9817 }
9818
9819 /**
9820 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
9821 }
9822
9823 /**
9824 + * atomic64_set_unchecked - set atomic64 variable
9825 + * @v: pointer to type atomic64_unchecked_t
9826 + * @i: required value
9827 + *
9828 + * Atomically sets the value of @v to @i.
9829 + */
9830 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9831 +{
9832 + v->counter = i;
9833 +}
9834 +
9835 +/**
9836 * atomic64_add - add integer to atomic64 variable
9837 * @i: integer value to add
9838 * @v: pointer to type atomic64_t
9839 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
9840 */
9841 static inline void atomic64_add(long i, atomic64_t *v)
9842 {
9843 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
9844 +
9845 +#ifdef CONFIG_PAX_REFCOUNT
9846 + "jno 0f\n"
9847 + LOCK_PREFIX "subq %1,%0\n"
9848 + "int $4\n0:\n"
9849 + _ASM_EXTABLE(0b, 0b)
9850 +#endif
9851 +
9852 + : "=m" (v->counter)
9853 + : "er" (i), "m" (v->counter));
9854 +}
9855 +
9856 +/**
9857 + * atomic64_add_unchecked - add integer to atomic64 variable
9858 + * @i: integer value to add
9859 + * @v: pointer to type atomic64_unchecked_t
9860 + *
9861 + * Atomically adds @i to @v.
9862 + */
9863 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
9864 +{
9865 asm volatile(LOCK_PREFIX "addq %1,%0"
9866 : "=m" (v->counter)
9867 : "er" (i), "m" (v->counter));
9868 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
9869 */
9870 static inline void atomic64_sub(long i, atomic64_t *v)
9871 {
9872 - asm volatile(LOCK_PREFIX "subq %1,%0"
9873 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
9874 +
9875 +#ifdef CONFIG_PAX_REFCOUNT
9876 + "jno 0f\n"
9877 + LOCK_PREFIX "addq %1,%0\n"
9878 + "int $4\n0:\n"
9879 + _ASM_EXTABLE(0b, 0b)
9880 +#endif
9881 +
9882 + : "=m" (v->counter)
9883 + : "er" (i), "m" (v->counter));
9884 +}
9885 +
9886 +/**
9887 + * atomic64_sub_unchecked - subtract the atomic64 variable
9888 + * @i: integer value to subtract
9889 + * @v: pointer to type atomic64_unchecked_t
9890 + *
9891 + * Atomically subtracts @i from @v.
9892 + */
9893 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
9894 +{
9895 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
9896 : "=m" (v->counter)
9897 : "er" (i), "m" (v->counter));
9898 }
9899 @@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9900 {
9901 unsigned char c;
9902
9903 - asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
9904 + asm volatile(LOCK_PREFIX "subq %2,%0\n"
9905 +
9906 +#ifdef CONFIG_PAX_REFCOUNT
9907 + "jno 0f\n"
9908 + LOCK_PREFIX "addq %2,%0\n"
9909 + "int $4\n0:\n"
9910 + _ASM_EXTABLE(0b, 0b)
9911 +#endif
9912 +
9913 + "sete %1\n"
9914 : "=m" (v->counter), "=qm" (c)
9915 : "er" (i), "m" (v->counter) : "memory");
9916 return c;
9917 @@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9918 */
9919 static inline void atomic64_inc(atomic64_t *v)
9920 {
9921 + asm volatile(LOCK_PREFIX "incq %0\n"
9922 +
9923 +#ifdef CONFIG_PAX_REFCOUNT
9924 + "jno 0f\n"
9925 + LOCK_PREFIX "decq %0\n"
9926 + "int $4\n0:\n"
9927 + _ASM_EXTABLE(0b, 0b)
9928 +#endif
9929 +
9930 + : "=m" (v->counter)
9931 + : "m" (v->counter));
9932 +}
9933 +
9934 +/**
9935 + * atomic64_inc_unchecked - increment atomic64 variable
9936 + * @v: pointer to type atomic64_unchecked_t
9937 + *
9938 + * Atomically increments @v by 1.
9939 + */
9940 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9941 +{
9942 asm volatile(LOCK_PREFIX "incq %0"
9943 : "=m" (v->counter)
9944 : "m" (v->counter));
9945 @@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
9946 */
9947 static inline void atomic64_dec(atomic64_t *v)
9948 {
9949 - asm volatile(LOCK_PREFIX "decq %0"
9950 + asm volatile(LOCK_PREFIX "decq %0\n"
9951 +
9952 +#ifdef CONFIG_PAX_REFCOUNT
9953 + "jno 0f\n"
9954 + LOCK_PREFIX "incq %0\n"
9955 + "int $4\n0:\n"
9956 + _ASM_EXTABLE(0b, 0b)
9957 +#endif
9958 +
9959 + : "=m" (v->counter)
9960 + : "m" (v->counter));
9961 +}
9962 +
9963 +/**
9964 + * atomic64_dec_unchecked - decrement atomic64 variable
9965 + * @v: pointer to type atomic64_t
9966 + *
9967 + * Atomically decrements @v by 1.
9968 + */
9969 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9970 +{
9971 + asm volatile(LOCK_PREFIX "decq %0\n"
9972 : "=m" (v->counter)
9973 : "m" (v->counter));
9974 }
9975 @@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
9976 {
9977 unsigned char c;
9978
9979 - asm volatile(LOCK_PREFIX "decq %0; sete %1"
9980 + asm volatile(LOCK_PREFIX "decq %0\n"
9981 +
9982 +#ifdef CONFIG_PAX_REFCOUNT
9983 + "jno 0f\n"
9984 + LOCK_PREFIX "incq %0\n"
9985 + "int $4\n0:\n"
9986 + _ASM_EXTABLE(0b, 0b)
9987 +#endif
9988 +
9989 + "sete %1\n"
9990 : "=m" (v->counter), "=qm" (c)
9991 : "m" (v->counter) : "memory");
9992 return c != 0;
9993 @@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
9994 {
9995 unsigned char c;
9996
9997 - asm volatile(LOCK_PREFIX "incq %0; sete %1"
9998 + asm volatile(LOCK_PREFIX "incq %0\n"
9999 +
10000 +#ifdef CONFIG_PAX_REFCOUNT
10001 + "jno 0f\n"
10002 + LOCK_PREFIX "decq %0\n"
10003 + "int $4\n0:\n"
10004 + _ASM_EXTABLE(0b, 0b)
10005 +#endif
10006 +
10007 + "sete %1\n"
10008 : "=m" (v->counter), "=qm" (c)
10009 : "m" (v->counter) : "memory");
10010 return c != 0;
10011 @@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
10012 {
10013 unsigned char c;
10014
10015 - asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
10016 + asm volatile(LOCK_PREFIX "addq %2,%0\n"
10017 +
10018 +#ifdef CONFIG_PAX_REFCOUNT
10019 + "jno 0f\n"
10020 + LOCK_PREFIX "subq %2,%0\n"
10021 + "int $4\n0:\n"
10022 + _ASM_EXTABLE(0b, 0b)
10023 +#endif
10024 +
10025 + "sets %1\n"
10026 : "=m" (v->counter), "=qm" (c)
10027 : "er" (i), "m" (v->counter) : "memory");
10028 return c;
10029 @@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
10030 */
10031 static inline long atomic64_add_return(long i, atomic64_t *v)
10032 {
10033 + return i + xadd_check_overflow(&v->counter, i);
10034 +}
10035 +
10036 +/**
10037 + * atomic64_add_return_unchecked - add and return
10038 + * @i: integer value to add
10039 + * @v: pointer to type atomic64_unchecked_t
10040 + *
10041 + * Atomically adds @i to @v and returns @i + @v
10042 + */
10043 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
10044 +{
10045 return i + xadd(&v->counter, i);
10046 }
10047
10048 @@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
10049 }
10050
10051 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
10052 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
10053 +{
10054 + return atomic64_add_return_unchecked(1, v);
10055 +}
10056 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
10057
10058 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
10059 @@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
10060 return cmpxchg(&v->counter, old, new);
10061 }
10062
10063 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
10064 +{
10065 + return cmpxchg(&v->counter, old, new);
10066 +}
10067 +
10068 static inline long atomic64_xchg(atomic64_t *v, long new)
10069 {
10070 return xchg(&v->counter, new);
10071 @@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
10072 */
10073 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
10074 {
10075 - long c, old;
10076 + long c, old, new;
10077 c = atomic64_read(v);
10078 for (;;) {
10079 - if (unlikely(c == (u)))
10080 + if (unlikely(c == u))
10081 break;
10082 - old = atomic64_cmpxchg((v), c, c + (a));
10083 +
10084 + asm volatile("add %2,%0\n"
10085 +
10086 +#ifdef CONFIG_PAX_REFCOUNT
10087 + "jno 0f\n"
10088 + "sub %2,%0\n"
10089 + "int $4\n0:\n"
10090 + _ASM_EXTABLE(0b, 0b)
10091 +#endif
10092 +
10093 + : "=r" (new)
10094 + : "0" (c), "ir" (a));
10095 +
10096 + old = atomic64_cmpxchg(v, c, new);
10097 if (likely(old == c))
10098 break;
10099 c = old;
10100 }
10101 - return c != (u);
10102 + return c != u;
10103 }
10104
10105 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
10106 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
10107 index 72f5009..2f8b9a9 100644
10108 --- a/arch/x86/include/asm/bitops.h
10109 +++ b/arch/x86/include/asm/bitops.h
10110 @@ -40,7 +40,7 @@
10111 * a mask operation on a byte.
10112 */
10113 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
10114 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
10115 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
10116 #define CONST_MASK(nr) (1 << ((nr) & 7))
10117
10118 /**
10119 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
10120 index b13fe63..0dab13a 100644
10121 --- a/arch/x86/include/asm/boot.h
10122 +++ b/arch/x86/include/asm/boot.h
10123 @@ -11,10 +11,15 @@
10124 #include <asm/pgtable_types.h>
10125
10126 /* Physical address where kernel should be loaded. */
10127 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10128 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10129 + (CONFIG_PHYSICAL_ALIGN - 1)) \
10130 & ~(CONFIG_PHYSICAL_ALIGN - 1))
10131
10132 +#ifndef __ASSEMBLY__
10133 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
10134 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
10135 +#endif
10136 +
10137 /* Minimum kernel alignment, as a power of two */
10138 #ifdef CONFIG_X86_64
10139 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
10140 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
10141 index 48f99f1..d78ebf9 100644
10142 --- a/arch/x86/include/asm/cache.h
10143 +++ b/arch/x86/include/asm/cache.h
10144 @@ -5,12 +5,13 @@
10145
10146 /* L1 cache line size */
10147 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
10148 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10149 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10150
10151 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
10152 +#define __read_only __attribute__((__section__(".data..read_only")))
10153
10154 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
10155 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
10156 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
10157
10158 #ifdef CONFIG_X86_VSMP
10159 #ifdef CONFIG_SMP
10160 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
10161 index 9863ee3..4a1f8e1 100644
10162 --- a/arch/x86/include/asm/cacheflush.h
10163 +++ b/arch/x86/include/asm/cacheflush.h
10164 @@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
10165 unsigned long pg_flags = pg->flags & _PGMT_MASK;
10166
10167 if (pg_flags == _PGMT_DEFAULT)
10168 - return -1;
10169 + return ~0UL;
10170 else if (pg_flags == _PGMT_WC)
10171 return _PAGE_CACHE_WC;
10172 else if (pg_flags == _PGMT_UC_MINUS)
10173 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
10174 index 46fc474..b02b0f9 100644
10175 --- a/arch/x86/include/asm/checksum_32.h
10176 +++ b/arch/x86/include/asm/checksum_32.h
10177 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
10178 int len, __wsum sum,
10179 int *src_err_ptr, int *dst_err_ptr);
10180
10181 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
10182 + int len, __wsum sum,
10183 + int *src_err_ptr, int *dst_err_ptr);
10184 +
10185 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
10186 + int len, __wsum sum,
10187 + int *src_err_ptr, int *dst_err_ptr);
10188 +
10189 /*
10190 * Note: when you get a NULL pointer exception here this means someone
10191 * passed in an incorrect kernel address to one of these functions.
10192 @@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
10193 int *err_ptr)
10194 {
10195 might_sleep();
10196 - return csum_partial_copy_generic((__force void *)src, dst,
10197 + return csum_partial_copy_generic_from_user((__force void *)src, dst,
10198 len, sum, err_ptr, NULL);
10199 }
10200
10201 @@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
10202 {
10203 might_sleep();
10204 if (access_ok(VERIFY_WRITE, dst, len))
10205 - return csum_partial_copy_generic(src, (__force void *)dst,
10206 + return csum_partial_copy_generic_to_user(src, (__force void *)dst,
10207 len, sum, NULL, err_ptr);
10208
10209 if (len)
10210 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
10211 index 99480e5..d81165b 100644
10212 --- a/arch/x86/include/asm/cmpxchg.h
10213 +++ b/arch/x86/include/asm/cmpxchg.h
10214 @@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
10215 __compiletime_error("Bad argument size for cmpxchg");
10216 extern void __xadd_wrong_size(void)
10217 __compiletime_error("Bad argument size for xadd");
10218 +extern void __xadd_check_overflow_wrong_size(void)
10219 + __compiletime_error("Bad argument size for xadd_check_overflow");
10220 extern void __add_wrong_size(void)
10221 __compiletime_error("Bad argument size for add");
10222 +extern void __add_check_overflow_wrong_size(void)
10223 + __compiletime_error("Bad argument size for add_check_overflow");
10224
10225 /*
10226 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
10227 @@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
10228 __ret; \
10229 })
10230
10231 +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
10232 + ({ \
10233 + __typeof__ (*(ptr)) __ret = (arg); \
10234 + switch (sizeof(*(ptr))) { \
10235 + case __X86_CASE_L: \
10236 + asm volatile (lock #op "l %0, %1\n" \
10237 + "jno 0f\n" \
10238 + "mov %0,%1\n" \
10239 + "int $4\n0:\n" \
10240 + _ASM_EXTABLE(0b, 0b) \
10241 + : "+r" (__ret), "+m" (*(ptr)) \
10242 + : : "memory", "cc"); \
10243 + break; \
10244 + case __X86_CASE_Q: \
10245 + asm volatile (lock #op "q %q0, %1\n" \
10246 + "jno 0f\n" \
10247 + "mov %0,%1\n" \
10248 + "int $4\n0:\n" \
10249 + _ASM_EXTABLE(0b, 0b) \
10250 + : "+r" (__ret), "+m" (*(ptr)) \
10251 + : : "memory", "cc"); \
10252 + break; \
10253 + default: \
10254 + __ ## op ## _check_overflow_wrong_size(); \
10255 + } \
10256 + __ret; \
10257 + })
10258 +
10259 /*
10260 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
10261 * Since this is generally used to protect other memory information, we
10262 @@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
10263 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
10264 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
10265
10266 +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
10267 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
10268 +
10269 #define __add(ptr, inc, lock) \
10270 ({ \
10271 __typeof__ (*(ptr)) __ret = (inc); \
10272 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
10273 index 6b7ee5f..9d664b3 100644
10274 --- a/arch/x86/include/asm/cpufeature.h
10275 +++ b/arch/x86/include/asm/cpufeature.h
10276 @@ -202,13 +202,14 @@
10277 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
10278 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
10279 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
10280 -#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
10281 +#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
10282 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
10283 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
10284 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
10285 #define X86_FEATURE_RTM (9*32+11) /* Restricted Transactional Memory */
10286 #define X86_FEATURE_RDSEED (9*32+18) /* The RDSEED instruction */
10287 #define X86_FEATURE_ADX (9*32+19) /* The ADCX and ADOX instructions */
10288 +#define X86_FEATURE_SMAP (9*32+20) /* Supervisor Mode Access Prevention */
10289
10290 #if defined(__KERNEL__) && !defined(__ASSEMBLY__)
10291
10292 @@ -373,7 +374,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
10293 ".section .discard,\"aw\",@progbits\n"
10294 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
10295 ".previous\n"
10296 - ".section .altinstr_replacement,\"ax\"\n"
10297 + ".section .altinstr_replacement,\"a\"\n"
10298 "3: movb $1,%0\n"
10299 "4:\n"
10300 ".previous\n"
10301 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
10302 index 8bf1c06..f723dfd 100644
10303 --- a/arch/x86/include/asm/desc.h
10304 +++ b/arch/x86/include/asm/desc.h
10305 @@ -4,6 +4,7 @@
10306 #include <asm/desc_defs.h>
10307 #include <asm/ldt.h>
10308 #include <asm/mmu.h>
10309 +#include <asm/pgtable.h>
10310
10311 #include <linux/smp.h>
10312 #include <linux/percpu.h>
10313 @@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10314
10315 desc->type = (info->read_exec_only ^ 1) << 1;
10316 desc->type |= info->contents << 2;
10317 + desc->type |= info->seg_not_present ^ 1;
10318
10319 desc->s = 1;
10320 desc->dpl = 0x3;
10321 @@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10322 }
10323
10324 extern struct desc_ptr idt_descr;
10325 -extern gate_desc idt_table[];
10326 extern struct desc_ptr nmi_idt_descr;
10327 -extern gate_desc nmi_idt_table[];
10328 -
10329 -struct gdt_page {
10330 - struct desc_struct gdt[GDT_ENTRIES];
10331 -} __attribute__((aligned(PAGE_SIZE)));
10332 -
10333 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
10334 +extern gate_desc idt_table[256];
10335 +extern gate_desc nmi_idt_table[256];
10336
10337 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
10338 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
10339 {
10340 - return per_cpu(gdt_page, cpu).gdt;
10341 + return cpu_gdt_table[cpu];
10342 }
10343
10344 #ifdef CONFIG_X86_64
10345 @@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
10346 unsigned long base, unsigned dpl, unsigned flags,
10347 unsigned short seg)
10348 {
10349 - gate->a = (seg << 16) | (base & 0xffff);
10350 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
10351 + gate->gate.offset_low = base;
10352 + gate->gate.seg = seg;
10353 + gate->gate.reserved = 0;
10354 + gate->gate.type = type;
10355 + gate->gate.s = 0;
10356 + gate->gate.dpl = dpl;
10357 + gate->gate.p = 1;
10358 + gate->gate.offset_high = base >> 16;
10359 }
10360
10361 #endif
10362 @@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
10363
10364 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
10365 {
10366 + pax_open_kernel();
10367 memcpy(&idt[entry], gate, sizeof(*gate));
10368 + pax_close_kernel();
10369 }
10370
10371 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
10372 {
10373 + pax_open_kernel();
10374 memcpy(&ldt[entry], desc, 8);
10375 + pax_close_kernel();
10376 }
10377
10378 static inline void
10379 @@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
10380 default: size = sizeof(*gdt); break;
10381 }
10382
10383 + pax_open_kernel();
10384 memcpy(&gdt[entry], desc, size);
10385 + pax_close_kernel();
10386 }
10387
10388 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
10389 @@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
10390
10391 static inline void native_load_tr_desc(void)
10392 {
10393 + pax_open_kernel();
10394 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
10395 + pax_close_kernel();
10396 }
10397
10398 static inline void native_load_gdt(const struct desc_ptr *dtr)
10399 @@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
10400 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
10401 unsigned int i;
10402
10403 + pax_open_kernel();
10404 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
10405 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
10406 + pax_close_kernel();
10407 }
10408
10409 #define _LDT_empty(info) \
10410 @@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
10411 }
10412
10413 #ifdef CONFIG_X86_64
10414 -static inline void set_nmi_gate(int gate, void *addr)
10415 +static inline void set_nmi_gate(int gate, const void *addr)
10416 {
10417 gate_desc s;
10418
10419 @@ -320,7 +333,7 @@ static inline void set_nmi_gate(int gate, void *addr)
10420 }
10421 #endif
10422
10423 -static inline void _set_gate(int gate, unsigned type, void *addr,
10424 +static inline void _set_gate(int gate, unsigned type, const void *addr,
10425 unsigned dpl, unsigned ist, unsigned seg)
10426 {
10427 gate_desc s;
10428 @@ -339,7 +352,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
10429 * Pentium F0 0F bugfix can have resulted in the mapped
10430 * IDT being write-protected.
10431 */
10432 -static inline void set_intr_gate(unsigned int n, void *addr)
10433 +static inline void set_intr_gate(unsigned int n, const void *addr)
10434 {
10435 BUG_ON((unsigned)n > 0xFF);
10436 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
10437 @@ -369,19 +382,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
10438 /*
10439 * This routine sets up an interrupt gate at directory privilege level 3.
10440 */
10441 -static inline void set_system_intr_gate(unsigned int n, void *addr)
10442 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
10443 {
10444 BUG_ON((unsigned)n > 0xFF);
10445 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
10446 }
10447
10448 -static inline void set_system_trap_gate(unsigned int n, void *addr)
10449 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
10450 {
10451 BUG_ON((unsigned)n > 0xFF);
10452 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
10453 }
10454
10455 -static inline void set_trap_gate(unsigned int n, void *addr)
10456 +static inline void set_trap_gate(unsigned int n, const void *addr)
10457 {
10458 BUG_ON((unsigned)n > 0xFF);
10459 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
10460 @@ -390,19 +403,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
10461 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
10462 {
10463 BUG_ON((unsigned)n > 0xFF);
10464 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
10465 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
10466 }
10467
10468 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
10469 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
10470 {
10471 BUG_ON((unsigned)n > 0xFF);
10472 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
10473 }
10474
10475 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
10476 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
10477 {
10478 BUG_ON((unsigned)n > 0xFF);
10479 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
10480 }
10481
10482 +#ifdef CONFIG_X86_32
10483 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
10484 +{
10485 + struct desc_struct d;
10486 +
10487 + if (likely(limit))
10488 + limit = (limit - 1UL) >> PAGE_SHIFT;
10489 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
10490 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
10491 +}
10492 +#endif
10493 +
10494 #endif /* _ASM_X86_DESC_H */
10495 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
10496 index 278441f..b95a174 100644
10497 --- a/arch/x86/include/asm/desc_defs.h
10498 +++ b/arch/x86/include/asm/desc_defs.h
10499 @@ -31,6 +31,12 @@ struct desc_struct {
10500 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
10501 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
10502 };
10503 + struct {
10504 + u16 offset_low;
10505 + u16 seg;
10506 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
10507 + unsigned offset_high: 16;
10508 + } gate;
10509 };
10510 } __attribute__((packed));
10511
10512 diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
10513 index 3778256..c5d4fce 100644
10514 --- a/arch/x86/include/asm/e820.h
10515 +++ b/arch/x86/include/asm/e820.h
10516 @@ -69,7 +69,7 @@ struct e820map {
10517 #define ISA_START_ADDRESS 0xa0000
10518 #define ISA_END_ADDRESS 0x100000
10519
10520 -#define BIOS_BEGIN 0x000a0000
10521 +#define BIOS_BEGIN 0x000c0000
10522 #define BIOS_END 0x00100000
10523
10524 #define BIOS_ROM_BASE 0xffe00000
10525 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
10526 index 5939f44..f8845f6 100644
10527 --- a/arch/x86/include/asm/elf.h
10528 +++ b/arch/x86/include/asm/elf.h
10529 @@ -243,7 +243,25 @@ extern int force_personality32;
10530 the loader. We need to make sure that it is out of the way of the program
10531 that it will "exec", and that there is sufficient room for the brk. */
10532
10533 +#ifdef CONFIG_PAX_SEGMEXEC
10534 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
10535 +#else
10536 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
10537 +#endif
10538 +
10539 +#ifdef CONFIG_PAX_ASLR
10540 +#ifdef CONFIG_X86_32
10541 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
10542 +
10543 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10544 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10545 +#else
10546 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
10547 +
10548 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10549 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10550 +#endif
10551 +#endif
10552
10553 /* This yields a mask that user programs can use to figure out what
10554 instruction set this CPU supports. This could be done in user space,
10555 @@ -296,16 +314,12 @@ do { \
10556
10557 #define ARCH_DLINFO \
10558 do { \
10559 - if (vdso_enabled) \
10560 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10561 - (unsigned long)current->mm->context.vdso); \
10562 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10563 } while (0)
10564
10565 #define ARCH_DLINFO_X32 \
10566 do { \
10567 - if (vdso_enabled) \
10568 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10569 - (unsigned long)current->mm->context.vdso); \
10570 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10571 } while (0)
10572
10573 #define AT_SYSINFO 32
10574 @@ -320,7 +334,7 @@ else \
10575
10576 #endif /* !CONFIG_X86_32 */
10577
10578 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
10579 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
10580
10581 #define VDSO_ENTRY \
10582 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
10583 @@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
10584 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
10585 #define compat_arch_setup_additional_pages syscall32_setup_pages
10586
10587 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
10588 -#define arch_randomize_brk arch_randomize_brk
10589 -
10590 /*
10591 * True on X86_32 or when emulating IA32 on X86_64
10592 */
10593 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
10594 index 75ce3f4..882e801 100644
10595 --- a/arch/x86/include/asm/emergency-restart.h
10596 +++ b/arch/x86/include/asm/emergency-restart.h
10597 @@ -13,6 +13,6 @@ enum reboot_type {
10598
10599 extern enum reboot_type reboot_type;
10600
10601 -extern void machine_emergency_restart(void);
10602 +extern void machine_emergency_restart(void) __noreturn;
10603
10604 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
10605 diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
10606 index 75f4c6d..9215c4a 100644
10607 --- a/arch/x86/include/asm/fpu-internal.h
10608 +++ b/arch/x86/include/asm/fpu-internal.h
10609 @@ -82,10 +82,12 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
10610 }
10611
10612 #ifdef CONFIG_X86_64
10613 -static inline int fxrstor_checking(struct i387_fxsave_struct *fx)
10614 +static inline int fxrstor_checking(struct i387_fxsave_struct __user *fx)
10615 {
10616 int err;
10617
10618 + fx = (struct i387_fxsave_struct __user *)____m(fx);
10619 +
10620 /* See comment in fxsave() below. */
10621 #ifdef CONFIG_AS_FXSAVEQ
10622 asm volatile("1: fxrstorq %[fx]\n\t"
10623 @@ -115,6 +117,8 @@ static inline int fxsave_user(struct i387_fxsave_struct __user *fx)
10624 {
10625 int err;
10626
10627 + fx = (struct i387_fxsave_struct __user *)____m(fx);
10628 +
10629 /*
10630 * Clear the bytes not touched by the fxsave and reserved
10631 * for the SW usage.
10632 @@ -183,15 +187,15 @@ static inline void fpu_fxsave(struct fpu *fpu)
10633 #else /* CONFIG_X86_32 */
10634
10635 /* perform fxrstor iff the processor has extended states, otherwise frstor */
10636 -static inline int fxrstor_checking(struct i387_fxsave_struct *fx)
10637 +static inline int fxrstor_checking(struct i387_fxsave_struct __user *fx)
10638 {
10639 /*
10640 * The "nop" is needed to make the instructions the same
10641 * length.
10642 */
10643 alternative_input(
10644 - "nop ; frstor %1",
10645 - "fxrstor %1",
10646 + __copyuser_seg" frstor %1; nop",
10647 + __copyuser_seg" fxrstor %1",
10648 X86_FEATURE_FXSR,
10649 "m" (*fx));
10650
10651 @@ -271,7 +275,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
10652 "emms\n\t" /* clear stack tags */
10653 "fildl %P[addr]", /* set F?P to defined value */
10654 X86_FEATURE_FXSAVE_LEAK,
10655 - [addr] "m" (tsk->thread.fpu.has_fpu));
10656 + [addr] "m" (init_tss[smp_processor_id()].x86_tss.sp0));
10657
10658 return fpu_restore_checking(&tsk->thread.fpu);
10659 }
10660 @@ -334,14 +338,17 @@ static inline void __thread_fpu_begin(struct task_struct *tsk)
10661 typedef struct { int preload; } fpu_switch_t;
10662
10663 /*
10664 - * FIXME! We could do a totally lazy restore, but we need to
10665 - * add a per-cpu "this was the task that last touched the FPU
10666 - * on this CPU" variable, and the task needs to have a "I last
10667 - * touched the FPU on this CPU" and check them.
10668 + * Must be run with preemption disabled: this clears the fpu_owner_task,
10669 + * on this CPU.
10670 *
10671 - * We don't do that yet, so "fpu_lazy_restore()" always returns
10672 - * false, but some day..
10673 + * This will disable any lazy FPU state restore of the current FPU state,
10674 + * but if the current thread owns the FPU, it will still be saved by.
10675 */
10676 +static inline void __cpu_disable_lazy_restore(unsigned int cpu)
10677 +{
10678 + per_cpu(fpu_owner_task, cpu) = NULL;
10679 +}
10680 +
10681 static inline int fpu_lazy_restore(struct task_struct *new, unsigned int cpu)
10682 {
10683 return new == this_cpu_read_stable(fpu_owner_task) &&
10684 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
10685 index 71ecbcb..11df950 100644
10686 --- a/arch/x86/include/asm/futex.h
10687 +++ b/arch/x86/include/asm/futex.h
10688 @@ -11,20 +11,22 @@
10689 #include <asm/processor.h>
10690
10691 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
10692 + typecheck(u32 __user *, uaddr); \
10693 asm volatile("1:\t" insn "\n" \
10694 "2:\t.section .fixup,\"ax\"\n" \
10695 "3:\tmov\t%3, %1\n" \
10696 "\tjmp\t2b\n" \
10697 "\t.previous\n" \
10698 _ASM_EXTABLE(1b, 3b) \
10699 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
10700 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr))\
10701 : "i" (-EFAULT), "0" (oparg), "1" (0))
10702
10703 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
10704 + typecheck(u32 __user *, uaddr); \
10705 asm volatile("1:\tmovl %2, %0\n" \
10706 "\tmovl\t%0, %3\n" \
10707 "\t" insn "\n" \
10708 - "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
10709 + "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
10710 "\tjnz\t1b\n" \
10711 "3:\t.section .fixup,\"ax\"\n" \
10712 "4:\tmov\t%5, %1\n" \
10713 @@ -33,7 +35,7 @@
10714 _ASM_EXTABLE(1b, 4b) \
10715 _ASM_EXTABLE(2b, 4b) \
10716 : "=&a" (oldval), "=&r" (ret), \
10717 - "+m" (*uaddr), "=&r" (tem) \
10718 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
10719 : "r" (oparg), "i" (-EFAULT), "1" (0))
10720
10721 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10722 @@ -60,10 +62,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10723
10724 switch (op) {
10725 case FUTEX_OP_SET:
10726 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
10727 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
10728 break;
10729 case FUTEX_OP_ADD:
10730 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
10731 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
10732 uaddr, oparg);
10733 break;
10734 case FUTEX_OP_OR:
10735 @@ -122,13 +124,13 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
10736 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
10737 return -EFAULT;
10738
10739 - asm volatile("1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
10740 + asm volatile("1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
10741 "2:\t.section .fixup, \"ax\"\n"
10742 "3:\tmov %3, %0\n"
10743 "\tjmp 2b\n"
10744 "\t.previous\n"
10745 _ASM_EXTABLE(1b, 3b)
10746 - : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
10747 + : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
10748 : "i" (-EFAULT), "r" (newval), "1" (oldval)
10749 : "memory"
10750 );
10751 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
10752 index eb92a6e..b98b2f4 100644
10753 --- a/arch/x86/include/asm/hw_irq.h
10754 +++ b/arch/x86/include/asm/hw_irq.h
10755 @@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
10756 extern void enable_IO_APIC(void);
10757
10758 /* Statistics */
10759 -extern atomic_t irq_err_count;
10760 -extern atomic_t irq_mis_count;
10761 +extern atomic_unchecked_t irq_err_count;
10762 +extern atomic_unchecked_t irq_mis_count;
10763
10764 /* EISA */
10765 extern void eisa_set_level_irq(unsigned int irq);
10766 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
10767 index d8e8eef..99f81ae 100644
10768 --- a/arch/x86/include/asm/io.h
10769 +++ b/arch/x86/include/asm/io.h
10770 @@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
10771
10772 #include <linux/vmalloc.h>
10773
10774 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
10775 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
10776 +{
10777 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10778 +}
10779 +
10780 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
10781 +{
10782 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10783 +}
10784 +
10785 /*
10786 * Convert a virtual cached pointer to an uncached pointer
10787 */
10788 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
10789 index bba3cf8..06bc8da 100644
10790 --- a/arch/x86/include/asm/irqflags.h
10791 +++ b/arch/x86/include/asm/irqflags.h
10792 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
10793 sti; \
10794 sysexit
10795
10796 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
10797 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
10798 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
10799 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
10800 +
10801 #else
10802 #define INTERRUPT_RETURN iret
10803 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
10804 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
10805 index 5478825..839e88c 100644
10806 --- a/arch/x86/include/asm/kprobes.h
10807 +++ b/arch/x86/include/asm/kprobes.h
10808 @@ -37,13 +37,8 @@ typedef u8 kprobe_opcode_t;
10809 #define RELATIVEJUMP_SIZE 5
10810 #define RELATIVECALL_OPCODE 0xe8
10811 #define RELATIVE_ADDR_SIZE 4
10812 -#define MAX_STACK_SIZE 64
10813 -#define MIN_STACK_SIZE(ADDR) \
10814 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
10815 - THREAD_SIZE - (unsigned long)(ADDR))) \
10816 - ? (MAX_STACK_SIZE) \
10817 - : (((unsigned long)current_thread_info()) + \
10818 - THREAD_SIZE - (unsigned long)(ADDR)))
10819 +#define MAX_STACK_SIZE 64UL
10820 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
10821
10822 #define flush_insn_slot(p) do { } while (0)
10823
10824 diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
10825 index 09155d6..d2e6df9 100644
10826 --- a/arch/x86/include/asm/kvm_host.h
10827 +++ b/arch/x86/include/asm/kvm_host.h
10828 @@ -694,7 +694,7 @@ struct kvm_x86_ops {
10829 int (*check_intercept)(struct kvm_vcpu *vcpu,
10830 struct x86_instruction_info *info,
10831 enum x86_intercept_stage stage);
10832 -};
10833 +} __do_const;
10834
10835 struct kvm_arch_async_pf {
10836 u32 token;
10837 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
10838 index c8bed0d..e5721fa 100644
10839 --- a/arch/x86/include/asm/local.h
10840 +++ b/arch/x86/include/asm/local.h
10841 @@ -17,26 +17,58 @@ typedef struct {
10842
10843 static inline void local_inc(local_t *l)
10844 {
10845 - asm volatile(_ASM_INC "%0"
10846 + asm volatile(_ASM_INC "%0\n"
10847 +
10848 +#ifdef CONFIG_PAX_REFCOUNT
10849 + "jno 0f\n"
10850 + _ASM_DEC "%0\n"
10851 + "int $4\n0:\n"
10852 + _ASM_EXTABLE(0b, 0b)
10853 +#endif
10854 +
10855 : "+m" (l->a.counter));
10856 }
10857
10858 static inline void local_dec(local_t *l)
10859 {
10860 - asm volatile(_ASM_DEC "%0"
10861 + asm volatile(_ASM_DEC "%0\n"
10862 +
10863 +#ifdef CONFIG_PAX_REFCOUNT
10864 + "jno 0f\n"
10865 + _ASM_INC "%0\n"
10866 + "int $4\n0:\n"
10867 + _ASM_EXTABLE(0b, 0b)
10868 +#endif
10869 +
10870 : "+m" (l->a.counter));
10871 }
10872
10873 static inline void local_add(long i, local_t *l)
10874 {
10875 - asm volatile(_ASM_ADD "%1,%0"
10876 + asm volatile(_ASM_ADD "%1,%0\n"
10877 +
10878 +#ifdef CONFIG_PAX_REFCOUNT
10879 + "jno 0f\n"
10880 + _ASM_SUB "%1,%0\n"
10881 + "int $4\n0:\n"
10882 + _ASM_EXTABLE(0b, 0b)
10883 +#endif
10884 +
10885 : "+m" (l->a.counter)
10886 : "ir" (i));
10887 }
10888
10889 static inline void local_sub(long i, local_t *l)
10890 {
10891 - asm volatile(_ASM_SUB "%1,%0"
10892 + asm volatile(_ASM_SUB "%1,%0\n"
10893 +
10894 +#ifdef CONFIG_PAX_REFCOUNT
10895 + "jno 0f\n"
10896 + _ASM_ADD "%1,%0\n"
10897 + "int $4\n0:\n"
10898 + _ASM_EXTABLE(0b, 0b)
10899 +#endif
10900 +
10901 : "+m" (l->a.counter)
10902 : "ir" (i));
10903 }
10904 @@ -54,7 +86,16 @@ static inline int local_sub_and_test(long i, local_t *l)
10905 {
10906 unsigned char c;
10907
10908 - asm volatile(_ASM_SUB "%2,%0; sete %1"
10909 + asm volatile(_ASM_SUB "%2,%0\n"
10910 +
10911 +#ifdef CONFIG_PAX_REFCOUNT
10912 + "jno 0f\n"
10913 + _ASM_ADD "%2,%0\n"
10914 + "int $4\n0:\n"
10915 + _ASM_EXTABLE(0b, 0b)
10916 +#endif
10917 +
10918 + "sete %1\n"
10919 : "+m" (l->a.counter), "=qm" (c)
10920 : "ir" (i) : "memory");
10921 return c;
10922 @@ -72,7 +113,16 @@ static inline int local_dec_and_test(local_t *l)
10923 {
10924 unsigned char c;
10925
10926 - asm volatile(_ASM_DEC "%0; sete %1"
10927 + asm volatile(_ASM_DEC "%0\n"
10928 +
10929 +#ifdef CONFIG_PAX_REFCOUNT
10930 + "jno 0f\n"
10931 + _ASM_INC "%0\n"
10932 + "int $4\n0:\n"
10933 + _ASM_EXTABLE(0b, 0b)
10934 +#endif
10935 +
10936 + "sete %1\n"
10937 : "+m" (l->a.counter), "=qm" (c)
10938 : : "memory");
10939 return c != 0;
10940 @@ -90,7 +140,16 @@ static inline int local_inc_and_test(local_t *l)
10941 {
10942 unsigned char c;
10943
10944 - asm volatile(_ASM_INC "%0; sete %1"
10945 + asm volatile(_ASM_INC "%0\n"
10946 +
10947 +#ifdef CONFIG_PAX_REFCOUNT
10948 + "jno 0f\n"
10949 + _ASM_DEC "%0\n"
10950 + "int $4\n0:\n"
10951 + _ASM_EXTABLE(0b, 0b)
10952 +#endif
10953 +
10954 + "sete %1\n"
10955 : "+m" (l->a.counter), "=qm" (c)
10956 : : "memory");
10957 return c != 0;
10958 @@ -109,7 +168,16 @@ static inline int local_add_negative(long i, local_t *l)
10959 {
10960 unsigned char c;
10961
10962 - asm volatile(_ASM_ADD "%2,%0; sets %1"
10963 + asm volatile(_ASM_ADD "%2,%0\n"
10964 +
10965 +#ifdef CONFIG_PAX_REFCOUNT
10966 + "jno 0f\n"
10967 + _ASM_SUB "%2,%0\n"
10968 + "int $4\n0:\n"
10969 + _ASM_EXTABLE(0b, 0b)
10970 +#endif
10971 +
10972 + "sets %1\n"
10973 : "+m" (l->a.counter), "=qm" (c)
10974 : "ir" (i) : "memory");
10975 return c;
10976 @@ -132,7 +200,15 @@ static inline long local_add_return(long i, local_t *l)
10977 #endif
10978 /* Modern 486+ processor */
10979 __i = i;
10980 - asm volatile(_ASM_XADD "%0, %1;"
10981 + asm volatile(_ASM_XADD "%0, %1\n"
10982 +
10983 +#ifdef CONFIG_PAX_REFCOUNT
10984 + "jno 0f\n"
10985 + _ASM_MOV "%0,%1\n"
10986 + "int $4\n0:\n"
10987 + _ASM_EXTABLE(0b, 0b)
10988 +#endif
10989 +
10990 : "+r" (i), "+m" (l->a.counter)
10991 : : "memory");
10992 return i + __i;
10993 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
10994 index 593e51d..fa69c9a 100644
10995 --- a/arch/x86/include/asm/mman.h
10996 +++ b/arch/x86/include/asm/mman.h
10997 @@ -5,4 +5,14 @@
10998
10999 #include <asm-generic/mman.h>
11000
11001 +#ifdef __KERNEL__
11002 +#ifndef __ASSEMBLY__
11003 +#ifdef CONFIG_X86_32
11004 +#define arch_mmap_check i386_mmap_check
11005 +int i386_mmap_check(unsigned long addr, unsigned long len,
11006 + unsigned long flags);
11007 +#endif
11008 +#endif
11009 +#endif
11010 +
11011 #endif /* _ASM_X86_MMAN_H */
11012 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
11013 index 5f55e69..e20bfb1 100644
11014 --- a/arch/x86/include/asm/mmu.h
11015 +++ b/arch/x86/include/asm/mmu.h
11016 @@ -9,7 +9,7 @@
11017 * we put the segment information here.
11018 */
11019 typedef struct {
11020 - void *ldt;
11021 + struct desc_struct *ldt;
11022 int size;
11023
11024 #ifdef CONFIG_X86_64
11025 @@ -18,7 +18,19 @@ typedef struct {
11026 #endif
11027
11028 struct mutex lock;
11029 - void *vdso;
11030 + unsigned long vdso;
11031 +
11032 +#ifdef CONFIG_X86_32
11033 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
11034 + unsigned long user_cs_base;
11035 + unsigned long user_cs_limit;
11036 +
11037 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
11038 + cpumask_t cpu_user_cs_mask;
11039 +#endif
11040 +
11041 +#endif
11042 +#endif
11043 } mm_context_t;
11044
11045 #ifdef CONFIG_SMP
11046 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
11047 index cdbf367..adb37ac 100644
11048 --- a/arch/x86/include/asm/mmu_context.h
11049 +++ b/arch/x86/include/asm/mmu_context.h
11050 @@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
11051
11052 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
11053 {
11054 +
11055 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11056 + unsigned int i;
11057 + pgd_t *pgd;
11058 +
11059 + pax_open_kernel();
11060 + pgd = get_cpu_pgd(smp_processor_id());
11061 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
11062 + set_pgd_batched(pgd+i, native_make_pgd(0));
11063 + pax_close_kernel();
11064 +#endif
11065 +
11066 #ifdef CONFIG_SMP
11067 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
11068 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
11069 @@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
11070 struct task_struct *tsk)
11071 {
11072 unsigned cpu = smp_processor_id();
11073 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11074 + int tlbstate = TLBSTATE_OK;
11075 +#endif
11076
11077 if (likely(prev != next)) {
11078 #ifdef CONFIG_SMP
11079 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11080 + tlbstate = this_cpu_read(cpu_tlbstate.state);
11081 +#endif
11082 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
11083 this_cpu_write(cpu_tlbstate.active_mm, next);
11084 #endif
11085 cpumask_set_cpu(cpu, mm_cpumask(next));
11086
11087 /* Re-load page tables */
11088 +#ifdef CONFIG_PAX_PER_CPU_PGD
11089 + pax_open_kernel();
11090 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
11091 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
11092 + pax_close_kernel();
11093 + load_cr3(get_cpu_pgd(cpu));
11094 +#else
11095 load_cr3(next->pgd);
11096 +#endif
11097
11098 /* stop flush ipis for the previous mm */
11099 cpumask_clear_cpu(cpu, mm_cpumask(prev));
11100 @@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
11101 */
11102 if (unlikely(prev->context.ldt != next->context.ldt))
11103 load_LDT_nolock(&next->context);
11104 - }
11105 +
11106 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
11107 + if (!(__supported_pte_mask & _PAGE_NX)) {
11108 + smp_mb__before_clear_bit();
11109 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
11110 + smp_mb__after_clear_bit();
11111 + cpu_set(cpu, next->context.cpu_user_cs_mask);
11112 + }
11113 +#endif
11114 +
11115 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11116 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
11117 + prev->context.user_cs_limit != next->context.user_cs_limit))
11118 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11119 #ifdef CONFIG_SMP
11120 + else if (unlikely(tlbstate != TLBSTATE_OK))
11121 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11122 +#endif
11123 +#endif
11124 +
11125 + }
11126 else {
11127 +
11128 +#ifdef CONFIG_PAX_PER_CPU_PGD
11129 + pax_open_kernel();
11130 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
11131 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
11132 + pax_close_kernel();
11133 + load_cr3(get_cpu_pgd(cpu));
11134 +#endif
11135 +
11136 +#ifdef CONFIG_SMP
11137 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
11138 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
11139
11140 @@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
11141 * tlb flush IPI delivery. We must reload CR3
11142 * to make sure to use no freed page tables.
11143 */
11144 +
11145 +#ifndef CONFIG_PAX_PER_CPU_PGD
11146 load_cr3(next->pgd);
11147 +#endif
11148 +
11149 load_LDT_nolock(&next->context);
11150 +
11151 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
11152 + if (!(__supported_pte_mask & _PAGE_NX))
11153 + cpu_set(cpu, next->context.cpu_user_cs_mask);
11154 +#endif
11155 +
11156 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11157 +#ifdef CONFIG_PAX_PAGEEXEC
11158 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
11159 +#endif
11160 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11161 +#endif
11162 +
11163 }
11164 +#endif
11165 }
11166 -#endif
11167 }
11168
11169 #define activate_mm(prev, next) \
11170 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
11171 index 9eae775..c914fea 100644
11172 --- a/arch/x86/include/asm/module.h
11173 +++ b/arch/x86/include/asm/module.h
11174 @@ -5,6 +5,7 @@
11175
11176 #ifdef CONFIG_X86_64
11177 /* X86_64 does not define MODULE_PROC_FAMILY */
11178 +#define MODULE_PROC_FAMILY ""
11179 #elif defined CONFIG_M386
11180 #define MODULE_PROC_FAMILY "386 "
11181 #elif defined CONFIG_M486
11182 @@ -59,8 +60,20 @@
11183 #error unknown processor family
11184 #endif
11185
11186 -#ifdef CONFIG_X86_32
11187 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
11188 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
11189 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
11190 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
11191 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
11192 +#else
11193 +#define MODULE_PAX_KERNEXEC ""
11194 #endif
11195
11196 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11197 +#define MODULE_PAX_UDEREF "UDEREF "
11198 +#else
11199 +#define MODULE_PAX_UDEREF ""
11200 +#endif
11201 +
11202 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
11203 +
11204 #endif /* _ASM_X86_MODULE_H */
11205 diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
11206 index 320f7bb..e89f8f8 100644
11207 --- a/arch/x86/include/asm/page_64_types.h
11208 +++ b/arch/x86/include/asm/page_64_types.h
11209 @@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
11210
11211 /* duplicated to the one in bootmem.h */
11212 extern unsigned long max_pfn;
11213 -extern unsigned long phys_base;
11214 +extern const unsigned long phys_base;
11215
11216 extern unsigned long __phys_addr(unsigned long);
11217 #define __phys_reloc_hide(x) (x)
11218 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
11219 index a0facf3..c017b15 100644
11220 --- a/arch/x86/include/asm/paravirt.h
11221 +++ b/arch/x86/include/asm/paravirt.h
11222 @@ -632,6 +632,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
11223 val);
11224 }
11225
11226 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11227 +{
11228 + pgdval_t val = native_pgd_val(pgd);
11229 +
11230 + if (sizeof(pgdval_t) > sizeof(long))
11231 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
11232 + val, (u64)val >> 32);
11233 + else
11234 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
11235 + val);
11236 +}
11237 +
11238 static inline void pgd_clear(pgd_t *pgdp)
11239 {
11240 set_pgd(pgdp, __pgd(0));
11241 @@ -713,6 +725,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
11242 pv_mmu_ops.set_fixmap(idx, phys, flags);
11243 }
11244
11245 +#ifdef CONFIG_PAX_KERNEXEC
11246 +static inline unsigned long pax_open_kernel(void)
11247 +{
11248 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
11249 +}
11250 +
11251 +static inline unsigned long pax_close_kernel(void)
11252 +{
11253 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
11254 +}
11255 +#else
11256 +static inline unsigned long pax_open_kernel(void) { return 0; }
11257 +static inline unsigned long pax_close_kernel(void) { return 0; }
11258 +#endif
11259 +
11260 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
11261
11262 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
11263 @@ -929,7 +956,7 @@ extern void default_banner(void);
11264
11265 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
11266 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
11267 -#define PARA_INDIRECT(addr) *%cs:addr
11268 +#define PARA_INDIRECT(addr) *%ss:addr
11269 #endif
11270
11271 #define INTERRUPT_RETURN \
11272 @@ -1004,6 +1031,21 @@ extern void default_banner(void);
11273 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
11274 CLBR_NONE, \
11275 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
11276 +
11277 +#define GET_CR0_INTO_RDI \
11278 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
11279 + mov %rax,%rdi
11280 +
11281 +#define SET_RDI_INTO_CR0 \
11282 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
11283 +
11284 +#define GET_CR3_INTO_RDI \
11285 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
11286 + mov %rax,%rdi
11287 +
11288 +#define SET_RDI_INTO_CR3 \
11289 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
11290 +
11291 #endif /* CONFIG_X86_32 */
11292
11293 #endif /* __ASSEMBLY__ */
11294 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
11295 index 142236e..6a6b4a6 100644
11296 --- a/arch/x86/include/asm/paravirt_types.h
11297 +++ b/arch/x86/include/asm/paravirt_types.h
11298 @@ -84,20 +84,20 @@ struct pv_init_ops {
11299 */
11300 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
11301 unsigned long addr, unsigned len);
11302 -};
11303 +} __no_const;
11304
11305
11306 struct pv_lazy_ops {
11307 /* Set deferred update mode, used for batching operations. */
11308 void (*enter)(void);
11309 void (*leave)(void);
11310 -};
11311 +} __no_const;
11312
11313 struct pv_time_ops {
11314 unsigned long long (*sched_clock)(void);
11315 unsigned long long (*steal_clock)(int cpu);
11316 unsigned long (*get_tsc_khz)(void);
11317 -};
11318 +} __no_const;
11319
11320 struct pv_cpu_ops {
11321 /* hooks for various privileged instructions */
11322 @@ -191,7 +191,7 @@ struct pv_cpu_ops {
11323
11324 void (*start_context_switch)(struct task_struct *prev);
11325 void (*end_context_switch)(struct task_struct *next);
11326 -};
11327 +} __no_const;
11328
11329 struct pv_irq_ops {
11330 /*
11331 @@ -222,7 +222,7 @@ struct pv_apic_ops {
11332 unsigned long start_eip,
11333 unsigned long start_esp);
11334 #endif
11335 -};
11336 +} __no_const;
11337
11338 struct pv_mmu_ops {
11339 unsigned long (*read_cr2)(void);
11340 @@ -312,6 +312,7 @@ struct pv_mmu_ops {
11341 struct paravirt_callee_save make_pud;
11342
11343 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
11344 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
11345 #endif /* PAGETABLE_LEVELS == 4 */
11346 #endif /* PAGETABLE_LEVELS >= 3 */
11347
11348 @@ -323,6 +324,12 @@ struct pv_mmu_ops {
11349 an mfn. We can tell which is which from the index. */
11350 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
11351 phys_addr_t phys, pgprot_t flags);
11352 +
11353 +#ifdef CONFIG_PAX_KERNEXEC
11354 + unsigned long (*pax_open_kernel)(void);
11355 + unsigned long (*pax_close_kernel)(void);
11356 +#endif
11357 +
11358 };
11359
11360 struct arch_spinlock;
11361 @@ -333,7 +340,7 @@ struct pv_lock_ops {
11362 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
11363 int (*spin_trylock)(struct arch_spinlock *lock);
11364 void (*spin_unlock)(struct arch_spinlock *lock);
11365 -};
11366 +} __no_const;
11367
11368 /* This contains all the paravirt structures: we get a convenient
11369 * number for each function using the offset which we use to indicate
11370 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
11371 index b4389a4..7024269 100644
11372 --- a/arch/x86/include/asm/pgalloc.h
11373 +++ b/arch/x86/include/asm/pgalloc.h
11374 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
11375 pmd_t *pmd, pte_t *pte)
11376 {
11377 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11378 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
11379 +}
11380 +
11381 +static inline void pmd_populate_user(struct mm_struct *mm,
11382 + pmd_t *pmd, pte_t *pte)
11383 +{
11384 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11385 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
11386 }
11387
11388 @@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
11389
11390 #ifdef CONFIG_X86_PAE
11391 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
11392 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
11393 +{
11394 + pud_populate(mm, pudp, pmd);
11395 +}
11396 #else /* !CONFIG_X86_PAE */
11397 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11398 {
11399 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11400 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
11401 }
11402 +
11403 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11404 +{
11405 + paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11406 + set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
11407 +}
11408 #endif /* CONFIG_X86_PAE */
11409
11410 #if PAGETABLE_LEVELS > 3
11411 @@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11412 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
11413 }
11414
11415 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11416 +{
11417 + paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
11418 + set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
11419 +}
11420 +
11421 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
11422 {
11423 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
11424 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
11425 index f2b489c..4f7e2e5 100644
11426 --- a/arch/x86/include/asm/pgtable-2level.h
11427 +++ b/arch/x86/include/asm/pgtable-2level.h
11428 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
11429
11430 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11431 {
11432 + pax_open_kernel();
11433 *pmdp = pmd;
11434 + pax_close_kernel();
11435 }
11436
11437 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11438 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
11439 index 4cc9f2b..5fd9226 100644
11440 --- a/arch/x86/include/asm/pgtable-3level.h
11441 +++ b/arch/x86/include/asm/pgtable-3level.h
11442 @@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11443
11444 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11445 {
11446 + pax_open_kernel();
11447 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
11448 + pax_close_kernel();
11449 }
11450
11451 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11452 {
11453 + pax_open_kernel();
11454 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
11455 + pax_close_kernel();
11456 }
11457
11458 /*
11459 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
11460 index c3520d7..cf742ef 100644
11461 --- a/arch/x86/include/asm/pgtable.h
11462 +++ b/arch/x86/include/asm/pgtable.h
11463 @@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11464
11465 #ifndef __PAGETABLE_PUD_FOLDED
11466 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
11467 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
11468 #define pgd_clear(pgd) native_pgd_clear(pgd)
11469 #endif
11470
11471 @@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11472
11473 #define arch_end_context_switch(prev) do {} while(0)
11474
11475 +#define pax_open_kernel() native_pax_open_kernel()
11476 +#define pax_close_kernel() native_pax_close_kernel()
11477 #endif /* CONFIG_PARAVIRT */
11478
11479 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
11480 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
11481 +
11482 +#ifdef CONFIG_PAX_KERNEXEC
11483 +static inline unsigned long native_pax_open_kernel(void)
11484 +{
11485 + unsigned long cr0;
11486 +
11487 + preempt_disable();
11488 + barrier();
11489 + cr0 = read_cr0() ^ X86_CR0_WP;
11490 + BUG_ON(unlikely(cr0 & X86_CR0_WP));
11491 + write_cr0(cr0);
11492 + return cr0 ^ X86_CR0_WP;
11493 +}
11494 +
11495 +static inline unsigned long native_pax_close_kernel(void)
11496 +{
11497 + unsigned long cr0;
11498 +
11499 + cr0 = read_cr0() ^ X86_CR0_WP;
11500 + BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
11501 + write_cr0(cr0);
11502 + barrier();
11503 + preempt_enable_no_resched();
11504 + return cr0 ^ X86_CR0_WP;
11505 +}
11506 +#else
11507 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
11508 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
11509 +#endif
11510 +
11511 /*
11512 * The following only work if pte_present() is true.
11513 * Undefined behaviour if not..
11514 */
11515 +static inline int pte_user(pte_t pte)
11516 +{
11517 + return pte_val(pte) & _PAGE_USER;
11518 +}
11519 +
11520 static inline int pte_dirty(pte_t pte)
11521 {
11522 return pte_flags(pte) & _PAGE_DIRTY;
11523 @@ -195,9 +235,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
11524 return pte_clear_flags(pte, _PAGE_RW);
11525 }
11526
11527 +static inline pte_t pte_mkread(pte_t pte)
11528 +{
11529 + return __pte(pte_val(pte) | _PAGE_USER);
11530 +}
11531 +
11532 static inline pte_t pte_mkexec(pte_t pte)
11533 {
11534 - return pte_clear_flags(pte, _PAGE_NX);
11535 +#ifdef CONFIG_X86_PAE
11536 + if (__supported_pte_mask & _PAGE_NX)
11537 + return pte_clear_flags(pte, _PAGE_NX);
11538 + else
11539 +#endif
11540 + return pte_set_flags(pte, _PAGE_USER);
11541 +}
11542 +
11543 +static inline pte_t pte_exprotect(pte_t pte)
11544 +{
11545 +#ifdef CONFIG_X86_PAE
11546 + if (__supported_pte_mask & _PAGE_NX)
11547 + return pte_set_flags(pte, _PAGE_NX);
11548 + else
11549 +#endif
11550 + return pte_clear_flags(pte, _PAGE_USER);
11551 }
11552
11553 static inline pte_t pte_mkdirty(pte_t pte)
11554 @@ -389,6 +449,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
11555 #endif
11556
11557 #ifndef __ASSEMBLY__
11558 +
11559 +#ifdef CONFIG_PAX_PER_CPU_PGD
11560 +extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
11561 +static inline pgd_t *get_cpu_pgd(unsigned int cpu)
11562 +{
11563 + return cpu_pgd[cpu];
11564 +}
11565 +#endif
11566 +
11567 #include <linux/mm_types.h>
11568
11569 static inline int pte_none(pte_t pte)
11570 @@ -565,7 +634,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
11571
11572 static inline int pgd_bad(pgd_t pgd)
11573 {
11574 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
11575 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
11576 }
11577
11578 static inline int pgd_none(pgd_t pgd)
11579 @@ -588,7 +657,12 @@ static inline int pgd_none(pgd_t pgd)
11580 * pgd_offset() returns a (pgd_t *)
11581 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
11582 */
11583 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
11584 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
11585 +
11586 +#ifdef CONFIG_PAX_PER_CPU_PGD
11587 +#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
11588 +#endif
11589 +
11590 /*
11591 * a shortcut which implies the use of the kernel's pgd, instead
11592 * of a process's
11593 @@ -599,6 +673,20 @@ static inline int pgd_none(pgd_t pgd)
11594 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
11595 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
11596
11597 +#ifdef CONFIG_X86_32
11598 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
11599 +#else
11600 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
11601 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
11602 +
11603 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11604 +#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
11605 +#else
11606 +#define PAX_USER_SHADOW_BASE (_AC(0,UL))
11607 +#endif
11608 +
11609 +#endif
11610 +
11611 #ifndef __ASSEMBLY__
11612
11613 extern int direct_gbpages;
11614 @@ -763,11 +851,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
11615 * dst and src can be on the same page, but the range must not overlap,
11616 * and must not cross a page boundary.
11617 */
11618 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
11619 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
11620 {
11621 - memcpy(dst, src, count * sizeof(pgd_t));
11622 + pax_open_kernel();
11623 + while (count--)
11624 + *dst++ = *src++;
11625 + pax_close_kernel();
11626 }
11627
11628 +#ifdef CONFIG_PAX_PER_CPU_PGD
11629 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
11630 +#endif
11631 +
11632 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11633 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
11634 +#else
11635 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
11636 +#endif
11637
11638 #include <asm-generic/pgtable.h>
11639 #endif /* __ASSEMBLY__ */
11640 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
11641 index 0c92113..34a77c6 100644
11642 --- a/arch/x86/include/asm/pgtable_32.h
11643 +++ b/arch/x86/include/asm/pgtable_32.h
11644 @@ -25,9 +25,6 @@
11645 struct mm_struct;
11646 struct vm_area_struct;
11647
11648 -extern pgd_t swapper_pg_dir[1024];
11649 -extern pgd_t initial_page_table[1024];
11650 -
11651 static inline void pgtable_cache_init(void) { }
11652 static inline void check_pgt_cache(void) { }
11653 void paging_init(void);
11654 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11655 # include <asm/pgtable-2level.h>
11656 #endif
11657
11658 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
11659 +extern pgd_t initial_page_table[PTRS_PER_PGD];
11660 +#ifdef CONFIG_X86_PAE
11661 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
11662 +#endif
11663 +
11664 #if defined(CONFIG_HIGHPTE)
11665 #define pte_offset_map(dir, address) \
11666 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
11667 @@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11668 /* Clear a kernel PTE and flush it from the TLB */
11669 #define kpte_clear_flush(ptep, vaddr) \
11670 do { \
11671 + pax_open_kernel(); \
11672 pte_clear(&init_mm, (vaddr), (ptep)); \
11673 + pax_close_kernel(); \
11674 __flush_tlb_one((vaddr)); \
11675 } while (0)
11676
11677 @@ -74,6 +79,9 @@ do { \
11678
11679 #endif /* !__ASSEMBLY__ */
11680
11681 +#define HAVE_ARCH_UNMAPPED_AREA
11682 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
11683 +
11684 /*
11685 * kern_addr_valid() is (1) for FLATMEM and (0) for
11686 * SPARSEMEM and DISCONTIGMEM
11687 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
11688 index ed5903b..c7fe163 100644
11689 --- a/arch/x86/include/asm/pgtable_32_types.h
11690 +++ b/arch/x86/include/asm/pgtable_32_types.h
11691 @@ -8,7 +8,7 @@
11692 */
11693 #ifdef CONFIG_X86_PAE
11694 # include <asm/pgtable-3level_types.h>
11695 -# define PMD_SIZE (1UL << PMD_SHIFT)
11696 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
11697 # define PMD_MASK (~(PMD_SIZE - 1))
11698 #else
11699 # include <asm/pgtable-2level_types.h>
11700 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
11701 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
11702 #endif
11703
11704 +#ifdef CONFIG_PAX_KERNEXEC
11705 +#ifndef __ASSEMBLY__
11706 +extern unsigned char MODULES_EXEC_VADDR[];
11707 +extern unsigned char MODULES_EXEC_END[];
11708 +#endif
11709 +#include <asm/boot.h>
11710 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
11711 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
11712 +#else
11713 +#define ktla_ktva(addr) (addr)
11714 +#define ktva_ktla(addr) (addr)
11715 +#endif
11716 +
11717 #define MODULES_VADDR VMALLOC_START
11718 #define MODULES_END VMALLOC_END
11719 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
11720 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
11721 index 8251be0..4ea8b46 100644
11722 --- a/arch/x86/include/asm/pgtable_64.h
11723 +++ b/arch/x86/include/asm/pgtable_64.h
11724 @@ -16,10 +16,14 @@
11725
11726 extern pud_t level3_kernel_pgt[512];
11727 extern pud_t level3_ident_pgt[512];
11728 +extern pud_t level3_vmalloc_start_pgt[512];
11729 +extern pud_t level3_vmalloc_end_pgt[512];
11730 +extern pud_t level3_vmemmap_pgt[512];
11731 +extern pud_t level2_vmemmap_pgt[512];
11732 extern pmd_t level2_kernel_pgt[512];
11733 extern pmd_t level2_fixmap_pgt[512];
11734 -extern pmd_t level2_ident_pgt[512];
11735 -extern pgd_t init_level4_pgt[];
11736 +extern pmd_t level2_ident_pgt[512*2];
11737 +extern pgd_t init_level4_pgt[512];
11738
11739 #define swapper_pg_dir init_level4_pgt
11740
11741 @@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11742
11743 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11744 {
11745 + pax_open_kernel();
11746 *pmdp = pmd;
11747 + pax_close_kernel();
11748 }
11749
11750 static inline void native_pmd_clear(pmd_t *pmd)
11751 @@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
11752
11753 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11754 {
11755 + pax_open_kernel();
11756 *pudp = pud;
11757 + pax_close_kernel();
11758 }
11759
11760 static inline void native_pud_clear(pud_t *pud)
11761 @@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
11762
11763 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
11764 {
11765 + pax_open_kernel();
11766 + *pgdp = pgd;
11767 + pax_close_kernel();
11768 +}
11769 +
11770 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11771 +{
11772 *pgdp = pgd;
11773 }
11774
11775 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
11776 index 766ea16..5b96cb3 100644
11777 --- a/arch/x86/include/asm/pgtable_64_types.h
11778 +++ b/arch/x86/include/asm/pgtable_64_types.h
11779 @@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
11780 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
11781 #define MODULES_END _AC(0xffffffffff000000, UL)
11782 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
11783 +#define MODULES_EXEC_VADDR MODULES_VADDR
11784 +#define MODULES_EXEC_END MODULES_END
11785 +
11786 +#define ktla_ktva(addr) (addr)
11787 +#define ktva_ktla(addr) (addr)
11788
11789 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
11790 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
11791 index 013286a..8b42f4f 100644
11792 --- a/arch/x86/include/asm/pgtable_types.h
11793 +++ b/arch/x86/include/asm/pgtable_types.h
11794 @@ -16,13 +16,12 @@
11795 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
11796 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
11797 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
11798 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
11799 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
11800 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
11801 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
11802 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
11803 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
11804 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
11805 -#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
11806 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
11807 +#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
11808 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
11809
11810 /* If _PAGE_BIT_PRESENT is clear, we use these: */
11811 @@ -40,7 +39,6 @@
11812 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
11813 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
11814 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
11815 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
11816 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
11817 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
11818 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
11819 @@ -57,8 +55,10 @@
11820
11821 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
11822 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
11823 -#else
11824 +#elif defined(CONFIG_KMEMCHECK)
11825 #define _PAGE_NX (_AT(pteval_t, 0))
11826 +#else
11827 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
11828 #endif
11829
11830 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
11831 @@ -96,6 +96,9 @@
11832 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
11833 _PAGE_ACCESSED)
11834
11835 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
11836 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
11837 +
11838 #define __PAGE_KERNEL_EXEC \
11839 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
11840 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
11841 @@ -106,7 +109,7 @@
11842 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
11843 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
11844 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
11845 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
11846 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
11847 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
11848 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
11849 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
11850 @@ -168,8 +171,8 @@
11851 * bits are combined, this will alow user to access the high address mapped
11852 * VDSO in the presence of CONFIG_COMPAT_VDSO
11853 */
11854 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
11855 -#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
11856 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11857 +#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11858 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
11859 #endif
11860
11861 @@ -207,7 +210,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
11862 {
11863 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
11864 }
11865 +#endif
11866
11867 +#if PAGETABLE_LEVELS == 3
11868 +#include <asm-generic/pgtable-nopud.h>
11869 +#endif
11870 +
11871 +#if PAGETABLE_LEVELS == 2
11872 +#include <asm-generic/pgtable-nopmd.h>
11873 +#endif
11874 +
11875 +#ifndef __ASSEMBLY__
11876 #if PAGETABLE_LEVELS > 3
11877 typedef struct { pudval_t pud; } pud_t;
11878
11879 @@ -221,8 +234,6 @@ static inline pudval_t native_pud_val(pud_t pud)
11880 return pud.pud;
11881 }
11882 #else
11883 -#include <asm-generic/pgtable-nopud.h>
11884 -
11885 static inline pudval_t native_pud_val(pud_t pud)
11886 {
11887 return native_pgd_val(pud.pgd);
11888 @@ -242,8 +253,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
11889 return pmd.pmd;
11890 }
11891 #else
11892 -#include <asm-generic/pgtable-nopmd.h>
11893 -
11894 static inline pmdval_t native_pmd_val(pmd_t pmd)
11895 {
11896 return native_pgd_val(pmd.pud.pgd);
11897 @@ -283,7 +292,6 @@ typedef struct page *pgtable_t;
11898
11899 extern pteval_t __supported_pte_mask;
11900 extern void set_nx(void);
11901 -extern int nx_enabled;
11902
11903 #define pgprot_writecombine pgprot_writecombine
11904 extern pgprot_t pgprot_writecombine(pgprot_t prot);
11905 diff --git a/arch/x86/include/asm/processor-flags.h b/arch/x86/include/asm/processor-flags.h
11906 index aea1d1d..680cf09 100644
11907 --- a/arch/x86/include/asm/processor-flags.h
11908 +++ b/arch/x86/include/asm/processor-flags.h
11909 @@ -65,6 +65,7 @@
11910 #define X86_CR4_PCIDE 0x00020000 /* enable PCID support */
11911 #define X86_CR4_OSXSAVE 0x00040000 /* enable xsave and xrestore */
11912 #define X86_CR4_SMEP 0x00100000 /* enable SMEP support */
11913 +#define X86_CR4_SMAP 0x00200000 /* enable SMAP support */
11914
11915 /*
11916 * x86-64 Task Priority Register, CR8
11917 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
11918 index d048cad..45e350f 100644
11919 --- a/arch/x86/include/asm/processor.h
11920 +++ b/arch/x86/include/asm/processor.h
11921 @@ -289,7 +289,7 @@ struct tss_struct {
11922
11923 } ____cacheline_aligned;
11924
11925 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
11926 +extern struct tss_struct init_tss[NR_CPUS];
11927
11928 /*
11929 * Save the original ist values for checking stack pointers during debugging
11930 @@ -822,11 +822,18 @@ static inline void spin_lock_prefetch(const void *x)
11931 */
11932 #define TASK_SIZE PAGE_OFFSET
11933 #define TASK_SIZE_MAX TASK_SIZE
11934 +
11935 +#ifdef CONFIG_PAX_SEGMEXEC
11936 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
11937 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
11938 +#else
11939 #define STACK_TOP TASK_SIZE
11940 -#define STACK_TOP_MAX STACK_TOP
11941 +#endif
11942 +
11943 +#define STACK_TOP_MAX TASK_SIZE
11944
11945 #define INIT_THREAD { \
11946 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
11947 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11948 .vm86_info = NULL, \
11949 .sysenter_cs = __KERNEL_CS, \
11950 .io_bitmap_ptr = NULL, \
11951 @@ -840,7 +847,7 @@ static inline void spin_lock_prefetch(const void *x)
11952 */
11953 #define INIT_TSS { \
11954 .x86_tss = { \
11955 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
11956 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11957 .ss0 = __KERNEL_DS, \
11958 .ss1 = __KERNEL_CS, \
11959 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
11960 @@ -851,11 +858,7 @@ static inline void spin_lock_prefetch(const void *x)
11961 extern unsigned long thread_saved_pc(struct task_struct *tsk);
11962
11963 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
11964 -#define KSTK_TOP(info) \
11965 -({ \
11966 - unsigned long *__ptr = (unsigned long *)(info); \
11967 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
11968 -})
11969 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
11970
11971 /*
11972 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
11973 @@ -870,7 +873,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11974 #define task_pt_regs(task) \
11975 ({ \
11976 struct pt_regs *__regs__; \
11977 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
11978 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
11979 __regs__ - 1; \
11980 })
11981
11982 @@ -880,13 +883,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11983 /*
11984 * User space process size. 47bits minus one guard page.
11985 */
11986 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
11987 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
11988
11989 /* This decides where the kernel will search for a free chunk of vm
11990 * space during mmap's.
11991 */
11992 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
11993 - 0xc0000000 : 0xFFFFe000)
11994 + 0xc0000000 : 0xFFFFf000)
11995
11996 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
11997 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
11998 @@ -897,11 +900,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11999 #define STACK_TOP_MAX TASK_SIZE_MAX
12000
12001 #define INIT_THREAD { \
12002 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
12003 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
12004 }
12005
12006 #define INIT_TSS { \
12007 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
12008 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
12009 }
12010
12011 /*
12012 @@ -929,6 +932,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
12013 */
12014 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
12015
12016 +#ifdef CONFIG_PAX_SEGMEXEC
12017 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
12018 +#endif
12019 +
12020 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
12021
12022 /* Get/set a process' ability to use the timestamp counter instruction */
12023 @@ -989,12 +996,12 @@ extern bool cpu_has_amd_erratum(const int *);
12024 #define cpu_has_amd_erratum(x) (false)
12025 #endif /* CONFIG_CPU_SUP_AMD */
12026
12027 -extern unsigned long arch_align_stack(unsigned long sp);
12028 +#define arch_align_stack(x) ((x) & ~0xfUL)
12029 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
12030
12031 void default_idle(void);
12032 bool set_pm_idle_to_default(void);
12033
12034 -void stop_this_cpu(void *dummy);
12035 +void stop_this_cpu(void *dummy) __noreturn;
12036
12037 #endif /* _ASM_X86_PROCESSOR_H */
12038 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
12039 index 19f16eb..b50624b 100644
12040 --- a/arch/x86/include/asm/ptrace.h
12041 +++ b/arch/x86/include/asm/ptrace.h
12042 @@ -155,28 +155,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
12043 }
12044
12045 /*
12046 - * user_mode_vm(regs) determines whether a register set came from user mode.
12047 + * user_mode(regs) determines whether a register set came from user mode.
12048 * This is true if V8086 mode was enabled OR if the register set was from
12049 * protected mode with RPL-3 CS value. This tricky test checks that with
12050 * one comparison. Many places in the kernel can bypass this full check
12051 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
12052 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
12053 + * be used.
12054 */
12055 -static inline int user_mode(struct pt_regs *regs)
12056 +static inline int user_mode_novm(struct pt_regs *regs)
12057 {
12058 #ifdef CONFIG_X86_32
12059 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
12060 #else
12061 - return !!(regs->cs & 3);
12062 + return !!(regs->cs & SEGMENT_RPL_MASK);
12063 #endif
12064 }
12065
12066 -static inline int user_mode_vm(struct pt_regs *regs)
12067 +static inline int user_mode(struct pt_regs *regs)
12068 {
12069 #ifdef CONFIG_X86_32
12070 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
12071 USER_RPL;
12072 #else
12073 - return user_mode(regs);
12074 + return user_mode_novm(regs);
12075 #endif
12076 }
12077
12078 @@ -192,15 +193,16 @@ static inline int v8086_mode(struct pt_regs *regs)
12079 #ifdef CONFIG_X86_64
12080 static inline bool user_64bit_mode(struct pt_regs *regs)
12081 {
12082 + unsigned long cs = regs->cs & 0xffff;
12083 #ifndef CONFIG_PARAVIRT
12084 /*
12085 * On non-paravirt systems, this is the only long mode CPL 3
12086 * selector. We do not allow long mode selectors in the LDT.
12087 */
12088 - return regs->cs == __USER_CS;
12089 + return cs == __USER_CS;
12090 #else
12091 /* Headers are too twisted for this to go in paravirt.h. */
12092 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
12093 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
12094 #endif
12095 }
12096 #endif
12097 diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
12098 index fe1ec5b..dc5c3fe 100644
12099 --- a/arch/x86/include/asm/realmode.h
12100 +++ b/arch/x86/include/asm/realmode.h
12101 @@ -22,16 +22,14 @@ struct real_mode_header {
12102 #endif
12103 /* APM/BIOS reboot */
12104 u32 machine_real_restart_asm;
12105 -#ifdef CONFIG_X86_64
12106 u32 machine_real_restart_seg;
12107 -#endif
12108 };
12109
12110 /* This must match data at trampoline_32/64.S */
12111 struct trampoline_header {
12112 #ifdef CONFIG_X86_32
12113 u32 start;
12114 - u16 gdt_pad;
12115 + u16 boot_cs;
12116 u16 gdt_limit;
12117 u32 gdt_base;
12118 #else
12119 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
12120 index a82c4f1..ac45053 100644
12121 --- a/arch/x86/include/asm/reboot.h
12122 +++ b/arch/x86/include/asm/reboot.h
12123 @@ -6,13 +6,13 @@
12124 struct pt_regs;
12125
12126 struct machine_ops {
12127 - void (*restart)(char *cmd);
12128 - void (*halt)(void);
12129 - void (*power_off)(void);
12130 + void (* __noreturn restart)(char *cmd);
12131 + void (* __noreturn halt)(void);
12132 + void (* __noreturn power_off)(void);
12133 void (*shutdown)(void);
12134 void (*crash_shutdown)(struct pt_regs *);
12135 - void (*emergency_restart)(void);
12136 -};
12137 + void (* __noreturn emergency_restart)(void);
12138 +} __no_const;
12139
12140 extern struct machine_ops machine_ops;
12141
12142 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
12143 index 2dbe4a7..ce1db00 100644
12144 --- a/arch/x86/include/asm/rwsem.h
12145 +++ b/arch/x86/include/asm/rwsem.h
12146 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
12147 {
12148 asm volatile("# beginning down_read\n\t"
12149 LOCK_PREFIX _ASM_INC "(%1)\n\t"
12150 +
12151 +#ifdef CONFIG_PAX_REFCOUNT
12152 + "jno 0f\n"
12153 + LOCK_PREFIX _ASM_DEC "(%1)\n"
12154 + "int $4\n0:\n"
12155 + _ASM_EXTABLE(0b, 0b)
12156 +#endif
12157 +
12158 /* adds 0x00000001 */
12159 " jns 1f\n"
12160 " call call_rwsem_down_read_failed\n"
12161 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
12162 "1:\n\t"
12163 " mov %1,%2\n\t"
12164 " add %3,%2\n\t"
12165 +
12166 +#ifdef CONFIG_PAX_REFCOUNT
12167 + "jno 0f\n"
12168 + "sub %3,%2\n"
12169 + "int $4\n0:\n"
12170 + _ASM_EXTABLE(0b, 0b)
12171 +#endif
12172 +
12173 " jle 2f\n\t"
12174 LOCK_PREFIX " cmpxchg %2,%0\n\t"
12175 " jnz 1b\n\t"
12176 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
12177 long tmp;
12178 asm volatile("# beginning down_write\n\t"
12179 LOCK_PREFIX " xadd %1,(%2)\n\t"
12180 +
12181 +#ifdef CONFIG_PAX_REFCOUNT
12182 + "jno 0f\n"
12183 + "mov %1,(%2)\n"
12184 + "int $4\n0:\n"
12185 + _ASM_EXTABLE(0b, 0b)
12186 +#endif
12187 +
12188 /* adds 0xffff0001, returns the old value */
12189 " test %1,%1\n\t"
12190 /* was the count 0 before? */
12191 @@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
12192 long tmp;
12193 asm volatile("# beginning __up_read\n\t"
12194 LOCK_PREFIX " xadd %1,(%2)\n\t"
12195 +
12196 +#ifdef CONFIG_PAX_REFCOUNT
12197 + "jno 0f\n"
12198 + "mov %1,(%2)\n"
12199 + "int $4\n0:\n"
12200 + _ASM_EXTABLE(0b, 0b)
12201 +#endif
12202 +
12203 /* subtracts 1, returns the old value */
12204 " jns 1f\n\t"
12205 " call call_rwsem_wake\n" /* expects old value in %edx */
12206 @@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
12207 long tmp;
12208 asm volatile("# beginning __up_write\n\t"
12209 LOCK_PREFIX " xadd %1,(%2)\n\t"
12210 +
12211 +#ifdef CONFIG_PAX_REFCOUNT
12212 + "jno 0f\n"
12213 + "mov %1,(%2)\n"
12214 + "int $4\n0:\n"
12215 + _ASM_EXTABLE(0b, 0b)
12216 +#endif
12217 +
12218 /* subtracts 0xffff0001, returns the old value */
12219 " jns 1f\n\t"
12220 " call call_rwsem_wake\n" /* expects old value in %edx */
12221 @@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12222 {
12223 asm volatile("# beginning __downgrade_write\n\t"
12224 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
12225 +
12226 +#ifdef CONFIG_PAX_REFCOUNT
12227 + "jno 0f\n"
12228 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
12229 + "int $4\n0:\n"
12230 + _ASM_EXTABLE(0b, 0b)
12231 +#endif
12232 +
12233 /*
12234 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
12235 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
12236 @@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12237 */
12238 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12239 {
12240 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
12241 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
12242 +
12243 +#ifdef CONFIG_PAX_REFCOUNT
12244 + "jno 0f\n"
12245 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
12246 + "int $4\n0:\n"
12247 + _ASM_EXTABLE(0b, 0b)
12248 +#endif
12249 +
12250 : "+m" (sem->count)
12251 : "er" (delta));
12252 }
12253 @@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12254 */
12255 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
12256 {
12257 - return delta + xadd(&sem->count, delta);
12258 + return delta + xadd_check_overflow(&sem->count, delta);
12259 }
12260
12261 #endif /* __KERNEL__ */
12262 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
12263 index c48a950..c6d7468 100644
12264 --- a/arch/x86/include/asm/segment.h
12265 +++ b/arch/x86/include/asm/segment.h
12266 @@ -64,10 +64,15 @@
12267 * 26 - ESPFIX small SS
12268 * 27 - per-cpu [ offset to per-cpu data area ]
12269 * 28 - stack_canary-20 [ for stack protector ]
12270 - * 29 - unused
12271 - * 30 - unused
12272 + * 29 - PCI BIOS CS
12273 + * 30 - PCI BIOS DS
12274 * 31 - TSS for double fault handler
12275 */
12276 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
12277 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
12278 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
12279 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
12280 +
12281 #define GDT_ENTRY_TLS_MIN 6
12282 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
12283
12284 @@ -79,6 +84,8 @@
12285
12286 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
12287
12288 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
12289 +
12290 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
12291
12292 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
12293 @@ -104,6 +111,12 @@
12294 #define __KERNEL_STACK_CANARY 0
12295 #endif
12296
12297 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
12298 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
12299 +
12300 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
12301 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
12302 +
12303 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
12304
12305 /*
12306 @@ -141,7 +154,7 @@
12307 */
12308
12309 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
12310 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
12311 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
12312
12313
12314 #else
12315 @@ -165,6 +178,8 @@
12316 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
12317 #define __USER32_DS __USER_DS
12318
12319 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
12320 +
12321 #define GDT_ENTRY_TSS 8 /* needs two entries */
12322 #define GDT_ENTRY_LDT 10 /* needs two entries */
12323 #define GDT_ENTRY_TLS_MIN 12
12324 @@ -185,6 +200,7 @@
12325 #endif
12326
12327 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
12328 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
12329 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
12330 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
12331 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
12332 @@ -265,7 +281,7 @@ static inline unsigned long get_limit(unsigned long segment)
12333 {
12334 unsigned long __limit;
12335 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
12336 - return __limit + 1;
12337 + return __limit;
12338 }
12339
12340 #endif /* !__ASSEMBLY__ */
12341 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
12342 index 4f19a15..9e14f27 100644
12343 --- a/arch/x86/include/asm/smp.h
12344 +++ b/arch/x86/include/asm/smp.h
12345 @@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
12346 /* cpus sharing the last level cache: */
12347 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
12348 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
12349 -DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
12350 +DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
12351
12352 static inline struct cpumask *cpu_sibling_mask(int cpu)
12353 {
12354 @@ -79,7 +79,7 @@ struct smp_ops {
12355
12356 void (*send_call_func_ipi)(const struct cpumask *mask);
12357 void (*send_call_func_single_ipi)(int cpu);
12358 -};
12359 +} __no_const;
12360
12361 /* Globals due to paravirt */
12362 extern void set_cpu_sibling_map(int cpu);
12363 @@ -190,14 +190,8 @@ extern unsigned disabled_cpus __cpuinitdata;
12364 extern int safe_smp_processor_id(void);
12365
12366 #elif defined(CONFIG_X86_64_SMP)
12367 -#define raw_smp_processor_id() (this_cpu_read(cpu_number))
12368 -
12369 -#define stack_smp_processor_id() \
12370 -({ \
12371 - struct thread_info *ti; \
12372 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
12373 - ti->cpu; \
12374 -})
12375 +#define raw_smp_processor_id() (this_cpu_read(cpu_number))
12376 +#define stack_smp_processor_id() raw_smp_processor_id()
12377 #define safe_smp_processor_id() smp_processor_id()
12378
12379 #endif
12380 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
12381 index 33692ea..350a534 100644
12382 --- a/arch/x86/include/asm/spinlock.h
12383 +++ b/arch/x86/include/asm/spinlock.h
12384 @@ -172,6 +172,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
12385 static inline void arch_read_lock(arch_rwlock_t *rw)
12386 {
12387 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
12388 +
12389 +#ifdef CONFIG_PAX_REFCOUNT
12390 + "jno 0f\n"
12391 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
12392 + "int $4\n0:\n"
12393 + _ASM_EXTABLE(0b, 0b)
12394 +#endif
12395 +
12396 "jns 1f\n"
12397 "call __read_lock_failed\n\t"
12398 "1:\n"
12399 @@ -181,6 +189,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
12400 static inline void arch_write_lock(arch_rwlock_t *rw)
12401 {
12402 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
12403 +
12404 +#ifdef CONFIG_PAX_REFCOUNT
12405 + "jno 0f\n"
12406 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
12407 + "int $4\n0:\n"
12408 + _ASM_EXTABLE(0b, 0b)
12409 +#endif
12410 +
12411 "jz 1f\n"
12412 "call __write_lock_failed\n\t"
12413 "1:\n"
12414 @@ -210,13 +226,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
12415
12416 static inline void arch_read_unlock(arch_rwlock_t *rw)
12417 {
12418 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
12419 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
12420 +
12421 +#ifdef CONFIG_PAX_REFCOUNT
12422 + "jno 0f\n"
12423 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
12424 + "int $4\n0:\n"
12425 + _ASM_EXTABLE(0b, 0b)
12426 +#endif
12427 +
12428 :"+m" (rw->lock) : : "memory");
12429 }
12430
12431 static inline void arch_write_unlock(arch_rwlock_t *rw)
12432 {
12433 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
12434 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
12435 +
12436 +#ifdef CONFIG_PAX_REFCOUNT
12437 + "jno 0f\n"
12438 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
12439 + "int $4\n0:\n"
12440 + _ASM_EXTABLE(0b, 0b)
12441 +#endif
12442 +
12443 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
12444 }
12445
12446 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
12447 index 6a99859..03cb807 100644
12448 --- a/arch/x86/include/asm/stackprotector.h
12449 +++ b/arch/x86/include/asm/stackprotector.h
12450 @@ -47,7 +47,7 @@
12451 * head_32 for boot CPU and setup_per_cpu_areas() for others.
12452 */
12453 #define GDT_STACK_CANARY_INIT \
12454 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
12455 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
12456
12457 /*
12458 * Initialize the stackprotector canary value.
12459 @@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
12460
12461 static inline void load_stack_canary_segment(void)
12462 {
12463 -#ifdef CONFIG_X86_32
12464 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
12465 asm volatile ("mov %0, %%gs" : : "r" (0));
12466 #endif
12467 }
12468 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
12469 index 70bbe39..4ae2bd4 100644
12470 --- a/arch/x86/include/asm/stacktrace.h
12471 +++ b/arch/x86/include/asm/stacktrace.h
12472 @@ -11,28 +11,20 @@
12473
12474 extern int kstack_depth_to_print;
12475
12476 -struct thread_info;
12477 +struct task_struct;
12478 struct stacktrace_ops;
12479
12480 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
12481 - unsigned long *stack,
12482 - unsigned long bp,
12483 - const struct stacktrace_ops *ops,
12484 - void *data,
12485 - unsigned long *end,
12486 - int *graph);
12487 +typedef unsigned long walk_stack_t(struct task_struct *task,
12488 + void *stack_start,
12489 + unsigned long *stack,
12490 + unsigned long bp,
12491 + const struct stacktrace_ops *ops,
12492 + void *data,
12493 + unsigned long *end,
12494 + int *graph);
12495
12496 -extern unsigned long
12497 -print_context_stack(struct thread_info *tinfo,
12498 - unsigned long *stack, unsigned long bp,
12499 - const struct stacktrace_ops *ops, void *data,
12500 - unsigned long *end, int *graph);
12501 -
12502 -extern unsigned long
12503 -print_context_stack_bp(struct thread_info *tinfo,
12504 - unsigned long *stack, unsigned long bp,
12505 - const struct stacktrace_ops *ops, void *data,
12506 - unsigned long *end, int *graph);
12507 +extern walk_stack_t print_context_stack;
12508 +extern walk_stack_t print_context_stack_bp;
12509
12510 /* Generic stack tracer with callbacks */
12511
12512 @@ -40,7 +32,7 @@ struct stacktrace_ops {
12513 void (*address)(void *data, unsigned long address, int reliable);
12514 /* On negative return stop dumping */
12515 int (*stack)(void *data, char *name);
12516 - walk_stack_t walk_stack;
12517 + walk_stack_t *walk_stack;
12518 };
12519
12520 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
12521 diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
12522 index 4ec45b3..a4f0a8a 100644
12523 --- a/arch/x86/include/asm/switch_to.h
12524 +++ b/arch/x86/include/asm/switch_to.h
12525 @@ -108,7 +108,7 @@ do { \
12526 "call __switch_to\n\t" \
12527 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
12528 __switch_canary \
12529 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
12530 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
12531 "movq %%rax,%%rdi\n\t" \
12532 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
12533 "jnz ret_from_fork\n\t" \
12534 @@ -119,7 +119,7 @@ do { \
12535 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
12536 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
12537 [_tif_fork] "i" (_TIF_FORK), \
12538 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
12539 + [thread_info] "m" (current_tinfo), \
12540 [current_task] "m" (current_task) \
12541 __switch_canary_iparam \
12542 : "memory", "cc" __EXTRA_CLOBBER)
12543 diff --git a/arch/x86/include/asm/sys_ia32.h b/arch/x86/include/asm/sys_ia32.h
12544 index 3fda9db4..4ca1c61 100644
12545 --- a/arch/x86/include/asm/sys_ia32.h
12546 +++ b/arch/x86/include/asm/sys_ia32.h
12547 @@ -40,7 +40,7 @@ asmlinkage long sys32_sigaction(int, struct old_sigaction32 __user *,
12548 struct old_sigaction32 __user *);
12549 asmlinkage long sys32_alarm(unsigned int);
12550
12551 -asmlinkage long sys32_waitpid(compat_pid_t, unsigned int *, int);
12552 +asmlinkage long sys32_waitpid(compat_pid_t, unsigned int __user *, int);
12553 asmlinkage long sys32_sysfs(int, u32, u32);
12554
12555 asmlinkage long sys32_sched_rr_get_interval(compat_pid_t,
12556 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
12557 index 89f794f..1422765 100644
12558 --- a/arch/x86/include/asm/thread_info.h
12559 +++ b/arch/x86/include/asm/thread_info.h
12560 @@ -10,6 +10,7 @@
12561 #include <linux/compiler.h>
12562 #include <asm/page.h>
12563 #include <asm/types.h>
12564 +#include <asm/percpu.h>
12565
12566 /*
12567 * low level task data that entry.S needs immediate access to
12568 @@ -24,7 +25,6 @@ struct exec_domain;
12569 #include <linux/atomic.h>
12570
12571 struct thread_info {
12572 - struct task_struct *task; /* main task structure */
12573 struct exec_domain *exec_domain; /* execution domain */
12574 __u32 flags; /* low level flags */
12575 __u32 status; /* thread synchronous flags */
12576 @@ -34,19 +34,13 @@ struct thread_info {
12577 mm_segment_t addr_limit;
12578 struct restart_block restart_block;
12579 void __user *sysenter_return;
12580 -#ifdef CONFIG_X86_32
12581 - unsigned long previous_esp; /* ESP of the previous stack in
12582 - case of nested (IRQ) stacks
12583 - */
12584 - __u8 supervisor_stack[0];
12585 -#endif
12586 + unsigned long lowest_stack;
12587 unsigned int sig_on_uaccess_error:1;
12588 unsigned int uaccess_err:1; /* uaccess failed */
12589 };
12590
12591 -#define INIT_THREAD_INFO(tsk) \
12592 +#define INIT_THREAD_INFO \
12593 { \
12594 - .task = &tsk, \
12595 .exec_domain = &default_exec_domain, \
12596 .flags = 0, \
12597 .cpu = 0, \
12598 @@ -57,7 +51,7 @@ struct thread_info {
12599 }, \
12600 }
12601
12602 -#define init_thread_info (init_thread_union.thread_info)
12603 +#define init_thread_info (init_thread_union.stack)
12604 #define init_stack (init_thread_union.stack)
12605
12606 #else /* !__ASSEMBLY__ */
12607 @@ -98,6 +92,7 @@ struct thread_info {
12608 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
12609 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
12610 #define TIF_X32 30 /* 32-bit native x86-64 binary */
12611 +#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
12612
12613 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
12614 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
12615 @@ -122,16 +117,18 @@ struct thread_info {
12616 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
12617 #define _TIF_ADDR32 (1 << TIF_ADDR32)
12618 #define _TIF_X32 (1 << TIF_X32)
12619 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
12620
12621 /* work to do in syscall_trace_enter() */
12622 #define _TIF_WORK_SYSCALL_ENTRY \
12623 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
12624 - _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT)
12625 + _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
12626 + _TIF_GRSEC_SETXID)
12627
12628 /* work to do in syscall_trace_leave() */
12629 #define _TIF_WORK_SYSCALL_EXIT \
12630 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
12631 - _TIF_SYSCALL_TRACEPOINT)
12632 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
12633
12634 /* work to do on interrupt/exception return */
12635 #define _TIF_WORK_MASK \
12636 @@ -141,7 +138,8 @@ struct thread_info {
12637
12638 /* work to do on any return to user space */
12639 #define _TIF_ALLWORK_MASK \
12640 - ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT)
12641 + ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
12642 + _TIF_GRSEC_SETXID)
12643
12644 /* Only used for 64 bit */
12645 #define _TIF_DO_NOTIFY_MASK \
12646 @@ -157,45 +155,40 @@ struct thread_info {
12647
12648 #define PREEMPT_ACTIVE 0x10000000
12649
12650 -#ifdef CONFIG_X86_32
12651 -
12652 -#define STACK_WARN (THREAD_SIZE/8)
12653 -/*
12654 - * macros/functions for gaining access to the thread information structure
12655 - *
12656 - * preempt_count needs to be 1 initially, until the scheduler is functional.
12657 - */
12658 -#ifndef __ASSEMBLY__
12659 -
12660 -
12661 -/* how to get the current stack pointer from C */
12662 -register unsigned long current_stack_pointer asm("esp") __used;
12663 -
12664 -/* how to get the thread information struct from C */
12665 -static inline struct thread_info *current_thread_info(void)
12666 -{
12667 - return (struct thread_info *)
12668 - (current_stack_pointer & ~(THREAD_SIZE - 1));
12669 -}
12670 -
12671 -#else /* !__ASSEMBLY__ */
12672 -
12673 +#ifdef __ASSEMBLY__
12674 /* how to get the thread information struct from ASM */
12675 #define GET_THREAD_INFO(reg) \
12676 - movl $-THREAD_SIZE, reg; \
12677 - andl %esp, reg
12678 + mov PER_CPU_VAR(current_tinfo), reg
12679
12680 /* use this one if reg already contains %esp */
12681 -#define GET_THREAD_INFO_WITH_ESP(reg) \
12682 - andl $-THREAD_SIZE, reg
12683 +#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
12684 +#else
12685 +/* how to get the thread information struct from C */
12686 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
12687 +
12688 +static __always_inline struct thread_info *current_thread_info(void)
12689 +{
12690 + return this_cpu_read_stable(current_tinfo);
12691 +}
12692 +#endif
12693 +
12694 +#ifdef CONFIG_X86_32
12695 +
12696 +#define STACK_WARN (THREAD_SIZE/8)
12697 +/*
12698 + * macros/functions for gaining access to the thread information structure
12699 + *
12700 + * preempt_count needs to be 1 initially, until the scheduler is functional.
12701 + */
12702 +#ifndef __ASSEMBLY__
12703 +
12704 +/* how to get the current stack pointer from C */
12705 +register unsigned long current_stack_pointer asm("esp") __used;
12706
12707 #endif
12708
12709 #else /* X86_32 */
12710
12711 -#include <asm/percpu.h>
12712 -#define KERNEL_STACK_OFFSET (5*8)
12713 -
12714 /*
12715 * macros/functions for gaining access to the thread information structure
12716 * preempt_count needs to be 1 initially, until the scheduler is functional.
12717 @@ -203,27 +196,8 @@ static inline struct thread_info *current_thread_info(void)
12718 #ifndef __ASSEMBLY__
12719 DECLARE_PER_CPU(unsigned long, kernel_stack);
12720
12721 -static inline struct thread_info *current_thread_info(void)
12722 -{
12723 - struct thread_info *ti;
12724 - ti = (void *)(this_cpu_read_stable(kernel_stack) +
12725 - KERNEL_STACK_OFFSET - THREAD_SIZE);
12726 - return ti;
12727 -}
12728 -
12729 -#else /* !__ASSEMBLY__ */
12730 -
12731 -/* how to get the thread information struct from ASM */
12732 -#define GET_THREAD_INFO(reg) \
12733 - movq PER_CPU_VAR(kernel_stack),reg ; \
12734 - subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
12735 -
12736 -/*
12737 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
12738 - * a certain register (to be used in assembler memory operands).
12739 - */
12740 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
12741 -
12742 +/* how to get the current stack pointer from C */
12743 +register unsigned long current_stack_pointer asm("rsp") __used;
12744 #endif
12745
12746 #endif /* !X86_32 */
12747 @@ -284,5 +258,12 @@ static inline bool is_ia32_task(void)
12748 extern void arch_task_cache_init(void);
12749 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
12750 extern void arch_release_task_struct(struct task_struct *tsk);
12751 +
12752 +#define __HAVE_THREAD_FUNCTIONS
12753 +#define task_thread_info(task) (&(task)->tinfo)
12754 +#define task_stack_page(task) ((task)->stack)
12755 +#define setup_thread_stack(p, org) do {} while (0)
12756 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
12757 +
12758 #endif
12759 #endif /* _ASM_X86_THREAD_INFO_H */
12760 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
12761 index e1f3a17..1ab364d 100644
12762 --- a/arch/x86/include/asm/uaccess.h
12763 +++ b/arch/x86/include/asm/uaccess.h
12764 @@ -7,12 +7,15 @@
12765 #include <linux/compiler.h>
12766 #include <linux/thread_info.h>
12767 #include <linux/string.h>
12768 +#include <linux/sched.h>
12769 #include <asm/asm.h>
12770 #include <asm/page.h>
12771
12772 #define VERIFY_READ 0
12773 #define VERIFY_WRITE 1
12774
12775 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
12776 +
12777 /*
12778 * The fs value determines whether argument validity checking should be
12779 * performed or not. If get_fs() == USER_DS, checking is performed, with
12780 @@ -28,7 +31,12 @@
12781
12782 #define get_ds() (KERNEL_DS)
12783 #define get_fs() (current_thread_info()->addr_limit)
12784 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12785 +void __set_fs(mm_segment_t x);
12786 +void set_fs(mm_segment_t x);
12787 +#else
12788 #define set_fs(x) (current_thread_info()->addr_limit = (x))
12789 +#endif
12790
12791 #define segment_eq(a, b) ((a).seg == (b).seg)
12792
12793 @@ -76,8 +84,33 @@
12794 * checks that the pointer is in the user space range - after calling
12795 * this function, memory access functions may still return -EFAULT.
12796 */
12797 -#define access_ok(type, addr, size) \
12798 - (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
12799 +#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
12800 +#define access_ok(type, addr, size) \
12801 +({ \
12802 + long __size = size; \
12803 + unsigned long __addr = (unsigned long)addr; \
12804 + unsigned long __addr_ao = __addr & PAGE_MASK; \
12805 + unsigned long __end_ao = __addr + __size - 1; \
12806 + bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
12807 + if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
12808 + while(__addr_ao <= __end_ao) { \
12809 + char __c_ao; \
12810 + __addr_ao += PAGE_SIZE; \
12811 + if (__size > PAGE_SIZE) \
12812 + cond_resched(); \
12813 + if (__get_user(__c_ao, (char __user *)__addr)) \
12814 + break; \
12815 + if (type != VERIFY_WRITE) { \
12816 + __addr = __addr_ao; \
12817 + continue; \
12818 + } \
12819 + if (__put_user(__c_ao, (char __user *)__addr)) \
12820 + break; \
12821 + __addr = __addr_ao; \
12822 + } \
12823 + } \
12824 + __ret_ao; \
12825 +})
12826
12827 /*
12828 * The exception table consists of pairs of addresses relative to the
12829 @@ -188,12 +221,20 @@ extern int __get_user_bad(void);
12830 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
12831 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
12832
12833 -
12834 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12835 +#define __copyuser_seg "gs;"
12836 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
12837 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
12838 +#else
12839 +#define __copyuser_seg
12840 +#define __COPYUSER_SET_ES
12841 +#define __COPYUSER_RESTORE_ES
12842 +#endif
12843
12844 #ifdef CONFIG_X86_32
12845 #define __put_user_asm_u64(x, addr, err, errret) \
12846 - asm volatile("1: movl %%eax,0(%2)\n" \
12847 - "2: movl %%edx,4(%2)\n" \
12848 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%2)\n" \
12849 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
12850 "3:\n" \
12851 ".section .fixup,\"ax\"\n" \
12852 "4: movl %3,%0\n" \
12853 @@ -205,8 +246,8 @@ extern int __get_user_bad(void);
12854 : "A" (x), "r" (addr), "i" (errret), "0" (err))
12855
12856 #define __put_user_asm_ex_u64(x, addr) \
12857 - asm volatile("1: movl %%eax,0(%1)\n" \
12858 - "2: movl %%edx,4(%1)\n" \
12859 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%1)\n" \
12860 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
12861 "3:\n" \
12862 _ASM_EXTABLE_EX(1b, 2b) \
12863 _ASM_EXTABLE_EX(2b, 3b) \
12864 @@ -258,7 +299,7 @@ extern void __put_user_8(void);
12865 __typeof__(*(ptr)) __pu_val; \
12866 __chk_user_ptr(ptr); \
12867 might_fault(); \
12868 - __pu_val = x; \
12869 + __pu_val = (x); \
12870 switch (sizeof(*(ptr))) { \
12871 case 1: \
12872 __put_user_x(1, __pu_val, ptr, __ret_pu); \
12873 @@ -379,7 +420,7 @@ do { \
12874 } while (0)
12875
12876 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12877 - asm volatile("1: mov"itype" %2,%"rtype"1\n" \
12878 + asm volatile("1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
12879 "2:\n" \
12880 ".section .fixup,\"ax\"\n" \
12881 "3: mov %3,%0\n" \
12882 @@ -387,7 +428,7 @@ do { \
12883 " jmp 2b\n" \
12884 ".previous\n" \
12885 _ASM_EXTABLE(1b, 3b) \
12886 - : "=r" (err), ltype(x) \
12887 + : "=r" (err), ltype (x) \
12888 : "m" (__m(addr)), "i" (errret), "0" (err))
12889
12890 #define __get_user_size_ex(x, ptr, size) \
12891 @@ -412,7 +453,7 @@ do { \
12892 } while (0)
12893
12894 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
12895 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
12896 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
12897 "2:\n" \
12898 _ASM_EXTABLE_EX(1b, 2b) \
12899 : ltype(x) : "m" (__m(addr)))
12900 @@ -429,13 +470,24 @@ do { \
12901 int __gu_err; \
12902 unsigned long __gu_val; \
12903 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
12904 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
12905 + (x) = (__typeof__(*(ptr)))__gu_val; \
12906 __gu_err; \
12907 })
12908
12909 /* FIXME: this hack is definitely wrong -AK */
12910 struct __large_struct { unsigned long buf[100]; };
12911 -#define __m(x) (*(struct __large_struct __user *)(x))
12912 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12913 +#define ____m(x) \
12914 +({ \
12915 + unsigned long ____x = (unsigned long)(x); \
12916 + if (____x < PAX_USER_SHADOW_BASE) \
12917 + ____x += PAX_USER_SHADOW_BASE; \
12918 + (void __user *)____x; \
12919 +})
12920 +#else
12921 +#define ____m(x) (x)
12922 +#endif
12923 +#define __m(x) (*(struct __large_struct __user *)____m(x))
12924
12925 /*
12926 * Tell gcc we read from memory instead of writing: this is because
12927 @@ -443,7 +495,7 @@ struct __large_struct { unsigned long buf[100]; };
12928 * aliasing issues.
12929 */
12930 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12931 - asm volatile("1: mov"itype" %"rtype"1,%2\n" \
12932 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
12933 "2:\n" \
12934 ".section .fixup,\"ax\"\n" \
12935 "3: mov %3,%0\n" \
12936 @@ -451,10 +503,10 @@ struct __large_struct { unsigned long buf[100]; };
12937 ".previous\n" \
12938 _ASM_EXTABLE(1b, 3b) \
12939 : "=r"(err) \
12940 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
12941 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
12942
12943 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
12944 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
12945 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
12946 "2:\n" \
12947 _ASM_EXTABLE_EX(1b, 2b) \
12948 : : ltype(x), "m" (__m(addr)))
12949 @@ -493,8 +545,12 @@ struct __large_struct { unsigned long buf[100]; };
12950 * On error, the variable @x is set to zero.
12951 */
12952
12953 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12954 +#define __get_user(x, ptr) get_user((x), (ptr))
12955 +#else
12956 #define __get_user(x, ptr) \
12957 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
12958 +#endif
12959
12960 /**
12961 * __put_user: - Write a simple value into user space, with less checking.
12962 @@ -516,8 +572,12 @@ struct __large_struct { unsigned long buf[100]; };
12963 * Returns zero on success, or -EFAULT on error.
12964 */
12965
12966 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12967 +#define __put_user(x, ptr) put_user((x), (ptr))
12968 +#else
12969 #define __put_user(x, ptr) \
12970 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
12971 +#endif
12972
12973 #define __get_user_unaligned __get_user
12974 #define __put_user_unaligned __put_user
12975 @@ -535,7 +595,7 @@ struct __large_struct { unsigned long buf[100]; };
12976 #define get_user_ex(x, ptr) do { \
12977 unsigned long __gue_val; \
12978 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
12979 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
12980 + (x) = (__typeof__(*(ptr)))__gue_val; \
12981 } while (0)
12982
12983 #ifdef CONFIG_X86_WP_WORKS_OK
12984 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
12985 index 576e39b..ccd0a39 100644
12986 --- a/arch/x86/include/asm/uaccess_32.h
12987 +++ b/arch/x86/include/asm/uaccess_32.h
12988 @@ -11,15 +11,15 @@
12989 #include <asm/page.h>
12990
12991 unsigned long __must_check __copy_to_user_ll
12992 - (void __user *to, const void *from, unsigned long n);
12993 + (void __user *to, const void *from, unsigned long n) __size_overflow(3);
12994 unsigned long __must_check __copy_from_user_ll
12995 - (void *to, const void __user *from, unsigned long n);
12996 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12997 unsigned long __must_check __copy_from_user_ll_nozero
12998 - (void *to, const void __user *from, unsigned long n);
12999 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
13000 unsigned long __must_check __copy_from_user_ll_nocache
13001 - (void *to, const void __user *from, unsigned long n);
13002 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
13003 unsigned long __must_check __copy_from_user_ll_nocache_nozero
13004 - (void *to, const void __user *from, unsigned long n);
13005 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
13006
13007 /**
13008 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
13009 @@ -43,6 +43,9 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
13010 static __always_inline unsigned long __must_check
13011 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
13012 {
13013 + if ((long)n < 0)
13014 + return n;
13015 +
13016 if (__builtin_constant_p(n)) {
13017 unsigned long ret;
13018
13019 @@ -61,6 +64,8 @@ __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
13020 return ret;
13021 }
13022 }
13023 + if (!__builtin_constant_p(n))
13024 + check_object_size(from, n, true);
13025 return __copy_to_user_ll(to, from, n);
13026 }
13027
13028 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
13029 __copy_to_user(void __user *to, const void *from, unsigned long n)
13030 {
13031 might_fault();
13032 +
13033 return __copy_to_user_inatomic(to, from, n);
13034 }
13035
13036 static __always_inline unsigned long
13037 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
13038 {
13039 + if ((long)n < 0)
13040 + return n;
13041 +
13042 /* Avoid zeroing the tail if the copy fails..
13043 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
13044 * but as the zeroing behaviour is only significant when n is not
13045 @@ -137,6 +146,10 @@ static __always_inline unsigned long
13046 __copy_from_user(void *to, const void __user *from, unsigned long n)
13047 {
13048 might_fault();
13049 +
13050 + if ((long)n < 0)
13051 + return n;
13052 +
13053 if (__builtin_constant_p(n)) {
13054 unsigned long ret;
13055
13056 @@ -152,6 +165,8 @@ __copy_from_user(void *to, const void __user *from, unsigned long n)
13057 return ret;
13058 }
13059 }
13060 + if (!__builtin_constant_p(n))
13061 + check_object_size(to, n, false);
13062 return __copy_from_user_ll(to, from, n);
13063 }
13064
13065 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
13066 const void __user *from, unsigned long n)
13067 {
13068 might_fault();
13069 +
13070 + if ((long)n < 0)
13071 + return n;
13072 +
13073 if (__builtin_constant_p(n)) {
13074 unsigned long ret;
13075
13076 @@ -181,15 +200,19 @@ static __always_inline unsigned long
13077 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
13078 unsigned long n)
13079 {
13080 - return __copy_from_user_ll_nocache_nozero(to, from, n);
13081 + if ((long)n < 0)
13082 + return n;
13083 +
13084 + return __copy_from_user_ll_nocache_nozero(to, from, n);
13085 }
13086
13087 -unsigned long __must_check copy_to_user(void __user *to,
13088 - const void *from, unsigned long n);
13089 -unsigned long __must_check _copy_from_user(void *to,
13090 - const void __user *from,
13091 - unsigned long n);
13092 -
13093 +extern void copy_to_user_overflow(void)
13094 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13095 + __compiletime_error("copy_to_user() buffer size is not provably correct")
13096 +#else
13097 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
13098 +#endif
13099 +;
13100
13101 extern void copy_from_user_overflow(void)
13102 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13103 @@ -199,21 +222,65 @@ extern void copy_from_user_overflow(void)
13104 #endif
13105 ;
13106
13107 -static inline unsigned long __must_check copy_from_user(void *to,
13108 - const void __user *from,
13109 - unsigned long n)
13110 +/**
13111 + * copy_to_user: - Copy a block of data into user space.
13112 + * @to: Destination address, in user space.
13113 + * @from: Source address, in kernel space.
13114 + * @n: Number of bytes to copy.
13115 + *
13116 + * Context: User context only. This function may sleep.
13117 + *
13118 + * Copy data from kernel space to user space.
13119 + *
13120 + * Returns number of bytes that could not be copied.
13121 + * On success, this will be zero.
13122 + */
13123 +static inline unsigned long __must_check
13124 +copy_to_user(void __user *to, const void *from, unsigned long n)
13125 {
13126 - int sz = __compiletime_object_size(to);
13127 + size_t sz = __compiletime_object_size(from);
13128
13129 - if (likely(sz == -1 || sz >= n))
13130 - n = _copy_from_user(to, from, n);
13131 - else
13132 + if (unlikely(sz != (size_t)-1 && sz < n))
13133 + copy_to_user_overflow();
13134 + else if (access_ok(VERIFY_WRITE, to, n))
13135 + n = __copy_to_user(to, from, n);
13136 + return n;
13137 +}
13138 +
13139 +/**
13140 + * copy_from_user: - Copy a block of data from user space.
13141 + * @to: Destination address, in kernel space.
13142 + * @from: Source address, in user space.
13143 + * @n: Number of bytes to copy.
13144 + *
13145 + * Context: User context only. This function may sleep.
13146 + *
13147 + * Copy data from user space to kernel space.
13148 + *
13149 + * Returns number of bytes that could not be copied.
13150 + * On success, this will be zero.
13151 + *
13152 + * If some data could not be copied, this function will pad the copied
13153 + * data to the requested size using zero bytes.
13154 + */
13155 +static inline unsigned long __must_check
13156 +copy_from_user(void *to, const void __user *from, unsigned long n)
13157 +{
13158 + size_t sz = __compiletime_object_size(to);
13159 +
13160 + if (unlikely(sz != (size_t)-1 && sz < n))
13161 copy_from_user_overflow();
13162 -
13163 + else if (access_ok(VERIFY_READ, from, n))
13164 + n = __copy_from_user(to, from, n);
13165 + else if ((long)n > 0) {
13166 + if (!__builtin_constant_p(n))
13167 + check_object_size(to, n, false);
13168 + memset(to, 0, n);
13169 + }
13170 return n;
13171 }
13172
13173 -unsigned long __must_check clear_user(void __user *mem, unsigned long len);
13174 -unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
13175 +unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13176 +unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13177
13178 #endif /* _ASM_X86_UACCESS_32_H */
13179 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
13180 index d8def8b..6052b20 100644
13181 --- a/arch/x86/include/asm/uaccess_64.h
13182 +++ b/arch/x86/include/asm/uaccess_64.h
13183 @@ -10,6 +10,9 @@
13184 #include <asm/alternative.h>
13185 #include <asm/cpufeature.h>
13186 #include <asm/page.h>
13187 +#include <asm/pgtable.h>
13188 +
13189 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
13190
13191 /*
13192 * Copy To/From Userspace
13193 @@ -17,13 +20,13 @@
13194
13195 /* Handles exceptions in both to and from, but doesn't do access_ok */
13196 __must_check unsigned long
13197 -copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
13198 +copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
13199 __must_check unsigned long
13200 -copy_user_generic_string(void *to, const void *from, unsigned len);
13201 +copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
13202 __must_check unsigned long
13203 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
13204 +copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
13205
13206 -static __always_inline __must_check unsigned long
13207 +static __always_inline __must_check __size_overflow(3) unsigned long
13208 copy_user_generic(void *to, const void *from, unsigned len)
13209 {
13210 unsigned ret;
13211 @@ -41,142 +44,205 @@ copy_user_generic(void *to, const void *from, unsigned len)
13212 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
13213 "=d" (len)),
13214 "1" (to), "2" (from), "3" (len)
13215 - : "memory", "rcx", "r8", "r9", "r10", "r11");
13216 + : "memory", "rcx", "r8", "r9", "r11");
13217 return ret;
13218 }
13219
13220 +static __always_inline __must_check unsigned long
13221 +__copy_to_user(void __user *to, const void *from, unsigned long len) __size_overflow(3);
13222 +static __always_inline __must_check unsigned long
13223 +__copy_from_user(void *to, const void __user *from, unsigned long len) __size_overflow(3);
13224 __must_check unsigned long
13225 -_copy_to_user(void __user *to, const void *from, unsigned len);
13226 -__must_check unsigned long
13227 -_copy_from_user(void *to, const void __user *from, unsigned len);
13228 -__must_check unsigned long
13229 -copy_in_user(void __user *to, const void __user *from, unsigned len);
13230 +copy_in_user(void __user *to, const void __user *from, unsigned long len) __size_overflow(3);
13231 +
13232 +extern void copy_to_user_overflow(void)
13233 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13234 + __compiletime_error("copy_to_user() buffer size is not provably correct")
13235 +#else
13236 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
13237 +#endif
13238 +;
13239 +
13240 +extern void copy_from_user_overflow(void)
13241 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13242 + __compiletime_error("copy_from_user() buffer size is not provably correct")
13243 +#else
13244 + __compiletime_warning("copy_from_user() buffer size is not provably correct")
13245 +#endif
13246 +;
13247
13248 static inline unsigned long __must_check copy_from_user(void *to,
13249 const void __user *from,
13250 unsigned long n)
13251 {
13252 - int sz = __compiletime_object_size(to);
13253 -
13254 might_fault();
13255 - if (likely(sz == -1 || sz >= n))
13256 - n = _copy_from_user(to, from, n);
13257 -#ifdef CONFIG_DEBUG_VM
13258 - else
13259 - WARN(1, "Buffer overflow detected!\n");
13260 -#endif
13261 +
13262 + if (access_ok(VERIFY_READ, from, n))
13263 + n = __copy_from_user(to, from, n);
13264 + else if (n < INT_MAX) {
13265 + if (!__builtin_constant_p(n))
13266 + check_object_size(to, n, false);
13267 + memset(to, 0, n);
13268 + }
13269 return n;
13270 }
13271
13272 static __always_inline __must_check
13273 -int copy_to_user(void __user *dst, const void *src, unsigned size)
13274 +int copy_to_user(void __user *dst, const void *src, unsigned long size)
13275 {
13276 might_fault();
13277
13278 - return _copy_to_user(dst, src, size);
13279 + if (access_ok(VERIFY_WRITE, dst, size))
13280 + size = __copy_to_user(dst, src, size);
13281 + return size;
13282 }
13283
13284 static __always_inline __must_check
13285 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
13286 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
13287 {
13288 - int ret = 0;
13289 + size_t sz = __compiletime_object_size(dst);
13290 + unsigned ret = 0;
13291
13292 might_fault();
13293 - if (!__builtin_constant_p(size))
13294 - return copy_user_generic(dst, (__force void *)src, size);
13295 +
13296 + if (size > INT_MAX)
13297 + return size;
13298 +
13299 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13300 + if (!__access_ok(VERIFY_READ, src, size))
13301 + return size;
13302 +#endif
13303 +
13304 + if (unlikely(sz != (size_t)-1 && sz < size)) {
13305 + copy_from_user_overflow();
13306 + return size;
13307 + }
13308 +
13309 + if (!__builtin_constant_p(size)) {
13310 + check_object_size(dst, size, false);
13311 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
13312 + }
13313 switch (size) {
13314 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
13315 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
13316 ret, "b", "b", "=q", 1);
13317 return ret;
13318 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
13319 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
13320 ret, "w", "w", "=r", 2);
13321 return ret;
13322 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
13323 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
13324 ret, "l", "k", "=r", 4);
13325 return ret;
13326 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
13327 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13328 ret, "q", "", "=r", 8);
13329 return ret;
13330 case 10:
13331 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13332 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13333 ret, "q", "", "=r", 10);
13334 if (unlikely(ret))
13335 return ret;
13336 __get_user_asm(*(u16 *)(8 + (char *)dst),
13337 - (u16 __user *)(8 + (char __user *)src),
13338 + (const u16 __user *)(8 + (const char __user *)src),
13339 ret, "w", "w", "=r", 2);
13340 return ret;
13341 case 16:
13342 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13343 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13344 ret, "q", "", "=r", 16);
13345 if (unlikely(ret))
13346 return ret;
13347 __get_user_asm(*(u64 *)(8 + (char *)dst),
13348 - (u64 __user *)(8 + (char __user *)src),
13349 + (const u64 __user *)(8 + (const char __user *)src),
13350 ret, "q", "", "=r", 8);
13351 return ret;
13352 default:
13353 - return copy_user_generic(dst, (__force void *)src, size);
13354 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
13355 }
13356 }
13357
13358 static __always_inline __must_check
13359 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
13360 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
13361 {
13362 - int ret = 0;
13363 + size_t sz = __compiletime_object_size(src);
13364 + unsigned ret = 0;
13365
13366 might_fault();
13367 - if (!__builtin_constant_p(size))
13368 - return copy_user_generic((__force void *)dst, src, size);
13369 +
13370 + if (size > INT_MAX)
13371 + return size;
13372 +
13373 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13374 + if (!__access_ok(VERIFY_WRITE, dst, size))
13375 + return size;
13376 +#endif
13377 +
13378 + if (unlikely(sz != (size_t)-1 && sz < size)) {
13379 + copy_to_user_overflow();
13380 + return size;
13381 + }
13382 +
13383 + if (!__builtin_constant_p(size)) {
13384 + check_object_size(src, size, true);
13385 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
13386 + }
13387 switch (size) {
13388 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
13389 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
13390 ret, "b", "b", "iq", 1);
13391 return ret;
13392 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
13393 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
13394 ret, "w", "w", "ir", 2);
13395 return ret;
13396 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
13397 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
13398 ret, "l", "k", "ir", 4);
13399 return ret;
13400 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
13401 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13402 ret, "q", "", "er", 8);
13403 return ret;
13404 case 10:
13405 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13406 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13407 ret, "q", "", "er", 10);
13408 if (unlikely(ret))
13409 return ret;
13410 asm("":::"memory");
13411 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
13412 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
13413 ret, "w", "w", "ir", 2);
13414 return ret;
13415 case 16:
13416 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13417 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13418 ret, "q", "", "er", 16);
13419 if (unlikely(ret))
13420 return ret;
13421 asm("":::"memory");
13422 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
13423 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
13424 ret, "q", "", "er", 8);
13425 return ret;
13426 default:
13427 - return copy_user_generic((__force void *)dst, src, size);
13428 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
13429 }
13430 }
13431
13432 static __always_inline __must_check
13433 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13434 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
13435 {
13436 - int ret = 0;
13437 + unsigned ret = 0;
13438
13439 might_fault();
13440 +
13441 + if (size > INT_MAX)
13442 + return size;
13443 +
13444 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13445 + if (!__access_ok(VERIFY_READ, src, size))
13446 + return size;
13447 + if (!__access_ok(VERIFY_WRITE, dst, size))
13448 + return size;
13449 +#endif
13450 +
13451 if (!__builtin_constant_p(size))
13452 - return copy_user_generic((__force void *)dst,
13453 - (__force void *)src, size);
13454 + return copy_user_generic((__force_kernel void *)____m(dst),
13455 + (__force_kernel const void *)____m(src), size);
13456 switch (size) {
13457 case 1: {
13458 u8 tmp;
13459 - __get_user_asm(tmp, (u8 __user *)src,
13460 + __get_user_asm(tmp, (const u8 __user *)src,
13461 ret, "b", "b", "=q", 1);
13462 if (likely(!ret))
13463 __put_user_asm(tmp, (u8 __user *)dst,
13464 @@ -185,7 +251,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13465 }
13466 case 2: {
13467 u16 tmp;
13468 - __get_user_asm(tmp, (u16 __user *)src,
13469 + __get_user_asm(tmp, (const u16 __user *)src,
13470 ret, "w", "w", "=r", 2);
13471 if (likely(!ret))
13472 __put_user_asm(tmp, (u16 __user *)dst,
13473 @@ -195,7 +261,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13474
13475 case 4: {
13476 u32 tmp;
13477 - __get_user_asm(tmp, (u32 __user *)src,
13478 + __get_user_asm(tmp, (const u32 __user *)src,
13479 ret, "l", "k", "=r", 4);
13480 if (likely(!ret))
13481 __put_user_asm(tmp, (u32 __user *)dst,
13482 @@ -204,7 +270,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13483 }
13484 case 8: {
13485 u64 tmp;
13486 - __get_user_asm(tmp, (u64 __user *)src,
13487 + __get_user_asm(tmp, (const u64 __user *)src,
13488 ret, "q", "", "=r", 8);
13489 if (likely(!ret))
13490 __put_user_asm(tmp, (u64 __user *)dst,
13491 @@ -212,44 +278,65 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13492 return ret;
13493 }
13494 default:
13495 - return copy_user_generic((__force void *)dst,
13496 - (__force void *)src, size);
13497 + return copy_user_generic((__force_kernel void *)____m(dst),
13498 + (__force_kernel const void *)____m(src), size);
13499 }
13500 }
13501
13502 -__must_check unsigned long clear_user(void __user *mem, unsigned long len);
13503 -__must_check unsigned long __clear_user(void __user *mem, unsigned long len);
13504 +__must_check unsigned long clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13505 +__must_check unsigned long __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13506
13507 static __must_check __always_inline int
13508 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
13509 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
13510 {
13511 - return copy_user_generic(dst, (__force const void *)src, size);
13512 + if (size > INT_MAX)
13513 + return size;
13514 +
13515 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
13516 }
13517
13518 -static __must_check __always_inline int
13519 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
13520 +static __must_check __always_inline unsigned long
13521 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
13522 {
13523 - return copy_user_generic((__force void *)dst, src, size);
13524 + if (size > INT_MAX)
13525 + return size;
13526 +
13527 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
13528 }
13529
13530 -extern long __copy_user_nocache(void *dst, const void __user *src,
13531 - unsigned size, int zerorest);
13532 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
13533 + unsigned long size, int zerorest) __size_overflow(3);
13534
13535 -static inline int
13536 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
13537 +static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
13538 {
13539 might_sleep();
13540 +
13541 + if (size > INT_MAX)
13542 + return size;
13543 +
13544 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13545 + if (!__access_ok(VERIFY_READ, src, size))
13546 + return size;
13547 +#endif
13548 +
13549 return __copy_user_nocache(dst, src, size, 1);
13550 }
13551
13552 -static inline int
13553 -__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13554 - unsigned size)
13555 +static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13556 + unsigned long size)
13557 {
13558 + if (size > INT_MAX)
13559 + return size;
13560 +
13561 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13562 + if (!__access_ok(VERIFY_READ, src, size))
13563 + return size;
13564 +#endif
13565 +
13566 return __copy_user_nocache(dst, src, size, 0);
13567 }
13568
13569 -unsigned long
13570 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
13571 +extern unsigned long
13572 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
13573
13574 #endif /* _ASM_X86_UACCESS_64_H */
13575 diff --git a/arch/x86/include/asm/vdso.h b/arch/x86/include/asm/vdso.h
13576 index bb05228..d763d5b 100644
13577 --- a/arch/x86/include/asm/vdso.h
13578 +++ b/arch/x86/include/asm/vdso.h
13579 @@ -11,7 +11,7 @@ extern const char VDSO32_PRELINK[];
13580 #define VDSO32_SYMBOL(base, name) \
13581 ({ \
13582 extern const char VDSO32_##name[]; \
13583 - (void *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13584 + (void __user *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13585 })
13586 #endif
13587
13588 diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
13589 index 5b238981..77fdd78 100644
13590 --- a/arch/x86/include/asm/word-at-a-time.h
13591 +++ b/arch/x86/include/asm/word-at-a-time.h
13592 @@ -11,7 +11,7 @@
13593 * and shift, for example.
13594 */
13595 struct word_at_a_time {
13596 - const unsigned long one_bits, high_bits;
13597 + unsigned long one_bits, high_bits;
13598 };
13599
13600 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
13601 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
13602 index 38155f6..e4184ba 100644
13603 --- a/arch/x86/include/asm/x86_init.h
13604 +++ b/arch/x86/include/asm/x86_init.h
13605 @@ -29,7 +29,7 @@ struct x86_init_mpparse {
13606 void (*mpc_oem_bus_info)(struct mpc_bus *m, char *name);
13607 void (*find_smp_config)(void);
13608 void (*get_smp_config)(unsigned int early);
13609 -};
13610 +} __no_const;
13611
13612 /**
13613 * struct x86_init_resources - platform specific resource related ops
13614 @@ -43,7 +43,7 @@ struct x86_init_resources {
13615 void (*probe_roms)(void);
13616 void (*reserve_resources)(void);
13617 char *(*memory_setup)(void);
13618 -};
13619 +} __no_const;
13620
13621 /**
13622 * struct x86_init_irqs - platform specific interrupt setup
13623 @@ -56,7 +56,7 @@ struct x86_init_irqs {
13624 void (*pre_vector_init)(void);
13625 void (*intr_init)(void);
13626 void (*trap_init)(void);
13627 -};
13628 +} __no_const;
13629
13630 /**
13631 * struct x86_init_oem - oem platform specific customizing functions
13632 @@ -66,7 +66,7 @@ struct x86_init_irqs {
13633 struct x86_init_oem {
13634 void (*arch_setup)(void);
13635 void (*banner)(void);
13636 -};
13637 +} __no_const;
13638
13639 /**
13640 * struct x86_init_mapping - platform specific initial kernel pagetable setup
13641 @@ -77,7 +77,7 @@ struct x86_init_oem {
13642 */
13643 struct x86_init_mapping {
13644 void (*pagetable_reserve)(u64 start, u64 end);
13645 -};
13646 +} __no_const;
13647
13648 /**
13649 * struct x86_init_paging - platform specific paging functions
13650 @@ -87,7 +87,7 @@ struct x86_init_mapping {
13651 struct x86_init_paging {
13652 void (*pagetable_setup_start)(pgd_t *base);
13653 void (*pagetable_setup_done)(pgd_t *base);
13654 -};
13655 +} __no_const;
13656
13657 /**
13658 * struct x86_init_timers - platform specific timer setup
13659 @@ -102,7 +102,7 @@ struct x86_init_timers {
13660 void (*tsc_pre_init)(void);
13661 void (*timer_init)(void);
13662 void (*wallclock_init)(void);
13663 -};
13664 +} __no_const;
13665
13666 /**
13667 * struct x86_init_iommu - platform specific iommu setup
13668 @@ -110,7 +110,7 @@ struct x86_init_timers {
13669 */
13670 struct x86_init_iommu {
13671 int (*iommu_init)(void);
13672 -};
13673 +} __no_const;
13674
13675 /**
13676 * struct x86_init_pci - platform specific pci init functions
13677 @@ -124,7 +124,7 @@ struct x86_init_pci {
13678 int (*init)(void);
13679 void (*init_irq)(void);
13680 void (*fixup_irqs)(void);
13681 -};
13682 +} __no_const;
13683
13684 /**
13685 * struct x86_init_ops - functions for platform specific setup
13686 @@ -140,7 +140,7 @@ struct x86_init_ops {
13687 struct x86_init_timers timers;
13688 struct x86_init_iommu iommu;
13689 struct x86_init_pci pci;
13690 -};
13691 +} __no_const;
13692
13693 /**
13694 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
13695 @@ -151,7 +151,7 @@ struct x86_cpuinit_ops {
13696 void (*setup_percpu_clockev)(void);
13697 void (*early_percpu_clock_init)(void);
13698 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
13699 -};
13700 +} __no_const;
13701
13702 /**
13703 * struct x86_platform_ops - platform specific runtime functions
13704 @@ -177,7 +177,7 @@ struct x86_platform_ops {
13705 void (*save_sched_clock_state)(void);
13706 void (*restore_sched_clock_state)(void);
13707 void (*apic_post_init)(void);
13708 -};
13709 +} __no_const;
13710
13711 struct pci_dev;
13712
13713 @@ -186,14 +186,14 @@ struct x86_msi_ops {
13714 void (*teardown_msi_irq)(unsigned int irq);
13715 void (*teardown_msi_irqs)(struct pci_dev *dev);
13716 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
13717 -};
13718 +} __no_const;
13719
13720 struct x86_io_apic_ops {
13721 void (*init) (void);
13722 unsigned int (*read) (unsigned int apic, unsigned int reg);
13723 void (*write) (unsigned int apic, unsigned int reg, unsigned int value);
13724 void (*modify)(unsigned int apic, unsigned int reg, unsigned int value);
13725 -};
13726 +} __no_const;
13727
13728 extern struct x86_init_ops x86_init;
13729 extern struct x86_cpuinit_ops x86_cpuinit;
13730 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
13731 index 8a1b6f9..d47ba6d 100644
13732 --- a/arch/x86/include/asm/xsave.h
13733 +++ b/arch/x86/include/asm/xsave.h
13734 @@ -65,6 +65,8 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13735 {
13736 int err;
13737
13738 + buf = (struct xsave_struct __user *)____m(buf);
13739 +
13740 /*
13741 * Clear the xsave header first, so that reserved fields are
13742 * initialized to zero.
13743 @@ -74,7 +76,9 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13744 if (unlikely(err))
13745 return -EFAULT;
13746
13747 - __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
13748 + __asm__ __volatile__("1:"
13749 + __copyuser_seg
13750 + ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
13751 "2:\n"
13752 ".section .fixup,\"ax\"\n"
13753 "3: movl $-1,%[err]\n"
13754 @@ -93,11 +97,13 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13755 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
13756 {
13757 int err;
13758 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
13759 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)____m(buf));
13760 u32 lmask = mask;
13761 u32 hmask = mask >> 32;
13762
13763 - __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
13764 + __asm__ __volatile__("1:"
13765 + __copyuser_seg
13766 + ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
13767 "2:\n"
13768 ".section .fixup,\"ax\"\n"
13769 "3: movl $-1,%[err]\n"
13770 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
13771 index 1b8e5a0..354fd59 100644
13772 --- a/arch/x86/kernel/acpi/sleep.c
13773 +++ b/arch/x86/kernel/acpi/sleep.c
13774 @@ -69,8 +69,12 @@ int acpi_suspend_lowlevel(void)
13775 #else /* CONFIG_64BIT */
13776 #ifdef CONFIG_SMP
13777 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
13778 +
13779 + pax_open_kernel();
13780 early_gdt_descr.address =
13781 (unsigned long)get_cpu_gdt_table(smp_processor_id());
13782 + pax_close_kernel();
13783 +
13784 initial_gs = per_cpu_offset(smp_processor_id());
13785 #endif
13786 initial_code = (unsigned long)wakeup_long64;
13787 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
13788 index 13ab720..95d5442 100644
13789 --- a/arch/x86/kernel/acpi/wakeup_32.S
13790 +++ b/arch/x86/kernel/acpi/wakeup_32.S
13791 @@ -30,13 +30,11 @@ wakeup_pmode_return:
13792 # and restore the stack ... but you need gdt for this to work
13793 movl saved_context_esp, %esp
13794
13795 - movl %cs:saved_magic, %eax
13796 - cmpl $0x12345678, %eax
13797 + cmpl $0x12345678, saved_magic
13798 jne bogus_magic
13799
13800 # jump to place where we left off
13801 - movl saved_eip, %eax
13802 - jmp *%eax
13803 + jmp *(saved_eip)
13804
13805 bogus_magic:
13806 jmp bogus_magic
13807 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
13808 index ced4534..3e75d69 100644
13809 --- a/arch/x86/kernel/alternative.c
13810 +++ b/arch/x86/kernel/alternative.c
13811 @@ -281,6 +281,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
13812 */
13813 for (a = start; a < end; a++) {
13814 instr = (u8 *)&a->instr_offset + a->instr_offset;
13815 +
13816 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13817 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13818 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
13819 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13820 +#endif
13821 +
13822 replacement = (u8 *)&a->repl_offset + a->repl_offset;
13823 BUG_ON(a->replacementlen > a->instrlen);
13824 BUG_ON(a->instrlen > sizeof(insnbuf));
13825 @@ -312,10 +319,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
13826 for (poff = start; poff < end; poff++) {
13827 u8 *ptr = (u8 *)poff + *poff;
13828
13829 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13830 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13831 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13832 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13833 +#endif
13834 +
13835 if (!*poff || ptr < text || ptr >= text_end)
13836 continue;
13837 /* turn DS segment override prefix into lock prefix */
13838 - if (*ptr == 0x3e)
13839 + if (*ktla_ktva(ptr) == 0x3e)
13840 text_poke(ptr, ((unsigned char []){0xf0}), 1);
13841 };
13842 mutex_unlock(&text_mutex);
13843 @@ -333,10 +346,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
13844 for (poff = start; poff < end; poff++) {
13845 u8 *ptr = (u8 *)poff + *poff;
13846
13847 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13848 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13849 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13850 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13851 +#endif
13852 +
13853 if (!*poff || ptr < text || ptr >= text_end)
13854 continue;
13855 /* turn lock prefix into DS segment override prefix */
13856 - if (*ptr == 0xf0)
13857 + if (*ktla_ktva(ptr) == 0xf0)
13858 text_poke(ptr, ((unsigned char []){0x3E}), 1);
13859 };
13860 mutex_unlock(&text_mutex);
13861 @@ -505,7 +524,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
13862
13863 BUG_ON(p->len > MAX_PATCH_LEN);
13864 /* prep the buffer with the original instructions */
13865 - memcpy(insnbuf, p->instr, p->len);
13866 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
13867 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
13868 (unsigned long)p->instr, p->len);
13869
13870 @@ -573,7 +592,7 @@ void __init alternative_instructions(void)
13871 if (smp_alt_once)
13872 free_init_pages("SMP alternatives",
13873 (unsigned long)__smp_locks,
13874 - (unsigned long)__smp_locks_end);
13875 + PAGE_ALIGN((unsigned long)__smp_locks_end));
13876
13877 restart_nmi();
13878 }
13879 @@ -590,13 +609,17 @@ void __init alternative_instructions(void)
13880 * instructions. And on the local CPU you need to be protected again NMI or MCE
13881 * handlers seeing an inconsistent instruction while you patch.
13882 */
13883 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
13884 +void *__kprobes text_poke_early(void *addr, const void *opcode,
13885 size_t len)
13886 {
13887 unsigned long flags;
13888 local_irq_save(flags);
13889 - memcpy(addr, opcode, len);
13890 +
13891 + pax_open_kernel();
13892 + memcpy(ktla_ktva(addr), opcode, len);
13893 sync_core();
13894 + pax_close_kernel();
13895 +
13896 local_irq_restore(flags);
13897 /* Could also do a CLFLUSH here to speed up CPU recovery; but
13898 that causes hangs on some VIA CPUs. */
13899 @@ -618,36 +641,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
13900 */
13901 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
13902 {
13903 - unsigned long flags;
13904 - char *vaddr;
13905 + unsigned char *vaddr = ktla_ktva(addr);
13906 struct page *pages[2];
13907 - int i;
13908 + size_t i;
13909
13910 if (!core_kernel_text((unsigned long)addr)) {
13911 - pages[0] = vmalloc_to_page(addr);
13912 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
13913 + pages[0] = vmalloc_to_page(vaddr);
13914 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
13915 } else {
13916 - pages[0] = virt_to_page(addr);
13917 + pages[0] = virt_to_page(vaddr);
13918 WARN_ON(!PageReserved(pages[0]));
13919 - pages[1] = virt_to_page(addr + PAGE_SIZE);
13920 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
13921 }
13922 BUG_ON(!pages[0]);
13923 - local_irq_save(flags);
13924 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
13925 - if (pages[1])
13926 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
13927 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
13928 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
13929 - clear_fixmap(FIX_TEXT_POKE0);
13930 - if (pages[1])
13931 - clear_fixmap(FIX_TEXT_POKE1);
13932 - local_flush_tlb();
13933 - sync_core();
13934 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
13935 - that causes hangs on some VIA CPUs. */
13936 + text_poke_early(addr, opcode, len);
13937 for (i = 0; i < len; i++)
13938 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
13939 - local_irq_restore(flags);
13940 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
13941 return addr;
13942 }
13943
13944 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
13945 index 24deb30..94a3426 100644
13946 --- a/arch/x86/kernel/apic/apic.c
13947 +++ b/arch/x86/kernel/apic/apic.c
13948 @@ -185,7 +185,7 @@ int first_system_vector = 0xfe;
13949 /*
13950 * Debug level, exported for io_apic.c
13951 */
13952 -unsigned int apic_verbosity;
13953 +int apic_verbosity;
13954
13955 int pic_mode;
13956
13957 @@ -1923,7 +1923,7 @@ void smp_error_interrupt(struct pt_regs *regs)
13958 apic_write(APIC_ESR, 0);
13959 v1 = apic_read(APIC_ESR);
13960 ack_APIC_irq();
13961 - atomic_inc(&irq_err_count);
13962 + atomic_inc_unchecked(&irq_err_count);
13963
13964 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
13965 smp_processor_id(), v0 , v1);
13966 @@ -2155,7 +2155,9 @@ void __init apic_set_eoi_write(void (*eoi_write)(u32 reg, u32 v))
13967 for (drv = __apicdrivers; drv < __apicdrivers_end; drv++) {
13968 /* Should happen once for each apic */
13969 WARN_ON((*drv)->eoi_write == eoi_write);
13970 - (*drv)->eoi_write = eoi_write;
13971 + pax_open_kernel();
13972 + *(void **)&(*drv)->eoi_write = eoi_write;
13973 + pax_close_kernel();
13974 }
13975 }
13976
13977 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
13978 index c265593..137c4ac 100644
13979 --- a/arch/x86/kernel/apic/io_apic.c
13980 +++ b/arch/x86/kernel/apic/io_apic.c
13981 @@ -1084,7 +1084,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
13982 }
13983 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
13984
13985 -void lock_vector_lock(void)
13986 +void lock_vector_lock(void) __acquires(vector_lock)
13987 {
13988 /* Used to the online set of cpus does not change
13989 * during assign_irq_vector.
13990 @@ -1092,7 +1092,7 @@ void lock_vector_lock(void)
13991 raw_spin_lock(&vector_lock);
13992 }
13993
13994 -void unlock_vector_lock(void)
13995 +void unlock_vector_lock(void) __releases(vector_lock)
13996 {
13997 raw_spin_unlock(&vector_lock);
13998 }
13999 @@ -2408,7 +2408,7 @@ static void ack_apic_edge(struct irq_data *data)
14000 ack_APIC_irq();
14001 }
14002
14003 -atomic_t irq_mis_count;
14004 +atomic_unchecked_t irq_mis_count;
14005
14006 #ifdef CONFIG_GENERIC_PENDING_IRQ
14007 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
14008 @@ -2549,7 +2549,7 @@ static void ack_apic_level(struct irq_data *data)
14009 * at the cpu.
14010 */
14011 if (!(v & (1 << (i & 0x1f)))) {
14012 - atomic_inc(&irq_mis_count);
14013 + atomic_inc_unchecked(&irq_mis_count);
14014
14015 eoi_ioapic_irq(irq, cfg);
14016 }
14017 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
14018 index d65464e..1035d31 100644
14019 --- a/arch/x86/kernel/apm_32.c
14020 +++ b/arch/x86/kernel/apm_32.c
14021 @@ -412,7 +412,7 @@ static DEFINE_MUTEX(apm_mutex);
14022 * This is for buggy BIOS's that refer to (real mode) segment 0x40
14023 * even though they are called in protected mode.
14024 */
14025 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
14026 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
14027 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
14028
14029 static const char driver_version[] = "1.16ac"; /* no spaces */
14030 @@ -590,7 +590,10 @@ static long __apm_bios_call(void *_call)
14031 BUG_ON(cpu != 0);
14032 gdt = get_cpu_gdt_table(cpu);
14033 save_desc_40 = gdt[0x40 / 8];
14034 +
14035 + pax_open_kernel();
14036 gdt[0x40 / 8] = bad_bios_desc;
14037 + pax_close_kernel();
14038
14039 apm_irq_save(flags);
14040 APM_DO_SAVE_SEGS;
14041 @@ -599,7 +602,11 @@ static long __apm_bios_call(void *_call)
14042 &call->esi);
14043 APM_DO_RESTORE_SEGS;
14044 apm_irq_restore(flags);
14045 +
14046 + pax_open_kernel();
14047 gdt[0x40 / 8] = save_desc_40;
14048 + pax_close_kernel();
14049 +
14050 put_cpu();
14051
14052 return call->eax & 0xff;
14053 @@ -666,7 +673,10 @@ static long __apm_bios_call_simple(void *_call)
14054 BUG_ON(cpu != 0);
14055 gdt = get_cpu_gdt_table(cpu);
14056 save_desc_40 = gdt[0x40 / 8];
14057 +
14058 + pax_open_kernel();
14059 gdt[0x40 / 8] = bad_bios_desc;
14060 + pax_close_kernel();
14061
14062 apm_irq_save(flags);
14063 APM_DO_SAVE_SEGS;
14064 @@ -674,7 +684,11 @@ static long __apm_bios_call_simple(void *_call)
14065 &call->eax);
14066 APM_DO_RESTORE_SEGS;
14067 apm_irq_restore(flags);
14068 +
14069 + pax_open_kernel();
14070 gdt[0x40 / 8] = save_desc_40;
14071 + pax_close_kernel();
14072 +
14073 put_cpu();
14074 return error;
14075 }
14076 @@ -2345,12 +2359,15 @@ static int __init apm_init(void)
14077 * code to that CPU.
14078 */
14079 gdt = get_cpu_gdt_table(0);
14080 +
14081 + pax_open_kernel();
14082 set_desc_base(&gdt[APM_CS >> 3],
14083 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
14084 set_desc_base(&gdt[APM_CS_16 >> 3],
14085 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
14086 set_desc_base(&gdt[APM_DS >> 3],
14087 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
14088 + pax_close_kernel();
14089
14090 proc_create("apm", 0, NULL, &apm_file_ops);
14091
14092 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
14093 index 68de2dc..1f3c720 100644
14094 --- a/arch/x86/kernel/asm-offsets.c
14095 +++ b/arch/x86/kernel/asm-offsets.c
14096 @@ -33,6 +33,8 @@ void common(void) {
14097 OFFSET(TI_status, thread_info, status);
14098 OFFSET(TI_addr_limit, thread_info, addr_limit);
14099 OFFSET(TI_preempt_count, thread_info, preempt_count);
14100 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
14101 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
14102
14103 BLANK();
14104 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
14105 @@ -53,8 +55,26 @@ void common(void) {
14106 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
14107 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
14108 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
14109 +
14110 +#ifdef CONFIG_PAX_KERNEXEC
14111 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
14112 #endif
14113
14114 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14115 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
14116 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
14117 +#ifdef CONFIG_X86_64
14118 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
14119 +#endif
14120 +#endif
14121 +
14122 +#endif
14123 +
14124 + BLANK();
14125 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
14126 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
14127 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
14128 +
14129 #ifdef CONFIG_XEN
14130 BLANK();
14131 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
14132 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
14133 index 1b4754f..fbb4227 100644
14134 --- a/arch/x86/kernel/asm-offsets_64.c
14135 +++ b/arch/x86/kernel/asm-offsets_64.c
14136 @@ -76,6 +76,7 @@ int main(void)
14137 BLANK();
14138 #undef ENTRY
14139
14140 + DEFINE(TSS_size, sizeof(struct tss_struct));
14141 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
14142 BLANK();
14143
14144 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
14145 index d30a6a9..79becab 100644
14146 --- a/arch/x86/kernel/cpu/Makefile
14147 +++ b/arch/x86/kernel/cpu/Makefile
14148 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
14149 CFLAGS_REMOVE_perf_event.o = -pg
14150 endif
14151
14152 -# Make sure load_percpu_segment has no stackprotector
14153 -nostackp := $(call cc-option, -fno-stack-protector)
14154 -CFLAGS_common.o := $(nostackp)
14155 -
14156 obj-y := intel_cacheinfo.o scattered.o topology.o
14157 obj-y += proc.o capflags.o powerflags.o common.o
14158 obj-y += vmware.o hypervisor.o mshyperv.o
14159 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
14160 index 9d92e19..49d7d79 100644
14161 --- a/arch/x86/kernel/cpu/amd.c
14162 +++ b/arch/x86/kernel/cpu/amd.c
14163 @@ -724,7 +724,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
14164 unsigned int size)
14165 {
14166 /* AMD errata T13 (order #21922) */
14167 - if ((c->x86 == 6)) {
14168 + if (c->x86 == 6) {
14169 /* Duron Rev A0 */
14170 if (c->x86_model == 3 && c->x86_mask == 0)
14171 size = 64;
14172 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
14173 index a5fbc3c..2254849 100644
14174 --- a/arch/x86/kernel/cpu/common.c
14175 +++ b/arch/x86/kernel/cpu/common.c
14176 @@ -86,60 +86,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
14177
14178 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
14179
14180 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
14181 -#ifdef CONFIG_X86_64
14182 - /*
14183 - * We need valid kernel segments for data and code in long mode too
14184 - * IRET will check the segment types kkeil 2000/10/28
14185 - * Also sysret mandates a special GDT layout
14186 - *
14187 - * TLS descriptors are currently at a different place compared to i386.
14188 - * Hopefully nobody expects them at a fixed place (Wine?)
14189 - */
14190 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
14191 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
14192 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
14193 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
14194 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
14195 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
14196 -#else
14197 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
14198 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14199 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
14200 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
14201 - /*
14202 - * Segments used for calling PnP BIOS have byte granularity.
14203 - * They code segments and data segments have fixed 64k limits,
14204 - * the transfer segment sizes are set at run time.
14205 - */
14206 - /* 32-bit code */
14207 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14208 - /* 16-bit code */
14209 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14210 - /* 16-bit data */
14211 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
14212 - /* 16-bit data */
14213 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
14214 - /* 16-bit data */
14215 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
14216 - /*
14217 - * The APM segments have byte granularity and their bases
14218 - * are set at run time. All have 64k limits.
14219 - */
14220 - /* 32-bit code */
14221 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14222 - /* 16-bit code */
14223 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14224 - /* data */
14225 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
14226 -
14227 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14228 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14229 - GDT_STACK_CANARY_INIT
14230 -#endif
14231 -} };
14232 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
14233 -
14234 static int __init x86_xsave_setup(char *s)
14235 {
14236 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
14237 @@ -376,7 +322,7 @@ void switch_to_new_gdt(int cpu)
14238 {
14239 struct desc_ptr gdt_descr;
14240
14241 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
14242 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
14243 gdt_descr.size = GDT_SIZE - 1;
14244 load_gdt(&gdt_descr);
14245 /* Reload the per-cpu base */
14246 @@ -872,6 +818,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
14247 /* Filter out anything that depends on CPUID levels we don't have */
14248 filter_cpuid_features(c, true);
14249
14250 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
14251 + setup_clear_cpu_cap(X86_FEATURE_SEP);
14252 +#endif
14253 +
14254 /* If the model name is still unset, do table lookup. */
14255 if (!c->x86_model_id[0]) {
14256 const char *p;
14257 @@ -1054,10 +1004,12 @@ static __init int setup_disablecpuid(char *arg)
14258 }
14259 __setup("clearcpuid=", setup_disablecpuid);
14260
14261 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
14262 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
14263 +
14264 #ifdef CONFIG_X86_64
14265 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
14266 -struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
14267 - (unsigned long) nmi_idt_table };
14268 +struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
14269
14270 DEFINE_PER_CPU_FIRST(union irq_stack_union,
14271 irq_stack_union) __aligned(PAGE_SIZE);
14272 @@ -1071,7 +1023,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
14273 EXPORT_PER_CPU_SYMBOL(current_task);
14274
14275 DEFINE_PER_CPU(unsigned long, kernel_stack) =
14276 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
14277 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
14278 EXPORT_PER_CPU_SYMBOL(kernel_stack);
14279
14280 DEFINE_PER_CPU(char *, irq_stack_ptr) =
14281 @@ -1165,7 +1117,7 @@ struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
14282 {
14283 memset(regs, 0, sizeof(struct pt_regs));
14284 regs->fs = __KERNEL_PERCPU;
14285 - regs->gs = __KERNEL_STACK_CANARY;
14286 + savesegment(gs, regs->gs);
14287
14288 return regs;
14289 }
14290 @@ -1220,7 +1172,7 @@ void __cpuinit cpu_init(void)
14291 int i;
14292
14293 cpu = stack_smp_processor_id();
14294 - t = &per_cpu(init_tss, cpu);
14295 + t = init_tss + cpu;
14296 oist = &per_cpu(orig_ist, cpu);
14297
14298 #ifdef CONFIG_NUMA
14299 @@ -1246,7 +1198,7 @@ void __cpuinit cpu_init(void)
14300 switch_to_new_gdt(cpu);
14301 loadsegment(fs, 0);
14302
14303 - load_idt((const struct desc_ptr *)&idt_descr);
14304 + load_idt(&idt_descr);
14305
14306 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
14307 syscall_init();
14308 @@ -1255,7 +1207,6 @@ void __cpuinit cpu_init(void)
14309 wrmsrl(MSR_KERNEL_GS_BASE, 0);
14310 barrier();
14311
14312 - x86_configure_nx();
14313 if (cpu != 0)
14314 enable_x2apic();
14315
14316 @@ -1311,7 +1262,7 @@ void __cpuinit cpu_init(void)
14317 {
14318 int cpu = smp_processor_id();
14319 struct task_struct *curr = current;
14320 - struct tss_struct *t = &per_cpu(init_tss, cpu);
14321 + struct tss_struct *t = init_tss + cpu;
14322 struct thread_struct *thread = &curr->thread;
14323
14324 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
14325 diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
14326 index 0a4ce29..f211176 100644
14327 --- a/arch/x86/kernel/cpu/intel.c
14328 +++ b/arch/x86/kernel/cpu/intel.c
14329 @@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
14330 * Update the IDT descriptor and reload the IDT so that
14331 * it uses the read-only mapped virtual address.
14332 */
14333 - idt_descr.address = fix_to_virt(FIX_F00F_IDT);
14334 + idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
14335 load_idt(&idt_descr);
14336 }
14337 #endif
14338 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
14339 index 292d025..b520c94 100644
14340 --- a/arch/x86/kernel/cpu/mcheck/mce.c
14341 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
14342 @@ -45,6 +45,7 @@
14343 #include <asm/processor.h>
14344 #include <asm/mce.h>
14345 #include <asm/msr.h>
14346 +#include <asm/local.h>
14347
14348 #include "mce-internal.h"
14349
14350 @@ -253,7 +254,7 @@ static void print_mce(struct mce *m)
14351 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
14352 m->cs, m->ip);
14353
14354 - if (m->cs == __KERNEL_CS)
14355 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
14356 print_symbol("{%s}", m->ip);
14357 pr_cont("\n");
14358 }
14359 @@ -286,10 +287,10 @@ static void print_mce(struct mce *m)
14360
14361 #define PANIC_TIMEOUT 5 /* 5 seconds */
14362
14363 -static atomic_t mce_paniced;
14364 +static atomic_unchecked_t mce_paniced;
14365
14366 static int fake_panic;
14367 -static atomic_t mce_fake_paniced;
14368 +static atomic_unchecked_t mce_fake_paniced;
14369
14370 /* Panic in progress. Enable interrupts and wait for final IPI */
14371 static void wait_for_panic(void)
14372 @@ -313,7 +314,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14373 /*
14374 * Make sure only one CPU runs in machine check panic
14375 */
14376 - if (atomic_inc_return(&mce_paniced) > 1)
14377 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
14378 wait_for_panic();
14379 barrier();
14380
14381 @@ -321,7 +322,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14382 console_verbose();
14383 } else {
14384 /* Don't log too much for fake panic */
14385 - if (atomic_inc_return(&mce_fake_paniced) > 1)
14386 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
14387 return;
14388 }
14389 /* First print corrected ones that are still unlogged */
14390 @@ -693,7 +694,7 @@ static int mce_timed_out(u64 *t)
14391 * might have been modified by someone else.
14392 */
14393 rmb();
14394 - if (atomic_read(&mce_paniced))
14395 + if (atomic_read_unchecked(&mce_paniced))
14396 wait_for_panic();
14397 if (!monarch_timeout)
14398 goto out;
14399 @@ -1619,7 +1620,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
14400 }
14401
14402 /* Call the installed machine check handler for this CPU setup. */
14403 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
14404 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
14405 unexpected_machine_check;
14406
14407 /*
14408 @@ -1642,7 +1643,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14409 return;
14410 }
14411
14412 + pax_open_kernel();
14413 machine_check_vector = do_machine_check;
14414 + pax_close_kernel();
14415
14416 __mcheck_cpu_init_generic();
14417 __mcheck_cpu_init_vendor(c);
14418 @@ -1656,7 +1659,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14419 */
14420
14421 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
14422 -static int mce_chrdev_open_count; /* #times opened */
14423 +static local_t mce_chrdev_open_count; /* #times opened */
14424 static int mce_chrdev_open_exclu; /* already open exclusive? */
14425
14426 static int mce_chrdev_open(struct inode *inode, struct file *file)
14427 @@ -1664,7 +1667,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14428 spin_lock(&mce_chrdev_state_lock);
14429
14430 if (mce_chrdev_open_exclu ||
14431 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
14432 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
14433 spin_unlock(&mce_chrdev_state_lock);
14434
14435 return -EBUSY;
14436 @@ -1672,7 +1675,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14437
14438 if (file->f_flags & O_EXCL)
14439 mce_chrdev_open_exclu = 1;
14440 - mce_chrdev_open_count++;
14441 + local_inc(&mce_chrdev_open_count);
14442
14443 spin_unlock(&mce_chrdev_state_lock);
14444
14445 @@ -1683,7 +1686,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
14446 {
14447 spin_lock(&mce_chrdev_state_lock);
14448
14449 - mce_chrdev_open_count--;
14450 + local_dec(&mce_chrdev_open_count);
14451 mce_chrdev_open_exclu = 0;
14452
14453 spin_unlock(&mce_chrdev_state_lock);
14454 @@ -2407,7 +2410,7 @@ struct dentry *mce_get_debugfs_dir(void)
14455 static void mce_reset(void)
14456 {
14457 cpu_missing = 0;
14458 - atomic_set(&mce_fake_paniced, 0);
14459 + atomic_set_unchecked(&mce_fake_paniced, 0);
14460 atomic_set(&mce_executing, 0);
14461 atomic_set(&mce_callin, 0);
14462 atomic_set(&global_nwo, 0);
14463 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
14464 index 2d5454c..51987eb 100644
14465 --- a/arch/x86/kernel/cpu/mcheck/p5.c
14466 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
14467 @@ -11,6 +11,7 @@
14468 #include <asm/processor.h>
14469 #include <asm/mce.h>
14470 #include <asm/msr.h>
14471 +#include <asm/pgtable.h>
14472
14473 /* By default disabled */
14474 int mce_p5_enabled __read_mostly;
14475 @@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
14476 if (!cpu_has(c, X86_FEATURE_MCE))
14477 return;
14478
14479 + pax_open_kernel();
14480 machine_check_vector = pentium_machine_check;
14481 + pax_close_kernel();
14482 /* Make sure the vector pointer is visible before we enable MCEs: */
14483 wmb();
14484
14485 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
14486 index 2d7998f..17c9de1 100644
14487 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
14488 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
14489 @@ -10,6 +10,7 @@
14490 #include <asm/processor.h>
14491 #include <asm/mce.h>
14492 #include <asm/msr.h>
14493 +#include <asm/pgtable.h>
14494
14495 /* Machine check handler for WinChip C6: */
14496 static void winchip_machine_check(struct pt_regs *regs, long error_code)
14497 @@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
14498 {
14499 u32 lo, hi;
14500
14501 + pax_open_kernel();
14502 machine_check_vector = winchip_machine_check;
14503 + pax_close_kernel();
14504 /* Make sure the vector pointer is visible before we enable MCEs: */
14505 wmb();
14506
14507 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
14508 index 6b96110..0da73eb 100644
14509 --- a/arch/x86/kernel/cpu/mtrr/main.c
14510 +++ b/arch/x86/kernel/cpu/mtrr/main.c
14511 @@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
14512 u64 size_or_mask, size_and_mask;
14513 static bool mtrr_aps_delayed_init;
14514
14515 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
14516 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
14517
14518 const struct mtrr_ops *mtrr_if;
14519
14520 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
14521 index df5e41f..816c719 100644
14522 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
14523 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
14524 @@ -25,7 +25,7 @@ struct mtrr_ops {
14525 int (*validate_add_page)(unsigned long base, unsigned long size,
14526 unsigned int type);
14527 int (*have_wrcomb)(void);
14528 -};
14529 +} __do_const;
14530
14531 extern int generic_get_free_region(unsigned long base, unsigned long size,
14532 int replace_reg);
14533 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
14534 index 915b876..171f845 100644
14535 --- a/arch/x86/kernel/cpu/perf_event.c
14536 +++ b/arch/x86/kernel/cpu/perf_event.c
14537 @@ -1757,7 +1757,7 @@ static unsigned long get_segment_base(unsigned int segment)
14538 if (idx > GDT_ENTRIES)
14539 return 0;
14540
14541 - desc = __this_cpu_ptr(&gdt_page.gdt[0]);
14542 + desc = get_cpu_gdt_table(smp_processor_id());
14543 }
14544
14545 return get_desc_base(desc + idx);
14546 @@ -1847,7 +1847,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
14547 break;
14548
14549 perf_callchain_store(entry, frame.return_address);
14550 - fp = frame.next_frame;
14551 + fp = (const void __force_user *)frame.next_frame;
14552 }
14553 }
14554
14555 diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
14556 index 6bca492..36e4496 100644
14557 --- a/arch/x86/kernel/cpu/perf_event_intel.c
14558 +++ b/arch/x86/kernel/cpu/perf_event_intel.c
14559 @@ -1947,10 +1947,10 @@ __init int intel_pmu_init(void)
14560 * v2 and above have a perf capabilities MSR
14561 */
14562 if (version > 1) {
14563 - u64 capabilities;
14564 + u64 capabilities = x86_pmu.intel_cap.capabilities;
14565
14566 - rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
14567 - x86_pmu.intel_cap.capabilities = capabilities;
14568 + if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
14569 + x86_pmu.intel_cap.capabilities = capabilities;
14570 }
14571
14572 intel_ds_init();
14573 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
14574 index 13ad899..f642b9a 100644
14575 --- a/arch/x86/kernel/crash.c
14576 +++ b/arch/x86/kernel/crash.c
14577 @@ -36,10 +36,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
14578 {
14579 #ifdef CONFIG_X86_32
14580 struct pt_regs fixed_regs;
14581 -#endif
14582
14583 -#ifdef CONFIG_X86_32
14584 - if (!user_mode_vm(regs)) {
14585 + if (!user_mode(regs)) {
14586 crash_fixup_ss_esp(&fixed_regs, regs);
14587 regs = &fixed_regs;
14588 }
14589 diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
14590 index 37250fe..bf2ec74 100644
14591 --- a/arch/x86/kernel/doublefault_32.c
14592 +++ b/arch/x86/kernel/doublefault_32.c
14593 @@ -11,7 +11,7 @@
14594
14595 #define DOUBLEFAULT_STACKSIZE (1024)
14596 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
14597 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
14598 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
14599
14600 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
14601
14602 @@ -21,7 +21,7 @@ static void doublefault_fn(void)
14603 unsigned long gdt, tss;
14604
14605 store_gdt(&gdt_desc);
14606 - gdt = gdt_desc.address;
14607 + gdt = (unsigned long)gdt_desc.address;
14608
14609 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
14610
14611 @@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
14612 /* 0x2 bit is always set */
14613 .flags = X86_EFLAGS_SF | 0x2,
14614 .sp = STACK_START,
14615 - .es = __USER_DS,
14616 + .es = __KERNEL_DS,
14617 .cs = __KERNEL_CS,
14618 .ss = __KERNEL_DS,
14619 - .ds = __USER_DS,
14620 + .ds = __KERNEL_DS,
14621 .fs = __KERNEL_PERCPU,
14622
14623 .__cr3 = __pa_nodebug(swapper_pg_dir),
14624 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
14625 index ae42418b..787c16b 100644
14626 --- a/arch/x86/kernel/dumpstack.c
14627 +++ b/arch/x86/kernel/dumpstack.c
14628 @@ -2,6 +2,9 @@
14629 * Copyright (C) 1991, 1992 Linus Torvalds
14630 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
14631 */
14632 +#ifdef CONFIG_GRKERNSEC_HIDESYM
14633 +#define __INCLUDED_BY_HIDESYM 1
14634 +#endif
14635 #include <linux/kallsyms.h>
14636 #include <linux/kprobes.h>
14637 #include <linux/uaccess.h>
14638 @@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
14639 static void
14640 print_ftrace_graph_addr(unsigned long addr, void *data,
14641 const struct stacktrace_ops *ops,
14642 - struct thread_info *tinfo, int *graph)
14643 + struct task_struct *task, int *graph)
14644 {
14645 - struct task_struct *task;
14646 unsigned long ret_addr;
14647 int index;
14648
14649 if (addr != (unsigned long)return_to_handler)
14650 return;
14651
14652 - task = tinfo->task;
14653 index = task->curr_ret_stack;
14654
14655 if (!task->ret_stack || index < *graph)
14656 @@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14657 static inline void
14658 print_ftrace_graph_addr(unsigned long addr, void *data,
14659 const struct stacktrace_ops *ops,
14660 - struct thread_info *tinfo, int *graph)
14661 + struct task_struct *task, int *graph)
14662 { }
14663 #endif
14664
14665 @@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14666 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
14667 */
14668
14669 -static inline int valid_stack_ptr(struct thread_info *tinfo,
14670 - void *p, unsigned int size, void *end)
14671 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
14672 {
14673 - void *t = tinfo;
14674 if (end) {
14675 if (p < end && p >= (end-THREAD_SIZE))
14676 return 1;
14677 @@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
14678 }
14679
14680 unsigned long
14681 -print_context_stack(struct thread_info *tinfo,
14682 +print_context_stack(struct task_struct *task, void *stack_start,
14683 unsigned long *stack, unsigned long bp,
14684 const struct stacktrace_ops *ops, void *data,
14685 unsigned long *end, int *graph)
14686 {
14687 struct stack_frame *frame = (struct stack_frame *)bp;
14688
14689 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
14690 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
14691 unsigned long addr;
14692
14693 addr = *stack;
14694 @@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
14695 } else {
14696 ops->address(data, addr, 0);
14697 }
14698 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14699 + print_ftrace_graph_addr(addr, data, ops, task, graph);
14700 }
14701 stack++;
14702 }
14703 @@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
14704 EXPORT_SYMBOL_GPL(print_context_stack);
14705
14706 unsigned long
14707 -print_context_stack_bp(struct thread_info *tinfo,
14708 +print_context_stack_bp(struct task_struct *task, void *stack_start,
14709 unsigned long *stack, unsigned long bp,
14710 const struct stacktrace_ops *ops, void *data,
14711 unsigned long *end, int *graph)
14712 @@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14713 struct stack_frame *frame = (struct stack_frame *)bp;
14714 unsigned long *ret_addr = &frame->return_address;
14715
14716 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
14717 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
14718 unsigned long addr = *ret_addr;
14719
14720 if (!__kernel_text_address(addr))
14721 @@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14722 ops->address(data, addr, 1);
14723 frame = frame->next_frame;
14724 ret_addr = &frame->return_address;
14725 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14726 + print_ftrace_graph_addr(addr, data, ops, task, graph);
14727 }
14728
14729 return (unsigned long)frame;
14730 @@ -189,7 +188,7 @@ void dump_stack(void)
14731
14732 bp = stack_frame(current, NULL);
14733 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
14734 - current->pid, current->comm, print_tainted(),
14735 + task_pid_nr(current), current->comm, print_tainted(),
14736 init_utsname()->release,
14737 (int)strcspn(init_utsname()->version, " "),
14738 init_utsname()->version);
14739 @@ -225,6 +224,8 @@ unsigned __kprobes long oops_begin(void)
14740 }
14741 EXPORT_SYMBOL_GPL(oops_begin);
14742
14743 +extern void gr_handle_kernel_exploit(void);
14744 +
14745 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14746 {
14747 if (regs && kexec_should_crash(current))
14748 @@ -246,7 +247,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14749 panic("Fatal exception in interrupt");
14750 if (panic_on_oops)
14751 panic("Fatal exception");
14752 - do_exit(signr);
14753 +
14754 + gr_handle_kernel_exploit();
14755 +
14756 + do_group_exit(signr);
14757 }
14758
14759 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14760 @@ -274,7 +278,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14761 print_modules();
14762 show_regs(regs);
14763 #ifdef CONFIG_X86_32
14764 - if (user_mode_vm(regs)) {
14765 + if (user_mode(regs)) {
14766 sp = regs->sp;
14767 ss = regs->ss & 0xffff;
14768 } else {
14769 @@ -302,7 +306,7 @@ void die(const char *str, struct pt_regs *regs, long err)
14770 unsigned long flags = oops_begin();
14771 int sig = SIGSEGV;
14772
14773 - if (!user_mode_vm(regs))
14774 + if (!user_mode(regs))
14775 report_bug(regs->ip, regs);
14776
14777 if (__die(str, regs, err))
14778 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
14779 index 1038a41..db2c12b 100644
14780 --- a/arch/x86/kernel/dumpstack_32.c
14781 +++ b/arch/x86/kernel/dumpstack_32.c
14782 @@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14783 bp = stack_frame(task, regs);
14784
14785 for (;;) {
14786 - struct thread_info *context;
14787 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14788
14789 - context = (struct thread_info *)
14790 - ((unsigned long)stack & (~(THREAD_SIZE - 1)));
14791 - bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
14792 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14793
14794 - stack = (unsigned long *)context->previous_esp;
14795 - if (!stack)
14796 + if (stack_start == task_stack_page(task))
14797 break;
14798 + stack = *(unsigned long **)stack_start;
14799 if (ops->stack(data, "IRQ") < 0)
14800 break;
14801 touch_nmi_watchdog();
14802 @@ -86,7 +84,7 @@ void show_regs(struct pt_regs *regs)
14803 {
14804 int i;
14805
14806 - __show_regs(regs, !user_mode_vm(regs));
14807 + __show_regs(regs, !user_mode(regs));
14808
14809 pr_emerg("Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)\n",
14810 TASK_COMM_LEN, current->comm, task_pid_nr(current),
14811 @@ -95,21 +93,22 @@ void show_regs(struct pt_regs *regs)
14812 * When in-kernel, we also print out the stack and code at the
14813 * time of the fault..
14814 */
14815 - if (!user_mode_vm(regs)) {
14816 + if (!user_mode(regs)) {
14817 unsigned int code_prologue = code_bytes * 43 / 64;
14818 unsigned int code_len = code_bytes;
14819 unsigned char c;
14820 u8 *ip;
14821 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
14822
14823 pr_emerg("Stack:\n");
14824 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
14825
14826 pr_emerg("Code:");
14827
14828 - ip = (u8 *)regs->ip - code_prologue;
14829 + ip = (u8 *)regs->ip - code_prologue + cs_base;
14830 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
14831 /* try starting at IP */
14832 - ip = (u8 *)regs->ip;
14833 + ip = (u8 *)regs->ip + cs_base;
14834 code_len = code_len - code_prologue + 1;
14835 }
14836 for (i = 0; i < code_len; i++, ip++) {
14837 @@ -118,7 +117,7 @@ void show_regs(struct pt_regs *regs)
14838 pr_cont(" Bad EIP value.");
14839 break;
14840 }
14841 - if (ip == (u8 *)regs->ip)
14842 + if (ip == (u8 *)regs->ip + cs_base)
14843 pr_cont(" <%02x>", c);
14844 else
14845 pr_cont(" %02x", c);
14846 @@ -131,6 +130,7 @@ int is_valid_bugaddr(unsigned long ip)
14847 {
14848 unsigned short ud2;
14849
14850 + ip = ktla_ktva(ip);
14851 if (ip < PAGE_OFFSET)
14852 return 0;
14853 if (probe_kernel_address((unsigned short *)ip, ud2))
14854 @@ -138,3 +138,15 @@ int is_valid_bugaddr(unsigned long ip)
14855
14856 return ud2 == 0x0b0f;
14857 }
14858 +
14859 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14860 +void pax_check_alloca(unsigned long size)
14861 +{
14862 + unsigned long sp = (unsigned long)&sp, stack_left;
14863 +
14864 + /* all kernel stacks are of the same size */
14865 + stack_left = sp & (THREAD_SIZE - 1);
14866 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14867 +}
14868 +EXPORT_SYMBOL(pax_check_alloca);
14869 +#endif
14870 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
14871 index b653675..51cc8c0 100644
14872 --- a/arch/x86/kernel/dumpstack_64.c
14873 +++ b/arch/x86/kernel/dumpstack_64.c
14874 @@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14875 unsigned long *irq_stack_end =
14876 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
14877 unsigned used = 0;
14878 - struct thread_info *tinfo;
14879 int graph = 0;
14880 unsigned long dummy;
14881 + void *stack_start;
14882
14883 if (!task)
14884 task = current;
14885 @@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14886 * current stack address. If the stacks consist of nested
14887 * exceptions
14888 */
14889 - tinfo = task_thread_info(task);
14890 for (;;) {
14891 char *id;
14892 unsigned long *estack_end;
14893 +
14894 estack_end = in_exception_stack(cpu, (unsigned long)stack,
14895 &used, &id);
14896
14897 @@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14898 if (ops->stack(data, id) < 0)
14899 break;
14900
14901 - bp = ops->walk_stack(tinfo, stack, bp, ops,
14902 + bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
14903 data, estack_end, &graph);
14904 ops->stack(data, "<EOE>");
14905 /*
14906 @@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14907 * second-to-last pointer (index -2 to end) in the
14908 * exception stack:
14909 */
14910 + if ((u16)estack_end[-1] != __KERNEL_DS)
14911 + goto out;
14912 stack = (unsigned long *) estack_end[-2];
14913 continue;
14914 }
14915 @@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14916 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
14917 if (ops->stack(data, "IRQ") < 0)
14918 break;
14919 - bp = ops->walk_stack(tinfo, stack, bp,
14920 + bp = ops->walk_stack(task, irq_stack, stack, bp,
14921 ops, data, irq_stack_end, &graph);
14922 /*
14923 * We link to the next stack (which would be
14924 @@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14925 /*
14926 * This handles the process stack:
14927 */
14928 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
14929 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14930 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14931 +out:
14932 put_cpu();
14933 }
14934 EXPORT_SYMBOL(dump_trace);
14935 @@ -249,7 +253,7 @@ void show_regs(struct pt_regs *regs)
14936 {
14937 int i;
14938 unsigned long sp;
14939 - const int cpu = smp_processor_id();
14940 + const int cpu = raw_smp_processor_id();
14941 struct task_struct *cur = current;
14942
14943 sp = regs->sp;
14944 @@ -304,3 +308,50 @@ int is_valid_bugaddr(unsigned long ip)
14945
14946 return ud2 == 0x0b0f;
14947 }
14948 +
14949 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14950 +void pax_check_alloca(unsigned long size)
14951 +{
14952 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
14953 + unsigned cpu, used;
14954 + char *id;
14955 +
14956 + /* check the process stack first */
14957 + stack_start = (unsigned long)task_stack_page(current);
14958 + stack_end = stack_start + THREAD_SIZE;
14959 + if (likely(stack_start <= sp && sp < stack_end)) {
14960 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
14961 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14962 + return;
14963 + }
14964 +
14965 + cpu = get_cpu();
14966 +
14967 + /* check the irq stacks */
14968 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
14969 + stack_start = stack_end - IRQ_STACK_SIZE;
14970 + if (stack_start <= sp && sp < stack_end) {
14971 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
14972 + put_cpu();
14973 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14974 + return;
14975 + }
14976 +
14977 + /* check the exception stacks */
14978 + used = 0;
14979 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
14980 + stack_start = stack_end - EXCEPTION_STKSZ;
14981 + if (stack_end && stack_start <= sp && sp < stack_end) {
14982 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
14983 + put_cpu();
14984 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14985 + return;
14986 + }
14987 +
14988 + put_cpu();
14989 +
14990 + /* unknown stack */
14991 + BUG();
14992 +}
14993 +EXPORT_SYMBOL(pax_check_alloca);
14994 +#endif
14995 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
14996 index 9b9f18b..9fcaa04 100644
14997 --- a/arch/x86/kernel/early_printk.c
14998 +++ b/arch/x86/kernel/early_printk.c
14999 @@ -7,6 +7,7 @@
15000 #include <linux/pci_regs.h>
15001 #include <linux/pci_ids.h>
15002 #include <linux/errno.h>
15003 +#include <linux/sched.h>
15004 #include <asm/io.h>
15005 #include <asm/processor.h>
15006 #include <asm/fcntl.h>
15007 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
15008 index 8f8e8ee..3617d6e 100644
15009 --- a/arch/x86/kernel/entry_32.S
15010 +++ b/arch/x86/kernel/entry_32.S
15011 @@ -176,13 +176,153 @@
15012 /*CFI_REL_OFFSET gs, PT_GS*/
15013 .endm
15014 .macro SET_KERNEL_GS reg
15015 +
15016 +#ifdef CONFIG_CC_STACKPROTECTOR
15017 movl $(__KERNEL_STACK_CANARY), \reg
15018 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
15019 + movl $(__USER_DS), \reg
15020 +#else
15021 + xorl \reg, \reg
15022 +#endif
15023 +
15024 movl \reg, %gs
15025 .endm
15026
15027 #endif /* CONFIG_X86_32_LAZY_GS */
15028
15029 -.macro SAVE_ALL
15030 +.macro pax_enter_kernel
15031 +#ifdef CONFIG_PAX_KERNEXEC
15032 + call pax_enter_kernel
15033 +#endif
15034 +.endm
15035 +
15036 +.macro pax_exit_kernel
15037 +#ifdef CONFIG_PAX_KERNEXEC
15038 + call pax_exit_kernel
15039 +#endif
15040 +.endm
15041 +
15042 +#ifdef CONFIG_PAX_KERNEXEC
15043 +ENTRY(pax_enter_kernel)
15044 +#ifdef CONFIG_PARAVIRT
15045 + pushl %eax
15046 + pushl %ecx
15047 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
15048 + mov %eax, %esi
15049 +#else
15050 + mov %cr0, %esi
15051 +#endif
15052 + bts $16, %esi
15053 + jnc 1f
15054 + mov %cs, %esi
15055 + cmp $__KERNEL_CS, %esi
15056 + jz 3f
15057 + ljmp $__KERNEL_CS, $3f
15058 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
15059 +2:
15060 +#ifdef CONFIG_PARAVIRT
15061 + mov %esi, %eax
15062 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
15063 +#else
15064 + mov %esi, %cr0
15065 +#endif
15066 +3:
15067 +#ifdef CONFIG_PARAVIRT
15068 + popl %ecx
15069 + popl %eax
15070 +#endif
15071 + ret
15072 +ENDPROC(pax_enter_kernel)
15073 +
15074 +ENTRY(pax_exit_kernel)
15075 +#ifdef CONFIG_PARAVIRT
15076 + pushl %eax
15077 + pushl %ecx
15078 +#endif
15079 + mov %cs, %esi
15080 + cmp $__KERNEXEC_KERNEL_CS, %esi
15081 + jnz 2f
15082 +#ifdef CONFIG_PARAVIRT
15083 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
15084 + mov %eax, %esi
15085 +#else
15086 + mov %cr0, %esi
15087 +#endif
15088 + btr $16, %esi
15089 + ljmp $__KERNEL_CS, $1f
15090 +1:
15091 +#ifdef CONFIG_PARAVIRT
15092 + mov %esi, %eax
15093 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
15094 +#else
15095 + mov %esi, %cr0
15096 +#endif
15097 +2:
15098 +#ifdef CONFIG_PARAVIRT
15099 + popl %ecx
15100 + popl %eax
15101 +#endif
15102 + ret
15103 +ENDPROC(pax_exit_kernel)
15104 +#endif
15105 +
15106 +.macro pax_erase_kstack
15107 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15108 + call pax_erase_kstack
15109 +#endif
15110 +.endm
15111 +
15112 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15113 +/*
15114 + * ebp: thread_info
15115 + */
15116 +ENTRY(pax_erase_kstack)
15117 + pushl %edi
15118 + pushl %ecx
15119 + pushl %eax
15120 +
15121 + mov TI_lowest_stack(%ebp), %edi
15122 + mov $-0xBEEF, %eax
15123 + std
15124 +
15125 +1: mov %edi, %ecx
15126 + and $THREAD_SIZE_asm - 1, %ecx
15127 + shr $2, %ecx
15128 + repne scasl
15129 + jecxz 2f
15130 +
15131 + cmp $2*16, %ecx
15132 + jc 2f
15133 +
15134 + mov $2*16, %ecx
15135 + repe scasl
15136 + jecxz 2f
15137 + jne 1b
15138 +
15139 +2: cld
15140 + mov %esp, %ecx
15141 + sub %edi, %ecx
15142 +
15143 + cmp $THREAD_SIZE_asm, %ecx
15144 + jb 3f
15145 + ud2
15146 +3:
15147 +
15148 + shr $2, %ecx
15149 + rep stosl
15150 +
15151 + mov TI_task_thread_sp0(%ebp), %edi
15152 + sub $128, %edi
15153 + mov %edi, TI_lowest_stack(%ebp)
15154 +
15155 + popl %eax
15156 + popl %ecx
15157 + popl %edi
15158 + ret
15159 +ENDPROC(pax_erase_kstack)
15160 +#endif
15161 +
15162 +.macro __SAVE_ALL _DS
15163 cld
15164 PUSH_GS
15165 pushl_cfi %fs
15166 @@ -205,7 +345,7 @@
15167 CFI_REL_OFFSET ecx, 0
15168 pushl_cfi %ebx
15169 CFI_REL_OFFSET ebx, 0
15170 - movl $(__USER_DS), %edx
15171 + movl $\_DS, %edx
15172 movl %edx, %ds
15173 movl %edx, %es
15174 movl $(__KERNEL_PERCPU), %edx
15175 @@ -213,6 +353,15 @@
15176 SET_KERNEL_GS %edx
15177 .endm
15178
15179 +.macro SAVE_ALL
15180 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
15181 + __SAVE_ALL __KERNEL_DS
15182 + pax_enter_kernel
15183 +#else
15184 + __SAVE_ALL __USER_DS
15185 +#endif
15186 +.endm
15187 +
15188 .macro RESTORE_INT_REGS
15189 popl_cfi %ebx
15190 CFI_RESTORE ebx
15191 @@ -296,7 +445,7 @@ ENTRY(ret_from_fork)
15192 popfl_cfi
15193 jmp syscall_exit
15194 CFI_ENDPROC
15195 -END(ret_from_fork)
15196 +ENDPROC(ret_from_fork)
15197
15198 /*
15199 * Interrupt exit functions should be protected against kprobes
15200 @@ -329,7 +478,15 @@ ret_from_intr:
15201 andl $SEGMENT_RPL_MASK, %eax
15202 #endif
15203 cmpl $USER_RPL, %eax
15204 +
15205 +#ifdef CONFIG_PAX_KERNEXEC
15206 + jae resume_userspace
15207 +
15208 + pax_exit_kernel
15209 + jmp resume_kernel
15210 +#else
15211 jb resume_kernel # not returning to v8086 or userspace
15212 +#endif
15213
15214 ENTRY(resume_userspace)
15215 LOCKDEP_SYS_EXIT
15216 @@ -341,8 +498,8 @@ ENTRY(resume_userspace)
15217 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
15218 # int/exception return?
15219 jne work_pending
15220 - jmp restore_all
15221 -END(ret_from_exception)
15222 + jmp restore_all_pax
15223 +ENDPROC(ret_from_exception)
15224
15225 #ifdef CONFIG_PREEMPT
15226 ENTRY(resume_kernel)
15227 @@ -357,7 +514,7 @@ need_resched:
15228 jz restore_all
15229 call preempt_schedule_irq
15230 jmp need_resched
15231 -END(resume_kernel)
15232 +ENDPROC(resume_kernel)
15233 #endif
15234 CFI_ENDPROC
15235 /*
15236 @@ -391,28 +548,43 @@ sysenter_past_esp:
15237 /*CFI_REL_OFFSET cs, 0*/
15238 /*
15239 * Push current_thread_info()->sysenter_return to the stack.
15240 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
15241 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
15242 */
15243 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
15244 + pushl_cfi $0
15245 CFI_REL_OFFSET eip, 0
15246
15247 pushl_cfi %eax
15248 SAVE_ALL
15249 + GET_THREAD_INFO(%ebp)
15250 + movl TI_sysenter_return(%ebp),%ebp
15251 + movl %ebp,PT_EIP(%esp)
15252 ENABLE_INTERRUPTS(CLBR_NONE)
15253
15254 /*
15255 * Load the potential sixth argument from user stack.
15256 * Careful about security.
15257 */
15258 + movl PT_OLDESP(%esp),%ebp
15259 +
15260 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15261 + mov PT_OLDSS(%esp),%ds
15262 +1: movl %ds:(%ebp),%ebp
15263 + push %ss
15264 + pop %ds
15265 +#else
15266 cmpl $__PAGE_OFFSET-3,%ebp
15267 jae syscall_fault
15268 1: movl (%ebp),%ebp
15269 +#endif
15270 +
15271 movl %ebp,PT_EBP(%esp)
15272 _ASM_EXTABLE(1b,syscall_fault)
15273
15274 GET_THREAD_INFO(%ebp)
15275
15276 +#ifdef CONFIG_PAX_RANDKSTACK
15277 + pax_erase_kstack
15278 +#endif
15279 +
15280 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
15281 jnz sysenter_audit
15282 sysenter_do_call:
15283 @@ -427,12 +599,24 @@ sysenter_do_call:
15284 testl $_TIF_ALLWORK_MASK, %ecx
15285 jne sysexit_audit
15286 sysenter_exit:
15287 +
15288 +#ifdef CONFIG_PAX_RANDKSTACK
15289 + pushl_cfi %eax
15290 + movl %esp, %eax
15291 + call pax_randomize_kstack
15292 + popl_cfi %eax
15293 +#endif
15294 +
15295 + pax_erase_kstack
15296 +
15297 /* if something modifies registers it must also disable sysexit */
15298 movl PT_EIP(%esp), %edx
15299 movl PT_OLDESP(%esp), %ecx
15300 xorl %ebp,%ebp
15301 TRACE_IRQS_ON
15302 1: mov PT_FS(%esp), %fs
15303 +2: mov PT_DS(%esp), %ds
15304 +3: mov PT_ES(%esp), %es
15305 PTGS_TO_GS
15306 ENABLE_INTERRUPTS_SYSEXIT
15307
15308 @@ -449,6 +633,9 @@ sysenter_audit:
15309 movl %eax,%edx /* 2nd arg: syscall number */
15310 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
15311 call __audit_syscall_entry
15312 +
15313 + pax_erase_kstack
15314 +
15315 pushl_cfi %ebx
15316 movl PT_EAX(%esp),%eax /* reload syscall number */
15317 jmp sysenter_do_call
15318 @@ -474,10 +661,16 @@ sysexit_audit:
15319
15320 CFI_ENDPROC
15321 .pushsection .fixup,"ax"
15322 -2: movl $0,PT_FS(%esp)
15323 +4: movl $0,PT_FS(%esp)
15324 + jmp 1b
15325 +5: movl $0,PT_DS(%esp)
15326 + jmp 1b
15327 +6: movl $0,PT_ES(%esp)
15328 jmp 1b
15329 .popsection
15330 - _ASM_EXTABLE(1b,2b)
15331 + _ASM_EXTABLE(1b,4b)
15332 + _ASM_EXTABLE(2b,5b)
15333 + _ASM_EXTABLE(3b,6b)
15334 PTGS_TO_GS_EX
15335 ENDPROC(ia32_sysenter_target)
15336
15337 @@ -491,6 +684,11 @@ ENTRY(system_call)
15338 pushl_cfi %eax # save orig_eax
15339 SAVE_ALL
15340 GET_THREAD_INFO(%ebp)
15341 +
15342 +#ifdef CONFIG_PAX_RANDKSTACK
15343 + pax_erase_kstack
15344 +#endif
15345 +
15346 # system call tracing in operation / emulation
15347 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
15348 jnz syscall_trace_entry
15349 @@ -509,6 +707,15 @@ syscall_exit:
15350 testl $_TIF_ALLWORK_MASK, %ecx # current->work
15351 jne syscall_exit_work
15352
15353 +restore_all_pax:
15354 +
15355 +#ifdef CONFIG_PAX_RANDKSTACK
15356 + movl %esp, %eax
15357 + call pax_randomize_kstack
15358 +#endif
15359 +
15360 + pax_erase_kstack
15361 +
15362 restore_all:
15363 TRACE_IRQS_IRET
15364 restore_all_notrace:
15365 @@ -565,14 +772,34 @@ ldt_ss:
15366 * compensating for the offset by changing to the ESPFIX segment with
15367 * a base address that matches for the difference.
15368 */
15369 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
15370 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
15371 mov %esp, %edx /* load kernel esp */
15372 mov PT_OLDESP(%esp), %eax /* load userspace esp */
15373 mov %dx, %ax /* eax: new kernel esp */
15374 sub %eax, %edx /* offset (low word is 0) */
15375 +#ifdef CONFIG_SMP
15376 + movl PER_CPU_VAR(cpu_number), %ebx
15377 + shll $PAGE_SHIFT_asm, %ebx
15378 + addl $cpu_gdt_table, %ebx
15379 +#else
15380 + movl $cpu_gdt_table, %ebx
15381 +#endif
15382 shr $16, %edx
15383 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
15384 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
15385 +
15386 +#ifdef CONFIG_PAX_KERNEXEC
15387 + mov %cr0, %esi
15388 + btr $16, %esi
15389 + mov %esi, %cr0
15390 +#endif
15391 +
15392 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
15393 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
15394 +
15395 +#ifdef CONFIG_PAX_KERNEXEC
15396 + bts $16, %esi
15397 + mov %esi, %cr0
15398 +#endif
15399 +
15400 pushl_cfi $__ESPFIX_SS
15401 pushl_cfi %eax /* new kernel esp */
15402 /* Disable interrupts, but do not irqtrace this section: we
15403 @@ -601,35 +828,23 @@ work_resched:
15404 movl TI_flags(%ebp), %ecx
15405 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
15406 # than syscall tracing?
15407 - jz restore_all
15408 + jz restore_all_pax
15409 testb $_TIF_NEED_RESCHED, %cl
15410 jnz work_resched
15411
15412 work_notifysig: # deal with pending signals and
15413 # notify-resume requests
15414 + movl %esp, %eax
15415 #ifdef CONFIG_VM86
15416 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
15417 - movl %esp, %eax
15418 - jne work_notifysig_v86 # returning to kernel-space or
15419 + jz 1f # returning to kernel-space or
15420 # vm86-space
15421 - TRACE_IRQS_ON
15422 - ENABLE_INTERRUPTS(CLBR_NONE)
15423 - movb PT_CS(%esp), %bl
15424 - andb $SEGMENT_RPL_MASK, %bl
15425 - cmpb $USER_RPL, %bl
15426 - jb resume_kernel
15427 - xorl %edx, %edx
15428 - call do_notify_resume
15429 - jmp resume_userspace
15430
15431 - ALIGN
15432 -work_notifysig_v86:
15433 pushl_cfi %ecx # save ti_flags for do_notify_resume
15434 call save_v86_state # %eax contains pt_regs pointer
15435 popl_cfi %ecx
15436 movl %eax, %esp
15437 -#else
15438 - movl %esp, %eax
15439 +1:
15440 #endif
15441 TRACE_IRQS_ON
15442 ENABLE_INTERRUPTS(CLBR_NONE)
15443 @@ -640,7 +855,7 @@ work_notifysig_v86:
15444 xorl %edx, %edx
15445 call do_notify_resume
15446 jmp resume_userspace
15447 -END(work_pending)
15448 +ENDPROC(work_pending)
15449
15450 # perform syscall exit tracing
15451 ALIGN
15452 @@ -648,11 +863,14 @@ syscall_trace_entry:
15453 movl $-ENOSYS,PT_EAX(%esp)
15454 movl %esp, %eax
15455 call syscall_trace_enter
15456 +
15457 + pax_erase_kstack
15458 +
15459 /* What it returned is what we'll actually use. */
15460 cmpl $(NR_syscalls), %eax
15461 jnae syscall_call
15462 jmp syscall_exit
15463 -END(syscall_trace_entry)
15464 +ENDPROC(syscall_trace_entry)
15465
15466 # perform syscall exit tracing
15467 ALIGN
15468 @@ -665,20 +883,24 @@ syscall_exit_work:
15469 movl %esp, %eax
15470 call syscall_trace_leave
15471 jmp resume_userspace
15472 -END(syscall_exit_work)
15473 +ENDPROC(syscall_exit_work)
15474 CFI_ENDPROC
15475
15476 RING0_INT_FRAME # can't unwind into user space anyway
15477 syscall_fault:
15478 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15479 + push %ss
15480 + pop %ds
15481 +#endif
15482 GET_THREAD_INFO(%ebp)
15483 movl $-EFAULT,PT_EAX(%esp)
15484 jmp resume_userspace
15485 -END(syscall_fault)
15486 +ENDPROC(syscall_fault)
15487
15488 syscall_badsys:
15489 movl $-ENOSYS,PT_EAX(%esp)
15490 jmp resume_userspace
15491 -END(syscall_badsys)
15492 +ENDPROC(syscall_badsys)
15493 CFI_ENDPROC
15494 /*
15495 * End of kprobes section
15496 @@ -750,6 +972,36 @@ ENTRY(ptregs_clone)
15497 CFI_ENDPROC
15498 ENDPROC(ptregs_clone)
15499
15500 + ALIGN;
15501 +ENTRY(kernel_execve)
15502 + CFI_STARTPROC
15503 + pushl_cfi %ebp
15504 + sub $PT_OLDSS+4,%esp
15505 + pushl_cfi %edi
15506 + pushl_cfi %ecx
15507 + pushl_cfi %eax
15508 + lea 3*4(%esp),%edi
15509 + mov $PT_OLDSS/4+1,%ecx
15510 + xorl %eax,%eax
15511 + rep stosl
15512 + popl_cfi %eax
15513 + popl_cfi %ecx
15514 + popl_cfi %edi
15515 + movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
15516 + pushl_cfi %esp
15517 + call sys_execve
15518 + add $4,%esp
15519 + CFI_ADJUST_CFA_OFFSET -4
15520 + GET_THREAD_INFO(%ebp)
15521 + test %eax,%eax
15522 + jz syscall_exit
15523 + add $PT_OLDSS+4,%esp
15524 + CFI_ADJUST_CFA_OFFSET -PT_OLDSS-4
15525 + popl_cfi %ebp
15526 + ret
15527 + CFI_ENDPROC
15528 +ENDPROC(kernel_execve)
15529 +
15530 .macro FIXUP_ESPFIX_STACK
15531 /*
15532 * Switch back for ESPFIX stack to the normal zerobased stack
15533 @@ -759,8 +1011,15 @@ ENDPROC(ptregs_clone)
15534 * normal stack and adjusts ESP with the matching offset.
15535 */
15536 /* fixup the stack */
15537 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
15538 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
15539 +#ifdef CONFIG_SMP
15540 + movl PER_CPU_VAR(cpu_number), %ebx
15541 + shll $PAGE_SHIFT_asm, %ebx
15542 + addl $cpu_gdt_table, %ebx
15543 +#else
15544 + movl $cpu_gdt_table, %ebx
15545 +#endif
15546 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
15547 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
15548 shl $16, %eax
15549 addl %esp, %eax /* the adjusted stack pointer */
15550 pushl_cfi $__KERNEL_DS
15551 @@ -813,7 +1072,7 @@ vector=vector+1
15552 .endr
15553 2: jmp common_interrupt
15554 .endr
15555 -END(irq_entries_start)
15556 +ENDPROC(irq_entries_start)
15557
15558 .previous
15559 END(interrupt)
15560 @@ -861,7 +1120,7 @@ ENTRY(coprocessor_error)
15561 pushl_cfi $do_coprocessor_error
15562 jmp error_code
15563 CFI_ENDPROC
15564 -END(coprocessor_error)
15565 +ENDPROC(coprocessor_error)
15566
15567 ENTRY(simd_coprocessor_error)
15568 RING0_INT_FRAME
15569 @@ -882,7 +1141,7 @@ ENTRY(simd_coprocessor_error)
15570 #endif
15571 jmp error_code
15572 CFI_ENDPROC
15573 -END(simd_coprocessor_error)
15574 +ENDPROC(simd_coprocessor_error)
15575
15576 ENTRY(device_not_available)
15577 RING0_INT_FRAME
15578 @@ -890,18 +1149,18 @@ ENTRY(device_not_available)
15579 pushl_cfi $do_device_not_available
15580 jmp error_code
15581 CFI_ENDPROC
15582 -END(device_not_available)
15583 +ENDPROC(device_not_available)
15584
15585 #ifdef CONFIG_PARAVIRT
15586 ENTRY(native_iret)
15587 iret
15588 _ASM_EXTABLE(native_iret, iret_exc)
15589 -END(native_iret)
15590 +ENDPROC(native_iret)
15591
15592 ENTRY(native_irq_enable_sysexit)
15593 sti
15594 sysexit
15595 -END(native_irq_enable_sysexit)
15596 +ENDPROC(native_irq_enable_sysexit)
15597 #endif
15598
15599 ENTRY(overflow)
15600 @@ -910,7 +1169,7 @@ ENTRY(overflow)
15601 pushl_cfi $do_overflow
15602 jmp error_code
15603 CFI_ENDPROC
15604 -END(overflow)
15605 +ENDPROC(overflow)
15606
15607 ENTRY(bounds)
15608 RING0_INT_FRAME
15609 @@ -918,7 +1177,7 @@ ENTRY(bounds)
15610 pushl_cfi $do_bounds
15611 jmp error_code
15612 CFI_ENDPROC
15613 -END(bounds)
15614 +ENDPROC(bounds)
15615
15616 ENTRY(invalid_op)
15617 RING0_INT_FRAME
15618 @@ -926,7 +1185,7 @@ ENTRY(invalid_op)
15619 pushl_cfi $do_invalid_op
15620 jmp error_code
15621 CFI_ENDPROC
15622 -END(invalid_op)
15623 +ENDPROC(invalid_op)
15624
15625 ENTRY(coprocessor_segment_overrun)
15626 RING0_INT_FRAME
15627 @@ -934,35 +1193,35 @@ ENTRY(coprocessor_segment_overrun)
15628 pushl_cfi $do_coprocessor_segment_overrun
15629 jmp error_code
15630 CFI_ENDPROC
15631 -END(coprocessor_segment_overrun)
15632 +ENDPROC(coprocessor_segment_overrun)
15633
15634 ENTRY(invalid_TSS)
15635 RING0_EC_FRAME
15636 pushl_cfi $do_invalid_TSS
15637 jmp error_code
15638 CFI_ENDPROC
15639 -END(invalid_TSS)
15640 +ENDPROC(invalid_TSS)
15641
15642 ENTRY(segment_not_present)
15643 RING0_EC_FRAME
15644 pushl_cfi $do_segment_not_present
15645 jmp error_code
15646 CFI_ENDPROC
15647 -END(segment_not_present)
15648 +ENDPROC(segment_not_present)
15649
15650 ENTRY(stack_segment)
15651 RING0_EC_FRAME
15652 pushl_cfi $do_stack_segment
15653 jmp error_code
15654 CFI_ENDPROC
15655 -END(stack_segment)
15656 +ENDPROC(stack_segment)
15657
15658 ENTRY(alignment_check)
15659 RING0_EC_FRAME
15660 pushl_cfi $do_alignment_check
15661 jmp error_code
15662 CFI_ENDPROC
15663 -END(alignment_check)
15664 +ENDPROC(alignment_check)
15665
15666 ENTRY(divide_error)
15667 RING0_INT_FRAME
15668 @@ -970,7 +1229,7 @@ ENTRY(divide_error)
15669 pushl_cfi $do_divide_error
15670 jmp error_code
15671 CFI_ENDPROC
15672 -END(divide_error)
15673 +ENDPROC(divide_error)
15674
15675 #ifdef CONFIG_X86_MCE
15676 ENTRY(machine_check)
15677 @@ -979,7 +1238,7 @@ ENTRY(machine_check)
15678 pushl_cfi machine_check_vector
15679 jmp error_code
15680 CFI_ENDPROC
15681 -END(machine_check)
15682 +ENDPROC(machine_check)
15683 #endif
15684
15685 ENTRY(spurious_interrupt_bug)
15686 @@ -988,7 +1247,7 @@ ENTRY(spurious_interrupt_bug)
15687 pushl_cfi $do_spurious_interrupt_bug
15688 jmp error_code
15689 CFI_ENDPROC
15690 -END(spurious_interrupt_bug)
15691 +ENDPROC(spurious_interrupt_bug)
15692 /*
15693 * End of kprobes section
15694 */
15695 @@ -1102,7 +1361,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
15696
15697 ENTRY(mcount)
15698 ret
15699 -END(mcount)
15700 +ENDPROC(mcount)
15701
15702 ENTRY(ftrace_caller)
15703 cmpl $0, function_trace_stop
15704 @@ -1131,7 +1390,7 @@ ftrace_graph_call:
15705 .globl ftrace_stub
15706 ftrace_stub:
15707 ret
15708 -END(ftrace_caller)
15709 +ENDPROC(ftrace_caller)
15710
15711 #else /* ! CONFIG_DYNAMIC_FTRACE */
15712
15713 @@ -1167,7 +1426,7 @@ trace:
15714 popl %ecx
15715 popl %eax
15716 jmp ftrace_stub
15717 -END(mcount)
15718 +ENDPROC(mcount)
15719 #endif /* CONFIG_DYNAMIC_FTRACE */
15720 #endif /* CONFIG_FUNCTION_TRACER */
15721
15722 @@ -1188,7 +1447,7 @@ ENTRY(ftrace_graph_caller)
15723 popl %ecx
15724 popl %eax
15725 ret
15726 -END(ftrace_graph_caller)
15727 +ENDPROC(ftrace_graph_caller)
15728
15729 .globl return_to_handler
15730 return_to_handler:
15731 @@ -1243,15 +1502,18 @@ error_code:
15732 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
15733 REG_TO_PTGS %ecx
15734 SET_KERNEL_GS %ecx
15735 - movl $(__USER_DS), %ecx
15736 + movl $(__KERNEL_DS), %ecx
15737 movl %ecx, %ds
15738 movl %ecx, %es
15739 +
15740 + pax_enter_kernel
15741 +
15742 TRACE_IRQS_OFF
15743 movl %esp,%eax # pt_regs pointer
15744 call *%edi
15745 jmp ret_from_exception
15746 CFI_ENDPROC
15747 -END(page_fault)
15748 +ENDPROC(page_fault)
15749
15750 /*
15751 * Debug traps and NMI can happen at the one SYSENTER instruction
15752 @@ -1293,7 +1555,7 @@ debug_stack_correct:
15753 call do_debug
15754 jmp ret_from_exception
15755 CFI_ENDPROC
15756 -END(debug)
15757 +ENDPROC(debug)
15758
15759 /*
15760 * NMI is doubly nasty. It can happen _while_ we're handling
15761 @@ -1330,6 +1592,9 @@ nmi_stack_correct:
15762 xorl %edx,%edx # zero error code
15763 movl %esp,%eax # pt_regs pointer
15764 call do_nmi
15765 +
15766 + pax_exit_kernel
15767 +
15768 jmp restore_all_notrace
15769 CFI_ENDPROC
15770
15771 @@ -1366,12 +1631,15 @@ nmi_espfix_stack:
15772 FIXUP_ESPFIX_STACK # %eax == %esp
15773 xorl %edx,%edx # zero error code
15774 call do_nmi
15775 +
15776 + pax_exit_kernel
15777 +
15778 RESTORE_REGS
15779 lss 12+4(%esp), %esp # back to espfix stack
15780 CFI_ADJUST_CFA_OFFSET -24
15781 jmp irq_return
15782 CFI_ENDPROC
15783 -END(nmi)
15784 +ENDPROC(nmi)
15785
15786 ENTRY(int3)
15787 RING0_INT_FRAME
15788 @@ -1383,14 +1651,14 @@ ENTRY(int3)
15789 call do_int3
15790 jmp ret_from_exception
15791 CFI_ENDPROC
15792 -END(int3)
15793 +ENDPROC(int3)
15794
15795 ENTRY(general_protection)
15796 RING0_EC_FRAME
15797 pushl_cfi $do_general_protection
15798 jmp error_code
15799 CFI_ENDPROC
15800 -END(general_protection)
15801 +ENDPROC(general_protection)
15802
15803 #ifdef CONFIG_KVM_GUEST
15804 ENTRY(async_page_fault)
15805 @@ -1398,7 +1666,7 @@ ENTRY(async_page_fault)
15806 pushl_cfi $do_async_page_fault
15807 jmp error_code
15808 CFI_ENDPROC
15809 -END(async_page_fault)
15810 +ENDPROC(async_page_fault)
15811 #endif
15812
15813 /*
15814 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
15815 index dcdd0ea..a520f76 100644
15816 --- a/arch/x86/kernel/entry_64.S
15817 +++ b/arch/x86/kernel/entry_64.S
15818 @@ -57,6 +57,8 @@
15819 #include <asm/percpu.h>
15820 #include <asm/asm.h>
15821 #include <linux/err.h>
15822 +#include <asm/pgtable.h>
15823 +#include <asm/alternative-asm.h>
15824
15825 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
15826 #include <linux/elf-em.h>
15827 @@ -70,8 +72,9 @@
15828 #ifdef CONFIG_FUNCTION_TRACER
15829 #ifdef CONFIG_DYNAMIC_FTRACE
15830 ENTRY(mcount)
15831 + pax_force_retaddr
15832 retq
15833 -END(mcount)
15834 +ENDPROC(mcount)
15835
15836 ENTRY(ftrace_caller)
15837 cmpl $0, function_trace_stop
15838 @@ -94,8 +97,9 @@ GLOBAL(ftrace_graph_call)
15839 #endif
15840
15841 GLOBAL(ftrace_stub)
15842 + pax_force_retaddr
15843 retq
15844 -END(ftrace_caller)
15845 +ENDPROC(ftrace_caller)
15846
15847 #else /* ! CONFIG_DYNAMIC_FTRACE */
15848 ENTRY(mcount)
15849 @@ -114,6 +118,7 @@ ENTRY(mcount)
15850 #endif
15851
15852 GLOBAL(ftrace_stub)
15853 + pax_force_retaddr
15854 retq
15855
15856 trace:
15857 @@ -123,12 +128,13 @@ trace:
15858 movq 8(%rbp), %rsi
15859 subq $MCOUNT_INSN_SIZE, %rdi
15860
15861 + pax_force_fptr ftrace_trace_function
15862 call *ftrace_trace_function
15863
15864 MCOUNT_RESTORE_FRAME
15865
15866 jmp ftrace_stub
15867 -END(mcount)
15868 +ENDPROC(mcount)
15869 #endif /* CONFIG_DYNAMIC_FTRACE */
15870 #endif /* CONFIG_FUNCTION_TRACER */
15871
15872 @@ -148,8 +154,9 @@ ENTRY(ftrace_graph_caller)
15873
15874 MCOUNT_RESTORE_FRAME
15875
15876 + pax_force_retaddr
15877 retq
15878 -END(ftrace_graph_caller)
15879 +ENDPROC(ftrace_graph_caller)
15880
15881 GLOBAL(return_to_handler)
15882 subq $24, %rsp
15883 @@ -165,6 +172,7 @@ GLOBAL(return_to_handler)
15884 movq 8(%rsp), %rdx
15885 movq (%rsp), %rax
15886 addq $24, %rsp
15887 + pax_force_fptr %rdi
15888 jmp *%rdi
15889 #endif
15890
15891 @@ -180,6 +188,273 @@ ENTRY(native_usergs_sysret64)
15892 ENDPROC(native_usergs_sysret64)
15893 #endif /* CONFIG_PARAVIRT */
15894
15895 + .macro ljmpq sel, off
15896 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
15897 + .byte 0x48; ljmp *1234f(%rip)
15898 + .pushsection .rodata
15899 + .align 16
15900 + 1234: .quad \off; .word \sel
15901 + .popsection
15902 +#else
15903 + pushq $\sel
15904 + pushq $\off
15905 + lretq
15906 +#endif
15907 + .endm
15908 +
15909 + .macro pax_enter_kernel
15910 + pax_set_fptr_mask
15911 +#ifdef CONFIG_PAX_KERNEXEC
15912 + call pax_enter_kernel
15913 +#endif
15914 + .endm
15915 +
15916 + .macro pax_exit_kernel
15917 +#ifdef CONFIG_PAX_KERNEXEC
15918 + call pax_exit_kernel
15919 +#endif
15920 + .endm
15921 +
15922 +#ifdef CONFIG_PAX_KERNEXEC
15923 +ENTRY(pax_enter_kernel)
15924 + pushq %rdi
15925 +
15926 +#ifdef CONFIG_PARAVIRT
15927 + PV_SAVE_REGS(CLBR_RDI)
15928 +#endif
15929 +
15930 + GET_CR0_INTO_RDI
15931 + bts $16,%rdi
15932 + jnc 3f
15933 + mov %cs,%edi
15934 + cmp $__KERNEL_CS,%edi
15935 + jnz 2f
15936 +1:
15937 +
15938 +#ifdef CONFIG_PARAVIRT
15939 + PV_RESTORE_REGS(CLBR_RDI)
15940 +#endif
15941 +
15942 + popq %rdi
15943 + pax_force_retaddr
15944 + retq
15945 +
15946 +2: ljmpq __KERNEL_CS,1f
15947 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
15948 +4: SET_RDI_INTO_CR0
15949 + jmp 1b
15950 +ENDPROC(pax_enter_kernel)
15951 +
15952 +ENTRY(pax_exit_kernel)
15953 + pushq %rdi
15954 +
15955 +#ifdef CONFIG_PARAVIRT
15956 + PV_SAVE_REGS(CLBR_RDI)
15957 +#endif
15958 +
15959 + mov %cs,%rdi
15960 + cmp $__KERNEXEC_KERNEL_CS,%edi
15961 + jz 2f
15962 +1:
15963 +
15964 +#ifdef CONFIG_PARAVIRT
15965 + PV_RESTORE_REGS(CLBR_RDI);
15966 +#endif
15967 +
15968 + popq %rdi
15969 + pax_force_retaddr
15970 + retq
15971 +
15972 +2: GET_CR0_INTO_RDI
15973 + btr $16,%rdi
15974 + ljmpq __KERNEL_CS,3f
15975 +3: SET_RDI_INTO_CR0
15976 + jmp 1b
15977 +ENDPROC(pax_exit_kernel)
15978 +#endif
15979 +
15980 + .macro pax_enter_kernel_user
15981 + pax_set_fptr_mask
15982 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15983 + call pax_enter_kernel_user
15984 +#endif
15985 + .endm
15986 +
15987 + .macro pax_exit_kernel_user
15988 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15989 + call pax_exit_kernel_user
15990 +#endif
15991 +#ifdef CONFIG_PAX_RANDKSTACK
15992 + pushq %rax
15993 + call pax_randomize_kstack
15994 + popq %rax
15995 +#endif
15996 + .endm
15997 +
15998 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15999 +ENTRY(pax_enter_kernel_user)
16000 + pushq %rdi
16001 + pushq %rbx
16002 +
16003 +#ifdef CONFIG_PARAVIRT
16004 + PV_SAVE_REGS(CLBR_RDI)
16005 +#endif
16006 +
16007 + GET_CR3_INTO_RDI
16008 + mov %rdi,%rbx
16009 + add $__START_KERNEL_map,%rbx
16010 + sub phys_base(%rip),%rbx
16011 +
16012 +#ifdef CONFIG_PARAVIRT
16013 + pushq %rdi
16014 + cmpl $0, pv_info+PARAVIRT_enabled
16015 + jz 1f
16016 + i = 0
16017 + .rept USER_PGD_PTRS
16018 + mov i*8(%rbx),%rsi
16019 + mov $0,%sil
16020 + lea i*8(%rbx),%rdi
16021 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
16022 + i = i + 1
16023 + .endr
16024 + jmp 2f
16025 +1:
16026 +#endif
16027 +
16028 + i = 0
16029 + .rept USER_PGD_PTRS
16030 + movb $0,i*8(%rbx)
16031 + i = i + 1
16032 + .endr
16033 +
16034 +#ifdef CONFIG_PARAVIRT
16035 +2: popq %rdi
16036 +#endif
16037 + SET_RDI_INTO_CR3
16038 +
16039 +#ifdef CONFIG_PAX_KERNEXEC
16040 + GET_CR0_INTO_RDI
16041 + bts $16,%rdi
16042 + SET_RDI_INTO_CR0
16043 +#endif
16044 +
16045 +#ifdef CONFIG_PARAVIRT
16046 + PV_RESTORE_REGS(CLBR_RDI)
16047 +#endif
16048 +
16049 + popq %rbx
16050 + popq %rdi
16051 + pax_force_retaddr
16052 + retq
16053 +ENDPROC(pax_enter_kernel_user)
16054 +
16055 +ENTRY(pax_exit_kernel_user)
16056 + push %rdi
16057 +
16058 +#ifdef CONFIG_PARAVIRT
16059 + pushq %rbx
16060 + PV_SAVE_REGS(CLBR_RDI)
16061 +#endif
16062 +
16063 +#ifdef CONFIG_PAX_KERNEXEC
16064 + GET_CR0_INTO_RDI
16065 + btr $16,%rdi
16066 + SET_RDI_INTO_CR0
16067 +#endif
16068 +
16069 + GET_CR3_INTO_RDI
16070 + add $__START_KERNEL_map,%rdi
16071 + sub phys_base(%rip),%rdi
16072 +
16073 +#ifdef CONFIG_PARAVIRT
16074 + cmpl $0, pv_info+PARAVIRT_enabled
16075 + jz 1f
16076 + mov %rdi,%rbx
16077 + i = 0
16078 + .rept USER_PGD_PTRS
16079 + mov i*8(%rbx),%rsi
16080 + mov $0x67,%sil
16081 + lea i*8(%rbx),%rdi
16082 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
16083 + i = i + 1
16084 + .endr
16085 + jmp 2f
16086 +1:
16087 +#endif
16088 +
16089 + i = 0
16090 + .rept USER_PGD_PTRS
16091 + movb $0x67,i*8(%rdi)
16092 + i = i + 1
16093 + .endr
16094 +
16095 +#ifdef CONFIG_PARAVIRT
16096 +2: PV_RESTORE_REGS(CLBR_RDI)
16097 + popq %rbx
16098 +#endif
16099 +
16100 + popq %rdi
16101 + pax_force_retaddr
16102 + retq
16103 +ENDPROC(pax_exit_kernel_user)
16104 +#endif
16105 +
16106 +.macro pax_erase_kstack
16107 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16108 + call pax_erase_kstack
16109 +#endif
16110 +.endm
16111 +
16112 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16113 +ENTRY(pax_erase_kstack)
16114 + pushq %rdi
16115 + pushq %rcx
16116 + pushq %rax
16117 + pushq %r11
16118 +
16119 + GET_THREAD_INFO(%r11)
16120 + mov TI_lowest_stack(%r11), %rdi
16121 + mov $-0xBEEF, %rax
16122 + std
16123 +
16124 +1: mov %edi, %ecx
16125 + and $THREAD_SIZE_asm - 1, %ecx
16126 + shr $3, %ecx
16127 + repne scasq
16128 + jecxz 2f
16129 +
16130 + cmp $2*8, %ecx
16131 + jc 2f
16132 +
16133 + mov $2*8, %ecx
16134 + repe scasq
16135 + jecxz 2f
16136 + jne 1b
16137 +
16138 +2: cld
16139 + mov %esp, %ecx
16140 + sub %edi, %ecx
16141 +
16142 + cmp $THREAD_SIZE_asm, %rcx
16143 + jb 3f
16144 + ud2
16145 +3:
16146 +
16147 + shr $3, %ecx
16148 + rep stosq
16149 +
16150 + mov TI_task_thread_sp0(%r11), %rdi
16151 + sub $256, %rdi
16152 + mov %rdi, TI_lowest_stack(%r11)
16153 +
16154 + popq %r11
16155 + popq %rax
16156 + popq %rcx
16157 + popq %rdi
16158 + pax_force_retaddr
16159 + ret
16160 +ENDPROC(pax_erase_kstack)
16161 +#endif
16162
16163 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
16164 #ifdef CONFIG_TRACE_IRQFLAGS
16165 @@ -271,8 +546,8 @@ ENDPROC(native_usergs_sysret64)
16166 .endm
16167
16168 .macro UNFAKE_STACK_FRAME
16169 - addq $8*6, %rsp
16170 - CFI_ADJUST_CFA_OFFSET -(6*8)
16171 + addq $8*6 + ARG_SKIP, %rsp
16172 + CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
16173 .endm
16174
16175 /*
16176 @@ -359,7 +634,7 @@ ENDPROC(native_usergs_sysret64)
16177 movq %rsp, %rsi
16178
16179 leaq -RBP(%rsp),%rdi /* arg1 for handler */
16180 - testl $3, CS-RBP(%rsi)
16181 + testb $3, CS-RBP(%rsi)
16182 je 1f
16183 SWAPGS
16184 /*
16185 @@ -394,9 +669,10 @@ ENTRY(save_rest)
16186 movq_cfi r15, R15+16
16187 movq %r11, 8(%rsp) /* return address */
16188 FIXUP_TOP_OF_STACK %r11, 16
16189 + pax_force_retaddr
16190 ret
16191 CFI_ENDPROC
16192 -END(save_rest)
16193 +ENDPROC(save_rest)
16194
16195 /* save complete stack frame */
16196 .pushsection .kprobes.text, "ax"
16197 @@ -425,9 +701,10 @@ ENTRY(save_paranoid)
16198 js 1f /* negative -> in kernel */
16199 SWAPGS
16200 xorl %ebx,%ebx
16201 -1: ret
16202 +1: pax_force_retaddr_bts
16203 + ret
16204 CFI_ENDPROC
16205 -END(save_paranoid)
16206 +ENDPROC(save_paranoid)
16207 .popsection
16208
16209 /*
16210 @@ -449,7 +726,7 @@ ENTRY(ret_from_fork)
16211
16212 RESTORE_REST
16213
16214 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16215 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16216 jz retint_restore_args
16217
16218 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
16219 @@ -459,7 +736,7 @@ ENTRY(ret_from_fork)
16220 jmp ret_from_sys_call # go to the SYSRET fastpath
16221
16222 CFI_ENDPROC
16223 -END(ret_from_fork)
16224 +ENDPROC(ret_from_fork)
16225
16226 /*
16227 * System call entry. Up to 6 arguments in registers are supported.
16228 @@ -495,7 +772,7 @@ END(ret_from_fork)
16229 ENTRY(system_call)
16230 CFI_STARTPROC simple
16231 CFI_SIGNAL_FRAME
16232 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
16233 + CFI_DEF_CFA rsp,0
16234 CFI_REGISTER rip,rcx
16235 /*CFI_REGISTER rflags,r11*/
16236 SWAPGS_UNSAFE_STACK
16237 @@ -508,16 +785,23 @@ GLOBAL(system_call_after_swapgs)
16238
16239 movq %rsp,PER_CPU_VAR(old_rsp)
16240 movq PER_CPU_VAR(kernel_stack),%rsp
16241 + SAVE_ARGS 8*6,0
16242 + pax_enter_kernel_user
16243 +
16244 +#ifdef CONFIG_PAX_RANDKSTACK
16245 + pax_erase_kstack
16246 +#endif
16247 +
16248 /*
16249 * No need to follow this irqs off/on section - it's straight
16250 * and short:
16251 */
16252 ENABLE_INTERRUPTS(CLBR_NONE)
16253 - SAVE_ARGS 8,0
16254 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
16255 movq %rcx,RIP-ARGOFFSET(%rsp)
16256 CFI_REL_OFFSET rip,RIP-ARGOFFSET
16257 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16258 + GET_THREAD_INFO(%rcx)
16259 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
16260 jnz tracesys
16261 system_call_fastpath:
16262 #if __SYSCALL_MASK == ~0
16263 @@ -527,7 +811,7 @@ system_call_fastpath:
16264 cmpl $__NR_syscall_max,%eax
16265 #endif
16266 ja badsys
16267 - movq %r10,%rcx
16268 + movq R10-ARGOFFSET(%rsp),%rcx
16269 call *sys_call_table(,%rax,8) # XXX: rip relative
16270 movq %rax,RAX-ARGOFFSET(%rsp)
16271 /*
16272 @@ -541,10 +825,13 @@ sysret_check:
16273 LOCKDEP_SYS_EXIT
16274 DISABLE_INTERRUPTS(CLBR_NONE)
16275 TRACE_IRQS_OFF
16276 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
16277 + GET_THREAD_INFO(%rcx)
16278 + movl TI_flags(%rcx),%edx
16279 andl %edi,%edx
16280 jnz sysret_careful
16281 CFI_REMEMBER_STATE
16282 + pax_exit_kernel_user
16283 + pax_erase_kstack
16284 /*
16285 * sysretq will re-enable interrupts:
16286 */
16287 @@ -596,14 +883,18 @@ badsys:
16288 * jump back to the normal fast path.
16289 */
16290 auditsys:
16291 - movq %r10,%r9 /* 6th arg: 4th syscall arg */
16292 + movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
16293 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
16294 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
16295 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
16296 movq %rax,%rsi /* 2nd arg: syscall number */
16297 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
16298 call __audit_syscall_entry
16299 +
16300 + pax_erase_kstack
16301 +
16302 LOAD_ARGS 0 /* reload call-clobbered registers */
16303 + pax_set_fptr_mask
16304 jmp system_call_fastpath
16305
16306 /*
16307 @@ -624,7 +915,7 @@ sysret_audit:
16308 /* Do syscall tracing */
16309 tracesys:
16310 #ifdef CONFIG_AUDITSYSCALL
16311 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16312 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
16313 jz auditsys
16314 #endif
16315 SAVE_REST
16316 @@ -632,12 +923,16 @@ tracesys:
16317 FIXUP_TOP_OF_STACK %rdi
16318 movq %rsp,%rdi
16319 call syscall_trace_enter
16320 +
16321 + pax_erase_kstack
16322 +
16323 /*
16324 * Reload arg registers from stack in case ptrace changed them.
16325 * We don't reload %rax because syscall_trace_enter() returned
16326 * the value it wants us to use in the table lookup.
16327 */
16328 LOAD_ARGS ARGOFFSET, 1
16329 + pax_set_fptr_mask
16330 RESTORE_REST
16331 #if __SYSCALL_MASK == ~0
16332 cmpq $__NR_syscall_max,%rax
16333 @@ -646,7 +941,7 @@ tracesys:
16334 cmpl $__NR_syscall_max,%eax
16335 #endif
16336 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
16337 - movq %r10,%rcx /* fixup for C */
16338 + movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
16339 call *sys_call_table(,%rax,8)
16340 movq %rax,RAX-ARGOFFSET(%rsp)
16341 /* Use IRET because user could have changed frame */
16342 @@ -667,7 +962,9 @@ GLOBAL(int_with_check)
16343 andl %edi,%edx
16344 jnz int_careful
16345 andl $~TS_COMPAT,TI_status(%rcx)
16346 - jmp retint_swapgs
16347 + pax_exit_kernel_user
16348 + pax_erase_kstack
16349 + jmp retint_swapgs_pax
16350
16351 /* Either reschedule or signal or syscall exit tracking needed. */
16352 /* First do a reschedule test. */
16353 @@ -713,7 +1010,7 @@ int_restore_rest:
16354 TRACE_IRQS_OFF
16355 jmp int_with_check
16356 CFI_ENDPROC
16357 -END(system_call)
16358 +ENDPROC(system_call)
16359
16360 /*
16361 * Certain special system calls that need to save a complete full stack frame.
16362 @@ -729,7 +1026,7 @@ ENTRY(\label)
16363 call \func
16364 jmp ptregscall_common
16365 CFI_ENDPROC
16366 -END(\label)
16367 +ENDPROC(\label)
16368 .endm
16369
16370 PTREGSCALL stub_clone, sys_clone, %r8
16371 @@ -747,9 +1044,10 @@ ENTRY(ptregscall_common)
16372 movq_cfi_restore R12+8, r12
16373 movq_cfi_restore RBP+8, rbp
16374 movq_cfi_restore RBX+8, rbx
16375 + pax_force_retaddr
16376 ret $REST_SKIP /* pop extended registers */
16377 CFI_ENDPROC
16378 -END(ptregscall_common)
16379 +ENDPROC(ptregscall_common)
16380
16381 ENTRY(stub_execve)
16382 CFI_STARTPROC
16383 @@ -764,7 +1062,7 @@ ENTRY(stub_execve)
16384 RESTORE_REST
16385 jmp int_ret_from_sys_call
16386 CFI_ENDPROC
16387 -END(stub_execve)
16388 +ENDPROC(stub_execve)
16389
16390 /*
16391 * sigreturn is special because it needs to restore all registers on return.
16392 @@ -782,7 +1080,7 @@ ENTRY(stub_rt_sigreturn)
16393 RESTORE_REST
16394 jmp int_ret_from_sys_call
16395 CFI_ENDPROC
16396 -END(stub_rt_sigreturn)
16397 +ENDPROC(stub_rt_sigreturn)
16398
16399 #ifdef CONFIG_X86_X32_ABI
16400 PTREGSCALL stub_x32_sigaltstack, sys32_sigaltstack, %rdx
16401 @@ -851,7 +1149,7 @@ vector=vector+1
16402 2: jmp common_interrupt
16403 .endr
16404 CFI_ENDPROC
16405 -END(irq_entries_start)
16406 +ENDPROC(irq_entries_start)
16407
16408 .previous
16409 END(interrupt)
16410 @@ -871,6 +1169,16 @@ END(interrupt)
16411 subq $ORIG_RAX-RBP, %rsp
16412 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
16413 SAVE_ARGS_IRQ
16414 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16415 + testb $3, CS(%rdi)
16416 + jnz 1f
16417 + pax_enter_kernel
16418 + jmp 2f
16419 +1: pax_enter_kernel_user
16420 +2:
16421 +#else
16422 + pax_enter_kernel
16423 +#endif
16424 call \func
16425 .endm
16426
16427 @@ -902,7 +1210,7 @@ ret_from_intr:
16428
16429 exit_intr:
16430 GET_THREAD_INFO(%rcx)
16431 - testl $3,CS-ARGOFFSET(%rsp)
16432 + testb $3,CS-ARGOFFSET(%rsp)
16433 je retint_kernel
16434
16435 /* Interrupt came from user space */
16436 @@ -924,12 +1232,16 @@ retint_swapgs: /* return to user-space */
16437 * The iretq could re-enable interrupts:
16438 */
16439 DISABLE_INTERRUPTS(CLBR_ANY)
16440 + pax_exit_kernel_user
16441 +retint_swapgs_pax:
16442 TRACE_IRQS_IRETQ
16443 SWAPGS
16444 jmp restore_args
16445
16446 retint_restore_args: /* return to kernel space */
16447 DISABLE_INTERRUPTS(CLBR_ANY)
16448 + pax_exit_kernel
16449 + pax_force_retaddr (RIP-ARGOFFSET)
16450 /*
16451 * The iretq could re-enable interrupts:
16452 */
16453 @@ -1012,7 +1324,7 @@ ENTRY(retint_kernel)
16454 #endif
16455
16456 CFI_ENDPROC
16457 -END(common_interrupt)
16458 +ENDPROC(common_interrupt)
16459 /*
16460 * End of kprobes section
16461 */
16462 @@ -1029,7 +1341,7 @@ ENTRY(\sym)
16463 interrupt \do_sym
16464 jmp ret_from_intr
16465 CFI_ENDPROC
16466 -END(\sym)
16467 +ENDPROC(\sym)
16468 .endm
16469
16470 #ifdef CONFIG_SMP
16471 @@ -1084,12 +1396,22 @@ ENTRY(\sym)
16472 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16473 call error_entry
16474 DEFAULT_FRAME 0
16475 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16476 + testb $3, CS(%rsp)
16477 + jnz 1f
16478 + pax_enter_kernel
16479 + jmp 2f
16480 +1: pax_enter_kernel_user
16481 +2:
16482 +#else
16483 + pax_enter_kernel
16484 +#endif
16485 movq %rsp,%rdi /* pt_regs pointer */
16486 xorl %esi,%esi /* no error code */
16487 call \do_sym
16488 jmp error_exit /* %ebx: no swapgs flag */
16489 CFI_ENDPROC
16490 -END(\sym)
16491 +ENDPROC(\sym)
16492 .endm
16493
16494 .macro paranoidzeroentry sym do_sym
16495 @@ -1101,15 +1423,25 @@ ENTRY(\sym)
16496 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16497 call save_paranoid
16498 TRACE_IRQS_OFF
16499 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16500 + testb $3, CS(%rsp)
16501 + jnz 1f
16502 + pax_enter_kernel
16503 + jmp 2f
16504 +1: pax_enter_kernel_user
16505 +2:
16506 +#else
16507 + pax_enter_kernel
16508 +#endif
16509 movq %rsp,%rdi /* pt_regs pointer */
16510 xorl %esi,%esi /* no error code */
16511 call \do_sym
16512 jmp paranoid_exit /* %ebx: no swapgs flag */
16513 CFI_ENDPROC
16514 -END(\sym)
16515 +ENDPROC(\sym)
16516 .endm
16517
16518 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
16519 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
16520 .macro paranoidzeroentry_ist sym do_sym ist
16521 ENTRY(\sym)
16522 INTR_FRAME
16523 @@ -1119,14 +1451,30 @@ ENTRY(\sym)
16524 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16525 call save_paranoid
16526 TRACE_IRQS_OFF_DEBUG
16527 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16528 + testb $3, CS(%rsp)
16529 + jnz 1f
16530 + pax_enter_kernel
16531 + jmp 2f
16532 +1: pax_enter_kernel_user
16533 +2:
16534 +#else
16535 + pax_enter_kernel
16536 +#endif
16537 movq %rsp,%rdi /* pt_regs pointer */
16538 xorl %esi,%esi /* no error code */
16539 +#ifdef CONFIG_SMP
16540 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
16541 + lea init_tss(%r12), %r12
16542 +#else
16543 + lea init_tss(%rip), %r12
16544 +#endif
16545 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16546 call \do_sym
16547 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16548 jmp paranoid_exit /* %ebx: no swapgs flag */
16549 CFI_ENDPROC
16550 -END(\sym)
16551 +ENDPROC(\sym)
16552 .endm
16553
16554 .macro errorentry sym do_sym
16555 @@ -1137,13 +1485,23 @@ ENTRY(\sym)
16556 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16557 call error_entry
16558 DEFAULT_FRAME 0
16559 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16560 + testb $3, CS(%rsp)
16561 + jnz 1f
16562 + pax_enter_kernel
16563 + jmp 2f
16564 +1: pax_enter_kernel_user
16565 +2:
16566 +#else
16567 + pax_enter_kernel
16568 +#endif
16569 movq %rsp,%rdi /* pt_regs pointer */
16570 movq ORIG_RAX(%rsp),%rsi /* get error code */
16571 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16572 call \do_sym
16573 jmp error_exit /* %ebx: no swapgs flag */
16574 CFI_ENDPROC
16575 -END(\sym)
16576 +ENDPROC(\sym)
16577 .endm
16578
16579 /* error code is on the stack already */
16580 @@ -1156,13 +1514,23 @@ ENTRY(\sym)
16581 call save_paranoid
16582 DEFAULT_FRAME 0
16583 TRACE_IRQS_OFF
16584 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16585 + testb $3, CS(%rsp)
16586 + jnz 1f
16587 + pax_enter_kernel
16588 + jmp 2f
16589 +1: pax_enter_kernel_user
16590 +2:
16591 +#else
16592 + pax_enter_kernel
16593 +#endif
16594 movq %rsp,%rdi /* pt_regs pointer */
16595 movq ORIG_RAX(%rsp),%rsi /* get error code */
16596 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16597 call \do_sym
16598 jmp paranoid_exit /* %ebx: no swapgs flag */
16599 CFI_ENDPROC
16600 -END(\sym)
16601 +ENDPROC(\sym)
16602 .endm
16603
16604 zeroentry divide_error do_divide_error
16605 @@ -1192,9 +1560,10 @@ gs_change:
16606 2: mfence /* workaround */
16607 SWAPGS
16608 popfq_cfi
16609 + pax_force_retaddr
16610 ret
16611 CFI_ENDPROC
16612 -END(native_load_gs_index)
16613 +ENDPROC(native_load_gs_index)
16614
16615 _ASM_EXTABLE(gs_change,bad_gs)
16616 .section .fixup,"ax"
16617 @@ -1213,13 +1582,14 @@ ENTRY(kernel_thread_helper)
16618 * Here we are in the child and the registers are set as they were
16619 * at kernel_thread() invocation in the parent.
16620 */
16621 + pax_force_fptr %rsi
16622 call *%rsi
16623 # exit
16624 mov %eax, %edi
16625 call do_exit
16626 ud2 # padding for call trace
16627 CFI_ENDPROC
16628 -END(kernel_thread_helper)
16629 +ENDPROC(kernel_thread_helper)
16630
16631 /*
16632 * execve(). This function needs to use IRET, not SYSRET, to set up all state properly.
16633 @@ -1246,11 +1616,11 @@ ENTRY(kernel_execve)
16634 RESTORE_REST
16635 testq %rax,%rax
16636 je int_ret_from_sys_call
16637 - RESTORE_ARGS
16638 UNFAKE_STACK_FRAME
16639 + pax_force_retaddr
16640 ret
16641 CFI_ENDPROC
16642 -END(kernel_execve)
16643 +ENDPROC(kernel_execve)
16644
16645 /* Call softirq on interrupt stack. Interrupts are off. */
16646 ENTRY(call_softirq)
16647 @@ -1268,9 +1638,10 @@ ENTRY(call_softirq)
16648 CFI_DEF_CFA_REGISTER rsp
16649 CFI_ADJUST_CFA_OFFSET -8
16650 decl PER_CPU_VAR(irq_count)
16651 + pax_force_retaddr
16652 ret
16653 CFI_ENDPROC
16654 -END(call_softirq)
16655 +ENDPROC(call_softirq)
16656
16657 #ifdef CONFIG_XEN
16658 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
16659 @@ -1308,7 +1679,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
16660 decl PER_CPU_VAR(irq_count)
16661 jmp error_exit
16662 CFI_ENDPROC
16663 -END(xen_do_hypervisor_callback)
16664 +ENDPROC(xen_do_hypervisor_callback)
16665
16666 /*
16667 * Hypervisor uses this for application faults while it executes.
16668 @@ -1367,7 +1738,7 @@ ENTRY(xen_failsafe_callback)
16669 SAVE_ALL
16670 jmp error_exit
16671 CFI_ENDPROC
16672 -END(xen_failsafe_callback)
16673 +ENDPROC(xen_failsafe_callback)
16674
16675 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
16676 xen_hvm_callback_vector xen_evtchn_do_upcall
16677 @@ -1416,16 +1787,31 @@ ENTRY(paranoid_exit)
16678 TRACE_IRQS_OFF_DEBUG
16679 testl %ebx,%ebx /* swapgs needed? */
16680 jnz paranoid_restore
16681 - testl $3,CS(%rsp)
16682 + testb $3,CS(%rsp)
16683 jnz paranoid_userspace
16684 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16685 + pax_exit_kernel
16686 + TRACE_IRQS_IRETQ 0
16687 + SWAPGS_UNSAFE_STACK
16688 + RESTORE_ALL 8
16689 + pax_force_retaddr_bts
16690 + jmp irq_return
16691 +#endif
16692 paranoid_swapgs:
16693 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16694 + pax_exit_kernel_user
16695 +#else
16696 + pax_exit_kernel
16697 +#endif
16698 TRACE_IRQS_IRETQ 0
16699 SWAPGS_UNSAFE_STACK
16700 RESTORE_ALL 8
16701 jmp irq_return
16702 paranoid_restore:
16703 + pax_exit_kernel
16704 TRACE_IRQS_IRETQ_DEBUG 0
16705 RESTORE_ALL 8
16706 + pax_force_retaddr_bts
16707 jmp irq_return
16708 paranoid_userspace:
16709 GET_THREAD_INFO(%rcx)
16710 @@ -1454,7 +1840,7 @@ paranoid_schedule:
16711 TRACE_IRQS_OFF
16712 jmp paranoid_userspace
16713 CFI_ENDPROC
16714 -END(paranoid_exit)
16715 +ENDPROC(paranoid_exit)
16716
16717 /*
16718 * Exception entry point. This expects an error code/orig_rax on the stack.
16719 @@ -1481,12 +1867,13 @@ ENTRY(error_entry)
16720 movq_cfi r14, R14+8
16721 movq_cfi r15, R15+8
16722 xorl %ebx,%ebx
16723 - testl $3,CS+8(%rsp)
16724 + testb $3,CS+8(%rsp)
16725 je error_kernelspace
16726 error_swapgs:
16727 SWAPGS
16728 error_sti:
16729 TRACE_IRQS_OFF
16730 + pax_force_retaddr_bts
16731 ret
16732
16733 /*
16734 @@ -1513,7 +1900,7 @@ bstep_iret:
16735 movq %rcx,RIP+8(%rsp)
16736 jmp error_swapgs
16737 CFI_ENDPROC
16738 -END(error_entry)
16739 +ENDPROC(error_entry)
16740
16741
16742 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
16743 @@ -1533,7 +1920,7 @@ ENTRY(error_exit)
16744 jnz retint_careful
16745 jmp retint_swapgs
16746 CFI_ENDPROC
16747 -END(error_exit)
16748 +ENDPROC(error_exit)
16749
16750 /*
16751 * Test if a given stack is an NMI stack or not.
16752 @@ -1591,9 +1978,11 @@ ENTRY(nmi)
16753 * If %cs was not the kernel segment, then the NMI triggered in user
16754 * space, which means it is definitely not nested.
16755 */
16756 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
16757 + je 1f
16758 cmpl $__KERNEL_CS, 16(%rsp)
16759 jne first_nmi
16760 -
16761 +1:
16762 /*
16763 * Check the special variable on the stack to see if NMIs are
16764 * executing.
16765 @@ -1752,6 +2141,17 @@ end_repeat_nmi:
16766 */
16767 movq %cr2, %r12
16768
16769 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16770 + testb $3, CS(%rsp)
16771 + jnz 1f
16772 + pax_enter_kernel
16773 + jmp 2f
16774 +1: pax_enter_kernel_user
16775 +2:
16776 +#else
16777 + pax_enter_kernel
16778 +#endif
16779 +
16780 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
16781 movq %rsp,%rdi
16782 movq $-1,%rsi
16783 @@ -1767,21 +2167,32 @@ end_repeat_nmi:
16784 testl %ebx,%ebx /* swapgs needed? */
16785 jnz nmi_restore
16786 nmi_swapgs:
16787 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16788 + pax_exit_kernel_user
16789 +#else
16790 + pax_exit_kernel
16791 +#endif
16792 SWAPGS_UNSAFE_STACK
16793 + RESTORE_ALL 8
16794 + /* Clear the NMI executing stack variable */
16795 + movq $0, 10*8(%rsp)
16796 + jmp irq_return
16797 nmi_restore:
16798 + pax_exit_kernel
16799 RESTORE_ALL 8
16800 + pax_force_retaddr_bts
16801 /* Clear the NMI executing stack variable */
16802 movq $0, 10*8(%rsp)
16803 jmp irq_return
16804 CFI_ENDPROC
16805 -END(nmi)
16806 +ENDPROC(nmi)
16807
16808 ENTRY(ignore_sysret)
16809 CFI_STARTPROC
16810 mov $-ENOSYS,%eax
16811 sysret
16812 CFI_ENDPROC
16813 -END(ignore_sysret)
16814 +ENDPROC(ignore_sysret)
16815
16816 /*
16817 * End of kprobes section
16818 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
16819 index c3a7cb4..3ad00dc 100644
16820 --- a/arch/x86/kernel/ftrace.c
16821 +++ b/arch/x86/kernel/ftrace.c
16822 @@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
16823 {
16824 unsigned char replaced[MCOUNT_INSN_SIZE];
16825
16826 + ip = ktla_ktva(ip);
16827 +
16828 /*
16829 * Note: Due to modules and __init, code can
16830 * disappear and change, we need to protect against faulting
16831 @@ -212,7 +214,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
16832 unsigned char old[MCOUNT_INSN_SIZE], *new;
16833 int ret;
16834
16835 - memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
16836 + memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
16837 new = ftrace_call_replace(ip, (unsigned long)func);
16838
16839 /* See comment above by declaration of modifying_ftrace_code */
16840 @@ -605,6 +607,8 @@ static int ftrace_mod_jmp(unsigned long ip,
16841 {
16842 unsigned char code[MCOUNT_INSN_SIZE];
16843
16844 + ip = ktla_ktva(ip);
16845 +
16846 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
16847 return -EFAULT;
16848
16849 diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
16850 index c18f59d..9c0c9f6 100644
16851 --- a/arch/x86/kernel/head32.c
16852 +++ b/arch/x86/kernel/head32.c
16853 @@ -18,6 +18,7 @@
16854 #include <asm/io_apic.h>
16855 #include <asm/bios_ebda.h>
16856 #include <asm/tlbflush.h>
16857 +#include <asm/boot.h>
16858
16859 static void __init i386_default_early_setup(void)
16860 {
16861 @@ -30,8 +31,7 @@ static void __init i386_default_early_setup(void)
16862
16863 void __init i386_start_kernel(void)
16864 {
16865 - memblock_reserve(__pa_symbol(&_text),
16866 - __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
16867 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
16868
16869 #ifdef CONFIG_BLK_DEV_INITRD
16870 /* Reserve INITRD */
16871 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
16872 index d42ab17..87b9555 100644
16873 --- a/arch/x86/kernel/head_32.S
16874 +++ b/arch/x86/kernel/head_32.S
16875 @@ -26,6 +26,12 @@
16876 /* Physical address */
16877 #define pa(X) ((X) - __PAGE_OFFSET)
16878
16879 +#ifdef CONFIG_PAX_KERNEXEC
16880 +#define ta(X) (X)
16881 +#else
16882 +#define ta(X) ((X) - __PAGE_OFFSET)
16883 +#endif
16884 +
16885 /*
16886 * References to members of the new_cpu_data structure.
16887 */
16888 @@ -55,11 +61,7 @@
16889 * and small than max_low_pfn, otherwise will waste some page table entries
16890 */
16891
16892 -#if PTRS_PER_PMD > 1
16893 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
16894 -#else
16895 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
16896 -#endif
16897 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
16898
16899 /* Number of possible pages in the lowmem region */
16900 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
16901 @@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
16902 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16903
16904 /*
16905 + * Real beginning of normal "text" segment
16906 + */
16907 +ENTRY(stext)
16908 +ENTRY(_stext)
16909 +
16910 +/*
16911 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
16912 * %esi points to the real-mode code as a 32-bit pointer.
16913 * CS and DS must be 4 GB flat segments, but we don't depend on
16914 @@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16915 * can.
16916 */
16917 __HEAD
16918 +
16919 +#ifdef CONFIG_PAX_KERNEXEC
16920 + jmp startup_32
16921 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
16922 +.fill PAGE_SIZE-5,1,0xcc
16923 +#endif
16924 +
16925 ENTRY(startup_32)
16926 movl pa(stack_start),%ecx
16927
16928 @@ -106,6 +121,59 @@ ENTRY(startup_32)
16929 2:
16930 leal -__PAGE_OFFSET(%ecx),%esp
16931
16932 +#ifdef CONFIG_SMP
16933 + movl $pa(cpu_gdt_table),%edi
16934 + movl $__per_cpu_load,%eax
16935 + movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
16936 + rorl $16,%eax
16937 + movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
16938 + movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
16939 + movl $__per_cpu_end - 1,%eax
16940 + subl $__per_cpu_start,%eax
16941 + movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
16942 +#endif
16943 +
16944 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16945 + movl $NR_CPUS,%ecx
16946 + movl $pa(cpu_gdt_table),%edi
16947 +1:
16948 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
16949 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
16950 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
16951 + addl $PAGE_SIZE_asm,%edi
16952 + loop 1b
16953 +#endif
16954 +
16955 +#ifdef CONFIG_PAX_KERNEXEC
16956 + movl $pa(boot_gdt),%edi
16957 + movl $__LOAD_PHYSICAL_ADDR,%eax
16958 + movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
16959 + rorl $16,%eax
16960 + movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
16961 + movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
16962 + rorl $16,%eax
16963 +
16964 + ljmp $(__BOOT_CS),$1f
16965 +1:
16966 +
16967 + movl $NR_CPUS,%ecx
16968 + movl $pa(cpu_gdt_table),%edi
16969 + addl $__PAGE_OFFSET,%eax
16970 +1:
16971 + movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
16972 + movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
16973 + movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
16974 + movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
16975 + rorl $16,%eax
16976 + movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
16977 + movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
16978 + movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
16979 + movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
16980 + rorl $16,%eax
16981 + addl $PAGE_SIZE_asm,%edi
16982 + loop 1b
16983 +#endif
16984 +
16985 /*
16986 * Clear BSS first so that there are no surprises...
16987 */
16988 @@ -196,8 +264,11 @@ ENTRY(startup_32)
16989 movl %eax, pa(max_pfn_mapped)
16990
16991 /* Do early initialization of the fixmap area */
16992 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16993 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
16994 +#ifdef CONFIG_COMPAT_VDSO
16995 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
16996 +#else
16997 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
16998 +#endif
16999 #else /* Not PAE */
17000
17001 page_pde_offset = (__PAGE_OFFSET >> 20);
17002 @@ -227,8 +298,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
17003 movl %eax, pa(max_pfn_mapped)
17004
17005 /* Do early initialization of the fixmap area */
17006 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
17007 - movl %eax,pa(initial_page_table+0xffc)
17008 +#ifdef CONFIG_COMPAT_VDSO
17009 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
17010 +#else
17011 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
17012 +#endif
17013 #endif
17014
17015 #ifdef CONFIG_PARAVIRT
17016 @@ -242,9 +316,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
17017 cmpl $num_subarch_entries, %eax
17018 jae bad_subarch
17019
17020 - movl pa(subarch_entries)(,%eax,4), %eax
17021 - subl $__PAGE_OFFSET, %eax
17022 - jmp *%eax
17023 + jmp *pa(subarch_entries)(,%eax,4)
17024
17025 bad_subarch:
17026 WEAK(lguest_entry)
17027 @@ -256,10 +328,10 @@ WEAK(xen_entry)
17028 __INITDATA
17029
17030 subarch_entries:
17031 - .long default_entry /* normal x86/PC */
17032 - .long lguest_entry /* lguest hypervisor */
17033 - .long xen_entry /* Xen hypervisor */
17034 - .long default_entry /* Moorestown MID */
17035 + .long ta(default_entry) /* normal x86/PC */
17036 + .long ta(lguest_entry) /* lguest hypervisor */
17037 + .long ta(xen_entry) /* Xen hypervisor */
17038 + .long ta(default_entry) /* Moorestown MID */
17039 num_subarch_entries = (. - subarch_entries) / 4
17040 .previous
17041 #else
17042 @@ -310,6 +382,7 @@ default_entry:
17043 orl %edx,%eax
17044 movl %eax,%cr4
17045
17046 +#ifdef CONFIG_X86_PAE
17047 testb $X86_CR4_PAE, %al # check if PAE is enabled
17048 jz 6f
17049
17050 @@ -338,6 +411,9 @@ default_entry:
17051 /* Make changes effective */
17052 wrmsr
17053
17054 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
17055 +#endif
17056 +
17057 6:
17058
17059 /*
17060 @@ -436,14 +512,20 @@ is386: movl $2,%ecx # set MP
17061 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
17062 movl %eax,%ss # after changing gdt.
17063
17064 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
17065 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
17066 movl %eax,%ds
17067 movl %eax,%es
17068
17069 movl $(__KERNEL_PERCPU), %eax
17070 movl %eax,%fs # set this cpu's percpu
17071
17072 +#ifdef CONFIG_CC_STACKPROTECTOR
17073 movl $(__KERNEL_STACK_CANARY),%eax
17074 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
17075 + movl $(__USER_DS),%eax
17076 +#else
17077 + xorl %eax,%eax
17078 +#endif
17079 movl %eax,%gs
17080
17081 xorl %eax,%eax # Clear LDT
17082 @@ -520,8 +602,11 @@ setup_once:
17083 * relocation. Manually set base address in stack canary
17084 * segment descriptor.
17085 */
17086 - movl $gdt_page,%eax
17087 + movl $cpu_gdt_table,%eax
17088 movl $stack_canary,%ecx
17089 +#ifdef CONFIG_SMP
17090 + addl $__per_cpu_load,%ecx
17091 +#endif
17092 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
17093 shrl $16, %ecx
17094 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
17095 @@ -552,7 +637,7 @@ ENDPROC(early_idt_handlers)
17096 /* This is global to keep gas from relaxing the jumps */
17097 ENTRY(early_idt_handler)
17098 cld
17099 - cmpl $2,%ss:early_recursion_flag
17100 + cmpl $1,%ss:early_recursion_flag
17101 je hlt_loop
17102 incl %ss:early_recursion_flag
17103
17104 @@ -590,8 +675,8 @@ ENTRY(early_idt_handler)
17105 pushl (20+6*4)(%esp) /* trapno */
17106 pushl $fault_msg
17107 call printk
17108 -#endif
17109 call dump_stack
17110 +#endif
17111 hlt_loop:
17112 hlt
17113 jmp hlt_loop
17114 @@ -610,8 +695,11 @@ ENDPROC(early_idt_handler)
17115 /* This is the default interrupt "handler" :-) */
17116 ALIGN
17117 ignore_int:
17118 - cld
17119 #ifdef CONFIG_PRINTK
17120 + cmpl $2,%ss:early_recursion_flag
17121 + je hlt_loop
17122 + incl %ss:early_recursion_flag
17123 + cld
17124 pushl %eax
17125 pushl %ecx
17126 pushl %edx
17127 @@ -620,9 +708,6 @@ ignore_int:
17128 movl $(__KERNEL_DS),%eax
17129 movl %eax,%ds
17130 movl %eax,%es
17131 - cmpl $2,early_recursion_flag
17132 - je hlt_loop
17133 - incl early_recursion_flag
17134 pushl 16(%esp)
17135 pushl 24(%esp)
17136 pushl 32(%esp)
17137 @@ -656,29 +741,43 @@ ENTRY(setup_once_ref)
17138 /*
17139 * BSS section
17140 */
17141 -__PAGE_ALIGNED_BSS
17142 - .align PAGE_SIZE
17143 #ifdef CONFIG_X86_PAE
17144 +.section .initial_pg_pmd,"a",@progbits
17145 initial_pg_pmd:
17146 .fill 1024*KPMDS,4,0
17147 #else
17148 +.section .initial_page_table,"a",@progbits
17149 ENTRY(initial_page_table)
17150 .fill 1024,4,0
17151 #endif
17152 +.section .initial_pg_fixmap,"a",@progbits
17153 initial_pg_fixmap:
17154 .fill 1024,4,0
17155 +.section .empty_zero_page,"a",@progbits
17156 ENTRY(empty_zero_page)
17157 .fill 4096,1,0
17158 +.section .swapper_pg_dir,"a",@progbits
17159 ENTRY(swapper_pg_dir)
17160 +#ifdef CONFIG_X86_PAE
17161 + .fill 4,8,0
17162 +#else
17163 .fill 1024,4,0
17164 +#endif
17165 +
17166 +/*
17167 + * The IDT has to be page-aligned to simplify the Pentium
17168 + * F0 0F bug workaround.. We have a special link segment
17169 + * for this.
17170 + */
17171 +.section .idt,"a",@progbits
17172 +ENTRY(idt_table)
17173 + .fill 256,8,0
17174
17175 /*
17176 * This starts the data section.
17177 */
17178 #ifdef CONFIG_X86_PAE
17179 -__PAGE_ALIGNED_DATA
17180 - /* Page-aligned for the benefit of paravirt? */
17181 - .align PAGE_SIZE
17182 +.section .initial_page_table,"a",@progbits
17183 ENTRY(initial_page_table)
17184 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
17185 # if KPMDS == 3
17186 @@ -697,12 +796,20 @@ ENTRY(initial_page_table)
17187 # error "Kernel PMDs should be 1, 2 or 3"
17188 # endif
17189 .align PAGE_SIZE /* needs to be page-sized too */
17190 +
17191 +#ifdef CONFIG_PAX_PER_CPU_PGD
17192 +ENTRY(cpu_pgd)
17193 + .rept NR_CPUS
17194 + .fill 4,8,0
17195 + .endr
17196 +#endif
17197 +
17198 #endif
17199
17200 .data
17201 .balign 4
17202 ENTRY(stack_start)
17203 - .long init_thread_union+THREAD_SIZE
17204 + .long init_thread_union+THREAD_SIZE-8
17205
17206 __INITRODATA
17207 int_msg:
17208 @@ -730,7 +837,7 @@ fault_msg:
17209 * segment size, and 32-bit linear address value:
17210 */
17211
17212 - .data
17213 +.section .rodata,"a",@progbits
17214 .globl boot_gdt_descr
17215 .globl idt_descr
17216
17217 @@ -739,7 +846,7 @@ fault_msg:
17218 .word 0 # 32 bit align gdt_desc.address
17219 boot_gdt_descr:
17220 .word __BOOT_DS+7
17221 - .long boot_gdt - __PAGE_OFFSET
17222 + .long pa(boot_gdt)
17223
17224 .word 0 # 32-bit align idt_desc.address
17225 idt_descr:
17226 @@ -750,7 +857,7 @@ idt_descr:
17227 .word 0 # 32 bit align gdt_desc.address
17228 ENTRY(early_gdt_descr)
17229 .word GDT_ENTRIES*8-1
17230 - .long gdt_page /* Overwritten for secondary CPUs */
17231 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
17232
17233 /*
17234 * The boot_gdt must mirror the equivalent in setup.S and is
17235 @@ -759,5 +866,65 @@ ENTRY(early_gdt_descr)
17236 .align L1_CACHE_BYTES
17237 ENTRY(boot_gdt)
17238 .fill GDT_ENTRY_BOOT_CS,8,0
17239 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
17240 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
17241 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
17242 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
17243 +
17244 + .align PAGE_SIZE_asm
17245 +ENTRY(cpu_gdt_table)
17246 + .rept NR_CPUS
17247 + .quad 0x0000000000000000 /* NULL descriptor */
17248 + .quad 0x0000000000000000 /* 0x0b reserved */
17249 + .quad 0x0000000000000000 /* 0x13 reserved */
17250 + .quad 0x0000000000000000 /* 0x1b reserved */
17251 +
17252 +#ifdef CONFIG_PAX_KERNEXEC
17253 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
17254 +#else
17255 + .quad 0x0000000000000000 /* 0x20 unused */
17256 +#endif
17257 +
17258 + .quad 0x0000000000000000 /* 0x28 unused */
17259 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
17260 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
17261 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
17262 + .quad 0x0000000000000000 /* 0x4b reserved */
17263 + .quad 0x0000000000000000 /* 0x53 reserved */
17264 + .quad 0x0000000000000000 /* 0x5b reserved */
17265 +
17266 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
17267 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
17268 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
17269 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
17270 +
17271 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
17272 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
17273 +
17274 + /*
17275 + * Segments used for calling PnP BIOS have byte granularity.
17276 + * The code segments and data segments have fixed 64k limits,
17277 + * the transfer segment sizes are set at run time.
17278 + */
17279 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
17280 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
17281 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
17282 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
17283 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
17284 +
17285 + /*
17286 + * The APM segments have byte granularity and their bases
17287 + * are set at run time. All have 64k limits.
17288 + */
17289 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
17290 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
17291 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
17292 +
17293 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
17294 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
17295 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
17296 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
17297 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
17298 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
17299 +
17300 + /* Be sure this is zeroed to avoid false validations in Xen */
17301 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
17302 + .endr
17303 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
17304 index 94bf9cc..400455a 100644
17305 --- a/arch/x86/kernel/head_64.S
17306 +++ b/arch/x86/kernel/head_64.S
17307 @@ -20,6 +20,8 @@
17308 #include <asm/processor-flags.h>
17309 #include <asm/percpu.h>
17310 #include <asm/nops.h>
17311 +#include <asm/cpufeature.h>
17312 +#include <asm/alternative-asm.h>
17313
17314 #ifdef CONFIG_PARAVIRT
17315 #include <asm/asm-offsets.h>
17316 @@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
17317 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
17318 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
17319 L3_START_KERNEL = pud_index(__START_KERNEL_map)
17320 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
17321 +L3_VMALLOC_START = pud_index(VMALLOC_START)
17322 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
17323 +L3_VMALLOC_END = pud_index(VMALLOC_END)
17324 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
17325 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
17326
17327 .text
17328 __HEAD
17329 @@ -88,35 +96,23 @@ startup_64:
17330 */
17331 addq %rbp, init_level4_pgt + 0(%rip)
17332 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
17333 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
17334 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
17335 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
17336 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
17337
17338 addq %rbp, level3_ident_pgt + 0(%rip)
17339 +#ifndef CONFIG_XEN
17340 + addq %rbp, level3_ident_pgt + 8(%rip)
17341 +#endif
17342
17343 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
17344 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
17345 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
17346 +
17347 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
17348 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
17349
17350 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
17351 -
17352 - /* Add an Identity mapping if I am above 1G */
17353 - leaq _text(%rip), %rdi
17354 - andq $PMD_PAGE_MASK, %rdi
17355 -
17356 - movq %rdi, %rax
17357 - shrq $PUD_SHIFT, %rax
17358 - andq $(PTRS_PER_PUD - 1), %rax
17359 - jz ident_complete
17360 -
17361 - leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
17362 - leaq level3_ident_pgt(%rip), %rbx
17363 - movq %rdx, 0(%rbx, %rax, 8)
17364 -
17365 - movq %rdi, %rax
17366 - shrq $PMD_SHIFT, %rax
17367 - andq $(PTRS_PER_PMD - 1), %rax
17368 - leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
17369 - leaq level2_spare_pgt(%rip), %rbx
17370 - movq %rdx, 0(%rbx, %rax, 8)
17371 -ident_complete:
17372 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
17373
17374 /*
17375 * Fixup the kernel text+data virtual addresses. Note that
17376 @@ -159,8 +155,8 @@ ENTRY(secondary_startup_64)
17377 * after the boot processor executes this code.
17378 */
17379
17380 - /* Enable PAE mode and PGE */
17381 - movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
17382 + /* Enable PAE mode and PSE/PGE */
17383 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
17384 movq %rax, %cr4
17385
17386 /* Setup early boot stage 4 level pagetables. */
17387 @@ -182,9 +178,17 @@ ENTRY(secondary_startup_64)
17388 movl $MSR_EFER, %ecx
17389 rdmsr
17390 btsl $_EFER_SCE, %eax /* Enable System Call */
17391 - btl $20,%edi /* No Execute supported? */
17392 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
17393 jnc 1f
17394 btsl $_EFER_NX, %eax
17395 + leaq init_level4_pgt(%rip), %rdi
17396 +#ifndef CONFIG_EFI
17397 + btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
17398 +#endif
17399 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
17400 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
17401 + btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
17402 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
17403 1: wrmsr /* Make changes effective */
17404
17405 /* Setup cr0 */
17406 @@ -246,6 +250,7 @@ ENTRY(secondary_startup_64)
17407 * jump. In addition we need to ensure %cs is set so we make this
17408 * a far return.
17409 */
17410 + pax_set_fptr_mask
17411 movq initial_code(%rip),%rax
17412 pushq $0 # fake return address to stop unwinder
17413 pushq $__KERNEL_CS # set correct cs
17414 @@ -268,7 +273,7 @@ ENTRY(secondary_startup_64)
17415 bad_address:
17416 jmp bad_address
17417
17418 - .section ".init.text","ax"
17419 + __INIT
17420 .globl early_idt_handlers
17421 early_idt_handlers:
17422 # 104(%rsp) %rflags
17423 @@ -347,11 +352,15 @@ ENTRY(early_idt_handler)
17424 addq $16,%rsp # drop vector number and error code
17425 decl early_recursion_flag(%rip)
17426 INTERRUPT_RETURN
17427 + .previous
17428
17429 + __INITDATA
17430 .balign 4
17431 early_recursion_flag:
17432 .long 0
17433 + .previous
17434
17435 + .section .rodata,"a",@progbits
17436 #ifdef CONFIG_EARLY_PRINTK
17437 early_idt_msg:
17438 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
17439 @@ -360,6 +369,7 @@ early_idt_ripmsg:
17440 #endif /* CONFIG_EARLY_PRINTK */
17441 .previous
17442
17443 + .section .rodata,"a",@progbits
17444 #define NEXT_PAGE(name) \
17445 .balign PAGE_SIZE; \
17446 ENTRY(name)
17447 @@ -372,7 +382,6 @@ ENTRY(name)
17448 i = i + 1 ; \
17449 .endr
17450
17451 - .data
17452 /*
17453 * This default setting generates an ident mapping at address 0x100000
17454 * and a mapping for the kernel that precisely maps virtual address
17455 @@ -383,13 +392,41 @@ NEXT_PAGE(init_level4_pgt)
17456 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17457 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
17458 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17459 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
17460 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
17461 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
17462 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
17463 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
17464 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17465 .org init_level4_pgt + L4_START_KERNEL*8, 0
17466 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
17467 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
17468
17469 +#ifdef CONFIG_PAX_PER_CPU_PGD
17470 +NEXT_PAGE(cpu_pgd)
17471 + .rept NR_CPUS
17472 + .fill 512,8,0
17473 + .endr
17474 +#endif
17475 +
17476 NEXT_PAGE(level3_ident_pgt)
17477 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17478 +#ifdef CONFIG_XEN
17479 .fill 511,8,0
17480 +#else
17481 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
17482 + .fill 510,8,0
17483 +#endif
17484 +
17485 +NEXT_PAGE(level3_vmalloc_start_pgt)
17486 + .fill 512,8,0
17487 +
17488 +NEXT_PAGE(level3_vmalloc_end_pgt)
17489 + .fill 512,8,0
17490 +
17491 +NEXT_PAGE(level3_vmemmap_pgt)
17492 + .fill L3_VMEMMAP_START,8,0
17493 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17494
17495 NEXT_PAGE(level3_kernel_pgt)
17496 .fill L3_START_KERNEL,8,0
17497 @@ -397,20 +434,23 @@ NEXT_PAGE(level3_kernel_pgt)
17498 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
17499 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17500
17501 +NEXT_PAGE(level2_vmemmap_pgt)
17502 + .fill 512,8,0
17503 +
17504 NEXT_PAGE(level2_fixmap_pgt)
17505 - .fill 506,8,0
17506 - .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17507 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
17508 - .fill 5,8,0
17509 + .fill 507,8,0
17510 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
17511 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
17512 + .fill 4,8,0
17513
17514 -NEXT_PAGE(level1_fixmap_pgt)
17515 +NEXT_PAGE(level1_vsyscall_pgt)
17516 .fill 512,8,0
17517
17518 -NEXT_PAGE(level2_ident_pgt)
17519 - /* Since I easily can, map the first 1G.
17520 + /* Since I easily can, map the first 2G.
17521 * Don't set NX because code runs from these pages.
17522 */
17523 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
17524 +NEXT_PAGE(level2_ident_pgt)
17525 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
17526
17527 NEXT_PAGE(level2_kernel_pgt)
17528 /*
17529 @@ -423,37 +463,59 @@ NEXT_PAGE(level2_kernel_pgt)
17530 * If you want to increase this then increase MODULES_VADDR
17531 * too.)
17532 */
17533 - PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
17534 - KERNEL_IMAGE_SIZE/PMD_SIZE)
17535 -
17536 -NEXT_PAGE(level2_spare_pgt)
17537 - .fill 512, 8, 0
17538 + PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
17539
17540 #undef PMDS
17541 #undef NEXT_PAGE
17542
17543 - .data
17544 + .align PAGE_SIZE
17545 +ENTRY(cpu_gdt_table)
17546 + .rept NR_CPUS
17547 + .quad 0x0000000000000000 /* NULL descriptor */
17548 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
17549 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
17550 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
17551 + .quad 0x00cffb000000ffff /* __USER32_CS */
17552 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
17553 + .quad 0x00affb000000ffff /* __USER_CS */
17554 +
17555 +#ifdef CONFIG_PAX_KERNEXEC
17556 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
17557 +#else
17558 + .quad 0x0 /* unused */
17559 +#endif
17560 +
17561 + .quad 0,0 /* TSS */
17562 + .quad 0,0 /* LDT */
17563 + .quad 0,0,0 /* three TLS descriptors */
17564 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
17565 + /* asm/segment.h:GDT_ENTRIES must match this */
17566 +
17567 + /* zero the remaining page */
17568 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
17569 + .endr
17570 +
17571 .align 16
17572 .globl early_gdt_descr
17573 early_gdt_descr:
17574 .word GDT_ENTRIES*8-1
17575 early_gdt_descr_base:
17576 - .quad INIT_PER_CPU_VAR(gdt_page)
17577 + .quad cpu_gdt_table
17578
17579 ENTRY(phys_base)
17580 /* This must match the first entry in level2_kernel_pgt */
17581 .quad 0x0000000000000000
17582
17583 #include "../../x86/xen/xen-head.S"
17584 -
17585 - .section .bss, "aw", @nobits
17586 +
17587 + .section .rodata,"a",@progbits
17588 .align L1_CACHE_BYTES
17589 ENTRY(idt_table)
17590 - .skip IDT_ENTRIES * 16
17591 + .fill 512,8,0
17592
17593 .align L1_CACHE_BYTES
17594 ENTRY(nmi_idt_table)
17595 - .skip IDT_ENTRIES * 16
17596 + .fill 512,8,0
17597
17598 __PAGE_ALIGNED_BSS
17599 .align PAGE_SIZE
17600 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
17601 index 9c3bd4a..e1d9b35 100644
17602 --- a/arch/x86/kernel/i386_ksyms_32.c
17603 +++ b/arch/x86/kernel/i386_ksyms_32.c
17604 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
17605 EXPORT_SYMBOL(cmpxchg8b_emu);
17606 #endif
17607
17608 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
17609 +
17610 /* Networking helper routines. */
17611 EXPORT_SYMBOL(csum_partial_copy_generic);
17612 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
17613 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
17614
17615 EXPORT_SYMBOL(__get_user_1);
17616 EXPORT_SYMBOL(__get_user_2);
17617 @@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
17618
17619 EXPORT_SYMBOL(csum_partial);
17620 EXPORT_SYMBOL(empty_zero_page);
17621 +
17622 +#ifdef CONFIG_PAX_KERNEXEC
17623 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
17624 +#endif
17625 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
17626 index f250431..54097e7 100644
17627 --- a/arch/x86/kernel/i387.c
17628 +++ b/arch/x86/kernel/i387.c
17629 @@ -59,7 +59,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
17630 static inline bool interrupted_user_mode(void)
17631 {
17632 struct pt_regs *regs = get_irq_regs();
17633 - return regs && user_mode_vm(regs);
17634 + return regs && user_mode(regs);
17635 }
17636
17637 /*
17638 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
17639 index 36d1853..bf25736 100644
17640 --- a/arch/x86/kernel/i8259.c
17641 +++ b/arch/x86/kernel/i8259.c
17642 @@ -209,7 +209,7 @@ spurious_8259A_irq:
17643 "spurious 8259A interrupt: IRQ%d.\n", irq);
17644 spurious_irq_mask |= irqmask;
17645 }
17646 - atomic_inc(&irq_err_count);
17647 + atomic_inc_unchecked(&irq_err_count);
17648 /*
17649 * Theoretically we do not have to handle this IRQ,
17650 * but in Linux this does not cause problems and is
17651 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
17652 index 8c96897..be66bfa 100644
17653 --- a/arch/x86/kernel/ioport.c
17654 +++ b/arch/x86/kernel/ioport.c
17655 @@ -6,6 +6,7 @@
17656 #include <linux/sched.h>
17657 #include <linux/kernel.h>
17658 #include <linux/capability.h>
17659 +#include <linux/security.h>
17660 #include <linux/errno.h>
17661 #include <linux/types.h>
17662 #include <linux/ioport.h>
17663 @@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17664
17665 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
17666 return -EINVAL;
17667 +#ifdef CONFIG_GRKERNSEC_IO
17668 + if (turn_on && grsec_disable_privio) {
17669 + gr_handle_ioperm();
17670 + return -EPERM;
17671 + }
17672 +#endif
17673 if (turn_on && !capable(CAP_SYS_RAWIO))
17674 return -EPERM;
17675
17676 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17677 * because the ->io_bitmap_max value must match the bitmap
17678 * contents:
17679 */
17680 - tss = &per_cpu(init_tss, get_cpu());
17681 + tss = init_tss + get_cpu();
17682
17683 if (turn_on)
17684 bitmap_clear(t->io_bitmap_ptr, from, num);
17685 @@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
17686 return -EINVAL;
17687 /* Trying to gain more privileges? */
17688 if (level > old) {
17689 +#ifdef CONFIG_GRKERNSEC_IO
17690 + if (grsec_disable_privio) {
17691 + gr_handle_iopl();
17692 + return -EPERM;
17693 + }
17694 +#endif
17695 if (!capable(CAP_SYS_RAWIO))
17696 return -EPERM;
17697 }
17698 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
17699 index d44f782..31ab01e 100644
17700 --- a/arch/x86/kernel/irq.c
17701 +++ b/arch/x86/kernel/irq.c
17702 @@ -18,7 +18,7 @@
17703 #include <asm/mce.h>
17704 #include <asm/hw_irq.h>
17705
17706 -atomic_t irq_err_count;
17707 +atomic_unchecked_t irq_err_count;
17708
17709 /* Function pointer for generic interrupt vector handling */
17710 void (*x86_platform_ipi_callback)(void) = NULL;
17711 @@ -121,9 +121,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
17712 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
17713 seq_printf(p, " Machine check polls\n");
17714 #endif
17715 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
17716 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
17717 #if defined(CONFIG_X86_IO_APIC)
17718 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
17719 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
17720 #endif
17721 return 0;
17722 }
17723 @@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
17724
17725 u64 arch_irq_stat(void)
17726 {
17727 - u64 sum = atomic_read(&irq_err_count);
17728 + u64 sum = atomic_read_unchecked(&irq_err_count);
17729
17730 #ifdef CONFIG_X86_IO_APIC
17731 - sum += atomic_read(&irq_mis_count);
17732 + sum += atomic_read_unchecked(&irq_mis_count);
17733 #endif
17734 return sum;
17735 }
17736 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
17737 index 344faf8..355f60d 100644
17738 --- a/arch/x86/kernel/irq_32.c
17739 +++ b/arch/x86/kernel/irq_32.c
17740 @@ -39,7 +39,7 @@ static int check_stack_overflow(void)
17741 __asm__ __volatile__("andl %%esp,%0" :
17742 "=r" (sp) : "0" (THREAD_SIZE - 1));
17743
17744 - return sp < (sizeof(struct thread_info) + STACK_WARN);
17745 + return sp < STACK_WARN;
17746 }
17747
17748 static void print_stack_overflow(void)
17749 @@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
17750 * per-CPU IRQ handling contexts (thread information and stack)
17751 */
17752 union irq_ctx {
17753 - struct thread_info tinfo;
17754 - u32 stack[THREAD_SIZE/sizeof(u32)];
17755 + unsigned long previous_esp;
17756 + u32 stack[THREAD_SIZE/sizeof(u32)];
17757 } __attribute__((aligned(THREAD_SIZE)));
17758
17759 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
17760 @@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
17761 static inline int
17762 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17763 {
17764 - union irq_ctx *curctx, *irqctx;
17765 + union irq_ctx *irqctx;
17766 u32 *isp, arg1, arg2;
17767
17768 - curctx = (union irq_ctx *) current_thread_info();
17769 irqctx = __this_cpu_read(hardirq_ctx);
17770
17771 /*
17772 @@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17773 * handler) we can't do that and just have to keep using the
17774 * current stack (which is the irq stack already after all)
17775 */
17776 - if (unlikely(curctx == irqctx))
17777 + if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
17778 return 0;
17779
17780 /* build the stack frame on the IRQ stack */
17781 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17782 - irqctx->tinfo.task = curctx->tinfo.task;
17783 - irqctx->tinfo.previous_esp = current_stack_pointer;
17784 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17785 + irqctx->previous_esp = current_stack_pointer;
17786
17787 - /* Copy the preempt_count so that the [soft]irq checks work. */
17788 - irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
17789 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17790 + __set_fs(MAKE_MM_SEG(0));
17791 +#endif
17792
17793 if (unlikely(overflow))
17794 call_on_stack(print_stack_overflow, isp);
17795 @@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17796 : "0" (irq), "1" (desc), "2" (isp),
17797 "D" (desc->handle_irq)
17798 : "memory", "cc", "ecx");
17799 +
17800 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17801 + __set_fs(current_thread_info()->addr_limit);
17802 +#endif
17803 +
17804 return 1;
17805 }
17806
17807 @@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17808 */
17809 void __cpuinit irq_ctx_init(int cpu)
17810 {
17811 - union irq_ctx *irqctx;
17812 -
17813 if (per_cpu(hardirq_ctx, cpu))
17814 return;
17815
17816 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17817 - THREADINFO_GFP,
17818 - THREAD_SIZE_ORDER));
17819 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17820 - irqctx->tinfo.cpu = cpu;
17821 - irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
17822 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17823 -
17824 - per_cpu(hardirq_ctx, cpu) = irqctx;
17825 -
17826 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17827 - THREADINFO_GFP,
17828 - THREAD_SIZE_ORDER));
17829 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17830 - irqctx->tinfo.cpu = cpu;
17831 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17832 -
17833 - per_cpu(softirq_ctx, cpu) = irqctx;
17834 + per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
17835 + per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
17836 +
17837 + printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17838 + cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17839
17840 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17841 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17842 @@ -152,7 +141,6 @@ void __cpuinit irq_ctx_init(int cpu)
17843 asmlinkage void do_softirq(void)
17844 {
17845 unsigned long flags;
17846 - struct thread_info *curctx;
17847 union irq_ctx *irqctx;
17848 u32 *isp;
17849
17850 @@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
17851 local_irq_save(flags);
17852
17853 if (local_softirq_pending()) {
17854 - curctx = current_thread_info();
17855 irqctx = __this_cpu_read(softirq_ctx);
17856 - irqctx->tinfo.task = curctx->task;
17857 - irqctx->tinfo.previous_esp = current_stack_pointer;
17858 + irqctx->previous_esp = current_stack_pointer;
17859
17860 /* build the stack frame on the softirq stack */
17861 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17862 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17863 +
17864 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17865 + __set_fs(MAKE_MM_SEG(0));
17866 +#endif
17867
17868 call_on_stack(__do_softirq, isp);
17869 +
17870 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17871 + __set_fs(current_thread_info()->addr_limit);
17872 +#endif
17873 +
17874 /*
17875 * Shouldn't happen, we returned above if in_interrupt():
17876 */
17877 @@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
17878 if (unlikely(!desc))
17879 return false;
17880
17881 - if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17882 + if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17883 if (unlikely(overflow))
17884 print_stack_overflow();
17885 desc->handle_irq(irq, desc);
17886 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
17887 index d04d3ec..ea4b374 100644
17888 --- a/arch/x86/kernel/irq_64.c
17889 +++ b/arch/x86/kernel/irq_64.c
17890 @@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
17891 u64 estack_top, estack_bottom;
17892 u64 curbase = (u64)task_stack_page(current);
17893
17894 - if (user_mode_vm(regs))
17895 + if (user_mode(regs))
17896 return;
17897
17898 if (regs->sp >= curbase + sizeof(struct thread_info) +
17899 diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
17900 index dc1404b..bbc43e7 100644
17901 --- a/arch/x86/kernel/kdebugfs.c
17902 +++ b/arch/x86/kernel/kdebugfs.c
17903 @@ -27,7 +27,7 @@ struct setup_data_node {
17904 u32 len;
17905 };
17906
17907 -static ssize_t setup_data_read(struct file *file, char __user *user_buf,
17908 +static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
17909 size_t count, loff_t *ppos)
17910 {
17911 struct setup_data_node *node = file->private_data;
17912 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
17913 index 3f61904..873cea9 100644
17914 --- a/arch/x86/kernel/kgdb.c
17915 +++ b/arch/x86/kernel/kgdb.c
17916 @@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
17917 #ifdef CONFIG_X86_32
17918 switch (regno) {
17919 case GDB_SS:
17920 - if (!user_mode_vm(regs))
17921 + if (!user_mode(regs))
17922 *(unsigned long *)mem = __KERNEL_DS;
17923 break;
17924 case GDB_SP:
17925 - if (!user_mode_vm(regs))
17926 + if (!user_mode(regs))
17927 *(unsigned long *)mem = kernel_stack_pointer(regs);
17928 break;
17929 case GDB_GS:
17930 @@ -476,12 +476,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
17931 case 'k':
17932 /* clear the trace bit */
17933 linux_regs->flags &= ~X86_EFLAGS_TF;
17934 - atomic_set(&kgdb_cpu_doing_single_step, -1);
17935 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
17936
17937 /* set the trace bit if we're stepping */
17938 if (remcomInBuffer[0] == 's') {
17939 linux_regs->flags |= X86_EFLAGS_TF;
17940 - atomic_set(&kgdb_cpu_doing_single_step,
17941 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
17942 raw_smp_processor_id());
17943 }
17944
17945 @@ -546,7 +546,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
17946
17947 switch (cmd) {
17948 case DIE_DEBUG:
17949 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
17950 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
17951 if (user_mode(regs))
17952 return single_step_cont(regs, args);
17953 break;
17954 diff --git a/arch/x86/kernel/kprobes-opt.c b/arch/x86/kernel/kprobes-opt.c
17955 index c5e410e..da6aaf9 100644
17956 --- a/arch/x86/kernel/kprobes-opt.c
17957 +++ b/arch/x86/kernel/kprobes-opt.c
17958 @@ -338,7 +338,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17959 * Verify if the address gap is in 2GB range, because this uses
17960 * a relative jump.
17961 */
17962 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
17963 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
17964 if (abs(rel) > 0x7fffffff)
17965 return -ERANGE;
17966
17967 @@ -359,11 +359,11 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17968 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
17969
17970 /* Set probe function call */
17971 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
17972 + synthesize_relcall(buf + TMPL_CALL_IDX, ktla_ktva(optimized_callback));
17973
17974 /* Set returning jmp instruction at the tail of out-of-line buffer */
17975 synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
17976 - (u8 *)op->kp.addr + op->optinsn.size);
17977 + (u8 *)ktla_ktva(op->kp.addr) + op->optinsn.size);
17978
17979 flush_icache_range((unsigned long) buf,
17980 (unsigned long) buf + TMPL_END_IDX +
17981 @@ -385,7 +385,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
17982 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
17983
17984 /* Backup instructions which will be replaced by jump address */
17985 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
17986 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
17987 RELATIVE_ADDR_SIZE);
17988
17989 insn_buf[0] = RELATIVEJUMP_OPCODE;
17990 diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
17991 index e2f751e..dffa2a0 100644
17992 --- a/arch/x86/kernel/kprobes.c
17993 +++ b/arch/x86/kernel/kprobes.c
17994 @@ -120,8 +120,11 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
17995 } __attribute__((packed)) *insn;
17996
17997 insn = (struct __arch_relative_insn *)from;
17998 +
17999 + pax_open_kernel();
18000 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
18001 insn->op = op;
18002 + pax_close_kernel();
18003 }
18004
18005 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
18006 @@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
18007 kprobe_opcode_t opcode;
18008 kprobe_opcode_t *orig_opcodes = opcodes;
18009
18010 - if (search_exception_tables((unsigned long)opcodes))
18011 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
18012 return 0; /* Page fault may occur on this address. */
18013
18014 retry:
18015 @@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
18016 /* Another subsystem puts a breakpoint, failed to recover */
18017 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
18018 return 0;
18019 + pax_open_kernel();
18020 memcpy(dest, insn.kaddr, insn.length);
18021 + pax_close_kernel();
18022
18023 #ifdef CONFIG_X86_64
18024 if (insn_rip_relative(&insn)) {
18025 @@ -355,7 +360,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
18026 newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
18027 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
18028 disp = (u8 *) dest + insn_offset_displacement(&insn);
18029 + pax_open_kernel();
18030 *(s32 *) disp = (s32) newdisp;
18031 + pax_close_kernel();
18032 }
18033 #endif
18034 return insn.length;
18035 @@ -485,7 +492,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
18036 * nor set current_kprobe, because it doesn't use single
18037 * stepping.
18038 */
18039 - regs->ip = (unsigned long)p->ainsn.insn;
18040 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
18041 preempt_enable_no_resched();
18042 return;
18043 }
18044 @@ -504,7 +511,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
18045 if (p->opcode == BREAKPOINT_INSTRUCTION)
18046 regs->ip = (unsigned long)p->addr;
18047 else
18048 - regs->ip = (unsigned long)p->ainsn.insn;
18049 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
18050 }
18051
18052 /*
18053 @@ -583,7 +590,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
18054 setup_singlestep(p, regs, kcb, 0);
18055 return 1;
18056 }
18057 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
18058 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
18059 /*
18060 * The breakpoint instruction was removed right
18061 * after we hit it. Another cpu has removed
18062 @@ -628,6 +635,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
18063 " movq %rax, 152(%rsp)\n"
18064 RESTORE_REGS_STRING
18065 " popfq\n"
18066 +#ifdef KERNEXEC_PLUGIN
18067 + " btsq $63,(%rsp)\n"
18068 +#endif
18069 #else
18070 " pushf\n"
18071 SAVE_REGS_STRING
18072 @@ -765,7 +775,7 @@ static void __kprobes
18073 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
18074 {
18075 unsigned long *tos = stack_addr(regs);
18076 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
18077 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
18078 unsigned long orig_ip = (unsigned long)p->addr;
18079 kprobe_opcode_t *insn = p->ainsn.insn;
18080
18081 @@ -947,7 +957,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
18082 struct die_args *args = data;
18083 int ret = NOTIFY_DONE;
18084
18085 - if (args->regs && user_mode_vm(args->regs))
18086 + if (args->regs && user_mode(args->regs))
18087 return ret;
18088
18089 switch (val) {
18090 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
18091 index ebc9873..1b9724b 100644
18092 --- a/arch/x86/kernel/ldt.c
18093 +++ b/arch/x86/kernel/ldt.c
18094 @@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
18095 if (reload) {
18096 #ifdef CONFIG_SMP
18097 preempt_disable();
18098 - load_LDT(pc);
18099 + load_LDT_nolock(pc);
18100 if (!cpumask_equal(mm_cpumask(current->mm),
18101 cpumask_of(smp_processor_id())))
18102 smp_call_function(flush_ldt, current->mm, 1);
18103 preempt_enable();
18104 #else
18105 - load_LDT(pc);
18106 + load_LDT_nolock(pc);
18107 #endif
18108 }
18109 if (oldsize) {
18110 @@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
18111 return err;
18112
18113 for (i = 0; i < old->size; i++)
18114 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
18115 + write_ldt_entry(new->ldt, i, old->ldt + i);
18116 return 0;
18117 }
18118
18119 @@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
18120 retval = copy_ldt(&mm->context, &old_mm->context);
18121 mutex_unlock(&old_mm->context.lock);
18122 }
18123 +
18124 + if (tsk == current) {
18125 + mm->context.vdso = 0;
18126 +
18127 +#ifdef CONFIG_X86_32
18128 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
18129 + mm->context.user_cs_base = 0UL;
18130 + mm->context.user_cs_limit = ~0UL;
18131 +
18132 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
18133 + cpus_clear(mm->context.cpu_user_cs_mask);
18134 +#endif
18135 +
18136 +#endif
18137 +#endif
18138 +
18139 + }
18140 +
18141 return retval;
18142 }
18143
18144 @@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
18145 }
18146 }
18147
18148 +#ifdef CONFIG_PAX_SEGMEXEC
18149 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
18150 + error = -EINVAL;
18151 + goto out_unlock;
18152 + }
18153 +#endif
18154 +
18155 fill_ldt(&ldt, &ldt_info);
18156 if (oldmode)
18157 ldt.avl = 0;
18158 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
18159 index 5b19e4d..6476a76 100644
18160 --- a/arch/x86/kernel/machine_kexec_32.c
18161 +++ b/arch/x86/kernel/machine_kexec_32.c
18162 @@ -26,7 +26,7 @@
18163 #include <asm/cacheflush.h>
18164 #include <asm/debugreg.h>
18165
18166 -static void set_idt(void *newidt, __u16 limit)
18167 +static void set_idt(struct desc_struct *newidt, __u16 limit)
18168 {
18169 struct desc_ptr curidt;
18170
18171 @@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
18172 }
18173
18174
18175 -static void set_gdt(void *newgdt, __u16 limit)
18176 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
18177 {
18178 struct desc_ptr curgdt;
18179
18180 @@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
18181 }
18182
18183 control_page = page_address(image->control_code_page);
18184 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
18185 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
18186
18187 relocate_kernel_ptr = control_page;
18188 page_list[PA_CONTROL_PAGE] = __pa(control_page);
18189 diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
18190 index 0327e2b..e43737b 100644
18191 --- a/arch/x86/kernel/microcode_intel.c
18192 +++ b/arch/x86/kernel/microcode_intel.c
18193 @@ -430,13 +430,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device)
18194
18195 static int get_ucode_user(void *to, const void *from, size_t n)
18196 {
18197 - return copy_from_user(to, from, n);
18198 + return copy_from_user(to, (const void __force_user *)from, n);
18199 }
18200
18201 static enum ucode_state
18202 request_microcode_user(int cpu, const void __user *buf, size_t size)
18203 {
18204 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
18205 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
18206 }
18207
18208 static void microcode_fini_cpu(int cpu)
18209 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
18210 index 216a4d7..b328f09 100644
18211 --- a/arch/x86/kernel/module.c
18212 +++ b/arch/x86/kernel/module.c
18213 @@ -43,15 +43,60 @@ do { \
18214 } while (0)
18215 #endif
18216
18217 -void *module_alloc(unsigned long size)
18218 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
18219 {
18220 - if (PAGE_ALIGN(size) > MODULES_LEN)
18221 + if (size == 0 || PAGE_ALIGN(size) > MODULES_LEN)
18222 return NULL;
18223 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
18224 - GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
18225 + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
18226 -1, __builtin_return_address(0));
18227 }
18228
18229 +void *module_alloc(unsigned long size)
18230 +{
18231 +
18232 +#ifdef CONFIG_PAX_KERNEXEC
18233 + return __module_alloc(size, PAGE_KERNEL);
18234 +#else
18235 + return __module_alloc(size, PAGE_KERNEL_EXEC);
18236 +#endif
18237 +
18238 +}
18239 +
18240 +#ifdef CONFIG_PAX_KERNEXEC
18241 +#ifdef CONFIG_X86_32
18242 +void *module_alloc_exec(unsigned long size)
18243 +{
18244 + struct vm_struct *area;
18245 +
18246 + if (size == 0)
18247 + return NULL;
18248 +
18249 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
18250 + return area ? area->addr : NULL;
18251 +}
18252 +EXPORT_SYMBOL(module_alloc_exec);
18253 +
18254 +void module_free_exec(struct module *mod, void *module_region)
18255 +{
18256 + vunmap(module_region);
18257 +}
18258 +EXPORT_SYMBOL(module_free_exec);
18259 +#else
18260 +void module_free_exec(struct module *mod, void *module_region)
18261 +{
18262 + module_free(mod, module_region);
18263 +}
18264 +EXPORT_SYMBOL(module_free_exec);
18265 +
18266 +void *module_alloc_exec(unsigned long size)
18267 +{
18268 + return __module_alloc(size, PAGE_KERNEL_RX);
18269 +}
18270 +EXPORT_SYMBOL(module_alloc_exec);
18271 +#endif
18272 +#endif
18273 +
18274 #ifdef CONFIG_X86_32
18275 int apply_relocate(Elf32_Shdr *sechdrs,
18276 const char *strtab,
18277 @@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18278 unsigned int i;
18279 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
18280 Elf32_Sym *sym;
18281 - uint32_t *location;
18282 + uint32_t *plocation, location;
18283
18284 DEBUGP("Applying relocate section %u to %u\n",
18285 relsec, sechdrs[relsec].sh_info);
18286 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
18287 /* This is where to make the change */
18288 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
18289 - + rel[i].r_offset;
18290 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
18291 + location = (uint32_t)plocation;
18292 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
18293 + plocation = ktla_ktva((void *)plocation);
18294 /* This is the symbol it is referring to. Note that all
18295 undefined symbols have been resolved. */
18296 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
18297 @@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18298 switch (ELF32_R_TYPE(rel[i].r_info)) {
18299 case R_386_32:
18300 /* We add the value into the location given */
18301 - *location += sym->st_value;
18302 + pax_open_kernel();
18303 + *plocation += sym->st_value;
18304 + pax_close_kernel();
18305 break;
18306 case R_386_PC32:
18307 /* Add the value, subtract its position */
18308 - *location += sym->st_value - (uint32_t)location;
18309 + pax_open_kernel();
18310 + *plocation += sym->st_value - location;
18311 + pax_close_kernel();
18312 break;
18313 default:
18314 pr_err("%s: Unknown relocation: %u\n",
18315 @@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
18316 case R_X86_64_NONE:
18317 break;
18318 case R_X86_64_64:
18319 + pax_open_kernel();
18320 *(u64 *)loc = val;
18321 + pax_close_kernel();
18322 break;
18323 case R_X86_64_32:
18324 + pax_open_kernel();
18325 *(u32 *)loc = val;
18326 + pax_close_kernel();
18327 if (val != *(u32 *)loc)
18328 goto overflow;
18329 break;
18330 case R_X86_64_32S:
18331 + pax_open_kernel();
18332 *(s32 *)loc = val;
18333 + pax_close_kernel();
18334 if ((s64)val != *(s32 *)loc)
18335 goto overflow;
18336 break;
18337 case R_X86_64_PC32:
18338 val -= (u64)loc;
18339 + pax_open_kernel();
18340 *(u32 *)loc = val;
18341 + pax_close_kernel();
18342 +
18343 #if 0
18344 if ((s64)val != *(s32 *)loc)
18345 goto overflow;
18346 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
18347 index f84f5c5..e27e54b 100644
18348 --- a/arch/x86/kernel/nmi.c
18349 +++ b/arch/x86/kernel/nmi.c
18350 @@ -479,6 +479,17 @@ static inline void nmi_nesting_postprocess(void)
18351 dotraplinkage notrace __kprobes void
18352 do_nmi(struct pt_regs *regs, long error_code)
18353 {
18354 +
18355 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18356 + if (!user_mode(regs)) {
18357 + unsigned long cs = regs->cs & 0xFFFF;
18358 + unsigned long ip = ktva_ktla(regs->ip);
18359 +
18360 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
18361 + regs->ip = ip;
18362 + }
18363 +#endif
18364 +
18365 nmi_nesting_preprocess(regs);
18366
18367 nmi_enter();
18368 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
18369 index 676b8c7..870ba04 100644
18370 --- a/arch/x86/kernel/paravirt-spinlocks.c
18371 +++ b/arch/x86/kernel/paravirt-spinlocks.c
18372 @@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
18373 arch_spin_lock(lock);
18374 }
18375
18376 -struct pv_lock_ops pv_lock_ops = {
18377 +struct pv_lock_ops pv_lock_ops __read_only = {
18378 #ifdef CONFIG_SMP
18379 .spin_is_locked = __ticket_spin_is_locked,
18380 .spin_is_contended = __ticket_spin_is_contended,
18381 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
18382 index 17fff18..7bb2088 100644
18383 --- a/arch/x86/kernel/paravirt.c
18384 +++ b/arch/x86/kernel/paravirt.c
18385 @@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
18386 {
18387 return x;
18388 }
18389 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18390 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
18391 +#endif
18392
18393 void __init default_banner(void)
18394 {
18395 @@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
18396 if (opfunc == NULL)
18397 /* If there's no function, patch it with a ud2a (BUG) */
18398 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
18399 - else if (opfunc == _paravirt_nop)
18400 + else if (opfunc == (void *)_paravirt_nop)
18401 /* If the operation is a nop, then nop the callsite */
18402 ret = paravirt_patch_nop();
18403
18404 /* identity functions just return their single argument */
18405 - else if (opfunc == _paravirt_ident_32)
18406 + else if (opfunc == (void *)_paravirt_ident_32)
18407 ret = paravirt_patch_ident_32(insnbuf, len);
18408 - else if (opfunc == _paravirt_ident_64)
18409 + else if (opfunc == (void *)_paravirt_ident_64)
18410 ret = paravirt_patch_ident_64(insnbuf, len);
18411 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18412 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
18413 + ret = paravirt_patch_ident_64(insnbuf, len);
18414 +#endif
18415
18416 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
18417 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
18418 @@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
18419 if (insn_len > len || start == NULL)
18420 insn_len = len;
18421 else
18422 - memcpy(insnbuf, start, insn_len);
18423 + memcpy(insnbuf, ktla_ktva(start), insn_len);
18424
18425 return insn_len;
18426 }
18427 @@ -304,7 +311,7 @@ void arch_flush_lazy_mmu_mode(void)
18428 preempt_enable();
18429 }
18430
18431 -struct pv_info pv_info = {
18432 +struct pv_info pv_info __read_only = {
18433 .name = "bare hardware",
18434 .paravirt_enabled = 0,
18435 .kernel_rpl = 0,
18436 @@ -315,16 +322,16 @@ struct pv_info pv_info = {
18437 #endif
18438 };
18439
18440 -struct pv_init_ops pv_init_ops = {
18441 +struct pv_init_ops pv_init_ops __read_only = {
18442 .patch = native_patch,
18443 };
18444
18445 -struct pv_time_ops pv_time_ops = {
18446 +struct pv_time_ops pv_time_ops __read_only = {
18447 .sched_clock = native_sched_clock,
18448 .steal_clock = native_steal_clock,
18449 };
18450
18451 -struct pv_irq_ops pv_irq_ops = {
18452 +struct pv_irq_ops pv_irq_ops __read_only = {
18453 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
18454 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
18455 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
18456 @@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
18457 #endif
18458 };
18459
18460 -struct pv_cpu_ops pv_cpu_ops = {
18461 +struct pv_cpu_ops pv_cpu_ops __read_only = {
18462 .cpuid = native_cpuid,
18463 .get_debugreg = native_get_debugreg,
18464 .set_debugreg = native_set_debugreg,
18465 @@ -395,21 +402,26 @@ struct pv_cpu_ops pv_cpu_ops = {
18466 .end_context_switch = paravirt_nop,
18467 };
18468
18469 -struct pv_apic_ops pv_apic_ops = {
18470 +struct pv_apic_ops pv_apic_ops __read_only = {
18471 #ifdef CONFIG_X86_LOCAL_APIC
18472 .startup_ipi_hook = paravirt_nop,
18473 #endif
18474 };
18475
18476 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
18477 +#ifdef CONFIG_X86_32
18478 +#ifdef CONFIG_X86_PAE
18479 +/* 64-bit pagetable entries */
18480 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
18481 +#else
18482 /* 32-bit pagetable entries */
18483 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
18484 +#endif
18485 #else
18486 /* 64-bit pagetable entries */
18487 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
18488 #endif
18489
18490 -struct pv_mmu_ops pv_mmu_ops = {
18491 +struct pv_mmu_ops pv_mmu_ops __read_only = {
18492
18493 .read_cr2 = native_read_cr2,
18494 .write_cr2 = native_write_cr2,
18495 @@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
18496 .make_pud = PTE_IDENT,
18497
18498 .set_pgd = native_set_pgd,
18499 + .set_pgd_batched = native_set_pgd_batched,
18500 #endif
18501 #endif /* PAGETABLE_LEVELS >= 3 */
18502
18503 @@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
18504 },
18505
18506 .set_fixmap = native_set_fixmap,
18507 +
18508 +#ifdef CONFIG_PAX_KERNEXEC
18509 + .pax_open_kernel = native_pax_open_kernel,
18510 + .pax_close_kernel = native_pax_close_kernel,
18511 +#endif
18512 +
18513 };
18514
18515 EXPORT_SYMBOL_GPL(pv_time_ops);
18516 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
18517 index 35ccf75..7a15747 100644
18518 --- a/arch/x86/kernel/pci-iommu_table.c
18519 +++ b/arch/x86/kernel/pci-iommu_table.c
18520 @@ -2,7 +2,7 @@
18521 #include <asm/iommu_table.h>
18522 #include <linux/string.h>
18523 #include <linux/kallsyms.h>
18524 -
18525 +#include <linux/sched.h>
18526
18527 #define DEBUG 1
18528
18529 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
18530 index ef6a845..8028ed3 100644
18531 --- a/arch/x86/kernel/process.c
18532 +++ b/arch/x86/kernel/process.c
18533 @@ -36,7 +36,8 @@
18534 * section. Since TSS's are completely CPU-local, we want them
18535 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
18536 */
18537 -DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
18538 +struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
18539 +EXPORT_SYMBOL(init_tss);
18540
18541 #ifdef CONFIG_X86_64
18542 static DEFINE_PER_CPU(unsigned char, is_idle);
18543 @@ -94,7 +95,7 @@ void arch_task_cache_init(void)
18544 task_xstate_cachep =
18545 kmem_cache_create("task_xstate", xstate_size,
18546 __alignof__(union thread_xstate),
18547 - SLAB_PANIC | SLAB_NOTRACK, NULL);
18548 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
18549 }
18550
18551 static inline void drop_fpu(struct task_struct *tsk)
18552 @@ -117,7 +118,7 @@ void exit_thread(void)
18553 unsigned long *bp = t->io_bitmap_ptr;
18554
18555 if (bp) {
18556 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
18557 + struct tss_struct *tss = init_tss + get_cpu();
18558
18559 t->io_bitmap_ptr = NULL;
18560 clear_thread_flag(TIF_IO_BITMAP);
18561 @@ -148,7 +149,7 @@ void show_regs_common(void)
18562 board = dmi_get_system_info(DMI_BOARD_NAME);
18563
18564 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s %s %s%s%s\n",
18565 - current->pid, current->comm, print_tainted(),
18566 + task_pid_nr(current), current->comm, print_tainted(),
18567 init_utsname()->release,
18568 (int)strcspn(init_utsname()->version, " "),
18569 init_utsname()->version,
18570 @@ -161,6 +162,9 @@ void flush_thread(void)
18571 {
18572 struct task_struct *tsk = current;
18573
18574 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18575 + loadsegment(gs, 0);
18576 +#endif
18577 flush_ptrace_hw_breakpoint(tsk);
18578 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
18579 drop_fpu(tsk);
18580 @@ -318,10 +322,10 @@ int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
18581 regs.di = (unsigned long) arg;
18582
18583 #ifdef CONFIG_X86_32
18584 - regs.ds = __USER_DS;
18585 - regs.es = __USER_DS;
18586 + regs.ds = __KERNEL_DS;
18587 + regs.es = __KERNEL_DS;
18588 regs.fs = __KERNEL_PERCPU;
18589 - regs.gs = __KERNEL_STACK_CANARY;
18590 + savesegment(gs, regs.gs);
18591 #else
18592 regs.ss = __KERNEL_DS;
18593 #endif
18594 @@ -407,7 +411,7 @@ static void __exit_idle(void)
18595 void exit_idle(void)
18596 {
18597 /* idle loop has pid 0 */
18598 - if (current->pid)
18599 + if (task_pid_nr(current))
18600 return;
18601 __exit_idle();
18602 }
18603 @@ -516,7 +520,7 @@ bool set_pm_idle_to_default(void)
18604
18605 return ret;
18606 }
18607 -void stop_this_cpu(void *dummy)
18608 +__noreturn void stop_this_cpu(void *dummy)
18609 {
18610 local_irq_disable();
18611 /*
18612 @@ -744,16 +748,37 @@ static int __init idle_setup(char *str)
18613 }
18614 early_param("idle", idle_setup);
18615
18616 -unsigned long arch_align_stack(unsigned long sp)
18617 +#ifdef CONFIG_PAX_RANDKSTACK
18618 +void pax_randomize_kstack(struct pt_regs *regs)
18619 {
18620 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
18621 - sp -= get_random_int() % 8192;
18622 - return sp & ~0xf;
18623 -}
18624 + struct thread_struct *thread = &current->thread;
18625 + unsigned long time;
18626
18627 -unsigned long arch_randomize_brk(struct mm_struct *mm)
18628 -{
18629 - unsigned long range_end = mm->brk + 0x02000000;
18630 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
18631 -}
18632 + if (!randomize_va_space)
18633 + return;
18634 +
18635 + if (v8086_mode(regs))
18636 + return;
18637
18638 + rdtscl(time);
18639 +
18640 + /* P4 seems to return a 0 LSB, ignore it */
18641 +#ifdef CONFIG_MPENTIUM4
18642 + time &= 0x3EUL;
18643 + time <<= 2;
18644 +#elif defined(CONFIG_X86_64)
18645 + time &= 0xFUL;
18646 + time <<= 4;
18647 +#else
18648 + time &= 0x1FUL;
18649 + time <<= 3;
18650 +#endif
18651 +
18652 + thread->sp0 ^= time;
18653 + load_sp0(init_tss + smp_processor_id(), thread);
18654 +
18655 +#ifdef CONFIG_X86_64
18656 + this_cpu_write(kernel_stack, thread->sp0);
18657 +#endif
18658 +}
18659 +#endif
18660 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
18661 index 516fa18..d3a7099 100644
18662 --- a/arch/x86/kernel/process_32.c
18663 +++ b/arch/x86/kernel/process_32.c
18664 @@ -64,6 +64,7 @@ asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
18665 unsigned long thread_saved_pc(struct task_struct *tsk)
18666 {
18667 return ((unsigned long *)tsk->thread.sp)[3];
18668 +//XXX return tsk->thread.eip;
18669 }
18670
18671 void __show_regs(struct pt_regs *regs, int all)
18672 @@ -73,21 +74,20 @@ void __show_regs(struct pt_regs *regs, int all)
18673 unsigned long sp;
18674 unsigned short ss, gs;
18675
18676 - if (user_mode_vm(regs)) {
18677 + if (user_mode(regs)) {
18678 sp = regs->sp;
18679 ss = regs->ss & 0xffff;
18680 - gs = get_user_gs(regs);
18681 } else {
18682 sp = kernel_stack_pointer(regs);
18683 savesegment(ss, ss);
18684 - savesegment(gs, gs);
18685 }
18686 + gs = get_user_gs(regs);
18687
18688 show_regs_common();
18689
18690 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
18691 (u16)regs->cs, regs->ip, regs->flags,
18692 - smp_processor_id());
18693 + raw_smp_processor_id());
18694 print_symbol("EIP is at %s\n", regs->ip);
18695
18696 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
18697 @@ -134,13 +134,14 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18698 struct task_struct *tsk;
18699 int err;
18700
18701 - childregs = task_pt_regs(p);
18702 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
18703 *childregs = *regs;
18704 childregs->ax = 0;
18705 childregs->sp = sp;
18706
18707 p->thread.sp = (unsigned long) childregs;
18708 p->thread.sp0 = (unsigned long) (childregs+1);
18709 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18710
18711 p->thread.ip = (unsigned long) ret_from_fork;
18712
18713 @@ -231,7 +232,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18714 struct thread_struct *prev = &prev_p->thread,
18715 *next = &next_p->thread;
18716 int cpu = smp_processor_id();
18717 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
18718 + struct tss_struct *tss = init_tss + cpu;
18719 fpu_switch_t fpu;
18720
18721 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
18722 @@ -255,6 +256,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18723 */
18724 lazy_save_gs(prev->gs);
18725
18726 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18727 + __set_fs(task_thread_info(next_p)->addr_limit);
18728 +#endif
18729 +
18730 /*
18731 * Load the per-thread Thread-Local Storage descriptor.
18732 */
18733 @@ -285,6 +290,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18734 */
18735 arch_end_context_switch(next_p);
18736
18737 + this_cpu_write(current_task, next_p);
18738 + this_cpu_write(current_tinfo, &next_p->tinfo);
18739 +
18740 /*
18741 * Restore %gs if needed (which is common)
18742 */
18743 @@ -293,8 +301,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18744
18745 switch_fpu_finish(next_p, fpu);
18746
18747 - this_cpu_write(current_task, next_p);
18748 -
18749 return prev_p;
18750 }
18751
18752 @@ -324,4 +330,3 @@ unsigned long get_wchan(struct task_struct *p)
18753 } while (count++ < 16);
18754 return 0;
18755 }
18756 -
18757 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
18758 index 0a980c9..1d0e689 100644
18759 --- a/arch/x86/kernel/process_64.c
18760 +++ b/arch/x86/kernel/process_64.c
18761 @@ -153,8 +153,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18762 struct pt_regs *childregs;
18763 struct task_struct *me = current;
18764
18765 - childregs = ((struct pt_regs *)
18766 - (THREAD_SIZE + task_stack_page(p))) - 1;
18767 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 16;
18768 *childregs = *regs;
18769
18770 childregs->ax = 0;
18771 @@ -166,6 +165,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18772 p->thread.sp = (unsigned long) childregs;
18773 p->thread.sp0 = (unsigned long) (childregs+1);
18774 p->thread.usersp = me->thread.usersp;
18775 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18776
18777 set_tsk_thread_flag(p, TIF_FORK);
18778
18779 @@ -271,7 +271,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18780 struct thread_struct *prev = &prev_p->thread;
18781 struct thread_struct *next = &next_p->thread;
18782 int cpu = smp_processor_id();
18783 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
18784 + struct tss_struct *tss = init_tss + cpu;
18785 unsigned fsindex, gsindex;
18786 fpu_switch_t fpu;
18787
18788 @@ -353,10 +353,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18789 prev->usersp = this_cpu_read(old_rsp);
18790 this_cpu_write(old_rsp, next->usersp);
18791 this_cpu_write(current_task, next_p);
18792 + this_cpu_write(current_tinfo, &next_p->tinfo);
18793
18794 - this_cpu_write(kernel_stack,
18795 - (unsigned long)task_stack_page(next_p) +
18796 - THREAD_SIZE - KERNEL_STACK_OFFSET);
18797 + this_cpu_write(kernel_stack, next->sp0);
18798
18799 /*
18800 * Now maybe reload the debug registers and handle I/O bitmaps
18801 @@ -425,12 +424,11 @@ unsigned long get_wchan(struct task_struct *p)
18802 if (!p || p == current || p->state == TASK_RUNNING)
18803 return 0;
18804 stack = (unsigned long)task_stack_page(p);
18805 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
18806 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
18807 return 0;
18808 fp = *(u64 *)(p->thread.sp);
18809 do {
18810 - if (fp < (unsigned long)stack ||
18811 - fp >= (unsigned long)stack+THREAD_SIZE)
18812 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
18813 return 0;
18814 ip = *(u64 *)(fp+8);
18815 if (!in_sched_functions(ip))
18816 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
18817 index 9ee1787..33228a7 100644
18818 --- a/arch/x86/kernel/ptrace.c
18819 +++ b/arch/x86/kernel/ptrace.c
18820 @@ -182,14 +182,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
18821 {
18822 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
18823 unsigned long sp = (unsigned long)&regs->sp;
18824 - struct thread_info *tinfo;
18825
18826 - if (context == (sp & ~(THREAD_SIZE - 1)))
18827 + if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
18828 return sp;
18829
18830 - tinfo = (struct thread_info *)context;
18831 - if (tinfo->previous_esp)
18832 - return tinfo->previous_esp;
18833 + sp = *(unsigned long *)context;
18834 + if (sp)
18835 + return sp;
18836
18837 return (unsigned long)regs;
18838 }
18839 @@ -854,7 +853,7 @@ long arch_ptrace(struct task_struct *child, long request,
18840 unsigned long addr, unsigned long data)
18841 {
18842 int ret;
18843 - unsigned long __user *datap = (unsigned long __user *)data;
18844 + unsigned long __user *datap = (__force unsigned long __user *)data;
18845
18846 switch (request) {
18847 /* read the word at location addr in the USER area. */
18848 @@ -939,14 +938,14 @@ long arch_ptrace(struct task_struct *child, long request,
18849 if ((int) addr < 0)
18850 return -EIO;
18851 ret = do_get_thread_area(child, addr,
18852 - (struct user_desc __user *)data);
18853 + (__force struct user_desc __user *) data);
18854 break;
18855
18856 case PTRACE_SET_THREAD_AREA:
18857 if ((int) addr < 0)
18858 return -EIO;
18859 ret = do_set_thread_area(child, addr,
18860 - (struct user_desc __user *)data, 0);
18861 + (__force struct user_desc __user *) data, 0);
18862 break;
18863 #endif
18864
18865 @@ -1456,7 +1455,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
18866 memset(info, 0, sizeof(*info));
18867 info->si_signo = SIGTRAP;
18868 info->si_code = si_code;
18869 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
18870 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
18871 }
18872
18873 void user_single_step_siginfo(struct task_struct *tsk,
18874 @@ -1485,6 +1484,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
18875 # define IS_IA32 0
18876 #endif
18877
18878 +#ifdef CONFIG_GRKERNSEC_SETXID
18879 +extern void gr_delayed_cred_worker(void);
18880 +#endif
18881 +
18882 /*
18883 * We must return the syscall number to actually look up in the table.
18884 * This can be -1L to skip running any syscall at all.
18885 @@ -1493,6 +1496,11 @@ long syscall_trace_enter(struct pt_regs *regs)
18886 {
18887 long ret = 0;
18888
18889 +#ifdef CONFIG_GRKERNSEC_SETXID
18890 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18891 + gr_delayed_cred_worker();
18892 +#endif
18893 +
18894 /*
18895 * If we stepped into a sysenter/syscall insn, it trapped in
18896 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
18897 @@ -1541,6 +1549,11 @@ void syscall_trace_leave(struct pt_regs *regs)
18898 {
18899 bool step;
18900
18901 +#ifdef CONFIG_GRKERNSEC_SETXID
18902 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18903 + gr_delayed_cred_worker();
18904 +#endif
18905 +
18906 audit_syscall_exit(regs);
18907
18908 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
18909 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
18910 index 42eb330..139955c 100644
18911 --- a/arch/x86/kernel/pvclock.c
18912 +++ b/arch/x86/kernel/pvclock.c
18913 @@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
18914 return pv_tsc_khz;
18915 }
18916
18917 -static atomic64_t last_value = ATOMIC64_INIT(0);
18918 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
18919
18920 void pvclock_resume(void)
18921 {
18922 - atomic64_set(&last_value, 0);
18923 + atomic64_set_unchecked(&last_value, 0);
18924 }
18925
18926 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18927 @@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18928 * updating at the same time, and one of them could be slightly behind,
18929 * making the assumption that last_value always go forward fail to hold.
18930 */
18931 - last = atomic64_read(&last_value);
18932 + last = atomic64_read_unchecked(&last_value);
18933 do {
18934 if (ret < last)
18935 return last;
18936 - last = atomic64_cmpxchg(&last_value, last, ret);
18937 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
18938 } while (unlikely(last != ret));
18939
18940 return ret;
18941 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
18942 index 52190a9..8074389 100644
18943 --- a/arch/x86/kernel/reboot.c
18944 +++ b/arch/x86/kernel/reboot.c
18945 @@ -36,7 +36,7 @@ void (*pm_power_off)(void);
18946 EXPORT_SYMBOL(pm_power_off);
18947
18948 static const struct desc_ptr no_idt = {};
18949 -static int reboot_mode;
18950 +static unsigned short reboot_mode;
18951 enum reboot_type reboot_type = BOOT_ACPI;
18952 int reboot_force;
18953
18954 @@ -157,6 +157,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
18955
18956 void __noreturn machine_real_restart(unsigned int type)
18957 {
18958 +
18959 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18960 + struct desc_struct *gdt;
18961 +#endif
18962 +
18963 local_irq_disable();
18964
18965 /*
18966 @@ -184,7 +189,29 @@ void __noreturn machine_real_restart(unsigned int type)
18967
18968 /* Jump to the identity-mapped low memory code */
18969 #ifdef CONFIG_X86_32
18970 - asm volatile("jmpl *%0" : :
18971 +
18972 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
18973 + gdt = get_cpu_gdt_table(smp_processor_id());
18974 + pax_open_kernel();
18975 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18976 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
18977 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
18978 + loadsegment(ds, __KERNEL_DS);
18979 + loadsegment(es, __KERNEL_DS);
18980 + loadsegment(ss, __KERNEL_DS);
18981 +#endif
18982 +#ifdef CONFIG_PAX_KERNEXEC
18983 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
18984 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
18985 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
18986 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
18987 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
18988 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
18989 +#endif
18990 + pax_close_kernel();
18991 +#endif
18992 +
18993 + asm volatile("ljmpl *%0" : :
18994 "rm" (real_mode_header->machine_real_restart_asm),
18995 "a" (type));
18996 #else
18997 @@ -539,7 +566,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
18998 * try to force a triple fault and then cycle between hitting the keyboard
18999 * controller and doing that
19000 */
19001 -static void native_machine_emergency_restart(void)
19002 +static void __noreturn native_machine_emergency_restart(void)
19003 {
19004 int i;
19005 int attempt = 0;
19006 @@ -662,13 +689,13 @@ void native_machine_shutdown(void)
19007 #endif
19008 }
19009
19010 -static void __machine_emergency_restart(int emergency)
19011 +static void __noreturn __machine_emergency_restart(int emergency)
19012 {
19013 reboot_emergency = emergency;
19014 machine_ops.emergency_restart();
19015 }
19016
19017 -static void native_machine_restart(char *__unused)
19018 +static void __noreturn native_machine_restart(char *__unused)
19019 {
19020 pr_notice("machine restart\n");
19021
19022 @@ -677,7 +704,7 @@ static void native_machine_restart(char *__unused)
19023 __machine_emergency_restart(0);
19024 }
19025
19026 -static void native_machine_halt(void)
19027 +static void __noreturn native_machine_halt(void)
19028 {
19029 /* Stop other cpus and apics */
19030 machine_shutdown();
19031 @@ -687,7 +714,7 @@ static void native_machine_halt(void)
19032 stop_this_cpu(NULL);
19033 }
19034
19035 -static void native_machine_power_off(void)
19036 +static void __noreturn native_machine_power_off(void)
19037 {
19038 if (pm_power_off) {
19039 if (!reboot_force)
19040 @@ -696,6 +723,7 @@ static void native_machine_power_off(void)
19041 }
19042 /* A fallback in case there is no PM info available */
19043 tboot_shutdown(TB_SHUTDOWN_HALT);
19044 + unreachable();
19045 }
19046
19047 struct machine_ops machine_ops = {
19048 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
19049 index 7a6f3b3..bed145d7 100644
19050 --- a/arch/x86/kernel/relocate_kernel_64.S
19051 +++ b/arch/x86/kernel/relocate_kernel_64.S
19052 @@ -11,6 +11,7 @@
19053 #include <asm/kexec.h>
19054 #include <asm/processor-flags.h>
19055 #include <asm/pgtable_types.h>
19056 +#include <asm/alternative-asm.h>
19057
19058 /*
19059 * Must be relocatable PIC code callable as a C function
19060 @@ -160,13 +161,14 @@ identity_mapped:
19061 xorq %rbp, %rbp
19062 xorq %r8, %r8
19063 xorq %r9, %r9
19064 - xorq %r10, %r9
19065 + xorq %r10, %r10
19066 xorq %r11, %r11
19067 xorq %r12, %r12
19068 xorq %r13, %r13
19069 xorq %r14, %r14
19070 xorq %r15, %r15
19071
19072 + pax_force_retaddr 0, 1
19073 ret
19074
19075 1:
19076 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
19077 index 5cee802..bc22bc3 100644
19078 --- a/arch/x86/kernel/setup.c
19079 +++ b/arch/x86/kernel/setup.c
19080 @@ -440,7 +440,7 @@ static void __init parse_setup_data(void)
19081
19082 switch (data->type) {
19083 case SETUP_E820_EXT:
19084 - parse_e820_ext(data);
19085 + parse_e820_ext((struct setup_data __force_kernel *)data);
19086 break;
19087 case SETUP_DTB:
19088 add_dtb(pa_data);
19089 @@ -632,7 +632,7 @@ static void __init trim_bios_range(void)
19090 * area (640->1Mb) as ram even though it is not.
19091 * take them out.
19092 */
19093 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
19094 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
19095 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
19096 }
19097
19098 @@ -755,14 +755,14 @@ void __init setup_arch(char **cmdline_p)
19099
19100 if (!boot_params.hdr.root_flags)
19101 root_mountflags &= ~MS_RDONLY;
19102 - init_mm.start_code = (unsigned long) _text;
19103 - init_mm.end_code = (unsigned long) _etext;
19104 + init_mm.start_code = ktla_ktva((unsigned long) _text);
19105 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
19106 init_mm.end_data = (unsigned long) _edata;
19107 init_mm.brk = _brk_end;
19108
19109 - code_resource.start = virt_to_phys(_text);
19110 - code_resource.end = virt_to_phys(_etext)-1;
19111 - data_resource.start = virt_to_phys(_etext);
19112 + code_resource.start = virt_to_phys(ktla_ktva(_text));
19113 + code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
19114 + data_resource.start = virt_to_phys(_sdata);
19115 data_resource.end = virt_to_phys(_edata)-1;
19116 bss_resource.start = virt_to_phys(&__bss_start);
19117 bss_resource.end = virt_to_phys(&__bss_stop)-1;
19118 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
19119 index 5cdff03..5810740 100644
19120 --- a/arch/x86/kernel/setup_percpu.c
19121 +++ b/arch/x86/kernel/setup_percpu.c
19122 @@ -21,19 +21,17 @@
19123 #include <asm/cpu.h>
19124 #include <asm/stackprotector.h>
19125
19126 -DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
19127 +#ifdef CONFIG_SMP
19128 +DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
19129 EXPORT_PER_CPU_SYMBOL(cpu_number);
19130 +#endif
19131
19132 -#ifdef CONFIG_X86_64
19133 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
19134 -#else
19135 -#define BOOT_PERCPU_OFFSET 0
19136 -#endif
19137
19138 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
19139 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
19140
19141 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
19142 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
19143 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
19144 };
19145 EXPORT_SYMBOL(__per_cpu_offset);
19146 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
19147 {
19148 #ifdef CONFIG_X86_32
19149 struct desc_struct gdt;
19150 + unsigned long base = per_cpu_offset(cpu);
19151
19152 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
19153 - 0x2 | DESCTYPE_S, 0x8);
19154 - gdt.s = 1;
19155 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
19156 + 0x83 | DESCTYPE_S, 0xC);
19157 write_gdt_entry(get_cpu_gdt_table(cpu),
19158 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
19159 #endif
19160 @@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
19161 /* alrighty, percpu areas up and running */
19162 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
19163 for_each_possible_cpu(cpu) {
19164 +#ifdef CONFIG_CC_STACKPROTECTOR
19165 +#ifdef CONFIG_X86_32
19166 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
19167 +#endif
19168 +#endif
19169 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
19170 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
19171 per_cpu(cpu_number, cpu) = cpu;
19172 @@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
19173 */
19174 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
19175 #endif
19176 +#ifdef CONFIG_CC_STACKPROTECTOR
19177 +#ifdef CONFIG_X86_32
19178 + if (!cpu)
19179 + per_cpu(stack_canary.canary, cpu) = canary;
19180 +#endif
19181 +#endif
19182 /*
19183 * Up to this point, the boot CPU has been using .init.data
19184 * area. Reload any changed state for the boot CPU.
19185 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
19186 index b280908..6de349e 100644
19187 --- a/arch/x86/kernel/signal.c
19188 +++ b/arch/x86/kernel/signal.c
19189 @@ -194,7 +194,7 @@ static unsigned long align_sigframe(unsigned long sp)
19190 * Align the stack pointer according to the i386 ABI,
19191 * i.e. so that on function entry ((sp + 4) & 15) == 0.
19192 */
19193 - sp = ((sp + 4) & -16ul) - 4;
19194 + sp = ((sp - 12) & -16ul) - 4;
19195 #else /* !CONFIG_X86_32 */
19196 sp = round_down(sp, 16) - 8;
19197 #endif
19198 @@ -245,11 +245,11 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
19199 * Return an always-bogus address instead so we will die with SIGSEGV.
19200 */
19201 if (onsigstack && !likely(on_sig_stack(sp)))
19202 - return (void __user *)-1L;
19203 + return (__force void __user *)-1L;
19204
19205 /* save i387 state */
19206 if (used_math() && save_i387_xstate(*fpstate) < 0)
19207 - return (void __user *)-1L;
19208 + return (__force void __user *)-1L;
19209
19210 return (void __user *)sp;
19211 }
19212 @@ -304,9 +304,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19213 }
19214
19215 if (current->mm->context.vdso)
19216 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19217 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19218 else
19219 - restorer = &frame->retcode;
19220 + restorer = (void __user *)&frame->retcode;
19221 if (ka->sa.sa_flags & SA_RESTORER)
19222 restorer = ka->sa.sa_restorer;
19223
19224 @@ -320,7 +320,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19225 * reasons and because gdb uses it as a signature to notice
19226 * signal handler stack frames.
19227 */
19228 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
19229 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
19230
19231 if (err)
19232 return -EFAULT;
19233 @@ -374,7 +374,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19234 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
19235
19236 /* Set up to return from userspace. */
19237 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19238 + if (current->mm->context.vdso)
19239 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19240 + else
19241 + restorer = (void __user *)&frame->retcode;
19242 if (ka->sa.sa_flags & SA_RESTORER)
19243 restorer = ka->sa.sa_restorer;
19244 put_user_ex(restorer, &frame->pretcode);
19245 @@ -386,7 +389,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19246 * reasons and because gdb uses it as a signature to notice
19247 * signal handler stack frames.
19248 */
19249 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
19250 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
19251 } put_user_catch(err);
19252
19253 if (err)
19254 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
19255 index 7c5a8c3..8a54a1a 100644
19256 --- a/arch/x86/kernel/smpboot.c
19257 +++ b/arch/x86/kernel/smpboot.c
19258 @@ -68,6 +68,8 @@
19259 #include <asm/mwait.h>
19260 #include <asm/apic.h>
19261 #include <asm/io_apic.h>
19262 +#include <asm/i387.h>
19263 +#include <asm/fpu-internal.h>
19264 #include <asm/setup.h>
19265 #include <asm/uv/uv.h>
19266 #include <linux/mc146818rtc.h>
19267 @@ -670,6 +672,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
19268 idle->thread.sp = (unsigned long) (((struct pt_regs *)
19269 (THREAD_SIZE + task_stack_page(idle))) - 1);
19270 per_cpu(current_task, cpu) = idle;
19271 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
19272
19273 #ifdef CONFIG_X86_32
19274 /* Stack for startup_32 can be just as for start_secondary onwards */
19275 @@ -677,11 +680,13 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
19276 #else
19277 clear_tsk_thread_flag(idle, TIF_FORK);
19278 initial_gs = per_cpu_offset(cpu);
19279 - per_cpu(kernel_stack, cpu) =
19280 - (unsigned long)task_stack_page(idle) -
19281 - KERNEL_STACK_OFFSET + THREAD_SIZE;
19282 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
19283 #endif
19284 +
19285 + pax_open_kernel();
19286 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
19287 + pax_close_kernel();
19288 +
19289 initial_code = (unsigned long)start_secondary;
19290 stack_start = idle->thread.sp;
19291
19292 @@ -817,6 +822,15 @@ int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle)
19293
19294 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
19295
19296 +#ifdef CONFIG_PAX_PER_CPU_PGD
19297 + clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
19298 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
19299 + KERNEL_PGD_PTRS);
19300 +#endif
19301 +
19302 + /* the FPU context is blank, nobody can own it */
19303 + __cpu_disable_lazy_restore(cpu);
19304 +
19305 err = do_boot_cpu(apicid, cpu, tidle);
19306 if (err) {
19307 pr_debug("do_boot_cpu failed %d\n", err);
19308 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
19309 index c346d11..d43b163 100644
19310 --- a/arch/x86/kernel/step.c
19311 +++ b/arch/x86/kernel/step.c
19312 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19313 struct desc_struct *desc;
19314 unsigned long base;
19315
19316 - seg &= ~7UL;
19317 + seg >>= 3;
19318
19319 mutex_lock(&child->mm->context.lock);
19320 - if (unlikely((seg >> 3) >= child->mm->context.size))
19321 + if (unlikely(seg >= child->mm->context.size))
19322 addr = -1L; /* bogus selector, access would fault */
19323 else {
19324 desc = child->mm->context.ldt + seg;
19325 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19326 addr += base;
19327 }
19328 mutex_unlock(&child->mm->context.lock);
19329 - }
19330 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
19331 + addr = ktla_ktva(addr);
19332
19333 return addr;
19334 }
19335 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
19336 unsigned char opcode[15];
19337 unsigned long addr = convert_ip_to_linear(child, regs);
19338
19339 + if (addr == -EINVAL)
19340 + return 0;
19341 +
19342 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
19343 for (i = 0; i < copied; i++) {
19344 switch (opcode[i]) {
19345 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
19346 index 0b0cb5f..db6b9ed 100644
19347 --- a/arch/x86/kernel/sys_i386_32.c
19348 +++ b/arch/x86/kernel/sys_i386_32.c
19349 @@ -24,17 +24,224 @@
19350
19351 #include <asm/syscalls.h>
19352
19353 -/*
19354 - * Do a system call from kernel instead of calling sys_execve so we
19355 - * end up with proper pt_regs.
19356 - */
19357 -int kernel_execve(const char *filename,
19358 - const char *const argv[],
19359 - const char *const envp[])
19360 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
19361 {
19362 - long __res;
19363 - asm volatile ("int $0x80"
19364 - : "=a" (__res)
19365 - : "0" (__NR_execve), "b" (filename), "c" (argv), "d" (envp) : "memory");
19366 - return __res;
19367 + unsigned long pax_task_size = TASK_SIZE;
19368 +
19369 +#ifdef CONFIG_PAX_SEGMEXEC
19370 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
19371 + pax_task_size = SEGMEXEC_TASK_SIZE;
19372 +#endif
19373 +
19374 + if (len > pax_task_size || addr > pax_task_size - len)
19375 + return -EINVAL;
19376 +
19377 + return 0;
19378 +}
19379 +
19380 +unsigned long
19381 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
19382 + unsigned long len, unsigned long pgoff, unsigned long flags)
19383 +{
19384 + struct mm_struct *mm = current->mm;
19385 + struct vm_area_struct *vma;
19386 + unsigned long start_addr, pax_task_size = TASK_SIZE;
19387 +
19388 +#ifdef CONFIG_PAX_SEGMEXEC
19389 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19390 + pax_task_size = SEGMEXEC_TASK_SIZE;
19391 +#endif
19392 +
19393 + pax_task_size -= PAGE_SIZE;
19394 +
19395 + if (len > pax_task_size)
19396 + return -ENOMEM;
19397 +
19398 + if (flags & MAP_FIXED)
19399 + return addr;
19400 +
19401 +#ifdef CONFIG_PAX_RANDMMAP
19402 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19403 +#endif
19404 +
19405 + if (addr) {
19406 + addr = PAGE_ALIGN(addr);
19407 + if (pax_task_size - len >= addr) {
19408 + vma = find_vma(mm, addr);
19409 + if (check_heap_stack_gap(vma, addr, len))
19410 + return addr;
19411 + }
19412 + }
19413 + if (len > mm->cached_hole_size) {
19414 + start_addr = addr = mm->free_area_cache;
19415 + } else {
19416 + start_addr = addr = mm->mmap_base;
19417 + mm->cached_hole_size = 0;
19418 + }
19419 +
19420 +#ifdef CONFIG_PAX_PAGEEXEC
19421 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
19422 + start_addr = 0x00110000UL;
19423 +
19424 +#ifdef CONFIG_PAX_RANDMMAP
19425 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19426 + start_addr += mm->delta_mmap & 0x03FFF000UL;
19427 +#endif
19428 +
19429 + if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
19430 + start_addr = addr = mm->mmap_base;
19431 + else
19432 + addr = start_addr;
19433 + }
19434 +#endif
19435 +
19436 +full_search:
19437 + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
19438 + /* At this point: (!vma || addr < vma->vm_end). */
19439 + if (pax_task_size - len < addr) {
19440 + /*
19441 + * Start a new search - just in case we missed
19442 + * some holes.
19443 + */
19444 + if (start_addr != mm->mmap_base) {
19445 + start_addr = addr = mm->mmap_base;
19446 + mm->cached_hole_size = 0;
19447 + goto full_search;
19448 + }
19449 + return -ENOMEM;
19450 + }
19451 + if (check_heap_stack_gap(vma, addr, len))
19452 + break;
19453 + if (addr + mm->cached_hole_size < vma->vm_start)
19454 + mm->cached_hole_size = vma->vm_start - addr;
19455 + addr = vma->vm_end;
19456 + if (mm->start_brk <= addr && addr < mm->mmap_base) {
19457 + start_addr = addr = mm->mmap_base;
19458 + mm->cached_hole_size = 0;
19459 + goto full_search;
19460 + }
19461 + }
19462 +
19463 + /*
19464 + * Remember the place where we stopped the search:
19465 + */
19466 + mm->free_area_cache = addr + len;
19467 + return addr;
19468 +}
19469 +
19470 +unsigned long
19471 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19472 + const unsigned long len, const unsigned long pgoff,
19473 + const unsigned long flags)
19474 +{
19475 + struct vm_area_struct *vma;
19476 + struct mm_struct *mm = current->mm;
19477 + unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
19478 +
19479 +#ifdef CONFIG_PAX_SEGMEXEC
19480 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19481 + pax_task_size = SEGMEXEC_TASK_SIZE;
19482 +#endif
19483 +
19484 + pax_task_size -= PAGE_SIZE;
19485 +
19486 + /* requested length too big for entire address space */
19487 + if (len > pax_task_size)
19488 + return -ENOMEM;
19489 +
19490 + if (flags & MAP_FIXED)
19491 + return addr;
19492 +
19493 +#ifdef CONFIG_PAX_PAGEEXEC
19494 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
19495 + goto bottomup;
19496 +#endif
19497 +
19498 +#ifdef CONFIG_PAX_RANDMMAP
19499 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19500 +#endif
19501 +
19502 + /* requesting a specific address */
19503 + if (addr) {
19504 + addr = PAGE_ALIGN(addr);
19505 + if (pax_task_size - len >= addr) {
19506 + vma = find_vma(mm, addr);
19507 + if (check_heap_stack_gap(vma, addr, len))
19508 + return addr;
19509 + }
19510 + }
19511 +
19512 + /* check if free_area_cache is useful for us */
19513 + if (len <= mm->cached_hole_size) {
19514 + mm->cached_hole_size = 0;
19515 + mm->free_area_cache = mm->mmap_base;
19516 + }
19517 +
19518 + /* either no address requested or can't fit in requested address hole */
19519 + addr = mm->free_area_cache;
19520 +
19521 + /* make sure it can fit in the remaining address space */
19522 + if (addr > len) {
19523 + vma = find_vma(mm, addr-len);
19524 + if (check_heap_stack_gap(vma, addr - len, len))
19525 + /* remember the address as a hint for next time */
19526 + return (mm->free_area_cache = addr-len);
19527 + }
19528 +
19529 + if (mm->mmap_base < len)
19530 + goto bottomup;
19531 +
19532 + addr = mm->mmap_base-len;
19533 +
19534 + do {
19535 + /*
19536 + * Lookup failure means no vma is above this address,
19537 + * else if new region fits below vma->vm_start,
19538 + * return with success:
19539 + */
19540 + vma = find_vma(mm, addr);
19541 + if (check_heap_stack_gap(vma, addr, len))
19542 + /* remember the address as a hint for next time */
19543 + return (mm->free_area_cache = addr);
19544 +
19545 + /* remember the largest hole we saw so far */
19546 + if (addr + mm->cached_hole_size < vma->vm_start)
19547 + mm->cached_hole_size = vma->vm_start - addr;
19548 +
19549 + /* try just below the current vma->vm_start */
19550 + addr = skip_heap_stack_gap(vma, len);
19551 + } while (!IS_ERR_VALUE(addr));
19552 +
19553 +bottomup:
19554 + /*
19555 + * A failed mmap() very likely causes application failure,
19556 + * so fall back to the bottom-up function here. This scenario
19557 + * can happen with large stack limits and large mmap()
19558 + * allocations.
19559 + */
19560 +
19561 +#ifdef CONFIG_PAX_SEGMEXEC
19562 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19563 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
19564 + else
19565 +#endif
19566 +
19567 + mm->mmap_base = TASK_UNMAPPED_BASE;
19568 +
19569 +#ifdef CONFIG_PAX_RANDMMAP
19570 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19571 + mm->mmap_base += mm->delta_mmap;
19572 +#endif
19573 +
19574 + mm->free_area_cache = mm->mmap_base;
19575 + mm->cached_hole_size = ~0UL;
19576 + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19577 + /*
19578 + * Restore the topdown base:
19579 + */
19580 + mm->mmap_base = base;
19581 + mm->free_area_cache = base;
19582 + mm->cached_hole_size = ~0UL;
19583 +
19584 + return addr;
19585 }
19586 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
19587 index b4d3c39..82bb73b 100644
19588 --- a/arch/x86/kernel/sys_x86_64.c
19589 +++ b/arch/x86/kernel/sys_x86_64.c
19590 @@ -95,8 +95,8 @@ out:
19591 return error;
19592 }
19593
19594 -static void find_start_end(unsigned long flags, unsigned long *begin,
19595 - unsigned long *end)
19596 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
19597 + unsigned long *begin, unsigned long *end)
19598 {
19599 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
19600 unsigned long new_begin;
19601 @@ -115,7 +115,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
19602 *begin = new_begin;
19603 }
19604 } else {
19605 - *begin = TASK_UNMAPPED_BASE;
19606 + *begin = mm->mmap_base;
19607 *end = TASK_SIZE;
19608 }
19609 }
19610 @@ -132,16 +132,19 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
19611 if (flags & MAP_FIXED)
19612 return addr;
19613
19614 - find_start_end(flags, &begin, &end);
19615 + find_start_end(mm, flags, &begin, &end);
19616
19617 if (len > end)
19618 return -ENOMEM;
19619
19620 +#ifdef CONFIG_PAX_RANDMMAP
19621 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19622 +#endif
19623 +
19624 if (addr) {
19625 addr = PAGE_ALIGN(addr);
19626 vma = find_vma(mm, addr);
19627 - if (end - len >= addr &&
19628 - (!vma || addr + len <= vma->vm_start))
19629 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
19630 return addr;
19631 }
19632 if (((flags & MAP_32BIT) || test_thread_flag(TIF_ADDR32))
19633 @@ -172,7 +175,7 @@ full_search:
19634 }
19635 return -ENOMEM;
19636 }
19637 - if (!vma || addr + len <= vma->vm_start) {
19638 + if (check_heap_stack_gap(vma, addr, len)) {
19639 /*
19640 * Remember the place where we stopped the search:
19641 */
19642 @@ -195,7 +198,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19643 {
19644 struct vm_area_struct *vma;
19645 struct mm_struct *mm = current->mm;
19646 - unsigned long addr = addr0, start_addr;
19647 + unsigned long base = mm->mmap_base, addr = addr0, start_addr;
19648
19649 /* requested length too big for entire address space */
19650 if (len > TASK_SIZE)
19651 @@ -208,13 +211,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19652 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
19653 goto bottomup;
19654
19655 +#ifdef CONFIG_PAX_RANDMMAP
19656 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19657 +#endif
19658 +
19659 /* requesting a specific address */
19660 if (addr) {
19661 addr = PAGE_ALIGN(addr);
19662 - vma = find_vma(mm, addr);
19663 - if (TASK_SIZE - len >= addr &&
19664 - (!vma || addr + len <= vma->vm_start))
19665 - return addr;
19666 + if (TASK_SIZE - len >= addr) {
19667 + vma = find_vma(mm, addr);
19668 + if (check_heap_stack_gap(vma, addr, len))
19669 + return addr;
19670 + }
19671 }
19672
19673 /* check if free_area_cache is useful for us */
19674 @@ -240,7 +248,7 @@ try_again:
19675 * return with success:
19676 */
19677 vma = find_vma(mm, addr);
19678 - if (!vma || addr+len <= vma->vm_start)
19679 + if (check_heap_stack_gap(vma, addr, len))
19680 /* remember the address as a hint for next time */
19681 return mm->free_area_cache = addr;
19682
19683 @@ -249,8 +257,8 @@ try_again:
19684 mm->cached_hole_size = vma->vm_start - addr;
19685
19686 /* try just below the current vma->vm_start */
19687 - addr = vma->vm_start-len;
19688 - } while (len < vma->vm_start);
19689 + addr = skip_heap_stack_gap(vma, len);
19690 + } while (!IS_ERR_VALUE(addr));
19691
19692 fail:
19693 /*
19694 @@ -270,13 +278,21 @@ bottomup:
19695 * can happen with large stack limits and large mmap()
19696 * allocations.
19697 */
19698 + mm->mmap_base = TASK_UNMAPPED_BASE;
19699 +
19700 +#ifdef CONFIG_PAX_RANDMMAP
19701 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19702 + mm->mmap_base += mm->delta_mmap;
19703 +#endif
19704 +
19705 + mm->free_area_cache = mm->mmap_base;
19706 mm->cached_hole_size = ~0UL;
19707 - mm->free_area_cache = TASK_UNMAPPED_BASE;
19708 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19709 /*
19710 * Restore the topdown base:
19711 */
19712 - mm->free_area_cache = mm->mmap_base;
19713 + mm->mmap_base = base;
19714 + mm->free_area_cache = base;
19715 mm->cached_hole_size = ~0UL;
19716
19717 return addr;
19718 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
19719 index f84fe00..93fe08f 100644
19720 --- a/arch/x86/kernel/tboot.c
19721 +++ b/arch/x86/kernel/tboot.c
19722 @@ -220,7 +220,7 @@ static int tboot_setup_sleep(void)
19723
19724 void tboot_shutdown(u32 shutdown_type)
19725 {
19726 - void (*shutdown)(void);
19727 + void (* __noreturn shutdown)(void);
19728
19729 if (!tboot_enabled())
19730 return;
19731 @@ -242,7 +242,7 @@ void tboot_shutdown(u32 shutdown_type)
19732
19733 switch_to_tboot_pt();
19734
19735 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
19736 + shutdown = (void *)tboot->shutdown_entry;
19737 shutdown();
19738
19739 /* should not reach here */
19740 @@ -300,7 +300,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
19741 return 0;
19742 }
19743
19744 -static atomic_t ap_wfs_count;
19745 +static atomic_unchecked_t ap_wfs_count;
19746
19747 static int tboot_wait_for_aps(int num_aps)
19748 {
19749 @@ -324,9 +324,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
19750 {
19751 switch (action) {
19752 case CPU_DYING:
19753 - atomic_inc(&ap_wfs_count);
19754 + atomic_inc_unchecked(&ap_wfs_count);
19755 if (num_online_cpus() == 1)
19756 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
19757 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
19758 return NOTIFY_BAD;
19759 break;
19760 }
19761 @@ -345,7 +345,7 @@ static __init int tboot_late_init(void)
19762
19763 tboot_create_trampoline();
19764
19765 - atomic_set(&ap_wfs_count, 0);
19766 + atomic_set_unchecked(&ap_wfs_count, 0);
19767 register_hotcpu_notifier(&tboot_cpu_notifier);
19768
19769 acpi_os_set_prepare_sleep(&tboot_sleep);
19770 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
19771 index 24d3c91..d06b473 100644
19772 --- a/arch/x86/kernel/time.c
19773 +++ b/arch/x86/kernel/time.c
19774 @@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
19775 {
19776 unsigned long pc = instruction_pointer(regs);
19777
19778 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
19779 + if (!user_mode(regs) && in_lock_functions(pc)) {
19780 #ifdef CONFIG_FRAME_POINTER
19781 - return *(unsigned long *)(regs->bp + sizeof(long));
19782 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
19783 #else
19784 unsigned long *sp =
19785 (unsigned long *)kernel_stack_pointer(regs);
19786 @@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
19787 * or above a saved flags. Eflags has bits 22-31 zero,
19788 * kernel addresses don't.
19789 */
19790 +
19791 +#ifdef CONFIG_PAX_KERNEXEC
19792 + return ktla_ktva(sp[0]);
19793 +#else
19794 if (sp[0] >> 22)
19795 return sp[0];
19796 if (sp[1] >> 22)
19797 return sp[1];
19798 #endif
19799 +
19800 +#endif
19801 }
19802 return pc;
19803 }
19804 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
19805 index 9d9d2f9..cad418a 100644
19806 --- a/arch/x86/kernel/tls.c
19807 +++ b/arch/x86/kernel/tls.c
19808 @@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
19809 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
19810 return -EINVAL;
19811
19812 +#ifdef CONFIG_PAX_SEGMEXEC
19813 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
19814 + return -EINVAL;
19815 +#endif
19816 +
19817 set_tls_desc(p, idx, &info, 1);
19818
19819 return 0;
19820 @@ -204,7 +209,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
19821
19822 if (kbuf)
19823 info = kbuf;
19824 - else if (__copy_from_user(infobuf, ubuf, count))
19825 + else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
19826 return -EFAULT;
19827 else
19828 info = infobuf;
19829 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
19830 index b481341..5918bbe 100644
19831 --- a/arch/x86/kernel/traps.c
19832 +++ b/arch/x86/kernel/traps.c
19833 @@ -70,12 +70,6 @@ asmlinkage int system_call(void);
19834
19835 /* Do we ignore FPU interrupts ? */
19836 char ignore_fpu_irq;
19837 -
19838 -/*
19839 - * The IDT has to be page-aligned to simplify the Pentium
19840 - * F0 0F bug workaround.
19841 - */
19842 -gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
19843 #endif
19844
19845 DECLARE_BITMAP(used_vectors, NR_VECTORS);
19846 @@ -108,13 +102,13 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
19847 }
19848
19849 static void __kprobes
19850 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19851 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
19852 long error_code, siginfo_t *info)
19853 {
19854 struct task_struct *tsk = current;
19855
19856 #ifdef CONFIG_X86_32
19857 - if (regs->flags & X86_VM_MASK) {
19858 + if (v8086_mode(regs)) {
19859 /*
19860 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
19861 * On nmi (interrupt 2), do_trap should not be called.
19862 @@ -125,7 +119,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19863 }
19864 #endif
19865
19866 - if (!user_mode(regs))
19867 + if (!user_mode_novm(regs))
19868 goto kernel_trap;
19869
19870 #ifdef CONFIG_X86_32
19871 @@ -147,7 +141,7 @@ trap_signal:
19872 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
19873 printk_ratelimit()) {
19874 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
19875 - tsk->comm, tsk->pid, str,
19876 + tsk->comm, task_pid_nr(tsk), str,
19877 regs->ip, regs->sp, error_code);
19878 print_vma_addr(" in ", regs->ip);
19879 pr_cont("\n");
19880 @@ -164,8 +158,20 @@ kernel_trap:
19881 if (!fixup_exception(regs)) {
19882 tsk->thread.error_code = error_code;
19883 tsk->thread.trap_nr = trapnr;
19884 +
19885 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19886 + if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
19887 + str = "PAX: suspicious stack segment fault";
19888 +#endif
19889 +
19890 die(str, regs, error_code);
19891 }
19892 +
19893 +#ifdef CONFIG_PAX_REFCOUNT
19894 + if (trapnr == 4)
19895 + pax_report_refcount_overflow(regs);
19896 +#endif
19897 +
19898 return;
19899
19900 #ifdef CONFIG_X86_32
19901 @@ -258,14 +264,30 @@ do_general_protection(struct pt_regs *regs, long error_code)
19902 conditional_sti(regs);
19903
19904 #ifdef CONFIG_X86_32
19905 - if (regs->flags & X86_VM_MASK)
19906 + if (v8086_mode(regs))
19907 goto gp_in_vm86;
19908 #endif
19909
19910 tsk = current;
19911 - if (!user_mode(regs))
19912 + if (!user_mode_novm(regs))
19913 goto gp_in_kernel;
19914
19915 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
19916 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
19917 + struct mm_struct *mm = tsk->mm;
19918 + unsigned long limit;
19919 +
19920 + down_write(&mm->mmap_sem);
19921 + limit = mm->context.user_cs_limit;
19922 + if (limit < TASK_SIZE) {
19923 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
19924 + up_write(&mm->mmap_sem);
19925 + return;
19926 + }
19927 + up_write(&mm->mmap_sem);
19928 + }
19929 +#endif
19930 +
19931 tsk->thread.error_code = error_code;
19932 tsk->thread.trap_nr = X86_TRAP_GP;
19933
19934 @@ -297,6 +319,13 @@ gp_in_kernel:
19935 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
19936 X86_TRAP_GP, SIGSEGV) == NOTIFY_STOP)
19937 return;
19938 +
19939 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19940 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
19941 + die("PAX: suspicious general protection fault", regs, error_code);
19942 + else
19943 +#endif
19944 +
19945 die("general protection fault", regs, error_code);
19946 }
19947
19948 @@ -432,7 +461,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19949 /* It's safe to allow irq's after DR6 has been saved */
19950 preempt_conditional_sti(regs);
19951
19952 - if (regs->flags & X86_VM_MASK) {
19953 + if (v8086_mode(regs)) {
19954 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
19955 X86_TRAP_DB);
19956 preempt_conditional_cli(regs);
19957 @@ -447,7 +476,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19958 * We already checked v86 mode above, so we can check for kernel mode
19959 * by just checking the CPL of CS.
19960 */
19961 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
19962 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
19963 tsk->thread.debugreg6 &= ~DR_STEP;
19964 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
19965 regs->flags &= ~X86_EFLAGS_TF;
19966 @@ -478,7 +507,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
19967 return;
19968 conditional_sti(regs);
19969
19970 - if (!user_mode_vm(regs))
19971 + if (!user_mode(regs))
19972 {
19973 if (!fixup_exception(regs)) {
19974 task->thread.error_code = error_code;
19975 diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
19976 index 36fd420..7e5892d 100644
19977 --- a/arch/x86/kernel/uprobes.c
19978 +++ b/arch/x86/kernel/uprobes.c
19979 @@ -607,7 +607,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
19980 int ret = NOTIFY_DONE;
19981
19982 /* We are only interested in userspace traps */
19983 - if (regs && !user_mode_vm(regs))
19984 + if (regs && !user_mode(regs))
19985 return NOTIFY_DONE;
19986
19987 switch (val) {
19988 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
19989 index b9242ba..50c5edd 100644
19990 --- a/arch/x86/kernel/verify_cpu.S
19991 +++ b/arch/x86/kernel/verify_cpu.S
19992 @@ -20,6 +20,7 @@
19993 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
19994 * arch/x86/kernel/trampoline_64.S: secondary processor verification
19995 * arch/x86/kernel/head_32.S: processor startup
19996 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
19997 *
19998 * verify_cpu, returns the status of longmode and SSE in register %eax.
19999 * 0: Success 1: Failure
20000 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
20001 index 54abcc0..eb6c848 100644
20002 --- a/arch/x86/kernel/vm86_32.c
20003 +++ b/arch/x86/kernel/vm86_32.c
20004 @@ -43,6 +43,7 @@
20005 #include <linux/ptrace.h>
20006 #include <linux/audit.h>
20007 #include <linux/stddef.h>
20008 +#include <linux/grsecurity.h>
20009
20010 #include <asm/uaccess.h>
20011 #include <asm/io.h>
20012 @@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
20013 do_exit(SIGSEGV);
20014 }
20015
20016 - tss = &per_cpu(init_tss, get_cpu());
20017 + tss = init_tss + get_cpu();
20018 current->thread.sp0 = current->thread.saved_sp0;
20019 current->thread.sysenter_cs = __KERNEL_CS;
20020 load_sp0(tss, &current->thread);
20021 @@ -212,6 +213,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
20022 struct task_struct *tsk;
20023 int tmp, ret = -EPERM;
20024
20025 +#ifdef CONFIG_GRKERNSEC_VM86
20026 + if (!capable(CAP_SYS_RAWIO)) {
20027 + gr_handle_vm86();
20028 + goto out;
20029 + }
20030 +#endif
20031 +
20032 tsk = current;
20033 if (tsk->thread.saved_sp0)
20034 goto out;
20035 @@ -242,6 +250,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
20036 int tmp, ret;
20037 struct vm86plus_struct __user *v86;
20038
20039 +#ifdef CONFIG_GRKERNSEC_VM86
20040 + if (!capable(CAP_SYS_RAWIO)) {
20041 + gr_handle_vm86();
20042 + ret = -EPERM;
20043 + goto out;
20044 + }
20045 +#endif
20046 +
20047 tsk = current;
20048 switch (cmd) {
20049 case VM86_REQUEST_IRQ:
20050 @@ -328,7 +344,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
20051 tsk->thread.saved_fs = info->regs32->fs;
20052 tsk->thread.saved_gs = get_user_gs(info->regs32);
20053
20054 - tss = &per_cpu(init_tss, get_cpu());
20055 + tss = init_tss + get_cpu();
20056 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
20057 if (cpu_has_sep)
20058 tsk->thread.sysenter_cs = 0;
20059 @@ -535,7 +551,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
20060 goto cannot_handle;
20061 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
20062 goto cannot_handle;
20063 - intr_ptr = (unsigned long __user *) (i << 2);
20064 + intr_ptr = (__force unsigned long __user *) (i << 2);
20065 if (get_user(segoffs, intr_ptr))
20066 goto cannot_handle;
20067 if ((segoffs >> 16) == BIOSSEG)
20068 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
20069 index 22a1530..8fbaaad 100644
20070 --- a/arch/x86/kernel/vmlinux.lds.S
20071 +++ b/arch/x86/kernel/vmlinux.lds.S
20072 @@ -26,6 +26,13 @@
20073 #include <asm/page_types.h>
20074 #include <asm/cache.h>
20075 #include <asm/boot.h>
20076 +#include <asm/segment.h>
20077 +
20078 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20079 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
20080 +#else
20081 +#define __KERNEL_TEXT_OFFSET 0
20082 +#endif
20083
20084 #undef i386 /* in case the preprocessor is a 32bit one */
20085
20086 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
20087
20088 PHDRS {
20089 text PT_LOAD FLAGS(5); /* R_E */
20090 +#ifdef CONFIG_X86_32
20091 + module PT_LOAD FLAGS(5); /* R_E */
20092 +#endif
20093 +#ifdef CONFIG_XEN
20094 + rodata PT_LOAD FLAGS(5); /* R_E */
20095 +#else
20096 + rodata PT_LOAD FLAGS(4); /* R__ */
20097 +#endif
20098 data PT_LOAD FLAGS(6); /* RW_ */
20099 -#ifdef CONFIG_X86_64
20100 + init.begin PT_LOAD FLAGS(6); /* RW_ */
20101 #ifdef CONFIG_SMP
20102 percpu PT_LOAD FLAGS(6); /* RW_ */
20103 #endif
20104 + text.init PT_LOAD FLAGS(5); /* R_E */
20105 + text.exit PT_LOAD FLAGS(5); /* R_E */
20106 init PT_LOAD FLAGS(7); /* RWE */
20107 -#endif
20108 note PT_NOTE FLAGS(0); /* ___ */
20109 }
20110
20111 SECTIONS
20112 {
20113 #ifdef CONFIG_X86_32
20114 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
20115 - phys_startup_32 = startup_32 - LOAD_OFFSET;
20116 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
20117 #else
20118 - . = __START_KERNEL;
20119 - phys_startup_64 = startup_64 - LOAD_OFFSET;
20120 + . = __START_KERNEL;
20121 #endif
20122
20123 /* Text and read-only data */
20124 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
20125 - _text = .;
20126 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20127 /* bootstrapping code */
20128 +#ifdef CONFIG_X86_32
20129 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20130 +#else
20131 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20132 +#endif
20133 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20134 + _text = .;
20135 HEAD_TEXT
20136 #ifdef CONFIG_X86_32
20137 . = ALIGN(PAGE_SIZE);
20138 @@ -108,13 +128,48 @@ SECTIONS
20139 IRQENTRY_TEXT
20140 *(.fixup)
20141 *(.gnu.warning)
20142 - /* End of text section */
20143 - _etext = .;
20144 } :text = 0x9090
20145
20146 - NOTES :text :note
20147 + . += __KERNEL_TEXT_OFFSET;
20148
20149 - EXCEPTION_TABLE(16) :text = 0x9090
20150 +#ifdef CONFIG_X86_32
20151 + . = ALIGN(PAGE_SIZE);
20152 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
20153 +
20154 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
20155 + MODULES_EXEC_VADDR = .;
20156 + BYTE(0)
20157 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
20158 + . = ALIGN(HPAGE_SIZE) - 1;
20159 + MODULES_EXEC_END = .;
20160 +#endif
20161 +
20162 + } :module
20163 +#endif
20164 +
20165 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
20166 + /* End of text section */
20167 + BYTE(0)
20168 + _etext = . - __KERNEL_TEXT_OFFSET;
20169 + }
20170 +
20171 +#ifdef CONFIG_X86_32
20172 + . = ALIGN(PAGE_SIZE);
20173 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
20174 + *(.idt)
20175 + . = ALIGN(PAGE_SIZE);
20176 + *(.empty_zero_page)
20177 + *(.initial_pg_fixmap)
20178 + *(.initial_pg_pmd)
20179 + *(.initial_page_table)
20180 + *(.swapper_pg_dir)
20181 + } :rodata
20182 +#endif
20183 +
20184 + . = ALIGN(PAGE_SIZE);
20185 + NOTES :rodata :note
20186 +
20187 + EXCEPTION_TABLE(16) :rodata
20188
20189 #if defined(CONFIG_DEBUG_RODATA)
20190 /* .text should occupy whole number of pages */
20191 @@ -126,16 +181,20 @@ SECTIONS
20192
20193 /* Data */
20194 .data : AT(ADDR(.data) - LOAD_OFFSET) {
20195 +
20196 +#ifdef CONFIG_PAX_KERNEXEC
20197 + . = ALIGN(HPAGE_SIZE);
20198 +#else
20199 + . = ALIGN(PAGE_SIZE);
20200 +#endif
20201 +
20202 /* Start of data section */
20203 _sdata = .;
20204
20205 /* init_task */
20206 INIT_TASK_DATA(THREAD_SIZE)
20207
20208 -#ifdef CONFIG_X86_32
20209 - /* 32 bit has nosave before _edata */
20210 NOSAVE_DATA
20211 -#endif
20212
20213 PAGE_ALIGNED_DATA(PAGE_SIZE)
20214
20215 @@ -176,12 +235,19 @@ SECTIONS
20216 #endif /* CONFIG_X86_64 */
20217
20218 /* Init code and data - will be freed after init */
20219 - . = ALIGN(PAGE_SIZE);
20220 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
20221 + BYTE(0)
20222 +
20223 +#ifdef CONFIG_PAX_KERNEXEC
20224 + . = ALIGN(HPAGE_SIZE);
20225 +#else
20226 + . = ALIGN(PAGE_SIZE);
20227 +#endif
20228 +
20229 __init_begin = .; /* paired with __init_end */
20230 - }
20231 + } :init.begin
20232
20233 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
20234 +#ifdef CONFIG_SMP
20235 /*
20236 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
20237 * output PHDR, so the next output section - .init.text - should
20238 @@ -190,12 +256,27 @@ SECTIONS
20239 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
20240 #endif
20241
20242 - INIT_TEXT_SECTION(PAGE_SIZE)
20243 -#ifdef CONFIG_X86_64
20244 - :init
20245 -#endif
20246 + . = ALIGN(PAGE_SIZE);
20247 + init_begin = .;
20248 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
20249 + VMLINUX_SYMBOL(_sinittext) = .;
20250 + INIT_TEXT
20251 + VMLINUX_SYMBOL(_einittext) = .;
20252 + . = ALIGN(PAGE_SIZE);
20253 + } :text.init
20254
20255 - INIT_DATA_SECTION(16)
20256 + /*
20257 + * .exit.text is discard at runtime, not link time, to deal with
20258 + * references from .altinstructions and .eh_frame
20259 + */
20260 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20261 + EXIT_TEXT
20262 + . = ALIGN(16);
20263 + } :text.exit
20264 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
20265 +
20266 + . = ALIGN(PAGE_SIZE);
20267 + INIT_DATA_SECTION(16) :init
20268
20269 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
20270 __x86_cpu_dev_start = .;
20271 @@ -257,19 +338,12 @@ SECTIONS
20272 }
20273
20274 . = ALIGN(8);
20275 - /*
20276 - * .exit.text is discard at runtime, not link time, to deal with
20277 - * references from .altinstructions and .eh_frame
20278 - */
20279 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
20280 - EXIT_TEXT
20281 - }
20282
20283 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
20284 EXIT_DATA
20285 }
20286
20287 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
20288 +#ifndef CONFIG_SMP
20289 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
20290 #endif
20291
20292 @@ -288,16 +362,10 @@ SECTIONS
20293 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
20294 __smp_locks = .;
20295 *(.smp_locks)
20296 - . = ALIGN(PAGE_SIZE);
20297 __smp_locks_end = .;
20298 + . = ALIGN(PAGE_SIZE);
20299 }
20300
20301 -#ifdef CONFIG_X86_64
20302 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
20303 - NOSAVE_DATA
20304 - }
20305 -#endif
20306 -
20307 /* BSS */
20308 . = ALIGN(PAGE_SIZE);
20309 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
20310 @@ -313,6 +381,7 @@ SECTIONS
20311 __brk_base = .;
20312 . += 64 * 1024; /* 64k alignment slop space */
20313 *(.brk_reservation) /* areas brk users have reserved */
20314 + . = ALIGN(HPAGE_SIZE);
20315 __brk_limit = .;
20316 }
20317
20318 @@ -339,13 +408,12 @@ SECTIONS
20319 * for the boot processor.
20320 */
20321 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
20322 -INIT_PER_CPU(gdt_page);
20323 INIT_PER_CPU(irq_stack_union);
20324
20325 /*
20326 * Build-time check on the image size:
20327 */
20328 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
20329 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
20330 "kernel image bigger than KERNEL_IMAGE_SIZE");
20331
20332 #ifdef CONFIG_SMP
20333 diff --git a/arch/x86/kernel/vsmp_64.c b/arch/x86/kernel/vsmp_64.c
20334 index 992f890..fc38904 100644
20335 --- a/arch/x86/kernel/vsmp_64.c
20336 +++ b/arch/x86/kernel/vsmp_64.c
20337 @@ -217,8 +217,8 @@ static void fill_vector_allocation_domain(int cpu, struct cpumask *retmask,
20338 static void vsmp_apic_post_init(void)
20339 {
20340 /* need to update phys_pkg_id */
20341 - apic->phys_pkg_id = apicid_phys_pkg_id;
20342 - apic->vector_allocation_domain = fill_vector_allocation_domain;
20343 + *(void **)&apic->phys_pkg_id = apicid_phys_pkg_id;
20344 + *(void **)&apic->vector_allocation_domain = fill_vector_allocation_domain;
20345 }
20346
20347 void __init vsmp_init(void)
20348 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
20349 index 8d141b3..40a0fe4 100644
20350 --- a/arch/x86/kernel/vsyscall_64.c
20351 +++ b/arch/x86/kernel/vsyscall_64.c
20352 @@ -56,15 +56,13 @@
20353 DEFINE_VVAR(int, vgetcpu_mode);
20354 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
20355
20356 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
20357 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
20358
20359 static int __init vsyscall_setup(char *str)
20360 {
20361 if (str) {
20362 if (!strcmp("emulate", str))
20363 vsyscall_mode = EMULATE;
20364 - else if (!strcmp("native", str))
20365 - vsyscall_mode = NATIVE;
20366 else if (!strcmp("none", str))
20367 vsyscall_mode = NONE;
20368 else
20369 @@ -306,8 +304,7 @@ done:
20370 return true;
20371
20372 sigsegv:
20373 - force_sig(SIGSEGV, current);
20374 - return true;
20375 + do_group_exit(SIGKILL);
20376 }
20377
20378 /*
20379 @@ -360,10 +357,7 @@ void __init map_vsyscall(void)
20380 extern char __vvar_page;
20381 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
20382
20383 - __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
20384 - vsyscall_mode == NATIVE
20385 - ? PAGE_KERNEL_VSYSCALL
20386 - : PAGE_KERNEL_VVAR);
20387 + __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
20388 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
20389 (unsigned long)VSYSCALL_START);
20390
20391 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
20392 index 6020f6f..bedd6e3 100644
20393 --- a/arch/x86/kernel/x8664_ksyms_64.c
20394 +++ b/arch/x86/kernel/x8664_ksyms_64.c
20395 @@ -30,8 +30,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
20396 EXPORT_SYMBOL(copy_user_generic_unrolled);
20397 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
20398 EXPORT_SYMBOL(__copy_user_nocache);
20399 -EXPORT_SYMBOL(_copy_from_user);
20400 -EXPORT_SYMBOL(_copy_to_user);
20401
20402 EXPORT_SYMBOL(copy_page);
20403 EXPORT_SYMBOL(clear_page);
20404 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
20405 index 3d3e207..316a7e0 100644
20406 --- a/arch/x86/kernel/xsave.c
20407 +++ b/arch/x86/kernel/xsave.c
20408 @@ -132,7 +132,7 @@ int check_for_xstate(struct i387_fxsave_struct __user *buf,
20409 fx_sw_user->xstate_size > fx_sw_user->extended_size)
20410 return -EINVAL;
20411
20412 - err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
20413 + err = __get_user(magic2, (__u32 __user *) (((void __user *)fpstate) +
20414 fx_sw_user->extended_size -
20415 FP_XSTATE_MAGIC2_SIZE));
20416 if (err)
20417 @@ -268,7 +268,7 @@ fx_only:
20418 * the other extended state.
20419 */
20420 xrstor_state(init_xstate_buf, pcntxt_mask & ~XSTATE_FPSSE);
20421 - return fxrstor_checking((__force struct i387_fxsave_struct *)buf);
20422 + return fxrstor_checking((struct i387_fxsave_struct __user *)buf);
20423 }
20424
20425 /*
20426 @@ -297,8 +297,7 @@ int restore_i387_xstate(void __user *buf)
20427 if (use_xsave())
20428 err = restore_user_xstate(buf);
20429 else
20430 - err = fxrstor_checking((__force struct i387_fxsave_struct *)
20431 - buf);
20432 + err = fxrstor_checking((struct i387_fxsave_struct __user *)buf);
20433 if (unlikely(err)) {
20434 /*
20435 * Encountered an error while doing the restore from the
20436 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
20437 index 0595f13..b544fa3 100644
20438 --- a/arch/x86/kvm/cpuid.c
20439 +++ b/arch/x86/kvm/cpuid.c
20440 @@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
20441 struct kvm_cpuid2 *cpuid,
20442 struct kvm_cpuid_entry2 __user *entries)
20443 {
20444 - int r;
20445 + int r, i;
20446
20447 r = -E2BIG;
20448 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
20449 goto out;
20450 r = -EFAULT;
20451 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
20452 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20453 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20454 goto out;
20455 + for (i = 0; i < cpuid->nent; ++i) {
20456 + struct kvm_cpuid_entry2 cpuid_entry;
20457 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
20458 + goto out;
20459 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
20460 + }
20461 vcpu->arch.cpuid_nent = cpuid->nent;
20462 kvm_apic_set_version(vcpu);
20463 kvm_x86_ops->cpuid_update(vcpu);
20464 @@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
20465 struct kvm_cpuid2 *cpuid,
20466 struct kvm_cpuid_entry2 __user *entries)
20467 {
20468 - int r;
20469 + int r, i;
20470
20471 r = -E2BIG;
20472 if (cpuid->nent < vcpu->arch.cpuid_nent)
20473 goto out;
20474 r = -EFAULT;
20475 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
20476 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20477 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20478 goto out;
20479 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
20480 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
20481 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
20482 + goto out;
20483 + }
20484 return 0;
20485
20486 out:
20487 diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
20488 index a3b57a2..e8f3324 100644
20489 --- a/arch/x86/kvm/emulate.c
20490 +++ b/arch/x86/kvm/emulate.c
20491 @@ -256,6 +256,7 @@ struct gprefix {
20492
20493 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
20494 do { \
20495 + unsigned long _tmp; \
20496 __asm__ __volatile__ ( \
20497 _PRE_EFLAGS("0", "4", "2") \
20498 _op _suffix " %"_x"3,%1; " \
20499 @@ -270,8 +271,6 @@ struct gprefix {
20500 /* Raw emulation: instruction has two explicit operands. */
20501 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
20502 do { \
20503 - unsigned long _tmp; \
20504 - \
20505 switch ((ctxt)->dst.bytes) { \
20506 case 2: \
20507 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
20508 @@ -287,7 +286,6 @@ struct gprefix {
20509
20510 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
20511 do { \
20512 - unsigned long _tmp; \
20513 switch ((ctxt)->dst.bytes) { \
20514 case 1: \
20515 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
20516 @@ -390,8 +388,7 @@ struct gprefix {
20517 _ASM_EXTABLE(1b, 3b) \
20518 : "=m" ((ctxt)->eflags), "=&r" (_tmp), \
20519 "+a" (*rax), "+d" (*rdx), "+qm"(_ex) \
20520 - : "i" (EFLAGS_MASK), "m" ((ctxt)->src.val), \
20521 - "a" (*rax), "d" (*rdx)); \
20522 + : "i" (EFLAGS_MASK), "m" ((ctxt)->src.val)); \
20523 } while (0)
20524
20525 /* instruction has only one source operand, destination is implicit (e.g. mul, div, imul, idiv) */
20526 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
20527 index ce87878..ab48aa3 100644
20528 --- a/arch/x86/kvm/lapic.c
20529 +++ b/arch/x86/kvm/lapic.c
20530 @@ -54,7 +54,7 @@
20531 #define APIC_BUS_CYCLE_NS 1
20532
20533 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
20534 -#define apic_debug(fmt, arg...)
20535 +#define apic_debug(fmt, arg...) do {} while (0)
20536
20537 #define APIC_LVT_NUM 6
20538 /* 14 is the version for Xeon and Pentium 8.4.8*/
20539 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
20540 index bb7cf01..0348a05 100644
20541 --- a/arch/x86/kvm/paging_tmpl.h
20542 +++ b/arch/x86/kvm/paging_tmpl.h
20543 @@ -196,7 +196,7 @@ retry_walk:
20544 if (unlikely(kvm_is_error_hva(host_addr)))
20545 goto error;
20546
20547 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
20548 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
20549 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
20550 goto error;
20551
20552 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
20553 index baead95..90feeb4 100644
20554 --- a/arch/x86/kvm/svm.c
20555 +++ b/arch/x86/kvm/svm.c
20556 @@ -3516,7 +3516,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
20557 int cpu = raw_smp_processor_id();
20558
20559 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
20560 +
20561 + pax_open_kernel();
20562 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
20563 + pax_close_kernel();
20564 +
20565 load_TR_desc();
20566 }
20567
20568 @@ -3894,6 +3898,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
20569 #endif
20570 #endif
20571
20572 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20573 + __set_fs(current_thread_info()->addr_limit);
20574 +#endif
20575 +
20576 reload_tss(vcpu);
20577
20578 local_irq_disable();
20579 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
20580 index ff66a3b..48ad872 100644
20581 --- a/arch/x86/kvm/vmx.c
20582 +++ b/arch/x86/kvm/vmx.c
20583 @@ -1331,7 +1331,11 @@ static void reload_tss(void)
20584 struct desc_struct *descs;
20585
20586 descs = (void *)gdt->address;
20587 +
20588 + pax_open_kernel();
20589 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
20590 + pax_close_kernel();
20591 +
20592 load_TR_desc();
20593 }
20594
20595 @@ -1541,6 +1545,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
20596 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
20597 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
20598
20599 +#ifdef CONFIG_PAX_PER_CPU_PGD
20600 + vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
20601 +#endif
20602 +
20603 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
20604 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
20605 vmx->loaded_vmcs->cpu = cpu;
20606 @@ -2674,8 +2682,11 @@ static __init int hardware_setup(void)
20607 if (!cpu_has_vmx_flexpriority())
20608 flexpriority_enabled = 0;
20609
20610 - if (!cpu_has_vmx_tpr_shadow())
20611 - kvm_x86_ops->update_cr8_intercept = NULL;
20612 + if (!cpu_has_vmx_tpr_shadow()) {
20613 + pax_open_kernel();
20614 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
20615 + pax_close_kernel();
20616 + }
20617
20618 if (enable_ept && !cpu_has_vmx_ept_2m_page())
20619 kvm_disable_largepages();
20620 @@ -3745,7 +3756,10 @@ static void vmx_set_constant_host_state(void)
20621
20622 vmcs_writel(HOST_CR0, read_cr0() | X86_CR0_TS); /* 22.2.3 */
20623 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
20624 +
20625 +#ifndef CONFIG_PAX_PER_CPU_PGD
20626 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
20627 +#endif
20628
20629 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
20630 #ifdef CONFIG_X86_64
20631 @@ -3767,7 +3781,7 @@ static void vmx_set_constant_host_state(void)
20632 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
20633
20634 asm("mov $.Lkvm_vmx_return, %0" : "=r"(tmpl));
20635 - vmcs_writel(HOST_RIP, tmpl); /* 22.2.5 */
20636 + vmcs_writel(HOST_RIP, ktla_ktva(tmpl)); /* 22.2.5 */
20637
20638 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
20639 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
20640 @@ -6321,6 +6335,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20641 "jmp .Lkvm_vmx_return \n\t"
20642 ".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
20643 ".Lkvm_vmx_return: "
20644 +
20645 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20646 + "ljmp %[cs],$.Lkvm_vmx_return2\n\t"
20647 + ".Lkvm_vmx_return2: "
20648 +#endif
20649 +
20650 /* Save guest registers, load host registers, keep flags */
20651 "mov %0, %c[wordsize](%%"R"sp) \n\t"
20652 "pop %0 \n\t"
20653 @@ -6369,6 +6389,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20654 #endif
20655 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
20656 [wordsize]"i"(sizeof(ulong))
20657 +
20658 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20659 + ,[cs]"i"(__KERNEL_CS)
20660 +#endif
20661 +
20662 : "cc", "memory"
20663 , R"ax", R"bx", R"di", R"si"
20664 #ifdef CONFIG_X86_64
20665 @@ -6376,7 +6401,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20666 #endif
20667 );
20668
20669 -#ifndef CONFIG_X86_64
20670 +#ifdef CONFIG_X86_32
20671 /*
20672 * The sysexit path does not restore ds/es, so we must set them to
20673 * a reasonable value ourselves.
20674 @@ -6385,8 +6410,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20675 * may be executed in interrupt context, which saves and restore segments
20676 * around it, nullifying its effect.
20677 */
20678 - loadsegment(ds, __USER_DS);
20679 - loadsegment(es, __USER_DS);
20680 + loadsegment(ds, __KERNEL_DS);
20681 + loadsegment(es, __KERNEL_DS);
20682 + loadsegment(ss, __KERNEL_DS);
20683 +
20684 +#ifdef CONFIG_PAX_KERNEXEC
20685 + loadsegment(fs, __KERNEL_PERCPU);
20686 +#endif
20687 +
20688 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20689 + __set_fs(current_thread_info()->addr_limit);
20690 +#endif
20691 +
20692 #endif
20693
20694 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
20695 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
20696 index a201790..9ac0c3c 100644
20697 --- a/arch/x86/kvm/x86.c
20698 +++ b/arch/x86/kvm/x86.c
20699 @@ -1379,8 +1379,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
20700 {
20701 struct kvm *kvm = vcpu->kvm;
20702 int lm = is_long_mode(vcpu);
20703 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20704 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20705 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20706 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20707 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
20708 : kvm->arch.xen_hvm_config.blob_size_32;
20709 u32 page_num = data & ~PAGE_MASK;
20710 @@ -2243,6 +2243,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
20711 if (n < msr_list.nmsrs)
20712 goto out;
20713 r = -EFAULT;
20714 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
20715 + goto out;
20716 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
20717 num_msrs_to_save * sizeof(u32)))
20718 goto out;
20719 @@ -2368,7 +2370,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
20720 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
20721 struct kvm_interrupt *irq)
20722 {
20723 - if (irq->irq < 0 || irq->irq >= 256)
20724 + if (irq->irq >= 256)
20725 return -EINVAL;
20726 if (irqchip_in_kernel(vcpu->kvm))
20727 return -ENXIO;
20728 @@ -4889,7 +4891,7 @@ static void kvm_set_mmio_spte_mask(void)
20729 kvm_mmu_set_mmio_spte_mask(mask);
20730 }
20731
20732 -int kvm_arch_init(void *opaque)
20733 +int kvm_arch_init(const void *opaque)
20734 {
20735 int r;
20736 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
20737 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
20738 index 642d880..cc9ebac 100644
20739 --- a/arch/x86/lguest/boot.c
20740 +++ b/arch/x86/lguest/boot.c
20741 @@ -1116,12 +1116,12 @@ static u32 lguest_apic_safe_wait_icr_idle(void)
20742
20743 static void set_lguest_basic_apic_ops(void)
20744 {
20745 - apic->read = lguest_apic_read;
20746 - apic->write = lguest_apic_write;
20747 - apic->icr_read = lguest_apic_icr_read;
20748 - apic->icr_write = lguest_apic_icr_write;
20749 - apic->wait_icr_idle = lguest_apic_wait_icr_idle;
20750 - apic->safe_wait_icr_idle = lguest_apic_safe_wait_icr_idle;
20751 + *(void **)&apic->read = lguest_apic_read;
20752 + *(void **)&apic->write = lguest_apic_write;
20753 + *(void **)&apic->icr_read = lguest_apic_icr_read;
20754 + *(void **)&apic->icr_write = lguest_apic_icr_write;
20755 + *(void **)&apic->wait_icr_idle = lguest_apic_wait_icr_idle;
20756 + *(void **)&apic->safe_wait_icr_idle = lguest_apic_safe_wait_icr_idle;
20757 };
20758 #endif
20759
20760 @@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
20761 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
20762 * Launcher to reboot us.
20763 */
20764 -static void lguest_restart(char *reason)
20765 +static __noreturn void lguest_restart(char *reason)
20766 {
20767 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
20768 + BUG();
20769 }
20770
20771 /*G:050
20772 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
20773 index 00933d5..3a64af9 100644
20774 --- a/arch/x86/lib/atomic64_386_32.S
20775 +++ b/arch/x86/lib/atomic64_386_32.S
20776 @@ -48,6 +48,10 @@ BEGIN(read)
20777 movl (v), %eax
20778 movl 4(v), %edx
20779 RET_ENDP
20780 +BEGIN(read_unchecked)
20781 + movl (v), %eax
20782 + movl 4(v), %edx
20783 +RET_ENDP
20784 #undef v
20785
20786 #define v %esi
20787 @@ -55,6 +59,10 @@ BEGIN(set)
20788 movl %ebx, (v)
20789 movl %ecx, 4(v)
20790 RET_ENDP
20791 +BEGIN(set_unchecked)
20792 + movl %ebx, (v)
20793 + movl %ecx, 4(v)
20794 +RET_ENDP
20795 #undef v
20796
20797 #define v %esi
20798 @@ -70,6 +78,20 @@ RET_ENDP
20799 BEGIN(add)
20800 addl %eax, (v)
20801 adcl %edx, 4(v)
20802 +
20803 +#ifdef CONFIG_PAX_REFCOUNT
20804 + jno 0f
20805 + subl %eax, (v)
20806 + sbbl %edx, 4(v)
20807 + int $4
20808 +0:
20809 + _ASM_EXTABLE(0b, 0b)
20810 +#endif
20811 +
20812 +RET_ENDP
20813 +BEGIN(add_unchecked)
20814 + addl %eax, (v)
20815 + adcl %edx, 4(v)
20816 RET_ENDP
20817 #undef v
20818
20819 @@ -77,6 +99,24 @@ RET_ENDP
20820 BEGIN(add_return)
20821 addl (v), %eax
20822 adcl 4(v), %edx
20823 +
20824 +#ifdef CONFIG_PAX_REFCOUNT
20825 + into
20826 +1234:
20827 + _ASM_EXTABLE(1234b, 2f)
20828 +#endif
20829 +
20830 + movl %eax, (v)
20831 + movl %edx, 4(v)
20832 +
20833 +#ifdef CONFIG_PAX_REFCOUNT
20834 +2:
20835 +#endif
20836 +
20837 +RET_ENDP
20838 +BEGIN(add_return_unchecked)
20839 + addl (v), %eax
20840 + adcl 4(v), %edx
20841 movl %eax, (v)
20842 movl %edx, 4(v)
20843 RET_ENDP
20844 @@ -86,6 +126,20 @@ RET_ENDP
20845 BEGIN(sub)
20846 subl %eax, (v)
20847 sbbl %edx, 4(v)
20848 +
20849 +#ifdef CONFIG_PAX_REFCOUNT
20850 + jno 0f
20851 + addl %eax, (v)
20852 + adcl %edx, 4(v)
20853 + int $4
20854 +0:
20855 + _ASM_EXTABLE(0b, 0b)
20856 +#endif
20857 +
20858 +RET_ENDP
20859 +BEGIN(sub_unchecked)
20860 + subl %eax, (v)
20861 + sbbl %edx, 4(v)
20862 RET_ENDP
20863 #undef v
20864
20865 @@ -96,6 +150,27 @@ BEGIN(sub_return)
20866 sbbl $0, %edx
20867 addl (v), %eax
20868 adcl 4(v), %edx
20869 +
20870 +#ifdef CONFIG_PAX_REFCOUNT
20871 + into
20872 +1234:
20873 + _ASM_EXTABLE(1234b, 2f)
20874 +#endif
20875 +
20876 + movl %eax, (v)
20877 + movl %edx, 4(v)
20878 +
20879 +#ifdef CONFIG_PAX_REFCOUNT
20880 +2:
20881 +#endif
20882 +
20883 +RET_ENDP
20884 +BEGIN(sub_return_unchecked)
20885 + negl %edx
20886 + negl %eax
20887 + sbbl $0, %edx
20888 + addl (v), %eax
20889 + adcl 4(v), %edx
20890 movl %eax, (v)
20891 movl %edx, 4(v)
20892 RET_ENDP
20893 @@ -105,6 +180,20 @@ RET_ENDP
20894 BEGIN(inc)
20895 addl $1, (v)
20896 adcl $0, 4(v)
20897 +
20898 +#ifdef CONFIG_PAX_REFCOUNT
20899 + jno 0f
20900 + subl $1, (v)
20901 + sbbl $0, 4(v)
20902 + int $4
20903 +0:
20904 + _ASM_EXTABLE(0b, 0b)
20905 +#endif
20906 +
20907 +RET_ENDP
20908 +BEGIN(inc_unchecked)
20909 + addl $1, (v)
20910 + adcl $0, 4(v)
20911 RET_ENDP
20912 #undef v
20913
20914 @@ -114,6 +203,26 @@ BEGIN(inc_return)
20915 movl 4(v), %edx
20916 addl $1, %eax
20917 adcl $0, %edx
20918 +
20919 +#ifdef CONFIG_PAX_REFCOUNT
20920 + into
20921 +1234:
20922 + _ASM_EXTABLE(1234b, 2f)
20923 +#endif
20924 +
20925 + movl %eax, (v)
20926 + movl %edx, 4(v)
20927 +
20928 +#ifdef CONFIG_PAX_REFCOUNT
20929 +2:
20930 +#endif
20931 +
20932 +RET_ENDP
20933 +BEGIN(inc_return_unchecked)
20934 + movl (v), %eax
20935 + movl 4(v), %edx
20936 + addl $1, %eax
20937 + adcl $0, %edx
20938 movl %eax, (v)
20939 movl %edx, 4(v)
20940 RET_ENDP
20941 @@ -123,6 +232,20 @@ RET_ENDP
20942 BEGIN(dec)
20943 subl $1, (v)
20944 sbbl $0, 4(v)
20945 +
20946 +#ifdef CONFIG_PAX_REFCOUNT
20947 + jno 0f
20948 + addl $1, (v)
20949 + adcl $0, 4(v)
20950 + int $4
20951 +0:
20952 + _ASM_EXTABLE(0b, 0b)
20953 +#endif
20954 +
20955 +RET_ENDP
20956 +BEGIN(dec_unchecked)
20957 + subl $1, (v)
20958 + sbbl $0, 4(v)
20959 RET_ENDP
20960 #undef v
20961
20962 @@ -132,6 +255,26 @@ BEGIN(dec_return)
20963 movl 4(v), %edx
20964 subl $1, %eax
20965 sbbl $0, %edx
20966 +
20967 +#ifdef CONFIG_PAX_REFCOUNT
20968 + into
20969 +1234:
20970 + _ASM_EXTABLE(1234b, 2f)
20971 +#endif
20972 +
20973 + movl %eax, (v)
20974 + movl %edx, 4(v)
20975 +
20976 +#ifdef CONFIG_PAX_REFCOUNT
20977 +2:
20978 +#endif
20979 +
20980 +RET_ENDP
20981 +BEGIN(dec_return_unchecked)
20982 + movl (v), %eax
20983 + movl 4(v), %edx
20984 + subl $1, %eax
20985 + sbbl $0, %edx
20986 movl %eax, (v)
20987 movl %edx, 4(v)
20988 RET_ENDP
20989 @@ -143,6 +286,13 @@ BEGIN(add_unless)
20990 adcl %edx, %edi
20991 addl (v), %eax
20992 adcl 4(v), %edx
20993 +
20994 +#ifdef CONFIG_PAX_REFCOUNT
20995 + into
20996 +1234:
20997 + _ASM_EXTABLE(1234b, 2f)
20998 +#endif
20999 +
21000 cmpl %eax, %ecx
21001 je 3f
21002 1:
21003 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
21004 1:
21005 addl $1, %eax
21006 adcl $0, %edx
21007 +
21008 +#ifdef CONFIG_PAX_REFCOUNT
21009 + into
21010 +1234:
21011 + _ASM_EXTABLE(1234b, 2f)
21012 +#endif
21013 +
21014 movl %eax, (v)
21015 movl %edx, 4(v)
21016 movl $1, %eax
21017 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
21018 movl 4(v), %edx
21019 subl $1, %eax
21020 sbbl $0, %edx
21021 +
21022 +#ifdef CONFIG_PAX_REFCOUNT
21023 + into
21024 +1234:
21025 + _ASM_EXTABLE(1234b, 1f)
21026 +#endif
21027 +
21028 js 1f
21029 movl %eax, (v)
21030 movl %edx, 4(v)
21031 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
21032 index f5cc9eb..51fa319 100644
21033 --- a/arch/x86/lib/atomic64_cx8_32.S
21034 +++ b/arch/x86/lib/atomic64_cx8_32.S
21035 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
21036 CFI_STARTPROC
21037
21038 read64 %ecx
21039 + pax_force_retaddr
21040 ret
21041 CFI_ENDPROC
21042 ENDPROC(atomic64_read_cx8)
21043
21044 +ENTRY(atomic64_read_unchecked_cx8)
21045 + CFI_STARTPROC
21046 +
21047 + read64 %ecx
21048 + pax_force_retaddr
21049 + ret
21050 + CFI_ENDPROC
21051 +ENDPROC(atomic64_read_unchecked_cx8)
21052 +
21053 ENTRY(atomic64_set_cx8)
21054 CFI_STARTPROC
21055
21056 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
21057 cmpxchg8b (%esi)
21058 jne 1b
21059
21060 + pax_force_retaddr
21061 ret
21062 CFI_ENDPROC
21063 ENDPROC(atomic64_set_cx8)
21064
21065 +ENTRY(atomic64_set_unchecked_cx8)
21066 + CFI_STARTPROC
21067 +
21068 +1:
21069 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
21070 + * are atomic on 586 and newer */
21071 + cmpxchg8b (%esi)
21072 + jne 1b
21073 +
21074 + pax_force_retaddr
21075 + ret
21076 + CFI_ENDPROC
21077 +ENDPROC(atomic64_set_unchecked_cx8)
21078 +
21079 ENTRY(atomic64_xchg_cx8)
21080 CFI_STARTPROC
21081
21082 @@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
21083 cmpxchg8b (%esi)
21084 jne 1b
21085
21086 + pax_force_retaddr
21087 ret
21088 CFI_ENDPROC
21089 ENDPROC(atomic64_xchg_cx8)
21090
21091 -.macro addsub_return func ins insc
21092 -ENTRY(atomic64_\func\()_return_cx8)
21093 +.macro addsub_return func ins insc unchecked=""
21094 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
21095 CFI_STARTPROC
21096 SAVE ebp
21097 SAVE ebx
21098 @@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
21099 movl %edx, %ecx
21100 \ins\()l %esi, %ebx
21101 \insc\()l %edi, %ecx
21102 +
21103 +.ifb \unchecked
21104 +#ifdef CONFIG_PAX_REFCOUNT
21105 + into
21106 +2:
21107 + _ASM_EXTABLE(2b, 3f)
21108 +#endif
21109 +.endif
21110 +
21111 LOCK_PREFIX
21112 cmpxchg8b (%ebp)
21113 jne 1b
21114 -
21115 -10:
21116 movl %ebx, %eax
21117 movl %ecx, %edx
21118 +
21119 +.ifb \unchecked
21120 +#ifdef CONFIG_PAX_REFCOUNT
21121 +3:
21122 +#endif
21123 +.endif
21124 +
21125 RESTORE edi
21126 RESTORE esi
21127 RESTORE ebx
21128 RESTORE ebp
21129 + pax_force_retaddr
21130 ret
21131 CFI_ENDPROC
21132 -ENDPROC(atomic64_\func\()_return_cx8)
21133 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
21134 .endm
21135
21136 addsub_return add add adc
21137 addsub_return sub sub sbb
21138 +addsub_return add add adc _unchecked
21139 +addsub_return sub sub sbb _unchecked
21140
21141 -.macro incdec_return func ins insc
21142 -ENTRY(atomic64_\func\()_return_cx8)
21143 +.macro incdec_return func ins insc unchecked=""
21144 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
21145 CFI_STARTPROC
21146 SAVE ebx
21147
21148 @@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
21149 movl %edx, %ecx
21150 \ins\()l $1, %ebx
21151 \insc\()l $0, %ecx
21152 +
21153 +.ifb \unchecked
21154 +#ifdef CONFIG_PAX_REFCOUNT
21155 + into
21156 +2:
21157 + _ASM_EXTABLE(2b, 3f)
21158 +#endif
21159 +.endif
21160 +
21161 LOCK_PREFIX
21162 cmpxchg8b (%esi)
21163 jne 1b
21164
21165 -10:
21166 movl %ebx, %eax
21167 movl %ecx, %edx
21168 +
21169 +.ifb \unchecked
21170 +#ifdef CONFIG_PAX_REFCOUNT
21171 +3:
21172 +#endif
21173 +.endif
21174 +
21175 RESTORE ebx
21176 + pax_force_retaddr
21177 ret
21178 CFI_ENDPROC
21179 -ENDPROC(atomic64_\func\()_return_cx8)
21180 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
21181 .endm
21182
21183 incdec_return inc add adc
21184 incdec_return dec sub sbb
21185 +incdec_return inc add adc _unchecked
21186 +incdec_return dec sub sbb _unchecked
21187
21188 ENTRY(atomic64_dec_if_positive_cx8)
21189 CFI_STARTPROC
21190 @@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
21191 movl %edx, %ecx
21192 subl $1, %ebx
21193 sbb $0, %ecx
21194 +
21195 +#ifdef CONFIG_PAX_REFCOUNT
21196 + into
21197 +1234:
21198 + _ASM_EXTABLE(1234b, 2f)
21199 +#endif
21200 +
21201 js 2f
21202 LOCK_PREFIX
21203 cmpxchg8b (%esi)
21204 @@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
21205 movl %ebx, %eax
21206 movl %ecx, %edx
21207 RESTORE ebx
21208 + pax_force_retaddr
21209 ret
21210 CFI_ENDPROC
21211 ENDPROC(atomic64_dec_if_positive_cx8)
21212 @@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
21213 movl %edx, %ecx
21214 addl %ebp, %ebx
21215 adcl %edi, %ecx
21216 +
21217 +#ifdef CONFIG_PAX_REFCOUNT
21218 + into
21219 +1234:
21220 + _ASM_EXTABLE(1234b, 3f)
21221 +#endif
21222 +
21223 LOCK_PREFIX
21224 cmpxchg8b (%esi)
21225 jne 1b
21226 @@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
21227 CFI_ADJUST_CFA_OFFSET -8
21228 RESTORE ebx
21229 RESTORE ebp
21230 + pax_force_retaddr
21231 ret
21232 4:
21233 cmpl %edx, 4(%esp)
21234 @@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
21235 xorl %ecx, %ecx
21236 addl $1, %ebx
21237 adcl %edx, %ecx
21238 +
21239 +#ifdef CONFIG_PAX_REFCOUNT
21240 + into
21241 +1234:
21242 + _ASM_EXTABLE(1234b, 3f)
21243 +#endif
21244 +
21245 LOCK_PREFIX
21246 cmpxchg8b (%esi)
21247 jne 1b
21248 @@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
21249 movl $1, %eax
21250 3:
21251 RESTORE ebx
21252 + pax_force_retaddr
21253 ret
21254 CFI_ENDPROC
21255 ENDPROC(atomic64_inc_not_zero_cx8)
21256 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
21257 index 2af5df3..62b1a5a 100644
21258 --- a/arch/x86/lib/checksum_32.S
21259 +++ b/arch/x86/lib/checksum_32.S
21260 @@ -29,7 +29,8 @@
21261 #include <asm/dwarf2.h>
21262 #include <asm/errno.h>
21263 #include <asm/asm.h>
21264 -
21265 +#include <asm/segment.h>
21266 +
21267 /*
21268 * computes a partial checksum, e.g. for TCP/UDP fragments
21269 */
21270 @@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
21271
21272 #define ARGBASE 16
21273 #define FP 12
21274 -
21275 -ENTRY(csum_partial_copy_generic)
21276 +
21277 +ENTRY(csum_partial_copy_generic_to_user)
21278 CFI_STARTPROC
21279 +
21280 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21281 + pushl_cfi %gs
21282 + popl_cfi %es
21283 + jmp csum_partial_copy_generic
21284 +#endif
21285 +
21286 +ENTRY(csum_partial_copy_generic_from_user)
21287 +
21288 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21289 + pushl_cfi %gs
21290 + popl_cfi %ds
21291 +#endif
21292 +
21293 +ENTRY(csum_partial_copy_generic)
21294 subl $4,%esp
21295 CFI_ADJUST_CFA_OFFSET 4
21296 pushl_cfi %edi
21297 @@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
21298 jmp 4f
21299 SRC(1: movw (%esi), %bx )
21300 addl $2, %esi
21301 -DST( movw %bx, (%edi) )
21302 +DST( movw %bx, %es:(%edi) )
21303 addl $2, %edi
21304 addw %bx, %ax
21305 adcl $0, %eax
21306 @@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
21307 SRC(1: movl (%esi), %ebx )
21308 SRC( movl 4(%esi), %edx )
21309 adcl %ebx, %eax
21310 -DST( movl %ebx, (%edi) )
21311 +DST( movl %ebx, %es:(%edi) )
21312 adcl %edx, %eax
21313 -DST( movl %edx, 4(%edi) )
21314 +DST( movl %edx, %es:4(%edi) )
21315
21316 SRC( movl 8(%esi), %ebx )
21317 SRC( movl 12(%esi), %edx )
21318 adcl %ebx, %eax
21319 -DST( movl %ebx, 8(%edi) )
21320 +DST( movl %ebx, %es:8(%edi) )
21321 adcl %edx, %eax
21322 -DST( movl %edx, 12(%edi) )
21323 +DST( movl %edx, %es:12(%edi) )
21324
21325 SRC( movl 16(%esi), %ebx )
21326 SRC( movl 20(%esi), %edx )
21327 adcl %ebx, %eax
21328 -DST( movl %ebx, 16(%edi) )
21329 +DST( movl %ebx, %es:16(%edi) )
21330 adcl %edx, %eax
21331 -DST( movl %edx, 20(%edi) )
21332 +DST( movl %edx, %es:20(%edi) )
21333
21334 SRC( movl 24(%esi), %ebx )
21335 SRC( movl 28(%esi), %edx )
21336 adcl %ebx, %eax
21337 -DST( movl %ebx, 24(%edi) )
21338 +DST( movl %ebx, %es:24(%edi) )
21339 adcl %edx, %eax
21340 -DST( movl %edx, 28(%edi) )
21341 +DST( movl %edx, %es:28(%edi) )
21342
21343 lea 32(%esi), %esi
21344 lea 32(%edi), %edi
21345 @@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
21346 shrl $2, %edx # This clears CF
21347 SRC(3: movl (%esi), %ebx )
21348 adcl %ebx, %eax
21349 -DST( movl %ebx, (%edi) )
21350 +DST( movl %ebx, %es:(%edi) )
21351 lea 4(%esi), %esi
21352 lea 4(%edi), %edi
21353 dec %edx
21354 @@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
21355 jb 5f
21356 SRC( movw (%esi), %cx )
21357 leal 2(%esi), %esi
21358 -DST( movw %cx, (%edi) )
21359 +DST( movw %cx, %es:(%edi) )
21360 leal 2(%edi), %edi
21361 je 6f
21362 shll $16,%ecx
21363 SRC(5: movb (%esi), %cl )
21364 -DST( movb %cl, (%edi) )
21365 +DST( movb %cl, %es:(%edi) )
21366 6: addl %ecx, %eax
21367 adcl $0, %eax
21368 7:
21369 @@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
21370
21371 6001:
21372 movl ARGBASE+20(%esp), %ebx # src_err_ptr
21373 - movl $-EFAULT, (%ebx)
21374 + movl $-EFAULT, %ss:(%ebx)
21375
21376 # zero the complete destination - computing the rest
21377 # is too much work
21378 @@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
21379
21380 6002:
21381 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21382 - movl $-EFAULT,(%ebx)
21383 + movl $-EFAULT,%ss:(%ebx)
21384 jmp 5000b
21385
21386 .previous
21387
21388 + pushl_cfi %ss
21389 + popl_cfi %ds
21390 + pushl_cfi %ss
21391 + popl_cfi %es
21392 popl_cfi %ebx
21393 CFI_RESTORE ebx
21394 popl_cfi %esi
21395 @@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
21396 popl_cfi %ecx # equivalent to addl $4,%esp
21397 ret
21398 CFI_ENDPROC
21399 -ENDPROC(csum_partial_copy_generic)
21400 +ENDPROC(csum_partial_copy_generic_to_user)
21401
21402 #else
21403
21404 /* Version for PentiumII/PPro */
21405
21406 #define ROUND1(x) \
21407 + nop; nop; nop; \
21408 SRC(movl x(%esi), %ebx ) ; \
21409 addl %ebx, %eax ; \
21410 - DST(movl %ebx, x(%edi) ) ;
21411 + DST(movl %ebx, %es:x(%edi)) ;
21412
21413 #define ROUND(x) \
21414 + nop; nop; nop; \
21415 SRC(movl x(%esi), %ebx ) ; \
21416 adcl %ebx, %eax ; \
21417 - DST(movl %ebx, x(%edi) ) ;
21418 + DST(movl %ebx, %es:x(%edi)) ;
21419
21420 #define ARGBASE 12
21421 -
21422 -ENTRY(csum_partial_copy_generic)
21423 +
21424 +ENTRY(csum_partial_copy_generic_to_user)
21425 CFI_STARTPROC
21426 +
21427 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21428 + pushl_cfi %gs
21429 + popl_cfi %es
21430 + jmp csum_partial_copy_generic
21431 +#endif
21432 +
21433 +ENTRY(csum_partial_copy_generic_from_user)
21434 +
21435 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21436 + pushl_cfi %gs
21437 + popl_cfi %ds
21438 +#endif
21439 +
21440 +ENTRY(csum_partial_copy_generic)
21441 pushl_cfi %ebx
21442 CFI_REL_OFFSET ebx, 0
21443 pushl_cfi %edi
21444 @@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
21445 subl %ebx, %edi
21446 lea -1(%esi),%edx
21447 andl $-32,%edx
21448 - lea 3f(%ebx,%ebx), %ebx
21449 + lea 3f(%ebx,%ebx,2), %ebx
21450 testl %esi, %esi
21451 jmp *%ebx
21452 1: addl $64,%esi
21453 @@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
21454 jb 5f
21455 SRC( movw (%esi), %dx )
21456 leal 2(%esi), %esi
21457 -DST( movw %dx, (%edi) )
21458 +DST( movw %dx, %es:(%edi) )
21459 leal 2(%edi), %edi
21460 je 6f
21461 shll $16,%edx
21462 5:
21463 SRC( movb (%esi), %dl )
21464 -DST( movb %dl, (%edi) )
21465 +DST( movb %dl, %es:(%edi) )
21466 6: addl %edx, %eax
21467 adcl $0, %eax
21468 7:
21469 .section .fixup, "ax"
21470 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
21471 - movl $-EFAULT, (%ebx)
21472 + movl $-EFAULT, %ss:(%ebx)
21473 # zero the complete destination (computing the rest is too much work)
21474 movl ARGBASE+8(%esp),%edi # dst
21475 movl ARGBASE+12(%esp),%ecx # len
21476 @@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
21477 rep; stosb
21478 jmp 7b
21479 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21480 - movl $-EFAULT, (%ebx)
21481 + movl $-EFAULT, %ss:(%ebx)
21482 jmp 7b
21483 .previous
21484
21485 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21486 + pushl_cfi %ss
21487 + popl_cfi %ds
21488 + pushl_cfi %ss
21489 + popl_cfi %es
21490 +#endif
21491 +
21492 popl_cfi %esi
21493 CFI_RESTORE esi
21494 popl_cfi %edi
21495 @@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
21496 CFI_RESTORE ebx
21497 ret
21498 CFI_ENDPROC
21499 -ENDPROC(csum_partial_copy_generic)
21500 +ENDPROC(csum_partial_copy_generic_to_user)
21501
21502 #undef ROUND
21503 #undef ROUND1
21504 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
21505 index f2145cf..cea889d 100644
21506 --- a/arch/x86/lib/clear_page_64.S
21507 +++ b/arch/x86/lib/clear_page_64.S
21508 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
21509 movl $4096/8,%ecx
21510 xorl %eax,%eax
21511 rep stosq
21512 + pax_force_retaddr
21513 ret
21514 CFI_ENDPROC
21515 ENDPROC(clear_page_c)
21516 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
21517 movl $4096,%ecx
21518 xorl %eax,%eax
21519 rep stosb
21520 + pax_force_retaddr
21521 ret
21522 CFI_ENDPROC
21523 ENDPROC(clear_page_c_e)
21524 @@ -43,6 +45,7 @@ ENTRY(clear_page)
21525 leaq 64(%rdi),%rdi
21526 jnz .Lloop
21527 nop
21528 + pax_force_retaddr
21529 ret
21530 CFI_ENDPROC
21531 .Lclear_page_end:
21532 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
21533
21534 #include <asm/cpufeature.h>
21535
21536 - .section .altinstr_replacement,"ax"
21537 + .section .altinstr_replacement,"a"
21538 1: .byte 0xeb /* jmp <disp8> */
21539 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
21540 2: .byte 0xeb /* jmp <disp8> */
21541 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
21542 index 1e572c5..2a162cd 100644
21543 --- a/arch/x86/lib/cmpxchg16b_emu.S
21544 +++ b/arch/x86/lib/cmpxchg16b_emu.S
21545 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
21546
21547 popf
21548 mov $1, %al
21549 + pax_force_retaddr
21550 ret
21551
21552 not_same:
21553 popf
21554 xor %al,%al
21555 + pax_force_retaddr
21556 ret
21557
21558 CFI_ENDPROC
21559 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
21560 index 6b34d04..dccb07f 100644
21561 --- a/arch/x86/lib/copy_page_64.S
21562 +++ b/arch/x86/lib/copy_page_64.S
21563 @@ -9,6 +9,7 @@ copy_page_c:
21564 CFI_STARTPROC
21565 movl $4096/8,%ecx
21566 rep movsq
21567 + pax_force_retaddr
21568 ret
21569 CFI_ENDPROC
21570 ENDPROC(copy_page_c)
21571 @@ -20,12 +21,14 @@ ENDPROC(copy_page_c)
21572
21573 ENTRY(copy_page)
21574 CFI_STARTPROC
21575 - subq $2*8,%rsp
21576 - CFI_ADJUST_CFA_OFFSET 2*8
21577 + subq $3*8,%rsp
21578 + CFI_ADJUST_CFA_OFFSET 3*8
21579 movq %rbx,(%rsp)
21580 CFI_REL_OFFSET rbx, 0
21581 movq %r12,1*8(%rsp)
21582 CFI_REL_OFFSET r12, 1*8
21583 + movq %r13,2*8(%rsp)
21584 + CFI_REL_OFFSET r13, 2*8
21585
21586 movl $(4096/64)-5,%ecx
21587 .p2align 4
21588 @@ -37,7 +40,7 @@ ENTRY(copy_page)
21589 movq 16 (%rsi), %rdx
21590 movq 24 (%rsi), %r8
21591 movq 32 (%rsi), %r9
21592 - movq 40 (%rsi), %r10
21593 + movq 40 (%rsi), %r13
21594 movq 48 (%rsi), %r11
21595 movq 56 (%rsi), %r12
21596
21597 @@ -48,7 +51,7 @@ ENTRY(copy_page)
21598 movq %rdx, 16 (%rdi)
21599 movq %r8, 24 (%rdi)
21600 movq %r9, 32 (%rdi)
21601 - movq %r10, 40 (%rdi)
21602 + movq %r13, 40 (%rdi)
21603 movq %r11, 48 (%rdi)
21604 movq %r12, 56 (%rdi)
21605
21606 @@ -67,7 +70,7 @@ ENTRY(copy_page)
21607 movq 16 (%rsi), %rdx
21608 movq 24 (%rsi), %r8
21609 movq 32 (%rsi), %r9
21610 - movq 40 (%rsi), %r10
21611 + movq 40 (%rsi), %r13
21612 movq 48 (%rsi), %r11
21613 movq 56 (%rsi), %r12
21614
21615 @@ -76,7 +79,7 @@ ENTRY(copy_page)
21616 movq %rdx, 16 (%rdi)
21617 movq %r8, 24 (%rdi)
21618 movq %r9, 32 (%rdi)
21619 - movq %r10, 40 (%rdi)
21620 + movq %r13, 40 (%rdi)
21621 movq %r11, 48 (%rdi)
21622 movq %r12, 56 (%rdi)
21623
21624 @@ -89,8 +92,11 @@ ENTRY(copy_page)
21625 CFI_RESTORE rbx
21626 movq 1*8(%rsp),%r12
21627 CFI_RESTORE r12
21628 - addq $2*8,%rsp
21629 - CFI_ADJUST_CFA_OFFSET -2*8
21630 + movq 2*8(%rsp),%r13
21631 + CFI_RESTORE r13
21632 + addq $3*8,%rsp
21633 + CFI_ADJUST_CFA_OFFSET -3*8
21634 + pax_force_retaddr
21635 ret
21636 .Lcopy_page_end:
21637 CFI_ENDPROC
21638 @@ -101,7 +107,7 @@ ENDPROC(copy_page)
21639
21640 #include <asm/cpufeature.h>
21641
21642 - .section .altinstr_replacement,"ax"
21643 + .section .altinstr_replacement,"a"
21644 1: .byte 0xeb /* jmp <disp8> */
21645 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
21646 2:
21647 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
21648 index 5b2995f..78e7644 100644
21649 --- a/arch/x86/lib/copy_user_64.S
21650 +++ b/arch/x86/lib/copy_user_64.S
21651 @@ -17,6 +17,7 @@
21652 #include <asm/cpufeature.h>
21653 #include <asm/alternative-asm.h>
21654 #include <asm/asm.h>
21655 +#include <asm/pgtable.h>
21656
21657 /*
21658 * By placing feature2 after feature1 in altinstructions section, we logically
21659 @@ -30,7 +31,7 @@
21660 .byte 0xe9 /* 32bit jump */
21661 .long \orig-1f /* by default jump to orig */
21662 1:
21663 - .section .altinstr_replacement,"ax"
21664 + .section .altinstr_replacement,"a"
21665 2: .byte 0xe9 /* near jump with 32bit immediate */
21666 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
21667 3: .byte 0xe9 /* near jump with 32bit immediate */
21668 @@ -69,47 +70,20 @@
21669 #endif
21670 .endm
21671
21672 -/* Standard copy_to_user with segment limit checking */
21673 -ENTRY(_copy_to_user)
21674 - CFI_STARTPROC
21675 - GET_THREAD_INFO(%rax)
21676 - movq %rdi,%rcx
21677 - addq %rdx,%rcx
21678 - jc bad_to_user
21679 - cmpq TI_addr_limit(%rax),%rcx
21680 - ja bad_to_user
21681 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21682 - copy_user_generic_unrolled,copy_user_generic_string, \
21683 - copy_user_enhanced_fast_string
21684 - CFI_ENDPROC
21685 -ENDPROC(_copy_to_user)
21686 -
21687 -/* Standard copy_from_user with segment limit checking */
21688 -ENTRY(_copy_from_user)
21689 - CFI_STARTPROC
21690 - GET_THREAD_INFO(%rax)
21691 - movq %rsi,%rcx
21692 - addq %rdx,%rcx
21693 - jc bad_from_user
21694 - cmpq TI_addr_limit(%rax),%rcx
21695 - ja bad_from_user
21696 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21697 - copy_user_generic_unrolled,copy_user_generic_string, \
21698 - copy_user_enhanced_fast_string
21699 - CFI_ENDPROC
21700 -ENDPROC(_copy_from_user)
21701 -
21702 .section .fixup,"ax"
21703 /* must zero dest */
21704 ENTRY(bad_from_user)
21705 bad_from_user:
21706 CFI_STARTPROC
21707 + testl %edx,%edx
21708 + js bad_to_user
21709 movl %edx,%ecx
21710 xorl %eax,%eax
21711 rep
21712 stosb
21713 bad_to_user:
21714 movl %edx,%eax
21715 + pax_force_retaddr
21716 ret
21717 CFI_ENDPROC
21718 ENDPROC(bad_from_user)
21719 @@ -139,19 +113,19 @@ ENTRY(copy_user_generic_unrolled)
21720 jz 17f
21721 1: movq (%rsi),%r8
21722 2: movq 1*8(%rsi),%r9
21723 -3: movq 2*8(%rsi),%r10
21724 +3: movq 2*8(%rsi),%rax
21725 4: movq 3*8(%rsi),%r11
21726 5: movq %r8,(%rdi)
21727 6: movq %r9,1*8(%rdi)
21728 -7: movq %r10,2*8(%rdi)
21729 +7: movq %rax,2*8(%rdi)
21730 8: movq %r11,3*8(%rdi)
21731 9: movq 4*8(%rsi),%r8
21732 10: movq 5*8(%rsi),%r9
21733 -11: movq 6*8(%rsi),%r10
21734 +11: movq 6*8(%rsi),%rax
21735 12: movq 7*8(%rsi),%r11
21736 13: movq %r8,4*8(%rdi)
21737 14: movq %r9,5*8(%rdi)
21738 -15: movq %r10,6*8(%rdi)
21739 +15: movq %rax,6*8(%rdi)
21740 16: movq %r11,7*8(%rdi)
21741 leaq 64(%rsi),%rsi
21742 leaq 64(%rdi),%rdi
21743 @@ -177,6 +151,7 @@ ENTRY(copy_user_generic_unrolled)
21744 decl %ecx
21745 jnz 21b
21746 23: xor %eax,%eax
21747 + pax_force_retaddr
21748 ret
21749
21750 .section .fixup,"ax"
21751 @@ -246,6 +221,7 @@ ENTRY(copy_user_generic_string)
21752 3: rep
21753 movsb
21754 4: xorl %eax,%eax
21755 + pax_force_retaddr
21756 ret
21757
21758 .section .fixup,"ax"
21759 @@ -279,6 +255,7 @@ ENTRY(copy_user_enhanced_fast_string)
21760 1: rep
21761 movsb
21762 2: xorl %eax,%eax
21763 + pax_force_retaddr
21764 ret
21765
21766 .section .fixup,"ax"
21767 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
21768 index cacddc7..09d49e4 100644
21769 --- a/arch/x86/lib/copy_user_nocache_64.S
21770 +++ b/arch/x86/lib/copy_user_nocache_64.S
21771 @@ -8,6 +8,7 @@
21772
21773 #include <linux/linkage.h>
21774 #include <asm/dwarf2.h>
21775 +#include <asm/alternative-asm.h>
21776
21777 #define FIX_ALIGNMENT 1
21778
21779 @@ -15,6 +16,7 @@
21780 #include <asm/asm-offsets.h>
21781 #include <asm/thread_info.h>
21782 #include <asm/asm.h>
21783 +#include <asm/pgtable.h>
21784
21785 .macro ALIGN_DESTINATION
21786 #ifdef FIX_ALIGNMENT
21787 @@ -48,6 +50,15 @@
21788 */
21789 ENTRY(__copy_user_nocache)
21790 CFI_STARTPROC
21791 +
21792 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21793 + mov $PAX_USER_SHADOW_BASE,%rcx
21794 + cmp %rcx,%rsi
21795 + jae 1f
21796 + add %rcx,%rsi
21797 +1:
21798 +#endif
21799 +
21800 cmpl $8,%edx
21801 jb 20f /* less then 8 bytes, go to byte copy loop */
21802 ALIGN_DESTINATION
21803 @@ -57,19 +68,19 @@ ENTRY(__copy_user_nocache)
21804 jz 17f
21805 1: movq (%rsi),%r8
21806 2: movq 1*8(%rsi),%r9
21807 -3: movq 2*8(%rsi),%r10
21808 +3: movq 2*8(%rsi),%rax
21809 4: movq 3*8(%rsi),%r11
21810 5: movnti %r8,(%rdi)
21811 6: movnti %r9,1*8(%rdi)
21812 -7: movnti %r10,2*8(%rdi)
21813 +7: movnti %rax,2*8(%rdi)
21814 8: movnti %r11,3*8(%rdi)
21815 9: movq 4*8(%rsi),%r8
21816 10: movq 5*8(%rsi),%r9
21817 -11: movq 6*8(%rsi),%r10
21818 +11: movq 6*8(%rsi),%rax
21819 12: movq 7*8(%rsi),%r11
21820 13: movnti %r8,4*8(%rdi)
21821 14: movnti %r9,5*8(%rdi)
21822 -15: movnti %r10,6*8(%rdi)
21823 +15: movnti %rax,6*8(%rdi)
21824 16: movnti %r11,7*8(%rdi)
21825 leaq 64(%rsi),%rsi
21826 leaq 64(%rdi),%rdi
21827 @@ -96,6 +107,7 @@ ENTRY(__copy_user_nocache)
21828 jnz 21b
21829 23: xorl %eax,%eax
21830 sfence
21831 + pax_force_retaddr
21832 ret
21833
21834 .section .fixup,"ax"
21835 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
21836 index 2419d5f..953ee51 100644
21837 --- a/arch/x86/lib/csum-copy_64.S
21838 +++ b/arch/x86/lib/csum-copy_64.S
21839 @@ -9,6 +9,7 @@
21840 #include <asm/dwarf2.h>
21841 #include <asm/errno.h>
21842 #include <asm/asm.h>
21843 +#include <asm/alternative-asm.h>
21844
21845 /*
21846 * Checksum copy with exception handling.
21847 @@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
21848 CFI_RESTORE rbp
21849 addq $7*8, %rsp
21850 CFI_ADJUST_CFA_OFFSET -7*8
21851 + pax_force_retaddr 0, 1
21852 ret
21853 CFI_RESTORE_STATE
21854
21855 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
21856 index 25b7ae8..169fafc 100644
21857 --- a/arch/x86/lib/csum-wrappers_64.c
21858 +++ b/arch/x86/lib/csum-wrappers_64.c
21859 @@ -52,7 +52,7 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
21860 len -= 2;
21861 }
21862 }
21863 - isum = csum_partial_copy_generic((__force const void *)src,
21864 + isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
21865 dst, len, isum, errp, NULL);
21866 if (unlikely(*errp))
21867 goto out_err;
21868 @@ -105,7 +105,7 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
21869 }
21870
21871 *errp = 0;
21872 - return csum_partial_copy_generic(src, (void __force *)dst,
21873 + return csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
21874 len, isum, NULL, errp);
21875 }
21876 EXPORT_SYMBOL(csum_partial_copy_to_user);
21877 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
21878 index b33b1fb..219f389 100644
21879 --- a/arch/x86/lib/getuser.S
21880 +++ b/arch/x86/lib/getuser.S
21881 @@ -33,15 +33,38 @@
21882 #include <asm/asm-offsets.h>
21883 #include <asm/thread_info.h>
21884 #include <asm/asm.h>
21885 +#include <asm/segment.h>
21886 +#include <asm/pgtable.h>
21887 +#include <asm/alternative-asm.h>
21888 +
21889 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
21890 +#define __copyuser_seg gs;
21891 +#else
21892 +#define __copyuser_seg
21893 +#endif
21894
21895 .text
21896 ENTRY(__get_user_1)
21897 CFI_STARTPROC
21898 +
21899 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21900 GET_THREAD_INFO(%_ASM_DX)
21901 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21902 jae bad_get_user
21903 -1: movzb (%_ASM_AX),%edx
21904 +
21905 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21906 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21907 + cmp %_ASM_DX,%_ASM_AX
21908 + jae 1234f
21909 + add %_ASM_DX,%_ASM_AX
21910 +1234:
21911 +#endif
21912 +
21913 +#endif
21914 +
21915 +1: __copyuser_seg movzb (%_ASM_AX),%edx
21916 xor %eax,%eax
21917 + pax_force_retaddr
21918 ret
21919 CFI_ENDPROC
21920 ENDPROC(__get_user_1)
21921 @@ -49,12 +72,26 @@ ENDPROC(__get_user_1)
21922 ENTRY(__get_user_2)
21923 CFI_STARTPROC
21924 add $1,%_ASM_AX
21925 +
21926 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21927 jc bad_get_user
21928 GET_THREAD_INFO(%_ASM_DX)
21929 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21930 jae bad_get_user
21931 -2: movzwl -1(%_ASM_AX),%edx
21932 +
21933 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21934 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21935 + cmp %_ASM_DX,%_ASM_AX
21936 + jae 1234f
21937 + add %_ASM_DX,%_ASM_AX
21938 +1234:
21939 +#endif
21940 +
21941 +#endif
21942 +
21943 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
21944 xor %eax,%eax
21945 + pax_force_retaddr
21946 ret
21947 CFI_ENDPROC
21948 ENDPROC(__get_user_2)
21949 @@ -62,12 +99,26 @@ ENDPROC(__get_user_2)
21950 ENTRY(__get_user_4)
21951 CFI_STARTPROC
21952 add $3,%_ASM_AX
21953 +
21954 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21955 jc bad_get_user
21956 GET_THREAD_INFO(%_ASM_DX)
21957 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21958 jae bad_get_user
21959 -3: mov -3(%_ASM_AX),%edx
21960 +
21961 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21962 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21963 + cmp %_ASM_DX,%_ASM_AX
21964 + jae 1234f
21965 + add %_ASM_DX,%_ASM_AX
21966 +1234:
21967 +#endif
21968 +
21969 +#endif
21970 +
21971 +3: __copyuser_seg mov -3(%_ASM_AX),%edx
21972 xor %eax,%eax
21973 + pax_force_retaddr
21974 ret
21975 CFI_ENDPROC
21976 ENDPROC(__get_user_4)
21977 @@ -80,8 +131,18 @@ ENTRY(__get_user_8)
21978 GET_THREAD_INFO(%_ASM_DX)
21979 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21980 jae bad_get_user
21981 +
21982 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21983 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21984 + cmp %_ASM_DX,%_ASM_AX
21985 + jae 1234f
21986 + add %_ASM_DX,%_ASM_AX
21987 +1234:
21988 +#endif
21989 +
21990 4: movq -7(%_ASM_AX),%_ASM_DX
21991 xor %eax,%eax
21992 + pax_force_retaddr
21993 ret
21994 CFI_ENDPROC
21995 ENDPROC(__get_user_8)
21996 @@ -91,6 +152,7 @@ bad_get_user:
21997 CFI_STARTPROC
21998 xor %edx,%edx
21999 mov $(-EFAULT),%_ASM_AX
22000 + pax_force_retaddr
22001 ret
22002 CFI_ENDPROC
22003 END(bad_get_user)
22004 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
22005 index b1e6c4b..21ae8fc 100644
22006 --- a/arch/x86/lib/insn.c
22007 +++ b/arch/x86/lib/insn.c
22008 @@ -21,6 +21,11 @@
22009 #include <linux/string.h>
22010 #include <asm/inat.h>
22011 #include <asm/insn.h>
22012 +#ifdef __KERNEL__
22013 +#include <asm/pgtable_types.h>
22014 +#else
22015 +#define ktla_ktva(addr) addr
22016 +#endif
22017
22018 /* Verify next sizeof(t) bytes can be on the same instruction */
22019 #define validate_next(t, insn, n) \
22020 @@ -49,8 +54,8 @@
22021 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
22022 {
22023 memset(insn, 0, sizeof(*insn));
22024 - insn->kaddr = kaddr;
22025 - insn->next_byte = kaddr;
22026 + insn->kaddr = ktla_ktva(kaddr);
22027 + insn->next_byte = ktla_ktva(kaddr);
22028 insn->x86_64 = x86_64 ? 1 : 0;
22029 insn->opnd_bytes = 4;
22030 if (x86_64)
22031 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
22032 index 05a95e7..326f2fa 100644
22033 --- a/arch/x86/lib/iomap_copy_64.S
22034 +++ b/arch/x86/lib/iomap_copy_64.S
22035 @@ -17,6 +17,7 @@
22036
22037 #include <linux/linkage.h>
22038 #include <asm/dwarf2.h>
22039 +#include <asm/alternative-asm.h>
22040
22041 /*
22042 * override generic version in lib/iomap_copy.c
22043 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
22044 CFI_STARTPROC
22045 movl %edx,%ecx
22046 rep movsd
22047 + pax_force_retaddr
22048 ret
22049 CFI_ENDPROC
22050 ENDPROC(__iowrite32_copy)
22051 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
22052 index 1c273be..da9cc0e 100644
22053 --- a/arch/x86/lib/memcpy_64.S
22054 +++ b/arch/x86/lib/memcpy_64.S
22055 @@ -33,6 +33,7 @@
22056 rep movsq
22057 movl %edx, %ecx
22058 rep movsb
22059 + pax_force_retaddr
22060 ret
22061 .Lmemcpy_e:
22062 .previous
22063 @@ -49,6 +50,7 @@
22064 movq %rdi, %rax
22065 movq %rdx, %rcx
22066 rep movsb
22067 + pax_force_retaddr
22068 ret
22069 .Lmemcpy_e_e:
22070 .previous
22071 @@ -76,13 +78,13 @@ ENTRY(memcpy)
22072 */
22073 movq 0*8(%rsi), %r8
22074 movq 1*8(%rsi), %r9
22075 - movq 2*8(%rsi), %r10
22076 + movq 2*8(%rsi), %rcx
22077 movq 3*8(%rsi), %r11
22078 leaq 4*8(%rsi), %rsi
22079
22080 movq %r8, 0*8(%rdi)
22081 movq %r9, 1*8(%rdi)
22082 - movq %r10, 2*8(%rdi)
22083 + movq %rcx, 2*8(%rdi)
22084 movq %r11, 3*8(%rdi)
22085 leaq 4*8(%rdi), %rdi
22086 jae .Lcopy_forward_loop
22087 @@ -105,12 +107,12 @@ ENTRY(memcpy)
22088 subq $0x20, %rdx
22089 movq -1*8(%rsi), %r8
22090 movq -2*8(%rsi), %r9
22091 - movq -3*8(%rsi), %r10
22092 + movq -3*8(%rsi), %rcx
22093 movq -4*8(%rsi), %r11
22094 leaq -4*8(%rsi), %rsi
22095 movq %r8, -1*8(%rdi)
22096 movq %r9, -2*8(%rdi)
22097 - movq %r10, -3*8(%rdi)
22098 + movq %rcx, -3*8(%rdi)
22099 movq %r11, -4*8(%rdi)
22100 leaq -4*8(%rdi), %rdi
22101 jae .Lcopy_backward_loop
22102 @@ -130,12 +132,13 @@ ENTRY(memcpy)
22103 */
22104 movq 0*8(%rsi), %r8
22105 movq 1*8(%rsi), %r9
22106 - movq -2*8(%rsi, %rdx), %r10
22107 + movq -2*8(%rsi, %rdx), %rcx
22108 movq -1*8(%rsi, %rdx), %r11
22109 movq %r8, 0*8(%rdi)
22110 movq %r9, 1*8(%rdi)
22111 - movq %r10, -2*8(%rdi, %rdx)
22112 + movq %rcx, -2*8(%rdi, %rdx)
22113 movq %r11, -1*8(%rdi, %rdx)
22114 + pax_force_retaddr
22115 retq
22116 .p2align 4
22117 .Lless_16bytes:
22118 @@ -148,6 +151,7 @@ ENTRY(memcpy)
22119 movq -1*8(%rsi, %rdx), %r9
22120 movq %r8, 0*8(%rdi)
22121 movq %r9, -1*8(%rdi, %rdx)
22122 + pax_force_retaddr
22123 retq
22124 .p2align 4
22125 .Lless_8bytes:
22126 @@ -161,6 +165,7 @@ ENTRY(memcpy)
22127 movl -4(%rsi, %rdx), %r8d
22128 movl %ecx, (%rdi)
22129 movl %r8d, -4(%rdi, %rdx)
22130 + pax_force_retaddr
22131 retq
22132 .p2align 4
22133 .Lless_3bytes:
22134 @@ -179,6 +184,7 @@ ENTRY(memcpy)
22135 movb %cl, (%rdi)
22136
22137 .Lend:
22138 + pax_force_retaddr
22139 retq
22140 CFI_ENDPROC
22141 ENDPROC(memcpy)
22142 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
22143 index ee16461..c39c199 100644
22144 --- a/arch/x86/lib/memmove_64.S
22145 +++ b/arch/x86/lib/memmove_64.S
22146 @@ -61,13 +61,13 @@ ENTRY(memmove)
22147 5:
22148 sub $0x20, %rdx
22149 movq 0*8(%rsi), %r11
22150 - movq 1*8(%rsi), %r10
22151 + movq 1*8(%rsi), %rcx
22152 movq 2*8(%rsi), %r9
22153 movq 3*8(%rsi), %r8
22154 leaq 4*8(%rsi), %rsi
22155
22156 movq %r11, 0*8(%rdi)
22157 - movq %r10, 1*8(%rdi)
22158 + movq %rcx, 1*8(%rdi)
22159 movq %r9, 2*8(%rdi)
22160 movq %r8, 3*8(%rdi)
22161 leaq 4*8(%rdi), %rdi
22162 @@ -81,10 +81,10 @@ ENTRY(memmove)
22163 4:
22164 movq %rdx, %rcx
22165 movq -8(%rsi, %rdx), %r11
22166 - lea -8(%rdi, %rdx), %r10
22167 + lea -8(%rdi, %rdx), %r9
22168 shrq $3, %rcx
22169 rep movsq
22170 - movq %r11, (%r10)
22171 + movq %r11, (%r9)
22172 jmp 13f
22173 .Lmemmove_end_forward:
22174
22175 @@ -95,14 +95,14 @@ ENTRY(memmove)
22176 7:
22177 movq %rdx, %rcx
22178 movq (%rsi), %r11
22179 - movq %rdi, %r10
22180 + movq %rdi, %r9
22181 leaq -8(%rsi, %rdx), %rsi
22182 leaq -8(%rdi, %rdx), %rdi
22183 shrq $3, %rcx
22184 std
22185 rep movsq
22186 cld
22187 - movq %r11, (%r10)
22188 + movq %r11, (%r9)
22189 jmp 13f
22190
22191 /*
22192 @@ -127,13 +127,13 @@ ENTRY(memmove)
22193 8:
22194 subq $0x20, %rdx
22195 movq -1*8(%rsi), %r11
22196 - movq -2*8(%rsi), %r10
22197 + movq -2*8(%rsi), %rcx
22198 movq -3*8(%rsi), %r9
22199 movq -4*8(%rsi), %r8
22200 leaq -4*8(%rsi), %rsi
22201
22202 movq %r11, -1*8(%rdi)
22203 - movq %r10, -2*8(%rdi)
22204 + movq %rcx, -2*8(%rdi)
22205 movq %r9, -3*8(%rdi)
22206 movq %r8, -4*8(%rdi)
22207 leaq -4*8(%rdi), %rdi
22208 @@ -151,11 +151,11 @@ ENTRY(memmove)
22209 * Move data from 16 bytes to 31 bytes.
22210 */
22211 movq 0*8(%rsi), %r11
22212 - movq 1*8(%rsi), %r10
22213 + movq 1*8(%rsi), %rcx
22214 movq -2*8(%rsi, %rdx), %r9
22215 movq -1*8(%rsi, %rdx), %r8
22216 movq %r11, 0*8(%rdi)
22217 - movq %r10, 1*8(%rdi)
22218 + movq %rcx, 1*8(%rdi)
22219 movq %r9, -2*8(%rdi, %rdx)
22220 movq %r8, -1*8(%rdi, %rdx)
22221 jmp 13f
22222 @@ -167,9 +167,9 @@ ENTRY(memmove)
22223 * Move data from 8 bytes to 15 bytes.
22224 */
22225 movq 0*8(%rsi), %r11
22226 - movq -1*8(%rsi, %rdx), %r10
22227 + movq -1*8(%rsi, %rdx), %r9
22228 movq %r11, 0*8(%rdi)
22229 - movq %r10, -1*8(%rdi, %rdx)
22230 + movq %r9, -1*8(%rdi, %rdx)
22231 jmp 13f
22232 10:
22233 cmpq $4, %rdx
22234 @@ -178,9 +178,9 @@ ENTRY(memmove)
22235 * Move data from 4 bytes to 7 bytes.
22236 */
22237 movl (%rsi), %r11d
22238 - movl -4(%rsi, %rdx), %r10d
22239 + movl -4(%rsi, %rdx), %r9d
22240 movl %r11d, (%rdi)
22241 - movl %r10d, -4(%rdi, %rdx)
22242 + movl %r9d, -4(%rdi, %rdx)
22243 jmp 13f
22244 11:
22245 cmp $2, %rdx
22246 @@ -189,9 +189,9 @@ ENTRY(memmove)
22247 * Move data from 2 bytes to 3 bytes.
22248 */
22249 movw (%rsi), %r11w
22250 - movw -2(%rsi, %rdx), %r10w
22251 + movw -2(%rsi, %rdx), %r9w
22252 movw %r11w, (%rdi)
22253 - movw %r10w, -2(%rdi, %rdx)
22254 + movw %r9w, -2(%rdi, %rdx)
22255 jmp 13f
22256 12:
22257 cmp $1, %rdx
22258 @@ -202,6 +202,7 @@ ENTRY(memmove)
22259 movb (%rsi), %r11b
22260 movb %r11b, (%rdi)
22261 13:
22262 + pax_force_retaddr
22263 retq
22264 CFI_ENDPROC
22265
22266 @@ -210,6 +211,7 @@ ENTRY(memmove)
22267 /* Forward moving data. */
22268 movq %rdx, %rcx
22269 rep movsb
22270 + pax_force_retaddr
22271 retq
22272 .Lmemmove_end_forward_efs:
22273 .previous
22274 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
22275 index 2dcb380..963660a 100644
22276 --- a/arch/x86/lib/memset_64.S
22277 +++ b/arch/x86/lib/memset_64.S
22278 @@ -30,6 +30,7 @@
22279 movl %edx,%ecx
22280 rep stosb
22281 movq %r9,%rax
22282 + pax_force_retaddr
22283 ret
22284 .Lmemset_e:
22285 .previous
22286 @@ -52,6 +53,7 @@
22287 movq %rdx,%rcx
22288 rep stosb
22289 movq %r9,%rax
22290 + pax_force_retaddr
22291 ret
22292 .Lmemset_e_e:
22293 .previous
22294 @@ -59,7 +61,7 @@
22295 ENTRY(memset)
22296 ENTRY(__memset)
22297 CFI_STARTPROC
22298 - movq %rdi,%r10
22299 + movq %rdi,%r11
22300
22301 /* expand byte value */
22302 movzbl %sil,%ecx
22303 @@ -117,7 +119,8 @@ ENTRY(__memset)
22304 jnz .Lloop_1
22305
22306 .Lende:
22307 - movq %r10,%rax
22308 + movq %r11,%rax
22309 + pax_force_retaddr
22310 ret
22311
22312 CFI_RESTORE_STATE
22313 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
22314 index c9f2d9b..e7fd2c0 100644
22315 --- a/arch/x86/lib/mmx_32.c
22316 +++ b/arch/x86/lib/mmx_32.c
22317 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22318 {
22319 void *p;
22320 int i;
22321 + unsigned long cr0;
22322
22323 if (unlikely(in_interrupt()))
22324 return __memcpy(to, from, len);
22325 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22326 kernel_fpu_begin();
22327
22328 __asm__ __volatile__ (
22329 - "1: prefetch (%0)\n" /* This set is 28 bytes */
22330 - " prefetch 64(%0)\n"
22331 - " prefetch 128(%0)\n"
22332 - " prefetch 192(%0)\n"
22333 - " prefetch 256(%0)\n"
22334 + "1: prefetch (%1)\n" /* This set is 28 bytes */
22335 + " prefetch 64(%1)\n"
22336 + " prefetch 128(%1)\n"
22337 + " prefetch 192(%1)\n"
22338 + " prefetch 256(%1)\n"
22339 "2: \n"
22340 ".section .fixup, \"ax\"\n"
22341 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22342 + "3: \n"
22343 +
22344 +#ifdef CONFIG_PAX_KERNEXEC
22345 + " movl %%cr0, %0\n"
22346 + " movl %0, %%eax\n"
22347 + " andl $0xFFFEFFFF, %%eax\n"
22348 + " movl %%eax, %%cr0\n"
22349 +#endif
22350 +
22351 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22352 +
22353 +#ifdef CONFIG_PAX_KERNEXEC
22354 + " movl %0, %%cr0\n"
22355 +#endif
22356 +
22357 " jmp 2b\n"
22358 ".previous\n"
22359 _ASM_EXTABLE(1b, 3b)
22360 - : : "r" (from));
22361 + : "=&r" (cr0) : "r" (from) : "ax");
22362
22363 for ( ; i > 5; i--) {
22364 __asm__ __volatile__ (
22365 - "1: prefetch 320(%0)\n"
22366 - "2: movq (%0), %%mm0\n"
22367 - " movq 8(%0), %%mm1\n"
22368 - " movq 16(%0), %%mm2\n"
22369 - " movq 24(%0), %%mm3\n"
22370 - " movq %%mm0, (%1)\n"
22371 - " movq %%mm1, 8(%1)\n"
22372 - " movq %%mm2, 16(%1)\n"
22373 - " movq %%mm3, 24(%1)\n"
22374 - " movq 32(%0), %%mm0\n"
22375 - " movq 40(%0), %%mm1\n"
22376 - " movq 48(%0), %%mm2\n"
22377 - " movq 56(%0), %%mm3\n"
22378 - " movq %%mm0, 32(%1)\n"
22379 - " movq %%mm1, 40(%1)\n"
22380 - " movq %%mm2, 48(%1)\n"
22381 - " movq %%mm3, 56(%1)\n"
22382 + "1: prefetch 320(%1)\n"
22383 + "2: movq (%1), %%mm0\n"
22384 + " movq 8(%1), %%mm1\n"
22385 + " movq 16(%1), %%mm2\n"
22386 + " movq 24(%1), %%mm3\n"
22387 + " movq %%mm0, (%2)\n"
22388 + " movq %%mm1, 8(%2)\n"
22389 + " movq %%mm2, 16(%2)\n"
22390 + " movq %%mm3, 24(%2)\n"
22391 + " movq 32(%1), %%mm0\n"
22392 + " movq 40(%1), %%mm1\n"
22393 + " movq 48(%1), %%mm2\n"
22394 + " movq 56(%1), %%mm3\n"
22395 + " movq %%mm0, 32(%2)\n"
22396 + " movq %%mm1, 40(%2)\n"
22397 + " movq %%mm2, 48(%2)\n"
22398 + " movq %%mm3, 56(%2)\n"
22399 ".section .fixup, \"ax\"\n"
22400 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22401 + "3:\n"
22402 +
22403 +#ifdef CONFIG_PAX_KERNEXEC
22404 + " movl %%cr0, %0\n"
22405 + " movl %0, %%eax\n"
22406 + " andl $0xFFFEFFFF, %%eax\n"
22407 + " movl %%eax, %%cr0\n"
22408 +#endif
22409 +
22410 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22411 +
22412 +#ifdef CONFIG_PAX_KERNEXEC
22413 + " movl %0, %%cr0\n"
22414 +#endif
22415 +
22416 " jmp 2b\n"
22417 ".previous\n"
22418 _ASM_EXTABLE(1b, 3b)
22419 - : : "r" (from), "r" (to) : "memory");
22420 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22421
22422 from += 64;
22423 to += 64;
22424 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
22425 static void fast_copy_page(void *to, void *from)
22426 {
22427 int i;
22428 + unsigned long cr0;
22429
22430 kernel_fpu_begin();
22431
22432 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
22433 * but that is for later. -AV
22434 */
22435 __asm__ __volatile__(
22436 - "1: prefetch (%0)\n"
22437 - " prefetch 64(%0)\n"
22438 - " prefetch 128(%0)\n"
22439 - " prefetch 192(%0)\n"
22440 - " prefetch 256(%0)\n"
22441 + "1: prefetch (%1)\n"
22442 + " prefetch 64(%1)\n"
22443 + " prefetch 128(%1)\n"
22444 + " prefetch 192(%1)\n"
22445 + " prefetch 256(%1)\n"
22446 "2: \n"
22447 ".section .fixup, \"ax\"\n"
22448 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22449 + "3: \n"
22450 +
22451 +#ifdef CONFIG_PAX_KERNEXEC
22452 + " movl %%cr0, %0\n"
22453 + " movl %0, %%eax\n"
22454 + " andl $0xFFFEFFFF, %%eax\n"
22455 + " movl %%eax, %%cr0\n"
22456 +#endif
22457 +
22458 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22459 +
22460 +#ifdef CONFIG_PAX_KERNEXEC
22461 + " movl %0, %%cr0\n"
22462 +#endif
22463 +
22464 " jmp 2b\n"
22465 ".previous\n"
22466 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
22467 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22468
22469 for (i = 0; i < (4096-320)/64; i++) {
22470 __asm__ __volatile__ (
22471 - "1: prefetch 320(%0)\n"
22472 - "2: movq (%0), %%mm0\n"
22473 - " movntq %%mm0, (%1)\n"
22474 - " movq 8(%0), %%mm1\n"
22475 - " movntq %%mm1, 8(%1)\n"
22476 - " movq 16(%0), %%mm2\n"
22477 - " movntq %%mm2, 16(%1)\n"
22478 - " movq 24(%0), %%mm3\n"
22479 - " movntq %%mm3, 24(%1)\n"
22480 - " movq 32(%0), %%mm4\n"
22481 - " movntq %%mm4, 32(%1)\n"
22482 - " movq 40(%0), %%mm5\n"
22483 - " movntq %%mm5, 40(%1)\n"
22484 - " movq 48(%0), %%mm6\n"
22485 - " movntq %%mm6, 48(%1)\n"
22486 - " movq 56(%0), %%mm7\n"
22487 - " movntq %%mm7, 56(%1)\n"
22488 + "1: prefetch 320(%1)\n"
22489 + "2: movq (%1), %%mm0\n"
22490 + " movntq %%mm0, (%2)\n"
22491 + " movq 8(%1), %%mm1\n"
22492 + " movntq %%mm1, 8(%2)\n"
22493 + " movq 16(%1), %%mm2\n"
22494 + " movntq %%mm2, 16(%2)\n"
22495 + " movq 24(%1), %%mm3\n"
22496 + " movntq %%mm3, 24(%2)\n"
22497 + " movq 32(%1), %%mm4\n"
22498 + " movntq %%mm4, 32(%2)\n"
22499 + " movq 40(%1), %%mm5\n"
22500 + " movntq %%mm5, 40(%2)\n"
22501 + " movq 48(%1), %%mm6\n"
22502 + " movntq %%mm6, 48(%2)\n"
22503 + " movq 56(%1), %%mm7\n"
22504 + " movntq %%mm7, 56(%2)\n"
22505 ".section .fixup, \"ax\"\n"
22506 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22507 + "3:\n"
22508 +
22509 +#ifdef CONFIG_PAX_KERNEXEC
22510 + " movl %%cr0, %0\n"
22511 + " movl %0, %%eax\n"
22512 + " andl $0xFFFEFFFF, %%eax\n"
22513 + " movl %%eax, %%cr0\n"
22514 +#endif
22515 +
22516 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22517 +
22518 +#ifdef CONFIG_PAX_KERNEXEC
22519 + " movl %0, %%cr0\n"
22520 +#endif
22521 +
22522 " jmp 2b\n"
22523 ".previous\n"
22524 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
22525 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22526
22527 from += 64;
22528 to += 64;
22529 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
22530 static void fast_copy_page(void *to, void *from)
22531 {
22532 int i;
22533 + unsigned long cr0;
22534
22535 kernel_fpu_begin();
22536
22537 __asm__ __volatile__ (
22538 - "1: prefetch (%0)\n"
22539 - " prefetch 64(%0)\n"
22540 - " prefetch 128(%0)\n"
22541 - " prefetch 192(%0)\n"
22542 - " prefetch 256(%0)\n"
22543 + "1: prefetch (%1)\n"
22544 + " prefetch 64(%1)\n"
22545 + " prefetch 128(%1)\n"
22546 + " prefetch 192(%1)\n"
22547 + " prefetch 256(%1)\n"
22548 "2: \n"
22549 ".section .fixup, \"ax\"\n"
22550 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22551 + "3: \n"
22552 +
22553 +#ifdef CONFIG_PAX_KERNEXEC
22554 + " movl %%cr0, %0\n"
22555 + " movl %0, %%eax\n"
22556 + " andl $0xFFFEFFFF, %%eax\n"
22557 + " movl %%eax, %%cr0\n"
22558 +#endif
22559 +
22560 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22561 +
22562 +#ifdef CONFIG_PAX_KERNEXEC
22563 + " movl %0, %%cr0\n"
22564 +#endif
22565 +
22566 " jmp 2b\n"
22567 ".previous\n"
22568 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
22569 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22570
22571 for (i = 0; i < 4096/64; i++) {
22572 __asm__ __volatile__ (
22573 - "1: prefetch 320(%0)\n"
22574 - "2: movq (%0), %%mm0\n"
22575 - " movq 8(%0), %%mm1\n"
22576 - " movq 16(%0), %%mm2\n"
22577 - " movq 24(%0), %%mm3\n"
22578 - " movq %%mm0, (%1)\n"
22579 - " movq %%mm1, 8(%1)\n"
22580 - " movq %%mm2, 16(%1)\n"
22581 - " movq %%mm3, 24(%1)\n"
22582 - " movq 32(%0), %%mm0\n"
22583 - " movq 40(%0), %%mm1\n"
22584 - " movq 48(%0), %%mm2\n"
22585 - " movq 56(%0), %%mm3\n"
22586 - " movq %%mm0, 32(%1)\n"
22587 - " movq %%mm1, 40(%1)\n"
22588 - " movq %%mm2, 48(%1)\n"
22589 - " movq %%mm3, 56(%1)\n"
22590 + "1: prefetch 320(%1)\n"
22591 + "2: movq (%1), %%mm0\n"
22592 + " movq 8(%1), %%mm1\n"
22593 + " movq 16(%1), %%mm2\n"
22594 + " movq 24(%1), %%mm3\n"
22595 + " movq %%mm0, (%2)\n"
22596 + " movq %%mm1, 8(%2)\n"
22597 + " movq %%mm2, 16(%2)\n"
22598 + " movq %%mm3, 24(%2)\n"
22599 + " movq 32(%1), %%mm0\n"
22600 + " movq 40(%1), %%mm1\n"
22601 + " movq 48(%1), %%mm2\n"
22602 + " movq 56(%1), %%mm3\n"
22603 + " movq %%mm0, 32(%2)\n"
22604 + " movq %%mm1, 40(%2)\n"
22605 + " movq %%mm2, 48(%2)\n"
22606 + " movq %%mm3, 56(%2)\n"
22607 ".section .fixup, \"ax\"\n"
22608 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22609 + "3:\n"
22610 +
22611 +#ifdef CONFIG_PAX_KERNEXEC
22612 + " movl %%cr0, %0\n"
22613 + " movl %0, %%eax\n"
22614 + " andl $0xFFFEFFFF, %%eax\n"
22615 + " movl %%eax, %%cr0\n"
22616 +#endif
22617 +
22618 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22619 +
22620 +#ifdef CONFIG_PAX_KERNEXEC
22621 + " movl %0, %%cr0\n"
22622 +#endif
22623 +
22624 " jmp 2b\n"
22625 ".previous\n"
22626 _ASM_EXTABLE(1b, 3b)
22627 - : : "r" (from), "r" (to) : "memory");
22628 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22629
22630 from += 64;
22631 to += 64;
22632 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
22633 index f6d13ee..aca5f0b 100644
22634 --- a/arch/x86/lib/msr-reg.S
22635 +++ b/arch/x86/lib/msr-reg.S
22636 @@ -3,6 +3,7 @@
22637 #include <asm/dwarf2.h>
22638 #include <asm/asm.h>
22639 #include <asm/msr.h>
22640 +#include <asm/alternative-asm.h>
22641
22642 #ifdef CONFIG_X86_64
22643 /*
22644 @@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
22645 CFI_STARTPROC
22646 pushq_cfi %rbx
22647 pushq_cfi %rbp
22648 - movq %rdi, %r10 /* Save pointer */
22649 + movq %rdi, %r9 /* Save pointer */
22650 xorl %r11d, %r11d /* Return value */
22651 movl (%rdi), %eax
22652 movl 4(%rdi), %ecx
22653 @@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
22654 movl 28(%rdi), %edi
22655 CFI_REMEMBER_STATE
22656 1: \op
22657 -2: movl %eax, (%r10)
22658 +2: movl %eax, (%r9)
22659 movl %r11d, %eax /* Return value */
22660 - movl %ecx, 4(%r10)
22661 - movl %edx, 8(%r10)
22662 - movl %ebx, 12(%r10)
22663 - movl %ebp, 20(%r10)
22664 - movl %esi, 24(%r10)
22665 - movl %edi, 28(%r10)
22666 + movl %ecx, 4(%r9)
22667 + movl %edx, 8(%r9)
22668 + movl %ebx, 12(%r9)
22669 + movl %ebp, 20(%r9)
22670 + movl %esi, 24(%r9)
22671 + movl %edi, 28(%r9)
22672 popq_cfi %rbp
22673 popq_cfi %rbx
22674 + pax_force_retaddr
22675 ret
22676 3:
22677 CFI_RESTORE_STATE
22678 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
22679 index 7f951c8..ebd573a 100644
22680 --- a/arch/x86/lib/putuser.S
22681 +++ b/arch/x86/lib/putuser.S
22682 @@ -15,7 +15,9 @@
22683 #include <asm/thread_info.h>
22684 #include <asm/errno.h>
22685 #include <asm/asm.h>
22686 -
22687 +#include <asm/segment.h>
22688 +#include <asm/pgtable.h>
22689 +#include <asm/alternative-asm.h>
22690
22691 /*
22692 * __put_user_X
22693 @@ -29,52 +31,119 @@
22694 * as they get called from within inline assembly.
22695 */
22696
22697 -#define ENTER CFI_STARTPROC ; \
22698 - GET_THREAD_INFO(%_ASM_BX)
22699 -#define EXIT ret ; \
22700 +#define ENTER CFI_STARTPROC
22701 +#define EXIT pax_force_retaddr; ret ; \
22702 CFI_ENDPROC
22703
22704 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22705 +#define _DEST %_ASM_CX,%_ASM_BX
22706 +#else
22707 +#define _DEST %_ASM_CX
22708 +#endif
22709 +
22710 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
22711 +#define __copyuser_seg gs;
22712 +#else
22713 +#define __copyuser_seg
22714 +#endif
22715 +
22716 .text
22717 ENTRY(__put_user_1)
22718 ENTER
22719 +
22720 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22721 + GET_THREAD_INFO(%_ASM_BX)
22722 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
22723 jae bad_put_user
22724 -1: movb %al,(%_ASM_CX)
22725 +
22726 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22727 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22728 + cmp %_ASM_BX,%_ASM_CX
22729 + jb 1234f
22730 + xor %ebx,%ebx
22731 +1234:
22732 +#endif
22733 +
22734 +#endif
22735 +
22736 +1: __copyuser_seg movb %al,(_DEST)
22737 xor %eax,%eax
22738 EXIT
22739 ENDPROC(__put_user_1)
22740
22741 ENTRY(__put_user_2)
22742 ENTER
22743 +
22744 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22745 + GET_THREAD_INFO(%_ASM_BX)
22746 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22747 sub $1,%_ASM_BX
22748 cmp %_ASM_BX,%_ASM_CX
22749 jae bad_put_user
22750 -2: movw %ax,(%_ASM_CX)
22751 +
22752 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22753 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22754 + cmp %_ASM_BX,%_ASM_CX
22755 + jb 1234f
22756 + xor %ebx,%ebx
22757 +1234:
22758 +#endif
22759 +
22760 +#endif
22761 +
22762 +2: __copyuser_seg movw %ax,(_DEST)
22763 xor %eax,%eax
22764 EXIT
22765 ENDPROC(__put_user_2)
22766
22767 ENTRY(__put_user_4)
22768 ENTER
22769 +
22770 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22771 + GET_THREAD_INFO(%_ASM_BX)
22772 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22773 sub $3,%_ASM_BX
22774 cmp %_ASM_BX,%_ASM_CX
22775 jae bad_put_user
22776 -3: movl %eax,(%_ASM_CX)
22777 +
22778 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22779 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22780 + cmp %_ASM_BX,%_ASM_CX
22781 + jb 1234f
22782 + xor %ebx,%ebx
22783 +1234:
22784 +#endif
22785 +
22786 +#endif
22787 +
22788 +3: __copyuser_seg movl %eax,(_DEST)
22789 xor %eax,%eax
22790 EXIT
22791 ENDPROC(__put_user_4)
22792
22793 ENTRY(__put_user_8)
22794 ENTER
22795 +
22796 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22797 + GET_THREAD_INFO(%_ASM_BX)
22798 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22799 sub $7,%_ASM_BX
22800 cmp %_ASM_BX,%_ASM_CX
22801 jae bad_put_user
22802 -4: mov %_ASM_AX,(%_ASM_CX)
22803 +
22804 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22805 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22806 + cmp %_ASM_BX,%_ASM_CX
22807 + jb 1234f
22808 + xor %ebx,%ebx
22809 +1234:
22810 +#endif
22811 +
22812 +#endif
22813 +
22814 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
22815 #ifdef CONFIG_X86_32
22816 -5: movl %edx,4(%_ASM_CX)
22817 +5: __copyuser_seg movl %edx,4(_DEST)
22818 #endif
22819 xor %eax,%eax
22820 EXIT
22821 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
22822 index 1cad221..de671ee 100644
22823 --- a/arch/x86/lib/rwlock.S
22824 +++ b/arch/x86/lib/rwlock.S
22825 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
22826 FRAME
22827 0: LOCK_PREFIX
22828 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22829 +
22830 +#ifdef CONFIG_PAX_REFCOUNT
22831 + jno 1234f
22832 + LOCK_PREFIX
22833 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22834 + int $4
22835 +1234:
22836 + _ASM_EXTABLE(1234b, 1234b)
22837 +#endif
22838 +
22839 1: rep; nop
22840 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
22841 jne 1b
22842 LOCK_PREFIX
22843 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22844 +
22845 +#ifdef CONFIG_PAX_REFCOUNT
22846 + jno 1234f
22847 + LOCK_PREFIX
22848 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22849 + int $4
22850 +1234:
22851 + _ASM_EXTABLE(1234b, 1234b)
22852 +#endif
22853 +
22854 jnz 0b
22855 ENDFRAME
22856 + pax_force_retaddr
22857 ret
22858 CFI_ENDPROC
22859 END(__write_lock_failed)
22860 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
22861 FRAME
22862 0: LOCK_PREFIX
22863 READ_LOCK_SIZE(inc) (%__lock_ptr)
22864 +
22865 +#ifdef CONFIG_PAX_REFCOUNT
22866 + jno 1234f
22867 + LOCK_PREFIX
22868 + READ_LOCK_SIZE(dec) (%__lock_ptr)
22869 + int $4
22870 +1234:
22871 + _ASM_EXTABLE(1234b, 1234b)
22872 +#endif
22873 +
22874 1: rep; nop
22875 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
22876 js 1b
22877 LOCK_PREFIX
22878 READ_LOCK_SIZE(dec) (%__lock_ptr)
22879 +
22880 +#ifdef CONFIG_PAX_REFCOUNT
22881 + jno 1234f
22882 + LOCK_PREFIX
22883 + READ_LOCK_SIZE(inc) (%__lock_ptr)
22884 + int $4
22885 +1234:
22886 + _ASM_EXTABLE(1234b, 1234b)
22887 +#endif
22888 +
22889 js 0b
22890 ENDFRAME
22891 + pax_force_retaddr
22892 ret
22893 CFI_ENDPROC
22894 END(__read_lock_failed)
22895 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
22896 index 5dff5f0..cadebf4 100644
22897 --- a/arch/x86/lib/rwsem.S
22898 +++ b/arch/x86/lib/rwsem.S
22899 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
22900 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22901 CFI_RESTORE __ASM_REG(dx)
22902 restore_common_regs
22903 + pax_force_retaddr
22904 ret
22905 CFI_ENDPROC
22906 ENDPROC(call_rwsem_down_read_failed)
22907 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
22908 movq %rax,%rdi
22909 call rwsem_down_write_failed
22910 restore_common_regs
22911 + pax_force_retaddr
22912 ret
22913 CFI_ENDPROC
22914 ENDPROC(call_rwsem_down_write_failed)
22915 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
22916 movq %rax,%rdi
22917 call rwsem_wake
22918 restore_common_regs
22919 -1: ret
22920 +1: pax_force_retaddr
22921 + ret
22922 CFI_ENDPROC
22923 ENDPROC(call_rwsem_wake)
22924
22925 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
22926 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22927 CFI_RESTORE __ASM_REG(dx)
22928 restore_common_regs
22929 + pax_force_retaddr
22930 ret
22931 CFI_ENDPROC
22932 ENDPROC(call_rwsem_downgrade_wake)
22933 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
22934 index a63efd6..ccecad8 100644
22935 --- a/arch/x86/lib/thunk_64.S
22936 +++ b/arch/x86/lib/thunk_64.S
22937 @@ -8,6 +8,7 @@
22938 #include <linux/linkage.h>
22939 #include <asm/dwarf2.h>
22940 #include <asm/calling.h>
22941 +#include <asm/alternative-asm.h>
22942
22943 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
22944 .macro THUNK name, func, put_ret_addr_in_rdi=0
22945 @@ -41,5 +42,6 @@
22946 SAVE_ARGS
22947 restore:
22948 RESTORE_ARGS
22949 + pax_force_retaddr
22950 ret
22951 CFI_ENDPROC
22952 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
22953 index 1781b2f..90368dd 100644
22954 --- a/arch/x86/lib/usercopy_32.c
22955 +++ b/arch/x86/lib/usercopy_32.c
22956 @@ -42,10 +42,12 @@ do { \
22957 int __d0; \
22958 might_fault(); \
22959 __asm__ __volatile__( \
22960 + __COPYUSER_SET_ES \
22961 "0: rep; stosl\n" \
22962 " movl %2,%0\n" \
22963 "1: rep; stosb\n" \
22964 "2:\n" \
22965 + __COPYUSER_RESTORE_ES \
22966 ".section .fixup,\"ax\"\n" \
22967 "3: lea 0(%2,%0,4),%0\n" \
22968 " jmp 2b\n" \
22969 @@ -97,7 +99,7 @@ EXPORT_SYMBOL(__clear_user);
22970
22971 #ifdef CONFIG_X86_INTEL_USERCOPY
22972 static unsigned long
22973 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
22974 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
22975 {
22976 int d0, d1;
22977 __asm__ __volatile__(
22978 @@ -109,36 +111,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22979 " .align 2,0x90\n"
22980 "3: movl 0(%4), %%eax\n"
22981 "4: movl 4(%4), %%edx\n"
22982 - "5: movl %%eax, 0(%3)\n"
22983 - "6: movl %%edx, 4(%3)\n"
22984 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
22985 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
22986 "7: movl 8(%4), %%eax\n"
22987 "8: movl 12(%4),%%edx\n"
22988 - "9: movl %%eax, 8(%3)\n"
22989 - "10: movl %%edx, 12(%3)\n"
22990 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
22991 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
22992 "11: movl 16(%4), %%eax\n"
22993 "12: movl 20(%4), %%edx\n"
22994 - "13: movl %%eax, 16(%3)\n"
22995 - "14: movl %%edx, 20(%3)\n"
22996 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
22997 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
22998 "15: movl 24(%4), %%eax\n"
22999 "16: movl 28(%4), %%edx\n"
23000 - "17: movl %%eax, 24(%3)\n"
23001 - "18: movl %%edx, 28(%3)\n"
23002 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
23003 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
23004 "19: movl 32(%4), %%eax\n"
23005 "20: movl 36(%4), %%edx\n"
23006 - "21: movl %%eax, 32(%3)\n"
23007 - "22: movl %%edx, 36(%3)\n"
23008 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
23009 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
23010 "23: movl 40(%4), %%eax\n"
23011 "24: movl 44(%4), %%edx\n"
23012 - "25: movl %%eax, 40(%3)\n"
23013 - "26: movl %%edx, 44(%3)\n"
23014 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
23015 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
23016 "27: movl 48(%4), %%eax\n"
23017 "28: movl 52(%4), %%edx\n"
23018 - "29: movl %%eax, 48(%3)\n"
23019 - "30: movl %%edx, 52(%3)\n"
23020 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
23021 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
23022 "31: movl 56(%4), %%eax\n"
23023 "32: movl 60(%4), %%edx\n"
23024 - "33: movl %%eax, 56(%3)\n"
23025 - "34: movl %%edx, 60(%3)\n"
23026 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
23027 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
23028 " addl $-64, %0\n"
23029 " addl $64, %4\n"
23030 " addl $64, %3\n"
23031 @@ -148,10 +150,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
23032 " shrl $2, %0\n"
23033 " andl $3, %%eax\n"
23034 " cld\n"
23035 + __COPYUSER_SET_ES
23036 "99: rep; movsl\n"
23037 "36: movl %%eax, %0\n"
23038 "37: rep; movsb\n"
23039 "100:\n"
23040 + __COPYUSER_RESTORE_ES
23041 ".section .fixup,\"ax\"\n"
23042 "101: lea 0(%%eax,%0,4),%0\n"
23043 " jmp 100b\n"
23044 @@ -201,46 +205,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
23045 }
23046
23047 static unsigned long
23048 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
23049 +{
23050 + int d0, d1;
23051 + __asm__ __volatile__(
23052 + " .align 2,0x90\n"
23053 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
23054 + " cmpl $67, %0\n"
23055 + " jbe 3f\n"
23056 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
23057 + " .align 2,0x90\n"
23058 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
23059 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
23060 + "5: movl %%eax, 0(%3)\n"
23061 + "6: movl %%edx, 4(%3)\n"
23062 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
23063 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
23064 + "9: movl %%eax, 8(%3)\n"
23065 + "10: movl %%edx, 12(%3)\n"
23066 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
23067 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
23068 + "13: movl %%eax, 16(%3)\n"
23069 + "14: movl %%edx, 20(%3)\n"
23070 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
23071 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
23072 + "17: movl %%eax, 24(%3)\n"
23073 + "18: movl %%edx, 28(%3)\n"
23074 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
23075 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
23076 + "21: movl %%eax, 32(%3)\n"
23077 + "22: movl %%edx, 36(%3)\n"
23078 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
23079 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
23080 + "25: movl %%eax, 40(%3)\n"
23081 + "26: movl %%edx, 44(%3)\n"
23082 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
23083 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
23084 + "29: movl %%eax, 48(%3)\n"
23085 + "30: movl %%edx, 52(%3)\n"
23086 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
23087 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
23088 + "33: movl %%eax, 56(%3)\n"
23089 + "34: movl %%edx, 60(%3)\n"
23090 + " addl $-64, %0\n"
23091 + " addl $64, %4\n"
23092 + " addl $64, %3\n"
23093 + " cmpl $63, %0\n"
23094 + " ja 1b\n"
23095 + "35: movl %0, %%eax\n"
23096 + " shrl $2, %0\n"
23097 + " andl $3, %%eax\n"
23098 + " cld\n"
23099 + "99: rep; "__copyuser_seg" movsl\n"
23100 + "36: movl %%eax, %0\n"
23101 + "37: rep; "__copyuser_seg" movsb\n"
23102 + "100:\n"
23103 + ".section .fixup,\"ax\"\n"
23104 + "101: lea 0(%%eax,%0,4),%0\n"
23105 + " jmp 100b\n"
23106 + ".previous\n"
23107 + _ASM_EXTABLE(1b,100b)
23108 + _ASM_EXTABLE(2b,100b)
23109 + _ASM_EXTABLE(3b,100b)
23110 + _ASM_EXTABLE(4b,100b)
23111 + _ASM_EXTABLE(5b,100b)
23112 + _ASM_EXTABLE(6b,100b)
23113 + _ASM_EXTABLE(7b,100b)
23114 + _ASM_EXTABLE(8b,100b)
23115 + _ASM_EXTABLE(9b,100b)
23116 + _ASM_EXTABLE(10b,100b)
23117 + _ASM_EXTABLE(11b,100b)
23118 + _ASM_EXTABLE(12b,100b)
23119 + _ASM_EXTABLE(13b,100b)
23120 + _ASM_EXTABLE(14b,100b)
23121 + _ASM_EXTABLE(15b,100b)
23122 + _ASM_EXTABLE(16b,100b)
23123 + _ASM_EXTABLE(17b,100b)
23124 + _ASM_EXTABLE(18b,100b)
23125 + _ASM_EXTABLE(19b,100b)
23126 + _ASM_EXTABLE(20b,100b)
23127 + _ASM_EXTABLE(21b,100b)
23128 + _ASM_EXTABLE(22b,100b)
23129 + _ASM_EXTABLE(23b,100b)
23130 + _ASM_EXTABLE(24b,100b)
23131 + _ASM_EXTABLE(25b,100b)
23132 + _ASM_EXTABLE(26b,100b)
23133 + _ASM_EXTABLE(27b,100b)
23134 + _ASM_EXTABLE(28b,100b)
23135 + _ASM_EXTABLE(29b,100b)
23136 + _ASM_EXTABLE(30b,100b)
23137 + _ASM_EXTABLE(31b,100b)
23138 + _ASM_EXTABLE(32b,100b)
23139 + _ASM_EXTABLE(33b,100b)
23140 + _ASM_EXTABLE(34b,100b)
23141 + _ASM_EXTABLE(35b,100b)
23142 + _ASM_EXTABLE(36b,100b)
23143 + _ASM_EXTABLE(37b,100b)
23144 + _ASM_EXTABLE(99b,101b)
23145 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
23146 + : "1"(to), "2"(from), "0"(size)
23147 + : "eax", "edx", "memory");
23148 + return size;
23149 +}
23150 +
23151 +static unsigned long __size_overflow(3)
23152 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23153 {
23154 int d0, d1;
23155 __asm__ __volatile__(
23156 " .align 2,0x90\n"
23157 - "0: movl 32(%4), %%eax\n"
23158 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23159 " cmpl $67, %0\n"
23160 " jbe 2f\n"
23161 - "1: movl 64(%4), %%eax\n"
23162 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23163 " .align 2,0x90\n"
23164 - "2: movl 0(%4), %%eax\n"
23165 - "21: movl 4(%4), %%edx\n"
23166 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23167 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23168 " movl %%eax, 0(%3)\n"
23169 " movl %%edx, 4(%3)\n"
23170 - "3: movl 8(%4), %%eax\n"
23171 - "31: movl 12(%4),%%edx\n"
23172 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23173 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23174 " movl %%eax, 8(%3)\n"
23175 " movl %%edx, 12(%3)\n"
23176 - "4: movl 16(%4), %%eax\n"
23177 - "41: movl 20(%4), %%edx\n"
23178 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23179 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23180 " movl %%eax, 16(%3)\n"
23181 " movl %%edx, 20(%3)\n"
23182 - "10: movl 24(%4), %%eax\n"
23183 - "51: movl 28(%4), %%edx\n"
23184 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23185 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23186 " movl %%eax, 24(%3)\n"
23187 " movl %%edx, 28(%3)\n"
23188 - "11: movl 32(%4), %%eax\n"
23189 - "61: movl 36(%4), %%edx\n"
23190 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23191 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23192 " movl %%eax, 32(%3)\n"
23193 " movl %%edx, 36(%3)\n"
23194 - "12: movl 40(%4), %%eax\n"
23195 - "71: movl 44(%4), %%edx\n"
23196 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23197 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23198 " movl %%eax, 40(%3)\n"
23199 " movl %%edx, 44(%3)\n"
23200 - "13: movl 48(%4), %%eax\n"
23201 - "81: movl 52(%4), %%edx\n"
23202 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23203 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23204 " movl %%eax, 48(%3)\n"
23205 " movl %%edx, 52(%3)\n"
23206 - "14: movl 56(%4), %%eax\n"
23207 - "91: movl 60(%4), %%edx\n"
23208 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23209 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23210 " movl %%eax, 56(%3)\n"
23211 " movl %%edx, 60(%3)\n"
23212 " addl $-64, %0\n"
23213 @@ -252,9 +360,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23214 " shrl $2, %0\n"
23215 " andl $3, %%eax\n"
23216 " cld\n"
23217 - "6: rep; movsl\n"
23218 + "6: rep; "__copyuser_seg" movsl\n"
23219 " movl %%eax,%0\n"
23220 - "7: rep; movsb\n"
23221 + "7: rep; "__copyuser_seg" movsb\n"
23222 "8:\n"
23223 ".section .fixup,\"ax\"\n"
23224 "9: lea 0(%%eax,%0,4),%0\n"
23225 @@ -297,48 +405,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23226 * hyoshiok@miraclelinux.com
23227 */
23228
23229 -static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23230 +static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
23231 const void __user *from, unsigned long size)
23232 {
23233 int d0, d1;
23234
23235 __asm__ __volatile__(
23236 " .align 2,0x90\n"
23237 - "0: movl 32(%4), %%eax\n"
23238 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23239 " cmpl $67, %0\n"
23240 " jbe 2f\n"
23241 - "1: movl 64(%4), %%eax\n"
23242 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23243 " .align 2,0x90\n"
23244 - "2: movl 0(%4), %%eax\n"
23245 - "21: movl 4(%4), %%edx\n"
23246 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23247 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23248 " movnti %%eax, 0(%3)\n"
23249 " movnti %%edx, 4(%3)\n"
23250 - "3: movl 8(%4), %%eax\n"
23251 - "31: movl 12(%4),%%edx\n"
23252 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23253 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23254 " movnti %%eax, 8(%3)\n"
23255 " movnti %%edx, 12(%3)\n"
23256 - "4: movl 16(%4), %%eax\n"
23257 - "41: movl 20(%4), %%edx\n"
23258 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23259 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23260 " movnti %%eax, 16(%3)\n"
23261 " movnti %%edx, 20(%3)\n"
23262 - "10: movl 24(%4), %%eax\n"
23263 - "51: movl 28(%4), %%edx\n"
23264 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23265 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23266 " movnti %%eax, 24(%3)\n"
23267 " movnti %%edx, 28(%3)\n"
23268 - "11: movl 32(%4), %%eax\n"
23269 - "61: movl 36(%4), %%edx\n"
23270 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23271 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23272 " movnti %%eax, 32(%3)\n"
23273 " movnti %%edx, 36(%3)\n"
23274 - "12: movl 40(%4), %%eax\n"
23275 - "71: movl 44(%4), %%edx\n"
23276 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23277 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23278 " movnti %%eax, 40(%3)\n"
23279 " movnti %%edx, 44(%3)\n"
23280 - "13: movl 48(%4), %%eax\n"
23281 - "81: movl 52(%4), %%edx\n"
23282 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23283 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23284 " movnti %%eax, 48(%3)\n"
23285 " movnti %%edx, 52(%3)\n"
23286 - "14: movl 56(%4), %%eax\n"
23287 - "91: movl 60(%4), %%edx\n"
23288 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23289 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23290 " movnti %%eax, 56(%3)\n"
23291 " movnti %%edx, 60(%3)\n"
23292 " addl $-64, %0\n"
23293 @@ -351,9 +459,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23294 " shrl $2, %0\n"
23295 " andl $3, %%eax\n"
23296 " cld\n"
23297 - "6: rep; movsl\n"
23298 + "6: rep; "__copyuser_seg" movsl\n"
23299 " movl %%eax,%0\n"
23300 - "7: rep; movsb\n"
23301 + "7: rep; "__copyuser_seg" movsb\n"
23302 "8:\n"
23303 ".section .fixup,\"ax\"\n"
23304 "9: lea 0(%%eax,%0,4),%0\n"
23305 @@ -391,48 +499,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23306 return size;
23307 }
23308
23309 -static unsigned long __copy_user_intel_nocache(void *to,
23310 +static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
23311 const void __user *from, unsigned long size)
23312 {
23313 int d0, d1;
23314
23315 __asm__ __volatile__(
23316 " .align 2,0x90\n"
23317 - "0: movl 32(%4), %%eax\n"
23318 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23319 " cmpl $67, %0\n"
23320 " jbe 2f\n"
23321 - "1: movl 64(%4), %%eax\n"
23322 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23323 " .align 2,0x90\n"
23324 - "2: movl 0(%4), %%eax\n"
23325 - "21: movl 4(%4), %%edx\n"
23326 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23327 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23328 " movnti %%eax, 0(%3)\n"
23329 " movnti %%edx, 4(%3)\n"
23330 - "3: movl 8(%4), %%eax\n"
23331 - "31: movl 12(%4),%%edx\n"
23332 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23333 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23334 " movnti %%eax, 8(%3)\n"
23335 " movnti %%edx, 12(%3)\n"
23336 - "4: movl 16(%4), %%eax\n"
23337 - "41: movl 20(%4), %%edx\n"
23338 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23339 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23340 " movnti %%eax, 16(%3)\n"
23341 " movnti %%edx, 20(%3)\n"
23342 - "10: movl 24(%4), %%eax\n"
23343 - "51: movl 28(%4), %%edx\n"
23344 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23345 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23346 " movnti %%eax, 24(%3)\n"
23347 " movnti %%edx, 28(%3)\n"
23348 - "11: movl 32(%4), %%eax\n"
23349 - "61: movl 36(%4), %%edx\n"
23350 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23351 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23352 " movnti %%eax, 32(%3)\n"
23353 " movnti %%edx, 36(%3)\n"
23354 - "12: movl 40(%4), %%eax\n"
23355 - "71: movl 44(%4), %%edx\n"
23356 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23357 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23358 " movnti %%eax, 40(%3)\n"
23359 " movnti %%edx, 44(%3)\n"
23360 - "13: movl 48(%4), %%eax\n"
23361 - "81: movl 52(%4), %%edx\n"
23362 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23363 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23364 " movnti %%eax, 48(%3)\n"
23365 " movnti %%edx, 52(%3)\n"
23366 - "14: movl 56(%4), %%eax\n"
23367 - "91: movl 60(%4), %%edx\n"
23368 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23369 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23370 " movnti %%eax, 56(%3)\n"
23371 " movnti %%edx, 60(%3)\n"
23372 " addl $-64, %0\n"
23373 @@ -445,9 +553,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
23374 " shrl $2, %0\n"
23375 " andl $3, %%eax\n"
23376 " cld\n"
23377 - "6: rep; movsl\n"
23378 + "6: rep; "__copyuser_seg" movsl\n"
23379 " movl %%eax,%0\n"
23380 - "7: rep; movsb\n"
23381 + "7: rep; "__copyuser_seg" movsb\n"
23382 "8:\n"
23383 ".section .fixup,\"ax\"\n"
23384 "9: lea 0(%%eax,%0,4),%0\n"
23385 @@ -487,32 +595,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
23386 */
23387 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
23388 unsigned long size);
23389 -unsigned long __copy_user_intel(void __user *to, const void *from,
23390 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
23391 + unsigned long size);
23392 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
23393 unsigned long size);
23394 unsigned long __copy_user_zeroing_intel_nocache(void *to,
23395 const void __user *from, unsigned long size);
23396 #endif /* CONFIG_X86_INTEL_USERCOPY */
23397
23398 /* Generic arbitrary sized copy. */
23399 -#define __copy_user(to, from, size) \
23400 +#define __copy_user(to, from, size, prefix, set, restore) \
23401 do { \
23402 int __d0, __d1, __d2; \
23403 __asm__ __volatile__( \
23404 + set \
23405 " cmp $7,%0\n" \
23406 " jbe 1f\n" \
23407 " movl %1,%0\n" \
23408 " negl %0\n" \
23409 " andl $7,%0\n" \
23410 " subl %0,%3\n" \
23411 - "4: rep; movsb\n" \
23412 + "4: rep; "prefix"movsb\n" \
23413 " movl %3,%0\n" \
23414 " shrl $2,%0\n" \
23415 " andl $3,%3\n" \
23416 " .align 2,0x90\n" \
23417 - "0: rep; movsl\n" \
23418 + "0: rep; "prefix"movsl\n" \
23419 " movl %3,%0\n" \
23420 - "1: rep; movsb\n" \
23421 + "1: rep; "prefix"movsb\n" \
23422 "2:\n" \
23423 + restore \
23424 ".section .fixup,\"ax\"\n" \
23425 "5: addl %3,%0\n" \
23426 " jmp 2b\n" \
23427 @@ -537,14 +649,14 @@ do { \
23428 " negl %0\n" \
23429 " andl $7,%0\n" \
23430 " subl %0,%3\n" \
23431 - "4: rep; movsb\n" \
23432 + "4: rep; "__copyuser_seg"movsb\n" \
23433 " movl %3,%0\n" \
23434 " shrl $2,%0\n" \
23435 " andl $3,%3\n" \
23436 " .align 2,0x90\n" \
23437 - "0: rep; movsl\n" \
23438 + "0: rep; "__copyuser_seg"movsl\n" \
23439 " movl %3,%0\n" \
23440 - "1: rep; movsb\n" \
23441 + "1: rep; "__copyuser_seg"movsb\n" \
23442 "2:\n" \
23443 ".section .fixup,\"ax\"\n" \
23444 "5: addl %3,%0\n" \
23445 @@ -627,9 +739,9 @@ survive:
23446 }
23447 #endif
23448 if (movsl_is_ok(to, from, n))
23449 - __copy_user(to, from, n);
23450 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
23451 else
23452 - n = __copy_user_intel(to, from, n);
23453 + n = __generic_copy_to_user_intel(to, from, n);
23454 return n;
23455 }
23456 EXPORT_SYMBOL(__copy_to_user_ll);
23457 @@ -649,10 +761,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
23458 unsigned long n)
23459 {
23460 if (movsl_is_ok(to, from, n))
23461 - __copy_user(to, from, n);
23462 + __copy_user(to, from, n, __copyuser_seg, "", "");
23463 else
23464 - n = __copy_user_intel((void __user *)to,
23465 - (const void *)from, n);
23466 + n = __generic_copy_from_user_intel(to, from, n);
23467 return n;
23468 }
23469 EXPORT_SYMBOL(__copy_from_user_ll_nozero);
23470 @@ -679,65 +790,50 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
23471 if (n > 64 && cpu_has_xmm2)
23472 n = __copy_user_intel_nocache(to, from, n);
23473 else
23474 - __copy_user(to, from, n);
23475 + __copy_user(to, from, n, __copyuser_seg, "", "");
23476 #else
23477 - __copy_user(to, from, n);
23478 + __copy_user(to, from, n, __copyuser_seg, "", "");
23479 #endif
23480 return n;
23481 }
23482 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
23483
23484 -/**
23485 - * copy_to_user: - Copy a block of data into user space.
23486 - * @to: Destination address, in user space.
23487 - * @from: Source address, in kernel space.
23488 - * @n: Number of bytes to copy.
23489 - *
23490 - * Context: User context only. This function may sleep.
23491 - *
23492 - * Copy data from kernel space to user space.
23493 - *
23494 - * Returns number of bytes that could not be copied.
23495 - * On success, this will be zero.
23496 - */
23497 -unsigned long
23498 -copy_to_user(void __user *to, const void *from, unsigned long n)
23499 -{
23500 - if (access_ok(VERIFY_WRITE, to, n))
23501 - n = __copy_to_user(to, from, n);
23502 - return n;
23503 -}
23504 -EXPORT_SYMBOL(copy_to_user);
23505 -
23506 -/**
23507 - * copy_from_user: - Copy a block of data from user space.
23508 - * @to: Destination address, in kernel space.
23509 - * @from: Source address, in user space.
23510 - * @n: Number of bytes to copy.
23511 - *
23512 - * Context: User context only. This function may sleep.
23513 - *
23514 - * Copy data from user space to kernel space.
23515 - *
23516 - * Returns number of bytes that could not be copied.
23517 - * On success, this will be zero.
23518 - *
23519 - * If some data could not be copied, this function will pad the copied
23520 - * data to the requested size using zero bytes.
23521 - */
23522 -unsigned long
23523 -_copy_from_user(void *to, const void __user *from, unsigned long n)
23524 -{
23525 - if (access_ok(VERIFY_READ, from, n))
23526 - n = __copy_from_user(to, from, n);
23527 - else
23528 - memset(to, 0, n);
23529 - return n;
23530 -}
23531 -EXPORT_SYMBOL(_copy_from_user);
23532 -
23533 void copy_from_user_overflow(void)
23534 {
23535 WARN(1, "Buffer overflow detected!\n");
23536 }
23537 EXPORT_SYMBOL(copy_from_user_overflow);
23538 +
23539 +void copy_to_user_overflow(void)
23540 +{
23541 + WARN(1, "Buffer overflow detected!\n");
23542 +}
23543 +EXPORT_SYMBOL(copy_to_user_overflow);
23544 +
23545 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23546 +void __set_fs(mm_segment_t x)
23547 +{
23548 + switch (x.seg) {
23549 + case 0:
23550 + loadsegment(gs, 0);
23551 + break;
23552 + case TASK_SIZE_MAX:
23553 + loadsegment(gs, __USER_DS);
23554 + break;
23555 + case -1UL:
23556 + loadsegment(gs, __KERNEL_DS);
23557 + break;
23558 + default:
23559 + BUG();
23560 + }
23561 + return;
23562 +}
23563 +EXPORT_SYMBOL(__set_fs);
23564 +
23565 +void set_fs(mm_segment_t x)
23566 +{
23567 + current_thread_info()->addr_limit = x;
23568 + __set_fs(x);
23569 +}
23570 +EXPORT_SYMBOL(set_fs);
23571 +#endif
23572 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
23573 index e5b130b..7d33980 100644
23574 --- a/arch/x86/lib/usercopy_64.c
23575 +++ b/arch/x86/lib/usercopy_64.c
23576 @@ -38,7 +38,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
23577 _ASM_EXTABLE(0b,3b)
23578 _ASM_EXTABLE(1b,2b)
23579 : [size8] "=&c"(size), [dst] "=&D" (__d0)
23580 - : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
23581 + : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
23582 [zero] "r" (0UL), [eight] "r" (8UL));
23583 return size;
23584 }
23585 @@ -52,12 +52,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
23586 }
23587 EXPORT_SYMBOL(clear_user);
23588
23589 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
23590 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
23591 {
23592 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23593 - return copy_user_generic((__force void *)to, (__force void *)from, len);
23594 - }
23595 - return len;
23596 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
23597 + return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
23598 + return len;
23599 }
23600 EXPORT_SYMBOL(copy_in_user);
23601
23602 @@ -67,7 +66,7 @@ EXPORT_SYMBOL(copy_in_user);
23603 * it is not necessary to optimize tail handling.
23604 */
23605 unsigned long
23606 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23607 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
23608 {
23609 char c;
23610 unsigned zero_len;
23611 @@ -84,3 +83,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23612 break;
23613 return len;
23614 }
23615 +
23616 +void copy_from_user_overflow(void)
23617 +{
23618 + WARN(1, "Buffer overflow detected!\n");
23619 +}
23620 +EXPORT_SYMBOL(copy_from_user_overflow);
23621 +
23622 +void copy_to_user_overflow(void)
23623 +{
23624 + WARN(1, "Buffer overflow detected!\n");
23625 +}
23626 +EXPORT_SYMBOL(copy_to_user_overflow);
23627 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
23628 index 903ec1e..c4166b2 100644
23629 --- a/arch/x86/mm/extable.c
23630 +++ b/arch/x86/mm/extable.c
23631 @@ -6,12 +6,24 @@
23632 static inline unsigned long
23633 ex_insn_addr(const struct exception_table_entry *x)
23634 {
23635 - return (unsigned long)&x->insn + x->insn;
23636 + unsigned long reloc = 0;
23637 +
23638 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23639 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23640 +#endif
23641 +
23642 + return (unsigned long)&x->insn + x->insn + reloc;
23643 }
23644 static inline unsigned long
23645 ex_fixup_addr(const struct exception_table_entry *x)
23646 {
23647 - return (unsigned long)&x->fixup + x->fixup;
23648 + unsigned long reloc = 0;
23649 +
23650 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23651 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23652 +#endif
23653 +
23654 + return (unsigned long)&x->fixup + x->fixup + reloc;
23655 }
23656
23657 int fixup_exception(struct pt_regs *regs)
23658 @@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
23659 unsigned long new_ip;
23660
23661 #ifdef CONFIG_PNPBIOS
23662 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
23663 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
23664 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
23665 extern u32 pnp_bios_is_utter_crap;
23666 pnp_bios_is_utter_crap = 1;
23667 @@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
23668 i += 4;
23669 p->fixup -= i;
23670 i += 4;
23671 +
23672 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23673 + BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
23674 + p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23675 + p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23676 +#endif
23677 +
23678 }
23679 }
23680
23681 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
23682 index 76dcd9d..e9dffde 100644
23683 --- a/arch/x86/mm/fault.c
23684 +++ b/arch/x86/mm/fault.c
23685 @@ -13,11 +13,18 @@
23686 #include <linux/perf_event.h> /* perf_sw_event */
23687 #include <linux/hugetlb.h> /* hstate_index_to_shift */
23688 #include <linux/prefetch.h> /* prefetchw */
23689 +#include <linux/unistd.h>
23690 +#include <linux/compiler.h>
23691
23692 #include <asm/traps.h> /* dotraplinkage, ... */
23693 #include <asm/pgalloc.h> /* pgd_*(), ... */
23694 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
23695 #include <asm/fixmap.h> /* VSYSCALL_START */
23696 +#include <asm/tlbflush.h>
23697 +
23698 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23699 +#include <asm/stacktrace.h>
23700 +#endif
23701
23702 /*
23703 * Page fault error code bits:
23704 @@ -55,7 +62,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
23705 int ret = 0;
23706
23707 /* kprobe_running() needs smp_processor_id() */
23708 - if (kprobes_built_in() && !user_mode_vm(regs)) {
23709 + if (kprobes_built_in() && !user_mode(regs)) {
23710 preempt_disable();
23711 if (kprobe_running() && kprobe_fault_handler(regs, 14))
23712 ret = 1;
23713 @@ -116,7 +123,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
23714 return !instr_lo || (instr_lo>>1) == 1;
23715 case 0x00:
23716 /* Prefetch instruction is 0x0F0D or 0x0F18 */
23717 - if (probe_kernel_address(instr, opcode))
23718 + if (user_mode(regs)) {
23719 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23720 + return 0;
23721 + } else if (probe_kernel_address(instr, opcode))
23722 return 0;
23723
23724 *prefetch = (instr_lo == 0xF) &&
23725 @@ -150,7 +160,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
23726 while (instr < max_instr) {
23727 unsigned char opcode;
23728
23729 - if (probe_kernel_address(instr, opcode))
23730 + if (user_mode(regs)) {
23731 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23732 + break;
23733 + } else if (probe_kernel_address(instr, opcode))
23734 break;
23735
23736 instr++;
23737 @@ -181,6 +194,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
23738 force_sig_info(si_signo, &info, tsk);
23739 }
23740
23741 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23742 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
23743 +#endif
23744 +
23745 +#ifdef CONFIG_PAX_EMUTRAMP
23746 +static int pax_handle_fetch_fault(struct pt_regs *regs);
23747 +#endif
23748 +
23749 +#ifdef CONFIG_PAX_PAGEEXEC
23750 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
23751 +{
23752 + pgd_t *pgd;
23753 + pud_t *pud;
23754 + pmd_t *pmd;
23755 +
23756 + pgd = pgd_offset(mm, address);
23757 + if (!pgd_present(*pgd))
23758 + return NULL;
23759 + pud = pud_offset(pgd, address);
23760 + if (!pud_present(*pud))
23761 + return NULL;
23762 + pmd = pmd_offset(pud, address);
23763 + if (!pmd_present(*pmd))
23764 + return NULL;
23765 + return pmd;
23766 +}
23767 +#endif
23768 +
23769 DEFINE_SPINLOCK(pgd_lock);
23770 LIST_HEAD(pgd_list);
23771
23772 @@ -231,10 +272,22 @@ void vmalloc_sync_all(void)
23773 for (address = VMALLOC_START & PMD_MASK;
23774 address >= TASK_SIZE && address < FIXADDR_TOP;
23775 address += PMD_SIZE) {
23776 +
23777 +#ifdef CONFIG_PAX_PER_CPU_PGD
23778 + unsigned long cpu;
23779 +#else
23780 struct page *page;
23781 +#endif
23782
23783 spin_lock(&pgd_lock);
23784 +
23785 +#ifdef CONFIG_PAX_PER_CPU_PGD
23786 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
23787 + pgd_t *pgd = get_cpu_pgd(cpu);
23788 + pmd_t *ret;
23789 +#else
23790 list_for_each_entry(page, &pgd_list, lru) {
23791 + pgd_t *pgd = page_address(page);
23792 spinlock_t *pgt_lock;
23793 pmd_t *ret;
23794
23795 @@ -242,8 +295,13 @@ void vmalloc_sync_all(void)
23796 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
23797
23798 spin_lock(pgt_lock);
23799 - ret = vmalloc_sync_one(page_address(page), address);
23800 +#endif
23801 +
23802 + ret = vmalloc_sync_one(pgd, address);
23803 +
23804 +#ifndef CONFIG_PAX_PER_CPU_PGD
23805 spin_unlock(pgt_lock);
23806 +#endif
23807
23808 if (!ret)
23809 break;
23810 @@ -277,6 +335,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23811 * an interrupt in the middle of a task switch..
23812 */
23813 pgd_paddr = read_cr3();
23814 +
23815 +#ifdef CONFIG_PAX_PER_CPU_PGD
23816 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
23817 +#endif
23818 +
23819 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
23820 if (!pmd_k)
23821 return -1;
23822 @@ -372,7 +435,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23823 * happen within a race in page table update. In the later
23824 * case just flush:
23825 */
23826 +
23827 +#ifdef CONFIG_PAX_PER_CPU_PGD
23828 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
23829 + pgd = pgd_offset_cpu(smp_processor_id(), address);
23830 +#else
23831 pgd = pgd_offset(current->active_mm, address);
23832 +#endif
23833 +
23834 pgd_ref = pgd_offset_k(address);
23835 if (pgd_none(*pgd_ref))
23836 return -1;
23837 @@ -540,7 +610,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
23838 static int is_errata100(struct pt_regs *regs, unsigned long address)
23839 {
23840 #ifdef CONFIG_X86_64
23841 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
23842 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
23843 return 1;
23844 #endif
23845 return 0;
23846 @@ -567,7 +637,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
23847 }
23848
23849 static const char nx_warning[] = KERN_CRIT
23850 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
23851 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
23852
23853 static void
23854 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23855 @@ -576,15 +646,26 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23856 if (!oops_may_print())
23857 return;
23858
23859 - if (error_code & PF_INSTR) {
23860 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
23861 unsigned int level;
23862
23863 pte_t *pte = lookup_address(address, &level);
23864
23865 if (pte && pte_present(*pte) && !pte_exec(*pte))
23866 - printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
23867 + printk(nx_warning, from_kuid(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
23868 }
23869
23870 +#ifdef CONFIG_PAX_KERNEXEC
23871 + if (init_mm.start_code <= address && address < init_mm.end_code) {
23872 + if (current->signal->curr_ip)
23873 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23874 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
23875 + else
23876 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23877 + current->comm, task_pid_nr(current), current_uid(), current_euid());
23878 + }
23879 +#endif
23880 +
23881 printk(KERN_ALERT "BUG: unable to handle kernel ");
23882 if (address < PAGE_SIZE)
23883 printk(KERN_CONT "NULL pointer dereference");
23884 @@ -748,6 +829,21 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
23885 }
23886 #endif
23887
23888 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23889 + if (pax_is_fetch_fault(regs, error_code, address)) {
23890 +
23891 +#ifdef CONFIG_PAX_EMUTRAMP
23892 + switch (pax_handle_fetch_fault(regs)) {
23893 + case 2:
23894 + return;
23895 + }
23896 +#endif
23897 +
23898 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23899 + do_group_exit(SIGKILL);
23900 + }
23901 +#endif
23902 +
23903 if (unlikely(show_unhandled_signals))
23904 show_signal_msg(regs, error_code, address, tsk);
23905
23906 @@ -844,7 +940,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
23907 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
23908 printk(KERN_ERR
23909 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
23910 - tsk->comm, tsk->pid, address);
23911 + tsk->comm, task_pid_nr(tsk), address);
23912 code = BUS_MCEERR_AR;
23913 }
23914 #endif
23915 @@ -900,6 +996,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
23916 return 1;
23917 }
23918
23919 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23920 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
23921 +{
23922 + pte_t *pte;
23923 + pmd_t *pmd;
23924 + spinlock_t *ptl;
23925 + unsigned char pte_mask;
23926 +
23927 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
23928 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
23929 + return 0;
23930 +
23931 + /* PaX: it's our fault, let's handle it if we can */
23932 +
23933 + /* PaX: take a look at read faults before acquiring any locks */
23934 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
23935 + /* instruction fetch attempt from a protected page in user mode */
23936 + up_read(&mm->mmap_sem);
23937 +
23938 +#ifdef CONFIG_PAX_EMUTRAMP
23939 + switch (pax_handle_fetch_fault(regs)) {
23940 + case 2:
23941 + return 1;
23942 + }
23943 +#endif
23944 +
23945 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23946 + do_group_exit(SIGKILL);
23947 + }
23948 +
23949 + pmd = pax_get_pmd(mm, address);
23950 + if (unlikely(!pmd))
23951 + return 0;
23952 +
23953 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
23954 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
23955 + pte_unmap_unlock(pte, ptl);
23956 + return 0;
23957 + }
23958 +
23959 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
23960 + /* write attempt to a protected page in user mode */
23961 + pte_unmap_unlock(pte, ptl);
23962 + return 0;
23963 + }
23964 +
23965 +#ifdef CONFIG_SMP
23966 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
23967 +#else
23968 + if (likely(address > get_limit(regs->cs)))
23969 +#endif
23970 + {
23971 + set_pte(pte, pte_mkread(*pte));
23972 + __flush_tlb_one(address);
23973 + pte_unmap_unlock(pte, ptl);
23974 + up_read(&mm->mmap_sem);
23975 + return 1;
23976 + }
23977 +
23978 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
23979 +
23980 + /*
23981 + * PaX: fill DTLB with user rights and retry
23982 + */
23983 + __asm__ __volatile__ (
23984 + "orb %2,(%1)\n"
23985 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
23986 +/*
23987 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
23988 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
23989 + * page fault when examined during a TLB load attempt. this is true not only
23990 + * for PTEs holding a non-present entry but also present entries that will
23991 + * raise a page fault (such as those set up by PaX, or the copy-on-write
23992 + * mechanism). in effect it means that we do *not* need to flush the TLBs
23993 + * for our target pages since their PTEs are simply not in the TLBs at all.
23994 +
23995 + * the best thing in omitting it is that we gain around 15-20% speed in the
23996 + * fast path of the page fault handler and can get rid of tracing since we
23997 + * can no longer flush unintended entries.
23998 + */
23999 + "invlpg (%0)\n"
24000 +#endif
24001 + __copyuser_seg"testb $0,(%0)\n"
24002 + "xorb %3,(%1)\n"
24003 + :
24004 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
24005 + : "memory", "cc");
24006 + pte_unmap_unlock(pte, ptl);
24007 + up_read(&mm->mmap_sem);
24008 + return 1;
24009 +}
24010 +#endif
24011 +
24012 /*
24013 * Handle a spurious fault caused by a stale TLB entry.
24014 *
24015 @@ -972,6 +1161,9 @@ int show_unhandled_signals = 1;
24016 static inline int
24017 access_error(unsigned long error_code, struct vm_area_struct *vma)
24018 {
24019 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
24020 + return 1;
24021 +
24022 if (error_code & PF_WRITE) {
24023 /* write, present and write, not present: */
24024 if (unlikely(!(vma->vm_flags & VM_WRITE)))
24025 @@ -1005,18 +1197,33 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
24026 {
24027 struct vm_area_struct *vma;
24028 struct task_struct *tsk;
24029 - unsigned long address;
24030 struct mm_struct *mm;
24031 int fault;
24032 int write = error_code & PF_WRITE;
24033 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
24034 (write ? FAULT_FLAG_WRITE : 0);
24035
24036 - tsk = current;
24037 - mm = tsk->mm;
24038 -
24039 /* Get the faulting address: */
24040 - address = read_cr2();
24041 + unsigned long address = read_cr2();
24042 +
24043 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24044 + if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
24045 + if (!search_exception_tables(regs->ip)) {
24046 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
24047 + bad_area_nosemaphore(regs, error_code, address);
24048 + return;
24049 + }
24050 + if (address < PAX_USER_SHADOW_BASE) {
24051 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
24052 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
24053 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
24054 + } else
24055 + address -= PAX_USER_SHADOW_BASE;
24056 + }
24057 +#endif
24058 +
24059 + tsk = current;
24060 + mm = tsk->mm;
24061
24062 /*
24063 * Detect and handle instructions that would cause a page fault for
24064 @@ -1077,7 +1284,7 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
24065 * User-mode registers count as a user access even for any
24066 * potential system fault or CPU buglet:
24067 */
24068 - if (user_mode_vm(regs)) {
24069 + if (user_mode(regs)) {
24070 local_irq_enable();
24071 error_code |= PF_USER;
24072 } else {
24073 @@ -1132,6 +1339,11 @@ retry:
24074 might_sleep();
24075 }
24076
24077 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
24078 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
24079 + return;
24080 +#endif
24081 +
24082 vma = find_vma(mm, address);
24083 if (unlikely(!vma)) {
24084 bad_area(regs, error_code, address);
24085 @@ -1143,18 +1355,24 @@ retry:
24086 bad_area(regs, error_code, address);
24087 return;
24088 }
24089 - if (error_code & PF_USER) {
24090 - /*
24091 - * Accessing the stack below %sp is always a bug.
24092 - * The large cushion allows instructions like enter
24093 - * and pusha to work. ("enter $65535, $31" pushes
24094 - * 32 pointers and then decrements %sp by 65535.)
24095 - */
24096 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
24097 - bad_area(regs, error_code, address);
24098 - return;
24099 - }
24100 + /*
24101 + * Accessing the stack below %sp is always a bug.
24102 + * The large cushion allows instructions like enter
24103 + * and pusha to work. ("enter $65535, $31" pushes
24104 + * 32 pointers and then decrements %sp by 65535.)
24105 + */
24106 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
24107 + bad_area(regs, error_code, address);
24108 + return;
24109 }
24110 +
24111 +#ifdef CONFIG_PAX_SEGMEXEC
24112 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
24113 + bad_area(regs, error_code, address);
24114 + return;
24115 + }
24116 +#endif
24117 +
24118 if (unlikely(expand_stack(vma, address))) {
24119 bad_area(regs, error_code, address);
24120 return;
24121 @@ -1209,3 +1427,292 @@ good_area:
24122
24123 up_read(&mm->mmap_sem);
24124 }
24125 +
24126 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24127 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
24128 +{
24129 + struct mm_struct *mm = current->mm;
24130 + unsigned long ip = regs->ip;
24131 +
24132 + if (v8086_mode(regs))
24133 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
24134 +
24135 +#ifdef CONFIG_PAX_PAGEEXEC
24136 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
24137 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
24138 + return true;
24139 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
24140 + return true;
24141 + return false;
24142 + }
24143 +#endif
24144 +
24145 +#ifdef CONFIG_PAX_SEGMEXEC
24146 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
24147 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
24148 + return true;
24149 + return false;
24150 + }
24151 +#endif
24152 +
24153 + return false;
24154 +}
24155 +#endif
24156 +
24157 +#ifdef CONFIG_PAX_EMUTRAMP
24158 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
24159 +{
24160 + int err;
24161 +
24162 + do { /* PaX: libffi trampoline emulation */
24163 + unsigned char mov, jmp;
24164 + unsigned int addr1, addr2;
24165 +
24166 +#ifdef CONFIG_X86_64
24167 + if ((regs->ip + 9) >> 32)
24168 + break;
24169 +#endif
24170 +
24171 + err = get_user(mov, (unsigned char __user *)regs->ip);
24172 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24173 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24174 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24175 +
24176 + if (err)
24177 + break;
24178 +
24179 + if (mov == 0xB8 && jmp == 0xE9) {
24180 + regs->ax = addr1;
24181 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24182 + return 2;
24183 + }
24184 + } while (0);
24185 +
24186 + do { /* PaX: gcc trampoline emulation #1 */
24187 + unsigned char mov1, mov2;
24188 + unsigned short jmp;
24189 + unsigned int addr1, addr2;
24190 +
24191 +#ifdef CONFIG_X86_64
24192 + if ((regs->ip + 11) >> 32)
24193 + break;
24194 +#endif
24195 +
24196 + err = get_user(mov1, (unsigned char __user *)regs->ip);
24197 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24198 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
24199 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24200 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
24201 +
24202 + if (err)
24203 + break;
24204 +
24205 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
24206 + regs->cx = addr1;
24207 + regs->ax = addr2;
24208 + regs->ip = addr2;
24209 + return 2;
24210 + }
24211 + } while (0);
24212 +
24213 + do { /* PaX: gcc trampoline emulation #2 */
24214 + unsigned char mov, jmp;
24215 + unsigned int addr1, addr2;
24216 +
24217 +#ifdef CONFIG_X86_64
24218 + if ((regs->ip + 9) >> 32)
24219 + break;
24220 +#endif
24221 +
24222 + err = get_user(mov, (unsigned char __user *)regs->ip);
24223 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24224 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24225 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24226 +
24227 + if (err)
24228 + break;
24229 +
24230 + if (mov == 0xB9 && jmp == 0xE9) {
24231 + regs->cx = addr1;
24232 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24233 + return 2;
24234 + }
24235 + } while (0);
24236 +
24237 + return 1; /* PaX in action */
24238 +}
24239 +
24240 +#ifdef CONFIG_X86_64
24241 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
24242 +{
24243 + int err;
24244 +
24245 + do { /* PaX: libffi trampoline emulation */
24246 + unsigned short mov1, mov2, jmp1;
24247 + unsigned char stcclc, jmp2;
24248 + unsigned long addr1, addr2;
24249 +
24250 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24251 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24252 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24253 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24254 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
24255 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
24256 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
24257 +
24258 + if (err)
24259 + break;
24260 +
24261 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24262 + regs->r11 = addr1;
24263 + regs->r10 = addr2;
24264 + if (stcclc == 0xF8)
24265 + regs->flags &= ~X86_EFLAGS_CF;
24266 + else
24267 + regs->flags |= X86_EFLAGS_CF;
24268 + regs->ip = addr1;
24269 + return 2;
24270 + }
24271 + } while (0);
24272 +
24273 + do { /* PaX: gcc trampoline emulation #1 */
24274 + unsigned short mov1, mov2, jmp1;
24275 + unsigned char jmp2;
24276 + unsigned int addr1;
24277 + unsigned long addr2;
24278 +
24279 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24280 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
24281 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
24282 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
24283 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
24284 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
24285 +
24286 + if (err)
24287 + break;
24288 +
24289 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24290 + regs->r11 = addr1;
24291 + regs->r10 = addr2;
24292 + regs->ip = addr1;
24293 + return 2;
24294 + }
24295 + } while (0);
24296 +
24297 + do { /* PaX: gcc trampoline emulation #2 */
24298 + unsigned short mov1, mov2, jmp1;
24299 + unsigned char jmp2;
24300 + unsigned long addr1, addr2;
24301 +
24302 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24303 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24304 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24305 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24306 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
24307 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
24308 +
24309 + if (err)
24310 + break;
24311 +
24312 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24313 + regs->r11 = addr1;
24314 + regs->r10 = addr2;
24315 + regs->ip = addr1;
24316 + return 2;
24317 + }
24318 + } while (0);
24319 +
24320 + return 1; /* PaX in action */
24321 +}
24322 +#endif
24323 +
24324 +/*
24325 + * PaX: decide what to do with offenders (regs->ip = fault address)
24326 + *
24327 + * returns 1 when task should be killed
24328 + * 2 when gcc trampoline was detected
24329 + */
24330 +static int pax_handle_fetch_fault(struct pt_regs *regs)
24331 +{
24332 + if (v8086_mode(regs))
24333 + return 1;
24334 +
24335 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
24336 + return 1;
24337 +
24338 +#ifdef CONFIG_X86_32
24339 + return pax_handle_fetch_fault_32(regs);
24340 +#else
24341 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
24342 + return pax_handle_fetch_fault_32(regs);
24343 + else
24344 + return pax_handle_fetch_fault_64(regs);
24345 +#endif
24346 +}
24347 +#endif
24348 +
24349 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24350 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
24351 +{
24352 + long i;
24353 +
24354 + printk(KERN_ERR "PAX: bytes at PC: ");
24355 + for (i = 0; i < 20; i++) {
24356 + unsigned char c;
24357 + if (get_user(c, (unsigned char __force_user *)pc+i))
24358 + printk(KERN_CONT "?? ");
24359 + else
24360 + printk(KERN_CONT "%02x ", c);
24361 + }
24362 + printk("\n");
24363 +
24364 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
24365 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
24366 + unsigned long c;
24367 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
24368 +#ifdef CONFIG_X86_32
24369 + printk(KERN_CONT "???????? ");
24370 +#else
24371 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
24372 + printk(KERN_CONT "???????? ???????? ");
24373 + else
24374 + printk(KERN_CONT "???????????????? ");
24375 +#endif
24376 + } else {
24377 +#ifdef CONFIG_X86_64
24378 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
24379 + printk(KERN_CONT "%08x ", (unsigned int)c);
24380 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
24381 + } else
24382 +#endif
24383 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
24384 + }
24385 + }
24386 + printk("\n");
24387 +}
24388 +#endif
24389 +
24390 +/**
24391 + * probe_kernel_write(): safely attempt to write to a location
24392 + * @dst: address to write to
24393 + * @src: pointer to the data that shall be written
24394 + * @size: size of the data chunk
24395 + *
24396 + * Safely write to address @dst from the buffer at @src. If a kernel fault
24397 + * happens, handle that and return -EFAULT.
24398 + */
24399 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
24400 +{
24401 + long ret;
24402 + mm_segment_t old_fs = get_fs();
24403 +
24404 + set_fs(KERNEL_DS);
24405 + pagefault_disable();
24406 + pax_open_kernel();
24407 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
24408 + pax_close_kernel();
24409 + pagefault_enable();
24410 + set_fs(old_fs);
24411 +
24412 + return ret ? -EFAULT : 0;
24413 +}
24414 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
24415 index dd74e46..7d26398 100644
24416 --- a/arch/x86/mm/gup.c
24417 +++ b/arch/x86/mm/gup.c
24418 @@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
24419 addr = start;
24420 len = (unsigned long) nr_pages << PAGE_SHIFT;
24421 end = start + len;
24422 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24423 + if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24424 (void __user *)start, len)))
24425 return 0;
24426
24427 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
24428 index 6f31ee5..8ee4164 100644
24429 --- a/arch/x86/mm/highmem_32.c
24430 +++ b/arch/x86/mm/highmem_32.c
24431 @@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
24432 idx = type + KM_TYPE_NR*smp_processor_id();
24433 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
24434 BUG_ON(!pte_none(*(kmap_pte-idx)));
24435 +
24436 + pax_open_kernel();
24437 set_pte(kmap_pte-idx, mk_pte(page, prot));
24438 + pax_close_kernel();
24439 +
24440 arch_flush_lazy_mmu_mode();
24441
24442 return (void *)vaddr;
24443 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
24444 index b91e485..d00e7c9 100644
24445 --- a/arch/x86/mm/hugetlbpage.c
24446 +++ b/arch/x86/mm/hugetlbpage.c
24447 @@ -277,13 +277,20 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
24448 struct hstate *h = hstate_file(file);
24449 struct mm_struct *mm = current->mm;
24450 struct vm_area_struct *vma;
24451 - unsigned long start_addr;
24452 + unsigned long start_addr, pax_task_size = TASK_SIZE;
24453 +
24454 +#ifdef CONFIG_PAX_SEGMEXEC
24455 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24456 + pax_task_size = SEGMEXEC_TASK_SIZE;
24457 +#endif
24458 +
24459 + pax_task_size -= PAGE_SIZE;
24460
24461 if (len > mm->cached_hole_size) {
24462 - start_addr = mm->free_area_cache;
24463 + start_addr = mm->free_area_cache;
24464 } else {
24465 - start_addr = TASK_UNMAPPED_BASE;
24466 - mm->cached_hole_size = 0;
24467 + start_addr = mm->mmap_base;
24468 + mm->cached_hole_size = 0;
24469 }
24470
24471 full_search:
24472 @@ -291,26 +298,27 @@ full_search:
24473
24474 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
24475 /* At this point: (!vma || addr < vma->vm_end). */
24476 - if (TASK_SIZE - len < addr) {
24477 + if (pax_task_size - len < addr) {
24478 /*
24479 * Start a new search - just in case we missed
24480 * some holes.
24481 */
24482 - if (start_addr != TASK_UNMAPPED_BASE) {
24483 - start_addr = TASK_UNMAPPED_BASE;
24484 + if (start_addr != mm->mmap_base) {
24485 + start_addr = mm->mmap_base;
24486 mm->cached_hole_size = 0;
24487 goto full_search;
24488 }
24489 return -ENOMEM;
24490 }
24491 - if (!vma || addr + len <= vma->vm_start) {
24492 - mm->free_area_cache = addr + len;
24493 - return addr;
24494 - }
24495 + if (check_heap_stack_gap(vma, addr, len))
24496 + break;
24497 if (addr + mm->cached_hole_size < vma->vm_start)
24498 mm->cached_hole_size = vma->vm_start - addr;
24499 addr = ALIGN(vma->vm_end, huge_page_size(h));
24500 }
24501 +
24502 + mm->free_area_cache = addr + len;
24503 + return addr;
24504 }
24505
24506 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24507 @@ -321,9 +329,8 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24508 struct mm_struct *mm = current->mm;
24509 struct vm_area_struct *vma;
24510 unsigned long base = mm->mmap_base;
24511 - unsigned long addr = addr0;
24512 + unsigned long addr;
24513 unsigned long largest_hole = mm->cached_hole_size;
24514 - unsigned long start_addr;
24515
24516 /* don't allow allocations above current base */
24517 if (mm->free_area_cache > base)
24518 @@ -333,16 +340,15 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24519 largest_hole = 0;
24520 mm->free_area_cache = base;
24521 }
24522 -try_again:
24523 - start_addr = mm->free_area_cache;
24524
24525 /* make sure it can fit in the remaining address space */
24526 if (mm->free_area_cache < len)
24527 goto fail;
24528
24529 /* either no address requested or can't fit in requested address hole */
24530 - addr = (mm->free_area_cache - len) & huge_page_mask(h);
24531 + addr = mm->free_area_cache - len;
24532 do {
24533 + addr &= huge_page_mask(h);
24534 /*
24535 * Lookup failure means no vma is above this address,
24536 * i.e. return with success:
24537 @@ -351,10 +357,10 @@ try_again:
24538 if (!vma)
24539 return addr;
24540
24541 - if (addr + len <= vma->vm_start) {
24542 + if (check_heap_stack_gap(vma, addr, len)) {
24543 /* remember the address as a hint for next time */
24544 - mm->cached_hole_size = largest_hole;
24545 - return (mm->free_area_cache = addr);
24546 + mm->cached_hole_size = largest_hole;
24547 + return (mm->free_area_cache = addr);
24548 } else if (mm->free_area_cache == vma->vm_end) {
24549 /* pull free_area_cache down to the first hole */
24550 mm->free_area_cache = vma->vm_start;
24551 @@ -363,29 +369,34 @@ try_again:
24552
24553 /* remember the largest hole we saw so far */
24554 if (addr + largest_hole < vma->vm_start)
24555 - largest_hole = vma->vm_start - addr;
24556 + largest_hole = vma->vm_start - addr;
24557
24558 /* try just below the current vma->vm_start */
24559 - addr = (vma->vm_start - len) & huge_page_mask(h);
24560 - } while (len <= vma->vm_start);
24561 + addr = skip_heap_stack_gap(vma, len);
24562 + } while (!IS_ERR_VALUE(addr));
24563
24564 fail:
24565 /*
24566 - * if hint left us with no space for the requested
24567 - * mapping then try again:
24568 - */
24569 - if (start_addr != base) {
24570 - mm->free_area_cache = base;
24571 - largest_hole = 0;
24572 - goto try_again;
24573 - }
24574 - /*
24575 * A failed mmap() very likely causes application failure,
24576 * so fall back to the bottom-up function here. This scenario
24577 * can happen with large stack limits and large mmap()
24578 * allocations.
24579 */
24580 - mm->free_area_cache = TASK_UNMAPPED_BASE;
24581 +
24582 +#ifdef CONFIG_PAX_SEGMEXEC
24583 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24584 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
24585 + else
24586 +#endif
24587 +
24588 + mm->mmap_base = TASK_UNMAPPED_BASE;
24589 +
24590 +#ifdef CONFIG_PAX_RANDMMAP
24591 + if (mm->pax_flags & MF_PAX_RANDMMAP)
24592 + mm->mmap_base += mm->delta_mmap;
24593 +#endif
24594 +
24595 + mm->free_area_cache = mm->mmap_base;
24596 mm->cached_hole_size = ~0UL;
24597 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
24598 len, pgoff, flags);
24599 @@ -393,6 +404,7 @@ fail:
24600 /*
24601 * Restore the topdown base:
24602 */
24603 + mm->mmap_base = base;
24604 mm->free_area_cache = base;
24605 mm->cached_hole_size = ~0UL;
24606
24607 @@ -406,10 +418,19 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24608 struct hstate *h = hstate_file(file);
24609 struct mm_struct *mm = current->mm;
24610 struct vm_area_struct *vma;
24611 + unsigned long pax_task_size = TASK_SIZE;
24612
24613 if (len & ~huge_page_mask(h))
24614 return -EINVAL;
24615 - if (len > TASK_SIZE)
24616 +
24617 +#ifdef CONFIG_PAX_SEGMEXEC
24618 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24619 + pax_task_size = SEGMEXEC_TASK_SIZE;
24620 +#endif
24621 +
24622 + pax_task_size -= PAGE_SIZE;
24623 +
24624 + if (len > pax_task_size)
24625 return -ENOMEM;
24626
24627 if (flags & MAP_FIXED) {
24628 @@ -421,8 +442,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24629 if (addr) {
24630 addr = ALIGN(addr, huge_page_size(h));
24631 vma = find_vma(mm, addr);
24632 - if (TASK_SIZE - len >= addr &&
24633 - (!vma || addr + len <= vma->vm_start))
24634 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
24635 return addr;
24636 }
24637 if (mm->get_unmapped_area == arch_get_unmapped_area)
24638 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
24639 index d7aea41..0fc945b 100644
24640 --- a/arch/x86/mm/init.c
24641 +++ b/arch/x86/mm/init.c
24642 @@ -4,6 +4,7 @@
24643 #include <linux/swap.h>
24644 #include <linux/memblock.h>
24645 #include <linux/bootmem.h> /* for max_low_pfn */
24646 +#include <linux/tboot.h>
24647
24648 #include <asm/cacheflush.h>
24649 #include <asm/e820.h>
24650 @@ -16,6 +17,8 @@
24651 #include <asm/tlb.h>
24652 #include <asm/proto.h>
24653 #include <asm/dma.h> /* for MAX_DMA_PFN */
24654 +#include <asm/desc.h>
24655 +#include <asm/bios_ebda.h>
24656
24657 unsigned long __initdata pgt_buf_start;
24658 unsigned long __meminitdata pgt_buf_end;
24659 @@ -44,7 +47,7 @@ static void __init find_early_table_space(struct map_range *mr, int nr_range)
24660 {
24661 int i;
24662 unsigned long puds = 0, pmds = 0, ptes = 0, tables;
24663 - unsigned long start = 0, good_end;
24664 + unsigned long start = 0x100000, good_end;
24665 phys_addr_t base;
24666
24667 for (i = 0; i < nr_range; i++) {
24668 @@ -321,10 +324,40 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
24669 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
24670 * mmio resources as well as potential bios/acpi data regions.
24671 */
24672 +
24673 +#ifdef CONFIG_GRKERNSEC_KMEM
24674 +static unsigned int ebda_start __read_only;
24675 +static unsigned int ebda_end __read_only;
24676 +#endif
24677 +
24678 int devmem_is_allowed(unsigned long pagenr)
24679 {
24680 - if (pagenr < 256)
24681 +#ifdef CONFIG_GRKERNSEC_KMEM
24682 + /* allow BDA */
24683 + if (!pagenr)
24684 return 1;
24685 + /* allow EBDA */
24686 + if (pagenr >= ebda_start && pagenr < ebda_end)
24687 + return 1;
24688 + /* if tboot is in use, allow access to its hardcoded serial log range */
24689 + if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
24690 + return 1;
24691 +#else
24692 + if (!pagenr)
24693 + return 1;
24694 +#ifdef CONFIG_VM86
24695 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
24696 + return 1;
24697 +#endif
24698 +#endif
24699 +
24700 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
24701 + return 1;
24702 +#ifdef CONFIG_GRKERNSEC_KMEM
24703 + /* throw out everything else below 1MB */
24704 + if (pagenr <= 256)
24705 + return 0;
24706 +#endif
24707 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
24708 return 0;
24709 if (!page_is_ram(pagenr))
24710 @@ -381,8 +414,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
24711 #endif
24712 }
24713
24714 +#ifdef CONFIG_GRKERNSEC_KMEM
24715 +static inline void gr_init_ebda(void)
24716 +{
24717 + unsigned int ebda_addr;
24718 + unsigned int ebda_size = 0;
24719 +
24720 + ebda_addr = get_bios_ebda();
24721 + if (ebda_addr) {
24722 + ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
24723 + ebda_size <<= 10;
24724 + }
24725 + if (ebda_addr && ebda_size) {
24726 + ebda_start = ebda_addr >> PAGE_SHIFT;
24727 + ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
24728 + } else {
24729 + ebda_start = 0x9f000 >> PAGE_SHIFT;
24730 + ebda_end = 0xa0000 >> PAGE_SHIFT;
24731 + }
24732 +}
24733 +#else
24734 +static inline void gr_init_ebda(void) { }
24735 +#endif
24736 +
24737 void free_initmem(void)
24738 {
24739 +#ifdef CONFIG_PAX_KERNEXEC
24740 +#ifdef CONFIG_X86_32
24741 + /* PaX: limit KERNEL_CS to actual size */
24742 + unsigned long addr, limit;
24743 + struct desc_struct d;
24744 + int cpu;
24745 +#else
24746 + pgd_t *pgd;
24747 + pud_t *pud;
24748 + pmd_t *pmd;
24749 + unsigned long addr, end;
24750 +#endif
24751 +#endif
24752 +
24753 + gr_init_ebda();
24754 +
24755 +#ifdef CONFIG_PAX_KERNEXEC
24756 +#ifdef CONFIG_X86_32
24757 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
24758 + limit = (limit - 1UL) >> PAGE_SHIFT;
24759 +
24760 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
24761 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
24762 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
24763 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
24764 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
24765 + }
24766 +
24767 + /* PaX: make KERNEL_CS read-only */
24768 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
24769 + if (!paravirt_enabled())
24770 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
24771 +/*
24772 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
24773 + pgd = pgd_offset_k(addr);
24774 + pud = pud_offset(pgd, addr);
24775 + pmd = pmd_offset(pud, addr);
24776 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24777 + }
24778 +*/
24779 +#ifdef CONFIG_X86_PAE
24780 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
24781 +/*
24782 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
24783 + pgd = pgd_offset_k(addr);
24784 + pud = pud_offset(pgd, addr);
24785 + pmd = pmd_offset(pud, addr);
24786 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24787 + }
24788 +*/
24789 +#endif
24790 +
24791 +#ifdef CONFIG_MODULES
24792 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
24793 +#endif
24794 +
24795 +#else
24796 + /* PaX: make kernel code/rodata read-only, rest non-executable */
24797 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
24798 + pgd = pgd_offset_k(addr);
24799 + pud = pud_offset(pgd, addr);
24800 + pmd = pmd_offset(pud, addr);
24801 + if (!pmd_present(*pmd))
24802 + continue;
24803 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
24804 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24805 + else
24806 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24807 + }
24808 +
24809 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
24810 + end = addr + KERNEL_IMAGE_SIZE;
24811 + for (; addr < end; addr += PMD_SIZE) {
24812 + pgd = pgd_offset_k(addr);
24813 + pud = pud_offset(pgd, addr);
24814 + pmd = pmd_offset(pud, addr);
24815 + if (!pmd_present(*pmd))
24816 + continue;
24817 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
24818 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24819 + }
24820 +#endif
24821 +
24822 + flush_tlb_all();
24823 +#endif
24824 +
24825 free_init_pages("unused kernel memory",
24826 (unsigned long)(&__init_begin),
24827 (unsigned long)(&__init_end));
24828 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
24829 index 575d86f..4987469 100644
24830 --- a/arch/x86/mm/init_32.c
24831 +++ b/arch/x86/mm/init_32.c
24832 @@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
24833 }
24834
24835 /*
24836 - * Creates a middle page table and puts a pointer to it in the
24837 - * given global directory entry. This only returns the gd entry
24838 - * in non-PAE compilation mode, since the middle layer is folded.
24839 - */
24840 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
24841 -{
24842 - pud_t *pud;
24843 - pmd_t *pmd_table;
24844 -
24845 -#ifdef CONFIG_X86_PAE
24846 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
24847 - if (after_bootmem)
24848 - pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
24849 - else
24850 - pmd_table = (pmd_t *)alloc_low_page();
24851 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
24852 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
24853 - pud = pud_offset(pgd, 0);
24854 - BUG_ON(pmd_table != pmd_offset(pud, 0));
24855 -
24856 - return pmd_table;
24857 - }
24858 -#endif
24859 - pud = pud_offset(pgd, 0);
24860 - pmd_table = pmd_offset(pud, 0);
24861 -
24862 - return pmd_table;
24863 -}
24864 -
24865 -/*
24866 * Create a page table and place a pointer to it in a middle page
24867 * directory entry:
24868 */
24869 @@ -122,13 +92,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
24870 page_table = (pte_t *)alloc_low_page();
24871
24872 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
24873 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24874 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
24875 +#else
24876 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
24877 +#endif
24878 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
24879 }
24880
24881 return pte_offset_kernel(pmd, 0);
24882 }
24883
24884 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
24885 +{
24886 + pud_t *pud;
24887 + pmd_t *pmd_table;
24888 +
24889 + pud = pud_offset(pgd, 0);
24890 + pmd_table = pmd_offset(pud, 0);
24891 +
24892 + return pmd_table;
24893 +}
24894 +
24895 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
24896 {
24897 int pgd_idx = pgd_index(vaddr);
24898 @@ -202,6 +187,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24899 int pgd_idx, pmd_idx;
24900 unsigned long vaddr;
24901 pgd_t *pgd;
24902 + pud_t *pud;
24903 pmd_t *pmd;
24904 pte_t *pte = NULL;
24905
24906 @@ -211,8 +197,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24907 pgd = pgd_base + pgd_idx;
24908
24909 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
24910 - pmd = one_md_table_init(pgd);
24911 - pmd = pmd + pmd_index(vaddr);
24912 + pud = pud_offset(pgd, vaddr);
24913 + pmd = pmd_offset(pud, vaddr);
24914 +
24915 +#ifdef CONFIG_X86_PAE
24916 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24917 +#endif
24918 +
24919 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
24920 pmd++, pmd_idx++) {
24921 pte = page_table_kmap_check(one_page_table_init(pmd),
24922 @@ -224,11 +215,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24923 }
24924 }
24925
24926 -static inline int is_kernel_text(unsigned long addr)
24927 +static inline int is_kernel_text(unsigned long start, unsigned long end)
24928 {
24929 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
24930 - return 1;
24931 - return 0;
24932 + if ((start > ktla_ktva((unsigned long)_etext) ||
24933 + end <= ktla_ktva((unsigned long)_stext)) &&
24934 + (start > ktla_ktva((unsigned long)_einittext) ||
24935 + end <= ktla_ktva((unsigned long)_sinittext)) &&
24936 +
24937 +#ifdef CONFIG_ACPI_SLEEP
24938 + (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
24939 +#endif
24940 +
24941 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
24942 + return 0;
24943 + return 1;
24944 }
24945
24946 /*
24947 @@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned long start,
24948 unsigned long last_map_addr = end;
24949 unsigned long start_pfn, end_pfn;
24950 pgd_t *pgd_base = swapper_pg_dir;
24951 - int pgd_idx, pmd_idx, pte_ofs;
24952 + unsigned int pgd_idx, pmd_idx, pte_ofs;
24953 unsigned long pfn;
24954 pgd_t *pgd;
24955 + pud_t *pud;
24956 pmd_t *pmd;
24957 pte_t *pte;
24958 unsigned pages_2m, pages_4k;
24959 @@ -280,8 +281,13 @@ repeat:
24960 pfn = start_pfn;
24961 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24962 pgd = pgd_base + pgd_idx;
24963 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
24964 - pmd = one_md_table_init(pgd);
24965 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
24966 + pud = pud_offset(pgd, 0);
24967 + pmd = pmd_offset(pud, 0);
24968 +
24969 +#ifdef CONFIG_X86_PAE
24970 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24971 +#endif
24972
24973 if (pfn >= end_pfn)
24974 continue;
24975 @@ -293,14 +299,13 @@ repeat:
24976 #endif
24977 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
24978 pmd++, pmd_idx++) {
24979 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
24980 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
24981
24982 /*
24983 * Map with big pages if possible, otherwise
24984 * create normal page tables:
24985 */
24986 if (use_pse) {
24987 - unsigned int addr2;
24988 pgprot_t prot = PAGE_KERNEL_LARGE;
24989 /*
24990 * first pass will use the same initial
24991 @@ -310,11 +315,7 @@ repeat:
24992 __pgprot(PTE_IDENT_ATTR |
24993 _PAGE_PSE);
24994
24995 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
24996 - PAGE_OFFSET + PAGE_SIZE-1;
24997 -
24998 - if (is_kernel_text(addr) ||
24999 - is_kernel_text(addr2))
25000 + if (is_kernel_text(address, address + PMD_SIZE))
25001 prot = PAGE_KERNEL_LARGE_EXEC;
25002
25003 pages_2m++;
25004 @@ -331,7 +332,7 @@ repeat:
25005 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
25006 pte += pte_ofs;
25007 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
25008 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
25009 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
25010 pgprot_t prot = PAGE_KERNEL;
25011 /*
25012 * first pass will use the same initial
25013 @@ -339,7 +340,7 @@ repeat:
25014 */
25015 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
25016
25017 - if (is_kernel_text(addr))
25018 + if (is_kernel_text(address, address + PAGE_SIZE))
25019 prot = PAGE_KERNEL_EXEC;
25020
25021 pages_4k++;
25022 @@ -465,7 +466,7 @@ void __init native_pagetable_setup_start(pgd_t *base)
25023
25024 pud = pud_offset(pgd, va);
25025 pmd = pmd_offset(pud, va);
25026 - if (!pmd_present(*pmd))
25027 + if (!pmd_present(*pmd) || pmd_huge(*pmd))
25028 break;
25029
25030 pte = pte_offset_kernel(pmd, va);
25031 @@ -517,12 +518,10 @@ void __init early_ioremap_page_table_range_init(void)
25032
25033 static void __init pagetable_init(void)
25034 {
25035 - pgd_t *pgd_base = swapper_pg_dir;
25036 -
25037 - permanent_kmaps_init(pgd_base);
25038 + permanent_kmaps_init(swapper_pg_dir);
25039 }
25040
25041 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
25042 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
25043 EXPORT_SYMBOL_GPL(__supported_pte_mask);
25044
25045 /* user-defined highmem size */
25046 @@ -734,6 +733,12 @@ void __init mem_init(void)
25047
25048 pci_iommu_alloc();
25049
25050 +#ifdef CONFIG_PAX_PER_CPU_PGD
25051 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
25052 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25053 + KERNEL_PGD_PTRS);
25054 +#endif
25055 +
25056 #ifdef CONFIG_FLATMEM
25057 BUG_ON(!mem_map);
25058 #endif
25059 @@ -760,7 +765,7 @@ void __init mem_init(void)
25060 reservedpages++;
25061
25062 codesize = (unsigned long) &_etext - (unsigned long) &_text;
25063 - datasize = (unsigned long) &_edata - (unsigned long) &_etext;
25064 + datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
25065 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
25066
25067 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
25068 @@ -801,10 +806,10 @@ void __init mem_init(void)
25069 ((unsigned long)&__init_end -
25070 (unsigned long)&__init_begin) >> 10,
25071
25072 - (unsigned long)&_etext, (unsigned long)&_edata,
25073 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
25074 + (unsigned long)&_sdata, (unsigned long)&_edata,
25075 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
25076
25077 - (unsigned long)&_text, (unsigned long)&_etext,
25078 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
25079 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
25080
25081 /*
25082 @@ -882,6 +887,7 @@ void set_kernel_text_rw(void)
25083 if (!kernel_set_to_readonly)
25084 return;
25085
25086 + start = ktla_ktva(start);
25087 pr_debug("Set kernel text: %lx - %lx for read write\n",
25088 start, start+size);
25089
25090 @@ -896,6 +902,7 @@ void set_kernel_text_ro(void)
25091 if (!kernel_set_to_readonly)
25092 return;
25093
25094 + start = ktla_ktva(start);
25095 pr_debug("Set kernel text: %lx - %lx for read only\n",
25096 start, start+size);
25097
25098 @@ -924,6 +931,7 @@ void mark_rodata_ro(void)
25099 unsigned long start = PFN_ALIGN(_text);
25100 unsigned long size = PFN_ALIGN(_etext) - start;
25101
25102 + start = ktla_ktva(start);
25103 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
25104 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
25105 size >> 10);
25106 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
25107 index 3baff25..8b37564 100644
25108 --- a/arch/x86/mm/init_64.c
25109 +++ b/arch/x86/mm/init_64.c
25110 @@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpages_on);
25111 * around without checking the pgd every time.
25112 */
25113
25114 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
25115 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
25116 EXPORT_SYMBOL_GPL(__supported_pte_mask);
25117
25118 int force_personality32;
25119 @@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25120
25121 for (address = start; address <= end; address += PGDIR_SIZE) {
25122 const pgd_t *pgd_ref = pgd_offset_k(address);
25123 +
25124 +#ifdef CONFIG_PAX_PER_CPU_PGD
25125 + unsigned long cpu;
25126 +#else
25127 struct page *page;
25128 +#endif
25129
25130 if (pgd_none(*pgd_ref))
25131 continue;
25132
25133 spin_lock(&pgd_lock);
25134 +
25135 +#ifdef CONFIG_PAX_PER_CPU_PGD
25136 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25137 + pgd_t *pgd = pgd_offset_cpu(cpu, address);
25138 +#else
25139 list_for_each_entry(page, &pgd_list, lru) {
25140 pgd_t *pgd;
25141 spinlock_t *pgt_lock;
25142 @@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25143 /* the pgt_lock only for Xen */
25144 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
25145 spin_lock(pgt_lock);
25146 +#endif
25147
25148 if (pgd_none(*pgd))
25149 set_pgd(pgd, *pgd_ref);
25150 @@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25151 BUG_ON(pgd_page_vaddr(*pgd)
25152 != pgd_page_vaddr(*pgd_ref));
25153
25154 +#ifndef CONFIG_PAX_PER_CPU_PGD
25155 spin_unlock(pgt_lock);
25156 +#endif
25157 +
25158 }
25159 spin_unlock(&pgd_lock);
25160 }
25161 @@ -161,7 +175,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
25162 {
25163 if (pgd_none(*pgd)) {
25164 pud_t *pud = (pud_t *)spp_getpage();
25165 - pgd_populate(&init_mm, pgd, pud);
25166 + pgd_populate_kernel(&init_mm, pgd, pud);
25167 if (pud != pud_offset(pgd, 0))
25168 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
25169 pud, pud_offset(pgd, 0));
25170 @@ -173,7 +187,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
25171 {
25172 if (pud_none(*pud)) {
25173 pmd_t *pmd = (pmd_t *) spp_getpage();
25174 - pud_populate(&init_mm, pud, pmd);
25175 + pud_populate_kernel(&init_mm, pud, pmd);
25176 if (pmd != pmd_offset(pud, 0))
25177 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
25178 pmd, pmd_offset(pud, 0));
25179 @@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
25180 pmd = fill_pmd(pud, vaddr);
25181 pte = fill_pte(pmd, vaddr);
25182
25183 + pax_open_kernel();
25184 set_pte(pte, new_pte);
25185 + pax_close_kernel();
25186
25187 /*
25188 * It's enough to flush this one mapping.
25189 @@ -261,14 +277,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
25190 pgd = pgd_offset_k((unsigned long)__va(phys));
25191 if (pgd_none(*pgd)) {
25192 pud = (pud_t *) spp_getpage();
25193 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
25194 - _PAGE_USER));
25195 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
25196 }
25197 pud = pud_offset(pgd, (unsigned long)__va(phys));
25198 if (pud_none(*pud)) {
25199 pmd = (pmd_t *) spp_getpage();
25200 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
25201 - _PAGE_USER));
25202 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
25203 }
25204 pmd = pmd_offset(pud, phys);
25205 BUG_ON(!pmd_none(*pmd));
25206 @@ -329,7 +343,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
25207 if (pfn >= pgt_buf_top)
25208 panic("alloc_low_page: ran out of memory");
25209
25210 - adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
25211 + adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
25212 clear_page(adr);
25213 *phys = pfn * PAGE_SIZE;
25214 return adr;
25215 @@ -345,7 +359,7 @@ static __ref void *map_low_page(void *virt)
25216
25217 phys = __pa(virt);
25218 left = phys & (PAGE_SIZE - 1);
25219 - adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
25220 + adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
25221 adr = (void *)(((unsigned long)adr) | left);
25222
25223 return adr;
25224 @@ -553,7 +567,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
25225 unmap_low_page(pmd);
25226
25227 spin_lock(&init_mm.page_table_lock);
25228 - pud_populate(&init_mm, pud, __va(pmd_phys));
25229 + pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
25230 spin_unlock(&init_mm.page_table_lock);
25231 }
25232 __flush_tlb_all();
25233 @@ -599,7 +613,7 @@ kernel_physical_mapping_init(unsigned long start,
25234 unmap_low_page(pud);
25235
25236 spin_lock(&init_mm.page_table_lock);
25237 - pgd_populate(&init_mm, pgd, __va(pud_phys));
25238 + pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
25239 spin_unlock(&init_mm.page_table_lock);
25240 pgd_changed = true;
25241 }
25242 @@ -691,6 +705,12 @@ void __init mem_init(void)
25243
25244 pci_iommu_alloc();
25245
25246 +#ifdef CONFIG_PAX_PER_CPU_PGD
25247 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
25248 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25249 + KERNEL_PGD_PTRS);
25250 +#endif
25251 +
25252 /* clear_bss() already clear the empty_zero_page */
25253
25254 reservedpages = 0;
25255 @@ -851,8 +871,8 @@ int kern_addr_valid(unsigned long addr)
25256 static struct vm_area_struct gate_vma = {
25257 .vm_start = VSYSCALL_START,
25258 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
25259 - .vm_page_prot = PAGE_READONLY_EXEC,
25260 - .vm_flags = VM_READ | VM_EXEC
25261 + .vm_page_prot = PAGE_READONLY,
25262 + .vm_flags = VM_READ
25263 };
25264
25265 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
25266 @@ -886,7 +906,7 @@ int in_gate_area_no_mm(unsigned long addr)
25267
25268 const char *arch_vma_name(struct vm_area_struct *vma)
25269 {
25270 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
25271 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
25272 return "[vdso]";
25273 if (vma == &gate_vma)
25274 return "[vsyscall]";
25275 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
25276 index 7b179b4..6bd1777 100644
25277 --- a/arch/x86/mm/iomap_32.c
25278 +++ b/arch/x86/mm/iomap_32.c
25279 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
25280 type = kmap_atomic_idx_push();
25281 idx = type + KM_TYPE_NR * smp_processor_id();
25282 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
25283 +
25284 + pax_open_kernel();
25285 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
25286 + pax_close_kernel();
25287 +
25288 arch_flush_lazy_mmu_mode();
25289
25290 return (void *)vaddr;
25291 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
25292 index 78fe3f1..8293b6f 100644
25293 --- a/arch/x86/mm/ioremap.c
25294 +++ b/arch/x86/mm/ioremap.c
25295 @@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
25296 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
25297 int is_ram = page_is_ram(pfn);
25298
25299 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
25300 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
25301 return NULL;
25302 WARN_ON_ONCE(is_ram);
25303 }
25304 @@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
25305
25306 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
25307 if (page_is_ram(start >> PAGE_SHIFT))
25308 +#ifdef CONFIG_HIGHMEM
25309 + if ((start >> PAGE_SHIFT) < max_low_pfn)
25310 +#endif
25311 return __va(phys);
25312
25313 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
25314 @@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
25315 early_param("early_ioremap_debug", early_ioremap_debug_setup);
25316
25317 static __initdata int after_paging_init;
25318 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
25319 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
25320
25321 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
25322 {
25323 @@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
25324 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
25325
25326 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
25327 - memset(bm_pte, 0, sizeof(bm_pte));
25328 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
25329 + pmd_populate_user(&init_mm, pmd, bm_pte);
25330
25331 /*
25332 * The boot-ioremap range spans multiple pmds, for which
25333 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
25334 index d87dd6d..bf3fa66 100644
25335 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
25336 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
25337 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
25338 * memory (e.g. tracked pages)? For now, we need this to avoid
25339 * invoking kmemcheck for PnP BIOS calls.
25340 */
25341 - if (regs->flags & X86_VM_MASK)
25342 + if (v8086_mode(regs))
25343 return false;
25344 - if (regs->cs != __KERNEL_CS)
25345 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
25346 return false;
25347
25348 pte = kmemcheck_pte_lookup(address);
25349 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
25350 index 845df68..1d8d29f 100644
25351 --- a/arch/x86/mm/mmap.c
25352 +++ b/arch/x86/mm/mmap.c
25353 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
25354 * Leave an at least ~128 MB hole with possible stack randomization.
25355 */
25356 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
25357 -#define MAX_GAP (TASK_SIZE/6*5)
25358 +#define MAX_GAP (pax_task_size/6*5)
25359
25360 static int mmap_is_legacy(void)
25361 {
25362 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
25363 return rnd << PAGE_SHIFT;
25364 }
25365
25366 -static unsigned long mmap_base(void)
25367 +static unsigned long mmap_base(struct mm_struct *mm)
25368 {
25369 unsigned long gap = rlimit(RLIMIT_STACK);
25370 + unsigned long pax_task_size = TASK_SIZE;
25371 +
25372 +#ifdef CONFIG_PAX_SEGMEXEC
25373 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25374 + pax_task_size = SEGMEXEC_TASK_SIZE;
25375 +#endif
25376
25377 if (gap < MIN_GAP)
25378 gap = MIN_GAP;
25379 else if (gap > MAX_GAP)
25380 gap = MAX_GAP;
25381
25382 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
25383 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
25384 }
25385
25386 /*
25387 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
25388 * does, but not when emulating X86_32
25389 */
25390 -static unsigned long mmap_legacy_base(void)
25391 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
25392 {
25393 - if (mmap_is_ia32())
25394 + if (mmap_is_ia32()) {
25395 +
25396 +#ifdef CONFIG_PAX_SEGMEXEC
25397 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25398 + return SEGMEXEC_TASK_UNMAPPED_BASE;
25399 + else
25400 +#endif
25401 +
25402 return TASK_UNMAPPED_BASE;
25403 - else
25404 + } else
25405 return TASK_UNMAPPED_BASE + mmap_rnd();
25406 }
25407
25408 @@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
25409 void arch_pick_mmap_layout(struct mm_struct *mm)
25410 {
25411 if (mmap_is_legacy()) {
25412 - mm->mmap_base = mmap_legacy_base();
25413 + mm->mmap_base = mmap_legacy_base(mm);
25414 +
25415 +#ifdef CONFIG_PAX_RANDMMAP
25416 + if (mm->pax_flags & MF_PAX_RANDMMAP)
25417 + mm->mmap_base += mm->delta_mmap;
25418 +#endif
25419 +
25420 mm->get_unmapped_area = arch_get_unmapped_area;
25421 mm->unmap_area = arch_unmap_area;
25422 } else {
25423 - mm->mmap_base = mmap_base();
25424 + mm->mmap_base = mmap_base(mm);
25425 +
25426 +#ifdef CONFIG_PAX_RANDMMAP
25427 + if (mm->pax_flags & MF_PAX_RANDMMAP)
25428 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
25429 +#endif
25430 +
25431 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
25432 mm->unmap_area = arch_unmap_area_topdown;
25433 }
25434 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
25435 index dc0b727..dc9d71a 100644
25436 --- a/arch/x86/mm/mmio-mod.c
25437 +++ b/arch/x86/mm/mmio-mod.c
25438 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
25439 break;
25440 default:
25441 {
25442 - unsigned char *ip = (unsigned char *)instptr;
25443 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
25444 my_trace->opcode = MMIO_UNKNOWN_OP;
25445 my_trace->width = 0;
25446 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
25447 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
25448 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25449 void __iomem *addr)
25450 {
25451 - static atomic_t next_id;
25452 + static atomic_unchecked_t next_id;
25453 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
25454 /* These are page-unaligned. */
25455 struct mmiotrace_map map = {
25456 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25457 .private = trace
25458 },
25459 .phys = offset,
25460 - .id = atomic_inc_return(&next_id)
25461 + .id = atomic_inc_return_unchecked(&next_id)
25462 };
25463 map.map_id = trace->id;
25464
25465 diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
25466 index b008656..773eac2 100644
25467 --- a/arch/x86/mm/pageattr-test.c
25468 +++ b/arch/x86/mm/pageattr-test.c
25469 @@ -36,7 +36,7 @@ enum {
25470
25471 static int pte_testbit(pte_t pte)
25472 {
25473 - return pte_flags(pte) & _PAGE_UNUSED1;
25474 + return pte_flags(pte) & _PAGE_CPA_TEST;
25475 }
25476
25477 struct split_state {
25478 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
25479 index a718e0d..45efc32 100644
25480 --- a/arch/x86/mm/pageattr.c
25481 +++ b/arch/x86/mm/pageattr.c
25482 @@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25483 */
25484 #ifdef CONFIG_PCI_BIOS
25485 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
25486 - pgprot_val(forbidden) |= _PAGE_NX;
25487 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25488 #endif
25489
25490 /*
25491 @@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25492 * Does not cover __inittext since that is gone later on. On
25493 * 64bit we do not enforce !NX on the low mapping
25494 */
25495 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
25496 - pgprot_val(forbidden) |= _PAGE_NX;
25497 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
25498 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25499
25500 +#ifdef CONFIG_DEBUG_RODATA
25501 /*
25502 * The .rodata section needs to be read-only. Using the pfn
25503 * catches all aliases.
25504 @@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25505 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
25506 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
25507 pgprot_val(forbidden) |= _PAGE_RW;
25508 +#endif
25509
25510 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
25511 /*
25512 @@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25513 }
25514 #endif
25515
25516 +#ifdef CONFIG_PAX_KERNEXEC
25517 + if (within(pfn, __pa((unsigned long)&_text), __pa((unsigned long)&_sdata))) {
25518 + pgprot_val(forbidden) |= _PAGE_RW;
25519 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25520 + }
25521 +#endif
25522 +
25523 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
25524
25525 return prot;
25526 @@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
25527 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
25528 {
25529 /* change init_mm */
25530 + pax_open_kernel();
25531 set_pte_atomic(kpte, pte);
25532 +
25533 #ifdef CONFIG_X86_32
25534 if (!SHARED_KERNEL_PMD) {
25535 +
25536 +#ifdef CONFIG_PAX_PER_CPU_PGD
25537 + unsigned long cpu;
25538 +#else
25539 struct page *page;
25540 +#endif
25541
25542 +#ifdef CONFIG_PAX_PER_CPU_PGD
25543 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25544 + pgd_t *pgd = get_cpu_pgd(cpu);
25545 +#else
25546 list_for_each_entry(page, &pgd_list, lru) {
25547 - pgd_t *pgd;
25548 + pgd_t *pgd = (pgd_t *)page_address(page);
25549 +#endif
25550 +
25551 pud_t *pud;
25552 pmd_t *pmd;
25553
25554 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
25555 + pgd += pgd_index(address);
25556 pud = pud_offset(pgd, address);
25557 pmd = pmd_offset(pud, address);
25558 set_pte_atomic((pte_t *)pmd, pte);
25559 }
25560 }
25561 #endif
25562 + pax_close_kernel();
25563 }
25564
25565 static int
25566 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
25567 index 3d68ef6..7f69136 100644
25568 --- a/arch/x86/mm/pat.c
25569 +++ b/arch/x86/mm/pat.c
25570 @@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
25571
25572 if (!entry) {
25573 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
25574 - current->comm, current->pid, start, end - 1);
25575 + current->comm, task_pid_nr(current), start, end - 1);
25576 return -EINVAL;
25577 }
25578
25579 @@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
25580
25581 while (cursor < to) {
25582 if (!devmem_is_allowed(pfn)) {
25583 - printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
25584 - current->comm, from, to - 1);
25585 + printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
25586 + current->comm, from, to - 1, cursor);
25587 return 0;
25588 }
25589 cursor += PAGE_SIZE;
25590 @@ -570,7 +570,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
25591 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
25592 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
25593 "for [mem %#010Lx-%#010Lx]\n",
25594 - current->comm, current->pid,
25595 + current->comm, task_pid_nr(current),
25596 cattr_name(flags),
25597 base, (unsigned long long)(base + size-1));
25598 return -EINVAL;
25599 @@ -605,7 +605,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25600 flags = lookup_memtype(paddr);
25601 if (want_flags != flags) {
25602 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
25603 - current->comm, current->pid,
25604 + current->comm, task_pid_nr(current),
25605 cattr_name(want_flags),
25606 (unsigned long long)paddr,
25607 (unsigned long long)(paddr + size - 1),
25608 @@ -627,7 +627,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25609 free_memtype(paddr, paddr + size);
25610 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
25611 " for [mem %#010Lx-%#010Lx], got %s\n",
25612 - current->comm, current->pid,
25613 + current->comm, task_pid_nr(current),
25614 cattr_name(want_flags),
25615 (unsigned long long)paddr,
25616 (unsigned long long)(paddr + size - 1),
25617 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
25618 index 9f0614d..92ae64a 100644
25619 --- a/arch/x86/mm/pf_in.c
25620 +++ b/arch/x86/mm/pf_in.c
25621 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
25622 int i;
25623 enum reason_type rv = OTHERS;
25624
25625 - p = (unsigned char *)ins_addr;
25626 + p = (unsigned char *)ktla_ktva(ins_addr);
25627 p += skip_prefix(p, &prf);
25628 p += get_opcode(p, &opcode);
25629
25630 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
25631 struct prefix_bits prf;
25632 int i;
25633
25634 - p = (unsigned char *)ins_addr;
25635 + p = (unsigned char *)ktla_ktva(ins_addr);
25636 p += skip_prefix(p, &prf);
25637 p += get_opcode(p, &opcode);
25638
25639 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
25640 struct prefix_bits prf;
25641 int i;
25642
25643 - p = (unsigned char *)ins_addr;
25644 + p = (unsigned char *)ktla_ktva(ins_addr);
25645 p += skip_prefix(p, &prf);
25646 p += get_opcode(p, &opcode);
25647
25648 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
25649 struct prefix_bits prf;
25650 int i;
25651
25652 - p = (unsigned char *)ins_addr;
25653 + p = (unsigned char *)ktla_ktva(ins_addr);
25654 p += skip_prefix(p, &prf);
25655 p += get_opcode(p, &opcode);
25656 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
25657 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
25658 struct prefix_bits prf;
25659 int i;
25660
25661 - p = (unsigned char *)ins_addr;
25662 + p = (unsigned char *)ktla_ktva(ins_addr);
25663 p += skip_prefix(p, &prf);
25664 p += get_opcode(p, &opcode);
25665 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
25666 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
25667 index 8573b83..4f3ed7e 100644
25668 --- a/arch/x86/mm/pgtable.c
25669 +++ b/arch/x86/mm/pgtable.c
25670 @@ -84,10 +84,64 @@ static inline void pgd_list_del(pgd_t *pgd)
25671 list_del(&page->lru);
25672 }
25673
25674 -#define UNSHARED_PTRS_PER_PGD \
25675 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25676 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25677 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
25678
25679 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
25680 +{
25681 + unsigned int count = USER_PGD_PTRS;
25682
25683 + while (count--)
25684 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
25685 +}
25686 +#endif
25687 +
25688 +#ifdef CONFIG_PAX_PER_CPU_PGD
25689 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
25690 +{
25691 + unsigned int count = USER_PGD_PTRS;
25692 +
25693 + while (count--) {
25694 + pgd_t pgd;
25695 +
25696 +#ifdef CONFIG_X86_64
25697 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
25698 +#else
25699 + pgd = *src++;
25700 +#endif
25701 +
25702 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25703 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
25704 +#endif
25705 +
25706 + *dst++ = pgd;
25707 + }
25708 +
25709 +}
25710 +#endif
25711 +
25712 +#ifdef CONFIG_X86_64
25713 +#define pxd_t pud_t
25714 +#define pyd_t pgd_t
25715 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
25716 +#define pxd_free(mm, pud) pud_free((mm), (pud))
25717 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
25718 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
25719 +#define PYD_SIZE PGDIR_SIZE
25720 +#else
25721 +#define pxd_t pmd_t
25722 +#define pyd_t pud_t
25723 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
25724 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
25725 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
25726 +#define pyd_offset(mm, address) pud_offset((mm), (address))
25727 +#define PYD_SIZE PUD_SIZE
25728 +#endif
25729 +
25730 +#ifdef CONFIG_PAX_PER_CPU_PGD
25731 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
25732 +static inline void pgd_dtor(pgd_t *pgd) {}
25733 +#else
25734 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
25735 {
25736 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
25737 @@ -128,6 +182,7 @@ static void pgd_dtor(pgd_t *pgd)
25738 pgd_list_del(pgd);
25739 spin_unlock(&pgd_lock);
25740 }
25741 +#endif
25742
25743 /*
25744 * List of all pgd's needed for non-PAE so it can invalidate entries
25745 @@ -140,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
25746 * -- wli
25747 */
25748
25749 -#ifdef CONFIG_X86_PAE
25750 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25751 /*
25752 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
25753 * updating the top-level pagetable entries to guarantee the
25754 @@ -152,7 +207,7 @@ static void pgd_dtor(pgd_t *pgd)
25755 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
25756 * and initialize the kernel pmds here.
25757 */
25758 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
25759 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25760
25761 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25762 {
25763 @@ -170,36 +225,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25764 */
25765 flush_tlb_mm(mm);
25766 }
25767 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
25768 +#define PREALLOCATED_PXDS USER_PGD_PTRS
25769 #else /* !CONFIG_X86_PAE */
25770
25771 /* No need to prepopulate any pagetable entries in non-PAE modes. */
25772 -#define PREALLOCATED_PMDS 0
25773 +#define PREALLOCATED_PXDS 0
25774
25775 #endif /* CONFIG_X86_PAE */
25776
25777 -static void free_pmds(pmd_t *pmds[])
25778 +static void free_pxds(pxd_t *pxds[])
25779 {
25780 int i;
25781
25782 - for(i = 0; i < PREALLOCATED_PMDS; i++)
25783 - if (pmds[i])
25784 - free_page((unsigned long)pmds[i]);
25785 + for(i = 0; i < PREALLOCATED_PXDS; i++)
25786 + if (pxds[i])
25787 + free_page((unsigned long)pxds[i]);
25788 }
25789
25790 -static int preallocate_pmds(pmd_t *pmds[])
25791 +static int preallocate_pxds(pxd_t *pxds[])
25792 {
25793 int i;
25794 bool failed = false;
25795
25796 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
25797 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
25798 - if (pmd == NULL)
25799 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
25800 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
25801 + if (pxd == NULL)
25802 failed = true;
25803 - pmds[i] = pmd;
25804 + pxds[i] = pxd;
25805 }
25806
25807 if (failed) {
25808 - free_pmds(pmds);
25809 + free_pxds(pxds);
25810 return -ENOMEM;
25811 }
25812
25813 @@ -212,51 +269,55 @@ static int preallocate_pmds(pmd_t *pmds[])
25814 * preallocate which never got a corresponding vma will need to be
25815 * freed manually.
25816 */
25817 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
25818 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
25819 {
25820 int i;
25821
25822 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
25823 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
25824 pgd_t pgd = pgdp[i];
25825
25826 if (pgd_val(pgd) != 0) {
25827 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
25828 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
25829
25830 - pgdp[i] = native_make_pgd(0);
25831 + set_pgd(pgdp + i, native_make_pgd(0));
25832
25833 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
25834 - pmd_free(mm, pmd);
25835 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
25836 + pxd_free(mm, pxd);
25837 }
25838 }
25839 }
25840
25841 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
25842 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
25843 {
25844 - pud_t *pud;
25845 + pyd_t *pyd;
25846 unsigned long addr;
25847 int i;
25848
25849 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
25850 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
25851 return;
25852
25853 - pud = pud_offset(pgd, 0);
25854 +#ifdef CONFIG_X86_64
25855 + pyd = pyd_offset(mm, 0L);
25856 +#else
25857 + pyd = pyd_offset(pgd, 0L);
25858 +#endif
25859
25860 - for (addr = i = 0; i < PREALLOCATED_PMDS;
25861 - i++, pud++, addr += PUD_SIZE) {
25862 - pmd_t *pmd = pmds[i];
25863 + for (addr = i = 0; i < PREALLOCATED_PXDS;
25864 + i++, pyd++, addr += PYD_SIZE) {
25865 + pxd_t *pxd = pxds[i];
25866
25867 if (i >= KERNEL_PGD_BOUNDARY)
25868 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25869 - sizeof(pmd_t) * PTRS_PER_PMD);
25870 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25871 + sizeof(pxd_t) * PTRS_PER_PMD);
25872
25873 - pud_populate(mm, pud, pmd);
25874 + pyd_populate(mm, pyd, pxd);
25875 }
25876 }
25877
25878 pgd_t *pgd_alloc(struct mm_struct *mm)
25879 {
25880 pgd_t *pgd;
25881 - pmd_t *pmds[PREALLOCATED_PMDS];
25882 + pxd_t *pxds[PREALLOCATED_PXDS];
25883
25884 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
25885
25886 @@ -265,11 +326,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25887
25888 mm->pgd = pgd;
25889
25890 - if (preallocate_pmds(pmds) != 0)
25891 + if (preallocate_pxds(pxds) != 0)
25892 goto out_free_pgd;
25893
25894 if (paravirt_pgd_alloc(mm) != 0)
25895 - goto out_free_pmds;
25896 + goto out_free_pxds;
25897
25898 /*
25899 * Make sure that pre-populating the pmds is atomic with
25900 @@ -279,14 +340,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25901 spin_lock(&pgd_lock);
25902
25903 pgd_ctor(mm, pgd);
25904 - pgd_prepopulate_pmd(mm, pgd, pmds);
25905 + pgd_prepopulate_pxd(mm, pgd, pxds);
25906
25907 spin_unlock(&pgd_lock);
25908
25909 return pgd;
25910
25911 -out_free_pmds:
25912 - free_pmds(pmds);
25913 +out_free_pxds:
25914 + free_pxds(pxds);
25915 out_free_pgd:
25916 free_page((unsigned long)pgd);
25917 out:
25918 @@ -295,7 +356,7 @@ out:
25919
25920 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
25921 {
25922 - pgd_mop_up_pmds(mm, pgd);
25923 + pgd_mop_up_pxds(mm, pgd);
25924 pgd_dtor(pgd);
25925 paravirt_pgd_free(mm, pgd);
25926 free_page((unsigned long)pgd);
25927 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
25928 index a69bcb8..19068ab 100644
25929 --- a/arch/x86/mm/pgtable_32.c
25930 +++ b/arch/x86/mm/pgtable_32.c
25931 @@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
25932 return;
25933 }
25934 pte = pte_offset_kernel(pmd, vaddr);
25935 +
25936 + pax_open_kernel();
25937 if (pte_val(pteval))
25938 set_pte_at(&init_mm, vaddr, pte, pteval);
25939 else
25940 pte_clear(&init_mm, vaddr, pte);
25941 + pax_close_kernel();
25942
25943 /*
25944 * It's enough to flush this one mapping.
25945 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
25946 index 410531d..0f16030 100644
25947 --- a/arch/x86/mm/setup_nx.c
25948 +++ b/arch/x86/mm/setup_nx.c
25949 @@ -5,8 +5,10 @@
25950 #include <asm/pgtable.h>
25951 #include <asm/proto.h>
25952
25953 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25954 static int disable_nx __cpuinitdata;
25955
25956 +#ifndef CONFIG_PAX_PAGEEXEC
25957 /*
25958 * noexec = on|off
25959 *
25960 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
25961 return 0;
25962 }
25963 early_param("noexec", noexec_setup);
25964 +#endif
25965 +
25966 +#endif
25967
25968 void __cpuinit x86_configure_nx(void)
25969 {
25970 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25971 if (cpu_has_nx && !disable_nx)
25972 __supported_pte_mask |= _PAGE_NX;
25973 else
25974 +#endif
25975 __supported_pte_mask &= ~_PAGE_NX;
25976 }
25977
25978 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
25979 index 613cd83..3a21f1c 100644
25980 --- a/arch/x86/mm/tlb.c
25981 +++ b/arch/x86/mm/tlb.c
25982 @@ -48,7 +48,11 @@ void leave_mm(int cpu)
25983 BUG();
25984 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
25985 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
25986 +
25987 +#ifndef CONFIG_PAX_PER_CPU_PGD
25988 load_cr3(swapper_pg_dir);
25989 +#endif
25990 +
25991 }
25992 }
25993 EXPORT_SYMBOL_GPL(leave_mm);
25994 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
25995 index 877b9a1..a8ecf42 100644
25996 --- a/arch/x86/net/bpf_jit.S
25997 +++ b/arch/x86/net/bpf_jit.S
25998 @@ -9,6 +9,7 @@
25999 */
26000 #include <linux/linkage.h>
26001 #include <asm/dwarf2.h>
26002 +#include <asm/alternative-asm.h>
26003
26004 /*
26005 * Calling convention :
26006 @@ -35,6 +36,7 @@ sk_load_word_positive_offset:
26007 jle bpf_slow_path_word
26008 mov (SKBDATA,%rsi),%eax
26009 bswap %eax /* ntohl() */
26010 + pax_force_retaddr
26011 ret
26012
26013 sk_load_half:
26014 @@ -52,6 +54,7 @@ sk_load_half_positive_offset:
26015 jle bpf_slow_path_half
26016 movzwl (SKBDATA,%rsi),%eax
26017 rol $8,%ax # ntohs()
26018 + pax_force_retaddr
26019 ret
26020
26021 sk_load_byte:
26022 @@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
26023 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
26024 jle bpf_slow_path_byte
26025 movzbl (SKBDATA,%rsi),%eax
26026 + pax_force_retaddr
26027 ret
26028
26029 /**
26030 @@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
26031 movzbl (SKBDATA,%rsi),%ebx
26032 and $15,%bl
26033 shl $2,%bl
26034 + pax_force_retaddr
26035 ret
26036
26037 /* rsi contains offset and can be scratched */
26038 @@ -109,6 +114,7 @@ bpf_slow_path_word:
26039 js bpf_error
26040 mov -12(%rbp),%eax
26041 bswap %eax
26042 + pax_force_retaddr
26043 ret
26044
26045 bpf_slow_path_half:
26046 @@ -117,12 +123,14 @@ bpf_slow_path_half:
26047 mov -12(%rbp),%ax
26048 rol $8,%ax
26049 movzwl %ax,%eax
26050 + pax_force_retaddr
26051 ret
26052
26053 bpf_slow_path_byte:
26054 bpf_slow_path_common(1)
26055 js bpf_error
26056 movzbl -12(%rbp),%eax
26057 + pax_force_retaddr
26058 ret
26059
26060 bpf_slow_path_byte_msh:
26061 @@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
26062 and $15,%al
26063 shl $2,%al
26064 xchg %eax,%ebx
26065 + pax_force_retaddr
26066 ret
26067
26068 #define sk_negative_common(SIZE) \
26069 @@ -157,6 +166,7 @@ sk_load_word_negative_offset:
26070 sk_negative_common(4)
26071 mov (%rax), %eax
26072 bswap %eax
26073 + pax_force_retaddr
26074 ret
26075
26076 bpf_slow_path_half_neg:
26077 @@ -168,6 +178,7 @@ sk_load_half_negative_offset:
26078 mov (%rax),%ax
26079 rol $8,%ax
26080 movzwl %ax,%eax
26081 + pax_force_retaddr
26082 ret
26083
26084 bpf_slow_path_byte_neg:
26085 @@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
26086 .globl sk_load_byte_negative_offset
26087 sk_negative_common(1)
26088 movzbl (%rax), %eax
26089 + pax_force_retaddr
26090 ret
26091
26092 bpf_slow_path_byte_msh_neg:
26093 @@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
26094 and $15,%al
26095 shl $2,%al
26096 xchg %eax,%ebx
26097 + pax_force_retaddr
26098 ret
26099
26100 bpf_error:
26101 @@ -197,4 +210,5 @@ bpf_error:
26102 xor %eax,%eax
26103 mov -8(%rbp),%rbx
26104 leaveq
26105 + pax_force_retaddr
26106 ret
26107 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
26108 index 33643a8..f6211a0 100644
26109 --- a/arch/x86/net/bpf_jit_comp.c
26110 +++ b/arch/x86/net/bpf_jit_comp.c
26111 @@ -11,6 +11,7 @@
26112 #include <asm/cacheflush.h>
26113 #include <linux/netdevice.h>
26114 #include <linux/filter.h>
26115 +#include <linux/random.h>
26116
26117 /*
26118 * Conventions :
26119 @@ -48,13 +49,87 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
26120 return ptr + len;
26121 }
26122
26123 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
26124 +#define MAX_INSTR_CODE_SIZE 96
26125 +#else
26126 +#define MAX_INSTR_CODE_SIZE 64
26127 +#endif
26128 +
26129 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
26130
26131 #define EMIT1(b1) EMIT(b1, 1)
26132 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
26133 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
26134 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
26135 +
26136 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
26137 +/* original constant will appear in ecx */
26138 +#define DILUTE_CONST_SEQUENCE(_off, _key) \
26139 +do { \
26140 + /* mov ecx, randkey */ \
26141 + EMIT1(0xb9); \
26142 + EMIT(_key, 4); \
26143 + /* xor ecx, randkey ^ off */ \
26144 + EMIT2(0x81, 0xf1); \
26145 + EMIT((_key) ^ (_off), 4); \
26146 +} while (0)
26147 +
26148 +#define EMIT1_off32(b1, _off) \
26149 +do { \
26150 + switch (b1) { \
26151 + case 0x05: /* add eax, imm32 */ \
26152 + case 0x2d: /* sub eax, imm32 */ \
26153 + case 0x25: /* and eax, imm32 */ \
26154 + case 0x0d: /* or eax, imm32 */ \
26155 + case 0xb8: /* mov eax, imm32 */ \
26156 + case 0x3d: /* cmp eax, imm32 */ \
26157 + case 0xa9: /* test eax, imm32 */ \
26158 + DILUTE_CONST_SEQUENCE(_off, randkey); \
26159 + EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
26160 + break; \
26161 + case 0xbb: /* mov ebx, imm32 */ \
26162 + DILUTE_CONST_SEQUENCE(_off, randkey); \
26163 + /* mov ebx, ecx */ \
26164 + EMIT2(0x89, 0xcb); \
26165 + break; \
26166 + case 0xbe: /* mov esi, imm32 */ \
26167 + DILUTE_CONST_SEQUENCE(_off, randkey); \
26168 + /* mov esi, ecx */ \
26169 + EMIT2(0x89, 0xce); \
26170 + break; \
26171 + case 0xe9: /* jmp rel imm32 */ \
26172 + EMIT1(b1); \
26173 + EMIT(_off, 4); \
26174 + /* prevent fall-through, we're not called if off = 0 */ \
26175 + EMIT(0xcccccccc, 4); \
26176 + EMIT(0xcccccccc, 4); \
26177 + break; \
26178 + default: \
26179 + EMIT1(b1); \
26180 + EMIT(_off, 4); \
26181 + } \
26182 +} while (0)
26183 +
26184 +#define EMIT2_off32(b1, b2, _off) \
26185 +do { \
26186 + if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
26187 + EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
26188 + EMIT(randkey, 4); \
26189 + EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
26190 + EMIT((_off) - randkey, 4); \
26191 + } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
26192 + DILUTE_CONST_SEQUENCE(_off, randkey); \
26193 + /* imul eax, ecx */ \
26194 + EMIT3(0x0f, 0xaf, 0xc1); \
26195 + } else { \
26196 + EMIT2(b1, b2); \
26197 + EMIT(_off, 4); \
26198 + } \
26199 +} while (0)
26200 +#else
26201 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
26202 +#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
26203 +#endif
26204
26205 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
26206 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
26207 @@ -89,6 +164,24 @@ do { \
26208 #define X86_JBE 0x76
26209 #define X86_JA 0x77
26210
26211 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
26212 +#define APPEND_FLOW_VERIFY() \
26213 +do { \
26214 + /* mov ecx, randkey */ \
26215 + EMIT1(0xb9); \
26216 + EMIT(randkey, 4); \
26217 + /* cmp ecx, randkey */ \
26218 + EMIT2(0x81, 0xf9); \
26219 + EMIT(randkey, 4); \
26220 + /* jz after 8 int 3s */ \
26221 + EMIT2(0x74, 0x08); \
26222 + EMIT(0xcccccccc, 4); \
26223 + EMIT(0xcccccccc, 4); \
26224 +} while (0)
26225 +#else
26226 +#define APPEND_FLOW_VERIFY() do { } while (0)
26227 +#endif
26228 +
26229 #define EMIT_COND_JMP(op, offset) \
26230 do { \
26231 if (is_near(offset)) \
26232 @@ -96,6 +189,7 @@ do { \
26233 else { \
26234 EMIT2(0x0f, op + 0x10); \
26235 EMIT(offset, 4); /* jxx .+off32 */ \
26236 + APPEND_FLOW_VERIFY(); \
26237 } \
26238 } while (0)
26239
26240 @@ -120,12 +214,17 @@ static inline void bpf_flush_icache(void *start, void *end)
26241 set_fs(old_fs);
26242 }
26243
26244 +struct bpf_jit_work {
26245 + struct work_struct work;
26246 + void *image;
26247 +};
26248 +
26249 #define CHOOSE_LOAD_FUNC(K, func) \
26250 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
26251
26252 void bpf_jit_compile(struct sk_filter *fp)
26253 {
26254 - u8 temp[64];
26255 + u8 temp[MAX_INSTR_CODE_SIZE];
26256 u8 *prog;
26257 unsigned int proglen, oldproglen = 0;
26258 int ilen, i;
26259 @@ -138,6 +237,9 @@ void bpf_jit_compile(struct sk_filter *fp)
26260 unsigned int *addrs;
26261 const struct sock_filter *filter = fp->insns;
26262 int flen = fp->len;
26263 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
26264 + unsigned int randkey;
26265 +#endif
26266
26267 if (!bpf_jit_enable)
26268 return;
26269 @@ -146,11 +248,19 @@ void bpf_jit_compile(struct sk_filter *fp)
26270 if (addrs == NULL)
26271 return;
26272
26273 + fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
26274 + if (!fp->work)
26275 + goto out;
26276 +
26277 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
26278 + randkey = get_random_int();
26279 +#endif
26280 +
26281 /* Before first pass, make a rough estimation of addrs[]
26282 - * each bpf instruction is translated to less than 64 bytes
26283 + * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
26284 */
26285 for (proglen = 0, i = 0; i < flen; i++) {
26286 - proglen += 64;
26287 + proglen += MAX_INSTR_CODE_SIZE;
26288 addrs[i] = proglen;
26289 }
26290 cleanup_addr = proglen; /* epilogue address */
26291 @@ -258,10 +368,8 @@ void bpf_jit_compile(struct sk_filter *fp)
26292 case BPF_S_ALU_MUL_K: /* A *= K */
26293 if (is_imm8(K))
26294 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
26295 - else {
26296 - EMIT2(0x69, 0xc0); /* imul imm32,%eax */
26297 - EMIT(K, 4);
26298 - }
26299 + else
26300 + EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
26301 break;
26302 case BPF_S_ALU_DIV_X: /* A /= X; */
26303 seen |= SEEN_XREG;
26304 @@ -281,8 +389,14 @@ void bpf_jit_compile(struct sk_filter *fp)
26305 EMIT4(0x31, 0xd2, 0xf7, 0xf3); /* xor %edx,%edx; div %ebx */
26306 break;
26307 case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K); */
26308 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
26309 + DILUTE_CONST_SEQUENCE(K, randkey);
26310 + // imul rax, rcx
26311 + EMIT4(0x48, 0x0f, 0xaf, 0xc1);
26312 +#else
26313 EMIT3(0x48, 0x69, 0xc0); /* imul imm32,%rax,%rax */
26314 EMIT(K, 4);
26315 +#endif
26316 EMIT4(0x48, 0xc1, 0xe8, 0x20); /* shr $0x20,%rax */
26317 break;
26318 case BPF_S_ALU_AND_X:
26319 @@ -509,8 +623,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
26320 if (is_imm8(K)) {
26321 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
26322 } else {
26323 - EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
26324 - EMIT(K, 4);
26325 + EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
26326 }
26327 } else {
26328 EMIT2(0x89,0xde); /* mov %ebx,%esi */
26329 @@ -593,17 +706,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26330 break;
26331 default:
26332 /* hmm, too complex filter, give up with jit compiler */
26333 - goto out;
26334 + goto error;
26335 }
26336 ilen = prog - temp;
26337 if (image) {
26338 if (unlikely(proglen + ilen > oldproglen)) {
26339 pr_err("bpb_jit_compile fatal error\n");
26340 - kfree(addrs);
26341 - module_free(NULL, image);
26342 - return;
26343 + module_free_exec(NULL, image);
26344 + goto error;
26345 }
26346 + pax_open_kernel();
26347 memcpy(image + proglen, temp, ilen);
26348 + pax_close_kernel();
26349 }
26350 proglen += ilen;
26351 addrs[i] = proglen;
26352 @@ -624,11 +738,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26353 break;
26354 }
26355 if (proglen == oldproglen) {
26356 - image = module_alloc(max_t(unsigned int,
26357 - proglen,
26358 - sizeof(struct work_struct)));
26359 + image = module_alloc_exec(proglen);
26360 if (!image)
26361 - goto out;
26362 + goto error;
26363 }
26364 oldproglen = proglen;
26365 }
26366 @@ -644,7 +756,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26367 bpf_flush_icache(image, image + proglen);
26368
26369 fp->bpf_func = (void *)image;
26370 - }
26371 + } else
26372 +error:
26373 + kfree(fp->work);
26374 +
26375 out:
26376 kfree(addrs);
26377 return;
26378 @@ -652,18 +767,20 @@ out:
26379
26380 static void jit_free_defer(struct work_struct *arg)
26381 {
26382 - module_free(NULL, arg);
26383 + module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
26384 + kfree(arg);
26385 }
26386
26387 /* run from softirq, we must use a work_struct to call
26388 - * module_free() from process context
26389 + * module_free_exec() from process context
26390 */
26391 void bpf_jit_free(struct sk_filter *fp)
26392 {
26393 if (fp->bpf_func != sk_run_filter) {
26394 - struct work_struct *work = (struct work_struct *)fp->bpf_func;
26395 + struct work_struct *work = &fp->work->work;
26396
26397 INIT_WORK(work, jit_free_defer);
26398 + fp->work->image = fp->bpf_func;
26399 schedule_work(work);
26400 }
26401 }
26402 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
26403 index d6aa6e8..266395a 100644
26404 --- a/arch/x86/oprofile/backtrace.c
26405 +++ b/arch/x86/oprofile/backtrace.c
26406 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
26407 struct stack_frame_ia32 *fp;
26408 unsigned long bytes;
26409
26410 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
26411 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
26412 if (bytes != sizeof(bufhead))
26413 return NULL;
26414
26415 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
26416 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
26417
26418 oprofile_add_trace(bufhead[0].return_address);
26419
26420 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
26421 struct stack_frame bufhead[2];
26422 unsigned long bytes;
26423
26424 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
26425 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
26426 if (bytes != sizeof(bufhead))
26427 return NULL;
26428
26429 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
26430 {
26431 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
26432
26433 - if (!user_mode_vm(regs)) {
26434 + if (!user_mode(regs)) {
26435 unsigned long stack = kernel_stack_pointer(regs);
26436 if (depth)
26437 dump_trace(NULL, regs, (unsigned long *)stack, 0,
26438 diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
26439 index e14a2ff..3fd6b58 100644
26440 --- a/arch/x86/pci/mrst.c
26441 +++ b/arch/x86/pci/mrst.c
26442 @@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
26443 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
26444 pci_mmcfg_late_init();
26445 pcibios_enable_irq = mrst_pci_irq_enable;
26446 - pci_root_ops = pci_mrst_ops;
26447 + pax_open_kernel();
26448 + memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
26449 + pax_close_kernel();
26450 pci_soc_mode = 1;
26451 /* Continue with standard init */
26452 return 1;
26453 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
26454 index da8fe05..7ee6704 100644
26455 --- a/arch/x86/pci/pcbios.c
26456 +++ b/arch/x86/pci/pcbios.c
26457 @@ -79,50 +79,93 @@ union bios32 {
26458 static struct {
26459 unsigned long address;
26460 unsigned short segment;
26461 -} bios32_indirect = { 0, __KERNEL_CS };
26462 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
26463
26464 /*
26465 * Returns the entry point for the given service, NULL on error
26466 */
26467
26468 -static unsigned long bios32_service(unsigned long service)
26469 +static unsigned long __devinit bios32_service(unsigned long service)
26470 {
26471 unsigned char return_code; /* %al */
26472 unsigned long address; /* %ebx */
26473 unsigned long length; /* %ecx */
26474 unsigned long entry; /* %edx */
26475 unsigned long flags;
26476 + struct desc_struct d, *gdt;
26477
26478 local_irq_save(flags);
26479 - __asm__("lcall *(%%edi); cld"
26480 +
26481 + gdt = get_cpu_gdt_table(smp_processor_id());
26482 +
26483 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
26484 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26485 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
26486 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26487 +
26488 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
26489 : "=a" (return_code),
26490 "=b" (address),
26491 "=c" (length),
26492 "=d" (entry)
26493 : "0" (service),
26494 "1" (0),
26495 - "D" (&bios32_indirect));
26496 + "D" (&bios32_indirect),
26497 + "r"(__PCIBIOS_DS)
26498 + : "memory");
26499 +
26500 + pax_open_kernel();
26501 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
26502 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
26503 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
26504 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
26505 + pax_close_kernel();
26506 +
26507 local_irq_restore(flags);
26508
26509 switch (return_code) {
26510 - case 0:
26511 - return address + entry;
26512 - case 0x80: /* Not present */
26513 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26514 - return 0;
26515 - default: /* Shouldn't happen */
26516 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26517 - service, return_code);
26518 + case 0: {
26519 + int cpu;
26520 + unsigned char flags;
26521 +
26522 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
26523 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
26524 + printk(KERN_WARNING "bios32_service: not valid\n");
26525 return 0;
26526 + }
26527 + address = address + PAGE_OFFSET;
26528 + length += 16UL; /* some BIOSs underreport this... */
26529 + flags = 4;
26530 + if (length >= 64*1024*1024) {
26531 + length >>= PAGE_SHIFT;
26532 + flags |= 8;
26533 + }
26534 +
26535 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
26536 + gdt = get_cpu_gdt_table(cpu);
26537 + pack_descriptor(&d, address, length, 0x9b, flags);
26538 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26539 + pack_descriptor(&d, address, length, 0x93, flags);
26540 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26541 + }
26542 + return entry;
26543 + }
26544 + case 0x80: /* Not present */
26545 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26546 + return 0;
26547 + default: /* Shouldn't happen */
26548 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26549 + service, return_code);
26550 + return 0;
26551 }
26552 }
26553
26554 static struct {
26555 unsigned long address;
26556 unsigned short segment;
26557 -} pci_indirect = { 0, __KERNEL_CS };
26558 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
26559
26560 -static int pci_bios_present;
26561 +static int pci_bios_present __read_only;
26562
26563 static int __devinit check_pcibios(void)
26564 {
26565 @@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
26566 unsigned long flags, pcibios_entry;
26567
26568 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
26569 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
26570 + pci_indirect.address = pcibios_entry;
26571
26572 local_irq_save(flags);
26573 - __asm__(
26574 - "lcall *(%%edi); cld\n\t"
26575 + __asm__("movw %w6, %%ds\n\t"
26576 + "lcall *%%ss:(%%edi); cld\n\t"
26577 + "push %%ss\n\t"
26578 + "pop %%ds\n\t"
26579 "jc 1f\n\t"
26580 "xor %%ah, %%ah\n"
26581 "1:"
26582 @@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
26583 "=b" (ebx),
26584 "=c" (ecx)
26585 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
26586 - "D" (&pci_indirect)
26587 + "D" (&pci_indirect),
26588 + "r" (__PCIBIOS_DS)
26589 : "memory");
26590 local_irq_restore(flags);
26591
26592 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26593
26594 switch (len) {
26595 case 1:
26596 - __asm__("lcall *(%%esi); cld\n\t"
26597 + __asm__("movw %w6, %%ds\n\t"
26598 + "lcall *%%ss:(%%esi); cld\n\t"
26599 + "push %%ss\n\t"
26600 + "pop %%ds\n\t"
26601 "jc 1f\n\t"
26602 "xor %%ah, %%ah\n"
26603 "1:"
26604 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26605 : "1" (PCIBIOS_READ_CONFIG_BYTE),
26606 "b" (bx),
26607 "D" ((long)reg),
26608 - "S" (&pci_indirect));
26609 + "S" (&pci_indirect),
26610 + "r" (__PCIBIOS_DS));
26611 /*
26612 * Zero-extend the result beyond 8 bits, do not trust the
26613 * BIOS having done it:
26614 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26615 *value &= 0xff;
26616 break;
26617 case 2:
26618 - __asm__("lcall *(%%esi); cld\n\t"
26619 + __asm__("movw %w6, %%ds\n\t"
26620 + "lcall *%%ss:(%%esi); cld\n\t"
26621 + "push %%ss\n\t"
26622 + "pop %%ds\n\t"
26623 "jc 1f\n\t"
26624 "xor %%ah, %%ah\n"
26625 "1:"
26626 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26627 : "1" (PCIBIOS_READ_CONFIG_WORD),
26628 "b" (bx),
26629 "D" ((long)reg),
26630 - "S" (&pci_indirect));
26631 + "S" (&pci_indirect),
26632 + "r" (__PCIBIOS_DS));
26633 /*
26634 * Zero-extend the result beyond 16 bits, do not trust the
26635 * BIOS having done it:
26636 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26637 *value &= 0xffff;
26638 break;
26639 case 4:
26640 - __asm__("lcall *(%%esi); cld\n\t"
26641 + __asm__("movw %w6, %%ds\n\t"
26642 + "lcall *%%ss:(%%esi); cld\n\t"
26643 + "push %%ss\n\t"
26644 + "pop %%ds\n\t"
26645 "jc 1f\n\t"
26646 "xor %%ah, %%ah\n"
26647 "1:"
26648 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26649 : "1" (PCIBIOS_READ_CONFIG_DWORD),
26650 "b" (bx),
26651 "D" ((long)reg),
26652 - "S" (&pci_indirect));
26653 + "S" (&pci_indirect),
26654 + "r" (__PCIBIOS_DS));
26655 break;
26656 }
26657
26658 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26659
26660 switch (len) {
26661 case 1:
26662 - __asm__("lcall *(%%esi); cld\n\t"
26663 + __asm__("movw %w6, %%ds\n\t"
26664 + "lcall *%%ss:(%%esi); cld\n\t"
26665 + "push %%ss\n\t"
26666 + "pop %%ds\n\t"
26667 "jc 1f\n\t"
26668 "xor %%ah, %%ah\n"
26669 "1:"
26670 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26671 "c" (value),
26672 "b" (bx),
26673 "D" ((long)reg),
26674 - "S" (&pci_indirect));
26675 + "S" (&pci_indirect),
26676 + "r" (__PCIBIOS_DS));
26677 break;
26678 case 2:
26679 - __asm__("lcall *(%%esi); cld\n\t"
26680 + __asm__("movw %w6, %%ds\n\t"
26681 + "lcall *%%ss:(%%esi); cld\n\t"
26682 + "push %%ss\n\t"
26683 + "pop %%ds\n\t"
26684 "jc 1f\n\t"
26685 "xor %%ah, %%ah\n"
26686 "1:"
26687 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26688 "c" (value),
26689 "b" (bx),
26690 "D" ((long)reg),
26691 - "S" (&pci_indirect));
26692 + "S" (&pci_indirect),
26693 + "r" (__PCIBIOS_DS));
26694 break;
26695 case 4:
26696 - __asm__("lcall *(%%esi); cld\n\t"
26697 + __asm__("movw %w6, %%ds\n\t"
26698 + "lcall *%%ss:(%%esi); cld\n\t"
26699 + "push %%ss\n\t"
26700 + "pop %%ds\n\t"
26701 "jc 1f\n\t"
26702 "xor %%ah, %%ah\n"
26703 "1:"
26704 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26705 "c" (value),
26706 "b" (bx),
26707 "D" ((long)reg),
26708 - "S" (&pci_indirect));
26709 + "S" (&pci_indirect),
26710 + "r" (__PCIBIOS_DS));
26711 break;
26712 }
26713
26714 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26715
26716 DBG("PCI: Fetching IRQ routing table... ");
26717 __asm__("push %%es\n\t"
26718 + "movw %w8, %%ds\n\t"
26719 "push %%ds\n\t"
26720 "pop %%es\n\t"
26721 - "lcall *(%%esi); cld\n\t"
26722 + "lcall *%%ss:(%%esi); cld\n\t"
26723 "pop %%es\n\t"
26724 + "push %%ss\n\t"
26725 + "pop %%ds\n"
26726 "jc 1f\n\t"
26727 "xor %%ah, %%ah\n"
26728 "1:"
26729 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26730 "1" (0),
26731 "D" ((long) &opt),
26732 "S" (&pci_indirect),
26733 - "m" (opt)
26734 + "m" (opt),
26735 + "r" (__PCIBIOS_DS)
26736 : "memory");
26737 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
26738 if (ret & 0xff00)
26739 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26740 {
26741 int ret;
26742
26743 - __asm__("lcall *(%%esi); cld\n\t"
26744 + __asm__("movw %w5, %%ds\n\t"
26745 + "lcall *%%ss:(%%esi); cld\n\t"
26746 + "push %%ss\n\t"
26747 + "pop %%ds\n"
26748 "jc 1f\n\t"
26749 "xor %%ah, %%ah\n"
26750 "1:"
26751 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26752 : "0" (PCIBIOS_SET_PCI_HW_INT),
26753 "b" ((dev->bus->number << 8) | dev->devfn),
26754 "c" ((irq << 8) | (pin + 10)),
26755 - "S" (&pci_indirect));
26756 + "S" (&pci_indirect),
26757 + "r" (__PCIBIOS_DS));
26758 return !(ret & 0xff00);
26759 }
26760 EXPORT_SYMBOL(pcibios_set_irq_routing);
26761 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
26762 index 40e4469..1ab536e 100644
26763 --- a/arch/x86/platform/efi/efi_32.c
26764 +++ b/arch/x86/platform/efi/efi_32.c
26765 @@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
26766 {
26767 struct desc_ptr gdt_descr;
26768
26769 +#ifdef CONFIG_PAX_KERNEXEC
26770 + struct desc_struct d;
26771 +#endif
26772 +
26773 local_irq_save(efi_rt_eflags);
26774
26775 load_cr3(initial_page_table);
26776 __flush_tlb_all();
26777
26778 +#ifdef CONFIG_PAX_KERNEXEC
26779 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
26780 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26781 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
26782 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26783 +#endif
26784 +
26785 gdt_descr.address = __pa(get_cpu_gdt_table(0));
26786 gdt_descr.size = GDT_SIZE - 1;
26787 load_gdt(&gdt_descr);
26788 @@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
26789 {
26790 struct desc_ptr gdt_descr;
26791
26792 +#ifdef CONFIG_PAX_KERNEXEC
26793 + struct desc_struct d;
26794 +
26795 + memset(&d, 0, sizeof d);
26796 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26797 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26798 +#endif
26799 +
26800 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
26801 gdt_descr.size = GDT_SIZE - 1;
26802 load_gdt(&gdt_descr);
26803 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
26804 index fbe66e6..eae5e38 100644
26805 --- a/arch/x86/platform/efi/efi_stub_32.S
26806 +++ b/arch/x86/platform/efi/efi_stub_32.S
26807 @@ -6,7 +6,9 @@
26808 */
26809
26810 #include <linux/linkage.h>
26811 +#include <linux/init.h>
26812 #include <asm/page_types.h>
26813 +#include <asm/segment.h>
26814
26815 /*
26816 * efi_call_phys(void *, ...) is a function with variable parameters.
26817 @@ -20,7 +22,7 @@
26818 * service functions will comply with gcc calling convention, too.
26819 */
26820
26821 -.text
26822 +__INIT
26823 ENTRY(efi_call_phys)
26824 /*
26825 * 0. The function can only be called in Linux kernel. So CS has been
26826 @@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
26827 * The mapping of lower virtual memory has been created in prelog and
26828 * epilog.
26829 */
26830 - movl $1f, %edx
26831 - subl $__PAGE_OFFSET, %edx
26832 - jmp *%edx
26833 +#ifdef CONFIG_PAX_KERNEXEC
26834 + movl $(__KERNEXEC_EFI_DS), %edx
26835 + mov %edx, %ds
26836 + mov %edx, %es
26837 + mov %edx, %ss
26838 + addl $2f,(1f)
26839 + ljmp *(1f)
26840 +
26841 +__INITDATA
26842 +1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
26843 +.previous
26844 +
26845 +2:
26846 + subl $2b,(1b)
26847 +#else
26848 + jmp 1f-__PAGE_OFFSET
26849 1:
26850 +#endif
26851
26852 /*
26853 * 2. Now on the top of stack is the return
26854 @@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
26855 * parameter 2, ..., param n. To make things easy, we save the return
26856 * address of efi_call_phys in a global variable.
26857 */
26858 - popl %edx
26859 - movl %edx, saved_return_addr
26860 - /* get the function pointer into ECX*/
26861 - popl %ecx
26862 - movl %ecx, efi_rt_function_ptr
26863 - movl $2f, %edx
26864 - subl $__PAGE_OFFSET, %edx
26865 - pushl %edx
26866 + popl (saved_return_addr)
26867 + popl (efi_rt_function_ptr)
26868
26869 /*
26870 * 3. Clear PG bit in %CR0.
26871 @@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
26872 /*
26873 * 5. Call the physical function.
26874 */
26875 - jmp *%ecx
26876 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
26877
26878 -2:
26879 /*
26880 * 6. After EFI runtime service returns, control will return to
26881 * following instruction. We'd better readjust stack pointer first.
26882 @@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
26883 movl %cr0, %edx
26884 orl $0x80000000, %edx
26885 movl %edx, %cr0
26886 - jmp 1f
26887 -1:
26888 +
26889 /*
26890 * 8. Now restore the virtual mode from flat mode by
26891 * adding EIP with PAGE_OFFSET.
26892 */
26893 - movl $1f, %edx
26894 - jmp *%edx
26895 +#ifdef CONFIG_PAX_KERNEXEC
26896 + movl $(__KERNEL_DS), %edx
26897 + mov %edx, %ds
26898 + mov %edx, %es
26899 + mov %edx, %ss
26900 + ljmp $(__KERNEL_CS),$1f
26901 +#else
26902 + jmp 1f+__PAGE_OFFSET
26903 +#endif
26904 1:
26905
26906 /*
26907 * 9. Balance the stack. And because EAX contain the return value,
26908 * we'd better not clobber it.
26909 */
26910 - leal efi_rt_function_ptr, %edx
26911 - movl (%edx), %ecx
26912 - pushl %ecx
26913 + pushl (efi_rt_function_ptr)
26914
26915 /*
26916 - * 10. Push the saved return address onto the stack and return.
26917 + * 10. Return to the saved return address.
26918 */
26919 - leal saved_return_addr, %edx
26920 - movl (%edx), %ecx
26921 - pushl %ecx
26922 - ret
26923 + jmpl *(saved_return_addr)
26924 ENDPROC(efi_call_phys)
26925 .previous
26926
26927 -.data
26928 +__INITDATA
26929 saved_return_addr:
26930 .long 0
26931 efi_rt_function_ptr:
26932 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
26933 index 4c07cca..2c8427d 100644
26934 --- a/arch/x86/platform/efi/efi_stub_64.S
26935 +++ b/arch/x86/platform/efi/efi_stub_64.S
26936 @@ -7,6 +7,7 @@
26937 */
26938
26939 #include <linux/linkage.h>
26940 +#include <asm/alternative-asm.h>
26941
26942 #define SAVE_XMM \
26943 mov %rsp, %rax; \
26944 @@ -40,6 +41,7 @@ ENTRY(efi_call0)
26945 call *%rdi
26946 addq $32, %rsp
26947 RESTORE_XMM
26948 + pax_force_retaddr 0, 1
26949 ret
26950 ENDPROC(efi_call0)
26951
26952 @@ -50,6 +52,7 @@ ENTRY(efi_call1)
26953 call *%rdi
26954 addq $32, %rsp
26955 RESTORE_XMM
26956 + pax_force_retaddr 0, 1
26957 ret
26958 ENDPROC(efi_call1)
26959
26960 @@ -60,6 +63,7 @@ ENTRY(efi_call2)
26961 call *%rdi
26962 addq $32, %rsp
26963 RESTORE_XMM
26964 + pax_force_retaddr 0, 1
26965 ret
26966 ENDPROC(efi_call2)
26967
26968 @@ -71,6 +75,7 @@ ENTRY(efi_call3)
26969 call *%rdi
26970 addq $32, %rsp
26971 RESTORE_XMM
26972 + pax_force_retaddr 0, 1
26973 ret
26974 ENDPROC(efi_call3)
26975
26976 @@ -83,6 +88,7 @@ ENTRY(efi_call4)
26977 call *%rdi
26978 addq $32, %rsp
26979 RESTORE_XMM
26980 + pax_force_retaddr 0, 1
26981 ret
26982 ENDPROC(efi_call4)
26983
26984 @@ -96,6 +102,7 @@ ENTRY(efi_call5)
26985 call *%rdi
26986 addq $48, %rsp
26987 RESTORE_XMM
26988 + pax_force_retaddr 0, 1
26989 ret
26990 ENDPROC(efi_call5)
26991
26992 @@ -112,5 +119,6 @@ ENTRY(efi_call6)
26993 call *%rdi
26994 addq $48, %rsp
26995 RESTORE_XMM
26996 + pax_force_retaddr 0, 1
26997 ret
26998 ENDPROC(efi_call6)
26999 diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
27000 index fd41a92..9c33628 100644
27001 --- a/arch/x86/platform/mrst/mrst.c
27002 +++ b/arch/x86/platform/mrst/mrst.c
27003 @@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
27004 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
27005 int sfi_mrtc_num;
27006
27007 -static void mrst_power_off(void)
27008 +static __noreturn void mrst_power_off(void)
27009 {
27010 + BUG();
27011 }
27012
27013 -static void mrst_reboot(void)
27014 +static __noreturn void mrst_reboot(void)
27015 {
27016 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
27017 + BUG();
27018 }
27019
27020 /* parse all the mtimer info to a static mtimer array */
27021 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
27022 index 218cdb1..fd55c08 100644
27023 --- a/arch/x86/power/cpu.c
27024 +++ b/arch/x86/power/cpu.c
27025 @@ -132,7 +132,7 @@ static void do_fpu_end(void)
27026 static void fix_processor_context(void)
27027 {
27028 int cpu = smp_processor_id();
27029 - struct tss_struct *t = &per_cpu(init_tss, cpu);
27030 + struct tss_struct *t = init_tss + cpu;
27031
27032 set_tss_desc(cpu, t); /*
27033 * This just modifies memory; should not be
27034 @@ -142,7 +142,9 @@ static void fix_processor_context(void)
27035 */
27036
27037 #ifdef CONFIG_X86_64
27038 + pax_open_kernel();
27039 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
27040 + pax_close_kernel();
27041
27042 syscall_init(); /* This sets MSR_*STAR and related */
27043 #endif
27044 diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
27045 index cbca565..bae7133 100644
27046 --- a/arch/x86/realmode/init.c
27047 +++ b/arch/x86/realmode/init.c
27048 @@ -62,7 +62,13 @@ void __init setup_real_mode(void)
27049 __va(real_mode_header->trampoline_header);
27050
27051 #ifdef CONFIG_X86_32
27052 - trampoline_header->start = __pa(startup_32_smp);
27053 + trampoline_header->start = __pa(ktla_ktva(startup_32_smp));
27054 +
27055 +#ifdef CONFIG_PAX_KERNEXEC
27056 + trampoline_header->start -= LOAD_PHYSICAL_ADDR;
27057 +#endif
27058 +
27059 + trampoline_header->boot_cs = __BOOT_CS;
27060 trampoline_header->gdt_limit = __BOOT_DS + 7;
27061 trampoline_header->gdt_base = __pa(boot_gdt);
27062 #else
27063 diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
27064 index 8869287..d577672 100644
27065 --- a/arch/x86/realmode/rm/Makefile
27066 +++ b/arch/x86/realmode/rm/Makefile
27067 @@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
27068 $(call cc-option, -fno-unit-at-a-time)) \
27069 $(call cc-option, -fno-stack-protector) \
27070 $(call cc-option, -mpreferred-stack-boundary=2)
27071 +ifdef CONSTIFY_PLUGIN
27072 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
27073 +endif
27074 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
27075 GCOV_PROFILE := n
27076 diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
27077 index a28221d..93c40f1 100644
27078 --- a/arch/x86/realmode/rm/header.S
27079 +++ b/arch/x86/realmode/rm/header.S
27080 @@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
27081 #endif
27082 /* APM/BIOS reboot */
27083 .long pa_machine_real_restart_asm
27084 -#ifdef CONFIG_X86_64
27085 +#ifdef CONFIG_X86_32
27086 + .long __KERNEL_CS
27087 +#else
27088 .long __KERNEL32_CS
27089 #endif
27090 END(real_mode_header)
27091 diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
27092 index c1b2791..f9e31c7 100644
27093 --- a/arch/x86/realmode/rm/trampoline_32.S
27094 +++ b/arch/x86/realmode/rm/trampoline_32.S
27095 @@ -25,6 +25,12 @@
27096 #include <asm/page_types.h>
27097 #include "realmode.h"
27098
27099 +#ifdef CONFIG_PAX_KERNEXEC
27100 +#define ta(X) (X)
27101 +#else
27102 +#define ta(X) (pa_ ## X)
27103 +#endif
27104 +
27105 .text
27106 .code16
27107
27108 @@ -39,8 +45,6 @@ ENTRY(trampoline_start)
27109
27110 cli # We should be safe anyway
27111
27112 - movl tr_start, %eax # where we need to go
27113 -
27114 movl $0xA5A5A5A5, trampoline_status
27115 # write marker for master knows we're running
27116
27117 @@ -56,7 +60,7 @@ ENTRY(trampoline_start)
27118 movw $1, %dx # protected mode (PE) bit
27119 lmsw %dx # into protected mode
27120
27121 - ljmpl $__BOOT_CS, $pa_startup_32
27122 + ljmpl *(trampoline_header)
27123
27124 .section ".text32","ax"
27125 .code32
27126 @@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
27127 .balign 8
27128 GLOBAL(trampoline_header)
27129 tr_start: .space 4
27130 - tr_gdt_pad: .space 2
27131 + tr_boot_cs: .space 2
27132 tr_gdt: .space 6
27133 END(trampoline_header)
27134
27135 diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
27136 index bb360dc..3e5945f 100644
27137 --- a/arch/x86/realmode/rm/trampoline_64.S
27138 +++ b/arch/x86/realmode/rm/trampoline_64.S
27139 @@ -107,7 +107,7 @@ ENTRY(startup_32)
27140 wrmsr
27141
27142 # Enable paging and in turn activate Long Mode
27143 - movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
27144 + movl $(X86_CR0_PG | X86_CR0_PE), %eax
27145 movl %eax, %cr0
27146
27147 /*
27148 diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
27149 index 5a1847d..deccb30 100644
27150 --- a/arch/x86/tools/relocs.c
27151 +++ b/arch/x86/tools/relocs.c
27152 @@ -12,10 +12,13 @@
27153 #include <regex.h>
27154 #include <tools/le_byteshift.h>
27155
27156 +#include "../../../include/generated/autoconf.h"
27157 +
27158 static void die(char *fmt, ...);
27159
27160 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
27161 static Elf32_Ehdr ehdr;
27162 +static Elf32_Phdr *phdr;
27163 static unsigned long reloc_count, reloc_idx;
27164 static unsigned long *relocs;
27165 static unsigned long reloc16_count, reloc16_idx;
27166 @@ -330,9 +333,39 @@ static void read_ehdr(FILE *fp)
27167 }
27168 }
27169
27170 +static void read_phdrs(FILE *fp)
27171 +{
27172 + unsigned int i;
27173 +
27174 + phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
27175 + if (!phdr) {
27176 + die("Unable to allocate %d program headers\n",
27177 + ehdr.e_phnum);
27178 + }
27179 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
27180 + die("Seek to %d failed: %s\n",
27181 + ehdr.e_phoff, strerror(errno));
27182 + }
27183 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
27184 + die("Cannot read ELF program headers: %s\n",
27185 + strerror(errno));
27186 + }
27187 + for(i = 0; i < ehdr.e_phnum; i++) {
27188 + phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
27189 + phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
27190 + phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
27191 + phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
27192 + phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
27193 + phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
27194 + phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
27195 + phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
27196 + }
27197 +
27198 +}
27199 +
27200 static void read_shdrs(FILE *fp)
27201 {
27202 - int i;
27203 + unsigned int i;
27204 Elf32_Shdr shdr;
27205
27206 secs = calloc(ehdr.e_shnum, sizeof(struct section));
27207 @@ -367,7 +400,7 @@ static void read_shdrs(FILE *fp)
27208
27209 static void read_strtabs(FILE *fp)
27210 {
27211 - int i;
27212 + unsigned int i;
27213 for (i = 0; i < ehdr.e_shnum; i++) {
27214 struct section *sec = &secs[i];
27215 if (sec->shdr.sh_type != SHT_STRTAB) {
27216 @@ -392,7 +425,7 @@ static void read_strtabs(FILE *fp)
27217
27218 static void read_symtabs(FILE *fp)
27219 {
27220 - int i,j;
27221 + unsigned int i,j;
27222 for (i = 0; i < ehdr.e_shnum; i++) {
27223 struct section *sec = &secs[i];
27224 if (sec->shdr.sh_type != SHT_SYMTAB) {
27225 @@ -423,9 +456,11 @@ static void read_symtabs(FILE *fp)
27226 }
27227
27228
27229 -static void read_relocs(FILE *fp)
27230 +static void read_relocs(FILE *fp, int use_real_mode)
27231 {
27232 - int i,j;
27233 + unsigned int i,j;
27234 + uint32_t base;
27235 +
27236 for (i = 0; i < ehdr.e_shnum; i++) {
27237 struct section *sec = &secs[i];
27238 if (sec->shdr.sh_type != SHT_REL) {
27239 @@ -445,9 +480,22 @@ static void read_relocs(FILE *fp)
27240 die("Cannot read symbol table: %s\n",
27241 strerror(errno));
27242 }
27243 + base = 0;
27244 +
27245 +#ifdef CONFIG_X86_32
27246 + for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
27247 + if (phdr[j].p_type != PT_LOAD )
27248 + continue;
27249 + 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)
27250 + continue;
27251 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
27252 + break;
27253 + }
27254 +#endif
27255 +
27256 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
27257 Elf32_Rel *rel = &sec->reltab[j];
27258 - rel->r_offset = elf32_to_cpu(rel->r_offset);
27259 + rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
27260 rel->r_info = elf32_to_cpu(rel->r_info);
27261 }
27262 }
27263 @@ -456,13 +504,13 @@ static void read_relocs(FILE *fp)
27264
27265 static void print_absolute_symbols(void)
27266 {
27267 - int i;
27268 + unsigned int i;
27269 printf("Absolute symbols\n");
27270 printf(" Num: Value Size Type Bind Visibility Name\n");
27271 for (i = 0; i < ehdr.e_shnum; i++) {
27272 struct section *sec = &secs[i];
27273 char *sym_strtab;
27274 - int j;
27275 + unsigned int j;
27276
27277 if (sec->shdr.sh_type != SHT_SYMTAB) {
27278 continue;
27279 @@ -489,14 +537,14 @@ static void print_absolute_symbols(void)
27280
27281 static void print_absolute_relocs(void)
27282 {
27283 - int i, printed = 0;
27284 + unsigned int i, printed = 0;
27285
27286 for (i = 0; i < ehdr.e_shnum; i++) {
27287 struct section *sec = &secs[i];
27288 struct section *sec_applies, *sec_symtab;
27289 char *sym_strtab;
27290 Elf32_Sym *sh_symtab;
27291 - int j;
27292 + unsigned int j;
27293 if (sec->shdr.sh_type != SHT_REL) {
27294 continue;
27295 }
27296 @@ -558,13 +606,13 @@ static void print_absolute_relocs(void)
27297 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
27298 int use_real_mode)
27299 {
27300 - int i;
27301 + unsigned int i;
27302 /* Walk through the relocations */
27303 for (i = 0; i < ehdr.e_shnum; i++) {
27304 char *sym_strtab;
27305 Elf32_Sym *sh_symtab;
27306 struct section *sec_applies, *sec_symtab;
27307 - int j;
27308 + unsigned int j;
27309 struct section *sec = &secs[i];
27310
27311 if (sec->shdr.sh_type != SHT_REL) {
27312 @@ -588,6 +636,24 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
27313 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
27314 r_type = ELF32_R_TYPE(rel->r_info);
27315
27316 + if (!use_real_mode) {
27317 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
27318 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
27319 + continue;
27320 +
27321 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
27322 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
27323 + if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
27324 + continue;
27325 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
27326 + continue;
27327 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
27328 + continue;
27329 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
27330 + continue;
27331 +#endif
27332 + }
27333 +
27334 shn_abs = sym->st_shndx == SHN_ABS;
27335
27336 switch (r_type) {
27337 @@ -681,7 +747,7 @@ static int write32(unsigned int v, FILE *f)
27338
27339 static void emit_relocs(int as_text, int use_real_mode)
27340 {
27341 - int i;
27342 + unsigned int i;
27343 /* Count how many relocations I have and allocate space for them. */
27344 reloc_count = 0;
27345 walk_relocs(count_reloc, use_real_mode);
27346 @@ -808,10 +874,11 @@ int main(int argc, char **argv)
27347 fname, strerror(errno));
27348 }
27349 read_ehdr(fp);
27350 + read_phdrs(fp);
27351 read_shdrs(fp);
27352 read_strtabs(fp);
27353 read_symtabs(fp);
27354 - read_relocs(fp);
27355 + read_relocs(fp, use_real_mode);
27356 if (show_absolute_syms) {
27357 print_absolute_symbols();
27358 return 0;
27359 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
27360 index fd14be1..e3c79c0 100644
27361 --- a/arch/x86/vdso/Makefile
27362 +++ b/arch/x86/vdso/Makefile
27363 @@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
27364 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
27365 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
27366
27367 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
27368 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
27369 GCOV_PROFILE := n
27370
27371 #
27372 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
27373 index 0faad64..39ef157 100644
27374 --- a/arch/x86/vdso/vdso32-setup.c
27375 +++ b/arch/x86/vdso/vdso32-setup.c
27376 @@ -25,6 +25,7 @@
27377 #include <asm/tlbflush.h>
27378 #include <asm/vdso.h>
27379 #include <asm/proto.h>
27380 +#include <asm/mman.h>
27381
27382 enum {
27383 VDSO_DISABLED = 0,
27384 @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
27385 void enable_sep_cpu(void)
27386 {
27387 int cpu = get_cpu();
27388 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
27389 + struct tss_struct *tss = init_tss + cpu;
27390
27391 if (!boot_cpu_has(X86_FEATURE_SEP)) {
27392 put_cpu();
27393 @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
27394 gate_vma.vm_start = FIXADDR_USER_START;
27395 gate_vma.vm_end = FIXADDR_USER_END;
27396 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
27397 - gate_vma.vm_page_prot = __P101;
27398 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
27399
27400 return 0;
27401 }
27402 @@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27403 if (compat)
27404 addr = VDSO_HIGH_BASE;
27405 else {
27406 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
27407 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
27408 if (IS_ERR_VALUE(addr)) {
27409 ret = addr;
27410 goto up_fail;
27411 }
27412 }
27413
27414 - current->mm->context.vdso = (void *)addr;
27415 + current->mm->context.vdso = addr;
27416
27417 if (compat_uses_vma || !compat) {
27418 /*
27419 @@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27420 }
27421
27422 current_thread_info()->sysenter_return =
27423 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
27424 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
27425
27426 up_fail:
27427 if (ret)
27428 - current->mm->context.vdso = NULL;
27429 + current->mm->context.vdso = 0;
27430
27431 up_write(&mm->mmap_sem);
27432
27433 @@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
27434
27435 const char *arch_vma_name(struct vm_area_struct *vma)
27436 {
27437 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
27438 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
27439 return "[vdso]";
27440 +
27441 +#ifdef CONFIG_PAX_SEGMEXEC
27442 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
27443 + return "[vdso]";
27444 +#endif
27445 +
27446 return NULL;
27447 }
27448
27449 @@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
27450 * Check to see if the corresponding task was created in compat vdso
27451 * mode.
27452 */
27453 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
27454 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
27455 return &gate_vma;
27456 return NULL;
27457 }
27458 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
27459 index 00aaf04..4a26505 100644
27460 --- a/arch/x86/vdso/vma.c
27461 +++ b/arch/x86/vdso/vma.c
27462 @@ -16,8 +16,6 @@
27463 #include <asm/vdso.h>
27464 #include <asm/page.h>
27465
27466 -unsigned int __read_mostly vdso_enabled = 1;
27467 -
27468 extern char vdso_start[], vdso_end[];
27469 extern unsigned short vdso_sync_cpuid;
27470
27471 @@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
27472 * unaligned here as a result of stack start randomization.
27473 */
27474 addr = PAGE_ALIGN(addr);
27475 - addr = align_addr(addr, NULL, ALIGN_VDSO);
27476
27477 return addr;
27478 }
27479 @@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
27480 unsigned size)
27481 {
27482 struct mm_struct *mm = current->mm;
27483 - unsigned long addr;
27484 + unsigned long addr = 0;
27485 int ret;
27486
27487 - if (!vdso_enabled)
27488 - return 0;
27489 -
27490 down_write(&mm->mmap_sem);
27491 +
27492 +#ifdef CONFIG_PAX_RANDMMAP
27493 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27494 +#endif
27495 +
27496 addr = vdso_addr(mm->start_stack, size);
27497 + addr = align_addr(addr, NULL, ALIGN_VDSO);
27498 addr = get_unmapped_area(NULL, addr, size, 0, 0);
27499 if (IS_ERR_VALUE(addr)) {
27500 ret = addr;
27501 goto up_fail;
27502 }
27503
27504 - current->mm->context.vdso = (void *)addr;
27505 + mm->context.vdso = addr;
27506
27507 ret = install_special_mapping(mm, addr, size,
27508 VM_READ|VM_EXEC|
27509 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
27510 pages);
27511 - if (ret) {
27512 - current->mm->context.vdso = NULL;
27513 - goto up_fail;
27514 - }
27515 + if (ret)
27516 + mm->context.vdso = 0;
27517
27518 up_fail:
27519 up_write(&mm->mmap_sem);
27520 @@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27521 vdsox32_size);
27522 }
27523 #endif
27524 -
27525 -static __init int vdso_setup(char *s)
27526 -{
27527 - vdso_enabled = simple_strtoul(s, NULL, 0);
27528 - return 0;
27529 -}
27530 -__setup("vdso=", vdso_setup);
27531 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
27532 index c1461de..355f120 100644
27533 --- a/arch/x86/xen/enlighten.c
27534 +++ b/arch/x86/xen/enlighten.c
27535 @@ -98,8 +98,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
27536
27537 struct shared_info xen_dummy_shared_info;
27538
27539 -void *xen_initial_gdt;
27540 -
27541 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
27542 __read_mostly int xen_have_vector_callback;
27543 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
27544 @@ -917,21 +915,21 @@ static u32 xen_safe_apic_wait_icr_idle(void)
27545
27546 static void set_xen_basic_apic_ops(void)
27547 {
27548 - apic->read = xen_apic_read;
27549 - apic->write = xen_apic_write;
27550 - apic->icr_read = xen_apic_icr_read;
27551 - apic->icr_write = xen_apic_icr_write;
27552 - apic->wait_icr_idle = xen_apic_wait_icr_idle;
27553 - apic->safe_wait_icr_idle = xen_safe_apic_wait_icr_idle;
27554 - apic->set_apic_id = xen_set_apic_id;
27555 - apic->get_apic_id = xen_get_apic_id;
27556 + *(void **)&apic->read = xen_apic_read;
27557 + *(void **)&apic->write = xen_apic_write;
27558 + *(void **)&apic->icr_read = xen_apic_icr_read;
27559 + *(void **)&apic->icr_write = xen_apic_icr_write;
27560 + *(void **)&apic->wait_icr_idle = xen_apic_wait_icr_idle;
27561 + *(void **)&apic->safe_wait_icr_idle = xen_safe_apic_wait_icr_idle;
27562 + *(void **)&apic->set_apic_id = xen_set_apic_id;
27563 + *(void **)&apic->get_apic_id = xen_get_apic_id;
27564
27565 #ifdef CONFIG_SMP
27566 - apic->send_IPI_allbutself = xen_send_IPI_allbutself;
27567 - apic->send_IPI_mask_allbutself = xen_send_IPI_mask_allbutself;
27568 - apic->send_IPI_mask = xen_send_IPI_mask;
27569 - apic->send_IPI_all = xen_send_IPI_all;
27570 - apic->send_IPI_self = xen_send_IPI_self;
27571 + *(void **)&apic->send_IPI_allbutself = xen_send_IPI_allbutself;
27572 + *(void **)&apic->send_IPI_mask_allbutself = xen_send_IPI_mask_allbutself;
27573 + *(void **)&apic->send_IPI_mask = xen_send_IPI_mask;
27574 + *(void **)&apic->send_IPI_all = xen_send_IPI_all;
27575 + *(void **)&apic->send_IPI_self = xen_send_IPI_self;
27576 #endif
27577 }
27578
27579 @@ -1221,30 +1219,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
27580 #endif
27581 };
27582
27583 -static void xen_reboot(int reason)
27584 +static __noreturn void xen_reboot(int reason)
27585 {
27586 struct sched_shutdown r = { .reason = reason };
27587
27588 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
27589 - BUG();
27590 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
27591 + BUG();
27592 }
27593
27594 -static void xen_restart(char *msg)
27595 +static __noreturn void xen_restart(char *msg)
27596 {
27597 xen_reboot(SHUTDOWN_reboot);
27598 }
27599
27600 -static void xen_emergency_restart(void)
27601 +static __noreturn void xen_emergency_restart(void)
27602 {
27603 xen_reboot(SHUTDOWN_reboot);
27604 }
27605
27606 -static void xen_machine_halt(void)
27607 +static __noreturn void xen_machine_halt(void)
27608 {
27609 xen_reboot(SHUTDOWN_poweroff);
27610 }
27611
27612 -static void xen_machine_power_off(void)
27613 +static __noreturn void xen_machine_power_off(void)
27614 {
27615 if (pm_power_off)
27616 pm_power_off();
27617 @@ -1347,7 +1345,17 @@ asmlinkage void __init xen_start_kernel(void)
27618 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
27619
27620 /* Work out if we support NX */
27621 - x86_configure_nx();
27622 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
27623 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
27624 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
27625 + unsigned l, h;
27626 +
27627 + __supported_pte_mask |= _PAGE_NX;
27628 + rdmsr(MSR_EFER, l, h);
27629 + l |= EFER_NX;
27630 + wrmsr(MSR_EFER, l, h);
27631 + }
27632 +#endif
27633
27634 xen_setup_features();
27635
27636 @@ -1378,13 +1386,6 @@ asmlinkage void __init xen_start_kernel(void)
27637
27638 machine_ops = xen_machine_ops;
27639
27640 - /*
27641 - * The only reliable way to retain the initial address of the
27642 - * percpu gdt_page is to remember it here, so we can go and
27643 - * mark it RW later, when the initial percpu area is freed.
27644 - */
27645 - xen_initial_gdt = &per_cpu(gdt_page, 0);
27646 -
27647 xen_smp_init();
27648
27649 #ifdef CONFIG_ACPI_NUMA
27650 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
27651 index dde1a3f..6b663e6 100644
27652 --- a/arch/x86/xen/mmu.c
27653 +++ b/arch/x86/xen/mmu.c
27654 @@ -1784,6 +1784,9 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27655 convert_pfn_mfn(init_level4_pgt);
27656 convert_pfn_mfn(level3_ident_pgt);
27657 convert_pfn_mfn(level3_kernel_pgt);
27658 + convert_pfn_mfn(level3_vmalloc_start_pgt);
27659 + convert_pfn_mfn(level3_vmalloc_end_pgt);
27660 + convert_pfn_mfn(level3_vmemmap_pgt);
27661
27662 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
27663 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
27664 @@ -1802,7 +1805,11 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27665 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
27666 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
27667 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
27668 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
27669 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
27670 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
27671 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
27672 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
27673 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
27674 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
27675
27676 @@ -1986,6 +1993,7 @@ static void __init xen_post_allocator_init(void)
27677 pv_mmu_ops.set_pud = xen_set_pud;
27678 #if PAGETABLE_LEVELS == 4
27679 pv_mmu_ops.set_pgd = xen_set_pgd;
27680 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
27681 #endif
27682
27683 /* This will work as long as patching hasn't happened yet
27684 @@ -2067,6 +2075,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
27685 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
27686 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
27687 .set_pgd = xen_set_pgd_hyper,
27688 + .set_pgd_batched = xen_set_pgd_hyper,
27689
27690 .alloc_pud = xen_alloc_pmd_init,
27691 .release_pud = xen_release_pmd_init,
27692 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
27693 index f58dca7..ad21f52 100644
27694 --- a/arch/x86/xen/smp.c
27695 +++ b/arch/x86/xen/smp.c
27696 @@ -229,11 +229,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
27697 {
27698 BUG_ON(smp_processor_id() != 0);
27699 native_smp_prepare_boot_cpu();
27700 -
27701 - /* We've switched to the "real" per-cpu gdt, so make sure the
27702 - old memory can be recycled */
27703 - make_lowmem_page_readwrite(xen_initial_gdt);
27704 -
27705 xen_filter_cpu_maps();
27706 xen_setup_vcpu_info_placement();
27707 }
27708 @@ -300,12 +295,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
27709 gdt = get_cpu_gdt_table(cpu);
27710
27711 ctxt->flags = VGCF_IN_KERNEL;
27712 - ctxt->user_regs.ds = __USER_DS;
27713 - ctxt->user_regs.es = __USER_DS;
27714 + ctxt->user_regs.ds = __KERNEL_DS;
27715 + ctxt->user_regs.es = __KERNEL_DS;
27716 ctxt->user_regs.ss = __KERNEL_DS;
27717 #ifdef CONFIG_X86_32
27718 ctxt->user_regs.fs = __KERNEL_PERCPU;
27719 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
27720 + savesegment(gs, ctxt->user_regs.gs);
27721 #else
27722 ctxt->gs_base_kernel = per_cpu_offset(cpu);
27723 #endif
27724 @@ -355,13 +350,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
27725 int rc;
27726
27727 per_cpu(current_task, cpu) = idle;
27728 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
27729 #ifdef CONFIG_X86_32
27730 irq_ctx_init(cpu);
27731 #else
27732 clear_tsk_thread_flag(idle, TIF_FORK);
27733 - per_cpu(kernel_stack, cpu) =
27734 - (unsigned long)task_stack_page(idle) -
27735 - KERNEL_STACK_OFFSET + THREAD_SIZE;
27736 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27737 #endif
27738 xen_setup_runstate_info(cpu);
27739 xen_setup_timer(cpu);
27740 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
27741 index f9643fc..602e8af 100644
27742 --- a/arch/x86/xen/xen-asm_32.S
27743 +++ b/arch/x86/xen/xen-asm_32.S
27744 @@ -84,14 +84,14 @@ ENTRY(xen_iret)
27745 ESP_OFFSET=4 # bytes pushed onto stack
27746
27747 /*
27748 - * Store vcpu_info pointer for easy access. Do it this way to
27749 - * avoid having to reload %fs
27750 + * Store vcpu_info pointer for easy access.
27751 */
27752 #ifdef CONFIG_SMP
27753 - GET_THREAD_INFO(%eax)
27754 - movl TI_cpu(%eax), %eax
27755 - movl __per_cpu_offset(,%eax,4), %eax
27756 - mov xen_vcpu(%eax), %eax
27757 + push %fs
27758 + mov $(__KERNEL_PERCPU), %eax
27759 + mov %eax, %fs
27760 + mov PER_CPU_VAR(xen_vcpu), %eax
27761 + pop %fs
27762 #else
27763 movl xen_vcpu, %eax
27764 #endif
27765 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
27766 index aaa7291..3f77960 100644
27767 --- a/arch/x86/xen/xen-head.S
27768 +++ b/arch/x86/xen/xen-head.S
27769 @@ -19,6 +19,17 @@ ENTRY(startup_xen)
27770 #ifdef CONFIG_X86_32
27771 mov %esi,xen_start_info
27772 mov $init_thread_union+THREAD_SIZE,%esp
27773 +#ifdef CONFIG_SMP
27774 + movl $cpu_gdt_table,%edi
27775 + movl $__per_cpu_load,%eax
27776 + movw %ax,__KERNEL_PERCPU + 2(%edi)
27777 + rorl $16,%eax
27778 + movb %al,__KERNEL_PERCPU + 4(%edi)
27779 + movb %ah,__KERNEL_PERCPU + 7(%edi)
27780 + movl $__per_cpu_end - 1,%eax
27781 + subl $__per_cpu_start,%eax
27782 + movw %ax,__KERNEL_PERCPU + 0(%edi)
27783 +#endif
27784 #else
27785 mov %rsi,xen_start_info
27786 mov $init_thread_union+THREAD_SIZE,%rsp
27787 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
27788 index 202d4c1..99b072a 100644
27789 --- a/arch/x86/xen/xen-ops.h
27790 +++ b/arch/x86/xen/xen-ops.h
27791 @@ -10,8 +10,6 @@
27792 extern const char xen_hypervisor_callback[];
27793 extern const char xen_failsafe_callback[];
27794
27795 -extern void *xen_initial_gdt;
27796 -
27797 struct trap_info;
27798 void xen_copy_trap_info(struct trap_info *traps);
27799
27800 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
27801 index 525bd3d..ef888b1 100644
27802 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
27803 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
27804 @@ -119,9 +119,9 @@
27805 ----------------------------------------------------------------------*/
27806
27807 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
27808 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
27809 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
27810 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
27811 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27812
27813 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
27814 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
27815 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
27816 index 2f33760..835e50a 100644
27817 --- a/arch/xtensa/variants/fsf/include/variant/core.h
27818 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
27819 @@ -11,6 +11,7 @@
27820 #ifndef _XTENSA_CORE_H
27821 #define _XTENSA_CORE_H
27822
27823 +#include <linux/const.h>
27824
27825 /****************************************************************************
27826 Parameters Useful for Any Code, USER or PRIVILEGED
27827 @@ -112,9 +113,9 @@
27828 ----------------------------------------------------------------------*/
27829
27830 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27831 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27832 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27833 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27834 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27835
27836 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
27837 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
27838 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
27839 index af00795..2bb8105 100644
27840 --- a/arch/xtensa/variants/s6000/include/variant/core.h
27841 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
27842 @@ -11,6 +11,7 @@
27843 #ifndef _XTENSA_CORE_CONFIGURATION_H
27844 #define _XTENSA_CORE_CONFIGURATION_H
27845
27846 +#include <linux/const.h>
27847
27848 /****************************************************************************
27849 Parameters Useful for Any Code, USER or PRIVILEGED
27850 @@ -118,9 +119,9 @@
27851 ----------------------------------------------------------------------*/
27852
27853 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27854 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27855 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27856 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27857 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27858
27859 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
27860 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
27861 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
27862 index 58916af..9cb880b 100644
27863 --- a/block/blk-iopoll.c
27864 +++ b/block/blk-iopoll.c
27865 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
27866 }
27867 EXPORT_SYMBOL(blk_iopoll_complete);
27868
27869 -static void blk_iopoll_softirq(struct softirq_action *h)
27870 +static void blk_iopoll_softirq(void)
27871 {
27872 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
27873 int rearm = 0, budget = blk_iopoll_budget;
27874 diff --git a/block/blk-map.c b/block/blk-map.c
27875 index 623e1cd..ca1e109 100644
27876 --- a/block/blk-map.c
27877 +++ b/block/blk-map.c
27878 @@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
27879 if (!len || !kbuf)
27880 return -EINVAL;
27881
27882 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
27883 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
27884 if (do_copy)
27885 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
27886 else
27887 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
27888 index 467c8de..4bddc6d 100644
27889 --- a/block/blk-softirq.c
27890 +++ b/block/blk-softirq.c
27891 @@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
27892 * Softirq action handler - move entries to local list and loop over them
27893 * while passing them to the queue registered handler.
27894 */
27895 -static void blk_done_softirq(struct softirq_action *h)
27896 +static void blk_done_softirq(void)
27897 {
27898 struct list_head *cpu_list, local_list;
27899
27900 diff --git a/block/bsg.c b/block/bsg.c
27901 index ff64ae3..593560c 100644
27902 --- a/block/bsg.c
27903 +++ b/block/bsg.c
27904 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
27905 struct sg_io_v4 *hdr, struct bsg_device *bd,
27906 fmode_t has_write_perm)
27907 {
27908 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27909 + unsigned char *cmdptr;
27910 +
27911 if (hdr->request_len > BLK_MAX_CDB) {
27912 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
27913 if (!rq->cmd)
27914 return -ENOMEM;
27915 - }
27916 + cmdptr = rq->cmd;
27917 + } else
27918 + cmdptr = tmpcmd;
27919
27920 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
27921 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
27922 hdr->request_len))
27923 return -EFAULT;
27924
27925 + if (cmdptr != rq->cmd)
27926 + memcpy(rq->cmd, cmdptr, hdr->request_len);
27927 +
27928 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
27929 if (blk_verify_command(rq->cmd, has_write_perm))
27930 return -EPERM;
27931 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
27932 index 7c668c8..db3521c 100644
27933 --- a/block/compat_ioctl.c
27934 +++ b/block/compat_ioctl.c
27935 @@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
27936 err |= __get_user(f->spec1, &uf->spec1);
27937 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
27938 err |= __get_user(name, &uf->name);
27939 - f->name = compat_ptr(name);
27940 + f->name = (void __force_kernel *)compat_ptr(name);
27941 if (err) {
27942 err = -EFAULT;
27943 goto out;
27944 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
27945 index 6296b40..417c00f 100644
27946 --- a/block/partitions/efi.c
27947 +++ b/block/partitions/efi.c
27948 @@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
27949 if (!gpt)
27950 return NULL;
27951
27952 + if (!le32_to_cpu(gpt->num_partition_entries))
27953 + return NULL;
27954 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
27955 + if (!pte)
27956 + return NULL;
27957 +
27958 count = le32_to_cpu(gpt->num_partition_entries) *
27959 le32_to_cpu(gpt->sizeof_partition_entry);
27960 - if (!count)
27961 - return NULL;
27962 - pte = kzalloc(count, GFP_KERNEL);
27963 - if (!pte)
27964 - return NULL;
27965 -
27966 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
27967 (u8 *) pte,
27968 count) < count) {
27969 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
27970 index 9a87daa..fb17486 100644
27971 --- a/block/scsi_ioctl.c
27972 +++ b/block/scsi_ioctl.c
27973 @@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
27974 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
27975 struct sg_io_hdr *hdr, fmode_t mode)
27976 {
27977 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
27978 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27979 + unsigned char *cmdptr;
27980 +
27981 + if (rq->cmd != rq->__cmd)
27982 + cmdptr = rq->cmd;
27983 + else
27984 + cmdptr = tmpcmd;
27985 +
27986 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
27987 return -EFAULT;
27988 +
27989 + if (cmdptr != rq->cmd)
27990 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
27991 +
27992 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
27993 return -EPERM;
27994
27995 @@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27996 int err;
27997 unsigned int in_len, out_len, bytes, opcode, cmdlen;
27998 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
27999 + unsigned char tmpcmd[sizeof(rq->__cmd)];
28000 + unsigned char *cmdptr;
28001
28002 if (!sic)
28003 return -EINVAL;
28004 @@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
28005 */
28006 err = -EFAULT;
28007 rq->cmd_len = cmdlen;
28008 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
28009 +
28010 + if (rq->cmd != rq->__cmd)
28011 + cmdptr = rq->cmd;
28012 + else
28013 + cmdptr = tmpcmd;
28014 +
28015 + if (copy_from_user(cmdptr, sic->data, cmdlen))
28016 goto error;
28017
28018 + if (rq->cmd != cmdptr)
28019 + memcpy(rq->cmd, cmdptr, cmdlen);
28020 +
28021 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
28022 goto error;
28023
28024 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
28025 index 7bdd61b..afec999 100644
28026 --- a/crypto/cryptd.c
28027 +++ b/crypto/cryptd.c
28028 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
28029
28030 struct cryptd_blkcipher_request_ctx {
28031 crypto_completion_t complete;
28032 -};
28033 +} __no_const;
28034
28035 struct cryptd_hash_ctx {
28036 struct crypto_shash *child;
28037 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
28038
28039 struct cryptd_aead_request_ctx {
28040 crypto_completion_t complete;
28041 -};
28042 +} __no_const;
28043
28044 static void cryptd_queue_worker(struct work_struct *work);
28045
28046 diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
28047 index e6defd8..c26a225 100644
28048 --- a/drivers/acpi/apei/cper.c
28049 +++ b/drivers/acpi/apei/cper.c
28050 @@ -38,12 +38,12 @@
28051 */
28052 u64 cper_next_record_id(void)
28053 {
28054 - static atomic64_t seq;
28055 + static atomic64_unchecked_t seq;
28056
28057 - if (!atomic64_read(&seq))
28058 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
28059 + if (!atomic64_read_unchecked(&seq))
28060 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
28061
28062 - return atomic64_inc_return(&seq);
28063 + return atomic64_inc_return_unchecked(&seq);
28064 }
28065 EXPORT_SYMBOL_GPL(cper_next_record_id);
28066
28067 diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
28068 index 7586544..636a2f0 100644
28069 --- a/drivers/acpi/ec_sys.c
28070 +++ b/drivers/acpi/ec_sys.c
28071 @@ -12,6 +12,7 @@
28072 #include <linux/acpi.h>
28073 #include <linux/debugfs.h>
28074 #include <linux/module.h>
28075 +#include <linux/uaccess.h>
28076 #include "internal.h"
28077
28078 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
28079 @@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
28080 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
28081 */
28082 unsigned int size = EC_SPACE_SIZE;
28083 - u8 *data = (u8 *) buf;
28084 + u8 data;
28085 loff_t init_off = *off;
28086 int err = 0;
28087
28088 @@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
28089 size = count;
28090
28091 while (size) {
28092 - err = ec_read(*off, &data[*off - init_off]);
28093 + err = ec_read(*off, &data);
28094 if (err)
28095 return err;
28096 + if (put_user(data, &buf[*off - init_off]))
28097 + return -EFAULT;
28098 *off += 1;
28099 size--;
28100 }
28101 @@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
28102
28103 unsigned int size = count;
28104 loff_t init_off = *off;
28105 - u8 *data = (u8 *) buf;
28106 int err = 0;
28107
28108 if (*off >= EC_SPACE_SIZE)
28109 @@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
28110 }
28111
28112 while (size) {
28113 - u8 byte_write = data[*off - init_off];
28114 + u8 byte_write;
28115 + if (get_user(byte_write, &buf[*off - init_off]))
28116 + return -EFAULT;
28117 err = ec_write(*off, byte_write);
28118 if (err)
28119 return err;
28120 diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
28121 index 251c7b62..000462d 100644
28122 --- a/drivers/acpi/proc.c
28123 +++ b/drivers/acpi/proc.c
28124 @@ -343,19 +343,13 @@ acpi_system_write_wakeup_device(struct file *file,
28125 size_t count, loff_t * ppos)
28126 {
28127 struct list_head *node, *next;
28128 - char strbuf[5];
28129 - char str[5] = "";
28130 - unsigned int len = count;
28131 + char strbuf[5] = {0};
28132
28133 - if (len > 4)
28134 - len = 4;
28135 - if (len < 0)
28136 + if (count > 4)
28137 + count = 4;
28138 + if (copy_from_user(strbuf, buffer, count))
28139 return -EFAULT;
28140 -
28141 - if (copy_from_user(strbuf, buffer, len))
28142 - return -EFAULT;
28143 - strbuf[len] = '\0';
28144 - sscanf(strbuf, "%s", str);
28145 + strbuf[count] = '\0';
28146
28147 mutex_lock(&acpi_device_lock);
28148 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
28149 @@ -364,7 +358,7 @@ acpi_system_write_wakeup_device(struct file *file,
28150 if (!dev->wakeup.flags.valid)
28151 continue;
28152
28153 - if (!strncmp(dev->pnp.bus_id, str, 4)) {
28154 + if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
28155 if (device_can_wakeup(&dev->dev)) {
28156 bool enable = !device_may_wakeup(&dev->dev);
28157 device_set_wakeup_enable(&dev->dev, enable);
28158 diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
28159 index bfc31cb..8213ce1 100644
28160 --- a/drivers/acpi/processor_driver.c
28161 +++ b/drivers/acpi/processor_driver.c
28162 @@ -551,7 +551,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
28163 return 0;
28164 #endif
28165
28166 - BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
28167 + BUG_ON(pr->id >= nr_cpu_ids);
28168
28169 /*
28170 * Buggy BIOS check
28171 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
28172 index 8e1039c..ea9cbd4 100644
28173 --- a/drivers/ata/libata-core.c
28174 +++ b/drivers/ata/libata-core.c
28175 @@ -4750,7 +4750,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
28176 struct ata_port *ap;
28177 unsigned int tag;
28178
28179 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
28180 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
28181 ap = qc->ap;
28182
28183 qc->flags = 0;
28184 @@ -4766,7 +4766,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
28185 struct ata_port *ap;
28186 struct ata_link *link;
28187
28188 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
28189 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
28190 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
28191 ap = qc->ap;
28192 link = qc->dev->link;
28193 @@ -5828,6 +5828,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
28194 return;
28195
28196 spin_lock(&lock);
28197 + pax_open_kernel();
28198
28199 for (cur = ops->inherits; cur; cur = cur->inherits) {
28200 void **inherit = (void **)cur;
28201 @@ -5841,8 +5842,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
28202 if (IS_ERR(*pp))
28203 *pp = NULL;
28204
28205 - ops->inherits = NULL;
28206 + *(struct ata_port_operations **)&ops->inherits = NULL;
28207
28208 + pax_close_kernel();
28209 spin_unlock(&lock);
28210 }
28211
28212 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
28213 index bfaa5cb..3ba1cc3 100644
28214 --- a/drivers/ata/pata_arasan_cf.c
28215 +++ b/drivers/ata/pata_arasan_cf.c
28216 @@ -854,7 +854,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
28217 /* Handle platform specific quirks */
28218 if (pdata->quirk) {
28219 if (pdata->quirk & CF_BROKEN_PIO) {
28220 - ap->ops->set_piomode = NULL;
28221 + pax_open_kernel();
28222 + *(void **)&ap->ops->set_piomode = NULL;
28223 + pax_close_kernel();
28224 ap->pio_mask = 0;
28225 }
28226 if (pdata->quirk & CF_BROKEN_MWDMA)
28227 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
28228 index f9b983a..887b9d8 100644
28229 --- a/drivers/atm/adummy.c
28230 +++ b/drivers/atm/adummy.c
28231 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
28232 vcc->pop(vcc, skb);
28233 else
28234 dev_kfree_skb_any(skb);
28235 - atomic_inc(&vcc->stats->tx);
28236 + atomic_inc_unchecked(&vcc->stats->tx);
28237
28238 return 0;
28239 }
28240 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
28241 index 89b30f3..7964211 100644
28242 --- a/drivers/atm/ambassador.c
28243 +++ b/drivers/atm/ambassador.c
28244 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
28245 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
28246
28247 // VC layer stats
28248 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28249 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28250
28251 // free the descriptor
28252 kfree (tx_descr);
28253 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
28254 dump_skb ("<<<", vc, skb);
28255
28256 // VC layer stats
28257 - atomic_inc(&atm_vcc->stats->rx);
28258 + atomic_inc_unchecked(&atm_vcc->stats->rx);
28259 __net_timestamp(skb);
28260 // end of our responsibility
28261 atm_vcc->push (atm_vcc, skb);
28262 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
28263 } else {
28264 PRINTK (KERN_INFO, "dropped over-size frame");
28265 // should we count this?
28266 - atomic_inc(&atm_vcc->stats->rx_drop);
28267 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
28268 }
28269
28270 } else {
28271 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
28272 }
28273
28274 if (check_area (skb->data, skb->len)) {
28275 - atomic_inc(&atm_vcc->stats->tx_err);
28276 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
28277 return -ENOMEM; // ?
28278 }
28279
28280 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
28281 index b22d71c..d6e1049 100644
28282 --- a/drivers/atm/atmtcp.c
28283 +++ b/drivers/atm/atmtcp.c
28284 @@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
28285 if (vcc->pop) vcc->pop(vcc,skb);
28286 else dev_kfree_skb(skb);
28287 if (dev_data) return 0;
28288 - atomic_inc(&vcc->stats->tx_err);
28289 + atomic_inc_unchecked(&vcc->stats->tx_err);
28290 return -ENOLINK;
28291 }
28292 size = skb->len+sizeof(struct atmtcp_hdr);
28293 @@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
28294 if (!new_skb) {
28295 if (vcc->pop) vcc->pop(vcc,skb);
28296 else dev_kfree_skb(skb);
28297 - atomic_inc(&vcc->stats->tx_err);
28298 + atomic_inc_unchecked(&vcc->stats->tx_err);
28299 return -ENOBUFS;
28300 }
28301 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
28302 @@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
28303 if (vcc->pop) vcc->pop(vcc,skb);
28304 else dev_kfree_skb(skb);
28305 out_vcc->push(out_vcc,new_skb);
28306 - atomic_inc(&vcc->stats->tx);
28307 - atomic_inc(&out_vcc->stats->rx);
28308 + atomic_inc_unchecked(&vcc->stats->tx);
28309 + atomic_inc_unchecked(&out_vcc->stats->rx);
28310 return 0;
28311 }
28312
28313 @@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
28314 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
28315 read_unlock(&vcc_sklist_lock);
28316 if (!out_vcc) {
28317 - atomic_inc(&vcc->stats->tx_err);
28318 + atomic_inc_unchecked(&vcc->stats->tx_err);
28319 goto done;
28320 }
28321 skb_pull(skb,sizeof(struct atmtcp_hdr));
28322 @@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
28323 __net_timestamp(new_skb);
28324 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
28325 out_vcc->push(out_vcc,new_skb);
28326 - atomic_inc(&vcc->stats->tx);
28327 - atomic_inc(&out_vcc->stats->rx);
28328 + atomic_inc_unchecked(&vcc->stats->tx);
28329 + atomic_inc_unchecked(&out_vcc->stats->rx);
28330 done:
28331 if (vcc->pop) vcc->pop(vcc,skb);
28332 else dev_kfree_skb(skb);
28333 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
28334 index 2059ee4..faf51c7 100644
28335 --- a/drivers/atm/eni.c
28336 +++ b/drivers/atm/eni.c
28337 @@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
28338 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
28339 vcc->dev->number);
28340 length = 0;
28341 - atomic_inc(&vcc->stats->rx_err);
28342 + atomic_inc_unchecked(&vcc->stats->rx_err);
28343 }
28344 else {
28345 length = ATM_CELL_SIZE-1; /* no HEC */
28346 @@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
28347 size);
28348 }
28349 eff = length = 0;
28350 - atomic_inc(&vcc->stats->rx_err);
28351 + atomic_inc_unchecked(&vcc->stats->rx_err);
28352 }
28353 else {
28354 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
28355 @@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
28356 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
28357 vcc->dev->number,vcc->vci,length,size << 2,descr);
28358 length = eff = 0;
28359 - atomic_inc(&vcc->stats->rx_err);
28360 + atomic_inc_unchecked(&vcc->stats->rx_err);
28361 }
28362 }
28363 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
28364 @@ -767,7 +767,7 @@ rx_dequeued++;
28365 vcc->push(vcc,skb);
28366 pushed++;
28367 }
28368 - atomic_inc(&vcc->stats->rx);
28369 + atomic_inc_unchecked(&vcc->stats->rx);
28370 }
28371 wake_up(&eni_dev->rx_wait);
28372 }
28373 @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
28374 PCI_DMA_TODEVICE);
28375 if (vcc->pop) vcc->pop(vcc,skb);
28376 else dev_kfree_skb_irq(skb);
28377 - atomic_inc(&vcc->stats->tx);
28378 + atomic_inc_unchecked(&vcc->stats->tx);
28379 wake_up(&eni_dev->tx_wait);
28380 dma_complete++;
28381 }
28382 @@ -1567,7 +1567,7 @@ tx_complete++;
28383 /*--------------------------------- entries ---------------------------------*/
28384
28385
28386 -static const char *media_name[] __devinitdata = {
28387 +static const char *media_name[] __devinitconst = {
28388 "MMF", "SMF", "MMF", "03?", /* 0- 3 */
28389 "UTP", "05?", "06?", "07?", /* 4- 7 */
28390 "TAXI","09?", "10?", "11?", /* 8-11 */
28391 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
28392 index 86fed1b..6dc4721 100644
28393 --- a/drivers/atm/firestream.c
28394 +++ b/drivers/atm/firestream.c
28395 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
28396 }
28397 }
28398
28399 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28400 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28401
28402 fs_dprintk (FS_DEBUG_TXMEM, "i");
28403 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
28404 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
28405 #endif
28406 skb_put (skb, qe->p1 & 0xffff);
28407 ATM_SKB(skb)->vcc = atm_vcc;
28408 - atomic_inc(&atm_vcc->stats->rx);
28409 + atomic_inc_unchecked(&atm_vcc->stats->rx);
28410 __net_timestamp(skb);
28411 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
28412 atm_vcc->push (atm_vcc, skb);
28413 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
28414 kfree (pe);
28415 }
28416 if (atm_vcc)
28417 - atomic_inc(&atm_vcc->stats->rx_drop);
28418 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
28419 break;
28420 case 0x1f: /* Reassembly abort: no buffers. */
28421 /* Silently increment error counter. */
28422 if (atm_vcc)
28423 - atomic_inc(&atm_vcc->stats->rx_drop);
28424 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
28425 break;
28426 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
28427 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
28428 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
28429 index 361f5ae..7fc552d 100644
28430 --- a/drivers/atm/fore200e.c
28431 +++ b/drivers/atm/fore200e.c
28432 @@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
28433 #endif
28434 /* check error condition */
28435 if (*entry->status & STATUS_ERROR)
28436 - atomic_inc(&vcc->stats->tx_err);
28437 + atomic_inc_unchecked(&vcc->stats->tx_err);
28438 else
28439 - atomic_inc(&vcc->stats->tx);
28440 + atomic_inc_unchecked(&vcc->stats->tx);
28441 }
28442 }
28443
28444 @@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
28445 if (skb == NULL) {
28446 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
28447
28448 - atomic_inc(&vcc->stats->rx_drop);
28449 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28450 return -ENOMEM;
28451 }
28452
28453 @@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
28454
28455 dev_kfree_skb_any(skb);
28456
28457 - atomic_inc(&vcc->stats->rx_drop);
28458 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28459 return -ENOMEM;
28460 }
28461
28462 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
28463
28464 vcc->push(vcc, skb);
28465 - atomic_inc(&vcc->stats->rx);
28466 + atomic_inc_unchecked(&vcc->stats->rx);
28467
28468 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
28469
28470 @@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
28471 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
28472 fore200e->atm_dev->number,
28473 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
28474 - atomic_inc(&vcc->stats->rx_err);
28475 + atomic_inc_unchecked(&vcc->stats->rx_err);
28476 }
28477 }
28478
28479 @@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
28480 goto retry_here;
28481 }
28482
28483 - atomic_inc(&vcc->stats->tx_err);
28484 + atomic_inc_unchecked(&vcc->stats->tx_err);
28485
28486 fore200e->tx_sat++;
28487 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
28488 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
28489 index b182c2f..1c6fa8a 100644
28490 --- a/drivers/atm/he.c
28491 +++ b/drivers/atm/he.c
28492 @@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28493
28494 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
28495 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
28496 - atomic_inc(&vcc->stats->rx_drop);
28497 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28498 goto return_host_buffers;
28499 }
28500
28501 @@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28502 RBRQ_LEN_ERR(he_dev->rbrq_head)
28503 ? "LEN_ERR" : "",
28504 vcc->vpi, vcc->vci);
28505 - atomic_inc(&vcc->stats->rx_err);
28506 + atomic_inc_unchecked(&vcc->stats->rx_err);
28507 goto return_host_buffers;
28508 }
28509
28510 @@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28511 vcc->push(vcc, skb);
28512 spin_lock(&he_dev->global_lock);
28513
28514 - atomic_inc(&vcc->stats->rx);
28515 + atomic_inc_unchecked(&vcc->stats->rx);
28516
28517 return_host_buffers:
28518 ++pdus_assembled;
28519 @@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
28520 tpd->vcc->pop(tpd->vcc, tpd->skb);
28521 else
28522 dev_kfree_skb_any(tpd->skb);
28523 - atomic_inc(&tpd->vcc->stats->tx_err);
28524 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
28525 }
28526 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
28527 return;
28528 @@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28529 vcc->pop(vcc, skb);
28530 else
28531 dev_kfree_skb_any(skb);
28532 - atomic_inc(&vcc->stats->tx_err);
28533 + atomic_inc_unchecked(&vcc->stats->tx_err);
28534 return -EINVAL;
28535 }
28536
28537 @@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28538 vcc->pop(vcc, skb);
28539 else
28540 dev_kfree_skb_any(skb);
28541 - atomic_inc(&vcc->stats->tx_err);
28542 + atomic_inc_unchecked(&vcc->stats->tx_err);
28543 return -EINVAL;
28544 }
28545 #endif
28546 @@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28547 vcc->pop(vcc, skb);
28548 else
28549 dev_kfree_skb_any(skb);
28550 - atomic_inc(&vcc->stats->tx_err);
28551 + atomic_inc_unchecked(&vcc->stats->tx_err);
28552 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28553 return -ENOMEM;
28554 }
28555 @@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28556 vcc->pop(vcc, skb);
28557 else
28558 dev_kfree_skb_any(skb);
28559 - atomic_inc(&vcc->stats->tx_err);
28560 + atomic_inc_unchecked(&vcc->stats->tx_err);
28561 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28562 return -ENOMEM;
28563 }
28564 @@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28565 __enqueue_tpd(he_dev, tpd, cid);
28566 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28567
28568 - atomic_inc(&vcc->stats->tx);
28569 + atomic_inc_unchecked(&vcc->stats->tx);
28570
28571 return 0;
28572 }
28573 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
28574 index 7d01c2a..4e3ac01 100644
28575 --- a/drivers/atm/horizon.c
28576 +++ b/drivers/atm/horizon.c
28577 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
28578 {
28579 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
28580 // VC layer stats
28581 - atomic_inc(&vcc->stats->rx);
28582 + atomic_inc_unchecked(&vcc->stats->rx);
28583 __net_timestamp(skb);
28584 // end of our responsibility
28585 vcc->push (vcc, skb);
28586 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
28587 dev->tx_iovec = NULL;
28588
28589 // VC layer stats
28590 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28591 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28592
28593 // free the skb
28594 hrz_kfree_skb (skb);
28595 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
28596 index 8974bd2..b856f85 100644
28597 --- a/drivers/atm/idt77252.c
28598 +++ b/drivers/atm/idt77252.c
28599 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
28600 else
28601 dev_kfree_skb(skb);
28602
28603 - atomic_inc(&vcc->stats->tx);
28604 + atomic_inc_unchecked(&vcc->stats->tx);
28605 }
28606
28607 atomic_dec(&scq->used);
28608 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28609 if ((sb = dev_alloc_skb(64)) == NULL) {
28610 printk("%s: Can't allocate buffers for aal0.\n",
28611 card->name);
28612 - atomic_add(i, &vcc->stats->rx_drop);
28613 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
28614 break;
28615 }
28616 if (!atm_charge(vcc, sb->truesize)) {
28617 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
28618 card->name);
28619 - atomic_add(i - 1, &vcc->stats->rx_drop);
28620 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
28621 dev_kfree_skb(sb);
28622 break;
28623 }
28624 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28625 ATM_SKB(sb)->vcc = vcc;
28626 __net_timestamp(sb);
28627 vcc->push(vcc, sb);
28628 - atomic_inc(&vcc->stats->rx);
28629 + atomic_inc_unchecked(&vcc->stats->rx);
28630
28631 cell += ATM_CELL_PAYLOAD;
28632 }
28633 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28634 "(CDC: %08x)\n",
28635 card->name, len, rpp->len, readl(SAR_REG_CDC));
28636 recycle_rx_pool_skb(card, rpp);
28637 - atomic_inc(&vcc->stats->rx_err);
28638 + atomic_inc_unchecked(&vcc->stats->rx_err);
28639 return;
28640 }
28641 if (stat & SAR_RSQE_CRC) {
28642 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
28643 recycle_rx_pool_skb(card, rpp);
28644 - atomic_inc(&vcc->stats->rx_err);
28645 + atomic_inc_unchecked(&vcc->stats->rx_err);
28646 return;
28647 }
28648 if (skb_queue_len(&rpp->queue) > 1) {
28649 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28650 RXPRINTK("%s: Can't alloc RX skb.\n",
28651 card->name);
28652 recycle_rx_pool_skb(card, rpp);
28653 - atomic_inc(&vcc->stats->rx_err);
28654 + atomic_inc_unchecked(&vcc->stats->rx_err);
28655 return;
28656 }
28657 if (!atm_charge(vcc, skb->truesize)) {
28658 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28659 __net_timestamp(skb);
28660
28661 vcc->push(vcc, skb);
28662 - atomic_inc(&vcc->stats->rx);
28663 + atomic_inc_unchecked(&vcc->stats->rx);
28664
28665 return;
28666 }
28667 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28668 __net_timestamp(skb);
28669
28670 vcc->push(vcc, skb);
28671 - atomic_inc(&vcc->stats->rx);
28672 + atomic_inc_unchecked(&vcc->stats->rx);
28673
28674 if (skb->truesize > SAR_FB_SIZE_3)
28675 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
28676 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
28677 if (vcc->qos.aal != ATM_AAL0) {
28678 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
28679 card->name, vpi, vci);
28680 - atomic_inc(&vcc->stats->rx_drop);
28681 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28682 goto drop;
28683 }
28684
28685 if ((sb = dev_alloc_skb(64)) == NULL) {
28686 printk("%s: Can't allocate buffers for AAL0.\n",
28687 card->name);
28688 - atomic_inc(&vcc->stats->rx_err);
28689 + atomic_inc_unchecked(&vcc->stats->rx_err);
28690 goto drop;
28691 }
28692
28693 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
28694 ATM_SKB(sb)->vcc = vcc;
28695 __net_timestamp(sb);
28696 vcc->push(vcc, sb);
28697 - atomic_inc(&vcc->stats->rx);
28698 + atomic_inc_unchecked(&vcc->stats->rx);
28699
28700 drop:
28701 skb_pull(queue, 64);
28702 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28703
28704 if (vc == NULL) {
28705 printk("%s: NULL connection in send().\n", card->name);
28706 - atomic_inc(&vcc->stats->tx_err);
28707 + atomic_inc_unchecked(&vcc->stats->tx_err);
28708 dev_kfree_skb(skb);
28709 return -EINVAL;
28710 }
28711 if (!test_bit(VCF_TX, &vc->flags)) {
28712 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
28713 - atomic_inc(&vcc->stats->tx_err);
28714 + atomic_inc_unchecked(&vcc->stats->tx_err);
28715 dev_kfree_skb(skb);
28716 return -EINVAL;
28717 }
28718 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28719 break;
28720 default:
28721 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
28722 - atomic_inc(&vcc->stats->tx_err);
28723 + atomic_inc_unchecked(&vcc->stats->tx_err);
28724 dev_kfree_skb(skb);
28725 return -EINVAL;
28726 }
28727
28728 if (skb_shinfo(skb)->nr_frags != 0) {
28729 printk("%s: No scatter-gather yet.\n", card->name);
28730 - atomic_inc(&vcc->stats->tx_err);
28731 + atomic_inc_unchecked(&vcc->stats->tx_err);
28732 dev_kfree_skb(skb);
28733 return -EINVAL;
28734 }
28735 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28736
28737 err = queue_skb(card, vc, skb, oam);
28738 if (err) {
28739 - atomic_inc(&vcc->stats->tx_err);
28740 + atomic_inc_unchecked(&vcc->stats->tx_err);
28741 dev_kfree_skb(skb);
28742 return err;
28743 }
28744 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
28745 skb = dev_alloc_skb(64);
28746 if (!skb) {
28747 printk("%s: Out of memory in send_oam().\n", card->name);
28748 - atomic_inc(&vcc->stats->tx_err);
28749 + atomic_inc_unchecked(&vcc->stats->tx_err);
28750 return -ENOMEM;
28751 }
28752 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
28753 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
28754 index 96cce6d..62c3ec5 100644
28755 --- a/drivers/atm/iphase.c
28756 +++ b/drivers/atm/iphase.c
28757 @@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
28758 status = (u_short) (buf_desc_ptr->desc_mode);
28759 if (status & (RX_CER | RX_PTE | RX_OFL))
28760 {
28761 - atomic_inc(&vcc->stats->rx_err);
28762 + atomic_inc_unchecked(&vcc->stats->rx_err);
28763 IF_ERR(printk("IA: bad packet, dropping it");)
28764 if (status & RX_CER) {
28765 IF_ERR(printk(" cause: packet CRC error\n");)
28766 @@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
28767 len = dma_addr - buf_addr;
28768 if (len > iadev->rx_buf_sz) {
28769 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
28770 - atomic_inc(&vcc->stats->rx_err);
28771 + atomic_inc_unchecked(&vcc->stats->rx_err);
28772 goto out_free_desc;
28773 }
28774
28775 @@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28776 ia_vcc = INPH_IA_VCC(vcc);
28777 if (ia_vcc == NULL)
28778 {
28779 - atomic_inc(&vcc->stats->rx_err);
28780 + atomic_inc_unchecked(&vcc->stats->rx_err);
28781 atm_return(vcc, skb->truesize);
28782 dev_kfree_skb_any(skb);
28783 goto INCR_DLE;
28784 @@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28785 if ((length > iadev->rx_buf_sz) || (length >
28786 (skb->len - sizeof(struct cpcs_trailer))))
28787 {
28788 - atomic_inc(&vcc->stats->rx_err);
28789 + atomic_inc_unchecked(&vcc->stats->rx_err);
28790 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
28791 length, skb->len);)
28792 atm_return(vcc, skb->truesize);
28793 @@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28794
28795 IF_RX(printk("rx_dle_intr: skb push");)
28796 vcc->push(vcc,skb);
28797 - atomic_inc(&vcc->stats->rx);
28798 + atomic_inc_unchecked(&vcc->stats->rx);
28799 iadev->rx_pkt_cnt++;
28800 }
28801 INCR_DLE:
28802 @@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
28803 {
28804 struct k_sonet_stats *stats;
28805 stats = &PRIV(_ia_dev[board])->sonet_stats;
28806 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
28807 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
28808 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
28809 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
28810 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
28811 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
28812 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
28813 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
28814 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
28815 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
28816 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
28817 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
28818 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
28819 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
28820 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
28821 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
28822 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
28823 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
28824 }
28825 ia_cmds.status = 0;
28826 break;
28827 @@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28828 if ((desc == 0) || (desc > iadev->num_tx_desc))
28829 {
28830 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
28831 - atomic_inc(&vcc->stats->tx);
28832 + atomic_inc_unchecked(&vcc->stats->tx);
28833 if (vcc->pop)
28834 vcc->pop(vcc, skb);
28835 else
28836 @@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28837 ATM_DESC(skb) = vcc->vci;
28838 skb_queue_tail(&iadev->tx_dma_q, skb);
28839
28840 - atomic_inc(&vcc->stats->tx);
28841 + atomic_inc_unchecked(&vcc->stats->tx);
28842 iadev->tx_pkt_cnt++;
28843 /* Increment transaction counter */
28844 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
28845
28846 #if 0
28847 /* add flow control logic */
28848 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
28849 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
28850 if (iavcc->vc_desc_cnt > 10) {
28851 vcc->tx_quota = vcc->tx_quota * 3 / 4;
28852 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
28853 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
28854 index 68c7588..7036683 100644
28855 --- a/drivers/atm/lanai.c
28856 +++ b/drivers/atm/lanai.c
28857 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
28858 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
28859 lanai_endtx(lanai, lvcc);
28860 lanai_free_skb(lvcc->tx.atmvcc, skb);
28861 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
28862 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
28863 }
28864
28865 /* Try to fill the buffer - don't call unless there is backlog */
28866 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
28867 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
28868 __net_timestamp(skb);
28869 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
28870 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
28871 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
28872 out:
28873 lvcc->rx.buf.ptr = end;
28874 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
28875 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28876 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
28877 "vcc %d\n", lanai->number, (unsigned int) s, vci);
28878 lanai->stats.service_rxnotaal5++;
28879 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28880 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28881 return 0;
28882 }
28883 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
28884 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28885 int bytes;
28886 read_unlock(&vcc_sklist_lock);
28887 DPRINTK("got trashed rx pdu on vci %d\n", vci);
28888 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28889 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28890 lvcc->stats.x.aal5.service_trash++;
28891 bytes = (SERVICE_GET_END(s) * 16) -
28892 (((unsigned long) lvcc->rx.buf.ptr) -
28893 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28894 }
28895 if (s & SERVICE_STREAM) {
28896 read_unlock(&vcc_sklist_lock);
28897 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28898 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28899 lvcc->stats.x.aal5.service_stream++;
28900 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
28901 "PDU on VCI %d!\n", lanai->number, vci);
28902 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28903 return 0;
28904 }
28905 DPRINTK("got rx crc error on vci %d\n", vci);
28906 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28907 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28908 lvcc->stats.x.aal5.service_rxcrc++;
28909 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
28910 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
28911 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
28912 index 1c70c45..300718d 100644
28913 --- a/drivers/atm/nicstar.c
28914 +++ b/drivers/atm/nicstar.c
28915 @@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28916 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
28917 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
28918 card->index);
28919 - atomic_inc(&vcc->stats->tx_err);
28920 + atomic_inc_unchecked(&vcc->stats->tx_err);
28921 dev_kfree_skb_any(skb);
28922 return -EINVAL;
28923 }
28924 @@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28925 if (!vc->tx) {
28926 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
28927 card->index);
28928 - atomic_inc(&vcc->stats->tx_err);
28929 + atomic_inc_unchecked(&vcc->stats->tx_err);
28930 dev_kfree_skb_any(skb);
28931 return -EINVAL;
28932 }
28933 @@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28934 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
28935 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
28936 card->index);
28937 - atomic_inc(&vcc->stats->tx_err);
28938 + atomic_inc_unchecked(&vcc->stats->tx_err);
28939 dev_kfree_skb_any(skb);
28940 return -EINVAL;
28941 }
28942
28943 if (skb_shinfo(skb)->nr_frags != 0) {
28944 printk("nicstar%d: No scatter-gather yet.\n", card->index);
28945 - atomic_inc(&vcc->stats->tx_err);
28946 + atomic_inc_unchecked(&vcc->stats->tx_err);
28947 dev_kfree_skb_any(skb);
28948 return -EINVAL;
28949 }
28950 @@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28951 }
28952
28953 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
28954 - atomic_inc(&vcc->stats->tx_err);
28955 + atomic_inc_unchecked(&vcc->stats->tx_err);
28956 dev_kfree_skb_any(skb);
28957 return -EIO;
28958 }
28959 - atomic_inc(&vcc->stats->tx);
28960 + atomic_inc_unchecked(&vcc->stats->tx);
28961
28962 return 0;
28963 }
28964 @@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28965 printk
28966 ("nicstar%d: Can't allocate buffers for aal0.\n",
28967 card->index);
28968 - atomic_add(i, &vcc->stats->rx_drop);
28969 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
28970 break;
28971 }
28972 if (!atm_charge(vcc, sb->truesize)) {
28973 RXPRINTK
28974 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
28975 card->index);
28976 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28977 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28978 dev_kfree_skb_any(sb);
28979 break;
28980 }
28981 @@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28982 ATM_SKB(sb)->vcc = vcc;
28983 __net_timestamp(sb);
28984 vcc->push(vcc, sb);
28985 - atomic_inc(&vcc->stats->rx);
28986 + atomic_inc_unchecked(&vcc->stats->rx);
28987 cell += ATM_CELL_PAYLOAD;
28988 }
28989
28990 @@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28991 if (iovb == NULL) {
28992 printk("nicstar%d: Out of iovec buffers.\n",
28993 card->index);
28994 - atomic_inc(&vcc->stats->rx_drop);
28995 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28996 recycle_rx_buf(card, skb);
28997 return;
28998 }
28999 @@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29000 small or large buffer itself. */
29001 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
29002 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
29003 - atomic_inc(&vcc->stats->rx_err);
29004 + atomic_inc_unchecked(&vcc->stats->rx_err);
29005 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
29006 NS_MAX_IOVECS);
29007 NS_PRV_IOVCNT(iovb) = 0;
29008 @@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29009 ("nicstar%d: Expected a small buffer, and this is not one.\n",
29010 card->index);
29011 which_list(card, skb);
29012 - atomic_inc(&vcc->stats->rx_err);
29013 + atomic_inc_unchecked(&vcc->stats->rx_err);
29014 recycle_rx_buf(card, skb);
29015 vc->rx_iov = NULL;
29016 recycle_iov_buf(card, iovb);
29017 @@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29018 ("nicstar%d: Expected a large buffer, and this is not one.\n",
29019 card->index);
29020 which_list(card, skb);
29021 - atomic_inc(&vcc->stats->rx_err);
29022 + atomic_inc_unchecked(&vcc->stats->rx_err);
29023 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
29024 NS_PRV_IOVCNT(iovb));
29025 vc->rx_iov = NULL;
29026 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29027 printk(" - PDU size mismatch.\n");
29028 else
29029 printk(".\n");
29030 - atomic_inc(&vcc->stats->rx_err);
29031 + atomic_inc_unchecked(&vcc->stats->rx_err);
29032 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
29033 NS_PRV_IOVCNT(iovb));
29034 vc->rx_iov = NULL;
29035 @@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29036 /* skb points to a small buffer */
29037 if (!atm_charge(vcc, skb->truesize)) {
29038 push_rxbufs(card, skb);
29039 - atomic_inc(&vcc->stats->rx_drop);
29040 + atomic_inc_unchecked(&vcc->stats->rx_drop);
29041 } else {
29042 skb_put(skb, len);
29043 dequeue_sm_buf(card, skb);
29044 @@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29045 ATM_SKB(skb)->vcc = vcc;
29046 __net_timestamp(skb);
29047 vcc->push(vcc, skb);
29048 - atomic_inc(&vcc->stats->rx);
29049 + atomic_inc_unchecked(&vcc->stats->rx);
29050 }
29051 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
29052 struct sk_buff *sb;
29053 @@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29054 if (len <= NS_SMBUFSIZE) {
29055 if (!atm_charge(vcc, sb->truesize)) {
29056 push_rxbufs(card, sb);
29057 - atomic_inc(&vcc->stats->rx_drop);
29058 + atomic_inc_unchecked(&vcc->stats->rx_drop);
29059 } else {
29060 skb_put(sb, len);
29061 dequeue_sm_buf(card, sb);
29062 @@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29063 ATM_SKB(sb)->vcc = vcc;
29064 __net_timestamp(sb);
29065 vcc->push(vcc, sb);
29066 - atomic_inc(&vcc->stats->rx);
29067 + atomic_inc_unchecked(&vcc->stats->rx);
29068 }
29069
29070 push_rxbufs(card, skb);
29071 @@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29072
29073 if (!atm_charge(vcc, skb->truesize)) {
29074 push_rxbufs(card, skb);
29075 - atomic_inc(&vcc->stats->rx_drop);
29076 + atomic_inc_unchecked(&vcc->stats->rx_drop);
29077 } else {
29078 dequeue_lg_buf(card, skb);
29079 #ifdef NS_USE_DESTRUCTORS
29080 @@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29081 ATM_SKB(skb)->vcc = vcc;
29082 __net_timestamp(skb);
29083 vcc->push(vcc, skb);
29084 - atomic_inc(&vcc->stats->rx);
29085 + atomic_inc_unchecked(&vcc->stats->rx);
29086 }
29087
29088 push_rxbufs(card, sb);
29089 @@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29090 printk
29091 ("nicstar%d: Out of huge buffers.\n",
29092 card->index);
29093 - atomic_inc(&vcc->stats->rx_drop);
29094 + atomic_inc_unchecked(&vcc->stats->rx_drop);
29095 recycle_iovec_rx_bufs(card,
29096 (struct iovec *)
29097 iovb->data,
29098 @@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29099 card->hbpool.count++;
29100 } else
29101 dev_kfree_skb_any(hb);
29102 - atomic_inc(&vcc->stats->rx_drop);
29103 + atomic_inc_unchecked(&vcc->stats->rx_drop);
29104 } else {
29105 /* Copy the small buffer to the huge buffer */
29106 sb = (struct sk_buff *)iov->iov_base;
29107 @@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29108 #endif /* NS_USE_DESTRUCTORS */
29109 __net_timestamp(hb);
29110 vcc->push(vcc, hb);
29111 - atomic_inc(&vcc->stats->rx);
29112 + atomic_inc_unchecked(&vcc->stats->rx);
29113 }
29114 }
29115
29116 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
29117 index 9851093..adb2b1e 100644
29118 --- a/drivers/atm/solos-pci.c
29119 +++ b/drivers/atm/solos-pci.c
29120 @@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
29121 }
29122 atm_charge(vcc, skb->truesize);
29123 vcc->push(vcc, skb);
29124 - atomic_inc(&vcc->stats->rx);
29125 + atomic_inc_unchecked(&vcc->stats->rx);
29126 break;
29127
29128 case PKT_STATUS:
29129 @@ -1009,7 +1009,7 @@ static uint32_t fpga_tx(struct solos_card *card)
29130 vcc = SKB_CB(oldskb)->vcc;
29131
29132 if (vcc) {
29133 - atomic_inc(&vcc->stats->tx);
29134 + atomic_inc_unchecked(&vcc->stats->tx);
29135 solos_pop(vcc, oldskb);
29136 } else
29137 dev_kfree_skb_irq(oldskb);
29138 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
29139 index 0215934..ce9f5b1 100644
29140 --- a/drivers/atm/suni.c
29141 +++ b/drivers/atm/suni.c
29142 @@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
29143
29144
29145 #define ADD_LIMITED(s,v) \
29146 - atomic_add((v),&stats->s); \
29147 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
29148 + atomic_add_unchecked((v),&stats->s); \
29149 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
29150
29151
29152 static void suni_hz(unsigned long from_timer)
29153 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
29154 index 5120a96..e2572bd 100644
29155 --- a/drivers/atm/uPD98402.c
29156 +++ b/drivers/atm/uPD98402.c
29157 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
29158 struct sonet_stats tmp;
29159 int error = 0;
29160
29161 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
29162 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
29163 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
29164 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
29165 if (zero && !error) {
29166 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
29167
29168
29169 #define ADD_LIMITED(s,v) \
29170 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
29171 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
29172 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
29173 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
29174 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
29175 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
29176
29177
29178 static void stat_event(struct atm_dev *dev)
29179 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
29180 if (reason & uPD98402_INT_PFM) stat_event(dev);
29181 if (reason & uPD98402_INT_PCO) {
29182 (void) GET(PCOCR); /* clear interrupt cause */
29183 - atomic_add(GET(HECCT),
29184 + atomic_add_unchecked(GET(HECCT),
29185 &PRIV(dev)->sonet_stats.uncorr_hcs);
29186 }
29187 if ((reason & uPD98402_INT_RFO) &&
29188 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
29189 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
29190 uPD98402_INT_LOS),PIMR); /* enable them */
29191 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
29192 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
29193 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
29194 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
29195 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
29196 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
29197 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
29198 return 0;
29199 }
29200
29201 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
29202 index abe4e20..83c4727 100644
29203 --- a/drivers/atm/zatm.c
29204 +++ b/drivers/atm/zatm.c
29205 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
29206 }
29207 if (!size) {
29208 dev_kfree_skb_irq(skb);
29209 - if (vcc) atomic_inc(&vcc->stats->rx_err);
29210 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
29211 continue;
29212 }
29213 if (!atm_charge(vcc,skb->truesize)) {
29214 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
29215 skb->len = size;
29216 ATM_SKB(skb)->vcc = vcc;
29217 vcc->push(vcc,skb);
29218 - atomic_inc(&vcc->stats->rx);
29219 + atomic_inc_unchecked(&vcc->stats->rx);
29220 }
29221 zout(pos & 0xffff,MTA(mbx));
29222 #if 0 /* probably a stupid idea */
29223 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
29224 skb_queue_head(&zatm_vcc->backlog,skb);
29225 break;
29226 }
29227 - atomic_inc(&vcc->stats->tx);
29228 + atomic_inc_unchecked(&vcc->stats->tx);
29229 wake_up(&zatm_vcc->tx_wait);
29230 }
29231
29232 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
29233 index deb4a45..211eff2 100644
29234 --- a/drivers/base/devtmpfs.c
29235 +++ b/drivers/base/devtmpfs.c
29236 @@ -347,7 +347,7 @@ int devtmpfs_mount(const char *mntdir)
29237 if (!thread)
29238 return 0;
29239
29240 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
29241 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
29242 if (err)
29243 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
29244 else
29245 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
29246 index cbb463b..babe2cf 100644
29247 --- a/drivers/base/power/wakeup.c
29248 +++ b/drivers/base/power/wakeup.c
29249 @@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
29250 * They need to be modified together atomically, so it's better to use one
29251 * atomic variable to hold them both.
29252 */
29253 -static atomic_t combined_event_count = ATOMIC_INIT(0);
29254 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
29255
29256 #define IN_PROGRESS_BITS (sizeof(int) * 4)
29257 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
29258
29259 static void split_counters(unsigned int *cnt, unsigned int *inpr)
29260 {
29261 - unsigned int comb = atomic_read(&combined_event_count);
29262 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
29263
29264 *cnt = (comb >> IN_PROGRESS_BITS);
29265 *inpr = comb & MAX_IN_PROGRESS;
29266 @@ -385,7 +385,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
29267 ws->start_prevent_time = ws->last_time;
29268
29269 /* Increment the counter of events in progress. */
29270 - cec = atomic_inc_return(&combined_event_count);
29271 + cec = atomic_inc_return_unchecked(&combined_event_count);
29272
29273 trace_wakeup_source_activate(ws->name, cec);
29274 }
29275 @@ -511,7 +511,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
29276 * Increment the counter of registered wakeup events and decrement the
29277 * couter of wakeup events in progress simultaneously.
29278 */
29279 - cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
29280 + cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
29281 trace_wakeup_source_deactivate(ws->name, cec);
29282
29283 split_counters(&cnt, &inpr);
29284 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
29285 index b0f553b..77b928b 100644
29286 --- a/drivers/block/cciss.c
29287 +++ b/drivers/block/cciss.c
29288 @@ -1198,6 +1198,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
29289 int err;
29290 u32 cp;
29291
29292 + memset(&arg64, 0, sizeof(arg64));
29293 +
29294 err = 0;
29295 err |=
29296 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
29297 @@ -3007,7 +3009,7 @@ static void start_io(ctlr_info_t *h)
29298 while (!list_empty(&h->reqQ)) {
29299 c = list_entry(h->reqQ.next, CommandList_struct, list);
29300 /* can't do anything if fifo is full */
29301 - if ((h->access.fifo_full(h))) {
29302 + if ((h->access->fifo_full(h))) {
29303 dev_warn(&h->pdev->dev, "fifo full\n");
29304 break;
29305 }
29306 @@ -3017,7 +3019,7 @@ static void start_io(ctlr_info_t *h)
29307 h->Qdepth--;
29308
29309 /* Tell the controller execute command */
29310 - h->access.submit_command(h, c);
29311 + h->access->submit_command(h, c);
29312
29313 /* Put job onto the completed Q */
29314 addQ(&h->cmpQ, c);
29315 @@ -3443,17 +3445,17 @@ startio:
29316
29317 static inline unsigned long get_next_completion(ctlr_info_t *h)
29318 {
29319 - return h->access.command_completed(h);
29320 + return h->access->command_completed(h);
29321 }
29322
29323 static inline int interrupt_pending(ctlr_info_t *h)
29324 {
29325 - return h->access.intr_pending(h);
29326 + return h->access->intr_pending(h);
29327 }
29328
29329 static inline long interrupt_not_for_us(ctlr_info_t *h)
29330 {
29331 - return ((h->access.intr_pending(h) == 0) ||
29332 + return ((h->access->intr_pending(h) == 0) ||
29333 (h->interrupts_enabled == 0));
29334 }
29335
29336 @@ -3486,7 +3488,7 @@ static inline u32 next_command(ctlr_info_t *h)
29337 u32 a;
29338
29339 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
29340 - return h->access.command_completed(h);
29341 + return h->access->command_completed(h);
29342
29343 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
29344 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
29345 @@ -4044,7 +4046,7 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
29346 trans_support & CFGTBL_Trans_use_short_tags);
29347
29348 /* Change the access methods to the performant access methods */
29349 - h->access = SA5_performant_access;
29350 + h->access = &SA5_performant_access;
29351 h->transMethod = CFGTBL_Trans_Performant;
29352
29353 return;
29354 @@ -4316,7 +4318,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
29355 if (prod_index < 0)
29356 return -ENODEV;
29357 h->product_name = products[prod_index].product_name;
29358 - h->access = *(products[prod_index].access);
29359 + h->access = products[prod_index].access;
29360
29361 if (cciss_board_disabled(h)) {
29362 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
29363 @@ -5041,7 +5043,7 @@ reinit_after_soft_reset:
29364 }
29365
29366 /* make sure the board interrupts are off */
29367 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29368 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29369 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
29370 if (rc)
29371 goto clean2;
29372 @@ -5093,7 +5095,7 @@ reinit_after_soft_reset:
29373 * fake ones to scoop up any residual completions.
29374 */
29375 spin_lock_irqsave(&h->lock, flags);
29376 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29377 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29378 spin_unlock_irqrestore(&h->lock, flags);
29379 free_irq(h->intr[h->intr_mode], h);
29380 rc = cciss_request_irq(h, cciss_msix_discard_completions,
29381 @@ -5113,9 +5115,9 @@ reinit_after_soft_reset:
29382 dev_info(&h->pdev->dev, "Board READY.\n");
29383 dev_info(&h->pdev->dev,
29384 "Waiting for stale completions to drain.\n");
29385 - h->access.set_intr_mask(h, CCISS_INTR_ON);
29386 + h->access->set_intr_mask(h, CCISS_INTR_ON);
29387 msleep(10000);
29388 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29389 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29390
29391 rc = controller_reset_failed(h->cfgtable);
29392 if (rc)
29393 @@ -5138,7 +5140,7 @@ reinit_after_soft_reset:
29394 cciss_scsi_setup(h);
29395
29396 /* Turn the interrupts on so we can service requests */
29397 - h->access.set_intr_mask(h, CCISS_INTR_ON);
29398 + h->access->set_intr_mask(h, CCISS_INTR_ON);
29399
29400 /* Get the firmware version */
29401 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
29402 @@ -5211,7 +5213,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
29403 kfree(flush_buf);
29404 if (return_code != IO_OK)
29405 dev_warn(&h->pdev->dev, "Error flushing cache\n");
29406 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29407 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29408 free_irq(h->intr[h->intr_mode], h);
29409 }
29410
29411 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
29412 index 7fda30e..eb5dfe0 100644
29413 --- a/drivers/block/cciss.h
29414 +++ b/drivers/block/cciss.h
29415 @@ -101,7 +101,7 @@ struct ctlr_info
29416 /* information about each logical volume */
29417 drive_info_struct *drv[CISS_MAX_LUN];
29418
29419 - struct access_method access;
29420 + struct access_method *access;
29421
29422 /* queue and queue Info */
29423 struct list_head reqQ;
29424 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
29425 index 9125bbe..eede5c8 100644
29426 --- a/drivers/block/cpqarray.c
29427 +++ b/drivers/block/cpqarray.c
29428 @@ -404,7 +404,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
29429 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
29430 goto Enomem4;
29431 }
29432 - hba[i]->access.set_intr_mask(hba[i], 0);
29433 + hba[i]->access->set_intr_mask(hba[i], 0);
29434 if (request_irq(hba[i]->intr, do_ida_intr,
29435 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
29436 {
29437 @@ -459,7 +459,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
29438 add_timer(&hba[i]->timer);
29439
29440 /* Enable IRQ now that spinlock and rate limit timer are set up */
29441 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
29442 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
29443
29444 for(j=0; j<NWD; j++) {
29445 struct gendisk *disk = ida_gendisk[i][j];
29446 @@ -694,7 +694,7 @@ DBGINFO(
29447 for(i=0; i<NR_PRODUCTS; i++) {
29448 if (board_id == products[i].board_id) {
29449 c->product_name = products[i].product_name;
29450 - c->access = *(products[i].access);
29451 + c->access = products[i].access;
29452 break;
29453 }
29454 }
29455 @@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detect(void)
29456 hba[ctlr]->intr = intr;
29457 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
29458 hba[ctlr]->product_name = products[j].product_name;
29459 - hba[ctlr]->access = *(products[j].access);
29460 + hba[ctlr]->access = products[j].access;
29461 hba[ctlr]->ctlr = ctlr;
29462 hba[ctlr]->board_id = board_id;
29463 hba[ctlr]->pci_dev = NULL; /* not PCI */
29464 @@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
29465
29466 while((c = h->reqQ) != NULL) {
29467 /* Can't do anything if we're busy */
29468 - if (h->access.fifo_full(h) == 0)
29469 + if (h->access->fifo_full(h) == 0)
29470 return;
29471
29472 /* Get the first entry from the request Q */
29473 @@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
29474 h->Qdepth--;
29475
29476 /* Tell the controller to do our bidding */
29477 - h->access.submit_command(h, c);
29478 + h->access->submit_command(h, c);
29479
29480 /* Get onto the completion Q */
29481 addQ(&h->cmpQ, c);
29482 @@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
29483 unsigned long flags;
29484 __u32 a,a1;
29485
29486 - istat = h->access.intr_pending(h);
29487 + istat = h->access->intr_pending(h);
29488 /* Is this interrupt for us? */
29489 if (istat == 0)
29490 return IRQ_NONE;
29491 @@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
29492 */
29493 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
29494 if (istat & FIFO_NOT_EMPTY) {
29495 - while((a = h->access.command_completed(h))) {
29496 + while((a = h->access->command_completed(h))) {
29497 a1 = a; a &= ~3;
29498 if ((c = h->cmpQ) == NULL)
29499 {
29500 @@ -1449,11 +1449,11 @@ static int sendcmd(
29501 /*
29502 * Disable interrupt
29503 */
29504 - info_p->access.set_intr_mask(info_p, 0);
29505 + info_p->access->set_intr_mask(info_p, 0);
29506 /* Make sure there is room in the command FIFO */
29507 /* Actually it should be completely empty at this time. */
29508 for (i = 200000; i > 0; i--) {
29509 - temp = info_p->access.fifo_full(info_p);
29510 + temp = info_p->access->fifo_full(info_p);
29511 if (temp != 0) {
29512 break;
29513 }
29514 @@ -1466,7 +1466,7 @@ DBG(
29515 /*
29516 * Send the cmd
29517 */
29518 - info_p->access.submit_command(info_p, c);
29519 + info_p->access->submit_command(info_p, c);
29520 complete = pollcomplete(ctlr);
29521
29522 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
29523 @@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
29524 * we check the new geometry. Then turn interrupts back on when
29525 * we're done.
29526 */
29527 - host->access.set_intr_mask(host, 0);
29528 + host->access->set_intr_mask(host, 0);
29529 getgeometry(ctlr);
29530 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
29531 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
29532
29533 for(i=0; i<NWD; i++) {
29534 struct gendisk *disk = ida_gendisk[ctlr][i];
29535 @@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
29536 /* Wait (up to 2 seconds) for a command to complete */
29537
29538 for (i = 200000; i > 0; i--) {
29539 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
29540 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
29541 if (done == 0) {
29542 udelay(10); /* a short fixed delay */
29543 } else
29544 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
29545 index be73e9d..7fbf140 100644
29546 --- a/drivers/block/cpqarray.h
29547 +++ b/drivers/block/cpqarray.h
29548 @@ -99,7 +99,7 @@ struct ctlr_info {
29549 drv_info_t drv[NWD];
29550 struct proc_dir_entry *proc;
29551
29552 - struct access_method access;
29553 + struct access_method *access;
29554
29555 cmdlist_t *reqQ;
29556 cmdlist_t *cmpQ;
29557 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
29558 index b953cc7..e3dc580 100644
29559 --- a/drivers/block/drbd/drbd_int.h
29560 +++ b/drivers/block/drbd/drbd_int.h
29561 @@ -735,7 +735,7 @@ struct drbd_request;
29562 struct drbd_epoch {
29563 struct list_head list;
29564 unsigned int barrier_nr;
29565 - atomic_t epoch_size; /* increased on every request added. */
29566 + atomic_unchecked_t epoch_size; /* increased on every request added. */
29567 atomic_t active; /* increased on every req. added, and dec on every finished. */
29568 unsigned long flags;
29569 };
29570 @@ -1116,7 +1116,7 @@ struct drbd_conf {
29571 void *int_dig_in;
29572 void *int_dig_vv;
29573 wait_queue_head_t seq_wait;
29574 - atomic_t packet_seq;
29575 + atomic_unchecked_t packet_seq;
29576 unsigned int peer_seq;
29577 spinlock_t peer_seq_lock;
29578 unsigned int minor;
29579 @@ -1658,30 +1658,30 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
29580
29581 static inline void drbd_tcp_cork(struct socket *sock)
29582 {
29583 - int __user val = 1;
29584 + int val = 1;
29585 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29586 - (char __user *)&val, sizeof(val));
29587 + (char __force_user *)&val, sizeof(val));
29588 }
29589
29590 static inline void drbd_tcp_uncork(struct socket *sock)
29591 {
29592 - int __user val = 0;
29593 + int val = 0;
29594 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29595 - (char __user *)&val, sizeof(val));
29596 + (char __force_user *)&val, sizeof(val));
29597 }
29598
29599 static inline void drbd_tcp_nodelay(struct socket *sock)
29600 {
29601 - int __user val = 1;
29602 + int val = 1;
29603 (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY,
29604 - (char __user *)&val, sizeof(val));
29605 + (char __force_user *)&val, sizeof(val));
29606 }
29607
29608 static inline void drbd_tcp_quickack(struct socket *sock)
29609 {
29610 - int __user val = 2;
29611 + int val = 2;
29612 (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
29613 - (char __user *)&val, sizeof(val));
29614 + (char __force_user *)&val, sizeof(val));
29615 }
29616
29617 void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo);
29618 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
29619 index f93a032..71c87bf 100644
29620 --- a/drivers/block/drbd/drbd_main.c
29621 +++ b/drivers/block/drbd/drbd_main.c
29622 @@ -2567,7 +2567,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packets cmd,
29623 p.sector = sector;
29624 p.block_id = block_id;
29625 p.blksize = blksize;
29626 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29627 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29628
29629 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
29630 return false;
29631 @@ -2865,7 +2865,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
29632
29633 p.sector = cpu_to_be64(req->sector);
29634 p.block_id = (unsigned long)req;
29635 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29636 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29637
29638 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
29639
29640 @@ -3150,7 +3150,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
29641 atomic_set(&mdev->unacked_cnt, 0);
29642 atomic_set(&mdev->local_cnt, 0);
29643 atomic_set(&mdev->net_cnt, 0);
29644 - atomic_set(&mdev->packet_seq, 0);
29645 + atomic_set_unchecked(&mdev->packet_seq, 0);
29646 atomic_set(&mdev->pp_in_use, 0);
29647 atomic_set(&mdev->pp_in_use_by_net, 0);
29648 atomic_set(&mdev->rs_sect_in, 0);
29649 @@ -3232,8 +3232,8 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
29650 mdev->receiver.t_state);
29651
29652 /* no need to lock it, I'm the only thread alive */
29653 - if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
29654 - dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
29655 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
29656 + dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
29657 mdev->al_writ_cnt =
29658 mdev->bm_writ_cnt =
29659 mdev->read_cnt =
29660 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
29661 index edb490a..ecd69da 100644
29662 --- a/drivers/block/drbd/drbd_nl.c
29663 +++ b/drivers/block/drbd/drbd_nl.c
29664 @@ -2407,7 +2407,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
29665 module_put(THIS_MODULE);
29666 }
29667
29668 -static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29669 +static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29670
29671 static unsigned short *
29672 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
29673 @@ -2478,7 +2478,7 @@ void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
29674 cn_reply->id.idx = CN_IDX_DRBD;
29675 cn_reply->id.val = CN_VAL_DRBD;
29676
29677 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29678 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29679 cn_reply->ack = 0; /* not used here. */
29680 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29681 (int)((char *)tl - (char *)reply->tag_list);
29682 @@ -2510,7 +2510,7 @@ void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
29683 cn_reply->id.idx = CN_IDX_DRBD;
29684 cn_reply->id.val = CN_VAL_DRBD;
29685
29686 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29687 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29688 cn_reply->ack = 0; /* not used here. */
29689 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29690 (int)((char *)tl - (char *)reply->tag_list);
29691 @@ -2588,7 +2588,7 @@ void drbd_bcast_ee(struct drbd_conf *mdev,
29692 cn_reply->id.idx = CN_IDX_DRBD;
29693 cn_reply->id.val = CN_VAL_DRBD;
29694
29695 - cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
29696 + cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
29697 cn_reply->ack = 0; // not used here.
29698 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29699 (int)((char*)tl - (char*)reply->tag_list);
29700 @@ -2627,7 +2627,7 @@ void drbd_bcast_sync_progress(struct drbd_conf *mdev)
29701 cn_reply->id.idx = CN_IDX_DRBD;
29702 cn_reply->id.val = CN_VAL_DRBD;
29703
29704 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29705 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29706 cn_reply->ack = 0; /* not used here. */
29707 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29708 (int)((char *)tl - (char *)reply->tag_list);
29709 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
29710 index c74ca2d..860c819 100644
29711 --- a/drivers/block/drbd/drbd_receiver.c
29712 +++ b/drivers/block/drbd/drbd_receiver.c
29713 @@ -898,7 +898,7 @@ retry:
29714 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
29715 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
29716
29717 - atomic_set(&mdev->packet_seq, 0);
29718 + atomic_set_unchecked(&mdev->packet_seq, 0);
29719 mdev->peer_seq = 0;
29720
29721 if (drbd_send_protocol(mdev) == -1)
29722 @@ -999,7 +999,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29723 do {
29724 next_epoch = NULL;
29725
29726 - epoch_size = atomic_read(&epoch->epoch_size);
29727 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
29728
29729 switch (ev & ~EV_CLEANUP) {
29730 case EV_PUT:
29731 @@ -1035,7 +1035,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29732 rv = FE_DESTROYED;
29733 } else {
29734 epoch->flags = 0;
29735 - atomic_set(&epoch->epoch_size, 0);
29736 + atomic_set_unchecked(&epoch->epoch_size, 0);
29737 /* atomic_set(&epoch->active, 0); is already zero */
29738 if (rv == FE_STILL_LIVE)
29739 rv = FE_RECYCLED;
29740 @@ -1210,14 +1210,14 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29741 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
29742 drbd_flush(mdev);
29743
29744 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
29745 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29746 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
29747 if (epoch)
29748 break;
29749 }
29750
29751 epoch = mdev->current_epoch;
29752 - wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
29753 + wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
29754
29755 D_ASSERT(atomic_read(&epoch->active) == 0);
29756 D_ASSERT(epoch->flags == 0);
29757 @@ -1229,11 +1229,11 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29758 }
29759
29760 epoch->flags = 0;
29761 - atomic_set(&epoch->epoch_size, 0);
29762 + atomic_set_unchecked(&epoch->epoch_size, 0);
29763 atomic_set(&epoch->active, 0);
29764
29765 spin_lock(&mdev->epoch_lock);
29766 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
29767 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29768 list_add(&epoch->list, &mdev->current_epoch->list);
29769 mdev->current_epoch = epoch;
29770 mdev->epochs++;
29771 @@ -1702,7 +1702,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29772 spin_unlock(&mdev->peer_seq_lock);
29773
29774 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
29775 - atomic_inc(&mdev->current_epoch->epoch_size);
29776 + atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
29777 return drbd_drain_block(mdev, data_size);
29778 }
29779
29780 @@ -1732,7 +1732,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29781
29782 spin_lock(&mdev->epoch_lock);
29783 e->epoch = mdev->current_epoch;
29784 - atomic_inc(&e->epoch->epoch_size);
29785 + atomic_inc_unchecked(&e->epoch->epoch_size);
29786 atomic_inc(&e->epoch->active);
29787 spin_unlock(&mdev->epoch_lock);
29788
29789 @@ -3954,7 +3954,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
29790 D_ASSERT(list_empty(&mdev->done_ee));
29791
29792 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
29793 - atomic_set(&mdev->current_epoch->epoch_size, 0);
29794 + atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
29795 D_ASSERT(list_empty(&mdev->current_epoch->list));
29796 }
29797
29798 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
29799 index 3bba655..6151b66 100644
29800 --- a/drivers/block/loop.c
29801 +++ b/drivers/block/loop.c
29802 @@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
29803 mm_segment_t old_fs = get_fs();
29804
29805 set_fs(get_ds());
29806 - bw = file->f_op->write(file, buf, len, &pos);
29807 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
29808 set_fs(old_fs);
29809 if (likely(bw == len))
29810 return 0;
29811 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
29812 index ea6f632..eafb192 100644
29813 --- a/drivers/char/Kconfig
29814 +++ b/drivers/char/Kconfig
29815 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
29816
29817 config DEVKMEM
29818 bool "/dev/kmem virtual device support"
29819 - default y
29820 + default n
29821 + depends on !GRKERNSEC_KMEM
29822 help
29823 Say Y here if you want to support the /dev/kmem device. The
29824 /dev/kmem device is rarely used, but can be used for certain
29825 @@ -581,6 +582,7 @@ config DEVPORT
29826 bool
29827 depends on !M68K
29828 depends on ISA || PCI
29829 + depends on !GRKERNSEC_KMEM
29830 default y
29831
29832 source "drivers/s390/char/Kconfig"
29833 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
29834 index 2e04433..22afc64 100644
29835 --- a/drivers/char/agp/frontend.c
29836 +++ b/drivers/char/agp/frontend.c
29837 @@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
29838 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
29839 return -EFAULT;
29840
29841 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
29842 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
29843 return -EFAULT;
29844
29845 client = agp_find_client_by_pid(reserve.pid);
29846 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
29847 index 21cb980..f15107c 100644
29848 --- a/drivers/char/genrtc.c
29849 +++ b/drivers/char/genrtc.c
29850 @@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
29851 switch (cmd) {
29852
29853 case RTC_PLL_GET:
29854 + memset(&pll, 0, sizeof(pll));
29855 if (get_rtc_pll(&pll))
29856 return -EINVAL;
29857 else
29858 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
29859 index dfd7876..c0b0885 100644
29860 --- a/drivers/char/hpet.c
29861 +++ b/drivers/char/hpet.c
29862 @@ -571,7 +571,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
29863 }
29864
29865 static int
29866 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
29867 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
29868 struct hpet_info *info)
29869 {
29870 struct hpet_timer __iomem *timer;
29871 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
29872 index 2c29942..604c5ba 100644
29873 --- a/drivers/char/ipmi/ipmi_msghandler.c
29874 +++ b/drivers/char/ipmi/ipmi_msghandler.c
29875 @@ -420,7 +420,7 @@ struct ipmi_smi {
29876 struct proc_dir_entry *proc_dir;
29877 char proc_dir_name[10];
29878
29879 - atomic_t stats[IPMI_NUM_STATS];
29880 + atomic_unchecked_t stats[IPMI_NUM_STATS];
29881
29882 /*
29883 * run_to_completion duplicate of smb_info, smi_info
29884 @@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
29885
29886
29887 #define ipmi_inc_stat(intf, stat) \
29888 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
29889 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
29890 #define ipmi_get_stat(intf, stat) \
29891 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
29892 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
29893
29894 static int is_lan_addr(struct ipmi_addr *addr)
29895 {
29896 @@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
29897 INIT_LIST_HEAD(&intf->cmd_rcvrs);
29898 init_waitqueue_head(&intf->waitq);
29899 for (i = 0; i < IPMI_NUM_STATS; i++)
29900 - atomic_set(&intf->stats[i], 0);
29901 + atomic_set_unchecked(&intf->stats[i], 0);
29902
29903 intf->proc_dir = NULL;
29904
29905 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
29906 index 83f85cf..279e63f 100644
29907 --- a/drivers/char/ipmi/ipmi_si_intf.c
29908 +++ b/drivers/char/ipmi/ipmi_si_intf.c
29909 @@ -275,7 +275,7 @@ struct smi_info {
29910 unsigned char slave_addr;
29911
29912 /* Counters and things for the proc filesystem. */
29913 - atomic_t stats[SI_NUM_STATS];
29914 + atomic_unchecked_t stats[SI_NUM_STATS];
29915
29916 struct task_struct *thread;
29917
29918 @@ -284,9 +284,9 @@ struct smi_info {
29919 };
29920
29921 #define smi_inc_stat(smi, stat) \
29922 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
29923 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
29924 #define smi_get_stat(smi, stat) \
29925 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
29926 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
29927
29928 #define SI_MAX_PARMS 4
29929
29930 @@ -3193,7 +3193,7 @@ static int try_smi_init(struct smi_info *new_smi)
29931 atomic_set(&new_smi->req_events, 0);
29932 new_smi->run_to_completion = 0;
29933 for (i = 0; i < SI_NUM_STATS; i++)
29934 - atomic_set(&new_smi->stats[i], 0);
29935 + atomic_set_unchecked(&new_smi->stats[i], 0);
29936
29937 new_smi->interrupt_disabled = 1;
29938 atomic_set(&new_smi->stop_operation, 0);
29939 diff --git a/drivers/char/mbcs.c b/drivers/char/mbcs.c
29940 index 47ff7e4..0c7d340 100644
29941 --- a/drivers/char/mbcs.c
29942 +++ b/drivers/char/mbcs.c
29943 @@ -799,7 +799,7 @@ static int mbcs_remove(struct cx_dev *dev)
29944 return 0;
29945 }
29946
29947 -static const struct cx_device_id __devinitdata mbcs_id_table[] = {
29948 +static const struct cx_device_id __devinitconst mbcs_id_table[] = {
29949 {
29950 .part_num = MBCS_PART_NUM,
29951 .mfg_num = MBCS_MFG_NUM,
29952 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
29953 index e5eedfa..fcab50ea 100644
29954 --- a/drivers/char/mem.c
29955 +++ b/drivers/char/mem.c
29956 @@ -18,6 +18,7 @@
29957 #include <linux/raw.h>
29958 #include <linux/tty.h>
29959 #include <linux/capability.h>
29960 +#include <linux/security.h>
29961 #include <linux/ptrace.h>
29962 #include <linux/device.h>
29963 #include <linux/highmem.h>
29964 @@ -37,6 +38,10 @@
29965
29966 #define DEVPORT_MINOR 4
29967
29968 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29969 +extern const struct file_operations grsec_fops;
29970 +#endif
29971 +
29972 static inline unsigned long size_inside_page(unsigned long start,
29973 unsigned long size)
29974 {
29975 @@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29976
29977 while (cursor < to) {
29978 if (!devmem_is_allowed(pfn)) {
29979 +#ifdef CONFIG_GRKERNSEC_KMEM
29980 + gr_handle_mem_readwrite(from, to);
29981 +#else
29982 printk(KERN_INFO
29983 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
29984 current->comm, from, to);
29985 +#endif
29986 return 0;
29987 }
29988 cursor += PAGE_SIZE;
29989 @@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29990 }
29991 return 1;
29992 }
29993 +#elif defined(CONFIG_GRKERNSEC_KMEM)
29994 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29995 +{
29996 + return 0;
29997 +}
29998 #else
29999 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
30000 {
30001 @@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
30002
30003 while (count > 0) {
30004 unsigned long remaining;
30005 + char *temp;
30006
30007 sz = size_inside_page(p, count);
30008
30009 @@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
30010 if (!ptr)
30011 return -EFAULT;
30012
30013 - remaining = copy_to_user(buf, ptr, sz);
30014 +#ifdef CONFIG_PAX_USERCOPY
30015 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
30016 + if (!temp) {
30017 + unxlate_dev_mem_ptr(p, ptr);
30018 + return -ENOMEM;
30019 + }
30020 + memcpy(temp, ptr, sz);
30021 +#else
30022 + temp = ptr;
30023 +#endif
30024 +
30025 + remaining = copy_to_user(buf, temp, sz);
30026 +
30027 +#ifdef CONFIG_PAX_USERCOPY
30028 + kfree(temp);
30029 +#endif
30030 +
30031 unxlate_dev_mem_ptr(p, ptr);
30032 if (remaining)
30033 return -EFAULT;
30034 @@ -398,9 +429,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
30035 size_t count, loff_t *ppos)
30036 {
30037 unsigned long p = *ppos;
30038 - ssize_t low_count, read, sz;
30039 + ssize_t low_count, read, sz, err = 0;
30040 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
30041 - int err = 0;
30042
30043 read = 0;
30044 if (p < (unsigned long) high_memory) {
30045 @@ -422,6 +452,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
30046 }
30047 #endif
30048 while (low_count > 0) {
30049 + char *temp;
30050 +
30051 sz = size_inside_page(p, low_count);
30052
30053 /*
30054 @@ -431,7 +463,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
30055 */
30056 kbuf = xlate_dev_kmem_ptr((char *)p);
30057
30058 - if (copy_to_user(buf, kbuf, sz))
30059 +#ifdef CONFIG_PAX_USERCOPY
30060 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
30061 + if (!temp)
30062 + return -ENOMEM;
30063 + memcpy(temp, kbuf, sz);
30064 +#else
30065 + temp = kbuf;
30066 +#endif
30067 +
30068 + err = copy_to_user(buf, temp, sz);
30069 +
30070 +#ifdef CONFIG_PAX_USERCOPY
30071 + kfree(temp);
30072 +#endif
30073 +
30074 + if (err)
30075 return -EFAULT;
30076 buf += sz;
30077 p += sz;
30078 @@ -833,6 +880,9 @@ static const struct memdev {
30079 #ifdef CONFIG_CRASH_DUMP
30080 [12] = { "oldmem", 0, &oldmem_fops, NULL },
30081 #endif
30082 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
30083 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
30084 +#endif
30085 };
30086
30087 static int memory_open(struct inode *inode, struct file *filp)
30088 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
30089 index 9df78e2..01ba9ae 100644
30090 --- a/drivers/char/nvram.c
30091 +++ b/drivers/char/nvram.c
30092 @@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
30093
30094 spin_unlock_irq(&rtc_lock);
30095
30096 - if (copy_to_user(buf, contents, tmp - contents))
30097 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
30098 return -EFAULT;
30099
30100 *ppos = i;
30101 diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
30102 index 0a484b4..f48ccd1 100644
30103 --- a/drivers/char/pcmcia/synclink_cs.c
30104 +++ b/drivers/char/pcmcia/synclink_cs.c
30105 @@ -2340,9 +2340,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
30106
30107 if (debug_level >= DEBUG_LEVEL_INFO)
30108 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
30109 - __FILE__,__LINE__, info->device_name, port->count);
30110 + __FILE__,__LINE__, info->device_name, atomic_read(&port->count));
30111
30112 - WARN_ON(!port->count);
30113 + WARN_ON(!atomic_read(&port->count));
30114
30115 if (tty_port_close_start(port, tty, filp) == 0)
30116 goto cleanup;
30117 @@ -2360,7 +2360,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
30118 cleanup:
30119 if (debug_level >= DEBUG_LEVEL_INFO)
30120 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__,__LINE__,
30121 - tty->driver->name, port->count);
30122 + tty->driver->name, atomic_read(&port->count));
30123 }
30124
30125 /* Wait until the transmitter is empty.
30126 @@ -2502,7 +2502,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
30127
30128 if (debug_level >= DEBUG_LEVEL_INFO)
30129 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
30130 - __FILE__,__LINE__,tty->driver->name, port->count);
30131 + __FILE__,__LINE__,tty->driver->name, atomic_read(&port->count));
30132
30133 /* If port is closing, signal caller to try again */
30134 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
30135 @@ -2522,11 +2522,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
30136 goto cleanup;
30137 }
30138 spin_lock(&port->lock);
30139 - port->count++;
30140 + atomic_inc(&port->count);
30141 spin_unlock(&port->lock);
30142 spin_unlock_irqrestore(&info->netlock, flags);
30143
30144 - if (port->count == 1) {
30145 + if (atomic_read(&port->count) == 1) {
30146 /* 1st open on this device, init hardware */
30147 retval = startup(info, tty);
30148 if (retval < 0)
30149 @@ -3891,7 +3891,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
30150 unsigned short new_crctype;
30151
30152 /* return error if TTY interface open */
30153 - if (info->port.count)
30154 + if (atomic_read(&info->port.count))
30155 return -EBUSY;
30156
30157 switch (encoding)
30158 @@ -3994,7 +3994,7 @@ static int hdlcdev_open(struct net_device *dev)
30159
30160 /* arbitrate between network and tty opens */
30161 spin_lock_irqsave(&info->netlock, flags);
30162 - if (info->port.count != 0 || info->netcount != 0) {
30163 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
30164 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
30165 spin_unlock_irqrestore(&info->netlock, flags);
30166 return -EBUSY;
30167 @@ -4083,7 +4083,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
30168 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
30169
30170 /* return error if TTY interface open */
30171 - if (info->port.count)
30172 + if (atomic_read(&info->port.count))
30173 return -EBUSY;
30174
30175 if (cmd != SIOCWANDEV)
30176 diff --git a/drivers/char/random.c b/drivers/char/random.c
30177 index b86eae9..4192a7a 100644
30178 --- a/drivers/char/random.c
30179 +++ b/drivers/char/random.c
30180 @@ -272,8 +272,13 @@
30181 /*
30182 * Configuration information
30183 */
30184 +#ifdef CONFIG_GRKERNSEC_RANDNET
30185 +#define INPUT_POOL_WORDS 512
30186 +#define OUTPUT_POOL_WORDS 128
30187 +#else
30188 #define INPUT_POOL_WORDS 128
30189 #define OUTPUT_POOL_WORDS 32
30190 +#endif
30191 #define SEC_XFER_SIZE 512
30192 #define EXTRACT_SIZE 10
30193
30194 @@ -313,10 +318,17 @@ static struct poolinfo {
30195 int poolwords;
30196 int tap1, tap2, tap3, tap4, tap5;
30197 } poolinfo_table[] = {
30198 +#ifdef CONFIG_GRKERNSEC_RANDNET
30199 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
30200 + { 512, 411, 308, 208, 104, 1 },
30201 + /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
30202 + { 128, 103, 76, 51, 25, 1 },
30203 +#else
30204 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
30205 { 128, 103, 76, 51, 25, 1 },
30206 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
30207 { 32, 26, 20, 14, 7, 1 },
30208 +#endif
30209 #if 0
30210 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
30211 { 2048, 1638, 1231, 819, 411, 1 },
30212 @@ -527,8 +539,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
30213 input_rotate += i ? 7 : 14;
30214 }
30215
30216 - ACCESS_ONCE(r->input_rotate) = input_rotate;
30217 - ACCESS_ONCE(r->add_ptr) = i;
30218 + ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
30219 + ACCESS_ONCE_RW(r->add_ptr) = i;
30220 smp_wmb();
30221
30222 if (out)
30223 @@ -799,6 +811,17 @@ void add_disk_randomness(struct gendisk *disk)
30224 }
30225 #endif
30226
30227 +#ifdef CONFIG_PAX_LATENT_ENTROPY
30228 +u64 latent_entropy;
30229 +
30230 +__init void transfer_latent_entropy(void)
30231 +{
30232 + mix_pool_bytes(&input_pool, &latent_entropy, sizeof(latent_entropy), NULL);
30233 + mix_pool_bytes(&nonblocking_pool, &latent_entropy, sizeof(latent_entropy), NULL);
30234 +// printk(KERN_INFO "PAX: transferring latent entropy: %16llx\n", latent_entropy);
30235 +}
30236 +#endif
30237 +
30238 /*********************************************************************
30239 *
30240 * Entropy extraction routines
30241 @@ -1008,7 +1031,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
30242
30243 extract_buf(r, tmp);
30244 i = min_t(int, nbytes, EXTRACT_SIZE);
30245 - if (copy_to_user(buf, tmp, i)) {
30246 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
30247 ret = -EFAULT;
30248 break;
30249 }
30250 @@ -1342,7 +1365,7 @@ EXPORT_SYMBOL(generate_random_uuid);
30251 #include <linux/sysctl.h>
30252
30253 static int min_read_thresh = 8, min_write_thresh;
30254 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
30255 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
30256 static int max_write_thresh = INPUT_POOL_WORDS * 32;
30257 static char sysctl_bootid[16];
30258
30259 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
30260 index f877805..403375a 100644
30261 --- a/drivers/char/sonypi.c
30262 +++ b/drivers/char/sonypi.c
30263 @@ -54,6 +54,7 @@
30264
30265 #include <asm/uaccess.h>
30266 #include <asm/io.h>
30267 +#include <asm/local.h>
30268
30269 #include <linux/sonypi.h>
30270
30271 @@ -490,7 +491,7 @@ static struct sonypi_device {
30272 spinlock_t fifo_lock;
30273 wait_queue_head_t fifo_proc_list;
30274 struct fasync_struct *fifo_async;
30275 - int open_count;
30276 + local_t open_count;
30277 int model;
30278 struct input_dev *input_jog_dev;
30279 struct input_dev *input_key_dev;
30280 @@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
30281 static int sonypi_misc_release(struct inode *inode, struct file *file)
30282 {
30283 mutex_lock(&sonypi_device.lock);
30284 - sonypi_device.open_count--;
30285 + local_dec(&sonypi_device.open_count);
30286 mutex_unlock(&sonypi_device.lock);
30287 return 0;
30288 }
30289 @@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
30290 {
30291 mutex_lock(&sonypi_device.lock);
30292 /* Flush input queue on first open */
30293 - if (!sonypi_device.open_count)
30294 + if (!local_read(&sonypi_device.open_count))
30295 kfifo_reset(&sonypi_device.fifo);
30296 - sonypi_device.open_count++;
30297 + local_inc(&sonypi_device.open_count);
30298 mutex_unlock(&sonypi_device.lock);
30299
30300 return 0;
30301 diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
30302 index 4dc8024..90108d1 100644
30303 --- a/drivers/char/tpm/tpm.c
30304 +++ b/drivers/char/tpm/tpm.c
30305 @@ -415,7 +415,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
30306 chip->vendor.req_complete_val)
30307 goto out_recv;
30308
30309 - if ((status == chip->vendor.req_canceled)) {
30310 + if (status == chip->vendor.req_canceled) {
30311 dev_err(chip->dev, "Operation Canceled\n");
30312 rc = -ECANCELED;
30313 goto out;
30314 diff --git a/drivers/char/tpm/tpm_bios.c b/drivers/char/tpm/tpm_bios.c
30315 index 0636520..169c1d0 100644
30316 --- a/drivers/char/tpm/tpm_bios.c
30317 +++ b/drivers/char/tpm/tpm_bios.c
30318 @@ -173,7 +173,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
30319 event = addr;
30320
30321 if ((event->event_type == 0 && event->event_size == 0) ||
30322 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
30323 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
30324 return NULL;
30325
30326 return addr;
30327 @@ -198,7 +198,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
30328 return NULL;
30329
30330 if ((event->event_type == 0 && event->event_size == 0) ||
30331 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
30332 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
30333 return NULL;
30334
30335 (*pos)++;
30336 @@ -291,7 +291,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
30337 int i;
30338
30339 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
30340 - seq_putc(m, data[i]);
30341 + if (!seq_putc(m, data[i]))
30342 + return -EFAULT;
30343
30344 return 0;
30345 }
30346 @@ -410,8 +411,13 @@ static int read_log(struct tpm_bios_log *log)
30347 log->bios_event_log_end = log->bios_event_log + len;
30348
30349 virt = acpi_os_map_memory(start, len);
30350 + if (!virt) {
30351 + kfree(log->bios_event_log);
30352 + log->bios_event_log = NULL;
30353 + return -EFAULT;
30354 + }
30355
30356 - memcpy(log->bios_event_log, virt, len);
30357 + memcpy(log->bios_event_log, (const char __force_kernel *)virt, len);
30358
30359 acpi_os_unmap_memory(virt, len);
30360 return 0;
30361 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
30362 index cdf2f54..e55c197 100644
30363 --- a/drivers/char/virtio_console.c
30364 +++ b/drivers/char/virtio_console.c
30365 @@ -563,7 +563,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
30366 if (to_user) {
30367 ssize_t ret;
30368
30369 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
30370 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
30371 if (ret)
30372 return -EFAULT;
30373 } else {
30374 @@ -662,7 +662,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
30375 if (!port_has_data(port) && !port->host_connected)
30376 return 0;
30377
30378 - return fill_readbuf(port, ubuf, count, true);
30379 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
30380 }
30381
30382 static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,
30383 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
30384 index e164c55..3aabb50 100644
30385 --- a/drivers/edac/edac_pci_sysfs.c
30386 +++ b/drivers/edac/edac_pci_sysfs.c
30387 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
30388 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
30389 static int edac_pci_poll_msec = 1000; /* one second workq period */
30390
30391 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
30392 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
30393 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
30394 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
30395
30396 static struct kobject *edac_pci_top_main_kobj;
30397 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
30398 @@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30399 edac_printk(KERN_CRIT, EDAC_PCI,
30400 "Signaled System Error on %s\n",
30401 pci_name(dev));
30402 - atomic_inc(&pci_nonparity_count);
30403 + atomic_inc_unchecked(&pci_nonparity_count);
30404 }
30405
30406 if (status & (PCI_STATUS_PARITY)) {
30407 @@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30408 "Master Data Parity Error on %s\n",
30409 pci_name(dev));
30410
30411 - atomic_inc(&pci_parity_count);
30412 + atomic_inc_unchecked(&pci_parity_count);
30413 }
30414
30415 if (status & (PCI_STATUS_DETECTED_PARITY)) {
30416 @@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30417 "Detected Parity Error on %s\n",
30418 pci_name(dev));
30419
30420 - atomic_inc(&pci_parity_count);
30421 + atomic_inc_unchecked(&pci_parity_count);
30422 }
30423 }
30424
30425 @@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30426 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
30427 "Signaled System Error on %s\n",
30428 pci_name(dev));
30429 - atomic_inc(&pci_nonparity_count);
30430 + atomic_inc_unchecked(&pci_nonparity_count);
30431 }
30432
30433 if (status & (PCI_STATUS_PARITY)) {
30434 @@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30435 "Master Data Parity Error on "
30436 "%s\n", pci_name(dev));
30437
30438 - atomic_inc(&pci_parity_count);
30439 + atomic_inc_unchecked(&pci_parity_count);
30440 }
30441
30442 if (status & (PCI_STATUS_DETECTED_PARITY)) {
30443 @@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30444 "Detected Parity Error on %s\n",
30445 pci_name(dev));
30446
30447 - atomic_inc(&pci_parity_count);
30448 + atomic_inc_unchecked(&pci_parity_count);
30449 }
30450 }
30451 }
30452 @@ -676,7 +676,7 @@ void edac_pci_do_parity_check(void)
30453 if (!check_pci_errors)
30454 return;
30455
30456 - before_count = atomic_read(&pci_parity_count);
30457 + before_count = atomic_read_unchecked(&pci_parity_count);
30458
30459 /* scan all PCI devices looking for a Parity Error on devices and
30460 * bridges.
30461 @@ -688,7 +688,7 @@ void edac_pci_do_parity_check(void)
30462 /* Only if operator has selected panic on PCI Error */
30463 if (edac_pci_get_panic_on_pe()) {
30464 /* If the count is different 'after' from 'before' */
30465 - if (before_count != atomic_read(&pci_parity_count))
30466 + if (before_count != atomic_read_unchecked(&pci_parity_count))
30467 panic("EDAC: PCI Parity Error");
30468 }
30469 }
30470 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
30471 index 8c87a5e..a19cbd7 100644
30472 --- a/drivers/edac/mce_amd.h
30473 +++ b/drivers/edac/mce_amd.h
30474 @@ -80,7 +80,7 @@ extern const char * const ii_msgs[];
30475 struct amd_decoder_ops {
30476 bool (*dc_mce)(u16, u8);
30477 bool (*ic_mce)(u16, u8);
30478 -};
30479 +} __no_const;
30480
30481 void amd_report_gart_errors(bool);
30482 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
30483 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
30484 index 57ea7f4..789e3c3 100644
30485 --- a/drivers/firewire/core-card.c
30486 +++ b/drivers/firewire/core-card.c
30487 @@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
30488
30489 void fw_core_remove_card(struct fw_card *card)
30490 {
30491 - struct fw_card_driver dummy_driver = dummy_driver_template;
30492 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
30493
30494 card->driver->update_phy_reg(card, 4,
30495 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
30496 diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
30497 index f8d2287..5aaf4db 100644
30498 --- a/drivers/firewire/core-cdev.c
30499 +++ b/drivers/firewire/core-cdev.c
30500 @@ -1365,8 +1365,7 @@ static int init_iso_resource(struct client *client,
30501 int ret;
30502
30503 if ((request->channels == 0 && request->bandwidth == 0) ||
30504 - request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
30505 - request->bandwidth < 0)
30506 + request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
30507 return -EINVAL;
30508
30509 r = kmalloc(sizeof(*r), GFP_KERNEL);
30510 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
30511 index 87d6f2d..5bf9d90 100644
30512 --- a/drivers/firewire/core-transaction.c
30513 +++ b/drivers/firewire/core-transaction.c
30514 @@ -37,6 +37,7 @@
30515 #include <linux/timer.h>
30516 #include <linux/types.h>
30517 #include <linux/workqueue.h>
30518 +#include <linux/sched.h>
30519
30520 #include <asm/byteorder.h>
30521
30522 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
30523 index 515a42c..5ecf3ba 100644
30524 --- a/drivers/firewire/core.h
30525 +++ b/drivers/firewire/core.h
30526 @@ -111,6 +111,7 @@ struct fw_card_driver {
30527
30528 int (*stop_iso)(struct fw_iso_context *ctx);
30529 };
30530 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
30531
30532 void fw_card_initialize(struct fw_card *card,
30533 const struct fw_card_driver *driver, struct device *device);
30534 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
30535 index b298158..7ed8432 100644
30536 --- a/drivers/firmware/dmi_scan.c
30537 +++ b/drivers/firmware/dmi_scan.c
30538 @@ -452,11 +452,6 @@ void __init dmi_scan_machine(void)
30539 }
30540 }
30541 else {
30542 - /*
30543 - * no iounmap() for that ioremap(); it would be a no-op, but
30544 - * it's so early in setup that sucker gets confused into doing
30545 - * what it shouldn't if we actually call it.
30546 - */
30547 p = dmi_ioremap(0xF0000, 0x10000);
30548 if (p == NULL)
30549 goto error;
30550 @@ -726,7 +721,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
30551 if (buf == NULL)
30552 return -1;
30553
30554 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
30555 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
30556
30557 iounmap(buf);
30558 return 0;
30559 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
30560 index 82d5c20..44a7177 100644
30561 --- a/drivers/gpio/gpio-vr41xx.c
30562 +++ b/drivers/gpio/gpio-vr41xx.c
30563 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
30564 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
30565 maskl, pendl, maskh, pendh);
30566
30567 - atomic_inc(&irq_err_count);
30568 + atomic_inc_unchecked(&irq_err_count);
30569
30570 return -EINVAL;
30571 }
30572 diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
30573 index 3252e70..b5314ace 100644
30574 --- a/drivers/gpu/drm/drm_crtc_helper.c
30575 +++ b/drivers/gpu/drm/drm_crtc_helper.c
30576 @@ -286,7 +286,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
30577 struct drm_crtc *tmp;
30578 int crtc_mask = 1;
30579
30580 - WARN(!crtc, "checking null crtc?\n");
30581 + BUG_ON(!crtc);
30582
30583 dev = crtc->dev;
30584
30585 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
30586 index 9238de4..a27c72a 100644
30587 --- a/drivers/gpu/drm/drm_drv.c
30588 +++ b/drivers/gpu/drm/drm_drv.c
30589 @@ -307,7 +307,7 @@ module_exit(drm_core_exit);
30590 /**
30591 * Copy and IOCTL return string to user space
30592 */
30593 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
30594 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
30595 {
30596 int len;
30597
30598 @@ -390,7 +390,7 @@ long drm_ioctl(struct file *filp,
30599 return -ENODEV;
30600
30601 atomic_inc(&dev->ioctl_count);
30602 - atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
30603 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
30604 ++file_priv->ioctl_count;
30605
30606 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
30607 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
30608 index 7aff5c7..bee6c27 100644
30609 --- a/drivers/gpu/drm/drm_fops.c
30610 +++ b/drivers/gpu/drm/drm_fops.c
30611 @@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
30612 }
30613
30614 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
30615 - atomic_set(&dev->counts[i], 0);
30616 + atomic_set_unchecked(&dev->counts[i], 0);
30617
30618 dev->sigdata.lock = NULL;
30619
30620 @@ -134,7 +134,7 @@ int drm_open(struct inode *inode, struct file *filp)
30621 if (drm_device_is_unplugged(dev))
30622 return -ENODEV;
30623
30624 - if (!dev->open_count++)
30625 + if (local_inc_return(&dev->open_count) == 1)
30626 need_setup = 1;
30627 mutex_lock(&dev->struct_mutex);
30628 old_mapping = dev->dev_mapping;
30629 @@ -149,7 +149,7 @@ int drm_open(struct inode *inode, struct file *filp)
30630 retcode = drm_open_helper(inode, filp, dev);
30631 if (retcode)
30632 goto err_undo;
30633 - atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
30634 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
30635 if (need_setup) {
30636 retcode = drm_setup(dev);
30637 if (retcode)
30638 @@ -164,7 +164,7 @@ err_undo:
30639 iput(container_of(dev->dev_mapping, struct inode, i_data));
30640 dev->dev_mapping = old_mapping;
30641 mutex_unlock(&dev->struct_mutex);
30642 - dev->open_count--;
30643 + local_dec(&dev->open_count);
30644 return retcode;
30645 }
30646 EXPORT_SYMBOL(drm_open);
30647 @@ -438,7 +438,7 @@ int drm_release(struct inode *inode, struct file *filp)
30648
30649 mutex_lock(&drm_global_mutex);
30650
30651 - DRM_DEBUG("open_count = %d\n", dev->open_count);
30652 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
30653
30654 if (dev->driver->preclose)
30655 dev->driver->preclose(dev, file_priv);
30656 @@ -447,10 +447,10 @@ int drm_release(struct inode *inode, struct file *filp)
30657 * Begin inline drm_release
30658 */
30659
30660 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
30661 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
30662 task_pid_nr(current),
30663 (long)old_encode_dev(file_priv->minor->device),
30664 - dev->open_count);
30665 + local_read(&dev->open_count));
30666
30667 /* Release any auth tokens that might point to this file_priv,
30668 (do that under the drm_global_mutex) */
30669 @@ -546,8 +546,8 @@ int drm_release(struct inode *inode, struct file *filp)
30670 * End inline drm_release
30671 */
30672
30673 - atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
30674 - if (!--dev->open_count) {
30675 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
30676 + if (local_dec_and_test(&dev->open_count)) {
30677 if (atomic_read(&dev->ioctl_count)) {
30678 DRM_ERROR("Device busy: %d\n",
30679 atomic_read(&dev->ioctl_count));
30680 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
30681 index c87dc96..326055d 100644
30682 --- a/drivers/gpu/drm/drm_global.c
30683 +++ b/drivers/gpu/drm/drm_global.c
30684 @@ -36,7 +36,7 @@
30685 struct drm_global_item {
30686 struct mutex mutex;
30687 void *object;
30688 - int refcount;
30689 + atomic_t refcount;
30690 };
30691
30692 static struct drm_global_item glob[DRM_GLOBAL_NUM];
30693 @@ -49,7 +49,7 @@ void drm_global_init(void)
30694 struct drm_global_item *item = &glob[i];
30695 mutex_init(&item->mutex);
30696 item->object = NULL;
30697 - item->refcount = 0;
30698 + atomic_set(&item->refcount, 0);
30699 }
30700 }
30701
30702 @@ -59,7 +59,7 @@ void drm_global_release(void)
30703 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
30704 struct drm_global_item *item = &glob[i];
30705 BUG_ON(item->object != NULL);
30706 - BUG_ON(item->refcount != 0);
30707 + BUG_ON(atomic_read(&item->refcount) != 0);
30708 }
30709 }
30710
30711 @@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30712 void *object;
30713
30714 mutex_lock(&item->mutex);
30715 - if (item->refcount == 0) {
30716 + if (atomic_read(&item->refcount) == 0) {
30717 item->object = kzalloc(ref->size, GFP_KERNEL);
30718 if (unlikely(item->object == NULL)) {
30719 ret = -ENOMEM;
30720 @@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30721 goto out_err;
30722
30723 }
30724 - ++item->refcount;
30725 + atomic_inc(&item->refcount);
30726 ref->object = item->object;
30727 object = item->object;
30728 mutex_unlock(&item->mutex);
30729 @@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
30730 struct drm_global_item *item = &glob[ref->global_type];
30731
30732 mutex_lock(&item->mutex);
30733 - BUG_ON(item->refcount == 0);
30734 + BUG_ON(atomic_read(&item->refcount) == 0);
30735 BUG_ON(ref->object != item->object);
30736 - if (--item->refcount == 0) {
30737 + if (atomic_dec_and_test(&item->refcount)) {
30738 ref->release(ref);
30739 item->object = NULL;
30740 }
30741 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
30742 index 8928edb..0c79258 100644
30743 --- a/drivers/gpu/drm/drm_info.c
30744 +++ b/drivers/gpu/drm/drm_info.c
30745 @@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
30746 struct drm_local_map *map;
30747 struct drm_map_list *r_list;
30748
30749 - /* Hardcoded from _DRM_FRAME_BUFFER,
30750 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
30751 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
30752 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
30753 + static const char * const types[] = {
30754 + [_DRM_FRAME_BUFFER] = "FB",
30755 + [_DRM_REGISTERS] = "REG",
30756 + [_DRM_SHM] = "SHM",
30757 + [_DRM_AGP] = "AGP",
30758 + [_DRM_SCATTER_GATHER] = "SG",
30759 + [_DRM_CONSISTENT] = "PCI",
30760 + [_DRM_GEM] = "GEM" };
30761 const char *type;
30762 int i;
30763
30764 @@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
30765 map = r_list->map;
30766 if (!map)
30767 continue;
30768 - if (map->type < 0 || map->type > 5)
30769 + if (map->type >= ARRAY_SIZE(types))
30770 type = "??";
30771 else
30772 type = types[map->type];
30773 @@ -254,7 +258,11 @@ int drm_vma_info(struct seq_file *m, void *data)
30774 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
30775 vma->vm_flags & VM_LOCKED ? 'l' : '-',
30776 vma->vm_flags & VM_IO ? 'i' : '-',
30777 +#ifdef CONFIG_GRKERNSEC_HIDESYM
30778 + 0);
30779 +#else
30780 vma->vm_pgoff);
30781 +#endif
30782
30783 #if defined(__i386__)
30784 pgprot = pgprot_val(vma->vm_page_prot);
30785 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
30786 index 637fcc3..e890b33 100644
30787 --- a/drivers/gpu/drm/drm_ioc32.c
30788 +++ b/drivers/gpu/drm/drm_ioc32.c
30789 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
30790 request = compat_alloc_user_space(nbytes);
30791 if (!access_ok(VERIFY_WRITE, request, nbytes))
30792 return -EFAULT;
30793 - list = (struct drm_buf_desc *) (request + 1);
30794 + list = (struct drm_buf_desc __user *) (request + 1);
30795
30796 if (__put_user(count, &request->count)
30797 || __put_user(list, &request->list))
30798 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
30799 request = compat_alloc_user_space(nbytes);
30800 if (!access_ok(VERIFY_WRITE, request, nbytes))
30801 return -EFAULT;
30802 - list = (struct drm_buf_pub *) (request + 1);
30803 + list = (struct drm_buf_pub __user *) (request + 1);
30804
30805 if (__put_user(count, &request->count)
30806 || __put_user(list, &request->list))
30807 diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
30808 index 64a62c6..ceab35e 100644
30809 --- a/drivers/gpu/drm/drm_ioctl.c
30810 +++ b/drivers/gpu/drm/drm_ioctl.c
30811 @@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
30812 stats->data[i].value =
30813 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
30814 else
30815 - stats->data[i].value = atomic_read(&dev->counts[i]);
30816 + stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
30817 stats->data[i].type = dev->types[i];
30818 }
30819
30820 diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
30821 index 3203955..c8090af 100644
30822 --- a/drivers/gpu/drm/drm_lock.c
30823 +++ b/drivers/gpu/drm/drm_lock.c
30824 @@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30825 if (drm_lock_take(&master->lock, lock->context)) {
30826 master->lock.file_priv = file_priv;
30827 master->lock.lock_time = jiffies;
30828 - atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
30829 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
30830 break; /* Got lock */
30831 }
30832
30833 @@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30834 return -EINVAL;
30835 }
30836
30837 - atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
30838 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
30839
30840 if (drm_lock_free(&master->lock, lock->context)) {
30841 /* FIXME: Should really bail out here. */
30842 diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
30843 index 21bcd4a..8e074e0 100644
30844 --- a/drivers/gpu/drm/drm_stub.c
30845 +++ b/drivers/gpu/drm/drm_stub.c
30846 @@ -511,7 +511,7 @@ void drm_unplug_dev(struct drm_device *dev)
30847
30848 drm_device_set_unplugged(dev);
30849
30850 - if (dev->open_count == 0) {
30851 + if (local_read(&dev->open_count) == 0) {
30852 drm_put_dev(dev);
30853 }
30854 mutex_unlock(&drm_global_mutex);
30855 diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
30856 index 463ec68..f5bd2b5 100644
30857 --- a/drivers/gpu/drm/i810/i810_dma.c
30858 +++ b/drivers/gpu/drm/i810/i810_dma.c
30859 @@ -946,8 +946,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
30860 dma->buflist[vertex->idx],
30861 vertex->discard, vertex->used);
30862
30863 - atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30864 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30865 + atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30866 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30867 sarea_priv->last_enqueue = dev_priv->counter - 1;
30868 sarea_priv->last_dispatch = (int)hw_status[5];
30869
30870 @@ -1107,8 +1107,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
30871 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
30872 mc->last_render);
30873
30874 - atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30875 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30876 + atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30877 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30878 sarea_priv->last_enqueue = dev_priv->counter - 1;
30879 sarea_priv->last_dispatch = (int)hw_status[5];
30880
30881 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
30882 index 6e0acad..93c8289 100644
30883 --- a/drivers/gpu/drm/i810/i810_drv.h
30884 +++ b/drivers/gpu/drm/i810/i810_drv.h
30885 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
30886 int page_flipping;
30887
30888 wait_queue_head_t irq_queue;
30889 - atomic_t irq_received;
30890 - atomic_t irq_emitted;
30891 + atomic_unchecked_t irq_received;
30892 + atomic_unchecked_t irq_emitted;
30893
30894 int front_offset;
30895 } drm_i810_private_t;
30896 diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
30897 index 359f6e8..ada68fd 100644
30898 --- a/drivers/gpu/drm/i915/i915_debugfs.c
30899 +++ b/drivers/gpu/drm/i915/i915_debugfs.c
30900 @@ -518,7 +518,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
30901 I915_READ(GTIMR));
30902 }
30903 seq_printf(m, "Interrupts received: %d\n",
30904 - atomic_read(&dev_priv->irq_received));
30905 + atomic_read_unchecked(&dev_priv->irq_received));
30906 for (i = 0; i < I915_NUM_RINGS; i++) {
30907 if (IS_GEN6(dev) || IS_GEN7(dev)) {
30908 seq_printf(m, "Graphics Interrupt mask (%s): %08x\n",
30909 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
30910 index 0969a7c..b9ffa45 100644
30911 --- a/drivers/gpu/drm/i915/i915_dma.c
30912 +++ b/drivers/gpu/drm/i915/i915_dma.c
30913 @@ -1269,7 +1269,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
30914 bool can_switch;
30915
30916 spin_lock(&dev->count_lock);
30917 - can_switch = (dev->open_count == 0);
30918 + can_switch = (local_read(&dev->open_count) == 0);
30919 spin_unlock(&dev->count_lock);
30920 return can_switch;
30921 }
30922 diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
30923 index 627fe35..c9a7346 100644
30924 --- a/drivers/gpu/drm/i915/i915_drv.h
30925 +++ b/drivers/gpu/drm/i915/i915_drv.h
30926 @@ -272,12 +272,12 @@ struct drm_i915_display_funcs {
30927 /* render clock increase/decrease */
30928 /* display clock increase/decrease */
30929 /* pll clock increase/decrease */
30930 -};
30931 +} __no_const;
30932
30933 struct drm_i915_gt_funcs {
30934 void (*force_wake_get)(struct drm_i915_private *dev_priv);
30935 void (*force_wake_put)(struct drm_i915_private *dev_priv);
30936 -};
30937 +} __no_const;
30938
30939 struct intel_device_info {
30940 u8 gen;
30941 @@ -408,7 +408,7 @@ typedef struct drm_i915_private {
30942 int current_page;
30943 int page_flipping;
30944
30945 - atomic_t irq_received;
30946 + atomic_unchecked_t irq_received;
30947
30948 /* protects the irq masks */
30949 spinlock_t irq_lock;
30950 @@ -1014,7 +1014,7 @@ struct drm_i915_gem_object {
30951 * will be page flipped away on the next vblank. When it
30952 * reaches 0, dev_priv->pending_flip_queue will be woken up.
30953 */
30954 - atomic_t pending_flip;
30955 + atomic_unchecked_t pending_flip;
30956 };
30957
30958 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
30959 @@ -1482,7 +1482,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
30960 struct drm_i915_private *dev_priv, unsigned port);
30961 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
30962 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
30963 -extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30964 +static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30965 {
30966 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
30967 }
30968 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30969 index cdf46b5..e785624 100644
30970 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30971 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30972 @@ -189,7 +189,7 @@ i915_gem_object_set_to_gpu_domain(struct drm_i915_gem_object *obj,
30973 i915_gem_clflush_object(obj);
30974
30975 if (obj->base.pending_write_domain)
30976 - cd->flips |= atomic_read(&obj->pending_flip);
30977 + cd->flips |= atomic_read_unchecked(&obj->pending_flip);
30978
30979 /* The actual obj->write_domain will be updated with
30980 * pending_write_domain after we emit the accumulated flush for all
30981 @@ -907,9 +907,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
30982
30983 static int
30984 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
30985 - int count)
30986 + unsigned int count)
30987 {
30988 - int i;
30989 + unsigned int i;
30990
30991 for (i = 0; i < count; i++) {
30992 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
30993 diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
30994 index 73fa3e1..ab2e9b9 100644
30995 --- a/drivers/gpu/drm/i915/i915_irq.c
30996 +++ b/drivers/gpu/drm/i915/i915_irq.c
30997 @@ -514,7 +514,7 @@ static irqreturn_t valleyview_irq_handler(DRM_IRQ_ARGS)
30998 u32 pipe_stats[I915_MAX_PIPES];
30999 bool blc_event;
31000
31001 - atomic_inc(&dev_priv->irq_received);
31002 + atomic_inc_unchecked(&dev_priv->irq_received);
31003
31004 while (true) {
31005 iir = I915_READ(VLV_IIR);
31006 @@ -661,7 +661,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
31007 irqreturn_t ret = IRQ_NONE;
31008 int i;
31009
31010 - atomic_inc(&dev_priv->irq_received);
31011 + atomic_inc_unchecked(&dev_priv->irq_received);
31012
31013 /* disable master interrupt before clearing iir */
31014 de_ier = I915_READ(DEIER);
31015 @@ -736,7 +736,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
31016 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
31017 u32 hotplug_mask;
31018
31019 - atomic_inc(&dev_priv->irq_received);
31020 + atomic_inc_unchecked(&dev_priv->irq_received);
31021
31022 /* disable master interrupt before clearing iir */
31023 de_ier = I915_READ(DEIER);
31024 @@ -1717,7 +1717,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
31025 {
31026 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
31027
31028 - atomic_set(&dev_priv->irq_received, 0);
31029 + atomic_set_unchecked(&dev_priv->irq_received, 0);
31030
31031 I915_WRITE(HWSTAM, 0xeffe);
31032
31033 @@ -1743,7 +1743,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
31034 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
31035 int pipe;
31036
31037 - atomic_set(&dev_priv->irq_received, 0);
31038 + atomic_set_unchecked(&dev_priv->irq_received, 0);
31039
31040 /* VLV magic */
31041 I915_WRITE(VLV_IMR, 0);
31042 @@ -2048,7 +2048,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
31043 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
31044 int pipe;
31045
31046 - atomic_set(&dev_priv->irq_received, 0);
31047 + atomic_set_unchecked(&dev_priv->irq_received, 0);
31048
31049 for_each_pipe(pipe)
31050 I915_WRITE(PIPESTAT(pipe), 0);
31051 @@ -2099,7 +2099,7 @@ static irqreturn_t i8xx_irq_handler(DRM_IRQ_ARGS)
31052 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
31053 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
31054
31055 - atomic_inc(&dev_priv->irq_received);
31056 + atomic_inc_unchecked(&dev_priv->irq_received);
31057
31058 iir = I915_READ16(IIR);
31059 if (iir == 0)
31060 @@ -2184,7 +2184,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
31061 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
31062 int pipe;
31063
31064 - atomic_set(&dev_priv->irq_received, 0);
31065 + atomic_set_unchecked(&dev_priv->irq_received, 0);
31066
31067 if (I915_HAS_HOTPLUG(dev)) {
31068 I915_WRITE(PORT_HOTPLUG_EN, 0);
31069 @@ -2279,7 +2279,7 @@ static irqreturn_t i915_irq_handler(DRM_IRQ_ARGS)
31070 };
31071 int pipe, ret = IRQ_NONE;
31072
31073 - atomic_inc(&dev_priv->irq_received);
31074 + atomic_inc_unchecked(&dev_priv->irq_received);
31075
31076 iir = I915_READ(IIR);
31077 do {
31078 @@ -2405,7 +2405,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
31079 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
31080 int pipe;
31081
31082 - atomic_set(&dev_priv->irq_received, 0);
31083 + atomic_set_unchecked(&dev_priv->irq_received, 0);
31084
31085 I915_WRITE(PORT_HOTPLUG_EN, 0);
31086 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
31087 @@ -2512,7 +2512,7 @@ static irqreturn_t i965_irq_handler(DRM_IRQ_ARGS)
31088 int irq_received;
31089 int ret = IRQ_NONE, pipe;
31090
31091 - atomic_inc(&dev_priv->irq_received);
31092 + atomic_inc_unchecked(&dev_priv->irq_received);
31093
31094 iir = I915_READ(IIR);
31095
31096 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
31097 index b634f6f..43c62f5 100644
31098 --- a/drivers/gpu/drm/i915/intel_display.c
31099 +++ b/drivers/gpu/drm/i915/intel_display.c
31100 @@ -2182,7 +2182,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
31101
31102 wait_event(dev_priv->pending_flip_queue,
31103 atomic_read(&dev_priv->mm.wedged) ||
31104 - atomic_read(&obj->pending_flip) == 0);
31105 + atomic_read_unchecked(&obj->pending_flip) == 0);
31106
31107 /* Big Hammer, we also need to ensure that any pending
31108 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
31109 @@ -6168,8 +6168,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
31110
31111 obj = work->old_fb_obj;
31112
31113 - atomic_clear_mask(1 << intel_crtc->plane,
31114 - &obj->pending_flip.counter);
31115 + atomic_clear_mask_unchecked(1 << intel_crtc->plane, &obj->pending_flip);
31116
31117 wake_up(&dev_priv->pending_flip_queue);
31118 schedule_work(&work->work);
31119 @@ -6515,7 +6514,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
31120 /* Block clients from rendering to the new back buffer until
31121 * the flip occurs and the object is no longer visible.
31122 */
31123 - atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
31124 + atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
31125
31126 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
31127 if (ret)
31128 @@ -6530,7 +6529,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
31129 return 0;
31130
31131 cleanup_pending:
31132 - atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
31133 + atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
31134 drm_gem_object_unreference(&work->old_fb_obj->base);
31135 drm_gem_object_unreference(&obj->base);
31136 mutex_unlock(&dev->struct_mutex);
31137 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
31138 index 54558a0..2d97005 100644
31139 --- a/drivers/gpu/drm/mga/mga_drv.h
31140 +++ b/drivers/gpu/drm/mga/mga_drv.h
31141 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
31142 u32 clear_cmd;
31143 u32 maccess;
31144
31145 - atomic_t vbl_received; /**< Number of vblanks received. */
31146 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
31147 wait_queue_head_t fence_queue;
31148 - atomic_t last_fence_retired;
31149 + atomic_unchecked_t last_fence_retired;
31150 u32 next_fence_to_post;
31151
31152 unsigned int fb_cpp;
31153 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
31154 index 2581202..f230a8d9 100644
31155 --- a/drivers/gpu/drm/mga/mga_irq.c
31156 +++ b/drivers/gpu/drm/mga/mga_irq.c
31157 @@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
31158 if (crtc != 0)
31159 return 0;
31160
31161 - return atomic_read(&dev_priv->vbl_received);
31162 + return atomic_read_unchecked(&dev_priv->vbl_received);
31163 }
31164
31165
31166 @@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
31167 /* VBLANK interrupt */
31168 if (status & MGA_VLINEPEN) {
31169 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
31170 - atomic_inc(&dev_priv->vbl_received);
31171 + atomic_inc_unchecked(&dev_priv->vbl_received);
31172 drm_handle_vblank(dev, 0);
31173 handled = 1;
31174 }
31175 @@ -79,7 +79,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
31176 if ((prim_start & ~0x03) != (prim_end & ~0x03))
31177 MGA_WRITE(MGA_PRIMEND, prim_end);
31178
31179 - atomic_inc(&dev_priv->last_fence_retired);
31180 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
31181 DRM_WAKEUP(&dev_priv->fence_queue);
31182 handled = 1;
31183 }
31184 @@ -130,7 +130,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
31185 * using fences.
31186 */
31187 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
31188 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
31189 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
31190 - *sequence) <= (1 << 23)));
31191
31192 *sequence = cur_fence;
31193 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
31194 index a0a3fe3..209bf10 100644
31195 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
31196 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
31197 @@ -5340,7 +5340,7 @@ parse_bit_U_tbl_entry(struct drm_device *dev, struct nvbios *bios,
31198 struct bit_table {
31199 const char id;
31200 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
31201 -};
31202 +} __no_const;
31203
31204 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
31205
31206 diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h
31207 index 4f2cc95..9c6c510 100644
31208 --- a/drivers/gpu/drm/nouveau/nouveau_drv.h
31209 +++ b/drivers/gpu/drm/nouveau/nouveau_drv.h
31210 @@ -302,7 +302,7 @@ struct nouveau_exec_engine {
31211 u32 handle, u16 class);
31212 void (*set_tile_region)(struct drm_device *dev, int i);
31213 void (*tlb_flush)(struct drm_device *, int engine);
31214 -};
31215 +} __no_const;
31216
31217 struct nouveau_instmem_engine {
31218 void *priv;
31219 @@ -324,13 +324,13 @@ struct nouveau_instmem_engine {
31220 struct nouveau_mc_engine {
31221 int (*init)(struct drm_device *dev);
31222 void (*takedown)(struct drm_device *dev);
31223 -};
31224 +} __no_const;
31225
31226 struct nouveau_timer_engine {
31227 int (*init)(struct drm_device *dev);
31228 void (*takedown)(struct drm_device *dev);
31229 uint64_t (*read)(struct drm_device *dev);
31230 -};
31231 +} __no_const;
31232
31233 struct nouveau_fb_engine {
31234 int num_tiles;
31235 @@ -547,7 +547,7 @@ struct nouveau_vram_engine {
31236 void (*put)(struct drm_device *, struct nouveau_mem **);
31237
31238 bool (*flags_valid)(struct drm_device *, u32 tile_flags);
31239 -};
31240 +} __no_const;
31241
31242 struct nouveau_engine {
31243 struct nouveau_instmem_engine instmem;
31244 @@ -693,7 +693,7 @@ struct drm_nouveau_private {
31245 struct drm_global_reference mem_global_ref;
31246 struct ttm_bo_global_ref bo_global_ref;
31247 struct ttm_bo_device bdev;
31248 - atomic_t validate_sequence;
31249 + atomic_unchecked_t validate_sequence;
31250 int (*move)(struct nouveau_channel *,
31251 struct ttm_buffer_object *,
31252 struct ttm_mem_reg *, struct ttm_mem_reg *);
31253 diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
31254 index af7cfb8..aadc2a3 100644
31255 --- a/drivers/gpu/drm/nouveau/nouveau_gem.c
31256 +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
31257 @@ -318,7 +318,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
31258 int trycnt = 0;
31259 int ret, i;
31260
31261 - sequence = atomic_add_return(1, &dev_priv->ttm.validate_sequence);
31262 + sequence = atomic_add_return_unchecked(1, &dev_priv->ttm.validate_sequence);
31263 retry:
31264 if (++trycnt > 100000) {
31265 NV_ERROR(dev, "%s failed and gave up.\n", __func__);
31266 diff --git a/drivers/gpu/drm/nouveau/nouveau_state.c b/drivers/gpu/drm/nouveau/nouveau_state.c
31267 index f5e9584..05934ba 100644
31268 --- a/drivers/gpu/drm/nouveau/nouveau_state.c
31269 +++ b/drivers/gpu/drm/nouveau/nouveau_state.c
31270 @@ -492,7 +492,7 @@ static bool nouveau_switcheroo_can_switch(struct pci_dev *pdev)
31271 bool can_switch;
31272
31273 spin_lock(&dev->count_lock);
31274 - can_switch = (dev->open_count == 0);
31275 + can_switch = (local_read(&dev->open_count) == 0);
31276 spin_unlock(&dev->count_lock);
31277 return can_switch;
31278 }
31279 diff --git a/drivers/gpu/drm/nouveau/nv50_sor.c b/drivers/gpu/drm/nouveau/nv50_sor.c
31280 index 93240bd..c490f60 100644
31281 --- a/drivers/gpu/drm/nouveau/nv50_sor.c
31282 +++ b/drivers/gpu/drm/nouveau/nv50_sor.c
31283 @@ -304,7 +304,7 @@ nv50_sor_dpms(struct drm_encoder *encoder, int mode)
31284 }
31285
31286 if (nv_encoder->dcb->type == OUTPUT_DP) {
31287 - struct dp_train_func func = {
31288 + static struct dp_train_func func = {
31289 .link_set = nv50_sor_dp_link_set,
31290 .train_set = nv50_sor_dp_train_set,
31291 .train_adj = nv50_sor_dp_train_adj
31292 diff --git a/drivers/gpu/drm/nouveau/nvd0_display.c b/drivers/gpu/drm/nouveau/nvd0_display.c
31293 index 8a2fc89..3a5cf40 100644
31294 --- a/drivers/gpu/drm/nouveau/nvd0_display.c
31295 +++ b/drivers/gpu/drm/nouveau/nvd0_display.c
31296 @@ -1367,7 +1367,7 @@ nvd0_sor_dpms(struct drm_encoder *encoder, int mode)
31297 nv_wait(dev, 0x61c030 + (or * 0x0800), 0x10000000, 0x00000000);
31298
31299 if (nv_encoder->dcb->type == OUTPUT_DP) {
31300 - struct dp_train_func func = {
31301 + static struct dp_train_func func = {
31302 .link_set = nvd0_sor_dp_link_set,
31303 .train_set = nvd0_sor_dp_train_set,
31304 .train_adj = nvd0_sor_dp_train_adj
31305 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
31306 index bcac90b..53bfc76 100644
31307 --- a/drivers/gpu/drm/r128/r128_cce.c
31308 +++ b/drivers/gpu/drm/r128/r128_cce.c
31309 @@ -378,7 +378,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
31310
31311 /* GH: Simple idle check.
31312 */
31313 - atomic_set(&dev_priv->idle_count, 0);
31314 + atomic_set_unchecked(&dev_priv->idle_count, 0);
31315
31316 /* We don't support anything other than bus-mastering ring mode,
31317 * but the ring can be in either AGP or PCI space for the ring
31318 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
31319 index 930c71b..499aded 100644
31320 --- a/drivers/gpu/drm/r128/r128_drv.h
31321 +++ b/drivers/gpu/drm/r128/r128_drv.h
31322 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
31323 int is_pci;
31324 unsigned long cce_buffers_offset;
31325
31326 - atomic_t idle_count;
31327 + atomic_unchecked_t idle_count;
31328
31329 int page_flipping;
31330 int current_page;
31331 u32 crtc_offset;
31332 u32 crtc_offset_cntl;
31333
31334 - atomic_t vbl_received;
31335 + atomic_unchecked_t vbl_received;
31336
31337 u32 color_fmt;
31338 unsigned int front_offset;
31339 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
31340 index 429d5a0..7e899ed 100644
31341 --- a/drivers/gpu/drm/r128/r128_irq.c
31342 +++ b/drivers/gpu/drm/r128/r128_irq.c
31343 @@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
31344 if (crtc != 0)
31345 return 0;
31346
31347 - return atomic_read(&dev_priv->vbl_received);
31348 + return atomic_read_unchecked(&dev_priv->vbl_received);
31349 }
31350
31351 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
31352 @@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
31353 /* VBLANK interrupt */
31354 if (status & R128_CRTC_VBLANK_INT) {
31355 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
31356 - atomic_inc(&dev_priv->vbl_received);
31357 + atomic_inc_unchecked(&dev_priv->vbl_received);
31358 drm_handle_vblank(dev, 0);
31359 return IRQ_HANDLED;
31360 }
31361 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
31362 index a9e33ce..09edd4b 100644
31363 --- a/drivers/gpu/drm/r128/r128_state.c
31364 +++ b/drivers/gpu/drm/r128/r128_state.c
31365 @@ -321,10 +321,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
31366
31367 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
31368 {
31369 - if (atomic_read(&dev_priv->idle_count) == 0)
31370 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
31371 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
31372 else
31373 - atomic_set(&dev_priv->idle_count, 0);
31374 + atomic_set_unchecked(&dev_priv->idle_count, 0);
31375 }
31376
31377 #endif
31378 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
31379 index 5a82b6b..9e69c73 100644
31380 --- a/drivers/gpu/drm/radeon/mkregtable.c
31381 +++ b/drivers/gpu/drm/radeon/mkregtable.c
31382 @@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
31383 regex_t mask_rex;
31384 regmatch_t match[4];
31385 char buf[1024];
31386 - size_t end;
31387 + long end;
31388 int len;
31389 int done = 0;
31390 int r;
31391 unsigned o;
31392 struct offset *offset;
31393 char last_reg_s[10];
31394 - int last_reg;
31395 + unsigned long last_reg;
31396
31397 if (regcomp
31398 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
31399 diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
31400 index 59a1531..3bab49b 100644
31401 --- a/drivers/gpu/drm/radeon/radeon.h
31402 +++ b/drivers/gpu/drm/radeon/radeon.h
31403 @@ -711,7 +711,7 @@ struct r600_blit_cp_primitives {
31404 int x2, int y2);
31405 void (*draw_auto)(struct radeon_device *rdev);
31406 void (*set_default_state)(struct radeon_device *rdev);
31407 -};
31408 +} __no_const;
31409
31410 struct r600_blit {
31411 struct radeon_bo *shader_obj;
31412 @@ -1216,7 +1216,7 @@ struct radeon_asic {
31413 u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
31414 void (*post_page_flip)(struct radeon_device *rdev, int crtc);
31415 } pflip;
31416 -};
31417 +} __no_const;
31418
31419 /*
31420 * Asic structures
31421 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
31422 index 7a3daeb..5016171 100644
31423 --- a/drivers/gpu/drm/radeon/radeon_device.c
31424 +++ b/drivers/gpu/drm/radeon/radeon_device.c
31425 @@ -952,7 +952,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
31426 bool can_switch;
31427
31428 spin_lock(&dev->count_lock);
31429 - can_switch = (dev->open_count == 0);
31430 + can_switch = (local_read(&dev->open_count) == 0);
31431 spin_unlock(&dev->count_lock);
31432 return can_switch;
31433 }
31434 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
31435 index a1b59ca..86f2d44 100644
31436 --- a/drivers/gpu/drm/radeon/radeon_drv.h
31437 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
31438 @@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
31439
31440 /* SW interrupt */
31441 wait_queue_head_t swi_queue;
31442 - atomic_t swi_emitted;
31443 + atomic_unchecked_t swi_emitted;
31444 int vblank_crtc;
31445 uint32_t irq_enable_reg;
31446 uint32_t r500_disp_irq_reg;
31447 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
31448 index 48b7cea..342236f 100644
31449 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
31450 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
31451 @@ -359,7 +359,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
31452 request = compat_alloc_user_space(sizeof(*request));
31453 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
31454 || __put_user(req32.param, &request->param)
31455 - || __put_user((void __user *)(unsigned long)req32.value,
31456 + || __put_user((unsigned long)req32.value,
31457 &request->value))
31458 return -EFAULT;
31459
31460 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
31461 index 00da384..32f972d 100644
31462 --- a/drivers/gpu/drm/radeon/radeon_irq.c
31463 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
31464 @@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_device * dev)
31465 unsigned int ret;
31466 RING_LOCALS;
31467
31468 - atomic_inc(&dev_priv->swi_emitted);
31469 - ret = atomic_read(&dev_priv->swi_emitted);
31470 + atomic_inc_unchecked(&dev_priv->swi_emitted);
31471 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
31472
31473 BEGIN_RING(4);
31474 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
31475 @@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
31476 drm_radeon_private_t *dev_priv =
31477 (drm_radeon_private_t *) dev->dev_private;
31478
31479 - atomic_set(&dev_priv->swi_emitted, 0);
31480 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
31481 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
31482
31483 dev->max_vblank_count = 0x001fffff;
31484 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
31485 index e8422ae..d22d4a8 100644
31486 --- a/drivers/gpu/drm/radeon/radeon_state.c
31487 +++ b/drivers/gpu/drm/radeon/radeon_state.c
31488 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
31489 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
31490 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
31491
31492 - if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
31493 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
31494 sarea_priv->nbox * sizeof(depth_boxes[0])))
31495 return -EFAULT;
31496
31497 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
31498 {
31499 drm_radeon_private_t *dev_priv = dev->dev_private;
31500 drm_radeon_getparam_t *param = data;
31501 - int value;
31502 + int value = 0;
31503
31504 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
31505
31506 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
31507 index 5b71c71..650f9e4 100644
31508 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
31509 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
31510 @@ -822,8 +822,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
31511 }
31512 if (unlikely(ttm_vm_ops == NULL)) {
31513 ttm_vm_ops = vma->vm_ops;
31514 - radeon_ttm_vm_ops = *ttm_vm_ops;
31515 - radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
31516 + pax_open_kernel();
31517 + memcpy((void *)&radeon_ttm_vm_ops, ttm_vm_ops, sizeof(radeon_ttm_vm_ops));
31518 + *(void **)&radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
31519 + pax_close_kernel();
31520 }
31521 vma->vm_ops = &radeon_ttm_vm_ops;
31522 return 0;
31523 diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
31524 index 3b663fc..57850f4 100644
31525 --- a/drivers/gpu/drm/radeon/rs690.c
31526 +++ b/drivers/gpu/drm/radeon/rs690.c
31527 @@ -304,9 +304,11 @@ void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
31528 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
31529 rdev->pm.sideport_bandwidth.full)
31530 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
31531 - read_delay_latency.full = dfixed_const(370 * 800 * 1000);
31532 + read_delay_latency.full = dfixed_const(800 * 1000);
31533 read_delay_latency.full = dfixed_div(read_delay_latency,
31534 rdev->pm.igp_sideport_mclk);
31535 + a.full = dfixed_const(370);
31536 + read_delay_latency.full = dfixed_mul(read_delay_latency, a);
31537 } else {
31538 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
31539 rdev->pm.k8_bandwidth.full)
31540 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31541 index 578207e..1073f25 100644
31542 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
31543 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31544 @@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
31545 static int ttm_pool_mm_shrink(struct shrinker *shrink,
31546 struct shrink_control *sc)
31547 {
31548 - static atomic_t start_pool = ATOMIC_INIT(0);
31549 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
31550 unsigned i;
31551 - unsigned pool_offset = atomic_add_return(1, &start_pool);
31552 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
31553 struct ttm_page_pool *pool;
31554 int shrink_pages = sc->nr_to_scan;
31555
31556 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
31557 index 88edacc..1e5412b 100644
31558 --- a/drivers/gpu/drm/via/via_drv.h
31559 +++ b/drivers/gpu/drm/via/via_drv.h
31560 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
31561 typedef uint32_t maskarray_t[5];
31562
31563 typedef struct drm_via_irq {
31564 - atomic_t irq_received;
31565 + atomic_unchecked_t irq_received;
31566 uint32_t pending_mask;
31567 uint32_t enable_mask;
31568 wait_queue_head_t irq_queue;
31569 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
31570 struct timeval last_vblank;
31571 int last_vblank_valid;
31572 unsigned usec_per_vblank;
31573 - atomic_t vbl_received;
31574 + atomic_unchecked_t vbl_received;
31575 drm_via_state_t hc_state;
31576 char pci_buf[VIA_PCI_BUF_SIZE];
31577 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
31578 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
31579 index d391f48..10c8ca3 100644
31580 --- a/drivers/gpu/drm/via/via_irq.c
31581 +++ b/drivers/gpu/drm/via/via_irq.c
31582 @@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
31583 if (crtc != 0)
31584 return 0;
31585
31586 - return atomic_read(&dev_priv->vbl_received);
31587 + return atomic_read_unchecked(&dev_priv->vbl_received);
31588 }
31589
31590 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31591 @@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31592
31593 status = VIA_READ(VIA_REG_INTERRUPT);
31594 if (status & VIA_IRQ_VBLANK_PENDING) {
31595 - atomic_inc(&dev_priv->vbl_received);
31596 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
31597 + atomic_inc_unchecked(&dev_priv->vbl_received);
31598 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
31599 do_gettimeofday(&cur_vblank);
31600 if (dev_priv->last_vblank_valid) {
31601 dev_priv->usec_per_vblank =
31602 @@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31603 dev_priv->last_vblank = cur_vblank;
31604 dev_priv->last_vblank_valid = 1;
31605 }
31606 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
31607 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
31608 DRM_DEBUG("US per vblank is: %u\n",
31609 dev_priv->usec_per_vblank);
31610 }
31611 @@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31612
31613 for (i = 0; i < dev_priv->num_irqs; ++i) {
31614 if (status & cur_irq->pending_mask) {
31615 - atomic_inc(&cur_irq->irq_received);
31616 + atomic_inc_unchecked(&cur_irq->irq_received);
31617 DRM_WAKEUP(&cur_irq->irq_queue);
31618 handled = 1;
31619 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
31620 @@ -243,11 +243,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
31621 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31622 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
31623 masks[irq][4]));
31624 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
31625 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
31626 } else {
31627 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31628 (((cur_irq_sequence =
31629 - atomic_read(&cur_irq->irq_received)) -
31630 + atomic_read_unchecked(&cur_irq->irq_received)) -
31631 *sequence) <= (1 << 23)));
31632 }
31633 *sequence = cur_irq_sequence;
31634 @@ -285,7 +285,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
31635 }
31636
31637 for (i = 0; i < dev_priv->num_irqs; ++i) {
31638 - atomic_set(&cur_irq->irq_received, 0);
31639 + atomic_set_unchecked(&cur_irq->irq_received, 0);
31640 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
31641 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
31642 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
31643 @@ -367,7 +367,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
31644 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
31645 case VIA_IRQ_RELATIVE:
31646 irqwait->request.sequence +=
31647 - atomic_read(&cur_irq->irq_received);
31648 + atomic_read_unchecked(&cur_irq->irq_received);
31649 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
31650 case VIA_IRQ_ABSOLUTE:
31651 break;
31652 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31653 index 29c984f..4084f1a 100644
31654 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31655 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31656 @@ -263,7 +263,7 @@ struct vmw_private {
31657 * Fencing and IRQs.
31658 */
31659
31660 - atomic_t marker_seq;
31661 + atomic_unchecked_t marker_seq;
31662 wait_queue_head_t fence_queue;
31663 wait_queue_head_t fifo_queue;
31664 int fence_queue_waiters; /* Protected by hw_mutex */
31665 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31666 index a0c2f12..68ae6cb 100644
31667 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31668 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31669 @@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
31670 (unsigned int) min,
31671 (unsigned int) fifo->capabilities);
31672
31673 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31674 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31675 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
31676 vmw_marker_queue_init(&fifo->marker_queue);
31677 return vmw_fifo_send_fence(dev_priv, &dummy);
31678 @@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
31679 if (reserveable)
31680 iowrite32(bytes, fifo_mem +
31681 SVGA_FIFO_RESERVED);
31682 - return fifo_mem + (next_cmd >> 2);
31683 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
31684 } else {
31685 need_bounce = true;
31686 }
31687 @@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31688
31689 fm = vmw_fifo_reserve(dev_priv, bytes);
31690 if (unlikely(fm == NULL)) {
31691 - *seqno = atomic_read(&dev_priv->marker_seq);
31692 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31693 ret = -ENOMEM;
31694 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
31695 false, 3*HZ);
31696 @@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31697 }
31698
31699 do {
31700 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
31701 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
31702 } while (*seqno == 0);
31703
31704 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
31705 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31706 index cabc95f..14b3d77 100644
31707 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31708 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31709 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
31710 * emitted. Then the fence is stale and signaled.
31711 */
31712
31713 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
31714 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
31715 > VMW_FENCE_WRAP);
31716
31717 return ret;
31718 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
31719
31720 if (fifo_idle)
31721 down_read(&fifo_state->rwsem);
31722 - signal_seq = atomic_read(&dev_priv->marker_seq);
31723 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
31724 ret = 0;
31725
31726 for (;;) {
31727 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31728 index 8a8725c..afed796 100644
31729 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31730 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31731 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
31732 while (!vmw_lag_lt(queue, us)) {
31733 spin_lock(&queue->lock);
31734 if (list_empty(&queue->head))
31735 - seqno = atomic_read(&dev_priv->marker_seq);
31736 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31737 else {
31738 marker = list_first_entry(&queue->head,
31739 struct vmw_marker, head);
31740 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
31741 index 5de3bb3..08e5063 100644
31742 --- a/drivers/hid/hid-core.c
31743 +++ b/drivers/hid/hid-core.c
31744 @@ -2177,7 +2177,7 @@ static bool hid_ignore(struct hid_device *hdev)
31745
31746 int hid_add_device(struct hid_device *hdev)
31747 {
31748 - static atomic_t id = ATOMIC_INIT(0);
31749 + static atomic_unchecked_t id = ATOMIC_INIT(0);
31750 int ret;
31751
31752 if (WARN_ON(hdev->status & HID_STAT_ADDED))
31753 @@ -2212,7 +2212,7 @@ int hid_add_device(struct hid_device *hdev)
31754 /* XXX hack, any other cleaner solution after the driver core
31755 * is converted to allow more than 20 bytes as the device name? */
31756 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
31757 - hdev->vendor, hdev->product, atomic_inc_return(&id));
31758 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
31759
31760 hid_debug_register(hdev, dev_name(&hdev->dev));
31761 ret = device_add(&hdev->dev);
31762 diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
31763 index eec3291..8ed706b 100644
31764 --- a/drivers/hid/hid-wiimote-debug.c
31765 +++ b/drivers/hid/hid-wiimote-debug.c
31766 @@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
31767 else if (size == 0)
31768 return -EIO;
31769
31770 - if (copy_to_user(u, buf, size))
31771 + if (size > sizeof(buf) || copy_to_user(u, buf, size))
31772 return -EFAULT;
31773
31774 *off += size;
31775 diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
31776 index 14599e2..711c965 100644
31777 --- a/drivers/hid/usbhid/hiddev.c
31778 +++ b/drivers/hid/usbhid/hiddev.c
31779 @@ -625,7 +625,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
31780 break;
31781
31782 case HIDIOCAPPLICATION:
31783 - if (arg < 0 || arg >= hid->maxapplication)
31784 + if (arg >= hid->maxapplication)
31785 break;
31786
31787 for (i = 0; i < hid->maxcollection; i++)
31788 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
31789 index f4c3d28..82f45a9 100644
31790 --- a/drivers/hv/channel.c
31791 +++ b/drivers/hv/channel.c
31792 @@ -402,8 +402,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
31793 int ret = 0;
31794 int t;
31795
31796 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
31797 - atomic_inc(&vmbus_connection.next_gpadl_handle);
31798 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
31799 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
31800
31801 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
31802 if (ret)
31803 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
31804 index 86f8885..ab9cb2b 100644
31805 --- a/drivers/hv/hv.c
31806 +++ b/drivers/hv/hv.c
31807 @@ -132,7 +132,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
31808 u64 output_address = (output) ? virt_to_phys(output) : 0;
31809 u32 output_address_hi = output_address >> 32;
31810 u32 output_address_lo = output_address & 0xFFFFFFFF;
31811 - void *hypercall_page = hv_context.hypercall_page;
31812 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
31813
31814 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
31815 "=a"(hv_status_lo) : "d" (control_hi),
31816 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
31817 index 0614ff3..f0b2b5c 100644
31818 --- a/drivers/hv/hyperv_vmbus.h
31819 +++ b/drivers/hv/hyperv_vmbus.h
31820 @@ -555,7 +555,7 @@ enum vmbus_connect_state {
31821 struct vmbus_connection {
31822 enum vmbus_connect_state conn_state;
31823
31824 - atomic_t next_gpadl_handle;
31825 + atomic_unchecked_t next_gpadl_handle;
31826
31827 /*
31828 * Represents channel interrupts. Each bit position represents a
31829 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
31830 index 4748086..3abf845 100644
31831 --- a/drivers/hv/vmbus_drv.c
31832 +++ b/drivers/hv/vmbus_drv.c
31833 @@ -662,10 +662,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
31834 {
31835 int ret = 0;
31836
31837 - static atomic_t device_num = ATOMIC_INIT(0);
31838 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
31839
31840 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
31841 - atomic_inc_return(&device_num));
31842 + atomic_inc_return_unchecked(&device_num));
31843
31844 child_device_obj->device.bus = &hv_bus;
31845 child_device_obj->device.parent = &hv_acpi_dev->dev;
31846 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
31847 index 8b011d0..3de24a1 100644
31848 --- a/drivers/hwmon/sht15.c
31849 +++ b/drivers/hwmon/sht15.c
31850 @@ -166,7 +166,7 @@ struct sht15_data {
31851 int supply_uV;
31852 bool supply_uV_valid;
31853 struct work_struct update_supply_work;
31854 - atomic_t interrupt_handled;
31855 + atomic_unchecked_t interrupt_handled;
31856 };
31857
31858 /**
31859 @@ -509,13 +509,13 @@ static int sht15_measurement(struct sht15_data *data,
31860 return ret;
31861
31862 gpio_direction_input(data->pdata->gpio_data);
31863 - atomic_set(&data->interrupt_handled, 0);
31864 + atomic_set_unchecked(&data->interrupt_handled, 0);
31865
31866 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31867 if (gpio_get_value(data->pdata->gpio_data) == 0) {
31868 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
31869 /* Only relevant if the interrupt hasn't occurred. */
31870 - if (!atomic_read(&data->interrupt_handled))
31871 + if (!atomic_read_unchecked(&data->interrupt_handled))
31872 schedule_work(&data->read_work);
31873 }
31874 ret = wait_event_timeout(data->wait_queue,
31875 @@ -782,7 +782,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
31876
31877 /* First disable the interrupt */
31878 disable_irq_nosync(irq);
31879 - atomic_inc(&data->interrupt_handled);
31880 + atomic_inc_unchecked(&data->interrupt_handled);
31881 /* Then schedule a reading work struct */
31882 if (data->state != SHT15_READING_NOTHING)
31883 schedule_work(&data->read_work);
31884 @@ -804,11 +804,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
31885 * If not, then start the interrupt again - care here as could
31886 * have gone low in meantime so verify it hasn't!
31887 */
31888 - atomic_set(&data->interrupt_handled, 0);
31889 + atomic_set_unchecked(&data->interrupt_handled, 0);
31890 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31891 /* If still not occurred or another handler was scheduled */
31892 if (gpio_get_value(data->pdata->gpio_data)
31893 - || atomic_read(&data->interrupt_handled))
31894 + || atomic_read_unchecked(&data->interrupt_handled))
31895 return;
31896 }
31897
31898 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
31899 index 378fcb5..5e91fa8 100644
31900 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
31901 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
31902 @@ -43,7 +43,7 @@
31903 extern struct i2c_adapter amd756_smbus;
31904
31905 static struct i2c_adapter *s4882_adapter;
31906 -static struct i2c_algorithm *s4882_algo;
31907 +static i2c_algorithm_no_const *s4882_algo;
31908
31909 /* Wrapper access functions for multiplexed SMBus */
31910 static DEFINE_MUTEX(amd756_lock);
31911 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
31912 index 29015eb..af2d8e9 100644
31913 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
31914 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
31915 @@ -41,7 +41,7 @@
31916 extern struct i2c_adapter *nforce2_smbus;
31917
31918 static struct i2c_adapter *s4985_adapter;
31919 -static struct i2c_algorithm *s4985_algo;
31920 +static i2c_algorithm_no_const *s4985_algo;
31921
31922 /* Wrapper access functions for multiplexed SMBus */
31923 static DEFINE_MUTEX(nforce2_lock);
31924 diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
31925 index 1038c38..eb92f51 100644
31926 --- a/drivers/i2c/i2c-mux.c
31927 +++ b/drivers/i2c/i2c-mux.c
31928 @@ -30,7 +30,7 @@
31929 /* multiplexer per channel data */
31930 struct i2c_mux_priv {
31931 struct i2c_adapter adap;
31932 - struct i2c_algorithm algo;
31933 + i2c_algorithm_no_const algo;
31934
31935 struct i2c_adapter *parent;
31936 void *mux_priv; /* the mux chip/device */
31937 diff --git a/drivers/ide/aec62xx.c b/drivers/ide/aec62xx.c
31938 index 57d00ca..0145194 100644
31939 --- a/drivers/ide/aec62xx.c
31940 +++ b/drivers/ide/aec62xx.c
31941 @@ -181,7 +181,7 @@ static const struct ide_port_ops atp86x_port_ops = {
31942 .cable_detect = atp86x_cable_detect,
31943 };
31944
31945 -static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
31946 +static const struct ide_port_info aec62xx_chipsets[] __devinitconst = {
31947 { /* 0: AEC6210 */
31948 .name = DRV_NAME,
31949 .init_chipset = init_chipset_aec62xx,
31950 diff --git a/drivers/ide/alim15x3.c b/drivers/ide/alim15x3.c
31951 index 2c8016a..911a27c 100644
31952 --- a/drivers/ide/alim15x3.c
31953 +++ b/drivers/ide/alim15x3.c
31954 @@ -512,7 +512,7 @@ static const struct ide_dma_ops ali_dma_ops = {
31955 .dma_sff_read_status = ide_dma_sff_read_status,
31956 };
31957
31958 -static const struct ide_port_info ali15x3_chipset __devinitdata = {
31959 +static const struct ide_port_info ali15x3_chipset __devinitconst = {
31960 .name = DRV_NAME,
31961 .init_chipset = init_chipset_ali15x3,
31962 .init_hwif = init_hwif_ali15x3,
31963 diff --git a/drivers/ide/amd74xx.c b/drivers/ide/amd74xx.c
31964 index 3747b25..56fc995 100644
31965 --- a/drivers/ide/amd74xx.c
31966 +++ b/drivers/ide/amd74xx.c
31967 @@ -223,7 +223,7 @@ static const struct ide_port_ops amd_port_ops = {
31968 .udma_mask = udma, \
31969 }
31970
31971 -static const struct ide_port_info amd74xx_chipsets[] __devinitdata = {
31972 +static const struct ide_port_info amd74xx_chipsets[] __devinitconst = {
31973 /* 0: AMD7401 */ DECLARE_AMD_DEV(0x00, ATA_UDMA2),
31974 /* 1: AMD7409 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA4),
31975 /* 2: AMD7411/7441 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA5),
31976 diff --git a/drivers/ide/atiixp.c b/drivers/ide/atiixp.c
31977 index 15f0ead..cb43480 100644
31978 --- a/drivers/ide/atiixp.c
31979 +++ b/drivers/ide/atiixp.c
31980 @@ -139,7 +139,7 @@ static const struct ide_port_ops atiixp_port_ops = {
31981 .cable_detect = atiixp_cable_detect,
31982 };
31983
31984 -static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
31985 +static const struct ide_port_info atiixp_pci_info[] __devinitconst = {
31986 { /* 0: IXP200/300/400/700 */
31987 .name = DRV_NAME,
31988 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
31989 diff --git a/drivers/ide/cmd64x.c b/drivers/ide/cmd64x.c
31990 index 5f80312..d1fc438 100644
31991 --- a/drivers/ide/cmd64x.c
31992 +++ b/drivers/ide/cmd64x.c
31993 @@ -327,7 +327,7 @@ static const struct ide_dma_ops cmd646_rev1_dma_ops = {
31994 .dma_sff_read_status = ide_dma_sff_read_status,
31995 };
31996
31997 -static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
31998 +static const struct ide_port_info cmd64x_chipsets[] __devinitconst = {
31999 { /* 0: CMD643 */
32000 .name = DRV_NAME,
32001 .init_chipset = init_chipset_cmd64x,
32002 diff --git a/drivers/ide/cs5520.c b/drivers/ide/cs5520.c
32003 index 2c1e5f7..1444762 100644
32004 --- a/drivers/ide/cs5520.c
32005 +++ b/drivers/ide/cs5520.c
32006 @@ -94,7 +94,7 @@ static const struct ide_port_ops cs5520_port_ops = {
32007 .set_dma_mode = cs5520_set_dma_mode,
32008 };
32009
32010 -static const struct ide_port_info cyrix_chipset __devinitdata = {
32011 +static const struct ide_port_info cyrix_chipset __devinitconst = {
32012 .name = DRV_NAME,
32013 .enablebits = { { 0x60, 0x01, 0x01 }, { 0x60, 0x02, 0x02 } },
32014 .port_ops = &cs5520_port_ops,
32015 diff --git a/drivers/ide/cs5530.c b/drivers/ide/cs5530.c
32016 index 4dc4eb9..49b40ad 100644
32017 --- a/drivers/ide/cs5530.c
32018 +++ b/drivers/ide/cs5530.c
32019 @@ -245,7 +245,7 @@ static const struct ide_port_ops cs5530_port_ops = {
32020 .udma_filter = cs5530_udma_filter,
32021 };
32022
32023 -static const struct ide_port_info cs5530_chipset __devinitdata = {
32024 +static const struct ide_port_info cs5530_chipset __devinitconst = {
32025 .name = DRV_NAME,
32026 .init_chipset = init_chipset_cs5530,
32027 .init_hwif = init_hwif_cs5530,
32028 diff --git a/drivers/ide/cs5535.c b/drivers/ide/cs5535.c
32029 index 5059faf..18d4c85 100644
32030 --- a/drivers/ide/cs5535.c
32031 +++ b/drivers/ide/cs5535.c
32032 @@ -170,7 +170,7 @@ static const struct ide_port_ops cs5535_port_ops = {
32033 .cable_detect = cs5535_cable_detect,
32034 };
32035
32036 -static const struct ide_port_info cs5535_chipset __devinitdata = {
32037 +static const struct ide_port_info cs5535_chipset __devinitconst = {
32038 .name = DRV_NAME,
32039 .port_ops = &cs5535_port_ops,
32040 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_POST_SET_MODE,
32041 diff --git a/drivers/ide/cy82c693.c b/drivers/ide/cy82c693.c
32042 index 847553f..3ffb49d 100644
32043 --- a/drivers/ide/cy82c693.c
32044 +++ b/drivers/ide/cy82c693.c
32045 @@ -163,7 +163,7 @@ static const struct ide_port_ops cy82c693_port_ops = {
32046 .set_dma_mode = cy82c693_set_dma_mode,
32047 };
32048
32049 -static const struct ide_port_info cy82c693_chipset __devinitdata = {
32050 +static const struct ide_port_info cy82c693_chipset __devinitconst = {
32051 .name = DRV_NAME,
32052 .init_iops = init_iops_cy82c693,
32053 .port_ops = &cy82c693_port_ops,
32054 diff --git a/drivers/ide/hpt366.c b/drivers/ide/hpt366.c
32055 index 58c51cd..4aec3b8 100644
32056 --- a/drivers/ide/hpt366.c
32057 +++ b/drivers/ide/hpt366.c
32058 @@ -443,7 +443,7 @@ static struct hpt_timings hpt37x_timings = {
32059 }
32060 };
32061
32062 -static const struct hpt_info hpt36x __devinitdata = {
32063 +static const struct hpt_info hpt36x __devinitconst = {
32064 .chip_name = "HPT36x",
32065 .chip_type = HPT36x,
32066 .udma_mask = HPT366_ALLOW_ATA66_3 ? (HPT366_ALLOW_ATA66_4 ? ATA_UDMA4 : ATA_UDMA3) : ATA_UDMA2,
32067 @@ -451,7 +451,7 @@ static const struct hpt_info hpt36x __devinitdata = {
32068 .timings = &hpt36x_timings
32069 };
32070
32071 -static const struct hpt_info hpt370 __devinitdata = {
32072 +static const struct hpt_info hpt370 __devinitconst = {
32073 .chip_name = "HPT370",
32074 .chip_type = HPT370,
32075 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
32076 @@ -459,7 +459,7 @@ static const struct hpt_info hpt370 __devinitdata = {
32077 .timings = &hpt37x_timings
32078 };
32079
32080 -static const struct hpt_info hpt370a __devinitdata = {
32081 +static const struct hpt_info hpt370a __devinitconst = {
32082 .chip_name = "HPT370A",
32083 .chip_type = HPT370A,
32084 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
32085 @@ -467,7 +467,7 @@ static const struct hpt_info hpt370a __devinitdata = {
32086 .timings = &hpt37x_timings
32087 };
32088
32089 -static const struct hpt_info hpt374 __devinitdata = {
32090 +static const struct hpt_info hpt374 __devinitconst = {
32091 .chip_name = "HPT374",
32092 .chip_type = HPT374,
32093 .udma_mask = ATA_UDMA5,
32094 @@ -475,7 +475,7 @@ static const struct hpt_info hpt374 __devinitdata = {
32095 .timings = &hpt37x_timings
32096 };
32097
32098 -static const struct hpt_info hpt372 __devinitdata = {
32099 +static const struct hpt_info hpt372 __devinitconst = {
32100 .chip_name = "HPT372",
32101 .chip_type = HPT372,
32102 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
32103 @@ -483,7 +483,7 @@ static const struct hpt_info hpt372 __devinitdata = {
32104 .timings = &hpt37x_timings
32105 };
32106
32107 -static const struct hpt_info hpt372a __devinitdata = {
32108 +static const struct hpt_info hpt372a __devinitconst = {
32109 .chip_name = "HPT372A",
32110 .chip_type = HPT372A,
32111 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
32112 @@ -491,7 +491,7 @@ static const struct hpt_info hpt372a __devinitdata = {
32113 .timings = &hpt37x_timings
32114 };
32115
32116 -static const struct hpt_info hpt302 __devinitdata = {
32117 +static const struct hpt_info hpt302 __devinitconst = {
32118 .chip_name = "HPT302",
32119 .chip_type = HPT302,
32120 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
32121 @@ -499,7 +499,7 @@ static const struct hpt_info hpt302 __devinitdata = {
32122 .timings = &hpt37x_timings
32123 };
32124
32125 -static const struct hpt_info hpt371 __devinitdata = {
32126 +static const struct hpt_info hpt371 __devinitconst = {
32127 .chip_name = "HPT371",
32128 .chip_type = HPT371,
32129 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
32130 @@ -507,7 +507,7 @@ static const struct hpt_info hpt371 __devinitdata = {
32131 .timings = &hpt37x_timings
32132 };
32133
32134 -static const struct hpt_info hpt372n __devinitdata = {
32135 +static const struct hpt_info hpt372n __devinitconst = {
32136 .chip_name = "HPT372N",
32137 .chip_type = HPT372N,
32138 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
32139 @@ -515,7 +515,7 @@ static const struct hpt_info hpt372n __devinitdata = {
32140 .timings = &hpt37x_timings
32141 };
32142
32143 -static const struct hpt_info hpt302n __devinitdata = {
32144 +static const struct hpt_info hpt302n __devinitconst = {
32145 .chip_name = "HPT302N",
32146 .chip_type = HPT302N,
32147 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
32148 @@ -523,7 +523,7 @@ static const struct hpt_info hpt302n __devinitdata = {
32149 .timings = &hpt37x_timings
32150 };
32151
32152 -static const struct hpt_info hpt371n __devinitdata = {
32153 +static const struct hpt_info hpt371n __devinitconst = {
32154 .chip_name = "HPT371N",
32155 .chip_type = HPT371N,
32156 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
32157 @@ -1361,7 +1361,7 @@ static const struct ide_dma_ops hpt36x_dma_ops = {
32158 .dma_sff_read_status = ide_dma_sff_read_status,
32159 };
32160
32161 -static const struct ide_port_info hpt366_chipsets[] __devinitdata = {
32162 +static const struct ide_port_info hpt366_chipsets[] __devinitconst = {
32163 { /* 0: HPT36x */
32164 .name = DRV_NAME,
32165 .init_chipset = init_chipset_hpt366,
32166 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
32167 index 8126824..55a2798 100644
32168 --- a/drivers/ide/ide-cd.c
32169 +++ b/drivers/ide/ide-cd.c
32170 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
32171 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
32172 if ((unsigned long)buf & alignment
32173 || blk_rq_bytes(rq) & q->dma_pad_mask
32174 - || object_is_on_stack(buf))
32175 + || object_starts_on_stack(buf))
32176 drive->dma = 0;
32177 }
32178 }
32179 diff --git a/drivers/ide/ide-pci-generic.c b/drivers/ide/ide-pci-generic.c
32180 index 7f56b73..dab5b67 100644
32181 --- a/drivers/ide/ide-pci-generic.c
32182 +++ b/drivers/ide/ide-pci-generic.c
32183 @@ -53,7 +53,7 @@ static const struct ide_port_ops netcell_port_ops = {
32184 .udma_mask = ATA_UDMA6, \
32185 }
32186
32187 -static const struct ide_port_info generic_chipsets[] __devinitdata = {
32188 +static const struct ide_port_info generic_chipsets[] __devinitconst = {
32189 /* 0: Unknown */
32190 DECLARE_GENERIC_PCI_DEV(0),
32191
32192 diff --git a/drivers/ide/it8172.c b/drivers/ide/it8172.c
32193 index 560e66d..d5dd180 100644
32194 --- a/drivers/ide/it8172.c
32195 +++ b/drivers/ide/it8172.c
32196 @@ -115,7 +115,7 @@ static const struct ide_port_ops it8172_port_ops = {
32197 .set_dma_mode = it8172_set_dma_mode,
32198 };
32199
32200 -static const struct ide_port_info it8172_port_info __devinitdata = {
32201 +static const struct ide_port_info it8172_port_info __devinitconst = {
32202 .name = DRV_NAME,
32203 .port_ops = &it8172_port_ops,
32204 .enablebits = { {0x41, 0x80, 0x80}, {0x00, 0x00, 0x00} },
32205 diff --git a/drivers/ide/it8213.c b/drivers/ide/it8213.c
32206 index 46816ba..1847aeb 100644
32207 --- a/drivers/ide/it8213.c
32208 +++ b/drivers/ide/it8213.c
32209 @@ -156,7 +156,7 @@ static const struct ide_port_ops it8213_port_ops = {
32210 .cable_detect = it8213_cable_detect,
32211 };
32212
32213 -static const struct ide_port_info it8213_chipset __devinitdata = {
32214 +static const struct ide_port_info it8213_chipset __devinitconst = {
32215 .name = DRV_NAME,
32216 .enablebits = { {0x41, 0x80, 0x80} },
32217 .port_ops = &it8213_port_ops,
32218 diff --git a/drivers/ide/it821x.c b/drivers/ide/it821x.c
32219 index 2e3169f..c5611db 100644
32220 --- a/drivers/ide/it821x.c
32221 +++ b/drivers/ide/it821x.c
32222 @@ -630,7 +630,7 @@ static const struct ide_port_ops it821x_port_ops = {
32223 .cable_detect = it821x_cable_detect,
32224 };
32225
32226 -static const struct ide_port_info it821x_chipset __devinitdata = {
32227 +static const struct ide_port_info it821x_chipset __devinitconst = {
32228 .name = DRV_NAME,
32229 .init_chipset = init_chipset_it821x,
32230 .init_hwif = init_hwif_it821x,
32231 diff --git a/drivers/ide/jmicron.c b/drivers/ide/jmicron.c
32232 index 74c2c4a..efddd7d 100644
32233 --- a/drivers/ide/jmicron.c
32234 +++ b/drivers/ide/jmicron.c
32235 @@ -102,7 +102,7 @@ static const struct ide_port_ops jmicron_port_ops = {
32236 .cable_detect = jmicron_cable_detect,
32237 };
32238
32239 -static const struct ide_port_info jmicron_chipset __devinitdata = {
32240 +static const struct ide_port_info jmicron_chipset __devinitconst = {
32241 .name = DRV_NAME,
32242 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
32243 .port_ops = &jmicron_port_ops,
32244 diff --git a/drivers/ide/ns87415.c b/drivers/ide/ns87415.c
32245 index 95327a2..73f78d8 100644
32246 --- a/drivers/ide/ns87415.c
32247 +++ b/drivers/ide/ns87415.c
32248 @@ -293,7 +293,7 @@ static const struct ide_dma_ops ns87415_dma_ops = {
32249 .dma_sff_read_status = superio_dma_sff_read_status,
32250 };
32251
32252 -static const struct ide_port_info ns87415_chipset __devinitdata = {
32253 +static const struct ide_port_info ns87415_chipset __devinitconst = {
32254 .name = DRV_NAME,
32255 .init_hwif = init_hwif_ns87415,
32256 .tp_ops = &ns87415_tp_ops,
32257 diff --git a/drivers/ide/opti621.c b/drivers/ide/opti621.c
32258 index 1a53a4c..39edc66 100644
32259 --- a/drivers/ide/opti621.c
32260 +++ b/drivers/ide/opti621.c
32261 @@ -131,7 +131,7 @@ static const struct ide_port_ops opti621_port_ops = {
32262 .set_pio_mode = opti621_set_pio_mode,
32263 };
32264
32265 -static const struct ide_port_info opti621_chipset __devinitdata = {
32266 +static const struct ide_port_info opti621_chipset __devinitconst = {
32267 .name = DRV_NAME,
32268 .enablebits = { {0x45, 0x80, 0x00}, {0x40, 0x08, 0x00} },
32269 .port_ops = &opti621_port_ops,
32270 diff --git a/drivers/ide/pdc202xx_new.c b/drivers/ide/pdc202xx_new.c
32271 index 9546fe2..2e5ceb6 100644
32272 --- a/drivers/ide/pdc202xx_new.c
32273 +++ b/drivers/ide/pdc202xx_new.c
32274 @@ -465,7 +465,7 @@ static const struct ide_port_ops pdcnew_port_ops = {
32275 .udma_mask = udma, \
32276 }
32277
32278 -static const struct ide_port_info pdcnew_chipsets[] __devinitdata = {
32279 +static const struct ide_port_info pdcnew_chipsets[] __devinitconst = {
32280 /* 0: PDC202{68,70} */ DECLARE_PDCNEW_DEV(ATA_UDMA5),
32281 /* 1: PDC202{69,71,75,76,77} */ DECLARE_PDCNEW_DEV(ATA_UDMA6),
32282 };
32283 diff --git a/drivers/ide/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c
32284 index 3a35ec6..5634510 100644
32285 --- a/drivers/ide/pdc202xx_old.c
32286 +++ b/drivers/ide/pdc202xx_old.c
32287 @@ -270,7 +270,7 @@ static const struct ide_dma_ops pdc2026x_dma_ops = {
32288 .max_sectors = sectors, \
32289 }
32290
32291 -static const struct ide_port_info pdc202xx_chipsets[] __devinitdata = {
32292 +static const struct ide_port_info pdc202xx_chipsets[] __devinitconst = {
32293 { /* 0: PDC20246 */
32294 .name = DRV_NAME,
32295 .init_chipset = init_chipset_pdc202xx,
32296 diff --git a/drivers/ide/piix.c b/drivers/ide/piix.c
32297 index 1892e81..fe0fd60 100644
32298 --- a/drivers/ide/piix.c
32299 +++ b/drivers/ide/piix.c
32300 @@ -344,7 +344,7 @@ static const struct ide_port_ops ich_port_ops = {
32301 .udma_mask = udma, \
32302 }
32303
32304 -static const struct ide_port_info piix_pci_info[] __devinitdata = {
32305 +static const struct ide_port_info piix_pci_info[] __devinitconst = {
32306 /* 0: MPIIX */
32307 { /*
32308 * MPIIX actually has only a single IDE channel mapped to
32309 diff --git a/drivers/ide/rz1000.c b/drivers/ide/rz1000.c
32310 index a6414a8..c04173e 100644
32311 --- a/drivers/ide/rz1000.c
32312 +++ b/drivers/ide/rz1000.c
32313 @@ -38,7 +38,7 @@ static int __devinit rz1000_disable_readahead(struct pci_dev *dev)
32314 }
32315 }
32316
32317 -static const struct ide_port_info rz1000_chipset __devinitdata = {
32318 +static const struct ide_port_info rz1000_chipset __devinitconst = {
32319 .name = DRV_NAME,
32320 .host_flags = IDE_HFLAG_NO_DMA,
32321 };
32322 diff --git a/drivers/ide/sc1200.c b/drivers/ide/sc1200.c
32323 index 356b9b5..d4758eb 100644
32324 --- a/drivers/ide/sc1200.c
32325 +++ b/drivers/ide/sc1200.c
32326 @@ -291,7 +291,7 @@ static const struct ide_dma_ops sc1200_dma_ops = {
32327 .dma_sff_read_status = ide_dma_sff_read_status,
32328 };
32329
32330 -static const struct ide_port_info sc1200_chipset __devinitdata = {
32331 +static const struct ide_port_info sc1200_chipset __devinitconst = {
32332 .name = DRV_NAME,
32333 .port_ops = &sc1200_port_ops,
32334 .dma_ops = &sc1200_dma_ops,
32335 diff --git a/drivers/ide/scc_pata.c b/drivers/ide/scc_pata.c
32336 index b7f5b0c..9701038 100644
32337 --- a/drivers/ide/scc_pata.c
32338 +++ b/drivers/ide/scc_pata.c
32339 @@ -811,7 +811,7 @@ static const struct ide_dma_ops scc_dma_ops = {
32340 .dma_sff_read_status = scc_dma_sff_read_status,
32341 };
32342
32343 -static const struct ide_port_info scc_chipset __devinitdata = {
32344 +static const struct ide_port_info scc_chipset __devinitconst = {
32345 .name = "sccIDE",
32346 .init_iops = init_iops_scc,
32347 .init_dma = scc_init_dma,
32348 diff --git a/drivers/ide/serverworks.c b/drivers/ide/serverworks.c
32349 index 35fb8da..24d72ef 100644
32350 --- a/drivers/ide/serverworks.c
32351 +++ b/drivers/ide/serverworks.c
32352 @@ -337,7 +337,7 @@ static const struct ide_port_ops svwks_port_ops = {
32353 .cable_detect = svwks_cable_detect,
32354 };
32355
32356 -static const struct ide_port_info serverworks_chipsets[] __devinitdata = {
32357 +static const struct ide_port_info serverworks_chipsets[] __devinitconst = {
32358 { /* 0: OSB4 */
32359 .name = DRV_NAME,
32360 .init_chipset = init_chipset_svwks,
32361 diff --git a/drivers/ide/siimage.c b/drivers/ide/siimage.c
32362 index ddeda44..46f7e30 100644
32363 --- a/drivers/ide/siimage.c
32364 +++ b/drivers/ide/siimage.c
32365 @@ -719,7 +719,7 @@ static const struct ide_dma_ops sil_dma_ops = {
32366 .udma_mask = ATA_UDMA6, \
32367 }
32368
32369 -static const struct ide_port_info siimage_chipsets[] __devinitdata = {
32370 +static const struct ide_port_info siimage_chipsets[] __devinitconst = {
32371 /* 0: SiI680 */ DECLARE_SII_DEV(&sil_pata_port_ops),
32372 /* 1: SiI3112 */ DECLARE_SII_DEV(&sil_sata_port_ops)
32373 };
32374 diff --git a/drivers/ide/sis5513.c b/drivers/ide/sis5513.c
32375 index 4a00225..09e61b4 100644
32376 --- a/drivers/ide/sis5513.c
32377 +++ b/drivers/ide/sis5513.c
32378 @@ -563,7 +563,7 @@ static const struct ide_port_ops sis_ata133_port_ops = {
32379 .cable_detect = sis_cable_detect,
32380 };
32381
32382 -static const struct ide_port_info sis5513_chipset __devinitdata = {
32383 +static const struct ide_port_info sis5513_chipset __devinitconst = {
32384 .name = DRV_NAME,
32385 .init_chipset = init_chipset_sis5513,
32386 .enablebits = { {0x4a, 0x02, 0x02}, {0x4a, 0x04, 0x04} },
32387 diff --git a/drivers/ide/sl82c105.c b/drivers/ide/sl82c105.c
32388 index f21dc2a..d051cd2 100644
32389 --- a/drivers/ide/sl82c105.c
32390 +++ b/drivers/ide/sl82c105.c
32391 @@ -299,7 +299,7 @@ static const struct ide_dma_ops sl82c105_dma_ops = {
32392 .dma_sff_read_status = ide_dma_sff_read_status,
32393 };
32394
32395 -static const struct ide_port_info sl82c105_chipset __devinitdata = {
32396 +static const struct ide_port_info sl82c105_chipset __devinitconst = {
32397 .name = DRV_NAME,
32398 .init_chipset = init_chipset_sl82c105,
32399 .enablebits = {{0x40,0x01,0x01}, {0x40,0x10,0x10}},
32400 diff --git a/drivers/ide/slc90e66.c b/drivers/ide/slc90e66.c
32401 index 864ffe0..863a5e9 100644
32402 --- a/drivers/ide/slc90e66.c
32403 +++ b/drivers/ide/slc90e66.c
32404 @@ -132,7 +132,7 @@ static const struct ide_port_ops slc90e66_port_ops = {
32405 .cable_detect = slc90e66_cable_detect,
32406 };
32407
32408 -static const struct ide_port_info slc90e66_chipset __devinitdata = {
32409 +static const struct ide_port_info slc90e66_chipset __devinitconst = {
32410 .name = DRV_NAME,
32411 .enablebits = { {0x41, 0x80, 0x80}, {0x43, 0x80, 0x80} },
32412 .port_ops = &slc90e66_port_ops,
32413 diff --git a/drivers/ide/tc86c001.c b/drivers/ide/tc86c001.c
32414 index 4799d5c..1794678 100644
32415 --- a/drivers/ide/tc86c001.c
32416 +++ b/drivers/ide/tc86c001.c
32417 @@ -192,7 +192,7 @@ static const struct ide_dma_ops tc86c001_dma_ops = {
32418 .dma_sff_read_status = ide_dma_sff_read_status,
32419 };
32420
32421 -static const struct ide_port_info tc86c001_chipset __devinitdata = {
32422 +static const struct ide_port_info tc86c001_chipset __devinitconst = {
32423 .name = DRV_NAME,
32424 .init_hwif = init_hwif_tc86c001,
32425 .port_ops = &tc86c001_port_ops,
32426 diff --git a/drivers/ide/triflex.c b/drivers/ide/triflex.c
32427 index 281c914..55ce1b8 100644
32428 --- a/drivers/ide/triflex.c
32429 +++ b/drivers/ide/triflex.c
32430 @@ -92,7 +92,7 @@ static const struct ide_port_ops triflex_port_ops = {
32431 .set_dma_mode = triflex_set_mode,
32432 };
32433
32434 -static const struct ide_port_info triflex_device __devinitdata = {
32435 +static const struct ide_port_info triflex_device __devinitconst = {
32436 .name = DRV_NAME,
32437 .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}},
32438 .port_ops = &triflex_port_ops,
32439 diff --git a/drivers/ide/trm290.c b/drivers/ide/trm290.c
32440 index 4b42ca0..e494a98 100644
32441 --- a/drivers/ide/trm290.c
32442 +++ b/drivers/ide/trm290.c
32443 @@ -324,7 +324,7 @@ static struct ide_dma_ops trm290_dma_ops = {
32444 .dma_check = trm290_dma_check,
32445 };
32446
32447 -static const struct ide_port_info trm290_chipset __devinitdata = {
32448 +static const struct ide_port_info trm290_chipset __devinitconst = {
32449 .name = DRV_NAME,
32450 .init_hwif = init_hwif_trm290,
32451 .tp_ops = &trm290_tp_ops,
32452 diff --git a/drivers/ide/via82cxxx.c b/drivers/ide/via82cxxx.c
32453 index f46f49c..eb77678 100644
32454 --- a/drivers/ide/via82cxxx.c
32455 +++ b/drivers/ide/via82cxxx.c
32456 @@ -403,7 +403,7 @@ static const struct ide_port_ops via_port_ops = {
32457 .cable_detect = via82cxxx_cable_detect,
32458 };
32459
32460 -static const struct ide_port_info via82cxxx_chipset __devinitdata = {
32461 +static const struct ide_port_info via82cxxx_chipset __devinitconst = {
32462 .name = DRV_NAME,
32463 .init_chipset = init_chipset_via82cxxx,
32464 .enablebits = { { 0x40, 0x02, 0x02 }, { 0x40, 0x01, 0x01 } },
32465 diff --git a/drivers/ieee802154/fakehard.c b/drivers/ieee802154/fakehard.c
32466 index 73d4531..c90cd2d 100644
32467 --- a/drivers/ieee802154/fakehard.c
32468 +++ b/drivers/ieee802154/fakehard.c
32469 @@ -386,7 +386,7 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
32470 phy->transmit_power = 0xbf;
32471
32472 dev->netdev_ops = &fake_ops;
32473 - dev->ml_priv = &fake_mlme;
32474 + dev->ml_priv = (void *)&fake_mlme;
32475
32476 priv = netdev_priv(dev);
32477 priv->phy = phy;
32478 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
32479 index d67999f..4c5d083 100644
32480 --- a/drivers/infiniband/core/cm.c
32481 +++ b/drivers/infiniband/core/cm.c
32482 @@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
32483
32484 struct cm_counter_group {
32485 struct kobject obj;
32486 - atomic_long_t counter[CM_ATTR_COUNT];
32487 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
32488 };
32489
32490 struct cm_counter_attribute {
32491 @@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
32492 struct ib_mad_send_buf *msg = NULL;
32493 int ret;
32494
32495 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32496 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32497 counter[CM_REQ_COUNTER]);
32498
32499 /* Quick state check to discard duplicate REQs. */
32500 @@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
32501 if (!cm_id_priv)
32502 return;
32503
32504 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32505 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32506 counter[CM_REP_COUNTER]);
32507 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
32508 if (ret)
32509 @@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
32510 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
32511 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
32512 spin_unlock_irq(&cm_id_priv->lock);
32513 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32514 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32515 counter[CM_RTU_COUNTER]);
32516 goto out;
32517 }
32518 @@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
32519 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
32520 dreq_msg->local_comm_id);
32521 if (!cm_id_priv) {
32522 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32523 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32524 counter[CM_DREQ_COUNTER]);
32525 cm_issue_drep(work->port, work->mad_recv_wc);
32526 return -EINVAL;
32527 @@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
32528 case IB_CM_MRA_REP_RCVD:
32529 break;
32530 case IB_CM_TIMEWAIT:
32531 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32532 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32533 counter[CM_DREQ_COUNTER]);
32534 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32535 goto unlock;
32536 @@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
32537 cm_free_msg(msg);
32538 goto deref;
32539 case IB_CM_DREQ_RCVD:
32540 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32541 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32542 counter[CM_DREQ_COUNTER]);
32543 goto unlock;
32544 default:
32545 @@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
32546 ib_modify_mad(cm_id_priv->av.port->mad_agent,
32547 cm_id_priv->msg, timeout)) {
32548 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
32549 - atomic_long_inc(&work->port->
32550 + atomic_long_inc_unchecked(&work->port->
32551 counter_group[CM_RECV_DUPLICATES].
32552 counter[CM_MRA_COUNTER]);
32553 goto out;
32554 @@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
32555 break;
32556 case IB_CM_MRA_REQ_RCVD:
32557 case IB_CM_MRA_REP_RCVD:
32558 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32559 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32560 counter[CM_MRA_COUNTER]);
32561 /* fall through */
32562 default:
32563 @@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
32564 case IB_CM_LAP_IDLE:
32565 break;
32566 case IB_CM_MRA_LAP_SENT:
32567 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32568 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32569 counter[CM_LAP_COUNTER]);
32570 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32571 goto unlock;
32572 @@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
32573 cm_free_msg(msg);
32574 goto deref;
32575 case IB_CM_LAP_RCVD:
32576 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32577 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32578 counter[CM_LAP_COUNTER]);
32579 goto unlock;
32580 default:
32581 @@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
32582 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
32583 if (cur_cm_id_priv) {
32584 spin_unlock_irq(&cm.lock);
32585 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32586 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32587 counter[CM_SIDR_REQ_COUNTER]);
32588 goto out; /* Duplicate message. */
32589 }
32590 @@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
32591 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
32592 msg->retries = 1;
32593
32594 - atomic_long_add(1 + msg->retries,
32595 + atomic_long_add_unchecked(1 + msg->retries,
32596 &port->counter_group[CM_XMIT].counter[attr_index]);
32597 if (msg->retries)
32598 - atomic_long_add(msg->retries,
32599 + atomic_long_add_unchecked(msg->retries,
32600 &port->counter_group[CM_XMIT_RETRIES].
32601 counter[attr_index]);
32602
32603 @@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
32604 }
32605
32606 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
32607 - atomic_long_inc(&port->counter_group[CM_RECV].
32608 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
32609 counter[attr_id - CM_ATTR_ID_OFFSET]);
32610
32611 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
32612 @@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
32613 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
32614
32615 return sprintf(buf, "%ld\n",
32616 - atomic_long_read(&group->counter[cm_attr->index]));
32617 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
32618 }
32619
32620 static const struct sysfs_ops cm_counter_ops = {
32621 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
32622 index 176c8f9..2627b62 100644
32623 --- a/drivers/infiniband/core/fmr_pool.c
32624 +++ b/drivers/infiniband/core/fmr_pool.c
32625 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
32626
32627 struct task_struct *thread;
32628
32629 - atomic_t req_ser;
32630 - atomic_t flush_ser;
32631 + atomic_unchecked_t req_ser;
32632 + atomic_unchecked_t flush_ser;
32633
32634 wait_queue_head_t force_wait;
32635 };
32636 @@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32637 struct ib_fmr_pool *pool = pool_ptr;
32638
32639 do {
32640 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
32641 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
32642 ib_fmr_batch_release(pool);
32643
32644 - atomic_inc(&pool->flush_ser);
32645 + atomic_inc_unchecked(&pool->flush_ser);
32646 wake_up_interruptible(&pool->force_wait);
32647
32648 if (pool->flush_function)
32649 @@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32650 }
32651
32652 set_current_state(TASK_INTERRUPTIBLE);
32653 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
32654 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
32655 !kthread_should_stop())
32656 schedule();
32657 __set_current_state(TASK_RUNNING);
32658 @@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
32659 pool->dirty_watermark = params->dirty_watermark;
32660 pool->dirty_len = 0;
32661 spin_lock_init(&pool->pool_lock);
32662 - atomic_set(&pool->req_ser, 0);
32663 - atomic_set(&pool->flush_ser, 0);
32664 + atomic_set_unchecked(&pool->req_ser, 0);
32665 + atomic_set_unchecked(&pool->flush_ser, 0);
32666 init_waitqueue_head(&pool->force_wait);
32667
32668 pool->thread = kthread_run(ib_fmr_cleanup_thread,
32669 @@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
32670 }
32671 spin_unlock_irq(&pool->pool_lock);
32672
32673 - serial = atomic_inc_return(&pool->req_ser);
32674 + serial = atomic_inc_return_unchecked(&pool->req_ser);
32675 wake_up_process(pool->thread);
32676
32677 if (wait_event_interruptible(pool->force_wait,
32678 - atomic_read(&pool->flush_ser) - serial >= 0))
32679 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
32680 return -EINTR;
32681
32682 return 0;
32683 @@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
32684 } else {
32685 list_add_tail(&fmr->list, &pool->dirty_list);
32686 if (++pool->dirty_len >= pool->dirty_watermark) {
32687 - atomic_inc(&pool->req_ser);
32688 + atomic_inc_unchecked(&pool->req_ser);
32689 wake_up_process(pool->thread);
32690 }
32691 }
32692 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
32693 index 57e07c6..56d09d4 100644
32694 --- a/drivers/infiniband/hw/cxgb4/mem.c
32695 +++ b/drivers/infiniband/hw/cxgb4/mem.c
32696 @@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32697 int err;
32698 struct fw_ri_tpte tpt;
32699 u32 stag_idx;
32700 - static atomic_t key;
32701 + static atomic_unchecked_t key;
32702
32703 if (c4iw_fatal_error(rdev))
32704 return -EIO;
32705 @@ -139,7 +139,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32706 if (rdev->stats.stag.cur > rdev->stats.stag.max)
32707 rdev->stats.stag.max = rdev->stats.stag.cur;
32708 mutex_unlock(&rdev->stats.lock);
32709 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
32710 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
32711 }
32712 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
32713 __func__, stag_state, type, pdid, stag_idx);
32714 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
32715 index 79b3dbc..96e5fcc 100644
32716 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
32717 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
32718 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32719 struct ib_atomic_eth *ateth;
32720 struct ipath_ack_entry *e;
32721 u64 vaddr;
32722 - atomic64_t *maddr;
32723 + atomic64_unchecked_t *maddr;
32724 u64 sdata;
32725 u32 rkey;
32726 u8 next;
32727 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32728 IB_ACCESS_REMOTE_ATOMIC)))
32729 goto nack_acc_unlck;
32730 /* Perform atomic OP and save result. */
32731 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32732 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32733 sdata = be64_to_cpu(ateth->swap_data);
32734 e = &qp->s_ack_queue[qp->r_head_ack_queue];
32735 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
32736 - (u64) atomic64_add_return(sdata, maddr) - sdata :
32737 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32738 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32739 be64_to_cpu(ateth->compare_data),
32740 sdata);
32741 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
32742 index 1f95bba..9530f87 100644
32743 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
32744 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
32745 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
32746 unsigned long flags;
32747 struct ib_wc wc;
32748 u64 sdata;
32749 - atomic64_t *maddr;
32750 + atomic64_unchecked_t *maddr;
32751 enum ib_wc_status send_status;
32752
32753 /*
32754 @@ -382,11 +382,11 @@ again:
32755 IB_ACCESS_REMOTE_ATOMIC)))
32756 goto acc_err;
32757 /* Perform atomic OP and save result. */
32758 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32759 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32760 sdata = wqe->wr.wr.atomic.compare_add;
32761 *(u64 *) sqp->s_sge.sge.vaddr =
32762 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
32763 - (u64) atomic64_add_return(sdata, maddr) - sdata :
32764 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32765 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32766 sdata, wqe->wr.wr.atomic.swap);
32767 goto send_comp;
32768 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
32769 index 7140199..da60063 100644
32770 --- a/drivers/infiniband/hw/nes/nes.c
32771 +++ b/drivers/infiniband/hw/nes/nes.c
32772 @@ -103,7 +103,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
32773 LIST_HEAD(nes_adapter_list);
32774 static LIST_HEAD(nes_dev_list);
32775
32776 -atomic_t qps_destroyed;
32777 +atomic_unchecked_t qps_destroyed;
32778
32779 static unsigned int ee_flsh_adapter;
32780 static unsigned int sysfs_nonidx_addr;
32781 @@ -272,7 +272,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
32782 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
32783 struct nes_adapter *nesadapter = nesdev->nesadapter;
32784
32785 - atomic_inc(&qps_destroyed);
32786 + atomic_inc_unchecked(&qps_destroyed);
32787
32788 /* Free the control structures */
32789
32790 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
32791 index c438e46..ca30356 100644
32792 --- a/drivers/infiniband/hw/nes/nes.h
32793 +++ b/drivers/infiniband/hw/nes/nes.h
32794 @@ -178,17 +178,17 @@ extern unsigned int nes_debug_level;
32795 extern unsigned int wqm_quanta;
32796 extern struct list_head nes_adapter_list;
32797
32798 -extern atomic_t cm_connects;
32799 -extern atomic_t cm_accepts;
32800 -extern atomic_t cm_disconnects;
32801 -extern atomic_t cm_closes;
32802 -extern atomic_t cm_connecteds;
32803 -extern atomic_t cm_connect_reqs;
32804 -extern atomic_t cm_rejects;
32805 -extern atomic_t mod_qp_timouts;
32806 -extern atomic_t qps_created;
32807 -extern atomic_t qps_destroyed;
32808 -extern atomic_t sw_qps_destroyed;
32809 +extern atomic_unchecked_t cm_connects;
32810 +extern atomic_unchecked_t cm_accepts;
32811 +extern atomic_unchecked_t cm_disconnects;
32812 +extern atomic_unchecked_t cm_closes;
32813 +extern atomic_unchecked_t cm_connecteds;
32814 +extern atomic_unchecked_t cm_connect_reqs;
32815 +extern atomic_unchecked_t cm_rejects;
32816 +extern atomic_unchecked_t mod_qp_timouts;
32817 +extern atomic_unchecked_t qps_created;
32818 +extern atomic_unchecked_t qps_destroyed;
32819 +extern atomic_unchecked_t sw_qps_destroyed;
32820 extern u32 mh_detected;
32821 extern u32 mh_pauses_sent;
32822 extern u32 cm_packets_sent;
32823 @@ -197,16 +197,16 @@ extern u32 cm_packets_created;
32824 extern u32 cm_packets_received;
32825 extern u32 cm_packets_dropped;
32826 extern u32 cm_packets_retrans;
32827 -extern atomic_t cm_listens_created;
32828 -extern atomic_t cm_listens_destroyed;
32829 +extern atomic_unchecked_t cm_listens_created;
32830 +extern atomic_unchecked_t cm_listens_destroyed;
32831 extern u32 cm_backlog_drops;
32832 -extern atomic_t cm_loopbacks;
32833 -extern atomic_t cm_nodes_created;
32834 -extern atomic_t cm_nodes_destroyed;
32835 -extern atomic_t cm_accel_dropped_pkts;
32836 -extern atomic_t cm_resets_recvd;
32837 -extern atomic_t pau_qps_created;
32838 -extern atomic_t pau_qps_destroyed;
32839 +extern atomic_unchecked_t cm_loopbacks;
32840 +extern atomic_unchecked_t cm_nodes_created;
32841 +extern atomic_unchecked_t cm_nodes_destroyed;
32842 +extern atomic_unchecked_t cm_accel_dropped_pkts;
32843 +extern atomic_unchecked_t cm_resets_recvd;
32844 +extern atomic_unchecked_t pau_qps_created;
32845 +extern atomic_unchecked_t pau_qps_destroyed;
32846
32847 extern u32 int_mod_timer_init;
32848 extern u32 int_mod_cq_depth_256;
32849 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
32850 index 020e95c..fbb3450 100644
32851 --- a/drivers/infiniband/hw/nes/nes_cm.c
32852 +++ b/drivers/infiniband/hw/nes/nes_cm.c
32853 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
32854 u32 cm_packets_retrans;
32855 u32 cm_packets_created;
32856 u32 cm_packets_received;
32857 -atomic_t cm_listens_created;
32858 -atomic_t cm_listens_destroyed;
32859 +atomic_unchecked_t cm_listens_created;
32860 +atomic_unchecked_t cm_listens_destroyed;
32861 u32 cm_backlog_drops;
32862 -atomic_t cm_loopbacks;
32863 -atomic_t cm_nodes_created;
32864 -atomic_t cm_nodes_destroyed;
32865 -atomic_t cm_accel_dropped_pkts;
32866 -atomic_t cm_resets_recvd;
32867 +atomic_unchecked_t cm_loopbacks;
32868 +atomic_unchecked_t cm_nodes_created;
32869 +atomic_unchecked_t cm_nodes_destroyed;
32870 +atomic_unchecked_t cm_accel_dropped_pkts;
32871 +atomic_unchecked_t cm_resets_recvd;
32872
32873 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
32874 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
32875 @@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
32876
32877 static struct nes_cm_core *g_cm_core;
32878
32879 -atomic_t cm_connects;
32880 -atomic_t cm_accepts;
32881 -atomic_t cm_disconnects;
32882 -atomic_t cm_closes;
32883 -atomic_t cm_connecteds;
32884 -atomic_t cm_connect_reqs;
32885 -atomic_t cm_rejects;
32886 +atomic_unchecked_t cm_connects;
32887 +atomic_unchecked_t cm_accepts;
32888 +atomic_unchecked_t cm_disconnects;
32889 +atomic_unchecked_t cm_closes;
32890 +atomic_unchecked_t cm_connecteds;
32891 +atomic_unchecked_t cm_connect_reqs;
32892 +atomic_unchecked_t cm_rejects;
32893
32894 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
32895 {
32896 @@ -1279,7 +1279,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
32897 kfree(listener);
32898 listener = NULL;
32899 ret = 0;
32900 - atomic_inc(&cm_listens_destroyed);
32901 + atomic_inc_unchecked(&cm_listens_destroyed);
32902 } else {
32903 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
32904 }
32905 @@ -1482,7 +1482,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
32906 cm_node->rem_mac);
32907
32908 add_hte_node(cm_core, cm_node);
32909 - atomic_inc(&cm_nodes_created);
32910 + atomic_inc_unchecked(&cm_nodes_created);
32911
32912 return cm_node;
32913 }
32914 @@ -1540,7 +1540,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
32915 }
32916
32917 atomic_dec(&cm_core->node_cnt);
32918 - atomic_inc(&cm_nodes_destroyed);
32919 + atomic_inc_unchecked(&cm_nodes_destroyed);
32920 nesqp = cm_node->nesqp;
32921 if (nesqp) {
32922 nesqp->cm_node = NULL;
32923 @@ -1604,7 +1604,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
32924
32925 static void drop_packet(struct sk_buff *skb)
32926 {
32927 - atomic_inc(&cm_accel_dropped_pkts);
32928 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
32929 dev_kfree_skb_any(skb);
32930 }
32931
32932 @@ -1667,7 +1667,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
32933 {
32934
32935 int reset = 0; /* whether to send reset in case of err.. */
32936 - atomic_inc(&cm_resets_recvd);
32937 + atomic_inc_unchecked(&cm_resets_recvd);
32938 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
32939 " refcnt=%d\n", cm_node, cm_node->state,
32940 atomic_read(&cm_node->ref_count));
32941 @@ -2308,7 +2308,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
32942 rem_ref_cm_node(cm_node->cm_core, cm_node);
32943 return NULL;
32944 }
32945 - atomic_inc(&cm_loopbacks);
32946 + atomic_inc_unchecked(&cm_loopbacks);
32947 loopbackremotenode->loopbackpartner = cm_node;
32948 loopbackremotenode->tcp_cntxt.rcv_wscale =
32949 NES_CM_DEFAULT_RCV_WND_SCALE;
32950 @@ -2583,7 +2583,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
32951 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
32952 else {
32953 rem_ref_cm_node(cm_core, cm_node);
32954 - atomic_inc(&cm_accel_dropped_pkts);
32955 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
32956 dev_kfree_skb_any(skb);
32957 }
32958 break;
32959 @@ -2891,7 +2891,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32960
32961 if ((cm_id) && (cm_id->event_handler)) {
32962 if (issue_disconn) {
32963 - atomic_inc(&cm_disconnects);
32964 + atomic_inc_unchecked(&cm_disconnects);
32965 cm_event.event = IW_CM_EVENT_DISCONNECT;
32966 cm_event.status = disconn_status;
32967 cm_event.local_addr = cm_id->local_addr;
32968 @@ -2913,7 +2913,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32969 }
32970
32971 if (issue_close) {
32972 - atomic_inc(&cm_closes);
32973 + atomic_inc_unchecked(&cm_closes);
32974 nes_disconnect(nesqp, 1);
32975
32976 cm_id->provider_data = nesqp;
32977 @@ -3049,7 +3049,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32978
32979 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
32980 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
32981 - atomic_inc(&cm_accepts);
32982 + atomic_inc_unchecked(&cm_accepts);
32983
32984 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
32985 netdev_refcnt_read(nesvnic->netdev));
32986 @@ -3251,7 +3251,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
32987 struct nes_cm_core *cm_core;
32988 u8 *start_buff;
32989
32990 - atomic_inc(&cm_rejects);
32991 + atomic_inc_unchecked(&cm_rejects);
32992 cm_node = (struct nes_cm_node *)cm_id->provider_data;
32993 loopback = cm_node->loopbackpartner;
32994 cm_core = cm_node->cm_core;
32995 @@ -3311,7 +3311,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32996 ntohl(cm_id->local_addr.sin_addr.s_addr),
32997 ntohs(cm_id->local_addr.sin_port));
32998
32999 - atomic_inc(&cm_connects);
33000 + atomic_inc_unchecked(&cm_connects);
33001 nesqp->active_conn = 1;
33002
33003 /* cache the cm_id in the qp */
33004 @@ -3421,7 +3421,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
33005 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
33006 return err;
33007 }
33008 - atomic_inc(&cm_listens_created);
33009 + atomic_inc_unchecked(&cm_listens_created);
33010 }
33011
33012 cm_id->add_ref(cm_id);
33013 @@ -3522,7 +3522,7 @@ static void cm_event_connected(struct nes_cm_event *event)
33014
33015 if (nesqp->destroyed)
33016 return;
33017 - atomic_inc(&cm_connecteds);
33018 + atomic_inc_unchecked(&cm_connecteds);
33019 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
33020 " local port 0x%04X. jiffies = %lu.\n",
33021 nesqp->hwqp.qp_id,
33022 @@ -3709,7 +3709,7 @@ static void cm_event_reset(struct nes_cm_event *event)
33023
33024 cm_id->add_ref(cm_id);
33025 ret = cm_id->event_handler(cm_id, &cm_event);
33026 - atomic_inc(&cm_closes);
33027 + atomic_inc_unchecked(&cm_closes);
33028 cm_event.event = IW_CM_EVENT_CLOSE;
33029 cm_event.status = 0;
33030 cm_event.provider_data = cm_id->provider_data;
33031 @@ -3745,7 +3745,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
33032 return;
33033 cm_id = cm_node->cm_id;
33034
33035 - atomic_inc(&cm_connect_reqs);
33036 + atomic_inc_unchecked(&cm_connect_reqs);
33037 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
33038 cm_node, cm_id, jiffies);
33039
33040 @@ -3785,7 +3785,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
33041 return;
33042 cm_id = cm_node->cm_id;
33043
33044 - atomic_inc(&cm_connect_reqs);
33045 + atomic_inc_unchecked(&cm_connect_reqs);
33046 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
33047 cm_node, cm_id, jiffies);
33048
33049 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
33050 index 3ba7be3..c81f6ff 100644
33051 --- a/drivers/infiniband/hw/nes/nes_mgt.c
33052 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
33053 @@ -40,8 +40,8 @@
33054 #include "nes.h"
33055 #include "nes_mgt.h"
33056
33057 -atomic_t pau_qps_created;
33058 -atomic_t pau_qps_destroyed;
33059 +atomic_unchecked_t pau_qps_created;
33060 +atomic_unchecked_t pau_qps_destroyed;
33061
33062 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
33063 {
33064 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
33065 {
33066 struct sk_buff *skb;
33067 unsigned long flags;
33068 - atomic_inc(&pau_qps_destroyed);
33069 + atomic_inc_unchecked(&pau_qps_destroyed);
33070
33071 /* Free packets that have not yet been forwarded */
33072 /* Lock is acquired by skb_dequeue when removing the skb */
33073 @@ -812,7 +812,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
33074 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
33075 skb_queue_head_init(&nesqp->pau_list);
33076 spin_lock_init(&nesqp->pau_lock);
33077 - atomic_inc(&pau_qps_created);
33078 + atomic_inc_unchecked(&pau_qps_created);
33079 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
33080 }
33081
33082 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
33083 index f3a3ecf..57d311d 100644
33084 --- a/drivers/infiniband/hw/nes/nes_nic.c
33085 +++ b/drivers/infiniband/hw/nes/nes_nic.c
33086 @@ -1277,39 +1277,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
33087 target_stat_values[++index] = mh_detected;
33088 target_stat_values[++index] = mh_pauses_sent;
33089 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
33090 - target_stat_values[++index] = atomic_read(&cm_connects);
33091 - target_stat_values[++index] = atomic_read(&cm_accepts);
33092 - target_stat_values[++index] = atomic_read(&cm_disconnects);
33093 - target_stat_values[++index] = atomic_read(&cm_connecteds);
33094 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
33095 - target_stat_values[++index] = atomic_read(&cm_rejects);
33096 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
33097 - target_stat_values[++index] = atomic_read(&qps_created);
33098 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
33099 - target_stat_values[++index] = atomic_read(&qps_destroyed);
33100 - target_stat_values[++index] = atomic_read(&cm_closes);
33101 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
33102 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
33103 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
33104 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
33105 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
33106 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
33107 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
33108 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
33109 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
33110 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
33111 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
33112 target_stat_values[++index] = cm_packets_sent;
33113 target_stat_values[++index] = cm_packets_bounced;
33114 target_stat_values[++index] = cm_packets_created;
33115 target_stat_values[++index] = cm_packets_received;
33116 target_stat_values[++index] = cm_packets_dropped;
33117 target_stat_values[++index] = cm_packets_retrans;
33118 - target_stat_values[++index] = atomic_read(&cm_listens_created);
33119 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
33120 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
33121 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
33122 target_stat_values[++index] = cm_backlog_drops;
33123 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
33124 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
33125 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
33126 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
33127 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
33128 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
33129 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
33130 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
33131 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
33132 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
33133 target_stat_values[++index] = nesadapter->free_4kpbl;
33134 target_stat_values[++index] = nesadapter->free_256pbl;
33135 target_stat_values[++index] = int_mod_timer_init;
33136 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
33137 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
33138 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
33139 - target_stat_values[++index] = atomic_read(&pau_qps_created);
33140 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
33141 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
33142 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
33143 }
33144
33145 /**
33146 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
33147 index 8b8812d..a5e1133 100644
33148 --- a/drivers/infiniband/hw/nes/nes_verbs.c
33149 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
33150 @@ -46,9 +46,9 @@
33151
33152 #include <rdma/ib_umem.h>
33153
33154 -atomic_t mod_qp_timouts;
33155 -atomic_t qps_created;
33156 -atomic_t sw_qps_destroyed;
33157 +atomic_unchecked_t mod_qp_timouts;
33158 +atomic_unchecked_t qps_created;
33159 +atomic_unchecked_t sw_qps_destroyed;
33160
33161 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
33162
33163 @@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
33164 if (init_attr->create_flags)
33165 return ERR_PTR(-EINVAL);
33166
33167 - atomic_inc(&qps_created);
33168 + atomic_inc_unchecked(&qps_created);
33169 switch (init_attr->qp_type) {
33170 case IB_QPT_RC:
33171 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
33172 @@ -1460,7 +1460,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
33173 struct iw_cm_event cm_event;
33174 int ret = 0;
33175
33176 - atomic_inc(&sw_qps_destroyed);
33177 + atomic_inc_unchecked(&sw_qps_destroyed);
33178 nesqp->destroyed = 1;
33179
33180 /* Blow away the connection if it exists. */
33181 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
33182 index 7b1b8669..4b69f85 100644
33183 --- a/drivers/infiniband/hw/qib/qib.h
33184 +++ b/drivers/infiniband/hw/qib/qib.h
33185 @@ -51,6 +51,7 @@
33186 #include <linux/completion.h>
33187 #include <linux/kref.h>
33188 #include <linux/sched.h>
33189 +#include <linux/slab.h>
33190
33191 #include "qib_common.h"
33192 #include "qib_verbs.h"
33193 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
33194 index da739d9..da1c7f4 100644
33195 --- a/drivers/input/gameport/gameport.c
33196 +++ b/drivers/input/gameport/gameport.c
33197 @@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
33198 */
33199 static void gameport_init_port(struct gameport *gameport)
33200 {
33201 - static atomic_t gameport_no = ATOMIC_INIT(0);
33202 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
33203
33204 __module_get(THIS_MODULE);
33205
33206 mutex_init(&gameport->drv_mutex);
33207 device_initialize(&gameport->dev);
33208 dev_set_name(&gameport->dev, "gameport%lu",
33209 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
33210 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
33211 gameport->dev.bus = &gameport_bus;
33212 gameport->dev.release = gameport_release_port;
33213 if (gameport->parent)
33214 diff --git a/drivers/input/input.c b/drivers/input/input.c
33215 index 8921c61..f5cd63d 100644
33216 --- a/drivers/input/input.c
33217 +++ b/drivers/input/input.c
33218 @@ -1814,7 +1814,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
33219 */
33220 int input_register_device(struct input_dev *dev)
33221 {
33222 - static atomic_t input_no = ATOMIC_INIT(0);
33223 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
33224 struct input_handler *handler;
33225 const char *path;
33226 int error;
33227 @@ -1851,7 +1851,7 @@ int input_register_device(struct input_dev *dev)
33228 dev->setkeycode = input_default_setkeycode;
33229
33230 dev_set_name(&dev->dev, "input%ld",
33231 - (unsigned long) atomic_inc_return(&input_no) - 1);
33232 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
33233
33234 error = device_add(&dev->dev);
33235 if (error)
33236 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
33237 index 04c69af..5f92d00 100644
33238 --- a/drivers/input/joystick/sidewinder.c
33239 +++ b/drivers/input/joystick/sidewinder.c
33240 @@ -30,6 +30,7 @@
33241 #include <linux/kernel.h>
33242 #include <linux/module.h>
33243 #include <linux/slab.h>
33244 +#include <linux/sched.h>
33245 #include <linux/init.h>
33246 #include <linux/input.h>
33247 #include <linux/gameport.h>
33248 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
33249 index 83811e4..0822b90 100644
33250 --- a/drivers/input/joystick/xpad.c
33251 +++ b/drivers/input/joystick/xpad.c
33252 @@ -726,7 +726,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
33253
33254 static int xpad_led_probe(struct usb_xpad *xpad)
33255 {
33256 - static atomic_t led_seq = ATOMIC_INIT(0);
33257 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
33258 long led_no;
33259 struct xpad_led *led;
33260 struct led_classdev *led_cdev;
33261 @@ -739,7 +739,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
33262 if (!led)
33263 return -ENOMEM;
33264
33265 - led_no = (long)atomic_inc_return(&led_seq) - 1;
33266 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
33267
33268 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
33269 led->xpad = xpad;
33270 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
33271 index 0110b5a..d3ad144 100644
33272 --- a/drivers/input/mousedev.c
33273 +++ b/drivers/input/mousedev.c
33274 @@ -763,7 +763,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
33275
33276 spin_unlock_irq(&client->packet_lock);
33277
33278 - if (copy_to_user(buffer, data, count))
33279 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
33280 return -EFAULT;
33281
33282 return count;
33283 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
33284 index d0f7533..fb8215b 100644
33285 --- a/drivers/input/serio/serio.c
33286 +++ b/drivers/input/serio/serio.c
33287 @@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
33288 */
33289 static void serio_init_port(struct serio *serio)
33290 {
33291 - static atomic_t serio_no = ATOMIC_INIT(0);
33292 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
33293
33294 __module_get(THIS_MODULE);
33295
33296 @@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
33297 mutex_init(&serio->drv_mutex);
33298 device_initialize(&serio->dev);
33299 dev_set_name(&serio->dev, "serio%ld",
33300 - (long)atomic_inc_return(&serio_no) - 1);
33301 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
33302 serio->dev.bus = &serio_bus;
33303 serio->dev.release = serio_release_port;
33304 serio->dev.groups = serio_device_attr_groups;
33305 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
33306 index 38c4bd8..58965d9 100644
33307 --- a/drivers/isdn/capi/capi.c
33308 +++ b/drivers/isdn/capi/capi.c
33309 @@ -83,8 +83,8 @@ struct capiminor {
33310
33311 struct capi20_appl *ap;
33312 u32 ncci;
33313 - atomic_t datahandle;
33314 - atomic_t msgid;
33315 + atomic_unchecked_t datahandle;
33316 + atomic_unchecked_t msgid;
33317
33318 struct tty_port port;
33319 int ttyinstop;
33320 @@ -392,7 +392,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
33321 capimsg_setu16(s, 2, mp->ap->applid);
33322 capimsg_setu8 (s, 4, CAPI_DATA_B3);
33323 capimsg_setu8 (s, 5, CAPI_RESP);
33324 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
33325 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
33326 capimsg_setu32(s, 8, mp->ncci);
33327 capimsg_setu16(s, 12, datahandle);
33328 }
33329 @@ -513,14 +513,14 @@ static void handle_minor_send(struct capiminor *mp)
33330 mp->outbytes -= len;
33331 spin_unlock_bh(&mp->outlock);
33332
33333 - datahandle = atomic_inc_return(&mp->datahandle);
33334 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
33335 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
33336 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
33337 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
33338 capimsg_setu16(skb->data, 2, mp->ap->applid);
33339 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
33340 capimsg_setu8 (skb->data, 5, CAPI_REQ);
33341 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
33342 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
33343 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
33344 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
33345 capimsg_setu16(skb->data, 16, len); /* Data length */
33346 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
33347 index a6d9fd2..afdb8a3 100644
33348 --- a/drivers/isdn/gigaset/interface.c
33349 +++ b/drivers/isdn/gigaset/interface.c
33350 @@ -160,9 +160,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
33351 }
33352 tty->driver_data = cs;
33353
33354 - ++cs->port.count;
33355 + atomic_inc(&cs->port.count);
33356
33357 - if (cs->port.count == 1) {
33358 + if (atomic_read(&cs->port.count) == 1) {
33359 tty_port_tty_set(&cs->port, tty);
33360 tty->low_latency = 1;
33361 }
33362 @@ -186,9 +186,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
33363
33364 if (!cs->connected)
33365 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
33366 - else if (!cs->port.count)
33367 + else if (!atomic_read(&cs->port.count))
33368 dev_warn(cs->dev, "%s: device not opened\n", __func__);
33369 - else if (!--cs->port.count)
33370 + else if (!atomic_dec_return(&cs->port.count))
33371 tty_port_tty_set(&cs->port, NULL);
33372
33373 mutex_unlock(&cs->mutex);
33374 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
33375 index 821f7ac..28d4030 100644
33376 --- a/drivers/isdn/hardware/avm/b1.c
33377 +++ b/drivers/isdn/hardware/avm/b1.c
33378 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
33379 }
33380 if (left) {
33381 if (t4file->user) {
33382 - if (copy_from_user(buf, dp, left))
33383 + if (left > sizeof buf || copy_from_user(buf, dp, left))
33384 return -EFAULT;
33385 } else {
33386 memcpy(buf, dp, left);
33387 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
33388 }
33389 if (left) {
33390 if (config->user) {
33391 - if (copy_from_user(buf, dp, left))
33392 + if (left > sizeof buf || copy_from_user(buf, dp, left))
33393 return -EFAULT;
33394 } else {
33395 memcpy(buf, dp, left);
33396 diff --git a/drivers/isdn/hardware/eicon/divasync.h b/drivers/isdn/hardware/eicon/divasync.h
33397 index dd6b53a..19d9ee6 100644
33398 --- a/drivers/isdn/hardware/eicon/divasync.h
33399 +++ b/drivers/isdn/hardware/eicon/divasync.h
33400 @@ -146,7 +146,7 @@ typedef struct _diva_didd_add_adapter {
33401 } diva_didd_add_adapter_t;
33402 typedef struct _diva_didd_remove_adapter {
33403 IDI_CALL p_request;
33404 -} diva_didd_remove_adapter_t;
33405 +} __no_const diva_didd_remove_adapter_t;
33406 typedef struct _diva_didd_read_adapter_array {
33407 void *buffer;
33408 dword length;
33409 diff --git a/drivers/isdn/hardware/eicon/xdi_adapter.h b/drivers/isdn/hardware/eicon/xdi_adapter.h
33410 index d303e65..28bcb7b 100644
33411 --- a/drivers/isdn/hardware/eicon/xdi_adapter.h
33412 +++ b/drivers/isdn/hardware/eicon/xdi_adapter.h
33413 @@ -44,7 +44,7 @@ typedef struct _xdi_mbox_t {
33414 typedef struct _diva_os_idi_adapter_interface {
33415 diva_init_card_proc_t cleanup_adapter_proc;
33416 diva_cmd_card_proc_t cmd_proc;
33417 -} diva_os_idi_adapter_interface_t;
33418 +} __no_const diva_os_idi_adapter_interface_t;
33419
33420 typedef struct _diva_os_xdi_adapter {
33421 struct list_head link;
33422 diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
33423 index 7bc5067..fd36232 100644
33424 --- a/drivers/isdn/i4l/isdn_tty.c
33425 +++ b/drivers/isdn/i4l/isdn_tty.c
33426 @@ -1505,9 +1505,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
33427 port = &info->port;
33428 #ifdef ISDN_DEBUG_MODEM_OPEN
33429 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
33430 - port->count);
33431 + atomic_read(&port->count))
33432 #endif
33433 - port->count++;
33434 + atomic_inc(&port->count);
33435 tty->driver_data = info;
33436 port->tty = tty;
33437 tty->port = port;
33438 @@ -1553,7 +1553,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
33439 #endif
33440 return;
33441 }
33442 - if ((tty->count == 1) && (port->count != 1)) {
33443 + if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
33444 /*
33445 * Uh, oh. tty->count is 1, which means that the tty
33446 * structure will be freed. Info->count should always
33447 @@ -1562,15 +1562,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
33448 * serial port won't be shutdown.
33449 */
33450 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
33451 - "info->count is %d\n", port->count);
33452 - port->count = 1;
33453 + "info->count is %d\n", atomic_read(&port->count));
33454 + atomic_set(&port->count, 1);
33455 }
33456 - if (--port->count < 0) {
33457 + if (atomic_dec_return(&port->count) < 0) {
33458 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
33459 - info->line, port->count);
33460 - port->count = 0;
33461 + info->line, atomic_read(&port->count));
33462 + atomic_set(&port->count, 0);
33463 }
33464 - if (port->count) {
33465 + if (atomic_read(&port->count)) {
33466 #ifdef ISDN_DEBUG_MODEM_OPEN
33467 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
33468 #endif
33469 @@ -1624,7 +1624,7 @@ isdn_tty_hangup(struct tty_struct *tty)
33470 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
33471 return;
33472 isdn_tty_shutdown(info);
33473 - port->count = 0;
33474 + atomic_set(&port->count, 0);
33475 port->flags &= ~ASYNC_NORMAL_ACTIVE;
33476 port->tty = NULL;
33477 wake_up_interruptible(&port->open_wait);
33478 @@ -1964,7 +1964,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
33479 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
33480 modem_info *info = &dev->mdm.info[i];
33481
33482 - if (info->port.count == 0)
33483 + if (atomic_read(&info->port.count) == 0)
33484 continue;
33485 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
33486 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
33487 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
33488 index e74df7c..03a03ba 100644
33489 --- a/drivers/isdn/icn/icn.c
33490 +++ b/drivers/isdn/icn/icn.c
33491 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
33492 if (count > len)
33493 count = len;
33494 if (user) {
33495 - if (copy_from_user(msg, buf, count))
33496 + if (count > sizeof msg || copy_from_user(msg, buf, count))
33497 return -EFAULT;
33498 } else
33499 memcpy(msg, buf, count);
33500 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
33501 index b5fdcb7..5b6c59f 100644
33502 --- a/drivers/lguest/core.c
33503 +++ b/drivers/lguest/core.c
33504 @@ -92,9 +92,17 @@ static __init int map_switcher(void)
33505 * it's worked so far. The end address needs +1 because __get_vm_area
33506 * allocates an extra guard page, so we need space for that.
33507 */
33508 +
33509 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
33510 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
33511 + VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
33512 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
33513 +#else
33514 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
33515 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
33516 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
33517 +#endif
33518 +
33519 if (!switcher_vma) {
33520 err = -ENOMEM;
33521 printk("lguest: could not map switcher pages high\n");
33522 @@ -119,7 +127,7 @@ static __init int map_switcher(void)
33523 * Now the Switcher is mapped at the right address, we can't fail!
33524 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
33525 */
33526 - memcpy(switcher_vma->addr, start_switcher_text,
33527 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
33528 end_switcher_text - start_switcher_text);
33529
33530 printk(KERN_INFO "lguest: mapped switcher at %p\n",
33531 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
33532 index 39809035..ce25c5e 100644
33533 --- a/drivers/lguest/x86/core.c
33534 +++ b/drivers/lguest/x86/core.c
33535 @@ -59,7 +59,7 @@ static struct {
33536 /* Offset from where switcher.S was compiled to where we've copied it */
33537 static unsigned long switcher_offset(void)
33538 {
33539 - return SWITCHER_ADDR - (unsigned long)start_switcher_text;
33540 + return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
33541 }
33542
33543 /* This cpu's struct lguest_pages. */
33544 @@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
33545 * These copies are pretty cheap, so we do them unconditionally: */
33546 /* Save the current Host top-level page directory.
33547 */
33548 +
33549 +#ifdef CONFIG_PAX_PER_CPU_PGD
33550 + pages->state.host_cr3 = read_cr3();
33551 +#else
33552 pages->state.host_cr3 = __pa(current->mm->pgd);
33553 +#endif
33554 +
33555 /*
33556 * Set up the Guest's page tables to see this CPU's pages (and no
33557 * other CPU's pages).
33558 @@ -472,7 +478,7 @@ void __init lguest_arch_host_init(void)
33559 * compiled-in switcher code and the high-mapped copy we just made.
33560 */
33561 for (i = 0; i < IDT_ENTRIES; i++)
33562 - default_idt_entries[i] += switcher_offset();
33563 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
33564
33565 /*
33566 * Set up the Switcher's per-cpu areas.
33567 @@ -555,7 +561,7 @@ void __init lguest_arch_host_init(void)
33568 * it will be undisturbed when we switch. To change %cs and jump we
33569 * need this structure to feed to Intel's "lcall" instruction.
33570 */
33571 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
33572 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
33573 lguest_entry.segment = LGUEST_CS;
33574
33575 /*
33576 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
33577 index 40634b0..4f5855e 100644
33578 --- a/drivers/lguest/x86/switcher_32.S
33579 +++ b/drivers/lguest/x86/switcher_32.S
33580 @@ -87,6 +87,7 @@
33581 #include <asm/page.h>
33582 #include <asm/segment.h>
33583 #include <asm/lguest.h>
33584 +#include <asm/processor-flags.h>
33585
33586 // We mark the start of the code to copy
33587 // It's placed in .text tho it's never run here
33588 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
33589 // Changes type when we load it: damn Intel!
33590 // For after we switch over our page tables
33591 // That entry will be read-only: we'd crash.
33592 +
33593 +#ifdef CONFIG_PAX_KERNEXEC
33594 + mov %cr0, %edx
33595 + xor $X86_CR0_WP, %edx
33596 + mov %edx, %cr0
33597 +#endif
33598 +
33599 movl $(GDT_ENTRY_TSS*8), %edx
33600 ltr %dx
33601
33602 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
33603 // Let's clear it again for our return.
33604 // The GDT descriptor of the Host
33605 // Points to the table after two "size" bytes
33606 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
33607 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
33608 // Clear "used" from type field (byte 5, bit 2)
33609 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
33610 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
33611 +
33612 +#ifdef CONFIG_PAX_KERNEXEC
33613 + mov %cr0, %eax
33614 + xor $X86_CR0_WP, %eax
33615 + mov %eax, %cr0
33616 +#endif
33617
33618 // Once our page table's switched, the Guest is live!
33619 // The Host fades as we run this final step.
33620 @@ -295,13 +309,12 @@ deliver_to_host:
33621 // I consulted gcc, and it gave
33622 // These instructions, which I gladly credit:
33623 leal (%edx,%ebx,8), %eax
33624 - movzwl (%eax),%edx
33625 - movl 4(%eax), %eax
33626 - xorw %ax, %ax
33627 - orl %eax, %edx
33628 + movl 4(%eax), %edx
33629 + movw (%eax), %dx
33630 // Now the address of the handler's in %edx
33631 // We call it now: its "iret" drops us home.
33632 - jmp *%edx
33633 + ljmp $__KERNEL_CS, $1f
33634 +1: jmp *%edx
33635
33636 // Every interrupt can come to us here
33637 // But we must truly tell each apart.
33638 diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
33639 index 20e5c2c..9e849a9 100644
33640 --- a/drivers/macintosh/macio_asic.c
33641 +++ b/drivers/macintosh/macio_asic.c
33642 @@ -748,7 +748,7 @@ static void __devexit macio_pci_remove(struct pci_dev* pdev)
33643 * MacIO is matched against any Apple ID, it's probe() function
33644 * will then decide wether it applies or not
33645 */
33646 -static const struct pci_device_id __devinitdata pci_ids [] = { {
33647 +static const struct pci_device_id __devinitconst pci_ids [] = { {
33648 .vendor = PCI_VENDOR_ID_APPLE,
33649 .device = PCI_ANY_ID,
33650 .subvendor = PCI_ANY_ID,
33651 diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
33652 index 94e7f6b..2f4a0d8 100644
33653 --- a/drivers/md/bitmap.c
33654 +++ b/drivers/md/bitmap.c
33655 @@ -1786,7 +1786,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
33656 chunk_kb ? "KB" : "B");
33657 if (bitmap->storage.file) {
33658 seq_printf(seq, ", file: ");
33659 - seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
33660 + seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
33661 }
33662
33663 seq_printf(seq, "\n");
33664 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
33665 index afd9598..528d8f9 100644
33666 --- a/drivers/md/dm-ioctl.c
33667 +++ b/drivers/md/dm-ioctl.c
33668 @@ -1593,7 +1593,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
33669 cmd == DM_LIST_VERSIONS_CMD)
33670 return 0;
33671
33672 - if ((cmd == DM_DEV_CREATE_CMD)) {
33673 + if (cmd == DM_DEV_CREATE_CMD) {
33674 if (!*param->name) {
33675 DMWARN("name not supplied when creating device");
33676 return -EINVAL;
33677 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
33678 index bc5ddba8..b961159 100644
33679 --- a/drivers/md/dm-raid1.c
33680 +++ b/drivers/md/dm-raid1.c
33681 @@ -40,7 +40,7 @@ enum dm_raid1_error {
33682
33683 struct mirror {
33684 struct mirror_set *ms;
33685 - atomic_t error_count;
33686 + atomic_unchecked_t error_count;
33687 unsigned long error_type;
33688 struct dm_dev *dev;
33689 sector_t offset;
33690 @@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
33691 struct mirror *m;
33692
33693 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
33694 - if (!atomic_read(&m->error_count))
33695 + if (!atomic_read_unchecked(&m->error_count))
33696 return m;
33697
33698 return NULL;
33699 @@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
33700 * simple way to tell if a device has encountered
33701 * errors.
33702 */
33703 - atomic_inc(&m->error_count);
33704 + atomic_inc_unchecked(&m->error_count);
33705
33706 if (test_and_set_bit(error_type, &m->error_type))
33707 return;
33708 @@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
33709 struct mirror *m = get_default_mirror(ms);
33710
33711 do {
33712 - if (likely(!atomic_read(&m->error_count)))
33713 + if (likely(!atomic_read_unchecked(&m->error_count)))
33714 return m;
33715
33716 if (m-- == ms->mirror)
33717 @@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
33718 {
33719 struct mirror *default_mirror = get_default_mirror(m->ms);
33720
33721 - return !atomic_read(&default_mirror->error_count);
33722 + return !atomic_read_unchecked(&default_mirror->error_count);
33723 }
33724
33725 static int mirror_available(struct mirror_set *ms, struct bio *bio)
33726 @@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
33727 */
33728 if (likely(region_in_sync(ms, region, 1)))
33729 m = choose_mirror(ms, bio->bi_sector);
33730 - else if (m && atomic_read(&m->error_count))
33731 + else if (m && atomic_read_unchecked(&m->error_count))
33732 m = NULL;
33733
33734 if (likely(m))
33735 @@ -938,7 +938,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
33736 }
33737
33738 ms->mirror[mirror].ms = ms;
33739 - atomic_set(&(ms->mirror[mirror].error_count), 0);
33740 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
33741 ms->mirror[mirror].error_type = 0;
33742 ms->mirror[mirror].offset = offset;
33743
33744 @@ -1356,7 +1356,7 @@ static void mirror_resume(struct dm_target *ti)
33745 */
33746 static char device_status_char(struct mirror *m)
33747 {
33748 - if (!atomic_read(&(m->error_count)))
33749 + if (!atomic_read_unchecked(&(m->error_count)))
33750 return 'A';
33751
33752 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
33753 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
33754 index a087bf2..4c94786 100644
33755 --- a/drivers/md/dm-stripe.c
33756 +++ b/drivers/md/dm-stripe.c
33757 @@ -20,7 +20,7 @@ struct stripe {
33758 struct dm_dev *dev;
33759 sector_t physical_start;
33760
33761 - atomic_t error_count;
33762 + atomic_unchecked_t error_count;
33763 };
33764
33765 struct stripe_c {
33766 @@ -183,7 +183,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
33767 kfree(sc);
33768 return r;
33769 }
33770 - atomic_set(&(sc->stripe[i].error_count), 0);
33771 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
33772 }
33773
33774 ti->private = sc;
33775 @@ -324,7 +324,7 @@ static int stripe_status(struct dm_target *ti, status_type_t type,
33776 DMEMIT("%d ", sc->stripes);
33777 for (i = 0; i < sc->stripes; i++) {
33778 DMEMIT("%s ", sc->stripe[i].dev->name);
33779 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
33780 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
33781 'D' : 'A';
33782 }
33783 buffer[i] = '\0';
33784 @@ -371,8 +371,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
33785 */
33786 for (i = 0; i < sc->stripes; i++)
33787 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
33788 - atomic_inc(&(sc->stripe[i].error_count));
33789 - if (atomic_read(&(sc->stripe[i].error_count)) <
33790 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
33791 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
33792 DM_IO_ERROR_THRESHOLD)
33793 schedule_work(&sc->trigger_event);
33794 }
33795 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
33796 index 100368e..64262ce 100644
33797 --- a/drivers/md/dm-table.c
33798 +++ b/drivers/md/dm-table.c
33799 @@ -390,7 +390,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
33800 if (!dev_size)
33801 return 0;
33802
33803 - if ((start >= dev_size) || (start + len > dev_size)) {
33804 + if ((start >= dev_size) || (len > dev_size - start)) {
33805 DMWARN("%s: %s too small for target: "
33806 "start=%llu, len=%llu, dev_size=%llu",
33807 dm_device_name(ti->table->md), bdevname(bdev, b),
33808 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
33809 index 693e149..b7e0fde 100644
33810 --- a/drivers/md/dm-thin-metadata.c
33811 +++ b/drivers/md/dm-thin-metadata.c
33812 @@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
33813 {
33814 pmd->info.tm = pmd->tm;
33815 pmd->info.levels = 2;
33816 - pmd->info.value_type.context = pmd->data_sm;
33817 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33818 pmd->info.value_type.size = sizeof(__le64);
33819 pmd->info.value_type.inc = data_block_inc;
33820 pmd->info.value_type.dec = data_block_dec;
33821 @@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
33822
33823 pmd->bl_info.tm = pmd->tm;
33824 pmd->bl_info.levels = 1;
33825 - pmd->bl_info.value_type.context = pmd->data_sm;
33826 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33827 pmd->bl_info.value_type.size = sizeof(__le64);
33828 pmd->bl_info.value_type.inc = data_block_inc;
33829 pmd->bl_info.value_type.dec = data_block_dec;
33830 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
33831 index 4256200..154b975 100644
33832 --- a/drivers/md/dm.c
33833 +++ b/drivers/md/dm.c
33834 @@ -176,9 +176,9 @@ struct mapped_device {
33835 /*
33836 * Event handling.
33837 */
33838 - atomic_t event_nr;
33839 + atomic_unchecked_t event_nr;
33840 wait_queue_head_t eventq;
33841 - atomic_t uevent_seq;
33842 + atomic_unchecked_t uevent_seq;
33843 struct list_head uevent_list;
33844 spinlock_t uevent_lock; /* Protect access to uevent_list */
33845
33846 @@ -1893,8 +1893,8 @@ static struct mapped_device *alloc_dev(int minor)
33847 rwlock_init(&md->map_lock);
33848 atomic_set(&md->holders, 1);
33849 atomic_set(&md->open_count, 0);
33850 - atomic_set(&md->event_nr, 0);
33851 - atomic_set(&md->uevent_seq, 0);
33852 + atomic_set_unchecked(&md->event_nr, 0);
33853 + atomic_set_unchecked(&md->uevent_seq, 0);
33854 INIT_LIST_HEAD(&md->uevent_list);
33855 spin_lock_init(&md->uevent_lock);
33856
33857 @@ -2028,7 +2028,7 @@ static void event_callback(void *context)
33858
33859 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
33860
33861 - atomic_inc(&md->event_nr);
33862 + atomic_inc_unchecked(&md->event_nr);
33863 wake_up(&md->eventq);
33864 }
33865
33866 @@ -2683,18 +2683,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
33867
33868 uint32_t dm_next_uevent_seq(struct mapped_device *md)
33869 {
33870 - return atomic_add_return(1, &md->uevent_seq);
33871 + return atomic_add_return_unchecked(1, &md->uevent_seq);
33872 }
33873
33874 uint32_t dm_get_event_nr(struct mapped_device *md)
33875 {
33876 - return atomic_read(&md->event_nr);
33877 + return atomic_read_unchecked(&md->event_nr);
33878 }
33879
33880 int dm_wait_event(struct mapped_device *md, int event_nr)
33881 {
33882 return wait_event_interruptible(md->eventq,
33883 - (event_nr != atomic_read(&md->event_nr)));
33884 + (event_nr != atomic_read_unchecked(&md->event_nr)));
33885 }
33886
33887 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
33888 diff --git a/drivers/md/md.c b/drivers/md/md.c
33889 index c7b000f..15a8b22 100644
33890 --- a/drivers/md/md.c
33891 +++ b/drivers/md/md.c
33892 @@ -277,10 +277,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
33893 * start build, activate spare
33894 */
33895 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
33896 -static atomic_t md_event_count;
33897 +static atomic_unchecked_t md_event_count;
33898 void md_new_event(struct mddev *mddev)
33899 {
33900 - atomic_inc(&md_event_count);
33901 + atomic_inc_unchecked(&md_event_count);
33902 wake_up(&md_event_waiters);
33903 }
33904 EXPORT_SYMBOL_GPL(md_new_event);
33905 @@ -290,7 +290,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
33906 */
33907 static void md_new_event_inintr(struct mddev *mddev)
33908 {
33909 - atomic_inc(&md_event_count);
33910 + atomic_inc_unchecked(&md_event_count);
33911 wake_up(&md_event_waiters);
33912 }
33913
33914 @@ -1519,7 +1519,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
33915 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
33916 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
33917 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
33918 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33919 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33920
33921 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
33922 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
33923 @@ -1763,7 +1763,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
33924 else
33925 sb->resync_offset = cpu_to_le64(0);
33926
33927 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
33928 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
33929
33930 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
33931 sb->size = cpu_to_le64(mddev->dev_sectors);
33932 @@ -2757,7 +2757,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
33933 static ssize_t
33934 errors_show(struct md_rdev *rdev, char *page)
33935 {
33936 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
33937 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
33938 }
33939
33940 static ssize_t
33941 @@ -2766,7 +2766,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
33942 char *e;
33943 unsigned long n = simple_strtoul(buf, &e, 10);
33944 if (*buf && (*e == 0 || *e == '\n')) {
33945 - atomic_set(&rdev->corrected_errors, n);
33946 + atomic_set_unchecked(&rdev->corrected_errors, n);
33947 return len;
33948 }
33949 return -EINVAL;
33950 @@ -3213,8 +3213,8 @@ int md_rdev_init(struct md_rdev *rdev)
33951 rdev->sb_loaded = 0;
33952 rdev->bb_page = NULL;
33953 atomic_set(&rdev->nr_pending, 0);
33954 - atomic_set(&rdev->read_errors, 0);
33955 - atomic_set(&rdev->corrected_errors, 0);
33956 + atomic_set_unchecked(&rdev->read_errors, 0);
33957 + atomic_set_unchecked(&rdev->corrected_errors, 0);
33958
33959 INIT_LIST_HEAD(&rdev->same_set);
33960 init_waitqueue_head(&rdev->blocked_wait);
33961 @@ -6947,7 +6947,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
33962
33963 spin_unlock(&pers_lock);
33964 seq_printf(seq, "\n");
33965 - seq->poll_event = atomic_read(&md_event_count);
33966 + seq->poll_event = atomic_read_unchecked(&md_event_count);
33967 return 0;
33968 }
33969 if (v == (void*)2) {
33970 @@ -7050,7 +7050,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
33971 return error;
33972
33973 seq = file->private_data;
33974 - seq->poll_event = atomic_read(&md_event_count);
33975 + seq->poll_event = atomic_read_unchecked(&md_event_count);
33976 return error;
33977 }
33978
33979 @@ -7064,7 +7064,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
33980 /* always allow read */
33981 mask = POLLIN | POLLRDNORM;
33982
33983 - if (seq->poll_event != atomic_read(&md_event_count))
33984 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
33985 mask |= POLLERR | POLLPRI;
33986 return mask;
33987 }
33988 @@ -7108,7 +7108,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
33989 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
33990 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
33991 (int)part_stat_read(&disk->part0, sectors[1]) -
33992 - atomic_read(&disk->sync_io);
33993 + atomic_read_unchecked(&disk->sync_io);
33994 /* sync IO will cause sync_io to increase before the disk_stats
33995 * as sync_io is counted when a request starts, and
33996 * disk_stats is counted when it completes.
33997 diff --git a/drivers/md/md.h b/drivers/md/md.h
33998 index f385b03..b600be8 100644
33999 --- a/drivers/md/md.h
34000 +++ b/drivers/md/md.h
34001 @@ -94,13 +94,13 @@ struct md_rdev {
34002 * only maintained for arrays that
34003 * support hot removal
34004 */
34005 - atomic_t read_errors; /* number of consecutive read errors that
34006 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
34007 * we have tried to ignore.
34008 */
34009 struct timespec last_read_error; /* monotonic time since our
34010 * last read error
34011 */
34012 - atomic_t corrected_errors; /* number of corrected read errors,
34013 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
34014 * for reporting to userspace and storing
34015 * in superblock.
34016 */
34017 @@ -432,7 +432,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
34018
34019 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
34020 {
34021 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
34022 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
34023 }
34024
34025 struct md_personality
34026 diff --git a/drivers/md/persistent-data/dm-space-map-disk.c b/drivers/md/persistent-data/dm-space-map-disk.c
34027 index f6d29e6..7917f5e 100644
34028 --- a/drivers/md/persistent-data/dm-space-map-disk.c
34029 +++ b/drivers/md/persistent-data/dm-space-map-disk.c
34030 @@ -22,7 +22,7 @@
34031 * Space map interface.
34032 */
34033 struct sm_disk {
34034 - struct dm_space_map sm;
34035 + dm_space_map_no_const sm;
34036
34037 struct ll_disk ll;
34038 struct ll_disk old_ll;
34039 diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
34040 index e89ae5e..062e4c2 100644
34041 --- a/drivers/md/persistent-data/dm-space-map-metadata.c
34042 +++ b/drivers/md/persistent-data/dm-space-map-metadata.c
34043 @@ -43,7 +43,7 @@ struct block_op {
34044 };
34045
34046 struct sm_metadata {
34047 - struct dm_space_map sm;
34048 + dm_space_map_no_const sm;
34049
34050 struct ll_disk ll;
34051 struct ll_disk old_ll;
34052 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
34053 index 1cbfc6b..56e1dbb 100644
34054 --- a/drivers/md/persistent-data/dm-space-map.h
34055 +++ b/drivers/md/persistent-data/dm-space-map.h
34056 @@ -60,6 +60,7 @@ struct dm_space_map {
34057 int (*root_size)(struct dm_space_map *sm, size_t *result);
34058 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
34059 };
34060 +typedef struct dm_space_map __no_const dm_space_map_no_const;
34061
34062 /*----------------------------------------------------------------*/
34063
34064 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
34065 index 05bb49e..84d7ce6 100644
34066 --- a/drivers/md/raid1.c
34067 +++ b/drivers/md/raid1.c
34068 @@ -1810,7 +1810,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
34069 if (r1_sync_page_io(rdev, sect, s,
34070 bio->bi_io_vec[idx].bv_page,
34071 READ) != 0)
34072 - atomic_add(s, &rdev->corrected_errors);
34073 + atomic_add_unchecked(s, &rdev->corrected_errors);
34074 }
34075 sectors -= s;
34076 sect += s;
34077 @@ -2032,7 +2032,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
34078 test_bit(In_sync, &rdev->flags)) {
34079 if (r1_sync_page_io(rdev, sect, s,
34080 conf->tmppage, READ)) {
34081 - atomic_add(s, &rdev->corrected_errors);
34082 + atomic_add_unchecked(s, &rdev->corrected_errors);
34083 printk(KERN_INFO
34084 "md/raid1:%s: read error corrected "
34085 "(%d sectors at %llu on %s)\n",
34086 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
34087 index c52d893..69c5d80 100644
34088 --- a/drivers/md/raid10.c
34089 +++ b/drivers/md/raid10.c
34090 @@ -1814,7 +1814,7 @@ static void end_sync_read(struct bio *bio, int error)
34091 /* The write handler will notice the lack of
34092 * R10BIO_Uptodate and record any errors etc
34093 */
34094 - atomic_add(r10_bio->sectors,
34095 + atomic_add_unchecked(r10_bio->sectors,
34096 &conf->mirrors[d].rdev->corrected_errors);
34097
34098 /* for reconstruct, we always reschedule after a read.
34099 @@ -2163,7 +2163,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
34100 {
34101 struct timespec cur_time_mon;
34102 unsigned long hours_since_last;
34103 - unsigned int read_errors = atomic_read(&rdev->read_errors);
34104 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
34105
34106 ktime_get_ts(&cur_time_mon);
34107
34108 @@ -2185,9 +2185,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
34109 * overflowing the shift of read_errors by hours_since_last.
34110 */
34111 if (hours_since_last >= 8 * sizeof(read_errors))
34112 - atomic_set(&rdev->read_errors, 0);
34113 + atomic_set_unchecked(&rdev->read_errors, 0);
34114 else
34115 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
34116 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
34117 }
34118
34119 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
34120 @@ -2241,8 +2241,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
34121 return;
34122
34123 check_decay_read_errors(mddev, rdev);
34124 - atomic_inc(&rdev->read_errors);
34125 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
34126 + atomic_inc_unchecked(&rdev->read_errors);
34127 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
34128 char b[BDEVNAME_SIZE];
34129 bdevname(rdev->bdev, b);
34130
34131 @@ -2250,7 +2250,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
34132 "md/raid10:%s: %s: Raid device exceeded "
34133 "read_error threshold [cur %d:max %d]\n",
34134 mdname(mddev), b,
34135 - atomic_read(&rdev->read_errors), max_read_errors);
34136 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
34137 printk(KERN_NOTICE
34138 "md/raid10:%s: %s: Failing raid device\n",
34139 mdname(mddev), b);
34140 @@ -2405,7 +2405,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
34141 sect +
34142 choose_data_offset(r10_bio, rdev)),
34143 bdevname(rdev->bdev, b));
34144 - atomic_add(s, &rdev->corrected_errors);
34145 + atomic_add_unchecked(s, &rdev->corrected_errors);
34146 }
34147
34148 rdev_dec_pending(rdev, mddev);
34149 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
34150 index 0689173..35df76c 100644
34151 --- a/drivers/md/raid5.c
34152 +++ b/drivers/md/raid5.c
34153 @@ -1756,21 +1756,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
34154 mdname(conf->mddev), STRIPE_SECTORS,
34155 (unsigned long long)s,
34156 bdevname(rdev->bdev, b));
34157 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
34158 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
34159 clear_bit(R5_ReadError, &sh->dev[i].flags);
34160 clear_bit(R5_ReWrite, &sh->dev[i].flags);
34161 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
34162 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
34163
34164 - if (atomic_read(&rdev->read_errors))
34165 - atomic_set(&rdev->read_errors, 0);
34166 + if (atomic_read_unchecked(&rdev->read_errors))
34167 + atomic_set_unchecked(&rdev->read_errors, 0);
34168 } else {
34169 const char *bdn = bdevname(rdev->bdev, b);
34170 int retry = 0;
34171 int set_bad = 0;
34172
34173 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
34174 - atomic_inc(&rdev->read_errors);
34175 + atomic_inc_unchecked(&rdev->read_errors);
34176 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
34177 printk_ratelimited(
34178 KERN_WARNING
34179 @@ -1798,7 +1798,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
34180 mdname(conf->mddev),
34181 (unsigned long long)s,
34182 bdn);
34183 - } else if (atomic_read(&rdev->read_errors)
34184 + } else if (atomic_read_unchecked(&rdev->read_errors)
34185 > conf->max_nr_stripes)
34186 printk(KERN_WARNING
34187 "md/raid:%s: Too many read errors, failing device %s.\n",
34188 diff --git a/drivers/media/dvb/ddbridge/ddbridge-core.c b/drivers/media/dvb/ddbridge/ddbridge-core.c
34189 index ebf3f05..b1f3e77 100644
34190 --- a/drivers/media/dvb/ddbridge/ddbridge-core.c
34191 +++ b/drivers/media/dvb/ddbridge/ddbridge-core.c
34192 @@ -1679,7 +1679,7 @@ static struct ddb_info ddb_v6 = {
34193 .subvendor = _subvend, .subdevice = _subdev, \
34194 .driver_data = (unsigned long)&_driverdata }
34195
34196 -static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
34197 +static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
34198 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
34199 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
34200 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
34201 diff --git a/drivers/media/dvb/dvb-core/dvb_demux.h b/drivers/media/dvb/dvb-core/dvb_demux.h
34202 index fa7188a..04a045e 100644
34203 --- a/drivers/media/dvb/dvb-core/dvb_demux.h
34204 +++ b/drivers/media/dvb/dvb-core/dvb_demux.h
34205 @@ -73,7 +73,7 @@ struct dvb_demux_feed {
34206 union {
34207 dmx_ts_cb ts;
34208 dmx_section_cb sec;
34209 - } cb;
34210 + } __no_const cb;
34211
34212 struct dvb_demux *demux;
34213 void *priv;
34214 diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
34215 index 39eab73..60033e7 100644
34216 --- a/drivers/media/dvb/dvb-core/dvbdev.c
34217 +++ b/drivers/media/dvb/dvb-core/dvbdev.c
34218 @@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
34219 const struct dvb_device *template, void *priv, int type)
34220 {
34221 struct dvb_device *dvbdev;
34222 - struct file_operations *dvbdevfops;
34223 + file_operations_no_const *dvbdevfops;
34224 struct device *clsdev;
34225 int minor;
34226 int id;
34227 diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
34228 index 3940bb0..fb3952a 100644
34229 --- a/drivers/media/dvb/dvb-usb/cxusb.c
34230 +++ b/drivers/media/dvb/dvb-usb/cxusb.c
34231 @@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
34232
34233 struct dib0700_adapter_state {
34234 int (*set_param_save) (struct dvb_frontend *);
34235 -};
34236 +} __no_const;
34237
34238 static int dib7070_set_param_override(struct dvb_frontend *fe)
34239 {
34240 diff --git a/drivers/media/dvb/dvb-usb/dw2102.c b/drivers/media/dvb/dvb-usb/dw2102.c
34241 index 9382895..ac8093c 100644
34242 --- a/drivers/media/dvb/dvb-usb/dw2102.c
34243 +++ b/drivers/media/dvb/dvb-usb/dw2102.c
34244 @@ -95,7 +95,7 @@ struct su3000_state {
34245
34246 struct s6x0_state {
34247 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
34248 -};
34249 +} __no_const;
34250
34251 /* debug */
34252 static int dvb_usb_dw2102_debug;
34253 diff --git a/drivers/media/dvb/frontends/dib3000.h b/drivers/media/dvb/frontends/dib3000.h
34254 index 404f63a..4796533 100644
34255 --- a/drivers/media/dvb/frontends/dib3000.h
34256 +++ b/drivers/media/dvb/frontends/dib3000.h
34257 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
34258 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
34259 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
34260 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
34261 -};
34262 +} __no_const;
34263
34264 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
34265 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
34266 diff --git a/drivers/media/dvb/ngene/ngene-cards.c b/drivers/media/dvb/ngene/ngene-cards.c
34267 index 72ee8de..eae0c80 100644
34268 --- a/drivers/media/dvb/ngene/ngene-cards.c
34269 +++ b/drivers/media/dvb/ngene/ngene-cards.c
34270 @@ -479,7 +479,7 @@ static struct ngene_info ngene_info_m780 = {
34271
34272 /****************************************************************************/
34273
34274 -static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
34275 +static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
34276 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
34277 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
34278 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
34279 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
34280 index 697a421..16c5a5f 100644
34281 --- a/drivers/media/radio/radio-cadet.c
34282 +++ b/drivers/media/radio/radio-cadet.c
34283 @@ -302,6 +302,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
34284 unsigned char readbuf[RDS_BUFFER];
34285 int i = 0;
34286
34287 + if (count > RDS_BUFFER)
34288 + return -EFAULT;
34289 mutex_lock(&dev->lock);
34290 if (dev->rdsstat == 0)
34291 cadet_start_rds(dev);
34292 @@ -317,7 +319,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
34293 while (i < count && dev->rdsin != dev->rdsout)
34294 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
34295
34296 - if (i && copy_to_user(data, readbuf, i))
34297 + if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
34298 i = -EFAULT;
34299 unlock:
34300 mutex_unlock(&dev->lock);
34301 diff --git a/drivers/media/radio/radio-tea5777.h b/drivers/media/radio/radio-tea5777.h
34302 index 55cbd78..428b0da 100644
34303 --- a/drivers/media/radio/radio-tea5777.h
34304 +++ b/drivers/media/radio/radio-tea5777.h
34305 @@ -63,7 +63,7 @@ struct radio_tea5777_ops {
34306
34307 struct radio_tea5777 {
34308 struct v4l2_device *v4l2_dev;
34309 - struct v4l2_file_operations fops;
34310 + v4l2_file_operations_no_const fops;
34311 struct video_device vd; /* video device */
34312 bool has_am; /* Device can tune to AM freqs */
34313 bool write_before_read; /* must write before read quirk */
34314 diff --git a/drivers/media/video/au0828/au0828.h b/drivers/media/video/au0828/au0828.h
34315 index 9cde353..8c6a1c3 100644
34316 --- a/drivers/media/video/au0828/au0828.h
34317 +++ b/drivers/media/video/au0828/au0828.h
34318 @@ -191,7 +191,7 @@ struct au0828_dev {
34319
34320 /* I2C */
34321 struct i2c_adapter i2c_adap;
34322 - struct i2c_algorithm i2c_algo;
34323 + i2c_algorithm_no_const i2c_algo;
34324 struct i2c_client i2c_client;
34325 u32 i2c_rc;
34326
34327 diff --git a/drivers/media/video/cx88/cx88-alsa.c b/drivers/media/video/cx88/cx88-alsa.c
34328 index dfac6e3..c26de31 100644
34329 --- a/drivers/media/video/cx88/cx88-alsa.c
34330 +++ b/drivers/media/video/cx88/cx88-alsa.c
34331 @@ -749,7 +749,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
34332 * Only boards with eeprom and byte 1 at eeprom=1 have it
34333 */
34334
34335 -static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitdata = {
34336 +static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitconst = {
34337 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
34338 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
34339 {0, }
34340 diff --git a/drivers/media/video/omap/omap_vout.c b/drivers/media/video/omap/omap_vout.c
34341 index 88cf9d9..bbc4b2c 100644
34342 --- a/drivers/media/video/omap/omap_vout.c
34343 +++ b/drivers/media/video/omap/omap_vout.c
34344 @@ -64,7 +64,6 @@ enum omap_vout_channels {
34345 OMAP_VIDEO2,
34346 };
34347
34348 -static struct videobuf_queue_ops video_vbq_ops;
34349 /* Variables configurable through module params*/
34350 static u32 video1_numbuffers = 3;
34351 static u32 video2_numbuffers = 3;
34352 @@ -1000,6 +999,12 @@ static int omap_vout_open(struct file *file)
34353 {
34354 struct videobuf_queue *q;
34355 struct omap_vout_device *vout = NULL;
34356 + static struct videobuf_queue_ops video_vbq_ops = {
34357 + .buf_setup = omap_vout_buffer_setup,
34358 + .buf_prepare = omap_vout_buffer_prepare,
34359 + .buf_release = omap_vout_buffer_release,
34360 + .buf_queue = omap_vout_buffer_queue,
34361 + };
34362
34363 vout = video_drvdata(file);
34364 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
34365 @@ -1017,10 +1022,6 @@ static int omap_vout_open(struct file *file)
34366 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
34367
34368 q = &vout->vbq;
34369 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
34370 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
34371 - video_vbq_ops.buf_release = omap_vout_buffer_release;
34372 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
34373 spin_lock_init(&vout->vbq_lock);
34374
34375 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
34376 diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34377 index 036952f..80d356d 100644
34378 --- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34379 +++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34380 @@ -196,7 +196,7 @@ struct pvr2_hdw {
34381
34382 /* I2C stuff */
34383 struct i2c_adapter i2c_adap;
34384 - struct i2c_algorithm i2c_algo;
34385 + i2c_algorithm_no_const i2c_algo;
34386 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
34387 int i2c_cx25840_hack_state;
34388 int i2c_linked;
34389 diff --git a/drivers/media/video/timblogiw.c b/drivers/media/video/timblogiw.c
34390 index 02194c0..091733b 100644
34391 --- a/drivers/media/video/timblogiw.c
34392 +++ b/drivers/media/video/timblogiw.c
34393 @@ -745,7 +745,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
34394
34395 /* Platform device functions */
34396
34397 -static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
34398 +static __devinitconst v4l2_ioctl_ops_no_const timblogiw_ioctl_ops = {
34399 .vidioc_querycap = timblogiw_querycap,
34400 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
34401 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
34402 @@ -767,7 +767,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
34403 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
34404 };
34405
34406 -static __devinitconst struct v4l2_file_operations timblogiw_fops = {
34407 +static __devinitconst v4l2_file_operations_no_const timblogiw_fops = {
34408 .owner = THIS_MODULE,
34409 .open = timblogiw_open,
34410 .release = timblogiw_close,
34411 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
34412 index d99db56..a16b959 100644
34413 --- a/drivers/message/fusion/mptbase.c
34414 +++ b/drivers/message/fusion/mptbase.c
34415 @@ -6751,8 +6751,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
34416 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
34417 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
34418
34419 +#ifdef CONFIG_GRKERNSEC_HIDESYM
34420 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
34421 +#else
34422 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
34423 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
34424 +#endif
34425 +
34426 /*
34427 * Rounding UP to nearest 4-kB boundary here...
34428 */
34429 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
34430 index 551262e..7551198 100644
34431 --- a/drivers/message/fusion/mptsas.c
34432 +++ b/drivers/message/fusion/mptsas.c
34433 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
34434 return 0;
34435 }
34436
34437 +static inline void
34438 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
34439 +{
34440 + if (phy_info->port_details) {
34441 + phy_info->port_details->rphy = rphy;
34442 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
34443 + ioc->name, rphy));
34444 + }
34445 +
34446 + if (rphy) {
34447 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
34448 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
34449 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
34450 + ioc->name, rphy, rphy->dev.release));
34451 + }
34452 +}
34453 +
34454 /* no mutex */
34455 static void
34456 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
34457 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
34458 return NULL;
34459 }
34460
34461 -static inline void
34462 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
34463 -{
34464 - if (phy_info->port_details) {
34465 - phy_info->port_details->rphy = rphy;
34466 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
34467 - ioc->name, rphy));
34468 - }
34469 -
34470 - if (rphy) {
34471 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
34472 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
34473 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
34474 - ioc->name, rphy, rphy->dev.release));
34475 - }
34476 -}
34477 -
34478 static inline struct sas_port *
34479 mptsas_get_port(struct mptsas_phyinfo *phy_info)
34480 {
34481 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
34482 index 0c3ced7..1fe34ec 100644
34483 --- a/drivers/message/fusion/mptscsih.c
34484 +++ b/drivers/message/fusion/mptscsih.c
34485 @@ -1270,15 +1270,16 @@ mptscsih_info(struct Scsi_Host *SChost)
34486
34487 h = shost_priv(SChost);
34488
34489 - if (h) {
34490 - if (h->info_kbuf == NULL)
34491 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34492 - return h->info_kbuf;
34493 - h->info_kbuf[0] = '\0';
34494 + if (!h)
34495 + return NULL;
34496
34497 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34498 - h->info_kbuf[size-1] = '\0';
34499 - }
34500 + if (h->info_kbuf == NULL)
34501 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34502 + return h->info_kbuf;
34503 + h->info_kbuf[0] = '\0';
34504 +
34505 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34506 + h->info_kbuf[size-1] = '\0';
34507
34508 return h->info_kbuf;
34509 }
34510 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
34511 index 8001aa6..b137580 100644
34512 --- a/drivers/message/i2o/i2o_proc.c
34513 +++ b/drivers/message/i2o/i2o_proc.c
34514 @@ -255,12 +255,6 @@ static char *scsi_devices[] = {
34515 "Array Controller Device"
34516 };
34517
34518 -static char *chtostr(char *tmp, u8 *chars, int n)
34519 -{
34520 - tmp[0] = 0;
34521 - return strncat(tmp, (char *)chars, n);
34522 -}
34523 -
34524 static int i2o_report_query_status(struct seq_file *seq, int block_status,
34525 char *group)
34526 {
34527 @@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
34528 } *result;
34529
34530 i2o_exec_execute_ddm_table ddm_table;
34531 - char tmp[28 + 1];
34532
34533 result = kmalloc(sizeof(*result), GFP_KERNEL);
34534 if (!result)
34535 @@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
34536
34537 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
34538 seq_printf(seq, "%-#8x", ddm_table.module_id);
34539 - seq_printf(seq, "%-29s",
34540 - chtostr(tmp, ddm_table.module_name_version, 28));
34541 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
34542 seq_printf(seq, "%9d ", ddm_table.data_size);
34543 seq_printf(seq, "%8d", ddm_table.code_size);
34544
34545 @@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
34546
34547 i2o_driver_result_table *result;
34548 i2o_driver_store_table *dst;
34549 - char tmp[28 + 1];
34550
34551 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
34552 if (result == NULL)
34553 @@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
34554
34555 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
34556 seq_printf(seq, "%-#8x", dst->module_id);
34557 - seq_printf(seq, "%-29s",
34558 - chtostr(tmp, dst->module_name_version, 28));
34559 - seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
34560 + seq_printf(seq, "%-.28s", dst->module_name_version);
34561 + seq_printf(seq, "%-.8s", dst->date);
34562 seq_printf(seq, "%8d ", dst->module_size);
34563 seq_printf(seq, "%8d ", dst->mpb_size);
34564 seq_printf(seq, "0x%04x", dst->module_flags);
34565 @@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
34566 // == (allow) 512d bytes (max)
34567 static u16 *work16 = (u16 *) work32;
34568 int token;
34569 - char tmp[16 + 1];
34570
34571 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
34572
34573 @@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
34574 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
34575 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
34576 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
34577 - seq_printf(seq, "Vendor info : %s\n",
34578 - chtostr(tmp, (u8 *) (work32 + 2), 16));
34579 - seq_printf(seq, "Product info : %s\n",
34580 - chtostr(tmp, (u8 *) (work32 + 6), 16));
34581 - seq_printf(seq, "Description : %s\n",
34582 - chtostr(tmp, (u8 *) (work32 + 10), 16));
34583 - seq_printf(seq, "Product rev. : %s\n",
34584 - chtostr(tmp, (u8 *) (work32 + 14), 8));
34585 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
34586 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
34587 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
34588 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
34589
34590 seq_printf(seq, "Serial number : ");
34591 print_serial_number(seq, (u8 *) (work32 + 16),
34592 @@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
34593 u8 pad[256]; // allow up to 256 byte (max) serial number
34594 } result;
34595
34596 - char tmp[24 + 1];
34597 -
34598 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
34599
34600 if (token < 0) {
34601 @@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
34602 }
34603
34604 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
34605 - seq_printf(seq, "Module name : %s\n",
34606 - chtostr(tmp, result.module_name, 24));
34607 - seq_printf(seq, "Module revision : %s\n",
34608 - chtostr(tmp, result.module_rev, 8));
34609 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
34610 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
34611
34612 seq_printf(seq, "Serial number : ");
34613 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
34614 @@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
34615 u8 instance_number[4];
34616 } result;
34617
34618 - char tmp[64 + 1];
34619 -
34620 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
34621
34622 if (token < 0) {
34623 @@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
34624 return 0;
34625 }
34626
34627 - seq_printf(seq, "Device name : %s\n",
34628 - chtostr(tmp, result.device_name, 64));
34629 - seq_printf(seq, "Service name : %s\n",
34630 - chtostr(tmp, result.service_name, 64));
34631 - seq_printf(seq, "Physical name : %s\n",
34632 - chtostr(tmp, result.physical_location, 64));
34633 - seq_printf(seq, "Instance number : %s\n",
34634 - chtostr(tmp, result.instance_number, 4));
34635 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
34636 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
34637 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
34638 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
34639
34640 return 0;
34641 }
34642 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
34643 index a8c08f3..155fe3d 100644
34644 --- a/drivers/message/i2o/iop.c
34645 +++ b/drivers/message/i2o/iop.c
34646 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
34647
34648 spin_lock_irqsave(&c->context_list_lock, flags);
34649
34650 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
34651 - atomic_inc(&c->context_list_counter);
34652 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
34653 + atomic_inc_unchecked(&c->context_list_counter);
34654
34655 - entry->context = atomic_read(&c->context_list_counter);
34656 + entry->context = atomic_read_unchecked(&c->context_list_counter);
34657
34658 list_add(&entry->list, &c->context_list);
34659
34660 @@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
34661
34662 #if BITS_PER_LONG == 64
34663 spin_lock_init(&c->context_list_lock);
34664 - atomic_set(&c->context_list_counter, 0);
34665 + atomic_set_unchecked(&c->context_list_counter, 0);
34666 INIT_LIST_HEAD(&c->context_list);
34667 #endif
34668
34669 diff --git a/drivers/mfd/abx500-core.c b/drivers/mfd/abx500-core.c
34670 index 7ce65f4..e66e9bc 100644
34671 --- a/drivers/mfd/abx500-core.c
34672 +++ b/drivers/mfd/abx500-core.c
34673 @@ -15,7 +15,7 @@ static LIST_HEAD(abx500_list);
34674
34675 struct abx500_device_entry {
34676 struct list_head list;
34677 - struct abx500_ops ops;
34678 + abx500_ops_no_const ops;
34679 struct device *dev;
34680 };
34681
34682 diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
34683 index 965c480..71f2db9 100644
34684 --- a/drivers/mfd/janz-cmodio.c
34685 +++ b/drivers/mfd/janz-cmodio.c
34686 @@ -13,6 +13,7 @@
34687
34688 #include <linux/kernel.h>
34689 #include <linux/module.h>
34690 +#include <linux/slab.h>
34691 #include <linux/init.h>
34692 #include <linux/pci.h>
34693 #include <linux/interrupt.h>
34694 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
34695 index a981e2a..5ca0c8b 100644
34696 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
34697 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
34698 @@ -466,7 +466,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
34699 * the lid is closed. This leads to interrupts as soon as a little move
34700 * is done.
34701 */
34702 - atomic_inc(&lis3->count);
34703 + atomic_inc_unchecked(&lis3->count);
34704
34705 wake_up_interruptible(&lis3->misc_wait);
34706 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
34707 @@ -552,7 +552,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
34708 if (lis3->pm_dev)
34709 pm_runtime_get_sync(lis3->pm_dev);
34710
34711 - atomic_set(&lis3->count, 0);
34712 + atomic_set_unchecked(&lis3->count, 0);
34713 return 0;
34714 }
34715
34716 @@ -585,7 +585,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
34717 add_wait_queue(&lis3->misc_wait, &wait);
34718 while (true) {
34719 set_current_state(TASK_INTERRUPTIBLE);
34720 - data = atomic_xchg(&lis3->count, 0);
34721 + data = atomic_xchg_unchecked(&lis3->count, 0);
34722 if (data)
34723 break;
34724
34725 @@ -626,7 +626,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
34726 struct lis3lv02d, miscdev);
34727
34728 poll_wait(file, &lis3->misc_wait, wait);
34729 - if (atomic_read(&lis3->count))
34730 + if (atomic_read_unchecked(&lis3->count))
34731 return POLLIN | POLLRDNORM;
34732 return 0;
34733 }
34734 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
34735 index 2b1482a..5d33616 100644
34736 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
34737 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
34738 @@ -266,7 +266,7 @@ struct lis3lv02d {
34739 struct input_polled_dev *idev; /* input device */
34740 struct platform_device *pdev; /* platform device */
34741 struct regulator_bulk_data regulators[2];
34742 - atomic_t count; /* interrupt count after last read */
34743 + atomic_unchecked_t count; /* interrupt count after last read */
34744 union axis_conversion ac; /* hw -> logical axis */
34745 int mapped_btns[3];
34746
34747 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
34748 index 2f30bad..c4c13d0 100644
34749 --- a/drivers/misc/sgi-gru/gruhandles.c
34750 +++ b/drivers/misc/sgi-gru/gruhandles.c
34751 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
34752 unsigned long nsec;
34753
34754 nsec = CLKS2NSEC(clks);
34755 - atomic_long_inc(&mcs_op_statistics[op].count);
34756 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
34757 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
34758 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
34759 if (mcs_op_statistics[op].max < nsec)
34760 mcs_op_statistics[op].max = nsec;
34761 }
34762 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
34763 index 950dbe9..eeef0f8 100644
34764 --- a/drivers/misc/sgi-gru/gruprocfs.c
34765 +++ b/drivers/misc/sgi-gru/gruprocfs.c
34766 @@ -32,9 +32,9 @@
34767
34768 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
34769
34770 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
34771 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
34772 {
34773 - unsigned long val = atomic_long_read(v);
34774 + unsigned long val = atomic_long_read_unchecked(v);
34775
34776 seq_printf(s, "%16lu %s\n", val, id);
34777 }
34778 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
34779
34780 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
34781 for (op = 0; op < mcsop_last; op++) {
34782 - count = atomic_long_read(&mcs_op_statistics[op].count);
34783 - total = atomic_long_read(&mcs_op_statistics[op].total);
34784 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
34785 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
34786 max = mcs_op_statistics[op].max;
34787 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
34788 count ? total / count : 0, max);
34789 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
34790 index 5c3ce24..4915ccb 100644
34791 --- a/drivers/misc/sgi-gru/grutables.h
34792 +++ b/drivers/misc/sgi-gru/grutables.h
34793 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
34794 * GRU statistics.
34795 */
34796 struct gru_stats_s {
34797 - atomic_long_t vdata_alloc;
34798 - atomic_long_t vdata_free;
34799 - atomic_long_t gts_alloc;
34800 - atomic_long_t gts_free;
34801 - atomic_long_t gms_alloc;
34802 - atomic_long_t gms_free;
34803 - atomic_long_t gts_double_allocate;
34804 - atomic_long_t assign_context;
34805 - atomic_long_t assign_context_failed;
34806 - atomic_long_t free_context;
34807 - atomic_long_t load_user_context;
34808 - atomic_long_t load_kernel_context;
34809 - atomic_long_t lock_kernel_context;
34810 - atomic_long_t unlock_kernel_context;
34811 - atomic_long_t steal_user_context;
34812 - atomic_long_t steal_kernel_context;
34813 - atomic_long_t steal_context_failed;
34814 - atomic_long_t nopfn;
34815 - atomic_long_t asid_new;
34816 - atomic_long_t asid_next;
34817 - atomic_long_t asid_wrap;
34818 - atomic_long_t asid_reuse;
34819 - atomic_long_t intr;
34820 - atomic_long_t intr_cbr;
34821 - atomic_long_t intr_tfh;
34822 - atomic_long_t intr_spurious;
34823 - atomic_long_t intr_mm_lock_failed;
34824 - atomic_long_t call_os;
34825 - atomic_long_t call_os_wait_queue;
34826 - atomic_long_t user_flush_tlb;
34827 - atomic_long_t user_unload_context;
34828 - atomic_long_t user_exception;
34829 - atomic_long_t set_context_option;
34830 - atomic_long_t check_context_retarget_intr;
34831 - atomic_long_t check_context_unload;
34832 - atomic_long_t tlb_dropin;
34833 - atomic_long_t tlb_preload_page;
34834 - atomic_long_t tlb_dropin_fail_no_asid;
34835 - atomic_long_t tlb_dropin_fail_upm;
34836 - atomic_long_t tlb_dropin_fail_invalid;
34837 - atomic_long_t tlb_dropin_fail_range_active;
34838 - atomic_long_t tlb_dropin_fail_idle;
34839 - atomic_long_t tlb_dropin_fail_fmm;
34840 - atomic_long_t tlb_dropin_fail_no_exception;
34841 - atomic_long_t tfh_stale_on_fault;
34842 - atomic_long_t mmu_invalidate_range;
34843 - atomic_long_t mmu_invalidate_page;
34844 - atomic_long_t flush_tlb;
34845 - atomic_long_t flush_tlb_gru;
34846 - atomic_long_t flush_tlb_gru_tgh;
34847 - atomic_long_t flush_tlb_gru_zero_asid;
34848 + atomic_long_unchecked_t vdata_alloc;
34849 + atomic_long_unchecked_t vdata_free;
34850 + atomic_long_unchecked_t gts_alloc;
34851 + atomic_long_unchecked_t gts_free;
34852 + atomic_long_unchecked_t gms_alloc;
34853 + atomic_long_unchecked_t gms_free;
34854 + atomic_long_unchecked_t gts_double_allocate;
34855 + atomic_long_unchecked_t assign_context;
34856 + atomic_long_unchecked_t assign_context_failed;
34857 + atomic_long_unchecked_t free_context;
34858 + atomic_long_unchecked_t load_user_context;
34859 + atomic_long_unchecked_t load_kernel_context;
34860 + atomic_long_unchecked_t lock_kernel_context;
34861 + atomic_long_unchecked_t unlock_kernel_context;
34862 + atomic_long_unchecked_t steal_user_context;
34863 + atomic_long_unchecked_t steal_kernel_context;
34864 + atomic_long_unchecked_t steal_context_failed;
34865 + atomic_long_unchecked_t nopfn;
34866 + atomic_long_unchecked_t asid_new;
34867 + atomic_long_unchecked_t asid_next;
34868 + atomic_long_unchecked_t asid_wrap;
34869 + atomic_long_unchecked_t asid_reuse;
34870 + atomic_long_unchecked_t intr;
34871 + atomic_long_unchecked_t intr_cbr;
34872 + atomic_long_unchecked_t intr_tfh;
34873 + atomic_long_unchecked_t intr_spurious;
34874 + atomic_long_unchecked_t intr_mm_lock_failed;
34875 + atomic_long_unchecked_t call_os;
34876 + atomic_long_unchecked_t call_os_wait_queue;
34877 + atomic_long_unchecked_t user_flush_tlb;
34878 + atomic_long_unchecked_t user_unload_context;
34879 + atomic_long_unchecked_t user_exception;
34880 + atomic_long_unchecked_t set_context_option;
34881 + atomic_long_unchecked_t check_context_retarget_intr;
34882 + atomic_long_unchecked_t check_context_unload;
34883 + atomic_long_unchecked_t tlb_dropin;
34884 + atomic_long_unchecked_t tlb_preload_page;
34885 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
34886 + atomic_long_unchecked_t tlb_dropin_fail_upm;
34887 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
34888 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
34889 + atomic_long_unchecked_t tlb_dropin_fail_idle;
34890 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
34891 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
34892 + atomic_long_unchecked_t tfh_stale_on_fault;
34893 + atomic_long_unchecked_t mmu_invalidate_range;
34894 + atomic_long_unchecked_t mmu_invalidate_page;
34895 + atomic_long_unchecked_t flush_tlb;
34896 + atomic_long_unchecked_t flush_tlb_gru;
34897 + atomic_long_unchecked_t flush_tlb_gru_tgh;
34898 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
34899
34900 - atomic_long_t copy_gpa;
34901 - atomic_long_t read_gpa;
34902 + atomic_long_unchecked_t copy_gpa;
34903 + atomic_long_unchecked_t read_gpa;
34904
34905 - atomic_long_t mesq_receive;
34906 - atomic_long_t mesq_receive_none;
34907 - atomic_long_t mesq_send;
34908 - atomic_long_t mesq_send_failed;
34909 - atomic_long_t mesq_noop;
34910 - atomic_long_t mesq_send_unexpected_error;
34911 - atomic_long_t mesq_send_lb_overflow;
34912 - atomic_long_t mesq_send_qlimit_reached;
34913 - atomic_long_t mesq_send_amo_nacked;
34914 - atomic_long_t mesq_send_put_nacked;
34915 - atomic_long_t mesq_page_overflow;
34916 - atomic_long_t mesq_qf_locked;
34917 - atomic_long_t mesq_qf_noop_not_full;
34918 - atomic_long_t mesq_qf_switch_head_failed;
34919 - atomic_long_t mesq_qf_unexpected_error;
34920 - atomic_long_t mesq_noop_unexpected_error;
34921 - atomic_long_t mesq_noop_lb_overflow;
34922 - atomic_long_t mesq_noop_qlimit_reached;
34923 - atomic_long_t mesq_noop_amo_nacked;
34924 - atomic_long_t mesq_noop_put_nacked;
34925 - atomic_long_t mesq_noop_page_overflow;
34926 + atomic_long_unchecked_t mesq_receive;
34927 + atomic_long_unchecked_t mesq_receive_none;
34928 + atomic_long_unchecked_t mesq_send;
34929 + atomic_long_unchecked_t mesq_send_failed;
34930 + atomic_long_unchecked_t mesq_noop;
34931 + atomic_long_unchecked_t mesq_send_unexpected_error;
34932 + atomic_long_unchecked_t mesq_send_lb_overflow;
34933 + atomic_long_unchecked_t mesq_send_qlimit_reached;
34934 + atomic_long_unchecked_t mesq_send_amo_nacked;
34935 + atomic_long_unchecked_t mesq_send_put_nacked;
34936 + atomic_long_unchecked_t mesq_page_overflow;
34937 + atomic_long_unchecked_t mesq_qf_locked;
34938 + atomic_long_unchecked_t mesq_qf_noop_not_full;
34939 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
34940 + atomic_long_unchecked_t mesq_qf_unexpected_error;
34941 + atomic_long_unchecked_t mesq_noop_unexpected_error;
34942 + atomic_long_unchecked_t mesq_noop_lb_overflow;
34943 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
34944 + atomic_long_unchecked_t mesq_noop_amo_nacked;
34945 + atomic_long_unchecked_t mesq_noop_put_nacked;
34946 + atomic_long_unchecked_t mesq_noop_page_overflow;
34947
34948 };
34949
34950 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
34951 tghop_invalidate, mcsop_last};
34952
34953 struct mcs_op_statistic {
34954 - atomic_long_t count;
34955 - atomic_long_t total;
34956 + atomic_long_unchecked_t count;
34957 + atomic_long_unchecked_t total;
34958 unsigned long max;
34959 };
34960
34961 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
34962
34963 #define STAT(id) do { \
34964 if (gru_options & OPT_STATS) \
34965 - atomic_long_inc(&gru_stats.id); \
34966 + atomic_long_inc_unchecked(&gru_stats.id); \
34967 } while (0)
34968
34969 #ifdef CONFIG_SGI_GRU_DEBUG
34970 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
34971 index c862cd4..0d176fe 100644
34972 --- a/drivers/misc/sgi-xp/xp.h
34973 +++ b/drivers/misc/sgi-xp/xp.h
34974 @@ -288,7 +288,7 @@ struct xpc_interface {
34975 xpc_notify_func, void *);
34976 void (*received) (short, int, void *);
34977 enum xp_retval (*partid_to_nasids) (short, void *);
34978 -};
34979 +} __no_const;
34980
34981 extern struct xpc_interface xpc_interface;
34982
34983 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
34984 index b94d5f7..7f494c5 100644
34985 --- a/drivers/misc/sgi-xp/xpc.h
34986 +++ b/drivers/misc/sgi-xp/xpc.h
34987 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
34988 void (*received_payload) (struct xpc_channel *, void *);
34989 void (*notify_senders_of_disconnect) (struct xpc_channel *);
34990 };
34991 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
34992
34993 /* struct xpc_partition act_state values (for XPC HB) */
34994
34995 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
34996 /* found in xpc_main.c */
34997 extern struct device *xpc_part;
34998 extern struct device *xpc_chan;
34999 -extern struct xpc_arch_operations xpc_arch_ops;
35000 +extern xpc_arch_operations_no_const xpc_arch_ops;
35001 extern int xpc_disengage_timelimit;
35002 extern int xpc_disengage_timedout;
35003 extern int xpc_activate_IRQ_rcvd;
35004 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
35005 index 8d082b4..aa749ae 100644
35006 --- a/drivers/misc/sgi-xp/xpc_main.c
35007 +++ b/drivers/misc/sgi-xp/xpc_main.c
35008 @@ -162,7 +162,7 @@ static struct notifier_block xpc_die_notifier = {
35009 .notifier_call = xpc_system_die,
35010 };
35011
35012 -struct xpc_arch_operations xpc_arch_ops;
35013 +xpc_arch_operations_no_const xpc_arch_ops;
35014
35015 /*
35016 * Timer function to enforce the timelimit on the partition disengage.
35017 diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
35018 index 504da71..9722d43 100644
35019 --- a/drivers/mmc/host/sdhci-pci.c
35020 +++ b/drivers/mmc/host/sdhci-pci.c
35021 @@ -653,7 +653,7 @@ static const struct sdhci_pci_fixes sdhci_via = {
35022 .probe = via_probe,
35023 };
35024
35025 -static const struct pci_device_id pci_ids[] __devinitdata = {
35026 +static const struct pci_device_id pci_ids[] __devinitconst = {
35027 {
35028 .vendor = PCI_VENDOR_ID_RICOH,
35029 .device = PCI_DEVICE_ID_RICOH_R5C822,
35030 diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
35031 index a4eb8b5..8c0628f 100644
35032 --- a/drivers/mtd/devices/doc2000.c
35033 +++ b/drivers/mtd/devices/doc2000.c
35034 @@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
35035
35036 /* The ECC will not be calculated correctly if less than 512 is written */
35037 /* DBB-
35038 - if (len != 0x200 && eccbuf)
35039 + if (len != 0x200)
35040 printk(KERN_WARNING
35041 "ECC needs a full sector write (adr: %lx size %lx)\n",
35042 (long) to, (long) len);
35043 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
35044 index 0650aaf..7718762 100644
35045 --- a/drivers/mtd/nand/denali.c
35046 +++ b/drivers/mtd/nand/denali.c
35047 @@ -26,6 +26,7 @@
35048 #include <linux/pci.h>
35049 #include <linux/mtd/mtd.h>
35050 #include <linux/module.h>
35051 +#include <linux/slab.h>
35052
35053 #include "denali.h"
35054
35055 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
35056 index 51b9d6a..52af9a7 100644
35057 --- a/drivers/mtd/nftlmount.c
35058 +++ b/drivers/mtd/nftlmount.c
35059 @@ -24,6 +24,7 @@
35060 #include <asm/errno.h>
35061 #include <linux/delay.h>
35062 #include <linux/slab.h>
35063 +#include <linux/sched.h>
35064 #include <linux/mtd/mtd.h>
35065 #include <linux/mtd/nand.h>
35066 #include <linux/mtd/nftl.h>
35067 diff --git a/drivers/net/bonding/bond_sysfs.c b/drivers/net/bonding/bond_sysfs.c
35068 index dc15d24..ef8d2a0 100644
35069 --- a/drivers/net/bonding/bond_sysfs.c
35070 +++ b/drivers/net/bonding/bond_sysfs.c
35071 @@ -1060,7 +1060,7 @@ static ssize_t bonding_store_primary(struct device *d,
35072 goto out;
35073 }
35074
35075 - sscanf(buf, "%16s", ifname); /* IFNAMSIZ */
35076 + sscanf(buf, "%15s", ifname); /* IFNAMSIZ */
35077
35078 /* check to see if we are clearing primary */
35079 if (!strlen(ifname) || buf[0] == '\n') {
35080 @@ -1237,7 +1237,7 @@ static ssize_t bonding_store_active_slave(struct device *d,
35081 goto out;
35082 }
35083
35084 - sscanf(buf, "%16s", ifname); /* IFNAMSIZ */
35085 + sscanf(buf, "%15s", ifname); /* IFNAMSIZ */
35086
35087 /* check to see if we are clearing active */
35088 if (!strlen(ifname) || buf[0] == '\n') {
35089 diff --git a/drivers/net/ethernet/atheros/atlx/atl2.c b/drivers/net/ethernet/atheros/atlx/atl2.c
35090 index 57d64b8..623dd86 100644
35091 --- a/drivers/net/ethernet/atheros/atlx/atl2.c
35092 +++ b/drivers/net/ethernet/atheros/atlx/atl2.c
35093 @@ -2845,7 +2845,7 @@ static void atl2_force_ps(struct atl2_hw *hw)
35094 */
35095
35096 #define ATL2_PARAM(X, desc) \
35097 - static const int __devinitdata X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
35098 + static const int __devinitconst X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
35099 MODULE_PARM(X, "1-" __MODULE_STRING(ATL2_MAX_NIC) "i"); \
35100 MODULE_PARM_DESC(X, desc);
35101 #else
35102 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
35103 index 0875ecf..794cdf3 100644
35104 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
35105 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
35106 @@ -3051,9 +3051,8 @@ static void bnx2x_drv_info_ether_stat(struct bnx2x *bp)
35107 struct eth_stats_info *ether_stat =
35108 &bp->slowpath->drv_info_to_mcp.ether_stat;
35109
35110 - /* leave last char as NULL */
35111 - memcpy(ether_stat->version, DRV_MODULE_VERSION,
35112 - ETH_STAT_INFO_VERSION_LEN - 1);
35113 + strlcpy(ether_stat->version, DRV_MODULE_VERSION,
35114 + ETH_STAT_INFO_VERSION_LEN);
35115
35116 bp->sp_objs[0].mac_obj.get_n_elements(bp, &bp->sp_objs[0].mac_obj,
35117 DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED,
35118 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
35119 index f83e033..8b4f43a 100644
35120 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
35121 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
35122 @@ -486,7 +486,7 @@ struct bnx2x_rx_mode_obj {
35123
35124 int (*wait_comp)(struct bnx2x *bp,
35125 struct bnx2x_rx_mode_ramrod_params *p);
35126 -};
35127 +} __no_const;
35128
35129 /********************** Set multicast group ***********************************/
35130
35131 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
35132 index 6d52cb2..bc95640 100644
35133 --- a/drivers/net/ethernet/broadcom/tg3.h
35134 +++ b/drivers/net/ethernet/broadcom/tg3.h
35135 @@ -140,6 +140,7 @@
35136 #define CHIPREV_ID_5750_A0 0x4000
35137 #define CHIPREV_ID_5750_A1 0x4001
35138 #define CHIPREV_ID_5750_A3 0x4003
35139 +#define CHIPREV_ID_5750_C1 0x4201
35140 #define CHIPREV_ID_5750_C2 0x4202
35141 #define CHIPREV_ID_5752_A0_HW 0x5000
35142 #define CHIPREV_ID_5752_A0 0x6000
35143 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
35144 index 8cffcdf..aadf043 100644
35145 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
35146 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
35147 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
35148 */
35149 struct l2t_skb_cb {
35150 arp_failure_handler_func arp_failure_handler;
35151 -};
35152 +} __no_const;
35153
35154 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
35155
35156 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
35157 index f879e92..726f20f 100644
35158 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
35159 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
35160 @@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
35161 for (i=0; i<ETH_ALEN; i++) {
35162 tmp.addr[i] = dev->dev_addr[i];
35163 }
35164 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
35165 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
35166 break;
35167
35168 case DE4X5_SET_HWADDR: /* Set the hardware address */
35169 @@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
35170 spin_lock_irqsave(&lp->lock, flags);
35171 memcpy(&statbuf, &lp->pktStats, ioc->len);
35172 spin_unlock_irqrestore(&lp->lock, flags);
35173 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
35174 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
35175 return -EFAULT;
35176 break;
35177 }
35178 diff --git a/drivers/net/ethernet/dec/tulip/eeprom.c b/drivers/net/ethernet/dec/tulip/eeprom.c
35179 index ed7d1dc..d426748 100644
35180 --- a/drivers/net/ethernet/dec/tulip/eeprom.c
35181 +++ b/drivers/net/ethernet/dec/tulip/eeprom.c
35182 @@ -79,7 +79,7 @@ static struct eeprom_fixup eeprom_fixups[] __devinitdata = {
35183 {NULL}};
35184
35185
35186 -static const char *block_name[] __devinitdata = {
35187 +static const char *block_name[] __devinitconst = {
35188 "21140 non-MII",
35189 "21140 MII PHY",
35190 "21142 Serial PHY",
35191 diff --git a/drivers/net/ethernet/dec/tulip/uli526x.c b/drivers/net/ethernet/dec/tulip/uli526x.c
35192 index 75d45f8..3d9c55b 100644
35193 --- a/drivers/net/ethernet/dec/tulip/uli526x.c
35194 +++ b/drivers/net/ethernet/dec/tulip/uli526x.c
35195 @@ -129,7 +129,7 @@ struct uli526x_board_info {
35196 struct uli_phy_ops {
35197 void (*write)(struct uli526x_board_info *, u8, u8, u16);
35198 u16 (*read)(struct uli526x_board_info *, u8, u8);
35199 - } phy;
35200 + } __no_const phy;
35201 struct net_device *next_dev; /* next device */
35202 struct pci_dev *pdev; /* PCI device */
35203 spinlock_t lock;
35204 diff --git a/drivers/net/ethernet/dec/tulip/winbond-840.c b/drivers/net/ethernet/dec/tulip/winbond-840.c
35205 index 4d1ffca..7c1ec4d 100644
35206 --- a/drivers/net/ethernet/dec/tulip/winbond-840.c
35207 +++ b/drivers/net/ethernet/dec/tulip/winbond-840.c
35208 @@ -236,7 +236,7 @@ struct pci_id_info {
35209 int drv_flags; /* Driver use, intended as capability flags. */
35210 };
35211
35212 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
35213 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
35214 { /* Sometime a Level-One switch card. */
35215 "Winbond W89c840", CanHaveMII | HasBrokenTx | FDXOnNoMII},
35216 { "Winbond W89c840", CanHaveMII | HasBrokenTx},
35217 diff --git a/drivers/net/ethernet/dlink/sundance.c b/drivers/net/ethernet/dlink/sundance.c
35218 index d7bb52a..3b83588 100644
35219 --- a/drivers/net/ethernet/dlink/sundance.c
35220 +++ b/drivers/net/ethernet/dlink/sundance.c
35221 @@ -218,7 +218,7 @@ enum {
35222 struct pci_id_info {
35223 const char *name;
35224 };
35225 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
35226 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
35227 {"D-Link DFE-550TX FAST Ethernet Adapter"},
35228 {"D-Link DFE-550FX 100Mbps Fiber-optics Adapter"},
35229 {"D-Link DFE-580TX 4 port Server Adapter"},
35230 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
35231 index 78b8aa8..dd6323a 100644
35232 --- a/drivers/net/ethernet/emulex/benet/be_main.c
35233 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
35234 @@ -403,7 +403,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
35235
35236 if (wrapped)
35237 newacc += 65536;
35238 - ACCESS_ONCE(*acc) = newacc;
35239 + ACCESS_ONCE_RW(*acc) = newacc;
35240 }
35241
35242 void be_parse_stats(struct be_adapter *adapter)
35243 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
35244 index 74d749e..eefb1bd 100644
35245 --- a/drivers/net/ethernet/faraday/ftgmac100.c
35246 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
35247 @@ -31,6 +31,8 @@
35248 #include <linux/netdevice.h>
35249 #include <linux/phy.h>
35250 #include <linux/platform_device.h>
35251 +#include <linux/interrupt.h>
35252 +#include <linux/irqreturn.h>
35253 #include <net/ip.h>
35254
35255 #include "ftgmac100.h"
35256 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
35257 index b901a01..1ff32ee 100644
35258 --- a/drivers/net/ethernet/faraday/ftmac100.c
35259 +++ b/drivers/net/ethernet/faraday/ftmac100.c
35260 @@ -31,6 +31,8 @@
35261 #include <linux/module.h>
35262 #include <linux/netdevice.h>
35263 #include <linux/platform_device.h>
35264 +#include <linux/interrupt.h>
35265 +#include <linux/irqreturn.h>
35266
35267 #include "ftmac100.h"
35268
35269 diff --git a/drivers/net/ethernet/fealnx.c b/drivers/net/ethernet/fealnx.c
35270 index 9d71c9c..0e4a0ac 100644
35271 --- a/drivers/net/ethernet/fealnx.c
35272 +++ b/drivers/net/ethernet/fealnx.c
35273 @@ -150,7 +150,7 @@ struct chip_info {
35274 int flags;
35275 };
35276
35277 -static const struct chip_info skel_netdrv_tbl[] __devinitdata = {
35278 +static const struct chip_info skel_netdrv_tbl[] __devinitconst = {
35279 { "100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
35280 { "100/10M Ethernet PCI Adapter", HAS_CHIP_XCVR },
35281 { "1000/100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
35282 diff --git a/drivers/net/ethernet/intel/e1000e/hw.h b/drivers/net/ethernet/intel/e1000e/hw.h
35283 index ed5b409..ec37828 100644
35284 --- a/drivers/net/ethernet/intel/e1000e/hw.h
35285 +++ b/drivers/net/ethernet/intel/e1000e/hw.h
35286 @@ -797,6 +797,7 @@ struct e1000_mac_operations {
35287 void (*rar_set)(struct e1000_hw *, u8 *, u32);
35288 s32 (*read_mac_addr)(struct e1000_hw *);
35289 };
35290 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35291
35292 /*
35293 * When to use various PHY register access functions:
35294 @@ -837,6 +838,7 @@ struct e1000_phy_operations {
35295 void (*power_up)(struct e1000_hw *);
35296 void (*power_down)(struct e1000_hw *);
35297 };
35298 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
35299
35300 /* Function pointers for the NVM. */
35301 struct e1000_nvm_operations {
35302 @@ -849,9 +851,10 @@ struct e1000_nvm_operations {
35303 s32 (*validate)(struct e1000_hw *);
35304 s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
35305 };
35306 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
35307
35308 struct e1000_mac_info {
35309 - struct e1000_mac_operations ops;
35310 + e1000_mac_operations_no_const ops;
35311 u8 addr[ETH_ALEN];
35312 u8 perm_addr[ETH_ALEN];
35313
35314 @@ -892,7 +895,7 @@ struct e1000_mac_info {
35315 };
35316
35317 struct e1000_phy_info {
35318 - struct e1000_phy_operations ops;
35319 + e1000_phy_operations_no_const ops;
35320
35321 enum e1000_phy_type type;
35322
35323 @@ -926,7 +929,7 @@ struct e1000_phy_info {
35324 };
35325
35326 struct e1000_nvm_info {
35327 - struct e1000_nvm_operations ops;
35328 + e1000_nvm_operations_no_const ops;
35329
35330 enum e1000_nvm_type type;
35331 enum e1000_nvm_override override;
35332 diff --git a/drivers/net/ethernet/intel/igb/e1000_hw.h b/drivers/net/ethernet/intel/igb/e1000_hw.h
35333 index c2a51dc..c2bd262 100644
35334 --- a/drivers/net/ethernet/intel/igb/e1000_hw.h
35335 +++ b/drivers/net/ethernet/intel/igb/e1000_hw.h
35336 @@ -327,6 +327,7 @@ struct e1000_mac_operations {
35337 void (*release_swfw_sync)(struct e1000_hw *, u16);
35338
35339 };
35340 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35341
35342 struct e1000_phy_operations {
35343 s32 (*acquire)(struct e1000_hw *);
35344 @@ -343,6 +344,7 @@ struct e1000_phy_operations {
35345 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
35346 s32 (*write_reg)(struct e1000_hw *, u32, u16);
35347 };
35348 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
35349
35350 struct e1000_nvm_operations {
35351 s32 (*acquire)(struct e1000_hw *);
35352 @@ -353,6 +355,7 @@ struct e1000_nvm_operations {
35353 s32 (*validate)(struct e1000_hw *);
35354 s32 (*valid_led_default)(struct e1000_hw *, u16 *);
35355 };
35356 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
35357
35358 struct e1000_info {
35359 s32 (*get_invariants)(struct e1000_hw *);
35360 @@ -364,7 +367,7 @@ struct e1000_info {
35361 extern const struct e1000_info e1000_82575_info;
35362
35363 struct e1000_mac_info {
35364 - struct e1000_mac_operations ops;
35365 + e1000_mac_operations_no_const ops;
35366
35367 u8 addr[6];
35368 u8 perm_addr[6];
35369 @@ -402,7 +405,7 @@ struct e1000_mac_info {
35370 };
35371
35372 struct e1000_phy_info {
35373 - struct e1000_phy_operations ops;
35374 + e1000_phy_operations_no_const ops;
35375
35376 enum e1000_phy_type type;
35377
35378 @@ -437,7 +440,7 @@ struct e1000_phy_info {
35379 };
35380
35381 struct e1000_nvm_info {
35382 - struct e1000_nvm_operations ops;
35383 + e1000_nvm_operations_no_const ops;
35384 enum e1000_nvm_type type;
35385 enum e1000_nvm_override override;
35386
35387 @@ -482,6 +485,7 @@ struct e1000_mbx_operations {
35388 s32 (*check_for_ack)(struct e1000_hw *, u16);
35389 s32 (*check_for_rst)(struct e1000_hw *, u16);
35390 };
35391 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
35392
35393 struct e1000_mbx_stats {
35394 u32 msgs_tx;
35395 @@ -493,7 +497,7 @@ struct e1000_mbx_stats {
35396 };
35397
35398 struct e1000_mbx_info {
35399 - struct e1000_mbx_operations ops;
35400 + e1000_mbx_operations_no_const ops;
35401 struct e1000_mbx_stats stats;
35402 u32 timeout;
35403 u32 usec_delay;
35404 diff --git a/drivers/net/ethernet/intel/igbvf/vf.h b/drivers/net/ethernet/intel/igbvf/vf.h
35405 index 57db3c6..aa825fc 100644
35406 --- a/drivers/net/ethernet/intel/igbvf/vf.h
35407 +++ b/drivers/net/ethernet/intel/igbvf/vf.h
35408 @@ -189,9 +189,10 @@ struct e1000_mac_operations {
35409 s32 (*read_mac_addr)(struct e1000_hw *);
35410 s32 (*set_vfta)(struct e1000_hw *, u16, bool);
35411 };
35412 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35413
35414 struct e1000_mac_info {
35415 - struct e1000_mac_operations ops;
35416 + e1000_mac_operations_no_const ops;
35417 u8 addr[6];
35418 u8 perm_addr[6];
35419
35420 @@ -213,6 +214,7 @@ struct e1000_mbx_operations {
35421 s32 (*check_for_ack)(struct e1000_hw *);
35422 s32 (*check_for_rst)(struct e1000_hw *);
35423 };
35424 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
35425
35426 struct e1000_mbx_stats {
35427 u32 msgs_tx;
35428 @@ -224,7 +226,7 @@ struct e1000_mbx_stats {
35429 };
35430
35431 struct e1000_mbx_info {
35432 - struct e1000_mbx_operations ops;
35433 + e1000_mbx_operations_no_const ops;
35434 struct e1000_mbx_stats stats;
35435 u32 timeout;
35436 u32 usec_delay;
35437 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
35438 index 3456d56..b688d81 100644
35439 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
35440 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
35441 @@ -884,7 +884,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
35442 /* store the new cycle speed */
35443 adapter->cycle_speed = cycle_speed;
35444
35445 - ACCESS_ONCE(adapter->base_incval) = incval;
35446 + ACCESS_ONCE_RW(adapter->base_incval) = incval;
35447 smp_mb();
35448
35449 /* grab the ptp lock */
35450 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35451 index 0722f33..771758a 100644
35452 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35453 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35454 @@ -2800,6 +2800,7 @@ struct ixgbe_eeprom_operations {
35455 s32 (*update_checksum)(struct ixgbe_hw *);
35456 u16 (*calc_checksum)(struct ixgbe_hw *);
35457 };
35458 +typedef struct ixgbe_eeprom_operations __no_const ixgbe_eeprom_operations_no_const;
35459
35460 struct ixgbe_mac_operations {
35461 s32 (*init_hw)(struct ixgbe_hw *);
35462 @@ -2866,6 +2867,7 @@ struct ixgbe_mac_operations {
35463 s32 (*get_thermal_sensor_data)(struct ixgbe_hw *);
35464 s32 (*init_thermal_sensor_thresh)(struct ixgbe_hw *hw);
35465 };
35466 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
35467
35468 struct ixgbe_phy_operations {
35469 s32 (*identify)(struct ixgbe_hw *);
35470 @@ -2885,9 +2887,10 @@ struct ixgbe_phy_operations {
35471 s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8);
35472 s32 (*check_overtemp)(struct ixgbe_hw *);
35473 };
35474 +typedef struct ixgbe_phy_operations __no_const ixgbe_phy_operations_no_const;
35475
35476 struct ixgbe_eeprom_info {
35477 - struct ixgbe_eeprom_operations ops;
35478 + ixgbe_eeprom_operations_no_const ops;
35479 enum ixgbe_eeprom_type type;
35480 u32 semaphore_delay;
35481 u16 word_size;
35482 @@ -2897,7 +2900,7 @@ struct ixgbe_eeprom_info {
35483
35484 #define IXGBE_FLAGS_DOUBLE_RESET_REQUIRED 0x01
35485 struct ixgbe_mac_info {
35486 - struct ixgbe_mac_operations ops;
35487 + ixgbe_mac_operations_no_const ops;
35488 enum ixgbe_mac_type type;
35489 u8 addr[ETH_ALEN];
35490 u8 perm_addr[ETH_ALEN];
35491 @@ -2927,7 +2930,7 @@ struct ixgbe_mac_info {
35492 };
35493
35494 struct ixgbe_phy_info {
35495 - struct ixgbe_phy_operations ops;
35496 + ixgbe_phy_operations_no_const ops;
35497 struct mdio_if_info mdio;
35498 enum ixgbe_phy_type type;
35499 u32 id;
35500 @@ -2955,6 +2958,7 @@ struct ixgbe_mbx_operations {
35501 s32 (*check_for_ack)(struct ixgbe_hw *, u16);
35502 s32 (*check_for_rst)(struct ixgbe_hw *, u16);
35503 };
35504 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
35505
35506 struct ixgbe_mbx_stats {
35507 u32 msgs_tx;
35508 @@ -2966,7 +2970,7 @@ struct ixgbe_mbx_stats {
35509 };
35510
35511 struct ixgbe_mbx_info {
35512 - struct ixgbe_mbx_operations ops;
35513 + ixgbe_mbx_operations_no_const ops;
35514 struct ixgbe_mbx_stats stats;
35515 u32 timeout;
35516 u32 usec_delay;
35517 diff --git a/drivers/net/ethernet/intel/ixgbevf/vf.h b/drivers/net/ethernet/intel/ixgbevf/vf.h
35518 index 25c951d..cc7cf33 100644
35519 --- a/drivers/net/ethernet/intel/ixgbevf/vf.h
35520 +++ b/drivers/net/ethernet/intel/ixgbevf/vf.h
35521 @@ -70,6 +70,7 @@ struct ixgbe_mac_operations {
35522 s32 (*clear_vfta)(struct ixgbe_hw *);
35523 s32 (*set_vfta)(struct ixgbe_hw *, u32, u32, bool);
35524 };
35525 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
35526
35527 enum ixgbe_mac_type {
35528 ixgbe_mac_unknown = 0,
35529 @@ -79,7 +80,7 @@ enum ixgbe_mac_type {
35530 };
35531
35532 struct ixgbe_mac_info {
35533 - struct ixgbe_mac_operations ops;
35534 + ixgbe_mac_operations_no_const ops;
35535 u8 addr[6];
35536 u8 perm_addr[6];
35537
35538 @@ -103,6 +104,7 @@ struct ixgbe_mbx_operations {
35539 s32 (*check_for_ack)(struct ixgbe_hw *);
35540 s32 (*check_for_rst)(struct ixgbe_hw *);
35541 };
35542 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
35543
35544 struct ixgbe_mbx_stats {
35545 u32 msgs_tx;
35546 @@ -114,7 +116,7 @@ struct ixgbe_mbx_stats {
35547 };
35548
35549 struct ixgbe_mbx_info {
35550 - struct ixgbe_mbx_operations ops;
35551 + ixgbe_mbx_operations_no_const ops;
35552 struct ixgbe_mbx_stats stats;
35553 u32 timeout;
35554 u32 udelay;
35555 diff --git a/drivers/net/ethernet/mellanox/mlx4/en_dcb_nl.c b/drivers/net/ethernet/mellanox/mlx4/en_dcb_nl.c
35556 index 5d367958..b799ab12 100644
35557 --- a/drivers/net/ethernet/mellanox/mlx4/en_dcb_nl.c
35558 +++ b/drivers/net/ethernet/mellanox/mlx4/en_dcb_nl.c
35559 @@ -237,7 +237,7 @@ static int mlx4_en_dcbnl_ieee_setmaxrate(struct net_device *dev,
35560 if (err)
35561 return err;
35562
35563 - memcpy(priv->maxrate, tmp, sizeof(*priv->maxrate));
35564 + memcpy(priv->maxrate, tmp, sizeof(priv->maxrate));
35565
35566 return 0;
35567 }
35568 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.h b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35569 index 9e0c1ee..8471f77 100644
35570 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.h
35571 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35572 @@ -514,7 +514,7 @@ struct vxge_hw_uld_cbs {
35573 void (*link_down)(struct __vxge_hw_device *devh);
35574 void (*crit_err)(struct __vxge_hw_device *devh,
35575 enum vxge_hw_event type, u64 ext_data);
35576 -};
35577 +} __no_const;
35578
35579 /*
35580 * struct __vxge_hw_blockpool_entry - Block private data structure
35581 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35582 index 4a518a3..936b334 100644
35583 --- a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35584 +++ b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35585 @@ -2088,7 +2088,7 @@ struct vxge_hw_mempool_cbs {
35586 struct vxge_hw_mempool_dma *dma_object,
35587 u32 index,
35588 u32 is_last);
35589 -};
35590 +} __no_const;
35591
35592 #define VXGE_HW_VIRTUAL_PATH_HANDLE(vpath) \
35593 ((struct __vxge_hw_vpath_handle *)(vpath)->vpath_handles.next)
35594 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
35595 index df7bbba..162f850 100644
35596 --- a/drivers/net/ethernet/realtek/r8169.c
35597 +++ b/drivers/net/ethernet/realtek/r8169.c
35598 @@ -745,22 +745,22 @@ struct rtl8169_private {
35599 struct mdio_ops {
35600 void (*write)(struct rtl8169_private *, int, int);
35601 int (*read)(struct rtl8169_private *, int);
35602 - } mdio_ops;
35603 + } __no_const mdio_ops;
35604
35605 struct pll_power_ops {
35606 void (*down)(struct rtl8169_private *);
35607 void (*up)(struct rtl8169_private *);
35608 - } pll_power_ops;
35609 + } __no_const pll_power_ops;
35610
35611 struct jumbo_ops {
35612 void (*enable)(struct rtl8169_private *);
35613 void (*disable)(struct rtl8169_private *);
35614 - } jumbo_ops;
35615 + } __no_const jumbo_ops;
35616
35617 struct csi_ops {
35618 void (*write)(struct rtl8169_private *, int, int);
35619 u32 (*read)(struct rtl8169_private *, int);
35620 - } csi_ops;
35621 + } __no_const csi_ops;
35622
35623 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
35624 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
35625 diff --git a/drivers/net/ethernet/sis/sis190.c b/drivers/net/ethernet/sis/sis190.c
35626 index 4613591..d816601 100644
35627 --- a/drivers/net/ethernet/sis/sis190.c
35628 +++ b/drivers/net/ethernet/sis/sis190.c
35629 @@ -1618,7 +1618,7 @@ static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
35630 static int __devinit sis190_get_mac_addr_from_apc(struct pci_dev *pdev,
35631 struct net_device *dev)
35632 {
35633 - static const u16 __devinitdata ids[] = { 0x0965, 0x0966, 0x0968 };
35634 + static const u16 __devinitconst ids[] = { 0x0965, 0x0966, 0x0968 };
35635 struct sis190_private *tp = netdev_priv(dev);
35636 struct pci_dev *isa_bridge;
35637 u8 reg, tmp8;
35638 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35639 index 0c74a70..3bc6f68 100644
35640 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35641 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35642 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
35643
35644 writel(value, ioaddr + MMC_CNTRL);
35645
35646 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35647 - MMC_CNTRL, value);
35648 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35649 +// MMC_CNTRL, value);
35650 }
35651
35652 /* To mask all all interrupts.*/
35653 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
35654 index 95ceb35..318fc12 100644
35655 --- a/drivers/net/hyperv/hyperv_net.h
35656 +++ b/drivers/net/hyperv/hyperv_net.h
35657 @@ -99,7 +99,7 @@ struct rndis_device {
35658
35659 enum rndis_device_state state;
35660 bool link_state;
35661 - atomic_t new_req_id;
35662 + atomic_unchecked_t new_req_id;
35663
35664 spinlock_t request_lock;
35665 struct list_head req_list;
35666 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
35667 index 1e88a10..1b01736 100644
35668 --- a/drivers/net/hyperv/rndis_filter.c
35669 +++ b/drivers/net/hyperv/rndis_filter.c
35670 @@ -99,7 +99,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
35671 * template
35672 */
35673 set = &rndis_msg->msg.set_req;
35674 - set->req_id = atomic_inc_return(&dev->new_req_id);
35675 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35676
35677 /* Add to the request list */
35678 spin_lock_irqsave(&dev->request_lock, flags);
35679 @@ -730,7 +730,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
35680
35681 /* Setup the rndis set */
35682 halt = &request->request_msg.msg.halt_req;
35683 - halt->req_id = atomic_inc_return(&dev->new_req_id);
35684 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35685
35686 /* Ignore return since this msg is optional. */
35687 rndis_filter_send_request(dev, request);
35688 diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
35689 index daec9b0..6428fcb 100644
35690 --- a/drivers/net/phy/mdio-bitbang.c
35691 +++ b/drivers/net/phy/mdio-bitbang.c
35692 @@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
35693 struct mdiobb_ctrl *ctrl = bus->priv;
35694
35695 module_put(ctrl->ops->owner);
35696 + mdiobus_unregister(bus);
35697 mdiobus_free(bus);
35698 }
35699 EXPORT_SYMBOL(free_mdio_bitbang);
35700 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
35701 index 5c05572..389610b 100644
35702 --- a/drivers/net/ppp/ppp_generic.c
35703 +++ b/drivers/net/ppp/ppp_generic.c
35704 @@ -986,7 +986,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35705 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
35706 struct ppp_stats stats;
35707 struct ppp_comp_stats cstats;
35708 - char *vers;
35709
35710 switch (cmd) {
35711 case SIOCGPPPSTATS:
35712 @@ -1008,8 +1007,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35713 break;
35714
35715 case SIOCGPPPVER:
35716 - vers = PPP_VERSION;
35717 - if (copy_to_user(addr, vers, strlen(vers) + 1))
35718 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
35719 break;
35720 err = 0;
35721 break;
35722 diff --git a/drivers/net/tun.c b/drivers/net/tun.c
35723 index 3a16d4f..a311cec 100644
35724 --- a/drivers/net/tun.c
35725 +++ b/drivers/net/tun.c
35726 @@ -1367,7 +1367,7 @@ static int set_offload(struct tun_struct *tun, unsigned long arg)
35727 }
35728
35729 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
35730 - unsigned long arg, int ifreq_len)
35731 + unsigned long arg, size_t ifreq_len)
35732 {
35733 struct tun_file *tfile = file->private_data;
35734 struct tun_struct *tun;
35735 @@ -1378,6 +1378,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
35736 int vnet_hdr_sz;
35737 int ret;
35738
35739 + if (ifreq_len > sizeof ifr)
35740 + return -EFAULT;
35741 +
35742 if (cmd == TUNSETIFF || _IOC_TYPE(cmd) == 0x89) {
35743 if (copy_from_user(&ifr, argp, ifreq_len))
35744 return -EFAULT;
35745 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
35746 index 62f30b4..ff99dfd 100644
35747 --- a/drivers/net/usb/hso.c
35748 +++ b/drivers/net/usb/hso.c
35749 @@ -71,7 +71,7 @@
35750 #include <asm/byteorder.h>
35751 #include <linux/serial_core.h>
35752 #include <linux/serial.h>
35753 -
35754 +#include <asm/local.h>
35755
35756 #define MOD_AUTHOR "Option Wireless"
35757 #define MOD_DESCRIPTION "USB High Speed Option driver"
35758 @@ -1182,7 +1182,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
35759 struct urb *urb;
35760
35761 urb = serial->rx_urb[0];
35762 - if (serial->port.count > 0) {
35763 + if (atomic_read(&serial->port.count) > 0) {
35764 count = put_rxbuf_data(urb, serial);
35765 if (count == -1)
35766 return;
35767 @@ -1218,7 +1218,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
35768 DUMP1(urb->transfer_buffer, urb->actual_length);
35769
35770 /* Anyone listening? */
35771 - if (serial->port.count == 0)
35772 + if (atomic_read(&serial->port.count) == 0)
35773 return;
35774
35775 if (status == 0) {
35776 @@ -1300,8 +1300,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35777 tty_port_tty_set(&serial->port, tty);
35778
35779 /* check for port already opened, if not set the termios */
35780 - serial->port.count++;
35781 - if (serial->port.count == 1) {
35782 + if (atomic_inc_return(&serial->port.count) == 1) {
35783 serial->rx_state = RX_IDLE;
35784 /* Force default termio settings */
35785 _hso_serial_set_termios(tty, NULL);
35786 @@ -1313,7 +1312,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35787 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
35788 if (result) {
35789 hso_stop_serial_device(serial->parent);
35790 - serial->port.count--;
35791 + atomic_dec(&serial->port.count);
35792 kref_put(&serial->parent->ref, hso_serial_ref_free);
35793 }
35794 } else {
35795 @@ -1350,10 +1349,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
35796
35797 /* reset the rts and dtr */
35798 /* do the actual close */
35799 - serial->port.count--;
35800 + atomic_dec(&serial->port.count);
35801
35802 - if (serial->port.count <= 0) {
35803 - serial->port.count = 0;
35804 + if (atomic_read(&serial->port.count) <= 0) {
35805 + atomic_set(&serial->port.count, 0);
35806 tty_port_tty_set(&serial->port, NULL);
35807 if (!usb_gone)
35808 hso_stop_serial_device(serial->parent);
35809 @@ -1429,7 +1428,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
35810
35811 /* the actual setup */
35812 spin_lock_irqsave(&serial->serial_lock, flags);
35813 - if (serial->port.count)
35814 + if (atomic_read(&serial->port.count))
35815 _hso_serial_set_termios(tty, old);
35816 else
35817 tty->termios = old;
35818 @@ -1888,7 +1887,7 @@ static void intr_callback(struct urb *urb)
35819 D1("Pending read interrupt on port %d\n", i);
35820 spin_lock(&serial->serial_lock);
35821 if (serial->rx_state == RX_IDLE &&
35822 - serial->port.count > 0) {
35823 + atomic_read(&serial->port.count) > 0) {
35824 /* Setup and send a ctrl req read on
35825 * port i */
35826 if (!serial->rx_urb_filled[0]) {
35827 @@ -3079,7 +3078,7 @@ static int hso_resume(struct usb_interface *iface)
35828 /* Start all serial ports */
35829 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
35830 if (serial_table[i] && (serial_table[i]->interface == iface)) {
35831 - if (dev2ser(serial_table[i])->port.count) {
35832 + if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
35833 result =
35834 hso_start_serial_device(serial_table[i], GFP_NOIO);
35835 hso_kick_transmit(dev2ser(serial_table[i]));
35836 diff --git a/drivers/net/wireless/ath/ath.h b/drivers/net/wireless/ath/ath.h
35837 index 6169fbd..40e8422 100644
35838 --- a/drivers/net/wireless/ath/ath.h
35839 +++ b/drivers/net/wireless/ath/ath.h
35840 @@ -119,6 +119,7 @@ struct ath_ops {
35841 void (*write_flush) (void *);
35842 u32 (*rmw)(void *, u32 reg_offset, u32 set, u32 clr);
35843 };
35844 +typedef struct ath_ops __no_const ath_ops_no_const;
35845
35846 struct ath_common;
35847 struct ath_bus_ops;
35848 diff --git a/drivers/net/wireless/ath/ath5k/base.c b/drivers/net/wireless/ath/ath5k/base.c
35849 index 2aab20e..b761ef8 100644
35850 --- a/drivers/net/wireless/ath/ath5k/base.c
35851 +++ b/drivers/net/wireless/ath/ath5k/base.c
35852 @@ -1803,7 +1803,7 @@ ath5k_beacon_update(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
35853 {
35854 int ret;
35855 struct ath5k_hw *ah = hw->priv;
35856 - struct ath5k_vif *avf = (void *)vif->drv_priv;
35857 + struct ath5k_vif *avf;
35858 struct sk_buff *skb;
35859
35860 if (WARN_ON(!vif)) {
35861 @@ -1818,6 +1818,7 @@ ath5k_beacon_update(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
35862 goto out;
35863 }
35864
35865 + avf = (void *)vif->drv_priv;
35866 ath5k_txbuf_free_skb(ah, avf->bbuf);
35867 avf->bbuf->skb = skb;
35868 ret = ath5k_beacon_setup(ah, avf->bbuf);
35869 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35870 index 8d78253..bebbb68 100644
35871 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35872 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35873 @@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35874 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
35875 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
35876
35877 - ACCESS_ONCE(ads->ds_link) = i->link;
35878 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
35879 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
35880 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
35881
35882 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
35883 ctl6 = SM(i->keytype, AR_EncrType);
35884 @@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35885
35886 if ((i->is_first || i->is_last) &&
35887 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
35888 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
35889 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
35890 | set11nTries(i->rates, 1)
35891 | set11nTries(i->rates, 2)
35892 | set11nTries(i->rates, 3)
35893 | (i->dur_update ? AR_DurUpdateEna : 0)
35894 | SM(0, AR_BurstDur);
35895
35896 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
35897 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
35898 | set11nRate(i->rates, 1)
35899 | set11nRate(i->rates, 2)
35900 | set11nRate(i->rates, 3);
35901 } else {
35902 - ACCESS_ONCE(ads->ds_ctl2) = 0;
35903 - ACCESS_ONCE(ads->ds_ctl3) = 0;
35904 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
35905 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
35906 }
35907
35908 if (!i->is_first) {
35909 - ACCESS_ONCE(ads->ds_ctl0) = 0;
35910 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35911 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35912 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
35913 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35914 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35915 return;
35916 }
35917
35918 @@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35919 break;
35920 }
35921
35922 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35923 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35924 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35925 | SM(i->txpower, AR_XmitPower)
35926 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35927 @@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35928 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
35929 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
35930
35931 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35932 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35933 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35934 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35935
35936 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
35937 return;
35938
35939 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35940 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35941 | set11nPktDurRTSCTS(i->rates, 1);
35942
35943 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35944 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35945 | set11nPktDurRTSCTS(i->rates, 3);
35946
35947 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35948 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35949 | set11nRateFlags(i->rates, 1)
35950 | set11nRateFlags(i->rates, 2)
35951 | set11nRateFlags(i->rates, 3)
35952 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35953 index 78816b8..1fcdfae 100644
35954 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35955 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35956 @@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35957 (i->qcu << AR_TxQcuNum_S) | desc_len;
35958
35959 checksum += val;
35960 - ACCESS_ONCE(ads->info) = val;
35961 + ACCESS_ONCE_RW(ads->info) = val;
35962
35963 checksum += i->link;
35964 - ACCESS_ONCE(ads->link) = i->link;
35965 + ACCESS_ONCE_RW(ads->link) = i->link;
35966
35967 checksum += i->buf_addr[0];
35968 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
35969 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
35970 checksum += i->buf_addr[1];
35971 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
35972 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
35973 checksum += i->buf_addr[2];
35974 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
35975 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
35976 checksum += i->buf_addr[3];
35977 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
35978 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
35979
35980 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
35981 - ACCESS_ONCE(ads->ctl3) = val;
35982 + ACCESS_ONCE_RW(ads->ctl3) = val;
35983 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
35984 - ACCESS_ONCE(ads->ctl5) = val;
35985 + ACCESS_ONCE_RW(ads->ctl5) = val;
35986 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
35987 - ACCESS_ONCE(ads->ctl7) = val;
35988 + ACCESS_ONCE_RW(ads->ctl7) = val;
35989 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
35990 - ACCESS_ONCE(ads->ctl9) = val;
35991 + ACCESS_ONCE_RW(ads->ctl9) = val;
35992
35993 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
35994 - ACCESS_ONCE(ads->ctl10) = checksum;
35995 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
35996
35997 if (i->is_first || i->is_last) {
35998 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
35999 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
36000 | set11nTries(i->rates, 1)
36001 | set11nTries(i->rates, 2)
36002 | set11nTries(i->rates, 3)
36003 | (i->dur_update ? AR_DurUpdateEna : 0)
36004 | SM(0, AR_BurstDur);
36005
36006 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
36007 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
36008 | set11nRate(i->rates, 1)
36009 | set11nRate(i->rates, 2)
36010 | set11nRate(i->rates, 3);
36011 } else {
36012 - ACCESS_ONCE(ads->ctl13) = 0;
36013 - ACCESS_ONCE(ads->ctl14) = 0;
36014 + ACCESS_ONCE_RW(ads->ctl13) = 0;
36015 + ACCESS_ONCE_RW(ads->ctl14) = 0;
36016 }
36017
36018 ads->ctl20 = 0;
36019 @@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
36020
36021 ctl17 = SM(i->keytype, AR_EncrType);
36022 if (!i->is_first) {
36023 - ACCESS_ONCE(ads->ctl11) = 0;
36024 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
36025 - ACCESS_ONCE(ads->ctl15) = 0;
36026 - ACCESS_ONCE(ads->ctl16) = 0;
36027 - ACCESS_ONCE(ads->ctl17) = ctl17;
36028 - ACCESS_ONCE(ads->ctl18) = 0;
36029 - ACCESS_ONCE(ads->ctl19) = 0;
36030 + ACCESS_ONCE_RW(ads->ctl11) = 0;
36031 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
36032 + ACCESS_ONCE_RW(ads->ctl15) = 0;
36033 + ACCESS_ONCE_RW(ads->ctl16) = 0;
36034 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
36035 + ACCESS_ONCE_RW(ads->ctl18) = 0;
36036 + ACCESS_ONCE_RW(ads->ctl19) = 0;
36037 return;
36038 }
36039
36040 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
36041 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
36042 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
36043 | SM(i->txpower, AR_XmitPower)
36044 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
36045 @@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
36046 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
36047 ctl12 |= SM(val, AR_PAPRDChainMask);
36048
36049 - ACCESS_ONCE(ads->ctl12) = ctl12;
36050 - ACCESS_ONCE(ads->ctl17) = ctl17;
36051 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
36052 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
36053
36054 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
36055 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
36056 | set11nPktDurRTSCTS(i->rates, 1);
36057
36058 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
36059 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
36060 | set11nPktDurRTSCTS(i->rates, 3);
36061
36062 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
36063 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
36064 | set11nRateFlags(i->rates, 1)
36065 | set11nRateFlags(i->rates, 2)
36066 | set11nRateFlags(i->rates, 3)
36067 | SM(i->rtscts_rate, AR_RTSCTSRate);
36068
36069 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
36070 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
36071 }
36072
36073 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
36074 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
36075 index de6968f..29ac4c1 100644
36076 --- a/drivers/net/wireless/ath/ath9k/hw.h
36077 +++ b/drivers/net/wireless/ath/ath9k/hw.h
36078 @@ -656,7 +656,7 @@ struct ath_hw_private_ops {
36079
36080 /* ANI */
36081 void (*ani_cache_ini_regs)(struct ath_hw *ah);
36082 -};
36083 +} __no_const;
36084
36085 /**
36086 * struct ath_hw_ops - callbacks used by hardware code and driver code
36087 @@ -686,7 +686,7 @@ struct ath_hw_ops {
36088 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
36089 struct ath_hw_antcomb_conf *antconf);
36090
36091 -};
36092 +} __no_const;
36093
36094 struct ath_nf_limits {
36095 s16 max;
36096 @@ -706,7 +706,7 @@ enum ath_cal_list {
36097 #define AH_FASTCC 0x4
36098
36099 struct ath_hw {
36100 - struct ath_ops reg_ops;
36101 + ath_ops_no_const reg_ops;
36102
36103 struct ieee80211_hw *hw;
36104 struct ath_common common;
36105 diff --git a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
36106 index af00e2c..ab04d34 100644
36107 --- a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
36108 +++ b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
36109 @@ -545,7 +545,7 @@ struct phy_func_ptr {
36110 void (*carrsuppr)(struct brcms_phy *);
36111 s32 (*rxsigpwr)(struct brcms_phy *, s32);
36112 void (*detach)(struct brcms_phy *);
36113 -};
36114 +} __no_const;
36115
36116 struct brcms_phy {
36117 struct brcms_phy_pub pubpi_ro;
36118 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
36119 index faec404..a5277f1 100644
36120 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
36121 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
36122 @@ -3611,7 +3611,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
36123 */
36124 if (il3945_mod_params.disable_hw_scan) {
36125 D_INFO("Disabling hw_scan\n");
36126 - il3945_mac_ops.hw_scan = NULL;
36127 + pax_open_kernel();
36128 + *(void **)&il3945_mac_ops.hw_scan = NULL;
36129 + pax_close_kernel();
36130 }
36131
36132 D_INFO("*** LOAD DRIVER ***\n");
36133 diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
36134 index a47b306..297daf2 100644
36135 --- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
36136 +++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
36137 @@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
36138 {
36139 struct iwl_priv *priv = file->private_data;
36140 char buf[64];
36141 - int buf_size;
36142 + size_t buf_size;
36143 u32 offset, len;
36144
36145 memset(buf, 0, sizeof(buf));
36146 @@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
36147 struct iwl_priv *priv = file->private_data;
36148
36149 char buf[8];
36150 - int buf_size;
36151 + size_t buf_size;
36152 u32 reset_flag;
36153
36154 memset(buf, 0, sizeof(buf));
36155 @@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
36156 {
36157 struct iwl_priv *priv = file->private_data;
36158 char buf[8];
36159 - int buf_size;
36160 + size_t buf_size;
36161 int ht40;
36162
36163 memset(buf, 0, sizeof(buf));
36164 @@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
36165 {
36166 struct iwl_priv *priv = file->private_data;
36167 char buf[8];
36168 - int buf_size;
36169 + size_t buf_size;
36170 int value;
36171
36172 memset(buf, 0, sizeof(buf));
36173 @@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
36174 {
36175 struct iwl_priv *priv = file->private_data;
36176 char buf[8];
36177 - int buf_size;
36178 + size_t buf_size;
36179 int clear;
36180
36181 memset(buf, 0, sizeof(buf));
36182 @@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
36183 {
36184 struct iwl_priv *priv = file->private_data;
36185 char buf[8];
36186 - int buf_size;
36187 + size_t buf_size;
36188 int trace;
36189
36190 memset(buf, 0, sizeof(buf));
36191 @@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
36192 {
36193 struct iwl_priv *priv = file->private_data;
36194 char buf[8];
36195 - int buf_size;
36196 + size_t buf_size;
36197 int missed;
36198
36199 memset(buf, 0, sizeof(buf));
36200 @@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
36201
36202 struct iwl_priv *priv = file->private_data;
36203 char buf[8];
36204 - int buf_size;
36205 + size_t buf_size;
36206 int plcp;
36207
36208 memset(buf, 0, sizeof(buf));
36209 @@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
36210
36211 struct iwl_priv *priv = file->private_data;
36212 char buf[8];
36213 - int buf_size;
36214 + size_t buf_size;
36215 int flush;
36216
36217 memset(buf, 0, sizeof(buf));
36218 @@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
36219
36220 struct iwl_priv *priv = file->private_data;
36221 char buf[8];
36222 - int buf_size;
36223 + size_t buf_size;
36224 int rts;
36225
36226 if (!priv->cfg->ht_params)
36227 @@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
36228 {
36229 struct iwl_priv *priv = file->private_data;
36230 char buf[8];
36231 - int buf_size;
36232 + size_t buf_size;
36233
36234 memset(buf, 0, sizeof(buf));
36235 buf_size = min(count, sizeof(buf) - 1);
36236 @@ -2256,7 +2256,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
36237 struct iwl_priv *priv = file->private_data;
36238 u32 event_log_flag;
36239 char buf[8];
36240 - int buf_size;
36241 + size_t buf_size;
36242
36243 /* check that the interface is up */
36244 if (!iwl_is_ready(priv))
36245 @@ -2310,7 +2310,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
36246 struct iwl_priv *priv = file->private_data;
36247 char buf[8];
36248 u32 calib_disabled;
36249 - int buf_size;
36250 + size_t buf_size;
36251
36252 memset(buf, 0, sizeof(buf));
36253 buf_size = min(count, sizeof(buf) - 1);
36254 diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
36255 index dbeebef..b45a152 100644
36256 --- a/drivers/net/wireless/iwlwifi/pcie/trans.c
36257 +++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
36258 @@ -1944,7 +1944,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
36259 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
36260
36261 char buf[8];
36262 - int buf_size;
36263 + size_t buf_size;
36264 u32 reset_flag;
36265
36266 memset(buf, 0, sizeof(buf));
36267 @@ -1965,7 +1965,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
36268 {
36269 struct iwl_trans *trans = file->private_data;
36270 char buf[8];
36271 - int buf_size;
36272 + size_t buf_size;
36273 int csr;
36274
36275 memset(buf, 0, sizeof(buf));
36276 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
36277 index 0083839..fcb7225 100644
36278 --- a/drivers/net/wireless/mac80211_hwsim.c
36279 +++ b/drivers/net/wireless/mac80211_hwsim.c
36280 @@ -1748,9 +1748,11 @@ static int __init init_mac80211_hwsim(void)
36281 return -EINVAL;
36282
36283 if (fake_hw_scan) {
36284 - mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
36285 - mac80211_hwsim_ops.sw_scan_start = NULL;
36286 - mac80211_hwsim_ops.sw_scan_complete = NULL;
36287 + pax_open_kernel();
36288 + *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
36289 + *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
36290 + *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
36291 + pax_close_kernel();
36292 }
36293
36294 spin_lock_init(&hwsim_radio_lock);
36295 diff --git a/drivers/net/wireless/mwifiex/main.h b/drivers/net/wireless/mwifiex/main.h
36296 index e7c2a82..582e228 100644
36297 --- a/drivers/net/wireless/mwifiex/main.h
36298 +++ b/drivers/net/wireless/mwifiex/main.h
36299 @@ -571,7 +571,7 @@ struct mwifiex_if_ops {
36300 int (*event_complete) (struct mwifiex_adapter *, struct sk_buff *);
36301 int (*data_complete) (struct mwifiex_adapter *, struct sk_buff *);
36302 int (*dnld_fw) (struct mwifiex_adapter *, struct mwifiex_fw_image *);
36303 -};
36304 +} __no_const;
36305
36306 struct mwifiex_adapter {
36307 u8 iface_type;
36308 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
36309 index 7a4ae9e..56e00bd 100644
36310 --- a/drivers/net/wireless/rndis_wlan.c
36311 +++ b/drivers/net/wireless/rndis_wlan.c
36312 @@ -1235,7 +1235,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
36313
36314 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
36315
36316 - if (rts_threshold < 0 || rts_threshold > 2347)
36317 + if (rts_threshold > 2347)
36318 rts_threshold = 2347;
36319
36320 tmp = cpu_to_le32(rts_threshold);
36321 diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
36322 index 8afb546..0c0dc5c 100644
36323 --- a/drivers/net/wireless/rt2x00/rt2x00.h
36324 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
36325 @@ -397,7 +397,7 @@ struct rt2x00_intf {
36326 * for hardware which doesn't support hardware
36327 * sequence counting.
36328 */
36329 - atomic_t seqno;
36330 + atomic_unchecked_t seqno;
36331 };
36332
36333 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
36334 diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
36335 index f7e74a0..da71431 100644
36336 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
36337 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
36338 @@ -240,9 +240,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
36339 * sequence counter given by mac80211.
36340 */
36341 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
36342 - seqno = atomic_add_return(0x10, &intf->seqno);
36343 + seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
36344 else
36345 - seqno = atomic_read(&intf->seqno);
36346 + seqno = atomic_read_unchecked(&intf->seqno);
36347
36348 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
36349 hdr->seq_ctrl |= cpu_to_le16(seqno);
36350 diff --git a/drivers/net/wireless/ti/wl1251/wl1251.h b/drivers/net/wireless/ti/wl1251/wl1251.h
36351 index fd02060..74ee481 100644
36352 --- a/drivers/net/wireless/ti/wl1251/wl1251.h
36353 +++ b/drivers/net/wireless/ti/wl1251/wl1251.h
36354 @@ -266,7 +266,7 @@ struct wl1251_if_operations {
36355 void (*reset)(struct wl1251 *wl);
36356 void (*enable_irq)(struct wl1251 *wl);
36357 void (*disable_irq)(struct wl1251 *wl);
36358 -};
36359 +} __no_const;
36360
36361 struct wl1251 {
36362 struct ieee80211_hw *hw;
36363 diff --git a/drivers/net/wireless/ti/wlcore/wlcore.h b/drivers/net/wireless/ti/wlcore/wlcore.h
36364 index 0ce7a8e..56a0ccf 100644
36365 --- a/drivers/net/wireless/ti/wlcore/wlcore.h
36366 +++ b/drivers/net/wireless/ti/wlcore/wlcore.h
36367 @@ -81,7 +81,7 @@ struct wlcore_ops {
36368 struct ieee80211_sta *sta,
36369 struct ieee80211_key_conf *key_conf);
36370 u32 (*pre_pkt_send)(struct wl1271 *wl, u32 buf_offset, u32 last_len);
36371 -};
36372 +} __no_const;
36373
36374 enum wlcore_partitions {
36375 PART_DOWN,
36376 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
36377 index f34b5b2..b5abb9f 100644
36378 --- a/drivers/oprofile/buffer_sync.c
36379 +++ b/drivers/oprofile/buffer_sync.c
36380 @@ -343,7 +343,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
36381 if (cookie == NO_COOKIE)
36382 offset = pc;
36383 if (cookie == INVALID_COOKIE) {
36384 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
36385 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
36386 offset = pc;
36387 }
36388 if (cookie != last_cookie) {
36389 @@ -387,14 +387,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
36390 /* add userspace sample */
36391
36392 if (!mm) {
36393 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
36394 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
36395 return 0;
36396 }
36397
36398 cookie = lookup_dcookie(mm, s->eip, &offset);
36399
36400 if (cookie == INVALID_COOKIE) {
36401 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
36402 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
36403 return 0;
36404 }
36405
36406 @@ -563,7 +563,7 @@ void sync_buffer(int cpu)
36407 /* ignore backtraces if failed to add a sample */
36408 if (state == sb_bt_start) {
36409 state = sb_bt_ignore;
36410 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
36411 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
36412 }
36413 }
36414 release_mm(mm);
36415 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
36416 index c0cc4e7..44d4e54 100644
36417 --- a/drivers/oprofile/event_buffer.c
36418 +++ b/drivers/oprofile/event_buffer.c
36419 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
36420 }
36421
36422 if (buffer_pos == buffer_size) {
36423 - atomic_inc(&oprofile_stats.event_lost_overflow);
36424 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
36425 return;
36426 }
36427
36428 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
36429 index ed2c3ec..deda85a 100644
36430 --- a/drivers/oprofile/oprof.c
36431 +++ b/drivers/oprofile/oprof.c
36432 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
36433 if (oprofile_ops.switch_events())
36434 return;
36435
36436 - atomic_inc(&oprofile_stats.multiplex_counter);
36437 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
36438 start_switch_worker();
36439 }
36440
36441 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
36442 index 917d28e..d62d981 100644
36443 --- a/drivers/oprofile/oprofile_stats.c
36444 +++ b/drivers/oprofile/oprofile_stats.c
36445 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
36446 cpu_buf->sample_invalid_eip = 0;
36447 }
36448
36449 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
36450 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
36451 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
36452 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
36453 - atomic_set(&oprofile_stats.multiplex_counter, 0);
36454 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
36455 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
36456 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
36457 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
36458 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
36459 }
36460
36461
36462 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
36463 index 38b6fc0..b5cbfce 100644
36464 --- a/drivers/oprofile/oprofile_stats.h
36465 +++ b/drivers/oprofile/oprofile_stats.h
36466 @@ -13,11 +13,11 @@
36467 #include <linux/atomic.h>
36468
36469 struct oprofile_stat_struct {
36470 - atomic_t sample_lost_no_mm;
36471 - atomic_t sample_lost_no_mapping;
36472 - atomic_t bt_lost_no_mapping;
36473 - atomic_t event_lost_overflow;
36474 - atomic_t multiplex_counter;
36475 + atomic_unchecked_t sample_lost_no_mm;
36476 + atomic_unchecked_t sample_lost_no_mapping;
36477 + atomic_unchecked_t bt_lost_no_mapping;
36478 + atomic_unchecked_t event_lost_overflow;
36479 + atomic_unchecked_t multiplex_counter;
36480 };
36481
36482 extern struct oprofile_stat_struct oprofile_stats;
36483 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
36484 index 849357c..b83c1e0 100644
36485 --- a/drivers/oprofile/oprofilefs.c
36486 +++ b/drivers/oprofile/oprofilefs.c
36487 @@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
36488
36489
36490 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
36491 - char const *name, atomic_t *val)
36492 + char const *name, atomic_unchecked_t *val)
36493 {
36494 return __oprofilefs_create_file(sb, root, name,
36495 &atomic_ro_fops, 0444, val);
36496 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
36497 index 3f56bc0..707d642 100644
36498 --- a/drivers/parport/procfs.c
36499 +++ b/drivers/parport/procfs.c
36500 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
36501
36502 *ppos += len;
36503
36504 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
36505 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
36506 }
36507
36508 #ifdef CONFIG_PARPORT_1284
36509 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
36510
36511 *ppos += len;
36512
36513 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
36514 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
36515 }
36516 #endif /* IEEE1284.3 support. */
36517
36518 diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
36519 index 9fff878..ad0ad53 100644
36520 --- a/drivers/pci/hotplug/cpci_hotplug.h
36521 +++ b/drivers/pci/hotplug/cpci_hotplug.h
36522 @@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
36523 int (*hardware_test) (struct slot* slot, u32 value);
36524 u8 (*get_power) (struct slot* slot);
36525 int (*set_power) (struct slot* slot, int value);
36526 -};
36527 +} __no_const;
36528
36529 struct cpci_hp_controller {
36530 unsigned int irq;
36531 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
36532 index 76ba8a1..20ca857 100644
36533 --- a/drivers/pci/hotplug/cpqphp_nvram.c
36534 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
36535 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
36536
36537 void compaq_nvram_init (void __iomem *rom_start)
36538 {
36539 +
36540 +#ifndef CONFIG_PAX_KERNEXEC
36541 if (rom_start) {
36542 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
36543 }
36544 +#endif
36545 +
36546 dbg("int15 entry = %p\n", compaq_int15_entry_point);
36547
36548 /* initialize our int15 lock */
36549 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
36550 index b500840..d7159d3 100644
36551 --- a/drivers/pci/pcie/aspm.c
36552 +++ b/drivers/pci/pcie/aspm.c
36553 @@ -27,9 +27,9 @@
36554 #define MODULE_PARAM_PREFIX "pcie_aspm."
36555
36556 /* Note: those are not register definitions */
36557 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
36558 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
36559 -#define ASPM_STATE_L1 (4) /* L1 state */
36560 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
36561 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
36562 +#define ASPM_STATE_L1 (4U) /* L1 state */
36563 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
36564 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
36565
36566 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
36567 index 61859d0..124539e 100644
36568 --- a/drivers/pci/probe.c
36569 +++ b/drivers/pci/probe.c
36570 @@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
36571 struct pci_bus_region region;
36572 bool bar_too_big = false, bar_disabled = false;
36573
36574 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
36575 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
36576
36577 /* No printks while decoding is disabled! */
36578 if (!dev->mmio_always_on) {
36579 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
36580 index af028c7..654cdfc 100644
36581 --- a/drivers/pci/proc.c
36582 +++ b/drivers/pci/proc.c
36583 @@ -484,7 +484,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
36584 static int __init pci_proc_init(void)
36585 {
36586 struct pci_dev *dev = NULL;
36587 +
36588 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
36589 +#ifdef CONFIG_GRKERNSEC_PROC_USER
36590 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
36591 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
36592 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
36593 +#endif
36594 +#else
36595 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
36596 +#endif
36597 proc_create("devices", 0, proc_bus_pci_dir,
36598 &proc_bus_pci_dev_operations);
36599 proc_initialized = 1;
36600 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
36601 index 52daaa8..d6b81eb 100644
36602 --- a/drivers/platform/x86/thinkpad_acpi.c
36603 +++ b/drivers/platform/x86/thinkpad_acpi.c
36604 @@ -2097,7 +2097,7 @@ static int hotkey_mask_get(void)
36605 return 0;
36606 }
36607
36608 -void static hotkey_mask_warn_incomplete_mask(void)
36609 +static void hotkey_mask_warn_incomplete_mask(void)
36610 {
36611 /* log only what the user can fix... */
36612 const u32 wantedmask = hotkey_driver_mask &
36613 @@ -2328,11 +2328,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
36614 }
36615 }
36616
36617 -static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36618 - struct tp_nvram_state *newn,
36619 - const u32 event_mask)
36620 -{
36621 -
36622 #define TPACPI_COMPARE_KEY(__scancode, __member) \
36623 do { \
36624 if ((event_mask & (1 << __scancode)) && \
36625 @@ -2346,36 +2341,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36626 tpacpi_hotkey_send_key(__scancode); \
36627 } while (0)
36628
36629 - void issue_volchange(const unsigned int oldvol,
36630 - const unsigned int newvol)
36631 - {
36632 - unsigned int i = oldvol;
36633 +static void issue_volchange(const unsigned int oldvol,
36634 + const unsigned int newvol,
36635 + const u32 event_mask)
36636 +{
36637 + unsigned int i = oldvol;
36638
36639 - while (i > newvol) {
36640 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
36641 - i--;
36642 - }
36643 - while (i < newvol) {
36644 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36645 - i++;
36646 - }
36647 + while (i > newvol) {
36648 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
36649 + i--;
36650 }
36651 + while (i < newvol) {
36652 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36653 + i++;
36654 + }
36655 +}
36656
36657 - void issue_brightnesschange(const unsigned int oldbrt,
36658 - const unsigned int newbrt)
36659 - {
36660 - unsigned int i = oldbrt;
36661 +static void issue_brightnesschange(const unsigned int oldbrt,
36662 + const unsigned int newbrt,
36663 + const u32 event_mask)
36664 +{
36665 + unsigned int i = oldbrt;
36666
36667 - while (i > newbrt) {
36668 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
36669 - i--;
36670 - }
36671 - while (i < newbrt) {
36672 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36673 - i++;
36674 - }
36675 + while (i > newbrt) {
36676 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
36677 + i--;
36678 + }
36679 + while (i < newbrt) {
36680 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36681 + i++;
36682 }
36683 +}
36684
36685 +static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36686 + struct tp_nvram_state *newn,
36687 + const u32 event_mask)
36688 +{
36689 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
36690 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
36691 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
36692 @@ -2409,7 +2410,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36693 oldn->volume_level != newn->volume_level) {
36694 /* recently muted, or repeated mute keypress, or
36695 * multiple presses ending in mute */
36696 - issue_volchange(oldn->volume_level, newn->volume_level);
36697 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36698 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
36699 }
36700 } else {
36701 @@ -2419,7 +2420,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36702 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36703 }
36704 if (oldn->volume_level != newn->volume_level) {
36705 - issue_volchange(oldn->volume_level, newn->volume_level);
36706 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36707 } else if (oldn->volume_toggle != newn->volume_toggle) {
36708 /* repeated vol up/down keypress at end of scale ? */
36709 if (newn->volume_level == 0)
36710 @@ -2432,7 +2433,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36711 /* handle brightness */
36712 if (oldn->brightness_level != newn->brightness_level) {
36713 issue_brightnesschange(oldn->brightness_level,
36714 - newn->brightness_level);
36715 + newn->brightness_level,
36716 + event_mask);
36717 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
36718 /* repeated key presses that didn't change state */
36719 if (newn->brightness_level == 0)
36720 @@ -2441,10 +2443,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36721 && !tp_features.bright_unkfw)
36722 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36723 }
36724 +}
36725
36726 #undef TPACPI_COMPARE_KEY
36727 #undef TPACPI_MAY_SEND_KEY
36728 -}
36729
36730 /*
36731 * Polling driver
36732 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
36733 index 769d265..a3a05ca 100644
36734 --- a/drivers/pnp/pnpbios/bioscalls.c
36735 +++ b/drivers/pnp/pnpbios/bioscalls.c
36736 @@ -58,7 +58,7 @@ do { \
36737 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
36738 } while(0)
36739
36740 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
36741 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
36742 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
36743
36744 /*
36745 @@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36746
36747 cpu = get_cpu();
36748 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
36749 +
36750 + pax_open_kernel();
36751 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
36752 + pax_close_kernel();
36753
36754 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
36755 spin_lock_irqsave(&pnp_bios_lock, flags);
36756 @@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36757 :"memory");
36758 spin_unlock_irqrestore(&pnp_bios_lock, flags);
36759
36760 + pax_open_kernel();
36761 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
36762 + pax_close_kernel();
36763 +
36764 put_cpu();
36765
36766 /* If we get here and this is set then the PnP BIOS faulted on us. */
36767 @@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
36768 return status;
36769 }
36770
36771 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
36772 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
36773 {
36774 int i;
36775
36776 @@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36777 pnp_bios_callpoint.offset = header->fields.pm16offset;
36778 pnp_bios_callpoint.segment = PNP_CS16;
36779
36780 + pax_open_kernel();
36781 +
36782 for_each_possible_cpu(i) {
36783 struct desc_struct *gdt = get_cpu_gdt_table(i);
36784 if (!gdt)
36785 @@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36786 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
36787 (unsigned long)__va(header->fields.pm16dseg));
36788 }
36789 +
36790 + pax_close_kernel();
36791 }
36792 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
36793 index b0ecacb..7c9da2e 100644
36794 --- a/drivers/pnp/resource.c
36795 +++ b/drivers/pnp/resource.c
36796 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
36797 return 1;
36798
36799 /* check if the resource is valid */
36800 - if (*irq < 0 || *irq > 15)
36801 + if (*irq > 15)
36802 return 0;
36803
36804 /* check if the resource is reserved */
36805 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
36806 return 1;
36807
36808 /* check if the resource is valid */
36809 - if (*dma < 0 || *dma == 4 || *dma > 7)
36810 + if (*dma == 4 || *dma > 7)
36811 return 0;
36812
36813 /* check if the resource is reserved */
36814 diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
36815 index 181ddec..774b6da 100644
36816 --- a/drivers/power/bq27x00_battery.c
36817 +++ b/drivers/power/bq27x00_battery.c
36818 @@ -80,7 +80,7 @@
36819 struct bq27x00_device_info;
36820 struct bq27x00_access_methods {
36821 int (*read)(struct bq27x00_device_info *di, u8 reg, bool single);
36822 -};
36823 +} __no_const;
36824
36825 enum bq27x00_chip { BQ27000, BQ27500, BQ27425};
36826
36827 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
36828 index 8d53174..04c65de 100644
36829 --- a/drivers/regulator/max8660.c
36830 +++ b/drivers/regulator/max8660.c
36831 @@ -333,8 +333,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
36832 max8660->shadow_regs[MAX8660_OVER1] = 5;
36833 } else {
36834 /* Otherwise devices can be toggled via software */
36835 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
36836 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
36837 + pax_open_kernel();
36838 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
36839 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
36840 + pax_close_kernel();
36841 }
36842
36843 /*
36844 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
36845 index b388b74..ed82573 100644
36846 --- a/drivers/regulator/mc13892-regulator.c
36847 +++ b/drivers/regulator/mc13892-regulator.c
36848 @@ -565,10 +565,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
36849 }
36850 mc13xxx_unlock(mc13892);
36851
36852 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36853 + pax_open_kernel();
36854 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36855 = mc13892_vcam_set_mode;
36856 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36857 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36858 = mc13892_vcam_get_mode;
36859 + pax_close_kernel();
36860
36861 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
36862 ARRAY_SIZE(mc13892_regulators));
36863 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
36864 index cace6d3..f623fda 100644
36865 --- a/drivers/rtc/rtc-dev.c
36866 +++ b/drivers/rtc/rtc-dev.c
36867 @@ -14,6 +14,7 @@
36868 #include <linux/module.h>
36869 #include <linux/rtc.h>
36870 #include <linux/sched.h>
36871 +#include <linux/grsecurity.h>
36872 #include "rtc-core.h"
36873
36874 static dev_t rtc_devt;
36875 @@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
36876 if (copy_from_user(&tm, uarg, sizeof(tm)))
36877 return -EFAULT;
36878
36879 + gr_log_timechange();
36880 +
36881 return rtc_set_time(rtc, &tm);
36882
36883 case RTC_PIE_ON:
36884 diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
36885 index 9e933a8..4f969f7 100644
36886 --- a/drivers/scsi/aacraid/aacraid.h
36887 +++ b/drivers/scsi/aacraid/aacraid.h
36888 @@ -503,7 +503,7 @@ struct adapter_ops
36889 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
36890 /* Administrative operations */
36891 int (*adapter_comm)(struct aac_dev * dev, int comm);
36892 -};
36893 +} __no_const;
36894
36895 /*
36896 * Define which interrupt handler needs to be installed
36897 diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
36898 index 7199534..cb7f158 100644
36899 --- a/drivers/scsi/aacraid/linit.c
36900 +++ b/drivers/scsi/aacraid/linit.c
36901 @@ -93,7 +93,7 @@ static DECLARE_PCI_DEVICE_TABLE(aac_pci_tbl) = {
36902 #elif defined(__devinitconst)
36903 static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36904 #else
36905 -static const struct pci_device_id aac_pci_tbl[] __devinitdata = {
36906 +static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36907 #endif
36908 { 0x1028, 0x0001, 0x1028, 0x0001, 0, 0, 0 }, /* PERC 2/Si (Iguana/PERC2Si) */
36909 { 0x1028, 0x0002, 0x1028, 0x0002, 0, 0, 1 }, /* PERC 3/Di (Opal/PERC3Di) */
36910 diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
36911 index ff80552..1c4120c 100644
36912 --- a/drivers/scsi/aic94xx/aic94xx_init.c
36913 +++ b/drivers/scsi/aic94xx/aic94xx_init.c
36914 @@ -1012,7 +1012,7 @@ static struct sas_domain_function_template aic94xx_transport_functions = {
36915 .lldd_ata_set_dmamode = asd_set_dmamode,
36916 };
36917
36918 -static const struct pci_device_id aic94xx_pci_table[] __devinitdata = {
36919 +static const struct pci_device_id aic94xx_pci_table[] __devinitconst = {
36920 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x410),0, 0, 1},
36921 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x412),0, 0, 1},
36922 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x416),0, 0, 1},
36923 diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
36924 index 4ad7e36..d004679 100644
36925 --- a/drivers/scsi/bfa/bfa.h
36926 +++ b/drivers/scsi/bfa/bfa.h
36927 @@ -196,7 +196,7 @@ struct bfa_hwif_s {
36928 u32 *end);
36929 int cpe_vec_q0;
36930 int rme_vec_q0;
36931 -};
36932 +} __no_const;
36933 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
36934
36935 struct bfa_faa_cbfn_s {
36936 diff --git a/drivers/scsi/bfa/bfa_fcpim.c b/drivers/scsi/bfa/bfa_fcpim.c
36937 index f0f80e2..8ec946b 100644
36938 --- a/drivers/scsi/bfa/bfa_fcpim.c
36939 +++ b/drivers/scsi/bfa/bfa_fcpim.c
36940 @@ -3715,7 +3715,7 @@ bfa_fcp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
36941
36942 bfa_iotag_attach(fcp);
36943
36944 - fcp->itn_arr = (struct bfa_itn_s *) bfa_mem_kva_curp(fcp);
36945 + fcp->itn_arr = (bfa_itn_s_no_const *) bfa_mem_kva_curp(fcp);
36946 bfa_mem_kva_curp(fcp) = (u8 *)fcp->itn_arr +
36947 (fcp->num_itns * sizeof(struct bfa_itn_s));
36948 memset(fcp->itn_arr, 0,
36949 @@ -3773,7 +3773,7 @@ bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36950 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m))
36951 {
36952 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
36953 - struct bfa_itn_s *itn;
36954 + bfa_itn_s_no_const *itn;
36955
36956 itn = BFA_ITN_FROM_TAG(fcp, rport->rport_tag);
36957 itn->isr = isr;
36958 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
36959 index 36f26da..38a34a8 100644
36960 --- a/drivers/scsi/bfa/bfa_fcpim.h
36961 +++ b/drivers/scsi/bfa/bfa_fcpim.h
36962 @@ -37,6 +37,7 @@ struct bfa_iotag_s {
36963 struct bfa_itn_s {
36964 bfa_isr_func_t isr;
36965 };
36966 +typedef struct bfa_itn_s __no_const bfa_itn_s_no_const;
36967
36968 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36969 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
36970 @@ -147,7 +148,7 @@ struct bfa_fcp_mod_s {
36971 struct list_head iotag_tio_free_q; /* free IO resources */
36972 struct list_head iotag_unused_q; /* unused IO resources*/
36973 struct bfa_iotag_s *iotag_arr;
36974 - struct bfa_itn_s *itn_arr;
36975 + bfa_itn_s_no_const *itn_arr;
36976 int num_ioim_reqs;
36977 int num_fwtio_reqs;
36978 int num_itns;
36979 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
36980 index 1a99d4b..e85d64b 100644
36981 --- a/drivers/scsi/bfa/bfa_ioc.h
36982 +++ b/drivers/scsi/bfa/bfa_ioc.h
36983 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
36984 bfa_ioc_disable_cbfn_t disable_cbfn;
36985 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
36986 bfa_ioc_reset_cbfn_t reset_cbfn;
36987 -};
36988 +} __no_const;
36989
36990 /*
36991 * IOC event notification mechanism.
36992 @@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
36993 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
36994 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
36995 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
36996 -};
36997 +} __no_const;
36998
36999 /*
37000 * Queue element to wait for room in request queue. FIFO order is
37001 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
37002 index 593085a..47aa999 100644
37003 --- a/drivers/scsi/hosts.c
37004 +++ b/drivers/scsi/hosts.c
37005 @@ -42,7 +42,7 @@
37006 #include "scsi_logging.h"
37007
37008
37009 -static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
37010 +static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
37011
37012
37013 static void scsi_host_cls_release(struct device *dev)
37014 @@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
37015 * subtract one because we increment first then return, but we need to
37016 * know what the next host number was before increment
37017 */
37018 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
37019 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
37020 shost->dma_channel = 0xff;
37021
37022 /* These three are default values which can be overridden */
37023 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
37024 index f9823f2..7bc3e81 100644
37025 --- a/drivers/scsi/hpsa.c
37026 +++ b/drivers/scsi/hpsa.c
37027 @@ -536,7 +536,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
37028 unsigned long flags;
37029
37030 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
37031 - return h->access.command_completed(h, q);
37032 + return h->access->command_completed(h, q);
37033
37034 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
37035 a = rq->head[rq->current_entry];
37036 @@ -3355,7 +3355,7 @@ static void start_io(struct ctlr_info *h)
37037 while (!list_empty(&h->reqQ)) {
37038 c = list_entry(h->reqQ.next, struct CommandList, list);
37039 /* can't do anything if fifo is full */
37040 - if ((h->access.fifo_full(h))) {
37041 + if ((h->access->fifo_full(h))) {
37042 dev_warn(&h->pdev->dev, "fifo full\n");
37043 break;
37044 }
37045 @@ -3377,7 +3377,7 @@ static void start_io(struct ctlr_info *h)
37046
37047 /* Tell the controller execute command */
37048 spin_unlock_irqrestore(&h->lock, flags);
37049 - h->access.submit_command(h, c);
37050 + h->access->submit_command(h, c);
37051 spin_lock_irqsave(&h->lock, flags);
37052 }
37053 spin_unlock_irqrestore(&h->lock, flags);
37054 @@ -3385,17 +3385,17 @@ static void start_io(struct ctlr_info *h)
37055
37056 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
37057 {
37058 - return h->access.command_completed(h, q);
37059 + return h->access->command_completed(h, q);
37060 }
37061
37062 static inline bool interrupt_pending(struct ctlr_info *h)
37063 {
37064 - return h->access.intr_pending(h);
37065 + return h->access->intr_pending(h);
37066 }
37067
37068 static inline long interrupt_not_for_us(struct ctlr_info *h)
37069 {
37070 - return (h->access.intr_pending(h) == 0) ||
37071 + return (h->access->intr_pending(h) == 0) ||
37072 (h->interrupts_enabled == 0);
37073 }
37074
37075 @@ -4299,7 +4299,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
37076 if (prod_index < 0)
37077 return -ENODEV;
37078 h->product_name = products[prod_index].product_name;
37079 - h->access = *(products[prod_index].access);
37080 + h->access = products[prod_index].access;
37081
37082 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
37083 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
37084 @@ -4581,7 +4581,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
37085
37086 assert_spin_locked(&lockup_detector_lock);
37087 remove_ctlr_from_lockup_detector_list(h);
37088 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
37089 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
37090 spin_lock_irqsave(&h->lock, flags);
37091 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
37092 spin_unlock_irqrestore(&h->lock, flags);
37093 @@ -4759,7 +4759,7 @@ reinit_after_soft_reset:
37094 }
37095
37096 /* make sure the board interrupts are off */
37097 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
37098 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
37099
37100 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
37101 goto clean2;
37102 @@ -4793,7 +4793,7 @@ reinit_after_soft_reset:
37103 * fake ones to scoop up any residual completions.
37104 */
37105 spin_lock_irqsave(&h->lock, flags);
37106 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
37107 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
37108 spin_unlock_irqrestore(&h->lock, flags);
37109 free_irqs(h);
37110 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
37111 @@ -4812,9 +4812,9 @@ reinit_after_soft_reset:
37112 dev_info(&h->pdev->dev, "Board READY.\n");
37113 dev_info(&h->pdev->dev,
37114 "Waiting for stale completions to drain.\n");
37115 - h->access.set_intr_mask(h, HPSA_INTR_ON);
37116 + h->access->set_intr_mask(h, HPSA_INTR_ON);
37117 msleep(10000);
37118 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
37119 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
37120
37121 rc = controller_reset_failed(h->cfgtable);
37122 if (rc)
37123 @@ -4835,7 +4835,7 @@ reinit_after_soft_reset:
37124 }
37125
37126 /* Turn the interrupts on so we can service requests */
37127 - h->access.set_intr_mask(h, HPSA_INTR_ON);
37128 + h->access->set_intr_mask(h, HPSA_INTR_ON);
37129
37130 hpsa_hba_inquiry(h);
37131 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
37132 @@ -4887,7 +4887,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
37133 * To write all data in the battery backed cache to disks
37134 */
37135 hpsa_flush_cache(h);
37136 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
37137 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
37138 hpsa_free_irqs_and_disable_msix(h);
37139 }
37140
37141 @@ -5056,7 +5056,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
37142 return;
37143 }
37144 /* Change the access methods to the performant access methods */
37145 - h->access = SA5_performant_access;
37146 + h->access = &SA5_performant_access;
37147 h->transMethod = CFGTBL_Trans_Performant;
37148 }
37149
37150 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
37151 index 9816479..c5d4e97 100644
37152 --- a/drivers/scsi/hpsa.h
37153 +++ b/drivers/scsi/hpsa.h
37154 @@ -79,7 +79,7 @@ struct ctlr_info {
37155 unsigned int msix_vector;
37156 unsigned int msi_vector;
37157 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
37158 - struct access_method access;
37159 + struct access_method *access;
37160
37161 /* queue and queue Info */
37162 struct list_head reqQ;
37163 diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
37164 index f2df059..a3a9930 100644
37165 --- a/drivers/scsi/ips.h
37166 +++ b/drivers/scsi/ips.h
37167 @@ -1027,7 +1027,7 @@ typedef struct {
37168 int (*intr)(struct ips_ha *);
37169 void (*enableint)(struct ips_ha *);
37170 uint32_t (*statupd)(struct ips_ha *);
37171 -} ips_hw_func_t;
37172 +} __no_const ips_hw_func_t;
37173
37174 typedef struct ips_ha {
37175 uint8_t ha_id[IPS_MAX_CHANNELS+1];
37176 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
37177 index c772d8d..35c362c 100644
37178 --- a/drivers/scsi/libfc/fc_exch.c
37179 +++ b/drivers/scsi/libfc/fc_exch.c
37180 @@ -100,12 +100,12 @@ struct fc_exch_mgr {
37181 u16 pool_max_index;
37182
37183 struct {
37184 - atomic_t no_free_exch;
37185 - atomic_t no_free_exch_xid;
37186 - atomic_t xid_not_found;
37187 - atomic_t xid_busy;
37188 - atomic_t seq_not_found;
37189 - atomic_t non_bls_resp;
37190 + atomic_unchecked_t no_free_exch;
37191 + atomic_unchecked_t no_free_exch_xid;
37192 + atomic_unchecked_t xid_not_found;
37193 + atomic_unchecked_t xid_busy;
37194 + atomic_unchecked_t seq_not_found;
37195 + atomic_unchecked_t non_bls_resp;
37196 } stats;
37197 };
37198
37199 @@ -725,7 +725,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
37200 /* allocate memory for exchange */
37201 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
37202 if (!ep) {
37203 - atomic_inc(&mp->stats.no_free_exch);
37204 + atomic_inc_unchecked(&mp->stats.no_free_exch);
37205 goto out;
37206 }
37207 memset(ep, 0, sizeof(*ep));
37208 @@ -786,7 +786,7 @@ out:
37209 return ep;
37210 err:
37211 spin_unlock_bh(&pool->lock);
37212 - atomic_inc(&mp->stats.no_free_exch_xid);
37213 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
37214 mempool_free(ep, mp->ep_pool);
37215 return NULL;
37216 }
37217 @@ -929,7 +929,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
37218 xid = ntohs(fh->fh_ox_id); /* we originated exch */
37219 ep = fc_exch_find(mp, xid);
37220 if (!ep) {
37221 - atomic_inc(&mp->stats.xid_not_found);
37222 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37223 reject = FC_RJT_OX_ID;
37224 goto out;
37225 }
37226 @@ -959,7 +959,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
37227 ep = fc_exch_find(mp, xid);
37228 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
37229 if (ep) {
37230 - atomic_inc(&mp->stats.xid_busy);
37231 + atomic_inc_unchecked(&mp->stats.xid_busy);
37232 reject = FC_RJT_RX_ID;
37233 goto rel;
37234 }
37235 @@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
37236 }
37237 xid = ep->xid; /* get our XID */
37238 } else if (!ep) {
37239 - atomic_inc(&mp->stats.xid_not_found);
37240 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37241 reject = FC_RJT_RX_ID; /* XID not found */
37242 goto out;
37243 }
37244 @@ -987,7 +987,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
37245 } else {
37246 sp = &ep->seq;
37247 if (sp->id != fh->fh_seq_id) {
37248 - atomic_inc(&mp->stats.seq_not_found);
37249 + atomic_inc_unchecked(&mp->stats.seq_not_found);
37250 if (f_ctl & FC_FC_END_SEQ) {
37251 /*
37252 * Update sequence_id based on incoming last
37253 @@ -1437,22 +1437,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
37254
37255 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
37256 if (!ep) {
37257 - atomic_inc(&mp->stats.xid_not_found);
37258 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37259 goto out;
37260 }
37261 if (ep->esb_stat & ESB_ST_COMPLETE) {
37262 - atomic_inc(&mp->stats.xid_not_found);
37263 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37264 goto rel;
37265 }
37266 if (ep->rxid == FC_XID_UNKNOWN)
37267 ep->rxid = ntohs(fh->fh_rx_id);
37268 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
37269 - atomic_inc(&mp->stats.xid_not_found);
37270 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37271 goto rel;
37272 }
37273 if (ep->did != ntoh24(fh->fh_s_id) &&
37274 ep->did != FC_FID_FLOGI) {
37275 - atomic_inc(&mp->stats.xid_not_found);
37276 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37277 goto rel;
37278 }
37279 sof = fr_sof(fp);
37280 @@ -1461,7 +1461,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
37281 sp->ssb_stat |= SSB_ST_RESP;
37282 sp->id = fh->fh_seq_id;
37283 } else if (sp->id != fh->fh_seq_id) {
37284 - atomic_inc(&mp->stats.seq_not_found);
37285 + atomic_inc_unchecked(&mp->stats.seq_not_found);
37286 goto rel;
37287 }
37288
37289 @@ -1525,9 +1525,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
37290 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
37291
37292 if (!sp)
37293 - atomic_inc(&mp->stats.xid_not_found);
37294 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37295 else
37296 - atomic_inc(&mp->stats.non_bls_resp);
37297 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
37298
37299 fc_frame_free(fp);
37300 }
37301 @@ -2174,13 +2174,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
37302
37303 list_for_each_entry(ema, &lport->ema_list, ema_list) {
37304 mp = ema->mp;
37305 - st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
37306 + st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
37307 st->fc_no_free_exch_xid +=
37308 - atomic_read(&mp->stats.no_free_exch_xid);
37309 - st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
37310 - st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
37311 - st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
37312 - st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
37313 + atomic_read_unchecked(&mp->stats.no_free_exch_xid);
37314 + st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
37315 + st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
37316 + st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
37317 + st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
37318 }
37319 }
37320 EXPORT_SYMBOL(fc_exch_update_stats);
37321 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
37322 index a59fcdc..abe55f3 100644
37323 --- a/drivers/scsi/libsas/sas_ata.c
37324 +++ b/drivers/scsi/libsas/sas_ata.c
37325 @@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
37326 .postreset = ata_std_postreset,
37327 .error_handler = ata_std_error_handler,
37328 .post_internal_cmd = sas_ata_post_internal,
37329 - .qc_defer = ata_std_qc_defer,
37330 + .qc_defer = ata_std_qc_defer,
37331 .qc_prep = ata_noop_qc_prep,
37332 .qc_issue = sas_ata_qc_issue,
37333 .qc_fill_rtf = sas_ata_qc_fill_rtf,
37334 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
37335 index a65c05a..a39e402 100644
37336 --- a/drivers/scsi/lpfc/lpfc.h
37337 +++ b/drivers/scsi/lpfc/lpfc.h
37338 @@ -420,7 +420,7 @@ struct lpfc_vport {
37339 struct dentry *debug_nodelist;
37340 struct dentry *vport_debugfs_root;
37341 struct lpfc_debugfs_trc *disc_trc;
37342 - atomic_t disc_trc_cnt;
37343 + atomic_unchecked_t disc_trc_cnt;
37344 #endif
37345 uint8_t stat_data_enabled;
37346 uint8_t stat_data_blocked;
37347 @@ -834,8 +834,8 @@ struct lpfc_hba {
37348 struct timer_list fabric_block_timer;
37349 unsigned long bit_flags;
37350 #define FABRIC_COMANDS_BLOCKED 0
37351 - atomic_t num_rsrc_err;
37352 - atomic_t num_cmd_success;
37353 + atomic_unchecked_t num_rsrc_err;
37354 + atomic_unchecked_t num_cmd_success;
37355 unsigned long last_rsrc_error_time;
37356 unsigned long last_ramp_down_time;
37357 unsigned long last_ramp_up_time;
37358 @@ -871,7 +871,7 @@ struct lpfc_hba {
37359
37360 struct dentry *debug_slow_ring_trc;
37361 struct lpfc_debugfs_trc *slow_ring_trc;
37362 - atomic_t slow_ring_trc_cnt;
37363 + atomic_unchecked_t slow_ring_trc_cnt;
37364 /* iDiag debugfs sub-directory */
37365 struct dentry *idiag_root;
37366 struct dentry *idiag_pci_cfg;
37367 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
37368 index 3217d63..c417981 100644
37369 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
37370 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
37371 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
37372
37373 #include <linux/debugfs.h>
37374
37375 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
37376 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
37377 static unsigned long lpfc_debugfs_start_time = 0L;
37378
37379 /* iDiag */
37380 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
37381 lpfc_debugfs_enable = 0;
37382
37383 len = 0;
37384 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
37385 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
37386 (lpfc_debugfs_max_disc_trc - 1);
37387 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
37388 dtp = vport->disc_trc + i;
37389 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
37390 lpfc_debugfs_enable = 0;
37391
37392 len = 0;
37393 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
37394 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
37395 (lpfc_debugfs_max_slow_ring_trc - 1);
37396 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
37397 dtp = phba->slow_ring_trc + i;
37398 @@ -636,14 +636,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
37399 !vport || !vport->disc_trc)
37400 return;
37401
37402 - index = atomic_inc_return(&vport->disc_trc_cnt) &
37403 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
37404 (lpfc_debugfs_max_disc_trc - 1);
37405 dtp = vport->disc_trc + index;
37406 dtp->fmt = fmt;
37407 dtp->data1 = data1;
37408 dtp->data2 = data2;
37409 dtp->data3 = data3;
37410 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
37411 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
37412 dtp->jif = jiffies;
37413 #endif
37414 return;
37415 @@ -674,14 +674,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
37416 !phba || !phba->slow_ring_trc)
37417 return;
37418
37419 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
37420 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
37421 (lpfc_debugfs_max_slow_ring_trc - 1);
37422 dtp = phba->slow_ring_trc + index;
37423 dtp->fmt = fmt;
37424 dtp->data1 = data1;
37425 dtp->data2 = data2;
37426 dtp->data3 = data3;
37427 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
37428 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
37429 dtp->jif = jiffies;
37430 #endif
37431 return;
37432 @@ -4090,7 +4090,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
37433 "slow_ring buffer\n");
37434 goto debug_failed;
37435 }
37436 - atomic_set(&phba->slow_ring_trc_cnt, 0);
37437 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
37438 memset(phba->slow_ring_trc, 0,
37439 (sizeof(struct lpfc_debugfs_trc) *
37440 lpfc_debugfs_max_slow_ring_trc));
37441 @@ -4136,7 +4136,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
37442 "buffer\n");
37443 goto debug_failed;
37444 }
37445 - atomic_set(&vport->disc_trc_cnt, 0);
37446 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
37447
37448 snprintf(name, sizeof(name), "discovery_trace");
37449 vport->debug_disc_trc =
37450 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
37451 index 45c1520..35ba744 100644
37452 --- a/drivers/scsi/lpfc/lpfc_init.c
37453 +++ b/drivers/scsi/lpfc/lpfc_init.c
37454 @@ -10478,8 +10478,10 @@ lpfc_init(void)
37455 "misc_register returned with status %d", error);
37456
37457 if (lpfc_enable_npiv) {
37458 - lpfc_transport_functions.vport_create = lpfc_vport_create;
37459 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
37460 + pax_open_kernel();
37461 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
37462 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
37463 + pax_close_kernel();
37464 }
37465 lpfc_transport_template =
37466 fc_attach_transport(&lpfc_transport_functions);
37467 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
37468 index 925975d..0f1fc07 100644
37469 --- a/drivers/scsi/lpfc/lpfc_scsi.c
37470 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
37471 @@ -311,7 +311,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
37472 uint32_t evt_posted;
37473
37474 spin_lock_irqsave(&phba->hbalock, flags);
37475 - atomic_inc(&phba->num_rsrc_err);
37476 + atomic_inc_unchecked(&phba->num_rsrc_err);
37477 phba->last_rsrc_error_time = jiffies;
37478
37479 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
37480 @@ -352,7 +352,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
37481 unsigned long flags;
37482 struct lpfc_hba *phba = vport->phba;
37483 uint32_t evt_posted;
37484 - atomic_inc(&phba->num_cmd_success);
37485 + atomic_inc_unchecked(&phba->num_cmd_success);
37486
37487 if (vport->cfg_lun_queue_depth <= queue_depth)
37488 return;
37489 @@ -396,8 +396,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
37490 unsigned long num_rsrc_err, num_cmd_success;
37491 int i;
37492
37493 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
37494 - num_cmd_success = atomic_read(&phba->num_cmd_success);
37495 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
37496 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
37497
37498 /*
37499 * The error and success command counters are global per
37500 @@ -425,8 +425,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
37501 }
37502 }
37503 lpfc_destroy_vport_work_array(phba, vports);
37504 - atomic_set(&phba->num_rsrc_err, 0);
37505 - atomic_set(&phba->num_cmd_success, 0);
37506 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
37507 + atomic_set_unchecked(&phba->num_cmd_success, 0);
37508 }
37509
37510 /**
37511 @@ -460,8 +460,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
37512 }
37513 }
37514 lpfc_destroy_vport_work_array(phba, vports);
37515 - atomic_set(&phba->num_rsrc_err, 0);
37516 - atomic_set(&phba->num_cmd_success, 0);
37517 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
37518 + atomic_set_unchecked(&phba->num_cmd_success, 0);
37519 }
37520
37521 /**
37522 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
37523 index ea8a0b4..812a124 100644
37524 --- a/drivers/scsi/pmcraid.c
37525 +++ b/drivers/scsi/pmcraid.c
37526 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
37527 res->scsi_dev = scsi_dev;
37528 scsi_dev->hostdata = res;
37529 res->change_detected = 0;
37530 - atomic_set(&res->read_failures, 0);
37531 - atomic_set(&res->write_failures, 0);
37532 + atomic_set_unchecked(&res->read_failures, 0);
37533 + atomic_set_unchecked(&res->write_failures, 0);
37534 rc = 0;
37535 }
37536 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
37537 @@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
37538
37539 /* If this was a SCSI read/write command keep count of errors */
37540 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
37541 - atomic_inc(&res->read_failures);
37542 + atomic_inc_unchecked(&res->read_failures);
37543 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
37544 - atomic_inc(&res->write_failures);
37545 + atomic_inc_unchecked(&res->write_failures);
37546
37547 if (!RES_IS_GSCSI(res->cfg_entry) &&
37548 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
37549 @@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
37550 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
37551 * hrrq_id assigned here in queuecommand
37552 */
37553 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
37554 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
37555 pinstance->num_hrrq;
37556 cmd->cmd_done = pmcraid_io_done;
37557
37558 @@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
37559 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
37560 * hrrq_id assigned here in queuecommand
37561 */
37562 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
37563 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
37564 pinstance->num_hrrq;
37565
37566 if (request_size) {
37567 @@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
37568
37569 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
37570 /* add resources only after host is added into system */
37571 - if (!atomic_read(&pinstance->expose_resources))
37572 + if (!atomic_read_unchecked(&pinstance->expose_resources))
37573 return;
37574
37575 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
37576 @@ -5331,8 +5331,8 @@ static int __devinit pmcraid_init_instance(
37577 init_waitqueue_head(&pinstance->reset_wait_q);
37578
37579 atomic_set(&pinstance->outstanding_cmds, 0);
37580 - atomic_set(&pinstance->last_message_id, 0);
37581 - atomic_set(&pinstance->expose_resources, 0);
37582 + atomic_set_unchecked(&pinstance->last_message_id, 0);
37583 + atomic_set_unchecked(&pinstance->expose_resources, 0);
37584
37585 INIT_LIST_HEAD(&pinstance->free_res_q);
37586 INIT_LIST_HEAD(&pinstance->used_res_q);
37587 @@ -6047,7 +6047,7 @@ static int __devinit pmcraid_probe(
37588 /* Schedule worker thread to handle CCN and take care of adding and
37589 * removing devices to OS
37590 */
37591 - atomic_set(&pinstance->expose_resources, 1);
37592 + atomic_set_unchecked(&pinstance->expose_resources, 1);
37593 schedule_work(&pinstance->worker_q);
37594 return rc;
37595
37596 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
37597 index e1d150f..6c6df44 100644
37598 --- a/drivers/scsi/pmcraid.h
37599 +++ b/drivers/scsi/pmcraid.h
37600 @@ -748,7 +748,7 @@ struct pmcraid_instance {
37601 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
37602
37603 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
37604 - atomic_t last_message_id;
37605 + atomic_unchecked_t last_message_id;
37606
37607 /* configuration table */
37608 struct pmcraid_config_table *cfg_table;
37609 @@ -777,7 +777,7 @@ struct pmcraid_instance {
37610 atomic_t outstanding_cmds;
37611
37612 /* should add/delete resources to mid-layer now ?*/
37613 - atomic_t expose_resources;
37614 + atomic_unchecked_t expose_resources;
37615
37616
37617
37618 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
37619 struct pmcraid_config_table_entry_ext cfg_entry_ext;
37620 };
37621 struct scsi_device *scsi_dev; /* Link scsi_device structure */
37622 - atomic_t read_failures; /* count of failed READ commands */
37623 - atomic_t write_failures; /* count of failed WRITE commands */
37624 + atomic_unchecked_t read_failures; /* count of failed READ commands */
37625 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
37626
37627 /* To indicate add/delete/modify during CCN */
37628 u8 change_detected;
37629 diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
37630 index 5ab9530..2dd80f7 100644
37631 --- a/drivers/scsi/qla2xxx/qla_attr.c
37632 +++ b/drivers/scsi/qla2xxx/qla_attr.c
37633 @@ -1855,7 +1855,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
37634 return 0;
37635 }
37636
37637 -struct fc_function_template qla2xxx_transport_functions = {
37638 +fc_function_template_no_const qla2xxx_transport_functions = {
37639
37640 .show_host_node_name = 1,
37641 .show_host_port_name = 1,
37642 @@ -1902,7 +1902,7 @@ struct fc_function_template qla2xxx_transport_functions = {
37643 .bsg_timeout = qla24xx_bsg_timeout,
37644 };
37645
37646 -struct fc_function_template qla2xxx_transport_vport_functions = {
37647 +fc_function_template_no_const qla2xxx_transport_vport_functions = {
37648
37649 .show_host_node_name = 1,
37650 .show_host_port_name = 1,
37651 diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
37652 index 39007f5..7fafc64 100644
37653 --- a/drivers/scsi/qla2xxx/qla_def.h
37654 +++ b/drivers/scsi/qla2xxx/qla_def.h
37655 @@ -2284,7 +2284,7 @@ struct isp_operations {
37656 int (*start_scsi) (srb_t *);
37657 int (*abort_isp) (struct scsi_qla_host *);
37658 int (*iospace_config)(struct qla_hw_data*);
37659 -};
37660 +} __no_const;
37661
37662 /* MSI-X Support *************************************************************/
37663
37664 diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
37665 index 9eacd2d..d79629c 100644
37666 --- a/drivers/scsi/qla2xxx/qla_gbl.h
37667 +++ b/drivers/scsi/qla2xxx/qla_gbl.h
37668 @@ -484,8 +484,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
37669 struct device_attribute;
37670 extern struct device_attribute *qla2x00_host_attrs[];
37671 struct fc_function_template;
37672 -extern struct fc_function_template qla2xxx_transport_functions;
37673 -extern struct fc_function_template qla2xxx_transport_vport_functions;
37674 +extern fc_function_template_no_const qla2xxx_transport_functions;
37675 +extern fc_function_template_no_const qla2xxx_transport_vport_functions;
37676 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
37677 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
37678 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
37679 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
37680 index 7fdba7f..1b4b2c2 100644
37681 --- a/drivers/scsi/qla4xxx/ql4_def.h
37682 +++ b/drivers/scsi/qla4xxx/ql4_def.h
37683 @@ -268,7 +268,7 @@ struct ddb_entry {
37684 * (4000 only) */
37685 atomic_t relogin_timer; /* Max Time to wait for
37686 * relogin to complete */
37687 - atomic_t relogin_retry_count; /* Num of times relogin has been
37688 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
37689 * retried */
37690 uint32_t default_time2wait; /* Default Min time between
37691 * relogins (+aens) */
37692 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
37693 index 9da4266..377b3b6 100644
37694 --- a/drivers/scsi/qla4xxx/ql4_os.c
37695 +++ b/drivers/scsi/qla4xxx/ql4_os.c
37696 @@ -2615,12 +2615,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
37697 */
37698 if (!iscsi_is_session_online(cls_sess)) {
37699 /* Reset retry relogin timer */
37700 - atomic_inc(&ddb_entry->relogin_retry_count);
37701 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
37702 DEBUG2(ql4_printk(KERN_INFO, ha,
37703 "%s: index[%d] relogin timed out-retrying"
37704 " relogin (%d), retry (%d)\n", __func__,
37705 ddb_entry->fw_ddb_index,
37706 - atomic_read(&ddb_entry->relogin_retry_count),
37707 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
37708 ddb_entry->default_time2wait + 4));
37709 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
37710 atomic_set(&ddb_entry->retry_relogin_timer,
37711 @@ -4635,7 +4635,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
37712
37713 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
37714 atomic_set(&ddb_entry->relogin_timer, 0);
37715 - atomic_set(&ddb_entry->relogin_retry_count, 0);
37716 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
37717 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
37718 ddb_entry->default_relogin_timeout =
37719 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
37720 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
37721 index 2936b44..546ecdb 100644
37722 --- a/drivers/scsi/scsi.c
37723 +++ b/drivers/scsi/scsi.c
37724 @@ -660,7 +660,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
37725 unsigned long timeout;
37726 int rtn = 0;
37727
37728 - atomic_inc(&cmd->device->iorequest_cnt);
37729 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37730
37731 /* check if the device is still usable */
37732 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
37733 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
37734 index faa790f..7e351ddd 100644
37735 --- a/drivers/scsi/scsi_lib.c
37736 +++ b/drivers/scsi/scsi_lib.c
37737 @@ -1442,7 +1442,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
37738 shost = sdev->host;
37739 scsi_init_cmd_errh(cmd);
37740 cmd->result = DID_NO_CONNECT << 16;
37741 - atomic_inc(&cmd->device->iorequest_cnt);
37742 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37743
37744 /*
37745 * SCSI request completion path will do scsi_device_unbusy(),
37746 @@ -1468,9 +1468,9 @@ static void scsi_softirq_done(struct request *rq)
37747
37748 INIT_LIST_HEAD(&cmd->eh_entry);
37749
37750 - atomic_inc(&cmd->device->iodone_cnt);
37751 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
37752 if (cmd->result)
37753 - atomic_inc(&cmd->device->ioerr_cnt);
37754 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
37755
37756 disposition = scsi_decide_disposition(cmd);
37757 if (disposition != SUCCESS &&
37758 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
37759 index ce5224c..8c6d071 100644
37760 --- a/drivers/scsi/scsi_sysfs.c
37761 +++ b/drivers/scsi/scsi_sysfs.c
37762 @@ -661,7 +661,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
37763 char *buf) \
37764 { \
37765 struct scsi_device *sdev = to_scsi_device(dev); \
37766 - unsigned long long count = atomic_read(&sdev->field); \
37767 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
37768 return snprintf(buf, 20, "0x%llx\n", count); \
37769 } \
37770 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
37771 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
37772 index 84a1fdf..693b0d6 100644
37773 --- a/drivers/scsi/scsi_tgt_lib.c
37774 +++ b/drivers/scsi/scsi_tgt_lib.c
37775 @@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
37776 int err;
37777
37778 dprintk("%lx %u\n", uaddr, len);
37779 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
37780 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
37781 if (err) {
37782 /*
37783 * TODO: need to fixup sg_tablesize, max_segment_size,
37784 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
37785 index e894ca7..de9d7660 100644
37786 --- a/drivers/scsi/scsi_transport_fc.c
37787 +++ b/drivers/scsi/scsi_transport_fc.c
37788 @@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
37789 * Netlink Infrastructure
37790 */
37791
37792 -static atomic_t fc_event_seq;
37793 +static atomic_unchecked_t fc_event_seq;
37794
37795 /**
37796 * fc_get_event_number - Obtain the next sequential FC event number
37797 @@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
37798 u32
37799 fc_get_event_number(void)
37800 {
37801 - return atomic_add_return(1, &fc_event_seq);
37802 + return atomic_add_return_unchecked(1, &fc_event_seq);
37803 }
37804 EXPORT_SYMBOL(fc_get_event_number);
37805
37806 @@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
37807 {
37808 int error;
37809
37810 - atomic_set(&fc_event_seq, 0);
37811 + atomic_set_unchecked(&fc_event_seq, 0);
37812
37813 error = transport_class_register(&fc_host_class);
37814 if (error)
37815 @@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
37816 char *cp;
37817
37818 *val = simple_strtoul(buf, &cp, 0);
37819 - if ((*cp && (*cp != '\n')) || (*val < 0))
37820 + if (*cp && (*cp != '\n'))
37821 return -EINVAL;
37822 /*
37823 * Check for overflow; dev_loss_tmo is u32
37824 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
37825 index fa1dfaa..4bb620c 100644
37826 --- a/drivers/scsi/scsi_transport_iscsi.c
37827 +++ b/drivers/scsi/scsi_transport_iscsi.c
37828 @@ -79,7 +79,7 @@ struct iscsi_internal {
37829 struct transport_container session_cont;
37830 };
37831
37832 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
37833 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
37834 static struct workqueue_struct *iscsi_eh_timer_workq;
37835
37836 static DEFINE_IDA(iscsi_sess_ida);
37837 @@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
37838 int err;
37839
37840 ihost = shost->shost_data;
37841 - session->sid = atomic_add_return(1, &iscsi_session_nr);
37842 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
37843
37844 if (target_id == ISCSI_MAX_TARGET) {
37845 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
37846 @@ -2943,7 +2943,7 @@ static __init int iscsi_transport_init(void)
37847 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
37848 ISCSI_TRANSPORT_VERSION);
37849
37850 - atomic_set(&iscsi_session_nr, 0);
37851 + atomic_set_unchecked(&iscsi_session_nr, 0);
37852
37853 err = class_register(&iscsi_transport_class);
37854 if (err)
37855 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
37856 index 21a045e..ec89e03 100644
37857 --- a/drivers/scsi/scsi_transport_srp.c
37858 +++ b/drivers/scsi/scsi_transport_srp.c
37859 @@ -33,7 +33,7 @@
37860 #include "scsi_transport_srp_internal.h"
37861
37862 struct srp_host_attrs {
37863 - atomic_t next_port_id;
37864 + atomic_unchecked_t next_port_id;
37865 };
37866 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
37867
37868 @@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
37869 struct Scsi_Host *shost = dev_to_shost(dev);
37870 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
37871
37872 - atomic_set(&srp_host->next_port_id, 0);
37873 + atomic_set_unchecked(&srp_host->next_port_id, 0);
37874 return 0;
37875 }
37876
37877 @@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
37878 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
37879 rport->roles = ids->roles;
37880
37881 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
37882 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
37883 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
37884
37885 transport_setup_device(&rport->dev);
37886 diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
37887 index 4df73e5..b691c58 100644
37888 --- a/drivers/scsi/sd.c
37889 +++ b/drivers/scsi/sd.c
37890 @@ -2709,7 +2709,7 @@ static int sd_probe(struct device *dev)
37891 sdkp->disk = gd;
37892 sdkp->index = index;
37893 atomic_set(&sdkp->openers, 0);
37894 - atomic_set(&sdkp->device->ioerr_cnt, 0);
37895 + atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
37896
37897 if (!sdp->request_queue->rq_timeout) {
37898 if (sdp->type != TYPE_MOD)
37899 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
37900 index 9c5c5f2..8414557 100644
37901 --- a/drivers/scsi/sg.c
37902 +++ b/drivers/scsi/sg.c
37903 @@ -1101,7 +1101,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
37904 sdp->disk->disk_name,
37905 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
37906 NULL,
37907 - (char *)arg);
37908 + (char __user *)arg);
37909 case BLKTRACESTART:
37910 return blk_trace_startstop(sdp->device->request_queue, 1);
37911 case BLKTRACESTOP:
37912 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
37913 index 84c2861..ece0a31 100644
37914 --- a/drivers/spi/spi.c
37915 +++ b/drivers/spi/spi.c
37916 @@ -1453,7 +1453,7 @@ int spi_bus_unlock(struct spi_master *master)
37917 EXPORT_SYMBOL_GPL(spi_bus_unlock);
37918
37919 /* portable code must never pass more than 32 bytes */
37920 -#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
37921 +#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
37922
37923 static u8 *buf;
37924
37925 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
37926 index 34afc16..ffe44dd 100644
37927 --- a/drivers/staging/octeon/ethernet-rx.c
37928 +++ b/drivers/staging/octeon/ethernet-rx.c
37929 @@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37930 /* Increment RX stats for virtual ports */
37931 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
37932 #ifdef CONFIG_64BIT
37933 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
37934 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
37935 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
37936 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
37937 #else
37938 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
37939 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
37940 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
37941 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
37942 #endif
37943 }
37944 netif_receive_skb(skb);
37945 @@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37946 dev->name);
37947 */
37948 #ifdef CONFIG_64BIT
37949 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
37950 + atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37951 #else
37952 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
37953 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
37954 #endif
37955 dev_kfree_skb_irq(skb);
37956 }
37957 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
37958 index 683bedc..86dba9a 100644
37959 --- a/drivers/staging/octeon/ethernet.c
37960 +++ b/drivers/staging/octeon/ethernet.c
37961 @@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
37962 * since the RX tasklet also increments it.
37963 */
37964 #ifdef CONFIG_64BIT
37965 - atomic64_add(rx_status.dropped_packets,
37966 - (atomic64_t *)&priv->stats.rx_dropped);
37967 + atomic64_add_unchecked(rx_status.dropped_packets,
37968 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37969 #else
37970 - atomic_add(rx_status.dropped_packets,
37971 - (atomic_t *)&priv->stats.rx_dropped);
37972 + atomic_add_unchecked(rx_status.dropped_packets,
37973 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
37974 #endif
37975 }
37976
37977 diff --git a/drivers/staging/omapdrm/omap_drv.c b/drivers/staging/omapdrm/omap_drv.c
37978 index 4beab94..44149ee 100644
37979 --- a/drivers/staging/omapdrm/omap_drv.c
37980 +++ b/drivers/staging/omapdrm/omap_drv.c
37981 @@ -761,7 +761,6 @@ static struct drm_driver omap_drm_driver = {
37982 .irq_postinstall = dev_irq_postinstall,
37983 .irq_uninstall = dev_irq_uninstall,
37984 .irq_handler = dev_irq_handler,
37985 - .reclaim_buffers = drm_core_reclaim_buffers,
37986 #ifdef CONFIG_DEBUG_FS
37987 .debugfs_init = omap_debugfs_init,
37988 .debugfs_cleanup = omap_debugfs_cleanup,
37989 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
37990 index dc23395..cf7e9b1 100644
37991 --- a/drivers/staging/rtl8712/rtl871x_io.h
37992 +++ b/drivers/staging/rtl8712/rtl871x_io.h
37993 @@ -108,7 +108,7 @@ struct _io_ops {
37994 u8 *pmem);
37995 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
37996 u8 *pmem);
37997 -};
37998 +} __no_const;
37999
38000 struct io_req {
38001 struct list_head list;
38002 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
38003 index c7b5e8b..783d6cb 100644
38004 --- a/drivers/staging/sbe-2t3e3/netdev.c
38005 +++ b/drivers/staging/sbe-2t3e3/netdev.c
38006 @@ -51,7 +51,7 @@ int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38007 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
38008
38009 if (rlen)
38010 - if (copy_to_user(data, &resp, rlen))
38011 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
38012 return -EFAULT;
38013
38014 return 0;
38015 diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h
38016 index 5d89c0f..9261317 100644
38017 --- a/drivers/staging/usbip/usbip_common.h
38018 +++ b/drivers/staging/usbip/usbip_common.h
38019 @@ -289,7 +289,7 @@ struct usbip_device {
38020 void (*shutdown)(struct usbip_device *);
38021 void (*reset)(struct usbip_device *);
38022 void (*unusable)(struct usbip_device *);
38023 - } eh_ops;
38024 + } __no_const eh_ops;
38025 };
38026
38027 #define kthread_get_run(threadfn, data, namefmt, ...) \
38028 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
38029 index c66b8b3..a4a035b 100644
38030 --- a/drivers/staging/usbip/vhci.h
38031 +++ b/drivers/staging/usbip/vhci.h
38032 @@ -83,7 +83,7 @@ struct vhci_hcd {
38033 unsigned resuming:1;
38034 unsigned long re_timeout;
38035
38036 - atomic_t seqnum;
38037 + atomic_unchecked_t seqnum;
38038
38039 /*
38040 * NOTE:
38041 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
38042 index 12a9a5f..afd8295 100644
38043 --- a/drivers/staging/usbip/vhci_hcd.c
38044 +++ b/drivers/staging/usbip/vhci_hcd.c
38045 @@ -471,7 +471,7 @@ static void vhci_tx_urb(struct urb *urb)
38046 return;
38047 }
38048
38049 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
38050 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
38051 if (priv->seqnum == 0xffff)
38052 dev_info(&urb->dev->dev, "seqnum max\n");
38053
38054 @@ -723,7 +723,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
38055 return -ENOMEM;
38056 }
38057
38058 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
38059 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
38060 if (unlink->seqnum == 0xffff)
38061 pr_info("seqnum max\n");
38062
38063 @@ -911,7 +911,7 @@ static int vhci_start(struct usb_hcd *hcd)
38064 vdev->rhport = rhport;
38065 }
38066
38067 - atomic_set(&vhci->seqnum, 0);
38068 + atomic_set_unchecked(&vhci->seqnum, 0);
38069 spin_lock_init(&vhci->lock);
38070
38071 hcd->power_budget = 0; /* no limit */
38072 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
38073 index f0eaf04..5a82e06 100644
38074 --- a/drivers/staging/usbip/vhci_rx.c
38075 +++ b/drivers/staging/usbip/vhci_rx.c
38076 @@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
38077 if (!urb) {
38078 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
38079 pr_info("max seqnum %d\n",
38080 - atomic_read(&the_controller->seqnum));
38081 + atomic_read_unchecked(&the_controller->seqnum));
38082 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
38083 return;
38084 }
38085 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
38086 index 6ac6f45..1b208ba 100644
38087 --- a/drivers/staging/vt6655/hostap.c
38088 +++ b/drivers/staging/vt6655/hostap.c
38089 @@ -73,14 +73,13 @@ static int msglevel =MSG_LEVEL_INFO;
38090 *
38091 */
38092
38093 +static net_device_ops_no_const apdev_netdev_ops;
38094 +
38095 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
38096 {
38097 PSDevice apdev_priv;
38098 struct net_device *dev = pDevice->dev;
38099 int ret;
38100 - const struct net_device_ops apdev_netdev_ops = {
38101 - .ndo_start_xmit = pDevice->tx_80211,
38102 - };
38103
38104 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
38105
38106 @@ -92,6 +91,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
38107 *apdev_priv = *pDevice;
38108 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
38109
38110 + /* only half broken now */
38111 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
38112 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
38113
38114 pDevice->apdev->type = ARPHRD_IEEE80211;
38115 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
38116 index 682002a..35ed5cf 100644
38117 --- a/drivers/staging/vt6656/hostap.c
38118 +++ b/drivers/staging/vt6656/hostap.c
38119 @@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
38120 *
38121 */
38122
38123 +static net_device_ops_no_const apdev_netdev_ops;
38124 +
38125 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
38126 {
38127 PSDevice apdev_priv;
38128 struct net_device *dev = pDevice->dev;
38129 int ret;
38130 - const struct net_device_ops apdev_netdev_ops = {
38131 - .ndo_start_xmit = pDevice->tx_80211,
38132 - };
38133
38134 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
38135
38136 @@ -79,6 +78,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
38137 *apdev_priv = *pDevice;
38138 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
38139
38140 + /* only half broken now */
38141 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
38142 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
38143
38144 pDevice->apdev->type = ARPHRD_IEEE80211;
38145 diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
38146 index 7843dfd..3db105f 100644
38147 --- a/drivers/staging/wlan-ng/hfa384x_usb.c
38148 +++ b/drivers/staging/wlan-ng/hfa384x_usb.c
38149 @@ -204,7 +204,7 @@ static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
38150
38151 struct usbctlx_completor {
38152 int (*complete) (struct usbctlx_completor *);
38153 -};
38154 +} __no_const;
38155
38156 static int
38157 hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
38158 diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
38159 index eaa9021..43f023b 100644
38160 --- a/drivers/staging/zcache/tmem.c
38161 +++ b/drivers/staging/zcache/tmem.c
38162 @@ -39,7 +39,7 @@
38163 * A tmem host implementation must use this function to register callbacks
38164 * for memory allocation.
38165 */
38166 -static struct tmem_hostops tmem_hostops;
38167 +static tmem_hostops_no_const tmem_hostops;
38168
38169 static void tmem_objnode_tree_init(void);
38170
38171 @@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
38172 * A tmem host implementation must use this function to register
38173 * callbacks for a page-accessible memory (PAM) implementation
38174 */
38175 -static struct tmem_pamops tmem_pamops;
38176 +static tmem_pamops_no_const tmem_pamops;
38177
38178 void tmem_register_pamops(struct tmem_pamops *m)
38179 {
38180 diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
38181 index 0d4aa82..f7832d4 100644
38182 --- a/drivers/staging/zcache/tmem.h
38183 +++ b/drivers/staging/zcache/tmem.h
38184 @@ -180,6 +180,7 @@ struct tmem_pamops {
38185 void (*new_obj)(struct tmem_obj *);
38186 int (*replace_in_obj)(void *, struct tmem_obj *);
38187 };
38188 +typedef struct tmem_pamops __no_const tmem_pamops_no_const;
38189 extern void tmem_register_pamops(struct tmem_pamops *m);
38190
38191 /* memory allocation methods provided by the host implementation */
38192 @@ -189,6 +190,7 @@ struct tmem_hostops {
38193 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
38194 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
38195 };
38196 +typedef struct tmem_hostops __no_const tmem_hostops_no_const;
38197 extern void tmem_register_hostops(struct tmem_hostops *m);
38198
38199 /* core tmem accessor functions */
38200 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
38201 index 7502660..f214d9f 100644
38202 --- a/drivers/target/target_core_transport.c
38203 +++ b/drivers/target/target_core_transport.c
38204 @@ -1098,7 +1098,7 @@ struct se_device *transport_add_device_to_core_hba(
38205 spin_lock_init(&dev->se_port_lock);
38206 spin_lock_init(&dev->se_tmr_lock);
38207 spin_lock_init(&dev->qf_cmd_lock);
38208 - atomic_set(&dev->dev_ordered_id, 0);
38209 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
38210
38211 se_dev_set_default_attribs(dev, dev_limits);
38212
38213 @@ -1288,7 +1288,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
38214 * Used to determine when ORDERED commands should go from
38215 * Dormant to Active status.
38216 */
38217 - cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
38218 + cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
38219 smp_mb__after_atomic_inc();
38220 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
38221 cmd->se_ordered_id, cmd->sam_task_attr,
38222 diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
38223 index e61cabd..7617d26 100644
38224 --- a/drivers/tty/cyclades.c
38225 +++ b/drivers/tty/cyclades.c
38226 @@ -1589,10 +1589,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
38227 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
38228 info->port.count);
38229 #endif
38230 - info->port.count++;
38231 + atomic_inc(&info->port.count);
38232 #ifdef CY_DEBUG_COUNT
38233 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
38234 - current->pid, info->port.count);
38235 + current->pid, atomic_read(&info->port.count));
38236 #endif
38237
38238 /*
38239 @@ -3987,7 +3987,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
38240 for (j = 0; j < cy_card[i].nports; j++) {
38241 info = &cy_card[i].ports[j];
38242
38243 - if (info->port.count) {
38244 + if (atomic_read(&info->port.count)) {
38245 /* XXX is the ldisc num worth this? */
38246 struct tty_struct *tty;
38247 struct tty_ldisc *ld;
38248 diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
38249 index 2d691eb..be02ebd 100644
38250 --- a/drivers/tty/hvc/hvc_console.c
38251 +++ b/drivers/tty/hvc/hvc_console.c
38252 @@ -315,7 +315,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
38253
38254 spin_lock_irqsave(&hp->port.lock, flags);
38255 /* Check and then increment for fast path open. */
38256 - if (hp->port.count++ > 0) {
38257 + if (atomic_inc_return(&hp->port.count) > 1) {
38258 spin_unlock_irqrestore(&hp->port.lock, flags);
38259 hvc_kick();
38260 return 0;
38261 @@ -366,7 +366,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
38262
38263 spin_lock_irqsave(&hp->port.lock, flags);
38264
38265 - if (--hp->port.count == 0) {
38266 + if (atomic_dec_return(&hp->port.count) == 0) {
38267 spin_unlock_irqrestore(&hp->port.lock, flags);
38268 /* We are done with the tty pointer now. */
38269 tty_port_tty_set(&hp->port, NULL);
38270 @@ -384,9 +384,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
38271 */
38272 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
38273 } else {
38274 - if (hp->port.count < 0)
38275 + if (atomic_read(&hp->port.count) < 0)
38276 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
38277 - hp->vtermno, hp->port.count);
38278 + hp->vtermno, atomic_read(&hp->port.count));
38279 spin_unlock_irqrestore(&hp->port.lock, flags);
38280 }
38281
38282 @@ -412,13 +412,13 @@ static void hvc_hangup(struct tty_struct *tty)
38283 * open->hangup case this can be called after the final close so prevent
38284 * that from happening for now.
38285 */
38286 - if (hp->port.count <= 0) {
38287 + if (atomic_read(&hp->port.count) <= 0) {
38288 spin_unlock_irqrestore(&hp->port.lock, flags);
38289 return;
38290 }
38291
38292 - temp_open_count = hp->port.count;
38293 - hp->port.count = 0;
38294 + temp_open_count = atomic_read(&hp->port.count);
38295 + atomic_set(&hp->port.count, 0);
38296 spin_unlock_irqrestore(&hp->port.lock, flags);
38297 tty_port_tty_set(&hp->port, NULL);
38298
38299 @@ -471,7 +471,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
38300 return -EPIPE;
38301
38302 /* FIXME what's this (unprotected) check for? */
38303 - if (hp->port.count <= 0)
38304 + if (atomic_read(&hp->port.count) <= 0)
38305 return -EIO;
38306
38307 spin_lock_irqsave(&hp->lock, flags);
38308 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
38309 index d56788c..12d8f85 100644
38310 --- a/drivers/tty/hvc/hvcs.c
38311 +++ b/drivers/tty/hvc/hvcs.c
38312 @@ -83,6 +83,7 @@
38313 #include <asm/hvcserver.h>
38314 #include <asm/uaccess.h>
38315 #include <asm/vio.h>
38316 +#include <asm/local.h>
38317
38318 /*
38319 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
38320 @@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
38321
38322 spin_lock_irqsave(&hvcsd->lock, flags);
38323
38324 - if (hvcsd->port.count > 0) {
38325 + if (atomic_read(&hvcsd->port.count) > 0) {
38326 spin_unlock_irqrestore(&hvcsd->lock, flags);
38327 printk(KERN_INFO "HVCS: vterm state unchanged. "
38328 "The hvcs device node is still in use.\n");
38329 @@ -1134,7 +1135,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
38330 if ((retval = hvcs_partner_connect(hvcsd)))
38331 goto error_release;
38332
38333 - hvcsd->port.count = 1;
38334 + atomic_set(&hvcsd->port.count, 1);
38335 hvcsd->port.tty = tty;
38336 tty->driver_data = hvcsd;
38337
38338 @@ -1168,7 +1169,7 @@ fast_open:
38339
38340 spin_lock_irqsave(&hvcsd->lock, flags);
38341 tty_port_get(&hvcsd->port);
38342 - hvcsd->port.count++;
38343 + atomic_inc(&hvcsd->port.count);
38344 hvcsd->todo_mask |= HVCS_SCHED_READ;
38345 spin_unlock_irqrestore(&hvcsd->lock, flags);
38346
38347 @@ -1212,7 +1213,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
38348 hvcsd = tty->driver_data;
38349
38350 spin_lock_irqsave(&hvcsd->lock, flags);
38351 - if (--hvcsd->port.count == 0) {
38352 + if (atomic_dec_and_test(&hvcsd->port.count)) {
38353
38354 vio_disable_interrupts(hvcsd->vdev);
38355
38356 @@ -1238,10 +1239,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
38357 free_irq(irq, hvcsd);
38358 tty_port_put(&hvcsd->port);
38359 return;
38360 - } else if (hvcsd->port.count < 0) {
38361 + } else if (atomic_read(&hvcsd->port.count) < 0) {
38362 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
38363 " is missmanaged.\n",
38364 - hvcsd->vdev->unit_address, hvcsd->port.count);
38365 + hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
38366 }
38367
38368 spin_unlock_irqrestore(&hvcsd->lock, flags);
38369 @@ -1257,7 +1258,7 @@ static void hvcs_hangup(struct tty_struct * tty)
38370
38371 spin_lock_irqsave(&hvcsd->lock, flags);
38372 /* Preserve this so that we know how many kref refs to put */
38373 - temp_open_count = hvcsd->port.count;
38374 + temp_open_count = atomic_read(&hvcsd->port.count);
38375
38376 /*
38377 * Don't kref put inside the spinlock because the destruction
38378 @@ -1272,7 +1273,7 @@ static void hvcs_hangup(struct tty_struct * tty)
38379 tty->driver_data = NULL;
38380 hvcsd->port.tty = NULL;
38381
38382 - hvcsd->port.count = 0;
38383 + atomic_set(&hvcsd->port.count, 0);
38384
38385 /* This will drop any buffered data on the floor which is OK in a hangup
38386 * scenario. */
38387 @@ -1343,7 +1344,7 @@ static int hvcs_write(struct tty_struct *tty,
38388 * the middle of a write operation? This is a crummy place to do this
38389 * but we want to keep it all in the spinlock.
38390 */
38391 - if (hvcsd->port.count <= 0) {
38392 + if (atomic_read(&hvcsd->port.count) <= 0) {
38393 spin_unlock_irqrestore(&hvcsd->lock, flags);
38394 return -ENODEV;
38395 }
38396 @@ -1417,7 +1418,7 @@ static int hvcs_write_room(struct tty_struct *tty)
38397 {
38398 struct hvcs_struct *hvcsd = tty->driver_data;
38399
38400 - if (!hvcsd || hvcsd->port.count <= 0)
38401 + if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
38402 return 0;
38403
38404 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
38405 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
38406 index f8b5fa0..4ba9f89 100644
38407 --- a/drivers/tty/ipwireless/tty.c
38408 +++ b/drivers/tty/ipwireless/tty.c
38409 @@ -29,6 +29,7 @@
38410 #include <linux/tty_driver.h>
38411 #include <linux/tty_flip.h>
38412 #include <linux/uaccess.h>
38413 +#include <asm/local.h>
38414
38415 #include "tty.h"
38416 #include "network.h"
38417 @@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
38418 mutex_unlock(&tty->ipw_tty_mutex);
38419 return -ENODEV;
38420 }
38421 - if (tty->port.count == 0)
38422 + if (atomic_read(&tty->port.count) == 0)
38423 tty->tx_bytes_queued = 0;
38424
38425 - tty->port.count++;
38426 + atomic_inc(&tty->port.count);
38427
38428 tty->port.tty = linux_tty;
38429 linux_tty->driver_data = tty;
38430 @@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
38431
38432 static void do_ipw_close(struct ipw_tty *tty)
38433 {
38434 - tty->port.count--;
38435 -
38436 - if (tty->port.count == 0) {
38437 + if (atomic_dec_return(&tty->port.count) == 0) {
38438 struct tty_struct *linux_tty = tty->port.tty;
38439
38440 if (linux_tty != NULL) {
38441 @@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
38442 return;
38443
38444 mutex_lock(&tty->ipw_tty_mutex);
38445 - if (tty->port.count == 0) {
38446 + if (atomic_read(&tty->port.count) == 0) {
38447 mutex_unlock(&tty->ipw_tty_mutex);
38448 return;
38449 }
38450 @@ -170,7 +169,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
38451 return;
38452 }
38453
38454 - if (!tty->port.count) {
38455 + if (!atomic_read(&tty->port.count)) {
38456 mutex_unlock(&tty->ipw_tty_mutex);
38457 return;
38458 }
38459 @@ -212,7 +211,7 @@ static int ipw_write(struct tty_struct *linux_tty,
38460 return -ENODEV;
38461
38462 mutex_lock(&tty->ipw_tty_mutex);
38463 - if (!tty->port.count) {
38464 + if (!atomic_read(&tty->port.count)) {
38465 mutex_unlock(&tty->ipw_tty_mutex);
38466 return -EINVAL;
38467 }
38468 @@ -252,7 +251,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
38469 if (!tty)
38470 return -ENODEV;
38471
38472 - if (!tty->port.count)
38473 + if (!atomic_read(&tty->port.count))
38474 return -EINVAL;
38475
38476 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
38477 @@ -294,7 +293,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
38478 if (!tty)
38479 return 0;
38480
38481 - if (!tty->port.count)
38482 + if (!atomic_read(&tty->port.count))
38483 return 0;
38484
38485 return tty->tx_bytes_queued;
38486 @@ -375,7 +374,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
38487 if (!tty)
38488 return -ENODEV;
38489
38490 - if (!tty->port.count)
38491 + if (!atomic_read(&tty->port.count))
38492 return -EINVAL;
38493
38494 return get_control_lines(tty);
38495 @@ -391,7 +390,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
38496 if (!tty)
38497 return -ENODEV;
38498
38499 - if (!tty->port.count)
38500 + if (!atomic_read(&tty->port.count))
38501 return -EINVAL;
38502
38503 return set_control_lines(tty, set, clear);
38504 @@ -405,7 +404,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
38505 if (!tty)
38506 return -ENODEV;
38507
38508 - if (!tty->port.count)
38509 + if (!atomic_read(&tty->port.count))
38510 return -EINVAL;
38511
38512 /* FIXME: Exactly how is the tty object locked here .. */
38513 @@ -561,7 +560,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
38514 * are gone */
38515 mutex_lock(&ttyj->ipw_tty_mutex);
38516 }
38517 - while (ttyj->port.count)
38518 + while (atomic_read(&ttyj->port.count))
38519 do_ipw_close(ttyj);
38520 ipwireless_disassociate_network_ttys(network,
38521 ttyj->channel_idx);
38522 diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
38523 index 324467d..504cc25 100644
38524 --- a/drivers/tty/moxa.c
38525 +++ b/drivers/tty/moxa.c
38526 @@ -1172,7 +1172,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
38527 }
38528
38529 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
38530 - ch->port.count++;
38531 + atomic_inc(&ch->port.count);
38532 tty->driver_data = ch;
38533 tty_port_tty_set(&ch->port, tty);
38534 mutex_lock(&ch->port.mutex);
38535 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
38536 index 90dff82..08119c3 100644
38537 --- a/drivers/tty/n_gsm.c
38538 +++ b/drivers/tty/n_gsm.c
38539 @@ -1639,7 +1639,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
38540 kref_init(&dlci->ref);
38541 mutex_init(&dlci->mutex);
38542 dlci->fifo = &dlci->_fifo;
38543 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
38544 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
38545 kfree(dlci);
38546 return NULL;
38547 }
38548 @@ -2909,7 +2909,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
38549 if (dlci == NULL)
38550 return -ENOMEM;
38551 port = &dlci->port;
38552 - port->count++;
38553 + atomic_inc(&port->count);
38554 tty->driver_data = dlci;
38555 dlci_get(dlci);
38556 dlci_get(dlci->gsm->dlci[0]);
38557 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
38558 index 26f0d0e..b7c4273 100644
38559 --- a/drivers/tty/n_tty.c
38560 +++ b/drivers/tty/n_tty.c
38561 @@ -2124,6 +2124,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
38562 {
38563 *ops = tty_ldisc_N_TTY;
38564 ops->owner = NULL;
38565 - ops->refcount = ops->flags = 0;
38566 + atomic_set(&ops->refcount, 0);
38567 + ops->flags = 0;
38568 }
38569 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
38570 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
38571 index 5505ffc..7affff9 100644
38572 --- a/drivers/tty/pty.c
38573 +++ b/drivers/tty/pty.c
38574 @@ -718,8 +718,10 @@ static void __init unix98_pty_init(void)
38575 panic("Couldn't register Unix98 pts driver");
38576
38577 /* Now create the /dev/ptmx special device */
38578 + pax_open_kernel();
38579 tty_default_fops(&ptmx_fops);
38580 - ptmx_fops.open = ptmx_open;
38581 + *(void **)&ptmx_fops.open = ptmx_open;
38582 + pax_close_kernel();
38583
38584 cdev_init(&ptmx_cdev, &ptmx_fops);
38585 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
38586 diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
38587 index 777d5f9..56d67ca 100644
38588 --- a/drivers/tty/rocket.c
38589 +++ b/drivers/tty/rocket.c
38590 @@ -924,7 +924,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
38591 tty->driver_data = info;
38592 tty_port_tty_set(port, tty);
38593
38594 - if (port->count++ == 0) {
38595 + if (atomic_inc_return(&port->count) == 1) {
38596 atomic_inc(&rp_num_ports_open);
38597
38598 #ifdef ROCKET_DEBUG_OPEN
38599 @@ -933,7 +933,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
38600 #endif
38601 }
38602 #ifdef ROCKET_DEBUG_OPEN
38603 - printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
38604 + printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
38605 #endif
38606
38607 /*
38608 @@ -1528,7 +1528,7 @@ static void rp_hangup(struct tty_struct *tty)
38609 spin_unlock_irqrestore(&info->port.lock, flags);
38610 return;
38611 }
38612 - if (info->port.count)
38613 + if (atomic_read(&info->port.count))
38614 atomic_dec(&rp_num_ports_open);
38615 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
38616 spin_unlock_irqrestore(&info->port.lock, flags);
38617 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
38618 index 2b42a01..32a2ed3 100644
38619 --- a/drivers/tty/serial/kgdboc.c
38620 +++ b/drivers/tty/serial/kgdboc.c
38621 @@ -24,8 +24,9 @@
38622 #define MAX_CONFIG_LEN 40
38623
38624 static struct kgdb_io kgdboc_io_ops;
38625 +static struct kgdb_io kgdboc_io_ops_console;
38626
38627 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
38628 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
38629 static int configured = -1;
38630
38631 static char config[MAX_CONFIG_LEN];
38632 @@ -148,6 +149,8 @@ static void cleanup_kgdboc(void)
38633 kgdboc_unregister_kbd();
38634 if (configured == 1)
38635 kgdb_unregister_io_module(&kgdboc_io_ops);
38636 + else if (configured == 2)
38637 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
38638 }
38639
38640 static int configure_kgdboc(void)
38641 @@ -157,13 +160,13 @@ static int configure_kgdboc(void)
38642 int err;
38643 char *cptr = config;
38644 struct console *cons;
38645 + int is_console = 0;
38646
38647 err = kgdboc_option_setup(config);
38648 if (err || !strlen(config) || isspace(config[0]))
38649 goto noconfig;
38650
38651 err = -ENODEV;
38652 - kgdboc_io_ops.is_console = 0;
38653 kgdb_tty_driver = NULL;
38654
38655 kgdboc_use_kms = 0;
38656 @@ -184,7 +187,7 @@ static int configure_kgdboc(void)
38657 int idx;
38658 if (cons->device && cons->device(cons, &idx) == p &&
38659 idx == tty_line) {
38660 - kgdboc_io_ops.is_console = 1;
38661 + is_console = 1;
38662 break;
38663 }
38664 cons = cons->next;
38665 @@ -194,12 +197,16 @@ static int configure_kgdboc(void)
38666 kgdb_tty_line = tty_line;
38667
38668 do_register:
38669 - err = kgdb_register_io_module(&kgdboc_io_ops);
38670 + if (is_console) {
38671 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
38672 + configured = 2;
38673 + } else {
38674 + err = kgdb_register_io_module(&kgdboc_io_ops);
38675 + configured = 1;
38676 + }
38677 if (err)
38678 goto noconfig;
38679
38680 - configured = 1;
38681 -
38682 return 0;
38683
38684 noconfig:
38685 @@ -213,7 +220,7 @@ noconfig:
38686 static int __init init_kgdboc(void)
38687 {
38688 /* Already configured? */
38689 - if (configured == 1)
38690 + if (configured >= 1)
38691 return 0;
38692
38693 return configure_kgdboc();
38694 @@ -262,7 +269,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
38695 if (config[len - 1] == '\n')
38696 config[len - 1] = '\0';
38697
38698 - if (configured == 1)
38699 + if (configured >= 1)
38700 cleanup_kgdboc();
38701
38702 /* Go and configure with the new params. */
38703 @@ -302,6 +309,15 @@ static struct kgdb_io kgdboc_io_ops = {
38704 .post_exception = kgdboc_post_exp_handler,
38705 };
38706
38707 +static struct kgdb_io kgdboc_io_ops_console = {
38708 + .name = "kgdboc",
38709 + .read_char = kgdboc_get_char,
38710 + .write_char = kgdboc_put_char,
38711 + .pre_exception = kgdboc_pre_exp_handler,
38712 + .post_exception = kgdboc_post_exp_handler,
38713 + .is_console = 1
38714 +};
38715 +
38716 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
38717 /* This is only available if kgdboc is a built in for early debugging */
38718 static int __init kgdboc_early_init(char *opt)
38719 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
38720 index a21dc8e..fe43e9e 100644
38721 --- a/drivers/tty/serial/serial_core.c
38722 +++ b/drivers/tty/serial/serial_core.c
38723 @@ -1392,7 +1392,7 @@ static void uart_hangup(struct tty_struct *tty)
38724 uart_flush_buffer(tty);
38725 uart_shutdown(tty, state);
38726 spin_lock_irqsave(&port->lock, flags);
38727 - port->count = 0;
38728 + atomic_set(&port->count, 0);
38729 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
38730 spin_unlock_irqrestore(&port->lock, flags);
38731 tty_port_tty_set(port, NULL);
38732 @@ -1488,7 +1488,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38733 goto end;
38734 }
38735
38736 - port->count++;
38737 + atomic_inc(&port->count);
38738 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
38739 retval = -ENXIO;
38740 goto err_dec_count;
38741 @@ -1515,7 +1515,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38742 /*
38743 * Make sure the device is in D0 state.
38744 */
38745 - if (port->count == 1)
38746 + if (atomic_read(&port->count) == 1)
38747 uart_change_pm(state, 0);
38748
38749 /*
38750 @@ -1533,7 +1533,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38751 end:
38752 return retval;
38753 err_dec_count:
38754 - port->count--;
38755 + atomic_inc(&port->count);
38756 mutex_unlock(&port->mutex);
38757 goto end;
38758 }
38759 diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
38760 index 593d40a..bdc61f3 100644
38761 --- a/drivers/tty/synclink.c
38762 +++ b/drivers/tty/synclink.c
38763 @@ -3095,7 +3095,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
38764
38765 if (debug_level >= DEBUG_LEVEL_INFO)
38766 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
38767 - __FILE__,__LINE__, info->device_name, info->port.count);
38768 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
38769
38770 if (tty_port_close_start(&info->port, tty, filp) == 0)
38771 goto cleanup;
38772 @@ -3113,7 +3113,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
38773 cleanup:
38774 if (debug_level >= DEBUG_LEVEL_INFO)
38775 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
38776 - tty->driver->name, info->port.count);
38777 + tty->driver->name, atomic_read(&info->port.count));
38778
38779 } /* end of mgsl_close() */
38780
38781 @@ -3212,8 +3212,8 @@ static void mgsl_hangup(struct tty_struct *tty)
38782
38783 mgsl_flush_buffer(tty);
38784 shutdown(info);
38785 -
38786 - info->port.count = 0;
38787 +
38788 + atomic_set(&info->port.count, 0);
38789 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38790 info->port.tty = NULL;
38791
38792 @@ -3302,12 +3302,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38793
38794 if (debug_level >= DEBUG_LEVEL_INFO)
38795 printk("%s(%d):block_til_ready before block on %s count=%d\n",
38796 - __FILE__,__LINE__, tty->driver->name, port->count );
38797 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38798
38799 spin_lock_irqsave(&info->irq_spinlock, flags);
38800 if (!tty_hung_up_p(filp)) {
38801 extra_count = true;
38802 - port->count--;
38803 + atomic_dec(&port->count);
38804 }
38805 spin_unlock_irqrestore(&info->irq_spinlock, flags);
38806 port->blocked_open++;
38807 @@ -3336,7 +3336,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38808
38809 if (debug_level >= DEBUG_LEVEL_INFO)
38810 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
38811 - __FILE__,__LINE__, tty->driver->name, port->count );
38812 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38813
38814 tty_unlock();
38815 schedule();
38816 @@ -3348,12 +3348,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38817
38818 /* FIXME: Racy on hangup during close wait */
38819 if (extra_count)
38820 - port->count++;
38821 + atomic_inc(&port->count);
38822 port->blocked_open--;
38823
38824 if (debug_level >= DEBUG_LEVEL_INFO)
38825 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
38826 - __FILE__,__LINE__, tty->driver->name, port->count );
38827 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38828
38829 if (!retval)
38830 port->flags |= ASYNC_NORMAL_ACTIVE;
38831 @@ -3398,7 +3398,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
38832
38833 if (debug_level >= DEBUG_LEVEL_INFO)
38834 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
38835 - __FILE__,__LINE__,tty->driver->name, info->port.count);
38836 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
38837
38838 /* If port is closing, signal caller to try again */
38839 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38840 @@ -3417,10 +3417,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
38841 spin_unlock_irqrestore(&info->netlock, flags);
38842 goto cleanup;
38843 }
38844 - info->port.count++;
38845 + atomic_inc(&info->port.count);
38846 spin_unlock_irqrestore(&info->netlock, flags);
38847
38848 - if (info->port.count == 1) {
38849 + if (atomic_read(&info->port.count) == 1) {
38850 /* 1st open on this device, init hardware */
38851 retval = startup(info);
38852 if (retval < 0)
38853 @@ -3444,8 +3444,8 @@ cleanup:
38854 if (retval) {
38855 if (tty->count == 1)
38856 info->port.tty = NULL; /* tty layer will release tty struct */
38857 - if(info->port.count)
38858 - info->port.count--;
38859 + if (atomic_read(&info->port.count))
38860 + atomic_dec(&info->port.count);
38861 }
38862
38863 return retval;
38864 @@ -7653,7 +7653,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38865 unsigned short new_crctype;
38866
38867 /* return error if TTY interface open */
38868 - if (info->port.count)
38869 + if (atomic_read(&info->port.count))
38870 return -EBUSY;
38871
38872 switch (encoding)
38873 @@ -7748,7 +7748,7 @@ static int hdlcdev_open(struct net_device *dev)
38874
38875 /* arbitrate between network and tty opens */
38876 spin_lock_irqsave(&info->netlock, flags);
38877 - if (info->port.count != 0 || info->netcount != 0) {
38878 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38879 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38880 spin_unlock_irqrestore(&info->netlock, flags);
38881 return -EBUSY;
38882 @@ -7834,7 +7834,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38883 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
38884
38885 /* return error if TTY interface open */
38886 - if (info->port.count)
38887 + if (atomic_read(&info->port.count))
38888 return -EBUSY;
38889
38890 if (cmd != SIOCWANDEV)
38891 diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
38892 index aa1debf..9297a16 100644
38893 --- a/drivers/tty/synclink_gt.c
38894 +++ b/drivers/tty/synclink_gt.c
38895 @@ -671,7 +671,7 @@ static int open(struct tty_struct *tty, struct file *filp)
38896 tty->driver_data = info;
38897 info->port.tty = tty;
38898
38899 - DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
38900 + DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
38901
38902 /* If port is closing, signal caller to try again */
38903 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38904 @@ -692,10 +692,10 @@ static int open(struct tty_struct *tty, struct file *filp)
38905 mutex_unlock(&info->port.mutex);
38906 goto cleanup;
38907 }
38908 - info->port.count++;
38909 + atomic_inc(&info->port.count);
38910 spin_unlock_irqrestore(&info->netlock, flags);
38911
38912 - if (info->port.count == 1) {
38913 + if (atomic_read(&info->port.count) == 1) {
38914 /* 1st open on this device, init hardware */
38915 retval = startup(info);
38916 if (retval < 0) {
38917 @@ -716,8 +716,8 @@ cleanup:
38918 if (retval) {
38919 if (tty->count == 1)
38920 info->port.tty = NULL; /* tty layer will release tty struct */
38921 - if(info->port.count)
38922 - info->port.count--;
38923 + if(atomic_read(&info->port.count))
38924 + atomic_dec(&info->port.count);
38925 }
38926
38927 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
38928 @@ -730,7 +730,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38929
38930 if (sanity_check(info, tty->name, "close"))
38931 return;
38932 - DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
38933 + DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
38934
38935 if (tty_port_close_start(&info->port, tty, filp) == 0)
38936 goto cleanup;
38937 @@ -747,7 +747,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38938 tty_port_close_end(&info->port, tty);
38939 info->port.tty = NULL;
38940 cleanup:
38941 - DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
38942 + DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
38943 }
38944
38945 static void hangup(struct tty_struct *tty)
38946 @@ -765,7 +765,7 @@ static void hangup(struct tty_struct *tty)
38947 shutdown(info);
38948
38949 spin_lock_irqsave(&info->port.lock, flags);
38950 - info->port.count = 0;
38951 + atomic_set(&info->port.count, 0);
38952 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38953 info->port.tty = NULL;
38954 spin_unlock_irqrestore(&info->port.lock, flags);
38955 @@ -1450,7 +1450,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38956 unsigned short new_crctype;
38957
38958 /* return error if TTY interface open */
38959 - if (info->port.count)
38960 + if (atomic_read(&info->port.count))
38961 return -EBUSY;
38962
38963 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
38964 @@ -1545,7 +1545,7 @@ static int hdlcdev_open(struct net_device *dev)
38965
38966 /* arbitrate between network and tty opens */
38967 spin_lock_irqsave(&info->netlock, flags);
38968 - if (info->port.count != 0 || info->netcount != 0) {
38969 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38970 DBGINFO(("%s hdlc_open busy\n", dev->name));
38971 spin_unlock_irqrestore(&info->netlock, flags);
38972 return -EBUSY;
38973 @@ -1630,7 +1630,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38974 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
38975
38976 /* return error if TTY interface open */
38977 - if (info->port.count)
38978 + if (atomic_read(&info->port.count))
38979 return -EBUSY;
38980
38981 if (cmd != SIOCWANDEV)
38982 @@ -2419,7 +2419,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
38983 if (port == NULL)
38984 continue;
38985 spin_lock(&port->lock);
38986 - if ((port->port.count || port->netcount) &&
38987 + if ((atomic_read(&port->port.count) || port->netcount) &&
38988 port->pending_bh && !port->bh_running &&
38989 !port->bh_requested) {
38990 DBGISR(("%s bh queued\n", port->device_name));
38991 @@ -3308,7 +3308,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38992 spin_lock_irqsave(&info->lock, flags);
38993 if (!tty_hung_up_p(filp)) {
38994 extra_count = true;
38995 - port->count--;
38996 + atomic_dec(&port->count);
38997 }
38998 spin_unlock_irqrestore(&info->lock, flags);
38999 port->blocked_open++;
39000 @@ -3345,7 +3345,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
39001 remove_wait_queue(&port->open_wait, &wait);
39002
39003 if (extra_count)
39004 - port->count++;
39005 + atomic_inc(&port->count);
39006 port->blocked_open--;
39007
39008 if (!retval)
39009 diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
39010 index a3dddc1..8905ab2 100644
39011 --- a/drivers/tty/synclinkmp.c
39012 +++ b/drivers/tty/synclinkmp.c
39013 @@ -742,7 +742,7 @@ static int open(struct tty_struct *tty, struct file *filp)
39014
39015 if (debug_level >= DEBUG_LEVEL_INFO)
39016 printk("%s(%d):%s open(), old ref count = %d\n",
39017 - __FILE__,__LINE__,tty->driver->name, info->port.count);
39018 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
39019
39020 /* If port is closing, signal caller to try again */
39021 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
39022 @@ -761,10 +761,10 @@ static int open(struct tty_struct *tty, struct file *filp)
39023 spin_unlock_irqrestore(&info->netlock, flags);
39024 goto cleanup;
39025 }
39026 - info->port.count++;
39027 + atomic_inc(&info->port.count);
39028 spin_unlock_irqrestore(&info->netlock, flags);
39029
39030 - if (info->port.count == 1) {
39031 + if (atomic_read(&info->port.count) == 1) {
39032 /* 1st open on this device, init hardware */
39033 retval = startup(info);
39034 if (retval < 0)
39035 @@ -788,8 +788,8 @@ cleanup:
39036 if (retval) {
39037 if (tty->count == 1)
39038 info->port.tty = NULL; /* tty layer will release tty struct */
39039 - if(info->port.count)
39040 - info->port.count--;
39041 + if(atomic_read(&info->port.count))
39042 + atomic_dec(&info->port.count);
39043 }
39044
39045 return retval;
39046 @@ -807,7 +807,7 @@ static void close(struct tty_struct *tty, struct file *filp)
39047
39048 if (debug_level >= DEBUG_LEVEL_INFO)
39049 printk("%s(%d):%s close() entry, count=%d\n",
39050 - __FILE__,__LINE__, info->device_name, info->port.count);
39051 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
39052
39053 if (tty_port_close_start(&info->port, tty, filp) == 0)
39054 goto cleanup;
39055 @@ -826,7 +826,7 @@ static void close(struct tty_struct *tty, struct file *filp)
39056 cleanup:
39057 if (debug_level >= DEBUG_LEVEL_INFO)
39058 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
39059 - tty->driver->name, info->port.count);
39060 + tty->driver->name, atomic_read(&info->port.count));
39061 }
39062
39063 /* Called by tty_hangup() when a hangup is signaled.
39064 @@ -849,7 +849,7 @@ static void hangup(struct tty_struct *tty)
39065 shutdown(info);
39066
39067 spin_lock_irqsave(&info->port.lock, flags);
39068 - info->port.count = 0;
39069 + atomic_set(&info->port.count, 0);
39070 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
39071 info->port.tty = NULL;
39072 spin_unlock_irqrestore(&info->port.lock, flags);
39073 @@ -1557,7 +1557,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
39074 unsigned short new_crctype;
39075
39076 /* return error if TTY interface open */
39077 - if (info->port.count)
39078 + if (atomic_read(&info->port.count))
39079 return -EBUSY;
39080
39081 switch (encoding)
39082 @@ -1652,7 +1652,7 @@ static int hdlcdev_open(struct net_device *dev)
39083
39084 /* arbitrate between network and tty opens */
39085 spin_lock_irqsave(&info->netlock, flags);
39086 - if (info->port.count != 0 || info->netcount != 0) {
39087 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
39088 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
39089 spin_unlock_irqrestore(&info->netlock, flags);
39090 return -EBUSY;
39091 @@ -1738,7 +1738,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
39092 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
39093
39094 /* return error if TTY interface open */
39095 - if (info->port.count)
39096 + if (atomic_read(&info->port.count))
39097 return -EBUSY;
39098
39099 if (cmd != SIOCWANDEV)
39100 @@ -2623,7 +2623,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
39101 * do not request bottom half processing if the
39102 * device is not open in a normal mode.
39103 */
39104 - if ( port && (port->port.count || port->netcount) &&
39105 + if ( port && (atomic_read(&port->port.count) || port->netcount) &&
39106 port->pending_bh && !port->bh_running &&
39107 !port->bh_requested ) {
39108 if ( debug_level >= DEBUG_LEVEL_ISR )
39109 @@ -3321,12 +3321,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
39110
39111 if (debug_level >= DEBUG_LEVEL_INFO)
39112 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
39113 - __FILE__,__LINE__, tty->driver->name, port->count );
39114 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
39115
39116 spin_lock_irqsave(&info->lock, flags);
39117 if (!tty_hung_up_p(filp)) {
39118 extra_count = true;
39119 - port->count--;
39120 + atomic_dec(&port->count);
39121 }
39122 spin_unlock_irqrestore(&info->lock, flags);
39123 port->blocked_open++;
39124 @@ -3355,7 +3355,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
39125
39126 if (debug_level >= DEBUG_LEVEL_INFO)
39127 printk("%s(%d):%s block_til_ready() count=%d\n",
39128 - __FILE__,__LINE__, tty->driver->name, port->count );
39129 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
39130
39131 tty_unlock();
39132 schedule();
39133 @@ -3366,12 +3366,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
39134 remove_wait_queue(&port->open_wait, &wait);
39135
39136 if (extra_count)
39137 - port->count++;
39138 + atomic_inc(&port->count);
39139 port->blocked_open--;
39140
39141 if (debug_level >= DEBUG_LEVEL_INFO)
39142 printk("%s(%d):%s block_til_ready() after, count=%d\n",
39143 - __FILE__,__LINE__, tty->driver->name, port->count );
39144 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
39145
39146 if (!retval)
39147 port->flags |= ASYNC_NORMAL_ACTIVE;
39148 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
39149 index 05728894..b9d44c6 100644
39150 --- a/drivers/tty/sysrq.c
39151 +++ b/drivers/tty/sysrq.c
39152 @@ -865,7 +865,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
39153 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
39154 size_t count, loff_t *ppos)
39155 {
39156 - if (count) {
39157 + if (count && capable(CAP_SYS_ADMIN)) {
39158 char c;
39159
39160 if (get_user(c, buf))
39161 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
39162 index b425c79..08a3f06 100644
39163 --- a/drivers/tty/tty_io.c
39164 +++ b/drivers/tty/tty_io.c
39165 @@ -3283,7 +3283,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
39166
39167 void tty_default_fops(struct file_operations *fops)
39168 {
39169 - *fops = tty_fops;
39170 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
39171 }
39172
39173 /*
39174 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
39175 index 6f99c99..8947bc4 100644
39176 --- a/drivers/tty/tty_ldisc.c
39177 +++ b/drivers/tty/tty_ldisc.c
39178 @@ -56,7 +56,7 @@ static void put_ldisc(struct tty_ldisc *ld)
39179 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
39180 struct tty_ldisc_ops *ldo = ld->ops;
39181
39182 - ldo->refcount--;
39183 + atomic_dec(&ldo->refcount);
39184 module_put(ldo->owner);
39185 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
39186
39187 @@ -91,7 +91,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
39188 spin_lock_irqsave(&tty_ldisc_lock, flags);
39189 tty_ldiscs[disc] = new_ldisc;
39190 new_ldisc->num = disc;
39191 - new_ldisc->refcount = 0;
39192 + atomic_set(&new_ldisc->refcount, 0);
39193 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
39194
39195 return ret;
39196 @@ -119,7 +119,7 @@ int tty_unregister_ldisc(int disc)
39197 return -EINVAL;
39198
39199 spin_lock_irqsave(&tty_ldisc_lock, flags);
39200 - if (tty_ldiscs[disc]->refcount)
39201 + if (atomic_read(&tty_ldiscs[disc]->refcount))
39202 ret = -EBUSY;
39203 else
39204 tty_ldiscs[disc] = NULL;
39205 @@ -140,7 +140,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
39206 if (ldops) {
39207 ret = ERR_PTR(-EAGAIN);
39208 if (try_module_get(ldops->owner)) {
39209 - ldops->refcount++;
39210 + atomic_inc(&ldops->refcount);
39211 ret = ldops;
39212 }
39213 }
39214 @@ -153,7 +153,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
39215 unsigned long flags;
39216
39217 spin_lock_irqsave(&tty_ldisc_lock, flags);
39218 - ldops->refcount--;
39219 + atomic_dec(&ldops->refcount);
39220 module_put(ldops->owner);
39221 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
39222 }
39223 diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
39224 index bf6e238..d401c04 100644
39225 --- a/drivers/tty/tty_port.c
39226 +++ b/drivers/tty/tty_port.c
39227 @@ -138,7 +138,7 @@ void tty_port_hangup(struct tty_port *port)
39228 unsigned long flags;
39229
39230 spin_lock_irqsave(&port->lock, flags);
39231 - port->count = 0;
39232 + atomic_set(&port->count, 0);
39233 port->flags &= ~ASYNC_NORMAL_ACTIVE;
39234 if (port->tty) {
39235 set_bit(TTY_IO_ERROR, &port->tty->flags);
39236 @@ -264,7 +264,7 @@ int tty_port_block_til_ready(struct tty_port *port,
39237 /* The port lock protects the port counts */
39238 spin_lock_irqsave(&port->lock, flags);
39239 if (!tty_hung_up_p(filp))
39240 - port->count--;
39241 + atomic_dec(&port->count);
39242 port->blocked_open++;
39243 spin_unlock_irqrestore(&port->lock, flags);
39244
39245 @@ -306,7 +306,7 @@ int tty_port_block_til_ready(struct tty_port *port,
39246 we must not mess that up further */
39247 spin_lock_irqsave(&port->lock, flags);
39248 if (!tty_hung_up_p(filp))
39249 - port->count++;
39250 + atomic_inc(&port->count);
39251 port->blocked_open--;
39252 if (retval == 0)
39253 port->flags |= ASYNC_NORMAL_ACTIVE;
39254 @@ -326,19 +326,19 @@ int tty_port_close_start(struct tty_port *port,
39255 return 0;
39256 }
39257
39258 - if (tty->count == 1 && port->count != 1) {
39259 + if (tty->count == 1 && atomic_read(&port->count) != 1) {
39260 printk(KERN_WARNING
39261 "tty_port_close_start: tty->count = 1 port count = %d.\n",
39262 - port->count);
39263 - port->count = 1;
39264 + atomic_read(&port->count));
39265 + atomic_set(&port->count, 1);
39266 }
39267 - if (--port->count < 0) {
39268 + if (atomic_dec_return(&port->count) < 0) {
39269 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
39270 - port->count);
39271 - port->count = 0;
39272 + atomic_read(&port->count));
39273 + atomic_set(&port->count, 0);
39274 }
39275
39276 - if (port->count) {
39277 + if (atomic_read(&port->count)) {
39278 spin_unlock_irqrestore(&port->lock, flags);
39279 if (port->ops->drop)
39280 port->ops->drop(port);
39281 @@ -418,7 +418,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
39282 {
39283 spin_lock_irq(&port->lock);
39284 if (!tty_hung_up_p(filp))
39285 - ++port->count;
39286 + atomic_inc(&port->count);
39287 spin_unlock_irq(&port->lock);
39288 tty_port_tty_set(port, tty);
39289
39290 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
39291 index 770a854..e5d3db3 100644
39292 --- a/drivers/tty/vt/keyboard.c
39293 +++ b/drivers/tty/vt/keyboard.c
39294 @@ -659,6 +659,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
39295 kbd->kbdmode == VC_OFF) &&
39296 value != KVAL(K_SAK))
39297 return; /* SAK is allowed even in raw mode */
39298 +
39299 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
39300 + {
39301 + void *func = fn_handler[value];
39302 + if (func == fn_show_state || func == fn_show_ptregs ||
39303 + func == fn_show_mem)
39304 + return;
39305 + }
39306 +#endif
39307 +
39308 fn_handler[value](vc);
39309 }
39310
39311 @@ -1805,9 +1815,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
39312 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
39313 return -EFAULT;
39314
39315 - if (!capable(CAP_SYS_TTY_CONFIG))
39316 - perm = 0;
39317 -
39318 switch (cmd) {
39319 case KDGKBENT:
39320 /* Ensure another thread doesn't free it under us */
39321 @@ -1822,6 +1829,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
39322 spin_unlock_irqrestore(&kbd_event_lock, flags);
39323 return put_user(val, &user_kbe->kb_value);
39324 case KDSKBENT:
39325 + if (!capable(CAP_SYS_TTY_CONFIG))
39326 + perm = 0;
39327 +
39328 if (!perm)
39329 return -EPERM;
39330 if (!i && v == K_NOSUCHMAP) {
39331 @@ -1912,9 +1922,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
39332 int i, j, k;
39333 int ret;
39334
39335 - if (!capable(CAP_SYS_TTY_CONFIG))
39336 - perm = 0;
39337 -
39338 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
39339 if (!kbs) {
39340 ret = -ENOMEM;
39341 @@ -1948,6 +1955,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
39342 kfree(kbs);
39343 return ((p && *p) ? -EOVERFLOW : 0);
39344 case KDSKBSENT:
39345 + if (!capable(CAP_SYS_TTY_CONFIG))
39346 + perm = 0;
39347 +
39348 if (!perm) {
39349 ret = -EPERM;
39350 goto reterr;
39351 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
39352 index a783d53..cb30d94 100644
39353 --- a/drivers/uio/uio.c
39354 +++ b/drivers/uio/uio.c
39355 @@ -25,6 +25,7 @@
39356 #include <linux/kobject.h>
39357 #include <linux/cdev.h>
39358 #include <linux/uio_driver.h>
39359 +#include <asm/local.h>
39360
39361 #define UIO_MAX_DEVICES (1U << MINORBITS)
39362
39363 @@ -32,10 +33,10 @@ struct uio_device {
39364 struct module *owner;
39365 struct device *dev;
39366 int minor;
39367 - atomic_t event;
39368 + atomic_unchecked_t event;
39369 struct fasync_struct *async_queue;
39370 wait_queue_head_t wait;
39371 - int vma_count;
39372 + local_t vma_count;
39373 struct uio_info *info;
39374 struct kobject *map_dir;
39375 struct kobject *portio_dir;
39376 @@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
39377 struct device_attribute *attr, char *buf)
39378 {
39379 struct uio_device *idev = dev_get_drvdata(dev);
39380 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
39381 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
39382 }
39383
39384 static struct device_attribute uio_class_attributes[] = {
39385 @@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
39386 {
39387 struct uio_device *idev = info->uio_dev;
39388
39389 - atomic_inc(&idev->event);
39390 + atomic_inc_unchecked(&idev->event);
39391 wake_up_interruptible(&idev->wait);
39392 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
39393 }
39394 @@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
39395 }
39396
39397 listener->dev = idev;
39398 - listener->event_count = atomic_read(&idev->event);
39399 + listener->event_count = atomic_read_unchecked(&idev->event);
39400 filep->private_data = listener;
39401
39402 if (idev->info->open) {
39403 @@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
39404 return -EIO;
39405
39406 poll_wait(filep, &idev->wait, wait);
39407 - if (listener->event_count != atomic_read(&idev->event))
39408 + if (listener->event_count != atomic_read_unchecked(&idev->event))
39409 return POLLIN | POLLRDNORM;
39410 return 0;
39411 }
39412 @@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
39413 do {
39414 set_current_state(TASK_INTERRUPTIBLE);
39415
39416 - event_count = atomic_read(&idev->event);
39417 + event_count = atomic_read_unchecked(&idev->event);
39418 if (event_count != listener->event_count) {
39419 if (copy_to_user(buf, &event_count, count))
39420 retval = -EFAULT;
39421 @@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
39422 static void uio_vma_open(struct vm_area_struct *vma)
39423 {
39424 struct uio_device *idev = vma->vm_private_data;
39425 - idev->vma_count++;
39426 + local_inc(&idev->vma_count);
39427 }
39428
39429 static void uio_vma_close(struct vm_area_struct *vma)
39430 {
39431 struct uio_device *idev = vma->vm_private_data;
39432 - idev->vma_count--;
39433 + local_dec(&idev->vma_count);
39434 }
39435
39436 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
39437 @@ -821,7 +822,7 @@ int __uio_register_device(struct module *owner,
39438 idev->owner = owner;
39439 idev->info = info;
39440 init_waitqueue_head(&idev->wait);
39441 - atomic_set(&idev->event, 0);
39442 + atomic_set_unchecked(&idev->event, 0);
39443
39444 ret = uio_get_minor(idev);
39445 if (ret)
39446 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
39447 index b7eb86a..36d28af 100644
39448 --- a/drivers/usb/atm/cxacru.c
39449 +++ b/drivers/usb/atm/cxacru.c
39450 @@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
39451 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
39452 if (ret < 2)
39453 return -EINVAL;
39454 - if (index < 0 || index > 0x7f)
39455 + if (index > 0x7f)
39456 return -EINVAL;
39457 pos += tmp;
39458
39459 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
39460 index ee62b35..b663594 100644
39461 --- a/drivers/usb/atm/usbatm.c
39462 +++ b/drivers/usb/atm/usbatm.c
39463 @@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39464 if (printk_ratelimit())
39465 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
39466 __func__, vpi, vci);
39467 - atomic_inc(&vcc->stats->rx_err);
39468 + atomic_inc_unchecked(&vcc->stats->rx_err);
39469 return;
39470 }
39471
39472 @@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39473 if (length > ATM_MAX_AAL5_PDU) {
39474 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
39475 __func__, length, vcc);
39476 - atomic_inc(&vcc->stats->rx_err);
39477 + atomic_inc_unchecked(&vcc->stats->rx_err);
39478 goto out;
39479 }
39480
39481 @@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39482 if (sarb->len < pdu_length) {
39483 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
39484 __func__, pdu_length, sarb->len, vcc);
39485 - atomic_inc(&vcc->stats->rx_err);
39486 + atomic_inc_unchecked(&vcc->stats->rx_err);
39487 goto out;
39488 }
39489
39490 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
39491 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
39492 __func__, vcc);
39493 - atomic_inc(&vcc->stats->rx_err);
39494 + atomic_inc_unchecked(&vcc->stats->rx_err);
39495 goto out;
39496 }
39497
39498 @@ -387,7 +387,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39499 if (printk_ratelimit())
39500 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
39501 __func__, length);
39502 - atomic_inc(&vcc->stats->rx_drop);
39503 + atomic_inc_unchecked(&vcc->stats->rx_drop);
39504 goto out;
39505 }
39506
39507 @@ -412,7 +412,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39508
39509 vcc->push(vcc, skb);
39510
39511 - atomic_inc(&vcc->stats->rx);
39512 + atomic_inc_unchecked(&vcc->stats->rx);
39513 out:
39514 skb_trim(sarb, 0);
39515 }
39516 @@ -615,7 +615,7 @@ static void usbatm_tx_process(unsigned long data)
39517 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
39518
39519 usbatm_pop(vcc, skb);
39520 - atomic_inc(&vcc->stats->tx);
39521 + atomic_inc_unchecked(&vcc->stats->tx);
39522
39523 skb = skb_dequeue(&instance->sndqueue);
39524 }
39525 @@ -770,11 +770,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
39526 if (!left--)
39527 return sprintf(page,
39528 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
39529 - atomic_read(&atm_dev->stats.aal5.tx),
39530 - atomic_read(&atm_dev->stats.aal5.tx_err),
39531 - atomic_read(&atm_dev->stats.aal5.rx),
39532 - atomic_read(&atm_dev->stats.aal5.rx_err),
39533 - atomic_read(&atm_dev->stats.aal5.rx_drop));
39534 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
39535 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
39536 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
39537 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
39538 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
39539
39540 if (!left--) {
39541 if (instance->disconnected)
39542 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
39543 index 3440812..2a4ef1f 100644
39544 --- a/drivers/usb/core/devices.c
39545 +++ b/drivers/usb/core/devices.c
39546 @@ -126,7 +126,7 @@ static const char format_endpt[] =
39547 * time it gets called.
39548 */
39549 static struct device_connect_event {
39550 - atomic_t count;
39551 + atomic_unchecked_t count;
39552 wait_queue_head_t wait;
39553 } device_event = {
39554 .count = ATOMIC_INIT(1),
39555 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
39556
39557 void usbfs_conn_disc_event(void)
39558 {
39559 - atomic_add(2, &device_event.count);
39560 + atomic_add_unchecked(2, &device_event.count);
39561 wake_up(&device_event.wait);
39562 }
39563
39564 @@ -648,7 +648,7 @@ static unsigned int usb_device_poll(struct file *file,
39565
39566 poll_wait(file, &device_event.wait, wait);
39567
39568 - event_count = atomic_read(&device_event.count);
39569 + event_count = atomic_read_unchecked(&device_event.count);
39570 if (file->f_version != event_count) {
39571 file->f_version = event_count;
39572 return POLLIN | POLLRDNORM;
39573 diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
39574 index 75ba209..08bf89e 100644
39575 --- a/drivers/usb/core/hcd.c
39576 +++ b/drivers/usb/core/hcd.c
39577 @@ -1478,7 +1478,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
39578 */
39579 usb_get_urb(urb);
39580 atomic_inc(&urb->use_count);
39581 - atomic_inc(&urb->dev->urbnum);
39582 + atomic_inc_unchecked(&urb->dev->urbnum);
39583 usbmon_urb_submit(&hcd->self, urb);
39584
39585 /* NOTE requirements on root-hub callers (usbfs and the hub
39586 @@ -1505,7 +1505,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
39587 urb->hcpriv = NULL;
39588 INIT_LIST_HEAD(&urb->urb_list);
39589 atomic_dec(&urb->use_count);
39590 - atomic_dec(&urb->dev->urbnum);
39591 + atomic_dec_unchecked(&urb->dev->urbnum);
39592 if (atomic_read(&urb->reject))
39593 wake_up(&usb_kill_urb_queue);
39594 usb_put_urb(urb);
39595 diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
39596 index 682e825..06d4f69 100644
39597 --- a/drivers/usb/core/sysfs.c
39598 +++ b/drivers/usb/core/sysfs.c
39599 @@ -226,7 +226,7 @@ show_urbnum(struct device *dev, struct device_attribute *attr, char *buf)
39600 struct usb_device *udev;
39601
39602 udev = to_usb_device(dev);
39603 - return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
39604 + return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
39605 }
39606 static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL);
39607
39608 diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
39609 index cd8fb44..17fbe0c 100644
39610 --- a/drivers/usb/core/usb.c
39611 +++ b/drivers/usb/core/usb.c
39612 @@ -397,7 +397,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
39613 set_dev_node(&dev->dev, dev_to_node(bus->controller));
39614 dev->state = USB_STATE_ATTACHED;
39615 dev->lpm_disable_count = 1;
39616 - atomic_set(&dev->urbnum, 0);
39617 + atomic_set_unchecked(&dev->urbnum, 0);
39618
39619 INIT_LIST_HEAD(&dev->ep0.urb_list);
39620 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
39621 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
39622 index 89dcf15..481800b 100644
39623 --- a/drivers/usb/early/ehci-dbgp.c
39624 +++ b/drivers/usb/early/ehci-dbgp.c
39625 @@ -97,7 +97,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
39626
39627 #ifdef CONFIG_KGDB
39628 static struct kgdb_io kgdbdbgp_io_ops;
39629 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
39630 +static struct kgdb_io kgdbdbgp_io_ops_console;
39631 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
39632 #else
39633 #define dbgp_kgdb_mode (0)
39634 #endif
39635 @@ -1035,6 +1036,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
39636 .write_char = kgdbdbgp_write_char,
39637 };
39638
39639 +static struct kgdb_io kgdbdbgp_io_ops_console = {
39640 + .name = "kgdbdbgp",
39641 + .read_char = kgdbdbgp_read_char,
39642 + .write_char = kgdbdbgp_write_char,
39643 + .is_console = 1
39644 +};
39645 +
39646 static int kgdbdbgp_wait_time;
39647
39648 static int __init kgdbdbgp_parse_config(char *str)
39649 @@ -1050,8 +1058,10 @@ static int __init kgdbdbgp_parse_config(char *str)
39650 ptr++;
39651 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
39652 }
39653 - kgdb_register_io_module(&kgdbdbgp_io_ops);
39654 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
39655 + if (early_dbgp_console.index != -1)
39656 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
39657 + else
39658 + kgdb_register_io_module(&kgdbdbgp_io_ops);
39659
39660 return 0;
39661 }
39662 diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
39663 index da6d479..80ed10b 100644
39664 --- a/drivers/usb/gadget/u_serial.c
39665 +++ b/drivers/usb/gadget/u_serial.c
39666 @@ -735,9 +735,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
39667 spin_lock_irq(&port->port_lock);
39668
39669 /* already open? Great. */
39670 - if (port->port.count) {
39671 + if (atomic_read(&port->port.count)) {
39672 status = 0;
39673 - port->port.count++;
39674 + atomic_inc(&port->port.count);
39675
39676 /* currently opening/closing? wait ... */
39677 } else if (port->openclose) {
39678 @@ -796,7 +796,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
39679 tty->driver_data = port;
39680 port->port.tty = tty;
39681
39682 - port->port.count = 1;
39683 + atomic_set(&port->port.count, 1);
39684 port->openclose = false;
39685
39686 /* if connected, start the I/O stream */
39687 @@ -838,11 +838,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
39688
39689 spin_lock_irq(&port->port_lock);
39690
39691 - if (port->port.count != 1) {
39692 - if (port->port.count == 0)
39693 + if (atomic_read(&port->port.count) != 1) {
39694 + if (atomic_read(&port->port.count) == 0)
39695 WARN_ON(1);
39696 else
39697 - --port->port.count;
39698 + atomic_dec(&port->port.count);
39699 goto exit;
39700 }
39701
39702 @@ -852,7 +852,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
39703 * and sleep if necessary
39704 */
39705 port->openclose = true;
39706 - port->port.count = 0;
39707 + atomic_set(&port->port.count, 0);
39708
39709 gser = port->port_usb;
39710 if (gser && gser->disconnect)
39711 @@ -1156,7 +1156,7 @@ static int gs_closed(struct gs_port *port)
39712 int cond;
39713
39714 spin_lock_irq(&port->port_lock);
39715 - cond = (port->port.count == 0) && !port->openclose;
39716 + cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
39717 spin_unlock_irq(&port->port_lock);
39718 return cond;
39719 }
39720 @@ -1269,7 +1269,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
39721 /* if it's already open, start I/O ... and notify the serial
39722 * protocol about open/close status (connect/disconnect).
39723 */
39724 - if (port->port.count) {
39725 + if (atomic_read(&port->port.count)) {
39726 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
39727 gs_start_io(port);
39728 if (gser->connect)
39729 @@ -1316,7 +1316,7 @@ void gserial_disconnect(struct gserial *gser)
39730
39731 port->port_usb = NULL;
39732 gser->ioport = NULL;
39733 - if (port->port.count > 0 || port->openclose) {
39734 + if (atomic_read(&port->port.count) > 0 || port->openclose) {
39735 wake_up_interruptible(&port->drain_wait);
39736 if (port->port.tty)
39737 tty_hangup(port->port.tty);
39738 @@ -1332,7 +1332,7 @@ void gserial_disconnect(struct gserial *gser)
39739
39740 /* finally, free any unused/unusable I/O buffers */
39741 spin_lock_irqsave(&port->port_lock, flags);
39742 - if (port->port.count == 0 && !port->openclose)
39743 + if (atomic_read(&port->port.count) == 0 && !port->openclose)
39744 gs_buf_free(&port->port_write_buf);
39745 gs_free_requests(gser->out, &port->read_pool, NULL);
39746 gs_free_requests(gser->out, &port->read_queue, NULL);
39747 diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
39748 index b9cca6d..75c75df 100644
39749 --- a/drivers/usb/serial/console.c
39750 +++ b/drivers/usb/serial/console.c
39751 @@ -127,7 +127,7 @@ static int usb_console_setup(struct console *co, char *options)
39752
39753 info->port = port;
39754
39755 - ++port->port.count;
39756 + atomic_inc(&port->port.count);
39757 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
39758 if (serial->type->set_termios) {
39759 /*
39760 @@ -177,7 +177,7 @@ static int usb_console_setup(struct console *co, char *options)
39761 }
39762 /* Now that any required fake tty operations are completed restore
39763 * the tty port count */
39764 - --port->port.count;
39765 + atomic_dec(&port->port.count);
39766 /* The console is special in terms of closing the device so
39767 * indicate this port is now acting as a system console. */
39768 port->port.console = 1;
39769 @@ -190,7 +190,7 @@ static int usb_console_setup(struct console *co, char *options)
39770 free_tty:
39771 kfree(tty);
39772 reset_open_count:
39773 - port->port.count = 0;
39774 + atomic_set(&port->port.count, 0);
39775 usb_autopm_put_interface(serial->interface);
39776 error_get_interface:
39777 usb_serial_put(serial);
39778 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
39779 index d6bea3e..60b250e 100644
39780 --- a/drivers/usb/wusbcore/wa-hc.h
39781 +++ b/drivers/usb/wusbcore/wa-hc.h
39782 @@ -192,7 +192,7 @@ struct wahc {
39783 struct list_head xfer_delayed_list;
39784 spinlock_t xfer_list_lock;
39785 struct work_struct xfer_work;
39786 - atomic_t xfer_id_count;
39787 + atomic_unchecked_t xfer_id_count;
39788 };
39789
39790
39791 @@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
39792 INIT_LIST_HEAD(&wa->xfer_delayed_list);
39793 spin_lock_init(&wa->xfer_list_lock);
39794 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
39795 - atomic_set(&wa->xfer_id_count, 1);
39796 + atomic_set_unchecked(&wa->xfer_id_count, 1);
39797 }
39798
39799 /**
39800 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
39801 index 57c01ab..8a05959 100644
39802 --- a/drivers/usb/wusbcore/wa-xfer.c
39803 +++ b/drivers/usb/wusbcore/wa-xfer.c
39804 @@ -296,7 +296,7 @@ out:
39805 */
39806 static void wa_xfer_id_init(struct wa_xfer *xfer)
39807 {
39808 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
39809 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
39810 }
39811
39812 /*
39813 diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
39814 index ef82a0d..78a026b 100644
39815 --- a/drivers/vhost/vhost.c
39816 +++ b/drivers/vhost/vhost.c
39817 @@ -634,7 +634,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
39818 return 0;
39819 }
39820
39821 -static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
39822 +static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
39823 {
39824 struct file *eventfp, *filep = NULL,
39825 *pollstart = NULL, *pollstop = NULL;
39826 @@ -1076,7 +1076,7 @@ static int translate_desc(struct vhost_dev *dev, u64 addr, u32 len,
39827 }
39828 _iov = iov + ret;
39829 size = reg->memory_size - addr + reg->guest_phys_addr;
39830 - _iov->iov_len = min((u64)len, size);
39831 + _iov->iov_len = min((u64)len - s, size);
39832 _iov->iov_base = (void __user *)(unsigned long)
39833 (reg->userspace_addr + addr - reg->guest_phys_addr);
39834 s += size;
39835 diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
39836 index 747442d..7c0c434 100644
39837 --- a/drivers/video/aty/aty128fb.c
39838 +++ b/drivers/video/aty/aty128fb.c
39839 @@ -149,7 +149,7 @@ enum {
39840 };
39841
39842 /* Must match above enum */
39843 -static const char *r128_family[] __devinitdata = {
39844 +static const char *r128_family[] __devinitconst = {
39845 "AGP",
39846 "PCI",
39847 "PRO AGP",
39848 diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
39849 index 5c3960d..15cf8fc 100644
39850 --- a/drivers/video/fbcmap.c
39851 +++ b/drivers/video/fbcmap.c
39852 @@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
39853 rc = -ENODEV;
39854 goto out;
39855 }
39856 - if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
39857 - !info->fbops->fb_setcmap)) {
39858 + if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
39859 rc = -EINVAL;
39860 goto out1;
39861 }
39862 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
39863 index 0dff12a..2ef47b3 100644
39864 --- a/drivers/video/fbmem.c
39865 +++ b/drivers/video/fbmem.c
39866 @@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
39867 image->dx += image->width + 8;
39868 }
39869 } else if (rotate == FB_ROTATE_UD) {
39870 - for (x = 0; x < num && image->dx >= 0; x++) {
39871 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
39872 info->fbops->fb_imageblit(info, image);
39873 image->dx -= image->width + 8;
39874 }
39875 @@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
39876 image->dy += image->height + 8;
39877 }
39878 } else if (rotate == FB_ROTATE_CCW) {
39879 - for (x = 0; x < num && image->dy >= 0; x++) {
39880 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
39881 info->fbops->fb_imageblit(info, image);
39882 image->dy -= image->height + 8;
39883 }
39884 @@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
39885 return -EFAULT;
39886 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
39887 return -EINVAL;
39888 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
39889 + if (con2fb.framebuffer >= FB_MAX)
39890 return -EINVAL;
39891 if (!registered_fb[con2fb.framebuffer])
39892 request_module("fb%d", con2fb.framebuffer);
39893 diff --git a/drivers/video/geode/gx1fb_core.c b/drivers/video/geode/gx1fb_core.c
39894 index 5a5d092..265c5ed 100644
39895 --- a/drivers/video/geode/gx1fb_core.c
39896 +++ b/drivers/video/geode/gx1fb_core.c
39897 @@ -29,7 +29,7 @@ static int crt_option = 1;
39898 static char panel_option[32] = "";
39899
39900 /* Modes relevant to the GX1 (taken from modedb.c) */
39901 -static const struct fb_videomode __devinitdata gx1_modedb[] = {
39902 +static const struct fb_videomode __devinitconst gx1_modedb[] = {
39903 /* 640x480-60 VESA */
39904 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
39905 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
39906 diff --git a/drivers/video/gxt4500.c b/drivers/video/gxt4500.c
39907 index 0fad23f..0e9afa4 100644
39908 --- a/drivers/video/gxt4500.c
39909 +++ b/drivers/video/gxt4500.c
39910 @@ -156,7 +156,7 @@ struct gxt4500_par {
39911 static char *mode_option;
39912
39913 /* default mode: 1280x1024 @ 60 Hz, 8 bpp */
39914 -static const struct fb_videomode defaultmode __devinitdata = {
39915 +static const struct fb_videomode defaultmode __devinitconst = {
39916 .refresh = 60,
39917 .xres = 1280,
39918 .yres = 1024,
39919 @@ -581,7 +581,7 @@ static int gxt4500_blank(int blank, struct fb_info *info)
39920 return 0;
39921 }
39922
39923 -static const struct fb_fix_screeninfo gxt4500_fix __devinitdata = {
39924 +static const struct fb_fix_screeninfo gxt4500_fix __devinitconst = {
39925 .id = "IBM GXT4500P",
39926 .type = FB_TYPE_PACKED_PIXELS,
39927 .visual = FB_VISUAL_PSEUDOCOLOR,
39928 diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
39929 index 7672d2e..b56437f 100644
39930 --- a/drivers/video/i810/i810_accel.c
39931 +++ b/drivers/video/i810/i810_accel.c
39932 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
39933 }
39934 }
39935 printk("ringbuffer lockup!!!\n");
39936 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
39937 i810_report_error(mmio);
39938 par->dev_flags |= LOCKUP;
39939 info->pixmap.scan_align = 1;
39940 diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
39941 index b83f361..2b05a91 100644
39942 --- a/drivers/video/i810/i810_main.c
39943 +++ b/drivers/video/i810/i810_main.c
39944 @@ -97,7 +97,7 @@ static int i810fb_blank (int blank_mode, struct fb_info *info);
39945 static void i810fb_release_resource (struct fb_info *info, struct i810fb_par *par);
39946
39947 /* PCI */
39948 -static const char *i810_pci_list[] __devinitdata = {
39949 +static const char *i810_pci_list[] __devinitconst = {
39950 "Intel(R) 810 Framebuffer Device" ,
39951 "Intel(R) 810-DC100 Framebuffer Device" ,
39952 "Intel(R) 810E Framebuffer Device" ,
39953 diff --git a/drivers/video/jz4740_fb.c b/drivers/video/jz4740_fb.c
39954 index de36693..3c63fc2 100644
39955 --- a/drivers/video/jz4740_fb.c
39956 +++ b/drivers/video/jz4740_fb.c
39957 @@ -136,7 +136,7 @@ struct jzfb {
39958 uint32_t pseudo_palette[16];
39959 };
39960
39961 -static const struct fb_fix_screeninfo jzfb_fix __devinitdata = {
39962 +static const struct fb_fix_screeninfo jzfb_fix __devinitconst = {
39963 .id = "JZ4740 FB",
39964 .type = FB_TYPE_PACKED_PIXELS,
39965 .visual = FB_VISUAL_TRUECOLOR,
39966 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
39967 index 3c14e43..eafa544 100644
39968 --- a/drivers/video/logo/logo_linux_clut224.ppm
39969 +++ b/drivers/video/logo/logo_linux_clut224.ppm
39970 @@ -1,1604 +1,1123 @@
39971 P3
39972 -# Standard 224-color Linux logo
39973 80 80
39974 255
39975 - 0 0 0 0 0 0 0 0 0 0 0 0
39976 - 0 0 0 0 0 0 0 0 0 0 0 0
39977 - 0 0 0 0 0 0 0 0 0 0 0 0
39978 - 0 0 0 0 0 0 0 0 0 0 0 0
39979 - 0 0 0 0 0 0 0 0 0 0 0 0
39980 - 0 0 0 0 0 0 0 0 0 0 0 0
39981 - 0 0 0 0 0 0 0 0 0 0 0 0
39982 - 0 0 0 0 0 0 0 0 0 0 0 0
39983 - 0 0 0 0 0 0 0 0 0 0 0 0
39984 - 6 6 6 6 6 6 10 10 10 10 10 10
39985 - 10 10 10 6 6 6 6 6 6 6 6 6
39986 - 0 0 0 0 0 0 0 0 0 0 0 0
39987 - 0 0 0 0 0 0 0 0 0 0 0 0
39988 - 0 0 0 0 0 0 0 0 0 0 0 0
39989 - 0 0 0 0 0 0 0 0 0 0 0 0
39990 - 0 0 0 0 0 0 0 0 0 0 0 0
39991 - 0 0 0 0 0 0 0 0 0 0 0 0
39992 - 0 0 0 0 0 0 0 0 0 0 0 0
39993 - 0 0 0 0 0 0 0 0 0 0 0 0
39994 - 0 0 0 0 0 0 0 0 0 0 0 0
39995 - 0 0 0 0 0 0 0 0 0 0 0 0
39996 - 0 0 0 0 0 0 0 0 0 0 0 0
39997 - 0 0 0 0 0 0 0 0 0 0 0 0
39998 - 0 0 0 0 0 0 0 0 0 0 0 0
39999 - 0 0 0 0 0 0 0 0 0 0 0 0
40000 - 0 0 0 0 0 0 0 0 0 0 0 0
40001 - 0 0 0 0 0 0 0 0 0 0 0 0
40002 - 0 0 0 0 0 0 0 0 0 0 0 0
40003 - 0 0 0 6 6 6 10 10 10 14 14 14
40004 - 22 22 22 26 26 26 30 30 30 34 34 34
40005 - 30 30 30 30 30 30 26 26 26 18 18 18
40006 - 14 14 14 10 10 10 6 6 6 0 0 0
40007 - 0 0 0 0 0 0 0 0 0 0 0 0
40008 - 0 0 0 0 0 0 0 0 0 0 0 0
40009 - 0 0 0 0 0 0 0 0 0 0 0 0
40010 - 0 0 0 0 0 0 0 0 0 0 0 0
40011 - 0 0 0 0 0 0 0 0 0 0 0 0
40012 - 0 0 0 0 0 0 0 0 0 0 0 0
40013 - 0 0 0 0 0 0 0 0 0 0 0 0
40014 - 0 0 0 0 0 0 0 0 0 0 0 0
40015 - 0 0 0 0 0 0 0 0 0 0 0 0
40016 - 0 0 0 0 0 1 0 0 1 0 0 0
40017 - 0 0 0 0 0 0 0 0 0 0 0 0
40018 - 0 0 0 0 0 0 0 0 0 0 0 0
40019 - 0 0 0 0 0 0 0 0 0 0 0 0
40020 - 0 0 0 0 0 0 0 0 0 0 0 0
40021 - 0 0 0 0 0 0 0 0 0 0 0 0
40022 - 0 0 0 0 0 0 0 0 0 0 0 0
40023 - 6 6 6 14 14 14 26 26 26 42 42 42
40024 - 54 54 54 66 66 66 78 78 78 78 78 78
40025 - 78 78 78 74 74 74 66 66 66 54 54 54
40026 - 42 42 42 26 26 26 18 18 18 10 10 10
40027 - 6 6 6 0 0 0 0 0 0 0 0 0
40028 - 0 0 0 0 0 0 0 0 0 0 0 0
40029 - 0 0 0 0 0 0 0 0 0 0 0 0
40030 - 0 0 0 0 0 0 0 0 0 0 0 0
40031 - 0 0 0 0 0 0 0 0 0 0 0 0
40032 - 0 0 0 0 0 0 0 0 0 0 0 0
40033 - 0 0 0 0 0 0 0 0 0 0 0 0
40034 - 0 0 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 1 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 0 0 0
40041 - 0 0 0 0 0 0 0 0 0 0 0 0
40042 - 0 0 0 0 0 0 0 0 0 10 10 10
40043 - 22 22 22 42 42 42 66 66 66 86 86 86
40044 - 66 66 66 38 38 38 38 38 38 22 22 22
40045 - 26 26 26 34 34 34 54 54 54 66 66 66
40046 - 86 86 86 70 70 70 46 46 46 26 26 26
40047 - 14 14 14 6 6 6 0 0 0 0 0 0
40048 - 0 0 0 0 0 0 0 0 0 0 0 0
40049 - 0 0 0 0 0 0 0 0 0 0 0 0
40050 - 0 0 0 0 0 0 0 0 0 0 0 0
40051 - 0 0 0 0 0 0 0 0 0 0 0 0
40052 - 0 0 0 0 0 0 0 0 0 0 0 0
40053 - 0 0 0 0 0 0 0 0 0 0 0 0
40054 - 0 0 0 0 0 0 0 0 0 0 0 0
40055 - 0 0 0 0 0 0 0 0 0 0 0 0
40056 - 0 0 1 0 0 1 0 0 1 0 0 0
40057 - 0 0 0 0 0 0 0 0 0 0 0 0
40058 - 0 0 0 0 0 0 0 0 0 0 0 0
40059 - 0 0 0 0 0 0 0 0 0 0 0 0
40060 - 0 0 0 0 0 0 0 0 0 0 0 0
40061 - 0 0 0 0 0 0 0 0 0 0 0 0
40062 - 0 0 0 0 0 0 10 10 10 26 26 26
40063 - 50 50 50 82 82 82 58 58 58 6 6 6
40064 - 2 2 6 2 2 6 2 2 6 2 2 6
40065 - 2 2 6 2 2 6 2 2 6 2 2 6
40066 - 6 6 6 54 54 54 86 86 86 66 66 66
40067 - 38 38 38 18 18 18 6 6 6 0 0 0
40068 - 0 0 0 0 0 0 0 0 0 0 0 0
40069 - 0 0 0 0 0 0 0 0 0 0 0 0
40070 - 0 0 0 0 0 0 0 0 0 0 0 0
40071 - 0 0 0 0 0 0 0 0 0 0 0 0
40072 - 0 0 0 0 0 0 0 0 0 0 0 0
40073 - 0 0 0 0 0 0 0 0 0 0 0 0
40074 - 0 0 0 0 0 0 0 0 0 0 0 0
40075 - 0 0 0 0 0 0 0 0 0 0 0 0
40076 - 0 0 0 0 0 0 0 0 0 0 0 0
40077 - 0 0 0 0 0 0 0 0 0 0 0 0
40078 - 0 0 0 0 0 0 0 0 0 0 0 0
40079 - 0 0 0 0 0 0 0 0 0 0 0 0
40080 - 0 0 0 0 0 0 0 0 0 0 0 0
40081 - 0 0 0 0 0 0 0 0 0 0 0 0
40082 - 0 0 0 6 6 6 22 22 22 50 50 50
40083 - 78 78 78 34 34 34 2 2 6 2 2 6
40084 - 2 2 6 2 2 6 2 2 6 2 2 6
40085 - 2 2 6 2 2 6 2 2 6 2 2 6
40086 - 2 2 6 2 2 6 6 6 6 70 70 70
40087 - 78 78 78 46 46 46 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 0 0 0 0
40095 - 0 0 0 0 0 0 0 0 0 0 0 0
40096 - 0 0 1 0 0 1 0 0 1 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 0 0 0
40101 - 0 0 0 0 0 0 0 0 0 0 0 0
40102 - 6 6 6 18 18 18 42 42 42 82 82 82
40103 - 26 26 26 2 2 6 2 2 6 2 2 6
40104 - 2 2 6 2 2 6 2 2 6 2 2 6
40105 - 2 2 6 2 2 6 2 2 6 14 14 14
40106 - 46 46 46 34 34 34 6 6 6 2 2 6
40107 - 42 42 42 78 78 78 42 42 42 18 18 18
40108 - 6 6 6 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 0 0 0 0
40115 - 0 0 0 0 0 0 0 0 0 0 0 0
40116 - 0 0 1 0 0 0 0 0 1 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 0 0 0
40121 - 0 0 0 0 0 0 0 0 0 0 0 0
40122 - 10 10 10 30 30 30 66 66 66 58 58 58
40123 - 2 2 6 2 2 6 2 2 6 2 2 6
40124 - 2 2 6 2 2 6 2 2 6 2 2 6
40125 - 2 2 6 2 2 6 2 2 6 26 26 26
40126 - 86 86 86 101 101 101 46 46 46 10 10 10
40127 - 2 2 6 58 58 58 70 70 70 34 34 34
40128 - 10 10 10 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 0 0 0 0
40135 - 0 0 0 0 0 0 0 0 0 0 0 0
40136 - 0 0 1 0 0 1 0 0 1 0 0 0
40137 - 0 0 0 0 0 0 0 0 0 0 0 0
40138 - 0 0 0 0 0 0 0 0 0 0 0 0
40139 - 0 0 0 0 0 0 0 0 0 0 0 0
40140 - 0 0 0 0 0 0 0 0 0 0 0 0
40141 - 0 0 0 0 0 0 0 0 0 0 0 0
40142 - 14 14 14 42 42 42 86 86 86 10 10 10
40143 - 2 2 6 2 2 6 2 2 6 2 2 6
40144 - 2 2 6 2 2 6 2 2 6 2 2 6
40145 - 2 2 6 2 2 6 2 2 6 30 30 30
40146 - 94 94 94 94 94 94 58 58 58 26 26 26
40147 - 2 2 6 6 6 6 78 78 78 54 54 54
40148 - 22 22 22 6 6 6 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 0 0 0
40161 - 0 0 0 0 0 0 0 0 0 6 6 6
40162 - 22 22 22 62 62 62 62 62 62 2 2 6
40163 - 2 2 6 2 2 6 2 2 6 2 2 6
40164 - 2 2 6 2 2 6 2 2 6 2 2 6
40165 - 2 2 6 2 2 6 2 2 6 26 26 26
40166 - 54 54 54 38 38 38 18 18 18 10 10 10
40167 - 2 2 6 2 2 6 34 34 34 82 82 82
40168 - 38 38 38 14 14 14 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 1 0 0 1 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 0 0 0
40181 - 0 0 0 0 0 0 0 0 0 6 6 6
40182 - 30 30 30 78 78 78 30 30 30 2 2 6
40183 - 2 2 6 2 2 6 2 2 6 2 2 6
40184 - 2 2 6 2 2 6 2 2 6 2 2 6
40185 - 2 2 6 2 2 6 2 2 6 10 10 10
40186 - 10 10 10 2 2 6 2 2 6 2 2 6
40187 - 2 2 6 2 2 6 2 2 6 78 78 78
40188 - 50 50 50 18 18 18 6 6 6 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 1 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 0 0 0
40201 - 0 0 0 0 0 0 0 0 0 10 10 10
40202 - 38 38 38 86 86 86 14 14 14 2 2 6
40203 - 2 2 6 2 2 6 2 2 6 2 2 6
40204 - 2 2 6 2 2 6 2 2 6 2 2 6
40205 - 2 2 6 2 2 6 2 2 6 2 2 6
40206 - 2 2 6 2 2 6 2 2 6 2 2 6
40207 - 2 2 6 2 2 6 2 2 6 54 54 54
40208 - 66 66 66 26 26 26 6 6 6 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 1 0 0 1 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 0 0 0
40221 - 0 0 0 0 0 0 0 0 0 14 14 14
40222 - 42 42 42 82 82 82 2 2 6 2 2 6
40223 - 2 2 6 6 6 6 10 10 10 2 2 6
40224 - 2 2 6 2 2 6 2 2 6 2 2 6
40225 - 2 2 6 2 2 6 2 2 6 6 6 6
40226 - 14 14 14 10 10 10 2 2 6 2 2 6
40227 - 2 2 6 2 2 6 2 2 6 18 18 18
40228 - 82 82 82 34 34 34 10 10 10 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 1 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 0 0 0
40241 - 0 0 0 0 0 0 0 0 0 14 14 14
40242 - 46 46 46 86 86 86 2 2 6 2 2 6
40243 - 6 6 6 6 6 6 22 22 22 34 34 34
40244 - 6 6 6 2 2 6 2 2 6 2 2 6
40245 - 2 2 6 2 2 6 18 18 18 34 34 34
40246 - 10 10 10 50 50 50 22 22 22 2 2 6
40247 - 2 2 6 2 2 6 2 2 6 10 10 10
40248 - 86 86 86 42 42 42 14 14 14 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 1 0 0 1 0 0 1 0 0 0
40257 - 0 0 0 0 0 0 0 0 0 0 0 0
40258 - 0 0 0 0 0 0 0 0 0 0 0 0
40259 - 0 0 0 0 0 0 0 0 0 0 0 0
40260 - 0 0 0 0 0 0 0 0 0 0 0 0
40261 - 0 0 0 0 0 0 0 0 0 14 14 14
40262 - 46 46 46 86 86 86 2 2 6 2 2 6
40263 - 38 38 38 116 116 116 94 94 94 22 22 22
40264 - 22 22 22 2 2 6 2 2 6 2 2 6
40265 - 14 14 14 86 86 86 138 138 138 162 162 162
40266 -154 154 154 38 38 38 26 26 26 6 6 6
40267 - 2 2 6 2 2 6 2 2 6 2 2 6
40268 - 86 86 86 46 46 46 14 14 14 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 0 0 0
40281 - 0 0 0 0 0 0 0 0 0 14 14 14
40282 - 46 46 46 86 86 86 2 2 6 14 14 14
40283 -134 134 134 198 198 198 195 195 195 116 116 116
40284 - 10 10 10 2 2 6 2 2 6 6 6 6
40285 -101 98 89 187 187 187 210 210 210 218 218 218
40286 -214 214 214 134 134 134 14 14 14 6 6 6
40287 - 2 2 6 2 2 6 2 2 6 2 2 6
40288 - 86 86 86 50 50 50 18 18 18 6 6 6
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 1 0 0 0
40296 - 0 0 1 0 0 1 0 0 1 0 0 0
40297 - 0 0 0 0 0 0 0 0 0 0 0 0
40298 - 0 0 0 0 0 0 0 0 0 0 0 0
40299 - 0 0 0 0 0 0 0 0 0 0 0 0
40300 - 0 0 0 0 0 0 0 0 0 0 0 0
40301 - 0 0 0 0 0 0 0 0 0 14 14 14
40302 - 46 46 46 86 86 86 2 2 6 54 54 54
40303 -218 218 218 195 195 195 226 226 226 246 246 246
40304 - 58 58 58 2 2 6 2 2 6 30 30 30
40305 -210 210 210 253 253 253 174 174 174 123 123 123
40306 -221 221 221 234 234 234 74 74 74 2 2 6
40307 - 2 2 6 2 2 6 2 2 6 2 2 6
40308 - 70 70 70 58 58 58 22 22 22 6 6 6
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 0 0 0 0 0 0
40321 - 0 0 0 0 0 0 0 0 0 14 14 14
40322 - 46 46 46 82 82 82 2 2 6 106 106 106
40323 -170 170 170 26 26 26 86 86 86 226 226 226
40324 -123 123 123 10 10 10 14 14 14 46 46 46
40325 -231 231 231 190 190 190 6 6 6 70 70 70
40326 - 90 90 90 238 238 238 158 158 158 2 2 6
40327 - 2 2 6 2 2 6 2 2 6 2 2 6
40328 - 70 70 70 58 58 58 22 22 22 6 6 6
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 1 0 0 0
40336 - 0 0 1 0 0 1 0 0 1 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 0 0 0 0 0 0 0 0 0
40341 - 0 0 0 0 0 0 0 0 0 14 14 14
40342 - 42 42 42 86 86 86 6 6 6 116 116 116
40343 -106 106 106 6 6 6 70 70 70 149 149 149
40344 -128 128 128 18 18 18 38 38 38 54 54 54
40345 -221 221 221 106 106 106 2 2 6 14 14 14
40346 - 46 46 46 190 190 190 198 198 198 2 2 6
40347 - 2 2 6 2 2 6 2 2 6 2 2 6
40348 - 74 74 74 62 62 62 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 1 0 0 0
40356 - 0 0 1 0 0 0 0 0 1 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 - 0 0 0 0 0 0 0 0 0 0 0 0
40361 - 0 0 0 0 0 0 0 0 0 14 14 14
40362 - 42 42 42 94 94 94 14 14 14 101 101 101
40363 -128 128 128 2 2 6 18 18 18 116 116 116
40364 -118 98 46 121 92 8 121 92 8 98 78 10
40365 -162 162 162 106 106 106 2 2 6 2 2 6
40366 - 2 2 6 195 195 195 195 195 195 6 6 6
40367 - 2 2 6 2 2 6 2 2 6 2 2 6
40368 - 74 74 74 62 62 62 22 22 22 6 6 6
40369 - 0 0 0 0 0 0 0 0 0 0 0 0
40370 - 0 0 0 0 0 0 0 0 0 0 0 0
40371 - 0 0 0 0 0 0 0 0 0 0 0 0
40372 - 0 0 0 0 0 0 0 0 0 0 0 0
40373 - 0 0 0 0 0 0 0 0 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 1 0 0 1
40376 - 0 0 1 0 0 0 0 0 1 0 0 0
40377 - 0 0 0 0 0 0 0 0 0 0 0 0
40378 - 0 0 0 0 0 0 0 0 0 0 0 0
40379 - 0 0 0 0 0 0 0 0 0 0 0 0
40380 - 0 0 0 0 0 0 0 0 0 0 0 0
40381 - 0 0 0 0 0 0 0 0 0 10 10 10
40382 - 38 38 38 90 90 90 14 14 14 58 58 58
40383 -210 210 210 26 26 26 54 38 6 154 114 10
40384 -226 170 11 236 186 11 225 175 15 184 144 12
40385 -215 174 15 175 146 61 37 26 9 2 2 6
40386 - 70 70 70 246 246 246 138 138 138 2 2 6
40387 - 2 2 6 2 2 6 2 2 6 2 2 6
40388 - 70 70 70 66 66 66 26 26 26 6 6 6
40389 - 0 0 0 0 0 0 0 0 0 0 0 0
40390 - 0 0 0 0 0 0 0 0 0 0 0 0
40391 - 0 0 0 0 0 0 0 0 0 0 0 0
40392 - 0 0 0 0 0 0 0 0 0 0 0 0
40393 - 0 0 0 0 0 0 0 0 0 0 0 0
40394 - 0 0 0 0 0 0 0 0 0 0 0 0
40395 - 0 0 0 0 0 0 0 0 0 0 0 0
40396 - 0 0 0 0 0 0 0 0 0 0 0 0
40397 - 0 0 0 0 0 0 0 0 0 0 0 0
40398 - 0 0 0 0 0 0 0 0 0 0 0 0
40399 - 0 0 0 0 0 0 0 0 0 0 0 0
40400 - 0 0 0 0 0 0 0 0 0 0 0 0
40401 - 0 0 0 0 0 0 0 0 0 10 10 10
40402 - 38 38 38 86 86 86 14 14 14 10 10 10
40403 -195 195 195 188 164 115 192 133 9 225 175 15
40404 -239 182 13 234 190 10 232 195 16 232 200 30
40405 -245 207 45 241 208 19 232 195 16 184 144 12
40406 -218 194 134 211 206 186 42 42 42 2 2 6
40407 - 2 2 6 2 2 6 2 2 6 2 2 6
40408 - 50 50 50 74 74 74 30 30 30 6 6 6
40409 - 0 0 0 0 0 0 0 0 0 0 0 0
40410 - 0 0 0 0 0 0 0 0 0 0 0 0
40411 - 0 0 0 0 0 0 0 0 0 0 0 0
40412 - 0 0 0 0 0 0 0 0 0 0 0 0
40413 - 0 0 0 0 0 0 0 0 0 0 0 0
40414 - 0 0 0 0 0 0 0 0 0 0 0 0
40415 - 0 0 0 0 0 0 0 0 0 0 0 0
40416 - 0 0 0 0 0 0 0 0 0 0 0 0
40417 - 0 0 0 0 0 0 0 0 0 0 0 0
40418 - 0 0 0 0 0 0 0 0 0 0 0 0
40419 - 0 0 0 0 0 0 0 0 0 0 0 0
40420 - 0 0 0 0 0 0 0 0 0 0 0 0
40421 - 0 0 0 0 0 0 0 0 0 10 10 10
40422 - 34 34 34 86 86 86 14 14 14 2 2 6
40423 -121 87 25 192 133 9 219 162 10 239 182 13
40424 -236 186 11 232 195 16 241 208 19 244 214 54
40425 -246 218 60 246 218 38 246 215 20 241 208 19
40426 -241 208 19 226 184 13 121 87 25 2 2 6
40427 - 2 2 6 2 2 6 2 2 6 2 2 6
40428 - 50 50 50 82 82 82 34 34 34 10 10 10
40429 - 0 0 0 0 0 0 0 0 0 0 0 0
40430 - 0 0 0 0 0 0 0 0 0 0 0 0
40431 - 0 0 0 0 0 0 0 0 0 0 0 0
40432 - 0 0 0 0 0 0 0 0 0 0 0 0
40433 - 0 0 0 0 0 0 0 0 0 0 0 0
40434 - 0 0 0 0 0 0 0 0 0 0 0 0
40435 - 0 0 0 0 0 0 0 0 0 0 0 0
40436 - 0 0 0 0 0 0 0 0 0 0 0 0
40437 - 0 0 0 0 0 0 0 0 0 0 0 0
40438 - 0 0 0 0 0 0 0 0 0 0 0 0
40439 - 0 0 0 0 0 0 0 0 0 0 0 0
40440 - 0 0 0 0 0 0 0 0 0 0 0 0
40441 - 0 0 0 0 0 0 0 0 0 10 10 10
40442 - 34 34 34 82 82 82 30 30 30 61 42 6
40443 -180 123 7 206 145 10 230 174 11 239 182 13
40444 -234 190 10 238 202 15 241 208 19 246 218 74
40445 -246 218 38 246 215 20 246 215 20 246 215 20
40446 -226 184 13 215 174 15 184 144 12 6 6 6
40447 - 2 2 6 2 2 6 2 2 6 2 2 6
40448 - 26 26 26 94 94 94 42 42 42 14 14 14
40449 - 0 0 0 0 0 0 0 0 0 0 0 0
40450 - 0 0 0 0 0 0 0 0 0 0 0 0
40451 - 0 0 0 0 0 0 0 0 0 0 0 0
40452 - 0 0 0 0 0 0 0 0 0 0 0 0
40453 - 0 0 0 0 0 0 0 0 0 0 0 0
40454 - 0 0 0 0 0 0 0 0 0 0 0 0
40455 - 0 0 0 0 0 0 0 0 0 0 0 0
40456 - 0 0 0 0 0 0 0 0 0 0 0 0
40457 - 0 0 0 0 0 0 0 0 0 0 0 0
40458 - 0 0 0 0 0 0 0 0 0 0 0 0
40459 - 0 0 0 0 0 0 0 0 0 0 0 0
40460 - 0 0 0 0 0 0 0 0 0 0 0 0
40461 - 0 0 0 0 0 0 0 0 0 10 10 10
40462 - 30 30 30 78 78 78 50 50 50 104 69 6
40463 -192 133 9 216 158 10 236 178 12 236 186 11
40464 -232 195 16 241 208 19 244 214 54 245 215 43
40465 -246 215 20 246 215 20 241 208 19 198 155 10
40466 -200 144 11 216 158 10 156 118 10 2 2 6
40467 - 2 2 6 2 2 6 2 2 6 2 2 6
40468 - 6 6 6 90 90 90 54 54 54 18 18 18
40469 - 6 6 6 0 0 0 0 0 0 0 0 0
40470 - 0 0 0 0 0 0 0 0 0 0 0 0
40471 - 0 0 0 0 0 0 0 0 0 0 0 0
40472 - 0 0 0 0 0 0 0 0 0 0 0 0
40473 - 0 0 0 0 0 0 0 0 0 0 0 0
40474 - 0 0 0 0 0 0 0 0 0 0 0 0
40475 - 0 0 0 0 0 0 0 0 0 0 0 0
40476 - 0 0 0 0 0 0 0 0 0 0 0 0
40477 - 0 0 0 0 0 0 0 0 0 0 0 0
40478 - 0 0 0 0 0 0 0 0 0 0 0 0
40479 - 0 0 0 0 0 0 0 0 0 0 0 0
40480 - 0 0 0 0 0 0 0 0 0 0 0 0
40481 - 0 0 0 0 0 0 0 0 0 10 10 10
40482 - 30 30 30 78 78 78 46 46 46 22 22 22
40483 -137 92 6 210 162 10 239 182 13 238 190 10
40484 -238 202 15 241 208 19 246 215 20 246 215 20
40485 -241 208 19 203 166 17 185 133 11 210 150 10
40486 -216 158 10 210 150 10 102 78 10 2 2 6
40487 - 6 6 6 54 54 54 14 14 14 2 2 6
40488 - 2 2 6 62 62 62 74 74 74 30 30 30
40489 - 10 10 10 0 0 0 0 0 0 0 0 0
40490 - 0 0 0 0 0 0 0 0 0 0 0 0
40491 - 0 0 0 0 0 0 0 0 0 0 0 0
40492 - 0 0 0 0 0 0 0 0 0 0 0 0
40493 - 0 0 0 0 0 0 0 0 0 0 0 0
40494 - 0 0 0 0 0 0 0 0 0 0 0 0
40495 - 0 0 0 0 0 0 0 0 0 0 0 0
40496 - 0 0 0 0 0 0 0 0 0 0 0 0
40497 - 0 0 0 0 0 0 0 0 0 0 0 0
40498 - 0 0 0 0 0 0 0 0 0 0 0 0
40499 - 0 0 0 0 0 0 0 0 0 0 0 0
40500 - 0 0 0 0 0 0 0 0 0 0 0 0
40501 - 0 0 0 0 0 0 0 0 0 10 10 10
40502 - 34 34 34 78 78 78 50 50 50 6 6 6
40503 - 94 70 30 139 102 15 190 146 13 226 184 13
40504 -232 200 30 232 195 16 215 174 15 190 146 13
40505 -168 122 10 192 133 9 210 150 10 213 154 11
40506 -202 150 34 182 157 106 101 98 89 2 2 6
40507 - 2 2 6 78 78 78 116 116 116 58 58 58
40508 - 2 2 6 22 22 22 90 90 90 46 46 46
40509 - 18 18 18 6 6 6 0 0 0 0 0 0
40510 - 0 0 0 0 0 0 0 0 0 0 0 0
40511 - 0 0 0 0 0 0 0 0 0 0 0 0
40512 - 0 0 0 0 0 0 0 0 0 0 0 0
40513 - 0 0 0 0 0 0 0 0 0 0 0 0
40514 - 0 0 0 0 0 0 0 0 0 0 0 0
40515 - 0 0 0 0 0 0 0 0 0 0 0 0
40516 - 0 0 0 0 0 0 0 0 0 0 0 0
40517 - 0 0 0 0 0 0 0 0 0 0 0 0
40518 - 0 0 0 0 0 0 0 0 0 0 0 0
40519 - 0 0 0 0 0 0 0 0 0 0 0 0
40520 - 0 0 0 0 0 0 0 0 0 0 0 0
40521 - 0 0 0 0 0 0 0 0 0 10 10 10
40522 - 38 38 38 86 86 86 50 50 50 6 6 6
40523 -128 128 128 174 154 114 156 107 11 168 122 10
40524 -198 155 10 184 144 12 197 138 11 200 144 11
40525 -206 145 10 206 145 10 197 138 11 188 164 115
40526 -195 195 195 198 198 198 174 174 174 14 14 14
40527 - 2 2 6 22 22 22 116 116 116 116 116 116
40528 - 22 22 22 2 2 6 74 74 74 70 70 70
40529 - 30 30 30 10 10 10 0 0 0 0 0 0
40530 - 0 0 0 0 0 0 0 0 0 0 0 0
40531 - 0 0 0 0 0 0 0 0 0 0 0 0
40532 - 0 0 0 0 0 0 0 0 0 0 0 0
40533 - 0 0 0 0 0 0 0 0 0 0 0 0
40534 - 0 0 0 0 0 0 0 0 0 0 0 0
40535 - 0 0 0 0 0 0 0 0 0 0 0 0
40536 - 0 0 0 0 0 0 0 0 0 0 0 0
40537 - 0 0 0 0 0 0 0 0 0 0 0 0
40538 - 0 0 0 0 0 0 0 0 0 0 0 0
40539 - 0 0 0 0 0 0 0 0 0 0 0 0
40540 - 0 0 0 0 0 0 0 0 0 0 0 0
40541 - 0 0 0 0 0 0 6 6 6 18 18 18
40542 - 50 50 50 101 101 101 26 26 26 10 10 10
40543 -138 138 138 190 190 190 174 154 114 156 107 11
40544 -197 138 11 200 144 11 197 138 11 192 133 9
40545 -180 123 7 190 142 34 190 178 144 187 187 187
40546 -202 202 202 221 221 221 214 214 214 66 66 66
40547 - 2 2 6 2 2 6 50 50 50 62 62 62
40548 - 6 6 6 2 2 6 10 10 10 90 90 90
40549 - 50 50 50 18 18 18 6 6 6 0 0 0
40550 - 0 0 0 0 0 0 0 0 0 0 0 0
40551 - 0 0 0 0 0 0 0 0 0 0 0 0
40552 - 0 0 0 0 0 0 0 0 0 0 0 0
40553 - 0 0 0 0 0 0 0 0 0 0 0 0
40554 - 0 0 0 0 0 0 0 0 0 0 0 0
40555 - 0 0 0 0 0 0 0 0 0 0 0 0
40556 - 0 0 0 0 0 0 0 0 0 0 0 0
40557 - 0 0 0 0 0 0 0 0 0 0 0 0
40558 - 0 0 0 0 0 0 0 0 0 0 0 0
40559 - 0 0 0 0 0 0 0 0 0 0 0 0
40560 - 0 0 0 0 0 0 0 0 0 0 0 0
40561 - 0 0 0 0 0 0 10 10 10 34 34 34
40562 - 74 74 74 74 74 74 2 2 6 6 6 6
40563 -144 144 144 198 198 198 190 190 190 178 166 146
40564 -154 121 60 156 107 11 156 107 11 168 124 44
40565 -174 154 114 187 187 187 190 190 190 210 210 210
40566 -246 246 246 253 253 253 253 253 253 182 182 182
40567 - 6 6 6 2 2 6 2 2 6 2 2 6
40568 - 2 2 6 2 2 6 2 2 6 62 62 62
40569 - 74 74 74 34 34 34 14 14 14 0 0 0
40570 - 0 0 0 0 0 0 0 0 0 0 0 0
40571 - 0 0 0 0 0 0 0 0 0 0 0 0
40572 - 0 0 0 0 0 0 0 0 0 0 0 0
40573 - 0 0 0 0 0 0 0 0 0 0 0 0
40574 - 0 0 0 0 0 0 0 0 0 0 0 0
40575 - 0 0 0 0 0 0 0 0 0 0 0 0
40576 - 0 0 0 0 0 0 0 0 0 0 0 0
40577 - 0 0 0 0 0 0 0 0 0 0 0 0
40578 - 0 0 0 0 0 0 0 0 0 0 0 0
40579 - 0 0 0 0 0 0 0 0 0 0 0 0
40580 - 0 0 0 0 0 0 0 0 0 0 0 0
40581 - 0 0 0 10 10 10 22 22 22 54 54 54
40582 - 94 94 94 18 18 18 2 2 6 46 46 46
40583 -234 234 234 221 221 221 190 190 190 190 190 190
40584 -190 190 190 187 187 187 187 187 187 190 190 190
40585 -190 190 190 195 195 195 214 214 214 242 242 242
40586 -253 253 253 253 253 253 253 253 253 253 253 253
40587 - 82 82 82 2 2 6 2 2 6 2 2 6
40588 - 2 2 6 2 2 6 2 2 6 14 14 14
40589 - 86 86 86 54 54 54 22 22 22 6 6 6
40590 - 0 0 0 0 0 0 0 0 0 0 0 0
40591 - 0 0 0 0 0 0 0 0 0 0 0 0
40592 - 0 0 0 0 0 0 0 0 0 0 0 0
40593 - 0 0 0 0 0 0 0 0 0 0 0 0
40594 - 0 0 0 0 0 0 0 0 0 0 0 0
40595 - 0 0 0 0 0 0 0 0 0 0 0 0
40596 - 0 0 0 0 0 0 0 0 0 0 0 0
40597 - 0 0 0 0 0 0 0 0 0 0 0 0
40598 - 0 0 0 0 0 0 0 0 0 0 0 0
40599 - 0 0 0 0 0 0 0 0 0 0 0 0
40600 - 0 0 0 0 0 0 0 0 0 0 0 0
40601 - 6 6 6 18 18 18 46 46 46 90 90 90
40602 - 46 46 46 18 18 18 6 6 6 182 182 182
40603 -253 253 253 246 246 246 206 206 206 190 190 190
40604 -190 190 190 190 190 190 190 190 190 190 190 190
40605 -206 206 206 231 231 231 250 250 250 253 253 253
40606 -253 253 253 253 253 253 253 253 253 253 253 253
40607 -202 202 202 14 14 14 2 2 6 2 2 6
40608 - 2 2 6 2 2 6 2 2 6 2 2 6
40609 - 42 42 42 86 86 86 42 42 42 18 18 18
40610 - 6 6 6 0 0 0 0 0 0 0 0 0
40611 - 0 0 0 0 0 0 0 0 0 0 0 0
40612 - 0 0 0 0 0 0 0 0 0 0 0 0
40613 - 0 0 0 0 0 0 0 0 0 0 0 0
40614 - 0 0 0 0 0 0 0 0 0 0 0 0
40615 - 0 0 0 0 0 0 0 0 0 0 0 0
40616 - 0 0 0 0 0 0 0 0 0 0 0 0
40617 - 0 0 0 0 0 0 0 0 0 0 0 0
40618 - 0 0 0 0 0 0 0 0 0 0 0 0
40619 - 0 0 0 0 0 0 0 0 0 0 0 0
40620 - 0 0 0 0 0 0 0 0 0 6 6 6
40621 - 14 14 14 38 38 38 74 74 74 66 66 66
40622 - 2 2 6 6 6 6 90 90 90 250 250 250
40623 -253 253 253 253 253 253 238 238 238 198 198 198
40624 -190 190 190 190 190 190 195 195 195 221 221 221
40625 -246 246 246 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 82 82 82 2 2 6 2 2 6
40628 - 2 2 6 2 2 6 2 2 6 2 2 6
40629 - 2 2 6 78 78 78 70 70 70 34 34 34
40630 - 14 14 14 6 6 6 0 0 0 0 0 0
40631 - 0 0 0 0 0 0 0 0 0 0 0 0
40632 - 0 0 0 0 0 0 0 0 0 0 0 0
40633 - 0 0 0 0 0 0 0 0 0 0 0 0
40634 - 0 0 0 0 0 0 0 0 0 0 0 0
40635 - 0 0 0 0 0 0 0 0 0 0 0 0
40636 - 0 0 0 0 0 0 0 0 0 0 0 0
40637 - 0 0 0 0 0 0 0 0 0 0 0 0
40638 - 0 0 0 0 0 0 0 0 0 0 0 0
40639 - 0 0 0 0 0 0 0 0 0 0 0 0
40640 - 0 0 0 0 0 0 0 0 0 14 14 14
40641 - 34 34 34 66 66 66 78 78 78 6 6 6
40642 - 2 2 6 18 18 18 218 218 218 253 253 253
40643 -253 253 253 253 253 253 253 253 253 246 246 246
40644 -226 226 226 231 231 231 246 246 246 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 178 178 178 2 2 6 2 2 6
40648 - 2 2 6 2 2 6 2 2 6 2 2 6
40649 - 2 2 6 18 18 18 90 90 90 62 62 62
40650 - 30 30 30 10 10 10 0 0 0 0 0 0
40651 - 0 0 0 0 0 0 0 0 0 0 0 0
40652 - 0 0 0 0 0 0 0 0 0 0 0 0
40653 - 0 0 0 0 0 0 0 0 0 0 0 0
40654 - 0 0 0 0 0 0 0 0 0 0 0 0
40655 - 0 0 0 0 0 0 0 0 0 0 0 0
40656 - 0 0 0 0 0 0 0 0 0 0 0 0
40657 - 0 0 0 0 0 0 0 0 0 0 0 0
40658 - 0 0 0 0 0 0 0 0 0 0 0 0
40659 - 0 0 0 0 0 0 0 0 0 0 0 0
40660 - 0 0 0 0 0 0 10 10 10 26 26 26
40661 - 58 58 58 90 90 90 18 18 18 2 2 6
40662 - 2 2 6 110 110 110 253 253 253 253 253 253
40663 -253 253 253 253 253 253 253 253 253 253 253 253
40664 -250 250 250 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 231 231 231 18 18 18 2 2 6
40668 - 2 2 6 2 2 6 2 2 6 2 2 6
40669 - 2 2 6 2 2 6 18 18 18 94 94 94
40670 - 54 54 54 26 26 26 10 10 10 0 0 0
40671 - 0 0 0 0 0 0 0 0 0 0 0 0
40672 - 0 0 0 0 0 0 0 0 0 0 0 0
40673 - 0 0 0 0 0 0 0 0 0 0 0 0
40674 - 0 0 0 0 0 0 0 0 0 0 0 0
40675 - 0 0 0 0 0 0 0 0 0 0 0 0
40676 - 0 0 0 0 0 0 0 0 0 0 0 0
40677 - 0 0 0 0 0 0 0 0 0 0 0 0
40678 - 0 0 0 0 0 0 0 0 0 0 0 0
40679 - 0 0 0 0 0 0 0 0 0 0 0 0
40680 - 0 0 0 6 6 6 22 22 22 50 50 50
40681 - 90 90 90 26 26 26 2 2 6 2 2 6
40682 - 14 14 14 195 195 195 250 250 250 253 253 253
40683 -253 253 253 253 253 253 253 253 253 253 253 253
40684 -253 253 253 253 253 253 253 253 253 253 253 253
40685 -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 -250 250 250 242 242 242 54 54 54 2 2 6
40688 - 2 2 6 2 2 6 2 2 6 2 2 6
40689 - 2 2 6 2 2 6 2 2 6 38 38 38
40690 - 86 86 86 50 50 50 22 22 22 6 6 6
40691 - 0 0 0 0 0 0 0 0 0 0 0 0
40692 - 0 0 0 0 0 0 0 0 0 0 0 0
40693 - 0 0 0 0 0 0 0 0 0 0 0 0
40694 - 0 0 0 0 0 0 0 0 0 0 0 0
40695 - 0 0 0 0 0 0 0 0 0 0 0 0
40696 - 0 0 0 0 0 0 0 0 0 0 0 0
40697 - 0 0 0 0 0 0 0 0 0 0 0 0
40698 - 0 0 0 0 0 0 0 0 0 0 0 0
40699 - 0 0 0 0 0 0 0 0 0 0 0 0
40700 - 6 6 6 14 14 14 38 38 38 82 82 82
40701 - 34 34 34 2 2 6 2 2 6 2 2 6
40702 - 42 42 42 195 195 195 246 246 246 253 253 253
40703 -253 253 253 253 253 253 253 253 253 250 250 250
40704 -242 242 242 242 242 242 250 250 250 253 253 253
40705 -253 253 253 253 253 253 253 253 253 253 253 253
40706 -253 253 253 250 250 250 246 246 246 238 238 238
40707 -226 226 226 231 231 231 101 101 101 6 6 6
40708 - 2 2 6 2 2 6 2 2 6 2 2 6
40709 - 2 2 6 2 2 6 2 2 6 2 2 6
40710 - 38 38 38 82 82 82 42 42 42 14 14 14
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 0 0 0
40718 - 0 0 0 0 0 0 0 0 0 0 0 0
40719 - 0 0 0 0 0 0 0 0 0 0 0 0
40720 - 10 10 10 26 26 26 62 62 62 66 66 66
40721 - 2 2 6 2 2 6 2 2 6 6 6 6
40722 - 70 70 70 170 170 170 206 206 206 234 234 234
40723 -246 246 246 250 250 250 250 250 250 238 238 238
40724 -226 226 226 231 231 231 238 238 238 250 250 250
40725 -250 250 250 250 250 250 246 246 246 231 231 231
40726 -214 214 214 206 206 206 202 202 202 202 202 202
40727 -198 198 198 202 202 202 182 182 182 18 18 18
40728 - 2 2 6 2 2 6 2 2 6 2 2 6
40729 - 2 2 6 2 2 6 2 2 6 2 2 6
40730 - 2 2 6 62 62 62 66 66 66 30 30 30
40731 - 10 10 10 0 0 0 0 0 0 0 0 0
40732 - 0 0 0 0 0 0 0 0 0 0 0 0
40733 - 0 0 0 0 0 0 0 0 0 0 0 0
40734 - 0 0 0 0 0 0 0 0 0 0 0 0
40735 - 0 0 0 0 0 0 0 0 0 0 0 0
40736 - 0 0 0 0 0 0 0 0 0 0 0 0
40737 - 0 0 0 0 0 0 0 0 0 0 0 0
40738 - 0 0 0 0 0 0 0 0 0 0 0 0
40739 - 0 0 0 0 0 0 0 0 0 0 0 0
40740 - 14 14 14 42 42 42 82 82 82 18 18 18
40741 - 2 2 6 2 2 6 2 2 6 10 10 10
40742 - 94 94 94 182 182 182 218 218 218 242 242 242
40743 -250 250 250 253 253 253 253 253 253 250 250 250
40744 -234 234 234 253 253 253 253 253 253 253 253 253
40745 -253 253 253 253 253 253 253 253 253 246 246 246
40746 -238 238 238 226 226 226 210 210 210 202 202 202
40747 -195 195 195 195 195 195 210 210 210 158 158 158
40748 - 6 6 6 14 14 14 50 50 50 14 14 14
40749 - 2 2 6 2 2 6 2 2 6 2 2 6
40750 - 2 2 6 6 6 6 86 86 86 46 46 46
40751 - 18 18 18 6 6 6 0 0 0 0 0 0
40752 - 0 0 0 0 0 0 0 0 0 0 0 0
40753 - 0 0 0 0 0 0 0 0 0 0 0 0
40754 - 0 0 0 0 0 0 0 0 0 0 0 0
40755 - 0 0 0 0 0 0 0 0 0 0 0 0
40756 - 0 0 0 0 0 0 0 0 0 0 0 0
40757 - 0 0 0 0 0 0 0 0 0 0 0 0
40758 - 0 0 0 0 0 0 0 0 0 0 0 0
40759 - 0 0 0 0 0 0 0 0 0 6 6 6
40760 - 22 22 22 54 54 54 70 70 70 2 2 6
40761 - 2 2 6 10 10 10 2 2 6 22 22 22
40762 -166 166 166 231 231 231 250 250 250 253 253 253
40763 -253 253 253 253 253 253 253 253 253 250 250 250
40764 -242 242 242 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 246 246 246
40767 -231 231 231 206 206 206 198 198 198 226 226 226
40768 - 94 94 94 2 2 6 6 6 6 38 38 38
40769 - 30 30 30 2 2 6 2 2 6 2 2 6
40770 - 2 2 6 2 2 6 62 62 62 66 66 66
40771 - 26 26 26 10 10 10 0 0 0 0 0 0
40772 - 0 0 0 0 0 0 0 0 0 0 0 0
40773 - 0 0 0 0 0 0 0 0 0 0 0 0
40774 - 0 0 0 0 0 0 0 0 0 0 0 0
40775 - 0 0 0 0 0 0 0 0 0 0 0 0
40776 - 0 0 0 0 0 0 0 0 0 0 0 0
40777 - 0 0 0 0 0 0 0 0 0 0 0 0
40778 - 0 0 0 0 0 0 0 0 0 0 0 0
40779 - 0 0 0 0 0 0 0 0 0 10 10 10
40780 - 30 30 30 74 74 74 50 50 50 2 2 6
40781 - 26 26 26 26 26 26 2 2 6 106 106 106
40782 -238 238 238 253 253 253 253 253 253 253 253 253
40783 -253 253 253 253 253 253 253 253 253 253 253 253
40784 -253 253 253 253 253 253 253 253 253 253 253 253
40785 -253 253 253 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 246 246 246 218 218 218 202 202 202
40788 -210 210 210 14 14 14 2 2 6 2 2 6
40789 - 30 30 30 22 22 22 2 2 6 2 2 6
40790 - 2 2 6 2 2 6 18 18 18 86 86 86
40791 - 42 42 42 14 14 14 0 0 0 0 0 0
40792 - 0 0 0 0 0 0 0 0 0 0 0 0
40793 - 0 0 0 0 0 0 0 0 0 0 0 0
40794 - 0 0 0 0 0 0 0 0 0 0 0 0
40795 - 0 0 0 0 0 0 0 0 0 0 0 0
40796 - 0 0 0 0 0 0 0 0 0 0 0 0
40797 - 0 0 0 0 0 0 0 0 0 0 0 0
40798 - 0 0 0 0 0 0 0 0 0 0 0 0
40799 - 0 0 0 0 0 0 0 0 0 14 14 14
40800 - 42 42 42 90 90 90 22 22 22 2 2 6
40801 - 42 42 42 2 2 6 18 18 18 218 218 218
40802 -253 253 253 253 253 253 253 253 253 253 253 253
40803 -253 253 253 253 253 253 253 253 253 253 253 253
40804 -253 253 253 253 253 253 253 253 253 253 253 253
40805 -253 253 253 253 253 253 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 250 250 250 221 221 221
40808 -218 218 218 101 101 101 2 2 6 14 14 14
40809 - 18 18 18 38 38 38 10 10 10 2 2 6
40810 - 2 2 6 2 2 6 2 2 6 78 78 78
40811 - 58 58 58 22 22 22 6 6 6 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 0 0 0 0 0 0
40818 - 0 0 0 0 0 0 0 0 0 0 0 0
40819 - 0 0 0 0 0 0 6 6 6 18 18 18
40820 - 54 54 54 82 82 82 2 2 6 26 26 26
40821 - 22 22 22 2 2 6 123 123 123 253 253 253
40822 -253 253 253 253 253 253 253 253 253 253 253 253
40823 -253 253 253 253 253 253 253 253 253 253 253 253
40824 -253 253 253 253 253 253 253 253 253 253 253 253
40825 -253 253 253 253 253 253 253 253 253 253 253 253
40826 -253 253 253 253 253 253 253 253 253 253 253 253
40827 -253 253 253 253 253 253 253 253 253 250 250 250
40828 -238 238 238 198 198 198 6 6 6 38 38 38
40829 - 58 58 58 26 26 26 38 38 38 2 2 6
40830 - 2 2 6 2 2 6 2 2 6 46 46 46
40831 - 78 78 78 30 30 30 10 10 10 0 0 0
40832 - 0 0 0 0 0 0 0 0 0 0 0 0
40833 - 0 0 0 0 0 0 0 0 0 0 0 0
40834 - 0 0 0 0 0 0 0 0 0 0 0 0
40835 - 0 0 0 0 0 0 0 0 0 0 0 0
40836 - 0 0 0 0 0 0 0 0 0 0 0 0
40837 - 0 0 0 0 0 0 0 0 0 0 0 0
40838 - 0 0 0 0 0 0 0 0 0 0 0 0
40839 - 0 0 0 0 0 0 10 10 10 30 30 30
40840 - 74 74 74 58 58 58 2 2 6 42 42 42
40841 - 2 2 6 22 22 22 231 231 231 253 253 253
40842 -253 253 253 253 253 253 253 253 253 253 253 253
40843 -253 253 253 253 253 253 253 253 253 250 250 250
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 253 253 253
40847 -253 253 253 253 253 253 253 253 253 253 253 253
40848 -253 253 253 246 246 246 46 46 46 38 38 38
40849 - 42 42 42 14 14 14 38 38 38 14 14 14
40850 - 2 2 6 2 2 6 2 2 6 6 6 6
40851 - 86 86 86 46 46 46 14 14 14 0 0 0
40852 - 0 0 0 0 0 0 0 0 0 0 0 0
40853 - 0 0 0 0 0 0 0 0 0 0 0 0
40854 - 0 0 0 0 0 0 0 0 0 0 0 0
40855 - 0 0 0 0 0 0 0 0 0 0 0 0
40856 - 0 0 0 0 0 0 0 0 0 0 0 0
40857 - 0 0 0 0 0 0 0 0 0 0 0 0
40858 - 0 0 0 0 0 0 0 0 0 0 0 0
40859 - 0 0 0 6 6 6 14 14 14 42 42 42
40860 - 90 90 90 18 18 18 18 18 18 26 26 26
40861 - 2 2 6 116 116 116 253 253 253 253 253 253
40862 -253 253 253 253 253 253 253 253 253 253 253 253
40863 -253 253 253 253 253 253 250 250 250 238 238 238
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 253 253 253
40867 -253 253 253 253 253 253 253 253 253 253 253 253
40868 -253 253 253 253 253 253 94 94 94 6 6 6
40869 - 2 2 6 2 2 6 10 10 10 34 34 34
40870 - 2 2 6 2 2 6 2 2 6 2 2 6
40871 - 74 74 74 58 58 58 22 22 22 6 6 6
40872 - 0 0 0 0 0 0 0 0 0 0 0 0
40873 - 0 0 0 0 0 0 0 0 0 0 0 0
40874 - 0 0 0 0 0 0 0 0 0 0 0 0
40875 - 0 0 0 0 0 0 0 0 0 0 0 0
40876 - 0 0 0 0 0 0 0 0 0 0 0 0
40877 - 0 0 0 0 0 0 0 0 0 0 0 0
40878 - 0 0 0 0 0 0 0 0 0 0 0 0
40879 - 0 0 0 10 10 10 26 26 26 66 66 66
40880 - 82 82 82 2 2 6 38 38 38 6 6 6
40881 - 14 14 14 210 210 210 253 253 253 253 253 253
40882 -253 253 253 253 253 253 253 253 253 253 253 253
40883 -253 253 253 253 253 253 246 246 246 242 242 242
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 253 253 253
40887 -253 253 253 253 253 253 253 253 253 253 253 253
40888 -253 253 253 253 253 253 144 144 144 2 2 6
40889 - 2 2 6 2 2 6 2 2 6 46 46 46
40890 - 2 2 6 2 2 6 2 2 6 2 2 6
40891 - 42 42 42 74 74 74 30 30 30 10 10 10
40892 - 0 0 0 0 0 0 0 0 0 0 0 0
40893 - 0 0 0 0 0 0 0 0 0 0 0 0
40894 - 0 0 0 0 0 0 0 0 0 0 0 0
40895 - 0 0 0 0 0 0 0 0 0 0 0 0
40896 - 0 0 0 0 0 0 0 0 0 0 0 0
40897 - 0 0 0 0 0 0 0 0 0 0 0 0
40898 - 0 0 0 0 0 0 0 0 0 0 0 0
40899 - 6 6 6 14 14 14 42 42 42 90 90 90
40900 - 26 26 26 6 6 6 42 42 42 2 2 6
40901 - 74 74 74 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 242 242 242 242 242 242
40904 -253 253 253 253 253 253 253 253 253 253 253 253
40905 -253 253 253 253 253 253 253 253 253 253 253 253
40906 -253 253 253 253 253 253 253 253 253 253 253 253
40907 -253 253 253 253 253 253 253 253 253 253 253 253
40908 -253 253 253 253 253 253 182 182 182 2 2 6
40909 - 2 2 6 2 2 6 2 2 6 46 46 46
40910 - 2 2 6 2 2 6 2 2 6 2 2 6
40911 - 10 10 10 86 86 86 38 38 38 10 10 10
40912 - 0 0 0 0 0 0 0 0 0 0 0 0
40913 - 0 0 0 0 0 0 0 0 0 0 0 0
40914 - 0 0 0 0 0 0 0 0 0 0 0 0
40915 - 0 0 0 0 0 0 0 0 0 0 0 0
40916 - 0 0 0 0 0 0 0 0 0 0 0 0
40917 - 0 0 0 0 0 0 0 0 0 0 0 0
40918 - 0 0 0 0 0 0 0 0 0 0 0 0
40919 - 10 10 10 26 26 26 66 66 66 82 82 82
40920 - 2 2 6 22 22 22 18 18 18 2 2 6
40921 -149 149 149 253 253 253 253 253 253 253 253 253
40922 -253 253 253 253 253 253 253 253 253 253 253 253
40923 -253 253 253 253 253 253 234 234 234 242 242 242
40924 -253 253 253 253 253 253 253 253 253 253 253 253
40925 -253 253 253 253 253 253 253 253 253 253 253 253
40926 -253 253 253 253 253 253 253 253 253 253 253 253
40927 -253 253 253 253 253 253 253 253 253 253 253 253
40928 -253 253 253 253 253 253 206 206 206 2 2 6
40929 - 2 2 6 2 2 6 2 2 6 38 38 38
40930 - 2 2 6 2 2 6 2 2 6 2 2 6
40931 - 6 6 6 86 86 86 46 46 46 14 14 14
40932 - 0 0 0 0 0 0 0 0 0 0 0 0
40933 - 0 0 0 0 0 0 0 0 0 0 0 0
40934 - 0 0 0 0 0 0 0 0 0 0 0 0
40935 - 0 0 0 0 0 0 0 0 0 0 0 0
40936 - 0 0 0 0 0 0 0 0 0 0 0 0
40937 - 0 0 0 0 0 0 0 0 0 0 0 0
40938 - 0 0 0 0 0 0 0 0 0 6 6 6
40939 - 18 18 18 46 46 46 86 86 86 18 18 18
40940 - 2 2 6 34 34 34 10 10 10 6 6 6
40941 -210 210 210 253 253 253 253 253 253 253 253 253
40942 -253 253 253 253 253 253 253 253 253 253 253 253
40943 -253 253 253 253 253 253 234 234 234 242 242 242
40944 -253 253 253 253 253 253 253 253 253 253 253 253
40945 -253 253 253 253 253 253 253 253 253 253 253 253
40946 -253 253 253 253 253 253 253 253 253 253 253 253
40947 -253 253 253 253 253 253 253 253 253 253 253 253
40948 -253 253 253 253 253 253 221 221 221 6 6 6
40949 - 2 2 6 2 2 6 6 6 6 30 30 30
40950 - 2 2 6 2 2 6 2 2 6 2 2 6
40951 - 2 2 6 82 82 82 54 54 54 18 18 18
40952 - 6 6 6 0 0 0 0 0 0 0 0 0
40953 - 0 0 0 0 0 0 0 0 0 0 0 0
40954 - 0 0 0 0 0 0 0 0 0 0 0 0
40955 - 0 0 0 0 0 0 0 0 0 0 0 0
40956 - 0 0 0 0 0 0 0 0 0 0 0 0
40957 - 0 0 0 0 0 0 0 0 0 0 0 0
40958 - 0 0 0 0 0 0 0 0 0 10 10 10
40959 - 26 26 26 66 66 66 62 62 62 2 2 6
40960 - 2 2 6 38 38 38 10 10 10 26 26 26
40961 -238 238 238 253 253 253 253 253 253 253 253 253
40962 -253 253 253 253 253 253 253 253 253 253 253 253
40963 -253 253 253 253 253 253 231 231 231 238 238 238
40964 -253 253 253 253 253 253 253 253 253 253 253 253
40965 -253 253 253 253 253 253 253 253 253 253 253 253
40966 -253 253 253 253 253 253 253 253 253 253 253 253
40967 -253 253 253 253 253 253 253 253 253 253 253 253
40968 -253 253 253 253 253 253 231 231 231 6 6 6
40969 - 2 2 6 2 2 6 10 10 10 30 30 30
40970 - 2 2 6 2 2 6 2 2 6 2 2 6
40971 - 2 2 6 66 66 66 58 58 58 22 22 22
40972 - 6 6 6 0 0 0 0 0 0 0 0 0
40973 - 0 0 0 0 0 0 0 0 0 0 0 0
40974 - 0 0 0 0 0 0 0 0 0 0 0 0
40975 - 0 0 0 0 0 0 0 0 0 0 0 0
40976 - 0 0 0 0 0 0 0 0 0 0 0 0
40977 - 0 0 0 0 0 0 0 0 0 0 0 0
40978 - 0 0 0 0 0 0 0 0 0 10 10 10
40979 - 38 38 38 78 78 78 6 6 6 2 2 6
40980 - 2 2 6 46 46 46 14 14 14 42 42 42
40981 -246 246 246 253 253 253 253 253 253 253 253 253
40982 -253 253 253 253 253 253 253 253 253 253 253 253
40983 -253 253 253 253 253 253 231 231 231 242 242 242
40984 -253 253 253 253 253 253 253 253 253 253 253 253
40985 -253 253 253 253 253 253 253 253 253 253 253 253
40986 -253 253 253 253 253 253 253 253 253 253 253 253
40987 -253 253 253 253 253 253 253 253 253 253 253 253
40988 -253 253 253 253 253 253 234 234 234 10 10 10
40989 - 2 2 6 2 2 6 22 22 22 14 14 14
40990 - 2 2 6 2 2 6 2 2 6 2 2 6
40991 - 2 2 6 66 66 66 62 62 62 22 22 22
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 0 0 0
40996 - 0 0 0 0 0 0 0 0 0 0 0 0
40997 - 0 0 0 0 0 0 0 0 0 0 0 0
40998 - 0 0 0 0 0 0 6 6 6 18 18 18
40999 - 50 50 50 74 74 74 2 2 6 2 2 6
41000 - 14 14 14 70 70 70 34 34 34 62 62 62
41001 -250 250 250 253 253 253 253 253 253 253 253 253
41002 -253 253 253 253 253 253 253 253 253 253 253 253
41003 -253 253 253 253 253 253 231 231 231 246 246 246
41004 -253 253 253 253 253 253 253 253 253 253 253 253
41005 -253 253 253 253 253 253 253 253 253 253 253 253
41006 -253 253 253 253 253 253 253 253 253 253 253 253
41007 -253 253 253 253 253 253 253 253 253 253 253 253
41008 -253 253 253 253 253 253 234 234 234 14 14 14
41009 - 2 2 6 2 2 6 30 30 30 2 2 6
41010 - 2 2 6 2 2 6 2 2 6 2 2 6
41011 - 2 2 6 66 66 66 62 62 62 22 22 22
41012 - 6 6 6 0 0 0 0 0 0 0 0 0
41013 - 0 0 0 0 0 0 0 0 0 0 0 0
41014 - 0 0 0 0 0 0 0 0 0 0 0 0
41015 - 0 0 0 0 0 0 0 0 0 0 0 0
41016 - 0 0 0 0 0 0 0 0 0 0 0 0
41017 - 0 0 0 0 0 0 0 0 0 0 0 0
41018 - 0 0 0 0 0 0 6 6 6 18 18 18
41019 - 54 54 54 62 62 62 2 2 6 2 2 6
41020 - 2 2 6 30 30 30 46 46 46 70 70 70
41021 -250 250 250 253 253 253 253 253 253 253 253 253
41022 -253 253 253 253 253 253 253 253 253 253 253 253
41023 -253 253 253 253 253 253 231 231 231 246 246 246
41024 -253 253 253 253 253 253 253 253 253 253 253 253
41025 -253 253 253 253 253 253 253 253 253 253 253 253
41026 -253 253 253 253 253 253 253 253 253 253 253 253
41027 -253 253 253 253 253 253 253 253 253 253 253 253
41028 -253 253 253 253 253 253 226 226 226 10 10 10
41029 - 2 2 6 6 6 6 30 30 30 2 2 6
41030 - 2 2 6 2 2 6 2 2 6 2 2 6
41031 - 2 2 6 66 66 66 58 58 58 22 22 22
41032 - 6 6 6 0 0 0 0 0 0 0 0 0
41033 - 0 0 0 0 0 0 0 0 0 0 0 0
41034 - 0 0 0 0 0 0 0 0 0 0 0 0
41035 - 0 0 0 0 0 0 0 0 0 0 0 0
41036 - 0 0 0 0 0 0 0 0 0 0 0 0
41037 - 0 0 0 0 0 0 0 0 0 0 0 0
41038 - 0 0 0 0 0 0 6 6 6 22 22 22
41039 - 58 58 58 62 62 62 2 2 6 2 2 6
41040 - 2 2 6 2 2 6 30 30 30 78 78 78
41041 -250 250 250 253 253 253 253 253 253 253 253 253
41042 -253 253 253 253 253 253 253 253 253 253 253 253
41043 -253 253 253 253 253 253 231 231 231 246 246 246
41044 -253 253 253 253 253 253 253 253 253 253 253 253
41045 -253 253 253 253 253 253 253 253 253 253 253 253
41046 -253 253 253 253 253 253 253 253 253 253 253 253
41047 -253 253 253 253 253 253 253 253 253 253 253 253
41048 -253 253 253 253 253 253 206 206 206 2 2 6
41049 - 22 22 22 34 34 34 18 14 6 22 22 22
41050 - 26 26 26 18 18 18 6 6 6 2 2 6
41051 - 2 2 6 82 82 82 54 54 54 18 18 18
41052 - 6 6 6 0 0 0 0 0 0 0 0 0
41053 - 0 0 0 0 0 0 0 0 0 0 0 0
41054 - 0 0 0 0 0 0 0 0 0 0 0 0
41055 - 0 0 0 0 0 0 0 0 0 0 0 0
41056 - 0 0 0 0 0 0 0 0 0 0 0 0
41057 - 0 0 0 0 0 0 0 0 0 0 0 0
41058 - 0 0 0 0 0 0 6 6 6 26 26 26
41059 - 62 62 62 106 106 106 74 54 14 185 133 11
41060 -210 162 10 121 92 8 6 6 6 62 62 62
41061 -238 238 238 253 253 253 253 253 253 253 253 253
41062 -253 253 253 253 253 253 253 253 253 253 253 253
41063 -253 253 253 253 253 253 231 231 231 246 246 246
41064 -253 253 253 253 253 253 253 253 253 253 253 253
41065 -253 253 253 253 253 253 253 253 253 253 253 253
41066 -253 253 253 253 253 253 253 253 253 253 253 253
41067 -253 253 253 253 253 253 253 253 253 253 253 253
41068 -253 253 253 253 253 253 158 158 158 18 18 18
41069 - 14 14 14 2 2 6 2 2 6 2 2 6
41070 - 6 6 6 18 18 18 66 66 66 38 38 38
41071 - 6 6 6 94 94 94 50 50 50 18 18 18
41072 - 6 6 6 0 0 0 0 0 0 0 0 0
41073 - 0 0 0 0 0 0 0 0 0 0 0 0
41074 - 0 0 0 0 0 0 0 0 0 0 0 0
41075 - 0 0 0 0 0 0 0 0 0 0 0 0
41076 - 0 0 0 0 0 0 0 0 0 0 0 0
41077 - 0 0 0 0 0 0 0 0 0 6 6 6
41078 - 10 10 10 10 10 10 18 18 18 38 38 38
41079 - 78 78 78 142 134 106 216 158 10 242 186 14
41080 -246 190 14 246 190 14 156 118 10 10 10 10
41081 - 90 90 90 238 238 238 253 253 253 253 253 253
41082 -253 253 253 253 253 253 253 253 253 253 253 253
41083 -253 253 253 253 253 253 231 231 231 250 250 250
41084 -253 253 253 253 253 253 253 253 253 253 253 253
41085 -253 253 253 253 253 253 253 253 253 253 253 253
41086 -253 253 253 253 253 253 253 253 253 253 253 253
41087 -253 253 253 253 253 253 253 253 253 246 230 190
41088 -238 204 91 238 204 91 181 142 44 37 26 9
41089 - 2 2 6 2 2 6 2 2 6 2 2 6
41090 - 2 2 6 2 2 6 38 38 38 46 46 46
41091 - 26 26 26 106 106 106 54 54 54 18 18 18
41092 - 6 6 6 0 0 0 0 0 0 0 0 0
41093 - 0 0 0 0 0 0 0 0 0 0 0 0
41094 - 0 0 0 0 0 0 0 0 0 0 0 0
41095 - 0 0 0 0 0 0 0 0 0 0 0 0
41096 - 0 0 0 0 0 0 0 0 0 0 0 0
41097 - 0 0 0 6 6 6 14 14 14 22 22 22
41098 - 30 30 30 38 38 38 50 50 50 70 70 70
41099 -106 106 106 190 142 34 226 170 11 242 186 14
41100 -246 190 14 246 190 14 246 190 14 154 114 10
41101 - 6 6 6 74 74 74 226 226 226 253 253 253
41102 -253 253 253 253 253 253 253 253 253 253 253 253
41103 -253 253 253 253 253 253 231 231 231 250 250 250
41104 -253 253 253 253 253 253 253 253 253 253 253 253
41105 -253 253 253 253 253 253 253 253 253 253 253 253
41106 -253 253 253 253 253 253 253 253 253 253 253 253
41107 -253 253 253 253 253 253 253 253 253 228 184 62
41108 -241 196 14 241 208 19 232 195 16 38 30 10
41109 - 2 2 6 2 2 6 2 2 6 2 2 6
41110 - 2 2 6 6 6 6 30 30 30 26 26 26
41111 -203 166 17 154 142 90 66 66 66 26 26 26
41112 - 6 6 6 0 0 0 0 0 0 0 0 0
41113 - 0 0 0 0 0 0 0 0 0 0 0 0
41114 - 0 0 0 0 0 0 0 0 0 0 0 0
41115 - 0 0 0 0 0 0 0 0 0 0 0 0
41116 - 0 0 0 0 0 0 0 0 0 0 0 0
41117 - 6 6 6 18 18 18 38 38 38 58 58 58
41118 - 78 78 78 86 86 86 101 101 101 123 123 123
41119 -175 146 61 210 150 10 234 174 13 246 186 14
41120 -246 190 14 246 190 14 246 190 14 238 190 10
41121 -102 78 10 2 2 6 46 46 46 198 198 198
41122 -253 253 253 253 253 253 253 253 253 253 253 253
41123 -253 253 253 253 253 253 234 234 234 242 242 242
41124 -253 253 253 253 253 253 253 253 253 253 253 253
41125 -253 253 253 253 253 253 253 253 253 253 253 253
41126 -253 253 253 253 253 253 253 253 253 253 253 253
41127 -253 253 253 253 253 253 253 253 253 224 178 62
41128 -242 186 14 241 196 14 210 166 10 22 18 6
41129 - 2 2 6 2 2 6 2 2 6 2 2 6
41130 - 2 2 6 2 2 6 6 6 6 121 92 8
41131 -238 202 15 232 195 16 82 82 82 34 34 34
41132 - 10 10 10 0 0 0 0 0 0 0 0 0
41133 - 0 0 0 0 0 0 0 0 0 0 0 0
41134 - 0 0 0 0 0 0 0 0 0 0 0 0
41135 - 0 0 0 0 0 0 0 0 0 0 0 0
41136 - 0 0 0 0 0 0 0 0 0 0 0 0
41137 - 14 14 14 38 38 38 70 70 70 154 122 46
41138 -190 142 34 200 144 11 197 138 11 197 138 11
41139 -213 154 11 226 170 11 242 186 14 246 190 14
41140 -246 190 14 246 190 14 246 190 14 246 190 14
41141 -225 175 15 46 32 6 2 2 6 22 22 22
41142 -158 158 158 250 250 250 253 253 253 253 253 253
41143 -253 253 253 253 253 253 253 253 253 253 253 253
41144 -253 253 253 253 253 253 253 253 253 253 253 253
41145 -253 253 253 253 253 253 253 253 253 253 253 253
41146 -253 253 253 253 253 253 253 253 253 253 253 253
41147 -253 253 253 250 250 250 242 242 242 224 178 62
41148 -239 182 13 236 186 11 213 154 11 46 32 6
41149 - 2 2 6 2 2 6 2 2 6 2 2 6
41150 - 2 2 6 2 2 6 61 42 6 225 175 15
41151 -238 190 10 236 186 11 112 100 78 42 42 42
41152 - 14 14 14 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 0 0 0 0 0 0
41156 - 0 0 0 0 0 0 0 0 0 6 6 6
41157 - 22 22 22 54 54 54 154 122 46 213 154 11
41158 -226 170 11 230 174 11 226 170 11 226 170 11
41159 -236 178 12 242 186 14 246 190 14 246 190 14
41160 -246 190 14 246 190 14 246 190 14 246 190 14
41161 -241 196 14 184 144 12 10 10 10 2 2 6
41162 - 6 6 6 116 116 116 242 242 242 253 253 253
41163 -253 253 253 253 253 253 253 253 253 253 253 253
41164 -253 253 253 253 253 253 253 253 253 253 253 253
41165 -253 253 253 253 253 253 253 253 253 253 253 253
41166 -253 253 253 253 253 253 253 253 253 253 253 253
41167 -253 253 253 231 231 231 198 198 198 214 170 54
41168 -236 178 12 236 178 12 210 150 10 137 92 6
41169 - 18 14 6 2 2 6 2 2 6 2 2 6
41170 - 6 6 6 70 47 6 200 144 11 236 178 12
41171 -239 182 13 239 182 13 124 112 88 58 58 58
41172 - 22 22 22 6 6 6 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 0 0 0
41176 - 0 0 0 0 0 0 0 0 0 10 10 10
41177 - 30 30 30 70 70 70 180 133 36 226 170 11
41178 -239 182 13 242 186 14 242 186 14 246 186 14
41179 -246 190 14 246 190 14 246 190 14 246 190 14
41180 -246 190 14 246 190 14 246 190 14 246 190 14
41181 -246 190 14 232 195 16 98 70 6 2 2 6
41182 - 2 2 6 2 2 6 66 66 66 221 221 221
41183 -253 253 253 253 253 253 253 253 253 253 253 253
41184 -253 253 253 253 253 253 253 253 253 253 253 253
41185 -253 253 253 253 253 253 253 253 253 253 253 253
41186 -253 253 253 253 253 253 253 253 253 253 253 253
41187 -253 253 253 206 206 206 198 198 198 214 166 58
41188 -230 174 11 230 174 11 216 158 10 192 133 9
41189 -163 110 8 116 81 8 102 78 10 116 81 8
41190 -167 114 7 197 138 11 226 170 11 239 182 13
41191 -242 186 14 242 186 14 162 146 94 78 78 78
41192 - 34 34 34 14 14 14 6 6 6 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 0 0 0
41196 - 0 0 0 0 0 0 0 0 0 6 6 6
41197 - 30 30 30 78 78 78 190 142 34 226 170 11
41198 -239 182 13 246 190 14 246 190 14 246 190 14
41199 -246 190 14 246 190 14 246 190 14 246 190 14
41200 -246 190 14 246 190 14 246 190 14 246 190 14
41201 -246 190 14 241 196 14 203 166 17 22 18 6
41202 - 2 2 6 2 2 6 2 2 6 38 38 38
41203 -218 218 218 253 253 253 253 253 253 253 253 253
41204 -253 253 253 253 253 253 253 253 253 253 253 253
41205 -253 253 253 253 253 253 253 253 253 253 253 253
41206 -253 253 253 253 253 253 253 253 253 253 253 253
41207 -250 250 250 206 206 206 198 198 198 202 162 69
41208 -226 170 11 236 178 12 224 166 10 210 150 10
41209 -200 144 11 197 138 11 192 133 9 197 138 11
41210 -210 150 10 226 170 11 242 186 14 246 190 14
41211 -246 190 14 246 186 14 225 175 15 124 112 88
41212 - 62 62 62 30 30 30 14 14 14 6 6 6
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 - 0 0 0 0 0 0 0 0 0 10 10 10
41217 - 30 30 30 78 78 78 174 135 50 224 166 10
41218 -239 182 13 246 190 14 246 190 14 246 190 14
41219 -246 190 14 246 190 14 246 190 14 246 190 14
41220 -246 190 14 246 190 14 246 190 14 246 190 14
41221 -246 190 14 246 190 14 241 196 14 139 102 15
41222 - 2 2 6 2 2 6 2 2 6 2 2 6
41223 - 78 78 78 250 250 250 253 253 253 253 253 253
41224 -253 253 253 253 253 253 253 253 253 253 253 253
41225 -253 253 253 253 253 253 253 253 253 253 253 253
41226 -253 253 253 253 253 253 253 253 253 253 253 253
41227 -250 250 250 214 214 214 198 198 198 190 150 46
41228 -219 162 10 236 178 12 234 174 13 224 166 10
41229 -216 158 10 213 154 11 213 154 11 216 158 10
41230 -226 170 11 239 182 13 246 190 14 246 190 14
41231 -246 190 14 246 190 14 242 186 14 206 162 42
41232 -101 101 101 58 58 58 30 30 30 14 14 14
41233 - 6 6 6 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 0 0 0 10 10 10
41237 - 30 30 30 74 74 74 174 135 50 216 158 10
41238 -236 178 12 246 190 14 246 190 14 246 190 14
41239 -246 190 14 246 190 14 246 190 14 246 190 14
41240 -246 190 14 246 190 14 246 190 14 246 190 14
41241 -246 190 14 246 190 14 241 196 14 226 184 13
41242 - 61 42 6 2 2 6 2 2 6 2 2 6
41243 - 22 22 22 238 238 238 253 253 253 253 253 253
41244 -253 253 253 253 253 253 253 253 253 253 253 253
41245 -253 253 253 253 253 253 253 253 253 253 253 253
41246 -253 253 253 253 253 253 253 253 253 253 253 253
41247 -253 253 253 226 226 226 187 187 187 180 133 36
41248 -216 158 10 236 178 12 239 182 13 236 178 12
41249 -230 174 11 226 170 11 226 170 11 230 174 11
41250 -236 178 12 242 186 14 246 190 14 246 190 14
41251 -246 190 14 246 190 14 246 186 14 239 182 13
41252 -206 162 42 106 106 106 66 66 66 34 34 34
41253 - 14 14 14 6 6 6 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 6 6 6
41257 - 26 26 26 70 70 70 163 133 67 213 154 11
41258 -236 178 12 246 190 14 246 190 14 246 190 14
41259 -246 190 14 246 190 14 246 190 14 246 190 14
41260 -246 190 14 246 190 14 246 190 14 246 190 14
41261 -246 190 14 246 190 14 246 190 14 241 196 14
41262 -190 146 13 18 14 6 2 2 6 2 2 6
41263 - 46 46 46 246 246 246 253 253 253 253 253 253
41264 -253 253 253 253 253 253 253 253 253 253 253 253
41265 -253 253 253 253 253 253 253 253 253 253 253 253
41266 -253 253 253 253 253 253 253 253 253 253 253 253
41267 -253 253 253 221 221 221 86 86 86 156 107 11
41268 -216 158 10 236 178 12 242 186 14 246 186 14
41269 -242 186 14 239 182 13 239 182 13 242 186 14
41270 -242 186 14 246 186 14 246 190 14 246 190 14
41271 -246 190 14 246 190 14 246 190 14 246 190 14
41272 -242 186 14 225 175 15 142 122 72 66 66 66
41273 - 30 30 30 10 10 10 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 6 6 6
41277 - 26 26 26 70 70 70 163 133 67 210 150 10
41278 -236 178 12 246 190 14 246 190 14 246 190 14
41279 -246 190 14 246 190 14 246 190 14 246 190 14
41280 -246 190 14 246 190 14 246 190 14 246 190 14
41281 -246 190 14 246 190 14 246 190 14 246 190 14
41282 -232 195 16 121 92 8 34 34 34 106 106 106
41283 -221 221 221 253 253 253 253 253 253 253 253 253
41284 -253 253 253 253 253 253 253 253 253 253 253 253
41285 -253 253 253 253 253 253 253 253 253 253 253 253
41286 -253 253 253 253 253 253 253 253 253 253 253 253
41287 -242 242 242 82 82 82 18 14 6 163 110 8
41288 -216 158 10 236 178 12 242 186 14 246 190 14
41289 -246 190 14 246 190 14 246 190 14 246 190 14
41290 -246 190 14 246 190 14 246 190 14 246 190 14
41291 -246 190 14 246 190 14 246 190 14 246 190 14
41292 -246 190 14 246 190 14 242 186 14 163 133 67
41293 - 46 46 46 18 18 18 6 6 6 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 10 10 10
41297 - 30 30 30 78 78 78 163 133 67 210 150 10
41298 -236 178 12 246 186 14 246 190 14 246 190 14
41299 -246 190 14 246 190 14 246 190 14 246 190 14
41300 -246 190 14 246 190 14 246 190 14 246 190 14
41301 -246 190 14 246 190 14 246 190 14 246 190 14
41302 -241 196 14 215 174 15 190 178 144 253 253 253
41303 -253 253 253 253 253 253 253 253 253 253 253 253
41304 -253 253 253 253 253 253 253 253 253 253 253 253
41305 -253 253 253 253 253 253 253 253 253 253 253 253
41306 -253 253 253 253 253 253 253 253 253 218 218 218
41307 - 58 58 58 2 2 6 22 18 6 167 114 7
41308 -216 158 10 236 178 12 246 186 14 246 190 14
41309 -246 190 14 246 190 14 246 190 14 246 190 14
41310 -246 190 14 246 190 14 246 190 14 246 190 14
41311 -246 190 14 246 190 14 246 190 14 246 190 14
41312 -246 190 14 246 186 14 242 186 14 190 150 46
41313 - 54 54 54 22 22 22 6 6 6 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 14 14 14
41317 - 38 38 38 86 86 86 180 133 36 213 154 11
41318 -236 178 12 246 186 14 246 190 14 246 190 14
41319 -246 190 14 246 190 14 246 190 14 246 190 14
41320 -246 190 14 246 190 14 246 190 14 246 190 14
41321 -246 190 14 246 190 14 246 190 14 246 190 14
41322 -246 190 14 232 195 16 190 146 13 214 214 214
41323 -253 253 253 253 253 253 253 253 253 253 253 253
41324 -253 253 253 253 253 253 253 253 253 253 253 253
41325 -253 253 253 253 253 253 253 253 253 253 253 253
41326 -253 253 253 250 250 250 170 170 170 26 26 26
41327 - 2 2 6 2 2 6 37 26 9 163 110 8
41328 -219 162 10 239 182 13 246 186 14 246 190 14
41329 -246 190 14 246 190 14 246 190 14 246 190 14
41330 -246 190 14 246 190 14 246 190 14 246 190 14
41331 -246 190 14 246 190 14 246 190 14 246 190 14
41332 -246 186 14 236 178 12 224 166 10 142 122 72
41333 - 46 46 46 18 18 18 6 6 6 0 0 0
41334 - 0 0 0 0 0 0 0 0 0 0 0 0
41335 - 0 0 0 0 0 0 0 0 0 0 0 0
41336 - 0 0 0 0 0 0 6 6 6 18 18 18
41337 - 50 50 50 109 106 95 192 133 9 224 166 10
41338 -242 186 14 246 190 14 246 190 14 246 190 14
41339 -246 190 14 246 190 14 246 190 14 246 190 14
41340 -246 190 14 246 190 14 246 190 14 246 190 14
41341 -246 190 14 246 190 14 246 190 14 246 190 14
41342 -242 186 14 226 184 13 210 162 10 142 110 46
41343 -226 226 226 253 253 253 253 253 253 253 253 253
41344 -253 253 253 253 253 253 253 253 253 253 253 253
41345 -253 253 253 253 253 253 253 253 253 253 253 253
41346 -198 198 198 66 66 66 2 2 6 2 2 6
41347 - 2 2 6 2 2 6 50 34 6 156 107 11
41348 -219 162 10 239 182 13 246 186 14 246 190 14
41349 -246 190 14 246 190 14 246 190 14 246 190 14
41350 -246 190 14 246 190 14 246 190 14 246 190 14
41351 -246 190 14 246 190 14 246 190 14 242 186 14
41352 -234 174 13 213 154 11 154 122 46 66 66 66
41353 - 30 30 30 10 10 10 0 0 0 0 0 0
41354 - 0 0 0 0 0 0 0 0 0 0 0 0
41355 - 0 0 0 0 0 0 0 0 0 0 0 0
41356 - 0 0 0 0 0 0 6 6 6 22 22 22
41357 - 58 58 58 154 121 60 206 145 10 234 174 13
41358 -242 186 14 246 186 14 246 190 14 246 190 14
41359 -246 190 14 246 190 14 246 190 14 246 190 14
41360 -246 190 14 246 190 14 246 190 14 246 190 14
41361 -246 190 14 246 190 14 246 190 14 246 190 14
41362 -246 186 14 236 178 12 210 162 10 163 110 8
41363 - 61 42 6 138 138 138 218 218 218 250 250 250
41364 -253 253 253 253 253 253 253 253 253 250 250 250
41365 -242 242 242 210 210 210 144 144 144 66 66 66
41366 - 6 6 6 2 2 6 2 2 6 2 2 6
41367 - 2 2 6 2 2 6 61 42 6 163 110 8
41368 -216 158 10 236 178 12 246 190 14 246 190 14
41369 -246 190 14 246 190 14 246 190 14 246 190 14
41370 -246 190 14 246 190 14 246 190 14 246 190 14
41371 -246 190 14 239 182 13 230 174 11 216 158 10
41372 -190 142 34 124 112 88 70 70 70 38 38 38
41373 - 18 18 18 6 6 6 0 0 0 0 0 0
41374 - 0 0 0 0 0 0 0 0 0 0 0 0
41375 - 0 0 0 0 0 0 0 0 0 0 0 0
41376 - 0 0 0 0 0 0 6 6 6 22 22 22
41377 - 62 62 62 168 124 44 206 145 10 224 166 10
41378 -236 178 12 239 182 13 242 186 14 242 186 14
41379 -246 186 14 246 190 14 246 190 14 246 190 14
41380 -246 190 14 246 190 14 246 190 14 246 190 14
41381 -246 190 14 246 190 14 246 190 14 246 190 14
41382 -246 190 14 236 178 12 216 158 10 175 118 6
41383 - 80 54 7 2 2 6 6 6 6 30 30 30
41384 - 54 54 54 62 62 62 50 50 50 38 38 38
41385 - 14 14 14 2 2 6 2 2 6 2 2 6
41386 - 2 2 6 2 2 6 2 2 6 2 2 6
41387 - 2 2 6 6 6 6 80 54 7 167 114 7
41388 -213 154 11 236 178 12 246 190 14 246 190 14
41389 -246 190 14 246 190 14 246 190 14 246 190 14
41390 -246 190 14 242 186 14 239 182 13 239 182 13
41391 -230 174 11 210 150 10 174 135 50 124 112 88
41392 - 82 82 82 54 54 54 34 34 34 18 18 18
41393 - 6 6 6 0 0 0 0 0 0 0 0 0
41394 - 0 0 0 0 0 0 0 0 0 0 0 0
41395 - 0 0 0 0 0 0 0 0 0 0 0 0
41396 - 0 0 0 0 0 0 6 6 6 18 18 18
41397 - 50 50 50 158 118 36 192 133 9 200 144 11
41398 -216 158 10 219 162 10 224 166 10 226 170 11
41399 -230 174 11 236 178 12 239 182 13 239 182 13
41400 -242 186 14 246 186 14 246 190 14 246 190 14
41401 -246 190 14 246 190 14 246 190 14 246 190 14
41402 -246 186 14 230 174 11 210 150 10 163 110 8
41403 -104 69 6 10 10 10 2 2 6 2 2 6
41404 - 2 2 6 2 2 6 2 2 6 2 2 6
41405 - 2 2 6 2 2 6 2 2 6 2 2 6
41406 - 2 2 6 2 2 6 2 2 6 2 2 6
41407 - 2 2 6 6 6 6 91 60 6 167 114 7
41408 -206 145 10 230 174 11 242 186 14 246 190 14
41409 -246 190 14 246 190 14 246 186 14 242 186 14
41410 -239 182 13 230 174 11 224 166 10 213 154 11
41411 -180 133 36 124 112 88 86 86 86 58 58 58
41412 - 38 38 38 22 22 22 10 10 10 6 6 6
41413 - 0 0 0 0 0 0 0 0 0 0 0 0
41414 - 0 0 0 0 0 0 0 0 0 0 0 0
41415 - 0 0 0 0 0 0 0 0 0 0 0 0
41416 - 0 0 0 0 0 0 0 0 0 14 14 14
41417 - 34 34 34 70 70 70 138 110 50 158 118 36
41418 -167 114 7 180 123 7 192 133 9 197 138 11
41419 -200 144 11 206 145 10 213 154 11 219 162 10
41420 -224 166 10 230 174 11 239 182 13 242 186 14
41421 -246 186 14 246 186 14 246 186 14 246 186 14
41422 -239 182 13 216 158 10 185 133 11 152 99 6
41423 -104 69 6 18 14 6 2 2 6 2 2 6
41424 - 2 2 6 2 2 6 2 2 6 2 2 6
41425 - 2 2 6 2 2 6 2 2 6 2 2 6
41426 - 2 2 6 2 2 6 2 2 6 2 2 6
41427 - 2 2 6 6 6 6 80 54 7 152 99 6
41428 -192 133 9 219 162 10 236 178 12 239 182 13
41429 -246 186 14 242 186 14 239 182 13 236 178 12
41430 -224 166 10 206 145 10 192 133 9 154 121 60
41431 - 94 94 94 62 62 62 42 42 42 22 22 22
41432 - 14 14 14 6 6 6 0 0 0 0 0 0
41433 - 0 0 0 0 0 0 0 0 0 0 0 0
41434 - 0 0 0 0 0 0 0 0 0 0 0 0
41435 - 0 0 0 0 0 0 0 0 0 0 0 0
41436 - 0 0 0 0 0 0 0 0 0 6 6 6
41437 - 18 18 18 34 34 34 58 58 58 78 78 78
41438 -101 98 89 124 112 88 142 110 46 156 107 11
41439 -163 110 8 167 114 7 175 118 6 180 123 7
41440 -185 133 11 197 138 11 210 150 10 219 162 10
41441 -226 170 11 236 178 12 236 178 12 234 174 13
41442 -219 162 10 197 138 11 163 110 8 130 83 6
41443 - 91 60 6 10 10 10 2 2 6 2 2 6
41444 - 18 18 18 38 38 38 38 38 38 38 38 38
41445 - 38 38 38 38 38 38 38 38 38 38 38 38
41446 - 38 38 38 38 38 38 26 26 26 2 2 6
41447 - 2 2 6 6 6 6 70 47 6 137 92 6
41448 -175 118 6 200 144 11 219 162 10 230 174 11
41449 -234 174 13 230 174 11 219 162 10 210 150 10
41450 -192 133 9 163 110 8 124 112 88 82 82 82
41451 - 50 50 50 30 30 30 14 14 14 6 6 6
41452 - 0 0 0 0 0 0 0 0 0 0 0 0
41453 - 0 0 0 0 0 0 0 0 0 0 0 0
41454 - 0 0 0 0 0 0 0 0 0 0 0 0
41455 - 0 0 0 0 0 0 0 0 0 0 0 0
41456 - 0 0 0 0 0 0 0 0 0 0 0 0
41457 - 6 6 6 14 14 14 22 22 22 34 34 34
41458 - 42 42 42 58 58 58 74 74 74 86 86 86
41459 -101 98 89 122 102 70 130 98 46 121 87 25
41460 -137 92 6 152 99 6 163 110 8 180 123 7
41461 -185 133 11 197 138 11 206 145 10 200 144 11
41462 -180 123 7 156 107 11 130 83 6 104 69 6
41463 - 50 34 6 54 54 54 110 110 110 101 98 89
41464 - 86 86 86 82 82 82 78 78 78 78 78 78
41465 - 78 78 78 78 78 78 78 78 78 78 78 78
41466 - 78 78 78 82 82 82 86 86 86 94 94 94
41467 -106 106 106 101 101 101 86 66 34 124 80 6
41468 -156 107 11 180 123 7 192 133 9 200 144 11
41469 -206 145 10 200 144 11 192 133 9 175 118 6
41470 -139 102 15 109 106 95 70 70 70 42 42 42
41471 - 22 22 22 10 10 10 0 0 0 0 0 0
41472 - 0 0 0 0 0 0 0 0 0 0 0 0
41473 - 0 0 0 0 0 0 0 0 0 0 0 0
41474 - 0 0 0 0 0 0 0 0 0 0 0 0
41475 - 0 0 0 0 0 0 0 0 0 0 0 0
41476 - 0 0 0 0 0 0 0 0 0 0 0 0
41477 - 0 0 0 0 0 0 6 6 6 10 10 10
41478 - 14 14 14 22 22 22 30 30 30 38 38 38
41479 - 50 50 50 62 62 62 74 74 74 90 90 90
41480 -101 98 89 112 100 78 121 87 25 124 80 6
41481 -137 92 6 152 99 6 152 99 6 152 99 6
41482 -138 86 6 124 80 6 98 70 6 86 66 30
41483 -101 98 89 82 82 82 58 58 58 46 46 46
41484 - 38 38 38 34 34 34 34 34 34 34 34 34
41485 - 34 34 34 34 34 34 34 34 34 34 34 34
41486 - 34 34 34 34 34 34 38 38 38 42 42 42
41487 - 54 54 54 82 82 82 94 86 76 91 60 6
41488 -134 86 6 156 107 11 167 114 7 175 118 6
41489 -175 118 6 167 114 7 152 99 6 121 87 25
41490 -101 98 89 62 62 62 34 34 34 18 18 18
41491 - 6 6 6 0 0 0 0 0 0 0 0 0
41492 - 0 0 0 0 0 0 0 0 0 0 0 0
41493 - 0 0 0 0 0 0 0 0 0 0 0 0
41494 - 0 0 0 0 0 0 0 0 0 0 0 0
41495 - 0 0 0 0 0 0 0 0 0 0 0 0
41496 - 0 0 0 0 0 0 0 0 0 0 0 0
41497 - 0 0 0 0 0 0 0 0 0 0 0 0
41498 - 0 0 0 6 6 6 6 6 6 10 10 10
41499 - 18 18 18 22 22 22 30 30 30 42 42 42
41500 - 50 50 50 66 66 66 86 86 86 101 98 89
41501 -106 86 58 98 70 6 104 69 6 104 69 6
41502 -104 69 6 91 60 6 82 62 34 90 90 90
41503 - 62 62 62 38 38 38 22 22 22 14 14 14
41504 - 10 10 10 10 10 10 10 10 10 10 10 10
41505 - 10 10 10 10 10 10 6 6 6 10 10 10
41506 - 10 10 10 10 10 10 10 10 10 14 14 14
41507 - 22 22 22 42 42 42 70 70 70 89 81 66
41508 - 80 54 7 104 69 6 124 80 6 137 92 6
41509 -134 86 6 116 81 8 100 82 52 86 86 86
41510 - 58 58 58 30 30 30 14 14 14 6 6 6
41511 - 0 0 0 0 0 0 0 0 0 0 0 0
41512 - 0 0 0 0 0 0 0 0 0 0 0 0
41513 - 0 0 0 0 0 0 0 0 0 0 0 0
41514 - 0 0 0 0 0 0 0 0 0 0 0 0
41515 - 0 0 0 0 0 0 0 0 0 0 0 0
41516 - 0 0 0 0 0 0 0 0 0 0 0 0
41517 - 0 0 0 0 0 0 0 0 0 0 0 0
41518 - 0 0 0 0 0 0 0 0 0 0 0 0
41519 - 0 0 0 6 6 6 10 10 10 14 14 14
41520 - 18 18 18 26 26 26 38 38 38 54 54 54
41521 - 70 70 70 86 86 86 94 86 76 89 81 66
41522 - 89 81 66 86 86 86 74 74 74 50 50 50
41523 - 30 30 30 14 14 14 6 6 6 0 0 0
41524 - 0 0 0 0 0 0 0 0 0 0 0 0
41525 - 0 0 0 0 0 0 0 0 0 0 0 0
41526 - 0 0 0 0 0 0 0 0 0 0 0 0
41527 - 6 6 6 18 18 18 34 34 34 58 58 58
41528 - 82 82 82 89 81 66 89 81 66 89 81 66
41529 - 94 86 66 94 86 76 74 74 74 50 50 50
41530 - 26 26 26 14 14 14 6 6 6 0 0 0
41531 - 0 0 0 0 0 0 0 0 0 0 0 0
41532 - 0 0 0 0 0 0 0 0 0 0 0 0
41533 - 0 0 0 0 0 0 0 0 0 0 0 0
41534 - 0 0 0 0 0 0 0 0 0 0 0 0
41535 - 0 0 0 0 0 0 0 0 0 0 0 0
41536 - 0 0 0 0 0 0 0 0 0 0 0 0
41537 - 0 0 0 0 0 0 0 0 0 0 0 0
41538 - 0 0 0 0 0 0 0 0 0 0 0 0
41539 - 0 0 0 0 0 0 0 0 0 0 0 0
41540 - 6 6 6 6 6 6 14 14 14 18 18 18
41541 - 30 30 30 38 38 38 46 46 46 54 54 54
41542 - 50 50 50 42 42 42 30 30 30 18 18 18
41543 - 10 10 10 0 0 0 0 0 0 0 0 0
41544 - 0 0 0 0 0 0 0 0 0 0 0 0
41545 - 0 0 0 0 0 0 0 0 0 0 0 0
41546 - 0 0 0 0 0 0 0 0 0 0 0 0
41547 - 0 0 0 6 6 6 14 14 14 26 26 26
41548 - 38 38 38 50 50 50 58 58 58 58 58 58
41549 - 54 54 54 42 42 42 30 30 30 18 18 18
41550 - 10 10 10 0 0 0 0 0 0 0 0 0
41551 - 0 0 0 0 0 0 0 0 0 0 0 0
41552 - 0 0 0 0 0 0 0 0 0 0 0 0
41553 - 0 0 0 0 0 0 0 0 0 0 0 0
41554 - 0 0 0 0 0 0 0 0 0 0 0 0
41555 - 0 0 0 0 0 0 0 0 0 0 0 0
41556 - 0 0 0 0 0 0 0 0 0 0 0 0
41557 - 0 0 0 0 0 0 0 0 0 0 0 0
41558 - 0 0 0 0 0 0 0 0 0 0 0 0
41559 - 0 0 0 0 0 0 0 0 0 0 0 0
41560 - 0 0 0 0 0 0 0 0 0 6 6 6
41561 - 6 6 6 10 10 10 14 14 14 18 18 18
41562 - 18 18 18 14 14 14 10 10 10 6 6 6
41563 - 0 0 0 0 0 0 0 0 0 0 0 0
41564 - 0 0 0 0 0 0 0 0 0 0 0 0
41565 - 0 0 0 0 0 0 0 0 0 0 0 0
41566 - 0 0 0 0 0 0 0 0 0 0 0 0
41567 - 0 0 0 0 0 0 0 0 0 6 6 6
41568 - 14 14 14 18 18 18 22 22 22 22 22 22
41569 - 18 18 18 14 14 14 10 10 10 6 6 6
41570 - 0 0 0 0 0 0 0 0 0 0 0 0
41571 - 0 0 0 0 0 0 0 0 0 0 0 0
41572 - 0 0 0 0 0 0 0 0 0 0 0 0
41573 - 0 0 0 0 0 0 0 0 0 0 0 0
41574 - 0 0 0 0 0 0 0 0 0 0 0 0
41575 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41576 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41577 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41578 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41579 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41580 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41581 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41582 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41583 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41584 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41585 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41586 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41587 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41588 +4 4 4 4 4 4
41589 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41590 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41591 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41592 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41593 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41594 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41595 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41596 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41597 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41598 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41599 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41600 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41601 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41602 +4 4 4 4 4 4
41603 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41604 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41605 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41606 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41607 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41608 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41609 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41610 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41611 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41612 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41613 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41614 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41615 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41616 +4 4 4 4 4 4
41617 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41618 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41619 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41620 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41621 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41622 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41623 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41624 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41625 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41626 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41627 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41628 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41629 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41630 +4 4 4 4 4 4
41631 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41632 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41633 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41634 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41635 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41636 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41637 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41638 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41639 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41640 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41641 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41642 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41643 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41644 +4 4 4 4 4 4
41645 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41646 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41647 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41648 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41649 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41650 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41651 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41652 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41653 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41654 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41655 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41656 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41657 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41658 +4 4 4 4 4 4
41659 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41660 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41661 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41662 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41663 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
41664 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
41665 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41666 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41667 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41668 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
41669 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41670 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
41671 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41672 +4 4 4 4 4 4
41673 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41674 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41675 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41676 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41677 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
41678 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
41679 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41680 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41681 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41682 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
41683 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
41684 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
41685 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41686 +4 4 4 4 4 4
41687 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41688 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41689 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41690 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41691 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
41692 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
41693 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41694 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41695 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41696 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
41697 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
41698 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
41699 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
41700 +4 4 4 4 4 4
41701 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41702 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41703 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41704 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
41705 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
41706 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
41707 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
41708 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41709 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
41710 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
41711 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
41712 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
41713 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
41714 +4 4 4 4 4 4
41715 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41716 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41717 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41718 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
41719 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
41720 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
41721 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
41722 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41723 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
41724 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
41725 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
41726 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
41727 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
41728 +4 4 4 4 4 4
41729 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41730 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41731 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41732 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
41733 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
41734 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
41735 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
41736 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
41737 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
41738 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
41739 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
41740 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
41741 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
41742 +4 4 4 4 4 4
41743 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41744 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41745 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
41746 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
41747 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
41748 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
41749 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
41750 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
41751 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
41752 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
41753 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
41754 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
41755 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
41756 +4 4 4 4 4 4
41757 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41758 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41759 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
41760 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
41761 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
41762 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
41763 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
41764 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
41765 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
41766 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
41767 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
41768 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
41769 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
41770 +4 4 4 4 4 4
41771 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41772 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41773 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
41774 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
41775 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
41776 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
41777 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
41778 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
41779 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
41780 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
41781 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
41782 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
41783 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41784 +4 4 4 4 4 4
41785 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41786 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41787 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
41788 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
41789 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
41790 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
41791 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
41792 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
41793 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
41794 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
41795 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
41796 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
41797 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
41798 +4 4 4 4 4 4
41799 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41800 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
41801 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
41802 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
41803 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
41804 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
41805 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
41806 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
41807 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
41808 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
41809 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
41810 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
41811 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
41812 +4 4 4 4 4 4
41813 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41814 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
41815 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
41816 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
41817 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
41818 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
41819 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
41820 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
41821 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
41822 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
41823 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
41824 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
41825 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
41826 +0 0 0 4 4 4
41827 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
41828 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
41829 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
41830 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
41831 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
41832 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
41833 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
41834 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
41835 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
41836 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
41837 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
41838 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
41839 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
41840 +2 0 0 0 0 0
41841 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
41842 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
41843 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
41844 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
41845 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
41846 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
41847 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
41848 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
41849 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
41850 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
41851 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
41852 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
41853 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
41854 +37 38 37 0 0 0
41855 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
41856 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
41857 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
41858 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
41859 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
41860 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
41861 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
41862 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
41863 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
41864 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
41865 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
41866 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
41867 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
41868 +85 115 134 4 0 0
41869 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
41870 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
41871 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
41872 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
41873 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
41874 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
41875 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
41876 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
41877 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
41878 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
41879 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
41880 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
41881 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
41882 +60 73 81 4 0 0
41883 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
41884 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
41885 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
41886 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
41887 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
41888 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
41889 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
41890 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
41891 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
41892 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
41893 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
41894 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
41895 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
41896 +16 19 21 4 0 0
41897 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
41898 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
41899 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
41900 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
41901 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
41902 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
41903 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
41904 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
41905 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
41906 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
41907 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
41908 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
41909 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
41910 +4 0 0 4 3 3
41911 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
41912 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
41913 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
41914 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
41915 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
41916 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
41917 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
41918 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
41919 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
41920 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
41921 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
41922 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
41923 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
41924 +3 2 2 4 4 4
41925 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
41926 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
41927 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
41928 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
41929 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
41930 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
41931 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
41932 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
41933 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
41934 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
41935 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
41936 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
41937 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
41938 +4 4 4 4 4 4
41939 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
41940 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
41941 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
41942 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
41943 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
41944 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
41945 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
41946 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
41947 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
41948 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
41949 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
41950 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
41951 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
41952 +4 4 4 4 4 4
41953 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
41954 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
41955 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
41956 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
41957 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
41958 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41959 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
41960 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
41961 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
41962 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
41963 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
41964 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
41965 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
41966 +5 5 5 5 5 5
41967 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
41968 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
41969 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
41970 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
41971 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
41972 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41973 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
41974 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
41975 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
41976 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
41977 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
41978 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
41979 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
41980 +5 5 5 4 4 4
41981 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
41982 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
41983 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
41984 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
41985 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41986 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
41987 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
41988 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
41989 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
41990 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
41991 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
41992 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
41993 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41994 +4 4 4 4 4 4
41995 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
41996 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
41997 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
41998 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
41999 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
42000 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
42001 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
42002 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
42003 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
42004 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
42005 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
42006 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
42007 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42008 +4 4 4 4 4 4
42009 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
42010 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
42011 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
42012 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
42013 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
42014 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
42015 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
42016 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
42017 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
42018 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
42019 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
42020 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42021 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42022 +4 4 4 4 4 4
42023 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
42024 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
42025 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
42026 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
42027 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
42028 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
42029 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
42030 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
42031 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
42032 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
42033 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
42034 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42035 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42036 +4 4 4 4 4 4
42037 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
42038 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
42039 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
42040 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
42041 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
42042 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
42043 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
42044 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
42045 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
42046 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
42047 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42048 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42049 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42050 +4 4 4 4 4 4
42051 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
42052 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
42053 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
42054 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
42055 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
42056 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
42057 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
42058 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
42059 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
42060 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
42061 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
42062 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42063 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42064 +4 4 4 4 4 4
42065 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
42066 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
42067 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
42068 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
42069 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
42070 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
42071 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
42072 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
42073 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
42074 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
42075 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
42076 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42077 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42078 +4 4 4 4 4 4
42079 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
42080 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
42081 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
42082 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
42083 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
42084 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
42085 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
42086 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
42087 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
42088 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
42089 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42090 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42091 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42092 +4 4 4 4 4 4
42093 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
42094 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
42095 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
42096 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
42097 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
42098 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
42099 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
42100 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
42101 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
42102 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
42103 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42104 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42105 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42106 +4 4 4 4 4 4
42107 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
42108 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
42109 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
42110 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
42111 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
42112 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
42113 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
42114 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
42115 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
42116 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
42117 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42118 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42119 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42120 +4 4 4 4 4 4
42121 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
42122 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
42123 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
42124 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
42125 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
42126 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
42127 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
42128 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
42129 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
42130 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42131 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42132 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42133 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42134 +4 4 4 4 4 4
42135 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
42136 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
42137 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
42138 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
42139 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
42140 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
42141 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
42142 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
42143 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
42144 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42145 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42146 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42147 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42148 +4 4 4 4 4 4
42149 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
42150 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
42151 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
42152 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
42153 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
42154 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
42155 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
42156 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
42157 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
42158 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42159 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42160 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42161 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42162 +4 4 4 4 4 4
42163 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
42164 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
42165 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
42166 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
42167 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
42168 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
42169 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
42170 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
42171 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
42172 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42173 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42174 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42175 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42176 +4 4 4 4 4 4
42177 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
42178 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
42179 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
42180 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
42181 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
42182 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
42183 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
42184 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
42185 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
42186 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42187 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42188 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42189 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42190 +4 4 4 4 4 4
42191 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
42192 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
42193 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
42194 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
42195 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
42196 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
42197 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
42198 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
42199 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
42200 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42201 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42202 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42203 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42204 +4 4 4 4 4 4
42205 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
42206 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
42207 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
42208 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
42209 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
42210 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
42211 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
42212 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
42213 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
42214 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42215 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42216 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42217 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42218 +4 4 4 4 4 4
42219 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
42220 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
42221 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
42222 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
42223 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
42224 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
42225 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
42226 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
42227 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
42228 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42229 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42230 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42231 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42232 +4 4 4 4 4 4
42233 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
42234 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
42235 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
42236 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
42237 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
42238 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
42239 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
42240 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
42241 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
42242 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42243 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42244 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42245 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42246 +4 4 4 4 4 4
42247 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
42248 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
42249 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
42250 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
42251 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
42252 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
42253 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
42254 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
42255 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
42256 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42257 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42258 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42259 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42260 +4 4 4 4 4 4
42261 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
42262 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
42263 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
42264 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
42265 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
42266 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
42267 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
42268 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
42269 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
42270 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42271 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42272 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42273 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42274 +4 4 4 4 4 4
42275 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
42276 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
42277 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
42278 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
42279 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
42280 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
42281 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
42282 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
42283 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
42284 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42285 +0 0 0 3 3 3 5 5 5 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42288 +4 4 4 4 4 4
42289 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
42290 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
42291 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
42292 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
42293 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
42294 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
42295 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
42296 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
42297 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
42298 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42299 +0 0 0 3 3 3 5 5 5 4 4 4 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 4 4 4 4 4 4 4 4 4
42302 +4 4 4 4 4 4
42303 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
42304 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
42305 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
42306 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
42307 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
42308 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
42309 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
42310 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
42311 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
42312 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42313 +0 0 0 3 3 3 5 5 5 4 4 4 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 4 4 4
42317 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
42318 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
42319 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
42320 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
42321 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
42322 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
42323 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
42324 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
42325 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
42326 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42327 +0 0 0 3 3 3 5 5 5 4 4 4 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
42331 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
42332 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
42333 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
42334 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
42335 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
42336 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
42337 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
42338 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
42339 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
42340 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
42341 +0 0 0 3 3 3 5 5 5 4 4 4 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
42345 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
42346 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
42347 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
42348 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
42349 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
42350 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
42351 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
42352 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
42353 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
42354 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
42355 +0 0 0 4 4 4 4 4 4 4 4 4 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
42359 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
42360 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
42361 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
42362 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
42363 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
42364 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
42365 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42366 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
42367 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
42368 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
42369 +4 3 3 5 5 5 4 4 4 4 4 4 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
42373 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
42374 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
42375 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
42376 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
42377 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
42378 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
42379 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
42380 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
42381 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
42382 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
42383 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42384 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42385 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42386 +4 4 4 4 4 4
42387 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
42388 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
42389 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
42390 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
42391 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
42392 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
42393 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
42394 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
42395 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
42396 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
42397 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42398 +4 4 4 4 4 4 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
42401 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
42402 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
42403 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
42404 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
42405 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
42406 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
42407 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
42408 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
42409 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
42410 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
42411 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42412 +4 4 4 4 4 4 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
42415 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
42416 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
42417 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
42418 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
42419 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
42420 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
42421 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
42422 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
42423 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
42424 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
42425 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42426 +4 4 4 4 4 4 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
42429 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
42430 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
42431 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
42432 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
42433 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
42434 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
42435 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
42436 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
42437 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
42438 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42439 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42440 +4 4 4 4 4 4 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
42443 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
42444 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
42445 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
42446 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
42447 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
42448 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
42449 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
42450 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
42451 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
42452 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42453 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42454 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42455 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42456 +4 4 4 4 4 4
42457 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
42458 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
42459 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
42460 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
42461 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
42462 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
42463 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
42464 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
42465 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
42466 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42467 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42468 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42469 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42470 +4 4 4 4 4 4
42471 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
42472 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
42473 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
42474 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
42475 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
42476 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
42477 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
42478 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
42479 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42480 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42481 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42482 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42483 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42484 +4 4 4 4 4 4
42485 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
42486 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
42487 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
42488 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
42489 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
42490 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
42491 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
42492 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
42493 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42494 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42495 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42496 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42497 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42498 +4 4 4 4 4 4
42499 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
42500 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
42501 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
42502 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
42503 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
42504 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
42505 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
42506 +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
42507 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42508 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42509 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42510 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42511 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42512 +4 4 4 4 4 4
42513 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
42514 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
42515 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42516 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
42517 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
42518 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
42519 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
42520 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
42521 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42522 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42523 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42524 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42525 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42526 +4 4 4 4 4 4
42527 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42528 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
42529 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
42530 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
42531 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
42532 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
42533 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
42534 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
42535 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42536 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42537 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42538 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42539 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42540 +4 4 4 4 4 4
42541 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42542 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
42543 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
42544 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
42545 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
42546 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
42547 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
42548 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42549 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42550 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42551 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42552 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42553 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42554 +4 4 4 4 4 4
42555 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42556 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42557 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
42558 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
42559 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
42560 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
42561 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
42562 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42563 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42564 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42565 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42566 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42567 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42568 +4 4 4 4 4 4
42569 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42570 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42571 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
42572 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42573 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
42574 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
42575 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
42576 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42577 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42578 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42579 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42580 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42581 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42582 +4 4 4 4 4 4
42583 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42584 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42585 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42586 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
42587 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
42588 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
42589 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
42590 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42591 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42592 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42593 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42594 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42595 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42596 +4 4 4 4 4 4
42597 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42598 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42599 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42600 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
42601 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
42602 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
42603 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
42604 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42605 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42606 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42607 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42608 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42609 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42610 +4 4 4 4 4 4
42611 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42612 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42613 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42614 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
42615 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
42616 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
42617 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
42618 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42619 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42620 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42621 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42622 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42623 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42624 +4 4 4 4 4 4
42625 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42626 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42627 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42628 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
42629 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
42630 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42631 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42632 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42633 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42634 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42635 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42636 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42637 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42638 +4 4 4 4 4 4
42639 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42640 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42641 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42642 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42643 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
42644 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
42645 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
42646 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42647 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42648 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42649 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42650 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42651 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42652 +4 4 4 4 4 4
42653 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42654 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42655 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42656 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42657 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
42658 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
42659 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42660 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42661 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42662 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42663 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42664 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42665 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42666 +4 4 4 4 4 4
42667 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42668 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42669 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42670 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42671 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
42672 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
42673 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42674 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42675 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42676 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42677 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42678 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42679 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42680 +4 4 4 4 4 4
42681 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42682 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42683 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42684 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42685 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
42686 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
42687 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42688 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42689 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42690 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42691 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42692 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42693 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42694 +4 4 4 4 4 4
42695 diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
42696 index 38fcfff..0072dcd 100644
42697 --- a/drivers/video/udlfb.c
42698 +++ b/drivers/video/udlfb.c
42699 @@ -620,11 +620,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
42700 dlfb_urb_completion(urb);
42701
42702 error:
42703 - atomic_add(bytes_sent, &dev->bytes_sent);
42704 - atomic_add(bytes_identical, &dev->bytes_identical);
42705 - atomic_add(width*height*2, &dev->bytes_rendered);
42706 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
42707 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
42708 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
42709 end_cycles = get_cycles();
42710 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
42711 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
42712 >> 10)), /* Kcycles */
42713 &dev->cpu_kcycles_used);
42714
42715 @@ -745,11 +745,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
42716 dlfb_urb_completion(urb);
42717
42718 error:
42719 - atomic_add(bytes_sent, &dev->bytes_sent);
42720 - atomic_add(bytes_identical, &dev->bytes_identical);
42721 - atomic_add(bytes_rendered, &dev->bytes_rendered);
42722 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
42723 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
42724 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
42725 end_cycles = get_cycles();
42726 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
42727 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
42728 >> 10)), /* Kcycles */
42729 &dev->cpu_kcycles_used);
42730 }
42731 @@ -1373,7 +1373,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
42732 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42733 struct dlfb_data *dev = fb_info->par;
42734 return snprintf(buf, PAGE_SIZE, "%u\n",
42735 - atomic_read(&dev->bytes_rendered));
42736 + atomic_read_unchecked(&dev->bytes_rendered));
42737 }
42738
42739 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
42740 @@ -1381,7 +1381,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
42741 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42742 struct dlfb_data *dev = fb_info->par;
42743 return snprintf(buf, PAGE_SIZE, "%u\n",
42744 - atomic_read(&dev->bytes_identical));
42745 + atomic_read_unchecked(&dev->bytes_identical));
42746 }
42747
42748 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
42749 @@ -1389,7 +1389,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
42750 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42751 struct dlfb_data *dev = fb_info->par;
42752 return snprintf(buf, PAGE_SIZE, "%u\n",
42753 - atomic_read(&dev->bytes_sent));
42754 + atomic_read_unchecked(&dev->bytes_sent));
42755 }
42756
42757 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
42758 @@ -1397,7 +1397,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
42759 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42760 struct dlfb_data *dev = fb_info->par;
42761 return snprintf(buf, PAGE_SIZE, "%u\n",
42762 - atomic_read(&dev->cpu_kcycles_used));
42763 + atomic_read_unchecked(&dev->cpu_kcycles_used));
42764 }
42765
42766 static ssize_t edid_show(
42767 @@ -1457,10 +1457,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
42768 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42769 struct dlfb_data *dev = fb_info->par;
42770
42771 - atomic_set(&dev->bytes_rendered, 0);
42772 - atomic_set(&dev->bytes_identical, 0);
42773 - atomic_set(&dev->bytes_sent, 0);
42774 - atomic_set(&dev->cpu_kcycles_used, 0);
42775 + atomic_set_unchecked(&dev->bytes_rendered, 0);
42776 + atomic_set_unchecked(&dev->bytes_identical, 0);
42777 + atomic_set_unchecked(&dev->bytes_sent, 0);
42778 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
42779
42780 return count;
42781 }
42782 diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
42783 index b0e2a42..e2df3ad 100644
42784 --- a/drivers/video/uvesafb.c
42785 +++ b/drivers/video/uvesafb.c
42786 @@ -19,6 +19,7 @@
42787 #include <linux/io.h>
42788 #include <linux/mutex.h>
42789 #include <linux/slab.h>
42790 +#include <linux/moduleloader.h>
42791 #include <video/edid.h>
42792 #include <video/uvesafb.h>
42793 #ifdef CONFIG_X86
42794 @@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
42795 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
42796 par->pmi_setpal = par->ypan = 0;
42797 } else {
42798 +
42799 +#ifdef CONFIG_PAX_KERNEXEC
42800 +#ifdef CONFIG_MODULES
42801 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
42802 +#endif
42803 + if (!par->pmi_code) {
42804 + par->pmi_setpal = par->ypan = 0;
42805 + return 0;
42806 + }
42807 +#endif
42808 +
42809 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
42810 + task->t.regs.edi);
42811 +
42812 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42813 + pax_open_kernel();
42814 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
42815 + pax_close_kernel();
42816 +
42817 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
42818 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
42819 +#else
42820 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
42821 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
42822 +#endif
42823 +
42824 printk(KERN_INFO "uvesafb: protected mode interface info at "
42825 "%04x:%04x\n",
42826 (u16)task->t.regs.es, (u16)task->t.regs.edi);
42827 @@ -816,13 +839,14 @@ static int __devinit uvesafb_vbe_init(struct fb_info *info)
42828 par->ypan = ypan;
42829
42830 if (par->pmi_setpal || par->ypan) {
42831 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
42832 if (__supported_pte_mask & _PAGE_NX) {
42833 par->pmi_setpal = par->ypan = 0;
42834 printk(KERN_WARNING "uvesafb: NX protection is actively."
42835 "We have better not to use the PMI.\n");
42836 - } else {
42837 + } else
42838 +#endif
42839 uvesafb_vbe_getpmi(task, par);
42840 - }
42841 }
42842 #else
42843 /* The protected mode interface is not available on non-x86. */
42844 @@ -1836,6 +1860,11 @@ out:
42845 if (par->vbe_modes)
42846 kfree(par->vbe_modes);
42847
42848 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42849 + if (par->pmi_code)
42850 + module_free_exec(NULL, par->pmi_code);
42851 +#endif
42852 +
42853 framebuffer_release(info);
42854 return err;
42855 }
42856 @@ -1862,6 +1891,12 @@ static int uvesafb_remove(struct platform_device *dev)
42857 kfree(par->vbe_state_orig);
42858 if (par->vbe_state_saved)
42859 kfree(par->vbe_state_saved);
42860 +
42861 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42862 + if (par->pmi_code)
42863 + module_free_exec(NULL, par->pmi_code);
42864 +#endif
42865 +
42866 }
42867
42868 framebuffer_release(info);
42869 diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
42870 index 501b340..86bd4cf 100644
42871 --- a/drivers/video/vesafb.c
42872 +++ b/drivers/video/vesafb.c
42873 @@ -9,6 +9,7 @@
42874 */
42875
42876 #include <linux/module.h>
42877 +#include <linux/moduleloader.h>
42878 #include <linux/kernel.h>
42879 #include <linux/errno.h>
42880 #include <linux/string.h>
42881 @@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
42882 static int vram_total __initdata; /* Set total amount of memory */
42883 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
42884 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
42885 -static void (*pmi_start)(void) __read_mostly;
42886 -static void (*pmi_pal) (void) __read_mostly;
42887 +static void (*pmi_start)(void) __read_only;
42888 +static void (*pmi_pal) (void) __read_only;
42889 static int depth __read_mostly;
42890 static int vga_compat __read_mostly;
42891 /* --------------------------------------------------------------------- */
42892 @@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
42893 unsigned int size_vmode;
42894 unsigned int size_remap;
42895 unsigned int size_total;
42896 + void *pmi_code = NULL;
42897
42898 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
42899 return -ENODEV;
42900 @@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
42901 size_remap = size_total;
42902 vesafb_fix.smem_len = size_remap;
42903
42904 -#ifndef __i386__
42905 - screen_info.vesapm_seg = 0;
42906 -#endif
42907 -
42908 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
42909 printk(KERN_WARNING
42910 "vesafb: cannot reserve video memory at 0x%lx\n",
42911 @@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
42912 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
42913 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
42914
42915 +#ifdef __i386__
42916 +
42917 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42918 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
42919 + if (!pmi_code)
42920 +#elif !defined(CONFIG_PAX_KERNEXEC)
42921 + if (0)
42922 +#endif
42923 +
42924 +#endif
42925 + screen_info.vesapm_seg = 0;
42926 +
42927 if (screen_info.vesapm_seg) {
42928 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
42929 - screen_info.vesapm_seg,screen_info.vesapm_off);
42930 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
42931 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
42932 }
42933
42934 if (screen_info.vesapm_seg < 0xc000)
42935 @@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
42936
42937 if (ypan || pmi_setpal) {
42938 unsigned short *pmi_base;
42939 +
42940 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
42941 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
42942 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
42943 +
42944 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42945 + pax_open_kernel();
42946 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
42947 +#else
42948 + pmi_code = pmi_base;
42949 +#endif
42950 +
42951 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
42952 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
42953 +
42954 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42955 + pmi_start = ktva_ktla(pmi_start);
42956 + pmi_pal = ktva_ktla(pmi_pal);
42957 + pax_close_kernel();
42958 +#endif
42959 +
42960 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
42961 if (pmi_base[3]) {
42962 printk(KERN_INFO "vesafb: pmi: ports = ");
42963 @@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
42964 info->node, info->fix.id);
42965 return 0;
42966 err:
42967 +
42968 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42969 + module_free_exec(NULL, pmi_code);
42970 +#endif
42971 +
42972 if (info->screen_base)
42973 iounmap(info->screen_base);
42974 framebuffer_release(info);
42975 diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
42976 index 88714ae..16c2e11 100644
42977 --- a/drivers/video/via/via_clock.h
42978 +++ b/drivers/video/via/via_clock.h
42979 @@ -56,7 +56,7 @@ struct via_clock {
42980
42981 void (*set_engine_pll_state)(u8 state);
42982 void (*set_engine_pll)(struct via_pll_config config);
42983 -};
42984 +} __no_const;
42985
42986
42987 static inline u32 get_pll_internal_frequency(u32 ref_freq,
42988 diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
42989 index 453db0c..604973e 100644
42990 --- a/drivers/virtio/virtio_mmio.c
42991 +++ b/drivers/virtio/virtio_mmio.c
42992 @@ -521,7 +521,7 @@ static int vm_cmdline_set(const char *device,
42993
42994 resources[0].end = memparse(device, &str) - 1;
42995
42996 - processed = sscanf(str, "@%lli:%u%n:%d%n",
42997 + processed = sscanf(str, "@%lli:%llu%n:%d%n",
42998 &base, &resources[1].start, &consumed,
42999 &vm_cmdline_id, &consumed);
43000
43001 diff --git a/drivers/xen/xen-pciback/conf_space.h b/drivers/xen/xen-pciback/conf_space.h
43002 index e56c934..fc22f4b 100644
43003 --- a/drivers/xen/xen-pciback/conf_space.h
43004 +++ b/drivers/xen/xen-pciback/conf_space.h
43005 @@ -44,15 +44,15 @@ struct config_field {
43006 struct {
43007 conf_dword_write write;
43008 conf_dword_read read;
43009 - } dw;
43010 + } __no_const dw;
43011 struct {
43012 conf_word_write write;
43013 conf_word_read read;
43014 - } w;
43015 + } __no_const w;
43016 struct {
43017 conf_byte_write write;
43018 conf_byte_read read;
43019 - } b;
43020 + } __no_const b;
43021 } u;
43022 struct list_head list;
43023 };
43024 diff --git a/drivers/xen/xenbus/xenbus_dev_frontend.c b/drivers/xen/xenbus/xenbus_dev_frontend.c
43025 index 89f7625..ac72702 100644
43026 --- a/drivers/xen/xenbus/xenbus_dev_frontend.c
43027 +++ b/drivers/xen/xenbus/xenbus_dev_frontend.c
43028 @@ -458,7 +458,7 @@ static ssize_t xenbus_file_write(struct file *filp,
43029 goto out;
43030
43031 /* Can't write a xenbus message larger we can buffer */
43032 - if ((len + u->len) > sizeof(u->u.buffer)) {
43033 + if (len > sizeof(u->u.buffer) - u->len) {
43034 /* On error, dump existing buffer */
43035 u->len = 0;
43036 rc = -EINVAL;
43037 diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
43038 index fef20db..d28b1ab 100644
43039 --- a/drivers/xen/xenfs/xenstored.c
43040 +++ b/drivers/xen/xenfs/xenstored.c
43041 @@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
43042 static int xsd_kva_open(struct inode *inode, struct file *file)
43043 {
43044 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
43045 +#ifdef CONFIG_GRKERNSEC_HIDESYM
43046 + NULL);
43047 +#else
43048 xen_store_interface);
43049 +#endif
43050 +
43051 if (!file->private_data)
43052 return -ENOMEM;
43053 return 0;
43054 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
43055 index cbf9dbb..35c3af7 100644
43056 --- a/fs/9p/vfs_inode.c
43057 +++ b/fs/9p/vfs_inode.c
43058 @@ -1329,7 +1329,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
43059 void
43060 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
43061 {
43062 - char *s = nd_get_link(nd);
43063 + const char *s = nd_get_link(nd);
43064
43065 p9_debug(P9_DEBUG_VFS, " %s %s\n",
43066 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
43067 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
43068 index 0225742..1cd4732 100644
43069 --- a/fs/Kconfig.binfmt
43070 +++ b/fs/Kconfig.binfmt
43071 @@ -89,7 +89,7 @@ config HAVE_AOUT
43072
43073 config BINFMT_AOUT
43074 tristate "Kernel support for a.out and ECOFF binaries"
43075 - depends on HAVE_AOUT
43076 + depends on HAVE_AOUT && BROKEN
43077 ---help---
43078 A.out (Assembler.OUTput) is a set of formats for libraries and
43079 executables used in the earliest versions of UNIX. Linux used
43080 diff --git a/fs/aio.c b/fs/aio.c
43081 index 71f613c..9d01f1f 100644
43082 --- a/fs/aio.c
43083 +++ b/fs/aio.c
43084 @@ -111,7 +111,7 @@ static int aio_setup_ring(struct kioctx *ctx)
43085 size += sizeof(struct io_event) * nr_events;
43086 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
43087
43088 - if (nr_pages < 0)
43089 + if (nr_pages <= 0)
43090 return -EINVAL;
43091
43092 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
43093 @@ -1373,18 +1373,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
43094 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
43095 {
43096 ssize_t ret;
43097 + struct iovec iovstack;
43098
43099 #ifdef CONFIG_COMPAT
43100 if (compat)
43101 ret = compat_rw_copy_check_uvector(type,
43102 (struct compat_iovec __user *)kiocb->ki_buf,
43103 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
43104 + kiocb->ki_nbytes, 1, &iovstack,
43105 &kiocb->ki_iovec);
43106 else
43107 #endif
43108 ret = rw_copy_check_uvector(type,
43109 (struct iovec __user *)kiocb->ki_buf,
43110 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
43111 + kiocb->ki_nbytes, 1, &iovstack,
43112 &kiocb->ki_iovec);
43113 if (ret < 0)
43114 goto out;
43115 @@ -1393,6 +1394,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
43116 if (ret < 0)
43117 goto out;
43118
43119 + if (kiocb->ki_iovec == &iovstack) {
43120 + kiocb->ki_inline_vec = iovstack;
43121 + kiocb->ki_iovec = &kiocb->ki_inline_vec;
43122 + }
43123 kiocb->ki_nr_segs = kiocb->ki_nbytes;
43124 kiocb->ki_cur_seg = 0;
43125 /* ki_nbytes/left now reflect bytes instead of segs */
43126 diff --git a/fs/attr.c b/fs/attr.c
43127 index 29e38a1..2bc037b 100644
43128 --- a/fs/attr.c
43129 +++ b/fs/attr.c
43130 @@ -99,6 +99,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
43131 unsigned long limit;
43132
43133 limit = rlimit(RLIMIT_FSIZE);
43134 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
43135 if (limit != RLIM_INFINITY && offset > limit)
43136 goto out_sig;
43137 if (offset > inode->i_sb->s_maxbytes)
43138 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
43139 index da8876d..4456166 100644
43140 --- a/fs/autofs4/waitq.c
43141 +++ b/fs/autofs4/waitq.c
43142 @@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
43143 {
43144 unsigned long sigpipe, flags;
43145 mm_segment_t fs;
43146 - const char *data = (const char *)addr;
43147 + const char __user *data = (const char __force_user *)addr;
43148 ssize_t wr = 0;
43149
43150 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
43151 @@ -348,6 +348,10 @@ static int validate_request(struct autofs_wait_queue **wait,
43152 return 1;
43153 }
43154
43155 +#ifdef CONFIG_GRKERNSEC_HIDESYM
43156 +static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
43157 +#endif
43158 +
43159 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
43160 enum autofs_notify notify)
43161 {
43162 @@ -381,7 +385,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
43163
43164 /* If this is a direct mount request create a dummy name */
43165 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
43166 +#ifdef CONFIG_GRKERNSEC_HIDESYM
43167 + /* this name does get written to userland via autofs4_write() */
43168 + qstr.len = sprintf(name, "%08lx", atomic_inc_return_unchecked(&autofs_dummy_name_id));
43169 +#else
43170 qstr.len = sprintf(name, "%p", dentry);
43171 +#endif
43172 else {
43173 qstr.len = autofs4_getpath(sbi, dentry, &name);
43174 if (!qstr.len) {
43175 diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
43176 index cf7f3c6..f61080d 100644
43177 --- a/fs/befs/linuxvfs.c
43178 +++ b/fs/befs/linuxvfs.c
43179 @@ -502,7 +502,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
43180 {
43181 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
43182 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
43183 - char *link = nd_get_link(nd);
43184 + const char *link = nd_get_link(nd);
43185 if (!IS_ERR(link))
43186 kfree(link);
43187 }
43188 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
43189 index d146e18..12d1bd1 100644
43190 --- a/fs/binfmt_aout.c
43191 +++ b/fs/binfmt_aout.c
43192 @@ -16,6 +16,7 @@
43193 #include <linux/string.h>
43194 #include <linux/fs.h>
43195 #include <linux/file.h>
43196 +#include <linux/security.h>
43197 #include <linux/stat.h>
43198 #include <linux/fcntl.h>
43199 #include <linux/ptrace.h>
43200 @@ -83,6 +84,8 @@ static int aout_core_dump(struct coredump_params *cprm)
43201 #endif
43202 # define START_STACK(u) ((void __user *)u.start_stack)
43203
43204 + memset(&dump, 0, sizeof(dump));
43205 +
43206 fs = get_fs();
43207 set_fs(KERNEL_DS);
43208 has_dumped = 1;
43209 @@ -94,10 +97,12 @@ static int aout_core_dump(struct coredump_params *cprm)
43210
43211 /* If the size of the dump file exceeds the rlimit, then see what would happen
43212 if we wrote the stack, but not the data area. */
43213 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
43214 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
43215 dump.u_dsize = 0;
43216
43217 /* Make sure we have enough room to write the stack and data areas. */
43218 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
43219 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
43220 dump.u_ssize = 0;
43221
43222 @@ -231,6 +236,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
43223 rlim = rlimit(RLIMIT_DATA);
43224 if (rlim >= RLIM_INFINITY)
43225 rlim = ~0;
43226 +
43227 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
43228 if (ex.a_data + ex.a_bss > rlim)
43229 return -ENOMEM;
43230
43231 @@ -265,6 +272,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
43232
43233 install_exec_creds(bprm);
43234
43235 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43236 + current->mm->pax_flags = 0UL;
43237 +#endif
43238 +
43239 +#ifdef CONFIG_PAX_PAGEEXEC
43240 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
43241 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
43242 +
43243 +#ifdef CONFIG_PAX_EMUTRAMP
43244 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
43245 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
43246 +#endif
43247 +
43248 +#ifdef CONFIG_PAX_MPROTECT
43249 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
43250 + current->mm->pax_flags |= MF_PAX_MPROTECT;
43251 +#endif
43252 +
43253 + }
43254 +#endif
43255 +
43256 if (N_MAGIC(ex) == OMAGIC) {
43257 unsigned long text_addr, map_size;
43258 loff_t pos;
43259 @@ -330,7 +358,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
43260 }
43261
43262 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
43263 - PROT_READ | PROT_WRITE | PROT_EXEC,
43264 + PROT_READ | PROT_WRITE,
43265 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
43266 fd_offset + ex.a_text);
43267 if (error != N_DATADDR(ex)) {
43268 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
43269 index 0225fdd..0c0d35d 100644
43270 --- a/fs/binfmt_elf.c
43271 +++ b/fs/binfmt_elf.c
43272 @@ -32,6 +32,7 @@
43273 #include <linux/elf.h>
43274 #include <linux/utsname.h>
43275 #include <linux/coredump.h>
43276 +#include <linux/xattr.h>
43277 #include <asm/uaccess.h>
43278 #include <asm/param.h>
43279 #include <asm/page.h>
43280 @@ -52,6 +53,10 @@ static int elf_core_dump(struct coredump_params *cprm);
43281 #define elf_core_dump NULL
43282 #endif
43283
43284 +#ifdef CONFIG_PAX_MPROTECT
43285 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
43286 +#endif
43287 +
43288 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
43289 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
43290 #else
43291 @@ -71,6 +76,11 @@ static struct linux_binfmt elf_format = {
43292 .load_binary = load_elf_binary,
43293 .load_shlib = load_elf_library,
43294 .core_dump = elf_core_dump,
43295 +
43296 +#ifdef CONFIG_PAX_MPROTECT
43297 + .handle_mprotect= elf_handle_mprotect,
43298 +#endif
43299 +
43300 .min_coredump = ELF_EXEC_PAGESIZE,
43301 };
43302
43303 @@ -78,6 +88,8 @@ static struct linux_binfmt elf_format = {
43304
43305 static int set_brk(unsigned long start, unsigned long end)
43306 {
43307 + unsigned long e = end;
43308 +
43309 start = ELF_PAGEALIGN(start);
43310 end = ELF_PAGEALIGN(end);
43311 if (end > start) {
43312 @@ -86,7 +98,7 @@ static int set_brk(unsigned long start, unsigned long end)
43313 if (BAD_ADDR(addr))
43314 return addr;
43315 }
43316 - current->mm->start_brk = current->mm->brk = end;
43317 + current->mm->start_brk = current->mm->brk = e;
43318 return 0;
43319 }
43320
43321 @@ -147,12 +159,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
43322 elf_addr_t __user *u_rand_bytes;
43323 const char *k_platform = ELF_PLATFORM;
43324 const char *k_base_platform = ELF_BASE_PLATFORM;
43325 - unsigned char k_rand_bytes[16];
43326 + u32 k_rand_bytes[4];
43327 int items;
43328 elf_addr_t *elf_info;
43329 int ei_index = 0;
43330 const struct cred *cred = current_cred();
43331 struct vm_area_struct *vma;
43332 + unsigned long saved_auxv[AT_VECTOR_SIZE];
43333
43334 /*
43335 * In some cases (e.g. Hyper-Threading), we want to avoid L1
43336 @@ -194,8 +207,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
43337 * Generate 16 random bytes for userspace PRNG seeding.
43338 */
43339 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
43340 - u_rand_bytes = (elf_addr_t __user *)
43341 - STACK_ALLOC(p, sizeof(k_rand_bytes));
43342 + srandom32(k_rand_bytes[0] ^ random32());
43343 + srandom32(k_rand_bytes[1] ^ random32());
43344 + srandom32(k_rand_bytes[2] ^ random32());
43345 + srandom32(k_rand_bytes[3] ^ random32());
43346 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
43347 + u_rand_bytes = (elf_addr_t __user *) p;
43348 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
43349 return -EFAULT;
43350
43351 @@ -307,9 +324,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
43352 return -EFAULT;
43353 current->mm->env_end = p;
43354
43355 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
43356 +
43357 /* Put the elf_info on the stack in the right place. */
43358 sp = (elf_addr_t __user *)envp + 1;
43359 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
43360 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
43361 return -EFAULT;
43362 return 0;
43363 }
43364 @@ -373,15 +392,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
43365 an ELF header */
43366
43367 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
43368 - struct file *interpreter, unsigned long *interp_map_addr,
43369 - unsigned long no_base)
43370 + struct file *interpreter, unsigned long no_base)
43371 {
43372 struct elf_phdr *elf_phdata;
43373 struct elf_phdr *eppnt;
43374 - unsigned long load_addr = 0;
43375 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
43376 int load_addr_set = 0;
43377 unsigned long last_bss = 0, elf_bss = 0;
43378 - unsigned long error = ~0UL;
43379 + unsigned long error = -EINVAL;
43380 unsigned long total_size;
43381 int retval, i, size;
43382
43383 @@ -427,6 +445,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
43384 goto out_close;
43385 }
43386
43387 +#ifdef CONFIG_PAX_SEGMEXEC
43388 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
43389 + pax_task_size = SEGMEXEC_TASK_SIZE;
43390 +#endif
43391 +
43392 eppnt = elf_phdata;
43393 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
43394 if (eppnt->p_type == PT_LOAD) {
43395 @@ -450,8 +473,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
43396 map_addr = elf_map(interpreter, load_addr + vaddr,
43397 eppnt, elf_prot, elf_type, total_size);
43398 total_size = 0;
43399 - if (!*interp_map_addr)
43400 - *interp_map_addr = map_addr;
43401 error = map_addr;
43402 if (BAD_ADDR(map_addr))
43403 goto out_close;
43404 @@ -470,8 +491,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
43405 k = load_addr + eppnt->p_vaddr;
43406 if (BAD_ADDR(k) ||
43407 eppnt->p_filesz > eppnt->p_memsz ||
43408 - eppnt->p_memsz > TASK_SIZE ||
43409 - TASK_SIZE - eppnt->p_memsz < k) {
43410 + eppnt->p_memsz > pax_task_size ||
43411 + pax_task_size - eppnt->p_memsz < k) {
43412 error = -ENOMEM;
43413 goto out_close;
43414 }
43415 @@ -523,6 +544,315 @@ out:
43416 return error;
43417 }
43418
43419 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
43420 +#ifdef CONFIG_PAX_SOFTMODE
43421 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
43422 +{
43423 + unsigned long pax_flags = 0UL;
43424 +
43425 +#ifdef CONFIG_PAX_PAGEEXEC
43426 + if (elf_phdata->p_flags & PF_PAGEEXEC)
43427 + pax_flags |= MF_PAX_PAGEEXEC;
43428 +#endif
43429 +
43430 +#ifdef CONFIG_PAX_SEGMEXEC
43431 + if (elf_phdata->p_flags & PF_SEGMEXEC)
43432 + pax_flags |= MF_PAX_SEGMEXEC;
43433 +#endif
43434 +
43435 +#ifdef CONFIG_PAX_EMUTRAMP
43436 + if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
43437 + pax_flags |= MF_PAX_EMUTRAMP;
43438 +#endif
43439 +
43440 +#ifdef CONFIG_PAX_MPROTECT
43441 + if (elf_phdata->p_flags & PF_MPROTECT)
43442 + pax_flags |= MF_PAX_MPROTECT;
43443 +#endif
43444 +
43445 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43446 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
43447 + pax_flags |= MF_PAX_RANDMMAP;
43448 +#endif
43449 +
43450 + return pax_flags;
43451 +}
43452 +#endif
43453 +
43454 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
43455 +{
43456 + unsigned long pax_flags = 0UL;
43457 +
43458 +#ifdef CONFIG_PAX_PAGEEXEC
43459 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
43460 + pax_flags |= MF_PAX_PAGEEXEC;
43461 +#endif
43462 +
43463 +#ifdef CONFIG_PAX_SEGMEXEC
43464 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
43465 + pax_flags |= MF_PAX_SEGMEXEC;
43466 +#endif
43467 +
43468 +#ifdef CONFIG_PAX_EMUTRAMP
43469 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
43470 + pax_flags |= MF_PAX_EMUTRAMP;
43471 +#endif
43472 +
43473 +#ifdef CONFIG_PAX_MPROTECT
43474 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
43475 + pax_flags |= MF_PAX_MPROTECT;
43476 +#endif
43477 +
43478 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43479 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
43480 + pax_flags |= MF_PAX_RANDMMAP;
43481 +#endif
43482 +
43483 + return pax_flags;
43484 +}
43485 +#endif
43486 +
43487 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
43488 +#ifdef CONFIG_PAX_SOFTMODE
43489 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
43490 +{
43491 + unsigned long pax_flags = 0UL;
43492 +
43493 +#ifdef CONFIG_PAX_PAGEEXEC
43494 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
43495 + pax_flags |= MF_PAX_PAGEEXEC;
43496 +#endif
43497 +
43498 +#ifdef CONFIG_PAX_SEGMEXEC
43499 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
43500 + pax_flags |= MF_PAX_SEGMEXEC;
43501 +#endif
43502 +
43503 +#ifdef CONFIG_PAX_EMUTRAMP
43504 + if (pax_flags_softmode & MF_PAX_EMUTRAMP)
43505 + pax_flags |= MF_PAX_EMUTRAMP;
43506 +#endif
43507 +
43508 +#ifdef CONFIG_PAX_MPROTECT
43509 + if (pax_flags_softmode & MF_PAX_MPROTECT)
43510 + pax_flags |= MF_PAX_MPROTECT;
43511 +#endif
43512 +
43513 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43514 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
43515 + pax_flags |= MF_PAX_RANDMMAP;
43516 +#endif
43517 +
43518 + return pax_flags;
43519 +}
43520 +#endif
43521 +
43522 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
43523 +{
43524 + unsigned long pax_flags = 0UL;
43525 +
43526 +#ifdef CONFIG_PAX_PAGEEXEC
43527 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
43528 + pax_flags |= MF_PAX_PAGEEXEC;
43529 +#endif
43530 +
43531 +#ifdef CONFIG_PAX_SEGMEXEC
43532 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
43533 + pax_flags |= MF_PAX_SEGMEXEC;
43534 +#endif
43535 +
43536 +#ifdef CONFIG_PAX_EMUTRAMP
43537 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
43538 + pax_flags |= MF_PAX_EMUTRAMP;
43539 +#endif
43540 +
43541 +#ifdef CONFIG_PAX_MPROTECT
43542 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
43543 + pax_flags |= MF_PAX_MPROTECT;
43544 +#endif
43545 +
43546 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43547 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
43548 + pax_flags |= MF_PAX_RANDMMAP;
43549 +#endif
43550 +
43551 + return pax_flags;
43552 +}
43553 +#endif
43554 +
43555 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43556 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
43557 +{
43558 + unsigned long pax_flags = 0UL;
43559 +
43560 +#ifdef CONFIG_PAX_EI_PAX
43561 +
43562 +#ifdef CONFIG_PAX_PAGEEXEC
43563 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
43564 + pax_flags |= MF_PAX_PAGEEXEC;
43565 +#endif
43566 +
43567 +#ifdef CONFIG_PAX_SEGMEXEC
43568 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
43569 + pax_flags |= MF_PAX_SEGMEXEC;
43570 +#endif
43571 +
43572 +#ifdef CONFIG_PAX_EMUTRAMP
43573 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
43574 + pax_flags |= MF_PAX_EMUTRAMP;
43575 +#endif
43576 +
43577 +#ifdef CONFIG_PAX_MPROTECT
43578 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
43579 + pax_flags |= MF_PAX_MPROTECT;
43580 +#endif
43581 +
43582 +#ifdef CONFIG_PAX_ASLR
43583 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
43584 + pax_flags |= MF_PAX_RANDMMAP;
43585 +#endif
43586 +
43587 +#else
43588 +
43589 +#ifdef CONFIG_PAX_PAGEEXEC
43590 + pax_flags |= MF_PAX_PAGEEXEC;
43591 +#endif
43592 +
43593 +#ifdef CONFIG_PAX_SEGMEXEC
43594 + pax_flags |= MF_PAX_SEGMEXEC;
43595 +#endif
43596 +
43597 +#ifdef CONFIG_PAX_MPROTECT
43598 + pax_flags |= MF_PAX_MPROTECT;
43599 +#endif
43600 +
43601 +#ifdef CONFIG_PAX_RANDMMAP
43602 + if (randomize_va_space)
43603 + pax_flags |= MF_PAX_RANDMMAP;
43604 +#endif
43605 +
43606 +#endif
43607 +
43608 + return pax_flags;
43609 +}
43610 +
43611 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
43612 +{
43613 +
43614 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
43615 + unsigned long i;
43616 +
43617 + for (i = 0UL; i < elf_ex->e_phnum; i++)
43618 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
43619 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
43620 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
43621 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
43622 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
43623 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
43624 + return ~0UL;
43625 +
43626 +#ifdef CONFIG_PAX_SOFTMODE
43627 + if (pax_softmode)
43628 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
43629 + else
43630 +#endif
43631 +
43632 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
43633 + break;
43634 + }
43635 +#endif
43636 +
43637 + return ~0UL;
43638 +}
43639 +
43640 +static unsigned long pax_parse_xattr_pax(struct file * const file)
43641 +{
43642 +
43643 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
43644 + ssize_t xattr_size, i;
43645 + unsigned char xattr_value[5];
43646 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
43647 +
43648 + xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
43649 + if (xattr_size <= 0 || xattr_size > 5)
43650 + return ~0UL;
43651 +
43652 + for (i = 0; i < xattr_size; i++)
43653 + switch (xattr_value[i]) {
43654 + default:
43655 + return ~0UL;
43656 +
43657 +#define parse_flag(option1, option2, flag) \
43658 + case option1: \
43659 + if (pax_flags_hardmode & MF_PAX_##flag) \
43660 + return ~0UL; \
43661 + pax_flags_hardmode |= MF_PAX_##flag; \
43662 + break; \
43663 + case option2: \
43664 + if (pax_flags_softmode & MF_PAX_##flag) \
43665 + return ~0UL; \
43666 + pax_flags_softmode |= MF_PAX_##flag; \
43667 + break;
43668 +
43669 + parse_flag('p', 'P', PAGEEXEC);
43670 + parse_flag('e', 'E', EMUTRAMP);
43671 + parse_flag('m', 'M', MPROTECT);
43672 + parse_flag('r', 'R', RANDMMAP);
43673 + parse_flag('s', 'S', SEGMEXEC);
43674 +
43675 +#undef parse_flag
43676 + }
43677 +
43678 + if (pax_flags_hardmode & pax_flags_softmode)
43679 + return ~0UL;
43680 +
43681 +#ifdef CONFIG_PAX_SOFTMODE
43682 + if (pax_softmode)
43683 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
43684 + else
43685 +#endif
43686 +
43687 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
43688 +#else
43689 + return ~0UL;
43690 +#endif
43691 +
43692 +}
43693 +
43694 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
43695 +{
43696 + unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
43697 +
43698 + pax_flags = pax_parse_ei_pax(elf_ex);
43699 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
43700 + xattr_pax_flags = pax_parse_xattr_pax(file);
43701 +
43702 + if (pt_pax_flags == ~0UL)
43703 + pt_pax_flags = xattr_pax_flags;
43704 + else if (xattr_pax_flags == ~0UL)
43705 + xattr_pax_flags = pt_pax_flags;
43706 + if (pt_pax_flags != xattr_pax_flags)
43707 + return -EINVAL;
43708 + if (pt_pax_flags != ~0UL)
43709 + pax_flags = pt_pax_flags;
43710 +
43711 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
43712 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43713 + if ((__supported_pte_mask & _PAGE_NX))
43714 + pax_flags &= ~MF_PAX_SEGMEXEC;
43715 + else
43716 + pax_flags &= ~MF_PAX_PAGEEXEC;
43717 + }
43718 +#endif
43719 +
43720 + if (0 > pax_check_flags(&pax_flags))
43721 + return -EINVAL;
43722 +
43723 + current->mm->pax_flags = pax_flags;
43724 + return 0;
43725 +}
43726 +#endif
43727 +
43728 /*
43729 * These are the functions used to load ELF style executables and shared
43730 * libraries. There is no binary dependent code anywhere else.
43731 @@ -539,6 +869,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
43732 {
43733 unsigned int random_variable = 0;
43734
43735 +#ifdef CONFIG_PAX_RANDUSTACK
43736 + if (randomize_va_space)
43737 + return stack_top - current->mm->delta_stack;
43738 +#endif
43739 +
43740 if ((current->flags & PF_RANDOMIZE) &&
43741 !(current->personality & ADDR_NO_RANDOMIZE)) {
43742 random_variable = get_random_int() & STACK_RND_MASK;
43743 @@ -557,7 +892,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43744 unsigned long load_addr = 0, load_bias = 0;
43745 int load_addr_set = 0;
43746 char * elf_interpreter = NULL;
43747 - unsigned long error;
43748 + unsigned long error = 0;
43749 struct elf_phdr *elf_ppnt, *elf_phdata;
43750 unsigned long elf_bss, elf_brk;
43751 int retval, i;
43752 @@ -567,11 +902,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43753 unsigned long start_code, end_code, start_data, end_data;
43754 unsigned long reloc_func_desc __maybe_unused = 0;
43755 int executable_stack = EXSTACK_DEFAULT;
43756 - unsigned long def_flags = 0;
43757 struct {
43758 struct elfhdr elf_ex;
43759 struct elfhdr interp_elf_ex;
43760 } *loc;
43761 + unsigned long pax_task_size = TASK_SIZE;
43762
43763 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
43764 if (!loc) {
43765 @@ -707,11 +1042,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43766 goto out_free_dentry;
43767
43768 /* OK, This is the point of no return */
43769 - current->mm->def_flags = def_flags;
43770 +
43771 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43772 + current->mm->pax_flags = 0UL;
43773 +#endif
43774 +
43775 +#ifdef CONFIG_PAX_DLRESOLVE
43776 + current->mm->call_dl_resolve = 0UL;
43777 +#endif
43778 +
43779 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
43780 + current->mm->call_syscall = 0UL;
43781 +#endif
43782 +
43783 +#ifdef CONFIG_PAX_ASLR
43784 + current->mm->delta_mmap = 0UL;
43785 + current->mm->delta_stack = 0UL;
43786 +#endif
43787 +
43788 + current->mm->def_flags = 0;
43789 +
43790 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43791 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
43792 + send_sig(SIGKILL, current, 0);
43793 + goto out_free_dentry;
43794 + }
43795 +#endif
43796 +
43797 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
43798 + pax_set_initial_flags(bprm);
43799 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
43800 + if (pax_set_initial_flags_func)
43801 + (pax_set_initial_flags_func)(bprm);
43802 +#endif
43803 +
43804 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
43805 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
43806 + current->mm->context.user_cs_limit = PAGE_SIZE;
43807 + current->mm->def_flags |= VM_PAGEEXEC;
43808 + }
43809 +#endif
43810 +
43811 +#ifdef CONFIG_PAX_SEGMEXEC
43812 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
43813 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
43814 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
43815 + pax_task_size = SEGMEXEC_TASK_SIZE;
43816 + current->mm->def_flags |= VM_NOHUGEPAGE;
43817 + }
43818 +#endif
43819 +
43820 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
43821 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43822 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
43823 + put_cpu();
43824 + }
43825 +#endif
43826
43827 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
43828 may depend on the personality. */
43829 SET_PERSONALITY(loc->elf_ex);
43830 +
43831 +#ifdef CONFIG_PAX_ASLR
43832 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
43833 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
43834 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
43835 + }
43836 +#endif
43837 +
43838 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
43839 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43840 + executable_stack = EXSTACK_DISABLE_X;
43841 + current->personality &= ~READ_IMPLIES_EXEC;
43842 + } else
43843 +#endif
43844 +
43845 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
43846 current->personality |= READ_IMPLIES_EXEC;
43847
43848 @@ -802,6 +1207,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43849 #else
43850 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
43851 #endif
43852 +
43853 +#ifdef CONFIG_PAX_RANDMMAP
43854 + /* PaX: randomize base address at the default exe base if requested */
43855 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
43856 +#ifdef CONFIG_SPARC64
43857 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
43858 +#else
43859 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
43860 +#endif
43861 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
43862 + elf_flags |= MAP_FIXED;
43863 + }
43864 +#endif
43865 +
43866 }
43867
43868 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
43869 @@ -834,9 +1253,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43870 * allowed task size. Note that p_filesz must always be
43871 * <= p_memsz so it is only necessary to check p_memsz.
43872 */
43873 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
43874 - elf_ppnt->p_memsz > TASK_SIZE ||
43875 - TASK_SIZE - elf_ppnt->p_memsz < k) {
43876 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
43877 + elf_ppnt->p_memsz > pax_task_size ||
43878 + pax_task_size - elf_ppnt->p_memsz < k) {
43879 /* set_brk can never work. Avoid overflows. */
43880 send_sig(SIGKILL, current, 0);
43881 retval = -EINVAL;
43882 @@ -875,17 +1294,44 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43883 goto out_free_dentry;
43884 }
43885 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
43886 - send_sig(SIGSEGV, current, 0);
43887 - retval = -EFAULT; /* Nobody gets to see this, but.. */
43888 - goto out_free_dentry;
43889 + /*
43890 + * This bss-zeroing can fail if the ELF
43891 + * file specifies odd protections. So
43892 + * we don't check the return value
43893 + */
43894 }
43895
43896 +#ifdef CONFIG_PAX_RANDMMAP
43897 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
43898 + unsigned long start, size;
43899 +
43900 + start = ELF_PAGEALIGN(elf_brk);
43901 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
43902 + down_read(&current->mm->mmap_sem);
43903 + retval = -ENOMEM;
43904 + if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
43905 + unsigned long prot = PROT_NONE;
43906 +
43907 + up_read(&current->mm->mmap_sem);
43908 + current->mm->brk_gap = PAGE_ALIGN(size) >> PAGE_SHIFT;
43909 +// if (current->personality & ADDR_NO_RANDOMIZE)
43910 +// prot = PROT_READ;
43911 + start = vm_mmap(NULL, start, size, prot, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
43912 + retval = IS_ERR_VALUE(start) ? start : 0;
43913 + } else
43914 + up_read(&current->mm->mmap_sem);
43915 + if (retval == 0)
43916 + retval = set_brk(start + size, start + size + PAGE_SIZE);
43917 + if (retval < 0) {
43918 + send_sig(SIGKILL, current, 0);
43919 + goto out_free_dentry;
43920 + }
43921 + }
43922 +#endif
43923 +
43924 if (elf_interpreter) {
43925 - unsigned long uninitialized_var(interp_map_addr);
43926 -
43927 elf_entry = load_elf_interp(&loc->interp_elf_ex,
43928 interpreter,
43929 - &interp_map_addr,
43930 load_bias);
43931 if (!IS_ERR((void *)elf_entry)) {
43932 /*
43933 @@ -1107,7 +1553,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
43934 * Decide what to dump of a segment, part, all or none.
43935 */
43936 static unsigned long vma_dump_size(struct vm_area_struct *vma,
43937 - unsigned long mm_flags)
43938 + unsigned long mm_flags, long signr)
43939 {
43940 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
43941
43942 @@ -1144,7 +1590,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
43943 if (vma->vm_file == NULL)
43944 return 0;
43945
43946 - if (FILTER(MAPPED_PRIVATE))
43947 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
43948 goto whole;
43949
43950 /*
43951 @@ -1366,9 +1812,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
43952 {
43953 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
43954 int i = 0;
43955 - do
43956 + do {
43957 i += 2;
43958 - while (auxv[i - 2] != AT_NULL);
43959 + } while (auxv[i - 2] != AT_NULL);
43960 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
43961 }
43962
43963 @@ -1879,14 +2325,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
43964 }
43965
43966 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
43967 - unsigned long mm_flags)
43968 + struct coredump_params *cprm)
43969 {
43970 struct vm_area_struct *vma;
43971 size_t size = 0;
43972
43973 for (vma = first_vma(current, gate_vma); vma != NULL;
43974 vma = next_vma(vma, gate_vma))
43975 - size += vma_dump_size(vma, mm_flags);
43976 + size += vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43977 return size;
43978 }
43979
43980 @@ -1980,7 +2426,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43981
43982 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
43983
43984 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
43985 + offset += elf_core_vma_data_size(gate_vma, cprm);
43986 offset += elf_core_extra_data_size();
43987 e_shoff = offset;
43988
43989 @@ -1994,10 +2440,12 @@ static int elf_core_dump(struct coredump_params *cprm)
43990 offset = dataoff;
43991
43992 size += sizeof(*elf);
43993 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43994 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
43995 goto end_coredump;
43996
43997 size += sizeof(*phdr4note);
43998 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43999 if (size > cprm->limit
44000 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
44001 goto end_coredump;
44002 @@ -2011,7 +2459,7 @@ static int elf_core_dump(struct coredump_params *cprm)
44003 phdr.p_offset = offset;
44004 phdr.p_vaddr = vma->vm_start;
44005 phdr.p_paddr = 0;
44006 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
44007 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->signr);
44008 phdr.p_memsz = vma->vm_end - vma->vm_start;
44009 offset += phdr.p_filesz;
44010 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
44011 @@ -2022,6 +2470,7 @@ static int elf_core_dump(struct coredump_params *cprm)
44012 phdr.p_align = ELF_EXEC_PAGESIZE;
44013
44014 size += sizeof(phdr);
44015 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
44016 if (size > cprm->limit
44017 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
44018 goto end_coredump;
44019 @@ -2046,7 +2495,7 @@ static int elf_core_dump(struct coredump_params *cprm)
44020 unsigned long addr;
44021 unsigned long end;
44022
44023 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
44024 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->signr);
44025
44026 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
44027 struct page *page;
44028 @@ -2055,6 +2504,7 @@ static int elf_core_dump(struct coredump_params *cprm)
44029 page = get_dump_page(addr);
44030 if (page) {
44031 void *kaddr = kmap(page);
44032 + gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
44033 stop = ((size += PAGE_SIZE) > cprm->limit) ||
44034 !dump_write(cprm->file, kaddr,
44035 PAGE_SIZE);
44036 @@ -2072,6 +2522,7 @@ static int elf_core_dump(struct coredump_params *cprm)
44037
44038 if (e_phnum == PN_XNUM) {
44039 size += sizeof(*shdr4extnum);
44040 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
44041 if (size > cprm->limit
44042 || !dump_write(cprm->file, shdr4extnum,
44043 sizeof(*shdr4extnum)))
44044 @@ -2092,6 +2543,97 @@ out:
44045
44046 #endif /* CONFIG_ELF_CORE */
44047
44048 +#ifdef CONFIG_PAX_MPROTECT
44049 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
44050 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
44051 + * we'll remove VM_MAYWRITE for good on RELRO segments.
44052 + *
44053 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
44054 + * basis because we want to allow the common case and not the special ones.
44055 + */
44056 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
44057 +{
44058 + struct elfhdr elf_h;
44059 + struct elf_phdr elf_p;
44060 + unsigned long i;
44061 + unsigned long oldflags;
44062 + bool is_textrel_rw, is_textrel_rx, is_relro;
44063 +
44064 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
44065 + return;
44066 +
44067 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
44068 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
44069 +
44070 +#ifdef CONFIG_PAX_ELFRELOCS
44071 + /* possible TEXTREL */
44072 + is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
44073 + 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);
44074 +#else
44075 + is_textrel_rw = false;
44076 + is_textrel_rx = false;
44077 +#endif
44078 +
44079 + /* possible RELRO */
44080 + is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
44081 +
44082 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
44083 + return;
44084 +
44085 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
44086 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
44087 +
44088 +#ifdef CONFIG_PAX_ETEXECRELOCS
44089 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
44090 +#else
44091 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
44092 +#endif
44093 +
44094 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
44095 + !elf_check_arch(&elf_h) ||
44096 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
44097 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
44098 + return;
44099 +
44100 + for (i = 0UL; i < elf_h.e_phnum; i++) {
44101 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
44102 + return;
44103 + switch (elf_p.p_type) {
44104 + case PT_DYNAMIC:
44105 + if (!is_textrel_rw && !is_textrel_rx)
44106 + continue;
44107 + i = 0UL;
44108 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
44109 + elf_dyn dyn;
44110 +
44111 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
44112 + return;
44113 + if (dyn.d_tag == DT_NULL)
44114 + return;
44115 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
44116 + gr_log_textrel(vma);
44117 + if (is_textrel_rw)
44118 + vma->vm_flags |= VM_MAYWRITE;
44119 + else
44120 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
44121 + vma->vm_flags &= ~VM_MAYWRITE;
44122 + return;
44123 + }
44124 + i++;
44125 + }
44126 + return;
44127 +
44128 + case PT_GNU_RELRO:
44129 + if (!is_relro)
44130 + continue;
44131 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
44132 + vma->vm_flags &= ~VM_MAYWRITE;
44133 + return;
44134 + }
44135 + }
44136 +}
44137 +#endif
44138 +
44139 static int __init init_elf_binfmt(void)
44140 {
44141 register_binfmt(&elf_format);
44142 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
44143 index 178cb70..8972997 100644
44144 --- a/fs/binfmt_flat.c
44145 +++ b/fs/binfmt_flat.c
44146 @@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
44147 realdatastart = (unsigned long) -ENOMEM;
44148 printk("Unable to allocate RAM for process data, errno %d\n",
44149 (int)-realdatastart);
44150 + down_write(&current->mm->mmap_sem);
44151 vm_munmap(textpos, text_len);
44152 + up_write(&current->mm->mmap_sem);
44153 ret = realdatastart;
44154 goto err;
44155 }
44156 @@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
44157 }
44158 if (IS_ERR_VALUE(result)) {
44159 printk("Unable to read data+bss, errno %d\n", (int)-result);
44160 + down_write(&current->mm->mmap_sem);
44161 vm_munmap(textpos, text_len);
44162 vm_munmap(realdatastart, len);
44163 + up_write(&current->mm->mmap_sem);
44164 ret = result;
44165 goto err;
44166 }
44167 @@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
44168 }
44169 if (IS_ERR_VALUE(result)) {
44170 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
44171 + down_write(&current->mm->mmap_sem);
44172 vm_munmap(textpos, text_len + data_len + extra +
44173 MAX_SHARED_LIBS * sizeof(unsigned long));
44174 + up_write(&current->mm->mmap_sem);
44175 ret = result;
44176 goto err;
44177 }
44178 diff --git a/fs/bio.c b/fs/bio.c
44179 index 71072ab..439851b 100644
44180 --- a/fs/bio.c
44181 +++ b/fs/bio.c
44182 @@ -842,7 +842,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
44183 /*
44184 * Overflow, abort
44185 */
44186 - if (end < start)
44187 + if (end < start || end - start > INT_MAX - nr_pages)
44188 return ERR_PTR(-EINVAL);
44189
44190 nr_pages += end - start;
44191 @@ -976,7 +976,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
44192 /*
44193 * Overflow, abort
44194 */
44195 - if (end < start)
44196 + if (end < start || end - start > INT_MAX - nr_pages)
44197 return ERR_PTR(-EINVAL);
44198
44199 nr_pages += end - start;
44200 @@ -1238,7 +1238,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
44201 const int read = bio_data_dir(bio) == READ;
44202 struct bio_map_data *bmd = bio->bi_private;
44203 int i;
44204 - char *p = bmd->sgvecs[0].iov_base;
44205 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
44206
44207 __bio_for_each_segment(bvec, bio, i, 0) {
44208 char *addr = page_address(bvec->bv_page);
44209 diff --git a/fs/block_dev.c b/fs/block_dev.c
44210 index 38e721b..7a9c5bc 100644
44211 --- a/fs/block_dev.c
44212 +++ b/fs/block_dev.c
44213 @@ -704,7 +704,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
44214 else if (bdev->bd_contains == bdev)
44215 return true; /* is a whole device which isn't held */
44216
44217 - else if (whole->bd_holder == bd_may_claim)
44218 + else if (whole->bd_holder == (void *)bd_may_claim)
44219 return true; /* is a partition of a device that is being partitioned */
44220 else if (whole->bd_holder != NULL)
44221 return false; /* is a partition of a held device */
44222 diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
44223 index 9197e2e..7f731f8 100644
44224 --- a/fs/btrfs/check-integrity.c
44225 +++ b/fs/btrfs/check-integrity.c
44226 @@ -155,7 +155,7 @@ struct btrfsic_block {
44227 union {
44228 bio_end_io_t *bio;
44229 bh_end_io_t *bh;
44230 - } orig_bio_bh_end_io;
44231 + } __no_const orig_bio_bh_end_io;
44232 int submit_bio_bh_rw;
44233 u64 flush_gen; /* only valid if !never_written */
44234 };
44235 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
44236 index 6d183f6..f47cc7a 100644
44237 --- a/fs/btrfs/ctree.c
44238 +++ b/fs/btrfs/ctree.c
44239 @@ -1037,9 +1037,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
44240 free_extent_buffer(buf);
44241 add_root_to_dirty_list(root);
44242 } else {
44243 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
44244 - parent_start = parent->start;
44245 - else
44246 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
44247 + if (parent)
44248 + parent_start = parent->start;
44249 + else
44250 + parent_start = 0;
44251 + } else
44252 parent_start = 0;
44253
44254 WARN_ON(trans->transid != btrfs_header_generation(parent));
44255 diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
44256 index ec154f9..bf617a7 100644
44257 --- a/fs/btrfs/inode.c
44258 +++ b/fs/btrfs/inode.c
44259 @@ -7126,7 +7126,7 @@ fail:
44260 return -ENOMEM;
44261 }
44262
44263 -static int btrfs_getattr(struct vfsmount *mnt,
44264 +int btrfs_getattr(struct vfsmount *mnt,
44265 struct dentry *dentry, struct kstat *stat)
44266 {
44267 struct inode *inode = dentry->d_inode;
44268 @@ -7140,6 +7140,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
44269 return 0;
44270 }
44271
44272 +EXPORT_SYMBOL(btrfs_getattr);
44273 +
44274 +dev_t get_btrfs_dev_from_inode(struct inode *inode)
44275 +{
44276 + return BTRFS_I(inode)->root->anon_dev;
44277 +}
44278 +EXPORT_SYMBOL(get_btrfs_dev_from_inode);
44279 +
44280 /*
44281 * If a file is moved, it will inherit the cow and compression flags of the new
44282 * directory.
44283 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
44284 index 9df50fa..6cd20d0 100644
44285 --- a/fs/btrfs/ioctl.c
44286 +++ b/fs/btrfs/ioctl.c
44287 @@ -2942,9 +2942,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
44288 for (i = 0; i < num_types; i++) {
44289 struct btrfs_space_info *tmp;
44290
44291 + /* Don't copy in more than we allocated */
44292 if (!slot_count)
44293 break;
44294
44295 + slot_count--;
44296 +
44297 info = NULL;
44298 rcu_read_lock();
44299 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
44300 @@ -2966,10 +2969,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
44301 memcpy(dest, &space, sizeof(space));
44302 dest++;
44303 space_args.total_spaces++;
44304 - slot_count--;
44305 }
44306 - if (!slot_count)
44307 - break;
44308 }
44309 up_read(&info->groups_sem);
44310 }
44311 diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
44312 index 4da0865..01c4778 100644
44313 --- a/fs/btrfs/relocation.c
44314 +++ b/fs/btrfs/relocation.c
44315 @@ -1269,7 +1269,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
44316 }
44317 spin_unlock(&rc->reloc_root_tree.lock);
44318
44319 - BUG_ON((struct btrfs_root *)node->data != root);
44320 + BUG_ON(!node || (struct btrfs_root *)node->data != root);
44321
44322 if (!del) {
44323 spin_lock(&rc->reloc_root_tree.lock);
44324 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
44325 index 622f469..e8d2d55 100644
44326 --- a/fs/cachefiles/bind.c
44327 +++ b/fs/cachefiles/bind.c
44328 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
44329 args);
44330
44331 /* start by checking things over */
44332 - ASSERT(cache->fstop_percent >= 0 &&
44333 - cache->fstop_percent < cache->fcull_percent &&
44334 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
44335 cache->fcull_percent < cache->frun_percent &&
44336 cache->frun_percent < 100);
44337
44338 - ASSERT(cache->bstop_percent >= 0 &&
44339 - cache->bstop_percent < cache->bcull_percent &&
44340 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
44341 cache->bcull_percent < cache->brun_percent &&
44342 cache->brun_percent < 100);
44343
44344 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
44345 index 0a1467b..6a53245 100644
44346 --- a/fs/cachefiles/daemon.c
44347 +++ b/fs/cachefiles/daemon.c
44348 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
44349 if (n > buflen)
44350 return -EMSGSIZE;
44351
44352 - if (copy_to_user(_buffer, buffer, n) != 0)
44353 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
44354 return -EFAULT;
44355
44356 return n;
44357 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
44358 if (test_bit(CACHEFILES_DEAD, &cache->flags))
44359 return -EIO;
44360
44361 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
44362 + if (datalen > PAGE_SIZE - 1)
44363 return -EOPNOTSUPP;
44364
44365 /* drag the command string into the kernel so we can parse it */
44366 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
44367 if (args[0] != '%' || args[1] != '\0')
44368 return -EINVAL;
44369
44370 - if (fstop < 0 || fstop >= cache->fcull_percent)
44371 + if (fstop >= cache->fcull_percent)
44372 return cachefiles_daemon_range_error(cache, args);
44373
44374 cache->fstop_percent = fstop;
44375 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
44376 if (args[0] != '%' || args[1] != '\0')
44377 return -EINVAL;
44378
44379 - if (bstop < 0 || bstop >= cache->bcull_percent)
44380 + if (bstop >= cache->bcull_percent)
44381 return cachefiles_daemon_range_error(cache, args);
44382
44383 cache->bstop_percent = bstop;
44384 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
44385 index bd6bc1b..b627b53 100644
44386 --- a/fs/cachefiles/internal.h
44387 +++ b/fs/cachefiles/internal.h
44388 @@ -57,7 +57,7 @@ struct cachefiles_cache {
44389 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
44390 struct rb_root active_nodes; /* active nodes (can't be culled) */
44391 rwlock_t active_lock; /* lock for active_nodes */
44392 - atomic_t gravecounter; /* graveyard uniquifier */
44393 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
44394 unsigned frun_percent; /* when to stop culling (% files) */
44395 unsigned fcull_percent; /* when to start culling (% files) */
44396 unsigned fstop_percent; /* when to stop allocating (% files) */
44397 @@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
44398 * proc.c
44399 */
44400 #ifdef CONFIG_CACHEFILES_HISTOGRAM
44401 -extern atomic_t cachefiles_lookup_histogram[HZ];
44402 -extern atomic_t cachefiles_mkdir_histogram[HZ];
44403 -extern atomic_t cachefiles_create_histogram[HZ];
44404 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
44405 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
44406 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
44407
44408 extern int __init cachefiles_proc_init(void);
44409 extern void cachefiles_proc_cleanup(void);
44410 static inline
44411 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
44412 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
44413 {
44414 unsigned long jif = jiffies - start_jif;
44415 if (jif >= HZ)
44416 jif = HZ - 1;
44417 - atomic_inc(&histogram[jif]);
44418 + atomic_inc_unchecked(&histogram[jif]);
44419 }
44420
44421 #else
44422 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
44423 index b0b5f7c..039bb26 100644
44424 --- a/fs/cachefiles/namei.c
44425 +++ b/fs/cachefiles/namei.c
44426 @@ -318,7 +318,7 @@ try_again:
44427 /* first step is to make up a grave dentry in the graveyard */
44428 sprintf(nbuffer, "%08x%08x",
44429 (uint32_t) get_seconds(),
44430 - (uint32_t) atomic_inc_return(&cache->gravecounter));
44431 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
44432
44433 /* do the multiway lock magic */
44434 trap = lock_rename(cache->graveyard, dir);
44435 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
44436 index eccd339..4c1d995 100644
44437 --- a/fs/cachefiles/proc.c
44438 +++ b/fs/cachefiles/proc.c
44439 @@ -14,9 +14,9 @@
44440 #include <linux/seq_file.h>
44441 #include "internal.h"
44442
44443 -atomic_t cachefiles_lookup_histogram[HZ];
44444 -atomic_t cachefiles_mkdir_histogram[HZ];
44445 -atomic_t cachefiles_create_histogram[HZ];
44446 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
44447 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
44448 +atomic_unchecked_t cachefiles_create_histogram[HZ];
44449
44450 /*
44451 * display the latency histogram
44452 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
44453 return 0;
44454 default:
44455 index = (unsigned long) v - 3;
44456 - x = atomic_read(&cachefiles_lookup_histogram[index]);
44457 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
44458 - z = atomic_read(&cachefiles_create_histogram[index]);
44459 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
44460 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
44461 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
44462 if (x == 0 && y == 0 && z == 0)
44463 return 0;
44464
44465 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
44466 index c994691..2a1537f 100644
44467 --- a/fs/cachefiles/rdwr.c
44468 +++ b/fs/cachefiles/rdwr.c
44469 @@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
44470 old_fs = get_fs();
44471 set_fs(KERNEL_DS);
44472 ret = file->f_op->write(
44473 - file, (const void __user *) data, len, &pos);
44474 + file, (const void __force_user *) data, len, &pos);
44475 set_fs(old_fs);
44476 kunmap(page);
44477 if (ret != len)
44478 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
44479 index e5b7731..b9c59fb 100644
44480 --- a/fs/ceph/dir.c
44481 +++ b/fs/ceph/dir.c
44482 @@ -243,7 +243,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
44483 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
44484 struct ceph_mds_client *mdsc = fsc->mdsc;
44485 unsigned frag = fpos_frag(filp->f_pos);
44486 - int off = fpos_off(filp->f_pos);
44487 + unsigned int off = fpos_off(filp->f_pos);
44488 int err;
44489 u32 ftype;
44490 struct ceph_mds_reply_info_parsed *rinfo;
44491 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
44492 index d9ea6ed..1e6c8ac 100644
44493 --- a/fs/cifs/cifs_debug.c
44494 +++ b/fs/cifs/cifs_debug.c
44495 @@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
44496
44497 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
44498 #ifdef CONFIG_CIFS_STATS2
44499 - atomic_set(&totBufAllocCount, 0);
44500 - atomic_set(&totSmBufAllocCount, 0);
44501 + atomic_set_unchecked(&totBufAllocCount, 0);
44502 + atomic_set_unchecked(&totSmBufAllocCount, 0);
44503 #endif /* CONFIG_CIFS_STATS2 */
44504 spin_lock(&cifs_tcp_ses_lock);
44505 list_for_each(tmp1, &cifs_tcp_ses_list) {
44506 @@ -281,7 +281,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
44507 tcon = list_entry(tmp3,
44508 struct cifs_tcon,
44509 tcon_list);
44510 - atomic_set(&tcon->num_smbs_sent, 0);
44511 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
44512 if (server->ops->clear_stats)
44513 server->ops->clear_stats(tcon);
44514 }
44515 @@ -313,8 +313,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
44516 smBufAllocCount.counter, cifs_min_small);
44517 #ifdef CONFIG_CIFS_STATS2
44518 seq_printf(m, "Total Large %d Small %d Allocations\n",
44519 - atomic_read(&totBufAllocCount),
44520 - atomic_read(&totSmBufAllocCount));
44521 + atomic_read_unchecked(&totBufAllocCount),
44522 + atomic_read_unchecked(&totSmBufAllocCount));
44523 #endif /* CONFIG_CIFS_STATS2 */
44524
44525 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
44526 @@ -343,7 +343,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
44527 if (tcon->need_reconnect)
44528 seq_puts(m, "\tDISCONNECTED ");
44529 seq_printf(m, "\nSMBs: %d",
44530 - atomic_read(&tcon->num_smbs_sent));
44531 + atomic_read_unchecked(&tcon->num_smbs_sent));
44532 if (server->ops->print_stats)
44533 server->ops->print_stats(m, tcon);
44534 }
44535 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
44536 index db8a404..c712e2e 100644
44537 --- a/fs/cifs/cifsfs.c
44538 +++ b/fs/cifs/cifsfs.c
44539 @@ -1003,7 +1003,7 @@ cifs_init_request_bufs(void)
44540 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
44541 cifs_req_cachep = kmem_cache_create("cifs_request",
44542 CIFSMaxBufSize + max_hdr_size, 0,
44543 - SLAB_HWCACHE_ALIGN, NULL);
44544 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
44545 if (cifs_req_cachep == NULL)
44546 return -ENOMEM;
44547
44548 @@ -1030,7 +1030,7 @@ cifs_init_request_bufs(void)
44549 efficient to alloc 1 per page off the slab compared to 17K (5page)
44550 alloc of large cifs buffers even when page debugging is on */
44551 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
44552 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
44553 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
44554 NULL);
44555 if (cifs_sm_req_cachep == NULL) {
44556 mempool_destroy(cifs_req_poolp);
44557 @@ -1115,8 +1115,8 @@ init_cifs(void)
44558 atomic_set(&bufAllocCount, 0);
44559 atomic_set(&smBufAllocCount, 0);
44560 #ifdef CONFIG_CIFS_STATS2
44561 - atomic_set(&totBufAllocCount, 0);
44562 - atomic_set(&totSmBufAllocCount, 0);
44563 + atomic_set_unchecked(&totBufAllocCount, 0);
44564 + atomic_set_unchecked(&totSmBufAllocCount, 0);
44565 #endif /* CONFIG_CIFS_STATS2 */
44566
44567 atomic_set(&midCount, 0);
44568 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
44569 index 977dc0e..ba48ab9 100644
44570 --- a/fs/cifs/cifsglob.h
44571 +++ b/fs/cifs/cifsglob.h
44572 @@ -590,35 +590,35 @@ struct cifs_tcon {
44573 __u16 Flags; /* optional support bits */
44574 enum statusEnum tidStatus;
44575 #ifdef CONFIG_CIFS_STATS
44576 - atomic_t num_smbs_sent;
44577 + atomic_unchecked_t num_smbs_sent;
44578 union {
44579 struct {
44580 - atomic_t num_writes;
44581 - atomic_t num_reads;
44582 - atomic_t num_flushes;
44583 - atomic_t num_oplock_brks;
44584 - atomic_t num_opens;
44585 - atomic_t num_closes;
44586 - atomic_t num_deletes;
44587 - atomic_t num_mkdirs;
44588 - atomic_t num_posixopens;
44589 - atomic_t num_posixmkdirs;
44590 - atomic_t num_rmdirs;
44591 - atomic_t num_renames;
44592 - atomic_t num_t2renames;
44593 - atomic_t num_ffirst;
44594 - atomic_t num_fnext;
44595 - atomic_t num_fclose;
44596 - atomic_t num_hardlinks;
44597 - atomic_t num_symlinks;
44598 - atomic_t num_locks;
44599 - atomic_t num_acl_get;
44600 - atomic_t num_acl_set;
44601 + atomic_unchecked_t num_writes;
44602 + atomic_unchecked_t num_reads;
44603 + atomic_unchecked_t num_flushes;
44604 + atomic_unchecked_t num_oplock_brks;
44605 + atomic_unchecked_t num_opens;
44606 + atomic_unchecked_t num_closes;
44607 + atomic_unchecked_t num_deletes;
44608 + atomic_unchecked_t num_mkdirs;
44609 + atomic_unchecked_t num_posixopens;
44610 + atomic_unchecked_t num_posixmkdirs;
44611 + atomic_unchecked_t num_rmdirs;
44612 + atomic_unchecked_t num_renames;
44613 + atomic_unchecked_t num_t2renames;
44614 + atomic_unchecked_t num_ffirst;
44615 + atomic_unchecked_t num_fnext;
44616 + atomic_unchecked_t num_fclose;
44617 + atomic_unchecked_t num_hardlinks;
44618 + atomic_unchecked_t num_symlinks;
44619 + atomic_unchecked_t num_locks;
44620 + atomic_unchecked_t num_acl_get;
44621 + atomic_unchecked_t num_acl_set;
44622 } cifs_stats;
44623 #ifdef CONFIG_CIFS_SMB2
44624 struct {
44625 - atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
44626 - atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
44627 + atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
44628 + atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
44629 } smb2_stats;
44630 #endif /* CONFIG_CIFS_SMB2 */
44631 } stats;
44632 @@ -862,7 +862,7 @@ build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb,
44633 }
44634
44635 #ifdef CONFIG_CIFS_STATS
44636 -#define cifs_stats_inc atomic_inc
44637 +#define cifs_stats_inc atomic_inc_unchecked
44638
44639 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
44640 unsigned int bytes)
44641 @@ -1227,8 +1227,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
44642 /* Various Debug counters */
44643 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
44644 #ifdef CONFIG_CIFS_STATS2
44645 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
44646 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
44647 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
44648 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
44649 #endif
44650 GLOBAL_EXTERN atomic_t smBufAllocCount;
44651 GLOBAL_EXTERN atomic_t midCount;
44652 diff --git a/fs/cifs/link.c b/fs/cifs/link.c
44653 index e6ce3b1..adc21fd 100644
44654 --- a/fs/cifs/link.c
44655 +++ b/fs/cifs/link.c
44656 @@ -602,7 +602,7 @@ symlink_exit:
44657
44658 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
44659 {
44660 - char *p = nd_get_link(nd);
44661 + const char *p = nd_get_link(nd);
44662 if (!IS_ERR(p))
44663 kfree(p);
44664 }
44665 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
44666 index ce41fee..ac0d27a 100644
44667 --- a/fs/cifs/misc.c
44668 +++ b/fs/cifs/misc.c
44669 @@ -169,7 +169,7 @@ cifs_buf_get(void)
44670 memset(ret_buf, 0, buf_size + 3);
44671 atomic_inc(&bufAllocCount);
44672 #ifdef CONFIG_CIFS_STATS2
44673 - atomic_inc(&totBufAllocCount);
44674 + atomic_inc_unchecked(&totBufAllocCount);
44675 #endif /* CONFIG_CIFS_STATS2 */
44676 }
44677
44678 @@ -204,7 +204,7 @@ cifs_small_buf_get(void)
44679 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
44680 atomic_inc(&smBufAllocCount);
44681 #ifdef CONFIG_CIFS_STATS2
44682 - atomic_inc(&totSmBufAllocCount);
44683 + atomic_inc_unchecked(&totSmBufAllocCount);
44684 #endif /* CONFIG_CIFS_STATS2 */
44685
44686 }
44687 diff --git a/fs/cifs/readdir.c b/fs/cifs/readdir.c
44688 index d87f826..1bab9d4 100644
44689 --- a/fs/cifs/readdir.c
44690 +++ b/fs/cifs/readdir.c
44691 @@ -86,14 +86,17 @@ cifs_readdir_lookup(struct dentry *parent, struct qstr *name,
44692
44693 dentry = d_lookup(parent, name);
44694 if (dentry) {
44695 + int err;
44696 inode = dentry->d_inode;
44697 /* update inode in place if i_ino didn't change */
44698 if (inode && CIFS_I(inode)->uniqueid == fattr->cf_uniqueid) {
44699 cifs_fattr_to_inode(inode, fattr);
44700 return dentry;
44701 }
44702 - d_drop(dentry);
44703 + err = d_invalidate(dentry);
44704 dput(dentry);
44705 + if (err)
44706 + return NULL;
44707 }
44708
44709 dentry = d_alloc(parent, name);
44710 diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
44711 index 3129ac7..cc4a948 100644
44712 --- a/fs/cifs/smb1ops.c
44713 +++ b/fs/cifs/smb1ops.c
44714 @@ -524,27 +524,27 @@ static void
44715 cifs_clear_stats(struct cifs_tcon *tcon)
44716 {
44717 #ifdef CONFIG_CIFS_STATS
44718 - atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
44719 - atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
44720 - atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
44721 - atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
44722 - atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
44723 - atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
44724 - atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
44725 - atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
44726 - atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
44727 - atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
44728 - atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
44729 - atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
44730 - atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
44731 - atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
44732 - atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
44733 - atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
44734 - atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
44735 - atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
44736 - atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
44737 - atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
44738 - atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
44739 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
44740 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
44741 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
44742 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
44743 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
44744 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
44745 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
44746 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
44747 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
44748 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
44749 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
44750 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
44751 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
44752 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
44753 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
44754 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
44755 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
44756 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
44757 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
44758 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
44759 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
44760 #endif
44761 }
44762
44763 @@ -553,36 +553,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
44764 {
44765 #ifdef CONFIG_CIFS_STATS
44766 seq_printf(m, " Oplocks breaks: %d",
44767 - atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
44768 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
44769 seq_printf(m, "\nReads: %d Bytes: %llu",
44770 - atomic_read(&tcon->stats.cifs_stats.num_reads),
44771 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
44772 (long long)(tcon->bytes_read));
44773 seq_printf(m, "\nWrites: %d Bytes: %llu",
44774 - atomic_read(&tcon->stats.cifs_stats.num_writes),
44775 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
44776 (long long)(tcon->bytes_written));
44777 seq_printf(m, "\nFlushes: %d",
44778 - atomic_read(&tcon->stats.cifs_stats.num_flushes));
44779 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
44780 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
44781 - atomic_read(&tcon->stats.cifs_stats.num_locks),
44782 - atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
44783 - atomic_read(&tcon->stats.cifs_stats.num_symlinks));
44784 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
44785 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
44786 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
44787 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
44788 - atomic_read(&tcon->stats.cifs_stats.num_opens),
44789 - atomic_read(&tcon->stats.cifs_stats.num_closes),
44790 - atomic_read(&tcon->stats.cifs_stats.num_deletes));
44791 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
44792 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
44793 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
44794 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
44795 - atomic_read(&tcon->stats.cifs_stats.num_posixopens),
44796 - atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
44797 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
44798 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
44799 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
44800 - atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
44801 - atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
44802 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
44803 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
44804 seq_printf(m, "\nRenames: %d T2 Renames %d",
44805 - atomic_read(&tcon->stats.cifs_stats.num_renames),
44806 - atomic_read(&tcon->stats.cifs_stats.num_t2renames));
44807 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
44808 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
44809 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
44810 - atomic_read(&tcon->stats.cifs_stats.num_ffirst),
44811 - atomic_read(&tcon->stats.cifs_stats.num_fnext),
44812 - atomic_read(&tcon->stats.cifs_stats.num_fclose));
44813 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
44814 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
44815 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
44816 #endif
44817 }
44818
44819 diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
44820 index 826209b..fa460f4 100644
44821 --- a/fs/cifs/smb2ops.c
44822 +++ b/fs/cifs/smb2ops.c
44823 @@ -219,8 +219,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
44824 #ifdef CONFIG_CIFS_STATS
44825 int i;
44826 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
44827 - atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
44828 - atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
44829 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
44830 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
44831 }
44832 #endif
44833 }
44834 @@ -229,66 +229,66 @@ static void
44835 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
44836 {
44837 #ifdef CONFIG_CIFS_STATS
44838 - atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
44839 - atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
44840 + atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
44841 + atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
44842 seq_printf(m, "\nNegotiates: %d sent %d failed",
44843 - atomic_read(&sent[SMB2_NEGOTIATE_HE]),
44844 - atomic_read(&failed[SMB2_NEGOTIATE_HE]));
44845 + atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
44846 + atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
44847 seq_printf(m, "\nSessionSetups: %d sent %d failed",
44848 - atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
44849 - atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
44850 + atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
44851 + atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
44852 #define SMB2LOGOFF 0x0002 /* trivial request/resp */
44853 seq_printf(m, "\nLogoffs: %d sent %d failed",
44854 - atomic_read(&sent[SMB2_LOGOFF_HE]),
44855 - atomic_read(&failed[SMB2_LOGOFF_HE]));
44856 + atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
44857 + atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
44858 seq_printf(m, "\nTreeConnects: %d sent %d failed",
44859 - atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
44860 - atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
44861 + atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
44862 + atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
44863 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
44864 - atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
44865 - atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
44866 + atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
44867 + atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
44868 seq_printf(m, "\nCreates: %d sent %d failed",
44869 - atomic_read(&sent[SMB2_CREATE_HE]),
44870 - atomic_read(&failed[SMB2_CREATE_HE]));
44871 + atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
44872 + atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
44873 seq_printf(m, "\nCloses: %d sent %d failed",
44874 - atomic_read(&sent[SMB2_CLOSE_HE]),
44875 - atomic_read(&failed[SMB2_CLOSE_HE]));
44876 + atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
44877 + atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
44878 seq_printf(m, "\nFlushes: %d sent %d failed",
44879 - atomic_read(&sent[SMB2_FLUSH_HE]),
44880 - atomic_read(&failed[SMB2_FLUSH_HE]));
44881 + atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
44882 + atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
44883 seq_printf(m, "\nReads: %d sent %d failed",
44884 - atomic_read(&sent[SMB2_READ_HE]),
44885 - atomic_read(&failed[SMB2_READ_HE]));
44886 + atomic_read_unchecked(&sent[SMB2_READ_HE]),
44887 + atomic_read_unchecked(&failed[SMB2_READ_HE]));
44888 seq_printf(m, "\nWrites: %d sent %d failed",
44889 - atomic_read(&sent[SMB2_WRITE_HE]),
44890 - atomic_read(&failed[SMB2_WRITE_HE]));
44891 + atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
44892 + atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
44893 seq_printf(m, "\nLocks: %d sent %d failed",
44894 - atomic_read(&sent[SMB2_LOCK_HE]),
44895 - atomic_read(&failed[SMB2_LOCK_HE]));
44896 + atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
44897 + atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
44898 seq_printf(m, "\nIOCTLs: %d sent %d failed",
44899 - atomic_read(&sent[SMB2_IOCTL_HE]),
44900 - atomic_read(&failed[SMB2_IOCTL_HE]));
44901 + atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
44902 + atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
44903 seq_printf(m, "\nCancels: %d sent %d failed",
44904 - atomic_read(&sent[SMB2_CANCEL_HE]),
44905 - atomic_read(&failed[SMB2_CANCEL_HE]));
44906 + atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
44907 + atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
44908 seq_printf(m, "\nEchos: %d sent %d failed",
44909 - atomic_read(&sent[SMB2_ECHO_HE]),
44910 - atomic_read(&failed[SMB2_ECHO_HE]));
44911 + atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
44912 + atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
44913 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
44914 - atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
44915 - atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
44916 + atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
44917 + atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
44918 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
44919 - atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
44920 - atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
44921 + atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
44922 + atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
44923 seq_printf(m, "\nQueryInfos: %d sent %d failed",
44924 - atomic_read(&sent[SMB2_QUERY_INFO_HE]),
44925 - atomic_read(&failed[SMB2_QUERY_INFO_HE]));
44926 + atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
44927 + atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
44928 seq_printf(m, "\nSetInfos: %d sent %d failed",
44929 - atomic_read(&sent[SMB2_SET_INFO_HE]),
44930 - atomic_read(&failed[SMB2_SET_INFO_HE]));
44931 + atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
44932 + atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
44933 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
44934 - atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
44935 - atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
44936 + atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
44937 + atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
44938 #endif
44939 }
44940
44941 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
44942 index 958ae0e..505c9d0 100644
44943 --- a/fs/coda/cache.c
44944 +++ b/fs/coda/cache.c
44945 @@ -24,7 +24,7 @@
44946 #include "coda_linux.h"
44947 #include "coda_cache.h"
44948
44949 -static atomic_t permission_epoch = ATOMIC_INIT(0);
44950 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
44951
44952 /* replace or extend an acl cache hit */
44953 void coda_cache_enter(struct inode *inode, int mask)
44954 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
44955 struct coda_inode_info *cii = ITOC(inode);
44956
44957 spin_lock(&cii->c_lock);
44958 - cii->c_cached_epoch = atomic_read(&permission_epoch);
44959 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
44960 if (cii->c_uid != current_fsuid()) {
44961 cii->c_uid = current_fsuid();
44962 cii->c_cached_perm = mask;
44963 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
44964 {
44965 struct coda_inode_info *cii = ITOC(inode);
44966 spin_lock(&cii->c_lock);
44967 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
44968 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
44969 spin_unlock(&cii->c_lock);
44970 }
44971
44972 /* remove all acl caches */
44973 void coda_cache_clear_all(struct super_block *sb)
44974 {
44975 - atomic_inc(&permission_epoch);
44976 + atomic_inc_unchecked(&permission_epoch);
44977 }
44978
44979
44980 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
44981 spin_lock(&cii->c_lock);
44982 hit = (mask & cii->c_cached_perm) == mask &&
44983 cii->c_uid == current_fsuid() &&
44984 - cii->c_cached_epoch == atomic_read(&permission_epoch);
44985 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
44986 spin_unlock(&cii->c_lock);
44987
44988 return hit;
44989 diff --git a/fs/compat.c b/fs/compat.c
44990 index 1bdb350..9f28287 100644
44991 --- a/fs/compat.c
44992 +++ b/fs/compat.c
44993 @@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
44994
44995 set_fs(KERNEL_DS);
44996 /* The __user pointer cast is valid because of the set_fs() */
44997 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
44998 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
44999 set_fs(oldfs);
45000 /* truncating is ok because it's a user address */
45001 if (!ret)
45002 @@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
45003 goto out;
45004
45005 ret = -EINVAL;
45006 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
45007 + if (nr_segs > UIO_MAXIOV)
45008 goto out;
45009 if (nr_segs > fast_segs) {
45010 ret = -ENOMEM;
45011 @@ -831,6 +831,7 @@ struct compat_old_linux_dirent {
45012
45013 struct compat_readdir_callback {
45014 struct compat_old_linux_dirent __user *dirent;
45015 + struct file * file;
45016 int result;
45017 };
45018
45019 @@ -848,6 +849,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
45020 buf->result = -EOVERFLOW;
45021 return -EOVERFLOW;
45022 }
45023 +
45024 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
45025 + return 0;
45026 +
45027 buf->result++;
45028 dirent = buf->dirent;
45029 if (!access_ok(VERIFY_WRITE, dirent,
45030 @@ -880,6 +885,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
45031
45032 buf.result = 0;
45033 buf.dirent = dirent;
45034 + buf.file = file;
45035
45036 error = vfs_readdir(file, compat_fillonedir, &buf);
45037 if (buf.result)
45038 @@ -899,6 +905,7 @@ struct compat_linux_dirent {
45039 struct compat_getdents_callback {
45040 struct compat_linux_dirent __user *current_dir;
45041 struct compat_linux_dirent __user *previous;
45042 + struct file * file;
45043 int count;
45044 int error;
45045 };
45046 @@ -920,6 +927,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
45047 buf->error = -EOVERFLOW;
45048 return -EOVERFLOW;
45049 }
45050 +
45051 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
45052 + return 0;
45053 +
45054 dirent = buf->previous;
45055 if (dirent) {
45056 if (__put_user(offset, &dirent->d_off))
45057 @@ -966,6 +977,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
45058 buf.previous = NULL;
45059 buf.count = count;
45060 buf.error = 0;
45061 + buf.file = file;
45062
45063 error = vfs_readdir(file, compat_filldir, &buf);
45064 if (error >= 0)
45065 @@ -986,6 +998,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
45066 struct compat_getdents_callback64 {
45067 struct linux_dirent64 __user *current_dir;
45068 struct linux_dirent64 __user *previous;
45069 + struct file * file;
45070 int count;
45071 int error;
45072 };
45073 @@ -1002,6 +1015,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
45074 buf->error = -EINVAL; /* only used if we fail.. */
45075 if (reclen > buf->count)
45076 return -EINVAL;
45077 +
45078 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
45079 + return 0;
45080 +
45081 dirent = buf->previous;
45082
45083 if (dirent) {
45084 @@ -1052,13 +1069,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
45085 buf.previous = NULL;
45086 buf.count = count;
45087 buf.error = 0;
45088 + buf.file = file;
45089
45090 error = vfs_readdir(file, compat_filldir64, &buf);
45091 if (error >= 0)
45092 error = buf.error;
45093 lastdirent = buf.previous;
45094 if (lastdirent) {
45095 - typeof(lastdirent->d_off) d_off = file->f_pos;
45096 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
45097 if (__put_user_unaligned(d_off, &lastdirent->d_off))
45098 error = -EFAULT;
45099 else
45100 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
45101 index 112e45a..b59845b 100644
45102 --- a/fs/compat_binfmt_elf.c
45103 +++ b/fs/compat_binfmt_elf.c
45104 @@ -30,11 +30,13 @@
45105 #undef elf_phdr
45106 #undef elf_shdr
45107 #undef elf_note
45108 +#undef elf_dyn
45109 #undef elf_addr_t
45110 #define elfhdr elf32_hdr
45111 #define elf_phdr elf32_phdr
45112 #define elf_shdr elf32_shdr
45113 #define elf_note elf32_note
45114 +#define elf_dyn Elf32_Dyn
45115 #define elf_addr_t Elf32_Addr
45116
45117 /*
45118 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
45119 index 5d2069f..75d31d4 100644
45120 --- a/fs/compat_ioctl.c
45121 +++ b/fs/compat_ioctl.c
45122 @@ -623,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
45123 return -EFAULT;
45124 if (__get_user(udata, &ss32->iomem_base))
45125 return -EFAULT;
45126 - ss.iomem_base = compat_ptr(udata);
45127 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
45128 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
45129 __get_user(ss.port_high, &ss32->port_high))
45130 return -EFAULT;
45131 @@ -798,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
45132 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
45133 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
45134 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
45135 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
45136 + copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
45137 return -EFAULT;
45138
45139 return ioctl_preallocate(file, p);
45140 @@ -1612,8 +1612,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
45141 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
45142 {
45143 unsigned int a, b;
45144 - a = *(unsigned int *)p;
45145 - b = *(unsigned int *)q;
45146 + a = *(const unsigned int *)p;
45147 + b = *(const unsigned int *)q;
45148 if (a > b)
45149 return 1;
45150 if (a < b)
45151 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
45152 index 7414ae2..d98ad6d 100644
45153 --- a/fs/configfs/dir.c
45154 +++ b/fs/configfs/dir.c
45155 @@ -1564,7 +1564,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
45156 }
45157 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
45158 struct configfs_dirent *next;
45159 - const char * name;
45160 + const unsigned char * name;
45161 + char d_name[sizeof(next->s_dentry->d_iname)];
45162 int len;
45163 struct inode *inode = NULL;
45164
45165 @@ -1574,7 +1575,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
45166 continue;
45167
45168 name = configfs_get_name(next);
45169 - len = strlen(name);
45170 + if (next->s_dentry && name == next->s_dentry->d_iname) {
45171 + len = next->s_dentry->d_name.len;
45172 + memcpy(d_name, name, len);
45173 + name = d_name;
45174 + } else
45175 + len = strlen(name);
45176
45177 /*
45178 * We'll have a dentry and an inode for
45179 diff --git a/fs/dcache.c b/fs/dcache.c
45180 index 693f95b..95f1223 100644
45181 --- a/fs/dcache.c
45182 +++ b/fs/dcache.c
45183 @@ -3164,7 +3164,7 @@ void __init vfs_caches_init(unsigned long mempages)
45184 mempages -= reserve;
45185
45186 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
45187 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
45188 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
45189
45190 dcache_init();
45191 inode_init();
45192 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
45193 index 4733eab..71ef6fa 100644
45194 --- a/fs/debugfs/inode.c
45195 +++ b/fs/debugfs/inode.c
45196 @@ -406,7 +406,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
45197 */
45198 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
45199 {
45200 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
45201 + return __create_file(name, S_IFDIR | S_IRWXU,
45202 +#else
45203 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
45204 +#endif
45205 parent, NULL, NULL);
45206 }
45207 EXPORT_SYMBOL_GPL(debugfs_create_dir);
45208 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
45209 index cc7709e..7e7211f 100644
45210 --- a/fs/ecryptfs/inode.c
45211 +++ b/fs/ecryptfs/inode.c
45212 @@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
45213 old_fs = get_fs();
45214 set_fs(get_ds());
45215 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
45216 - (char __user *)lower_buf,
45217 + (char __force_user *)lower_buf,
45218 PATH_MAX);
45219 set_fs(old_fs);
45220 if (rc < 0)
45221 @@ -706,7 +706,7 @@ out:
45222 static void
45223 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
45224 {
45225 - char *buf = nd_get_link(nd);
45226 + const char *buf = nd_get_link(nd);
45227 if (!IS_ERR(buf)) {
45228 /* Free the char* */
45229 kfree(buf);
45230 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
45231 index 412e6ed..4292d22 100644
45232 --- a/fs/ecryptfs/miscdev.c
45233 +++ b/fs/ecryptfs/miscdev.c
45234 @@ -315,7 +315,7 @@ check_list:
45235 goto out_unlock_msg_ctx;
45236 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
45237 if (msg_ctx->msg) {
45238 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
45239 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
45240 goto out_unlock_msg_ctx;
45241 i += packet_length_size;
45242 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
45243 diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
45244 index b2a34a1..162fa69 100644
45245 --- a/fs/ecryptfs/read_write.c
45246 +++ b/fs/ecryptfs/read_write.c
45247 @@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
45248 return -EIO;
45249 fs_save = get_fs();
45250 set_fs(get_ds());
45251 - rc = vfs_write(lower_file, data, size, &offset);
45252 + rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
45253 set_fs(fs_save);
45254 mark_inode_dirty_sync(ecryptfs_inode);
45255 return rc;
45256 @@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
45257 return -EIO;
45258 fs_save = get_fs();
45259 set_fs(get_ds());
45260 - rc = vfs_read(lower_file, data, size, &offset);
45261 + rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
45262 set_fs(fs_save);
45263 return rc;
45264 }
45265 diff --git a/fs/exec.c b/fs/exec.c
45266 index fab2c6d..6a13dff 100644
45267 --- a/fs/exec.c
45268 +++ b/fs/exec.c
45269 @@ -55,6 +55,15 @@
45270 #include <linux/pipe_fs_i.h>
45271 #include <linux/oom.h>
45272 #include <linux/compat.h>
45273 +#include <linux/random.h>
45274 +#include <linux/seq_file.h>
45275 +
45276 +#ifdef CONFIG_PAX_REFCOUNT
45277 +#include <linux/kallsyms.h>
45278 +#include <linux/kdebug.h>
45279 +#endif
45280 +
45281 +#include <trace/events/fs.h>
45282
45283 #include <asm/uaccess.h>
45284 #include <asm/mmu_context.h>
45285 @@ -66,6 +75,18 @@
45286
45287 #include <trace/events/sched.h>
45288
45289 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
45290 +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
45291 +{
45292 + pr_warn_once("PAX: PAX_HAVE_ACL_FLAGS was enabled without providing the pax_set_initial_flags callback, this is probably not what you wanted.\n");
45293 +}
45294 +#endif
45295 +
45296 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
45297 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
45298 +EXPORT_SYMBOL(pax_set_initial_flags_func);
45299 +#endif
45300 +
45301 int core_uses_pid;
45302 char core_pattern[CORENAME_MAX_SIZE] = "core";
45303 unsigned int core_pipe_limit;
45304 @@ -75,7 +96,7 @@ struct core_name {
45305 char *corename;
45306 int used, size;
45307 };
45308 -static atomic_t call_count = ATOMIC_INIT(1);
45309 +static atomic_unchecked_t call_count = ATOMIC_INIT(1);
45310
45311 /* The maximal length of core_pattern is also specified in sysctl.c */
45312
45313 @@ -191,18 +212,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
45314 int write)
45315 {
45316 struct page *page;
45317 - int ret;
45318
45319 -#ifdef CONFIG_STACK_GROWSUP
45320 - if (write) {
45321 - ret = expand_downwards(bprm->vma, pos);
45322 - if (ret < 0)
45323 - return NULL;
45324 - }
45325 -#endif
45326 - ret = get_user_pages(current, bprm->mm, pos,
45327 - 1, write, 1, &page, NULL);
45328 - if (ret <= 0)
45329 + if (0 > expand_downwards(bprm->vma, pos))
45330 + return NULL;
45331 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
45332 return NULL;
45333
45334 if (write) {
45335 @@ -218,6 +231,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
45336 if (size <= ARG_MAX)
45337 return page;
45338
45339 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45340 + // only allow 512KB for argv+env on suid/sgid binaries
45341 + // to prevent easy ASLR exhaustion
45342 + if (((bprm->cred->euid != current_euid()) ||
45343 + (bprm->cred->egid != current_egid())) &&
45344 + (size > (512 * 1024))) {
45345 + put_page(page);
45346 + return NULL;
45347 + }
45348 +#endif
45349 +
45350 /*
45351 * Limit to 1/4-th the stack size for the argv+env strings.
45352 * This ensures that:
45353 @@ -277,6 +301,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
45354 vma->vm_end = STACK_TOP_MAX;
45355 vma->vm_start = vma->vm_end - PAGE_SIZE;
45356 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
45357 +
45358 +#ifdef CONFIG_PAX_SEGMEXEC
45359 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
45360 +#endif
45361 +
45362 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
45363 INIT_LIST_HEAD(&vma->anon_vma_chain);
45364
45365 @@ -287,6 +316,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
45366 mm->stack_vm = mm->total_vm = 1;
45367 up_write(&mm->mmap_sem);
45368 bprm->p = vma->vm_end - sizeof(void *);
45369 +
45370 +#ifdef CONFIG_PAX_RANDUSTACK
45371 + if (randomize_va_space)
45372 + bprm->p ^= random32() & ~PAGE_MASK;
45373 +#endif
45374 +
45375 return 0;
45376 err:
45377 up_write(&mm->mmap_sem);
45378 @@ -395,19 +430,7 @@ err:
45379 return err;
45380 }
45381
45382 -struct user_arg_ptr {
45383 -#ifdef CONFIG_COMPAT
45384 - bool is_compat;
45385 -#endif
45386 - union {
45387 - const char __user *const __user *native;
45388 -#ifdef CONFIG_COMPAT
45389 - compat_uptr_t __user *compat;
45390 -#endif
45391 - } ptr;
45392 -};
45393 -
45394 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
45395 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
45396 {
45397 const char __user *native;
45398
45399 @@ -416,14 +439,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
45400 compat_uptr_t compat;
45401
45402 if (get_user(compat, argv.ptr.compat + nr))
45403 - return ERR_PTR(-EFAULT);
45404 + return (const char __force_user *)ERR_PTR(-EFAULT);
45405
45406 return compat_ptr(compat);
45407 }
45408 #endif
45409
45410 if (get_user(native, argv.ptr.native + nr))
45411 - return ERR_PTR(-EFAULT);
45412 + return (const char __force_user *)ERR_PTR(-EFAULT);
45413
45414 return native;
45415 }
45416 @@ -442,7 +465,7 @@ static int count(struct user_arg_ptr argv, int max)
45417 if (!p)
45418 break;
45419
45420 - if (IS_ERR(p))
45421 + if (IS_ERR((const char __force_kernel *)p))
45422 return -EFAULT;
45423
45424 if (i++ >= max)
45425 @@ -476,7 +499,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
45426
45427 ret = -EFAULT;
45428 str = get_user_arg_ptr(argv, argc);
45429 - if (IS_ERR(str))
45430 + if (IS_ERR((const char __force_kernel *)str))
45431 goto out;
45432
45433 len = strnlen_user(str, MAX_ARG_STRLEN);
45434 @@ -558,7 +581,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
45435 int r;
45436 mm_segment_t oldfs = get_fs();
45437 struct user_arg_ptr argv = {
45438 - .ptr.native = (const char __user *const __user *)__argv,
45439 + .ptr.native = (const char __force_user *const __force_user *)__argv,
45440 };
45441
45442 set_fs(KERNEL_DS);
45443 @@ -593,7 +616,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
45444 unsigned long new_end = old_end - shift;
45445 struct mmu_gather tlb;
45446
45447 - BUG_ON(new_start > new_end);
45448 + if (new_start >= new_end || new_start < mmap_min_addr)
45449 + return -ENOMEM;
45450
45451 /*
45452 * ensure there are no vmas between where we want to go
45453 @@ -602,6 +626,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
45454 if (vma != find_vma(mm, new_start))
45455 return -EFAULT;
45456
45457 +#ifdef CONFIG_PAX_SEGMEXEC
45458 + BUG_ON(pax_find_mirror_vma(vma));
45459 +#endif
45460 +
45461 /*
45462 * cover the whole range: [new_start, old_end)
45463 */
45464 @@ -682,10 +710,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
45465 stack_top = arch_align_stack(stack_top);
45466 stack_top = PAGE_ALIGN(stack_top);
45467
45468 - if (unlikely(stack_top < mmap_min_addr) ||
45469 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
45470 - return -ENOMEM;
45471 -
45472 stack_shift = vma->vm_end - stack_top;
45473
45474 bprm->p -= stack_shift;
45475 @@ -697,8 +721,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
45476 bprm->exec -= stack_shift;
45477
45478 down_write(&mm->mmap_sem);
45479 +
45480 + /* Move stack pages down in memory. */
45481 + if (stack_shift) {
45482 + ret = shift_arg_pages(vma, stack_shift);
45483 + if (ret)
45484 + goto out_unlock;
45485 + }
45486 +
45487 vm_flags = VM_STACK_FLAGS;
45488
45489 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
45490 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
45491 + vm_flags &= ~VM_EXEC;
45492 +
45493 +#ifdef CONFIG_PAX_MPROTECT
45494 + if (mm->pax_flags & MF_PAX_MPROTECT)
45495 + vm_flags &= ~VM_MAYEXEC;
45496 +#endif
45497 +
45498 + }
45499 +#endif
45500 +
45501 /*
45502 * Adjust stack execute permissions; explicitly enable for
45503 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
45504 @@ -717,13 +761,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
45505 goto out_unlock;
45506 BUG_ON(prev != vma);
45507
45508 - /* Move stack pages down in memory. */
45509 - if (stack_shift) {
45510 - ret = shift_arg_pages(vma, stack_shift);
45511 - if (ret)
45512 - goto out_unlock;
45513 - }
45514 -
45515 /* mprotect_fixup is overkill to remove the temporary stack flags */
45516 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
45517
45518 @@ -781,6 +818,8 @@ struct file *open_exec(const char *name)
45519
45520 fsnotify_open(file);
45521
45522 + trace_open_exec(name);
45523 +
45524 err = deny_write_access(file);
45525 if (err)
45526 goto exit;
45527 @@ -804,7 +843,7 @@ int kernel_read(struct file *file, loff_t offset,
45528 old_fs = get_fs();
45529 set_fs(get_ds());
45530 /* The cast to a user pointer is valid due to the set_fs() */
45531 - result = vfs_read(file, (void __user *)addr, count, &pos);
45532 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
45533 set_fs(old_fs);
45534 return result;
45535 }
45536 @@ -1258,7 +1297,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
45537 }
45538 rcu_read_unlock();
45539
45540 - if (p->fs->users > n_fs) {
45541 + if (atomic_read(&p->fs->users) > n_fs) {
45542 bprm->unsafe |= LSM_UNSAFE_SHARE;
45543 } else {
45544 res = -EAGAIN;
45545 @@ -1461,6 +1500,28 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
45546
45547 EXPORT_SYMBOL(search_binary_handler);
45548
45549 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45550 +static DEFINE_PER_CPU(u64, exec_counter);
45551 +static int __init init_exec_counters(void)
45552 +{
45553 + unsigned int cpu;
45554 +
45555 + for_each_possible_cpu(cpu) {
45556 + per_cpu(exec_counter, cpu) = (u64)cpu;
45557 + }
45558 +
45559 + return 0;
45560 +}
45561 +early_initcall(init_exec_counters);
45562 +static inline void increment_exec_counter(void)
45563 +{
45564 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
45565 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
45566 +}
45567 +#else
45568 +static inline void increment_exec_counter(void) {}
45569 +#endif
45570 +
45571 /*
45572 * sys_execve() executes a new program.
45573 */
45574 @@ -1469,6 +1530,11 @@ static int do_execve_common(const char *filename,
45575 struct user_arg_ptr envp,
45576 struct pt_regs *regs)
45577 {
45578 +#ifdef CONFIG_GRKERNSEC
45579 + struct file *old_exec_file;
45580 + struct acl_subject_label *old_acl;
45581 + struct rlimit old_rlim[RLIM_NLIMITS];
45582 +#endif
45583 struct linux_binprm *bprm;
45584 struct file *file;
45585 struct files_struct *displaced;
45586 @@ -1476,6 +1542,8 @@ static int do_execve_common(const char *filename,
45587 int retval;
45588 const struct cred *cred = current_cred();
45589
45590 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
45591 +
45592 /*
45593 * We move the actual failure in case of RLIMIT_NPROC excess from
45594 * set*uid() to execve() because too many poorly written programs
45595 @@ -1516,12 +1584,27 @@ static int do_execve_common(const char *filename,
45596 if (IS_ERR(file))
45597 goto out_unmark;
45598
45599 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
45600 + retval = -EPERM;
45601 + goto out_file;
45602 + }
45603 +
45604 sched_exec();
45605
45606 bprm->file = file;
45607 bprm->filename = filename;
45608 bprm->interp = filename;
45609
45610 + if (gr_process_user_ban()) {
45611 + retval = -EPERM;
45612 + goto out_file;
45613 + }
45614 +
45615 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
45616 + retval = -EACCES;
45617 + goto out_file;
45618 + }
45619 +
45620 retval = bprm_mm_init(bprm);
45621 if (retval)
45622 goto out_file;
45623 @@ -1538,24 +1621,65 @@ static int do_execve_common(const char *filename,
45624 if (retval < 0)
45625 goto out;
45626
45627 +#ifdef CONFIG_GRKERNSEC
45628 + old_acl = current->acl;
45629 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
45630 + old_exec_file = current->exec_file;
45631 + get_file(file);
45632 + current->exec_file = file;
45633 +#endif
45634 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45635 + /* limit suid stack to 8MB
45636 + we saved the old limits above and will restore them if this exec fails
45637 + */
45638 + if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
45639 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
45640 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
45641 +#endif
45642 +
45643 + if (!gr_tpe_allow(file)) {
45644 + retval = -EACCES;
45645 + goto out_fail;
45646 + }
45647 +
45648 + if (gr_check_crash_exec(file)) {
45649 + retval = -EACCES;
45650 + goto out_fail;
45651 + }
45652 +
45653 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
45654 + bprm->unsafe);
45655 + if (retval < 0)
45656 + goto out_fail;
45657 +
45658 retval = copy_strings_kernel(1, &bprm->filename, bprm);
45659 if (retval < 0)
45660 - goto out;
45661 + goto out_fail;
45662
45663 bprm->exec = bprm->p;
45664 retval = copy_strings(bprm->envc, envp, bprm);
45665 if (retval < 0)
45666 - goto out;
45667 + goto out_fail;
45668
45669 retval = copy_strings(bprm->argc, argv, bprm);
45670 if (retval < 0)
45671 - goto out;
45672 + goto out_fail;
45673 +
45674 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
45675 +
45676 + gr_handle_exec_args(bprm, argv);
45677
45678 retval = search_binary_handler(bprm,regs);
45679 if (retval < 0)
45680 - goto out;
45681 + goto out_fail;
45682 +#ifdef CONFIG_GRKERNSEC
45683 + if (old_exec_file)
45684 + fput(old_exec_file);
45685 +#endif
45686
45687 /* execve succeeded */
45688 +
45689 + increment_exec_counter();
45690 current->fs->in_exec = 0;
45691 current->in_execve = 0;
45692 acct_update_integrals(current);
45693 @@ -1564,6 +1688,14 @@ static int do_execve_common(const char *filename,
45694 put_files_struct(displaced);
45695 return retval;
45696
45697 +out_fail:
45698 +#ifdef CONFIG_GRKERNSEC
45699 + current->acl = old_acl;
45700 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
45701 + fput(current->exec_file);
45702 + current->exec_file = old_exec_file;
45703 +#endif
45704 +
45705 out:
45706 if (bprm->mm) {
45707 acct_arg_size(bprm, 0);
45708 @@ -1637,7 +1769,7 @@ static int expand_corename(struct core_name *cn)
45709 {
45710 char *old_corename = cn->corename;
45711
45712 - cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
45713 + cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
45714 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
45715
45716 if (!cn->corename) {
45717 @@ -1734,7 +1866,7 @@ static int format_corename(struct core_name *cn, long signr)
45718 int pid_in_pattern = 0;
45719 int err = 0;
45720
45721 - cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
45722 + cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
45723 cn->corename = kmalloc(cn->size, GFP_KERNEL);
45724 cn->used = 0;
45725
45726 @@ -1831,6 +1963,250 @@ out:
45727 return ispipe;
45728 }
45729
45730 +int pax_check_flags(unsigned long *flags)
45731 +{
45732 + int retval = 0;
45733 +
45734 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
45735 + if (*flags & MF_PAX_SEGMEXEC)
45736 + {
45737 + *flags &= ~MF_PAX_SEGMEXEC;
45738 + retval = -EINVAL;
45739 + }
45740 +#endif
45741 +
45742 + if ((*flags & MF_PAX_PAGEEXEC)
45743 +
45744 +#ifdef CONFIG_PAX_PAGEEXEC
45745 + && (*flags & MF_PAX_SEGMEXEC)
45746 +#endif
45747 +
45748 + )
45749 + {
45750 + *flags &= ~MF_PAX_PAGEEXEC;
45751 + retval = -EINVAL;
45752 + }
45753 +
45754 + if ((*flags & MF_PAX_MPROTECT)
45755 +
45756 +#ifdef CONFIG_PAX_MPROTECT
45757 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
45758 +#endif
45759 +
45760 + )
45761 + {
45762 + *flags &= ~MF_PAX_MPROTECT;
45763 + retval = -EINVAL;
45764 + }
45765 +
45766 + if ((*flags & MF_PAX_EMUTRAMP)
45767 +
45768 +#ifdef CONFIG_PAX_EMUTRAMP
45769 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
45770 +#endif
45771 +
45772 + )
45773 + {
45774 + *flags &= ~MF_PAX_EMUTRAMP;
45775 + retval = -EINVAL;
45776 + }
45777 +
45778 + return retval;
45779 +}
45780 +
45781 +EXPORT_SYMBOL(pax_check_flags);
45782 +
45783 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
45784 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
45785 +{
45786 + struct task_struct *tsk = current;
45787 + struct mm_struct *mm = current->mm;
45788 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
45789 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
45790 + char *path_exec = NULL;
45791 + char *path_fault = NULL;
45792 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
45793 +
45794 + if (buffer_exec && buffer_fault) {
45795 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
45796 +
45797 + down_read(&mm->mmap_sem);
45798 + vma = mm->mmap;
45799 + while (vma && (!vma_exec || !vma_fault)) {
45800 + if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
45801 + vma_exec = vma;
45802 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
45803 + vma_fault = vma;
45804 + vma = vma->vm_next;
45805 + }
45806 + if (vma_exec) {
45807 + path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
45808 + if (IS_ERR(path_exec))
45809 + path_exec = "<path too long>";
45810 + else {
45811 + path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
45812 + if (path_exec) {
45813 + *path_exec = 0;
45814 + path_exec = buffer_exec;
45815 + } else
45816 + path_exec = "<path too long>";
45817 + }
45818 + }
45819 + if (vma_fault) {
45820 + start = vma_fault->vm_start;
45821 + end = vma_fault->vm_end;
45822 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
45823 + if (vma_fault->vm_file) {
45824 + path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
45825 + if (IS_ERR(path_fault))
45826 + path_fault = "<path too long>";
45827 + else {
45828 + path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
45829 + if (path_fault) {
45830 + *path_fault = 0;
45831 + path_fault = buffer_fault;
45832 + } else
45833 + path_fault = "<path too long>";
45834 + }
45835 + } else
45836 + path_fault = "<anonymous mapping>";
45837 + }
45838 + up_read(&mm->mmap_sem);
45839 + }
45840 + if (tsk->signal->curr_ip)
45841 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
45842 + else
45843 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
45844 + printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
45845 + "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
45846 + task_uid(tsk), task_euid(tsk), pc, sp);
45847 + free_page((unsigned long)buffer_exec);
45848 + free_page((unsigned long)buffer_fault);
45849 + pax_report_insns(regs, pc, sp);
45850 + do_coredump(SIGKILL, SIGKILL, regs);
45851 +}
45852 +#endif
45853 +
45854 +#ifdef CONFIG_PAX_REFCOUNT
45855 +void pax_report_refcount_overflow(struct pt_regs *regs)
45856 +{
45857 + if (current->signal->curr_ip)
45858 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
45859 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
45860 + else
45861 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
45862 + current->comm, task_pid_nr(current), current_uid(), current_euid());
45863 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
45864 + show_regs(regs);
45865 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
45866 +}
45867 +#endif
45868 +
45869 +#ifdef CONFIG_PAX_USERCOPY
45870 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
45871 +static noinline int check_stack_object(const void *obj, unsigned long len)
45872 +{
45873 + const void * const stack = task_stack_page(current);
45874 + const void * const stackend = stack + THREAD_SIZE;
45875 +
45876 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
45877 + const void *frame = NULL;
45878 + const void *oldframe;
45879 +#endif
45880 +
45881 + if (obj + len < obj)
45882 + return -1;
45883 +
45884 + if (obj + len <= stack || stackend <= obj)
45885 + return 0;
45886 +
45887 + if (obj < stack || stackend < obj + len)
45888 + return -1;
45889 +
45890 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
45891 + oldframe = __builtin_frame_address(1);
45892 + if (oldframe)
45893 + frame = __builtin_frame_address(2);
45894 + /*
45895 + low ----------------------------------------------> high
45896 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
45897 + ^----------------^
45898 + allow copies only within here
45899 + */
45900 + while (stack <= frame && frame < stackend) {
45901 + /* if obj + len extends past the last frame, this
45902 + check won't pass and the next frame will be 0,
45903 + causing us to bail out and correctly report
45904 + the copy as invalid
45905 + */
45906 + if (obj + len <= frame)
45907 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
45908 + oldframe = frame;
45909 + frame = *(const void * const *)frame;
45910 + }
45911 + return -1;
45912 +#else
45913 + return 1;
45914 +#endif
45915 +}
45916 +
45917 +static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
45918 +{
45919 + if (current->signal->curr_ip)
45920 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
45921 + &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
45922 + else
45923 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
45924 + to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
45925 + dump_stack();
45926 + gr_handle_kernel_exploit();
45927 + do_group_exit(SIGKILL);
45928 +}
45929 +#endif
45930 +
45931 +void check_object_size(const void *ptr, unsigned long n, bool to)
45932 +{
45933 +
45934 +#ifdef CONFIG_PAX_USERCOPY
45935 + const char *type;
45936 +
45937 + if (!n)
45938 + return;
45939 +
45940 + type = check_heap_object(ptr, n, to);
45941 + if (!type) {
45942 + if (check_stack_object(ptr, n) != -1)
45943 + return;
45944 + type = "<process stack>";
45945 + }
45946 +
45947 + pax_report_usercopy(ptr, n, to, type);
45948 +#endif
45949 +
45950 +}
45951 +EXPORT_SYMBOL(check_object_size);
45952 +
45953 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
45954 +void pax_track_stack(void)
45955 +{
45956 + unsigned long sp = (unsigned long)&sp;
45957 + if (sp < current_thread_info()->lowest_stack &&
45958 + sp > (unsigned long)task_stack_page(current))
45959 + current_thread_info()->lowest_stack = sp;
45960 +}
45961 +EXPORT_SYMBOL(pax_track_stack);
45962 +#endif
45963 +
45964 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
45965 +void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
45966 +{
45967 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
45968 + dump_stack();
45969 + do_group_exit(SIGKILL);
45970 +}
45971 +EXPORT_SYMBOL(report_size_overflow);
45972 +#endif
45973 +
45974 static int zap_process(struct task_struct *start, int exit_code)
45975 {
45976 struct task_struct *t;
45977 @@ -2041,17 +2417,17 @@ static void wait_for_dump_helpers(struct file *file)
45978 pipe = file->f_path.dentry->d_inode->i_pipe;
45979
45980 pipe_lock(pipe);
45981 - pipe->readers++;
45982 - pipe->writers--;
45983 + atomic_inc(&pipe->readers);
45984 + atomic_dec(&pipe->writers);
45985
45986 - while ((pipe->readers > 1) && (!signal_pending(current))) {
45987 + while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
45988 wake_up_interruptible_sync(&pipe->wait);
45989 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
45990 pipe_wait(pipe);
45991 }
45992
45993 - pipe->readers--;
45994 - pipe->writers++;
45995 + atomic_dec(&pipe->readers);
45996 + atomic_inc(&pipe->writers);
45997 pipe_unlock(pipe);
45998
45999 }
46000 @@ -2106,7 +2482,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
46001 int flag = 0;
46002 int ispipe;
46003 bool need_nonrelative = false;
46004 - static atomic_t core_dump_count = ATOMIC_INIT(0);
46005 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
46006 struct coredump_params cprm = {
46007 .signr = signr,
46008 .regs = regs,
46009 @@ -2121,6 +2497,9 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
46010
46011 audit_core_dumps(signr);
46012
46013 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
46014 + gr_handle_brute_attach(current, cprm.mm_flags);
46015 +
46016 binfmt = mm->binfmt;
46017 if (!binfmt || !binfmt->core_dump)
46018 goto fail;
46019 @@ -2191,7 +2570,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
46020 }
46021 cprm.limit = RLIM_INFINITY;
46022
46023 - dump_count = atomic_inc_return(&core_dump_count);
46024 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
46025 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
46026 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
46027 task_tgid_vnr(current), current->comm);
46028 @@ -2218,6 +2597,8 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
46029 } else {
46030 struct inode *inode;
46031
46032 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
46033 +
46034 if (cprm.limit < binfmt->min_coredump)
46035 goto fail_unlock;
46036
46037 @@ -2269,7 +2650,7 @@ close_fail:
46038 filp_close(cprm.file, NULL);
46039 fail_dropcount:
46040 if (ispipe)
46041 - atomic_dec(&core_dump_count);
46042 + atomic_dec_unchecked(&core_dump_count);
46043 fail_unlock:
46044 kfree(cn.corename);
46045 fail_corename:
46046 @@ -2288,7 +2669,7 @@ fail:
46047 */
46048 int dump_write(struct file *file, const void *addr, int nr)
46049 {
46050 - return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
46051 + return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
46052 }
46053 EXPORT_SYMBOL(dump_write);
46054
46055 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
46056 index 376aa77..59a129c 100644
46057 --- a/fs/ext2/balloc.c
46058 +++ b/fs/ext2/balloc.c
46059 @@ -1190,10 +1190,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
46060
46061 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
46062 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
46063 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
46064 + if (free_blocks < root_blocks + 1 &&
46065 !uid_eq(sbi->s_resuid, current_fsuid()) &&
46066 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
46067 - !in_group_p (sbi->s_resgid))) {
46068 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
46069 return 0;
46070 }
46071 return 1;
46072 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
46073 index 90d901f..159975f 100644
46074 --- a/fs/ext3/balloc.c
46075 +++ b/fs/ext3/balloc.c
46076 @@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
46077
46078 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
46079 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
46080 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
46081 + if (free_blocks < root_blocks + 1 &&
46082 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
46083 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
46084 - !in_group_p (sbi->s_resgid))) {
46085 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
46086 return 0;
46087 }
46088 return 1;
46089 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
46090 index cf18217..8f6b9c3 100644
46091 --- a/fs/ext4/balloc.c
46092 +++ b/fs/ext4/balloc.c
46093 @@ -498,8 +498,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
46094 /* Hm, nope. Are (enough) root reserved clusters available? */
46095 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
46096 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
46097 - capable(CAP_SYS_RESOURCE) ||
46098 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
46099 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
46100 + capable_nolog(CAP_SYS_RESOURCE)) {
46101
46102 if (free_clusters >= (nclusters + dirty_clusters))
46103 return 1;
46104 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
46105 index b686b43..4b46d01 100644
46106 --- a/fs/ext4/ext4.h
46107 +++ b/fs/ext4/ext4.h
46108 @@ -1248,19 +1248,19 @@ struct ext4_sb_info {
46109 unsigned long s_mb_last_start;
46110
46111 /* stats for buddy allocator */
46112 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
46113 - atomic_t s_bal_success; /* we found long enough chunks */
46114 - atomic_t s_bal_allocated; /* in blocks */
46115 - atomic_t s_bal_ex_scanned; /* total extents scanned */
46116 - atomic_t s_bal_goals; /* goal hits */
46117 - atomic_t s_bal_breaks; /* too long searches */
46118 - atomic_t s_bal_2orders; /* 2^order hits */
46119 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
46120 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
46121 + atomic_unchecked_t s_bal_allocated; /* in blocks */
46122 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
46123 + atomic_unchecked_t s_bal_goals; /* goal hits */
46124 + atomic_unchecked_t s_bal_breaks; /* too long searches */
46125 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
46126 spinlock_t s_bal_lock;
46127 unsigned long s_mb_buddies_generated;
46128 unsigned long long s_mb_generation_time;
46129 - atomic_t s_mb_lost_chunks;
46130 - atomic_t s_mb_preallocated;
46131 - atomic_t s_mb_discarded;
46132 + atomic_unchecked_t s_mb_lost_chunks;
46133 + atomic_unchecked_t s_mb_preallocated;
46134 + atomic_unchecked_t s_mb_discarded;
46135 atomic_t s_lock_busy;
46136
46137 /* locality groups */
46138 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
46139 index b26410c..7383d90 100644
46140 --- a/fs/ext4/mballoc.c
46141 +++ b/fs/ext4/mballoc.c
46142 @@ -1746,7 +1746,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
46143 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
46144
46145 if (EXT4_SB(sb)->s_mb_stats)
46146 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
46147 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
46148
46149 break;
46150 }
46151 @@ -2040,7 +2040,7 @@ repeat:
46152 ac->ac_status = AC_STATUS_CONTINUE;
46153 ac->ac_flags |= EXT4_MB_HINT_FIRST;
46154 cr = 3;
46155 - atomic_inc(&sbi->s_mb_lost_chunks);
46156 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
46157 goto repeat;
46158 }
46159 }
46160 @@ -2551,25 +2551,25 @@ int ext4_mb_release(struct super_block *sb)
46161 if (sbi->s_mb_stats) {
46162 ext4_msg(sb, KERN_INFO,
46163 "mballoc: %u blocks %u reqs (%u success)",
46164 - atomic_read(&sbi->s_bal_allocated),
46165 - atomic_read(&sbi->s_bal_reqs),
46166 - atomic_read(&sbi->s_bal_success));
46167 + atomic_read_unchecked(&sbi->s_bal_allocated),
46168 + atomic_read_unchecked(&sbi->s_bal_reqs),
46169 + atomic_read_unchecked(&sbi->s_bal_success));
46170 ext4_msg(sb, KERN_INFO,
46171 "mballoc: %u extents scanned, %u goal hits, "
46172 "%u 2^N hits, %u breaks, %u lost",
46173 - atomic_read(&sbi->s_bal_ex_scanned),
46174 - atomic_read(&sbi->s_bal_goals),
46175 - atomic_read(&sbi->s_bal_2orders),
46176 - atomic_read(&sbi->s_bal_breaks),
46177 - atomic_read(&sbi->s_mb_lost_chunks));
46178 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
46179 + atomic_read_unchecked(&sbi->s_bal_goals),
46180 + atomic_read_unchecked(&sbi->s_bal_2orders),
46181 + atomic_read_unchecked(&sbi->s_bal_breaks),
46182 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
46183 ext4_msg(sb, KERN_INFO,
46184 "mballoc: %lu generated and it took %Lu",
46185 sbi->s_mb_buddies_generated,
46186 sbi->s_mb_generation_time);
46187 ext4_msg(sb, KERN_INFO,
46188 "mballoc: %u preallocated, %u discarded",
46189 - atomic_read(&sbi->s_mb_preallocated),
46190 - atomic_read(&sbi->s_mb_discarded));
46191 + atomic_read_unchecked(&sbi->s_mb_preallocated),
46192 + atomic_read_unchecked(&sbi->s_mb_discarded));
46193 }
46194
46195 free_percpu(sbi->s_locality_groups);
46196 @@ -3051,16 +3051,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
46197 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
46198
46199 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
46200 - atomic_inc(&sbi->s_bal_reqs);
46201 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
46202 + atomic_inc_unchecked(&sbi->s_bal_reqs);
46203 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
46204 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
46205 - atomic_inc(&sbi->s_bal_success);
46206 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
46207 + atomic_inc_unchecked(&sbi->s_bal_success);
46208 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
46209 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
46210 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
46211 - atomic_inc(&sbi->s_bal_goals);
46212 + atomic_inc_unchecked(&sbi->s_bal_goals);
46213 if (ac->ac_found > sbi->s_mb_max_to_scan)
46214 - atomic_inc(&sbi->s_bal_breaks);
46215 + atomic_inc_unchecked(&sbi->s_bal_breaks);
46216 }
46217
46218 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
46219 @@ -3460,7 +3460,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
46220 trace_ext4_mb_new_inode_pa(ac, pa);
46221
46222 ext4_mb_use_inode_pa(ac, pa);
46223 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
46224 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
46225
46226 ei = EXT4_I(ac->ac_inode);
46227 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
46228 @@ -3520,7 +3520,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
46229 trace_ext4_mb_new_group_pa(ac, pa);
46230
46231 ext4_mb_use_group_pa(ac, pa);
46232 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
46233 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
46234
46235 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
46236 lg = ac->ac_lg;
46237 @@ -3609,7 +3609,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
46238 * from the bitmap and continue.
46239 */
46240 }
46241 - atomic_add(free, &sbi->s_mb_discarded);
46242 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
46243
46244 return err;
46245 }
46246 @@ -3627,7 +3627,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
46247 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
46248 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
46249 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
46250 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
46251 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
46252 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
46253
46254 return 0;
46255 diff --git a/fs/fcntl.c b/fs/fcntl.c
46256 index 887b5ba..0e3f2c3 100644
46257 --- a/fs/fcntl.c
46258 +++ b/fs/fcntl.c
46259 @@ -225,6 +225,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
46260 if (err)
46261 return err;
46262
46263 + if (gr_handle_chroot_fowner(pid, type))
46264 + return -ENOENT;
46265 + if (gr_check_protected_task_fowner(pid, type))
46266 + return -EACCES;
46267 +
46268 f_modown(filp, pid, type, force);
46269 return 0;
46270 }
46271 @@ -267,7 +272,7 @@ pid_t f_getown(struct file *filp)
46272
46273 static int f_setown_ex(struct file *filp, unsigned long arg)
46274 {
46275 - struct f_owner_ex * __user owner_p = (void * __user)arg;
46276 + struct f_owner_ex __user *owner_p = (void __user *)arg;
46277 struct f_owner_ex owner;
46278 struct pid *pid;
46279 int type;
46280 @@ -307,7 +312,7 @@ static int f_setown_ex(struct file *filp, unsigned long arg)
46281
46282 static int f_getown_ex(struct file *filp, unsigned long arg)
46283 {
46284 - struct f_owner_ex * __user owner_p = (void * __user)arg;
46285 + struct f_owner_ex __user *owner_p = (void __user *)arg;
46286 struct f_owner_ex owner;
46287 int ret = 0;
46288
46289 @@ -374,6 +379,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
46290 switch (cmd) {
46291 case F_DUPFD:
46292 case F_DUPFD_CLOEXEC:
46293 + gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
46294 if (arg >= rlimit(RLIMIT_NOFILE))
46295 break;
46296 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
46297 diff --git a/fs/fifo.c b/fs/fifo.c
46298 index cf6f434..3d7942c 100644
46299 --- a/fs/fifo.c
46300 +++ b/fs/fifo.c
46301 @@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
46302 */
46303 filp->f_op = &read_pipefifo_fops;
46304 pipe->r_counter++;
46305 - if (pipe->readers++ == 0)
46306 + if (atomic_inc_return(&pipe->readers) == 1)
46307 wake_up_partner(inode);
46308
46309 - if (!pipe->writers) {
46310 + if (!atomic_read(&pipe->writers)) {
46311 if ((filp->f_flags & O_NONBLOCK)) {
46312 /* suppress POLLHUP until we have
46313 * seen a writer */
46314 @@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
46315 * errno=ENXIO when there is no process reading the FIFO.
46316 */
46317 ret = -ENXIO;
46318 - if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
46319 + if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
46320 goto err;
46321
46322 filp->f_op = &write_pipefifo_fops;
46323 pipe->w_counter++;
46324 - if (!pipe->writers++)
46325 + if (atomic_inc_return(&pipe->writers) == 1)
46326 wake_up_partner(inode);
46327
46328 - if (!pipe->readers) {
46329 + if (!atomic_read(&pipe->readers)) {
46330 if (wait_for_partner(inode, &pipe->r_counter))
46331 goto err_wr;
46332 }
46333 @@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
46334 */
46335 filp->f_op = &rdwr_pipefifo_fops;
46336
46337 - pipe->readers++;
46338 - pipe->writers++;
46339 + atomic_inc(&pipe->readers);
46340 + atomic_inc(&pipe->writers);
46341 pipe->r_counter++;
46342 pipe->w_counter++;
46343 - if (pipe->readers == 1 || pipe->writers == 1)
46344 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
46345 wake_up_partner(inode);
46346 break;
46347
46348 @@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
46349 return 0;
46350
46351 err_rd:
46352 - if (!--pipe->readers)
46353 + if (atomic_dec_and_test(&pipe->readers))
46354 wake_up_interruptible(&pipe->wait);
46355 ret = -ERESTARTSYS;
46356 goto err;
46357
46358 err_wr:
46359 - if (!--pipe->writers)
46360 + if (atomic_dec_and_test(&pipe->writers))
46361 wake_up_interruptible(&pipe->wait);
46362 ret = -ERESTARTSYS;
46363 goto err;
46364
46365 err:
46366 - if (!pipe->readers && !pipe->writers)
46367 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
46368 free_pipe_info(inode);
46369
46370 err_nocleanup:
46371 diff --git a/fs/file.c b/fs/file.c
46372 index ba3f605..fade102 100644
46373 --- a/fs/file.c
46374 +++ b/fs/file.c
46375 @@ -15,6 +15,7 @@
46376 #include <linux/slab.h>
46377 #include <linux/vmalloc.h>
46378 #include <linux/file.h>
46379 +#include <linux/security.h>
46380 #include <linux/fdtable.h>
46381 #include <linux/bitops.h>
46382 #include <linux/interrupt.h>
46383 @@ -255,6 +256,7 @@ int expand_files(struct files_struct *files, int nr)
46384 * N.B. For clone tasks sharing a files structure, this test
46385 * will limit the total number of files that can be opened.
46386 */
46387 + gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
46388 if (nr >= rlimit(RLIMIT_NOFILE))
46389 return -EMFILE;
46390
46391 diff --git a/fs/filesystems.c b/fs/filesystems.c
46392 index 96f2428..f5eeb8e 100644
46393 --- a/fs/filesystems.c
46394 +++ b/fs/filesystems.c
46395 @@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
46396 int len = dot ? dot - name : strlen(name);
46397
46398 fs = __get_fs_type(name, len);
46399 +
46400 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
46401 + if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
46402 +#else
46403 if (!fs && (request_module("%.*s", len, name) == 0))
46404 +#endif
46405 fs = __get_fs_type(name, len);
46406
46407 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
46408 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
46409 index 5df4775..f656176 100644
46410 --- a/fs/fs_struct.c
46411 +++ b/fs/fs_struct.c
46412 @@ -4,6 +4,7 @@
46413 #include <linux/path.h>
46414 #include <linux/slab.h>
46415 #include <linux/fs_struct.h>
46416 +#include <linux/grsecurity.h>
46417 #include "internal.h"
46418
46419 /*
46420 @@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
46421 write_seqcount_begin(&fs->seq);
46422 old_root = fs->root;
46423 fs->root = *path;
46424 + gr_set_chroot_entries(current, path);
46425 write_seqcount_end(&fs->seq);
46426 spin_unlock(&fs->lock);
46427 if (old_root.dentry)
46428 @@ -53,6 +55,21 @@ static inline int replace_path(struct path *p, const struct path *old, const str
46429 return 1;
46430 }
46431
46432 +static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
46433 +{
46434 + if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
46435 + return 0;
46436 + *p = *new;
46437 +
46438 + /* This function is only called from pivot_root(). Leave our
46439 + gr_chroot_dentry and is_chrooted flags as-is, so that a
46440 + pivoted root isn't treated as a chroot
46441 + */
46442 + //gr_set_chroot_entries(task, new);
46443 +
46444 + return 1;
46445 +}
46446 +
46447 void chroot_fs_refs(struct path *old_root, struct path *new_root)
46448 {
46449 struct task_struct *g, *p;
46450 @@ -67,7 +84,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
46451 int hits = 0;
46452 spin_lock(&fs->lock);
46453 write_seqcount_begin(&fs->seq);
46454 - hits += replace_path(&fs->root, old_root, new_root);
46455 + hits += replace_root_path(p, &fs->root, old_root, new_root);
46456 hits += replace_path(&fs->pwd, old_root, new_root);
46457 write_seqcount_end(&fs->seq);
46458 while (hits--) {
46459 @@ -94,12 +111,15 @@ void exit_fs(struct task_struct *tsk)
46460 {
46461 struct fs_struct *fs = tsk->fs;
46462
46463 + gr_put_exec_file(tsk);
46464 +
46465 if (fs) {
46466 int kill;
46467 task_lock(tsk);
46468 spin_lock(&fs->lock);
46469 tsk->fs = NULL;
46470 - kill = !--fs->users;
46471 + gr_clear_chroot_entries(tsk);
46472 + kill = !atomic_dec_return(&fs->users);
46473 spin_unlock(&fs->lock);
46474 task_unlock(tsk);
46475 if (kill)
46476 @@ -112,7 +132,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
46477 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
46478 /* We don't need to lock fs - think why ;-) */
46479 if (fs) {
46480 - fs->users = 1;
46481 + atomic_set(&fs->users, 1);
46482 fs->in_exec = 0;
46483 spin_lock_init(&fs->lock);
46484 seqcount_init(&fs->seq);
46485 @@ -121,6 +141,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
46486 spin_lock(&old->lock);
46487 fs->root = old->root;
46488 path_get(&fs->root);
46489 + /* instead of calling gr_set_chroot_entries here,
46490 + we call it from every caller of this function
46491 + */
46492 fs->pwd = old->pwd;
46493 path_get(&fs->pwd);
46494 spin_unlock(&old->lock);
46495 @@ -139,8 +162,9 @@ int unshare_fs_struct(void)
46496
46497 task_lock(current);
46498 spin_lock(&fs->lock);
46499 - kill = !--fs->users;
46500 + kill = !atomic_dec_return(&fs->users);
46501 current->fs = new_fs;
46502 + gr_set_chroot_entries(current, &new_fs->root);
46503 spin_unlock(&fs->lock);
46504 task_unlock(current);
46505
46506 @@ -153,13 +177,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
46507
46508 int current_umask(void)
46509 {
46510 - return current->fs->umask;
46511 + return current->fs->umask | gr_acl_umask();
46512 }
46513 EXPORT_SYMBOL(current_umask);
46514
46515 /* to be mentioned only in INIT_TASK */
46516 struct fs_struct init_fs = {
46517 - .users = 1,
46518 + .users = ATOMIC_INIT(1),
46519 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
46520 .seq = SEQCNT_ZERO,
46521 .umask = 0022,
46522 @@ -169,18 +193,21 @@ void daemonize_fs_struct(void)
46523 {
46524 struct fs_struct *fs = current->fs;
46525
46526 + gr_put_exec_file(current);
46527 +
46528 if (fs) {
46529 int kill;
46530
46531 task_lock(current);
46532
46533 spin_lock(&init_fs.lock);
46534 - init_fs.users++;
46535 + atomic_inc(&init_fs.users);
46536 spin_unlock(&init_fs.lock);
46537
46538 spin_lock(&fs->lock);
46539 current->fs = &init_fs;
46540 - kill = !--fs->users;
46541 + gr_set_chroot_entries(current, &current->fs->root);
46542 + kill = !atomic_dec_return(&fs->users);
46543 spin_unlock(&fs->lock);
46544
46545 task_unlock(current);
46546 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
46547 index 9905350..02eaec4 100644
46548 --- a/fs/fscache/cookie.c
46549 +++ b/fs/fscache/cookie.c
46550 @@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
46551 parent ? (char *) parent->def->name : "<no-parent>",
46552 def->name, netfs_data);
46553
46554 - fscache_stat(&fscache_n_acquires);
46555 + fscache_stat_unchecked(&fscache_n_acquires);
46556
46557 /* if there's no parent cookie, then we don't create one here either */
46558 if (!parent) {
46559 - fscache_stat(&fscache_n_acquires_null);
46560 + fscache_stat_unchecked(&fscache_n_acquires_null);
46561 _leave(" [no parent]");
46562 return NULL;
46563 }
46564 @@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
46565 /* allocate and initialise a cookie */
46566 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
46567 if (!cookie) {
46568 - fscache_stat(&fscache_n_acquires_oom);
46569 + fscache_stat_unchecked(&fscache_n_acquires_oom);
46570 _leave(" [ENOMEM]");
46571 return NULL;
46572 }
46573 @@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
46574
46575 switch (cookie->def->type) {
46576 case FSCACHE_COOKIE_TYPE_INDEX:
46577 - fscache_stat(&fscache_n_cookie_index);
46578 + fscache_stat_unchecked(&fscache_n_cookie_index);
46579 break;
46580 case FSCACHE_COOKIE_TYPE_DATAFILE:
46581 - fscache_stat(&fscache_n_cookie_data);
46582 + fscache_stat_unchecked(&fscache_n_cookie_data);
46583 break;
46584 default:
46585 - fscache_stat(&fscache_n_cookie_special);
46586 + fscache_stat_unchecked(&fscache_n_cookie_special);
46587 break;
46588 }
46589
46590 @@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
46591 if (fscache_acquire_non_index_cookie(cookie) < 0) {
46592 atomic_dec(&parent->n_children);
46593 __fscache_cookie_put(cookie);
46594 - fscache_stat(&fscache_n_acquires_nobufs);
46595 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
46596 _leave(" = NULL");
46597 return NULL;
46598 }
46599 }
46600
46601 - fscache_stat(&fscache_n_acquires_ok);
46602 + fscache_stat_unchecked(&fscache_n_acquires_ok);
46603 _leave(" = %p", cookie);
46604 return cookie;
46605 }
46606 @@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
46607 cache = fscache_select_cache_for_object(cookie->parent);
46608 if (!cache) {
46609 up_read(&fscache_addremove_sem);
46610 - fscache_stat(&fscache_n_acquires_no_cache);
46611 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
46612 _leave(" = -ENOMEDIUM [no cache]");
46613 return -ENOMEDIUM;
46614 }
46615 @@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
46616 object = cache->ops->alloc_object(cache, cookie);
46617 fscache_stat_d(&fscache_n_cop_alloc_object);
46618 if (IS_ERR(object)) {
46619 - fscache_stat(&fscache_n_object_no_alloc);
46620 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
46621 ret = PTR_ERR(object);
46622 goto error;
46623 }
46624
46625 - fscache_stat(&fscache_n_object_alloc);
46626 + fscache_stat_unchecked(&fscache_n_object_alloc);
46627
46628 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
46629
46630 @@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
46631 struct fscache_object *object;
46632 struct hlist_node *_p;
46633
46634 - fscache_stat(&fscache_n_updates);
46635 + fscache_stat_unchecked(&fscache_n_updates);
46636
46637 if (!cookie) {
46638 - fscache_stat(&fscache_n_updates_null);
46639 + fscache_stat_unchecked(&fscache_n_updates_null);
46640 _leave(" [no cookie]");
46641 return;
46642 }
46643 @@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
46644 struct fscache_object *object;
46645 unsigned long event;
46646
46647 - fscache_stat(&fscache_n_relinquishes);
46648 + fscache_stat_unchecked(&fscache_n_relinquishes);
46649 if (retire)
46650 - fscache_stat(&fscache_n_relinquishes_retire);
46651 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
46652
46653 if (!cookie) {
46654 - fscache_stat(&fscache_n_relinquishes_null);
46655 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
46656 _leave(" [no cookie]");
46657 return;
46658 }
46659 @@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
46660
46661 /* wait for the cookie to finish being instantiated (or to fail) */
46662 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
46663 - fscache_stat(&fscache_n_relinquishes_waitcrt);
46664 + fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
46665 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
46666 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
46667 }
46668 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
46669 index f6aad48..88dcf26 100644
46670 --- a/fs/fscache/internal.h
46671 +++ b/fs/fscache/internal.h
46672 @@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
46673 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
46674 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
46675
46676 -extern atomic_t fscache_n_op_pend;
46677 -extern atomic_t fscache_n_op_run;
46678 -extern atomic_t fscache_n_op_enqueue;
46679 -extern atomic_t fscache_n_op_deferred_release;
46680 -extern atomic_t fscache_n_op_release;
46681 -extern atomic_t fscache_n_op_gc;
46682 -extern atomic_t fscache_n_op_cancelled;
46683 -extern atomic_t fscache_n_op_rejected;
46684 +extern atomic_unchecked_t fscache_n_op_pend;
46685 +extern atomic_unchecked_t fscache_n_op_run;
46686 +extern atomic_unchecked_t fscache_n_op_enqueue;
46687 +extern atomic_unchecked_t fscache_n_op_deferred_release;
46688 +extern atomic_unchecked_t fscache_n_op_release;
46689 +extern atomic_unchecked_t fscache_n_op_gc;
46690 +extern atomic_unchecked_t fscache_n_op_cancelled;
46691 +extern atomic_unchecked_t fscache_n_op_rejected;
46692
46693 -extern atomic_t fscache_n_attr_changed;
46694 -extern atomic_t fscache_n_attr_changed_ok;
46695 -extern atomic_t fscache_n_attr_changed_nobufs;
46696 -extern atomic_t fscache_n_attr_changed_nomem;
46697 -extern atomic_t fscache_n_attr_changed_calls;
46698 +extern atomic_unchecked_t fscache_n_attr_changed;
46699 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
46700 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
46701 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
46702 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
46703
46704 -extern atomic_t fscache_n_allocs;
46705 -extern atomic_t fscache_n_allocs_ok;
46706 -extern atomic_t fscache_n_allocs_wait;
46707 -extern atomic_t fscache_n_allocs_nobufs;
46708 -extern atomic_t fscache_n_allocs_intr;
46709 -extern atomic_t fscache_n_allocs_object_dead;
46710 -extern atomic_t fscache_n_alloc_ops;
46711 -extern atomic_t fscache_n_alloc_op_waits;
46712 +extern atomic_unchecked_t fscache_n_allocs;
46713 +extern atomic_unchecked_t fscache_n_allocs_ok;
46714 +extern atomic_unchecked_t fscache_n_allocs_wait;
46715 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
46716 +extern atomic_unchecked_t fscache_n_allocs_intr;
46717 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
46718 +extern atomic_unchecked_t fscache_n_alloc_ops;
46719 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
46720
46721 -extern atomic_t fscache_n_retrievals;
46722 -extern atomic_t fscache_n_retrievals_ok;
46723 -extern atomic_t fscache_n_retrievals_wait;
46724 -extern atomic_t fscache_n_retrievals_nodata;
46725 -extern atomic_t fscache_n_retrievals_nobufs;
46726 -extern atomic_t fscache_n_retrievals_intr;
46727 -extern atomic_t fscache_n_retrievals_nomem;
46728 -extern atomic_t fscache_n_retrievals_object_dead;
46729 -extern atomic_t fscache_n_retrieval_ops;
46730 -extern atomic_t fscache_n_retrieval_op_waits;
46731 +extern atomic_unchecked_t fscache_n_retrievals;
46732 +extern atomic_unchecked_t fscache_n_retrievals_ok;
46733 +extern atomic_unchecked_t fscache_n_retrievals_wait;
46734 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
46735 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
46736 +extern atomic_unchecked_t fscache_n_retrievals_intr;
46737 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
46738 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
46739 +extern atomic_unchecked_t fscache_n_retrieval_ops;
46740 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
46741
46742 -extern atomic_t fscache_n_stores;
46743 -extern atomic_t fscache_n_stores_ok;
46744 -extern atomic_t fscache_n_stores_again;
46745 -extern atomic_t fscache_n_stores_nobufs;
46746 -extern atomic_t fscache_n_stores_oom;
46747 -extern atomic_t fscache_n_store_ops;
46748 -extern atomic_t fscache_n_store_calls;
46749 -extern atomic_t fscache_n_store_pages;
46750 -extern atomic_t fscache_n_store_radix_deletes;
46751 -extern atomic_t fscache_n_store_pages_over_limit;
46752 +extern atomic_unchecked_t fscache_n_stores;
46753 +extern atomic_unchecked_t fscache_n_stores_ok;
46754 +extern atomic_unchecked_t fscache_n_stores_again;
46755 +extern atomic_unchecked_t fscache_n_stores_nobufs;
46756 +extern atomic_unchecked_t fscache_n_stores_oom;
46757 +extern atomic_unchecked_t fscache_n_store_ops;
46758 +extern atomic_unchecked_t fscache_n_store_calls;
46759 +extern atomic_unchecked_t fscache_n_store_pages;
46760 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
46761 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
46762
46763 -extern atomic_t fscache_n_store_vmscan_not_storing;
46764 -extern atomic_t fscache_n_store_vmscan_gone;
46765 -extern atomic_t fscache_n_store_vmscan_busy;
46766 -extern atomic_t fscache_n_store_vmscan_cancelled;
46767 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
46768 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
46769 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
46770 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
46771
46772 -extern atomic_t fscache_n_marks;
46773 -extern atomic_t fscache_n_uncaches;
46774 +extern atomic_unchecked_t fscache_n_marks;
46775 +extern atomic_unchecked_t fscache_n_uncaches;
46776
46777 -extern atomic_t fscache_n_acquires;
46778 -extern atomic_t fscache_n_acquires_null;
46779 -extern atomic_t fscache_n_acquires_no_cache;
46780 -extern atomic_t fscache_n_acquires_ok;
46781 -extern atomic_t fscache_n_acquires_nobufs;
46782 -extern atomic_t fscache_n_acquires_oom;
46783 +extern atomic_unchecked_t fscache_n_acquires;
46784 +extern atomic_unchecked_t fscache_n_acquires_null;
46785 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
46786 +extern atomic_unchecked_t fscache_n_acquires_ok;
46787 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
46788 +extern atomic_unchecked_t fscache_n_acquires_oom;
46789
46790 -extern atomic_t fscache_n_updates;
46791 -extern atomic_t fscache_n_updates_null;
46792 -extern atomic_t fscache_n_updates_run;
46793 +extern atomic_unchecked_t fscache_n_updates;
46794 +extern atomic_unchecked_t fscache_n_updates_null;
46795 +extern atomic_unchecked_t fscache_n_updates_run;
46796
46797 -extern atomic_t fscache_n_relinquishes;
46798 -extern atomic_t fscache_n_relinquishes_null;
46799 -extern atomic_t fscache_n_relinquishes_waitcrt;
46800 -extern atomic_t fscache_n_relinquishes_retire;
46801 +extern atomic_unchecked_t fscache_n_relinquishes;
46802 +extern atomic_unchecked_t fscache_n_relinquishes_null;
46803 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
46804 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
46805
46806 -extern atomic_t fscache_n_cookie_index;
46807 -extern atomic_t fscache_n_cookie_data;
46808 -extern atomic_t fscache_n_cookie_special;
46809 +extern atomic_unchecked_t fscache_n_cookie_index;
46810 +extern atomic_unchecked_t fscache_n_cookie_data;
46811 +extern atomic_unchecked_t fscache_n_cookie_special;
46812
46813 -extern atomic_t fscache_n_object_alloc;
46814 -extern atomic_t fscache_n_object_no_alloc;
46815 -extern atomic_t fscache_n_object_lookups;
46816 -extern atomic_t fscache_n_object_lookups_negative;
46817 -extern atomic_t fscache_n_object_lookups_positive;
46818 -extern atomic_t fscache_n_object_lookups_timed_out;
46819 -extern atomic_t fscache_n_object_created;
46820 -extern atomic_t fscache_n_object_avail;
46821 -extern atomic_t fscache_n_object_dead;
46822 +extern atomic_unchecked_t fscache_n_object_alloc;
46823 +extern atomic_unchecked_t fscache_n_object_no_alloc;
46824 +extern atomic_unchecked_t fscache_n_object_lookups;
46825 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
46826 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
46827 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
46828 +extern atomic_unchecked_t fscache_n_object_created;
46829 +extern atomic_unchecked_t fscache_n_object_avail;
46830 +extern atomic_unchecked_t fscache_n_object_dead;
46831
46832 -extern atomic_t fscache_n_checkaux_none;
46833 -extern atomic_t fscache_n_checkaux_okay;
46834 -extern atomic_t fscache_n_checkaux_update;
46835 -extern atomic_t fscache_n_checkaux_obsolete;
46836 +extern atomic_unchecked_t fscache_n_checkaux_none;
46837 +extern atomic_unchecked_t fscache_n_checkaux_okay;
46838 +extern atomic_unchecked_t fscache_n_checkaux_update;
46839 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
46840
46841 extern atomic_t fscache_n_cop_alloc_object;
46842 extern atomic_t fscache_n_cop_lookup_object;
46843 @@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
46844 atomic_inc(stat);
46845 }
46846
46847 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
46848 +{
46849 + atomic_inc_unchecked(stat);
46850 +}
46851 +
46852 static inline void fscache_stat_d(atomic_t *stat)
46853 {
46854 atomic_dec(stat);
46855 @@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
46856
46857 #define __fscache_stat(stat) (NULL)
46858 #define fscache_stat(stat) do {} while (0)
46859 +#define fscache_stat_unchecked(stat) do {} while (0)
46860 #define fscache_stat_d(stat) do {} while (0)
46861 #endif
46862
46863 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
46864 index b6b897c..0ffff9c 100644
46865 --- a/fs/fscache/object.c
46866 +++ b/fs/fscache/object.c
46867 @@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46868 /* update the object metadata on disk */
46869 case FSCACHE_OBJECT_UPDATING:
46870 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
46871 - fscache_stat(&fscache_n_updates_run);
46872 + fscache_stat_unchecked(&fscache_n_updates_run);
46873 fscache_stat(&fscache_n_cop_update_object);
46874 object->cache->ops->update_object(object);
46875 fscache_stat_d(&fscache_n_cop_update_object);
46876 @@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46877 spin_lock(&object->lock);
46878 object->state = FSCACHE_OBJECT_DEAD;
46879 spin_unlock(&object->lock);
46880 - fscache_stat(&fscache_n_object_dead);
46881 + fscache_stat_unchecked(&fscache_n_object_dead);
46882 goto terminal_transit;
46883
46884 /* handle the parent cache of this object being withdrawn from
46885 @@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46886 spin_lock(&object->lock);
46887 object->state = FSCACHE_OBJECT_DEAD;
46888 spin_unlock(&object->lock);
46889 - fscache_stat(&fscache_n_object_dead);
46890 + fscache_stat_unchecked(&fscache_n_object_dead);
46891 goto terminal_transit;
46892
46893 /* complain about the object being woken up once it is
46894 @@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
46895 parent->cookie->def->name, cookie->def->name,
46896 object->cache->tag->name);
46897
46898 - fscache_stat(&fscache_n_object_lookups);
46899 + fscache_stat_unchecked(&fscache_n_object_lookups);
46900 fscache_stat(&fscache_n_cop_lookup_object);
46901 ret = object->cache->ops->lookup_object(object);
46902 fscache_stat_d(&fscache_n_cop_lookup_object);
46903 @@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
46904 if (ret == -ETIMEDOUT) {
46905 /* probably stuck behind another object, so move this one to
46906 * the back of the queue */
46907 - fscache_stat(&fscache_n_object_lookups_timed_out);
46908 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
46909 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
46910 }
46911
46912 @@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
46913
46914 spin_lock(&object->lock);
46915 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
46916 - fscache_stat(&fscache_n_object_lookups_negative);
46917 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
46918
46919 /* transit here to allow write requests to begin stacking up
46920 * and read requests to begin returning ENODATA */
46921 @@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
46922 * result, in which case there may be data available */
46923 spin_lock(&object->lock);
46924 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
46925 - fscache_stat(&fscache_n_object_lookups_positive);
46926 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
46927
46928 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
46929
46930 @@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
46931 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
46932 } else {
46933 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
46934 - fscache_stat(&fscache_n_object_created);
46935 + fscache_stat_unchecked(&fscache_n_object_created);
46936
46937 object->state = FSCACHE_OBJECT_AVAILABLE;
46938 spin_unlock(&object->lock);
46939 @@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
46940 fscache_enqueue_dependents(object);
46941
46942 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
46943 - fscache_stat(&fscache_n_object_avail);
46944 + fscache_stat_unchecked(&fscache_n_object_avail);
46945
46946 _leave("");
46947 }
46948 @@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
46949 enum fscache_checkaux result;
46950
46951 if (!object->cookie->def->check_aux) {
46952 - fscache_stat(&fscache_n_checkaux_none);
46953 + fscache_stat_unchecked(&fscache_n_checkaux_none);
46954 return FSCACHE_CHECKAUX_OKAY;
46955 }
46956
46957 @@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
46958 switch (result) {
46959 /* entry okay as is */
46960 case FSCACHE_CHECKAUX_OKAY:
46961 - fscache_stat(&fscache_n_checkaux_okay);
46962 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
46963 break;
46964
46965 /* entry requires update */
46966 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
46967 - fscache_stat(&fscache_n_checkaux_update);
46968 + fscache_stat_unchecked(&fscache_n_checkaux_update);
46969 break;
46970
46971 /* entry requires deletion */
46972 case FSCACHE_CHECKAUX_OBSOLETE:
46973 - fscache_stat(&fscache_n_checkaux_obsolete);
46974 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
46975 break;
46976
46977 default:
46978 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
46979 index 30afdfa..2256596 100644
46980 --- a/fs/fscache/operation.c
46981 +++ b/fs/fscache/operation.c
46982 @@ -17,7 +17,7 @@
46983 #include <linux/slab.h>
46984 #include "internal.h"
46985
46986 -atomic_t fscache_op_debug_id;
46987 +atomic_unchecked_t fscache_op_debug_id;
46988 EXPORT_SYMBOL(fscache_op_debug_id);
46989
46990 /**
46991 @@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
46992 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
46993 ASSERTCMP(atomic_read(&op->usage), >, 0);
46994
46995 - fscache_stat(&fscache_n_op_enqueue);
46996 + fscache_stat_unchecked(&fscache_n_op_enqueue);
46997 switch (op->flags & FSCACHE_OP_TYPE) {
46998 case FSCACHE_OP_ASYNC:
46999 _debug("queue async");
47000 @@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
47001 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
47002 if (op->processor)
47003 fscache_enqueue_operation(op);
47004 - fscache_stat(&fscache_n_op_run);
47005 + fscache_stat_unchecked(&fscache_n_op_run);
47006 }
47007
47008 /*
47009 @@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
47010 if (object->n_ops > 1) {
47011 atomic_inc(&op->usage);
47012 list_add_tail(&op->pend_link, &object->pending_ops);
47013 - fscache_stat(&fscache_n_op_pend);
47014 + fscache_stat_unchecked(&fscache_n_op_pend);
47015 } else if (!list_empty(&object->pending_ops)) {
47016 atomic_inc(&op->usage);
47017 list_add_tail(&op->pend_link, &object->pending_ops);
47018 - fscache_stat(&fscache_n_op_pend);
47019 + fscache_stat_unchecked(&fscache_n_op_pend);
47020 fscache_start_operations(object);
47021 } else {
47022 ASSERTCMP(object->n_in_progress, ==, 0);
47023 @@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
47024 object->n_exclusive++; /* reads and writes must wait */
47025 atomic_inc(&op->usage);
47026 list_add_tail(&op->pend_link, &object->pending_ops);
47027 - fscache_stat(&fscache_n_op_pend);
47028 + fscache_stat_unchecked(&fscache_n_op_pend);
47029 ret = 0;
47030 } else {
47031 /* not allowed to submit ops in any other state */
47032 @@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
47033 if (object->n_exclusive > 0) {
47034 atomic_inc(&op->usage);
47035 list_add_tail(&op->pend_link, &object->pending_ops);
47036 - fscache_stat(&fscache_n_op_pend);
47037 + fscache_stat_unchecked(&fscache_n_op_pend);
47038 } else if (!list_empty(&object->pending_ops)) {
47039 atomic_inc(&op->usage);
47040 list_add_tail(&op->pend_link, &object->pending_ops);
47041 - fscache_stat(&fscache_n_op_pend);
47042 + fscache_stat_unchecked(&fscache_n_op_pend);
47043 fscache_start_operations(object);
47044 } else {
47045 ASSERTCMP(object->n_exclusive, ==, 0);
47046 @@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
47047 object->n_ops++;
47048 atomic_inc(&op->usage);
47049 list_add_tail(&op->pend_link, &object->pending_ops);
47050 - fscache_stat(&fscache_n_op_pend);
47051 + fscache_stat_unchecked(&fscache_n_op_pend);
47052 ret = 0;
47053 } else if (object->state == FSCACHE_OBJECT_DYING ||
47054 object->state == FSCACHE_OBJECT_LC_DYING ||
47055 object->state == FSCACHE_OBJECT_WITHDRAWING) {
47056 - fscache_stat(&fscache_n_op_rejected);
47057 + fscache_stat_unchecked(&fscache_n_op_rejected);
47058 ret = -ENOBUFS;
47059 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
47060 fscache_report_unexpected_submission(object, op, ostate);
47061 @@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
47062
47063 ret = -EBUSY;
47064 if (!list_empty(&op->pend_link)) {
47065 - fscache_stat(&fscache_n_op_cancelled);
47066 + fscache_stat_unchecked(&fscache_n_op_cancelled);
47067 list_del_init(&op->pend_link);
47068 object->n_ops--;
47069 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
47070 @@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
47071 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
47072 BUG();
47073
47074 - fscache_stat(&fscache_n_op_release);
47075 + fscache_stat_unchecked(&fscache_n_op_release);
47076
47077 if (op->release) {
47078 op->release(op);
47079 @@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
47080 * lock, and defer it otherwise */
47081 if (!spin_trylock(&object->lock)) {
47082 _debug("defer put");
47083 - fscache_stat(&fscache_n_op_deferred_release);
47084 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
47085
47086 cache = object->cache;
47087 spin_lock(&cache->op_gc_list_lock);
47088 @@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
47089
47090 _debug("GC DEFERRED REL OBJ%x OP%x",
47091 object->debug_id, op->debug_id);
47092 - fscache_stat(&fscache_n_op_gc);
47093 + fscache_stat_unchecked(&fscache_n_op_gc);
47094
47095 ASSERTCMP(atomic_read(&op->usage), ==, 0);
47096
47097 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
47098 index 3f7a59b..cf196cc 100644
47099 --- a/fs/fscache/page.c
47100 +++ b/fs/fscache/page.c
47101 @@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
47102 val = radix_tree_lookup(&cookie->stores, page->index);
47103 if (!val) {
47104 rcu_read_unlock();
47105 - fscache_stat(&fscache_n_store_vmscan_not_storing);
47106 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
47107 __fscache_uncache_page(cookie, page);
47108 return true;
47109 }
47110 @@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
47111 spin_unlock(&cookie->stores_lock);
47112
47113 if (xpage) {
47114 - fscache_stat(&fscache_n_store_vmscan_cancelled);
47115 - fscache_stat(&fscache_n_store_radix_deletes);
47116 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
47117 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
47118 ASSERTCMP(xpage, ==, page);
47119 } else {
47120 - fscache_stat(&fscache_n_store_vmscan_gone);
47121 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
47122 }
47123
47124 wake_up_bit(&cookie->flags, 0);
47125 @@ -107,7 +107,7 @@ page_busy:
47126 /* we might want to wait here, but that could deadlock the allocator as
47127 * the work threads writing to the cache may all end up sleeping
47128 * on memory allocation */
47129 - fscache_stat(&fscache_n_store_vmscan_busy);
47130 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
47131 return false;
47132 }
47133 EXPORT_SYMBOL(__fscache_maybe_release_page);
47134 @@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
47135 FSCACHE_COOKIE_STORING_TAG);
47136 if (!radix_tree_tag_get(&cookie->stores, page->index,
47137 FSCACHE_COOKIE_PENDING_TAG)) {
47138 - fscache_stat(&fscache_n_store_radix_deletes);
47139 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
47140 xpage = radix_tree_delete(&cookie->stores, page->index);
47141 }
47142 spin_unlock(&cookie->stores_lock);
47143 @@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
47144
47145 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
47146
47147 - fscache_stat(&fscache_n_attr_changed_calls);
47148 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
47149
47150 if (fscache_object_is_active(object)) {
47151 fscache_stat(&fscache_n_cop_attr_changed);
47152 @@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
47153
47154 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
47155
47156 - fscache_stat(&fscache_n_attr_changed);
47157 + fscache_stat_unchecked(&fscache_n_attr_changed);
47158
47159 op = kzalloc(sizeof(*op), GFP_KERNEL);
47160 if (!op) {
47161 - fscache_stat(&fscache_n_attr_changed_nomem);
47162 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
47163 _leave(" = -ENOMEM");
47164 return -ENOMEM;
47165 }
47166 @@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
47167 if (fscache_submit_exclusive_op(object, op) < 0)
47168 goto nobufs;
47169 spin_unlock(&cookie->lock);
47170 - fscache_stat(&fscache_n_attr_changed_ok);
47171 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
47172 fscache_put_operation(op);
47173 _leave(" = 0");
47174 return 0;
47175 @@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
47176 nobufs:
47177 spin_unlock(&cookie->lock);
47178 kfree(op);
47179 - fscache_stat(&fscache_n_attr_changed_nobufs);
47180 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
47181 _leave(" = %d", -ENOBUFS);
47182 return -ENOBUFS;
47183 }
47184 @@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
47185 /* allocate a retrieval operation and attempt to submit it */
47186 op = kzalloc(sizeof(*op), GFP_NOIO);
47187 if (!op) {
47188 - fscache_stat(&fscache_n_retrievals_nomem);
47189 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
47190 return NULL;
47191 }
47192
47193 @@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
47194 return 0;
47195 }
47196
47197 - fscache_stat(&fscache_n_retrievals_wait);
47198 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
47199
47200 jif = jiffies;
47201 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
47202 fscache_wait_bit_interruptible,
47203 TASK_INTERRUPTIBLE) != 0) {
47204 - fscache_stat(&fscache_n_retrievals_intr);
47205 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
47206 _leave(" = -ERESTARTSYS");
47207 return -ERESTARTSYS;
47208 }
47209 @@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
47210 */
47211 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
47212 struct fscache_retrieval *op,
47213 - atomic_t *stat_op_waits,
47214 - atomic_t *stat_object_dead)
47215 + atomic_unchecked_t *stat_op_waits,
47216 + atomic_unchecked_t *stat_object_dead)
47217 {
47218 int ret;
47219
47220 @@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
47221 goto check_if_dead;
47222
47223 _debug(">>> WT");
47224 - fscache_stat(stat_op_waits);
47225 + fscache_stat_unchecked(stat_op_waits);
47226 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
47227 fscache_wait_bit_interruptible,
47228 TASK_INTERRUPTIBLE) < 0) {
47229 @@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
47230
47231 check_if_dead:
47232 if (unlikely(fscache_object_is_dead(object))) {
47233 - fscache_stat(stat_object_dead);
47234 + fscache_stat_unchecked(stat_object_dead);
47235 return -ENOBUFS;
47236 }
47237 return 0;
47238 @@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
47239
47240 _enter("%p,%p,,,", cookie, page);
47241
47242 - fscache_stat(&fscache_n_retrievals);
47243 + fscache_stat_unchecked(&fscache_n_retrievals);
47244
47245 if (hlist_empty(&cookie->backing_objects))
47246 goto nobufs;
47247 @@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
47248 goto nobufs_unlock;
47249 spin_unlock(&cookie->lock);
47250
47251 - fscache_stat(&fscache_n_retrieval_ops);
47252 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
47253
47254 /* pin the netfs read context in case we need to do the actual netfs
47255 * read because we've encountered a cache read failure */
47256 @@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
47257
47258 error:
47259 if (ret == -ENOMEM)
47260 - fscache_stat(&fscache_n_retrievals_nomem);
47261 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
47262 else if (ret == -ERESTARTSYS)
47263 - fscache_stat(&fscache_n_retrievals_intr);
47264 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
47265 else if (ret == -ENODATA)
47266 - fscache_stat(&fscache_n_retrievals_nodata);
47267 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
47268 else if (ret < 0)
47269 - fscache_stat(&fscache_n_retrievals_nobufs);
47270 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
47271 else
47272 - fscache_stat(&fscache_n_retrievals_ok);
47273 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
47274
47275 fscache_put_retrieval(op);
47276 _leave(" = %d", ret);
47277 @@ -429,7 +429,7 @@ nobufs_unlock:
47278 spin_unlock(&cookie->lock);
47279 kfree(op);
47280 nobufs:
47281 - fscache_stat(&fscache_n_retrievals_nobufs);
47282 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
47283 _leave(" = -ENOBUFS");
47284 return -ENOBUFS;
47285 }
47286 @@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
47287
47288 _enter("%p,,%d,,,", cookie, *nr_pages);
47289
47290 - fscache_stat(&fscache_n_retrievals);
47291 + fscache_stat_unchecked(&fscache_n_retrievals);
47292
47293 if (hlist_empty(&cookie->backing_objects))
47294 goto nobufs;
47295 @@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
47296 goto nobufs_unlock;
47297 spin_unlock(&cookie->lock);
47298
47299 - fscache_stat(&fscache_n_retrieval_ops);
47300 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
47301
47302 /* pin the netfs read context in case we need to do the actual netfs
47303 * read because we've encountered a cache read failure */
47304 @@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
47305
47306 error:
47307 if (ret == -ENOMEM)
47308 - fscache_stat(&fscache_n_retrievals_nomem);
47309 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
47310 else if (ret == -ERESTARTSYS)
47311 - fscache_stat(&fscache_n_retrievals_intr);
47312 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
47313 else if (ret == -ENODATA)
47314 - fscache_stat(&fscache_n_retrievals_nodata);
47315 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
47316 else if (ret < 0)
47317 - fscache_stat(&fscache_n_retrievals_nobufs);
47318 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
47319 else
47320 - fscache_stat(&fscache_n_retrievals_ok);
47321 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
47322
47323 fscache_put_retrieval(op);
47324 _leave(" = %d", ret);
47325 @@ -545,7 +545,7 @@ nobufs_unlock:
47326 spin_unlock(&cookie->lock);
47327 kfree(op);
47328 nobufs:
47329 - fscache_stat(&fscache_n_retrievals_nobufs);
47330 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
47331 _leave(" = -ENOBUFS");
47332 return -ENOBUFS;
47333 }
47334 @@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
47335
47336 _enter("%p,%p,,,", cookie, page);
47337
47338 - fscache_stat(&fscache_n_allocs);
47339 + fscache_stat_unchecked(&fscache_n_allocs);
47340
47341 if (hlist_empty(&cookie->backing_objects))
47342 goto nobufs;
47343 @@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
47344 goto nobufs_unlock;
47345 spin_unlock(&cookie->lock);
47346
47347 - fscache_stat(&fscache_n_alloc_ops);
47348 + fscache_stat_unchecked(&fscache_n_alloc_ops);
47349
47350 ret = fscache_wait_for_retrieval_activation(
47351 object, op,
47352 @@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
47353
47354 error:
47355 if (ret == -ERESTARTSYS)
47356 - fscache_stat(&fscache_n_allocs_intr);
47357 + fscache_stat_unchecked(&fscache_n_allocs_intr);
47358 else if (ret < 0)
47359 - fscache_stat(&fscache_n_allocs_nobufs);
47360 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
47361 else
47362 - fscache_stat(&fscache_n_allocs_ok);
47363 + fscache_stat_unchecked(&fscache_n_allocs_ok);
47364
47365 fscache_put_retrieval(op);
47366 _leave(" = %d", ret);
47367 @@ -625,7 +625,7 @@ nobufs_unlock:
47368 spin_unlock(&cookie->lock);
47369 kfree(op);
47370 nobufs:
47371 - fscache_stat(&fscache_n_allocs_nobufs);
47372 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
47373 _leave(" = -ENOBUFS");
47374 return -ENOBUFS;
47375 }
47376 @@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
47377
47378 spin_lock(&cookie->stores_lock);
47379
47380 - fscache_stat(&fscache_n_store_calls);
47381 + fscache_stat_unchecked(&fscache_n_store_calls);
47382
47383 /* find a page to store */
47384 page = NULL;
47385 @@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
47386 page = results[0];
47387 _debug("gang %d [%lx]", n, page->index);
47388 if (page->index > op->store_limit) {
47389 - fscache_stat(&fscache_n_store_pages_over_limit);
47390 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
47391 goto superseded;
47392 }
47393
47394 @@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
47395 spin_unlock(&cookie->stores_lock);
47396 spin_unlock(&object->lock);
47397
47398 - fscache_stat(&fscache_n_store_pages);
47399 + fscache_stat_unchecked(&fscache_n_store_pages);
47400 fscache_stat(&fscache_n_cop_write_page);
47401 ret = object->cache->ops->write_page(op, page);
47402 fscache_stat_d(&fscache_n_cop_write_page);
47403 @@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
47404 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
47405 ASSERT(PageFsCache(page));
47406
47407 - fscache_stat(&fscache_n_stores);
47408 + fscache_stat_unchecked(&fscache_n_stores);
47409
47410 op = kzalloc(sizeof(*op), GFP_NOIO);
47411 if (!op)
47412 @@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
47413 spin_unlock(&cookie->stores_lock);
47414 spin_unlock(&object->lock);
47415
47416 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
47417 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
47418 op->store_limit = object->store_limit;
47419
47420 if (fscache_submit_op(object, &op->op) < 0)
47421 @@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
47422
47423 spin_unlock(&cookie->lock);
47424 radix_tree_preload_end();
47425 - fscache_stat(&fscache_n_store_ops);
47426 - fscache_stat(&fscache_n_stores_ok);
47427 + fscache_stat_unchecked(&fscache_n_store_ops);
47428 + fscache_stat_unchecked(&fscache_n_stores_ok);
47429
47430 /* the work queue now carries its own ref on the object */
47431 fscache_put_operation(&op->op);
47432 @@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
47433 return 0;
47434
47435 already_queued:
47436 - fscache_stat(&fscache_n_stores_again);
47437 + fscache_stat_unchecked(&fscache_n_stores_again);
47438 already_pending:
47439 spin_unlock(&cookie->stores_lock);
47440 spin_unlock(&object->lock);
47441 spin_unlock(&cookie->lock);
47442 radix_tree_preload_end();
47443 kfree(op);
47444 - fscache_stat(&fscache_n_stores_ok);
47445 + fscache_stat_unchecked(&fscache_n_stores_ok);
47446 _leave(" = 0");
47447 return 0;
47448
47449 @@ -851,14 +851,14 @@ nobufs:
47450 spin_unlock(&cookie->lock);
47451 radix_tree_preload_end();
47452 kfree(op);
47453 - fscache_stat(&fscache_n_stores_nobufs);
47454 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
47455 _leave(" = -ENOBUFS");
47456 return -ENOBUFS;
47457
47458 nomem_free:
47459 kfree(op);
47460 nomem:
47461 - fscache_stat(&fscache_n_stores_oom);
47462 + fscache_stat_unchecked(&fscache_n_stores_oom);
47463 _leave(" = -ENOMEM");
47464 return -ENOMEM;
47465 }
47466 @@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
47467 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
47468 ASSERTCMP(page, !=, NULL);
47469
47470 - fscache_stat(&fscache_n_uncaches);
47471 + fscache_stat_unchecked(&fscache_n_uncaches);
47472
47473 /* cache withdrawal may beat us to it */
47474 if (!PageFsCache(page))
47475 @@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
47476 unsigned long loop;
47477
47478 #ifdef CONFIG_FSCACHE_STATS
47479 - atomic_add(pagevec->nr, &fscache_n_marks);
47480 + atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
47481 #endif
47482
47483 for (loop = 0; loop < pagevec->nr; loop++) {
47484 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
47485 index 4765190..2a067f2 100644
47486 --- a/fs/fscache/stats.c
47487 +++ b/fs/fscache/stats.c
47488 @@ -18,95 +18,95 @@
47489 /*
47490 * operation counters
47491 */
47492 -atomic_t fscache_n_op_pend;
47493 -atomic_t fscache_n_op_run;
47494 -atomic_t fscache_n_op_enqueue;
47495 -atomic_t fscache_n_op_requeue;
47496 -atomic_t fscache_n_op_deferred_release;
47497 -atomic_t fscache_n_op_release;
47498 -atomic_t fscache_n_op_gc;
47499 -atomic_t fscache_n_op_cancelled;
47500 -atomic_t fscache_n_op_rejected;
47501 +atomic_unchecked_t fscache_n_op_pend;
47502 +atomic_unchecked_t fscache_n_op_run;
47503 +atomic_unchecked_t fscache_n_op_enqueue;
47504 +atomic_unchecked_t fscache_n_op_requeue;
47505 +atomic_unchecked_t fscache_n_op_deferred_release;
47506 +atomic_unchecked_t fscache_n_op_release;
47507 +atomic_unchecked_t fscache_n_op_gc;
47508 +atomic_unchecked_t fscache_n_op_cancelled;
47509 +atomic_unchecked_t fscache_n_op_rejected;
47510
47511 -atomic_t fscache_n_attr_changed;
47512 -atomic_t fscache_n_attr_changed_ok;
47513 -atomic_t fscache_n_attr_changed_nobufs;
47514 -atomic_t fscache_n_attr_changed_nomem;
47515 -atomic_t fscache_n_attr_changed_calls;
47516 +atomic_unchecked_t fscache_n_attr_changed;
47517 +atomic_unchecked_t fscache_n_attr_changed_ok;
47518 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
47519 +atomic_unchecked_t fscache_n_attr_changed_nomem;
47520 +atomic_unchecked_t fscache_n_attr_changed_calls;
47521
47522 -atomic_t fscache_n_allocs;
47523 -atomic_t fscache_n_allocs_ok;
47524 -atomic_t fscache_n_allocs_wait;
47525 -atomic_t fscache_n_allocs_nobufs;
47526 -atomic_t fscache_n_allocs_intr;
47527 -atomic_t fscache_n_allocs_object_dead;
47528 -atomic_t fscache_n_alloc_ops;
47529 -atomic_t fscache_n_alloc_op_waits;
47530 +atomic_unchecked_t fscache_n_allocs;
47531 +atomic_unchecked_t fscache_n_allocs_ok;
47532 +atomic_unchecked_t fscache_n_allocs_wait;
47533 +atomic_unchecked_t fscache_n_allocs_nobufs;
47534 +atomic_unchecked_t fscache_n_allocs_intr;
47535 +atomic_unchecked_t fscache_n_allocs_object_dead;
47536 +atomic_unchecked_t fscache_n_alloc_ops;
47537 +atomic_unchecked_t fscache_n_alloc_op_waits;
47538
47539 -atomic_t fscache_n_retrievals;
47540 -atomic_t fscache_n_retrievals_ok;
47541 -atomic_t fscache_n_retrievals_wait;
47542 -atomic_t fscache_n_retrievals_nodata;
47543 -atomic_t fscache_n_retrievals_nobufs;
47544 -atomic_t fscache_n_retrievals_intr;
47545 -atomic_t fscache_n_retrievals_nomem;
47546 -atomic_t fscache_n_retrievals_object_dead;
47547 -atomic_t fscache_n_retrieval_ops;
47548 -atomic_t fscache_n_retrieval_op_waits;
47549 +atomic_unchecked_t fscache_n_retrievals;
47550 +atomic_unchecked_t fscache_n_retrievals_ok;
47551 +atomic_unchecked_t fscache_n_retrievals_wait;
47552 +atomic_unchecked_t fscache_n_retrievals_nodata;
47553 +atomic_unchecked_t fscache_n_retrievals_nobufs;
47554 +atomic_unchecked_t fscache_n_retrievals_intr;
47555 +atomic_unchecked_t fscache_n_retrievals_nomem;
47556 +atomic_unchecked_t fscache_n_retrievals_object_dead;
47557 +atomic_unchecked_t fscache_n_retrieval_ops;
47558 +atomic_unchecked_t fscache_n_retrieval_op_waits;
47559
47560 -atomic_t fscache_n_stores;
47561 -atomic_t fscache_n_stores_ok;
47562 -atomic_t fscache_n_stores_again;
47563 -atomic_t fscache_n_stores_nobufs;
47564 -atomic_t fscache_n_stores_oom;
47565 -atomic_t fscache_n_store_ops;
47566 -atomic_t fscache_n_store_calls;
47567 -atomic_t fscache_n_store_pages;
47568 -atomic_t fscache_n_store_radix_deletes;
47569 -atomic_t fscache_n_store_pages_over_limit;
47570 +atomic_unchecked_t fscache_n_stores;
47571 +atomic_unchecked_t fscache_n_stores_ok;
47572 +atomic_unchecked_t fscache_n_stores_again;
47573 +atomic_unchecked_t fscache_n_stores_nobufs;
47574 +atomic_unchecked_t fscache_n_stores_oom;
47575 +atomic_unchecked_t fscache_n_store_ops;
47576 +atomic_unchecked_t fscache_n_store_calls;
47577 +atomic_unchecked_t fscache_n_store_pages;
47578 +atomic_unchecked_t fscache_n_store_radix_deletes;
47579 +atomic_unchecked_t fscache_n_store_pages_over_limit;
47580
47581 -atomic_t fscache_n_store_vmscan_not_storing;
47582 -atomic_t fscache_n_store_vmscan_gone;
47583 -atomic_t fscache_n_store_vmscan_busy;
47584 -atomic_t fscache_n_store_vmscan_cancelled;
47585 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
47586 +atomic_unchecked_t fscache_n_store_vmscan_gone;
47587 +atomic_unchecked_t fscache_n_store_vmscan_busy;
47588 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
47589
47590 -atomic_t fscache_n_marks;
47591 -atomic_t fscache_n_uncaches;
47592 +atomic_unchecked_t fscache_n_marks;
47593 +atomic_unchecked_t fscache_n_uncaches;
47594
47595 -atomic_t fscache_n_acquires;
47596 -atomic_t fscache_n_acquires_null;
47597 -atomic_t fscache_n_acquires_no_cache;
47598 -atomic_t fscache_n_acquires_ok;
47599 -atomic_t fscache_n_acquires_nobufs;
47600 -atomic_t fscache_n_acquires_oom;
47601 +atomic_unchecked_t fscache_n_acquires;
47602 +atomic_unchecked_t fscache_n_acquires_null;
47603 +atomic_unchecked_t fscache_n_acquires_no_cache;
47604 +atomic_unchecked_t fscache_n_acquires_ok;
47605 +atomic_unchecked_t fscache_n_acquires_nobufs;
47606 +atomic_unchecked_t fscache_n_acquires_oom;
47607
47608 -atomic_t fscache_n_updates;
47609 -atomic_t fscache_n_updates_null;
47610 -atomic_t fscache_n_updates_run;
47611 +atomic_unchecked_t fscache_n_updates;
47612 +atomic_unchecked_t fscache_n_updates_null;
47613 +atomic_unchecked_t fscache_n_updates_run;
47614
47615 -atomic_t fscache_n_relinquishes;
47616 -atomic_t fscache_n_relinquishes_null;
47617 -atomic_t fscache_n_relinquishes_waitcrt;
47618 -atomic_t fscache_n_relinquishes_retire;
47619 +atomic_unchecked_t fscache_n_relinquishes;
47620 +atomic_unchecked_t fscache_n_relinquishes_null;
47621 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
47622 +atomic_unchecked_t fscache_n_relinquishes_retire;
47623
47624 -atomic_t fscache_n_cookie_index;
47625 -atomic_t fscache_n_cookie_data;
47626 -atomic_t fscache_n_cookie_special;
47627 +atomic_unchecked_t fscache_n_cookie_index;
47628 +atomic_unchecked_t fscache_n_cookie_data;
47629 +atomic_unchecked_t fscache_n_cookie_special;
47630
47631 -atomic_t fscache_n_object_alloc;
47632 -atomic_t fscache_n_object_no_alloc;
47633 -atomic_t fscache_n_object_lookups;
47634 -atomic_t fscache_n_object_lookups_negative;
47635 -atomic_t fscache_n_object_lookups_positive;
47636 -atomic_t fscache_n_object_lookups_timed_out;
47637 -atomic_t fscache_n_object_created;
47638 -atomic_t fscache_n_object_avail;
47639 -atomic_t fscache_n_object_dead;
47640 +atomic_unchecked_t fscache_n_object_alloc;
47641 +atomic_unchecked_t fscache_n_object_no_alloc;
47642 +atomic_unchecked_t fscache_n_object_lookups;
47643 +atomic_unchecked_t fscache_n_object_lookups_negative;
47644 +atomic_unchecked_t fscache_n_object_lookups_positive;
47645 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
47646 +atomic_unchecked_t fscache_n_object_created;
47647 +atomic_unchecked_t fscache_n_object_avail;
47648 +atomic_unchecked_t fscache_n_object_dead;
47649
47650 -atomic_t fscache_n_checkaux_none;
47651 -atomic_t fscache_n_checkaux_okay;
47652 -atomic_t fscache_n_checkaux_update;
47653 -atomic_t fscache_n_checkaux_obsolete;
47654 +atomic_unchecked_t fscache_n_checkaux_none;
47655 +atomic_unchecked_t fscache_n_checkaux_okay;
47656 +atomic_unchecked_t fscache_n_checkaux_update;
47657 +atomic_unchecked_t fscache_n_checkaux_obsolete;
47658
47659 atomic_t fscache_n_cop_alloc_object;
47660 atomic_t fscache_n_cop_lookup_object;
47661 @@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
47662 seq_puts(m, "FS-Cache statistics\n");
47663
47664 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
47665 - atomic_read(&fscache_n_cookie_index),
47666 - atomic_read(&fscache_n_cookie_data),
47667 - atomic_read(&fscache_n_cookie_special));
47668 + atomic_read_unchecked(&fscache_n_cookie_index),
47669 + atomic_read_unchecked(&fscache_n_cookie_data),
47670 + atomic_read_unchecked(&fscache_n_cookie_special));
47671
47672 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
47673 - atomic_read(&fscache_n_object_alloc),
47674 - atomic_read(&fscache_n_object_no_alloc),
47675 - atomic_read(&fscache_n_object_avail),
47676 - atomic_read(&fscache_n_object_dead));
47677 + atomic_read_unchecked(&fscache_n_object_alloc),
47678 + atomic_read_unchecked(&fscache_n_object_no_alloc),
47679 + atomic_read_unchecked(&fscache_n_object_avail),
47680 + atomic_read_unchecked(&fscache_n_object_dead));
47681 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
47682 - atomic_read(&fscache_n_checkaux_none),
47683 - atomic_read(&fscache_n_checkaux_okay),
47684 - atomic_read(&fscache_n_checkaux_update),
47685 - atomic_read(&fscache_n_checkaux_obsolete));
47686 + atomic_read_unchecked(&fscache_n_checkaux_none),
47687 + atomic_read_unchecked(&fscache_n_checkaux_okay),
47688 + atomic_read_unchecked(&fscache_n_checkaux_update),
47689 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
47690
47691 seq_printf(m, "Pages : mrk=%u unc=%u\n",
47692 - atomic_read(&fscache_n_marks),
47693 - atomic_read(&fscache_n_uncaches));
47694 + atomic_read_unchecked(&fscache_n_marks),
47695 + atomic_read_unchecked(&fscache_n_uncaches));
47696
47697 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
47698 " oom=%u\n",
47699 - atomic_read(&fscache_n_acquires),
47700 - atomic_read(&fscache_n_acquires_null),
47701 - atomic_read(&fscache_n_acquires_no_cache),
47702 - atomic_read(&fscache_n_acquires_ok),
47703 - atomic_read(&fscache_n_acquires_nobufs),
47704 - atomic_read(&fscache_n_acquires_oom));
47705 + atomic_read_unchecked(&fscache_n_acquires),
47706 + atomic_read_unchecked(&fscache_n_acquires_null),
47707 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
47708 + atomic_read_unchecked(&fscache_n_acquires_ok),
47709 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
47710 + atomic_read_unchecked(&fscache_n_acquires_oom));
47711
47712 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
47713 - atomic_read(&fscache_n_object_lookups),
47714 - atomic_read(&fscache_n_object_lookups_negative),
47715 - atomic_read(&fscache_n_object_lookups_positive),
47716 - atomic_read(&fscache_n_object_created),
47717 - atomic_read(&fscache_n_object_lookups_timed_out));
47718 + atomic_read_unchecked(&fscache_n_object_lookups),
47719 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
47720 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
47721 + atomic_read_unchecked(&fscache_n_object_created),
47722 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
47723
47724 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
47725 - atomic_read(&fscache_n_updates),
47726 - atomic_read(&fscache_n_updates_null),
47727 - atomic_read(&fscache_n_updates_run));
47728 + atomic_read_unchecked(&fscache_n_updates),
47729 + atomic_read_unchecked(&fscache_n_updates_null),
47730 + atomic_read_unchecked(&fscache_n_updates_run));
47731
47732 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
47733 - atomic_read(&fscache_n_relinquishes),
47734 - atomic_read(&fscache_n_relinquishes_null),
47735 - atomic_read(&fscache_n_relinquishes_waitcrt),
47736 - atomic_read(&fscache_n_relinquishes_retire));
47737 + atomic_read_unchecked(&fscache_n_relinquishes),
47738 + atomic_read_unchecked(&fscache_n_relinquishes_null),
47739 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
47740 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
47741
47742 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
47743 - atomic_read(&fscache_n_attr_changed),
47744 - atomic_read(&fscache_n_attr_changed_ok),
47745 - atomic_read(&fscache_n_attr_changed_nobufs),
47746 - atomic_read(&fscache_n_attr_changed_nomem),
47747 - atomic_read(&fscache_n_attr_changed_calls));
47748 + atomic_read_unchecked(&fscache_n_attr_changed),
47749 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
47750 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
47751 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
47752 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
47753
47754 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
47755 - atomic_read(&fscache_n_allocs),
47756 - atomic_read(&fscache_n_allocs_ok),
47757 - atomic_read(&fscache_n_allocs_wait),
47758 - atomic_read(&fscache_n_allocs_nobufs),
47759 - atomic_read(&fscache_n_allocs_intr));
47760 + atomic_read_unchecked(&fscache_n_allocs),
47761 + atomic_read_unchecked(&fscache_n_allocs_ok),
47762 + atomic_read_unchecked(&fscache_n_allocs_wait),
47763 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
47764 + atomic_read_unchecked(&fscache_n_allocs_intr));
47765 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
47766 - atomic_read(&fscache_n_alloc_ops),
47767 - atomic_read(&fscache_n_alloc_op_waits),
47768 - atomic_read(&fscache_n_allocs_object_dead));
47769 + atomic_read_unchecked(&fscache_n_alloc_ops),
47770 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
47771 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
47772
47773 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
47774 " int=%u oom=%u\n",
47775 - atomic_read(&fscache_n_retrievals),
47776 - atomic_read(&fscache_n_retrievals_ok),
47777 - atomic_read(&fscache_n_retrievals_wait),
47778 - atomic_read(&fscache_n_retrievals_nodata),
47779 - atomic_read(&fscache_n_retrievals_nobufs),
47780 - atomic_read(&fscache_n_retrievals_intr),
47781 - atomic_read(&fscache_n_retrievals_nomem));
47782 + atomic_read_unchecked(&fscache_n_retrievals),
47783 + atomic_read_unchecked(&fscache_n_retrievals_ok),
47784 + atomic_read_unchecked(&fscache_n_retrievals_wait),
47785 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
47786 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
47787 + atomic_read_unchecked(&fscache_n_retrievals_intr),
47788 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
47789 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
47790 - atomic_read(&fscache_n_retrieval_ops),
47791 - atomic_read(&fscache_n_retrieval_op_waits),
47792 - atomic_read(&fscache_n_retrievals_object_dead));
47793 + atomic_read_unchecked(&fscache_n_retrieval_ops),
47794 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
47795 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
47796
47797 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
47798 - atomic_read(&fscache_n_stores),
47799 - atomic_read(&fscache_n_stores_ok),
47800 - atomic_read(&fscache_n_stores_again),
47801 - atomic_read(&fscache_n_stores_nobufs),
47802 - atomic_read(&fscache_n_stores_oom));
47803 + atomic_read_unchecked(&fscache_n_stores),
47804 + atomic_read_unchecked(&fscache_n_stores_ok),
47805 + atomic_read_unchecked(&fscache_n_stores_again),
47806 + atomic_read_unchecked(&fscache_n_stores_nobufs),
47807 + atomic_read_unchecked(&fscache_n_stores_oom));
47808 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
47809 - atomic_read(&fscache_n_store_ops),
47810 - atomic_read(&fscache_n_store_calls),
47811 - atomic_read(&fscache_n_store_pages),
47812 - atomic_read(&fscache_n_store_radix_deletes),
47813 - atomic_read(&fscache_n_store_pages_over_limit));
47814 + atomic_read_unchecked(&fscache_n_store_ops),
47815 + atomic_read_unchecked(&fscache_n_store_calls),
47816 + atomic_read_unchecked(&fscache_n_store_pages),
47817 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
47818 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
47819
47820 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
47821 - atomic_read(&fscache_n_store_vmscan_not_storing),
47822 - atomic_read(&fscache_n_store_vmscan_gone),
47823 - atomic_read(&fscache_n_store_vmscan_busy),
47824 - atomic_read(&fscache_n_store_vmscan_cancelled));
47825 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
47826 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
47827 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
47828 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
47829
47830 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
47831 - atomic_read(&fscache_n_op_pend),
47832 - atomic_read(&fscache_n_op_run),
47833 - atomic_read(&fscache_n_op_enqueue),
47834 - atomic_read(&fscache_n_op_cancelled),
47835 - atomic_read(&fscache_n_op_rejected));
47836 + atomic_read_unchecked(&fscache_n_op_pend),
47837 + atomic_read_unchecked(&fscache_n_op_run),
47838 + atomic_read_unchecked(&fscache_n_op_enqueue),
47839 + atomic_read_unchecked(&fscache_n_op_cancelled),
47840 + atomic_read_unchecked(&fscache_n_op_rejected));
47841 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
47842 - atomic_read(&fscache_n_op_deferred_release),
47843 - atomic_read(&fscache_n_op_release),
47844 - atomic_read(&fscache_n_op_gc));
47845 + atomic_read_unchecked(&fscache_n_op_deferred_release),
47846 + atomic_read_unchecked(&fscache_n_op_release),
47847 + atomic_read_unchecked(&fscache_n_op_gc));
47848
47849 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
47850 atomic_read(&fscache_n_cop_alloc_object),
47851 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
47852 index ee8d550..7189d8c 100644
47853 --- a/fs/fuse/cuse.c
47854 +++ b/fs/fuse/cuse.c
47855 @@ -585,10 +585,12 @@ static int __init cuse_init(void)
47856 INIT_LIST_HEAD(&cuse_conntbl[i]);
47857
47858 /* inherit and extend fuse_dev_operations */
47859 - cuse_channel_fops = fuse_dev_operations;
47860 - cuse_channel_fops.owner = THIS_MODULE;
47861 - cuse_channel_fops.open = cuse_channel_open;
47862 - cuse_channel_fops.release = cuse_channel_release;
47863 + pax_open_kernel();
47864 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
47865 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
47866 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
47867 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
47868 + pax_close_kernel();
47869
47870 cuse_class = class_create(THIS_MODULE, "cuse");
47871 if (IS_ERR(cuse_class))
47872 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
47873 index f4246cf..b4aed1d 100644
47874 --- a/fs/fuse/dev.c
47875 +++ b/fs/fuse/dev.c
47876 @@ -1242,7 +1242,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
47877 ret = 0;
47878 pipe_lock(pipe);
47879
47880 - if (!pipe->readers) {
47881 + if (!atomic_read(&pipe->readers)) {
47882 send_sig(SIGPIPE, current, 0);
47883 if (!ret)
47884 ret = -EPIPE;
47885 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
47886 index 324bc08..4fdd56e 100644
47887 --- a/fs/fuse/dir.c
47888 +++ b/fs/fuse/dir.c
47889 @@ -1226,7 +1226,7 @@ static char *read_link(struct dentry *dentry)
47890 return link;
47891 }
47892
47893 -static void free_link(char *link)
47894 +static void free_link(const char *link)
47895 {
47896 if (!IS_ERR(link))
47897 free_page((unsigned long) link);
47898 diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
47899 index 753af3d..f7b021a 100644
47900 --- a/fs/gfs2/inode.c
47901 +++ b/fs/gfs2/inode.c
47902 @@ -1498,7 +1498,7 @@ out:
47903
47904 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
47905 {
47906 - char *s = nd_get_link(nd);
47907 + const char *s = nd_get_link(nd);
47908 if (!IS_ERR(s))
47909 kfree(s);
47910 }
47911 diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c
47912 index a3bde91..2524579 100644
47913 --- a/fs/gfs2/quota.c
47914 +++ b/fs/gfs2/quota.c
47915 @@ -497,8 +497,11 @@ int gfs2_quota_hold(struct gfs2_inode *ip, u32 uid, u32 gid)
47916 struct gfs2_quota_data **qd;
47917 int error;
47918
47919 - if (ip->i_res == NULL)
47920 - gfs2_rs_alloc(ip);
47921 + if (ip->i_res == NULL) {
47922 + error = gfs2_rs_alloc(ip);
47923 + if (error)
47924 + return error;
47925 + }
47926
47927 qd = ip->i_res->rs_qa_qd;
47928
47929 diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c
47930 index c9ed814..4a45d5f 100644
47931 --- a/fs/gfs2/rgrp.c
47932 +++ b/fs/gfs2/rgrp.c
47933 @@ -477,7 +477,6 @@ void gfs2_free_clones(struct gfs2_rgrpd *rgd)
47934 */
47935 int gfs2_rs_alloc(struct gfs2_inode *ip)
47936 {
47937 - int error = 0;
47938 struct gfs2_blkreserv *res;
47939
47940 if (ip->i_res)
47941 @@ -485,7 +484,7 @@ int gfs2_rs_alloc(struct gfs2_inode *ip)
47942
47943 res = kmem_cache_zalloc(gfs2_rsrv_cachep, GFP_NOFS);
47944 if (!res)
47945 - error = -ENOMEM;
47946 + return -ENOMEM;
47947
47948 down_write(&ip->i_rw_mutex);
47949 if (ip->i_res)
47950 @@ -493,7 +492,7 @@ int gfs2_rs_alloc(struct gfs2_inode *ip)
47951 else
47952 ip->i_res = res;
47953 up_write(&ip->i_rw_mutex);
47954 - return error;
47955 + return 0;
47956 }
47957
47958 static void dump_rs(struct seq_file *seq, struct gfs2_blkreserv *rs)
47959 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
47960 index 8349a89..51a0254 100644
47961 --- a/fs/hugetlbfs/inode.c
47962 +++ b/fs/hugetlbfs/inode.c
47963 @@ -920,7 +920,7 @@ static struct file_system_type hugetlbfs_fs_type = {
47964 .kill_sb = kill_litter_super,
47965 };
47966
47967 -static struct vfsmount *hugetlbfs_vfsmount;
47968 +struct vfsmount *hugetlbfs_vfsmount;
47969
47970 static int can_do_hugetlb_shm(void)
47971 {
47972 diff --git a/fs/inode.c b/fs/inode.c
47973 index 7c14897..d40169e 100644
47974 --- a/fs/inode.c
47975 +++ b/fs/inode.c
47976 @@ -880,8 +880,8 @@ unsigned int get_next_ino(void)
47977
47978 #ifdef CONFIG_SMP
47979 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
47980 - static atomic_t shared_last_ino;
47981 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
47982 + static atomic_unchecked_t shared_last_ino;
47983 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
47984
47985 res = next - LAST_INO_BATCH;
47986 }
47987 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
47988 index 4a6cf28..d3a29d3 100644
47989 --- a/fs/jffs2/erase.c
47990 +++ b/fs/jffs2/erase.c
47991 @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
47992 struct jffs2_unknown_node marker = {
47993 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
47994 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
47995 - .totlen = cpu_to_je32(c->cleanmarker_size)
47996 + .totlen = cpu_to_je32(c->cleanmarker_size),
47997 + .hdr_crc = cpu_to_je32(0)
47998 };
47999
48000 jffs2_prealloc_raw_node_refs(c, jeb, 1);
48001 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
48002 index a6597d6..41b30ec 100644
48003 --- a/fs/jffs2/wbuf.c
48004 +++ b/fs/jffs2/wbuf.c
48005 @@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
48006 {
48007 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
48008 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
48009 - .totlen = constant_cpu_to_je32(8)
48010 + .totlen = constant_cpu_to_je32(8),
48011 + .hdr_crc = constant_cpu_to_je32(0)
48012 };
48013
48014 /*
48015 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
48016 index c55c745..f67ee56 100644
48017 --- a/fs/jfs/super.c
48018 +++ b/fs/jfs/super.c
48019 @@ -806,7 +806,7 @@ static int __init init_jfs_fs(void)
48020
48021 jfs_inode_cachep =
48022 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
48023 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
48024 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
48025 init_once);
48026 if (jfs_inode_cachep == NULL)
48027 return -ENOMEM;
48028 diff --git a/fs/libfs.c b/fs/libfs.c
48029 index a74cb17..37fcbe4 100644
48030 --- a/fs/libfs.c
48031 +++ b/fs/libfs.c
48032 @@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
48033
48034 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
48035 struct dentry *next;
48036 + char d_name[sizeof(next->d_iname)];
48037 + const unsigned char *name;
48038 +
48039 next = list_entry(p, struct dentry, d_u.d_child);
48040 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
48041 if (!simple_positive(next)) {
48042 @@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
48043
48044 spin_unlock(&next->d_lock);
48045 spin_unlock(&dentry->d_lock);
48046 - if (filldir(dirent, next->d_name.name,
48047 + name = next->d_name.name;
48048 + if (name == next->d_iname) {
48049 + memcpy(d_name, name, next->d_name.len);
48050 + name = d_name;
48051 + }
48052 + if (filldir(dirent, name,
48053 next->d_name.len, filp->f_pos,
48054 next->d_inode->i_ino,
48055 dt_type(next->d_inode)) < 0)
48056 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
48057 index 05d2912..760abfa 100644
48058 --- a/fs/lockd/clntproc.c
48059 +++ b/fs/lockd/clntproc.c
48060 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
48061 /*
48062 * Cookie counter for NLM requests
48063 */
48064 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
48065 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
48066
48067 void nlmclnt_next_cookie(struct nlm_cookie *c)
48068 {
48069 - u32 cookie = atomic_inc_return(&nlm_cookie);
48070 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
48071
48072 memcpy(c->data, &cookie, 4);
48073 c->len=4;
48074 diff --git a/fs/locks.c b/fs/locks.c
48075 index 7e81bfc..c3649aa 100644
48076 --- a/fs/locks.c
48077 +++ b/fs/locks.c
48078 @@ -2066,16 +2066,16 @@ void locks_remove_flock(struct file *filp)
48079 return;
48080
48081 if (filp->f_op && filp->f_op->flock) {
48082 - struct file_lock fl = {
48083 + struct file_lock flock = {
48084 .fl_pid = current->tgid,
48085 .fl_file = filp,
48086 .fl_flags = FL_FLOCK,
48087 .fl_type = F_UNLCK,
48088 .fl_end = OFFSET_MAX,
48089 };
48090 - filp->f_op->flock(filp, F_SETLKW, &fl);
48091 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
48092 - fl.fl_ops->fl_release_private(&fl);
48093 + filp->f_op->flock(filp, F_SETLKW, &flock);
48094 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
48095 + flock.fl_ops->fl_release_private(&flock);
48096 }
48097
48098 lock_flocks();
48099 diff --git a/fs/namei.c b/fs/namei.c
48100 index 091c4b7..eb220a4 100644
48101 --- a/fs/namei.c
48102 +++ b/fs/namei.c
48103 @@ -265,16 +265,32 @@ int generic_permission(struct inode *inode, int mask)
48104 if (ret != -EACCES)
48105 return ret;
48106
48107 +#ifdef CONFIG_GRKERNSEC
48108 + /* we'll block if we have to log due to a denied capability use */
48109 + if (mask & MAY_NOT_BLOCK)
48110 + return -ECHILD;
48111 +#endif
48112 +
48113 if (S_ISDIR(inode->i_mode)) {
48114 /* DACs are overridable for directories */
48115 - if (inode_capable(inode, CAP_DAC_OVERRIDE))
48116 - return 0;
48117 if (!(mask & MAY_WRITE))
48118 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
48119 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
48120 + inode_capable(inode, CAP_DAC_READ_SEARCH))
48121 return 0;
48122 + if (inode_capable(inode, CAP_DAC_OVERRIDE))
48123 + return 0;
48124 return -EACCES;
48125 }
48126 /*
48127 + * Searching includes executable on directories, else just read.
48128 + */
48129 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
48130 + if (mask == MAY_READ)
48131 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
48132 + inode_capable(inode, CAP_DAC_READ_SEARCH))
48133 + return 0;
48134 +
48135 + /*
48136 * Read/write DACs are always overridable.
48137 * Executable DACs are overridable when there is
48138 * at least one exec bit set.
48139 @@ -283,14 +299,6 @@ int generic_permission(struct inode *inode, int mask)
48140 if (inode_capable(inode, CAP_DAC_OVERRIDE))
48141 return 0;
48142
48143 - /*
48144 - * Searching includes executable on directories, else just read.
48145 - */
48146 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
48147 - if (mask == MAY_READ)
48148 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
48149 - return 0;
48150 -
48151 return -EACCES;
48152 }
48153
48154 @@ -772,7 +780,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
48155 {
48156 struct dentry *dentry = link->dentry;
48157 int error;
48158 - char *s;
48159 + const char *s;
48160
48161 BUG_ON(nd->flags & LOOKUP_RCU);
48162
48163 @@ -793,6 +801,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
48164 if (error)
48165 goto out_put_nd_path;
48166
48167 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
48168 + dentry->d_inode, dentry, nd->path.mnt)) {
48169 + error = -EACCES;
48170 + goto out_put_nd_path;
48171 + }
48172 +
48173 nd->last_type = LAST_BIND;
48174 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
48175 error = PTR_ERR(*p);
48176 @@ -1550,6 +1564,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
48177 break;
48178 res = walk_component(nd, path, &nd->last,
48179 nd->last_type, LOOKUP_FOLLOW);
48180 + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
48181 + res = -EACCES;
48182 put_link(nd, &link, cookie);
48183 } while (res > 0);
48184
48185 @@ -1648,7 +1664,7 @@ EXPORT_SYMBOL(full_name_hash);
48186 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
48187 {
48188 unsigned long a, b, adata, bdata, mask, hash, len;
48189 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
48190 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
48191
48192 hash = a = 0;
48193 len = -sizeof(unsigned long);
48194 @@ -1943,6 +1959,8 @@ static int path_lookupat(int dfd, const char *name,
48195 if (err)
48196 break;
48197 err = lookup_last(nd, &path);
48198 + if (!err && gr_handle_symlink_owner(&link, nd->inode))
48199 + err = -EACCES;
48200 put_link(nd, &link, cookie);
48201 }
48202 }
48203 @@ -1950,6 +1968,21 @@ static int path_lookupat(int dfd, const char *name,
48204 if (!err)
48205 err = complete_walk(nd);
48206
48207 + if (!(nd->flags & LOOKUP_PARENT)) {
48208 +#ifdef CONFIG_GRKERNSEC
48209 + if (flags & LOOKUP_RCU) {
48210 + if (!err)
48211 + path_put(&nd->path);
48212 + err = -ECHILD;
48213 + } else
48214 +#endif
48215 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
48216 + if (!err)
48217 + path_put(&nd->path);
48218 + err = -ENOENT;
48219 + }
48220 + }
48221 +
48222 if (!err && nd->flags & LOOKUP_DIRECTORY) {
48223 if (!nd->inode->i_op->lookup) {
48224 path_put(&nd->path);
48225 @@ -1977,6 +2010,15 @@ static int do_path_lookup(int dfd, const char *name,
48226 retval = path_lookupat(dfd, name, flags | LOOKUP_REVAL, nd);
48227
48228 if (likely(!retval)) {
48229 + if (*name != '/' && nd->path.dentry && nd->inode) {
48230 +#ifdef CONFIG_GRKERNSEC
48231 + if (flags & LOOKUP_RCU)
48232 + return -ECHILD;
48233 +#endif
48234 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
48235 + return -ENOENT;
48236 + }
48237 +
48238 if (unlikely(!audit_dummy_context())) {
48239 if (nd->path.dentry && nd->inode)
48240 audit_inode(name, nd->path.dentry);
48241 @@ -2076,6 +2118,11 @@ struct dentry *lookup_one_len(const char *name, struct dentry *base, int len)
48242 if (!len)
48243 return ERR_PTR(-EACCES);
48244
48245 + if (unlikely(name[0] == '.')) {
48246 + if (len < 2 || (len == 2 && name[1] == '.'))
48247 + return ERR_PTR(-EACCES);
48248 + }
48249 +
48250 while (len--) {
48251 c = *(const unsigned char *)name++;
48252 if (c == '/' || c == '\0')
48253 @@ -2336,6 +2383,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
48254 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
48255 return -EPERM;
48256
48257 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
48258 + return -EPERM;
48259 + if (gr_handle_rawio(inode))
48260 + return -EPERM;
48261 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
48262 + return -EACCES;
48263 +
48264 return 0;
48265 }
48266
48267 @@ -2557,7 +2611,7 @@ looked_up:
48268 * cleared otherwise prior to returning.
48269 */
48270 static int lookup_open(struct nameidata *nd, struct path *path,
48271 - struct file *file,
48272 + struct path *link, struct file *file,
48273 const struct open_flags *op,
48274 bool got_write, int *opened)
48275 {
48276 @@ -2592,6 +2646,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
48277 /* Negative dentry, just create the file */
48278 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
48279 umode_t mode = op->mode;
48280 +
48281 + if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
48282 + error = -EACCES;
48283 + goto out_dput;
48284 + }
48285 +
48286 + if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
48287 + error = -EACCES;
48288 + goto out_dput;
48289 + }
48290 +
48291 if (!IS_POSIXACL(dir->d_inode))
48292 mode &= ~current_umask();
48293 /*
48294 @@ -2613,6 +2678,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
48295 nd->flags & LOOKUP_EXCL);
48296 if (error)
48297 goto out_dput;
48298 + else
48299 + gr_handle_create(dentry, nd->path.mnt);
48300 }
48301 out_no_open:
48302 path->dentry = dentry;
48303 @@ -2627,7 +2694,7 @@ out_dput:
48304 /*
48305 * Handle the last step of open()
48306 */
48307 -static int do_last(struct nameidata *nd, struct path *path,
48308 +static int do_last(struct nameidata *nd, struct path *path, struct path *link,
48309 struct file *file, const struct open_flags *op,
48310 int *opened, const char *pathname)
48311 {
48312 @@ -2656,16 +2723,44 @@ static int do_last(struct nameidata *nd, struct path *path,
48313 error = complete_walk(nd);
48314 if (error)
48315 return error;
48316 +#ifdef CONFIG_GRKERNSEC
48317 + if (nd->flags & LOOKUP_RCU) {
48318 + error = -ECHILD;
48319 + goto out;
48320 + }
48321 +#endif
48322 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
48323 + error = -ENOENT;
48324 + goto out;
48325 + }
48326 audit_inode(pathname, nd->path.dentry);
48327 if (open_flag & O_CREAT) {
48328 error = -EISDIR;
48329 goto out;
48330 }
48331 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
48332 + error = -EACCES;
48333 + goto out;
48334 + }
48335 goto finish_open;
48336 case LAST_BIND:
48337 error = complete_walk(nd);
48338 if (error)
48339 return error;
48340 +#ifdef CONFIG_GRKERNSEC
48341 + if (nd->flags & LOOKUP_RCU) {
48342 + error = -ECHILD;
48343 + goto out;
48344 + }
48345 +#endif
48346 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
48347 + error = -ENOENT;
48348 + goto out;
48349 + }
48350 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
48351 + error = -EACCES;
48352 + goto out;
48353 + }
48354 audit_inode(pathname, dir);
48355 goto finish_open;
48356 }
48357 @@ -2714,7 +2809,7 @@ retry_lookup:
48358 */
48359 }
48360 mutex_lock(&dir->d_inode->i_mutex);
48361 - error = lookup_open(nd, path, file, op, got_write, opened);
48362 + error = lookup_open(nd, path, link, file, op, got_write, opened);
48363 mutex_unlock(&dir->d_inode->i_mutex);
48364
48365 if (error <= 0) {
48366 @@ -2738,11 +2833,28 @@ retry_lookup:
48367 goto finish_open_created;
48368 }
48369
48370 + if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
48371 + error = -ENOENT;
48372 + goto exit_dput;
48373 + }
48374 + if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
48375 + error = -EACCES;
48376 + goto exit_dput;
48377 + }
48378 +
48379 /*
48380 * create/update audit record if it already exists.
48381 */
48382 - if (path->dentry->d_inode)
48383 + if (path->dentry->d_inode) {
48384 + /* only check if O_CREAT is specified, all other checks need to go
48385 + into may_open */
48386 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
48387 + error = -EACCES;
48388 + goto exit_dput;
48389 + }
48390 +
48391 audit_inode(pathname, path->dentry);
48392 + }
48393
48394 /*
48395 * If atomic_open() acquired write access it is dropped now due to
48396 @@ -2783,6 +2895,11 @@ finish_lookup:
48397 }
48398 }
48399 BUG_ON(inode != path->dentry->d_inode);
48400 + /* if we're resolving a symlink to another symlink */
48401 + if (link && gr_handle_symlink_owner(link, inode)) {
48402 + error = -EACCES;
48403 + goto out;
48404 + }
48405 return 1;
48406 }
48407
48408 @@ -2792,7 +2909,6 @@ finish_lookup:
48409 save_parent.dentry = nd->path.dentry;
48410 save_parent.mnt = mntget(path->mnt);
48411 nd->path.dentry = path->dentry;
48412 -
48413 }
48414 nd->inode = inode;
48415 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
48416 @@ -2801,6 +2917,22 @@ finish_lookup:
48417 path_put(&save_parent);
48418 return error;
48419 }
48420 +
48421 +#ifdef CONFIG_GRKERNSEC
48422 + if (nd->flags & LOOKUP_RCU) {
48423 + error = -ECHILD;
48424 + goto out;
48425 + }
48426 +#endif
48427 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
48428 + error = -ENOENT;
48429 + goto out;
48430 + }
48431 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
48432 + error = -EACCES;
48433 + goto out;
48434 + }
48435 +
48436 error = -EISDIR;
48437 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
48438 goto out;
48439 @@ -2899,7 +3031,7 @@ static struct file *path_openat(int dfd, const char *pathname,
48440 if (unlikely(error))
48441 goto out;
48442
48443 - error = do_last(nd, &path, file, op, &opened, pathname);
48444 + error = do_last(nd, &path, NULL, file, op, &opened, pathname);
48445 while (unlikely(error > 0)) { /* trailing symlink */
48446 struct path link = path;
48447 void *cookie;
48448 @@ -2917,7 +3049,7 @@ static struct file *path_openat(int dfd, const char *pathname,
48449 error = follow_link(&link, nd, &cookie);
48450 if (unlikely(error))
48451 break;
48452 - error = do_last(nd, &path, file, op, &opened, pathname);
48453 + error = do_last(nd, &path, &link, file, op, &opened, pathname);
48454 put_link(nd, &link, cookie);
48455 }
48456 out:
48457 @@ -3006,8 +3138,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
48458 goto unlock;
48459
48460 error = -EEXIST;
48461 - if (dentry->d_inode)
48462 + if (dentry->d_inode) {
48463 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
48464 + error = -ENOENT;
48465 + }
48466 goto fail;
48467 + }
48468 /*
48469 * Special case - lookup gave negative, but... we had foo/bar/
48470 * From the vfs_mknod() POV we just have a negative dentry -
48471 @@ -3058,6 +3194,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
48472 }
48473 EXPORT_SYMBOL(user_path_create);
48474
48475 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, char **to, int is_dir)
48476 +{
48477 + char *tmp = getname(pathname);
48478 + struct dentry *res;
48479 + if (IS_ERR(tmp))
48480 + return ERR_CAST(tmp);
48481 + res = kern_path_create(dfd, tmp, path, is_dir);
48482 + if (IS_ERR(res))
48483 + putname(tmp);
48484 + else
48485 + *to = tmp;
48486 + return res;
48487 +}
48488 +
48489 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
48490 {
48491 int error = may_create(dir, dentry);
48492 @@ -3119,6 +3269,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
48493
48494 if (!IS_POSIXACL(path.dentry->d_inode))
48495 mode &= ~current_umask();
48496 +
48497 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
48498 + error = -EPERM;
48499 + goto out;
48500 + }
48501 +
48502 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
48503 + error = -EACCES;
48504 + goto out;
48505 + }
48506 +
48507 error = security_path_mknod(&path, dentry, mode, dev);
48508 if (error)
48509 goto out;
48510 @@ -3135,6 +3296,8 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
48511 break;
48512 }
48513 out:
48514 + if (!error)
48515 + gr_handle_create(dentry, path.mnt);
48516 done_path_create(&path, dentry);
48517 return error;
48518 }
48519 @@ -3181,9 +3344,18 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode)
48520
48521 if (!IS_POSIXACL(path.dentry->d_inode))
48522 mode &= ~current_umask();
48523 +
48524 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
48525 + error = -EACCES;
48526 + goto out;
48527 + }
48528 +
48529 error = security_path_mkdir(&path, dentry, mode);
48530 if (!error)
48531 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
48532 + if (!error)
48533 + gr_handle_create(dentry, path.mnt);
48534 +out:
48535 done_path_create(&path, dentry);
48536 return error;
48537 }
48538 @@ -3260,6 +3432,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
48539 char * name;
48540 struct dentry *dentry;
48541 struct nameidata nd;
48542 + ino_t saved_ino = 0;
48543 + dev_t saved_dev = 0;
48544
48545 error = user_path_parent(dfd, pathname, &nd, &name);
48546 if (error)
48547 @@ -3291,10 +3465,21 @@ static long do_rmdir(int dfd, const char __user *pathname)
48548 error = -ENOENT;
48549 goto exit3;
48550 }
48551 +
48552 + saved_ino = dentry->d_inode->i_ino;
48553 + saved_dev = gr_get_dev_from_dentry(dentry);
48554 +
48555 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
48556 + error = -EACCES;
48557 + goto exit3;
48558 + }
48559 +
48560 error = security_path_rmdir(&nd.path, dentry);
48561 if (error)
48562 goto exit3;
48563 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
48564 + if (!error && (saved_dev || saved_ino))
48565 + gr_handle_delete(saved_ino, saved_dev);
48566 exit3:
48567 dput(dentry);
48568 exit2:
48569 @@ -3356,6 +3541,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
48570 struct dentry *dentry;
48571 struct nameidata nd;
48572 struct inode *inode = NULL;
48573 + ino_t saved_ino = 0;
48574 + dev_t saved_dev = 0;
48575
48576 error = user_path_parent(dfd, pathname, &nd, &name);
48577 if (error)
48578 @@ -3381,10 +3568,22 @@ static long do_unlinkat(int dfd, const char __user *pathname)
48579 if (!inode)
48580 goto slashes;
48581 ihold(inode);
48582 +
48583 + if (inode->i_nlink <= 1) {
48584 + saved_ino = inode->i_ino;
48585 + saved_dev = gr_get_dev_from_dentry(dentry);
48586 + }
48587 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
48588 + error = -EACCES;
48589 + goto exit2;
48590 + }
48591 +
48592 error = security_path_unlink(&nd.path, dentry);
48593 if (error)
48594 goto exit2;
48595 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
48596 + if (!error && (saved_ino || saved_dev))
48597 + gr_handle_delete(saved_ino, saved_dev);
48598 exit2:
48599 dput(dentry);
48600 }
48601 @@ -3456,9 +3655,17 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
48602 if (IS_ERR(dentry))
48603 goto out_putname;
48604
48605 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
48606 + error = -EACCES;
48607 + goto out;
48608 + }
48609 +
48610 error = security_path_symlink(&path, dentry, from);
48611 if (!error)
48612 error = vfs_symlink(path.dentry->d_inode, dentry, from);
48613 + if (!error)
48614 + gr_handle_create(dentry, path.mnt);
48615 +out:
48616 done_path_create(&path, dentry);
48617 out_putname:
48618 putname(from);
48619 @@ -3528,6 +3735,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
48620 {
48621 struct dentry *new_dentry;
48622 struct path old_path, new_path;
48623 + char *to = NULL;
48624 int how = 0;
48625 int error;
48626
48627 @@ -3551,7 +3759,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
48628 if (error)
48629 return error;
48630
48631 - new_dentry = user_path_create(newdfd, newname, &new_path, 0);
48632 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
48633 error = PTR_ERR(new_dentry);
48634 if (IS_ERR(new_dentry))
48635 goto out;
48636 @@ -3562,11 +3770,28 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
48637 error = may_linkat(&old_path);
48638 if (unlikely(error))
48639 goto out_dput;
48640 +
48641 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
48642 + old_path.dentry->d_inode,
48643 + old_path.dentry->d_inode->i_mode, to)) {
48644 + error = -EACCES;
48645 + goto out_dput;
48646 + }
48647 +
48648 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
48649 + old_path.dentry, old_path.mnt, to)) {
48650 + error = -EACCES;
48651 + goto out_dput;
48652 + }
48653 +
48654 error = security_path_link(old_path.dentry, &new_path, new_dentry);
48655 if (error)
48656 goto out_dput;
48657 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
48658 + if (!error)
48659 + gr_handle_create(new_dentry, new_path.mnt);
48660 out_dput:
48661 + putname(to);
48662 done_path_create(&new_path, new_dentry);
48663 out:
48664 path_put(&old_path);
48665 @@ -3802,12 +4027,21 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
48666 if (new_dentry == trap)
48667 goto exit5;
48668
48669 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
48670 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
48671 + to);
48672 + if (error)
48673 + goto exit5;
48674 +
48675 error = security_path_rename(&oldnd.path, old_dentry,
48676 &newnd.path, new_dentry);
48677 if (error)
48678 goto exit5;
48679 error = vfs_rename(old_dir->d_inode, old_dentry,
48680 new_dir->d_inode, new_dentry);
48681 + if (!error)
48682 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
48683 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
48684 exit5:
48685 dput(new_dentry);
48686 exit4:
48687 @@ -3832,6 +4066,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
48688
48689 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
48690 {
48691 + char tmpbuf[64];
48692 + const char *newlink;
48693 int len;
48694
48695 len = PTR_ERR(link);
48696 @@ -3841,7 +4077,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
48697 len = strlen(link);
48698 if (len > (unsigned) buflen)
48699 len = buflen;
48700 - if (copy_to_user(buffer, link, len))
48701 +
48702 + if (len < sizeof(tmpbuf)) {
48703 + memcpy(tmpbuf, link, len);
48704 + newlink = tmpbuf;
48705 + } else
48706 + newlink = link;
48707 +
48708 + if (copy_to_user(buffer, newlink, len))
48709 len = -EFAULT;
48710 out:
48711 return len;
48712 diff --git a/fs/namespace.c b/fs/namespace.c
48713 index 7bdf790..eb79c4b 100644
48714 --- a/fs/namespace.c
48715 +++ b/fs/namespace.c
48716 @@ -1212,6 +1212,9 @@ static int do_umount(struct mount *mnt, int flags)
48717 if (!(sb->s_flags & MS_RDONLY))
48718 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
48719 up_write(&sb->s_umount);
48720 +
48721 + gr_log_remount(mnt->mnt_devname, retval);
48722 +
48723 return retval;
48724 }
48725
48726 @@ -1231,6 +1234,9 @@ static int do_umount(struct mount *mnt, int flags)
48727 br_write_unlock(&vfsmount_lock);
48728 up_write(&namespace_sem);
48729 release_mounts(&umount_list);
48730 +
48731 + gr_log_unmount(mnt->mnt_devname, retval);
48732 +
48733 return retval;
48734 }
48735
48736 @@ -2244,6 +2250,16 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
48737 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
48738 MS_STRICTATIME);
48739
48740 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
48741 + retval = -EPERM;
48742 + goto dput_out;
48743 + }
48744 +
48745 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
48746 + retval = -EPERM;
48747 + goto dput_out;
48748 + }
48749 +
48750 if (flags & MS_REMOUNT)
48751 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
48752 data_page);
48753 @@ -2258,6 +2274,9 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
48754 dev_name, data_page);
48755 dput_out:
48756 path_put(&path);
48757 +
48758 + gr_log_mount(dev_name, dir_name, retval);
48759 +
48760 return retval;
48761 }
48762
48763 @@ -2516,6 +2535,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
48764 if (error)
48765 goto out2;
48766
48767 + if (gr_handle_chroot_pivot()) {
48768 + error = -EPERM;
48769 + goto out2;
48770 + }
48771 +
48772 get_fs_root(current->fs, &root);
48773 error = lock_mount(&old);
48774 if (error)
48775 diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c
48776 index 627f108..afc1fc5b 100644
48777 --- a/fs/nfs/dir.c
48778 +++ b/fs/nfs/dir.c
48779 @@ -450,7 +450,8 @@ void nfs_prime_dcache(struct dentry *parent, struct nfs_entry *entry)
48780 nfs_refresh_inode(dentry->d_inode, entry->fattr);
48781 goto out;
48782 } else {
48783 - d_drop(dentry);
48784 + if (d_invalidate(dentry) != 0)
48785 + goto out;
48786 dput(dentry);
48787 }
48788 }
48789 @@ -1100,6 +1101,8 @@ out_set_verifier:
48790 out_zap_parent:
48791 nfs_zap_caches(dir);
48792 out_bad:
48793 + nfs_free_fattr(fattr);
48794 + nfs_free_fhandle(fhandle);
48795 nfs_mark_for_revalidate(dir);
48796 if (inode && S_ISDIR(inode->i_mode)) {
48797 /* Purge readdir caches. */
48798 @@ -1112,8 +1115,6 @@ out_zap_parent:
48799 shrink_dcache_parent(dentry);
48800 }
48801 d_drop(dentry);
48802 - nfs_free_fattr(fattr);
48803 - nfs_free_fhandle(fhandle);
48804 dput(parent);
48805 dfprintk(LOOKUPCACHE, "NFS: %s(%s/%s) is invalid\n",
48806 __func__, dentry->d_parent->d_name.name,
48807 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
48808 index 9b47610..066975e 100644
48809 --- a/fs/nfs/inode.c
48810 +++ b/fs/nfs/inode.c
48811 @@ -1026,16 +1026,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
48812 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
48813 }
48814
48815 -static atomic_long_t nfs_attr_generation_counter;
48816 +static atomic_long_unchecked_t nfs_attr_generation_counter;
48817
48818 static unsigned long nfs_read_attr_generation_counter(void)
48819 {
48820 - return atomic_long_read(&nfs_attr_generation_counter);
48821 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
48822 }
48823
48824 unsigned long nfs_inc_attr_generation_counter(void)
48825 {
48826 - return atomic_long_inc_return(&nfs_attr_generation_counter);
48827 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
48828 }
48829
48830 void nfs_fattr_init(struct nfs_fattr *fattr)
48831 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
48832 index a9269f1..5490437 100644
48833 --- a/fs/nfsd/vfs.c
48834 +++ b/fs/nfsd/vfs.c
48835 @@ -941,7 +941,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
48836 } else {
48837 oldfs = get_fs();
48838 set_fs(KERNEL_DS);
48839 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
48840 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
48841 set_fs(oldfs);
48842 }
48843
48844 @@ -1045,7 +1045,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
48845
48846 /* Write the data. */
48847 oldfs = get_fs(); set_fs(KERNEL_DS);
48848 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
48849 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
48850 set_fs(oldfs);
48851 if (host_err < 0)
48852 goto out_nfserr;
48853 @@ -1581,7 +1581,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
48854 */
48855
48856 oldfs = get_fs(); set_fs(KERNEL_DS);
48857 - host_err = inode->i_op->readlink(path.dentry, buf, *lenp);
48858 + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
48859 set_fs(oldfs);
48860
48861 if (host_err < 0)
48862 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
48863 index d438036..0ecadde 100644
48864 --- a/fs/notify/fanotify/fanotify_user.c
48865 +++ b/fs/notify/fanotify/fanotify_user.c
48866 @@ -274,7 +274,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
48867 goto out_close_fd;
48868
48869 ret = -EFAULT;
48870 - if (copy_to_user(buf, &fanotify_event_metadata,
48871 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
48872 + copy_to_user(buf, &fanotify_event_metadata,
48873 fanotify_event_metadata.event_len))
48874 goto out_kill_access_response;
48875
48876 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
48877 index c887b13..0fdf472 100644
48878 --- a/fs/notify/notification.c
48879 +++ b/fs/notify/notification.c
48880 @@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
48881 * get set to 0 so it will never get 'freed'
48882 */
48883 static struct fsnotify_event *q_overflow_event;
48884 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48885 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48886
48887 /**
48888 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
48889 @@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48890 */
48891 u32 fsnotify_get_cookie(void)
48892 {
48893 - return atomic_inc_return(&fsnotify_sync_cookie);
48894 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
48895 }
48896 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
48897
48898 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
48899 index 99e3610..02c1068 100644
48900 --- a/fs/ntfs/dir.c
48901 +++ b/fs/ntfs/dir.c
48902 @@ -1329,7 +1329,7 @@ find_next_index_buffer:
48903 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
48904 ~(s64)(ndir->itype.index.block_size - 1)));
48905 /* Bounds checks. */
48906 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
48907 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
48908 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
48909 "inode 0x%lx or driver bug.", vdir->i_ino);
48910 goto err_out;
48911 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
48912 index 1ecf464..e1ff8bf 100644
48913 --- a/fs/ntfs/file.c
48914 +++ b/fs/ntfs/file.c
48915 @@ -2232,6 +2232,6 @@ const struct inode_operations ntfs_file_inode_ops = {
48916 #endif /* NTFS_RW */
48917 };
48918
48919 -const struct file_operations ntfs_empty_file_ops = {};
48920 +const struct file_operations ntfs_empty_file_ops __read_only;
48921
48922 -const struct inode_operations ntfs_empty_inode_ops = {};
48923 +const struct inode_operations ntfs_empty_inode_ops __read_only;
48924 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
48925 index a9f78c7..ed8a381 100644
48926 --- a/fs/ocfs2/localalloc.c
48927 +++ b/fs/ocfs2/localalloc.c
48928 @@ -1279,7 +1279,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
48929 goto bail;
48930 }
48931
48932 - atomic_inc(&osb->alloc_stats.moves);
48933 + atomic_inc_unchecked(&osb->alloc_stats.moves);
48934
48935 bail:
48936 if (handle)
48937 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
48938 index d355e6e..578d905 100644
48939 --- a/fs/ocfs2/ocfs2.h
48940 +++ b/fs/ocfs2/ocfs2.h
48941 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
48942
48943 struct ocfs2_alloc_stats
48944 {
48945 - atomic_t moves;
48946 - atomic_t local_data;
48947 - atomic_t bitmap_data;
48948 - atomic_t bg_allocs;
48949 - atomic_t bg_extends;
48950 + atomic_unchecked_t moves;
48951 + atomic_unchecked_t local_data;
48952 + atomic_unchecked_t bitmap_data;
48953 + atomic_unchecked_t bg_allocs;
48954 + atomic_unchecked_t bg_extends;
48955 };
48956
48957 enum ocfs2_local_alloc_state
48958 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
48959 index f169da4..9112253 100644
48960 --- a/fs/ocfs2/suballoc.c
48961 +++ b/fs/ocfs2/suballoc.c
48962 @@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
48963 mlog_errno(status);
48964 goto bail;
48965 }
48966 - atomic_inc(&osb->alloc_stats.bg_extends);
48967 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
48968
48969 /* You should never ask for this much metadata */
48970 BUG_ON(bits_wanted >
48971 @@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
48972 mlog_errno(status);
48973 goto bail;
48974 }
48975 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48976 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48977
48978 *suballoc_loc = res.sr_bg_blkno;
48979 *suballoc_bit_start = res.sr_bit_offset;
48980 @@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
48981 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
48982 res->sr_bits);
48983
48984 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48985 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48986
48987 BUG_ON(res->sr_bits != 1);
48988
48989 @@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
48990 mlog_errno(status);
48991 goto bail;
48992 }
48993 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48994 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48995
48996 BUG_ON(res.sr_bits != 1);
48997
48998 @@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
48999 cluster_start,
49000 num_clusters);
49001 if (!status)
49002 - atomic_inc(&osb->alloc_stats.local_data);
49003 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
49004 } else {
49005 if (min_clusters > (osb->bitmap_cpg - 1)) {
49006 /* The only paths asking for contiguousness
49007 @@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
49008 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
49009 res.sr_bg_blkno,
49010 res.sr_bit_offset);
49011 - atomic_inc(&osb->alloc_stats.bitmap_data);
49012 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
49013 *num_clusters = res.sr_bits;
49014 }
49015 }
49016 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
49017 index 68f4541..89cfe6a 100644
49018 --- a/fs/ocfs2/super.c
49019 +++ b/fs/ocfs2/super.c
49020 @@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
49021 "%10s => GlobalAllocs: %d LocalAllocs: %d "
49022 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
49023 "Stats",
49024 - atomic_read(&osb->alloc_stats.bitmap_data),
49025 - atomic_read(&osb->alloc_stats.local_data),
49026 - atomic_read(&osb->alloc_stats.bg_allocs),
49027 - atomic_read(&osb->alloc_stats.moves),
49028 - atomic_read(&osb->alloc_stats.bg_extends));
49029 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
49030 + atomic_read_unchecked(&osb->alloc_stats.local_data),
49031 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
49032 + atomic_read_unchecked(&osb->alloc_stats.moves),
49033 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
49034
49035 out += snprintf(buf + out, len - out,
49036 "%10s => State: %u Descriptor: %llu Size: %u bits "
49037 @@ -2116,11 +2116,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
49038 spin_lock_init(&osb->osb_xattr_lock);
49039 ocfs2_init_steal_slots(osb);
49040
49041 - atomic_set(&osb->alloc_stats.moves, 0);
49042 - atomic_set(&osb->alloc_stats.local_data, 0);
49043 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
49044 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
49045 - atomic_set(&osb->alloc_stats.bg_extends, 0);
49046 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
49047 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
49048 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
49049 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
49050 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
49051
49052 /* Copy the blockcheck stats from the superblock probe */
49053 osb->osb_ecc_stats = *stats;
49054 diff --git a/fs/open.c b/fs/open.c
49055 index e1f2cdb..3bd5f39 100644
49056 --- a/fs/open.c
49057 +++ b/fs/open.c
49058 @@ -31,6 +31,8 @@
49059 #include <linux/ima.h>
49060 #include <linux/dnotify.h>
49061
49062 +#define CREATE_TRACE_POINTS
49063 +#include <trace/events/fs.h>
49064 #include "internal.h"
49065
49066 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
49067 @@ -112,6 +114,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
49068 error = locks_verify_truncate(inode, NULL, length);
49069 if (!error)
49070 error = security_path_truncate(&path);
49071 +
49072 + if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
49073 + error = -EACCES;
49074 +
49075 if (!error)
49076 error = do_truncate(path.dentry, length, 0, NULL);
49077
49078 @@ -364,6 +370,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
49079 if (__mnt_is_readonly(path.mnt))
49080 res = -EROFS;
49081
49082 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
49083 + res = -EACCES;
49084 +
49085 out_path_release:
49086 path_put(&path);
49087 out:
49088 @@ -390,6 +399,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
49089 if (error)
49090 goto dput_and_out;
49091
49092 + gr_log_chdir(path.dentry, path.mnt);
49093 +
49094 set_fs_pwd(current->fs, &path);
49095
49096 dput_and_out:
49097 @@ -416,6 +427,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
49098 goto out_putf;
49099
49100 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
49101 +
49102 + if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
49103 + error = -EPERM;
49104 +
49105 + if (!error)
49106 + gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
49107 +
49108 if (!error)
49109 set_fs_pwd(current->fs, &file->f_path);
49110 out_putf:
49111 @@ -444,7 +462,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
49112 if (error)
49113 goto dput_and_out;
49114
49115 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
49116 + goto dput_and_out;
49117 +
49118 set_fs_root(current->fs, &path);
49119 +
49120 + gr_handle_chroot_chdir(&path);
49121 +
49122 error = 0;
49123 dput_and_out:
49124 path_put(&path);
49125 @@ -462,6 +486,16 @@ static int chmod_common(struct path *path, umode_t mode)
49126 if (error)
49127 return error;
49128 mutex_lock(&inode->i_mutex);
49129 +
49130 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
49131 + error = -EACCES;
49132 + goto out_unlock;
49133 + }
49134 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
49135 + error = -EACCES;
49136 + goto out_unlock;
49137 + }
49138 +
49139 error = security_path_chmod(path, mode);
49140 if (error)
49141 goto out_unlock;
49142 @@ -517,6 +551,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
49143 uid = make_kuid(current_user_ns(), user);
49144 gid = make_kgid(current_user_ns(), group);
49145
49146 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
49147 + return -EACCES;
49148 +
49149 newattrs.ia_valid = ATTR_CTIME;
49150 if (user != (uid_t) -1) {
49151 if (!uid_valid(uid))
49152 @@ -958,6 +995,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
49153 } else {
49154 fsnotify_open(f);
49155 fd_install(fd, f);
49156 + trace_do_sys_open(tmp, flags, mode);
49157 }
49158 }
49159 putname(tmp);
49160 diff --git a/fs/pipe.c b/fs/pipe.c
49161 index 8d85d70..581036b 100644
49162 --- a/fs/pipe.c
49163 +++ b/fs/pipe.c
49164 @@ -438,9 +438,9 @@ redo:
49165 }
49166 if (bufs) /* More to do? */
49167 continue;
49168 - if (!pipe->writers)
49169 + if (!atomic_read(&pipe->writers))
49170 break;
49171 - if (!pipe->waiting_writers) {
49172 + if (!atomic_read(&pipe->waiting_writers)) {
49173 /* syscall merging: Usually we must not sleep
49174 * if O_NONBLOCK is set, or if we got some data.
49175 * But if a writer sleeps in kernel space, then
49176 @@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
49177 mutex_lock(&inode->i_mutex);
49178 pipe = inode->i_pipe;
49179
49180 - if (!pipe->readers) {
49181 + if (!atomic_read(&pipe->readers)) {
49182 send_sig(SIGPIPE, current, 0);
49183 ret = -EPIPE;
49184 goto out;
49185 @@ -553,7 +553,7 @@ redo1:
49186 for (;;) {
49187 int bufs;
49188
49189 - if (!pipe->readers) {
49190 + if (!atomic_read(&pipe->readers)) {
49191 send_sig(SIGPIPE, current, 0);
49192 if (!ret)
49193 ret = -EPIPE;
49194 @@ -644,9 +644,9 @@ redo2:
49195 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
49196 do_wakeup = 0;
49197 }
49198 - pipe->waiting_writers++;
49199 + atomic_inc(&pipe->waiting_writers);
49200 pipe_wait(pipe);
49201 - pipe->waiting_writers--;
49202 + atomic_dec(&pipe->waiting_writers);
49203 }
49204 out:
49205 mutex_unlock(&inode->i_mutex);
49206 @@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
49207 mask = 0;
49208 if (filp->f_mode & FMODE_READ) {
49209 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
49210 - if (!pipe->writers && filp->f_version != pipe->w_counter)
49211 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
49212 mask |= POLLHUP;
49213 }
49214
49215 @@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
49216 * Most Unices do not set POLLERR for FIFOs but on Linux they
49217 * behave exactly like pipes for poll().
49218 */
49219 - if (!pipe->readers)
49220 + if (!atomic_read(&pipe->readers))
49221 mask |= POLLERR;
49222 }
49223
49224 @@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
49225
49226 mutex_lock(&inode->i_mutex);
49227 pipe = inode->i_pipe;
49228 - pipe->readers -= decr;
49229 - pipe->writers -= decw;
49230 + atomic_sub(decr, &pipe->readers);
49231 + atomic_sub(decw, &pipe->writers);
49232
49233 - if (!pipe->readers && !pipe->writers) {
49234 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
49235 free_pipe_info(inode);
49236 } else {
49237 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
49238 @@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
49239
49240 if (inode->i_pipe) {
49241 ret = 0;
49242 - inode->i_pipe->readers++;
49243 + atomic_inc(&inode->i_pipe->readers);
49244 }
49245
49246 mutex_unlock(&inode->i_mutex);
49247 @@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
49248
49249 if (inode->i_pipe) {
49250 ret = 0;
49251 - inode->i_pipe->writers++;
49252 + atomic_inc(&inode->i_pipe->writers);
49253 }
49254
49255 mutex_unlock(&inode->i_mutex);
49256 @@ -868,9 +868,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
49257 if (inode->i_pipe) {
49258 ret = 0;
49259 if (filp->f_mode & FMODE_READ)
49260 - inode->i_pipe->readers++;
49261 + atomic_inc(&inode->i_pipe->readers);
49262 if (filp->f_mode & FMODE_WRITE)
49263 - inode->i_pipe->writers++;
49264 + atomic_inc(&inode->i_pipe->writers);
49265 }
49266
49267 mutex_unlock(&inode->i_mutex);
49268 @@ -962,7 +962,7 @@ void free_pipe_info(struct inode *inode)
49269 inode->i_pipe = NULL;
49270 }
49271
49272 -static struct vfsmount *pipe_mnt __read_mostly;
49273 +struct vfsmount *pipe_mnt __read_mostly;
49274
49275 /*
49276 * pipefs_dname() is called from d_path().
49277 @@ -992,7 +992,8 @@ static struct inode * get_pipe_inode(void)
49278 goto fail_iput;
49279 inode->i_pipe = pipe;
49280
49281 - pipe->readers = pipe->writers = 1;
49282 + atomic_set(&pipe->readers, 1);
49283 + atomic_set(&pipe->writers, 1);
49284 inode->i_fop = &rdwr_pipefifo_fops;
49285
49286 /*
49287 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
49288 index 15af622..0e9f4467 100644
49289 --- a/fs/proc/Kconfig
49290 +++ b/fs/proc/Kconfig
49291 @@ -30,12 +30,12 @@ config PROC_FS
49292
49293 config PROC_KCORE
49294 bool "/proc/kcore support" if !ARM
49295 - depends on PROC_FS && MMU
49296 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
49297
49298 config PROC_VMCORE
49299 bool "/proc/vmcore support"
49300 - depends on PROC_FS && CRASH_DUMP
49301 - default y
49302 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
49303 + default n
49304 help
49305 Exports the dump image of crashed kernel in ELF format.
49306
49307 @@ -59,8 +59,8 @@ config PROC_SYSCTL
49308 limited in memory.
49309
49310 config PROC_PAGE_MONITOR
49311 - default y
49312 - depends on PROC_FS && MMU
49313 + default n
49314 + depends on PROC_FS && MMU && !GRKERNSEC
49315 bool "Enable /proc page monitoring" if EXPERT
49316 help
49317 Various /proc files exist to monitor process memory utilization:
49318 diff --git a/fs/proc/array.c b/fs/proc/array.c
49319 index c1c207c..01ce725 100644
49320 --- a/fs/proc/array.c
49321 +++ b/fs/proc/array.c
49322 @@ -60,6 +60,7 @@
49323 #include <linux/tty.h>
49324 #include <linux/string.h>
49325 #include <linux/mman.h>
49326 +#include <linux/grsecurity.h>
49327 #include <linux/proc_fs.h>
49328 #include <linux/ioport.h>
49329 #include <linux/uaccess.h>
49330 @@ -346,6 +347,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
49331 seq_putc(m, '\n');
49332 }
49333
49334 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
49335 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
49336 +{
49337 + if (p->mm)
49338 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
49339 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
49340 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
49341 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
49342 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
49343 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
49344 + else
49345 + seq_printf(m, "PaX:\t-----\n");
49346 +}
49347 +#endif
49348 +
49349 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
49350 struct pid *pid, struct task_struct *task)
49351 {
49352 @@ -363,9 +379,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
49353 task_cpus_allowed(m, task);
49354 cpuset_task_status_allowed(m, task);
49355 task_context_switch_counts(m, task);
49356 +
49357 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
49358 + task_pax(m, task);
49359 +#endif
49360 +
49361 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
49362 + task_grsec_rbac(m, task);
49363 +#endif
49364 +
49365 return 0;
49366 }
49367
49368 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49369 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
49370 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
49371 + _mm->pax_flags & MF_PAX_SEGMEXEC))
49372 +#endif
49373 +
49374 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
49375 struct pid *pid, struct task_struct *task, int whole)
49376 {
49377 @@ -387,6 +418,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
49378 char tcomm[sizeof(task->comm)];
49379 unsigned long flags;
49380
49381 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49382 + if (current->exec_id != m->exec_id) {
49383 + gr_log_badprocpid("stat");
49384 + return 0;
49385 + }
49386 +#endif
49387 +
49388 state = *get_task_state(task);
49389 vsize = eip = esp = 0;
49390 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
49391 @@ -458,6 +496,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
49392 gtime = task->gtime;
49393 }
49394
49395 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49396 + if (PAX_RAND_FLAGS(mm)) {
49397 + eip = 0;
49398 + esp = 0;
49399 + wchan = 0;
49400 + }
49401 +#endif
49402 +#ifdef CONFIG_GRKERNSEC_HIDESYM
49403 + wchan = 0;
49404 + eip =0;
49405 + esp =0;
49406 +#endif
49407 +
49408 /* scale priority and nice values from timeslices to -20..20 */
49409 /* to make it look like a "normal" Unix priority/nice value */
49410 priority = task_prio(task);
49411 @@ -494,9 +545,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
49412 seq_put_decimal_ull(m, ' ', vsize);
49413 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
49414 seq_put_decimal_ull(m, ' ', rsslim);
49415 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49416 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
49417 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
49418 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
49419 +#else
49420 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
49421 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
49422 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
49423 +#endif
49424 seq_put_decimal_ull(m, ' ', esp);
49425 seq_put_decimal_ull(m, ' ', eip);
49426 /* The signal information here is obsolete.
49427 @@ -518,7 +575,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
49428 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
49429 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
49430
49431 - if (mm && permitted) {
49432 + if (mm && permitted
49433 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49434 + && !PAX_RAND_FLAGS(mm)
49435 +#endif
49436 + ) {
49437 seq_put_decimal_ull(m, ' ', mm->start_data);
49438 seq_put_decimal_ull(m, ' ', mm->end_data);
49439 seq_put_decimal_ull(m, ' ', mm->start_brk);
49440 @@ -556,8 +617,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
49441 struct pid *pid, struct task_struct *task)
49442 {
49443 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
49444 - struct mm_struct *mm = get_task_mm(task);
49445 + struct mm_struct *mm;
49446
49447 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49448 + if (current->exec_id != m->exec_id) {
49449 + gr_log_badprocpid("statm");
49450 + return 0;
49451 + }
49452 +#endif
49453 + mm = get_task_mm(task);
49454 if (mm) {
49455 size = task_statm(mm, &shared, &text, &data, &resident);
49456 mmput(mm);
49457 @@ -580,6 +648,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
49458 return 0;
49459 }
49460
49461 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49462 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
49463 +{
49464 + return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
49465 +}
49466 +#endif
49467 +
49468 #ifdef CONFIG_CHECKPOINT_RESTORE
49469 static struct pid *
49470 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
49471 diff --git a/fs/proc/base.c b/fs/proc/base.c
49472 index 1b6c84c..66b738b 100644
49473 --- a/fs/proc/base.c
49474 +++ b/fs/proc/base.c
49475 @@ -110,6 +110,14 @@ struct pid_entry {
49476 union proc_op op;
49477 };
49478
49479 +struct getdents_callback {
49480 + struct linux_dirent __user * current_dir;
49481 + struct linux_dirent __user * previous;
49482 + struct file * file;
49483 + int count;
49484 + int error;
49485 +};
49486 +
49487 #define NOD(NAME, MODE, IOP, FOP, OP) { \
49488 .name = (NAME), \
49489 .len = sizeof(NAME) - 1, \
49490 @@ -209,6 +217,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
49491 if (!mm->arg_end)
49492 goto out_mm; /* Shh! No looking before we're done */
49493
49494 + if (gr_acl_handle_procpidmem(task))
49495 + goto out_mm;
49496 +
49497 len = mm->arg_end - mm->arg_start;
49498
49499 if (len > PAGE_SIZE)
49500 @@ -236,12 +247,28 @@ out:
49501 return res;
49502 }
49503
49504 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49505 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
49506 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
49507 + _mm->pax_flags & MF_PAX_SEGMEXEC))
49508 +#endif
49509 +
49510 static int proc_pid_auxv(struct task_struct *task, char *buffer)
49511 {
49512 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
49513 int res = PTR_ERR(mm);
49514 if (mm && !IS_ERR(mm)) {
49515 unsigned int nwords = 0;
49516 +
49517 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49518 + /* allow if we're currently ptracing this task */
49519 + if (PAX_RAND_FLAGS(mm) &&
49520 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
49521 + mmput(mm);
49522 + return 0;
49523 + }
49524 +#endif
49525 +
49526 do {
49527 nwords += 2;
49528 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
49529 @@ -255,7 +282,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
49530 }
49531
49532
49533 -#ifdef CONFIG_KALLSYMS
49534 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49535 /*
49536 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
49537 * Returns the resolved symbol. If that fails, simply return the address.
49538 @@ -294,7 +321,7 @@ static void unlock_trace(struct task_struct *task)
49539 mutex_unlock(&task->signal->cred_guard_mutex);
49540 }
49541
49542 -#ifdef CONFIG_STACKTRACE
49543 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49544
49545 #define MAX_STACK_TRACE_DEPTH 64
49546
49547 @@ -486,7 +513,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
49548 return count;
49549 }
49550
49551 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49552 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49553 static int proc_pid_syscall(struct task_struct *task, char *buffer)
49554 {
49555 long nr;
49556 @@ -515,7 +542,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
49557 /************************************************************************/
49558
49559 /* permission checks */
49560 -static int proc_fd_access_allowed(struct inode *inode)
49561 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
49562 {
49563 struct task_struct *task;
49564 int allowed = 0;
49565 @@ -525,7 +552,10 @@ static int proc_fd_access_allowed(struct inode *inode)
49566 */
49567 task = get_proc_task(inode);
49568 if (task) {
49569 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
49570 + if (log)
49571 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
49572 + else
49573 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
49574 put_task_struct(task);
49575 }
49576 return allowed;
49577 @@ -563,10 +593,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
49578 struct task_struct *task,
49579 int hide_pid_min)
49580 {
49581 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49582 + return false;
49583 +
49584 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49585 + rcu_read_lock();
49586 + {
49587 + const struct cred *tmpcred = current_cred();
49588 + const struct cred *cred = __task_cred(task);
49589 +
49590 + if (!tmpcred->uid || (tmpcred->uid == cred->uid)
49591 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49592 + || in_group_p(grsec_proc_gid)
49593 +#endif
49594 + ) {
49595 + rcu_read_unlock();
49596 + return true;
49597 + }
49598 + }
49599 + rcu_read_unlock();
49600 +
49601 + if (!pid->hide_pid)
49602 + return false;
49603 +#endif
49604 +
49605 if (pid->hide_pid < hide_pid_min)
49606 return true;
49607 if (in_group_p(pid->pid_gid))
49608 return true;
49609 +
49610 return ptrace_may_access(task, PTRACE_MODE_READ);
49611 }
49612
49613 @@ -584,7 +639,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
49614 put_task_struct(task);
49615
49616 if (!has_perms) {
49617 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49618 + {
49619 +#else
49620 if (pid->hide_pid == 2) {
49621 +#endif
49622 /*
49623 * Let's make getdents(), stat(), and open()
49624 * consistent with each other. If a process
49625 @@ -682,6 +741,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
49626 if (!task)
49627 return -ESRCH;
49628
49629 + if (gr_acl_handle_procpidmem(task)) {
49630 + put_task_struct(task);
49631 + return -EPERM;
49632 + }
49633 +
49634 mm = mm_access(task, mode);
49635 put_task_struct(task);
49636
49637 @@ -697,6 +761,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
49638
49639 file->private_data = mm;
49640
49641 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49642 + file->f_version = current->exec_id;
49643 +#endif
49644 +
49645 return 0;
49646 }
49647
49648 @@ -718,6 +786,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
49649 ssize_t copied;
49650 char *page;
49651
49652 +#ifdef CONFIG_GRKERNSEC
49653 + if (write)
49654 + return -EPERM;
49655 +#endif
49656 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49657 + if (file->f_version != current->exec_id) {
49658 + gr_log_badprocpid("mem");
49659 + return 0;
49660 + }
49661 +#endif
49662 +
49663 if (!mm)
49664 return 0;
49665
49666 @@ -822,6 +901,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
49667 if (!mm)
49668 return 0;
49669
49670 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49671 + if (file->f_version != current->exec_id) {
49672 + gr_log_badprocpid("environ");
49673 + return 0;
49674 + }
49675 +#endif
49676 +
49677 page = (char *)__get_free_page(GFP_TEMPORARY);
49678 if (!page)
49679 return -ENOMEM;
49680 @@ -1435,7 +1521,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
49681 int error = -EACCES;
49682
49683 /* Are we allowed to snoop on the tasks file descriptors? */
49684 - if (!proc_fd_access_allowed(inode))
49685 + if (!proc_fd_access_allowed(inode, 0))
49686 goto out;
49687
49688 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
49689 @@ -1479,8 +1565,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
49690 struct path path;
49691
49692 /* Are we allowed to snoop on the tasks file descriptors? */
49693 - if (!proc_fd_access_allowed(inode))
49694 - goto out;
49695 + /* logging this is needed for learning on chromium to work properly,
49696 + but we don't want to flood the logs from 'ps' which does a readlink
49697 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
49698 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
49699 + */
49700 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
49701 + if (!proc_fd_access_allowed(inode,0))
49702 + goto out;
49703 + } else {
49704 + if (!proc_fd_access_allowed(inode,1))
49705 + goto out;
49706 + }
49707
49708 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
49709 if (error)
49710 @@ -1545,7 +1641,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
49711 rcu_read_lock();
49712 cred = __task_cred(task);
49713 inode->i_uid = cred->euid;
49714 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49715 + inode->i_gid = grsec_proc_gid;
49716 +#else
49717 inode->i_gid = cred->egid;
49718 +#endif
49719 rcu_read_unlock();
49720 }
49721 security_task_to_inode(task, inode);
49722 @@ -1581,10 +1681,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
49723 return -ENOENT;
49724 }
49725 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
49726 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49727 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
49728 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49729 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
49730 +#endif
49731 task_dumpable(task)) {
49732 cred = __task_cred(task);
49733 stat->uid = cred->euid;
49734 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49735 + stat->gid = grsec_proc_gid;
49736 +#else
49737 stat->gid = cred->egid;
49738 +#endif
49739 }
49740 }
49741 rcu_read_unlock();
49742 @@ -1622,11 +1731,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
49743
49744 if (task) {
49745 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
49746 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49747 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
49748 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49749 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
49750 +#endif
49751 task_dumpable(task)) {
49752 rcu_read_lock();
49753 cred = __task_cred(task);
49754 inode->i_uid = cred->euid;
49755 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49756 + inode->i_gid = grsec_proc_gid;
49757 +#else
49758 inode->i_gid = cred->egid;
49759 +#endif
49760 rcu_read_unlock();
49761 } else {
49762 inode->i_uid = GLOBAL_ROOT_UID;
49763 @@ -1744,7 +1862,8 @@ static int proc_fd_info(struct inode *inode, struct path *path, char *info)
49764 int fd = proc_fd(inode);
49765
49766 if (task) {
49767 - files = get_files_struct(task);
49768 + if (!gr_acl_handle_procpidmem(task))
49769 + files = get_files_struct(task);
49770 put_task_struct(task);
49771 }
49772 if (files) {
49773 @@ -2343,11 +2462,21 @@ static const struct file_operations proc_map_files_operations = {
49774 */
49775 static int proc_fd_permission(struct inode *inode, int mask)
49776 {
49777 + struct task_struct *task;
49778 int rv = generic_permission(inode, mask);
49779 - if (rv == 0)
49780 - return 0;
49781 +
49782 if (task_pid(current) == proc_pid(inode))
49783 rv = 0;
49784 +
49785 + task = get_proc_task(inode);
49786 + if (task == NULL)
49787 + return rv;
49788 +
49789 + if (gr_acl_handle_procpidmem(task))
49790 + rv = -EACCES;
49791 +
49792 + put_task_struct(task);
49793 +
49794 return rv;
49795 }
49796
49797 @@ -2457,6 +2586,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
49798 if (!task)
49799 goto out_no_task;
49800
49801 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49802 + goto out;
49803 +
49804 /*
49805 * Yes, it does not scale. And it should not. Don't add
49806 * new entries into /proc/<tgid>/ without very good reasons.
49807 @@ -2501,6 +2633,9 @@ static int proc_pident_readdir(struct file *filp,
49808 if (!task)
49809 goto out_no_task;
49810
49811 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49812 + goto out;
49813 +
49814 ret = 0;
49815 i = filp->f_pos;
49816 switch (i) {
49817 @@ -2771,7 +2906,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
49818 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
49819 void *cookie)
49820 {
49821 - char *s = nd_get_link(nd);
49822 + const char *s = nd_get_link(nd);
49823 if (!IS_ERR(s))
49824 __putname(s);
49825 }
49826 @@ -3040,7 +3175,7 @@ static const struct pid_entry tgid_base_stuff[] = {
49827 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
49828 #endif
49829 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
49830 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49831 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49832 INF("syscall", S_IRUGO, proc_pid_syscall),
49833 #endif
49834 INF("cmdline", S_IRUGO, proc_pid_cmdline),
49835 @@ -3065,10 +3200,10 @@ static const struct pid_entry tgid_base_stuff[] = {
49836 #ifdef CONFIG_SECURITY
49837 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
49838 #endif
49839 -#ifdef CONFIG_KALLSYMS
49840 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49841 INF("wchan", S_IRUGO, proc_pid_wchan),
49842 #endif
49843 -#ifdef CONFIG_STACKTRACE
49844 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49845 ONE("stack", S_IRUGO, proc_pid_stack),
49846 #endif
49847 #ifdef CONFIG_SCHEDSTATS
49848 @@ -3102,6 +3237,9 @@ static const struct pid_entry tgid_base_stuff[] = {
49849 #ifdef CONFIG_HARDWALL
49850 INF("hardwall", S_IRUGO, proc_pid_hardwall),
49851 #endif
49852 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49853 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
49854 +#endif
49855 #ifdef CONFIG_USER_NS
49856 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
49857 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
49858 @@ -3233,7 +3371,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
49859 if (!inode)
49860 goto out;
49861
49862 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49863 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
49864 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49865 + inode->i_gid = grsec_proc_gid;
49866 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
49867 +#else
49868 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
49869 +#endif
49870 inode->i_op = &proc_tgid_base_inode_operations;
49871 inode->i_fop = &proc_tgid_base_operations;
49872 inode->i_flags|=S_IMMUTABLE;
49873 @@ -3275,7 +3420,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
49874 if (!task)
49875 goto out;
49876
49877 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49878 + goto out_put_task;
49879 +
49880 result = proc_pid_instantiate(dir, dentry, task, NULL);
49881 +out_put_task:
49882 put_task_struct(task);
49883 out:
49884 return result;
49885 @@ -3338,6 +3487,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
49886 static int fake_filldir(void *buf, const char *name, int namelen,
49887 loff_t offset, u64 ino, unsigned d_type)
49888 {
49889 + struct getdents_callback * __buf = (struct getdents_callback *) buf;
49890 + __buf->error = -EINVAL;
49891 return 0;
49892 }
49893
49894 @@ -3404,7 +3555,7 @@ static const struct pid_entry tid_base_stuff[] = {
49895 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
49896 #endif
49897 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
49898 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49899 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49900 INF("syscall", S_IRUGO, proc_pid_syscall),
49901 #endif
49902 INF("cmdline", S_IRUGO, proc_pid_cmdline),
49903 @@ -3431,10 +3582,10 @@ static const struct pid_entry tid_base_stuff[] = {
49904 #ifdef CONFIG_SECURITY
49905 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
49906 #endif
49907 -#ifdef CONFIG_KALLSYMS
49908 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49909 INF("wchan", S_IRUGO, proc_pid_wchan),
49910 #endif
49911 -#ifdef CONFIG_STACKTRACE
49912 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49913 ONE("stack", S_IRUGO, proc_pid_stack),
49914 #endif
49915 #ifdef CONFIG_SCHEDSTATS
49916 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
49917 index 82676e3..5f8518a 100644
49918 --- a/fs/proc/cmdline.c
49919 +++ b/fs/proc/cmdline.c
49920 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
49921
49922 static int __init proc_cmdline_init(void)
49923 {
49924 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
49925 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
49926 +#else
49927 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
49928 +#endif
49929 return 0;
49930 }
49931 module_init(proc_cmdline_init);
49932 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
49933 index b143471..bb105e5 100644
49934 --- a/fs/proc/devices.c
49935 +++ b/fs/proc/devices.c
49936 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
49937
49938 static int __init proc_devices_init(void)
49939 {
49940 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
49941 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
49942 +#else
49943 proc_create("devices", 0, NULL, &proc_devinfo_operations);
49944 +#endif
49945 return 0;
49946 }
49947 module_init(proc_devices_init);
49948 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
49949 index 7ac817b..c5c9eb0 100644
49950 --- a/fs/proc/inode.c
49951 +++ b/fs/proc/inode.c
49952 @@ -21,11 +21,17 @@
49953 #include <linux/seq_file.h>
49954 #include <linux/slab.h>
49955 #include <linux/mount.h>
49956 +#include <linux/grsecurity.h>
49957
49958 #include <asm/uaccess.h>
49959
49960 #include "internal.h"
49961
49962 +#ifdef CONFIG_PROC_SYSCTL
49963 +extern const struct inode_operations proc_sys_inode_operations;
49964 +extern const struct inode_operations proc_sys_dir_operations;
49965 +#endif
49966 +
49967 static void proc_evict_inode(struct inode *inode)
49968 {
49969 struct proc_dir_entry *de;
49970 @@ -51,6 +57,13 @@ static void proc_evict_inode(struct inode *inode)
49971 ns_ops = PROC_I(inode)->ns_ops;
49972 if (ns_ops && ns_ops->put)
49973 ns_ops->put(PROC_I(inode)->ns);
49974 +
49975 +#ifdef CONFIG_PROC_SYSCTL
49976 + if (inode->i_op == &proc_sys_inode_operations ||
49977 + inode->i_op == &proc_sys_dir_operations)
49978 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
49979 +#endif
49980 +
49981 }
49982
49983 static struct kmem_cache * proc_inode_cachep;
49984 @@ -456,7 +469,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
49985 if (de->mode) {
49986 inode->i_mode = de->mode;
49987 inode->i_uid = de->uid;
49988 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49989 + inode->i_gid = grsec_proc_gid;
49990 +#else
49991 inode->i_gid = de->gid;
49992 +#endif
49993 }
49994 if (de->size)
49995 inode->i_size = de->size;
49996 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
49997 index e1167a1..bd24f20 100644
49998 --- a/fs/proc/internal.h
49999 +++ b/fs/proc/internal.h
50000 @@ -52,6 +52,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
50001 struct pid *pid, struct task_struct *task);
50002 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
50003 struct pid *pid, struct task_struct *task);
50004 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
50005 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
50006 +#endif
50007 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
50008
50009 extern const struct file_operations proc_tid_children_operations;
50010 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
50011 index 86c67ee..cdca321 100644
50012 --- a/fs/proc/kcore.c
50013 +++ b/fs/proc/kcore.c
50014 @@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
50015 * the addresses in the elf_phdr on our list.
50016 */
50017 start = kc_offset_to_vaddr(*fpos - elf_buflen);
50018 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
50019 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
50020 + if (tsz > buflen)
50021 tsz = buflen;
50022 -
50023 +
50024 while (buflen) {
50025 struct kcore_list *m;
50026
50027 @@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
50028 kfree(elf_buf);
50029 } else {
50030 if (kern_addr_valid(start)) {
50031 - unsigned long n;
50032 + char *elf_buf;
50033 + mm_segment_t oldfs;
50034
50035 - n = copy_to_user(buffer, (char *)start, tsz);
50036 - /*
50037 - * We cannot distinguish between fault on source
50038 - * and fault on destination. When this happens
50039 - * we clear too and hope it will trigger the
50040 - * EFAULT again.
50041 - */
50042 - if (n) {
50043 - if (clear_user(buffer + tsz - n,
50044 - n))
50045 + elf_buf = kmalloc(tsz, GFP_KERNEL);
50046 + if (!elf_buf)
50047 + return -ENOMEM;
50048 + oldfs = get_fs();
50049 + set_fs(KERNEL_DS);
50050 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
50051 + set_fs(oldfs);
50052 + if (copy_to_user(buffer, elf_buf, tsz)) {
50053 + kfree(elf_buf);
50054 return -EFAULT;
50055 + }
50056 }
50057 + set_fs(oldfs);
50058 + kfree(elf_buf);
50059 } else {
50060 if (clear_user(buffer, tsz))
50061 return -EFAULT;
50062 @@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
50063
50064 static int open_kcore(struct inode *inode, struct file *filp)
50065 {
50066 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
50067 + return -EPERM;
50068 +#endif
50069 if (!capable(CAP_SYS_RAWIO))
50070 return -EPERM;
50071 if (kcore_need_update)
50072 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
50073 index 80e4645..53e5fcf 100644
50074 --- a/fs/proc/meminfo.c
50075 +++ b/fs/proc/meminfo.c
50076 @@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
50077 vmi.used >> 10,
50078 vmi.largest_chunk >> 10
50079 #ifdef CONFIG_MEMORY_FAILURE
50080 - ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
50081 + ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
50082 #endif
50083 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
50084 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
50085 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
50086 index b1822dd..df622cb 100644
50087 --- a/fs/proc/nommu.c
50088 +++ b/fs/proc/nommu.c
50089 @@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
50090 if (len < 1)
50091 len = 1;
50092 seq_printf(m, "%*c", len, ' ');
50093 - seq_path(m, &file->f_path, "");
50094 + seq_path(m, &file->f_path, "\n\\");
50095 }
50096
50097 seq_putc(m, '\n');
50098 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
50099 index fe72cd0..cb9b67d 100644
50100 --- a/fs/proc/proc_net.c
50101 +++ b/fs/proc/proc_net.c
50102 @@ -23,6 +23,7 @@
50103 #include <linux/nsproxy.h>
50104 #include <net/net_namespace.h>
50105 #include <linux/seq_file.h>
50106 +#include <linux/grsecurity.h>
50107
50108 #include "internal.h"
50109
50110 @@ -105,6 +106,17 @@ static struct net *get_proc_task_net(struct inode *dir)
50111 struct task_struct *task;
50112 struct nsproxy *ns;
50113 struct net *net = NULL;
50114 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50115 + const struct cred *cred = current_cred();
50116 +#endif
50117 +
50118 +#ifdef CONFIG_GRKERNSEC_PROC_USER
50119 + if (cred->fsuid)
50120 + return net;
50121 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50122 + if (cred->fsuid && !in_group_p(grsec_proc_gid))
50123 + return net;
50124 +#endif
50125
50126 rcu_read_lock();
50127 task = pid_task(proc_pid(dir), PIDTYPE_PID);
50128 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
50129 index eb7cc91..7327a46 100644
50130 --- a/fs/proc/proc_sysctl.c
50131 +++ b/fs/proc/proc_sysctl.c
50132 @@ -12,11 +12,15 @@
50133 #include <linux/module.h>
50134 #include "internal.h"
50135
50136 +extern int gr_handle_chroot_sysctl(const int op);
50137 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
50138 + const int op);
50139 +
50140 static const struct dentry_operations proc_sys_dentry_operations;
50141 static const struct file_operations proc_sys_file_operations;
50142 -static const struct inode_operations proc_sys_inode_operations;
50143 +const struct inode_operations proc_sys_inode_operations;
50144 static const struct file_operations proc_sys_dir_file_operations;
50145 -static const struct inode_operations proc_sys_dir_operations;
50146 +const struct inode_operations proc_sys_dir_operations;
50147
50148 void proc_sys_poll_notify(struct ctl_table_poll *poll)
50149 {
50150 @@ -467,6 +471,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
50151
50152 err = NULL;
50153 d_set_d_op(dentry, &proc_sys_dentry_operations);
50154 +
50155 + gr_handle_proc_create(dentry, inode);
50156 +
50157 d_add(dentry, inode);
50158
50159 out:
50160 @@ -482,18 +489,20 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
50161 struct inode *inode = filp->f_path.dentry->d_inode;
50162 struct ctl_table_header *head = grab_header(inode);
50163 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
50164 + int op = write ? MAY_WRITE : MAY_READ;
50165 ssize_t error;
50166 size_t res;
50167
50168 if (IS_ERR(head))
50169 return PTR_ERR(head);
50170
50171 +
50172 /*
50173 * At this point we know that the sysctl was not unregistered
50174 * and won't be until we finish.
50175 */
50176 error = -EPERM;
50177 - if (sysctl_perm(head->root, table, write ? MAY_WRITE : MAY_READ))
50178 + if (sysctl_perm(head->root, table, op))
50179 goto out;
50180
50181 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
50182 @@ -501,6 +510,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
50183 if (!table->proc_handler)
50184 goto out;
50185
50186 +#ifdef CONFIG_GRKERNSEC
50187 + error = -EPERM;
50188 + if (gr_handle_chroot_sysctl(op))
50189 + goto out;
50190 + dget(filp->f_path.dentry);
50191 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
50192 + dput(filp->f_path.dentry);
50193 + goto out;
50194 + }
50195 + dput(filp->f_path.dentry);
50196 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
50197 + goto out;
50198 + if (write && !capable(CAP_SYS_ADMIN))
50199 + goto out;
50200 +#endif
50201 +
50202 /* careful: calling conventions are nasty here */
50203 res = count;
50204 error = table->proc_handler(table, write, buf, &res, ppos);
50205 @@ -598,6 +623,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
50206 return -ENOMEM;
50207 } else {
50208 d_set_d_op(child, &proc_sys_dentry_operations);
50209 +
50210 + gr_handle_proc_create(child, inode);
50211 +
50212 d_add(child, inode);
50213 }
50214 } else {
50215 @@ -641,6 +669,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
50216 if ((*pos)++ < file->f_pos)
50217 return 0;
50218
50219 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
50220 + return 0;
50221 +
50222 if (unlikely(S_ISLNK(table->mode)))
50223 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
50224 else
50225 @@ -758,6 +789,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
50226 if (IS_ERR(head))
50227 return PTR_ERR(head);
50228
50229 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
50230 + return -ENOENT;
50231 +
50232 generic_fillattr(inode, stat);
50233 if (table)
50234 stat->mode = (stat->mode & S_IFMT) | table->mode;
50235 @@ -780,13 +814,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
50236 .llseek = generic_file_llseek,
50237 };
50238
50239 -static const struct inode_operations proc_sys_inode_operations = {
50240 +const struct inode_operations proc_sys_inode_operations = {
50241 .permission = proc_sys_permission,
50242 .setattr = proc_sys_setattr,
50243 .getattr = proc_sys_getattr,
50244 };
50245
50246 -static const struct inode_operations proc_sys_dir_operations = {
50247 +const struct inode_operations proc_sys_dir_operations = {
50248 .lookup = proc_sys_lookup,
50249 .permission = proc_sys_permission,
50250 .setattr = proc_sys_setattr,
50251 diff --git a/fs/proc/root.c b/fs/proc/root.c
50252 index 9a2d9fd..ddfc92a 100644
50253 --- a/fs/proc/root.c
50254 +++ b/fs/proc/root.c
50255 @@ -187,7 +187,15 @@ void __init proc_root_init(void)
50256 #ifdef CONFIG_PROC_DEVICETREE
50257 proc_device_tree_init();
50258 #endif
50259 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
50260 +#ifdef CONFIG_GRKERNSEC_PROC_USER
50261 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
50262 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50263 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
50264 +#endif
50265 +#else
50266 proc_mkdir("bus", NULL);
50267 +#endif
50268 proc_sys_init();
50269 }
50270
50271 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
50272 index 4540b8f..1b9772f 100644
50273 --- a/fs/proc/task_mmu.c
50274 +++ b/fs/proc/task_mmu.c
50275 @@ -11,12 +11,19 @@
50276 #include <linux/rmap.h>
50277 #include <linux/swap.h>
50278 #include <linux/swapops.h>
50279 +#include <linux/grsecurity.h>
50280
50281 #include <asm/elf.h>
50282 #include <asm/uaccess.h>
50283 #include <asm/tlbflush.h>
50284 #include "internal.h"
50285
50286 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50287 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
50288 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
50289 + _mm->pax_flags & MF_PAX_SEGMEXEC))
50290 +#endif
50291 +
50292 void task_mem(struct seq_file *m, struct mm_struct *mm)
50293 {
50294 unsigned long data, text, lib, swap;
50295 @@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
50296 "VmExe:\t%8lu kB\n"
50297 "VmLib:\t%8lu kB\n"
50298 "VmPTE:\t%8lu kB\n"
50299 - "VmSwap:\t%8lu kB\n",
50300 - hiwater_vm << (PAGE_SHIFT-10),
50301 + "VmSwap:\t%8lu kB\n"
50302 +
50303 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
50304 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
50305 +#endif
50306 +
50307 + ,hiwater_vm << (PAGE_SHIFT-10),
50308 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
50309 mm->locked_vm << (PAGE_SHIFT-10),
50310 mm->pinned_vm << (PAGE_SHIFT-10),
50311 @@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
50312 data << (PAGE_SHIFT-10),
50313 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
50314 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
50315 - swap << (PAGE_SHIFT-10));
50316 + swap << (PAGE_SHIFT-10)
50317 +
50318 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
50319 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50320 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
50321 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
50322 +#else
50323 + , mm->context.user_cs_base
50324 + , mm->context.user_cs_limit
50325 +#endif
50326 +#endif
50327 +
50328 + );
50329 }
50330
50331 unsigned long task_vsize(struct mm_struct *mm)
50332 @@ -231,13 +255,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
50333 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
50334 }
50335
50336 - /* We don't show the stack guard page in /proc/maps */
50337 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50338 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
50339 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
50340 +#else
50341 start = vma->vm_start;
50342 - if (stack_guard_page_start(vma, start))
50343 - start += PAGE_SIZE;
50344 end = vma->vm_end;
50345 - if (stack_guard_page_end(vma, end))
50346 - end -= PAGE_SIZE;
50347 +#endif
50348
50349 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
50350 start,
50351 @@ -246,7 +270,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
50352 flags & VM_WRITE ? 'w' : '-',
50353 flags & VM_EXEC ? 'x' : '-',
50354 flags & VM_MAYSHARE ? 's' : 'p',
50355 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50356 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
50357 +#else
50358 pgoff,
50359 +#endif
50360 MAJOR(dev), MINOR(dev), ino, &len);
50361
50362 /*
50363 @@ -255,7 +283,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
50364 */
50365 if (file) {
50366 pad_len_spaces(m, len);
50367 - seq_path(m, &file->f_path, "\n");
50368 + seq_path(m, &file->f_path, "\n\\");
50369 goto done;
50370 }
50371
50372 @@ -281,8 +309,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
50373 * Thread stack in /proc/PID/task/TID/maps or
50374 * the main process stack.
50375 */
50376 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
50377 - vma->vm_end >= mm->start_stack)) {
50378 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
50379 + (vma->vm_start <= mm->start_stack &&
50380 + vma->vm_end >= mm->start_stack)) {
50381 name = "[stack]";
50382 } else {
50383 /* Thread stack in /proc/PID/maps */
50384 @@ -306,6 +335,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
50385 struct proc_maps_private *priv = m->private;
50386 struct task_struct *task = priv->task;
50387
50388 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50389 + if (current->exec_id != m->exec_id) {
50390 + gr_log_badprocpid("maps");
50391 + return 0;
50392 + }
50393 +#endif
50394 +
50395 show_map_vma(m, vma, is_pid);
50396
50397 if (m->count < m->size) /* vma is copied successfully */
50398 @@ -492,12 +528,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
50399 .private = &mss,
50400 };
50401
50402 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50403 + if (current->exec_id != m->exec_id) {
50404 + gr_log_badprocpid("smaps");
50405 + return 0;
50406 + }
50407 +#endif
50408 memset(&mss, 0, sizeof mss);
50409 - mss.vma = vma;
50410 - /* mmap_sem is held in m_start */
50411 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
50412 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
50413 -
50414 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50415 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
50416 +#endif
50417 + mss.vma = vma;
50418 + /* mmap_sem is held in m_start */
50419 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
50420 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
50421 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50422 + }
50423 +#endif
50424 show_map_vma(m, vma, is_pid);
50425
50426 seq_printf(m,
50427 @@ -515,7 +562,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
50428 "KernelPageSize: %8lu kB\n"
50429 "MMUPageSize: %8lu kB\n"
50430 "Locked: %8lu kB\n",
50431 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50432 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
50433 +#else
50434 (vma->vm_end - vma->vm_start) >> 10,
50435 +#endif
50436 mss.resident >> 10,
50437 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
50438 mss.shared_clean >> 10,
50439 @@ -1164,6 +1215,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
50440 int n;
50441 char buffer[50];
50442
50443 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50444 + if (current->exec_id != m->exec_id) {
50445 + gr_log_badprocpid("numa_maps");
50446 + return 0;
50447 + }
50448 +#endif
50449 +
50450 if (!mm)
50451 return 0;
50452
50453 @@ -1181,11 +1239,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
50454 mpol_to_str(buffer, sizeof(buffer), pol, 0);
50455 mpol_cond_put(pol);
50456
50457 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50458 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
50459 +#else
50460 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
50461 +#endif
50462
50463 if (file) {
50464 seq_printf(m, " file=");
50465 - seq_path(m, &file->f_path, "\n\t= ");
50466 + seq_path(m, &file->f_path, "\n\t\\= ");
50467 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
50468 seq_printf(m, " heap");
50469 } else {
50470 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
50471 index 1ccfa53..0848f95 100644
50472 --- a/fs/proc/task_nommu.c
50473 +++ b/fs/proc/task_nommu.c
50474 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
50475 else
50476 bytes += kobjsize(mm);
50477
50478 - if (current->fs && current->fs->users > 1)
50479 + if (current->fs && atomic_read(&current->fs->users) > 1)
50480 sbytes += kobjsize(current->fs);
50481 else
50482 bytes += kobjsize(current->fs);
50483 @@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
50484
50485 if (file) {
50486 pad_len_spaces(m, len);
50487 - seq_path(m, &file->f_path, "");
50488 + seq_path(m, &file->f_path, "\n\\");
50489 } else if (mm) {
50490 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
50491
50492 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
50493 index d67908b..d13f6a6 100644
50494 --- a/fs/quota/netlink.c
50495 +++ b/fs/quota/netlink.c
50496 @@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
50497 void quota_send_warning(short type, unsigned int id, dev_t dev,
50498 const char warntype)
50499 {
50500 - static atomic_t seq;
50501 + static atomic_unchecked_t seq;
50502 struct sk_buff *skb;
50503 void *msg_head;
50504 int ret;
50505 @@ -49,7 +49,7 @@ void quota_send_warning(short type, unsigned int id, dev_t dev,
50506 "VFS: Not enough memory to send quota warning.\n");
50507 return;
50508 }
50509 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
50510 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
50511 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
50512 if (!msg_head) {
50513 printk(KERN_ERR
50514 diff --git a/fs/readdir.c b/fs/readdir.c
50515 index 39e3370..20d446d 100644
50516 --- a/fs/readdir.c
50517 +++ b/fs/readdir.c
50518 @@ -17,6 +17,7 @@
50519 #include <linux/security.h>
50520 #include <linux/syscalls.h>
50521 #include <linux/unistd.h>
50522 +#include <linux/namei.h>
50523
50524 #include <asm/uaccess.h>
50525
50526 @@ -67,6 +68,7 @@ struct old_linux_dirent {
50527
50528 struct readdir_callback {
50529 struct old_linux_dirent __user * dirent;
50530 + struct file * file;
50531 int result;
50532 };
50533
50534 @@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
50535 buf->result = -EOVERFLOW;
50536 return -EOVERFLOW;
50537 }
50538 +
50539 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50540 + return 0;
50541 +
50542 buf->result++;
50543 dirent = buf->dirent;
50544 if (!access_ok(VERIFY_WRITE, dirent,
50545 @@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
50546
50547 buf.result = 0;
50548 buf.dirent = dirent;
50549 + buf.file = file;
50550
50551 error = vfs_readdir(file, fillonedir, &buf);
50552 if (buf.result)
50553 @@ -141,6 +148,7 @@ struct linux_dirent {
50554 struct getdents_callback {
50555 struct linux_dirent __user * current_dir;
50556 struct linux_dirent __user * previous;
50557 + struct file * file;
50558 int count;
50559 int error;
50560 };
50561 @@ -162,6 +170,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
50562 buf->error = -EOVERFLOW;
50563 return -EOVERFLOW;
50564 }
50565 +
50566 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50567 + return 0;
50568 +
50569 dirent = buf->previous;
50570 if (dirent) {
50571 if (__put_user(offset, &dirent->d_off))
50572 @@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
50573 buf.previous = NULL;
50574 buf.count = count;
50575 buf.error = 0;
50576 + buf.file = file;
50577
50578 error = vfs_readdir(file, filldir, &buf);
50579 if (error >= 0)
50580 @@ -226,6 +239,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
50581 struct getdents_callback64 {
50582 struct linux_dirent64 __user * current_dir;
50583 struct linux_dirent64 __user * previous;
50584 + struct file *file;
50585 int count;
50586 int error;
50587 };
50588 @@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
50589 buf->error = -EINVAL; /* only used if we fail.. */
50590 if (reclen > buf->count)
50591 return -EINVAL;
50592 +
50593 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50594 + return 0;
50595 +
50596 dirent = buf->previous;
50597 if (dirent) {
50598 if (__put_user(offset, &dirent->d_off))
50599 @@ -287,6 +305,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
50600
50601 buf.current_dir = dirent;
50602 buf.previous = NULL;
50603 + buf.file = file;
50604 buf.count = count;
50605 buf.error = 0;
50606
50607 @@ -295,7 +314,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
50608 error = buf.error;
50609 lastdirent = buf.previous;
50610 if (lastdirent) {
50611 - typeof(lastdirent->d_off) d_off = file->f_pos;
50612 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
50613 if (__put_user(d_off, &lastdirent->d_off))
50614 error = -EFAULT;
50615 else
50616 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
50617 index 2b7882b..1c5ef48 100644
50618 --- a/fs/reiserfs/do_balan.c
50619 +++ b/fs/reiserfs/do_balan.c
50620 @@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
50621 return;
50622 }
50623
50624 - atomic_inc(&(fs_generation(tb->tb_sb)));
50625 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
50626 do_balance_starts(tb);
50627
50628 /* balance leaf returns 0 except if combining L R and S into
50629 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
50630 index e60e870..f40ac16 100644
50631 --- a/fs/reiserfs/procfs.c
50632 +++ b/fs/reiserfs/procfs.c
50633 @@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
50634 "SMALL_TAILS " : "NO_TAILS ",
50635 replay_only(sb) ? "REPLAY_ONLY " : "",
50636 convert_reiserfs(sb) ? "CONV " : "",
50637 - atomic_read(&r->s_generation_counter),
50638 + atomic_read_unchecked(&r->s_generation_counter),
50639 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
50640 SF(s_do_balance), SF(s_unneeded_left_neighbor),
50641 SF(s_good_search_by_key_reada), SF(s_bmaps),
50642 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
50643 index 33215f5..c5d427a 100644
50644 --- a/fs/reiserfs/reiserfs.h
50645 +++ b/fs/reiserfs/reiserfs.h
50646 @@ -453,7 +453,7 @@ struct reiserfs_sb_info {
50647 /* Comment? -Hans */
50648 wait_queue_head_t s_wait;
50649 /* To be obsoleted soon by per buffer seals.. -Hans */
50650 - atomic_t s_generation_counter; // increased by one every time the
50651 + atomic_unchecked_t s_generation_counter; // increased by one every time the
50652 // tree gets re-balanced
50653 unsigned long s_properties; /* File system properties. Currently holds
50654 on-disk FS format */
50655 @@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
50656 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
50657
50658 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
50659 -#define get_generation(s) atomic_read (&fs_generation(s))
50660 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
50661 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
50662 #define __fs_changed(gen,s) (gen != get_generation (s))
50663 #define fs_changed(gen,s) \
50664 diff --git a/fs/select.c b/fs/select.c
50665 index db14c78..3aae1bd 100644
50666 --- a/fs/select.c
50667 +++ b/fs/select.c
50668 @@ -20,6 +20,7 @@
50669 #include <linux/export.h>
50670 #include <linux/slab.h>
50671 #include <linux/poll.h>
50672 +#include <linux/security.h>
50673 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
50674 #include <linux/file.h>
50675 #include <linux/fdtable.h>
50676 @@ -831,6 +832,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
50677 struct poll_list *walk = head;
50678 unsigned long todo = nfds;
50679
50680 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
50681 if (nfds > rlimit(RLIMIT_NOFILE))
50682 return -EINVAL;
50683
50684 diff --git a/fs/seq_file.c b/fs/seq_file.c
50685 index 14cf9de..adc4d5b 100644
50686 --- a/fs/seq_file.c
50687 +++ b/fs/seq_file.c
50688 @@ -9,6 +9,7 @@
50689 #include <linux/export.h>
50690 #include <linux/seq_file.h>
50691 #include <linux/slab.h>
50692 +#include <linux/sched.h>
50693
50694 #include <asm/uaccess.h>
50695 #include <asm/page.h>
50696 @@ -56,6 +57,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
50697 memset(p, 0, sizeof(*p));
50698 mutex_init(&p->lock);
50699 p->op = op;
50700 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50701 + p->exec_id = current->exec_id;
50702 +#endif
50703
50704 /*
50705 * Wrappers around seq_open(e.g. swaps_open) need to be
50706 @@ -92,7 +96,7 @@ static int traverse(struct seq_file *m, loff_t offset)
50707 return 0;
50708 }
50709 if (!m->buf) {
50710 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
50711 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
50712 if (!m->buf)
50713 return -ENOMEM;
50714 }
50715 @@ -132,7 +136,7 @@ static int traverse(struct seq_file *m, loff_t offset)
50716 Eoverflow:
50717 m->op->stop(m, p);
50718 kfree(m->buf);
50719 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
50720 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
50721 return !m->buf ? -ENOMEM : -EAGAIN;
50722 }
50723
50724 @@ -187,7 +191,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
50725
50726 /* grab buffer if we didn't have one */
50727 if (!m->buf) {
50728 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
50729 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
50730 if (!m->buf)
50731 goto Enomem;
50732 }
50733 @@ -228,7 +232,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
50734 goto Fill;
50735 m->op->stop(m, p);
50736 kfree(m->buf);
50737 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
50738 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
50739 if (!m->buf)
50740 goto Enomem;
50741 m->count = 0;
50742 @@ -577,7 +581,7 @@ static void single_stop(struct seq_file *p, void *v)
50743 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
50744 void *data)
50745 {
50746 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
50747 + seq_operations_no_const *op = kmalloc(sizeof(*op), GFP_KERNEL);
50748 int res = -ENOMEM;
50749
50750 if (op) {
50751 diff --git a/fs/splice.c b/fs/splice.c
50752 index 41514dd..6564a93 100644
50753 --- a/fs/splice.c
50754 +++ b/fs/splice.c
50755 @@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
50756 pipe_lock(pipe);
50757
50758 for (;;) {
50759 - if (!pipe->readers) {
50760 + if (!atomic_read(&pipe->readers)) {
50761 send_sig(SIGPIPE, current, 0);
50762 if (!ret)
50763 ret = -EPIPE;
50764 @@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
50765 do_wakeup = 0;
50766 }
50767
50768 - pipe->waiting_writers++;
50769 + atomic_inc(&pipe->waiting_writers);
50770 pipe_wait(pipe);
50771 - pipe->waiting_writers--;
50772 + atomic_dec(&pipe->waiting_writers);
50773 }
50774
50775 pipe_unlock(pipe);
50776 @@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
50777 old_fs = get_fs();
50778 set_fs(get_ds());
50779 /* The cast to a user pointer is valid due to the set_fs() */
50780 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
50781 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
50782 set_fs(old_fs);
50783
50784 return res;
50785 @@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
50786 old_fs = get_fs();
50787 set_fs(get_ds());
50788 /* The cast to a user pointer is valid due to the set_fs() */
50789 - res = vfs_write(file, (const char __user *)buf, count, &pos);
50790 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
50791 set_fs(old_fs);
50792
50793 return res;
50794 @@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
50795 goto err;
50796
50797 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
50798 - vec[i].iov_base = (void __user *) page_address(page);
50799 + vec[i].iov_base = (void __force_user *) page_address(page);
50800 vec[i].iov_len = this_len;
50801 spd.pages[i] = page;
50802 spd.nr_pages++;
50803 @@ -849,10 +849,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
50804 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
50805 {
50806 while (!pipe->nrbufs) {
50807 - if (!pipe->writers)
50808 + if (!atomic_read(&pipe->writers))
50809 return 0;
50810
50811 - if (!pipe->waiting_writers && sd->num_spliced)
50812 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
50813 return 0;
50814
50815 if (sd->flags & SPLICE_F_NONBLOCK)
50816 @@ -1190,7 +1190,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
50817 * out of the pipe right after the splice_to_pipe(). So set
50818 * PIPE_READERS appropriately.
50819 */
50820 - pipe->readers = 1;
50821 + atomic_set(&pipe->readers, 1);
50822
50823 current->splice_pipe = pipe;
50824 }
50825 @@ -1743,9 +1743,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50826 ret = -ERESTARTSYS;
50827 break;
50828 }
50829 - if (!pipe->writers)
50830 + if (!atomic_read(&pipe->writers))
50831 break;
50832 - if (!pipe->waiting_writers) {
50833 + if (!atomic_read(&pipe->waiting_writers)) {
50834 if (flags & SPLICE_F_NONBLOCK) {
50835 ret = -EAGAIN;
50836 break;
50837 @@ -1777,7 +1777,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50838 pipe_lock(pipe);
50839
50840 while (pipe->nrbufs >= pipe->buffers) {
50841 - if (!pipe->readers) {
50842 + if (!atomic_read(&pipe->readers)) {
50843 send_sig(SIGPIPE, current, 0);
50844 ret = -EPIPE;
50845 break;
50846 @@ -1790,9 +1790,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50847 ret = -ERESTARTSYS;
50848 break;
50849 }
50850 - pipe->waiting_writers++;
50851 + atomic_inc(&pipe->waiting_writers);
50852 pipe_wait(pipe);
50853 - pipe->waiting_writers--;
50854 + atomic_dec(&pipe->waiting_writers);
50855 }
50856
50857 pipe_unlock(pipe);
50858 @@ -1828,14 +1828,14 @@ retry:
50859 pipe_double_lock(ipipe, opipe);
50860
50861 do {
50862 - if (!opipe->readers) {
50863 + if (!atomic_read(&opipe->readers)) {
50864 send_sig(SIGPIPE, current, 0);
50865 if (!ret)
50866 ret = -EPIPE;
50867 break;
50868 }
50869
50870 - if (!ipipe->nrbufs && !ipipe->writers)
50871 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
50872 break;
50873
50874 /*
50875 @@ -1932,7 +1932,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
50876 pipe_double_lock(ipipe, opipe);
50877
50878 do {
50879 - if (!opipe->readers) {
50880 + if (!atomic_read(&opipe->readers)) {
50881 send_sig(SIGPIPE, current, 0);
50882 if (!ret)
50883 ret = -EPIPE;
50884 @@ -1977,7 +1977,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
50885 * return EAGAIN if we have the potential of some data in the
50886 * future, otherwise just return 0
50887 */
50888 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
50889 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
50890 ret = -EAGAIN;
50891
50892 pipe_unlock(ipipe);
50893 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
50894 index 2fbdff6..5530a61 100644
50895 --- a/fs/sysfs/dir.c
50896 +++ b/fs/sysfs/dir.c
50897 @@ -685,6 +685,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
50898 struct sysfs_dirent *sd;
50899 int rc;
50900
50901 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
50902 + const char *parent_name = parent_sd->s_name;
50903 +
50904 + mode = S_IFDIR | S_IRWXU;
50905 +
50906 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
50907 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
50908 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
50909 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
50910 + mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
50911 +#endif
50912 +
50913 /* allocate */
50914 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
50915 if (!sd)
50916 diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
50917 index 00012e3..8392349 100644
50918 --- a/fs/sysfs/file.c
50919 +++ b/fs/sysfs/file.c
50920 @@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
50921
50922 struct sysfs_open_dirent {
50923 atomic_t refcnt;
50924 - atomic_t event;
50925 + atomic_unchecked_t event;
50926 wait_queue_head_t poll;
50927 struct list_head buffers; /* goes through sysfs_buffer.list */
50928 };
50929 @@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
50930 if (!sysfs_get_active(attr_sd))
50931 return -ENODEV;
50932
50933 - buffer->event = atomic_read(&attr_sd->s_attr.open->event);
50934 + buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
50935 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
50936
50937 sysfs_put_active(attr_sd);
50938 @@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
50939 return -ENOMEM;
50940
50941 atomic_set(&new_od->refcnt, 0);
50942 - atomic_set(&new_od->event, 1);
50943 + atomic_set_unchecked(&new_od->event, 1);
50944 init_waitqueue_head(&new_od->poll);
50945 INIT_LIST_HEAD(&new_od->buffers);
50946 goto retry;
50947 @@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
50948
50949 sysfs_put_active(attr_sd);
50950
50951 - if (buffer->event != atomic_read(&od->event))
50952 + if (buffer->event != atomic_read_unchecked(&od->event))
50953 goto trigger;
50954
50955 return DEFAULT_POLLMASK;
50956 @@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
50957
50958 od = sd->s_attr.open;
50959 if (od) {
50960 - atomic_inc(&od->event);
50961 + atomic_inc_unchecked(&od->event);
50962 wake_up_interruptible(&od->poll);
50963 }
50964
50965 diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
50966 index a7ac78f..02158e1 100644
50967 --- a/fs/sysfs/symlink.c
50968 +++ b/fs/sysfs/symlink.c
50969 @@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
50970
50971 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
50972 {
50973 - char *page = nd_get_link(nd);
50974 + const char *page = nd_get_link(nd);
50975 if (!IS_ERR(page))
50976 free_page((unsigned long)page);
50977 }
50978 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
50979 index c175b4d..8f36a16 100644
50980 --- a/fs/udf/misc.c
50981 +++ b/fs/udf/misc.c
50982 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
50983
50984 u8 udf_tag_checksum(const struct tag *t)
50985 {
50986 - u8 *data = (u8 *)t;
50987 + const u8 *data = (const u8 *)t;
50988 u8 checksum = 0;
50989 int i;
50990 for (i = 0; i < sizeof(struct tag); ++i)
50991 diff --git a/fs/utimes.c b/fs/utimes.c
50992 index fa4dbe4..e12d1b9 100644
50993 --- a/fs/utimes.c
50994 +++ b/fs/utimes.c
50995 @@ -1,6 +1,7 @@
50996 #include <linux/compiler.h>
50997 #include <linux/file.h>
50998 #include <linux/fs.h>
50999 +#include <linux/security.h>
51000 #include <linux/linkage.h>
51001 #include <linux/mount.h>
51002 #include <linux/namei.h>
51003 @@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
51004 goto mnt_drop_write_and_out;
51005 }
51006 }
51007 +
51008 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
51009 + error = -EACCES;
51010 + goto mnt_drop_write_and_out;
51011 + }
51012 +
51013 mutex_lock(&inode->i_mutex);
51014 error = notify_change(path->dentry, &newattrs);
51015 mutex_unlock(&inode->i_mutex);
51016 diff --git a/fs/xattr.c b/fs/xattr.c
51017 index 4d45b71..2ec08e10 100644
51018 --- a/fs/xattr.c
51019 +++ b/fs/xattr.c
51020 @@ -316,7 +316,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
51021 * Extended attribute SET operations
51022 */
51023 static long
51024 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
51025 +setxattr(struct path *path, const char __user *name, const void __user *value,
51026 size_t size, int flags)
51027 {
51028 int error;
51029 @@ -349,7 +349,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
51030 }
51031 }
51032
51033 - error = vfs_setxattr(d, kname, kvalue, size, flags);
51034 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
51035 + error = -EACCES;
51036 + goto out;
51037 + }
51038 +
51039 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
51040 out:
51041 if (vvalue)
51042 vfree(vvalue);
51043 @@ -370,7 +375,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
51044 return error;
51045 error = mnt_want_write(path.mnt);
51046 if (!error) {
51047 - error = setxattr(path.dentry, name, value, size, flags);
51048 + error = setxattr(&path, name, value, size, flags);
51049 mnt_drop_write(path.mnt);
51050 }
51051 path_put(&path);
51052 @@ -389,7 +394,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
51053 return error;
51054 error = mnt_want_write(path.mnt);
51055 if (!error) {
51056 - error = setxattr(path.dentry, name, value, size, flags);
51057 + error = setxattr(&path, name, value, size, flags);
51058 mnt_drop_write(path.mnt);
51059 }
51060 path_put(&path);
51061 @@ -401,17 +406,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
51062 {
51063 int fput_needed;
51064 struct file *f;
51065 - struct dentry *dentry;
51066 int error = -EBADF;
51067
51068 f = fget_light(fd, &fput_needed);
51069 if (!f)
51070 return error;
51071 - dentry = f->f_path.dentry;
51072 - audit_inode(NULL, dentry);
51073 + audit_inode(NULL, f->f_path.dentry);
51074 error = mnt_want_write_file(f);
51075 if (!error) {
51076 - error = setxattr(dentry, name, value, size, flags);
51077 + error = setxattr(&f->f_path, name, value, size, flags);
51078 mnt_drop_write_file(f);
51079 }
51080 fput_light(f, fput_needed);
51081 diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
51082 index 69d06b0..c0996e5 100644
51083 --- a/fs/xattr_acl.c
51084 +++ b/fs/xattr_acl.c
51085 @@ -17,8 +17,8 @@
51086 struct posix_acl *
51087 posix_acl_from_xattr(const void *value, size_t size)
51088 {
51089 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
51090 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
51091 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
51092 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
51093 int count;
51094 struct posix_acl *acl;
51095 struct posix_acl_entry *acl_e;
51096 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
51097 index 848ffa7..1f249bf 100644
51098 --- a/fs/xfs/xfs_bmap.c
51099 +++ b/fs/xfs/xfs_bmap.c
51100 @@ -189,7 +189,7 @@ xfs_bmap_validate_ret(
51101 int nmap,
51102 int ret_nmap);
51103 #else
51104 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
51105 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
51106 #endif /* DEBUG */
51107
51108 STATIC int
51109 diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
51110 index 1b9fc3e..e1bdde0 100644
51111 --- a/fs/xfs/xfs_dir2_sf.c
51112 +++ b/fs/xfs/xfs_dir2_sf.c
51113 @@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
51114 }
51115
51116 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
51117 - if (filldir(dirent, (char *)sfep->name, sfep->namelen,
51118 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
51119 + char name[sfep->namelen];
51120 + memcpy(name, sfep->name, sfep->namelen);
51121 + if (filldir(dirent, name, sfep->namelen,
51122 + off & 0x7fffffff, ino, DT_UNKNOWN)) {
51123 + *offset = off & 0x7fffffff;
51124 + return 0;
51125 + }
51126 + } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
51127 off & 0x7fffffff, ino, DT_UNKNOWN)) {
51128 *offset = off & 0x7fffffff;
51129 return 0;
51130 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
51131 index 0e0232c..fa5c3fe 100644
51132 --- a/fs/xfs/xfs_ioctl.c
51133 +++ b/fs/xfs/xfs_ioctl.c
51134 @@ -126,7 +126,7 @@ xfs_find_handle(
51135 }
51136
51137 error = -EFAULT;
51138 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
51139 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
51140 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
51141 goto out_put;
51142
51143 diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
51144 index 4e00cf0..3374374 100644
51145 --- a/fs/xfs/xfs_iops.c
51146 +++ b/fs/xfs/xfs_iops.c
51147 @@ -394,7 +394,7 @@ xfs_vn_put_link(
51148 struct nameidata *nd,
51149 void *p)
51150 {
51151 - char *s = nd_get_link(nd);
51152 + const char *s = nd_get_link(nd);
51153
51154 if (!IS_ERR(s))
51155 kfree(s);
51156 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
51157 new file mode 100644
51158 index 0000000..10c36fb
51159 --- /dev/null
51160 +++ b/grsecurity/Kconfig
51161 @@ -0,0 +1,964 @@
51162 +#
51163 +# grecurity configuration
51164 +#
51165 +menu "Memory Protections"
51166 +depends on GRKERNSEC
51167 +
51168 +config GRKERNSEC_KMEM
51169 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
51170 + default y if GRKERNSEC_CONFIG_AUTO
51171 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
51172 + help
51173 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
51174 + be written to or read from to modify or leak the contents of the running
51175 + kernel. /dev/port will also not be allowed to be opened. If you have module
51176 + support disabled, enabling this will close up four ways that are
51177 + currently used to insert malicious code into the running kernel.
51178 + Even with all these features enabled, we still highly recommend that
51179 + you use the RBAC system, as it is still possible for an attacker to
51180 + modify the running kernel through privileged I/O granted by ioperm/iopl.
51181 + If you are not using XFree86, you may be able to stop this additional
51182 + case by enabling the 'Disable privileged I/O' option. Though nothing
51183 + legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
51184 + but only to video memory, which is the only writing we allow in this
51185 + case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
51186 + not be allowed to mprotect it with PROT_WRITE later.
51187 + It is highly recommended that you say Y here if you meet all the
51188 + conditions above.
51189 +
51190 +config GRKERNSEC_VM86
51191 + bool "Restrict VM86 mode"
51192 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
51193 + depends on X86_32
51194 +
51195 + help
51196 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
51197 + make use of a special execution mode on 32bit x86 processors called
51198 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
51199 + video cards and will still work with this option enabled. The purpose
51200 + of the option is to prevent exploitation of emulation errors in
51201 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
51202 + Nearly all users should be able to enable this option.
51203 +
51204 +config GRKERNSEC_IO
51205 + bool "Disable privileged I/O"
51206 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
51207 + depends on X86
51208 + select RTC_CLASS
51209 + select RTC_INTF_DEV
51210 + select RTC_DRV_CMOS
51211 +
51212 + help
51213 + If you say Y here, all ioperm and iopl calls will return an error.
51214 + Ioperm and iopl can be used to modify the running kernel.
51215 + Unfortunately, some programs need this access to operate properly,
51216 + the most notable of which are XFree86 and hwclock. hwclock can be
51217 + remedied by having RTC support in the kernel, so real-time
51218 + clock support is enabled if this option is enabled, to ensure
51219 + that hwclock operates correctly. XFree86 still will not
51220 + operate correctly with this option enabled, so DO NOT CHOOSE Y
51221 + IF YOU USE XFree86. If you use XFree86 and you still want to
51222 + protect your kernel against modification, use the RBAC system.
51223 +
51224 +config GRKERNSEC_JIT_HARDEN
51225 + bool "Harden BPF JIT against spray attacks"
51226 + default y if GRKERNSEC_CONFIG_AUTO
51227 + depends on BPF_JIT
51228 + help
51229 + If you say Y here, the native code generated by the kernel's Berkeley
51230 + Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
51231 + attacks that attempt to fit attacker-beneficial instructions in
51232 + 32bit immediate fields of JIT-generated native instructions. The
51233 + attacker will generally aim to cause an unintended instruction sequence
51234 + of JIT-generated native code to execute by jumping into the middle of
51235 + a generated instruction. This feature effectively randomizes the 32bit
51236 + immediate constants present in the generated code to thwart such attacks.
51237 +
51238 + If you're using KERNEXEC, it's recommended that you enable this option
51239 + to supplement the hardening of the kernel.
51240 +
51241 +config GRKERNSEC_PROC_MEMMAP
51242 + bool "Harden ASLR against information leaks and entropy reduction"
51243 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
51244 + depends on PAX_NOEXEC || PAX_ASLR
51245 + help
51246 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
51247 + give no information about the addresses of its mappings if
51248 + PaX features that rely on random addresses are enabled on the task.
51249 + In addition to sanitizing this information and disabling other
51250 + dangerous sources of information, this option causes reads of sensitive
51251 + /proc/<pid> entries where the file descriptor was opened in a different
51252 + task than the one performing the read. Such attempts are logged.
51253 + This option also limits argv/env strings for suid/sgid binaries
51254 + to 512KB to prevent a complete exhaustion of the stack entropy provided
51255 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
51256 + binaries to prevent alternative mmap layouts from being abused.
51257 +
51258 + If you use PaX it is essential that you say Y here as it closes up
51259 + several holes that make full ASLR useless locally.
51260 +
51261 +config GRKERNSEC_BRUTE
51262 + bool "Deter exploit bruteforcing"
51263 + default y if GRKERNSEC_CONFIG_AUTO
51264 + help
51265 + If you say Y here, attempts to bruteforce exploits against forking
51266 + daemons such as apache or sshd, as well as against suid/sgid binaries
51267 + will be deterred. When a child of a forking daemon is killed by PaX
51268 + or crashes due to an illegal instruction or other suspicious signal,
51269 + the parent process will be delayed 30 seconds upon every subsequent
51270 + fork until the administrator is able to assess the situation and
51271 + restart the daemon.
51272 + In the suid/sgid case, the attempt is logged, the user has all their
51273 + processes terminated, and they are prevented from executing any further
51274 + processes for 15 minutes.
51275 + It is recommended that you also enable signal logging in the auditing
51276 + section so that logs are generated when a process triggers a suspicious
51277 + signal.
51278 + If the sysctl option is enabled, a sysctl option with name
51279 + "deter_bruteforce" is created.
51280 +
51281 +
51282 +config GRKERNSEC_MODHARDEN
51283 + bool "Harden module auto-loading"
51284 + default y if GRKERNSEC_CONFIG_AUTO
51285 + depends on MODULES
51286 + help
51287 + If you say Y here, module auto-loading in response to use of some
51288 + feature implemented by an unloaded module will be restricted to
51289 + root users. Enabling this option helps defend against attacks
51290 + by unprivileged users who abuse the auto-loading behavior to
51291 + cause a vulnerable module to load that is then exploited.
51292 +
51293 + If this option prevents a legitimate use of auto-loading for a
51294 + non-root user, the administrator can execute modprobe manually
51295 + with the exact name of the module mentioned in the alert log.
51296 + Alternatively, the administrator can add the module to the list
51297 + of modules loaded at boot by modifying init scripts.
51298 +
51299 + Modification of init scripts will most likely be needed on
51300 + Ubuntu servers with encrypted home directory support enabled,
51301 + as the first non-root user logging in will cause the ecb(aes),
51302 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
51303 +
51304 +config GRKERNSEC_HIDESYM
51305 + bool "Hide kernel symbols"
51306 + default y if GRKERNSEC_CONFIG_AUTO
51307 + select PAX_USERCOPY_SLABS
51308 + help
51309 + If you say Y here, getting information on loaded modules, and
51310 + displaying all kernel symbols through a syscall will be restricted
51311 + to users with CAP_SYS_MODULE. For software compatibility reasons,
51312 + /proc/kallsyms will be restricted to the root user. The RBAC
51313 + system can hide that entry even from root.
51314 +
51315 + This option also prevents leaking of kernel addresses through
51316 + several /proc entries.
51317 +
51318 + Note that this option is only effective provided the following
51319 + conditions are met:
51320 + 1) The kernel using grsecurity is not precompiled by some distribution
51321 + 2) You have also enabled GRKERNSEC_DMESG
51322 + 3) You are using the RBAC system and hiding other files such as your
51323 + kernel image and System.map. Alternatively, enabling this option
51324 + causes the permissions on /boot, /lib/modules, and the kernel
51325 + source directory to change at compile time to prevent
51326 + reading by non-root users.
51327 + If the above conditions are met, this option will aid in providing a
51328 + useful protection against local kernel exploitation of overflows
51329 + and arbitrary read/write vulnerabilities.
51330 +
51331 +config GRKERNSEC_KERN_LOCKOUT
51332 + bool "Active kernel exploit response"
51333 + default y if GRKERNSEC_CONFIG_AUTO
51334 + depends on X86 || ARM || PPC || SPARC
51335 + help
51336 + If you say Y here, when a PaX alert is triggered due to suspicious
51337 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
51338 + or an OOPS occurs due to bad memory accesses, instead of just
51339 + terminating the offending process (and potentially allowing
51340 + a subsequent exploit from the same user), we will take one of two
51341 + actions:
51342 + If the user was root, we will panic the system
51343 + If the user was non-root, we will log the attempt, terminate
51344 + all processes owned by the user, then prevent them from creating
51345 + any new processes until the system is restarted
51346 + This deters repeated kernel exploitation/bruteforcing attempts
51347 + and is useful for later forensics.
51348 +
51349 +endmenu
51350 +menu "Role Based Access Control Options"
51351 +depends on GRKERNSEC
51352 +
51353 +config GRKERNSEC_RBAC_DEBUG
51354 + bool
51355 +
51356 +config GRKERNSEC_NO_RBAC
51357 + bool "Disable RBAC system"
51358 + help
51359 + If you say Y here, the /dev/grsec device will be removed from the kernel,
51360 + preventing the RBAC system from being enabled. You should only say Y
51361 + here if you have no intention of using the RBAC system, so as to prevent
51362 + an attacker with root access from misusing the RBAC system to hide files
51363 + and processes when loadable module support and /dev/[k]mem have been
51364 + locked down.
51365 +
51366 +config GRKERNSEC_ACL_HIDEKERN
51367 + bool "Hide kernel processes"
51368 + help
51369 + If you say Y here, all kernel threads will be hidden to all
51370 + processes but those whose subject has the "view hidden processes"
51371 + flag.
51372 +
51373 +config GRKERNSEC_ACL_MAXTRIES
51374 + int "Maximum tries before password lockout"
51375 + default 3
51376 + help
51377 + This option enforces the maximum number of times a user can attempt
51378 + to authorize themselves with the grsecurity RBAC system before being
51379 + denied the ability to attempt authorization again for a specified time.
51380 + The lower the number, the harder it will be to brute-force a password.
51381 +
51382 +config GRKERNSEC_ACL_TIMEOUT
51383 + int "Time to wait after max password tries, in seconds"
51384 + default 30
51385 + help
51386 + This option specifies the time the user must wait after attempting to
51387 + authorize to the RBAC system with the maximum number of invalid
51388 + passwords. The higher the number, the harder it will be to brute-force
51389 + a password.
51390 +
51391 +endmenu
51392 +menu "Filesystem Protections"
51393 +depends on GRKERNSEC
51394 +
51395 +config GRKERNSEC_PROC
51396 + bool "Proc restrictions"
51397 + default y if GRKERNSEC_CONFIG_AUTO
51398 + help
51399 + If you say Y here, the permissions of the /proc filesystem
51400 + will be altered to enhance system security and privacy. You MUST
51401 + choose either a user only restriction or a user and group restriction.
51402 + Depending upon the option you choose, you can either restrict users to
51403 + see only the processes they themselves run, or choose a group that can
51404 + view all processes and files normally restricted to root if you choose
51405 + the "restrict to user only" option. NOTE: If you're running identd or
51406 + ntpd as a non-root user, you will have to run it as the group you
51407 + specify here.
51408 +
51409 +config GRKERNSEC_PROC_USER
51410 + bool "Restrict /proc to user only"
51411 + depends on GRKERNSEC_PROC
51412 + help
51413 + If you say Y here, non-root users will only be able to view their own
51414 + processes, and restricts them from viewing network-related information,
51415 + and viewing kernel symbol and module information.
51416 +
51417 +config GRKERNSEC_PROC_USERGROUP
51418 + bool "Allow special group"
51419 + default y if GRKERNSEC_CONFIG_AUTO
51420 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
51421 + help
51422 + If you say Y here, you will be able to select a group that will be
51423 + able to view all processes and network-related information. If you've
51424 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
51425 + remain hidden. This option is useful if you want to run identd as
51426 + a non-root user. The group you select may also be chosen at boot time
51427 + via "grsec_proc_gid=" on the kernel commandline.
51428 +
51429 +config GRKERNSEC_PROC_GID
51430 + int "GID for special group"
51431 + depends on GRKERNSEC_PROC_USERGROUP
51432 + default 1001
51433 +
51434 +config GRKERNSEC_PROC_ADD
51435 + bool "Additional restrictions"
51436 + default y if GRKERNSEC_CONFIG_AUTO
51437 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
51438 + help
51439 + If you say Y here, additional restrictions will be placed on
51440 + /proc that keep normal users from viewing device information and
51441 + slabinfo information that could be useful for exploits.
51442 +
51443 +config GRKERNSEC_LINK
51444 + bool "Linking restrictions"
51445 + default y if GRKERNSEC_CONFIG_AUTO
51446 + help
51447 + If you say Y here, /tmp race exploits will be prevented, since users
51448 + will no longer be able to follow symlinks owned by other users in
51449 + world-writable +t directories (e.g. /tmp), unless the owner of the
51450 + symlink is the owner of the directory. users will also not be
51451 + able to hardlink to files they do not own. If the sysctl option is
51452 + enabled, a sysctl option with name "linking_restrictions" is created.
51453 +
51454 +config GRKERNSEC_SYMLINKOWN
51455 + bool "Kernel-enforced SymlinksIfOwnerMatch"
51456 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
51457 + help
51458 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
51459 + that prevents it from being used as a security feature. As Apache
51460 + verifies the symlink by performing a stat() against the target of
51461 + the symlink before it is followed, an attacker can setup a symlink
51462 + to point to a same-owned file, then replace the symlink with one
51463 + that targets another user's file just after Apache "validates" the
51464 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
51465 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
51466 + will be in place for the group you specify. If the sysctl option
51467 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
51468 + created.
51469 +
51470 +config GRKERNSEC_SYMLINKOWN_GID
51471 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
51472 + depends on GRKERNSEC_SYMLINKOWN
51473 + default 1006
51474 + help
51475 + Setting this GID determines what group kernel-enforced
51476 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
51477 + is enabled, a sysctl option with name "symlinkown_gid" is created.
51478 +
51479 +config GRKERNSEC_FIFO
51480 + bool "FIFO restrictions"
51481 + default y if GRKERNSEC_CONFIG_AUTO
51482 + help
51483 + If you say Y here, users will not be able to write to FIFOs they don't
51484 + own in world-writable +t directories (e.g. /tmp), unless the owner of
51485 + the FIFO is the same owner of the directory it's held in. If the sysctl
51486 + option is enabled, a sysctl option with name "fifo_restrictions" is
51487 + created.
51488 +
51489 +config GRKERNSEC_SYSFS_RESTRICT
51490 + bool "Sysfs/debugfs restriction"
51491 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
51492 + depends on SYSFS
51493 + help
51494 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
51495 + any filesystem normally mounted under it (e.g. debugfs) will be
51496 + mostly accessible only by root. These filesystems generally provide access
51497 + to hardware and debug information that isn't appropriate for unprivileged
51498 + users of the system. Sysfs and debugfs have also become a large source
51499 + of new vulnerabilities, ranging from infoleaks to local compromise.
51500 + There has been very little oversight with an eye toward security involved
51501 + in adding new exporters of information to these filesystems, so their
51502 + use is discouraged.
51503 + For reasons of compatibility, a few directories have been whitelisted
51504 + for access by non-root users:
51505 + /sys/fs/selinux
51506 + /sys/fs/fuse
51507 + /sys/devices/system/cpu
51508 +
51509 +config GRKERNSEC_ROFS
51510 + bool "Runtime read-only mount protection"
51511 + help
51512 + If you say Y here, a sysctl option with name "romount_protect" will
51513 + be created. By setting this option to 1 at runtime, filesystems
51514 + will be protected in the following ways:
51515 + * No new writable mounts will be allowed
51516 + * Existing read-only mounts won't be able to be remounted read/write
51517 + * Write operations will be denied on all block devices
51518 + This option acts independently of grsec_lock: once it is set to 1,
51519 + it cannot be turned off. Therefore, please be mindful of the resulting
51520 + behavior if this option is enabled in an init script on a read-only
51521 + filesystem. This feature is mainly intended for secure embedded systems.
51522 +
51523 +config GRKERNSEC_CHROOT
51524 + bool "Chroot jail restrictions"
51525 + default y if GRKERNSEC_CONFIG_AUTO
51526 + help
51527 + If you say Y here, you will be able to choose several options that will
51528 + make breaking out of a chrooted jail much more difficult. If you
51529 + encounter no software incompatibilities with the following options, it
51530 + is recommended that you enable each one.
51531 +
51532 +config GRKERNSEC_CHROOT_MOUNT
51533 + bool "Deny mounts"
51534 + default y if GRKERNSEC_CONFIG_AUTO
51535 + depends on GRKERNSEC_CHROOT
51536 + help
51537 + If you say Y here, processes inside a chroot will not be able to
51538 + mount or remount filesystems. If the sysctl option is enabled, a
51539 + sysctl option with name "chroot_deny_mount" is created.
51540 +
51541 +config GRKERNSEC_CHROOT_DOUBLE
51542 + bool "Deny double-chroots"
51543 + default y if GRKERNSEC_CONFIG_AUTO
51544 + depends on GRKERNSEC_CHROOT
51545 + help
51546 + If you say Y here, processes inside a chroot will not be able to chroot
51547 + again outside the chroot. This is a widely used method of breaking
51548 + out of a chroot jail and should not be allowed. If the sysctl
51549 + option is enabled, a sysctl option with name
51550 + "chroot_deny_chroot" is created.
51551 +
51552 +config GRKERNSEC_CHROOT_PIVOT
51553 + bool "Deny pivot_root in chroot"
51554 + default y if GRKERNSEC_CONFIG_AUTO
51555 + depends on GRKERNSEC_CHROOT
51556 + help
51557 + If you say Y here, processes inside a chroot will not be able to use
51558 + a function called pivot_root() that was introduced in Linux 2.3.41. It
51559 + works similar to chroot in that it changes the root filesystem. This
51560 + function could be misused in a chrooted process to attempt to break out
51561 + of the chroot, and therefore should not be allowed. If the sysctl
51562 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
51563 + created.
51564 +
51565 +config GRKERNSEC_CHROOT_CHDIR
51566 + bool "Enforce chdir(\"/\") on all chroots"
51567 + default y if GRKERNSEC_CONFIG_AUTO
51568 + depends on GRKERNSEC_CHROOT
51569 + help
51570 + If you say Y here, the current working directory of all newly-chrooted
51571 + applications will be set to the the root directory of the chroot.
51572 + The man page on chroot(2) states:
51573 + Note that this call does not change the current working
51574 + directory, so that `.' can be outside the tree rooted at
51575 + `/'. In particular, the super-user can escape from a
51576 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
51577 +
51578 + It is recommended that you say Y here, since it's not known to break
51579 + any software. If the sysctl option is enabled, a sysctl option with
51580 + name "chroot_enforce_chdir" is created.
51581 +
51582 +config GRKERNSEC_CHROOT_CHMOD
51583 + bool "Deny (f)chmod +s"
51584 + default y if GRKERNSEC_CONFIG_AUTO
51585 + depends on GRKERNSEC_CHROOT
51586 + help
51587 + If you say Y here, processes inside a chroot will not be able to chmod
51588 + or fchmod files to make them have suid or sgid bits. This protects
51589 + against another published method of breaking a chroot. If the sysctl
51590 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
51591 + created.
51592 +
51593 +config GRKERNSEC_CHROOT_FCHDIR
51594 + bool "Deny fchdir out of chroot"
51595 + default y if GRKERNSEC_CONFIG_AUTO
51596 + depends on GRKERNSEC_CHROOT
51597 + help
51598 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
51599 + to a file descriptor of the chrooting process that points to a directory
51600 + outside the filesystem will be stopped. If the sysctl option
51601 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
51602 +
51603 +config GRKERNSEC_CHROOT_MKNOD
51604 + bool "Deny mknod"
51605 + default y if GRKERNSEC_CONFIG_AUTO
51606 + depends on GRKERNSEC_CHROOT
51607 + help
51608 + If you say Y here, processes inside a chroot will not be allowed to
51609 + mknod. The problem with using mknod inside a chroot is that it
51610 + would allow an attacker to create a device entry that is the same
51611 + as one on the physical root of your system, which could range from
51612 + anything from the console device to a device for your harddrive (which
51613 + they could then use to wipe the drive or steal data). It is recommended
51614 + that you say Y here, unless you run into software incompatibilities.
51615 + If the sysctl option is enabled, a sysctl option with name
51616 + "chroot_deny_mknod" is created.
51617 +
51618 +config GRKERNSEC_CHROOT_SHMAT
51619 + bool "Deny shmat() out of chroot"
51620 + default y if GRKERNSEC_CONFIG_AUTO
51621 + depends on GRKERNSEC_CHROOT
51622 + help
51623 + If you say Y here, processes inside a chroot will not be able to attach
51624 + to shared memory segments that were created outside of the chroot jail.
51625 + It is recommended that you say Y here. If the sysctl option is enabled,
51626 + a sysctl option with name "chroot_deny_shmat" is created.
51627 +
51628 +config GRKERNSEC_CHROOT_UNIX
51629 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
51630 + default y if GRKERNSEC_CONFIG_AUTO
51631 + depends on GRKERNSEC_CHROOT
51632 + help
51633 + If you say Y here, processes inside a chroot will not be able to
51634 + connect to abstract (meaning not belonging to a filesystem) Unix
51635 + domain sockets that were bound outside of a chroot. It is recommended
51636 + that you say Y here. If the sysctl option is enabled, a sysctl option
51637 + with name "chroot_deny_unix" is created.
51638 +
51639 +config GRKERNSEC_CHROOT_FINDTASK
51640 + bool "Protect outside processes"
51641 + default y if GRKERNSEC_CONFIG_AUTO
51642 + depends on GRKERNSEC_CHROOT
51643 + help
51644 + If you say Y here, processes inside a chroot will not be able to
51645 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
51646 + getsid, or view any process outside of the chroot. If the sysctl
51647 + option is enabled, a sysctl option with name "chroot_findtask" is
51648 + created.
51649 +
51650 +config GRKERNSEC_CHROOT_NICE
51651 + bool "Restrict priority changes"
51652 + default y if GRKERNSEC_CONFIG_AUTO
51653 + depends on GRKERNSEC_CHROOT
51654 + help
51655 + If you say Y here, processes inside a chroot will not be able to raise
51656 + the priority of processes in the chroot, or alter the priority of
51657 + processes outside the chroot. This provides more security than simply
51658 + removing CAP_SYS_NICE from the process' capability set. If the
51659 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
51660 + is created.
51661 +
51662 +config GRKERNSEC_CHROOT_SYSCTL
51663 + bool "Deny sysctl writes"
51664 + default y if GRKERNSEC_CONFIG_AUTO
51665 + depends on GRKERNSEC_CHROOT
51666 + help
51667 + If you say Y here, an attacker in a chroot will not be able to
51668 + write to sysctl entries, either by sysctl(2) or through a /proc
51669 + interface. It is strongly recommended that you say Y here. If the
51670 + sysctl option is enabled, a sysctl option with name
51671 + "chroot_deny_sysctl" is created.
51672 +
51673 +config GRKERNSEC_CHROOT_CAPS
51674 + bool "Capability restrictions"
51675 + default y if GRKERNSEC_CONFIG_AUTO
51676 + depends on GRKERNSEC_CHROOT
51677 + help
51678 + If you say Y here, the capabilities on all processes within a
51679 + chroot jail will be lowered to stop module insertion, raw i/o,
51680 + system and net admin tasks, rebooting the system, modifying immutable
51681 + files, modifying IPC owned by another, and changing the system time.
51682 + This is left an option because it can break some apps. Disable this
51683 + if your chrooted apps are having problems performing those kinds of
51684 + tasks. If the sysctl option is enabled, a sysctl option with
51685 + name "chroot_caps" is created.
51686 +
51687 +endmenu
51688 +menu "Kernel Auditing"
51689 +depends on GRKERNSEC
51690 +
51691 +config GRKERNSEC_AUDIT_GROUP
51692 + bool "Single group for auditing"
51693 + help
51694 + If you say Y here, the exec, chdir, and (un)mount logging features
51695 + will only operate on a group you specify. This option is recommended
51696 + if you only want to watch certain users instead of having a large
51697 + amount of logs from the entire system. If the sysctl option is enabled,
51698 + a sysctl option with name "audit_group" is created.
51699 +
51700 +config GRKERNSEC_AUDIT_GID
51701 + int "GID for auditing"
51702 + depends on GRKERNSEC_AUDIT_GROUP
51703 + default 1007
51704 +
51705 +config GRKERNSEC_EXECLOG
51706 + bool "Exec logging"
51707 + help
51708 + If you say Y here, all execve() calls will be logged (since the
51709 + other exec*() calls are frontends to execve(), all execution
51710 + will be logged). Useful for shell-servers that like to keep track
51711 + of their users. If the sysctl option is enabled, a sysctl option with
51712 + name "exec_logging" is created.
51713 + WARNING: This option when enabled will produce a LOT of logs, especially
51714 + on an active system.
51715 +
51716 +config GRKERNSEC_RESLOG
51717 + bool "Resource logging"
51718 + default y if GRKERNSEC_CONFIG_AUTO
51719 + help
51720 + If you say Y here, all attempts to overstep resource limits will
51721 + be logged with the resource name, the requested size, and the current
51722 + limit. It is highly recommended that you say Y here. If the sysctl
51723 + option is enabled, a sysctl option with name "resource_logging" is
51724 + created. If the RBAC system is enabled, the sysctl value is ignored.
51725 +
51726 +config GRKERNSEC_CHROOT_EXECLOG
51727 + bool "Log execs within chroot"
51728 + help
51729 + If you say Y here, all executions inside a chroot jail will be logged
51730 + to syslog. This can cause a large amount of logs if certain
51731 + applications (eg. djb's daemontools) are installed on the system, and
51732 + is therefore left as an option. If the sysctl option is enabled, a
51733 + sysctl option with name "chroot_execlog" is created.
51734 +
51735 +config GRKERNSEC_AUDIT_PTRACE
51736 + bool "Ptrace logging"
51737 + help
51738 + If you say Y here, all attempts to attach to a process via ptrace
51739 + will be logged. If the sysctl option is enabled, a sysctl option
51740 + with name "audit_ptrace" is created.
51741 +
51742 +config GRKERNSEC_AUDIT_CHDIR
51743 + bool "Chdir logging"
51744 + help
51745 + If you say Y here, all chdir() calls will be logged. If the sysctl
51746 + option is enabled, a sysctl option with name "audit_chdir" is created.
51747 +
51748 +config GRKERNSEC_AUDIT_MOUNT
51749 + bool "(Un)Mount logging"
51750 + help
51751 + If you say Y here, all mounts and unmounts will be logged. If the
51752 + sysctl option is enabled, a sysctl option with name "audit_mount" is
51753 + created.
51754 +
51755 +config GRKERNSEC_SIGNAL
51756 + bool "Signal logging"
51757 + default y if GRKERNSEC_CONFIG_AUTO
51758 + help
51759 + If you say Y here, certain important signals will be logged, such as
51760 + SIGSEGV, which will as a result inform you of when a error in a program
51761 + occurred, which in some cases could mean a possible exploit attempt.
51762 + If the sysctl option is enabled, a sysctl option with name
51763 + "signal_logging" is created.
51764 +
51765 +config GRKERNSEC_FORKFAIL
51766 + bool "Fork failure logging"
51767 + help
51768 + If you say Y here, all failed fork() attempts will be logged.
51769 + This could suggest a fork bomb, or someone attempting to overstep
51770 + their process limit. If the sysctl option is enabled, a sysctl option
51771 + with name "forkfail_logging" is created.
51772 +
51773 +config GRKERNSEC_TIME
51774 + bool "Time change logging"
51775 + default y if GRKERNSEC_CONFIG_AUTO
51776 + help
51777 + If you say Y here, any changes of the system clock will be logged.
51778 + If the sysctl option is enabled, a sysctl option with name
51779 + "timechange_logging" is created.
51780 +
51781 +config GRKERNSEC_PROC_IPADDR
51782 + bool "/proc/<pid>/ipaddr support"
51783 + default y if GRKERNSEC_CONFIG_AUTO
51784 + help
51785 + If you say Y here, a new entry will be added to each /proc/<pid>
51786 + directory that contains the IP address of the person using the task.
51787 + The IP is carried across local TCP and AF_UNIX stream sockets.
51788 + This information can be useful for IDS/IPSes to perform remote response
51789 + to a local attack. The entry is readable by only the owner of the
51790 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
51791 + the RBAC system), and thus does not create privacy concerns.
51792 +
51793 +config GRKERNSEC_RWXMAP_LOG
51794 + bool 'Denied RWX mmap/mprotect logging'
51795 + default y if GRKERNSEC_CONFIG_AUTO
51796 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
51797 + help
51798 + If you say Y here, calls to mmap() and mprotect() with explicit
51799 + usage of PROT_WRITE and PROT_EXEC together will be logged when
51800 + denied by the PAX_MPROTECT feature. If the sysctl option is
51801 + enabled, a sysctl option with name "rwxmap_logging" is created.
51802 +
51803 +config GRKERNSEC_AUDIT_TEXTREL
51804 + bool 'ELF text relocations logging (READ HELP)'
51805 + depends on PAX_MPROTECT
51806 + help
51807 + If you say Y here, text relocations will be logged with the filename
51808 + of the offending library or binary. The purpose of the feature is
51809 + to help Linux distribution developers get rid of libraries and
51810 + binaries that need text relocations which hinder the future progress
51811 + of PaX. Only Linux distribution developers should say Y here, and
51812 + never on a production machine, as this option creates an information
51813 + leak that could aid an attacker in defeating the randomization of
51814 + a single memory region. If the sysctl option is enabled, a sysctl
51815 + option with name "audit_textrel" is created.
51816 +
51817 +endmenu
51818 +
51819 +menu "Executable Protections"
51820 +depends on GRKERNSEC
51821 +
51822 +config GRKERNSEC_DMESG
51823 + bool "Dmesg(8) restriction"
51824 + default y if GRKERNSEC_CONFIG_AUTO
51825 + help
51826 + If you say Y here, non-root users will not be able to use dmesg(8)
51827 + to view up to the last 4kb of messages in the kernel's log buffer.
51828 + The kernel's log buffer often contains kernel addresses and other
51829 + identifying information useful to an attacker in fingerprinting a
51830 + system for a targeted exploit.
51831 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
51832 + created.
51833 +
51834 +config GRKERNSEC_HARDEN_PTRACE
51835 + bool "Deter ptrace-based process snooping"
51836 + default y if GRKERNSEC_CONFIG_AUTO
51837 + help
51838 + If you say Y here, TTY sniffers and other malicious monitoring
51839 + programs implemented through ptrace will be defeated. If you
51840 + have been using the RBAC system, this option has already been
51841 + enabled for several years for all users, with the ability to make
51842 + fine-grained exceptions.
51843 +
51844 + This option only affects the ability of non-root users to ptrace
51845 + processes that are not a descendent of the ptracing process.
51846 + This means that strace ./binary and gdb ./binary will still work,
51847 + but attaching to arbitrary processes will not. If the sysctl
51848 + option is enabled, a sysctl option with name "harden_ptrace" is
51849 + created.
51850 +
51851 +config GRKERNSEC_PTRACE_READEXEC
51852 + bool "Require read access to ptrace sensitive binaries"
51853 + default y if GRKERNSEC_CONFIG_AUTO
51854 + help
51855 + If you say Y here, unprivileged users will not be able to ptrace unreadable
51856 + binaries. This option is useful in environments that
51857 + remove the read bits (e.g. file mode 4711) from suid binaries to
51858 + prevent infoleaking of their contents. This option adds
51859 + consistency to the use of that file mode, as the binary could normally
51860 + be read out when run without privileges while ptracing.
51861 +
51862 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
51863 + is created.
51864 +
51865 +config GRKERNSEC_SETXID
51866 + bool "Enforce consistent multithreaded privileges"
51867 + default y if GRKERNSEC_CONFIG_AUTO
51868 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
51869 + help
51870 + If you say Y here, a change from a root uid to a non-root uid
51871 + in a multithreaded application will cause the resulting uids,
51872 + gids, supplementary groups, and capabilities in that thread
51873 + to be propagated to the other threads of the process. In most
51874 + cases this is unnecessary, as glibc will emulate this behavior
51875 + on behalf of the application. Other libcs do not act in the
51876 + same way, allowing the other threads of the process to continue
51877 + running with root privileges. If the sysctl option is enabled,
51878 + a sysctl option with name "consistent_setxid" is created.
51879 +
51880 +config GRKERNSEC_TPE
51881 + bool "Trusted Path Execution (TPE)"
51882 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
51883 + help
51884 + If you say Y here, you will be able to choose a gid to add to the
51885 + supplementary groups of users you want to mark as "untrusted."
51886 + These users will not be able to execute any files that are not in
51887 + root-owned directories writable only by root. If the sysctl option
51888 + is enabled, a sysctl option with name "tpe" is created.
51889 +
51890 +config GRKERNSEC_TPE_ALL
51891 + bool "Partially restrict all non-root users"
51892 + depends on GRKERNSEC_TPE
51893 + help
51894 + If you say Y here, all non-root users will be covered under
51895 + a weaker TPE restriction. This is separate from, and in addition to,
51896 + the main TPE options that you have selected elsewhere. Thus, if a
51897 + "trusted" GID is chosen, this restriction applies to even that GID.
51898 + Under this restriction, all non-root users will only be allowed to
51899 + execute files in directories they own that are not group or
51900 + world-writable, or in directories owned by root and writable only by
51901 + root. If the sysctl option is enabled, a sysctl option with name
51902 + "tpe_restrict_all" is created.
51903 +
51904 +config GRKERNSEC_TPE_INVERT
51905 + bool "Invert GID option"
51906 + depends on GRKERNSEC_TPE
51907 + help
51908 + If you say Y here, the group you specify in the TPE configuration will
51909 + decide what group TPE restrictions will be *disabled* for. This
51910 + option is useful if you want TPE restrictions to be applied to most
51911 + users on the system. If the sysctl option is enabled, a sysctl option
51912 + with name "tpe_invert" is created. Unlike other sysctl options, this
51913 + entry will default to on for backward-compatibility.
51914 +
51915 +config GRKERNSEC_TPE_GID
51916 + int
51917 + default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
51918 + default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
51919 +
51920 +config GRKERNSEC_TPE_UNTRUSTED_GID
51921 + int "GID for TPE-untrusted users"
51922 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
51923 + default 1005
51924 + help
51925 + Setting this GID determines what group TPE restrictions will be
51926 + *enabled* for. If the sysctl option is enabled, a sysctl option
51927 + with name "tpe_gid" is created.
51928 +
51929 +config GRKERNSEC_TPE_TRUSTED_GID
51930 + int "GID for TPE-trusted users"
51931 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
51932 + default 1005
51933 + help
51934 + Setting this GID determines what group TPE restrictions will be
51935 + *disabled* for. If the sysctl option is enabled, a sysctl option
51936 + with name "tpe_gid" is created.
51937 +
51938 +endmenu
51939 +menu "Network Protections"
51940 +depends on GRKERNSEC
51941 +
51942 +config GRKERNSEC_RANDNET
51943 + bool "Larger entropy pools"
51944 + default y if GRKERNSEC_CONFIG_AUTO
51945 + help
51946 + If you say Y here, the entropy pools used for many features of Linux
51947 + and grsecurity will be doubled in size. Since several grsecurity
51948 + features use additional randomness, it is recommended that you say Y
51949 + here. Saying Y here has a similar effect as modifying
51950 + /proc/sys/kernel/random/poolsize.
51951 +
51952 +config GRKERNSEC_BLACKHOLE
51953 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
51954 + default y if GRKERNSEC_CONFIG_AUTO
51955 + depends on NET
51956 + help
51957 + If you say Y here, neither TCP resets nor ICMP
51958 + destination-unreachable packets will be sent in response to packets
51959 + sent to ports for which no associated listening process exists.
51960 + This feature supports both IPV4 and IPV6 and exempts the
51961 + loopback interface from blackholing. Enabling this feature
51962 + makes a host more resilient to DoS attacks and reduces network
51963 + visibility against scanners.
51964 +
51965 + The blackhole feature as-implemented is equivalent to the FreeBSD
51966 + blackhole feature, as it prevents RST responses to all packets, not
51967 + just SYNs. Under most application behavior this causes no
51968 + problems, but applications (like haproxy) may not close certain
51969 + connections in a way that cleanly terminates them on the remote
51970 + end, leaving the remote host in LAST_ACK state. Because of this
51971 + side-effect and to prevent intentional LAST_ACK DoSes, this
51972 + feature also adds automatic mitigation against such attacks.
51973 + The mitigation drastically reduces the amount of time a socket
51974 + can spend in LAST_ACK state. If you're using haproxy and not
51975 + all servers it connects to have this option enabled, consider
51976 + disabling this feature on the haproxy host.
51977 +
51978 + If the sysctl option is enabled, two sysctl options with names
51979 + "ip_blackhole" and "lastack_retries" will be created.
51980 + While "ip_blackhole" takes the standard zero/non-zero on/off
51981 + toggle, "lastack_retries" uses the same kinds of values as
51982 + "tcp_retries1" and "tcp_retries2". The default value of 4
51983 + prevents a socket from lasting more than 45 seconds in LAST_ACK
51984 + state.
51985 +
51986 +config GRKERNSEC_SOCKET
51987 + bool "Socket restrictions"
51988 + depends on NET
51989 + help
51990 + If you say Y here, you will be able to choose from several options.
51991 + If you assign a GID on your system and add it to the supplementary
51992 + groups of users you want to restrict socket access to, this patch
51993 + will perform up to three things, based on the option(s) you choose.
51994 +
51995 +config GRKERNSEC_SOCKET_ALL
51996 + bool "Deny any sockets to group"
51997 + depends on GRKERNSEC_SOCKET
51998 + help
51999 + If you say Y here, you will be able to choose a GID of whose users will
52000 + be unable to connect to other hosts from your machine or run server
52001 + applications from your machine. If the sysctl option is enabled, a
52002 + sysctl option with name "socket_all" is created.
52003 +
52004 +config GRKERNSEC_SOCKET_ALL_GID
52005 + int "GID to deny all sockets for"
52006 + depends on GRKERNSEC_SOCKET_ALL
52007 + default 1004
52008 + help
52009 + Here you can choose the GID to disable socket access for. Remember to
52010 + add the users you want socket access disabled for to the GID
52011 + specified here. If the sysctl option is enabled, a sysctl option
52012 + with name "socket_all_gid" is created.
52013 +
52014 +config GRKERNSEC_SOCKET_CLIENT
52015 + bool "Deny client sockets to group"
52016 + depends on GRKERNSEC_SOCKET
52017 + help
52018 + If you say Y here, you will be able to choose a GID of whose users will
52019 + be unable to connect to other hosts from your machine, but will be
52020 + able to run servers. If this option is enabled, all users in the group
52021 + you specify will have to use passive mode when initiating ftp transfers
52022 + from the shell on your machine. If the sysctl option is enabled, a
52023 + sysctl option with name "socket_client" is created.
52024 +
52025 +config GRKERNSEC_SOCKET_CLIENT_GID
52026 + int "GID to deny client sockets for"
52027 + depends on GRKERNSEC_SOCKET_CLIENT
52028 + default 1003
52029 + help
52030 + Here you can choose the GID to disable client socket access for.
52031 + Remember to add the users you want client socket access disabled for to
52032 + the GID specified here. If the sysctl option is enabled, a sysctl
52033 + option with name "socket_client_gid" is created.
52034 +
52035 +config GRKERNSEC_SOCKET_SERVER
52036 + bool "Deny server sockets to group"
52037 + depends on GRKERNSEC_SOCKET
52038 + help
52039 + If you say Y here, you will be able to choose a GID of whose users will
52040 + be unable to run server applications from your machine. If the sysctl
52041 + option is enabled, a sysctl option with name "socket_server" is created.
52042 +
52043 +config GRKERNSEC_SOCKET_SERVER_GID
52044 + int "GID to deny server sockets for"
52045 + depends on GRKERNSEC_SOCKET_SERVER
52046 + default 1002
52047 + help
52048 + Here you can choose the GID to disable server socket access for.
52049 + Remember to add the users you want server socket access disabled for to
52050 + the GID specified here. If the sysctl option is enabled, a sysctl
52051 + option with name "socket_server_gid" is created.
52052 +
52053 +endmenu
52054 +menu "Sysctl Support"
52055 +depends on GRKERNSEC && SYSCTL
52056 +
52057 +config GRKERNSEC_SYSCTL
52058 + bool "Sysctl support"
52059 + default y if GRKERNSEC_CONFIG_AUTO
52060 + help
52061 + If you say Y here, you will be able to change the options that
52062 + grsecurity runs with at bootup, without having to recompile your
52063 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
52064 + to enable (1) or disable (0) various features. All the sysctl entries
52065 + are mutable until the "grsec_lock" entry is set to a non-zero value.
52066 + All features enabled in the kernel configuration are disabled at boot
52067 + if you do not say Y to the "Turn on features by default" option.
52068 + All options should be set at startup, and the grsec_lock entry should
52069 + be set to a non-zero value after all the options are set.
52070 + *THIS IS EXTREMELY IMPORTANT*
52071 +
52072 +config GRKERNSEC_SYSCTL_DISTRO
52073 + bool "Extra sysctl support for distro makers (READ HELP)"
52074 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
52075 + help
52076 + If you say Y here, additional sysctl options will be created
52077 + for features that affect processes running as root. Therefore,
52078 + it is critical when using this option that the grsec_lock entry be
52079 + enabled after boot. Only distros with prebuilt kernel packages
52080 + with this option enabled that can ensure grsec_lock is enabled
52081 + after boot should use this option.
52082 + *Failure to set grsec_lock after boot makes all grsec features
52083 + this option covers useless*
52084 +
52085 + Currently this option creates the following sysctl entries:
52086 + "Disable Privileged I/O": "disable_priv_io"
52087 +
52088 +config GRKERNSEC_SYSCTL_ON
52089 + bool "Turn on features by default"
52090 + default y if GRKERNSEC_CONFIG_AUTO
52091 + depends on GRKERNSEC_SYSCTL
52092 + help
52093 + If you say Y here, instead of having all features enabled in the
52094 + kernel configuration disabled at boot time, the features will be
52095 + enabled at boot time. It is recommended you say Y here unless
52096 + there is some reason you would want all sysctl-tunable features to
52097 + be disabled by default. As mentioned elsewhere, it is important
52098 + to enable the grsec_lock entry once you have finished modifying
52099 + the sysctl entries.
52100 +
52101 +endmenu
52102 +menu "Logging Options"
52103 +depends on GRKERNSEC
52104 +
52105 +config GRKERNSEC_FLOODTIME
52106 + int "Seconds in between log messages (minimum)"
52107 + default 10
52108 + help
52109 + This option allows you to enforce the number of seconds between
52110 + grsecurity log messages. The default should be suitable for most
52111 + people, however, if you choose to change it, choose a value small enough
52112 + to allow informative logs to be produced, but large enough to
52113 + prevent flooding.
52114 +
52115 +config GRKERNSEC_FLOODBURST
52116 + int "Number of messages in a burst (maximum)"
52117 + default 6
52118 + help
52119 + This option allows you to choose the maximum number of messages allowed
52120 + within the flood time interval you chose in a separate option. The
52121 + default should be suitable for most people, however if you find that
52122 + many of your logs are being interpreted as flooding, you may want to
52123 + raise this value.
52124 +
52125 +endmenu
52126 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
52127 new file mode 100644
52128 index 0000000..1b9afa9
52129 --- /dev/null
52130 +++ b/grsecurity/Makefile
52131 @@ -0,0 +1,38 @@
52132 +# grsecurity's ACL system was originally written in 2001 by Michael Dalton
52133 +# during 2001-2009 it has been completely redesigned by Brad Spengler
52134 +# into an RBAC system
52135 +#
52136 +# All code in this directory and various hooks inserted throughout the kernel
52137 +# are copyright Brad Spengler - Open Source Security, Inc., and released
52138 +# under the GPL v2 or higher
52139 +
52140 +KBUILD_CFLAGS += -Werror
52141 +
52142 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
52143 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
52144 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
52145 +
52146 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
52147 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
52148 + gracl_learn.o grsec_log.o
52149 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
52150 +
52151 +ifdef CONFIG_NET
52152 +obj-y += grsec_sock.o
52153 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
52154 +endif
52155 +
52156 +ifndef CONFIG_GRKERNSEC
52157 +obj-y += grsec_disabled.o
52158 +endif
52159 +
52160 +ifdef CONFIG_GRKERNSEC_HIDESYM
52161 +extra-y := grsec_hidesym.o
52162 +$(obj)/grsec_hidesym.o:
52163 + @-chmod -f 500 /boot
52164 + @-chmod -f 500 /lib/modules
52165 + @-chmod -f 500 /lib64/modules
52166 + @-chmod -f 500 /lib32/modules
52167 + @-chmod -f 700 .
52168 + @echo ' grsec: protected kernel image paths'
52169 +endif
52170 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
52171 new file mode 100644
52172 index 0000000..4428c82
52173 --- /dev/null
52174 +++ b/grsecurity/gracl.c
52175 @@ -0,0 +1,4056 @@
52176 +#include <linux/kernel.h>
52177 +#include <linux/module.h>
52178 +#include <linux/sched.h>
52179 +#include <linux/mm.h>
52180 +#include <linux/file.h>
52181 +#include <linux/fs.h>
52182 +#include <linux/namei.h>
52183 +#include <linux/mount.h>
52184 +#include <linux/tty.h>
52185 +#include <linux/proc_fs.h>
52186 +#include <linux/lglock.h>
52187 +#include <linux/slab.h>
52188 +#include <linux/vmalloc.h>
52189 +#include <linux/types.h>
52190 +#include <linux/sysctl.h>
52191 +#include <linux/netdevice.h>
52192 +#include <linux/ptrace.h>
52193 +#include <linux/gracl.h>
52194 +#include <linux/gralloc.h>
52195 +#include <linux/security.h>
52196 +#include <linux/grinternal.h>
52197 +#include <linux/pid_namespace.h>
52198 +#include <linux/stop_machine.h>
52199 +#include <linux/fdtable.h>
52200 +#include <linux/percpu.h>
52201 +#include <linux/lglock.h>
52202 +#include "../fs/mount.h"
52203 +
52204 +#include <asm/uaccess.h>
52205 +#include <asm/errno.h>
52206 +#include <asm/mman.h>
52207 +
52208 +extern struct lglock vfsmount_lock;
52209 +
52210 +static struct acl_role_db acl_role_set;
52211 +static struct name_db name_set;
52212 +static struct inodev_db inodev_set;
52213 +
52214 +/* for keeping track of userspace pointers used for subjects, so we
52215 + can share references in the kernel as well
52216 +*/
52217 +
52218 +static struct path real_root;
52219 +
52220 +static struct acl_subj_map_db subj_map_set;
52221 +
52222 +static struct acl_role_label *default_role;
52223 +
52224 +static struct acl_role_label *role_list;
52225 +
52226 +static u16 acl_sp_role_value;
52227 +
52228 +extern char *gr_shared_page[4];
52229 +static DEFINE_MUTEX(gr_dev_mutex);
52230 +DEFINE_RWLOCK(gr_inode_lock);
52231 +
52232 +struct gr_arg *gr_usermode;
52233 +
52234 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
52235 +
52236 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
52237 +extern void gr_clear_learn_entries(void);
52238 +
52239 +#ifdef CONFIG_GRKERNSEC_RESLOG
52240 +extern void gr_log_resource(const struct task_struct *task,
52241 + const int res, const unsigned long wanted, const int gt);
52242 +#endif
52243 +
52244 +unsigned char *gr_system_salt;
52245 +unsigned char *gr_system_sum;
52246 +
52247 +static struct sprole_pw **acl_special_roles = NULL;
52248 +static __u16 num_sprole_pws = 0;
52249 +
52250 +static struct acl_role_label *kernel_role = NULL;
52251 +
52252 +static unsigned int gr_auth_attempts = 0;
52253 +static unsigned long gr_auth_expires = 0UL;
52254 +
52255 +#ifdef CONFIG_NET
52256 +extern struct vfsmount *sock_mnt;
52257 +#endif
52258 +
52259 +extern struct vfsmount *pipe_mnt;
52260 +extern struct vfsmount *shm_mnt;
52261 +#ifdef CONFIG_HUGETLBFS
52262 +extern struct vfsmount *hugetlbfs_vfsmount;
52263 +#endif
52264 +
52265 +static struct acl_object_label *fakefs_obj_rw;
52266 +static struct acl_object_label *fakefs_obj_rwx;
52267 +
52268 +extern int gr_init_uidset(void);
52269 +extern void gr_free_uidset(void);
52270 +extern void gr_remove_uid(uid_t uid);
52271 +extern int gr_find_uid(uid_t uid);
52272 +
52273 +__inline__ int
52274 +gr_acl_is_enabled(void)
52275 +{
52276 + return (gr_status & GR_READY);
52277 +}
52278 +
52279 +#ifdef CONFIG_BTRFS_FS
52280 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
52281 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
52282 +#endif
52283 +
52284 +static inline dev_t __get_dev(const struct dentry *dentry)
52285 +{
52286 +#ifdef CONFIG_BTRFS_FS
52287 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
52288 + return get_btrfs_dev_from_inode(dentry->d_inode);
52289 + else
52290 +#endif
52291 + return dentry->d_inode->i_sb->s_dev;
52292 +}
52293 +
52294 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
52295 +{
52296 + return __get_dev(dentry);
52297 +}
52298 +
52299 +static char gr_task_roletype_to_char(struct task_struct *task)
52300 +{
52301 + switch (task->role->roletype &
52302 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
52303 + GR_ROLE_SPECIAL)) {
52304 + case GR_ROLE_DEFAULT:
52305 + return 'D';
52306 + case GR_ROLE_USER:
52307 + return 'U';
52308 + case GR_ROLE_GROUP:
52309 + return 'G';
52310 + case GR_ROLE_SPECIAL:
52311 + return 'S';
52312 + }
52313 +
52314 + return 'X';
52315 +}
52316 +
52317 +char gr_roletype_to_char(void)
52318 +{
52319 + return gr_task_roletype_to_char(current);
52320 +}
52321 +
52322 +__inline__ int
52323 +gr_acl_tpe_check(void)
52324 +{
52325 + if (unlikely(!(gr_status & GR_READY)))
52326 + return 0;
52327 + if (current->role->roletype & GR_ROLE_TPE)
52328 + return 1;
52329 + else
52330 + return 0;
52331 +}
52332 +
52333 +int
52334 +gr_handle_rawio(const struct inode *inode)
52335 +{
52336 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
52337 + if (inode && S_ISBLK(inode->i_mode) &&
52338 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
52339 + !capable(CAP_SYS_RAWIO))
52340 + return 1;
52341 +#endif
52342 + return 0;
52343 +}
52344 +
52345 +static int
52346 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
52347 +{
52348 + if (likely(lena != lenb))
52349 + return 0;
52350 +
52351 + return !memcmp(a, b, lena);
52352 +}
52353 +
52354 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
52355 +{
52356 + *buflen -= namelen;
52357 + if (*buflen < 0)
52358 + return -ENAMETOOLONG;
52359 + *buffer -= namelen;
52360 + memcpy(*buffer, str, namelen);
52361 + return 0;
52362 +}
52363 +
52364 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
52365 +{
52366 + return prepend(buffer, buflen, name->name, name->len);
52367 +}
52368 +
52369 +static int prepend_path(const struct path *path, struct path *root,
52370 + char **buffer, int *buflen)
52371 +{
52372 + struct dentry *dentry = path->dentry;
52373 + struct vfsmount *vfsmnt = path->mnt;
52374 + struct mount *mnt = real_mount(vfsmnt);
52375 + bool slash = false;
52376 + int error = 0;
52377 +
52378 + while (dentry != root->dentry || vfsmnt != root->mnt) {
52379 + struct dentry * parent;
52380 +
52381 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
52382 + /* Global root? */
52383 + if (!mnt_has_parent(mnt)) {
52384 + goto out;
52385 + }
52386 + dentry = mnt->mnt_mountpoint;
52387 + mnt = mnt->mnt_parent;
52388 + vfsmnt = &mnt->mnt;
52389 + continue;
52390 + }
52391 + parent = dentry->d_parent;
52392 + prefetch(parent);
52393 + spin_lock(&dentry->d_lock);
52394 + error = prepend_name(buffer, buflen, &dentry->d_name);
52395 + spin_unlock(&dentry->d_lock);
52396 + if (!error)
52397 + error = prepend(buffer, buflen, "/", 1);
52398 + if (error)
52399 + break;
52400 +
52401 + slash = true;
52402 + dentry = parent;
52403 + }
52404 +
52405 +out:
52406 + if (!error && !slash)
52407 + error = prepend(buffer, buflen, "/", 1);
52408 +
52409 + return error;
52410 +}
52411 +
52412 +/* this must be called with vfsmount_lock and rename_lock held */
52413 +
52414 +static char *__our_d_path(const struct path *path, struct path *root,
52415 + char *buf, int buflen)
52416 +{
52417 + char *res = buf + buflen;
52418 + int error;
52419 +
52420 + prepend(&res, &buflen, "\0", 1);
52421 + error = prepend_path(path, root, &res, &buflen);
52422 + if (error)
52423 + return ERR_PTR(error);
52424 +
52425 + return res;
52426 +}
52427 +
52428 +static char *
52429 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
52430 +{
52431 + char *retval;
52432 +
52433 + retval = __our_d_path(path, root, buf, buflen);
52434 + if (unlikely(IS_ERR(retval)))
52435 + retval = strcpy(buf, "<path too long>");
52436 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
52437 + retval[1] = '\0';
52438 +
52439 + return retval;
52440 +}
52441 +
52442 +static char *
52443 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
52444 + char *buf, int buflen)
52445 +{
52446 + struct path path;
52447 + char *res;
52448 +
52449 + path.dentry = (struct dentry *)dentry;
52450 + path.mnt = (struct vfsmount *)vfsmnt;
52451 +
52452 + /* we can use real_root.dentry, real_root.mnt, because this is only called
52453 + by the RBAC system */
52454 + res = gen_full_path(&path, &real_root, buf, buflen);
52455 +
52456 + return res;
52457 +}
52458 +
52459 +static char *
52460 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
52461 + char *buf, int buflen)
52462 +{
52463 + char *res;
52464 + struct path path;
52465 + struct path root;
52466 + struct task_struct *reaper = init_pid_ns.child_reaper;
52467 +
52468 + path.dentry = (struct dentry *)dentry;
52469 + path.mnt = (struct vfsmount *)vfsmnt;
52470 +
52471 + /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
52472 + get_fs_root(reaper->fs, &root);
52473 +
52474 + write_seqlock(&rename_lock);
52475 + br_read_lock(&vfsmount_lock);
52476 + res = gen_full_path(&path, &root, buf, buflen);
52477 + br_read_unlock(&vfsmount_lock);
52478 + write_sequnlock(&rename_lock);
52479 +
52480 + path_put(&root);
52481 + return res;
52482 +}
52483 +
52484 +static char *
52485 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
52486 +{
52487 + char *ret;
52488 + write_seqlock(&rename_lock);
52489 + br_read_lock(&vfsmount_lock);
52490 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
52491 + PAGE_SIZE);
52492 + br_read_unlock(&vfsmount_lock);
52493 + write_sequnlock(&rename_lock);
52494 + return ret;
52495 +}
52496 +
52497 +static char *
52498 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
52499 +{
52500 + char *ret;
52501 + char *buf;
52502 + int buflen;
52503 +
52504 + write_seqlock(&rename_lock);
52505 + br_read_lock(&vfsmount_lock);
52506 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
52507 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
52508 + buflen = (int)(ret - buf);
52509 + if (buflen >= 5)
52510 + prepend(&ret, &buflen, "/proc", 5);
52511 + else
52512 + ret = strcpy(buf, "<path too long>");
52513 + br_read_unlock(&vfsmount_lock);
52514 + write_sequnlock(&rename_lock);
52515 + return ret;
52516 +}
52517 +
52518 +char *
52519 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
52520 +{
52521 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
52522 + PAGE_SIZE);
52523 +}
52524 +
52525 +char *
52526 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
52527 +{
52528 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
52529 + PAGE_SIZE);
52530 +}
52531 +
52532 +char *
52533 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
52534 +{
52535 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
52536 + PAGE_SIZE);
52537 +}
52538 +
52539 +char *
52540 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
52541 +{
52542 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
52543 + PAGE_SIZE);
52544 +}
52545 +
52546 +char *
52547 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
52548 +{
52549 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
52550 + PAGE_SIZE);
52551 +}
52552 +
52553 +__inline__ __u32
52554 +to_gr_audit(const __u32 reqmode)
52555 +{
52556 + /* masks off auditable permission flags, then shifts them to create
52557 + auditing flags, and adds the special case of append auditing if
52558 + we're requesting write */
52559 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
52560 +}
52561 +
52562 +struct acl_subject_label *
52563 +lookup_subject_map(const struct acl_subject_label *userp)
52564 +{
52565 + unsigned int index = shash(userp, subj_map_set.s_size);
52566 + struct subject_map *match;
52567 +
52568 + match = subj_map_set.s_hash[index];
52569 +
52570 + while (match && match->user != userp)
52571 + match = match->next;
52572 +
52573 + if (match != NULL)
52574 + return match->kernel;
52575 + else
52576 + return NULL;
52577 +}
52578 +
52579 +static void
52580 +insert_subj_map_entry(struct subject_map *subjmap)
52581 +{
52582 + unsigned int index = shash(subjmap->user, subj_map_set.s_size);
52583 + struct subject_map **curr;
52584 +
52585 + subjmap->prev = NULL;
52586 +
52587 + curr = &subj_map_set.s_hash[index];
52588 + if (*curr != NULL)
52589 + (*curr)->prev = subjmap;
52590 +
52591 + subjmap->next = *curr;
52592 + *curr = subjmap;
52593 +
52594 + return;
52595 +}
52596 +
52597 +static struct acl_role_label *
52598 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
52599 + const gid_t gid)
52600 +{
52601 + unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
52602 + struct acl_role_label *match;
52603 + struct role_allowed_ip *ipp;
52604 + unsigned int x;
52605 + u32 curr_ip = task->signal->curr_ip;
52606 +
52607 + task->signal->saved_ip = curr_ip;
52608 +
52609 + match = acl_role_set.r_hash[index];
52610 +
52611 + while (match) {
52612 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
52613 + for (x = 0; x < match->domain_child_num; x++) {
52614 + if (match->domain_children[x] == uid)
52615 + goto found;
52616 + }
52617 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
52618 + break;
52619 + match = match->next;
52620 + }
52621 +found:
52622 + if (match == NULL) {
52623 + try_group:
52624 + index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
52625 + match = acl_role_set.r_hash[index];
52626 +
52627 + while (match) {
52628 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
52629 + for (x = 0; x < match->domain_child_num; x++) {
52630 + if (match->domain_children[x] == gid)
52631 + goto found2;
52632 + }
52633 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
52634 + break;
52635 + match = match->next;
52636 + }
52637 +found2:
52638 + if (match == NULL)
52639 + match = default_role;
52640 + if (match->allowed_ips == NULL)
52641 + return match;
52642 + else {
52643 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
52644 + if (likely
52645 + ((ntohl(curr_ip) & ipp->netmask) ==
52646 + (ntohl(ipp->addr) & ipp->netmask)))
52647 + return match;
52648 + }
52649 + match = default_role;
52650 + }
52651 + } else if (match->allowed_ips == NULL) {
52652 + return match;
52653 + } else {
52654 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
52655 + if (likely
52656 + ((ntohl(curr_ip) & ipp->netmask) ==
52657 + (ntohl(ipp->addr) & ipp->netmask)))
52658 + return match;
52659 + }
52660 + goto try_group;
52661 + }
52662 +
52663 + return match;
52664 +}
52665 +
52666 +struct acl_subject_label *
52667 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
52668 + const struct acl_role_label *role)
52669 +{
52670 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
52671 + struct acl_subject_label *match;
52672 +
52673 + match = role->subj_hash[index];
52674 +
52675 + while (match && (match->inode != ino || match->device != dev ||
52676 + (match->mode & GR_DELETED))) {
52677 + match = match->next;
52678 + }
52679 +
52680 + if (match && !(match->mode & GR_DELETED))
52681 + return match;
52682 + else
52683 + return NULL;
52684 +}
52685 +
52686 +struct acl_subject_label *
52687 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
52688 + const struct acl_role_label *role)
52689 +{
52690 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
52691 + struct acl_subject_label *match;
52692 +
52693 + match = role->subj_hash[index];
52694 +
52695 + while (match && (match->inode != ino || match->device != dev ||
52696 + !(match->mode & GR_DELETED))) {
52697 + match = match->next;
52698 + }
52699 +
52700 + if (match && (match->mode & GR_DELETED))
52701 + return match;
52702 + else
52703 + return NULL;
52704 +}
52705 +
52706 +static struct acl_object_label *
52707 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
52708 + const struct acl_subject_label *subj)
52709 +{
52710 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
52711 + struct acl_object_label *match;
52712 +
52713 + match = subj->obj_hash[index];
52714 +
52715 + while (match && (match->inode != ino || match->device != dev ||
52716 + (match->mode & GR_DELETED))) {
52717 + match = match->next;
52718 + }
52719 +
52720 + if (match && !(match->mode & GR_DELETED))
52721 + return match;
52722 + else
52723 + return NULL;
52724 +}
52725 +
52726 +static struct acl_object_label *
52727 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
52728 + const struct acl_subject_label *subj)
52729 +{
52730 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
52731 + struct acl_object_label *match;
52732 +
52733 + match = subj->obj_hash[index];
52734 +
52735 + while (match && (match->inode != ino || match->device != dev ||
52736 + !(match->mode & GR_DELETED))) {
52737 + match = match->next;
52738 + }
52739 +
52740 + if (match && (match->mode & GR_DELETED))
52741 + return match;
52742 +
52743 + match = subj->obj_hash[index];
52744 +
52745 + while (match && (match->inode != ino || match->device != dev ||
52746 + (match->mode & GR_DELETED))) {
52747 + match = match->next;
52748 + }
52749 +
52750 + if (match && !(match->mode & GR_DELETED))
52751 + return match;
52752 + else
52753 + return NULL;
52754 +}
52755 +
52756 +static struct name_entry *
52757 +lookup_name_entry(const char *name)
52758 +{
52759 + unsigned int len = strlen(name);
52760 + unsigned int key = full_name_hash(name, len);
52761 + unsigned int index = key % name_set.n_size;
52762 + struct name_entry *match;
52763 +
52764 + match = name_set.n_hash[index];
52765 +
52766 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
52767 + match = match->next;
52768 +
52769 + return match;
52770 +}
52771 +
52772 +static struct name_entry *
52773 +lookup_name_entry_create(const char *name)
52774 +{
52775 + unsigned int len = strlen(name);
52776 + unsigned int key = full_name_hash(name, len);
52777 + unsigned int index = key % name_set.n_size;
52778 + struct name_entry *match;
52779 +
52780 + match = name_set.n_hash[index];
52781 +
52782 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
52783 + !match->deleted))
52784 + match = match->next;
52785 +
52786 + if (match && match->deleted)
52787 + return match;
52788 +
52789 + match = name_set.n_hash[index];
52790 +
52791 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
52792 + match->deleted))
52793 + match = match->next;
52794 +
52795 + if (match && !match->deleted)
52796 + return match;
52797 + else
52798 + return NULL;
52799 +}
52800 +
52801 +static struct inodev_entry *
52802 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
52803 +{
52804 + unsigned int index = fhash(ino, dev, inodev_set.i_size);
52805 + struct inodev_entry *match;
52806 +
52807 + match = inodev_set.i_hash[index];
52808 +
52809 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
52810 + match = match->next;
52811 +
52812 + return match;
52813 +}
52814 +
52815 +static void
52816 +insert_inodev_entry(struct inodev_entry *entry)
52817 +{
52818 + unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
52819 + inodev_set.i_size);
52820 + struct inodev_entry **curr;
52821 +
52822 + entry->prev = NULL;
52823 +
52824 + curr = &inodev_set.i_hash[index];
52825 + if (*curr != NULL)
52826 + (*curr)->prev = entry;
52827 +
52828 + entry->next = *curr;
52829 + *curr = entry;
52830 +
52831 + return;
52832 +}
52833 +
52834 +static void
52835 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
52836 +{
52837 + unsigned int index =
52838 + rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
52839 + struct acl_role_label **curr;
52840 + struct acl_role_label *tmp, *tmp2;
52841 +
52842 + curr = &acl_role_set.r_hash[index];
52843 +
52844 + /* simple case, slot is empty, just set it to our role */
52845 + if (*curr == NULL) {
52846 + *curr = role;
52847 + } else {
52848 + /* example:
52849 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
52850 + 2 -> 3
52851 + */
52852 + /* first check to see if we can already be reached via this slot */
52853 + tmp = *curr;
52854 + while (tmp && tmp != role)
52855 + tmp = tmp->next;
52856 + if (tmp == role) {
52857 + /* we don't need to add ourselves to this slot's chain */
52858 + return;
52859 + }
52860 + /* we need to add ourselves to this chain, two cases */
52861 + if (role->next == NULL) {
52862 + /* simple case, append the current chain to our role */
52863 + role->next = *curr;
52864 + *curr = role;
52865 + } else {
52866 + /* 1 -> 2 -> 3 -> 4
52867 + 2 -> 3 -> 4
52868 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
52869 + */
52870 + /* trickier case: walk our role's chain until we find
52871 + the role for the start of the current slot's chain */
52872 + tmp = role;
52873 + tmp2 = *curr;
52874 + while (tmp->next && tmp->next != tmp2)
52875 + tmp = tmp->next;
52876 + if (tmp->next == tmp2) {
52877 + /* from example above, we found 3, so just
52878 + replace this slot's chain with ours */
52879 + *curr = role;
52880 + } else {
52881 + /* we didn't find a subset of our role's chain
52882 + in the current slot's chain, so append their
52883 + chain to ours, and set us as the first role in
52884 + the slot's chain
52885 +
52886 + we could fold this case with the case above,
52887 + but making it explicit for clarity
52888 + */
52889 + tmp->next = tmp2;
52890 + *curr = role;
52891 + }
52892 + }
52893 + }
52894 +
52895 + return;
52896 +}
52897 +
52898 +static void
52899 +insert_acl_role_label(struct acl_role_label *role)
52900 +{
52901 + int i;
52902 +
52903 + if (role_list == NULL) {
52904 + role_list = role;
52905 + role->prev = NULL;
52906 + } else {
52907 + role->prev = role_list;
52908 + role_list = role;
52909 + }
52910 +
52911 + /* used for hash chains */
52912 + role->next = NULL;
52913 +
52914 + if (role->roletype & GR_ROLE_DOMAIN) {
52915 + for (i = 0; i < role->domain_child_num; i++)
52916 + __insert_acl_role_label(role, role->domain_children[i]);
52917 + } else
52918 + __insert_acl_role_label(role, role->uidgid);
52919 +}
52920 +
52921 +static int
52922 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
52923 +{
52924 + struct name_entry **curr, *nentry;
52925 + struct inodev_entry *ientry;
52926 + unsigned int len = strlen(name);
52927 + unsigned int key = full_name_hash(name, len);
52928 + unsigned int index = key % name_set.n_size;
52929 +
52930 + curr = &name_set.n_hash[index];
52931 +
52932 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
52933 + curr = &((*curr)->next);
52934 +
52935 + if (*curr != NULL)
52936 + return 1;
52937 +
52938 + nentry = acl_alloc(sizeof (struct name_entry));
52939 + if (nentry == NULL)
52940 + return 0;
52941 + ientry = acl_alloc(sizeof (struct inodev_entry));
52942 + if (ientry == NULL)
52943 + return 0;
52944 + ientry->nentry = nentry;
52945 +
52946 + nentry->key = key;
52947 + nentry->name = name;
52948 + nentry->inode = inode;
52949 + nentry->device = device;
52950 + nentry->len = len;
52951 + nentry->deleted = deleted;
52952 +
52953 + nentry->prev = NULL;
52954 + curr = &name_set.n_hash[index];
52955 + if (*curr != NULL)
52956 + (*curr)->prev = nentry;
52957 + nentry->next = *curr;
52958 + *curr = nentry;
52959 +
52960 + /* insert us into the table searchable by inode/dev */
52961 + insert_inodev_entry(ientry);
52962 +
52963 + return 1;
52964 +}
52965 +
52966 +static void
52967 +insert_acl_obj_label(struct acl_object_label *obj,
52968 + struct acl_subject_label *subj)
52969 +{
52970 + unsigned int index =
52971 + fhash(obj->inode, obj->device, subj->obj_hash_size);
52972 + struct acl_object_label **curr;
52973 +
52974 +
52975 + obj->prev = NULL;
52976 +
52977 + curr = &subj->obj_hash[index];
52978 + if (*curr != NULL)
52979 + (*curr)->prev = obj;
52980 +
52981 + obj->next = *curr;
52982 + *curr = obj;
52983 +
52984 + return;
52985 +}
52986 +
52987 +static void
52988 +insert_acl_subj_label(struct acl_subject_label *obj,
52989 + struct acl_role_label *role)
52990 +{
52991 + unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
52992 + struct acl_subject_label **curr;
52993 +
52994 + obj->prev = NULL;
52995 +
52996 + curr = &role->subj_hash[index];
52997 + if (*curr != NULL)
52998 + (*curr)->prev = obj;
52999 +
53000 + obj->next = *curr;
53001 + *curr = obj;
53002 +
53003 + return;
53004 +}
53005 +
53006 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
53007 +
53008 +static void *
53009 +create_table(__u32 * len, int elementsize)
53010 +{
53011 + unsigned int table_sizes[] = {
53012 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
53013 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
53014 + 4194301, 8388593, 16777213, 33554393, 67108859
53015 + };
53016 + void *newtable = NULL;
53017 + unsigned int pwr = 0;
53018 +
53019 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
53020 + table_sizes[pwr] <= *len)
53021 + pwr++;
53022 +
53023 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
53024 + return newtable;
53025 +
53026 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
53027 + newtable =
53028 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
53029 + else
53030 + newtable = vmalloc(table_sizes[pwr] * elementsize);
53031 +
53032 + *len = table_sizes[pwr];
53033 +
53034 + return newtable;
53035 +}
53036 +
53037 +static int
53038 +init_variables(const struct gr_arg *arg)
53039 +{
53040 + struct task_struct *reaper = init_pid_ns.child_reaper;
53041 + unsigned int stacksize;
53042 +
53043 + subj_map_set.s_size = arg->role_db.num_subjects;
53044 + acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
53045 + name_set.n_size = arg->role_db.num_objects;
53046 + inodev_set.i_size = arg->role_db.num_objects;
53047 +
53048 + if (!subj_map_set.s_size || !acl_role_set.r_size ||
53049 + !name_set.n_size || !inodev_set.i_size)
53050 + return 1;
53051 +
53052 + if (!gr_init_uidset())
53053 + return 1;
53054 +
53055 + /* set up the stack that holds allocation info */
53056 +
53057 + stacksize = arg->role_db.num_pointers + 5;
53058 +
53059 + if (!acl_alloc_stack_init(stacksize))
53060 + return 1;
53061 +
53062 + /* grab reference for the real root dentry and vfsmount */
53063 + get_fs_root(reaper->fs, &real_root);
53064 +
53065 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53066 + printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
53067 +#endif
53068 +
53069 + fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
53070 + if (fakefs_obj_rw == NULL)
53071 + return 1;
53072 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
53073 +
53074 + fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
53075 + if (fakefs_obj_rwx == NULL)
53076 + return 1;
53077 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
53078 +
53079 + subj_map_set.s_hash =
53080 + (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
53081 + acl_role_set.r_hash =
53082 + (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
53083 + name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
53084 + inodev_set.i_hash =
53085 + (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
53086 +
53087 + if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
53088 + !name_set.n_hash || !inodev_set.i_hash)
53089 + return 1;
53090 +
53091 + memset(subj_map_set.s_hash, 0,
53092 + sizeof(struct subject_map *) * subj_map_set.s_size);
53093 + memset(acl_role_set.r_hash, 0,
53094 + sizeof (struct acl_role_label *) * acl_role_set.r_size);
53095 + memset(name_set.n_hash, 0,
53096 + sizeof (struct name_entry *) * name_set.n_size);
53097 + memset(inodev_set.i_hash, 0,
53098 + sizeof (struct inodev_entry *) * inodev_set.i_size);
53099 +
53100 + return 0;
53101 +}
53102 +
53103 +/* free information not needed after startup
53104 + currently contains user->kernel pointer mappings for subjects
53105 +*/
53106 +
53107 +static void
53108 +free_init_variables(void)
53109 +{
53110 + __u32 i;
53111 +
53112 + if (subj_map_set.s_hash) {
53113 + for (i = 0; i < subj_map_set.s_size; i++) {
53114 + if (subj_map_set.s_hash[i]) {
53115 + kfree(subj_map_set.s_hash[i]);
53116 + subj_map_set.s_hash[i] = NULL;
53117 + }
53118 + }
53119 +
53120 + if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
53121 + PAGE_SIZE)
53122 + kfree(subj_map_set.s_hash);
53123 + else
53124 + vfree(subj_map_set.s_hash);
53125 + }
53126 +
53127 + return;
53128 +}
53129 +
53130 +static void
53131 +free_variables(void)
53132 +{
53133 + struct acl_subject_label *s;
53134 + struct acl_role_label *r;
53135 + struct task_struct *task, *task2;
53136 + unsigned int x;
53137 +
53138 + gr_clear_learn_entries();
53139 +
53140 + read_lock(&tasklist_lock);
53141 + do_each_thread(task2, task) {
53142 + task->acl_sp_role = 0;
53143 + task->acl_role_id = 0;
53144 + task->acl = NULL;
53145 + task->role = NULL;
53146 + } while_each_thread(task2, task);
53147 + read_unlock(&tasklist_lock);
53148 +
53149 + /* release the reference to the real root dentry and vfsmount */
53150 + path_put(&real_root);
53151 + memset(&real_root, 0, sizeof(real_root));
53152 +
53153 + /* free all object hash tables */
53154 +
53155 + FOR_EACH_ROLE_START(r)
53156 + if (r->subj_hash == NULL)
53157 + goto next_role;
53158 + FOR_EACH_SUBJECT_START(r, s, x)
53159 + if (s->obj_hash == NULL)
53160 + break;
53161 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
53162 + kfree(s->obj_hash);
53163 + else
53164 + vfree(s->obj_hash);
53165 + FOR_EACH_SUBJECT_END(s, x)
53166 + FOR_EACH_NESTED_SUBJECT_START(r, s)
53167 + if (s->obj_hash == NULL)
53168 + break;
53169 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
53170 + kfree(s->obj_hash);
53171 + else
53172 + vfree(s->obj_hash);
53173 + FOR_EACH_NESTED_SUBJECT_END(s)
53174 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
53175 + kfree(r->subj_hash);
53176 + else
53177 + vfree(r->subj_hash);
53178 + r->subj_hash = NULL;
53179 +next_role:
53180 + FOR_EACH_ROLE_END(r)
53181 +
53182 + acl_free_all();
53183 +
53184 + if (acl_role_set.r_hash) {
53185 + if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
53186 + PAGE_SIZE)
53187 + kfree(acl_role_set.r_hash);
53188 + else
53189 + vfree(acl_role_set.r_hash);
53190 + }
53191 + if (name_set.n_hash) {
53192 + if ((name_set.n_size * sizeof (struct name_entry *)) <=
53193 + PAGE_SIZE)
53194 + kfree(name_set.n_hash);
53195 + else
53196 + vfree(name_set.n_hash);
53197 + }
53198 +
53199 + if (inodev_set.i_hash) {
53200 + if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
53201 + PAGE_SIZE)
53202 + kfree(inodev_set.i_hash);
53203 + else
53204 + vfree(inodev_set.i_hash);
53205 + }
53206 +
53207 + gr_free_uidset();
53208 +
53209 + memset(&name_set, 0, sizeof (struct name_db));
53210 + memset(&inodev_set, 0, sizeof (struct inodev_db));
53211 + memset(&acl_role_set, 0, sizeof (struct acl_role_db));
53212 + memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
53213 +
53214 + default_role = NULL;
53215 + kernel_role = NULL;
53216 + role_list = NULL;
53217 +
53218 + return;
53219 +}
53220 +
53221 +static __u32
53222 +count_user_objs(struct acl_object_label *userp)
53223 +{
53224 + struct acl_object_label o_tmp;
53225 + __u32 num = 0;
53226 +
53227 + while (userp) {
53228 + if (copy_from_user(&o_tmp, userp,
53229 + sizeof (struct acl_object_label)))
53230 + break;
53231 +
53232 + userp = o_tmp.prev;
53233 + num++;
53234 + }
53235 +
53236 + return num;
53237 +}
53238 +
53239 +static struct acl_subject_label *
53240 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
53241 +
53242 +static int
53243 +copy_user_glob(struct acl_object_label *obj)
53244 +{
53245 + struct acl_object_label *g_tmp, **guser;
53246 + unsigned int len;
53247 + char *tmp;
53248 +
53249 + if (obj->globbed == NULL)
53250 + return 0;
53251 +
53252 + guser = &obj->globbed;
53253 + while (*guser) {
53254 + g_tmp = (struct acl_object_label *)
53255 + acl_alloc(sizeof (struct acl_object_label));
53256 + if (g_tmp == NULL)
53257 + return -ENOMEM;
53258 +
53259 + if (copy_from_user(g_tmp, *guser,
53260 + sizeof (struct acl_object_label)))
53261 + return -EFAULT;
53262 +
53263 + len = strnlen_user(g_tmp->filename, PATH_MAX);
53264 +
53265 + if (!len || len >= PATH_MAX)
53266 + return -EINVAL;
53267 +
53268 + if ((tmp = (char *) acl_alloc(len)) == NULL)
53269 + return -ENOMEM;
53270 +
53271 + if (copy_from_user(tmp, g_tmp->filename, len))
53272 + return -EFAULT;
53273 + tmp[len-1] = '\0';
53274 + g_tmp->filename = tmp;
53275 +
53276 + *guser = g_tmp;
53277 + guser = &(g_tmp->next);
53278 + }
53279 +
53280 + return 0;
53281 +}
53282 +
53283 +static int
53284 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
53285 + struct acl_role_label *role)
53286 +{
53287 + struct acl_object_label *o_tmp;
53288 + unsigned int len;
53289 + int ret;
53290 + char *tmp;
53291 +
53292 + while (userp) {
53293 + if ((o_tmp = (struct acl_object_label *)
53294 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
53295 + return -ENOMEM;
53296 +
53297 + if (copy_from_user(o_tmp, userp,
53298 + sizeof (struct acl_object_label)))
53299 + return -EFAULT;
53300 +
53301 + userp = o_tmp->prev;
53302 +
53303 + len = strnlen_user(o_tmp->filename, PATH_MAX);
53304 +
53305 + if (!len || len >= PATH_MAX)
53306 + return -EINVAL;
53307 +
53308 + if ((tmp = (char *) acl_alloc(len)) == NULL)
53309 + return -ENOMEM;
53310 +
53311 + if (copy_from_user(tmp, o_tmp->filename, len))
53312 + return -EFAULT;
53313 + tmp[len-1] = '\0';
53314 + o_tmp->filename = tmp;
53315 +
53316 + insert_acl_obj_label(o_tmp, subj);
53317 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
53318 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
53319 + return -ENOMEM;
53320 +
53321 + ret = copy_user_glob(o_tmp);
53322 + if (ret)
53323 + return ret;
53324 +
53325 + if (o_tmp->nested) {
53326 + int already_copied;
53327 +
53328 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
53329 + if (IS_ERR(o_tmp->nested))
53330 + return PTR_ERR(o_tmp->nested);
53331 +
53332 + /* insert into nested subject list if we haven't copied this one yet
53333 + to prevent duplicate entries */
53334 + if (!already_copied) {
53335 + o_tmp->nested->next = role->hash->first;
53336 + role->hash->first = o_tmp->nested;
53337 + }
53338 + }
53339 + }
53340 +
53341 + return 0;
53342 +}
53343 +
53344 +static __u32
53345 +count_user_subjs(struct acl_subject_label *userp)
53346 +{
53347 + struct acl_subject_label s_tmp;
53348 + __u32 num = 0;
53349 +
53350 + while (userp) {
53351 + if (copy_from_user(&s_tmp, userp,
53352 + sizeof (struct acl_subject_label)))
53353 + break;
53354 +
53355 + userp = s_tmp.prev;
53356 + /* do not count nested subjects against this count, since
53357 + they are not included in the hash table, but are
53358 + attached to objects. We have already counted
53359 + the subjects in userspace for the allocation
53360 + stack
53361 + */
53362 + if (!(s_tmp.mode & GR_NESTED))
53363 + num++;
53364 + }
53365 +
53366 + return num;
53367 +}
53368 +
53369 +static int
53370 +copy_user_allowedips(struct acl_role_label *rolep)
53371 +{
53372 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
53373 +
53374 + ruserip = rolep->allowed_ips;
53375 +
53376 + while (ruserip) {
53377 + rlast = rtmp;
53378 +
53379 + if ((rtmp = (struct role_allowed_ip *)
53380 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
53381 + return -ENOMEM;
53382 +
53383 + if (copy_from_user(rtmp, ruserip,
53384 + sizeof (struct role_allowed_ip)))
53385 + return -EFAULT;
53386 +
53387 + ruserip = rtmp->prev;
53388 +
53389 + if (!rlast) {
53390 + rtmp->prev = NULL;
53391 + rolep->allowed_ips = rtmp;
53392 + } else {
53393 + rlast->next = rtmp;
53394 + rtmp->prev = rlast;
53395 + }
53396 +
53397 + if (!ruserip)
53398 + rtmp->next = NULL;
53399 + }
53400 +
53401 + return 0;
53402 +}
53403 +
53404 +static int
53405 +copy_user_transitions(struct acl_role_label *rolep)
53406 +{
53407 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
53408 +
53409 + unsigned int len;
53410 + char *tmp;
53411 +
53412 + rusertp = rolep->transitions;
53413 +
53414 + while (rusertp) {
53415 + rlast = rtmp;
53416 +
53417 + if ((rtmp = (struct role_transition *)
53418 + acl_alloc(sizeof (struct role_transition))) == NULL)
53419 + return -ENOMEM;
53420 +
53421 + if (copy_from_user(rtmp, rusertp,
53422 + sizeof (struct role_transition)))
53423 + return -EFAULT;
53424 +
53425 + rusertp = rtmp->prev;
53426 +
53427 + len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
53428 +
53429 + if (!len || len >= GR_SPROLE_LEN)
53430 + return -EINVAL;
53431 +
53432 + if ((tmp = (char *) acl_alloc(len)) == NULL)
53433 + return -ENOMEM;
53434 +
53435 + if (copy_from_user(tmp, rtmp->rolename, len))
53436 + return -EFAULT;
53437 + tmp[len-1] = '\0';
53438 + rtmp->rolename = tmp;
53439 +
53440 + if (!rlast) {
53441 + rtmp->prev = NULL;
53442 + rolep->transitions = rtmp;
53443 + } else {
53444 + rlast->next = rtmp;
53445 + rtmp->prev = rlast;
53446 + }
53447 +
53448 + if (!rusertp)
53449 + rtmp->next = NULL;
53450 + }
53451 +
53452 + return 0;
53453 +}
53454 +
53455 +static struct acl_subject_label *
53456 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
53457 +{
53458 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
53459 + unsigned int len;
53460 + char *tmp;
53461 + __u32 num_objs;
53462 + struct acl_ip_label **i_tmp, *i_utmp2;
53463 + struct gr_hash_struct ghash;
53464 + struct subject_map *subjmap;
53465 + unsigned int i_num;
53466 + int err;
53467 +
53468 + if (already_copied != NULL)
53469 + *already_copied = 0;
53470 +
53471 + s_tmp = lookup_subject_map(userp);
53472 +
53473 + /* we've already copied this subject into the kernel, just return
53474 + the reference to it, and don't copy it over again
53475 + */
53476 + if (s_tmp) {
53477 + if (already_copied != NULL)
53478 + *already_copied = 1;
53479 + return(s_tmp);
53480 + }
53481 +
53482 + if ((s_tmp = (struct acl_subject_label *)
53483 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
53484 + return ERR_PTR(-ENOMEM);
53485 +
53486 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
53487 + if (subjmap == NULL)
53488 + return ERR_PTR(-ENOMEM);
53489 +
53490 + subjmap->user = userp;
53491 + subjmap->kernel = s_tmp;
53492 + insert_subj_map_entry(subjmap);
53493 +
53494 + if (copy_from_user(s_tmp, userp,
53495 + sizeof (struct acl_subject_label)))
53496 + return ERR_PTR(-EFAULT);
53497 +
53498 + len = strnlen_user(s_tmp->filename, PATH_MAX);
53499 +
53500 + if (!len || len >= PATH_MAX)
53501 + return ERR_PTR(-EINVAL);
53502 +
53503 + if ((tmp = (char *) acl_alloc(len)) == NULL)
53504 + return ERR_PTR(-ENOMEM);
53505 +
53506 + if (copy_from_user(tmp, s_tmp->filename, len))
53507 + return ERR_PTR(-EFAULT);
53508 + tmp[len-1] = '\0';
53509 + s_tmp->filename = tmp;
53510 +
53511 + if (!strcmp(s_tmp->filename, "/"))
53512 + role->root_label = s_tmp;
53513 +
53514 + if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
53515 + return ERR_PTR(-EFAULT);
53516 +
53517 + /* copy user and group transition tables */
53518 +
53519 + if (s_tmp->user_trans_num) {
53520 + uid_t *uidlist;
53521 +
53522 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
53523 + if (uidlist == NULL)
53524 + return ERR_PTR(-ENOMEM);
53525 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
53526 + return ERR_PTR(-EFAULT);
53527 +
53528 + s_tmp->user_transitions = uidlist;
53529 + }
53530 +
53531 + if (s_tmp->group_trans_num) {
53532 + gid_t *gidlist;
53533 +
53534 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
53535 + if (gidlist == NULL)
53536 + return ERR_PTR(-ENOMEM);
53537 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
53538 + return ERR_PTR(-EFAULT);
53539 +
53540 + s_tmp->group_transitions = gidlist;
53541 + }
53542 +
53543 + /* set up object hash table */
53544 + num_objs = count_user_objs(ghash.first);
53545 +
53546 + s_tmp->obj_hash_size = num_objs;
53547 + s_tmp->obj_hash =
53548 + (struct acl_object_label **)
53549 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
53550 +
53551 + if (!s_tmp->obj_hash)
53552 + return ERR_PTR(-ENOMEM);
53553 +
53554 + memset(s_tmp->obj_hash, 0,
53555 + s_tmp->obj_hash_size *
53556 + sizeof (struct acl_object_label *));
53557 +
53558 + /* add in objects */
53559 + err = copy_user_objs(ghash.first, s_tmp, role);
53560 +
53561 + if (err)
53562 + return ERR_PTR(err);
53563 +
53564 + /* set pointer for parent subject */
53565 + if (s_tmp->parent_subject) {
53566 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
53567 +
53568 + if (IS_ERR(s_tmp2))
53569 + return s_tmp2;
53570 +
53571 + s_tmp->parent_subject = s_tmp2;
53572 + }
53573 +
53574 + /* add in ip acls */
53575 +
53576 + if (!s_tmp->ip_num) {
53577 + s_tmp->ips = NULL;
53578 + goto insert;
53579 + }
53580 +
53581 + i_tmp =
53582 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
53583 + sizeof (struct acl_ip_label *));
53584 +
53585 + if (!i_tmp)
53586 + return ERR_PTR(-ENOMEM);
53587 +
53588 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
53589 + *(i_tmp + i_num) =
53590 + (struct acl_ip_label *)
53591 + acl_alloc(sizeof (struct acl_ip_label));
53592 + if (!*(i_tmp + i_num))
53593 + return ERR_PTR(-ENOMEM);
53594 +
53595 + if (copy_from_user
53596 + (&i_utmp2, s_tmp->ips + i_num,
53597 + sizeof (struct acl_ip_label *)))
53598 + return ERR_PTR(-EFAULT);
53599 +
53600 + if (copy_from_user
53601 + (*(i_tmp + i_num), i_utmp2,
53602 + sizeof (struct acl_ip_label)))
53603 + return ERR_PTR(-EFAULT);
53604 +
53605 + if ((*(i_tmp + i_num))->iface == NULL)
53606 + continue;
53607 +
53608 + len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
53609 + if (!len || len >= IFNAMSIZ)
53610 + return ERR_PTR(-EINVAL);
53611 + tmp = acl_alloc(len);
53612 + if (tmp == NULL)
53613 + return ERR_PTR(-ENOMEM);
53614 + if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
53615 + return ERR_PTR(-EFAULT);
53616 + (*(i_tmp + i_num))->iface = tmp;
53617 + }
53618 +
53619 + s_tmp->ips = i_tmp;
53620 +
53621 +insert:
53622 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
53623 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
53624 + return ERR_PTR(-ENOMEM);
53625 +
53626 + return s_tmp;
53627 +}
53628 +
53629 +static int
53630 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
53631 +{
53632 + struct acl_subject_label s_pre;
53633 + struct acl_subject_label * ret;
53634 + int err;
53635 +
53636 + while (userp) {
53637 + if (copy_from_user(&s_pre, userp,
53638 + sizeof (struct acl_subject_label)))
53639 + return -EFAULT;
53640 +
53641 + /* do not add nested subjects here, add
53642 + while parsing objects
53643 + */
53644 +
53645 + if (s_pre.mode & GR_NESTED) {
53646 + userp = s_pre.prev;
53647 + continue;
53648 + }
53649 +
53650 + ret = do_copy_user_subj(userp, role, NULL);
53651 +
53652 + err = PTR_ERR(ret);
53653 + if (IS_ERR(ret))
53654 + return err;
53655 +
53656 + insert_acl_subj_label(ret, role);
53657 +
53658 + userp = s_pre.prev;
53659 + }
53660 +
53661 + return 0;
53662 +}
53663 +
53664 +static int
53665 +copy_user_acl(struct gr_arg *arg)
53666 +{
53667 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
53668 + struct acl_subject_label *subj_list;
53669 + struct sprole_pw *sptmp;
53670 + struct gr_hash_struct *ghash;
53671 + uid_t *domainlist;
53672 + unsigned int r_num;
53673 + unsigned int len;
53674 + char *tmp;
53675 + int err = 0;
53676 + __u16 i;
53677 + __u32 num_subjs;
53678 +
53679 + /* we need a default and kernel role */
53680 + if (arg->role_db.num_roles < 2)
53681 + return -EINVAL;
53682 +
53683 + /* copy special role authentication info from userspace */
53684 +
53685 + num_sprole_pws = arg->num_sprole_pws;
53686 + acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
53687 +
53688 + if (!acl_special_roles && num_sprole_pws)
53689 + return -ENOMEM;
53690 +
53691 + for (i = 0; i < num_sprole_pws; i++) {
53692 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
53693 + if (!sptmp)
53694 + return -ENOMEM;
53695 + if (copy_from_user(sptmp, arg->sprole_pws + i,
53696 + sizeof (struct sprole_pw)))
53697 + return -EFAULT;
53698 +
53699 + len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
53700 +
53701 + if (!len || len >= GR_SPROLE_LEN)
53702 + return -EINVAL;
53703 +
53704 + if ((tmp = (char *) acl_alloc(len)) == NULL)
53705 + return -ENOMEM;
53706 +
53707 + if (copy_from_user(tmp, sptmp->rolename, len))
53708 + return -EFAULT;
53709 +
53710 + tmp[len-1] = '\0';
53711 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53712 + printk(KERN_ALERT "Copying special role %s\n", tmp);
53713 +#endif
53714 + sptmp->rolename = tmp;
53715 + acl_special_roles[i] = sptmp;
53716 + }
53717 +
53718 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
53719 +
53720 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
53721 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
53722 +
53723 + if (!r_tmp)
53724 + return -ENOMEM;
53725 +
53726 + if (copy_from_user(&r_utmp2, r_utmp + r_num,
53727 + sizeof (struct acl_role_label *)))
53728 + return -EFAULT;
53729 +
53730 + if (copy_from_user(r_tmp, r_utmp2,
53731 + sizeof (struct acl_role_label)))
53732 + return -EFAULT;
53733 +
53734 + len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
53735 +
53736 + if (!len || len >= PATH_MAX)
53737 + return -EINVAL;
53738 +
53739 + if ((tmp = (char *) acl_alloc(len)) == NULL)
53740 + return -ENOMEM;
53741 +
53742 + if (copy_from_user(tmp, r_tmp->rolename, len))
53743 + return -EFAULT;
53744 +
53745 + tmp[len-1] = '\0';
53746 + r_tmp->rolename = tmp;
53747 +
53748 + if (!strcmp(r_tmp->rolename, "default")
53749 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
53750 + default_role = r_tmp;
53751 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
53752 + kernel_role = r_tmp;
53753 + }
53754 +
53755 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
53756 + return -ENOMEM;
53757 +
53758 + if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
53759 + return -EFAULT;
53760 +
53761 + r_tmp->hash = ghash;
53762 +
53763 + num_subjs = count_user_subjs(r_tmp->hash->first);
53764 +
53765 + r_tmp->subj_hash_size = num_subjs;
53766 + r_tmp->subj_hash =
53767 + (struct acl_subject_label **)
53768 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
53769 +
53770 + if (!r_tmp->subj_hash)
53771 + return -ENOMEM;
53772 +
53773 + err = copy_user_allowedips(r_tmp);
53774 + if (err)
53775 + return err;
53776 +
53777 + /* copy domain info */
53778 + if (r_tmp->domain_children != NULL) {
53779 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
53780 + if (domainlist == NULL)
53781 + return -ENOMEM;
53782 +
53783 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
53784 + return -EFAULT;
53785 +
53786 + r_tmp->domain_children = domainlist;
53787 + }
53788 +
53789 + err = copy_user_transitions(r_tmp);
53790 + if (err)
53791 + return err;
53792 +
53793 + memset(r_tmp->subj_hash, 0,
53794 + r_tmp->subj_hash_size *
53795 + sizeof (struct acl_subject_label *));
53796 +
53797 + /* acquire the list of subjects, then NULL out
53798 + the list prior to parsing the subjects for this role,
53799 + as during this parsing the list is replaced with a list
53800 + of *nested* subjects for the role
53801 + */
53802 + subj_list = r_tmp->hash->first;
53803 +
53804 + /* set nested subject list to null */
53805 + r_tmp->hash->first = NULL;
53806 +
53807 + err = copy_user_subjs(subj_list, r_tmp);
53808 +
53809 + if (err)
53810 + return err;
53811 +
53812 + insert_acl_role_label(r_tmp);
53813 + }
53814 +
53815 + if (default_role == NULL || kernel_role == NULL)
53816 + return -EINVAL;
53817 +
53818 + return err;
53819 +}
53820 +
53821 +static int
53822 +gracl_init(struct gr_arg *args)
53823 +{
53824 + int error = 0;
53825 +
53826 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
53827 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
53828 +
53829 + if (init_variables(args)) {
53830 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
53831 + error = -ENOMEM;
53832 + free_variables();
53833 + goto out;
53834 + }
53835 +
53836 + error = copy_user_acl(args);
53837 + free_init_variables();
53838 + if (error) {
53839 + free_variables();
53840 + goto out;
53841 + }
53842 +
53843 + if ((error = gr_set_acls(0))) {
53844 + free_variables();
53845 + goto out;
53846 + }
53847 +
53848 + pax_open_kernel();
53849 + gr_status |= GR_READY;
53850 + pax_close_kernel();
53851 +
53852 + out:
53853 + return error;
53854 +}
53855 +
53856 +/* derived from glibc fnmatch() 0: match, 1: no match*/
53857 +
53858 +static int
53859 +glob_match(const char *p, const char *n)
53860 +{
53861 + char c;
53862 +
53863 + while ((c = *p++) != '\0') {
53864 + switch (c) {
53865 + case '?':
53866 + if (*n == '\0')
53867 + return 1;
53868 + else if (*n == '/')
53869 + return 1;
53870 + break;
53871 + case '\\':
53872 + if (*n != c)
53873 + return 1;
53874 + break;
53875 + case '*':
53876 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
53877 + if (*n == '/')
53878 + return 1;
53879 + else if (c == '?') {
53880 + if (*n == '\0')
53881 + return 1;
53882 + else
53883 + ++n;
53884 + }
53885 + }
53886 + if (c == '\0') {
53887 + return 0;
53888 + } else {
53889 + const char *endp;
53890 +
53891 + if ((endp = strchr(n, '/')) == NULL)
53892 + endp = n + strlen(n);
53893 +
53894 + if (c == '[') {
53895 + for (--p; n < endp; ++n)
53896 + if (!glob_match(p, n))
53897 + return 0;
53898 + } else if (c == '/') {
53899 + while (*n != '\0' && *n != '/')
53900 + ++n;
53901 + if (*n == '/' && !glob_match(p, n + 1))
53902 + return 0;
53903 + } else {
53904 + for (--p; n < endp; ++n)
53905 + if (*n == c && !glob_match(p, n))
53906 + return 0;
53907 + }
53908 +
53909 + return 1;
53910 + }
53911 + case '[':
53912 + {
53913 + int not;
53914 + char cold;
53915 +
53916 + if (*n == '\0' || *n == '/')
53917 + return 1;
53918 +
53919 + not = (*p == '!' || *p == '^');
53920 + if (not)
53921 + ++p;
53922 +
53923 + c = *p++;
53924 + for (;;) {
53925 + unsigned char fn = (unsigned char)*n;
53926 +
53927 + if (c == '\0')
53928 + return 1;
53929 + else {
53930 + if (c == fn)
53931 + goto matched;
53932 + cold = c;
53933 + c = *p++;
53934 +
53935 + if (c == '-' && *p != ']') {
53936 + unsigned char cend = *p++;
53937 +
53938 + if (cend == '\0')
53939 + return 1;
53940 +
53941 + if (cold <= fn && fn <= cend)
53942 + goto matched;
53943 +
53944 + c = *p++;
53945 + }
53946 + }
53947 +
53948 + if (c == ']')
53949 + break;
53950 + }
53951 + if (!not)
53952 + return 1;
53953 + break;
53954 + matched:
53955 + while (c != ']') {
53956 + if (c == '\0')
53957 + return 1;
53958 +
53959 + c = *p++;
53960 + }
53961 + if (not)
53962 + return 1;
53963 + }
53964 + break;
53965 + default:
53966 + if (c != *n)
53967 + return 1;
53968 + }
53969 +
53970 + ++n;
53971 + }
53972 +
53973 + if (*n == '\0')
53974 + return 0;
53975 +
53976 + if (*n == '/')
53977 + return 0;
53978 +
53979 + return 1;
53980 +}
53981 +
53982 +static struct acl_object_label *
53983 +chk_glob_label(struct acl_object_label *globbed,
53984 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
53985 +{
53986 + struct acl_object_label *tmp;
53987 +
53988 + if (*path == NULL)
53989 + *path = gr_to_filename_nolock(dentry, mnt);
53990 +
53991 + tmp = globbed;
53992 +
53993 + while (tmp) {
53994 + if (!glob_match(tmp->filename, *path))
53995 + return tmp;
53996 + tmp = tmp->next;
53997 + }
53998 +
53999 + return NULL;
54000 +}
54001 +
54002 +static struct acl_object_label *
54003 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
54004 + const ino_t curr_ino, const dev_t curr_dev,
54005 + const struct acl_subject_label *subj, char **path, const int checkglob)
54006 +{
54007 + struct acl_subject_label *tmpsubj;
54008 + struct acl_object_label *retval;
54009 + struct acl_object_label *retval2;
54010 +
54011 + tmpsubj = (struct acl_subject_label *) subj;
54012 + read_lock(&gr_inode_lock);
54013 + do {
54014 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
54015 + if (retval) {
54016 + if (checkglob && retval->globbed) {
54017 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
54018 + if (retval2)
54019 + retval = retval2;
54020 + }
54021 + break;
54022 + }
54023 + } while ((tmpsubj = tmpsubj->parent_subject));
54024 + read_unlock(&gr_inode_lock);
54025 +
54026 + return retval;
54027 +}
54028 +
54029 +static __inline__ struct acl_object_label *
54030 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
54031 + struct dentry *curr_dentry,
54032 + const struct acl_subject_label *subj, char **path, const int checkglob)
54033 +{
54034 + int newglob = checkglob;
54035 + ino_t inode;
54036 + dev_t device;
54037 +
54038 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
54039 + as we don't want a / * rule to match instead of the / object
54040 + don't do this for create lookups that call this function though, since they're looking up
54041 + on the parent and thus need globbing checks on all paths
54042 + */
54043 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
54044 + newglob = GR_NO_GLOB;
54045 +
54046 + spin_lock(&curr_dentry->d_lock);
54047 + inode = curr_dentry->d_inode->i_ino;
54048 + device = __get_dev(curr_dentry);
54049 + spin_unlock(&curr_dentry->d_lock);
54050 +
54051 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
54052 +}
54053 +
54054 +static struct acl_object_label *
54055 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
54056 + const struct acl_subject_label *subj, char *path, const int checkglob)
54057 +{
54058 + struct dentry *dentry = (struct dentry *) l_dentry;
54059 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
54060 + struct mount *real_mnt = real_mount(mnt);
54061 + struct acl_object_label *retval;
54062 + struct dentry *parent;
54063 +
54064 + write_seqlock(&rename_lock);
54065 + br_read_lock(&vfsmount_lock);
54066 +
54067 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
54068 +#ifdef CONFIG_NET
54069 + mnt == sock_mnt ||
54070 +#endif
54071 +#ifdef CONFIG_HUGETLBFS
54072 + (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
54073 +#endif
54074 + /* ignore Eric Biederman */
54075 + IS_PRIVATE(l_dentry->d_inode))) {
54076 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
54077 + goto out;
54078 + }
54079 +
54080 + for (;;) {
54081 + if (dentry == real_root.dentry && mnt == real_root.mnt)
54082 + break;
54083 +
54084 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
54085 + if (!mnt_has_parent(real_mnt))
54086 + break;
54087 +
54088 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
54089 + if (retval != NULL)
54090 + goto out;
54091 +
54092 + dentry = real_mnt->mnt_mountpoint;
54093 + real_mnt = real_mnt->mnt_parent;
54094 + mnt = &real_mnt->mnt;
54095 + continue;
54096 + }
54097 +
54098 + parent = dentry->d_parent;
54099 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
54100 + if (retval != NULL)
54101 + goto out;
54102 +
54103 + dentry = parent;
54104 + }
54105 +
54106 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
54107 +
54108 + /* real_root is pinned so we don't have to hold a reference */
54109 + if (retval == NULL)
54110 + retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
54111 +out:
54112 + br_read_unlock(&vfsmount_lock);
54113 + write_sequnlock(&rename_lock);
54114 +
54115 + BUG_ON(retval == NULL);
54116 +
54117 + return retval;
54118 +}
54119 +
54120 +static __inline__ struct acl_object_label *
54121 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
54122 + const struct acl_subject_label *subj)
54123 +{
54124 + char *path = NULL;
54125 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
54126 +}
54127 +
54128 +static __inline__ struct acl_object_label *
54129 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
54130 + const struct acl_subject_label *subj)
54131 +{
54132 + char *path = NULL;
54133 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
54134 +}
54135 +
54136 +static __inline__ struct acl_object_label *
54137 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
54138 + const struct acl_subject_label *subj, char *path)
54139 +{
54140 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
54141 +}
54142 +
54143 +static struct acl_subject_label *
54144 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
54145 + const struct acl_role_label *role)
54146 +{
54147 + struct dentry *dentry = (struct dentry *) l_dentry;
54148 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
54149 + struct mount *real_mnt = real_mount(mnt);
54150 + struct acl_subject_label *retval;
54151 + struct dentry *parent;
54152 +
54153 + write_seqlock(&rename_lock);
54154 + br_read_lock(&vfsmount_lock);
54155 +
54156 + for (;;) {
54157 + if (dentry == real_root.dentry && mnt == real_root.mnt)
54158 + break;
54159 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
54160 + if (!mnt_has_parent(real_mnt))
54161 + break;
54162 +
54163 + spin_lock(&dentry->d_lock);
54164 + read_lock(&gr_inode_lock);
54165 + retval =
54166 + lookup_acl_subj_label(dentry->d_inode->i_ino,
54167 + __get_dev(dentry), role);
54168 + read_unlock(&gr_inode_lock);
54169 + spin_unlock(&dentry->d_lock);
54170 + if (retval != NULL)
54171 + goto out;
54172 +
54173 + dentry = real_mnt->mnt_mountpoint;
54174 + real_mnt = real_mnt->mnt_parent;
54175 + mnt = &real_mnt->mnt;
54176 + continue;
54177 + }
54178 +
54179 + spin_lock(&dentry->d_lock);
54180 + read_lock(&gr_inode_lock);
54181 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
54182 + __get_dev(dentry), role);
54183 + read_unlock(&gr_inode_lock);
54184 + parent = dentry->d_parent;
54185 + spin_unlock(&dentry->d_lock);
54186 +
54187 + if (retval != NULL)
54188 + goto out;
54189 +
54190 + dentry = parent;
54191 + }
54192 +
54193 + spin_lock(&dentry->d_lock);
54194 + read_lock(&gr_inode_lock);
54195 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
54196 + __get_dev(dentry), role);
54197 + read_unlock(&gr_inode_lock);
54198 + spin_unlock(&dentry->d_lock);
54199 +
54200 + if (unlikely(retval == NULL)) {
54201 + /* real_root is pinned, we don't need to hold a reference */
54202 + read_lock(&gr_inode_lock);
54203 + retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
54204 + __get_dev(real_root.dentry), role);
54205 + read_unlock(&gr_inode_lock);
54206 + }
54207 +out:
54208 + br_read_unlock(&vfsmount_lock);
54209 + write_sequnlock(&rename_lock);
54210 +
54211 + BUG_ON(retval == NULL);
54212 +
54213 + return retval;
54214 +}
54215 +
54216 +static void
54217 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
54218 +{
54219 + struct task_struct *task = current;
54220 + const struct cred *cred = current_cred();
54221 +
54222 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
54223 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
54224 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
54225 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
54226 +
54227 + return;
54228 +}
54229 +
54230 +static void
54231 +gr_log_learn_id_change(const char type, const unsigned int real,
54232 + const unsigned int effective, const unsigned int fs)
54233 +{
54234 + struct task_struct *task = current;
54235 + const struct cred *cred = current_cred();
54236 +
54237 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
54238 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
54239 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
54240 + type, real, effective, fs, &task->signal->saved_ip);
54241 +
54242 + return;
54243 +}
54244 +
54245 +__u32
54246 +gr_search_file(const struct dentry * dentry, const __u32 mode,
54247 + const struct vfsmount * mnt)
54248 +{
54249 + __u32 retval = mode;
54250 + struct acl_subject_label *curracl;
54251 + struct acl_object_label *currobj;
54252 +
54253 + if (unlikely(!(gr_status & GR_READY)))
54254 + return (mode & ~GR_AUDITS);
54255 +
54256 + curracl = current->acl;
54257 +
54258 + currobj = chk_obj_label(dentry, mnt, curracl);
54259 + retval = currobj->mode & mode;
54260 +
54261 + /* if we're opening a specified transfer file for writing
54262 + (e.g. /dev/initctl), then transfer our role to init
54263 + */
54264 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
54265 + current->role->roletype & GR_ROLE_PERSIST)) {
54266 + struct task_struct *task = init_pid_ns.child_reaper;
54267 +
54268 + if (task->role != current->role) {
54269 + task->acl_sp_role = 0;
54270 + task->acl_role_id = current->acl_role_id;
54271 + task->role = current->role;
54272 + rcu_read_lock();
54273 + read_lock(&grsec_exec_file_lock);
54274 + gr_apply_subject_to_task(task);
54275 + read_unlock(&grsec_exec_file_lock);
54276 + rcu_read_unlock();
54277 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
54278 + }
54279 + }
54280 +
54281 + if (unlikely
54282 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
54283 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
54284 + __u32 new_mode = mode;
54285 +
54286 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
54287 +
54288 + retval = new_mode;
54289 +
54290 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
54291 + new_mode |= GR_INHERIT;
54292 +
54293 + if (!(mode & GR_NOLEARN))
54294 + gr_log_learn(dentry, mnt, new_mode);
54295 + }
54296 +
54297 + return retval;
54298 +}
54299 +
54300 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
54301 + const struct dentry *parent,
54302 + const struct vfsmount *mnt)
54303 +{
54304 + struct name_entry *match;
54305 + struct acl_object_label *matchpo;
54306 + struct acl_subject_label *curracl;
54307 + char *path;
54308 +
54309 + if (unlikely(!(gr_status & GR_READY)))
54310 + return NULL;
54311 +
54312 + preempt_disable();
54313 + path = gr_to_filename_rbac(new_dentry, mnt);
54314 + match = lookup_name_entry_create(path);
54315 +
54316 + curracl = current->acl;
54317 +
54318 + if (match) {
54319 + read_lock(&gr_inode_lock);
54320 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
54321 + read_unlock(&gr_inode_lock);
54322 +
54323 + if (matchpo) {
54324 + preempt_enable();
54325 + return matchpo;
54326 + }
54327 + }
54328 +
54329 + // lookup parent
54330 +
54331 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
54332 +
54333 + preempt_enable();
54334 + return matchpo;
54335 +}
54336 +
54337 +__u32
54338 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
54339 + const struct vfsmount * mnt, const __u32 mode)
54340 +{
54341 + struct acl_object_label *matchpo;
54342 + __u32 retval;
54343 +
54344 + if (unlikely(!(gr_status & GR_READY)))
54345 + return (mode & ~GR_AUDITS);
54346 +
54347 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
54348 +
54349 + retval = matchpo->mode & mode;
54350 +
54351 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
54352 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
54353 + __u32 new_mode = mode;
54354 +
54355 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
54356 +
54357 + gr_log_learn(new_dentry, mnt, new_mode);
54358 + return new_mode;
54359 + }
54360 +
54361 + return retval;
54362 +}
54363 +
54364 +__u32
54365 +gr_check_link(const struct dentry * new_dentry,
54366 + const struct dentry * parent_dentry,
54367 + const struct vfsmount * parent_mnt,
54368 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
54369 +{
54370 + struct acl_object_label *obj;
54371 + __u32 oldmode, newmode;
54372 + __u32 needmode;
54373 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
54374 + GR_DELETE | GR_INHERIT;
54375 +
54376 + if (unlikely(!(gr_status & GR_READY)))
54377 + return (GR_CREATE | GR_LINK);
54378 +
54379 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
54380 + oldmode = obj->mode;
54381 +
54382 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
54383 + newmode = obj->mode;
54384 +
54385 + needmode = newmode & checkmodes;
54386 +
54387 + // old name for hardlink must have at least the permissions of the new name
54388 + if ((oldmode & needmode) != needmode)
54389 + goto bad;
54390 +
54391 + // if old name had restrictions/auditing, make sure the new name does as well
54392 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
54393 +
54394 + // don't allow hardlinking of suid/sgid/fcapped files without permission
54395 + if (is_privileged_binary(old_dentry))
54396 + needmode |= GR_SETID;
54397 +
54398 + if ((newmode & needmode) != needmode)
54399 + goto bad;
54400 +
54401 + // enforce minimum permissions
54402 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
54403 + return newmode;
54404 +bad:
54405 + needmode = oldmode;
54406 + if (is_privileged_binary(old_dentry))
54407 + needmode |= GR_SETID;
54408 +
54409 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
54410 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
54411 + return (GR_CREATE | GR_LINK);
54412 + } else if (newmode & GR_SUPPRESS)
54413 + return GR_SUPPRESS;
54414 + else
54415 + return 0;
54416 +}
54417 +
54418 +int
54419 +gr_check_hidden_task(const struct task_struct *task)
54420 +{
54421 + if (unlikely(!(gr_status & GR_READY)))
54422 + return 0;
54423 +
54424 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
54425 + return 1;
54426 +
54427 + return 0;
54428 +}
54429 +
54430 +int
54431 +gr_check_protected_task(const struct task_struct *task)
54432 +{
54433 + if (unlikely(!(gr_status & GR_READY) || !task))
54434 + return 0;
54435 +
54436 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
54437 + task->acl != current->acl)
54438 + return 1;
54439 +
54440 + return 0;
54441 +}
54442 +
54443 +int
54444 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
54445 +{
54446 + struct task_struct *p;
54447 + int ret = 0;
54448 +
54449 + if (unlikely(!(gr_status & GR_READY) || !pid))
54450 + return ret;
54451 +
54452 + read_lock(&tasklist_lock);
54453 + do_each_pid_task(pid, type, p) {
54454 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
54455 + p->acl != current->acl) {
54456 + ret = 1;
54457 + goto out;
54458 + }
54459 + } while_each_pid_task(pid, type, p);
54460 +out:
54461 + read_unlock(&tasklist_lock);
54462 +
54463 + return ret;
54464 +}
54465 +
54466 +void
54467 +gr_copy_label(struct task_struct *tsk)
54468 +{
54469 + tsk->signal->used_accept = 0;
54470 + tsk->acl_sp_role = 0;
54471 + tsk->acl_role_id = current->acl_role_id;
54472 + tsk->acl = current->acl;
54473 + tsk->role = current->role;
54474 + tsk->signal->curr_ip = current->signal->curr_ip;
54475 + tsk->signal->saved_ip = current->signal->saved_ip;
54476 + if (current->exec_file)
54477 + get_file(current->exec_file);
54478 + tsk->exec_file = current->exec_file;
54479 + tsk->is_writable = current->is_writable;
54480 + if (unlikely(current->signal->used_accept)) {
54481 + current->signal->curr_ip = 0;
54482 + current->signal->saved_ip = 0;
54483 + }
54484 +
54485 + return;
54486 +}
54487 +
54488 +static void
54489 +gr_set_proc_res(struct task_struct *task)
54490 +{
54491 + struct acl_subject_label *proc;
54492 + unsigned short i;
54493 +
54494 + proc = task->acl;
54495 +
54496 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
54497 + return;
54498 +
54499 + for (i = 0; i < RLIM_NLIMITS; i++) {
54500 + if (!(proc->resmask & (1 << i)))
54501 + continue;
54502 +
54503 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
54504 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
54505 + }
54506 +
54507 + return;
54508 +}
54509 +
54510 +extern int __gr_process_user_ban(struct user_struct *user);
54511 +
54512 +int
54513 +gr_check_user_change(int real, int effective, int fs)
54514 +{
54515 + unsigned int i;
54516 + __u16 num;
54517 + uid_t *uidlist;
54518 + int curuid;
54519 + int realok = 0;
54520 + int effectiveok = 0;
54521 + int fsok = 0;
54522 +
54523 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
54524 + struct user_struct *user;
54525 +
54526 + if (real == -1)
54527 + goto skipit;
54528 +
54529 + user = find_user(real);
54530 + if (user == NULL)
54531 + goto skipit;
54532 +
54533 + if (__gr_process_user_ban(user)) {
54534 + /* for find_user */
54535 + free_uid(user);
54536 + return 1;
54537 + }
54538 +
54539 + /* for find_user */
54540 + free_uid(user);
54541 +
54542 +skipit:
54543 +#endif
54544 +
54545 + if (unlikely(!(gr_status & GR_READY)))
54546 + return 0;
54547 +
54548 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
54549 + gr_log_learn_id_change('u', real, effective, fs);
54550 +
54551 + num = current->acl->user_trans_num;
54552 + uidlist = current->acl->user_transitions;
54553 +
54554 + if (uidlist == NULL)
54555 + return 0;
54556 +
54557 + if (real == -1)
54558 + realok = 1;
54559 + if (effective == -1)
54560 + effectiveok = 1;
54561 + if (fs == -1)
54562 + fsok = 1;
54563 +
54564 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
54565 + for (i = 0; i < num; i++) {
54566 + curuid = (int)uidlist[i];
54567 + if (real == curuid)
54568 + realok = 1;
54569 + if (effective == curuid)
54570 + effectiveok = 1;
54571 + if (fs == curuid)
54572 + fsok = 1;
54573 + }
54574 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
54575 + for (i = 0; i < num; i++) {
54576 + curuid = (int)uidlist[i];
54577 + if (real == curuid)
54578 + break;
54579 + if (effective == curuid)
54580 + break;
54581 + if (fs == curuid)
54582 + break;
54583 + }
54584 + /* not in deny list */
54585 + if (i == num) {
54586 + realok = 1;
54587 + effectiveok = 1;
54588 + fsok = 1;
54589 + }
54590 + }
54591 +
54592 + if (realok && effectiveok && fsok)
54593 + return 0;
54594 + else {
54595 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
54596 + return 1;
54597 + }
54598 +}
54599 +
54600 +int
54601 +gr_check_group_change(int real, int effective, int fs)
54602 +{
54603 + unsigned int i;
54604 + __u16 num;
54605 + gid_t *gidlist;
54606 + int curgid;
54607 + int realok = 0;
54608 + int effectiveok = 0;
54609 + int fsok = 0;
54610 +
54611 + if (unlikely(!(gr_status & GR_READY)))
54612 + return 0;
54613 +
54614 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
54615 + gr_log_learn_id_change('g', real, effective, fs);
54616 +
54617 + num = current->acl->group_trans_num;
54618 + gidlist = current->acl->group_transitions;
54619 +
54620 + if (gidlist == NULL)
54621 + return 0;
54622 +
54623 + if (real == -1)
54624 + realok = 1;
54625 + if (effective == -1)
54626 + effectiveok = 1;
54627 + if (fs == -1)
54628 + fsok = 1;
54629 +
54630 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
54631 + for (i = 0; i < num; i++) {
54632 + curgid = (int)gidlist[i];
54633 + if (real == curgid)
54634 + realok = 1;
54635 + if (effective == curgid)
54636 + effectiveok = 1;
54637 + if (fs == curgid)
54638 + fsok = 1;
54639 + }
54640 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
54641 + for (i = 0; i < num; i++) {
54642 + curgid = (int)gidlist[i];
54643 + if (real == curgid)
54644 + break;
54645 + if (effective == curgid)
54646 + break;
54647 + if (fs == curgid)
54648 + break;
54649 + }
54650 + /* not in deny list */
54651 + if (i == num) {
54652 + realok = 1;
54653 + effectiveok = 1;
54654 + fsok = 1;
54655 + }
54656 + }
54657 +
54658 + if (realok && effectiveok && fsok)
54659 + return 0;
54660 + else {
54661 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
54662 + return 1;
54663 + }
54664 +}
54665 +
54666 +extern int gr_acl_is_capable(const int cap);
54667 +
54668 +void
54669 +gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
54670 +{
54671 + struct acl_role_label *role = task->role;
54672 + struct acl_subject_label *subj = NULL;
54673 + struct acl_object_label *obj;
54674 + struct file *filp;
54675 +
54676 + if (unlikely(!(gr_status & GR_READY)))
54677 + return;
54678 +
54679 + filp = task->exec_file;
54680 +
54681 + /* kernel process, we'll give them the kernel role */
54682 + if (unlikely(!filp)) {
54683 + task->role = kernel_role;
54684 + task->acl = kernel_role->root_label;
54685 + return;
54686 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
54687 + role = lookup_acl_role_label(task, uid, gid);
54688 +
54689 + /* don't change the role if we're not a privileged process */
54690 + if (role && task->role != role &&
54691 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
54692 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
54693 + return;
54694 +
54695 + /* perform subject lookup in possibly new role
54696 + we can use this result below in the case where role == task->role
54697 + */
54698 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
54699 +
54700 + /* if we changed uid/gid, but result in the same role
54701 + and are using inheritance, don't lose the inherited subject
54702 + if current subject is other than what normal lookup
54703 + would result in, we arrived via inheritance, don't
54704 + lose subject
54705 + */
54706 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
54707 + (subj == task->acl)))
54708 + task->acl = subj;
54709 +
54710 + task->role = role;
54711 +
54712 + task->is_writable = 0;
54713 +
54714 + /* ignore additional mmap checks for processes that are writable
54715 + by the default ACL */
54716 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54717 + if (unlikely(obj->mode & GR_WRITE))
54718 + task->is_writable = 1;
54719 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
54720 + if (unlikely(obj->mode & GR_WRITE))
54721 + task->is_writable = 1;
54722 +
54723 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54724 + printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54725 +#endif
54726 +
54727 + gr_set_proc_res(task);
54728 +
54729 + return;
54730 +}
54731 +
54732 +int
54733 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
54734 + const int unsafe_flags)
54735 +{
54736 + struct task_struct *task = current;
54737 + struct acl_subject_label *newacl;
54738 + struct acl_object_label *obj;
54739 + __u32 retmode;
54740 +
54741 + if (unlikely(!(gr_status & GR_READY)))
54742 + return 0;
54743 +
54744 + newacl = chk_subj_label(dentry, mnt, task->role);
54745 +
54746 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
54747 + did an exec
54748 + */
54749 + rcu_read_lock();
54750 + read_lock(&tasklist_lock);
54751 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
54752 + (task->parent->acl->mode & GR_POVERRIDE))) {
54753 + read_unlock(&tasklist_lock);
54754 + rcu_read_unlock();
54755 + goto skip_check;
54756 + }
54757 + read_unlock(&tasklist_lock);
54758 + rcu_read_unlock();
54759 +
54760 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
54761 + !(task->role->roletype & GR_ROLE_GOD) &&
54762 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
54763 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
54764 + if (unsafe_flags & LSM_UNSAFE_SHARE)
54765 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
54766 + else
54767 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
54768 + return -EACCES;
54769 + }
54770 +
54771 +skip_check:
54772 +
54773 + obj = chk_obj_label(dentry, mnt, task->acl);
54774 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
54775 +
54776 + if (!(task->acl->mode & GR_INHERITLEARN) &&
54777 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
54778 + if (obj->nested)
54779 + task->acl = obj->nested;
54780 + else
54781 + task->acl = newacl;
54782 + } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
54783 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
54784 +
54785 + task->is_writable = 0;
54786 +
54787 + /* ignore additional mmap checks for processes that are writable
54788 + by the default ACL */
54789 + obj = chk_obj_label(dentry, mnt, default_role->root_label);
54790 + if (unlikely(obj->mode & GR_WRITE))
54791 + task->is_writable = 1;
54792 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
54793 + if (unlikely(obj->mode & GR_WRITE))
54794 + task->is_writable = 1;
54795 +
54796 + gr_set_proc_res(task);
54797 +
54798 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54799 + printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54800 +#endif
54801 + return 0;
54802 +}
54803 +
54804 +/* always called with valid inodev ptr */
54805 +static void
54806 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
54807 +{
54808 + struct acl_object_label *matchpo;
54809 + struct acl_subject_label *matchps;
54810 + struct acl_subject_label *subj;
54811 + struct acl_role_label *role;
54812 + unsigned int x;
54813 +
54814 + FOR_EACH_ROLE_START(role)
54815 + FOR_EACH_SUBJECT_START(role, subj, x)
54816 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
54817 + matchpo->mode |= GR_DELETED;
54818 + FOR_EACH_SUBJECT_END(subj,x)
54819 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
54820 + /* nested subjects aren't in the role's subj_hash table */
54821 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
54822 + matchpo->mode |= GR_DELETED;
54823 + FOR_EACH_NESTED_SUBJECT_END(subj)
54824 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
54825 + matchps->mode |= GR_DELETED;
54826 + FOR_EACH_ROLE_END(role)
54827 +
54828 + inodev->nentry->deleted = 1;
54829 +
54830 + return;
54831 +}
54832 +
54833 +void
54834 +gr_handle_delete(const ino_t ino, const dev_t dev)
54835 +{
54836 + struct inodev_entry *inodev;
54837 +
54838 + if (unlikely(!(gr_status & GR_READY)))
54839 + return;
54840 +
54841 + write_lock(&gr_inode_lock);
54842 + inodev = lookup_inodev_entry(ino, dev);
54843 + if (inodev != NULL)
54844 + do_handle_delete(inodev, ino, dev);
54845 + write_unlock(&gr_inode_lock);
54846 +
54847 + return;
54848 +}
54849 +
54850 +static void
54851 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
54852 + const ino_t newinode, const dev_t newdevice,
54853 + struct acl_subject_label *subj)
54854 +{
54855 + unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
54856 + struct acl_object_label *match;
54857 +
54858 + match = subj->obj_hash[index];
54859 +
54860 + while (match && (match->inode != oldinode ||
54861 + match->device != olddevice ||
54862 + !(match->mode & GR_DELETED)))
54863 + match = match->next;
54864 +
54865 + if (match && (match->inode == oldinode)
54866 + && (match->device == olddevice)
54867 + && (match->mode & GR_DELETED)) {
54868 + if (match->prev == NULL) {
54869 + subj->obj_hash[index] = match->next;
54870 + if (match->next != NULL)
54871 + match->next->prev = NULL;
54872 + } else {
54873 + match->prev->next = match->next;
54874 + if (match->next != NULL)
54875 + match->next->prev = match->prev;
54876 + }
54877 + match->prev = NULL;
54878 + match->next = NULL;
54879 + match->inode = newinode;
54880 + match->device = newdevice;
54881 + match->mode &= ~GR_DELETED;
54882 +
54883 + insert_acl_obj_label(match, subj);
54884 + }
54885 +
54886 + return;
54887 +}
54888 +
54889 +static void
54890 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
54891 + const ino_t newinode, const dev_t newdevice,
54892 + struct acl_role_label *role)
54893 +{
54894 + unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
54895 + struct acl_subject_label *match;
54896 +
54897 + match = role->subj_hash[index];
54898 +
54899 + while (match && (match->inode != oldinode ||
54900 + match->device != olddevice ||
54901 + !(match->mode & GR_DELETED)))
54902 + match = match->next;
54903 +
54904 + if (match && (match->inode == oldinode)
54905 + && (match->device == olddevice)
54906 + && (match->mode & GR_DELETED)) {
54907 + if (match->prev == NULL) {
54908 + role->subj_hash[index] = match->next;
54909 + if (match->next != NULL)
54910 + match->next->prev = NULL;
54911 + } else {
54912 + match->prev->next = match->next;
54913 + if (match->next != NULL)
54914 + match->next->prev = match->prev;
54915 + }
54916 + match->prev = NULL;
54917 + match->next = NULL;
54918 + match->inode = newinode;
54919 + match->device = newdevice;
54920 + match->mode &= ~GR_DELETED;
54921 +
54922 + insert_acl_subj_label(match, role);
54923 + }
54924 +
54925 + return;
54926 +}
54927 +
54928 +static void
54929 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
54930 + const ino_t newinode, const dev_t newdevice)
54931 +{
54932 + unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
54933 + struct inodev_entry *match;
54934 +
54935 + match = inodev_set.i_hash[index];
54936 +
54937 + while (match && (match->nentry->inode != oldinode ||
54938 + match->nentry->device != olddevice || !match->nentry->deleted))
54939 + match = match->next;
54940 +
54941 + if (match && (match->nentry->inode == oldinode)
54942 + && (match->nentry->device == olddevice) &&
54943 + match->nentry->deleted) {
54944 + if (match->prev == NULL) {
54945 + inodev_set.i_hash[index] = match->next;
54946 + if (match->next != NULL)
54947 + match->next->prev = NULL;
54948 + } else {
54949 + match->prev->next = match->next;
54950 + if (match->next != NULL)
54951 + match->next->prev = match->prev;
54952 + }
54953 + match->prev = NULL;
54954 + match->next = NULL;
54955 + match->nentry->inode = newinode;
54956 + match->nentry->device = newdevice;
54957 + match->nentry->deleted = 0;
54958 +
54959 + insert_inodev_entry(match);
54960 + }
54961 +
54962 + return;
54963 +}
54964 +
54965 +static void
54966 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
54967 +{
54968 + struct acl_subject_label *subj;
54969 + struct acl_role_label *role;
54970 + unsigned int x;
54971 +
54972 + FOR_EACH_ROLE_START(role)
54973 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
54974 +
54975 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
54976 + if ((subj->inode == ino) && (subj->device == dev)) {
54977 + subj->inode = ino;
54978 + subj->device = dev;
54979 + }
54980 + /* nested subjects aren't in the role's subj_hash table */
54981 + update_acl_obj_label(matchn->inode, matchn->device,
54982 + ino, dev, subj);
54983 + FOR_EACH_NESTED_SUBJECT_END(subj)
54984 + FOR_EACH_SUBJECT_START(role, subj, x)
54985 + update_acl_obj_label(matchn->inode, matchn->device,
54986 + ino, dev, subj);
54987 + FOR_EACH_SUBJECT_END(subj,x)
54988 + FOR_EACH_ROLE_END(role)
54989 +
54990 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
54991 +
54992 + return;
54993 +}
54994 +
54995 +static void
54996 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
54997 + const struct vfsmount *mnt)
54998 +{
54999 + ino_t ino = dentry->d_inode->i_ino;
55000 + dev_t dev = __get_dev(dentry);
55001 +
55002 + __do_handle_create(matchn, ino, dev);
55003 +
55004 + return;
55005 +}
55006 +
55007 +void
55008 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
55009 +{
55010 + struct name_entry *matchn;
55011 +
55012 + if (unlikely(!(gr_status & GR_READY)))
55013 + return;
55014 +
55015 + preempt_disable();
55016 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
55017 +
55018 + if (unlikely((unsigned long)matchn)) {
55019 + write_lock(&gr_inode_lock);
55020 + do_handle_create(matchn, dentry, mnt);
55021 + write_unlock(&gr_inode_lock);
55022 + }
55023 + preempt_enable();
55024 +
55025 + return;
55026 +}
55027 +
55028 +void
55029 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
55030 +{
55031 + struct name_entry *matchn;
55032 +
55033 + if (unlikely(!(gr_status & GR_READY)))
55034 + return;
55035 +
55036 + preempt_disable();
55037 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
55038 +
55039 + if (unlikely((unsigned long)matchn)) {
55040 + write_lock(&gr_inode_lock);
55041 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
55042 + write_unlock(&gr_inode_lock);
55043 + }
55044 + preempt_enable();
55045 +
55046 + return;
55047 +}
55048 +
55049 +void
55050 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
55051 + struct dentry *old_dentry,
55052 + struct dentry *new_dentry,
55053 + struct vfsmount *mnt, const __u8 replace)
55054 +{
55055 + struct name_entry *matchn;
55056 + struct inodev_entry *inodev;
55057 + struct inode *inode = new_dentry->d_inode;
55058 + ino_t old_ino = old_dentry->d_inode->i_ino;
55059 + dev_t old_dev = __get_dev(old_dentry);
55060 +
55061 + /* vfs_rename swaps the name and parent link for old_dentry and
55062 + new_dentry
55063 + at this point, old_dentry has the new name, parent link, and inode
55064 + for the renamed file
55065 + if a file is being replaced by a rename, new_dentry has the inode
55066 + and name for the replaced file
55067 + */
55068 +
55069 + if (unlikely(!(gr_status & GR_READY)))
55070 + return;
55071 +
55072 + preempt_disable();
55073 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
55074 +
55075 + /* we wouldn't have to check d_inode if it weren't for
55076 + NFS silly-renaming
55077 + */
55078 +
55079 + write_lock(&gr_inode_lock);
55080 + if (unlikely(replace && inode)) {
55081 + ino_t new_ino = inode->i_ino;
55082 + dev_t new_dev = __get_dev(new_dentry);
55083 +
55084 + inodev = lookup_inodev_entry(new_ino, new_dev);
55085 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
55086 + do_handle_delete(inodev, new_ino, new_dev);
55087 + }
55088 +
55089 + inodev = lookup_inodev_entry(old_ino, old_dev);
55090 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
55091 + do_handle_delete(inodev, old_ino, old_dev);
55092 +
55093 + if (unlikely((unsigned long)matchn))
55094 + do_handle_create(matchn, old_dentry, mnt);
55095 +
55096 + write_unlock(&gr_inode_lock);
55097 + preempt_enable();
55098 +
55099 + return;
55100 +}
55101 +
55102 +static int
55103 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
55104 + unsigned char **sum)
55105 +{
55106 + struct acl_role_label *r;
55107 + struct role_allowed_ip *ipp;
55108 + struct role_transition *trans;
55109 + unsigned int i;
55110 + int found = 0;
55111 + u32 curr_ip = current->signal->curr_ip;
55112 +
55113 + current->signal->saved_ip = curr_ip;
55114 +
55115 + /* check transition table */
55116 +
55117 + for (trans = current->role->transitions; trans; trans = trans->next) {
55118 + if (!strcmp(rolename, trans->rolename)) {
55119 + found = 1;
55120 + break;
55121 + }
55122 + }
55123 +
55124 + if (!found)
55125 + return 0;
55126 +
55127 + /* handle special roles that do not require authentication
55128 + and check ip */
55129 +
55130 + FOR_EACH_ROLE_START(r)
55131 + if (!strcmp(rolename, r->rolename) &&
55132 + (r->roletype & GR_ROLE_SPECIAL)) {
55133 + found = 0;
55134 + if (r->allowed_ips != NULL) {
55135 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
55136 + if ((ntohl(curr_ip) & ipp->netmask) ==
55137 + (ntohl(ipp->addr) & ipp->netmask))
55138 + found = 1;
55139 + }
55140 + } else
55141 + found = 2;
55142 + if (!found)
55143 + return 0;
55144 +
55145 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
55146 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
55147 + *salt = NULL;
55148 + *sum = NULL;
55149 + return 1;
55150 + }
55151 + }
55152 + FOR_EACH_ROLE_END(r)
55153 +
55154 + for (i = 0; i < num_sprole_pws; i++) {
55155 + if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
55156 + *salt = acl_special_roles[i]->salt;
55157 + *sum = acl_special_roles[i]->sum;
55158 + return 1;
55159 + }
55160 + }
55161 +
55162 + return 0;
55163 +}
55164 +
55165 +static void
55166 +assign_special_role(char *rolename)
55167 +{
55168 + struct acl_object_label *obj;
55169 + struct acl_role_label *r;
55170 + struct acl_role_label *assigned = NULL;
55171 + struct task_struct *tsk;
55172 + struct file *filp;
55173 +
55174 + FOR_EACH_ROLE_START(r)
55175 + if (!strcmp(rolename, r->rolename) &&
55176 + (r->roletype & GR_ROLE_SPECIAL)) {
55177 + assigned = r;
55178 + break;
55179 + }
55180 + FOR_EACH_ROLE_END(r)
55181 +
55182 + if (!assigned)
55183 + return;
55184 +
55185 + read_lock(&tasklist_lock);
55186 + read_lock(&grsec_exec_file_lock);
55187 +
55188 + tsk = current->real_parent;
55189 + if (tsk == NULL)
55190 + goto out_unlock;
55191 +
55192 + filp = tsk->exec_file;
55193 + if (filp == NULL)
55194 + goto out_unlock;
55195 +
55196 + tsk->is_writable = 0;
55197 +
55198 + tsk->acl_sp_role = 1;
55199 + tsk->acl_role_id = ++acl_sp_role_value;
55200 + tsk->role = assigned;
55201 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
55202 +
55203 + /* ignore additional mmap checks for processes that are writable
55204 + by the default ACL */
55205 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
55206 + if (unlikely(obj->mode & GR_WRITE))
55207 + tsk->is_writable = 1;
55208 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
55209 + if (unlikely(obj->mode & GR_WRITE))
55210 + tsk->is_writable = 1;
55211 +
55212 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
55213 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
55214 +#endif
55215 +
55216 +out_unlock:
55217 + read_unlock(&grsec_exec_file_lock);
55218 + read_unlock(&tasklist_lock);
55219 + return;
55220 +}
55221 +
55222 +int gr_check_secure_terminal(struct task_struct *task)
55223 +{
55224 + struct task_struct *p, *p2, *p3;
55225 + struct files_struct *files;
55226 + struct fdtable *fdt;
55227 + struct file *our_file = NULL, *file;
55228 + int i;
55229 +
55230 + if (task->signal->tty == NULL)
55231 + return 1;
55232 +
55233 + files = get_files_struct(task);
55234 + if (files != NULL) {
55235 + rcu_read_lock();
55236 + fdt = files_fdtable(files);
55237 + for (i=0; i < fdt->max_fds; i++) {
55238 + file = fcheck_files(files, i);
55239 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
55240 + get_file(file);
55241 + our_file = file;
55242 + }
55243 + }
55244 + rcu_read_unlock();
55245 + put_files_struct(files);
55246 + }
55247 +
55248 + if (our_file == NULL)
55249 + return 1;
55250 +
55251 + read_lock(&tasklist_lock);
55252 + do_each_thread(p2, p) {
55253 + files = get_files_struct(p);
55254 + if (files == NULL ||
55255 + (p->signal && p->signal->tty == task->signal->tty)) {
55256 + if (files != NULL)
55257 + put_files_struct(files);
55258 + continue;
55259 + }
55260 + rcu_read_lock();
55261 + fdt = files_fdtable(files);
55262 + for (i=0; i < fdt->max_fds; i++) {
55263 + file = fcheck_files(files, i);
55264 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
55265 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
55266 + p3 = task;
55267 + while (p3->pid > 0) {
55268 + if (p3 == p)
55269 + break;
55270 + p3 = p3->real_parent;
55271 + }
55272 + if (p3 == p)
55273 + break;
55274 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
55275 + gr_handle_alertkill(p);
55276 + rcu_read_unlock();
55277 + put_files_struct(files);
55278 + read_unlock(&tasklist_lock);
55279 + fput(our_file);
55280 + return 0;
55281 + }
55282 + }
55283 + rcu_read_unlock();
55284 + put_files_struct(files);
55285 + } while_each_thread(p2, p);
55286 + read_unlock(&tasklist_lock);
55287 +
55288 + fput(our_file);
55289 + return 1;
55290 +}
55291 +
55292 +static int gr_rbac_disable(void *unused)
55293 +{
55294 + pax_open_kernel();
55295 + gr_status &= ~GR_READY;
55296 + pax_close_kernel();
55297 +
55298 + return 0;
55299 +}
55300 +
55301 +ssize_t
55302 +write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
55303 +{
55304 + struct gr_arg_wrapper uwrap;
55305 + unsigned char *sprole_salt = NULL;
55306 + unsigned char *sprole_sum = NULL;
55307 + int error = sizeof (struct gr_arg_wrapper);
55308 + int error2 = 0;
55309 +
55310 + mutex_lock(&gr_dev_mutex);
55311 +
55312 + if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
55313 + error = -EPERM;
55314 + goto out;
55315 + }
55316 +
55317 + if (count != sizeof (struct gr_arg_wrapper)) {
55318 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
55319 + error = -EINVAL;
55320 + goto out;
55321 + }
55322 +
55323 +
55324 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
55325 + gr_auth_expires = 0;
55326 + gr_auth_attempts = 0;
55327 + }
55328 +
55329 + if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
55330 + error = -EFAULT;
55331 + goto out;
55332 + }
55333 +
55334 + if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
55335 + error = -EINVAL;
55336 + goto out;
55337 + }
55338 +
55339 + if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
55340 + error = -EFAULT;
55341 + goto out;
55342 + }
55343 +
55344 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
55345 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
55346 + time_after(gr_auth_expires, get_seconds())) {
55347 + error = -EBUSY;
55348 + goto out;
55349 + }
55350 +
55351 + /* if non-root trying to do anything other than use a special role,
55352 + do not attempt authentication, do not count towards authentication
55353 + locking
55354 + */
55355 +
55356 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
55357 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
55358 + !uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
55359 + error = -EPERM;
55360 + goto out;
55361 + }
55362 +
55363 + /* ensure pw and special role name are null terminated */
55364 +
55365 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
55366 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
55367 +
55368 + /* Okay.
55369 + * We have our enough of the argument structure..(we have yet
55370 + * to copy_from_user the tables themselves) . Copy the tables
55371 + * only if we need them, i.e. for loading operations. */
55372 +
55373 + switch (gr_usermode->mode) {
55374 + case GR_STATUS:
55375 + if (gr_status & GR_READY) {
55376 + error = 1;
55377 + if (!gr_check_secure_terminal(current))
55378 + error = 3;
55379 + } else
55380 + error = 2;
55381 + goto out;
55382 + case GR_SHUTDOWN:
55383 + if ((gr_status & GR_READY)
55384 + && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
55385 + stop_machine(gr_rbac_disable, NULL, NULL);
55386 + free_variables();
55387 + memset(gr_usermode, 0, sizeof (struct gr_arg));
55388 + memset(gr_system_salt, 0, GR_SALT_LEN);
55389 + memset(gr_system_sum, 0, GR_SHA_LEN);
55390 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
55391 + } else if (gr_status & GR_READY) {
55392 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
55393 + error = -EPERM;
55394 + } else {
55395 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
55396 + error = -EAGAIN;
55397 + }
55398 + break;
55399 + case GR_ENABLE:
55400 + if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
55401 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
55402 + else {
55403 + if (gr_status & GR_READY)
55404 + error = -EAGAIN;
55405 + else
55406 + error = error2;
55407 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
55408 + }
55409 + break;
55410 + case GR_RELOAD:
55411 + if (!(gr_status & GR_READY)) {
55412 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
55413 + error = -EAGAIN;
55414 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
55415 + stop_machine(gr_rbac_disable, NULL, NULL);
55416 + free_variables();
55417 + error2 = gracl_init(gr_usermode);
55418 + if (!error2)
55419 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
55420 + else {
55421 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
55422 + error = error2;
55423 + }
55424 + } else {
55425 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
55426 + error = -EPERM;
55427 + }
55428 + break;
55429 + case GR_SEGVMOD:
55430 + if (unlikely(!(gr_status & GR_READY))) {
55431 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
55432 + error = -EAGAIN;
55433 + break;
55434 + }
55435 +
55436 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
55437 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
55438 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
55439 + struct acl_subject_label *segvacl;
55440 + segvacl =
55441 + lookup_acl_subj_label(gr_usermode->segv_inode,
55442 + gr_usermode->segv_device,
55443 + current->role);
55444 + if (segvacl) {
55445 + segvacl->crashes = 0;
55446 + segvacl->expires = 0;
55447 + }
55448 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
55449 + gr_remove_uid(gr_usermode->segv_uid);
55450 + }
55451 + } else {
55452 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
55453 + error = -EPERM;
55454 + }
55455 + break;
55456 + case GR_SPROLE:
55457 + case GR_SPROLEPAM:
55458 + if (unlikely(!(gr_status & GR_READY))) {
55459 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
55460 + error = -EAGAIN;
55461 + break;
55462 + }
55463 +
55464 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
55465 + current->role->expires = 0;
55466 + current->role->auth_attempts = 0;
55467 + }
55468 +
55469 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
55470 + time_after(current->role->expires, get_seconds())) {
55471 + error = -EBUSY;
55472 + goto out;
55473 + }
55474 +
55475 + if (lookup_special_role_auth
55476 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
55477 + && ((!sprole_salt && !sprole_sum)
55478 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
55479 + char *p = "";
55480 + assign_special_role(gr_usermode->sp_role);
55481 + read_lock(&tasklist_lock);
55482 + if (current->real_parent)
55483 + p = current->real_parent->role->rolename;
55484 + read_unlock(&tasklist_lock);
55485 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
55486 + p, acl_sp_role_value);
55487 + } else {
55488 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
55489 + error = -EPERM;
55490 + if(!(current->role->auth_attempts++))
55491 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
55492 +
55493 + goto out;
55494 + }
55495 + break;
55496 + case GR_UNSPROLE:
55497 + if (unlikely(!(gr_status & GR_READY))) {
55498 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
55499 + error = -EAGAIN;
55500 + break;
55501 + }
55502 +
55503 + if (current->role->roletype & GR_ROLE_SPECIAL) {
55504 + char *p = "";
55505 + int i = 0;
55506 +
55507 + read_lock(&tasklist_lock);
55508 + if (current->real_parent) {
55509 + p = current->real_parent->role->rolename;
55510 + i = current->real_parent->acl_role_id;
55511 + }
55512 + read_unlock(&tasklist_lock);
55513 +
55514 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
55515 + gr_set_acls(1);
55516 + } else {
55517 + error = -EPERM;
55518 + goto out;
55519 + }
55520 + break;
55521 + default:
55522 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
55523 + error = -EINVAL;
55524 + break;
55525 + }
55526 +
55527 + if (error != -EPERM)
55528 + goto out;
55529 +
55530 + if(!(gr_auth_attempts++))
55531 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
55532 +
55533 + out:
55534 + mutex_unlock(&gr_dev_mutex);
55535 + return error;
55536 +}
55537 +
55538 +/* must be called with
55539 + rcu_read_lock();
55540 + read_lock(&tasklist_lock);
55541 + read_lock(&grsec_exec_file_lock);
55542 +*/
55543 +int gr_apply_subject_to_task(struct task_struct *task)
55544 +{
55545 + struct acl_object_label *obj;
55546 + char *tmpname;
55547 + struct acl_subject_label *tmpsubj;
55548 + struct file *filp;
55549 + struct name_entry *nmatch;
55550 +
55551 + filp = task->exec_file;
55552 + if (filp == NULL)
55553 + return 0;
55554 +
55555 + /* the following is to apply the correct subject
55556 + on binaries running when the RBAC system
55557 + is enabled, when the binaries have been
55558 + replaced or deleted since their execution
55559 + -----
55560 + when the RBAC system starts, the inode/dev
55561 + from exec_file will be one the RBAC system
55562 + is unaware of. It only knows the inode/dev
55563 + of the present file on disk, or the absence
55564 + of it.
55565 + */
55566 + preempt_disable();
55567 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
55568 +
55569 + nmatch = lookup_name_entry(tmpname);
55570 + preempt_enable();
55571 + tmpsubj = NULL;
55572 + if (nmatch) {
55573 + if (nmatch->deleted)
55574 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
55575 + else
55576 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
55577 + if (tmpsubj != NULL)
55578 + task->acl = tmpsubj;
55579 + }
55580 + if (tmpsubj == NULL)
55581 + task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
55582 + task->role);
55583 + if (task->acl) {
55584 + task->is_writable = 0;
55585 + /* ignore additional mmap checks for processes that are writable
55586 + by the default ACL */
55587 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
55588 + if (unlikely(obj->mode & GR_WRITE))
55589 + task->is_writable = 1;
55590 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
55591 + if (unlikely(obj->mode & GR_WRITE))
55592 + task->is_writable = 1;
55593 +
55594 + gr_set_proc_res(task);
55595 +
55596 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
55597 + printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
55598 +#endif
55599 + } else {
55600 + return 1;
55601 + }
55602 +
55603 + return 0;
55604 +}
55605 +
55606 +int
55607 +gr_set_acls(const int type)
55608 +{
55609 + struct task_struct *task, *task2;
55610 + struct acl_role_label *role = current->role;
55611 + __u16 acl_role_id = current->acl_role_id;
55612 + const struct cred *cred;
55613 + int ret;
55614 +
55615 + rcu_read_lock();
55616 + read_lock(&tasklist_lock);
55617 + read_lock(&grsec_exec_file_lock);
55618 + do_each_thread(task2, task) {
55619 + /* check to see if we're called from the exit handler,
55620 + if so, only replace ACLs that have inherited the admin
55621 + ACL */
55622 +
55623 + if (type && (task->role != role ||
55624 + task->acl_role_id != acl_role_id))
55625 + continue;
55626 +
55627 + task->acl_role_id = 0;
55628 + task->acl_sp_role = 0;
55629 +
55630 + if (task->exec_file) {
55631 + cred = __task_cred(task);
55632 + task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
55633 + ret = gr_apply_subject_to_task(task);
55634 + if (ret) {
55635 + read_unlock(&grsec_exec_file_lock);
55636 + read_unlock(&tasklist_lock);
55637 + rcu_read_unlock();
55638 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
55639 + return ret;
55640 + }
55641 + } else {
55642 + // it's a kernel process
55643 + task->role = kernel_role;
55644 + task->acl = kernel_role->root_label;
55645 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
55646 + task->acl->mode &= ~GR_PROCFIND;
55647 +#endif
55648 + }
55649 + } while_each_thread(task2, task);
55650 + read_unlock(&grsec_exec_file_lock);
55651 + read_unlock(&tasklist_lock);
55652 + rcu_read_unlock();
55653 +
55654 + return 0;
55655 +}
55656 +
55657 +void
55658 +gr_learn_resource(const struct task_struct *task,
55659 + const int res, const unsigned long wanted, const int gt)
55660 +{
55661 + struct acl_subject_label *acl;
55662 + const struct cred *cred;
55663 +
55664 + if (unlikely((gr_status & GR_READY) &&
55665 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
55666 + goto skip_reslog;
55667 +
55668 +#ifdef CONFIG_GRKERNSEC_RESLOG
55669 + gr_log_resource(task, res, wanted, gt);
55670 +#endif
55671 + skip_reslog:
55672 +
55673 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
55674 + return;
55675 +
55676 + acl = task->acl;
55677 +
55678 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
55679 + !(acl->resmask & (1 << (unsigned short) res))))
55680 + return;
55681 +
55682 + if (wanted >= acl->res[res].rlim_cur) {
55683 + unsigned long res_add;
55684 +
55685 + res_add = wanted;
55686 + switch (res) {
55687 + case RLIMIT_CPU:
55688 + res_add += GR_RLIM_CPU_BUMP;
55689 + break;
55690 + case RLIMIT_FSIZE:
55691 + res_add += GR_RLIM_FSIZE_BUMP;
55692 + break;
55693 + case RLIMIT_DATA:
55694 + res_add += GR_RLIM_DATA_BUMP;
55695 + break;
55696 + case RLIMIT_STACK:
55697 + res_add += GR_RLIM_STACK_BUMP;
55698 + break;
55699 + case RLIMIT_CORE:
55700 + res_add += GR_RLIM_CORE_BUMP;
55701 + break;
55702 + case RLIMIT_RSS:
55703 + res_add += GR_RLIM_RSS_BUMP;
55704 + break;
55705 + case RLIMIT_NPROC:
55706 + res_add += GR_RLIM_NPROC_BUMP;
55707 + break;
55708 + case RLIMIT_NOFILE:
55709 + res_add += GR_RLIM_NOFILE_BUMP;
55710 + break;
55711 + case RLIMIT_MEMLOCK:
55712 + res_add += GR_RLIM_MEMLOCK_BUMP;
55713 + break;
55714 + case RLIMIT_AS:
55715 + res_add += GR_RLIM_AS_BUMP;
55716 + break;
55717 + case RLIMIT_LOCKS:
55718 + res_add += GR_RLIM_LOCKS_BUMP;
55719 + break;
55720 + case RLIMIT_SIGPENDING:
55721 + res_add += GR_RLIM_SIGPENDING_BUMP;
55722 + break;
55723 + case RLIMIT_MSGQUEUE:
55724 + res_add += GR_RLIM_MSGQUEUE_BUMP;
55725 + break;
55726 + case RLIMIT_NICE:
55727 + res_add += GR_RLIM_NICE_BUMP;
55728 + break;
55729 + case RLIMIT_RTPRIO:
55730 + res_add += GR_RLIM_RTPRIO_BUMP;
55731 + break;
55732 + case RLIMIT_RTTIME:
55733 + res_add += GR_RLIM_RTTIME_BUMP;
55734 + break;
55735 + }
55736 +
55737 + acl->res[res].rlim_cur = res_add;
55738 +
55739 + if (wanted > acl->res[res].rlim_max)
55740 + acl->res[res].rlim_max = res_add;
55741 +
55742 + /* only log the subject filename, since resource logging is supported for
55743 + single-subject learning only */
55744 + rcu_read_lock();
55745 + cred = __task_cred(task);
55746 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
55747 + task->role->roletype, cred->uid, cred->gid, acl->filename,
55748 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
55749 + "", (unsigned long) res, &task->signal->saved_ip);
55750 + rcu_read_unlock();
55751 + }
55752 +
55753 + return;
55754 +}
55755 +
55756 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
55757 +void
55758 +pax_set_initial_flags(struct linux_binprm *bprm)
55759 +{
55760 + struct task_struct *task = current;
55761 + struct acl_subject_label *proc;
55762 + unsigned long flags;
55763 +
55764 + if (unlikely(!(gr_status & GR_READY)))
55765 + return;
55766 +
55767 + flags = pax_get_flags(task);
55768 +
55769 + proc = task->acl;
55770 +
55771 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
55772 + flags &= ~MF_PAX_PAGEEXEC;
55773 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
55774 + flags &= ~MF_PAX_SEGMEXEC;
55775 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
55776 + flags &= ~MF_PAX_RANDMMAP;
55777 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
55778 + flags &= ~MF_PAX_EMUTRAMP;
55779 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
55780 + flags &= ~MF_PAX_MPROTECT;
55781 +
55782 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
55783 + flags |= MF_PAX_PAGEEXEC;
55784 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
55785 + flags |= MF_PAX_SEGMEXEC;
55786 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
55787 + flags |= MF_PAX_RANDMMAP;
55788 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
55789 + flags |= MF_PAX_EMUTRAMP;
55790 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
55791 + flags |= MF_PAX_MPROTECT;
55792 +
55793 + pax_set_flags(task, flags);
55794 +
55795 + return;
55796 +}
55797 +#endif
55798 +
55799 +int
55800 +gr_handle_proc_ptrace(struct task_struct *task)
55801 +{
55802 + struct file *filp;
55803 + struct task_struct *tmp = task;
55804 + struct task_struct *curtemp = current;
55805 + __u32 retmode;
55806 +
55807 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
55808 + if (unlikely(!(gr_status & GR_READY)))
55809 + return 0;
55810 +#endif
55811 +
55812 + read_lock(&tasklist_lock);
55813 + read_lock(&grsec_exec_file_lock);
55814 + filp = task->exec_file;
55815 +
55816 + while (tmp->pid > 0) {
55817 + if (tmp == curtemp)
55818 + break;
55819 + tmp = tmp->real_parent;
55820 + }
55821 +
55822 + if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
55823 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
55824 + read_unlock(&grsec_exec_file_lock);
55825 + read_unlock(&tasklist_lock);
55826 + return 1;
55827 + }
55828 +
55829 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
55830 + if (!(gr_status & GR_READY)) {
55831 + read_unlock(&grsec_exec_file_lock);
55832 + read_unlock(&tasklist_lock);
55833 + return 0;
55834 + }
55835 +#endif
55836 +
55837 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
55838 + read_unlock(&grsec_exec_file_lock);
55839 + read_unlock(&tasklist_lock);
55840 +
55841 + if (retmode & GR_NOPTRACE)
55842 + return 1;
55843 +
55844 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
55845 + && (current->acl != task->acl || (current->acl != current->role->root_label
55846 + && current->pid != task->pid)))
55847 + return 1;
55848 +
55849 + return 0;
55850 +}
55851 +
55852 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
55853 +{
55854 + if (unlikely(!(gr_status & GR_READY)))
55855 + return;
55856 +
55857 + if (!(current->role->roletype & GR_ROLE_GOD))
55858 + return;
55859 +
55860 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
55861 + p->role->rolename, gr_task_roletype_to_char(p),
55862 + p->acl->filename);
55863 +}
55864 +
55865 +int
55866 +gr_handle_ptrace(struct task_struct *task, const long request)
55867 +{
55868 + struct task_struct *tmp = task;
55869 + struct task_struct *curtemp = current;
55870 + __u32 retmode;
55871 +
55872 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
55873 + if (unlikely(!(gr_status & GR_READY)))
55874 + return 0;
55875 +#endif
55876 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
55877 + read_lock(&tasklist_lock);
55878 + while (tmp->pid > 0) {
55879 + if (tmp == curtemp)
55880 + break;
55881 + tmp = tmp->real_parent;
55882 + }
55883 +
55884 + if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
55885 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
55886 + read_unlock(&tasklist_lock);
55887 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55888 + return 1;
55889 + }
55890 + read_unlock(&tasklist_lock);
55891 + }
55892 +
55893 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
55894 + if (!(gr_status & GR_READY))
55895 + return 0;
55896 +#endif
55897 +
55898 + read_lock(&grsec_exec_file_lock);
55899 + if (unlikely(!task->exec_file)) {
55900 + read_unlock(&grsec_exec_file_lock);
55901 + return 0;
55902 + }
55903 +
55904 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
55905 + read_unlock(&grsec_exec_file_lock);
55906 +
55907 + if (retmode & GR_NOPTRACE) {
55908 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55909 + return 1;
55910 + }
55911 +
55912 + if (retmode & GR_PTRACERD) {
55913 + switch (request) {
55914 + case PTRACE_SEIZE:
55915 + case PTRACE_POKETEXT:
55916 + case PTRACE_POKEDATA:
55917 + case PTRACE_POKEUSR:
55918 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
55919 + case PTRACE_SETREGS:
55920 + case PTRACE_SETFPREGS:
55921 +#endif
55922 +#ifdef CONFIG_X86
55923 + case PTRACE_SETFPXREGS:
55924 +#endif
55925 +#ifdef CONFIG_ALTIVEC
55926 + case PTRACE_SETVRREGS:
55927 +#endif
55928 + return 1;
55929 + default:
55930 + return 0;
55931 + }
55932 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
55933 + !(current->role->roletype & GR_ROLE_GOD) &&
55934 + (current->acl != task->acl)) {
55935 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55936 + return 1;
55937 + }
55938 +
55939 + return 0;
55940 +}
55941 +
55942 +static int is_writable_mmap(const struct file *filp)
55943 +{
55944 + struct task_struct *task = current;
55945 + struct acl_object_label *obj, *obj2;
55946 +
55947 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
55948 + !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))) {
55949 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
55950 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
55951 + task->role->root_label);
55952 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
55953 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
55954 + return 1;
55955 + }
55956 + }
55957 + return 0;
55958 +}
55959 +
55960 +int
55961 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
55962 +{
55963 + __u32 mode;
55964 +
55965 + if (unlikely(!file || !(prot & PROT_EXEC)))
55966 + return 1;
55967 +
55968 + if (is_writable_mmap(file))
55969 + return 0;
55970 +
55971 + mode =
55972 + gr_search_file(file->f_path.dentry,
55973 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
55974 + file->f_path.mnt);
55975 +
55976 + if (!gr_tpe_allow(file))
55977 + return 0;
55978 +
55979 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
55980 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55981 + return 0;
55982 + } else if (unlikely(!(mode & GR_EXEC))) {
55983 + return 0;
55984 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
55985 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55986 + return 1;
55987 + }
55988 +
55989 + return 1;
55990 +}
55991 +
55992 +int
55993 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
55994 +{
55995 + __u32 mode;
55996 +
55997 + if (unlikely(!file || !(prot & PROT_EXEC)))
55998 + return 1;
55999 +
56000 + if (is_writable_mmap(file))
56001 + return 0;
56002 +
56003 + mode =
56004 + gr_search_file(file->f_path.dentry,
56005 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
56006 + file->f_path.mnt);
56007 +
56008 + if (!gr_tpe_allow(file))
56009 + return 0;
56010 +
56011 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
56012 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
56013 + return 0;
56014 + } else if (unlikely(!(mode & GR_EXEC))) {
56015 + return 0;
56016 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
56017 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
56018 + return 1;
56019 + }
56020 +
56021 + return 1;
56022 +}
56023 +
56024 +void
56025 +gr_acl_handle_psacct(struct task_struct *task, const long code)
56026 +{
56027 + unsigned long runtime;
56028 + unsigned long cputime;
56029 + unsigned int wday, cday;
56030 + __u8 whr, chr;
56031 + __u8 wmin, cmin;
56032 + __u8 wsec, csec;
56033 + struct timespec timeval;
56034 +
56035 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
56036 + !(task->acl->mode & GR_PROCACCT)))
56037 + return;
56038 +
56039 + do_posix_clock_monotonic_gettime(&timeval);
56040 + runtime = timeval.tv_sec - task->start_time.tv_sec;
56041 + wday = runtime / (3600 * 24);
56042 + runtime -= wday * (3600 * 24);
56043 + whr = runtime / 3600;
56044 + runtime -= whr * 3600;
56045 + wmin = runtime / 60;
56046 + runtime -= wmin * 60;
56047 + wsec = runtime;
56048 +
56049 + cputime = (task->utime + task->stime) / HZ;
56050 + cday = cputime / (3600 * 24);
56051 + cputime -= cday * (3600 * 24);
56052 + chr = cputime / 3600;
56053 + cputime -= chr * 3600;
56054 + cmin = cputime / 60;
56055 + cputime -= cmin * 60;
56056 + csec = cputime;
56057 +
56058 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
56059 +
56060 + return;
56061 +}
56062 +
56063 +void gr_set_kernel_label(struct task_struct *task)
56064 +{
56065 + if (gr_status & GR_READY) {
56066 + task->role = kernel_role;
56067 + task->acl = kernel_role->root_label;
56068 + }
56069 + return;
56070 +}
56071 +
56072 +#ifdef CONFIG_TASKSTATS
56073 +int gr_is_taskstats_denied(int pid)
56074 +{
56075 + struct task_struct *task;
56076 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
56077 + const struct cred *cred;
56078 +#endif
56079 + int ret = 0;
56080 +
56081 + /* restrict taskstats viewing to un-chrooted root users
56082 + who have the 'view' subject flag if the RBAC system is enabled
56083 + */
56084 +
56085 + rcu_read_lock();
56086 + read_lock(&tasklist_lock);
56087 + task = find_task_by_vpid(pid);
56088 + if (task) {
56089 +#ifdef CONFIG_GRKERNSEC_CHROOT
56090 + if (proc_is_chrooted(task))
56091 + ret = -EACCES;
56092 +#endif
56093 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
56094 + cred = __task_cred(task);
56095 +#ifdef CONFIG_GRKERNSEC_PROC_USER
56096 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID))
56097 + ret = -EACCES;
56098 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
56099 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && !groups_search(cred->group_info, grsec_proc_gid))
56100 + ret = -EACCES;
56101 +#endif
56102 +#endif
56103 + if (gr_status & GR_READY) {
56104 + if (!(task->acl->mode & GR_VIEW))
56105 + ret = -EACCES;
56106 + }
56107 + } else
56108 + ret = -ENOENT;
56109 +
56110 + read_unlock(&tasklist_lock);
56111 + rcu_read_unlock();
56112 +
56113 + return ret;
56114 +}
56115 +#endif
56116 +
56117 +/* AUXV entries are filled via a descendant of search_binary_handler
56118 + after we've already applied the subject for the target
56119 +*/
56120 +int gr_acl_enable_at_secure(void)
56121 +{
56122 + if (unlikely(!(gr_status & GR_READY)))
56123 + return 0;
56124 +
56125 + if (current->acl->mode & GR_ATSECURE)
56126 + return 1;
56127 +
56128 + return 0;
56129 +}
56130 +
56131 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
56132 +{
56133 + struct task_struct *task = current;
56134 + struct dentry *dentry = file->f_path.dentry;
56135 + struct vfsmount *mnt = file->f_path.mnt;
56136 + struct acl_object_label *obj, *tmp;
56137 + struct acl_subject_label *subj;
56138 + unsigned int bufsize;
56139 + int is_not_root;
56140 + char *path;
56141 + dev_t dev = __get_dev(dentry);
56142 +
56143 + if (unlikely(!(gr_status & GR_READY)))
56144 + return 1;
56145 +
56146 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
56147 + return 1;
56148 +
56149 + /* ignore Eric Biederman */
56150 + if (IS_PRIVATE(dentry->d_inode))
56151 + return 1;
56152 +
56153 + subj = task->acl;
56154 + read_lock(&gr_inode_lock);
56155 + do {
56156 + obj = lookup_acl_obj_label(ino, dev, subj);
56157 + if (obj != NULL) {
56158 + read_unlock(&gr_inode_lock);
56159 + return (obj->mode & GR_FIND) ? 1 : 0;
56160 + }
56161 + } while ((subj = subj->parent_subject));
56162 + read_unlock(&gr_inode_lock);
56163 +
56164 + /* this is purely an optimization since we're looking for an object
56165 + for the directory we're doing a readdir on
56166 + if it's possible for any globbed object to match the entry we're
56167 + filling into the directory, then the object we find here will be
56168 + an anchor point with attached globbed objects
56169 + */
56170 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
56171 + if (obj->globbed == NULL)
56172 + return (obj->mode & GR_FIND) ? 1 : 0;
56173 +
56174 + is_not_root = ((obj->filename[0] == '/') &&
56175 + (obj->filename[1] == '\0')) ? 0 : 1;
56176 + bufsize = PAGE_SIZE - namelen - is_not_root;
56177 +
56178 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
56179 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
56180 + return 1;
56181 +
56182 + preempt_disable();
56183 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
56184 + bufsize);
56185 +
56186 + bufsize = strlen(path);
56187 +
56188 + /* if base is "/", don't append an additional slash */
56189 + if (is_not_root)
56190 + *(path + bufsize) = '/';
56191 + memcpy(path + bufsize + is_not_root, name, namelen);
56192 + *(path + bufsize + namelen + is_not_root) = '\0';
56193 +
56194 + tmp = obj->globbed;
56195 + while (tmp) {
56196 + if (!glob_match(tmp->filename, path)) {
56197 + preempt_enable();
56198 + return (tmp->mode & GR_FIND) ? 1 : 0;
56199 + }
56200 + tmp = tmp->next;
56201 + }
56202 + preempt_enable();
56203 + return (obj->mode & GR_FIND) ? 1 : 0;
56204 +}
56205 +
56206 +void gr_put_exec_file(struct task_struct *task)
56207 +{
56208 + struct file *filp;
56209 +
56210 + write_lock(&grsec_exec_file_lock);
56211 + filp = task->exec_file;
56212 + task->exec_file = NULL;
56213 + write_unlock(&grsec_exec_file_lock);
56214 +
56215 + if (filp)
56216 + fput(filp);
56217 +
56218 + return;
56219 +}
56220 +
56221 +
56222 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
56223 +EXPORT_SYMBOL(gr_acl_is_enabled);
56224 +#endif
56225 +EXPORT_SYMBOL(gr_learn_resource);
56226 +EXPORT_SYMBOL(gr_set_kernel_label);
56227 +#ifdef CONFIG_SECURITY
56228 +EXPORT_SYMBOL(gr_check_user_change);
56229 +EXPORT_SYMBOL(gr_check_group_change);
56230 +#endif
56231 +
56232 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
56233 new file mode 100644
56234 index 0000000..34fefda
56235 --- /dev/null
56236 +++ b/grsecurity/gracl_alloc.c
56237 @@ -0,0 +1,105 @@
56238 +#include <linux/kernel.h>
56239 +#include <linux/mm.h>
56240 +#include <linux/slab.h>
56241 +#include <linux/vmalloc.h>
56242 +#include <linux/gracl.h>
56243 +#include <linux/grsecurity.h>
56244 +
56245 +static unsigned long alloc_stack_next = 1;
56246 +static unsigned long alloc_stack_size = 1;
56247 +static void **alloc_stack;
56248 +
56249 +static __inline__ int
56250 +alloc_pop(void)
56251 +{
56252 + if (alloc_stack_next == 1)
56253 + return 0;
56254 +
56255 + kfree(alloc_stack[alloc_stack_next - 2]);
56256 +
56257 + alloc_stack_next--;
56258 +
56259 + return 1;
56260 +}
56261 +
56262 +static __inline__ int
56263 +alloc_push(void *buf)
56264 +{
56265 + if (alloc_stack_next >= alloc_stack_size)
56266 + return 1;
56267 +
56268 + alloc_stack[alloc_stack_next - 1] = buf;
56269 +
56270 + alloc_stack_next++;
56271 +
56272 + return 0;
56273 +}
56274 +
56275 +void *
56276 +acl_alloc(unsigned long len)
56277 +{
56278 + void *ret = NULL;
56279 +
56280 + if (!len || len > PAGE_SIZE)
56281 + goto out;
56282 +
56283 + ret = kmalloc(len, GFP_KERNEL);
56284 +
56285 + if (ret) {
56286 + if (alloc_push(ret)) {
56287 + kfree(ret);
56288 + ret = NULL;
56289 + }
56290 + }
56291 +
56292 +out:
56293 + return ret;
56294 +}
56295 +
56296 +void *
56297 +acl_alloc_num(unsigned long num, unsigned long len)
56298 +{
56299 + if (!len || (num > (PAGE_SIZE / len)))
56300 + return NULL;
56301 +
56302 + return acl_alloc(num * len);
56303 +}
56304 +
56305 +void
56306 +acl_free_all(void)
56307 +{
56308 + if (gr_acl_is_enabled() || !alloc_stack)
56309 + return;
56310 +
56311 + while (alloc_pop()) ;
56312 +
56313 + if (alloc_stack) {
56314 + if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
56315 + kfree(alloc_stack);
56316 + else
56317 + vfree(alloc_stack);
56318 + }
56319 +
56320 + alloc_stack = NULL;
56321 + alloc_stack_size = 1;
56322 + alloc_stack_next = 1;
56323 +
56324 + return;
56325 +}
56326 +
56327 +int
56328 +acl_alloc_stack_init(unsigned long size)
56329 +{
56330 + if ((size * sizeof (void *)) <= PAGE_SIZE)
56331 + alloc_stack =
56332 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
56333 + else
56334 + alloc_stack = (void **) vmalloc(size * sizeof (void *));
56335 +
56336 + alloc_stack_size = size;
56337 +
56338 + if (!alloc_stack)
56339 + return 0;
56340 + else
56341 + return 1;
56342 +}
56343 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
56344 new file mode 100644
56345 index 0000000..6d21049
56346 --- /dev/null
56347 +++ b/grsecurity/gracl_cap.c
56348 @@ -0,0 +1,110 @@
56349 +#include <linux/kernel.h>
56350 +#include <linux/module.h>
56351 +#include <linux/sched.h>
56352 +#include <linux/gracl.h>
56353 +#include <linux/grsecurity.h>
56354 +#include <linux/grinternal.h>
56355 +
56356 +extern const char *captab_log[];
56357 +extern int captab_log_entries;
56358 +
56359 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
56360 +{
56361 + struct acl_subject_label *curracl;
56362 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
56363 + kernel_cap_t cap_audit = __cap_empty_set;
56364 +
56365 + if (!gr_acl_is_enabled())
56366 + return 1;
56367 +
56368 + curracl = task->acl;
56369 +
56370 + cap_drop = curracl->cap_lower;
56371 + cap_mask = curracl->cap_mask;
56372 + cap_audit = curracl->cap_invert_audit;
56373 +
56374 + while ((curracl = curracl->parent_subject)) {
56375 + /* if the cap isn't specified in the current computed mask but is specified in the
56376 + current level subject, and is lowered in the current level subject, then add
56377 + it to the set of dropped capabilities
56378 + otherwise, add the current level subject's mask to the current computed mask
56379 + */
56380 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
56381 + cap_raise(cap_mask, cap);
56382 + if (cap_raised(curracl->cap_lower, cap))
56383 + cap_raise(cap_drop, cap);
56384 + if (cap_raised(curracl->cap_invert_audit, cap))
56385 + cap_raise(cap_audit, cap);
56386 + }
56387 + }
56388 +
56389 + if (!cap_raised(cap_drop, cap)) {
56390 + if (cap_raised(cap_audit, cap))
56391 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
56392 + return 1;
56393 + }
56394 +
56395 + curracl = task->acl;
56396 +
56397 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
56398 + && cap_raised(cred->cap_effective, cap)) {
56399 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
56400 + task->role->roletype, cred->uid,
56401 + cred->gid, task->exec_file ?
56402 + gr_to_filename(task->exec_file->f_path.dentry,
56403 + task->exec_file->f_path.mnt) : curracl->filename,
56404 + curracl->filename, 0UL,
56405 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
56406 + return 1;
56407 + }
56408 +
56409 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
56410 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
56411 +
56412 + return 0;
56413 +}
56414 +
56415 +int
56416 +gr_acl_is_capable(const int cap)
56417 +{
56418 + return gr_task_acl_is_capable(current, current_cred(), cap);
56419 +}
56420 +
56421 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
56422 +{
56423 + struct acl_subject_label *curracl;
56424 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
56425 +
56426 + if (!gr_acl_is_enabled())
56427 + return 1;
56428 +
56429 + curracl = task->acl;
56430 +
56431 + cap_drop = curracl->cap_lower;
56432 + cap_mask = curracl->cap_mask;
56433 +
56434 + while ((curracl = curracl->parent_subject)) {
56435 + /* if the cap isn't specified in the current computed mask but is specified in the
56436 + current level subject, and is lowered in the current level subject, then add
56437 + it to the set of dropped capabilities
56438 + otherwise, add the current level subject's mask to the current computed mask
56439 + */
56440 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
56441 + cap_raise(cap_mask, cap);
56442 + if (cap_raised(curracl->cap_lower, cap))
56443 + cap_raise(cap_drop, cap);
56444 + }
56445 + }
56446 +
56447 + if (!cap_raised(cap_drop, cap))
56448 + return 1;
56449 +
56450 + return 0;
56451 +}
56452 +
56453 +int
56454 +gr_acl_is_capable_nolog(const int cap)
56455 +{
56456 + return gr_task_acl_is_capable_nolog(current, cap);
56457 +}
56458 +
56459 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
56460 new file mode 100644
56461 index 0000000..d28e241
56462 --- /dev/null
56463 +++ b/grsecurity/gracl_fs.c
56464 @@ -0,0 +1,437 @@
56465 +#include <linux/kernel.h>
56466 +#include <linux/sched.h>
56467 +#include <linux/types.h>
56468 +#include <linux/fs.h>
56469 +#include <linux/file.h>
56470 +#include <linux/stat.h>
56471 +#include <linux/grsecurity.h>
56472 +#include <linux/grinternal.h>
56473 +#include <linux/gracl.h>
56474 +
56475 +umode_t
56476 +gr_acl_umask(void)
56477 +{
56478 + if (unlikely(!gr_acl_is_enabled()))
56479 + return 0;
56480 +
56481 + return current->role->umask;
56482 +}
56483 +
56484 +__u32
56485 +gr_acl_handle_hidden_file(const struct dentry * dentry,
56486 + const struct vfsmount * mnt)
56487 +{
56488 + __u32 mode;
56489 +
56490 + if (unlikely(!dentry->d_inode))
56491 + return GR_FIND;
56492 +
56493 + mode =
56494 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
56495 +
56496 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
56497 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
56498 + return mode;
56499 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
56500 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
56501 + return 0;
56502 + } else if (unlikely(!(mode & GR_FIND)))
56503 + return 0;
56504 +
56505 + return GR_FIND;
56506 +}
56507 +
56508 +__u32
56509 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
56510 + int acc_mode)
56511 +{
56512 + __u32 reqmode = GR_FIND;
56513 + __u32 mode;
56514 +
56515 + if (unlikely(!dentry->d_inode))
56516 + return reqmode;
56517 +
56518 + if (acc_mode & MAY_APPEND)
56519 + reqmode |= GR_APPEND;
56520 + else if (acc_mode & MAY_WRITE)
56521 + reqmode |= GR_WRITE;
56522 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
56523 + reqmode |= GR_READ;
56524 +
56525 + mode =
56526 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
56527 + mnt);
56528 +
56529 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
56530 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
56531 + reqmode & GR_READ ? " reading" : "",
56532 + reqmode & GR_WRITE ? " writing" : reqmode &
56533 + GR_APPEND ? " appending" : "");
56534 + return reqmode;
56535 + } else
56536 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
56537 + {
56538 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
56539 + reqmode & GR_READ ? " reading" : "",
56540 + reqmode & GR_WRITE ? " writing" : reqmode &
56541 + GR_APPEND ? " appending" : "");
56542 + return 0;
56543 + } else if (unlikely((mode & reqmode) != reqmode))
56544 + return 0;
56545 +
56546 + return reqmode;
56547 +}
56548 +
56549 +__u32
56550 +gr_acl_handle_creat(const struct dentry * dentry,
56551 + const struct dentry * p_dentry,
56552 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
56553 + const int imode)
56554 +{
56555 + __u32 reqmode = GR_WRITE | GR_CREATE;
56556 + __u32 mode;
56557 +
56558 + if (acc_mode & MAY_APPEND)
56559 + reqmode |= GR_APPEND;
56560 + // if a directory was required or the directory already exists, then
56561 + // don't count this open as a read
56562 + if ((acc_mode & MAY_READ) &&
56563 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
56564 + reqmode |= GR_READ;
56565 + if ((open_flags & O_CREAT) &&
56566 + ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
56567 + reqmode |= GR_SETID;
56568 +
56569 + mode =
56570 + gr_check_create(dentry, p_dentry, p_mnt,
56571 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
56572 +
56573 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
56574 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
56575 + reqmode & GR_READ ? " reading" : "",
56576 + reqmode & GR_WRITE ? " writing" : reqmode &
56577 + GR_APPEND ? " appending" : "");
56578 + return reqmode;
56579 + } else
56580 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
56581 + {
56582 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
56583 + reqmode & GR_READ ? " reading" : "",
56584 + reqmode & GR_WRITE ? " writing" : reqmode &
56585 + GR_APPEND ? " appending" : "");
56586 + return 0;
56587 + } else if (unlikely((mode & reqmode) != reqmode))
56588 + return 0;
56589 +
56590 + return reqmode;
56591 +}
56592 +
56593 +__u32
56594 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
56595 + const int fmode)
56596 +{
56597 + __u32 mode, reqmode = GR_FIND;
56598 +
56599 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
56600 + reqmode |= GR_EXEC;
56601 + if (fmode & S_IWOTH)
56602 + reqmode |= GR_WRITE;
56603 + if (fmode & S_IROTH)
56604 + reqmode |= GR_READ;
56605 +
56606 + mode =
56607 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
56608 + mnt);
56609 +
56610 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
56611 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
56612 + reqmode & GR_READ ? " reading" : "",
56613 + reqmode & GR_WRITE ? " writing" : "",
56614 + reqmode & GR_EXEC ? " executing" : "");
56615 + return reqmode;
56616 + } else
56617 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
56618 + {
56619 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
56620 + reqmode & GR_READ ? " reading" : "",
56621 + reqmode & GR_WRITE ? " writing" : "",
56622 + reqmode & GR_EXEC ? " executing" : "");
56623 + return 0;
56624 + } else if (unlikely((mode & reqmode) != reqmode))
56625 + return 0;
56626 +
56627 + return reqmode;
56628 +}
56629 +
56630 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
56631 +{
56632 + __u32 mode;
56633 +
56634 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
56635 +
56636 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
56637 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
56638 + return mode;
56639 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
56640 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
56641 + return 0;
56642 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
56643 + return 0;
56644 +
56645 + return (reqmode);
56646 +}
56647 +
56648 +__u32
56649 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
56650 +{
56651 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
56652 +}
56653 +
56654 +__u32
56655 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
56656 +{
56657 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
56658 +}
56659 +
56660 +__u32
56661 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
56662 +{
56663 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
56664 +}
56665 +
56666 +__u32
56667 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
56668 +{
56669 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
56670 +}
56671 +
56672 +__u32
56673 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
56674 + umode_t *modeptr)
56675 +{
56676 + umode_t mode;
56677 +
56678 + *modeptr &= ~gr_acl_umask();
56679 + mode = *modeptr;
56680 +
56681 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
56682 + return 1;
56683 +
56684 + if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
56685 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
56686 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
56687 + GR_CHMOD_ACL_MSG);
56688 + } else {
56689 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
56690 + }
56691 +}
56692 +
56693 +__u32
56694 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
56695 +{
56696 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
56697 +}
56698 +
56699 +__u32
56700 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
56701 +{
56702 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
56703 +}
56704 +
56705 +__u32
56706 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
56707 +{
56708 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
56709 +}
56710 +
56711 +__u32
56712 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
56713 +{
56714 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
56715 + GR_UNIXCONNECT_ACL_MSG);
56716 +}
56717 +
56718 +/* hardlinks require at minimum create and link permission,
56719 + any additional privilege required is based on the
56720 + privilege of the file being linked to
56721 +*/
56722 +__u32
56723 +gr_acl_handle_link(const struct dentry * new_dentry,
56724 + const struct dentry * parent_dentry,
56725 + const struct vfsmount * parent_mnt,
56726 + const struct dentry * old_dentry,
56727 + const struct vfsmount * old_mnt, const char *to)
56728 +{
56729 + __u32 mode;
56730 + __u32 needmode = GR_CREATE | GR_LINK;
56731 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
56732 +
56733 + mode =
56734 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
56735 + old_mnt);
56736 +
56737 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
56738 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
56739 + return mode;
56740 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
56741 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
56742 + return 0;
56743 + } else if (unlikely((mode & needmode) != needmode))
56744 + return 0;
56745 +
56746 + return 1;
56747 +}
56748 +
56749 +__u32
56750 +gr_acl_handle_symlink(const struct dentry * new_dentry,
56751 + const struct dentry * parent_dentry,
56752 + const struct vfsmount * parent_mnt, const char *from)
56753 +{
56754 + __u32 needmode = GR_WRITE | GR_CREATE;
56755 + __u32 mode;
56756 +
56757 + mode =
56758 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
56759 + GR_CREATE | GR_AUDIT_CREATE |
56760 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
56761 +
56762 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
56763 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
56764 + return mode;
56765 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
56766 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
56767 + return 0;
56768 + } else if (unlikely((mode & needmode) != needmode))
56769 + return 0;
56770 +
56771 + return (GR_WRITE | GR_CREATE);
56772 +}
56773 +
56774 +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)
56775 +{
56776 + __u32 mode;
56777 +
56778 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
56779 +
56780 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
56781 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
56782 + return mode;
56783 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
56784 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
56785 + return 0;
56786 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
56787 + return 0;
56788 +
56789 + return (reqmode);
56790 +}
56791 +
56792 +__u32
56793 +gr_acl_handle_mknod(const struct dentry * new_dentry,
56794 + const struct dentry * parent_dentry,
56795 + const struct vfsmount * parent_mnt,
56796 + const int mode)
56797 +{
56798 + __u32 reqmode = GR_WRITE | GR_CREATE;
56799 + if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
56800 + reqmode |= GR_SETID;
56801 +
56802 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
56803 + reqmode, GR_MKNOD_ACL_MSG);
56804 +}
56805 +
56806 +__u32
56807 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
56808 + const struct dentry *parent_dentry,
56809 + const struct vfsmount *parent_mnt)
56810 +{
56811 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
56812 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
56813 +}
56814 +
56815 +#define RENAME_CHECK_SUCCESS(old, new) \
56816 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
56817 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
56818 +
56819 +int
56820 +gr_acl_handle_rename(struct dentry *new_dentry,
56821 + struct dentry *parent_dentry,
56822 + const struct vfsmount *parent_mnt,
56823 + struct dentry *old_dentry,
56824 + struct inode *old_parent_inode,
56825 + struct vfsmount *old_mnt, const char *newname)
56826 +{
56827 + __u32 comp1, comp2;
56828 + int error = 0;
56829 +
56830 + if (unlikely(!gr_acl_is_enabled()))
56831 + return 0;
56832 +
56833 + if (!new_dentry->d_inode) {
56834 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
56835 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
56836 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
56837 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
56838 + GR_DELETE | GR_AUDIT_DELETE |
56839 + GR_AUDIT_READ | GR_AUDIT_WRITE |
56840 + GR_SUPPRESS, old_mnt);
56841 + } else {
56842 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
56843 + GR_CREATE | GR_DELETE |
56844 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
56845 + GR_AUDIT_READ | GR_AUDIT_WRITE |
56846 + GR_SUPPRESS, parent_mnt);
56847 + comp2 =
56848 + gr_search_file(old_dentry,
56849 + GR_READ | GR_WRITE | GR_AUDIT_READ |
56850 + GR_DELETE | GR_AUDIT_DELETE |
56851 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
56852 + }
56853 +
56854 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
56855 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
56856 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
56857 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
56858 + && !(comp2 & GR_SUPPRESS)) {
56859 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
56860 + error = -EACCES;
56861 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
56862 + error = -EACCES;
56863 +
56864 + return error;
56865 +}
56866 +
56867 +void
56868 +gr_acl_handle_exit(void)
56869 +{
56870 + u16 id;
56871 + char *rolename;
56872 + struct file *exec_file;
56873 +
56874 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
56875 + !(current->role->roletype & GR_ROLE_PERSIST))) {
56876 + id = current->acl_role_id;
56877 + rolename = current->role->rolename;
56878 + gr_set_acls(1);
56879 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
56880 + }
56881 +
56882 + write_lock(&grsec_exec_file_lock);
56883 + exec_file = current->exec_file;
56884 + current->exec_file = NULL;
56885 + write_unlock(&grsec_exec_file_lock);
56886 +
56887 + if (exec_file)
56888 + fput(exec_file);
56889 +}
56890 +
56891 +int
56892 +gr_acl_handle_procpidmem(const struct task_struct *task)
56893 +{
56894 + if (unlikely(!gr_acl_is_enabled()))
56895 + return 0;
56896 +
56897 + if (task != current && task->acl->mode & GR_PROTPROCFD)
56898 + return -EACCES;
56899 +
56900 + return 0;
56901 +}
56902 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
56903 new file mode 100644
56904 index 0000000..58800a7
56905 --- /dev/null
56906 +++ b/grsecurity/gracl_ip.c
56907 @@ -0,0 +1,384 @@
56908 +#include <linux/kernel.h>
56909 +#include <asm/uaccess.h>
56910 +#include <asm/errno.h>
56911 +#include <net/sock.h>
56912 +#include <linux/file.h>
56913 +#include <linux/fs.h>
56914 +#include <linux/net.h>
56915 +#include <linux/in.h>
56916 +#include <linux/skbuff.h>
56917 +#include <linux/ip.h>
56918 +#include <linux/udp.h>
56919 +#include <linux/types.h>
56920 +#include <linux/sched.h>
56921 +#include <linux/netdevice.h>
56922 +#include <linux/inetdevice.h>
56923 +#include <linux/gracl.h>
56924 +#include <linux/grsecurity.h>
56925 +#include <linux/grinternal.h>
56926 +
56927 +#define GR_BIND 0x01
56928 +#define GR_CONNECT 0x02
56929 +#define GR_INVERT 0x04
56930 +#define GR_BINDOVERRIDE 0x08
56931 +#define GR_CONNECTOVERRIDE 0x10
56932 +#define GR_SOCK_FAMILY 0x20
56933 +
56934 +static const char * gr_protocols[IPPROTO_MAX] = {
56935 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
56936 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
56937 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
56938 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
56939 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
56940 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
56941 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
56942 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
56943 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
56944 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
56945 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
56946 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
56947 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
56948 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
56949 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
56950 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
56951 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
56952 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
56953 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
56954 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
56955 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
56956 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
56957 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
56958 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
56959 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
56960 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
56961 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
56962 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
56963 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
56964 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
56965 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
56966 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
56967 + };
56968 +
56969 +static const char * gr_socktypes[SOCK_MAX] = {
56970 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
56971 + "unknown:7", "unknown:8", "unknown:9", "packet"
56972 + };
56973 +
56974 +static const char * gr_sockfamilies[AF_MAX+1] = {
56975 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
56976 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
56977 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
56978 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
56979 + };
56980 +
56981 +const char *
56982 +gr_proto_to_name(unsigned char proto)
56983 +{
56984 + return gr_protocols[proto];
56985 +}
56986 +
56987 +const char *
56988 +gr_socktype_to_name(unsigned char type)
56989 +{
56990 + return gr_socktypes[type];
56991 +}
56992 +
56993 +const char *
56994 +gr_sockfamily_to_name(unsigned char family)
56995 +{
56996 + return gr_sockfamilies[family];
56997 +}
56998 +
56999 +int
57000 +gr_search_socket(const int domain, const int type, const int protocol)
57001 +{
57002 + struct acl_subject_label *curr;
57003 + const struct cred *cred = current_cred();
57004 +
57005 + if (unlikely(!gr_acl_is_enabled()))
57006 + goto exit;
57007 +
57008 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
57009 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
57010 + goto exit; // let the kernel handle it
57011 +
57012 + curr = current->acl;
57013 +
57014 + if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
57015 + /* the family is allowed, if this is PF_INET allow it only if
57016 + the extra sock type/protocol checks pass */
57017 + if (domain == PF_INET)
57018 + goto inet_check;
57019 + goto exit;
57020 + } else {
57021 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
57022 + __u32 fakeip = 0;
57023 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
57024 + current->role->roletype, cred->uid,
57025 + cred->gid, current->exec_file ?
57026 + gr_to_filename(current->exec_file->f_path.dentry,
57027 + current->exec_file->f_path.mnt) :
57028 + curr->filename, curr->filename,
57029 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
57030 + &current->signal->saved_ip);
57031 + goto exit;
57032 + }
57033 + goto exit_fail;
57034 + }
57035 +
57036 +inet_check:
57037 + /* the rest of this checking is for IPv4 only */
57038 + if (!curr->ips)
57039 + goto exit;
57040 +
57041 + if ((curr->ip_type & (1 << type)) &&
57042 + (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
57043 + goto exit;
57044 +
57045 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
57046 + /* we don't place acls on raw sockets , and sometimes
57047 + dgram/ip sockets are opened for ioctl and not
57048 + bind/connect, so we'll fake a bind learn log */
57049 + if (type == SOCK_RAW || type == SOCK_PACKET) {
57050 + __u32 fakeip = 0;
57051 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
57052 + current->role->roletype, cred->uid,
57053 + cred->gid, current->exec_file ?
57054 + gr_to_filename(current->exec_file->f_path.dentry,
57055 + current->exec_file->f_path.mnt) :
57056 + curr->filename, curr->filename,
57057 + &fakeip, 0, type,
57058 + protocol, GR_CONNECT, &current->signal->saved_ip);
57059 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
57060 + __u32 fakeip = 0;
57061 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
57062 + current->role->roletype, cred->uid,
57063 + cred->gid, current->exec_file ?
57064 + gr_to_filename(current->exec_file->f_path.dentry,
57065 + current->exec_file->f_path.mnt) :
57066 + curr->filename, curr->filename,
57067 + &fakeip, 0, type,
57068 + protocol, GR_BIND, &current->signal->saved_ip);
57069 + }
57070 + /* we'll log when they use connect or bind */
57071 + goto exit;
57072 + }
57073 +
57074 +exit_fail:
57075 + if (domain == PF_INET)
57076 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
57077 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
57078 + else
57079 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
57080 + gr_socktype_to_name(type), protocol);
57081 +
57082 + return 0;
57083 +exit:
57084 + return 1;
57085 +}
57086 +
57087 +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)
57088 +{
57089 + if ((ip->mode & mode) &&
57090 + (ip_port >= ip->low) &&
57091 + (ip_port <= ip->high) &&
57092 + ((ntohl(ip_addr) & our_netmask) ==
57093 + (ntohl(our_addr) & our_netmask))
57094 + && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
57095 + && (ip->type & (1 << type))) {
57096 + if (ip->mode & GR_INVERT)
57097 + return 2; // specifically denied
57098 + else
57099 + return 1; // allowed
57100 + }
57101 +
57102 + return 0; // not specifically allowed, may continue parsing
57103 +}
57104 +
57105 +static int
57106 +gr_search_connectbind(const int full_mode, struct sock *sk,
57107 + struct sockaddr_in *addr, const int type)
57108 +{
57109 + char iface[IFNAMSIZ] = {0};
57110 + struct acl_subject_label *curr;
57111 + struct acl_ip_label *ip;
57112 + struct inet_sock *isk;
57113 + struct net_device *dev;
57114 + struct in_device *idev;
57115 + unsigned long i;
57116 + int ret;
57117 + int mode = full_mode & (GR_BIND | GR_CONNECT);
57118 + __u32 ip_addr = 0;
57119 + __u32 our_addr;
57120 + __u32 our_netmask;
57121 + char *p;
57122 + __u16 ip_port = 0;
57123 + const struct cred *cred = current_cred();
57124 +
57125 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
57126 + return 0;
57127 +
57128 + curr = current->acl;
57129 + isk = inet_sk(sk);
57130 +
57131 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
57132 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
57133 + addr->sin_addr.s_addr = curr->inaddr_any_override;
57134 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
57135 + struct sockaddr_in saddr;
57136 + int err;
57137 +
57138 + saddr.sin_family = AF_INET;
57139 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
57140 + saddr.sin_port = isk->inet_sport;
57141 +
57142 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
57143 + if (err)
57144 + return err;
57145 +
57146 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
57147 + if (err)
57148 + return err;
57149 + }
57150 +
57151 + if (!curr->ips)
57152 + return 0;
57153 +
57154 + ip_addr = addr->sin_addr.s_addr;
57155 + ip_port = ntohs(addr->sin_port);
57156 +
57157 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
57158 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
57159 + current->role->roletype, cred->uid,
57160 + cred->gid, current->exec_file ?
57161 + gr_to_filename(current->exec_file->f_path.dentry,
57162 + current->exec_file->f_path.mnt) :
57163 + curr->filename, curr->filename,
57164 + &ip_addr, ip_port, type,
57165 + sk->sk_protocol, mode, &current->signal->saved_ip);
57166 + return 0;
57167 + }
57168 +
57169 + for (i = 0; i < curr->ip_num; i++) {
57170 + ip = *(curr->ips + i);
57171 + if (ip->iface != NULL) {
57172 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
57173 + p = strchr(iface, ':');
57174 + if (p != NULL)
57175 + *p = '\0';
57176 + dev = dev_get_by_name(sock_net(sk), iface);
57177 + if (dev == NULL)
57178 + continue;
57179 + idev = in_dev_get(dev);
57180 + if (idev == NULL) {
57181 + dev_put(dev);
57182 + continue;
57183 + }
57184 + rcu_read_lock();
57185 + for_ifa(idev) {
57186 + if (!strcmp(ip->iface, ifa->ifa_label)) {
57187 + our_addr = ifa->ifa_address;
57188 + our_netmask = 0xffffffff;
57189 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
57190 + if (ret == 1) {
57191 + rcu_read_unlock();
57192 + in_dev_put(idev);
57193 + dev_put(dev);
57194 + return 0;
57195 + } else if (ret == 2) {
57196 + rcu_read_unlock();
57197 + in_dev_put(idev);
57198 + dev_put(dev);
57199 + goto denied;
57200 + }
57201 + }
57202 + } endfor_ifa(idev);
57203 + rcu_read_unlock();
57204 + in_dev_put(idev);
57205 + dev_put(dev);
57206 + } else {
57207 + our_addr = ip->addr;
57208 + our_netmask = ip->netmask;
57209 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
57210 + if (ret == 1)
57211 + return 0;
57212 + else if (ret == 2)
57213 + goto denied;
57214 + }
57215 + }
57216 +
57217 +denied:
57218 + if (mode == GR_BIND)
57219 + 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));
57220 + else if (mode == GR_CONNECT)
57221 + 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));
57222 +
57223 + return -EACCES;
57224 +}
57225 +
57226 +int
57227 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
57228 +{
57229 + /* always allow disconnection of dgram sockets with connect */
57230 + if (addr->sin_family == AF_UNSPEC)
57231 + return 0;
57232 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
57233 +}
57234 +
57235 +int
57236 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
57237 +{
57238 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
57239 +}
57240 +
57241 +int gr_search_listen(struct socket *sock)
57242 +{
57243 + struct sock *sk = sock->sk;
57244 + struct sockaddr_in addr;
57245 +
57246 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
57247 + addr.sin_port = inet_sk(sk)->inet_sport;
57248 +
57249 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
57250 +}
57251 +
57252 +int gr_search_accept(struct socket *sock)
57253 +{
57254 + struct sock *sk = sock->sk;
57255 + struct sockaddr_in addr;
57256 +
57257 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
57258 + addr.sin_port = inet_sk(sk)->inet_sport;
57259 +
57260 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
57261 +}
57262 +
57263 +int
57264 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
57265 +{
57266 + if (addr)
57267 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
57268 + else {
57269 + struct sockaddr_in sin;
57270 + const struct inet_sock *inet = inet_sk(sk);
57271 +
57272 + sin.sin_addr.s_addr = inet->inet_daddr;
57273 + sin.sin_port = inet->inet_dport;
57274 +
57275 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
57276 + }
57277 +}
57278 +
57279 +int
57280 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
57281 +{
57282 + struct sockaddr_in sin;
57283 +
57284 + if (unlikely(skb->len < sizeof (struct udphdr)))
57285 + return 0; // skip this packet
57286 +
57287 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
57288 + sin.sin_port = udp_hdr(skb)->source;
57289 +
57290 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
57291 +}
57292 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
57293 new file mode 100644
57294 index 0000000..25f54ef
57295 --- /dev/null
57296 +++ b/grsecurity/gracl_learn.c
57297 @@ -0,0 +1,207 @@
57298 +#include <linux/kernel.h>
57299 +#include <linux/mm.h>
57300 +#include <linux/sched.h>
57301 +#include <linux/poll.h>
57302 +#include <linux/string.h>
57303 +#include <linux/file.h>
57304 +#include <linux/types.h>
57305 +#include <linux/vmalloc.h>
57306 +#include <linux/grinternal.h>
57307 +
57308 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
57309 + size_t count, loff_t *ppos);
57310 +extern int gr_acl_is_enabled(void);
57311 +
57312 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
57313 +static int gr_learn_attached;
57314 +
57315 +/* use a 512k buffer */
57316 +#define LEARN_BUFFER_SIZE (512 * 1024)
57317 +
57318 +static DEFINE_SPINLOCK(gr_learn_lock);
57319 +static DEFINE_MUTEX(gr_learn_user_mutex);
57320 +
57321 +/* we need to maintain two buffers, so that the kernel context of grlearn
57322 + uses a semaphore around the userspace copying, and the other kernel contexts
57323 + use a spinlock when copying into the buffer, since they cannot sleep
57324 +*/
57325 +static char *learn_buffer;
57326 +static char *learn_buffer_user;
57327 +static int learn_buffer_len;
57328 +static int learn_buffer_user_len;
57329 +
57330 +static ssize_t
57331 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
57332 +{
57333 + DECLARE_WAITQUEUE(wait, current);
57334 + ssize_t retval = 0;
57335 +
57336 + add_wait_queue(&learn_wait, &wait);
57337 + set_current_state(TASK_INTERRUPTIBLE);
57338 + do {
57339 + mutex_lock(&gr_learn_user_mutex);
57340 + spin_lock(&gr_learn_lock);
57341 + if (learn_buffer_len)
57342 + break;
57343 + spin_unlock(&gr_learn_lock);
57344 + mutex_unlock(&gr_learn_user_mutex);
57345 + if (file->f_flags & O_NONBLOCK) {
57346 + retval = -EAGAIN;
57347 + goto out;
57348 + }
57349 + if (signal_pending(current)) {
57350 + retval = -ERESTARTSYS;
57351 + goto out;
57352 + }
57353 +
57354 + schedule();
57355 + } while (1);
57356 +
57357 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
57358 + learn_buffer_user_len = learn_buffer_len;
57359 + retval = learn_buffer_len;
57360 + learn_buffer_len = 0;
57361 +
57362 + spin_unlock(&gr_learn_lock);
57363 +
57364 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
57365 + retval = -EFAULT;
57366 +
57367 + mutex_unlock(&gr_learn_user_mutex);
57368 +out:
57369 + set_current_state(TASK_RUNNING);
57370 + remove_wait_queue(&learn_wait, &wait);
57371 + return retval;
57372 +}
57373 +
57374 +static unsigned int
57375 +poll_learn(struct file * file, poll_table * wait)
57376 +{
57377 + poll_wait(file, &learn_wait, wait);
57378 +
57379 + if (learn_buffer_len)
57380 + return (POLLIN | POLLRDNORM);
57381 +
57382 + return 0;
57383 +}
57384 +
57385 +void
57386 +gr_clear_learn_entries(void)
57387 +{
57388 + char *tmp;
57389 +
57390 + mutex_lock(&gr_learn_user_mutex);
57391 + spin_lock(&gr_learn_lock);
57392 + tmp = learn_buffer;
57393 + learn_buffer = NULL;
57394 + spin_unlock(&gr_learn_lock);
57395 + if (tmp)
57396 + vfree(tmp);
57397 + if (learn_buffer_user != NULL) {
57398 + vfree(learn_buffer_user);
57399 + learn_buffer_user = NULL;
57400 + }
57401 + learn_buffer_len = 0;
57402 + mutex_unlock(&gr_learn_user_mutex);
57403 +
57404 + return;
57405 +}
57406 +
57407 +void
57408 +gr_add_learn_entry(const char *fmt, ...)
57409 +{
57410 + va_list args;
57411 + unsigned int len;
57412 +
57413 + if (!gr_learn_attached)
57414 + return;
57415 +
57416 + spin_lock(&gr_learn_lock);
57417 +
57418 + /* leave a gap at the end so we know when it's "full" but don't have to
57419 + compute the exact length of the string we're trying to append
57420 + */
57421 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
57422 + spin_unlock(&gr_learn_lock);
57423 + wake_up_interruptible(&learn_wait);
57424 + return;
57425 + }
57426 + if (learn_buffer == NULL) {
57427 + spin_unlock(&gr_learn_lock);
57428 + return;
57429 + }
57430 +
57431 + va_start(args, fmt);
57432 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
57433 + va_end(args);
57434 +
57435 + learn_buffer_len += len + 1;
57436 +
57437 + spin_unlock(&gr_learn_lock);
57438 + wake_up_interruptible(&learn_wait);
57439 +
57440 + return;
57441 +}
57442 +
57443 +static int
57444 +open_learn(struct inode *inode, struct file *file)
57445 +{
57446 + if (file->f_mode & FMODE_READ && gr_learn_attached)
57447 + return -EBUSY;
57448 + if (file->f_mode & FMODE_READ) {
57449 + int retval = 0;
57450 + mutex_lock(&gr_learn_user_mutex);
57451 + if (learn_buffer == NULL)
57452 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
57453 + if (learn_buffer_user == NULL)
57454 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
57455 + if (learn_buffer == NULL) {
57456 + retval = -ENOMEM;
57457 + goto out_error;
57458 + }
57459 + if (learn_buffer_user == NULL) {
57460 + retval = -ENOMEM;
57461 + goto out_error;
57462 + }
57463 + learn_buffer_len = 0;
57464 + learn_buffer_user_len = 0;
57465 + gr_learn_attached = 1;
57466 +out_error:
57467 + mutex_unlock(&gr_learn_user_mutex);
57468 + return retval;
57469 + }
57470 + return 0;
57471 +}
57472 +
57473 +static int
57474 +close_learn(struct inode *inode, struct file *file)
57475 +{
57476 + if (file->f_mode & FMODE_READ) {
57477 + char *tmp = NULL;
57478 + mutex_lock(&gr_learn_user_mutex);
57479 + spin_lock(&gr_learn_lock);
57480 + tmp = learn_buffer;
57481 + learn_buffer = NULL;
57482 + spin_unlock(&gr_learn_lock);
57483 + if (tmp)
57484 + vfree(tmp);
57485 + if (learn_buffer_user != NULL) {
57486 + vfree(learn_buffer_user);
57487 + learn_buffer_user = NULL;
57488 + }
57489 + learn_buffer_len = 0;
57490 + learn_buffer_user_len = 0;
57491 + gr_learn_attached = 0;
57492 + mutex_unlock(&gr_learn_user_mutex);
57493 + }
57494 +
57495 + return 0;
57496 +}
57497 +
57498 +const struct file_operations grsec_fops = {
57499 + .read = read_learn,
57500 + .write = write_grsec_handler,
57501 + .open = open_learn,
57502 + .release = close_learn,
57503 + .poll = poll_learn,
57504 +};
57505 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
57506 new file mode 100644
57507 index 0000000..39645c9
57508 --- /dev/null
57509 +++ b/grsecurity/gracl_res.c
57510 @@ -0,0 +1,68 @@
57511 +#include <linux/kernel.h>
57512 +#include <linux/sched.h>
57513 +#include <linux/gracl.h>
57514 +#include <linux/grinternal.h>
57515 +
57516 +static const char *restab_log[] = {
57517 + [RLIMIT_CPU] = "RLIMIT_CPU",
57518 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
57519 + [RLIMIT_DATA] = "RLIMIT_DATA",
57520 + [RLIMIT_STACK] = "RLIMIT_STACK",
57521 + [RLIMIT_CORE] = "RLIMIT_CORE",
57522 + [RLIMIT_RSS] = "RLIMIT_RSS",
57523 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
57524 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
57525 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
57526 + [RLIMIT_AS] = "RLIMIT_AS",
57527 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
57528 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
57529 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
57530 + [RLIMIT_NICE] = "RLIMIT_NICE",
57531 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
57532 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
57533 + [GR_CRASH_RES] = "RLIMIT_CRASH"
57534 +};
57535 +
57536 +void
57537 +gr_log_resource(const struct task_struct *task,
57538 + const int res, const unsigned long wanted, const int gt)
57539 +{
57540 + const struct cred *cred;
57541 + unsigned long rlim;
57542 +
57543 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
57544 + return;
57545 +
57546 + // not yet supported resource
57547 + if (unlikely(!restab_log[res]))
57548 + return;
57549 +
57550 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
57551 + rlim = task_rlimit_max(task, res);
57552 + else
57553 + rlim = task_rlimit(task, res);
57554 +
57555 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
57556 + return;
57557 +
57558 + rcu_read_lock();
57559 + cred = __task_cred(task);
57560 +
57561 + if (res == RLIMIT_NPROC &&
57562 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
57563 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
57564 + goto out_rcu_unlock;
57565 + else if (res == RLIMIT_MEMLOCK &&
57566 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
57567 + goto out_rcu_unlock;
57568 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
57569 + goto out_rcu_unlock;
57570 + rcu_read_unlock();
57571 +
57572 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
57573 +
57574 + return;
57575 +out_rcu_unlock:
57576 + rcu_read_unlock();
57577 + return;
57578 +}
57579 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
57580 new file mode 100644
57581 index 0000000..25197e9
57582 --- /dev/null
57583 +++ b/grsecurity/gracl_segv.c
57584 @@ -0,0 +1,299 @@
57585 +#include <linux/kernel.h>
57586 +#include <linux/mm.h>
57587 +#include <asm/uaccess.h>
57588 +#include <asm/errno.h>
57589 +#include <asm/mman.h>
57590 +#include <net/sock.h>
57591 +#include <linux/file.h>
57592 +#include <linux/fs.h>
57593 +#include <linux/net.h>
57594 +#include <linux/in.h>
57595 +#include <linux/slab.h>
57596 +#include <linux/types.h>
57597 +#include <linux/sched.h>
57598 +#include <linux/timer.h>
57599 +#include <linux/gracl.h>
57600 +#include <linux/grsecurity.h>
57601 +#include <linux/grinternal.h>
57602 +
57603 +static struct crash_uid *uid_set;
57604 +static unsigned short uid_used;
57605 +static DEFINE_SPINLOCK(gr_uid_lock);
57606 +extern rwlock_t gr_inode_lock;
57607 +extern struct acl_subject_label *
57608 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
57609 + struct acl_role_label *role);
57610 +
57611 +#ifdef CONFIG_BTRFS_FS
57612 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
57613 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
57614 +#endif
57615 +
57616 +static inline dev_t __get_dev(const struct dentry *dentry)
57617 +{
57618 +#ifdef CONFIG_BTRFS_FS
57619 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
57620 + return get_btrfs_dev_from_inode(dentry->d_inode);
57621 + else
57622 +#endif
57623 + return dentry->d_inode->i_sb->s_dev;
57624 +}
57625 +
57626 +int
57627 +gr_init_uidset(void)
57628 +{
57629 + uid_set =
57630 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
57631 + uid_used = 0;
57632 +
57633 + return uid_set ? 1 : 0;
57634 +}
57635 +
57636 +void
57637 +gr_free_uidset(void)
57638 +{
57639 + if (uid_set)
57640 + kfree(uid_set);
57641 +
57642 + return;
57643 +}
57644 +
57645 +int
57646 +gr_find_uid(const uid_t uid)
57647 +{
57648 + struct crash_uid *tmp = uid_set;
57649 + uid_t buid;
57650 + int low = 0, high = uid_used - 1, mid;
57651 +
57652 + while (high >= low) {
57653 + mid = (low + high) >> 1;
57654 + buid = tmp[mid].uid;
57655 + if (buid == uid)
57656 + return mid;
57657 + if (buid > uid)
57658 + high = mid - 1;
57659 + if (buid < uid)
57660 + low = mid + 1;
57661 + }
57662 +
57663 + return -1;
57664 +}
57665 +
57666 +static __inline__ void
57667 +gr_insertsort(void)
57668 +{
57669 + unsigned short i, j;
57670 + struct crash_uid index;
57671 +
57672 + for (i = 1; i < uid_used; i++) {
57673 + index = uid_set[i];
57674 + j = i;
57675 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
57676 + uid_set[j] = uid_set[j - 1];
57677 + j--;
57678 + }
57679 + uid_set[j] = index;
57680 + }
57681 +
57682 + return;
57683 +}
57684 +
57685 +static __inline__ void
57686 +gr_insert_uid(const uid_t uid, const unsigned long expires)
57687 +{
57688 + int loc;
57689 +
57690 + if (uid_used == GR_UIDTABLE_MAX)
57691 + return;
57692 +
57693 + loc = gr_find_uid(uid);
57694 +
57695 + if (loc >= 0) {
57696 + uid_set[loc].expires = expires;
57697 + return;
57698 + }
57699 +
57700 + uid_set[uid_used].uid = uid;
57701 + uid_set[uid_used].expires = expires;
57702 + uid_used++;
57703 +
57704 + gr_insertsort();
57705 +
57706 + return;
57707 +}
57708 +
57709 +void
57710 +gr_remove_uid(const unsigned short loc)
57711 +{
57712 + unsigned short i;
57713 +
57714 + for (i = loc + 1; i < uid_used; i++)
57715 + uid_set[i - 1] = uid_set[i];
57716 +
57717 + uid_used--;
57718 +
57719 + return;
57720 +}
57721 +
57722 +int
57723 +gr_check_crash_uid(const uid_t uid)
57724 +{
57725 + int loc;
57726 + int ret = 0;
57727 +
57728 + if (unlikely(!gr_acl_is_enabled()))
57729 + return 0;
57730 +
57731 + spin_lock(&gr_uid_lock);
57732 + loc = gr_find_uid(uid);
57733 +
57734 + if (loc < 0)
57735 + goto out_unlock;
57736 +
57737 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
57738 + gr_remove_uid(loc);
57739 + else
57740 + ret = 1;
57741 +
57742 +out_unlock:
57743 + spin_unlock(&gr_uid_lock);
57744 + return ret;
57745 +}
57746 +
57747 +static __inline__ int
57748 +proc_is_setxid(const struct cred *cred)
57749 +{
57750 + if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
57751 + !uid_eq(cred->uid, cred->fsuid))
57752 + return 1;
57753 + if (!uid_eq(cred->gid, cred->egid) || !uid_eq(cred->gid, cred->sgid) ||
57754 + !uid_eq(cred->gid, cred->fsgid))
57755 + return 1;
57756 +
57757 + return 0;
57758 +}
57759 +
57760 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
57761 +
57762 +void
57763 +gr_handle_crash(struct task_struct *task, const int sig)
57764 +{
57765 + struct acl_subject_label *curr;
57766 + struct task_struct *tsk, *tsk2;
57767 + const struct cred *cred;
57768 + const struct cred *cred2;
57769 +
57770 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
57771 + return;
57772 +
57773 + if (unlikely(!gr_acl_is_enabled()))
57774 + return;
57775 +
57776 + curr = task->acl;
57777 +
57778 + if (!(curr->resmask & (1 << GR_CRASH_RES)))
57779 + return;
57780 +
57781 + if (time_before_eq(curr->expires, get_seconds())) {
57782 + curr->expires = 0;
57783 + curr->crashes = 0;
57784 + }
57785 +
57786 + curr->crashes++;
57787 +
57788 + if (!curr->expires)
57789 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
57790 +
57791 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
57792 + time_after(curr->expires, get_seconds())) {
57793 + rcu_read_lock();
57794 + cred = __task_cred(task);
57795 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && proc_is_setxid(cred)) {
57796 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
57797 + spin_lock(&gr_uid_lock);
57798 + gr_insert_uid(cred->uid, curr->expires);
57799 + spin_unlock(&gr_uid_lock);
57800 + curr->expires = 0;
57801 + curr->crashes = 0;
57802 + read_lock(&tasklist_lock);
57803 + do_each_thread(tsk2, tsk) {
57804 + cred2 = __task_cred(tsk);
57805 + if (tsk != task && uid_eq(cred2->uid, cred->uid))
57806 + gr_fake_force_sig(SIGKILL, tsk);
57807 + } while_each_thread(tsk2, tsk);
57808 + read_unlock(&tasklist_lock);
57809 + } else {
57810 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
57811 + read_lock(&tasklist_lock);
57812 + read_lock(&grsec_exec_file_lock);
57813 + do_each_thread(tsk2, tsk) {
57814 + if (likely(tsk != task)) {
57815 + // if this thread has the same subject as the one that triggered
57816 + // RES_CRASH and it's the same binary, kill it
57817 + if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
57818 + gr_fake_force_sig(SIGKILL, tsk);
57819 + }
57820 + } while_each_thread(tsk2, tsk);
57821 + read_unlock(&grsec_exec_file_lock);
57822 + read_unlock(&tasklist_lock);
57823 + }
57824 + rcu_read_unlock();
57825 + }
57826 +
57827 + return;
57828 +}
57829 +
57830 +int
57831 +gr_check_crash_exec(const struct file *filp)
57832 +{
57833 + struct acl_subject_label *curr;
57834 +
57835 + if (unlikely(!gr_acl_is_enabled()))
57836 + return 0;
57837 +
57838 + read_lock(&gr_inode_lock);
57839 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
57840 + __get_dev(filp->f_path.dentry),
57841 + current->role);
57842 + read_unlock(&gr_inode_lock);
57843 +
57844 + if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
57845 + (!curr->crashes && !curr->expires))
57846 + return 0;
57847 +
57848 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
57849 + time_after(curr->expires, get_seconds()))
57850 + return 1;
57851 + else if (time_before_eq(curr->expires, get_seconds())) {
57852 + curr->crashes = 0;
57853 + curr->expires = 0;
57854 + }
57855 +
57856 + return 0;
57857 +}
57858 +
57859 +void
57860 +gr_handle_alertkill(struct task_struct *task)
57861 +{
57862 + struct acl_subject_label *curracl;
57863 + __u32 curr_ip;
57864 + struct task_struct *p, *p2;
57865 +
57866 + if (unlikely(!gr_acl_is_enabled()))
57867 + return;
57868 +
57869 + curracl = task->acl;
57870 + curr_ip = task->signal->curr_ip;
57871 +
57872 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
57873 + read_lock(&tasklist_lock);
57874 + do_each_thread(p2, p) {
57875 + if (p->signal->curr_ip == curr_ip)
57876 + gr_fake_force_sig(SIGKILL, p);
57877 + } while_each_thread(p2, p);
57878 + read_unlock(&tasklist_lock);
57879 + } else if (curracl->mode & GR_KILLPROC)
57880 + gr_fake_force_sig(SIGKILL, task);
57881 +
57882 + return;
57883 +}
57884 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
57885 new file mode 100644
57886 index 0000000..9d83a69
57887 --- /dev/null
57888 +++ b/grsecurity/gracl_shm.c
57889 @@ -0,0 +1,40 @@
57890 +#include <linux/kernel.h>
57891 +#include <linux/mm.h>
57892 +#include <linux/sched.h>
57893 +#include <linux/file.h>
57894 +#include <linux/ipc.h>
57895 +#include <linux/gracl.h>
57896 +#include <linux/grsecurity.h>
57897 +#include <linux/grinternal.h>
57898 +
57899 +int
57900 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57901 + const time_t shm_createtime, const uid_t cuid, const int shmid)
57902 +{
57903 + struct task_struct *task;
57904 +
57905 + if (!gr_acl_is_enabled())
57906 + return 1;
57907 +
57908 + rcu_read_lock();
57909 + read_lock(&tasklist_lock);
57910 +
57911 + task = find_task_by_vpid(shm_cprid);
57912 +
57913 + if (unlikely(!task))
57914 + task = find_task_by_vpid(shm_lapid);
57915 +
57916 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
57917 + (task->pid == shm_lapid)) &&
57918 + (task->acl->mode & GR_PROTSHM) &&
57919 + (task->acl != current->acl))) {
57920 + read_unlock(&tasklist_lock);
57921 + rcu_read_unlock();
57922 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
57923 + return 0;
57924 + }
57925 + read_unlock(&tasklist_lock);
57926 + rcu_read_unlock();
57927 +
57928 + return 1;
57929 +}
57930 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
57931 new file mode 100644
57932 index 0000000..bc0be01
57933 --- /dev/null
57934 +++ b/grsecurity/grsec_chdir.c
57935 @@ -0,0 +1,19 @@
57936 +#include <linux/kernel.h>
57937 +#include <linux/sched.h>
57938 +#include <linux/fs.h>
57939 +#include <linux/file.h>
57940 +#include <linux/grsecurity.h>
57941 +#include <linux/grinternal.h>
57942 +
57943 +void
57944 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
57945 +{
57946 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
57947 + if ((grsec_enable_chdir && grsec_enable_group &&
57948 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
57949 + !grsec_enable_group)) {
57950 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
57951 + }
57952 +#endif
57953 + return;
57954 +}
57955 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
57956 new file mode 100644
57957 index 0000000..9807ee2
57958 --- /dev/null
57959 +++ b/grsecurity/grsec_chroot.c
57960 @@ -0,0 +1,368 @@
57961 +#include <linux/kernel.h>
57962 +#include <linux/module.h>
57963 +#include <linux/sched.h>
57964 +#include <linux/file.h>
57965 +#include <linux/fs.h>
57966 +#include <linux/mount.h>
57967 +#include <linux/types.h>
57968 +#include "../fs/mount.h"
57969 +#include <linux/grsecurity.h>
57970 +#include <linux/grinternal.h>
57971 +
57972 +void gr_set_chroot_entries(struct task_struct *task, struct path *path)
57973 +{
57974 +#ifdef CONFIG_GRKERNSEC
57975 + if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
57976 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
57977 + task->gr_is_chrooted = 1;
57978 + else
57979 + task->gr_is_chrooted = 0;
57980 +
57981 + task->gr_chroot_dentry = path->dentry;
57982 +#endif
57983 + return;
57984 +}
57985 +
57986 +void gr_clear_chroot_entries(struct task_struct *task)
57987 +{
57988 +#ifdef CONFIG_GRKERNSEC
57989 + task->gr_is_chrooted = 0;
57990 + task->gr_chroot_dentry = NULL;
57991 +#endif
57992 + return;
57993 +}
57994 +
57995 +int
57996 +gr_handle_chroot_unix(const pid_t pid)
57997 +{
57998 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
57999 + struct task_struct *p;
58000 +
58001 + if (unlikely(!grsec_enable_chroot_unix))
58002 + return 1;
58003 +
58004 + if (likely(!proc_is_chrooted(current)))
58005 + return 1;
58006 +
58007 + rcu_read_lock();
58008 + read_lock(&tasklist_lock);
58009 + p = find_task_by_vpid_unrestricted(pid);
58010 + if (unlikely(p && !have_same_root(current, p))) {
58011 + read_unlock(&tasklist_lock);
58012 + rcu_read_unlock();
58013 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
58014 + return 0;
58015 + }
58016 + read_unlock(&tasklist_lock);
58017 + rcu_read_unlock();
58018 +#endif
58019 + return 1;
58020 +}
58021 +
58022 +int
58023 +gr_handle_chroot_nice(void)
58024 +{
58025 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
58026 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
58027 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
58028 + return -EPERM;
58029 + }
58030 +#endif
58031 + return 0;
58032 +}
58033 +
58034 +int
58035 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
58036 +{
58037 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
58038 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
58039 + && proc_is_chrooted(current)) {
58040 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
58041 + return -EACCES;
58042 + }
58043 +#endif
58044 + return 0;
58045 +}
58046 +
58047 +int
58048 +gr_handle_chroot_rawio(const struct inode *inode)
58049 +{
58050 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58051 + if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
58052 + inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
58053 + return 1;
58054 +#endif
58055 + return 0;
58056 +}
58057 +
58058 +int
58059 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
58060 +{
58061 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
58062 + struct task_struct *p;
58063 + int ret = 0;
58064 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
58065 + return ret;
58066 +
58067 + read_lock(&tasklist_lock);
58068 + do_each_pid_task(pid, type, p) {
58069 + if (!have_same_root(current, p)) {
58070 + ret = 1;
58071 + goto out;
58072 + }
58073 + } while_each_pid_task(pid, type, p);
58074 +out:
58075 + read_unlock(&tasklist_lock);
58076 + return ret;
58077 +#endif
58078 + return 0;
58079 +}
58080 +
58081 +int
58082 +gr_pid_is_chrooted(struct task_struct *p)
58083 +{
58084 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
58085 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
58086 + return 0;
58087 +
58088 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
58089 + !have_same_root(current, p)) {
58090 + return 1;
58091 + }
58092 +#endif
58093 + return 0;
58094 +}
58095 +
58096 +EXPORT_SYMBOL(gr_pid_is_chrooted);
58097 +
58098 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
58099 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
58100 +{
58101 + struct path path, currentroot;
58102 + int ret = 0;
58103 +
58104 + path.dentry = (struct dentry *)u_dentry;
58105 + path.mnt = (struct vfsmount *)u_mnt;
58106 + get_fs_root(current->fs, &currentroot);
58107 + if (path_is_under(&path, &currentroot))
58108 + ret = 1;
58109 + path_put(&currentroot);
58110 +
58111 + return ret;
58112 +}
58113 +#endif
58114 +
58115 +int
58116 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
58117 +{
58118 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
58119 + if (!grsec_enable_chroot_fchdir)
58120 + return 1;
58121 +
58122 + if (!proc_is_chrooted(current))
58123 + return 1;
58124 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
58125 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
58126 + return 0;
58127 + }
58128 +#endif
58129 + return 1;
58130 +}
58131 +
58132 +int
58133 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
58134 + const time_t shm_createtime)
58135 +{
58136 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
58137 + struct task_struct *p;
58138 + time_t starttime;
58139 +
58140 + if (unlikely(!grsec_enable_chroot_shmat))
58141 + return 1;
58142 +
58143 + if (likely(!proc_is_chrooted(current)))
58144 + return 1;
58145 +
58146 + rcu_read_lock();
58147 + read_lock(&tasklist_lock);
58148 +
58149 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
58150 + starttime = p->start_time.tv_sec;
58151 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
58152 + if (have_same_root(current, p)) {
58153 + goto allow;
58154 + } else {
58155 + read_unlock(&tasklist_lock);
58156 + rcu_read_unlock();
58157 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
58158 + return 0;
58159 + }
58160 + }
58161 + /* creator exited, pid reuse, fall through to next check */
58162 + }
58163 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
58164 + if (unlikely(!have_same_root(current, p))) {
58165 + read_unlock(&tasklist_lock);
58166 + rcu_read_unlock();
58167 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
58168 + return 0;
58169 + }
58170 + }
58171 +
58172 +allow:
58173 + read_unlock(&tasklist_lock);
58174 + rcu_read_unlock();
58175 +#endif
58176 + return 1;
58177 +}
58178 +
58179 +void
58180 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
58181 +{
58182 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
58183 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
58184 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
58185 +#endif
58186 + return;
58187 +}
58188 +
58189 +int
58190 +gr_handle_chroot_mknod(const struct dentry *dentry,
58191 + const struct vfsmount *mnt, const int mode)
58192 +{
58193 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
58194 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
58195 + proc_is_chrooted(current)) {
58196 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
58197 + return -EPERM;
58198 + }
58199 +#endif
58200 + return 0;
58201 +}
58202 +
58203 +int
58204 +gr_handle_chroot_mount(const struct dentry *dentry,
58205 + const struct vfsmount *mnt, const char *dev_name)
58206 +{
58207 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
58208 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
58209 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
58210 + return -EPERM;
58211 + }
58212 +#endif
58213 + return 0;
58214 +}
58215 +
58216 +int
58217 +gr_handle_chroot_pivot(void)
58218 +{
58219 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
58220 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
58221 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
58222 + return -EPERM;
58223 + }
58224 +#endif
58225 + return 0;
58226 +}
58227 +
58228 +int
58229 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
58230 +{
58231 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
58232 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
58233 + !gr_is_outside_chroot(dentry, mnt)) {
58234 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
58235 + return -EPERM;
58236 + }
58237 +#endif
58238 + return 0;
58239 +}
58240 +
58241 +extern const char *captab_log[];
58242 +extern int captab_log_entries;
58243 +
58244 +int
58245 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
58246 +{
58247 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58248 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
58249 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
58250 + if (cap_raised(chroot_caps, cap)) {
58251 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
58252 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
58253 + }
58254 + return 0;
58255 + }
58256 + }
58257 +#endif
58258 + return 1;
58259 +}
58260 +
58261 +int
58262 +gr_chroot_is_capable(const int cap)
58263 +{
58264 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58265 + return gr_task_chroot_is_capable(current, current_cred(), cap);
58266 +#endif
58267 + return 1;
58268 +}
58269 +
58270 +int
58271 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
58272 +{
58273 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58274 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
58275 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
58276 + if (cap_raised(chroot_caps, cap)) {
58277 + return 0;
58278 + }
58279 + }
58280 +#endif
58281 + return 1;
58282 +}
58283 +
58284 +int
58285 +gr_chroot_is_capable_nolog(const int cap)
58286 +{
58287 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58288 + return gr_task_chroot_is_capable_nolog(current, cap);
58289 +#endif
58290 + return 1;
58291 +}
58292 +
58293 +int
58294 +gr_handle_chroot_sysctl(const int op)
58295 +{
58296 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
58297 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
58298 + proc_is_chrooted(current))
58299 + return -EACCES;
58300 +#endif
58301 + return 0;
58302 +}
58303 +
58304 +void
58305 +gr_handle_chroot_chdir(struct path *path)
58306 +{
58307 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
58308 + if (grsec_enable_chroot_chdir)
58309 + set_fs_pwd(current->fs, path);
58310 +#endif
58311 + return;
58312 +}
58313 +
58314 +int
58315 +gr_handle_chroot_chmod(const struct dentry *dentry,
58316 + const struct vfsmount *mnt, const int mode)
58317 +{
58318 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
58319 + /* allow chmod +s on directories, but not files */
58320 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
58321 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
58322 + proc_is_chrooted(current)) {
58323 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
58324 + return -EPERM;
58325 + }
58326 +#endif
58327 + return 0;
58328 +}
58329 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
58330 new file mode 100644
58331 index 0000000..b79fe50
58332 --- /dev/null
58333 +++ b/grsecurity/grsec_disabled.c
58334 @@ -0,0 +1,442 @@
58335 +#include <linux/kernel.h>
58336 +#include <linux/module.h>
58337 +#include <linux/sched.h>
58338 +#include <linux/file.h>
58339 +#include <linux/fs.h>
58340 +#include <linux/kdev_t.h>
58341 +#include <linux/net.h>
58342 +#include <linux/in.h>
58343 +#include <linux/ip.h>
58344 +#include <linux/skbuff.h>
58345 +#include <linux/sysctl.h>
58346 +
58347 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
58348 +void
58349 +pax_set_initial_flags(struct linux_binprm *bprm)
58350 +{
58351 + return;
58352 +}
58353 +#endif
58354 +
58355 +#ifdef CONFIG_SYSCTL
58356 +__u32
58357 +gr_handle_sysctl(const struct ctl_table * table, const int op)
58358 +{
58359 + return 0;
58360 +}
58361 +#endif
58362 +
58363 +#ifdef CONFIG_TASKSTATS
58364 +int gr_is_taskstats_denied(int pid)
58365 +{
58366 + return 0;
58367 +}
58368 +#endif
58369 +
58370 +int
58371 +gr_acl_is_enabled(void)
58372 +{
58373 + return 0;
58374 +}
58375 +
58376 +void
58377 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
58378 +{
58379 + return;
58380 +}
58381 +
58382 +int
58383 +gr_handle_rawio(const struct inode *inode)
58384 +{
58385 + return 0;
58386 +}
58387 +
58388 +void
58389 +gr_acl_handle_psacct(struct task_struct *task, const long code)
58390 +{
58391 + return;
58392 +}
58393 +
58394 +int
58395 +gr_handle_ptrace(struct task_struct *task, const long request)
58396 +{
58397 + return 0;
58398 +}
58399 +
58400 +int
58401 +gr_handle_proc_ptrace(struct task_struct *task)
58402 +{
58403 + return 0;
58404 +}
58405 +
58406 +void
58407 +gr_learn_resource(const struct task_struct *task,
58408 + const int res, const unsigned long wanted, const int gt)
58409 +{
58410 + return;
58411 +}
58412 +
58413 +int
58414 +gr_set_acls(const int type)
58415 +{
58416 + return 0;
58417 +}
58418 +
58419 +int
58420 +gr_check_hidden_task(const struct task_struct *tsk)
58421 +{
58422 + return 0;
58423 +}
58424 +
58425 +int
58426 +gr_check_protected_task(const struct task_struct *task)
58427 +{
58428 + return 0;
58429 +}
58430 +
58431 +int
58432 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
58433 +{
58434 + return 0;
58435 +}
58436 +
58437 +void
58438 +gr_copy_label(struct task_struct *tsk)
58439 +{
58440 + return;
58441 +}
58442 +
58443 +void
58444 +gr_set_pax_flags(struct task_struct *task)
58445 +{
58446 + return;
58447 +}
58448 +
58449 +int
58450 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
58451 + const int unsafe_share)
58452 +{
58453 + return 0;
58454 +}
58455 +
58456 +void
58457 +gr_handle_delete(const ino_t ino, const dev_t dev)
58458 +{
58459 + return;
58460 +}
58461 +
58462 +void
58463 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
58464 +{
58465 + return;
58466 +}
58467 +
58468 +void
58469 +gr_handle_crash(struct task_struct *task, const int sig)
58470 +{
58471 + return;
58472 +}
58473 +
58474 +int
58475 +gr_check_crash_exec(const struct file *filp)
58476 +{
58477 + return 0;
58478 +}
58479 +
58480 +int
58481 +gr_check_crash_uid(const uid_t uid)
58482 +{
58483 + return 0;
58484 +}
58485 +
58486 +void
58487 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
58488 + struct dentry *old_dentry,
58489 + struct dentry *new_dentry,
58490 + struct vfsmount *mnt, const __u8 replace)
58491 +{
58492 + return;
58493 +}
58494 +
58495 +int
58496 +gr_search_socket(const int family, const int type, const int protocol)
58497 +{
58498 + return 1;
58499 +}
58500 +
58501 +int
58502 +gr_search_connectbind(const int mode, const struct socket *sock,
58503 + const struct sockaddr_in *addr)
58504 +{
58505 + return 0;
58506 +}
58507 +
58508 +void
58509 +gr_handle_alertkill(struct task_struct *task)
58510 +{
58511 + return;
58512 +}
58513 +
58514 +__u32
58515 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
58516 +{
58517 + return 1;
58518 +}
58519 +
58520 +__u32
58521 +gr_acl_handle_hidden_file(const struct dentry * dentry,
58522 + const struct vfsmount * mnt)
58523 +{
58524 + return 1;
58525 +}
58526 +
58527 +__u32
58528 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
58529 + int acc_mode)
58530 +{
58531 + return 1;
58532 +}
58533 +
58534 +__u32
58535 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
58536 +{
58537 + return 1;
58538 +}
58539 +
58540 +__u32
58541 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
58542 +{
58543 + return 1;
58544 +}
58545 +
58546 +int
58547 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
58548 + unsigned int *vm_flags)
58549 +{
58550 + return 1;
58551 +}
58552 +
58553 +__u32
58554 +gr_acl_handle_truncate(const struct dentry * dentry,
58555 + const struct vfsmount * mnt)
58556 +{
58557 + return 1;
58558 +}
58559 +
58560 +__u32
58561 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
58562 +{
58563 + return 1;
58564 +}
58565 +
58566 +__u32
58567 +gr_acl_handle_access(const struct dentry * dentry,
58568 + const struct vfsmount * mnt, const int fmode)
58569 +{
58570 + return 1;
58571 +}
58572 +
58573 +__u32
58574 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
58575 + umode_t *mode)
58576 +{
58577 + return 1;
58578 +}
58579 +
58580 +__u32
58581 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
58582 +{
58583 + return 1;
58584 +}
58585 +
58586 +__u32
58587 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
58588 +{
58589 + return 1;
58590 +}
58591 +
58592 +void
58593 +grsecurity_init(void)
58594 +{
58595 + return;
58596 +}
58597 +
58598 +umode_t gr_acl_umask(void)
58599 +{
58600 + return 0;
58601 +}
58602 +
58603 +__u32
58604 +gr_acl_handle_mknod(const struct dentry * new_dentry,
58605 + const struct dentry * parent_dentry,
58606 + const struct vfsmount * parent_mnt,
58607 + const int mode)
58608 +{
58609 + return 1;
58610 +}
58611 +
58612 +__u32
58613 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
58614 + const struct dentry * parent_dentry,
58615 + const struct vfsmount * parent_mnt)
58616 +{
58617 + return 1;
58618 +}
58619 +
58620 +__u32
58621 +gr_acl_handle_symlink(const struct dentry * new_dentry,
58622 + const struct dentry * parent_dentry,
58623 + const struct vfsmount * parent_mnt, const char *from)
58624 +{
58625 + return 1;
58626 +}
58627 +
58628 +__u32
58629 +gr_acl_handle_link(const struct dentry * new_dentry,
58630 + const struct dentry * parent_dentry,
58631 + const struct vfsmount * parent_mnt,
58632 + const struct dentry * old_dentry,
58633 + const struct vfsmount * old_mnt, const char *to)
58634 +{
58635 + return 1;
58636 +}
58637 +
58638 +int
58639 +gr_acl_handle_rename(const struct dentry *new_dentry,
58640 + const struct dentry *parent_dentry,
58641 + const struct vfsmount *parent_mnt,
58642 + const struct dentry *old_dentry,
58643 + const struct inode *old_parent_inode,
58644 + const struct vfsmount *old_mnt, const char *newname)
58645 +{
58646 + return 0;
58647 +}
58648 +
58649 +int
58650 +gr_acl_handle_filldir(const struct file *file, const char *name,
58651 + const int namelen, const ino_t ino)
58652 +{
58653 + return 1;
58654 +}
58655 +
58656 +int
58657 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
58658 + const time_t shm_createtime, const uid_t cuid, const int shmid)
58659 +{
58660 + return 1;
58661 +}
58662 +
58663 +int
58664 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
58665 +{
58666 + return 0;
58667 +}
58668 +
58669 +int
58670 +gr_search_accept(const struct socket *sock)
58671 +{
58672 + return 0;
58673 +}
58674 +
58675 +int
58676 +gr_search_listen(const struct socket *sock)
58677 +{
58678 + return 0;
58679 +}
58680 +
58681 +int
58682 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
58683 +{
58684 + return 0;
58685 +}
58686 +
58687 +__u32
58688 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
58689 +{
58690 + return 1;
58691 +}
58692 +
58693 +__u32
58694 +gr_acl_handle_creat(const struct dentry * dentry,
58695 + const struct dentry * p_dentry,
58696 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
58697 + const int imode)
58698 +{
58699 + return 1;
58700 +}
58701 +
58702 +void
58703 +gr_acl_handle_exit(void)
58704 +{
58705 + return;
58706 +}
58707 +
58708 +int
58709 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
58710 +{
58711 + return 1;
58712 +}
58713 +
58714 +void
58715 +gr_set_role_label(const uid_t uid, const gid_t gid)
58716 +{
58717 + return;
58718 +}
58719 +
58720 +int
58721 +gr_acl_handle_procpidmem(const struct task_struct *task)
58722 +{
58723 + return 0;
58724 +}
58725 +
58726 +int
58727 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
58728 +{
58729 + return 0;
58730 +}
58731 +
58732 +int
58733 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
58734 +{
58735 + return 0;
58736 +}
58737 +
58738 +void
58739 +gr_set_kernel_label(struct task_struct *task)
58740 +{
58741 + return;
58742 +}
58743 +
58744 +int
58745 +gr_check_user_change(int real, int effective, int fs)
58746 +{
58747 + return 0;
58748 +}
58749 +
58750 +int
58751 +gr_check_group_change(int real, int effective, int fs)
58752 +{
58753 + return 0;
58754 +}
58755 +
58756 +int gr_acl_enable_at_secure(void)
58757 +{
58758 + return 0;
58759 +}
58760 +
58761 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
58762 +{
58763 + return dentry->d_inode->i_sb->s_dev;
58764 +}
58765 +
58766 +void gr_put_exec_file(struct task_struct *task)
58767 +{
58768 + return;
58769 +}
58770 +
58771 +EXPORT_SYMBOL(gr_learn_resource);
58772 +EXPORT_SYMBOL(gr_set_kernel_label);
58773 +#ifdef CONFIG_SECURITY
58774 +EXPORT_SYMBOL(gr_check_user_change);
58775 +EXPORT_SYMBOL(gr_check_group_change);
58776 +#endif
58777 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
58778 new file mode 100644
58779 index 0000000..abfa971
58780 --- /dev/null
58781 +++ b/grsecurity/grsec_exec.c
58782 @@ -0,0 +1,174 @@
58783 +#include <linux/kernel.h>
58784 +#include <linux/sched.h>
58785 +#include <linux/file.h>
58786 +#include <linux/binfmts.h>
58787 +#include <linux/fs.h>
58788 +#include <linux/types.h>
58789 +#include <linux/grdefs.h>
58790 +#include <linux/grsecurity.h>
58791 +#include <linux/grinternal.h>
58792 +#include <linux/capability.h>
58793 +#include <linux/module.h>
58794 +
58795 +#include <asm/uaccess.h>
58796 +
58797 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58798 +static char gr_exec_arg_buf[132];
58799 +static DEFINE_MUTEX(gr_exec_arg_mutex);
58800 +#endif
58801 +
58802 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
58803 +
58804 +void
58805 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
58806 +{
58807 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58808 + char *grarg = gr_exec_arg_buf;
58809 + unsigned int i, x, execlen = 0;
58810 + char c;
58811 +
58812 + if (!((grsec_enable_execlog && grsec_enable_group &&
58813 + in_group_p(grsec_audit_gid))
58814 + || (grsec_enable_execlog && !grsec_enable_group)))
58815 + return;
58816 +
58817 + mutex_lock(&gr_exec_arg_mutex);
58818 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
58819 +
58820 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
58821 + const char __user *p;
58822 + unsigned int len;
58823 +
58824 + p = get_user_arg_ptr(argv, i);
58825 + if (IS_ERR(p))
58826 + goto log;
58827 +
58828 + len = strnlen_user(p, 128 - execlen);
58829 + if (len > 128 - execlen)
58830 + len = 128 - execlen;
58831 + else if (len > 0)
58832 + len--;
58833 + if (copy_from_user(grarg + execlen, p, len))
58834 + goto log;
58835 +
58836 + /* rewrite unprintable characters */
58837 + for (x = 0; x < len; x++) {
58838 + c = *(grarg + execlen + x);
58839 + if (c < 32 || c > 126)
58840 + *(grarg + execlen + x) = ' ';
58841 + }
58842 +
58843 + execlen += len;
58844 + *(grarg + execlen) = ' ';
58845 + *(grarg + execlen + 1) = '\0';
58846 + execlen++;
58847 + }
58848 +
58849 + log:
58850 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
58851 + bprm->file->f_path.mnt, grarg);
58852 + mutex_unlock(&gr_exec_arg_mutex);
58853 +#endif
58854 + return;
58855 +}
58856 +
58857 +#ifdef CONFIG_GRKERNSEC
58858 +extern int gr_acl_is_capable(const int cap);
58859 +extern int gr_acl_is_capable_nolog(const int cap);
58860 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
58861 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
58862 +extern int gr_chroot_is_capable(const int cap);
58863 +extern int gr_chroot_is_capable_nolog(const int cap);
58864 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
58865 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
58866 +#endif
58867 +
58868 +const char *captab_log[] = {
58869 + "CAP_CHOWN",
58870 + "CAP_DAC_OVERRIDE",
58871 + "CAP_DAC_READ_SEARCH",
58872 + "CAP_FOWNER",
58873 + "CAP_FSETID",
58874 + "CAP_KILL",
58875 + "CAP_SETGID",
58876 + "CAP_SETUID",
58877 + "CAP_SETPCAP",
58878 + "CAP_LINUX_IMMUTABLE",
58879 + "CAP_NET_BIND_SERVICE",
58880 + "CAP_NET_BROADCAST",
58881 + "CAP_NET_ADMIN",
58882 + "CAP_NET_RAW",
58883 + "CAP_IPC_LOCK",
58884 + "CAP_IPC_OWNER",
58885 + "CAP_SYS_MODULE",
58886 + "CAP_SYS_RAWIO",
58887 + "CAP_SYS_CHROOT",
58888 + "CAP_SYS_PTRACE",
58889 + "CAP_SYS_PACCT",
58890 + "CAP_SYS_ADMIN",
58891 + "CAP_SYS_BOOT",
58892 + "CAP_SYS_NICE",
58893 + "CAP_SYS_RESOURCE",
58894 + "CAP_SYS_TIME",
58895 + "CAP_SYS_TTY_CONFIG",
58896 + "CAP_MKNOD",
58897 + "CAP_LEASE",
58898 + "CAP_AUDIT_WRITE",
58899 + "CAP_AUDIT_CONTROL",
58900 + "CAP_SETFCAP",
58901 + "CAP_MAC_OVERRIDE",
58902 + "CAP_MAC_ADMIN",
58903 + "CAP_SYSLOG",
58904 + "CAP_WAKE_ALARM"
58905 +};
58906 +
58907 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
58908 +
58909 +int gr_is_capable(const int cap)
58910 +{
58911 +#ifdef CONFIG_GRKERNSEC
58912 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
58913 + return 1;
58914 + return 0;
58915 +#else
58916 + return 1;
58917 +#endif
58918 +}
58919 +
58920 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
58921 +{
58922 +#ifdef CONFIG_GRKERNSEC
58923 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
58924 + return 1;
58925 + return 0;
58926 +#else
58927 + return 1;
58928 +#endif
58929 +}
58930 +
58931 +int gr_is_capable_nolog(const int cap)
58932 +{
58933 +#ifdef CONFIG_GRKERNSEC
58934 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
58935 + return 1;
58936 + return 0;
58937 +#else
58938 + return 1;
58939 +#endif
58940 +}
58941 +
58942 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
58943 +{
58944 +#ifdef CONFIG_GRKERNSEC
58945 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
58946 + return 1;
58947 + return 0;
58948 +#else
58949 + return 1;
58950 +#endif
58951 +}
58952 +
58953 +EXPORT_SYMBOL(gr_is_capable);
58954 +EXPORT_SYMBOL(gr_is_capable_nolog);
58955 +EXPORT_SYMBOL(gr_task_is_capable);
58956 +EXPORT_SYMBOL(gr_task_is_capable_nolog);
58957 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
58958 new file mode 100644
58959 index 0000000..d3ee748
58960 --- /dev/null
58961 +++ b/grsecurity/grsec_fifo.c
58962 @@ -0,0 +1,24 @@
58963 +#include <linux/kernel.h>
58964 +#include <linux/sched.h>
58965 +#include <linux/fs.h>
58966 +#include <linux/file.h>
58967 +#include <linux/grinternal.h>
58968 +
58969 +int
58970 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
58971 + const struct dentry *dir, const int flag, const int acc_mode)
58972 +{
58973 +#ifdef CONFIG_GRKERNSEC_FIFO
58974 + const struct cred *cred = current_cred();
58975 +
58976 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
58977 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
58978 + (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
58979 + (cred->fsuid != dentry->d_inode->i_uid)) {
58980 + if (!inode_permission(dentry->d_inode, acc_mode))
58981 + gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
58982 + return -EACCES;
58983 + }
58984 +#endif
58985 + return 0;
58986 +}
58987 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
58988 new file mode 100644
58989 index 0000000..8ca18bf
58990 --- /dev/null
58991 +++ b/grsecurity/grsec_fork.c
58992 @@ -0,0 +1,23 @@
58993 +#include <linux/kernel.h>
58994 +#include <linux/sched.h>
58995 +#include <linux/grsecurity.h>
58996 +#include <linux/grinternal.h>
58997 +#include <linux/errno.h>
58998 +
58999 +void
59000 +gr_log_forkfail(const int retval)
59001 +{
59002 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
59003 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
59004 + switch (retval) {
59005 + case -EAGAIN:
59006 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
59007 + break;
59008 + case -ENOMEM:
59009 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
59010 + break;
59011 + }
59012 + }
59013 +#endif
59014 + return;
59015 +}
59016 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
59017 new file mode 100644
59018 index 0000000..05a6015
59019 --- /dev/null
59020 +++ b/grsecurity/grsec_init.c
59021 @@ -0,0 +1,283 @@
59022 +#include <linux/kernel.h>
59023 +#include <linux/sched.h>
59024 +#include <linux/mm.h>
59025 +#include <linux/gracl.h>
59026 +#include <linux/slab.h>
59027 +#include <linux/vmalloc.h>
59028 +#include <linux/percpu.h>
59029 +#include <linux/module.h>
59030 +
59031 +int grsec_enable_ptrace_readexec;
59032 +int grsec_enable_setxid;
59033 +int grsec_enable_symlinkown;
59034 +int grsec_symlinkown_gid;
59035 +int grsec_enable_brute;
59036 +int grsec_enable_link;
59037 +int grsec_enable_dmesg;
59038 +int grsec_enable_harden_ptrace;
59039 +int grsec_enable_fifo;
59040 +int grsec_enable_execlog;
59041 +int grsec_enable_signal;
59042 +int grsec_enable_forkfail;
59043 +int grsec_enable_audit_ptrace;
59044 +int grsec_enable_time;
59045 +int grsec_enable_audit_textrel;
59046 +int grsec_enable_group;
59047 +int grsec_audit_gid;
59048 +int grsec_enable_chdir;
59049 +int grsec_enable_mount;
59050 +int grsec_enable_rofs;
59051 +int grsec_enable_chroot_findtask;
59052 +int grsec_enable_chroot_mount;
59053 +int grsec_enable_chroot_shmat;
59054 +int grsec_enable_chroot_fchdir;
59055 +int grsec_enable_chroot_double;
59056 +int grsec_enable_chroot_pivot;
59057 +int grsec_enable_chroot_chdir;
59058 +int grsec_enable_chroot_chmod;
59059 +int grsec_enable_chroot_mknod;
59060 +int grsec_enable_chroot_nice;
59061 +int grsec_enable_chroot_execlog;
59062 +int grsec_enable_chroot_caps;
59063 +int grsec_enable_chroot_sysctl;
59064 +int grsec_enable_chroot_unix;
59065 +int grsec_enable_tpe;
59066 +int grsec_tpe_gid;
59067 +int grsec_enable_blackhole;
59068 +#ifdef CONFIG_IPV6_MODULE
59069 +EXPORT_SYMBOL(grsec_enable_blackhole);
59070 +#endif
59071 +int grsec_lastack_retries;
59072 +int grsec_enable_tpe_all;
59073 +int grsec_enable_tpe_invert;
59074 +int grsec_enable_socket_all;
59075 +int grsec_socket_all_gid;
59076 +int grsec_enable_socket_client;
59077 +int grsec_socket_client_gid;
59078 +int grsec_enable_socket_server;
59079 +int grsec_socket_server_gid;
59080 +int grsec_resource_logging;
59081 +int grsec_disable_privio;
59082 +int grsec_enable_log_rwxmaps;
59083 +int grsec_lock;
59084 +
59085 +DEFINE_SPINLOCK(grsec_alert_lock);
59086 +unsigned long grsec_alert_wtime = 0;
59087 +unsigned long grsec_alert_fyet = 0;
59088 +
59089 +DEFINE_SPINLOCK(grsec_audit_lock);
59090 +
59091 +DEFINE_RWLOCK(grsec_exec_file_lock);
59092 +
59093 +char *gr_shared_page[4];
59094 +
59095 +char *gr_alert_log_fmt;
59096 +char *gr_audit_log_fmt;
59097 +char *gr_alert_log_buf;
59098 +char *gr_audit_log_buf;
59099 +
59100 +extern struct gr_arg *gr_usermode;
59101 +extern unsigned char *gr_system_salt;
59102 +extern unsigned char *gr_system_sum;
59103 +
59104 +void __init
59105 +grsecurity_init(void)
59106 +{
59107 + int j;
59108 + /* create the per-cpu shared pages */
59109 +
59110 +#ifdef CONFIG_X86
59111 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
59112 +#endif
59113 +
59114 + for (j = 0; j < 4; j++) {
59115 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
59116 + if (gr_shared_page[j] == NULL) {
59117 + panic("Unable to allocate grsecurity shared page");
59118 + return;
59119 + }
59120 + }
59121 +
59122 + /* allocate log buffers */
59123 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
59124 + if (!gr_alert_log_fmt) {
59125 + panic("Unable to allocate grsecurity alert log format buffer");
59126 + return;
59127 + }
59128 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
59129 + if (!gr_audit_log_fmt) {
59130 + panic("Unable to allocate grsecurity audit log format buffer");
59131 + return;
59132 + }
59133 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
59134 + if (!gr_alert_log_buf) {
59135 + panic("Unable to allocate grsecurity alert log buffer");
59136 + return;
59137 + }
59138 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
59139 + if (!gr_audit_log_buf) {
59140 + panic("Unable to allocate grsecurity audit log buffer");
59141 + return;
59142 + }
59143 +
59144 + /* allocate memory for authentication structure */
59145 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
59146 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
59147 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
59148 +
59149 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
59150 + panic("Unable to allocate grsecurity authentication structure");
59151 + return;
59152 + }
59153 +
59154 +
59155 +#ifdef CONFIG_GRKERNSEC_IO
59156 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
59157 + grsec_disable_privio = 1;
59158 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
59159 + grsec_disable_privio = 1;
59160 +#else
59161 + grsec_disable_privio = 0;
59162 +#endif
59163 +#endif
59164 +
59165 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
59166 + /* for backward compatibility, tpe_invert always defaults to on if
59167 + enabled in the kernel
59168 + */
59169 + grsec_enable_tpe_invert = 1;
59170 +#endif
59171 +
59172 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
59173 +#ifndef CONFIG_GRKERNSEC_SYSCTL
59174 + grsec_lock = 1;
59175 +#endif
59176 +
59177 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
59178 + grsec_enable_audit_textrel = 1;
59179 +#endif
59180 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59181 + grsec_enable_log_rwxmaps = 1;
59182 +#endif
59183 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
59184 + grsec_enable_group = 1;
59185 + grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
59186 +#endif
59187 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
59188 + grsec_enable_ptrace_readexec = 1;
59189 +#endif
59190 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
59191 + grsec_enable_chdir = 1;
59192 +#endif
59193 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
59194 + grsec_enable_harden_ptrace = 1;
59195 +#endif
59196 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59197 + grsec_enable_mount = 1;
59198 +#endif
59199 +#ifdef CONFIG_GRKERNSEC_LINK
59200 + grsec_enable_link = 1;
59201 +#endif
59202 +#ifdef CONFIG_GRKERNSEC_BRUTE
59203 + grsec_enable_brute = 1;
59204 +#endif
59205 +#ifdef CONFIG_GRKERNSEC_DMESG
59206 + grsec_enable_dmesg = 1;
59207 +#endif
59208 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
59209 + grsec_enable_blackhole = 1;
59210 + grsec_lastack_retries = 4;
59211 +#endif
59212 +#ifdef CONFIG_GRKERNSEC_FIFO
59213 + grsec_enable_fifo = 1;
59214 +#endif
59215 +#ifdef CONFIG_GRKERNSEC_EXECLOG
59216 + grsec_enable_execlog = 1;
59217 +#endif
59218 +#ifdef CONFIG_GRKERNSEC_SETXID
59219 + grsec_enable_setxid = 1;
59220 +#endif
59221 +#ifdef CONFIG_GRKERNSEC_SIGNAL
59222 + grsec_enable_signal = 1;
59223 +#endif
59224 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
59225 + grsec_enable_forkfail = 1;
59226 +#endif
59227 +#ifdef CONFIG_GRKERNSEC_TIME
59228 + grsec_enable_time = 1;
59229 +#endif
59230 +#ifdef CONFIG_GRKERNSEC_RESLOG
59231 + grsec_resource_logging = 1;
59232 +#endif
59233 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
59234 + grsec_enable_chroot_findtask = 1;
59235 +#endif
59236 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
59237 + grsec_enable_chroot_unix = 1;
59238 +#endif
59239 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
59240 + grsec_enable_chroot_mount = 1;
59241 +#endif
59242 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
59243 + grsec_enable_chroot_fchdir = 1;
59244 +#endif
59245 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
59246 + grsec_enable_chroot_shmat = 1;
59247 +#endif
59248 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
59249 + grsec_enable_audit_ptrace = 1;
59250 +#endif
59251 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
59252 + grsec_enable_chroot_double = 1;
59253 +#endif
59254 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
59255 + grsec_enable_chroot_pivot = 1;
59256 +#endif
59257 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
59258 + grsec_enable_chroot_chdir = 1;
59259 +#endif
59260 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
59261 + grsec_enable_chroot_chmod = 1;
59262 +#endif
59263 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
59264 + grsec_enable_chroot_mknod = 1;
59265 +#endif
59266 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
59267 + grsec_enable_chroot_nice = 1;
59268 +#endif
59269 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
59270 + grsec_enable_chroot_execlog = 1;
59271 +#endif
59272 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59273 + grsec_enable_chroot_caps = 1;
59274 +#endif
59275 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
59276 + grsec_enable_chroot_sysctl = 1;
59277 +#endif
59278 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
59279 + grsec_enable_symlinkown = 1;
59280 + grsec_symlinkown_gid = CONFIG_GRKERNSEC_SYMLINKOWN_GID;
59281 +#endif
59282 +#ifdef CONFIG_GRKERNSEC_TPE
59283 + grsec_enable_tpe = 1;
59284 + grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
59285 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
59286 + grsec_enable_tpe_all = 1;
59287 +#endif
59288 +#endif
59289 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59290 + grsec_enable_socket_all = 1;
59291 + grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
59292 +#endif
59293 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59294 + grsec_enable_socket_client = 1;
59295 + grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
59296 +#endif
59297 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59298 + grsec_enable_socket_server = 1;
59299 + grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
59300 +#endif
59301 +#endif
59302 +
59303 + return;
59304 +}
59305 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
59306 new file mode 100644
59307 index 0000000..589481f
59308 --- /dev/null
59309 +++ b/grsecurity/grsec_link.c
59310 @@ -0,0 +1,58 @@
59311 +#include <linux/kernel.h>
59312 +#include <linux/sched.h>
59313 +#include <linux/fs.h>
59314 +#include <linux/file.h>
59315 +#include <linux/grinternal.h>
59316 +
59317 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
59318 +{
59319 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
59320 + const struct inode *link_inode = link->dentry->d_inode;
59321 +
59322 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
59323 + /* ignore root-owned links, e.g. /proc/self */
59324 + !uid_eq(link_inode->i_uid, GLOBAL_ROOT_UID) && target &&
59325 + !uid_eq(link_inode->i_uid, target->i_uid)) {
59326 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
59327 + return 1;
59328 + }
59329 +#endif
59330 + return 0;
59331 +}
59332 +
59333 +int
59334 +gr_handle_follow_link(const struct inode *parent,
59335 + const struct inode *inode,
59336 + const struct dentry *dentry, const struct vfsmount *mnt)
59337 +{
59338 +#ifdef CONFIG_GRKERNSEC_LINK
59339 + const struct cred *cred = current_cred();
59340 +
59341 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
59342 + (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
59343 + (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
59344 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
59345 + return -EACCES;
59346 + }
59347 +#endif
59348 + return 0;
59349 +}
59350 +
59351 +int
59352 +gr_handle_hardlink(const struct dentry *dentry,
59353 + const struct vfsmount *mnt,
59354 + struct inode *inode, const int mode, const char *to)
59355 +{
59356 +#ifdef CONFIG_GRKERNSEC_LINK
59357 + const struct cred *cred = current_cred();
59358 +
59359 + if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
59360 + (!S_ISREG(mode) || is_privileged_binary(dentry) ||
59361 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
59362 + !capable(CAP_FOWNER) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
59363 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
59364 + return -EPERM;
59365 + }
59366 +#endif
59367 + return 0;
59368 +}
59369 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
59370 new file mode 100644
59371 index 0000000..a45d2e9
59372 --- /dev/null
59373 +++ b/grsecurity/grsec_log.c
59374 @@ -0,0 +1,322 @@
59375 +#include <linux/kernel.h>
59376 +#include <linux/sched.h>
59377 +#include <linux/file.h>
59378 +#include <linux/tty.h>
59379 +#include <linux/fs.h>
59380 +#include <linux/grinternal.h>
59381 +
59382 +#ifdef CONFIG_TREE_PREEMPT_RCU
59383 +#define DISABLE_PREEMPT() preempt_disable()
59384 +#define ENABLE_PREEMPT() preempt_enable()
59385 +#else
59386 +#define DISABLE_PREEMPT()
59387 +#define ENABLE_PREEMPT()
59388 +#endif
59389 +
59390 +#define BEGIN_LOCKS(x) \
59391 + DISABLE_PREEMPT(); \
59392 + rcu_read_lock(); \
59393 + read_lock(&tasklist_lock); \
59394 + read_lock(&grsec_exec_file_lock); \
59395 + if (x != GR_DO_AUDIT) \
59396 + spin_lock(&grsec_alert_lock); \
59397 + else \
59398 + spin_lock(&grsec_audit_lock)
59399 +
59400 +#define END_LOCKS(x) \
59401 + if (x != GR_DO_AUDIT) \
59402 + spin_unlock(&grsec_alert_lock); \
59403 + else \
59404 + spin_unlock(&grsec_audit_lock); \
59405 + read_unlock(&grsec_exec_file_lock); \
59406 + read_unlock(&tasklist_lock); \
59407 + rcu_read_unlock(); \
59408 + ENABLE_PREEMPT(); \
59409 + if (x == GR_DONT_AUDIT) \
59410 + gr_handle_alertkill(current)
59411 +
59412 +enum {
59413 + FLOODING,
59414 + NO_FLOODING
59415 +};
59416 +
59417 +extern char *gr_alert_log_fmt;
59418 +extern char *gr_audit_log_fmt;
59419 +extern char *gr_alert_log_buf;
59420 +extern char *gr_audit_log_buf;
59421 +
59422 +static int gr_log_start(int audit)
59423 +{
59424 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
59425 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
59426 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
59427 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
59428 + unsigned long curr_secs = get_seconds();
59429 +
59430 + if (audit == GR_DO_AUDIT)
59431 + goto set_fmt;
59432 +
59433 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
59434 + grsec_alert_wtime = curr_secs;
59435 + grsec_alert_fyet = 0;
59436 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
59437 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
59438 + grsec_alert_fyet++;
59439 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
59440 + grsec_alert_wtime = curr_secs;
59441 + grsec_alert_fyet++;
59442 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
59443 + return FLOODING;
59444 + }
59445 + else return FLOODING;
59446 +
59447 +set_fmt:
59448 +#endif
59449 + memset(buf, 0, PAGE_SIZE);
59450 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
59451 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
59452 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
59453 + } else if (current->signal->curr_ip) {
59454 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
59455 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
59456 + } else if (gr_acl_is_enabled()) {
59457 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
59458 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
59459 + } else {
59460 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
59461 + strcpy(buf, fmt);
59462 + }
59463 +
59464 + return NO_FLOODING;
59465 +}
59466 +
59467 +static void gr_log_middle(int audit, const char *msg, va_list ap)
59468 + __attribute__ ((format (printf, 2, 0)));
59469 +
59470 +static void gr_log_middle(int audit, const char *msg, va_list ap)
59471 +{
59472 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
59473 + unsigned int len = strlen(buf);
59474 +
59475 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
59476 +
59477 + return;
59478 +}
59479 +
59480 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
59481 + __attribute__ ((format (printf, 2, 3)));
59482 +
59483 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
59484 +{
59485 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
59486 + unsigned int len = strlen(buf);
59487 + va_list ap;
59488 +
59489 + va_start(ap, msg);
59490 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
59491 + va_end(ap);
59492 +
59493 + return;
59494 +}
59495 +
59496 +static void gr_log_end(int audit, int append_default)
59497 +{
59498 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
59499 +
59500 + if (append_default) {
59501 + unsigned int len = strlen(buf);
59502 + snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
59503 + }
59504 +
59505 + printk("%s\n", buf);
59506 +
59507 + return;
59508 +}
59509 +
59510 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
59511 +{
59512 + int logtype;
59513 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
59514 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
59515 + void *voidptr = NULL;
59516 + int num1 = 0, num2 = 0;
59517 + unsigned long ulong1 = 0, ulong2 = 0;
59518 + struct dentry *dentry = NULL;
59519 + struct vfsmount *mnt = NULL;
59520 + struct file *file = NULL;
59521 + struct task_struct *task = NULL;
59522 + const struct cred *cred, *pcred;
59523 + va_list ap;
59524 +
59525 + BEGIN_LOCKS(audit);
59526 + logtype = gr_log_start(audit);
59527 + if (logtype == FLOODING) {
59528 + END_LOCKS(audit);
59529 + return;
59530 + }
59531 + va_start(ap, argtypes);
59532 + switch (argtypes) {
59533 + case GR_TTYSNIFF:
59534 + task = va_arg(ap, struct task_struct *);
59535 + 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);
59536 + break;
59537 + case GR_SYSCTL_HIDDEN:
59538 + str1 = va_arg(ap, char *);
59539 + gr_log_middle_varargs(audit, msg, result, str1);
59540 + break;
59541 + case GR_RBAC:
59542 + dentry = va_arg(ap, struct dentry *);
59543 + mnt = va_arg(ap, struct vfsmount *);
59544 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
59545 + break;
59546 + case GR_RBAC_STR:
59547 + dentry = va_arg(ap, struct dentry *);
59548 + mnt = va_arg(ap, struct vfsmount *);
59549 + str1 = va_arg(ap, char *);
59550 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
59551 + break;
59552 + case GR_STR_RBAC:
59553 + str1 = va_arg(ap, char *);
59554 + dentry = va_arg(ap, struct dentry *);
59555 + mnt = va_arg(ap, struct vfsmount *);
59556 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
59557 + break;
59558 + case GR_RBAC_MODE2:
59559 + dentry = va_arg(ap, struct dentry *);
59560 + mnt = va_arg(ap, struct vfsmount *);
59561 + str1 = va_arg(ap, char *);
59562 + str2 = va_arg(ap, char *);
59563 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
59564 + break;
59565 + case GR_RBAC_MODE3:
59566 + dentry = va_arg(ap, struct dentry *);
59567 + mnt = va_arg(ap, struct vfsmount *);
59568 + str1 = va_arg(ap, char *);
59569 + str2 = va_arg(ap, char *);
59570 + str3 = va_arg(ap, char *);
59571 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
59572 + break;
59573 + case GR_FILENAME:
59574 + dentry = va_arg(ap, struct dentry *);
59575 + mnt = va_arg(ap, struct vfsmount *);
59576 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
59577 + break;
59578 + case GR_STR_FILENAME:
59579 + str1 = va_arg(ap, char *);
59580 + dentry = va_arg(ap, struct dentry *);
59581 + mnt = va_arg(ap, struct vfsmount *);
59582 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
59583 + break;
59584 + case GR_FILENAME_STR:
59585 + dentry = va_arg(ap, struct dentry *);
59586 + mnt = va_arg(ap, struct vfsmount *);
59587 + str1 = va_arg(ap, char *);
59588 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
59589 + break;
59590 + case GR_FILENAME_TWO_INT:
59591 + dentry = va_arg(ap, struct dentry *);
59592 + mnt = va_arg(ap, struct vfsmount *);
59593 + num1 = va_arg(ap, int);
59594 + num2 = va_arg(ap, int);
59595 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
59596 + break;
59597 + case GR_FILENAME_TWO_INT_STR:
59598 + dentry = va_arg(ap, struct dentry *);
59599 + mnt = va_arg(ap, struct vfsmount *);
59600 + num1 = va_arg(ap, int);
59601 + num2 = va_arg(ap, int);
59602 + str1 = va_arg(ap, char *);
59603 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
59604 + break;
59605 + case GR_TEXTREL:
59606 + file = va_arg(ap, struct file *);
59607 + ulong1 = va_arg(ap, unsigned long);
59608 + ulong2 = va_arg(ap, unsigned long);
59609 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
59610 + break;
59611 + case GR_PTRACE:
59612 + task = va_arg(ap, struct task_struct *);
59613 + 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);
59614 + break;
59615 + case GR_RESOURCE:
59616 + task = va_arg(ap, struct task_struct *);
59617 + cred = __task_cred(task);
59618 + pcred = __task_cred(task->real_parent);
59619 + ulong1 = va_arg(ap, unsigned long);
59620 + str1 = va_arg(ap, char *);
59621 + ulong2 = va_arg(ap, unsigned long);
59622 + 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);
59623 + break;
59624 + case GR_CAP:
59625 + task = va_arg(ap, struct task_struct *);
59626 + cred = __task_cred(task);
59627 + pcred = __task_cred(task->real_parent);
59628 + str1 = va_arg(ap, char *);
59629 + 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);
59630 + break;
59631 + case GR_SIG:
59632 + str1 = va_arg(ap, char *);
59633 + voidptr = va_arg(ap, void *);
59634 + gr_log_middle_varargs(audit, msg, str1, voidptr);
59635 + break;
59636 + case GR_SIG2:
59637 + task = va_arg(ap, struct task_struct *);
59638 + cred = __task_cred(task);
59639 + pcred = __task_cred(task->real_parent);
59640 + num1 = va_arg(ap, int);
59641 + 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);
59642 + break;
59643 + case GR_CRASH1:
59644 + task = va_arg(ap, struct task_struct *);
59645 + cred = __task_cred(task);
59646 + pcred = __task_cred(task->real_parent);
59647 + ulong1 = va_arg(ap, unsigned long);
59648 + 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);
59649 + break;
59650 + case GR_CRASH2:
59651 + task = va_arg(ap, struct task_struct *);
59652 + cred = __task_cred(task);
59653 + pcred = __task_cred(task->real_parent);
59654 + ulong1 = va_arg(ap, unsigned long);
59655 + 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);
59656 + break;
59657 + case GR_RWXMAP:
59658 + file = va_arg(ap, struct file *);
59659 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
59660 + break;
59661 + case GR_PSACCT:
59662 + {
59663 + unsigned int wday, cday;
59664 + __u8 whr, chr;
59665 + __u8 wmin, cmin;
59666 + __u8 wsec, csec;
59667 + char cur_tty[64] = { 0 };
59668 + char parent_tty[64] = { 0 };
59669 +
59670 + task = va_arg(ap, struct task_struct *);
59671 + wday = va_arg(ap, unsigned int);
59672 + cday = va_arg(ap, unsigned int);
59673 + whr = va_arg(ap, int);
59674 + chr = va_arg(ap, int);
59675 + wmin = va_arg(ap, int);
59676 + cmin = va_arg(ap, int);
59677 + wsec = va_arg(ap, int);
59678 + csec = va_arg(ap, int);
59679 + ulong1 = va_arg(ap, unsigned long);
59680 + cred = __task_cred(task);
59681 + pcred = __task_cred(task->real_parent);
59682 +
59683 + 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);
59684 + }
59685 + break;
59686 + default:
59687 + gr_log_middle(audit, msg, ap);
59688 + }
59689 + va_end(ap);
59690 + // these don't need DEFAULTSECARGS printed on the end
59691 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
59692 + gr_log_end(audit, 0);
59693 + else
59694 + gr_log_end(audit, 1);
59695 + END_LOCKS(audit);
59696 +}
59697 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
59698 new file mode 100644
59699 index 0000000..f536303
59700 --- /dev/null
59701 +++ b/grsecurity/grsec_mem.c
59702 @@ -0,0 +1,40 @@
59703 +#include <linux/kernel.h>
59704 +#include <linux/sched.h>
59705 +#include <linux/mm.h>
59706 +#include <linux/mman.h>
59707 +#include <linux/grinternal.h>
59708 +
59709 +void
59710 +gr_handle_ioperm(void)
59711 +{
59712 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
59713 + return;
59714 +}
59715 +
59716 +void
59717 +gr_handle_iopl(void)
59718 +{
59719 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
59720 + return;
59721 +}
59722 +
59723 +void
59724 +gr_handle_mem_readwrite(u64 from, u64 to)
59725 +{
59726 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
59727 + return;
59728 +}
59729 +
59730 +void
59731 +gr_handle_vm86(void)
59732 +{
59733 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
59734 + return;
59735 +}
59736 +
59737 +void
59738 +gr_log_badprocpid(const char *entry)
59739 +{
59740 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
59741 + return;
59742 +}
59743 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
59744 new file mode 100644
59745 index 0000000..2131422
59746 --- /dev/null
59747 +++ b/grsecurity/grsec_mount.c
59748 @@ -0,0 +1,62 @@
59749 +#include <linux/kernel.h>
59750 +#include <linux/sched.h>
59751 +#include <linux/mount.h>
59752 +#include <linux/grsecurity.h>
59753 +#include <linux/grinternal.h>
59754 +
59755 +void
59756 +gr_log_remount(const char *devname, const int retval)
59757 +{
59758 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59759 + if (grsec_enable_mount && (retval >= 0))
59760 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
59761 +#endif
59762 + return;
59763 +}
59764 +
59765 +void
59766 +gr_log_unmount(const char *devname, const int retval)
59767 +{
59768 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59769 + if (grsec_enable_mount && (retval >= 0))
59770 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
59771 +#endif
59772 + return;
59773 +}
59774 +
59775 +void
59776 +gr_log_mount(const char *from, const char *to, const int retval)
59777 +{
59778 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59779 + if (grsec_enable_mount && (retval >= 0))
59780 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
59781 +#endif
59782 + return;
59783 +}
59784 +
59785 +int
59786 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
59787 +{
59788 +#ifdef CONFIG_GRKERNSEC_ROFS
59789 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
59790 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
59791 + return -EPERM;
59792 + } else
59793 + return 0;
59794 +#endif
59795 + return 0;
59796 +}
59797 +
59798 +int
59799 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
59800 +{
59801 +#ifdef CONFIG_GRKERNSEC_ROFS
59802 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
59803 + dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
59804 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
59805 + return -EPERM;
59806 + } else
59807 + return 0;
59808 +#endif
59809 + return 0;
59810 +}
59811 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
59812 new file mode 100644
59813 index 0000000..a3b12a0
59814 --- /dev/null
59815 +++ b/grsecurity/grsec_pax.c
59816 @@ -0,0 +1,36 @@
59817 +#include <linux/kernel.h>
59818 +#include <linux/sched.h>
59819 +#include <linux/mm.h>
59820 +#include <linux/file.h>
59821 +#include <linux/grinternal.h>
59822 +#include <linux/grsecurity.h>
59823 +
59824 +void
59825 +gr_log_textrel(struct vm_area_struct * vma)
59826 +{
59827 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
59828 + if (grsec_enable_audit_textrel)
59829 + gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
59830 +#endif
59831 + return;
59832 +}
59833 +
59834 +void
59835 +gr_log_rwxmmap(struct file *file)
59836 +{
59837 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59838 + if (grsec_enable_log_rwxmaps)
59839 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
59840 +#endif
59841 + return;
59842 +}
59843 +
59844 +void
59845 +gr_log_rwxmprotect(struct file *file)
59846 +{
59847 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59848 + if (grsec_enable_log_rwxmaps)
59849 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
59850 +#endif
59851 + return;
59852 +}
59853 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
59854 new file mode 100644
59855 index 0000000..f7f29aa
59856 --- /dev/null
59857 +++ b/grsecurity/grsec_ptrace.c
59858 @@ -0,0 +1,30 @@
59859 +#include <linux/kernel.h>
59860 +#include <linux/sched.h>
59861 +#include <linux/grinternal.h>
59862 +#include <linux/security.h>
59863 +
59864 +void
59865 +gr_audit_ptrace(struct task_struct *task)
59866 +{
59867 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
59868 + if (grsec_enable_audit_ptrace)
59869 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
59870 +#endif
59871 + return;
59872 +}
59873 +
59874 +int
59875 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
59876 +{
59877 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
59878 + const struct dentry *dentry = file->f_path.dentry;
59879 + const struct vfsmount *mnt = file->f_path.mnt;
59880 +
59881 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
59882 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
59883 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
59884 + return -EACCES;
59885 + }
59886 +#endif
59887 + return 0;
59888 +}
59889 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
59890 new file mode 100644
59891 index 0000000..b4ac94c
59892 --- /dev/null
59893 +++ b/grsecurity/grsec_sig.c
59894 @@ -0,0 +1,209 @@
59895 +#include <linux/kernel.h>
59896 +#include <linux/sched.h>
59897 +#include <linux/delay.h>
59898 +#include <linux/grsecurity.h>
59899 +#include <linux/grinternal.h>
59900 +#include <linux/hardirq.h>
59901 +
59902 +char *signames[] = {
59903 + [SIGSEGV] = "Segmentation fault",
59904 + [SIGILL] = "Illegal instruction",
59905 + [SIGABRT] = "Abort",
59906 + [SIGBUS] = "Invalid alignment/Bus error"
59907 +};
59908 +
59909 +void
59910 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
59911 +{
59912 +#ifdef CONFIG_GRKERNSEC_SIGNAL
59913 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
59914 + (sig == SIGABRT) || (sig == SIGBUS))) {
59915 + if (t->pid == current->pid) {
59916 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
59917 + } else {
59918 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
59919 + }
59920 + }
59921 +#endif
59922 + return;
59923 +}
59924 +
59925 +int
59926 +gr_handle_signal(const struct task_struct *p, const int sig)
59927 +{
59928 +#ifdef CONFIG_GRKERNSEC
59929 + /* ignore the 0 signal for protected task checks */
59930 + if (current->pid > 1 && sig && gr_check_protected_task(p)) {
59931 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
59932 + return -EPERM;
59933 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
59934 + return -EPERM;
59935 + }
59936 +#endif
59937 + return 0;
59938 +}
59939 +
59940 +#ifdef CONFIG_GRKERNSEC
59941 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
59942 +
59943 +int gr_fake_force_sig(int sig, struct task_struct *t)
59944 +{
59945 + unsigned long int flags;
59946 + int ret, blocked, ignored;
59947 + struct k_sigaction *action;
59948 +
59949 + spin_lock_irqsave(&t->sighand->siglock, flags);
59950 + action = &t->sighand->action[sig-1];
59951 + ignored = action->sa.sa_handler == SIG_IGN;
59952 + blocked = sigismember(&t->blocked, sig);
59953 + if (blocked || ignored) {
59954 + action->sa.sa_handler = SIG_DFL;
59955 + if (blocked) {
59956 + sigdelset(&t->blocked, sig);
59957 + recalc_sigpending_and_wake(t);
59958 + }
59959 + }
59960 + if (action->sa.sa_handler == SIG_DFL)
59961 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
59962 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
59963 +
59964 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
59965 +
59966 + return ret;
59967 +}
59968 +#endif
59969 +
59970 +#ifdef CONFIG_GRKERNSEC_BRUTE
59971 +#define GR_USER_BAN_TIME (15 * 60)
59972 +
59973 +static int __get_dumpable(unsigned long mm_flags)
59974 +{
59975 + int ret;
59976 +
59977 + ret = mm_flags & MMF_DUMPABLE_MASK;
59978 + return (ret >= 2) ? 2 : ret;
59979 +}
59980 +#endif
59981 +
59982 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
59983 +{
59984 +#ifdef CONFIG_GRKERNSEC_BRUTE
59985 + kuid_t uid = GLOBAL_ROOT_UID;
59986 +
59987 + if (!grsec_enable_brute)
59988 + return;
59989 +
59990 + rcu_read_lock();
59991 + read_lock(&tasklist_lock);
59992 + read_lock(&grsec_exec_file_lock);
59993 + if (p->real_parent && p->real_parent->exec_file == p->exec_file)
59994 + p->real_parent->brute = 1;
59995 + else {
59996 + const struct cred *cred = __task_cred(p), *cred2;
59997 + struct task_struct *tsk, *tsk2;
59998 +
59999 + if (!__get_dumpable(mm_flags) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
60000 + struct user_struct *user;
60001 +
60002 + uid = cred->uid;
60003 +
60004 + /* this is put upon execution past expiration */
60005 + user = find_user(uid);
60006 + if (user == NULL)
60007 + goto unlock;
60008 + user->banned = 1;
60009 + user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
60010 + if (user->ban_expires == ~0UL)
60011 + user->ban_expires--;
60012 +
60013 + do_each_thread(tsk2, tsk) {
60014 + cred2 = __task_cred(tsk);
60015 + if (tsk != p && uid_eq(cred2->uid, uid))
60016 + gr_fake_force_sig(SIGKILL, tsk);
60017 + } while_each_thread(tsk2, tsk);
60018 + }
60019 + }
60020 +unlock:
60021 + read_unlock(&grsec_exec_file_lock);
60022 + read_unlock(&tasklist_lock);
60023 + rcu_read_unlock();
60024 +
60025 + if (!uid_eq(uid, GLOBAL_ROOT_UID))
60026 + printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
60027 + from_kuid_munged(&init_user_ns, uid), GR_USER_BAN_TIME / 60);
60028 +
60029 +#endif
60030 + return;
60031 +}
60032 +
60033 +void gr_handle_brute_check(void)
60034 +{
60035 +#ifdef CONFIG_GRKERNSEC_BRUTE
60036 + if (current->brute)
60037 + msleep(30 * 1000);
60038 +#endif
60039 + return;
60040 +}
60041 +
60042 +void gr_handle_kernel_exploit(void)
60043 +{
60044 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
60045 + const struct cred *cred;
60046 + struct task_struct *tsk, *tsk2;
60047 + struct user_struct *user;
60048 + kuid_t uid;
60049 +
60050 + if (in_irq() || in_serving_softirq() || in_nmi())
60051 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
60052 +
60053 + uid = current_uid();
60054 +
60055 + if (uid_eq(uid, GLOBAL_ROOT_UID))
60056 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
60057 + else {
60058 + /* kill all the processes of this user, hold a reference
60059 + to their creds struct, and prevent them from creating
60060 + another process until system reset
60061 + */
60062 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
60063 + from_kuid_munged(&init_user_ns, uid));
60064 + /* we intentionally leak this ref */
60065 + user = get_uid(current->cred->user);
60066 + if (user) {
60067 + user->banned = 1;
60068 + user->ban_expires = ~0UL;
60069 + }
60070 +
60071 + read_lock(&tasklist_lock);
60072 + do_each_thread(tsk2, tsk) {
60073 + cred = __task_cred(tsk);
60074 + if (uid_eq(cred->uid, uid))
60075 + gr_fake_force_sig(SIGKILL, tsk);
60076 + } while_each_thread(tsk2, tsk);
60077 + read_unlock(&tasklist_lock);
60078 + }
60079 +#endif
60080 +}
60081 +
60082 +int __gr_process_user_ban(struct user_struct *user)
60083 +{
60084 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
60085 + if (unlikely(user->banned)) {
60086 + if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
60087 + user->banned = 0;
60088 + user->ban_expires = 0;
60089 + free_uid(user);
60090 + } else
60091 + return -EPERM;
60092 + }
60093 +#endif
60094 + return 0;
60095 +}
60096 +
60097 +int gr_process_user_ban(void)
60098 +{
60099 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
60100 + return __gr_process_user_ban(current->cred->user);
60101 +#endif
60102 + return 0;
60103 +}
60104 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
60105 new file mode 100644
60106 index 0000000..4030d57
60107 --- /dev/null
60108 +++ b/grsecurity/grsec_sock.c
60109 @@ -0,0 +1,244 @@
60110 +#include <linux/kernel.h>
60111 +#include <linux/module.h>
60112 +#include <linux/sched.h>
60113 +#include <linux/file.h>
60114 +#include <linux/net.h>
60115 +#include <linux/in.h>
60116 +#include <linux/ip.h>
60117 +#include <net/sock.h>
60118 +#include <net/inet_sock.h>
60119 +#include <linux/grsecurity.h>
60120 +#include <linux/grinternal.h>
60121 +#include <linux/gracl.h>
60122 +
60123 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
60124 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
60125 +
60126 +EXPORT_SYMBOL(gr_search_udp_recvmsg);
60127 +EXPORT_SYMBOL(gr_search_udp_sendmsg);
60128 +
60129 +#ifdef CONFIG_UNIX_MODULE
60130 +EXPORT_SYMBOL(gr_acl_handle_unix);
60131 +EXPORT_SYMBOL(gr_acl_handle_mknod);
60132 +EXPORT_SYMBOL(gr_handle_chroot_unix);
60133 +EXPORT_SYMBOL(gr_handle_create);
60134 +#endif
60135 +
60136 +#ifdef CONFIG_GRKERNSEC
60137 +#define gr_conn_table_size 32749
60138 +struct conn_table_entry {
60139 + struct conn_table_entry *next;
60140 + struct signal_struct *sig;
60141 +};
60142 +
60143 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
60144 +DEFINE_SPINLOCK(gr_conn_table_lock);
60145 +
60146 +extern const char * gr_socktype_to_name(unsigned char type);
60147 +extern const char * gr_proto_to_name(unsigned char proto);
60148 +extern const char * gr_sockfamily_to_name(unsigned char family);
60149 +
60150 +static __inline__ int
60151 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
60152 +{
60153 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
60154 +}
60155 +
60156 +static __inline__ int
60157 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
60158 + __u16 sport, __u16 dport)
60159 +{
60160 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
60161 + sig->gr_sport == sport && sig->gr_dport == dport))
60162 + return 1;
60163 + else
60164 + return 0;
60165 +}
60166 +
60167 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
60168 +{
60169 + struct conn_table_entry **match;
60170 + unsigned int index;
60171 +
60172 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
60173 + sig->gr_sport, sig->gr_dport,
60174 + gr_conn_table_size);
60175 +
60176 + newent->sig = sig;
60177 +
60178 + match = &gr_conn_table[index];
60179 + newent->next = *match;
60180 + *match = newent;
60181 +
60182 + return;
60183 +}
60184 +
60185 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
60186 +{
60187 + struct conn_table_entry *match, *last = NULL;
60188 + unsigned int index;
60189 +
60190 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
60191 + sig->gr_sport, sig->gr_dport,
60192 + gr_conn_table_size);
60193 +
60194 + match = gr_conn_table[index];
60195 + while (match && !conn_match(match->sig,
60196 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
60197 + sig->gr_dport)) {
60198 + last = match;
60199 + match = match->next;
60200 + }
60201 +
60202 + if (match) {
60203 + if (last)
60204 + last->next = match->next;
60205 + else
60206 + gr_conn_table[index] = NULL;
60207 + kfree(match);
60208 + }
60209 +
60210 + return;
60211 +}
60212 +
60213 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
60214 + __u16 sport, __u16 dport)
60215 +{
60216 + struct conn_table_entry *match;
60217 + unsigned int index;
60218 +
60219 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
60220 +
60221 + match = gr_conn_table[index];
60222 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
60223 + match = match->next;
60224 +
60225 + if (match)
60226 + return match->sig;
60227 + else
60228 + return NULL;
60229 +}
60230 +
60231 +#endif
60232 +
60233 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
60234 +{
60235 +#ifdef CONFIG_GRKERNSEC
60236 + struct signal_struct *sig = task->signal;
60237 + struct conn_table_entry *newent;
60238 +
60239 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
60240 + if (newent == NULL)
60241 + return;
60242 + /* no bh lock needed since we are called with bh disabled */
60243 + spin_lock(&gr_conn_table_lock);
60244 + gr_del_task_from_ip_table_nolock(sig);
60245 + sig->gr_saddr = inet->inet_rcv_saddr;
60246 + sig->gr_daddr = inet->inet_daddr;
60247 + sig->gr_sport = inet->inet_sport;
60248 + sig->gr_dport = inet->inet_dport;
60249 + gr_add_to_task_ip_table_nolock(sig, newent);
60250 + spin_unlock(&gr_conn_table_lock);
60251 +#endif
60252 + return;
60253 +}
60254 +
60255 +void gr_del_task_from_ip_table(struct task_struct *task)
60256 +{
60257 +#ifdef CONFIG_GRKERNSEC
60258 + spin_lock_bh(&gr_conn_table_lock);
60259 + gr_del_task_from_ip_table_nolock(task->signal);
60260 + spin_unlock_bh(&gr_conn_table_lock);
60261 +#endif
60262 + return;
60263 +}
60264 +
60265 +void
60266 +gr_attach_curr_ip(const struct sock *sk)
60267 +{
60268 +#ifdef CONFIG_GRKERNSEC
60269 + struct signal_struct *p, *set;
60270 + const struct inet_sock *inet = inet_sk(sk);
60271 +
60272 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
60273 + return;
60274 +
60275 + set = current->signal;
60276 +
60277 + spin_lock_bh(&gr_conn_table_lock);
60278 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
60279 + inet->inet_dport, inet->inet_sport);
60280 + if (unlikely(p != NULL)) {
60281 + set->curr_ip = p->curr_ip;
60282 + set->used_accept = 1;
60283 + gr_del_task_from_ip_table_nolock(p);
60284 + spin_unlock_bh(&gr_conn_table_lock);
60285 + return;
60286 + }
60287 + spin_unlock_bh(&gr_conn_table_lock);
60288 +
60289 + set->curr_ip = inet->inet_daddr;
60290 + set->used_accept = 1;
60291 +#endif
60292 + return;
60293 +}
60294 +
60295 +int
60296 +gr_handle_sock_all(const int family, const int type, const int protocol)
60297 +{
60298 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
60299 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
60300 + (family != AF_UNIX)) {
60301 + if (family == AF_INET)
60302 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
60303 + else
60304 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
60305 + return -EACCES;
60306 + }
60307 +#endif
60308 + return 0;
60309 +}
60310 +
60311 +int
60312 +gr_handle_sock_server(const struct sockaddr *sck)
60313 +{
60314 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
60315 + if (grsec_enable_socket_server &&
60316 + in_group_p(grsec_socket_server_gid) &&
60317 + sck && (sck->sa_family != AF_UNIX) &&
60318 + (sck->sa_family != AF_LOCAL)) {
60319 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
60320 + return -EACCES;
60321 + }
60322 +#endif
60323 + return 0;
60324 +}
60325 +
60326 +int
60327 +gr_handle_sock_server_other(const struct sock *sck)
60328 +{
60329 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
60330 + if (grsec_enable_socket_server &&
60331 + in_group_p(grsec_socket_server_gid) &&
60332 + sck && (sck->sk_family != AF_UNIX) &&
60333 + (sck->sk_family != AF_LOCAL)) {
60334 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
60335 + return -EACCES;
60336 + }
60337 +#endif
60338 + return 0;
60339 +}
60340 +
60341 +int
60342 +gr_handle_sock_client(const struct sockaddr *sck)
60343 +{
60344 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
60345 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
60346 + sck && (sck->sa_family != AF_UNIX) &&
60347 + (sck->sa_family != AF_LOCAL)) {
60348 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
60349 + return -EACCES;
60350 + }
60351 +#endif
60352 + return 0;
60353 +}
60354 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
60355 new file mode 100644
60356 index 0000000..f55ef0f
60357 --- /dev/null
60358 +++ b/grsecurity/grsec_sysctl.c
60359 @@ -0,0 +1,469 @@
60360 +#include <linux/kernel.h>
60361 +#include <linux/sched.h>
60362 +#include <linux/sysctl.h>
60363 +#include <linux/grsecurity.h>
60364 +#include <linux/grinternal.h>
60365 +
60366 +int
60367 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
60368 +{
60369 +#ifdef CONFIG_GRKERNSEC_SYSCTL
60370 + if (dirname == NULL || name == NULL)
60371 + return 0;
60372 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
60373 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
60374 + return -EACCES;
60375 + }
60376 +#endif
60377 + return 0;
60378 +}
60379 +
60380 +#ifdef CONFIG_GRKERNSEC_ROFS
60381 +static int __maybe_unused one = 1;
60382 +#endif
60383 +
60384 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
60385 +struct ctl_table grsecurity_table[] = {
60386 +#ifdef CONFIG_GRKERNSEC_SYSCTL
60387 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
60388 +#ifdef CONFIG_GRKERNSEC_IO
60389 + {
60390 + .procname = "disable_priv_io",
60391 + .data = &grsec_disable_privio,
60392 + .maxlen = sizeof(int),
60393 + .mode = 0600,
60394 + .proc_handler = &proc_dointvec,
60395 + },
60396 +#endif
60397 +#endif
60398 +#ifdef CONFIG_GRKERNSEC_LINK
60399 + {
60400 + .procname = "linking_restrictions",
60401 + .data = &grsec_enable_link,
60402 + .maxlen = sizeof(int),
60403 + .mode = 0600,
60404 + .proc_handler = &proc_dointvec,
60405 + },
60406 +#endif
60407 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
60408 + {
60409 + .procname = "enforce_symlinksifowner",
60410 + .data = &grsec_enable_symlinkown,
60411 + .maxlen = sizeof(int),
60412 + .mode = 0600,
60413 + .proc_handler = &proc_dointvec,
60414 + },
60415 + {
60416 + .procname = "symlinkown_gid",
60417 + .data = &grsec_symlinkown_gid,
60418 + .maxlen = sizeof(int),
60419 + .mode = 0600,
60420 + .proc_handler = &proc_dointvec,
60421 + },
60422 +#endif
60423 +#ifdef CONFIG_GRKERNSEC_BRUTE
60424 + {
60425 + .procname = "deter_bruteforce",
60426 + .data = &grsec_enable_brute,
60427 + .maxlen = sizeof(int),
60428 + .mode = 0600,
60429 + .proc_handler = &proc_dointvec,
60430 + },
60431 +#endif
60432 +#ifdef CONFIG_GRKERNSEC_FIFO
60433 + {
60434 + .procname = "fifo_restrictions",
60435 + .data = &grsec_enable_fifo,
60436 + .maxlen = sizeof(int),
60437 + .mode = 0600,
60438 + .proc_handler = &proc_dointvec,
60439 + },
60440 +#endif
60441 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
60442 + {
60443 + .procname = "ptrace_readexec",
60444 + .data = &grsec_enable_ptrace_readexec,
60445 + .maxlen = sizeof(int),
60446 + .mode = 0600,
60447 + .proc_handler = &proc_dointvec,
60448 + },
60449 +#endif
60450 +#ifdef CONFIG_GRKERNSEC_SETXID
60451 + {
60452 + .procname = "consistent_setxid",
60453 + .data = &grsec_enable_setxid,
60454 + .maxlen = sizeof(int),
60455 + .mode = 0600,
60456 + .proc_handler = &proc_dointvec,
60457 + },
60458 +#endif
60459 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
60460 + {
60461 + .procname = "ip_blackhole",
60462 + .data = &grsec_enable_blackhole,
60463 + .maxlen = sizeof(int),
60464 + .mode = 0600,
60465 + .proc_handler = &proc_dointvec,
60466 + },
60467 + {
60468 + .procname = "lastack_retries",
60469 + .data = &grsec_lastack_retries,
60470 + .maxlen = sizeof(int),
60471 + .mode = 0600,
60472 + .proc_handler = &proc_dointvec,
60473 + },
60474 +#endif
60475 +#ifdef CONFIG_GRKERNSEC_EXECLOG
60476 + {
60477 + .procname = "exec_logging",
60478 + .data = &grsec_enable_execlog,
60479 + .maxlen = sizeof(int),
60480 + .mode = 0600,
60481 + .proc_handler = &proc_dointvec,
60482 + },
60483 +#endif
60484 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
60485 + {
60486 + .procname = "rwxmap_logging",
60487 + .data = &grsec_enable_log_rwxmaps,
60488 + .maxlen = sizeof(int),
60489 + .mode = 0600,
60490 + .proc_handler = &proc_dointvec,
60491 + },
60492 +#endif
60493 +#ifdef CONFIG_GRKERNSEC_SIGNAL
60494 + {
60495 + .procname = "signal_logging",
60496 + .data = &grsec_enable_signal,
60497 + .maxlen = sizeof(int),
60498 + .mode = 0600,
60499 + .proc_handler = &proc_dointvec,
60500 + },
60501 +#endif
60502 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
60503 + {
60504 + .procname = "forkfail_logging",
60505 + .data = &grsec_enable_forkfail,
60506 + .maxlen = sizeof(int),
60507 + .mode = 0600,
60508 + .proc_handler = &proc_dointvec,
60509 + },
60510 +#endif
60511 +#ifdef CONFIG_GRKERNSEC_TIME
60512 + {
60513 + .procname = "timechange_logging",
60514 + .data = &grsec_enable_time,
60515 + .maxlen = sizeof(int),
60516 + .mode = 0600,
60517 + .proc_handler = &proc_dointvec,
60518 + },
60519 +#endif
60520 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
60521 + {
60522 + .procname = "chroot_deny_shmat",
60523 + .data = &grsec_enable_chroot_shmat,
60524 + .maxlen = sizeof(int),
60525 + .mode = 0600,
60526 + .proc_handler = &proc_dointvec,
60527 + },
60528 +#endif
60529 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
60530 + {
60531 + .procname = "chroot_deny_unix",
60532 + .data = &grsec_enable_chroot_unix,
60533 + .maxlen = sizeof(int),
60534 + .mode = 0600,
60535 + .proc_handler = &proc_dointvec,
60536 + },
60537 +#endif
60538 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
60539 + {
60540 + .procname = "chroot_deny_mount",
60541 + .data = &grsec_enable_chroot_mount,
60542 + .maxlen = sizeof(int),
60543 + .mode = 0600,
60544 + .proc_handler = &proc_dointvec,
60545 + },
60546 +#endif
60547 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
60548 + {
60549 + .procname = "chroot_deny_fchdir",
60550 + .data = &grsec_enable_chroot_fchdir,
60551 + .maxlen = sizeof(int),
60552 + .mode = 0600,
60553 + .proc_handler = &proc_dointvec,
60554 + },
60555 +#endif
60556 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
60557 + {
60558 + .procname = "chroot_deny_chroot",
60559 + .data = &grsec_enable_chroot_double,
60560 + .maxlen = sizeof(int),
60561 + .mode = 0600,
60562 + .proc_handler = &proc_dointvec,
60563 + },
60564 +#endif
60565 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
60566 + {
60567 + .procname = "chroot_deny_pivot",
60568 + .data = &grsec_enable_chroot_pivot,
60569 + .maxlen = sizeof(int),
60570 + .mode = 0600,
60571 + .proc_handler = &proc_dointvec,
60572 + },
60573 +#endif
60574 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
60575 + {
60576 + .procname = "chroot_enforce_chdir",
60577 + .data = &grsec_enable_chroot_chdir,
60578 + .maxlen = sizeof(int),
60579 + .mode = 0600,
60580 + .proc_handler = &proc_dointvec,
60581 + },
60582 +#endif
60583 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
60584 + {
60585 + .procname = "chroot_deny_chmod",
60586 + .data = &grsec_enable_chroot_chmod,
60587 + .maxlen = sizeof(int),
60588 + .mode = 0600,
60589 + .proc_handler = &proc_dointvec,
60590 + },
60591 +#endif
60592 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
60593 + {
60594 + .procname = "chroot_deny_mknod",
60595 + .data = &grsec_enable_chroot_mknod,
60596 + .maxlen = sizeof(int),
60597 + .mode = 0600,
60598 + .proc_handler = &proc_dointvec,
60599 + },
60600 +#endif
60601 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
60602 + {
60603 + .procname = "chroot_restrict_nice",
60604 + .data = &grsec_enable_chroot_nice,
60605 + .maxlen = sizeof(int),
60606 + .mode = 0600,
60607 + .proc_handler = &proc_dointvec,
60608 + },
60609 +#endif
60610 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
60611 + {
60612 + .procname = "chroot_execlog",
60613 + .data = &grsec_enable_chroot_execlog,
60614 + .maxlen = sizeof(int),
60615 + .mode = 0600,
60616 + .proc_handler = &proc_dointvec,
60617 + },
60618 +#endif
60619 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
60620 + {
60621 + .procname = "chroot_caps",
60622 + .data = &grsec_enable_chroot_caps,
60623 + .maxlen = sizeof(int),
60624 + .mode = 0600,
60625 + .proc_handler = &proc_dointvec,
60626 + },
60627 +#endif
60628 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
60629 + {
60630 + .procname = "chroot_deny_sysctl",
60631 + .data = &grsec_enable_chroot_sysctl,
60632 + .maxlen = sizeof(int),
60633 + .mode = 0600,
60634 + .proc_handler = &proc_dointvec,
60635 + },
60636 +#endif
60637 +#ifdef CONFIG_GRKERNSEC_TPE
60638 + {
60639 + .procname = "tpe",
60640 + .data = &grsec_enable_tpe,
60641 + .maxlen = sizeof(int),
60642 + .mode = 0600,
60643 + .proc_handler = &proc_dointvec,
60644 + },
60645 + {
60646 + .procname = "tpe_gid",
60647 + .data = &grsec_tpe_gid,
60648 + .maxlen = sizeof(int),
60649 + .mode = 0600,
60650 + .proc_handler = &proc_dointvec,
60651 + },
60652 +#endif
60653 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
60654 + {
60655 + .procname = "tpe_invert",
60656 + .data = &grsec_enable_tpe_invert,
60657 + .maxlen = sizeof(int),
60658 + .mode = 0600,
60659 + .proc_handler = &proc_dointvec,
60660 + },
60661 +#endif
60662 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
60663 + {
60664 + .procname = "tpe_restrict_all",
60665 + .data = &grsec_enable_tpe_all,
60666 + .maxlen = sizeof(int),
60667 + .mode = 0600,
60668 + .proc_handler = &proc_dointvec,
60669 + },
60670 +#endif
60671 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
60672 + {
60673 + .procname = "socket_all",
60674 + .data = &grsec_enable_socket_all,
60675 + .maxlen = sizeof(int),
60676 + .mode = 0600,
60677 + .proc_handler = &proc_dointvec,
60678 + },
60679 + {
60680 + .procname = "socket_all_gid",
60681 + .data = &grsec_socket_all_gid,
60682 + .maxlen = sizeof(int),
60683 + .mode = 0600,
60684 + .proc_handler = &proc_dointvec,
60685 + },
60686 +#endif
60687 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
60688 + {
60689 + .procname = "socket_client",
60690 + .data = &grsec_enable_socket_client,
60691 + .maxlen = sizeof(int),
60692 + .mode = 0600,
60693 + .proc_handler = &proc_dointvec,
60694 + },
60695 + {
60696 + .procname = "socket_client_gid",
60697 + .data = &grsec_socket_client_gid,
60698 + .maxlen = sizeof(int),
60699 + .mode = 0600,
60700 + .proc_handler = &proc_dointvec,
60701 + },
60702 +#endif
60703 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
60704 + {
60705 + .procname = "socket_server",
60706 + .data = &grsec_enable_socket_server,
60707 + .maxlen = sizeof(int),
60708 + .mode = 0600,
60709 + .proc_handler = &proc_dointvec,
60710 + },
60711 + {
60712 + .procname = "socket_server_gid",
60713 + .data = &grsec_socket_server_gid,
60714 + .maxlen = sizeof(int),
60715 + .mode = 0600,
60716 + .proc_handler = &proc_dointvec,
60717 + },
60718 +#endif
60719 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
60720 + {
60721 + .procname = "audit_group",
60722 + .data = &grsec_enable_group,
60723 + .maxlen = sizeof(int),
60724 + .mode = 0600,
60725 + .proc_handler = &proc_dointvec,
60726 + },
60727 + {
60728 + .procname = "audit_gid",
60729 + .data = &grsec_audit_gid,
60730 + .maxlen = sizeof(int),
60731 + .mode = 0600,
60732 + .proc_handler = &proc_dointvec,
60733 + },
60734 +#endif
60735 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
60736 + {
60737 + .procname = "audit_chdir",
60738 + .data = &grsec_enable_chdir,
60739 + .maxlen = sizeof(int),
60740 + .mode = 0600,
60741 + .proc_handler = &proc_dointvec,
60742 + },
60743 +#endif
60744 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
60745 + {
60746 + .procname = "audit_mount",
60747 + .data = &grsec_enable_mount,
60748 + .maxlen = sizeof(int),
60749 + .mode = 0600,
60750 + .proc_handler = &proc_dointvec,
60751 + },
60752 +#endif
60753 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
60754 + {
60755 + .procname = "audit_textrel",
60756 + .data = &grsec_enable_audit_textrel,
60757 + .maxlen = sizeof(int),
60758 + .mode = 0600,
60759 + .proc_handler = &proc_dointvec,
60760 + },
60761 +#endif
60762 +#ifdef CONFIG_GRKERNSEC_DMESG
60763 + {
60764 + .procname = "dmesg",
60765 + .data = &grsec_enable_dmesg,
60766 + .maxlen = sizeof(int),
60767 + .mode = 0600,
60768 + .proc_handler = &proc_dointvec,
60769 + },
60770 +#endif
60771 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
60772 + {
60773 + .procname = "chroot_findtask",
60774 + .data = &grsec_enable_chroot_findtask,
60775 + .maxlen = sizeof(int),
60776 + .mode = 0600,
60777 + .proc_handler = &proc_dointvec,
60778 + },
60779 +#endif
60780 +#ifdef CONFIG_GRKERNSEC_RESLOG
60781 + {
60782 + .procname = "resource_logging",
60783 + .data = &grsec_resource_logging,
60784 + .maxlen = sizeof(int),
60785 + .mode = 0600,
60786 + .proc_handler = &proc_dointvec,
60787 + },
60788 +#endif
60789 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
60790 + {
60791 + .procname = "audit_ptrace",
60792 + .data = &grsec_enable_audit_ptrace,
60793 + .maxlen = sizeof(int),
60794 + .mode = 0600,
60795 + .proc_handler = &proc_dointvec,
60796 + },
60797 +#endif
60798 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
60799 + {
60800 + .procname = "harden_ptrace",
60801 + .data = &grsec_enable_harden_ptrace,
60802 + .maxlen = sizeof(int),
60803 + .mode = 0600,
60804 + .proc_handler = &proc_dointvec,
60805 + },
60806 +#endif
60807 + {
60808 + .procname = "grsec_lock",
60809 + .data = &grsec_lock,
60810 + .maxlen = sizeof(int),
60811 + .mode = 0600,
60812 + .proc_handler = &proc_dointvec,
60813 + },
60814 +#endif
60815 +#ifdef CONFIG_GRKERNSEC_ROFS
60816 + {
60817 + .procname = "romount_protect",
60818 + .data = &grsec_enable_rofs,
60819 + .maxlen = sizeof(int),
60820 + .mode = 0600,
60821 + .proc_handler = &proc_dointvec_minmax,
60822 + .extra1 = &one,
60823 + .extra2 = &one,
60824 + },
60825 +#endif
60826 + { }
60827 +};
60828 +#endif
60829 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
60830 new file mode 100644
60831 index 0000000..0dc13c3
60832 --- /dev/null
60833 +++ b/grsecurity/grsec_time.c
60834 @@ -0,0 +1,16 @@
60835 +#include <linux/kernel.h>
60836 +#include <linux/sched.h>
60837 +#include <linux/grinternal.h>
60838 +#include <linux/module.h>
60839 +
60840 +void
60841 +gr_log_timechange(void)
60842 +{
60843 +#ifdef CONFIG_GRKERNSEC_TIME
60844 + if (grsec_enable_time)
60845 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
60846 +#endif
60847 + return;
60848 +}
60849 +
60850 +EXPORT_SYMBOL(gr_log_timechange);
60851 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
60852 new file mode 100644
60853 index 0000000..07e0dc0
60854 --- /dev/null
60855 +++ b/grsecurity/grsec_tpe.c
60856 @@ -0,0 +1,73 @@
60857 +#include <linux/kernel.h>
60858 +#include <linux/sched.h>
60859 +#include <linux/file.h>
60860 +#include <linux/fs.h>
60861 +#include <linux/grinternal.h>
60862 +
60863 +extern int gr_acl_tpe_check(void);
60864 +
60865 +int
60866 +gr_tpe_allow(const struct file *file)
60867 +{
60868 +#ifdef CONFIG_GRKERNSEC
60869 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
60870 + const struct cred *cred = current_cred();
60871 + char *msg = NULL;
60872 + char *msg2 = NULL;
60873 +
60874 + // never restrict root
60875 + if (!cred->uid)
60876 + return 1;
60877 +
60878 + if (grsec_enable_tpe) {
60879 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
60880 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
60881 + msg = "not being in trusted group";
60882 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
60883 + msg = "being in untrusted group";
60884 +#else
60885 + if (in_group_p(grsec_tpe_gid))
60886 + msg = "being in untrusted group";
60887 +#endif
60888 + }
60889 + if (!msg && gr_acl_tpe_check())
60890 + msg = "being in untrusted role";
60891 +
60892 + // not in any affected group/role
60893 + if (!msg)
60894 + goto next_check;
60895 +
60896 + if (inode->i_uid)
60897 + msg2 = "file in non-root-owned directory";
60898 + else if (inode->i_mode & S_IWOTH)
60899 + msg2 = "file in world-writable directory";
60900 + else if (inode->i_mode & S_IWGRP)
60901 + msg2 = "file in group-writable directory";
60902 +
60903 + if (msg && msg2) {
60904 + char fullmsg[70] = {0};
60905 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
60906 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
60907 + return 0;
60908 + }
60909 + msg = NULL;
60910 +next_check:
60911 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
60912 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
60913 + return 1;
60914 +
60915 + if (inode->i_uid && (inode->i_uid != cred->uid))
60916 + msg = "directory not owned by user";
60917 + else if (inode->i_mode & S_IWOTH)
60918 + msg = "file in world-writable directory";
60919 + else if (inode->i_mode & S_IWGRP)
60920 + msg = "file in group-writable directory";
60921 +
60922 + if (msg) {
60923 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
60924 + return 0;
60925 + }
60926 +#endif
60927 +#endif
60928 + return 1;
60929 +}
60930 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
60931 new file mode 100644
60932 index 0000000..9f7b1ac
60933 --- /dev/null
60934 +++ b/grsecurity/grsum.c
60935 @@ -0,0 +1,61 @@
60936 +#include <linux/err.h>
60937 +#include <linux/kernel.h>
60938 +#include <linux/sched.h>
60939 +#include <linux/mm.h>
60940 +#include <linux/scatterlist.h>
60941 +#include <linux/crypto.h>
60942 +#include <linux/gracl.h>
60943 +
60944 +
60945 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
60946 +#error "crypto and sha256 must be built into the kernel"
60947 +#endif
60948 +
60949 +int
60950 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
60951 +{
60952 + char *p;
60953 + struct crypto_hash *tfm;
60954 + struct hash_desc desc;
60955 + struct scatterlist sg;
60956 + unsigned char temp_sum[GR_SHA_LEN];
60957 + volatile int retval = 0;
60958 + volatile int dummy = 0;
60959 + unsigned int i;
60960 +
60961 + sg_init_table(&sg, 1);
60962 +
60963 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
60964 + if (IS_ERR(tfm)) {
60965 + /* should never happen, since sha256 should be built in */
60966 + return 1;
60967 + }
60968 +
60969 + desc.tfm = tfm;
60970 + desc.flags = 0;
60971 +
60972 + crypto_hash_init(&desc);
60973 +
60974 + p = salt;
60975 + sg_set_buf(&sg, p, GR_SALT_LEN);
60976 + crypto_hash_update(&desc, &sg, sg.length);
60977 +
60978 + p = entry->pw;
60979 + sg_set_buf(&sg, p, strlen(p));
60980 +
60981 + crypto_hash_update(&desc, &sg, sg.length);
60982 +
60983 + crypto_hash_final(&desc, temp_sum);
60984 +
60985 + memset(entry->pw, 0, GR_PW_LEN);
60986 +
60987 + for (i = 0; i < GR_SHA_LEN; i++)
60988 + if (sum[i] != temp_sum[i])
60989 + retval = 1;
60990 + else
60991 + dummy = 1; // waste a cycle
60992 +
60993 + crypto_free_hash(tfm);
60994 +
60995 + return retval;
60996 +}
60997 diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
60998 index bde976e..a1cc32a 100644
60999 --- a/include/acpi/acpi_bus.h
61000 +++ b/include/acpi/acpi_bus.h
61001 @@ -136,7 +136,7 @@ struct acpi_device_ops {
61002 acpi_op_bind bind;
61003 acpi_op_unbind unbind;
61004 acpi_op_notify notify;
61005 -};
61006 +} __no_const;
61007
61008 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
61009
61010 diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
61011 index 77ff547..181834f 100644
61012 --- a/include/asm-generic/4level-fixup.h
61013 +++ b/include/asm-generic/4level-fixup.h
61014 @@ -13,8 +13,10 @@
61015 #define pmd_alloc(mm, pud, address) \
61016 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
61017 NULL: pmd_offset(pud, address))
61018 +#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
61019
61020 #define pud_alloc(mm, pgd, address) (pgd)
61021 +#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
61022 #define pud_offset(pgd, start) (pgd)
61023 #define pud_none(pud) 0
61024 #define pud_bad(pud) 0
61025 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
61026 index b7babf0..3ba8aee 100644
61027 --- a/include/asm-generic/atomic-long.h
61028 +++ b/include/asm-generic/atomic-long.h
61029 @@ -22,6 +22,12 @@
61030
61031 typedef atomic64_t atomic_long_t;
61032
61033 +#ifdef CONFIG_PAX_REFCOUNT
61034 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
61035 +#else
61036 +typedef atomic64_t atomic_long_unchecked_t;
61037 +#endif
61038 +
61039 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
61040
61041 static inline long atomic_long_read(atomic_long_t *l)
61042 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
61043 return (long)atomic64_read(v);
61044 }
61045
61046 +#ifdef CONFIG_PAX_REFCOUNT
61047 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
61048 +{
61049 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
61050 +
61051 + return (long)atomic64_read_unchecked(v);
61052 +}
61053 +#endif
61054 +
61055 static inline void atomic_long_set(atomic_long_t *l, long i)
61056 {
61057 atomic64_t *v = (atomic64_t *)l;
61058 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
61059 atomic64_set(v, i);
61060 }
61061
61062 +#ifdef CONFIG_PAX_REFCOUNT
61063 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
61064 +{
61065 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
61066 +
61067 + atomic64_set_unchecked(v, i);
61068 +}
61069 +#endif
61070 +
61071 static inline void atomic_long_inc(atomic_long_t *l)
61072 {
61073 atomic64_t *v = (atomic64_t *)l;
61074 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
61075 atomic64_inc(v);
61076 }
61077
61078 +#ifdef CONFIG_PAX_REFCOUNT
61079 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
61080 +{
61081 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
61082 +
61083 + atomic64_inc_unchecked(v);
61084 +}
61085 +#endif
61086 +
61087 static inline void atomic_long_dec(atomic_long_t *l)
61088 {
61089 atomic64_t *v = (atomic64_t *)l;
61090 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
61091 atomic64_dec(v);
61092 }
61093
61094 +#ifdef CONFIG_PAX_REFCOUNT
61095 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
61096 +{
61097 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
61098 +
61099 + atomic64_dec_unchecked(v);
61100 +}
61101 +#endif
61102 +
61103 static inline void atomic_long_add(long i, atomic_long_t *l)
61104 {
61105 atomic64_t *v = (atomic64_t *)l;
61106 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
61107 atomic64_add(i, v);
61108 }
61109
61110 +#ifdef CONFIG_PAX_REFCOUNT
61111 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
61112 +{
61113 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
61114 +
61115 + atomic64_add_unchecked(i, v);
61116 +}
61117 +#endif
61118 +
61119 static inline void atomic_long_sub(long i, atomic_long_t *l)
61120 {
61121 atomic64_t *v = (atomic64_t *)l;
61122 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
61123 atomic64_sub(i, v);
61124 }
61125
61126 +#ifdef CONFIG_PAX_REFCOUNT
61127 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
61128 +{
61129 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
61130 +
61131 + atomic64_sub_unchecked(i, v);
61132 +}
61133 +#endif
61134 +
61135 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
61136 {
61137 atomic64_t *v = (atomic64_t *)l;
61138 @@ -115,6 +175,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
61139 return (long)atomic64_inc_return(v);
61140 }
61141
61142 +#ifdef CONFIG_PAX_REFCOUNT
61143 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
61144 +{
61145 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
61146 +
61147 + return (long)atomic64_inc_return_unchecked(v);
61148 +}
61149 +#endif
61150 +
61151 static inline long atomic_long_dec_return(atomic_long_t *l)
61152 {
61153 atomic64_t *v = (atomic64_t *)l;
61154 @@ -140,6 +209,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
61155
61156 typedef atomic_t atomic_long_t;
61157
61158 +#ifdef CONFIG_PAX_REFCOUNT
61159 +typedef atomic_unchecked_t atomic_long_unchecked_t;
61160 +#else
61161 +typedef atomic_t atomic_long_unchecked_t;
61162 +#endif
61163 +
61164 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
61165 static inline long atomic_long_read(atomic_long_t *l)
61166 {
61167 @@ -148,6 +223,15 @@ static inline long atomic_long_read(atomic_long_t *l)
61168 return (long)atomic_read(v);
61169 }
61170
61171 +#ifdef CONFIG_PAX_REFCOUNT
61172 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
61173 +{
61174 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61175 +
61176 + return (long)atomic_read_unchecked(v);
61177 +}
61178 +#endif
61179 +
61180 static inline void atomic_long_set(atomic_long_t *l, long i)
61181 {
61182 atomic_t *v = (atomic_t *)l;
61183 @@ -155,6 +239,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
61184 atomic_set(v, i);
61185 }
61186
61187 +#ifdef CONFIG_PAX_REFCOUNT
61188 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
61189 +{
61190 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61191 +
61192 + atomic_set_unchecked(v, i);
61193 +}
61194 +#endif
61195 +
61196 static inline void atomic_long_inc(atomic_long_t *l)
61197 {
61198 atomic_t *v = (atomic_t *)l;
61199 @@ -162,6 +255,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
61200 atomic_inc(v);
61201 }
61202
61203 +#ifdef CONFIG_PAX_REFCOUNT
61204 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
61205 +{
61206 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61207 +
61208 + atomic_inc_unchecked(v);
61209 +}
61210 +#endif
61211 +
61212 static inline void atomic_long_dec(atomic_long_t *l)
61213 {
61214 atomic_t *v = (atomic_t *)l;
61215 @@ -169,6 +271,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
61216 atomic_dec(v);
61217 }
61218
61219 +#ifdef CONFIG_PAX_REFCOUNT
61220 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
61221 +{
61222 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61223 +
61224 + atomic_dec_unchecked(v);
61225 +}
61226 +#endif
61227 +
61228 static inline void atomic_long_add(long i, atomic_long_t *l)
61229 {
61230 atomic_t *v = (atomic_t *)l;
61231 @@ -176,6 +287,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
61232 atomic_add(i, v);
61233 }
61234
61235 +#ifdef CONFIG_PAX_REFCOUNT
61236 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
61237 +{
61238 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61239 +
61240 + atomic_add_unchecked(i, v);
61241 +}
61242 +#endif
61243 +
61244 static inline void atomic_long_sub(long i, atomic_long_t *l)
61245 {
61246 atomic_t *v = (atomic_t *)l;
61247 @@ -183,6 +303,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
61248 atomic_sub(i, v);
61249 }
61250
61251 +#ifdef CONFIG_PAX_REFCOUNT
61252 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
61253 +{
61254 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61255 +
61256 + atomic_sub_unchecked(i, v);
61257 +}
61258 +#endif
61259 +
61260 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
61261 {
61262 atomic_t *v = (atomic_t *)l;
61263 @@ -232,6 +361,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
61264 return (long)atomic_inc_return(v);
61265 }
61266
61267 +#ifdef CONFIG_PAX_REFCOUNT
61268 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
61269 +{
61270 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61271 +
61272 + return (long)atomic_inc_return_unchecked(v);
61273 +}
61274 +#endif
61275 +
61276 static inline long atomic_long_dec_return(atomic_long_t *l)
61277 {
61278 atomic_t *v = (atomic_t *)l;
61279 @@ -255,4 +393,55 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
61280
61281 #endif /* BITS_PER_LONG == 64 */
61282
61283 +#ifdef CONFIG_PAX_REFCOUNT
61284 +static inline void pax_refcount_needs_these_functions(void)
61285 +{
61286 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
61287 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
61288 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
61289 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
61290 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
61291 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
61292 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
61293 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
61294 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
61295 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
61296 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
61297 +#ifdef CONFIG_X86
61298 + atomic_clear_mask_unchecked(0, NULL);
61299 + atomic_set_mask_unchecked(0, NULL);
61300 +#endif
61301 +
61302 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
61303 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
61304 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
61305 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
61306 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
61307 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
61308 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
61309 +}
61310 +#else
61311 +#define atomic_read_unchecked(v) atomic_read(v)
61312 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
61313 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
61314 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
61315 +#define atomic_inc_unchecked(v) atomic_inc(v)
61316 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
61317 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
61318 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
61319 +#define atomic_dec_unchecked(v) atomic_dec(v)
61320 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
61321 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
61322 +#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
61323 +#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
61324 +
61325 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
61326 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
61327 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
61328 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
61329 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
61330 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
61331 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
61332 +#endif
61333 +
61334 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
61335 diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
61336 index 1ced641..c896ee8 100644
61337 --- a/include/asm-generic/atomic.h
61338 +++ b/include/asm-generic/atomic.h
61339 @@ -159,7 +159,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
61340 * Atomically clears the bits set in @mask from @v
61341 */
61342 #ifndef atomic_clear_mask
61343 -static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
61344 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
61345 {
61346 unsigned long flags;
61347
61348 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
61349 index b18ce4f..2ee2843 100644
61350 --- a/include/asm-generic/atomic64.h
61351 +++ b/include/asm-generic/atomic64.h
61352 @@ -16,6 +16,8 @@ typedef struct {
61353 long long counter;
61354 } atomic64_t;
61355
61356 +typedef atomic64_t atomic64_unchecked_t;
61357 +
61358 #define ATOMIC64_INIT(i) { (i) }
61359
61360 extern long long atomic64_read(const atomic64_t *v);
61361 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
61362 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
61363 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
61364
61365 +#define atomic64_read_unchecked(v) atomic64_read(v)
61366 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
61367 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
61368 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
61369 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
61370 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
61371 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
61372 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
61373 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
61374 +
61375 #endif /* _ASM_GENERIC_ATOMIC64_H */
61376 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
61377 index 1bfcfe5..e04c5c9 100644
61378 --- a/include/asm-generic/cache.h
61379 +++ b/include/asm-generic/cache.h
61380 @@ -6,7 +6,7 @@
61381 * cache lines need to provide their own cache.h.
61382 */
61383
61384 -#define L1_CACHE_SHIFT 5
61385 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
61386 +#define L1_CACHE_SHIFT 5UL
61387 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
61388
61389 #endif /* __ASM_GENERIC_CACHE_H */
61390 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
61391 index 0d68a1e..b74a761 100644
61392 --- a/include/asm-generic/emergency-restart.h
61393 +++ b/include/asm-generic/emergency-restart.h
61394 @@ -1,7 +1,7 @@
61395 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
61396 #define _ASM_GENERIC_EMERGENCY_RESTART_H
61397
61398 -static inline void machine_emergency_restart(void)
61399 +static inline __noreturn void machine_emergency_restart(void)
61400 {
61401 machine_restart(NULL);
61402 }
61403 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
61404 index 90f99c7..00ce236 100644
61405 --- a/include/asm-generic/kmap_types.h
61406 +++ b/include/asm-generic/kmap_types.h
61407 @@ -2,9 +2,9 @@
61408 #define _ASM_GENERIC_KMAP_TYPES_H
61409
61410 #ifdef __WITH_KM_FENCE
61411 -# define KM_TYPE_NR 41
61412 +# define KM_TYPE_NR 42
61413 #else
61414 -# define KM_TYPE_NR 20
61415 +# define KM_TYPE_NR 21
61416 #endif
61417
61418 #endif
61419 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
61420 index 9ceb03b..2efbcbd 100644
61421 --- a/include/asm-generic/local.h
61422 +++ b/include/asm-generic/local.h
61423 @@ -39,6 +39,7 @@ typedef struct
61424 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
61425 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
61426 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
61427 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
61428
61429 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
61430 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
61431 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
61432 index 725612b..9cc513a 100644
61433 --- a/include/asm-generic/pgtable-nopmd.h
61434 +++ b/include/asm-generic/pgtable-nopmd.h
61435 @@ -1,14 +1,19 @@
61436 #ifndef _PGTABLE_NOPMD_H
61437 #define _PGTABLE_NOPMD_H
61438
61439 -#ifndef __ASSEMBLY__
61440 -
61441 #include <asm-generic/pgtable-nopud.h>
61442
61443 -struct mm_struct;
61444 -
61445 #define __PAGETABLE_PMD_FOLDED
61446
61447 +#define PMD_SHIFT PUD_SHIFT
61448 +#define PTRS_PER_PMD 1
61449 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
61450 +#define PMD_MASK (~(PMD_SIZE-1))
61451 +
61452 +#ifndef __ASSEMBLY__
61453 +
61454 +struct mm_struct;
61455 +
61456 /*
61457 * Having the pmd type consist of a pud gets the size right, and allows
61458 * us to conceptually access the pud entry that this pmd is folded into
61459 @@ -16,11 +21,6 @@ struct mm_struct;
61460 */
61461 typedef struct { pud_t pud; } pmd_t;
61462
61463 -#define PMD_SHIFT PUD_SHIFT
61464 -#define PTRS_PER_PMD 1
61465 -#define PMD_SIZE (1UL << PMD_SHIFT)
61466 -#define PMD_MASK (~(PMD_SIZE-1))
61467 -
61468 /*
61469 * The "pud_xxx()" functions here are trivial for a folded two-level
61470 * setup: the pmd is never bad, and a pmd always exists (as it's folded
61471 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
61472 index 810431d..0ec4804f 100644
61473 --- a/include/asm-generic/pgtable-nopud.h
61474 +++ b/include/asm-generic/pgtable-nopud.h
61475 @@ -1,10 +1,15 @@
61476 #ifndef _PGTABLE_NOPUD_H
61477 #define _PGTABLE_NOPUD_H
61478
61479 -#ifndef __ASSEMBLY__
61480 -
61481 #define __PAGETABLE_PUD_FOLDED
61482
61483 +#define PUD_SHIFT PGDIR_SHIFT
61484 +#define PTRS_PER_PUD 1
61485 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
61486 +#define PUD_MASK (~(PUD_SIZE-1))
61487 +
61488 +#ifndef __ASSEMBLY__
61489 +
61490 /*
61491 * Having the pud type consist of a pgd gets the size right, and allows
61492 * us to conceptually access the pgd entry that this pud is folded into
61493 @@ -12,11 +17,6 @@
61494 */
61495 typedef struct { pgd_t pgd; } pud_t;
61496
61497 -#define PUD_SHIFT PGDIR_SHIFT
61498 -#define PTRS_PER_PUD 1
61499 -#define PUD_SIZE (1UL << PUD_SHIFT)
61500 -#define PUD_MASK (~(PUD_SIZE-1))
61501 -
61502 /*
61503 * The "pgd_xxx()" functions here are trivial for a folded two-level
61504 * setup: the pud is never bad, and a pud always exists (as it's folded
61505 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
61506 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
61507
61508 #define pgd_populate(mm, pgd, pud) do { } while (0)
61509 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
61510 /*
61511 * (puds are folded into pgds so this doesn't get actually called,
61512 * but the define is needed for a generic inline function.)
61513 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
61514 index ff4947b..f48183f 100644
61515 --- a/include/asm-generic/pgtable.h
61516 +++ b/include/asm-generic/pgtable.h
61517 @@ -530,6 +530,14 @@ static inline int pmd_trans_unstable(pmd_t *pmd)
61518 #endif
61519 }
61520
61521 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
61522 +static inline unsigned long pax_open_kernel(void) { return 0; }
61523 +#endif
61524 +
61525 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
61526 +static inline unsigned long pax_close_kernel(void) { return 0; }
61527 +#endif
61528 +
61529 #endif /* CONFIG_MMU */
61530
61531 #endif /* !__ASSEMBLY__ */
61532 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
61533 index 4e2e1cc..12c266b 100644
61534 --- a/include/asm-generic/vmlinux.lds.h
61535 +++ b/include/asm-generic/vmlinux.lds.h
61536 @@ -218,6 +218,7 @@
61537 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
61538 VMLINUX_SYMBOL(__start_rodata) = .; \
61539 *(.rodata) *(.rodata.*) \
61540 + *(.data..read_only) \
61541 *(__vermagic) /* Kernel version magic */ \
61542 . = ALIGN(8); \
61543 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
61544 @@ -716,17 +717,18 @@
61545 * section in the linker script will go there too. @phdr should have
61546 * a leading colon.
61547 *
61548 - * Note that this macros defines __per_cpu_load as an absolute symbol.
61549 + * Note that this macros defines per_cpu_load as an absolute symbol.
61550 * If there is no need to put the percpu section at a predetermined
61551 * address, use PERCPU_SECTION.
61552 */
61553 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
61554 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
61555 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
61556 + per_cpu_load = .; \
61557 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
61558 - LOAD_OFFSET) { \
61559 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
61560 PERCPU_INPUT(cacheline) \
61561 } phdr \
61562 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
61563 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
61564
61565 /**
61566 * PERCPU_SECTION - define output section for percpu area, simple version
61567 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
61568 index d6b67bb..a272c29 100644
61569 --- a/include/drm/drmP.h
61570 +++ b/include/drm/drmP.h
61571 @@ -72,6 +72,7 @@
61572 #include <linux/workqueue.h>
61573 #include <linux/poll.h>
61574 #include <asm/pgalloc.h>
61575 +#include <asm/local.h>
61576 #include "drm.h"
61577
61578 #include <linux/idr.h>
61579 @@ -1067,7 +1068,7 @@ struct drm_device {
61580
61581 /** \name Usage Counters */
61582 /*@{ */
61583 - int open_count; /**< Outstanding files open */
61584 + local_t open_count; /**< Outstanding files open */
61585 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
61586 atomic_t vma_count; /**< Outstanding vma areas open */
61587 int buf_use; /**< Buffers in use -- cannot alloc */
61588 @@ -1078,7 +1079,7 @@ struct drm_device {
61589 /*@{ */
61590 unsigned long counters;
61591 enum drm_stat_type types[15];
61592 - atomic_t counts[15];
61593 + atomic_unchecked_t counts[15];
61594 /*@} */
61595
61596 struct list_head filelist;
61597 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
61598 index e01cc80..319855d 100644
61599 --- a/include/drm/drm_crtc_helper.h
61600 +++ b/include/drm/drm_crtc_helper.h
61601 @@ -81,7 +81,7 @@ struct drm_crtc_helper_funcs {
61602
61603 /* disable crtc when not in use - more explicit than dpms off */
61604 void (*disable)(struct drm_crtc *crtc);
61605 -};
61606 +} __no_const;
61607
61608 /**
61609 * drm_encoder_helper_funcs - helper operations for encoders
61610 @@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
61611 struct drm_connector *connector);
61612 /* disable encoder when not in use - more explicit than dpms off */
61613 void (*disable)(struct drm_encoder *encoder);
61614 -};
61615 +} __no_const;
61616
61617 /**
61618 * drm_connector_helper_funcs - helper operations for connectors
61619 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
61620 index d6d1da4..fdd1ac5 100644
61621 --- a/include/drm/ttm/ttm_memory.h
61622 +++ b/include/drm/ttm/ttm_memory.h
61623 @@ -48,7 +48,7 @@
61624
61625 struct ttm_mem_shrink {
61626 int (*do_shrink) (struct ttm_mem_shrink *);
61627 -};
61628 +} __no_const;
61629
61630 /**
61631 * struct ttm_mem_global - Global memory accounting structure.
61632 diff --git a/include/linux/a.out.h b/include/linux/a.out.h
61633 index e86dfca..40cc55f 100644
61634 --- a/include/linux/a.out.h
61635 +++ b/include/linux/a.out.h
61636 @@ -39,6 +39,14 @@ enum machine_type {
61637 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
61638 };
61639
61640 +/* Constants for the N_FLAGS field */
61641 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
61642 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
61643 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
61644 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
61645 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
61646 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
61647 +
61648 #if !defined (N_MAGIC)
61649 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
61650 #endif
61651 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
61652 index 06fd4bb..1caec0d 100644
61653 --- a/include/linux/atmdev.h
61654 +++ b/include/linux/atmdev.h
61655 @@ -237,7 +237,7 @@ struct compat_atm_iobuf {
61656 #endif
61657
61658 struct k_atm_aal_stats {
61659 -#define __HANDLE_ITEM(i) atomic_t i
61660 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
61661 __AAL_STAT_ITEMS
61662 #undef __HANDLE_ITEM
61663 };
61664 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
61665 index 366422b..1fa7f84 100644
61666 --- a/include/linux/binfmts.h
61667 +++ b/include/linux/binfmts.h
61668 @@ -89,6 +89,7 @@ struct linux_binfmt {
61669 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
61670 int (*load_shlib)(struct file *);
61671 int (*core_dump)(struct coredump_params *cprm);
61672 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
61673 unsigned long min_coredump; /* minimal dump size */
61674 };
61675
61676 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
61677 index 4a2ab7c..a2de7a8 100644
61678 --- a/include/linux/blkdev.h
61679 +++ b/include/linux/blkdev.h
61680 @@ -1420,7 +1420,7 @@ struct block_device_operations {
61681 /* this callback is with swap_lock and sometimes page table lock held */
61682 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
61683 struct module *owner;
61684 -};
61685 +} __do_const;
61686
61687 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
61688 unsigned long);
61689 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
61690 index 4d1a074..88f929a 100644
61691 --- a/include/linux/blktrace_api.h
61692 +++ b/include/linux/blktrace_api.h
61693 @@ -162,7 +162,7 @@ struct blk_trace {
61694 struct dentry *dir;
61695 struct dentry *dropped_file;
61696 struct dentry *msg_file;
61697 - atomic_t dropped;
61698 + atomic_unchecked_t dropped;
61699 };
61700
61701 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
61702 diff --git a/include/linux/byteorder/little_endian.h b/include/linux/byteorder/little_endian.h
61703 index 83195fb..0b0f77d 100644
61704 --- a/include/linux/byteorder/little_endian.h
61705 +++ b/include/linux/byteorder/little_endian.h
61706 @@ -42,51 +42,51 @@
61707
61708 static inline __le64 __cpu_to_le64p(const __u64 *p)
61709 {
61710 - return (__force __le64)*p;
61711 + return (__force const __le64)*p;
61712 }
61713 static inline __u64 __le64_to_cpup(const __le64 *p)
61714 {
61715 - return (__force __u64)*p;
61716 + return (__force const __u64)*p;
61717 }
61718 static inline __le32 __cpu_to_le32p(const __u32 *p)
61719 {
61720 - return (__force __le32)*p;
61721 + return (__force const __le32)*p;
61722 }
61723 static inline __u32 __le32_to_cpup(const __le32 *p)
61724 {
61725 - return (__force __u32)*p;
61726 + return (__force const __u32)*p;
61727 }
61728 static inline __le16 __cpu_to_le16p(const __u16 *p)
61729 {
61730 - return (__force __le16)*p;
61731 + return (__force const __le16)*p;
61732 }
61733 static inline __u16 __le16_to_cpup(const __le16 *p)
61734 {
61735 - return (__force __u16)*p;
61736 + return (__force const __u16)*p;
61737 }
61738 static inline __be64 __cpu_to_be64p(const __u64 *p)
61739 {
61740 - return (__force __be64)__swab64p(p);
61741 + return (__force const __be64)__swab64p(p);
61742 }
61743 static inline __u64 __be64_to_cpup(const __be64 *p)
61744 {
61745 - return __swab64p((__u64 *)p);
61746 + return __swab64p((const __u64 *)p);
61747 }
61748 static inline __be32 __cpu_to_be32p(const __u32 *p)
61749 {
61750 - return (__force __be32)__swab32p(p);
61751 + return (__force const __be32)__swab32p(p);
61752 }
61753 static inline __u32 __be32_to_cpup(const __be32 *p)
61754 {
61755 - return __swab32p((__u32 *)p);
61756 + return __swab32p((const __u32 *)p);
61757 }
61758 static inline __be16 __cpu_to_be16p(const __u16 *p)
61759 {
61760 - return (__force __be16)__swab16p(p);
61761 + return (__force const __be16)__swab16p(p);
61762 }
61763 static inline __u16 __be16_to_cpup(const __be16 *p)
61764 {
61765 - return __swab16p((__u16 *)p);
61766 + return __swab16p((const __u16 *)p);
61767 }
61768 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
61769 #define __le64_to_cpus(x) do { (void)(x); } while (0)
61770 diff --git a/include/linux/cache.h b/include/linux/cache.h
61771 index 4c57065..4307975 100644
61772 --- a/include/linux/cache.h
61773 +++ b/include/linux/cache.h
61774 @@ -16,6 +16,10 @@
61775 #define __read_mostly
61776 #endif
61777
61778 +#ifndef __read_only
61779 +#define __read_only __read_mostly
61780 +#endif
61781 +
61782 #ifndef ____cacheline_aligned
61783 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
61784 #endif
61785 diff --git a/include/linux/capability.h b/include/linux/capability.h
61786 index d10b7ed..0288b79 100644
61787 --- a/include/linux/capability.h
61788 +++ b/include/linux/capability.h
61789 @@ -553,10 +553,15 @@ extern bool capable(int cap);
61790 extern bool ns_capable(struct user_namespace *ns, int cap);
61791 extern bool nsown_capable(int cap);
61792 extern bool inode_capable(const struct inode *inode, int cap);
61793 +extern bool capable_nolog(int cap);
61794 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
61795 +extern bool inode_capable_nolog(const struct inode *inode, int cap);
61796
61797 /* audit system wants to get cap info from files as well */
61798 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
61799
61800 +extern int is_privileged_binary(const struct dentry *dentry);
61801 +
61802 #endif /* __KERNEL__ */
61803
61804 #endif /* !_LINUX_CAPABILITY_H */
61805 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
61806 index 42e55de..1cd0e66 100644
61807 --- a/include/linux/cleancache.h
61808 +++ b/include/linux/cleancache.h
61809 @@ -31,7 +31,7 @@ struct cleancache_ops {
61810 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
61811 void (*invalidate_inode)(int, struct cleancache_filekey);
61812 void (*invalidate_fs)(int);
61813 -};
61814 +} __no_const;
61815
61816 extern struct cleancache_ops
61817 cleancache_register_ops(struct cleancache_ops *ops);
61818 diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
61819 index 77335fa..6cbe7dd 100644
61820 --- a/include/linux/clk-provider.h
61821 +++ b/include/linux/clk-provider.h
61822 @@ -111,6 +111,7 @@ struct clk_ops {
61823 unsigned long);
61824 void (*init)(struct clk_hw *hw);
61825 };
61826 +typedef struct clk_ops __no_const clk_ops_no_const;
61827
61828 /**
61829 * struct clk_init_data - holds init data that's common to all clocks and is
61830 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
61831 index 934bc34..1b47129 100644
61832 --- a/include/linux/compiler-gcc4.h
61833 +++ b/include/linux/compiler-gcc4.h
61834 @@ -32,6 +32,21 @@
61835 #define __linktime_error(message) __attribute__((__error__(message)))
61836
61837 #if __GNUC_MINOR__ >= 5
61838 +
61839 +#ifdef CONSTIFY_PLUGIN
61840 +#define __no_const __attribute__((no_const))
61841 +#define __do_const __attribute__((do_const))
61842 +#endif
61843 +
61844 +#ifdef SIZE_OVERFLOW_PLUGIN
61845 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
61846 +#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
61847 +#endif
61848 +
61849 +#ifdef LATENT_ENTROPY_PLUGIN
61850 +#define __latent_entropy __attribute__((latent_entropy))
61851 +#endif
61852 +
61853 /*
61854 * Mark a position in code as unreachable. This can be used to
61855 * suppress control flow warnings after asm blocks that transfer
61856 @@ -47,6 +62,11 @@
61857 #define __noclone __attribute__((__noclone__))
61858
61859 #endif
61860 +
61861 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
61862 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
61863 +#define __bos0(ptr) __bos((ptr), 0)
61864 +#define __bos1(ptr) __bos((ptr), 1)
61865 #endif
61866
61867 #if __GNUC_MINOR__ >= 6
61868 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
61869 index f430e41..38be90f 100644
61870 --- a/include/linux/compiler.h
61871 +++ b/include/linux/compiler.h
61872 @@ -5,31 +5,62 @@
61873
61874 #ifdef __CHECKER__
61875 # define __user __attribute__((noderef, address_space(1)))
61876 +# define __force_user __force __user
61877 # define __kernel __attribute__((address_space(0)))
61878 +# define __force_kernel __force __kernel
61879 # define __safe __attribute__((safe))
61880 # define __force __attribute__((force))
61881 # define __nocast __attribute__((nocast))
61882 # define __iomem __attribute__((noderef, address_space(2)))
61883 +# define __force_iomem __force __iomem
61884 # define __acquires(x) __attribute__((context(x,0,1)))
61885 # define __releases(x) __attribute__((context(x,1,0)))
61886 # define __acquire(x) __context__(x,1)
61887 # define __release(x) __context__(x,-1)
61888 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
61889 # define __percpu __attribute__((noderef, address_space(3)))
61890 +# define __force_percpu __force __percpu
61891 #ifdef CONFIG_SPARSE_RCU_POINTER
61892 # define __rcu __attribute__((noderef, address_space(4)))
61893 +# define __force_rcu __force __rcu
61894 #else
61895 # define __rcu
61896 +# define __force_rcu
61897 #endif
61898 extern void __chk_user_ptr(const volatile void __user *);
61899 extern void __chk_io_ptr(const volatile void __iomem *);
61900 +#elif defined(CHECKER_PLUGIN)
61901 +//# define __user
61902 +//# define __force_user
61903 +//# define __kernel
61904 +//# define __force_kernel
61905 +# define __safe
61906 +# define __force
61907 +# define __nocast
61908 +# define __iomem
61909 +# define __force_iomem
61910 +# define __chk_user_ptr(x) (void)0
61911 +# define __chk_io_ptr(x) (void)0
61912 +# define __builtin_warning(x, y...) (1)
61913 +# define __acquires(x)
61914 +# define __releases(x)
61915 +# define __acquire(x) (void)0
61916 +# define __release(x) (void)0
61917 +# define __cond_lock(x,c) (c)
61918 +# define __percpu
61919 +# define __force_percpu
61920 +# define __rcu
61921 +# define __force_rcu
61922 #else
61923 # define __user
61924 +# define __force_user
61925 # define __kernel
61926 +# define __force_kernel
61927 # define __safe
61928 # define __force
61929 # define __nocast
61930 # define __iomem
61931 +# define __force_iomem
61932 # define __chk_user_ptr(x) (void)0
61933 # define __chk_io_ptr(x) (void)0
61934 # define __builtin_warning(x, y...) (1)
61935 @@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
61936 # define __release(x) (void)0
61937 # define __cond_lock(x,c) (c)
61938 # define __percpu
61939 +# define __force_percpu
61940 # define __rcu
61941 +# define __force_rcu
61942 #endif
61943
61944 #ifdef __KERNEL__
61945 @@ -264,6 +297,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61946 # define __attribute_const__ /* unimplemented */
61947 #endif
61948
61949 +#ifndef __no_const
61950 +# define __no_const
61951 +#endif
61952 +
61953 +#ifndef __do_const
61954 +# define __do_const
61955 +#endif
61956 +
61957 +#ifndef __size_overflow
61958 +# define __size_overflow(...)
61959 +#endif
61960 +
61961 +#ifndef __intentional_overflow
61962 +# define __intentional_overflow(...)
61963 +#endif
61964 +
61965 +#ifndef __latent_entropy
61966 +# define __latent_entropy
61967 +#endif
61968 +
61969 /*
61970 * Tell gcc if a function is cold. The compiler will assume any path
61971 * directly leading to the call is unlikely.
61972 @@ -273,6 +326,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61973 #define __cold
61974 #endif
61975
61976 +#ifndef __alloc_size
61977 +#define __alloc_size(...)
61978 +#endif
61979 +
61980 +#ifndef __bos
61981 +#define __bos(ptr, arg)
61982 +#endif
61983 +
61984 +#ifndef __bos0
61985 +#define __bos0(ptr)
61986 +#endif
61987 +
61988 +#ifndef __bos1
61989 +#define __bos1(ptr)
61990 +#endif
61991 +
61992 /* Simple shorthand for a section definition */
61993 #ifndef __section
61994 # define __section(S) __attribute__ ((__section__(#S)))
61995 @@ -312,6 +381,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61996 * use is to mediate communication between process-level code and irq/NMI
61997 * handlers, all running on the same CPU.
61998 */
61999 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
62000 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
62001 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
62002
62003 #endif /* __LINUX_COMPILER_H */
62004 diff --git a/include/linux/cred.h b/include/linux/cred.h
62005 index ebbed2c..908cc2c 100644
62006 --- a/include/linux/cred.h
62007 +++ b/include/linux/cred.h
62008 @@ -208,6 +208,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
62009 static inline void validate_process_creds(void)
62010 {
62011 }
62012 +static inline void validate_task_creds(struct task_struct *task)
62013 +{
62014 +}
62015 #endif
62016
62017 /**
62018 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
62019 index b92eadf..b4ecdc1 100644
62020 --- a/include/linux/crypto.h
62021 +++ b/include/linux/crypto.h
62022 @@ -373,7 +373,7 @@ struct cipher_tfm {
62023 const u8 *key, unsigned int keylen);
62024 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
62025 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
62026 -};
62027 +} __no_const;
62028
62029 struct hash_tfm {
62030 int (*init)(struct hash_desc *desc);
62031 @@ -394,13 +394,13 @@ struct compress_tfm {
62032 int (*cot_decompress)(struct crypto_tfm *tfm,
62033 const u8 *src, unsigned int slen,
62034 u8 *dst, unsigned int *dlen);
62035 -};
62036 +} __no_const;
62037
62038 struct rng_tfm {
62039 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
62040 unsigned int dlen);
62041 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
62042 -};
62043 +} __no_const;
62044
62045 #define crt_ablkcipher crt_u.ablkcipher
62046 #define crt_aead crt_u.aead
62047 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
62048 index 7925bf0..d5143d2 100644
62049 --- a/include/linux/decompress/mm.h
62050 +++ b/include/linux/decompress/mm.h
62051 @@ -77,7 +77,7 @@ static void free(void *where)
62052 * warnings when not needed (indeed large_malloc / large_free are not
62053 * needed by inflate */
62054
62055 -#define malloc(a) kmalloc(a, GFP_KERNEL)
62056 +#define malloc(a) kmalloc((a), GFP_KERNEL)
62057 #define free(a) kfree(a)
62058
62059 #define large_malloc(a) vmalloc(a)
62060 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
62061 index 94af418..b1ca7a2 100644
62062 --- a/include/linux/dma-mapping.h
62063 +++ b/include/linux/dma-mapping.h
62064 @@ -54,7 +54,7 @@ struct dma_map_ops {
62065 u64 (*get_required_mask)(struct device *dev);
62066 #endif
62067 int is_phys;
62068 -};
62069 +} __do_const;
62070
62071 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
62072
62073 diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
62074 index 9c02a45..89fdd73 100644
62075 --- a/include/linux/dmaengine.h
62076 +++ b/include/linux/dmaengine.h
62077 @@ -1017,9 +1017,9 @@ struct dma_pinned_list {
62078 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
62079 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
62080
62081 -dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
62082 +dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
62083 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
62084 -dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
62085 +dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
62086 struct dma_pinned_list *pinned_list, struct page *page,
62087 unsigned int offset, size_t len);
62088
62089 diff --git a/include/linux/efi.h b/include/linux/efi.h
62090 index 5782114..e9b1ba1 100644
62091 --- a/include/linux/efi.h
62092 +++ b/include/linux/efi.h
62093 @@ -640,7 +640,7 @@ struct efivar_operations {
62094 efi_get_variable_t *get_variable;
62095 efi_get_next_variable_t *get_next_variable;
62096 efi_set_variable_t *set_variable;
62097 -};
62098 +} __no_const;
62099
62100 struct efivars {
62101 /*
62102 diff --git a/include/linux/elf.h b/include/linux/elf.h
62103 index 999b4f5..57753b4 100644
62104 --- a/include/linux/elf.h
62105 +++ b/include/linux/elf.h
62106 @@ -40,6 +40,17 @@ typedef __s64 Elf64_Sxword;
62107 #define PT_GNU_EH_FRAME 0x6474e550
62108
62109 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
62110 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
62111 +
62112 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
62113 +
62114 +/* Constants for the e_flags field */
62115 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
62116 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
62117 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
62118 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
62119 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
62120 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
62121
62122 /*
62123 * Extended Numbering
62124 @@ -97,6 +108,8 @@ typedef __s64 Elf64_Sxword;
62125 #define DT_DEBUG 21
62126 #define DT_TEXTREL 22
62127 #define DT_JMPREL 23
62128 +#define DT_FLAGS 30
62129 + #define DF_TEXTREL 0x00000004
62130 #define DT_ENCODING 32
62131 #define OLD_DT_LOOS 0x60000000
62132 #define DT_LOOS 0x6000000d
62133 @@ -243,6 +256,19 @@ typedef struct elf64_hdr {
62134 #define PF_W 0x2
62135 #define PF_X 0x1
62136
62137 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
62138 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
62139 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
62140 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
62141 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
62142 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
62143 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
62144 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
62145 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
62146 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
62147 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
62148 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
62149 +
62150 typedef struct elf32_phdr{
62151 Elf32_Word p_type;
62152 Elf32_Off p_offset;
62153 @@ -335,6 +361,8 @@ typedef struct elf64_shdr {
62154 #define EI_OSABI 7
62155 #define EI_PAD 8
62156
62157 +#define EI_PAX 14
62158 +
62159 #define ELFMAG0 0x7f /* EI_MAG */
62160 #define ELFMAG1 'E'
62161 #define ELFMAG2 'L'
62162 @@ -421,6 +449,7 @@ extern Elf32_Dyn _DYNAMIC [];
62163 #define elf_note elf32_note
62164 #define elf_addr_t Elf32_Off
62165 #define Elf_Half Elf32_Half
62166 +#define elf_dyn Elf32_Dyn
62167
62168 #else
62169
62170 @@ -431,6 +460,7 @@ extern Elf64_Dyn _DYNAMIC [];
62171 #define elf_note elf64_note
62172 #define elf_addr_t Elf64_Off
62173 #define Elf_Half Elf64_Half
62174 +#define elf_dyn Elf64_Dyn
62175
62176 #endif
62177
62178 diff --git a/include/linux/filter.h b/include/linux/filter.h
62179 index 82b0135..917914d 100644
62180 --- a/include/linux/filter.h
62181 +++ b/include/linux/filter.h
62182 @@ -146,6 +146,7 @@ struct compat_sock_fprog {
62183
62184 struct sk_buff;
62185 struct sock;
62186 +struct bpf_jit_work;
62187
62188 struct sk_filter
62189 {
62190 @@ -153,6 +154,9 @@ struct sk_filter
62191 unsigned int len; /* Number of filter blocks */
62192 unsigned int (*bpf_func)(const struct sk_buff *skb,
62193 const struct sock_filter *filter);
62194 +#ifdef CONFIG_BPF_JIT
62195 + struct bpf_jit_work *work;
62196 +#endif
62197 struct rcu_head rcu;
62198 struct sock_filter insns[0];
62199 };
62200 diff --git a/include/linux/firewire.h b/include/linux/firewire.h
62201 index db04ec5..f6ed627 100644
62202 --- a/include/linux/firewire.h
62203 +++ b/include/linux/firewire.h
62204 @@ -430,7 +430,7 @@ struct fw_iso_context {
62205 union {
62206 fw_iso_callback_t sc;
62207 fw_iso_mc_callback_t mc;
62208 - } callback;
62209 + } __no_const callback;
62210 void *callback_data;
62211 };
62212
62213 diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
62214 index 0e4e2ee..4ff4312 100644
62215 --- a/include/linux/frontswap.h
62216 +++ b/include/linux/frontswap.h
62217 @@ -11,7 +11,7 @@ struct frontswap_ops {
62218 int (*load)(unsigned, pgoff_t, struct page *);
62219 void (*invalidate_page)(unsigned, pgoff_t);
62220 void (*invalidate_area)(unsigned);
62221 -};
62222 +} __no_const;
62223
62224 extern bool frontswap_enabled;
62225 extern struct frontswap_ops
62226 diff --git a/include/linux/fs.h b/include/linux/fs.h
62227 index aa11047..7d046d0 100644
62228 --- a/include/linux/fs.h
62229 +++ b/include/linux/fs.h
62230 @@ -1802,7 +1802,8 @@ struct file_operations {
62231 int (*setlease)(struct file *, long, struct file_lock **);
62232 long (*fallocate)(struct file *file, int mode, loff_t offset,
62233 loff_t len);
62234 -};
62235 +} __do_const;
62236 +typedef struct file_operations __no_const file_operations_no_const;
62237
62238 struct inode_operations {
62239 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
62240 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
62241 index 003dc0f..3c4ea97 100644
62242 --- a/include/linux/fs_struct.h
62243 +++ b/include/linux/fs_struct.h
62244 @@ -6,7 +6,7 @@
62245 #include <linux/seqlock.h>
62246
62247 struct fs_struct {
62248 - int users;
62249 + atomic_t users;
62250 spinlock_t lock;
62251 seqcount_t seq;
62252 int umask;
62253 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
62254 index ce31408..b1ad003 100644
62255 --- a/include/linux/fscache-cache.h
62256 +++ b/include/linux/fscache-cache.h
62257 @@ -102,7 +102,7 @@ struct fscache_operation {
62258 fscache_operation_release_t release;
62259 };
62260
62261 -extern atomic_t fscache_op_debug_id;
62262 +extern atomic_unchecked_t fscache_op_debug_id;
62263 extern void fscache_op_work_func(struct work_struct *work);
62264
62265 extern void fscache_enqueue_operation(struct fscache_operation *);
62266 @@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
62267 {
62268 INIT_WORK(&op->work, fscache_op_work_func);
62269 atomic_set(&op->usage, 1);
62270 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
62271 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
62272 op->processor = processor;
62273 op->release = release;
62274 INIT_LIST_HEAD(&op->pend_link);
62275 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
62276 index a6dfe69..569586df 100644
62277 --- a/include/linux/fsnotify.h
62278 +++ b/include/linux/fsnotify.h
62279 @@ -315,7 +315,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
62280 */
62281 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
62282 {
62283 - return kstrdup(name, GFP_KERNEL);
62284 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
62285 }
62286
62287 /*
62288 diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
62289 index 63d966d..cdcb717 100644
62290 --- a/include/linux/fsnotify_backend.h
62291 +++ b/include/linux/fsnotify_backend.h
62292 @@ -105,6 +105,7 @@ struct fsnotify_ops {
62293 void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group);
62294 void (*free_event_priv)(struct fsnotify_event_private_data *priv);
62295 };
62296 +typedef struct fsnotify_ops __no_const fsnotify_ops_no_const;
62297
62298 /*
62299 * A group is a "thing" that wants to receive notification about filesystem
62300 diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
62301 index 642928c..e6c83a7 100644
62302 --- a/include/linux/ftrace_event.h
62303 +++ b/include/linux/ftrace_event.h
62304 @@ -97,7 +97,7 @@ struct trace_event_functions {
62305 trace_print_func raw;
62306 trace_print_func hex;
62307 trace_print_func binary;
62308 -};
62309 +} __no_const;
62310
62311 struct trace_event {
62312 struct hlist_node node;
62313 @@ -266,7 +266,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
62314 extern int trace_add_event_call(struct ftrace_event_call *call);
62315 extern void trace_remove_event_call(struct ftrace_event_call *call);
62316
62317 -#define is_signed_type(type) (((type)(-1)) < 0)
62318 +#define is_signed_type(type) (((type)(-1)) < (type)1)
62319
62320 int trace_set_clr_event(const char *system, const char *event, int set);
62321
62322 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
62323 index 4f440b3..342233a 100644
62324 --- a/include/linux/genhd.h
62325 +++ b/include/linux/genhd.h
62326 @@ -190,7 +190,7 @@ struct gendisk {
62327 struct kobject *slave_dir;
62328
62329 struct timer_rand_state *random;
62330 - atomic_t sync_io; /* RAID */
62331 + atomic_unchecked_t sync_io; /* RAID */
62332 struct disk_events *ev;
62333 #ifdef CONFIG_BLK_DEV_INTEGRITY
62334 struct blk_integrity *integrity;
62335 diff --git a/include/linux/gfp.h b/include/linux/gfp.h
62336 index 4883f39..26688a8 100644
62337 --- a/include/linux/gfp.h
62338 +++ b/include/linux/gfp.h
62339 @@ -39,6 +39,12 @@ struct vm_area_struct;
62340 #define ___GFP_OTHER_NODE 0x800000u
62341 #define ___GFP_WRITE 0x1000000u
62342
62343 +#ifdef CONFIG_PAX_USERCOPY_SLABS
62344 +#define ___GFP_USERCOPY 0x2000000u
62345 +#else
62346 +#define ___GFP_USERCOPY 0
62347 +#endif
62348 +
62349 /*
62350 * GFP bitmasks..
62351 *
62352 @@ -93,6 +99,7 @@ struct vm_area_struct;
62353 #define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD)
62354 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
62355 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
62356 +#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
62357
62358 /*
62359 * This may seem redundant, but it's a way of annotating false positives vs.
62360 @@ -100,7 +107,7 @@ struct vm_area_struct;
62361 */
62362 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
62363
62364 -#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
62365 +#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
62366 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
62367
62368 /* This equals 0, but use constants in case they ever change */
62369 @@ -154,6 +161,8 @@ struct vm_area_struct;
62370 /* 4GB DMA on some platforms */
62371 #define GFP_DMA32 __GFP_DMA32
62372
62373 +#define GFP_USERCOPY __GFP_USERCOPY
62374 +
62375 /* Convert GFP flags to their corresponding migrate type */
62376 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
62377 {
62378 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
62379 new file mode 100644
62380 index 0000000..c938b1f
62381 --- /dev/null
62382 +++ b/include/linux/gracl.h
62383 @@ -0,0 +1,319 @@
62384 +#ifndef GR_ACL_H
62385 +#define GR_ACL_H
62386 +
62387 +#include <linux/grdefs.h>
62388 +#include <linux/resource.h>
62389 +#include <linux/capability.h>
62390 +#include <linux/dcache.h>
62391 +#include <asm/resource.h>
62392 +
62393 +/* Major status information */
62394 +
62395 +#define GR_VERSION "grsecurity 2.9.1"
62396 +#define GRSECURITY_VERSION 0x2901
62397 +
62398 +enum {
62399 + GR_SHUTDOWN = 0,
62400 + GR_ENABLE = 1,
62401 + GR_SPROLE = 2,
62402 + GR_RELOAD = 3,
62403 + GR_SEGVMOD = 4,
62404 + GR_STATUS = 5,
62405 + GR_UNSPROLE = 6,
62406 + GR_PASSSET = 7,
62407 + GR_SPROLEPAM = 8,
62408 +};
62409 +
62410 +/* Password setup definitions
62411 + * kernel/grhash.c */
62412 +enum {
62413 + GR_PW_LEN = 128,
62414 + GR_SALT_LEN = 16,
62415 + GR_SHA_LEN = 32,
62416 +};
62417 +
62418 +enum {
62419 + GR_SPROLE_LEN = 64,
62420 +};
62421 +
62422 +enum {
62423 + GR_NO_GLOB = 0,
62424 + GR_REG_GLOB,
62425 + GR_CREATE_GLOB
62426 +};
62427 +
62428 +#define GR_NLIMITS 32
62429 +
62430 +/* Begin Data Structures */
62431 +
62432 +struct sprole_pw {
62433 + unsigned char *rolename;
62434 + unsigned char salt[GR_SALT_LEN];
62435 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
62436 +};
62437 +
62438 +struct name_entry {
62439 + __u32 key;
62440 + ino_t inode;
62441 + dev_t device;
62442 + char *name;
62443 + __u16 len;
62444 + __u8 deleted;
62445 + struct name_entry *prev;
62446 + struct name_entry *next;
62447 +};
62448 +
62449 +struct inodev_entry {
62450 + struct name_entry *nentry;
62451 + struct inodev_entry *prev;
62452 + struct inodev_entry *next;
62453 +};
62454 +
62455 +struct acl_role_db {
62456 + struct acl_role_label **r_hash;
62457 + __u32 r_size;
62458 +};
62459 +
62460 +struct inodev_db {
62461 + struct inodev_entry **i_hash;
62462 + __u32 i_size;
62463 +};
62464 +
62465 +struct name_db {
62466 + struct name_entry **n_hash;
62467 + __u32 n_size;
62468 +};
62469 +
62470 +struct crash_uid {
62471 + uid_t uid;
62472 + unsigned long expires;
62473 +};
62474 +
62475 +struct gr_hash_struct {
62476 + void **table;
62477 + void **nametable;
62478 + void *first;
62479 + __u32 table_size;
62480 + __u32 used_size;
62481 + int type;
62482 +};
62483 +
62484 +/* Userspace Grsecurity ACL data structures */
62485 +
62486 +struct acl_subject_label {
62487 + char *filename;
62488 + ino_t inode;
62489 + dev_t device;
62490 + __u32 mode;
62491 + kernel_cap_t cap_mask;
62492 + kernel_cap_t cap_lower;
62493 + kernel_cap_t cap_invert_audit;
62494 +
62495 + struct rlimit res[GR_NLIMITS];
62496 + __u32 resmask;
62497 +
62498 + __u8 user_trans_type;
62499 + __u8 group_trans_type;
62500 + uid_t *user_transitions;
62501 + gid_t *group_transitions;
62502 + __u16 user_trans_num;
62503 + __u16 group_trans_num;
62504 +
62505 + __u32 sock_families[2];
62506 + __u32 ip_proto[8];
62507 + __u32 ip_type;
62508 + struct acl_ip_label **ips;
62509 + __u32 ip_num;
62510 + __u32 inaddr_any_override;
62511 +
62512 + __u32 crashes;
62513 + unsigned long expires;
62514 +
62515 + struct acl_subject_label *parent_subject;
62516 + struct gr_hash_struct *hash;
62517 + struct acl_subject_label *prev;
62518 + struct acl_subject_label *next;
62519 +
62520 + struct acl_object_label **obj_hash;
62521 + __u32 obj_hash_size;
62522 + __u16 pax_flags;
62523 +};
62524 +
62525 +struct role_allowed_ip {
62526 + __u32 addr;
62527 + __u32 netmask;
62528 +
62529 + struct role_allowed_ip *prev;
62530 + struct role_allowed_ip *next;
62531 +};
62532 +
62533 +struct role_transition {
62534 + char *rolename;
62535 +
62536 + struct role_transition *prev;
62537 + struct role_transition *next;
62538 +};
62539 +
62540 +struct acl_role_label {
62541 + char *rolename;
62542 + uid_t uidgid;
62543 + __u16 roletype;
62544 +
62545 + __u16 auth_attempts;
62546 + unsigned long expires;
62547 +
62548 + struct acl_subject_label *root_label;
62549 + struct gr_hash_struct *hash;
62550 +
62551 + struct acl_role_label *prev;
62552 + struct acl_role_label *next;
62553 +
62554 + struct role_transition *transitions;
62555 + struct role_allowed_ip *allowed_ips;
62556 + uid_t *domain_children;
62557 + __u16 domain_child_num;
62558 +
62559 + umode_t umask;
62560 +
62561 + struct acl_subject_label **subj_hash;
62562 + __u32 subj_hash_size;
62563 +};
62564 +
62565 +struct user_acl_role_db {
62566 + struct acl_role_label **r_table;
62567 + __u32 num_pointers; /* Number of allocations to track */
62568 + __u32 num_roles; /* Number of roles */
62569 + __u32 num_domain_children; /* Number of domain children */
62570 + __u32 num_subjects; /* Number of subjects */
62571 + __u32 num_objects; /* Number of objects */
62572 +};
62573 +
62574 +struct acl_object_label {
62575 + char *filename;
62576 + ino_t inode;
62577 + dev_t device;
62578 + __u32 mode;
62579 +
62580 + struct acl_subject_label *nested;
62581 + struct acl_object_label *globbed;
62582 +
62583 + /* next two structures not used */
62584 +
62585 + struct acl_object_label *prev;
62586 + struct acl_object_label *next;
62587 +};
62588 +
62589 +struct acl_ip_label {
62590 + char *iface;
62591 + __u32 addr;
62592 + __u32 netmask;
62593 + __u16 low, high;
62594 + __u8 mode;
62595 + __u32 type;
62596 + __u32 proto[8];
62597 +
62598 + /* next two structures not used */
62599 +
62600 + struct acl_ip_label *prev;
62601 + struct acl_ip_label *next;
62602 +};
62603 +
62604 +struct gr_arg {
62605 + struct user_acl_role_db role_db;
62606 + unsigned char pw[GR_PW_LEN];
62607 + unsigned char salt[GR_SALT_LEN];
62608 + unsigned char sum[GR_SHA_LEN];
62609 + unsigned char sp_role[GR_SPROLE_LEN];
62610 + struct sprole_pw *sprole_pws;
62611 + dev_t segv_device;
62612 + ino_t segv_inode;
62613 + uid_t segv_uid;
62614 + __u16 num_sprole_pws;
62615 + __u16 mode;
62616 +};
62617 +
62618 +struct gr_arg_wrapper {
62619 + struct gr_arg *arg;
62620 + __u32 version;
62621 + __u32 size;
62622 +};
62623 +
62624 +struct subject_map {
62625 + struct acl_subject_label *user;
62626 + struct acl_subject_label *kernel;
62627 + struct subject_map *prev;
62628 + struct subject_map *next;
62629 +};
62630 +
62631 +struct acl_subj_map_db {
62632 + struct subject_map **s_hash;
62633 + __u32 s_size;
62634 +};
62635 +
62636 +/* End Data Structures Section */
62637 +
62638 +/* Hash functions generated by empirical testing by Brad Spengler
62639 + Makes good use of the low bits of the inode. Generally 0-1 times
62640 + in loop for successful match. 0-3 for unsuccessful match.
62641 + Shift/add algorithm with modulus of table size and an XOR*/
62642 +
62643 +static __inline__ unsigned int
62644 +rhash(const uid_t uid, const __u16 type, const unsigned int sz)
62645 +{
62646 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
62647 +}
62648 +
62649 + static __inline__ unsigned int
62650 +shash(const struct acl_subject_label *userp, const unsigned int sz)
62651 +{
62652 + return ((const unsigned long)userp % sz);
62653 +}
62654 +
62655 +static __inline__ unsigned int
62656 +fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
62657 +{
62658 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
62659 +}
62660 +
62661 +static __inline__ unsigned int
62662 +nhash(const char *name, const __u16 len, const unsigned int sz)
62663 +{
62664 + return full_name_hash((const unsigned char *)name, len) % sz;
62665 +}
62666 +
62667 +#define FOR_EACH_ROLE_START(role) \
62668 + role = role_list; \
62669 + while (role) {
62670 +
62671 +#define FOR_EACH_ROLE_END(role) \
62672 + role = role->prev; \
62673 + }
62674 +
62675 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
62676 + subj = NULL; \
62677 + iter = 0; \
62678 + while (iter < role->subj_hash_size) { \
62679 + if (subj == NULL) \
62680 + subj = role->subj_hash[iter]; \
62681 + if (subj == NULL) { \
62682 + iter++; \
62683 + continue; \
62684 + }
62685 +
62686 +#define FOR_EACH_SUBJECT_END(subj,iter) \
62687 + subj = subj->next; \
62688 + if (subj == NULL) \
62689 + iter++; \
62690 + }
62691 +
62692 +
62693 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
62694 + subj = role->hash->first; \
62695 + while (subj != NULL) {
62696 +
62697 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
62698 + subj = subj->next; \
62699 + }
62700 +
62701 +#endif
62702 +
62703 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
62704 new file mode 100644
62705 index 0000000..323ecf2
62706 --- /dev/null
62707 +++ b/include/linux/gralloc.h
62708 @@ -0,0 +1,9 @@
62709 +#ifndef __GRALLOC_H
62710 +#define __GRALLOC_H
62711 +
62712 +void acl_free_all(void);
62713 +int acl_alloc_stack_init(unsigned long size);
62714 +void *acl_alloc(unsigned long len);
62715 +void *acl_alloc_num(unsigned long num, unsigned long len);
62716 +
62717 +#endif
62718 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
62719 new file mode 100644
62720 index 0000000..b30e9bc
62721 --- /dev/null
62722 +++ b/include/linux/grdefs.h
62723 @@ -0,0 +1,140 @@
62724 +#ifndef GRDEFS_H
62725 +#define GRDEFS_H
62726 +
62727 +/* Begin grsecurity status declarations */
62728 +
62729 +enum {
62730 + GR_READY = 0x01,
62731 + GR_STATUS_INIT = 0x00 // disabled state
62732 +};
62733 +
62734 +/* Begin ACL declarations */
62735 +
62736 +/* Role flags */
62737 +
62738 +enum {
62739 + GR_ROLE_USER = 0x0001,
62740 + GR_ROLE_GROUP = 0x0002,
62741 + GR_ROLE_DEFAULT = 0x0004,
62742 + GR_ROLE_SPECIAL = 0x0008,
62743 + GR_ROLE_AUTH = 0x0010,
62744 + GR_ROLE_NOPW = 0x0020,
62745 + GR_ROLE_GOD = 0x0040,
62746 + GR_ROLE_LEARN = 0x0080,
62747 + GR_ROLE_TPE = 0x0100,
62748 + GR_ROLE_DOMAIN = 0x0200,
62749 + GR_ROLE_PAM = 0x0400,
62750 + GR_ROLE_PERSIST = 0x0800
62751 +};
62752 +
62753 +/* ACL Subject and Object mode flags */
62754 +enum {
62755 + GR_DELETED = 0x80000000
62756 +};
62757 +
62758 +/* ACL Object-only mode flags */
62759 +enum {
62760 + GR_READ = 0x00000001,
62761 + GR_APPEND = 0x00000002,
62762 + GR_WRITE = 0x00000004,
62763 + GR_EXEC = 0x00000008,
62764 + GR_FIND = 0x00000010,
62765 + GR_INHERIT = 0x00000020,
62766 + GR_SETID = 0x00000040,
62767 + GR_CREATE = 0x00000080,
62768 + GR_DELETE = 0x00000100,
62769 + GR_LINK = 0x00000200,
62770 + GR_AUDIT_READ = 0x00000400,
62771 + GR_AUDIT_APPEND = 0x00000800,
62772 + GR_AUDIT_WRITE = 0x00001000,
62773 + GR_AUDIT_EXEC = 0x00002000,
62774 + GR_AUDIT_FIND = 0x00004000,
62775 + GR_AUDIT_INHERIT= 0x00008000,
62776 + GR_AUDIT_SETID = 0x00010000,
62777 + GR_AUDIT_CREATE = 0x00020000,
62778 + GR_AUDIT_DELETE = 0x00040000,
62779 + GR_AUDIT_LINK = 0x00080000,
62780 + GR_PTRACERD = 0x00100000,
62781 + GR_NOPTRACE = 0x00200000,
62782 + GR_SUPPRESS = 0x00400000,
62783 + GR_NOLEARN = 0x00800000,
62784 + GR_INIT_TRANSFER= 0x01000000
62785 +};
62786 +
62787 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
62788 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
62789 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
62790 +
62791 +/* ACL subject-only mode flags */
62792 +enum {
62793 + GR_KILL = 0x00000001,
62794 + GR_VIEW = 0x00000002,
62795 + GR_PROTECTED = 0x00000004,
62796 + GR_LEARN = 0x00000008,
62797 + GR_OVERRIDE = 0x00000010,
62798 + /* just a placeholder, this mode is only used in userspace */
62799 + GR_DUMMY = 0x00000020,
62800 + GR_PROTSHM = 0x00000040,
62801 + GR_KILLPROC = 0x00000080,
62802 + GR_KILLIPPROC = 0x00000100,
62803 + /* just a placeholder, this mode is only used in userspace */
62804 + GR_NOTROJAN = 0x00000200,
62805 + GR_PROTPROCFD = 0x00000400,
62806 + GR_PROCACCT = 0x00000800,
62807 + GR_RELAXPTRACE = 0x00001000,
62808 + GR_NESTED = 0x00002000,
62809 + GR_INHERITLEARN = 0x00004000,
62810 + GR_PROCFIND = 0x00008000,
62811 + GR_POVERRIDE = 0x00010000,
62812 + GR_KERNELAUTH = 0x00020000,
62813 + GR_ATSECURE = 0x00040000,
62814 + GR_SHMEXEC = 0x00080000
62815 +};
62816 +
62817 +enum {
62818 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
62819 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
62820 + GR_PAX_ENABLE_MPROTECT = 0x0004,
62821 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
62822 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
62823 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
62824 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
62825 + GR_PAX_DISABLE_MPROTECT = 0x0400,
62826 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
62827 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
62828 +};
62829 +
62830 +enum {
62831 + GR_ID_USER = 0x01,
62832 + GR_ID_GROUP = 0x02,
62833 +};
62834 +
62835 +enum {
62836 + GR_ID_ALLOW = 0x01,
62837 + GR_ID_DENY = 0x02,
62838 +};
62839 +
62840 +#define GR_CRASH_RES 31
62841 +#define GR_UIDTABLE_MAX 500
62842 +
62843 +/* begin resource learning section */
62844 +enum {
62845 + GR_RLIM_CPU_BUMP = 60,
62846 + GR_RLIM_FSIZE_BUMP = 50000,
62847 + GR_RLIM_DATA_BUMP = 10000,
62848 + GR_RLIM_STACK_BUMP = 1000,
62849 + GR_RLIM_CORE_BUMP = 10000,
62850 + GR_RLIM_RSS_BUMP = 500000,
62851 + GR_RLIM_NPROC_BUMP = 1,
62852 + GR_RLIM_NOFILE_BUMP = 5,
62853 + GR_RLIM_MEMLOCK_BUMP = 50000,
62854 + GR_RLIM_AS_BUMP = 500000,
62855 + GR_RLIM_LOCKS_BUMP = 2,
62856 + GR_RLIM_SIGPENDING_BUMP = 5,
62857 + GR_RLIM_MSGQUEUE_BUMP = 10000,
62858 + GR_RLIM_NICE_BUMP = 1,
62859 + GR_RLIM_RTPRIO_BUMP = 1,
62860 + GR_RLIM_RTTIME_BUMP = 1000000
62861 +};
62862 +
62863 +#endif
62864 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
62865 new file mode 100644
62866 index 0000000..c9292f7
62867 --- /dev/null
62868 +++ b/include/linux/grinternal.h
62869 @@ -0,0 +1,223 @@
62870 +#ifndef __GRINTERNAL_H
62871 +#define __GRINTERNAL_H
62872 +
62873 +#ifdef CONFIG_GRKERNSEC
62874 +
62875 +#include <linux/fs.h>
62876 +#include <linux/mnt_namespace.h>
62877 +#include <linux/nsproxy.h>
62878 +#include <linux/gracl.h>
62879 +#include <linux/grdefs.h>
62880 +#include <linux/grmsg.h>
62881 +
62882 +void gr_add_learn_entry(const char *fmt, ...)
62883 + __attribute__ ((format (printf, 1, 2)));
62884 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
62885 + const struct vfsmount *mnt);
62886 +__u32 gr_check_create(const struct dentry *new_dentry,
62887 + const struct dentry *parent,
62888 + const struct vfsmount *mnt, const __u32 mode);
62889 +int gr_check_protected_task(const struct task_struct *task);
62890 +__u32 to_gr_audit(const __u32 reqmode);
62891 +int gr_set_acls(const int type);
62892 +int gr_apply_subject_to_task(struct task_struct *task);
62893 +int gr_acl_is_enabled(void);
62894 +char gr_roletype_to_char(void);
62895 +
62896 +void gr_handle_alertkill(struct task_struct *task);
62897 +char *gr_to_filename(const struct dentry *dentry,
62898 + const struct vfsmount *mnt);
62899 +char *gr_to_filename1(const struct dentry *dentry,
62900 + const struct vfsmount *mnt);
62901 +char *gr_to_filename2(const struct dentry *dentry,
62902 + const struct vfsmount *mnt);
62903 +char *gr_to_filename3(const struct dentry *dentry,
62904 + const struct vfsmount *mnt);
62905 +
62906 +extern int grsec_enable_ptrace_readexec;
62907 +extern int grsec_enable_harden_ptrace;
62908 +extern int grsec_enable_link;
62909 +extern int grsec_enable_fifo;
62910 +extern int grsec_enable_execve;
62911 +extern int grsec_enable_shm;
62912 +extern int grsec_enable_execlog;
62913 +extern int grsec_enable_signal;
62914 +extern int grsec_enable_audit_ptrace;
62915 +extern int grsec_enable_forkfail;
62916 +extern int grsec_enable_time;
62917 +extern int grsec_enable_rofs;
62918 +extern int grsec_enable_chroot_shmat;
62919 +extern int grsec_enable_chroot_mount;
62920 +extern int grsec_enable_chroot_double;
62921 +extern int grsec_enable_chroot_pivot;
62922 +extern int grsec_enable_chroot_chdir;
62923 +extern int grsec_enable_chroot_chmod;
62924 +extern int grsec_enable_chroot_mknod;
62925 +extern int grsec_enable_chroot_fchdir;
62926 +extern int grsec_enable_chroot_nice;
62927 +extern int grsec_enable_chroot_execlog;
62928 +extern int grsec_enable_chroot_caps;
62929 +extern int grsec_enable_chroot_sysctl;
62930 +extern int grsec_enable_chroot_unix;
62931 +extern int grsec_enable_symlinkown;
62932 +extern int grsec_symlinkown_gid;
62933 +extern int grsec_enable_tpe;
62934 +extern int grsec_tpe_gid;
62935 +extern int grsec_enable_tpe_all;
62936 +extern int grsec_enable_tpe_invert;
62937 +extern int grsec_enable_socket_all;
62938 +extern int grsec_socket_all_gid;
62939 +extern int grsec_enable_socket_client;
62940 +extern int grsec_socket_client_gid;
62941 +extern int grsec_enable_socket_server;
62942 +extern int grsec_socket_server_gid;
62943 +extern int grsec_audit_gid;
62944 +extern int grsec_enable_group;
62945 +extern int grsec_enable_audit_textrel;
62946 +extern int grsec_enable_log_rwxmaps;
62947 +extern int grsec_enable_mount;
62948 +extern int grsec_enable_chdir;
62949 +extern int grsec_resource_logging;
62950 +extern int grsec_enable_blackhole;
62951 +extern int grsec_lastack_retries;
62952 +extern int grsec_enable_brute;
62953 +extern int grsec_lock;
62954 +
62955 +extern spinlock_t grsec_alert_lock;
62956 +extern unsigned long grsec_alert_wtime;
62957 +extern unsigned long grsec_alert_fyet;
62958 +
62959 +extern spinlock_t grsec_audit_lock;
62960 +
62961 +extern rwlock_t grsec_exec_file_lock;
62962 +
62963 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
62964 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
62965 + (tsk)->exec_file->f_vfsmnt) : "/")
62966 +
62967 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
62968 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
62969 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
62970 +
62971 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
62972 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
62973 + (tsk)->exec_file->f_vfsmnt) : "/")
62974 +
62975 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
62976 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
62977 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
62978 +
62979 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
62980 +
62981 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
62982 +
62983 +#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
62984 + (task)->pid, (cred)->uid, \
62985 + (cred)->euid, (cred)->gid, (cred)->egid, \
62986 + gr_parent_task_fullpath(task), \
62987 + (task)->real_parent->comm, (task)->real_parent->pid, \
62988 + (pcred)->uid, (pcred)->euid, \
62989 + (pcred)->gid, (pcred)->egid
62990 +
62991 +#define GR_CHROOT_CAPS {{ \
62992 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
62993 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
62994 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
62995 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
62996 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
62997 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
62998 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
62999 +
63000 +#define security_learn(normal_msg,args...) \
63001 +({ \
63002 + read_lock(&grsec_exec_file_lock); \
63003 + gr_add_learn_entry(normal_msg "\n", ## args); \
63004 + read_unlock(&grsec_exec_file_lock); \
63005 +})
63006 +
63007 +enum {
63008 + GR_DO_AUDIT,
63009 + GR_DONT_AUDIT,
63010 + /* used for non-audit messages that we shouldn't kill the task on */
63011 + GR_DONT_AUDIT_GOOD
63012 +};
63013 +
63014 +enum {
63015 + GR_TTYSNIFF,
63016 + GR_RBAC,
63017 + GR_RBAC_STR,
63018 + GR_STR_RBAC,
63019 + GR_RBAC_MODE2,
63020 + GR_RBAC_MODE3,
63021 + GR_FILENAME,
63022 + GR_SYSCTL_HIDDEN,
63023 + GR_NOARGS,
63024 + GR_ONE_INT,
63025 + GR_ONE_INT_TWO_STR,
63026 + GR_ONE_STR,
63027 + GR_STR_INT,
63028 + GR_TWO_STR_INT,
63029 + GR_TWO_INT,
63030 + GR_TWO_U64,
63031 + GR_THREE_INT,
63032 + GR_FIVE_INT_TWO_STR,
63033 + GR_TWO_STR,
63034 + GR_THREE_STR,
63035 + GR_FOUR_STR,
63036 + GR_STR_FILENAME,
63037 + GR_FILENAME_STR,
63038 + GR_FILENAME_TWO_INT,
63039 + GR_FILENAME_TWO_INT_STR,
63040 + GR_TEXTREL,
63041 + GR_PTRACE,
63042 + GR_RESOURCE,
63043 + GR_CAP,
63044 + GR_SIG,
63045 + GR_SIG2,
63046 + GR_CRASH1,
63047 + GR_CRASH2,
63048 + GR_PSACCT,
63049 + GR_RWXMAP
63050 +};
63051 +
63052 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
63053 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
63054 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
63055 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
63056 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
63057 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
63058 +#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)
63059 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
63060 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
63061 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
63062 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
63063 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
63064 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
63065 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
63066 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
63067 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
63068 +#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)
63069 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
63070 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
63071 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
63072 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
63073 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
63074 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
63075 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
63076 +#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)
63077 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
63078 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
63079 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
63080 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
63081 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
63082 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
63083 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
63084 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
63085 +#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)
63086 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
63087 +
63088 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
63089 +
63090 +#endif
63091 +
63092 +#endif
63093 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
63094 new file mode 100644
63095 index 0000000..54f4e85
63096 --- /dev/null
63097 +++ b/include/linux/grmsg.h
63098 @@ -0,0 +1,110 @@
63099 +#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"
63100 +#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"
63101 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
63102 +#define GR_STOPMOD_MSG "denied modification of module state by "
63103 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
63104 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
63105 +#define GR_IOPERM_MSG "denied use of ioperm() by "
63106 +#define GR_IOPL_MSG "denied use of iopl() by "
63107 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
63108 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
63109 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
63110 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
63111 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
63112 +#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"
63113 +#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"
63114 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
63115 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
63116 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
63117 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
63118 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
63119 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
63120 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
63121 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
63122 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
63123 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
63124 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
63125 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
63126 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
63127 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
63128 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
63129 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
63130 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
63131 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
63132 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
63133 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
63134 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
63135 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
63136 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
63137 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
63138 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
63139 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
63140 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
63141 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
63142 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
63143 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
63144 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
63145 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
63146 +#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
63147 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
63148 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
63149 +#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"
63150 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
63151 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
63152 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
63153 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
63154 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
63155 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
63156 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
63157 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
63158 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
63159 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
63160 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
63161 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
63162 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
63163 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
63164 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
63165 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
63166 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
63167 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
63168 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
63169 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
63170 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
63171 +#define GR_NICE_CHROOT_MSG "denied priority change by "
63172 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
63173 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
63174 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
63175 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
63176 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
63177 +#define GR_TIME_MSG "time set by "
63178 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
63179 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
63180 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
63181 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
63182 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
63183 +#define GR_BIND_MSG "denied bind() by "
63184 +#define GR_CONNECT_MSG "denied connect() by "
63185 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
63186 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
63187 +#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"
63188 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
63189 +#define GR_CAP_ACL_MSG "use of %s denied for "
63190 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
63191 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
63192 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
63193 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
63194 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
63195 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
63196 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
63197 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
63198 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
63199 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
63200 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
63201 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
63202 +#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
63203 +#define GR_VM86_MSG "denied use of vm86 by "
63204 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
63205 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
63206 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
63207 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
63208 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
63209 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
63210 new file mode 100644
63211 index 0000000..187b3ed
63212 --- /dev/null
63213 +++ b/include/linux/grsecurity.h
63214 @@ -0,0 +1,239 @@
63215 +#ifndef GR_SECURITY_H
63216 +#define GR_SECURITY_H
63217 +#include <linux/fs.h>
63218 +#include <linux/fs_struct.h>
63219 +#include <linux/binfmts.h>
63220 +#include <linux/gracl.h>
63221 +
63222 +/* notify of brain-dead configs */
63223 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63224 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
63225 +#endif
63226 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
63227 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
63228 +#endif
63229 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
63230 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
63231 +#endif
63232 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
63233 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
63234 +#endif
63235 +
63236 +#include <linux/compat.h>
63237 +
63238 +struct user_arg_ptr {
63239 +#ifdef CONFIG_COMPAT
63240 + bool is_compat;
63241 +#endif
63242 + union {
63243 + const char __user *const __user *native;
63244 +#ifdef CONFIG_COMPAT
63245 + compat_uptr_t __user *compat;
63246 +#endif
63247 + } ptr;
63248 +};
63249 +
63250 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
63251 +void gr_handle_brute_check(void);
63252 +void gr_handle_kernel_exploit(void);
63253 +int gr_process_user_ban(void);
63254 +
63255 +char gr_roletype_to_char(void);
63256 +
63257 +int gr_acl_enable_at_secure(void);
63258 +
63259 +int gr_check_user_change(int real, int effective, int fs);
63260 +int gr_check_group_change(int real, int effective, int fs);
63261 +
63262 +void gr_del_task_from_ip_table(struct task_struct *p);
63263 +
63264 +int gr_pid_is_chrooted(struct task_struct *p);
63265 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
63266 +int gr_handle_chroot_nice(void);
63267 +int gr_handle_chroot_sysctl(const int op);
63268 +int gr_handle_chroot_setpriority(struct task_struct *p,
63269 + const int niceval);
63270 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
63271 +int gr_handle_chroot_chroot(const struct dentry *dentry,
63272 + const struct vfsmount *mnt);
63273 +void gr_handle_chroot_chdir(struct path *path);
63274 +int gr_handle_chroot_chmod(const struct dentry *dentry,
63275 + const struct vfsmount *mnt, const int mode);
63276 +int gr_handle_chroot_mknod(const struct dentry *dentry,
63277 + const struct vfsmount *mnt, const int mode);
63278 +int gr_handle_chroot_mount(const struct dentry *dentry,
63279 + const struct vfsmount *mnt,
63280 + const char *dev_name);
63281 +int gr_handle_chroot_pivot(void);
63282 +int gr_handle_chroot_unix(const pid_t pid);
63283 +
63284 +int gr_handle_rawio(const struct inode *inode);
63285 +
63286 +void gr_handle_ioperm(void);
63287 +void gr_handle_iopl(void);
63288 +
63289 +umode_t gr_acl_umask(void);
63290 +
63291 +int gr_tpe_allow(const struct file *file);
63292 +
63293 +void gr_set_chroot_entries(struct task_struct *task, struct path *path);
63294 +void gr_clear_chroot_entries(struct task_struct *task);
63295 +
63296 +void gr_log_forkfail(const int retval);
63297 +void gr_log_timechange(void);
63298 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
63299 +void gr_log_chdir(const struct dentry *dentry,
63300 + const struct vfsmount *mnt);
63301 +void gr_log_chroot_exec(const struct dentry *dentry,
63302 + const struct vfsmount *mnt);
63303 +void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
63304 +void gr_log_remount(const char *devname, const int retval);
63305 +void gr_log_unmount(const char *devname, const int retval);
63306 +void gr_log_mount(const char *from, const char *to, const int retval);
63307 +void gr_log_textrel(struct vm_area_struct *vma);
63308 +void gr_log_rwxmmap(struct file *file);
63309 +void gr_log_rwxmprotect(struct file *file);
63310 +
63311 +int gr_handle_follow_link(const struct inode *parent,
63312 + const struct inode *inode,
63313 + const struct dentry *dentry,
63314 + const struct vfsmount *mnt);
63315 +int gr_handle_fifo(const struct dentry *dentry,
63316 + const struct vfsmount *mnt,
63317 + const struct dentry *dir, const int flag,
63318 + const int acc_mode);
63319 +int gr_handle_hardlink(const struct dentry *dentry,
63320 + const struct vfsmount *mnt,
63321 + struct inode *inode,
63322 + const int mode, const char *to);
63323 +
63324 +int gr_is_capable(const int cap);
63325 +int gr_is_capable_nolog(const int cap);
63326 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
63327 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
63328 +
63329 +void gr_learn_resource(const struct task_struct *task, const int limit,
63330 + const unsigned long wanted, const int gt);
63331 +void gr_copy_label(struct task_struct *tsk);
63332 +void gr_handle_crash(struct task_struct *task, const int sig);
63333 +int gr_handle_signal(const struct task_struct *p, const int sig);
63334 +int gr_check_crash_uid(const uid_t uid);
63335 +int gr_check_protected_task(const struct task_struct *task);
63336 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
63337 +int gr_acl_handle_mmap(const struct file *file,
63338 + const unsigned long prot);
63339 +int gr_acl_handle_mprotect(const struct file *file,
63340 + const unsigned long prot);
63341 +int gr_check_hidden_task(const struct task_struct *tsk);
63342 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
63343 + const struct vfsmount *mnt);
63344 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
63345 + const struct vfsmount *mnt);
63346 +__u32 gr_acl_handle_access(const struct dentry *dentry,
63347 + const struct vfsmount *mnt, const int fmode);
63348 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
63349 + const struct vfsmount *mnt, umode_t *mode);
63350 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
63351 + const struct vfsmount *mnt);
63352 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
63353 + const struct vfsmount *mnt);
63354 +int gr_handle_ptrace(struct task_struct *task, const long request);
63355 +int gr_handle_proc_ptrace(struct task_struct *task);
63356 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
63357 + const struct vfsmount *mnt);
63358 +int gr_check_crash_exec(const struct file *filp);
63359 +int gr_acl_is_enabled(void);
63360 +void gr_set_kernel_label(struct task_struct *task);
63361 +void gr_set_role_label(struct task_struct *task, const uid_t uid,
63362 + const gid_t gid);
63363 +int gr_set_proc_label(const struct dentry *dentry,
63364 + const struct vfsmount *mnt,
63365 + const int unsafe_flags);
63366 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
63367 + const struct vfsmount *mnt);
63368 +__u32 gr_acl_handle_open(const struct dentry *dentry,
63369 + const struct vfsmount *mnt, int acc_mode);
63370 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
63371 + const struct dentry *p_dentry,
63372 + const struct vfsmount *p_mnt,
63373 + int open_flags, int acc_mode, const int imode);
63374 +void gr_handle_create(const struct dentry *dentry,
63375 + const struct vfsmount *mnt);
63376 +void gr_handle_proc_create(const struct dentry *dentry,
63377 + const struct inode *inode);
63378 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
63379 + const struct dentry *parent_dentry,
63380 + const struct vfsmount *parent_mnt,
63381 + const int mode);
63382 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
63383 + const struct dentry *parent_dentry,
63384 + const struct vfsmount *parent_mnt);
63385 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
63386 + const struct vfsmount *mnt);
63387 +void gr_handle_delete(const ino_t ino, const dev_t dev);
63388 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
63389 + const struct vfsmount *mnt);
63390 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
63391 + const struct dentry *parent_dentry,
63392 + const struct vfsmount *parent_mnt,
63393 + const char *from);
63394 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
63395 + const struct dentry *parent_dentry,
63396 + const struct vfsmount *parent_mnt,
63397 + const struct dentry *old_dentry,
63398 + const struct vfsmount *old_mnt, const char *to);
63399 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
63400 +int gr_acl_handle_rename(struct dentry *new_dentry,
63401 + struct dentry *parent_dentry,
63402 + const struct vfsmount *parent_mnt,
63403 + struct dentry *old_dentry,
63404 + struct inode *old_parent_inode,
63405 + struct vfsmount *old_mnt, const char *newname);
63406 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
63407 + struct dentry *old_dentry,
63408 + struct dentry *new_dentry,
63409 + struct vfsmount *mnt, const __u8 replace);
63410 +__u32 gr_check_link(const struct dentry *new_dentry,
63411 + const struct dentry *parent_dentry,
63412 + const struct vfsmount *parent_mnt,
63413 + const struct dentry *old_dentry,
63414 + const struct vfsmount *old_mnt);
63415 +int gr_acl_handle_filldir(const struct file *file, const char *name,
63416 + const unsigned int namelen, const ino_t ino);
63417 +
63418 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
63419 + const struct vfsmount *mnt);
63420 +void gr_acl_handle_exit(void);
63421 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
63422 +int gr_acl_handle_procpidmem(const struct task_struct *task);
63423 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
63424 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
63425 +void gr_audit_ptrace(struct task_struct *task);
63426 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
63427 +void gr_put_exec_file(struct task_struct *task);
63428 +
63429 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
63430 +
63431 +#ifdef CONFIG_GRKERNSEC
63432 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
63433 +void gr_handle_vm86(void);
63434 +void gr_handle_mem_readwrite(u64 from, u64 to);
63435 +
63436 +void gr_log_badprocpid(const char *entry);
63437 +
63438 +extern int grsec_enable_dmesg;
63439 +extern int grsec_disable_privio;
63440 +
63441 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63442 +extern int grsec_proc_gid;
63443 +#endif
63444 +
63445 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
63446 +extern int grsec_enable_chroot_findtask;
63447 +#endif
63448 +#ifdef CONFIG_GRKERNSEC_SETXID
63449 +extern int grsec_enable_setxid;
63450 +#endif
63451 +#endif
63452 +
63453 +#endif
63454 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
63455 new file mode 100644
63456 index 0000000..e7ffaaf
63457 --- /dev/null
63458 +++ b/include/linux/grsock.h
63459 @@ -0,0 +1,19 @@
63460 +#ifndef __GRSOCK_H
63461 +#define __GRSOCK_H
63462 +
63463 +extern void gr_attach_curr_ip(const struct sock *sk);
63464 +extern int gr_handle_sock_all(const int family, const int type,
63465 + const int protocol);
63466 +extern int gr_handle_sock_server(const struct sockaddr *sck);
63467 +extern int gr_handle_sock_server_other(const struct sock *sck);
63468 +extern int gr_handle_sock_client(const struct sockaddr *sck);
63469 +extern int gr_search_connect(struct socket * sock,
63470 + struct sockaddr_in * addr);
63471 +extern int gr_search_bind(struct socket * sock,
63472 + struct sockaddr_in * addr);
63473 +extern int gr_search_listen(struct socket * sock);
63474 +extern int gr_search_accept(struct socket * sock);
63475 +extern int gr_search_socket(const int domain, const int type,
63476 + const int protocol);
63477 +
63478 +#endif
63479 diff --git a/include/linux/hid.h b/include/linux/hid.h
63480 index 42970de..5db3c92 100644
63481 --- a/include/linux/hid.h
63482 +++ b/include/linux/hid.h
63483 @@ -705,7 +705,7 @@ struct hid_ll_driver {
63484 unsigned int code, int value);
63485
63486 int (*parse)(struct hid_device *hdev);
63487 -};
63488 +} __no_const;
63489
63490 #define PM_HINT_FULLON 1<<5
63491 #define PM_HINT_NORMAL 1<<1
63492 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
63493 index ef788b5..ac41b7b 100644
63494 --- a/include/linux/highmem.h
63495 +++ b/include/linux/highmem.h
63496 @@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
63497 kunmap_atomic(kaddr);
63498 }
63499
63500 +static inline void sanitize_highpage(struct page *page)
63501 +{
63502 + void *kaddr;
63503 + unsigned long flags;
63504 +
63505 + local_irq_save(flags);
63506 + kaddr = kmap_atomic(page);
63507 + clear_page(kaddr);
63508 + kunmap_atomic(kaddr);
63509 + local_irq_restore(flags);
63510 +}
63511 +
63512 static inline void zero_user_segments(struct page *page,
63513 unsigned start1, unsigned end1,
63514 unsigned start2, unsigned end2)
63515 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
63516 index 5970266..1c48c3b 100644
63517 --- a/include/linux/i2c.h
63518 +++ b/include/linux/i2c.h
63519 @@ -369,6 +369,7 @@ struct i2c_algorithm {
63520 /* To determine what the adapter supports */
63521 u32 (*functionality) (struct i2c_adapter *);
63522 };
63523 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
63524
63525 /*
63526 * i2c_adapter is the structure used to identify a physical i2c bus along
63527 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
63528 index d23c3c2..eb63c81 100644
63529 --- a/include/linux/i2o.h
63530 +++ b/include/linux/i2o.h
63531 @@ -565,7 +565,7 @@ struct i2o_controller {
63532 struct i2o_device *exec; /* Executive */
63533 #if BITS_PER_LONG == 64
63534 spinlock_t context_list_lock; /* lock for context_list */
63535 - atomic_t context_list_counter; /* needed for unique contexts */
63536 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
63537 struct list_head context_list; /* list of context id's
63538 and pointers */
63539 #endif
63540 diff --git a/include/linux/if_team.h b/include/linux/if_team.h
63541 index aa2e167..84024ce 100644
63542 --- a/include/linux/if_team.h
63543 +++ b/include/linux/if_team.h
63544 @@ -109,6 +109,7 @@ struct team_mode_ops {
63545 void (*port_enabled)(struct team *team, struct team_port *port);
63546 void (*port_disabled)(struct team *team, struct team_port *port);
63547 };
63548 +typedef struct team_mode_ops __no_const team_mode_ops_no_const;
63549
63550 enum team_option_type {
63551 TEAM_OPTION_TYPE_U32,
63552 @@ -181,7 +182,7 @@ struct team {
63553 struct list_head option_inst_list; /* list of option instances */
63554
63555 const struct team_mode *mode;
63556 - struct team_mode_ops ops;
63557 + team_mode_ops_no_const ops;
63558 long mode_priv[TEAM_MODE_PRIV_LONGS];
63559 };
63560
63561 diff --git a/include/linux/init.h b/include/linux/init.h
63562 index 5e664f6..ba694f0 100644
63563 --- a/include/linux/init.h
63564 +++ b/include/linux/init.h
63565 @@ -39,9 +39,36 @@
63566 * Also note, that this data cannot be "const".
63567 */
63568
63569 +#ifdef MODULE
63570 +#define add_init_latent_entropy
63571 +#define add_devinit_latent_entropy
63572 +#define add_cpuinit_latent_entropy
63573 +#define add_meminit_latent_entropy
63574 +#else
63575 +#define add_init_latent_entropy __latent_entropy
63576 +
63577 +#ifdef CONFIG_HOTPLUG
63578 +#define add_devinit_latent_entropy
63579 +#else
63580 +#define add_devinit_latent_entropy __latent_entropy
63581 +#endif
63582 +
63583 +#ifdef CONFIG_HOTPLUG_CPU
63584 +#define add_cpuinit_latent_entropy
63585 +#else
63586 +#define add_cpuinit_latent_entropy __latent_entropy
63587 +#endif
63588 +
63589 +#ifdef CONFIG_MEMORY_HOTPLUG
63590 +#define add_meminit_latent_entropy
63591 +#else
63592 +#define add_meminit_latent_entropy __latent_entropy
63593 +#endif
63594 +#endif
63595 +
63596 /* These are for everybody (although not all archs will actually
63597 discard it in modules) */
63598 -#define __init __section(.init.text) __cold notrace
63599 +#define __init __section(.init.text) __cold notrace add_init_latent_entropy
63600 #define __initdata __section(.init.data)
63601 #define __initconst __section(.init.rodata)
63602 #define __exitdata __section(.exit.data)
63603 @@ -83,7 +110,7 @@
63604 #define __exit __section(.exit.text) __exitused __cold notrace
63605
63606 /* Used for HOTPLUG */
63607 -#define __devinit __section(.devinit.text) __cold notrace
63608 +#define __devinit __section(.devinit.text) __cold notrace add_devinit_latent_entropy
63609 #define __devinitdata __section(.devinit.data)
63610 #define __devinitconst __section(.devinit.rodata)
63611 #define __devexit __section(.devexit.text) __exitused __cold notrace
63612 @@ -91,7 +118,7 @@
63613 #define __devexitconst __section(.devexit.rodata)
63614
63615 /* Used for HOTPLUG_CPU */
63616 -#define __cpuinit __section(.cpuinit.text) __cold notrace
63617 +#define __cpuinit __section(.cpuinit.text) __cold notrace add_cpuinit_latent_entropy
63618 #define __cpuinitdata __section(.cpuinit.data)
63619 #define __cpuinitconst __section(.cpuinit.rodata)
63620 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
63621 @@ -99,7 +126,7 @@
63622 #define __cpuexitconst __section(.cpuexit.rodata)
63623
63624 /* Used for MEMORY_HOTPLUG */
63625 -#define __meminit __section(.meminit.text) __cold notrace
63626 +#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
63627 #define __meminitdata __section(.meminit.data)
63628 #define __meminitconst __section(.meminit.rodata)
63629 #define __memexit __section(.memexit.text) __exitused __cold notrace
63630 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
63631 index 89f1cb1..7986c0f 100644
63632 --- a/include/linux/init_task.h
63633 +++ b/include/linux/init_task.h
63634 @@ -143,6 +143,12 @@ extern struct task_group root_task_group;
63635
63636 #define INIT_TASK_COMM "swapper"
63637
63638 +#ifdef CONFIG_X86
63639 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
63640 +#else
63641 +#define INIT_TASK_THREAD_INFO
63642 +#endif
63643 +
63644 /*
63645 * INIT_TASK is used to set up the first task table, touch at
63646 * your own risk!. Base=0, limit=0x1fffff (=2MB)
63647 @@ -182,6 +188,7 @@ extern struct task_group root_task_group;
63648 RCU_POINTER_INITIALIZER(cred, &init_cred), \
63649 .comm = INIT_TASK_COMM, \
63650 .thread = INIT_THREAD, \
63651 + INIT_TASK_THREAD_INFO \
63652 .fs = &init_fs, \
63653 .files = &init_files, \
63654 .signal = &init_signals, \
63655 diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
63656 index 78e2ada..745564d 100644
63657 --- a/include/linux/intel-iommu.h
63658 +++ b/include/linux/intel-iommu.h
63659 @@ -296,7 +296,7 @@ struct iommu_flush {
63660 u8 fm, u64 type);
63661 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
63662 unsigned int size_order, u64 type);
63663 -};
63664 +} __no_const;
63665
63666 enum {
63667 SR_DMAR_FECTL_REG,
63668 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
63669 index c5f856a..d29c117 100644
63670 --- a/include/linux/interrupt.h
63671 +++ b/include/linux/interrupt.h
63672 @@ -433,7 +433,7 @@ enum
63673 /* map softirq index to softirq name. update 'softirq_to_name' in
63674 * kernel/softirq.c when adding a new softirq.
63675 */
63676 -extern char *softirq_to_name[NR_SOFTIRQS];
63677 +extern const char * const softirq_to_name[NR_SOFTIRQS];
63678
63679 /* softirq mask and active fields moved to irq_cpustat_t in
63680 * asm/hardirq.h to get better cache usage. KAO
63681 @@ -441,12 +441,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
63682
63683 struct softirq_action
63684 {
63685 - void (*action)(struct softirq_action *);
63686 + void (*action)(void);
63687 };
63688
63689 asmlinkage void do_softirq(void);
63690 asmlinkage void __do_softirq(void);
63691 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
63692 +extern void open_softirq(int nr, void (*action)(void));
63693 extern void softirq_init(void);
63694 extern void __raise_softirq_irqoff(unsigned int nr);
63695
63696 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
63697 index 6883e19..06992b1 100644
63698 --- a/include/linux/kallsyms.h
63699 +++ b/include/linux/kallsyms.h
63700 @@ -15,7 +15,8 @@
63701
63702 struct module;
63703
63704 -#ifdef CONFIG_KALLSYMS
63705 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
63706 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63707 /* Lookup the address for a symbol. Returns 0 if not found. */
63708 unsigned long kallsyms_lookup_name(const char *name);
63709
63710 @@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
63711 /* Stupid that this does nothing, but I didn't create this mess. */
63712 #define __print_symbol(fmt, addr)
63713 #endif /*CONFIG_KALLSYMS*/
63714 +#else /* when included by kallsyms.c, vsnprintf.c, or
63715 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
63716 +extern void __print_symbol(const char *fmt, unsigned long address);
63717 +extern int sprint_backtrace(char *buffer, unsigned long address);
63718 +extern int sprint_symbol(char *buffer, unsigned long address);
63719 +extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
63720 +const char *kallsyms_lookup(unsigned long addr,
63721 + unsigned long *symbolsize,
63722 + unsigned long *offset,
63723 + char **modname, char *namebuf);
63724 +#endif
63725
63726 /* This macro allows us to keep printk typechecking */
63727 static __printf(1, 2)
63728 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
63729 index c4d2fc1..5df9c19 100644
63730 --- a/include/linux/kgdb.h
63731 +++ b/include/linux/kgdb.h
63732 @@ -53,7 +53,7 @@ extern int kgdb_connected;
63733 extern int kgdb_io_module_registered;
63734
63735 extern atomic_t kgdb_setting_breakpoint;
63736 -extern atomic_t kgdb_cpu_doing_single_step;
63737 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
63738
63739 extern struct task_struct *kgdb_usethread;
63740 extern struct task_struct *kgdb_contthread;
63741 @@ -252,7 +252,7 @@ struct kgdb_arch {
63742 void (*disable_hw_break)(struct pt_regs *regs);
63743 void (*remove_all_hw_break)(void);
63744 void (*correct_hw_break)(void);
63745 -};
63746 +} __do_const;
63747
63748 /**
63749 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
63750 @@ -277,7 +277,7 @@ struct kgdb_io {
63751 void (*pre_exception) (void);
63752 void (*post_exception) (void);
63753 int is_console;
63754 -};
63755 +} __do_const;
63756
63757 extern struct kgdb_arch arch_kgdb_ops;
63758
63759 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
63760 index 5398d58..5883a34 100644
63761 --- a/include/linux/kmod.h
63762 +++ b/include/linux/kmod.h
63763 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
63764 * usually useless though. */
63765 extern __printf(2, 3)
63766 int __request_module(bool wait, const char *name, ...);
63767 +extern __printf(3, 4)
63768 +int ___request_module(bool wait, char *param_name, const char *name, ...);
63769 #define request_module(mod...) __request_module(true, mod)
63770 #define request_module_nowait(mod...) __request_module(false, mod)
63771 #define try_then_request_module(x, mod...) \
63772 diff --git a/include/linux/kref.h b/include/linux/kref.h
63773 index 65af688..0592677 100644
63774 --- a/include/linux/kref.h
63775 +++ b/include/linux/kref.h
63776 @@ -64,7 +64,7 @@ static inline void kref_get(struct kref *kref)
63777 static inline int kref_sub(struct kref *kref, unsigned int count,
63778 void (*release)(struct kref *kref))
63779 {
63780 - WARN_ON(release == NULL);
63781 + BUG_ON(release == NULL);
63782
63783 if (atomic_sub_and_test((int) count, &kref->refcount)) {
63784 release(kref);
63785 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
63786 index b70b48b..0d7153b 100644
63787 --- a/include/linux/kvm_host.h
63788 +++ b/include/linux/kvm_host.h
63789 @@ -351,7 +351,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
63790 void vcpu_load(struct kvm_vcpu *vcpu);
63791 void vcpu_put(struct kvm_vcpu *vcpu);
63792
63793 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
63794 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
63795 struct module *module);
63796 void kvm_exit(void);
63797
63798 @@ -517,7 +517,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
63799 struct kvm_guest_debug *dbg);
63800 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
63801
63802 -int kvm_arch_init(void *opaque);
63803 +int kvm_arch_init(const void *opaque);
63804 void kvm_arch_exit(void);
63805
63806 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
63807 diff --git a/include/linux/libata.h b/include/linux/libata.h
63808 index 64f90e1..32b945b 100644
63809 --- a/include/linux/libata.h
63810 +++ b/include/linux/libata.h
63811 @@ -909,7 +909,7 @@ struct ata_port_operations {
63812 * fields must be pointers.
63813 */
63814 const struct ata_port_operations *inherits;
63815 -};
63816 +} __do_const;
63817
63818 struct ata_port_info {
63819 unsigned long flags;
63820 diff --git a/include/linux/memory.h b/include/linux/memory.h
63821 index ff9a9f8..c715deb 100644
63822 --- a/include/linux/memory.h
63823 +++ b/include/linux/memory.h
63824 @@ -143,7 +143,7 @@ struct memory_accessor {
63825 size_t count);
63826 ssize_t (*write)(struct memory_accessor *, const char *buf,
63827 off_t offset, size_t count);
63828 -};
63829 +} __no_const;
63830
63831 /*
63832 * Kernel text modification mutex, used for code patching. Users of this lock
63833 diff --git a/include/linux/mfd/abx500.h b/include/linux/mfd/abx500.h
63834 index 1318ca6..7521340 100644
63835 --- a/include/linux/mfd/abx500.h
63836 +++ b/include/linux/mfd/abx500.h
63837 @@ -452,6 +452,7 @@ struct abx500_ops {
63838 int (*event_registers_startup_state_get) (struct device *, u8 *);
63839 int (*startup_irq_enabled) (struct device *, unsigned int);
63840 };
63841 +typedef struct abx500_ops __no_const abx500_ops_no_const;
63842
63843 int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
63844 void abx500_remove_ops(struct device *dev);
63845 diff --git a/include/linux/mfd/abx500/ux500_chargalg.h b/include/linux/mfd/abx500/ux500_chargalg.h
63846 index 9b07725..3d55001 100644
63847 --- a/include/linux/mfd/abx500/ux500_chargalg.h
63848 +++ b/include/linux/mfd/abx500/ux500_chargalg.h
63849 @@ -19,7 +19,7 @@ struct ux500_charger_ops {
63850 int (*enable) (struct ux500_charger *, int, int, int);
63851 int (*kick_wd) (struct ux500_charger *);
63852 int (*update_curr) (struct ux500_charger *, int);
63853 -};
63854 +} __no_const;
63855
63856 /**
63857 * struct ux500_charger - power supply ux500 charger sub class
63858 diff --git a/include/linux/mm.h b/include/linux/mm.h
63859 index 311be90..5f1638c 100644
63860 --- a/include/linux/mm.h
63861 +++ b/include/linux/mm.h
63862 @@ -116,7 +116,14 @@ extern unsigned int kobjsize(const void *objp);
63863
63864 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
63865 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
63866 +
63867 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
63868 +#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
63869 +#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
63870 +#else
63871 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
63872 +#endif
63873 +
63874 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
63875 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
63876
63877 @@ -1038,34 +1045,6 @@ int set_page_dirty(struct page *page);
63878 int set_page_dirty_lock(struct page *page);
63879 int clear_page_dirty_for_io(struct page *page);
63880
63881 -/* Is the vma a continuation of the stack vma above it? */
63882 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
63883 -{
63884 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
63885 -}
63886 -
63887 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
63888 - unsigned long addr)
63889 -{
63890 - return (vma->vm_flags & VM_GROWSDOWN) &&
63891 - (vma->vm_start == addr) &&
63892 - !vma_growsdown(vma->vm_prev, addr);
63893 -}
63894 -
63895 -/* Is the vma a continuation of the stack vma below it? */
63896 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
63897 -{
63898 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
63899 -}
63900 -
63901 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
63902 - unsigned long addr)
63903 -{
63904 - return (vma->vm_flags & VM_GROWSUP) &&
63905 - (vma->vm_end == addr) &&
63906 - !vma_growsup(vma->vm_next, addr);
63907 -}
63908 -
63909 extern pid_t
63910 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
63911
63912 @@ -1164,6 +1143,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
63913 }
63914 #endif
63915
63916 +#ifdef CONFIG_MMU
63917 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
63918 +#else
63919 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
63920 +{
63921 + return __pgprot(0);
63922 +}
63923 +#endif
63924 +
63925 int vma_wants_writenotify(struct vm_area_struct *vma);
63926
63927 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
63928 @@ -1182,8 +1170,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
63929 {
63930 return 0;
63931 }
63932 +
63933 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
63934 + unsigned long address)
63935 +{
63936 + return 0;
63937 +}
63938 #else
63939 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
63940 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
63941 #endif
63942
63943 #ifdef __PAGETABLE_PMD_FOLDED
63944 @@ -1192,8 +1187,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
63945 {
63946 return 0;
63947 }
63948 +
63949 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
63950 + unsigned long address)
63951 +{
63952 + return 0;
63953 +}
63954 #else
63955 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
63956 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
63957 #endif
63958
63959 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
63960 @@ -1211,11 +1213,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
63961 NULL: pud_offset(pgd, address);
63962 }
63963
63964 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
63965 +{
63966 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
63967 + NULL: pud_offset(pgd, address);
63968 +}
63969 +
63970 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
63971 {
63972 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
63973 NULL: pmd_offset(pud, address);
63974 }
63975 +
63976 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
63977 +{
63978 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
63979 + NULL: pmd_offset(pud, address);
63980 +}
63981 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
63982
63983 #if USE_SPLIT_PTLOCKS
63984 @@ -1426,6 +1440,7 @@ extern unsigned long do_mmap_pgoff(struct file *, unsigned long,
63985 unsigned long, unsigned long,
63986 unsigned long, unsigned long);
63987 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
63988 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
63989
63990 /* These take the mm semaphore themselves */
63991 extern unsigned long vm_brk(unsigned long, unsigned long);
63992 @@ -1489,6 +1504,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
63993 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
63994 struct vm_area_struct **pprev);
63995
63996 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
63997 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
63998 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
63999 +
64000 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
64001 NULL if none. Assume start_addr < end_addr. */
64002 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
64003 @@ -1517,15 +1536,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
64004 return vma;
64005 }
64006
64007 -#ifdef CONFIG_MMU
64008 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
64009 -#else
64010 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
64011 -{
64012 - return __pgprot(0);
64013 -}
64014 -#endif
64015 -
64016 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
64017 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
64018 unsigned long pfn, unsigned long size, pgprot_t);
64019 @@ -1631,7 +1641,7 @@ extern int unpoison_memory(unsigned long pfn);
64020 extern int sysctl_memory_failure_early_kill;
64021 extern int sysctl_memory_failure_recovery;
64022 extern void shake_page(struct page *p, int access);
64023 -extern atomic_long_t mce_bad_pages;
64024 +extern atomic_long_unchecked_t mce_bad_pages;
64025 extern int soft_offline_page(struct page *page, int flags);
64026
64027 extern void dump_page(struct page *page);
64028 @@ -1662,5 +1672,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
64029 static inline bool page_is_guard(struct page *page) { return false; }
64030 #endif /* CONFIG_DEBUG_PAGEALLOC */
64031
64032 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
64033 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
64034 +#else
64035 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
64036 +#endif
64037 +
64038 #endif /* __KERNEL__ */
64039 #endif /* _LINUX_MM_H */
64040 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
64041 index bf78672..debc693 100644
64042 --- a/include/linux/mm_types.h
64043 +++ b/include/linux/mm_types.h
64044 @@ -279,6 +279,8 @@ struct vm_area_struct {
64045 #ifdef CONFIG_NUMA
64046 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
64047 #endif
64048 +
64049 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
64050 };
64051
64052 struct core_thread {
64053 @@ -353,7 +355,7 @@ struct mm_struct {
64054 unsigned long def_flags;
64055 unsigned long nr_ptes; /* Page table pages */
64056 unsigned long start_code, end_code, start_data, end_data;
64057 - unsigned long start_brk, brk, start_stack;
64058 + unsigned long brk_gap, start_brk, brk, start_stack;
64059 unsigned long arg_start, arg_end, env_start, env_end;
64060
64061 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
64062 @@ -405,6 +407,24 @@ struct mm_struct {
64063 struct cpumask cpumask_allocation;
64064 #endif
64065 struct uprobes_state uprobes_state;
64066 +
64067 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
64068 + unsigned long pax_flags;
64069 +#endif
64070 +
64071 +#ifdef CONFIG_PAX_DLRESOLVE
64072 + unsigned long call_dl_resolve;
64073 +#endif
64074 +
64075 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
64076 + unsigned long call_syscall;
64077 +#endif
64078 +
64079 +#ifdef CONFIG_PAX_ASLR
64080 + unsigned long delta_mmap; /* randomized offset */
64081 + unsigned long delta_stack; /* randomized offset */
64082 +#endif
64083 +
64084 };
64085
64086 static inline void mm_init_cpumask(struct mm_struct *mm)
64087 diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h
64088 index 1d1b1e1..2a13c78 100644
64089 --- a/include/linux/mmu_notifier.h
64090 +++ b/include/linux/mmu_notifier.h
64091 @@ -255,12 +255,12 @@ static inline void mmu_notifier_mm_destroy(struct mm_struct *mm)
64092 */
64093 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
64094 ({ \
64095 - pte_t __pte; \
64096 + pte_t ___pte; \
64097 struct vm_area_struct *___vma = __vma; \
64098 unsigned long ___address = __address; \
64099 - __pte = ptep_clear_flush(___vma, ___address, __ptep); \
64100 + ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
64101 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
64102 - __pte; \
64103 + ___pte; \
64104 })
64105
64106 #define pmdp_clear_flush_notify(__vma, __address, __pmdp) \
64107 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
64108 index a16d929..860ae00 100644
64109 --- a/include/linux/mmzone.h
64110 +++ b/include/linux/mmzone.h
64111 @@ -414,7 +414,7 @@ struct zone {
64112 unsigned long flags; /* zone flags, see below */
64113
64114 /* Zone statistics */
64115 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
64116 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
64117
64118 /*
64119 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
64120 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
64121 index 6955045..ebdb7cd 100644
64122 --- a/include/linux/mod_devicetable.h
64123 +++ b/include/linux/mod_devicetable.h
64124 @@ -12,7 +12,7 @@
64125 typedef unsigned long kernel_ulong_t;
64126 #endif
64127
64128 -#define PCI_ANY_ID (~0)
64129 +#define PCI_ANY_ID ((__u16)~0)
64130
64131 struct pci_device_id {
64132 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
64133 @@ -139,7 +139,7 @@ struct usb_device_id {
64134 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
64135 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
64136
64137 -#define HID_ANY_ID (~0)
64138 +#define HID_ANY_ID (~0U)
64139 #define HID_BUS_ANY 0xffff
64140 #define HID_GROUP_ANY 0x0000
64141
64142 diff --git a/include/linux/module.h b/include/linux/module.h
64143 index fbcafe2..e5d9587 100644
64144 --- a/include/linux/module.h
64145 +++ b/include/linux/module.h
64146 @@ -17,6 +17,7 @@
64147 #include <linux/moduleparam.h>
64148 #include <linux/tracepoint.h>
64149 #include <linux/export.h>
64150 +#include <linux/fs.h>
64151
64152 #include <linux/percpu.h>
64153 #include <asm/module.h>
64154 @@ -273,19 +274,16 @@ struct module
64155 int (*init)(void);
64156
64157 /* If this is non-NULL, vfree after init() returns */
64158 - void *module_init;
64159 + void *module_init_rx, *module_init_rw;
64160
64161 /* Here is the actual code + data, vfree'd on unload. */
64162 - void *module_core;
64163 + void *module_core_rx, *module_core_rw;
64164
64165 /* Here are the sizes of the init and core sections */
64166 - unsigned int init_size, core_size;
64167 + unsigned int init_size_rw, core_size_rw;
64168
64169 /* The size of the executable code in each section. */
64170 - unsigned int init_text_size, core_text_size;
64171 -
64172 - /* Size of RO sections of the module (text+rodata) */
64173 - unsigned int init_ro_size, core_ro_size;
64174 + unsigned int init_size_rx, core_size_rx;
64175
64176 /* Arch-specific module values */
64177 struct mod_arch_specific arch;
64178 @@ -341,6 +339,10 @@ struct module
64179 #ifdef CONFIG_EVENT_TRACING
64180 struct ftrace_event_call **trace_events;
64181 unsigned int num_trace_events;
64182 + struct file_operations trace_id;
64183 + struct file_operations trace_enable;
64184 + struct file_operations trace_format;
64185 + struct file_operations trace_filter;
64186 #endif
64187 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
64188 unsigned int num_ftrace_callsites;
64189 @@ -388,16 +390,46 @@ bool is_module_address(unsigned long addr);
64190 bool is_module_percpu_address(unsigned long addr);
64191 bool is_module_text_address(unsigned long addr);
64192
64193 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
64194 +{
64195 +
64196 +#ifdef CONFIG_PAX_KERNEXEC
64197 + if (ktla_ktva(addr) >= (unsigned long)start &&
64198 + ktla_ktva(addr) < (unsigned long)start + size)
64199 + return 1;
64200 +#endif
64201 +
64202 + return ((void *)addr >= start && (void *)addr < start + size);
64203 +}
64204 +
64205 +static inline int within_module_core_rx(unsigned long addr, struct module *mod)
64206 +{
64207 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
64208 +}
64209 +
64210 +static inline int within_module_core_rw(unsigned long addr, struct module *mod)
64211 +{
64212 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
64213 +}
64214 +
64215 +static inline int within_module_init_rx(unsigned long addr, struct module *mod)
64216 +{
64217 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
64218 +}
64219 +
64220 +static inline int within_module_init_rw(unsigned long addr, struct module *mod)
64221 +{
64222 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
64223 +}
64224 +
64225 static inline int within_module_core(unsigned long addr, struct module *mod)
64226 {
64227 - return (unsigned long)mod->module_core <= addr &&
64228 - addr < (unsigned long)mod->module_core + mod->core_size;
64229 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
64230 }
64231
64232 static inline int within_module_init(unsigned long addr, struct module *mod)
64233 {
64234 - return (unsigned long)mod->module_init <= addr &&
64235 - addr < (unsigned long)mod->module_init + mod->init_size;
64236 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
64237 }
64238
64239 /* Search for module by name: must hold module_mutex. */
64240 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
64241 index b2be02e..72d2f78 100644
64242 --- a/include/linux/moduleloader.h
64243 +++ b/include/linux/moduleloader.h
64244 @@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
64245
64246 /* Allocator used for allocating struct module, core sections and init
64247 sections. Returns NULL on failure. */
64248 -void *module_alloc(unsigned long size);
64249 +void *module_alloc(unsigned long size) __size_overflow(1);
64250 +
64251 +#ifdef CONFIG_PAX_KERNEXEC
64252 +void *module_alloc_exec(unsigned long size) __size_overflow(1);
64253 +#else
64254 +#define module_alloc_exec(x) module_alloc(x)
64255 +#endif
64256
64257 /* Free memory returned from module_alloc. */
64258 void module_free(struct module *mod, void *module_region);
64259
64260 +#ifdef CONFIG_PAX_KERNEXEC
64261 +void module_free_exec(struct module *mod, void *module_region);
64262 +#else
64263 +#define module_free_exec(x, y) module_free((x), (y))
64264 +#endif
64265 +
64266 /* Apply the given relocation to the (simplified) ELF. Return -error
64267 or 0. */
64268 int apply_relocate(Elf_Shdr *sechdrs,
64269 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
64270 index d6a5806..7c13347 100644
64271 --- a/include/linux/moduleparam.h
64272 +++ b/include/linux/moduleparam.h
64273 @@ -286,7 +286,7 @@ static inline void __kernel_param_unlock(void)
64274 * @len is usually just sizeof(string).
64275 */
64276 #define module_param_string(name, string, len, perm) \
64277 - static const struct kparam_string __param_string_##name \
64278 + static const struct kparam_string __param_string_##name __used \
64279 = { len, string }; \
64280 __module_param_call(MODULE_PARAM_PREFIX, name, \
64281 &param_ops_string, \
64282 @@ -425,7 +425,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
64283 */
64284 #define module_param_array_named(name, array, type, nump, perm) \
64285 param_check_##type(name, &(array)[0]); \
64286 - static const struct kparam_array __param_arr_##name \
64287 + static const struct kparam_array __param_arr_##name __used \
64288 = { .max = ARRAY_SIZE(array), .num = nump, \
64289 .ops = &param_ops_##type, \
64290 .elemsize = sizeof(array[0]), .elem = array }; \
64291 diff --git a/include/linux/namei.h b/include/linux/namei.h
64292 index 4bf19d8..5268cea 100644
64293 --- a/include/linux/namei.h
64294 +++ b/include/linux/namei.h
64295 @@ -18,7 +18,7 @@ struct nameidata {
64296 unsigned seq;
64297 int last_type;
64298 unsigned depth;
64299 - char *saved_names[MAX_NESTED_LINKS + 1];
64300 + const char *saved_names[MAX_NESTED_LINKS + 1];
64301 };
64302
64303 /*
64304 @@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
64305
64306 extern void nd_jump_link(struct nameidata *nd, struct path *path);
64307
64308 -static inline void nd_set_link(struct nameidata *nd, char *path)
64309 +static inline void nd_set_link(struct nameidata *nd, const char *path)
64310 {
64311 nd->saved_names[nd->depth] = path;
64312 }
64313
64314 -static inline char *nd_get_link(struct nameidata *nd)
64315 +static inline const char *nd_get_link(const struct nameidata *nd)
64316 {
64317 return nd->saved_names[nd->depth];
64318 }
64319 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
64320 index 59dc05f3..c905a34 100644
64321 --- a/include/linux/netdevice.h
64322 +++ b/include/linux/netdevice.h
64323 @@ -1027,6 +1027,7 @@ struct net_device_ops {
64324 struct net_device *dev,
64325 int idx);
64326 };
64327 +typedef struct net_device_ops __no_const net_device_ops_no_const;
64328
64329 /*
64330 * The DEVICE structure.
64331 @@ -1087,7 +1088,7 @@ struct net_device {
64332 int iflink;
64333
64334 struct net_device_stats stats;
64335 - atomic_long_t rx_dropped; /* dropped packets by core network
64336 + atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
64337 * Do not use this in drivers.
64338 */
64339
64340 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
64341 new file mode 100644
64342 index 0000000..33f4af8
64343 --- /dev/null
64344 +++ b/include/linux/netfilter/xt_gradm.h
64345 @@ -0,0 +1,9 @@
64346 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
64347 +#define _LINUX_NETFILTER_XT_GRADM_H 1
64348 +
64349 +struct xt_gradm_mtinfo {
64350 + __u16 flags;
64351 + __u16 invflags;
64352 +};
64353 +
64354 +#endif
64355 diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
64356 index c65a18a..0c05f3a 100644
64357 --- a/include/linux/of_pdt.h
64358 +++ b/include/linux/of_pdt.h
64359 @@ -32,7 +32,7 @@ struct of_pdt_ops {
64360
64361 /* return 0 on success; fill in 'len' with number of bytes in path */
64362 int (*pkg2path)(phandle node, char *buf, const int buflen, int *len);
64363 -};
64364 +} __no_const;
64365
64366 extern void *prom_early_alloc(unsigned long size);
64367
64368 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
64369 index a4c5624..79d6d88 100644
64370 --- a/include/linux/oprofile.h
64371 +++ b/include/linux/oprofile.h
64372 @@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
64373 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
64374 char const * name, ulong * val);
64375
64376 -/** Create a file for read-only access to an atomic_t. */
64377 +/** Create a file for read-only access to an atomic_unchecked_t. */
64378 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
64379 - char const * name, atomic_t * val);
64380 + char const * name, atomic_unchecked_t * val);
64381
64382 /** create a directory */
64383 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
64384 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
64385 index bdb4161..f373d41 100644
64386 --- a/include/linux/perf_event.h
64387 +++ b/include/linux/perf_event.h
64388 @@ -882,8 +882,8 @@ struct perf_event {
64389
64390 enum perf_event_active_state state;
64391 unsigned int attach_state;
64392 - local64_t count;
64393 - atomic64_t child_count;
64394 + local64_t count; /* PaX: fix it one day */
64395 + atomic64_unchecked_t child_count;
64396
64397 /*
64398 * These are the total time in nanoseconds that the event
64399 @@ -934,8 +934,8 @@ struct perf_event {
64400 * These accumulate total time (in nanoseconds) that children
64401 * events have been enabled and running, respectively.
64402 */
64403 - atomic64_t child_total_time_enabled;
64404 - atomic64_t child_total_time_running;
64405 + atomic64_unchecked_t child_total_time_enabled;
64406 + atomic64_unchecked_t child_total_time_running;
64407
64408 /*
64409 * Protect attach/detach and child_list:
64410 diff --git a/include/linux/personality.h b/include/linux/personality.h
64411 index 8fc7dd1a..c19d89e 100644
64412 --- a/include/linux/personality.h
64413 +++ b/include/linux/personality.h
64414 @@ -44,6 +44,7 @@ enum {
64415 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
64416 ADDR_NO_RANDOMIZE | \
64417 ADDR_COMPAT_LAYOUT | \
64418 + ADDR_LIMIT_3GB | \
64419 MMAP_PAGE_ZERO)
64420
64421 /*
64422 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
64423 index ad1a427..6419649 100644
64424 --- a/include/linux/pipe_fs_i.h
64425 +++ b/include/linux/pipe_fs_i.h
64426 @@ -45,9 +45,9 @@ struct pipe_buffer {
64427 struct pipe_inode_info {
64428 wait_queue_head_t wait;
64429 unsigned int nrbufs, curbuf, buffers;
64430 - unsigned int readers;
64431 - unsigned int writers;
64432 - unsigned int waiting_writers;
64433 + atomic_t readers;
64434 + atomic_t writers;
64435 + atomic_t waiting_writers;
64436 unsigned int r_counter;
64437 unsigned int w_counter;
64438 struct page *tmp_page;
64439 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
64440 index f271860..6b3bec5 100644
64441 --- a/include/linux/pm_runtime.h
64442 +++ b/include/linux/pm_runtime.h
64443 @@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
64444
64445 static inline void pm_runtime_mark_last_busy(struct device *dev)
64446 {
64447 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
64448 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
64449 }
64450
64451 #else /* !CONFIG_PM_RUNTIME */
64452 diff --git a/include/linux/poison.h b/include/linux/poison.h
64453 index 2110a81..13a11bb 100644
64454 --- a/include/linux/poison.h
64455 +++ b/include/linux/poison.h
64456 @@ -19,8 +19,8 @@
64457 * under normal circumstances, used to verify that nobody uses
64458 * non-initialized list entries.
64459 */
64460 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
64461 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
64462 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
64463 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
64464
64465 /********** include/linux/timer.h **********/
64466 /*
64467 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
64468 index 5a710b9..0b0dab9 100644
64469 --- a/include/linux/preempt.h
64470 +++ b/include/linux/preempt.h
64471 @@ -126,7 +126,7 @@ struct preempt_ops {
64472 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
64473 void (*sched_out)(struct preempt_notifier *notifier,
64474 struct task_struct *next);
64475 -};
64476 +} __no_const;
64477
64478 /**
64479 * preempt_notifier - key for installing preemption notifiers
64480 diff --git a/include/linux/printk.h b/include/linux/printk.h
64481 index 9afc01e..92c32e8 100644
64482 --- a/include/linux/printk.h
64483 +++ b/include/linux/printk.h
64484 @@ -101,6 +101,8 @@ void early_printk(const char *fmt, ...);
64485 extern int printk_needs_cpu(int cpu);
64486 extern void printk_tick(void);
64487
64488 +extern int kptr_restrict;
64489 +
64490 #ifdef CONFIG_PRINTK
64491 asmlinkage __printf(5, 0)
64492 int vprintk_emit(int facility, int level,
64493 @@ -135,7 +137,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
64494
64495 extern int printk_delay_msec;
64496 extern int dmesg_restrict;
64497 -extern int kptr_restrict;
64498
64499 void log_buf_kexec_setup(void);
64500 void __init setup_log_buf(int early);
64501 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
64502 index 3fd2e87..d93a721 100644
64503 --- a/include/linux/proc_fs.h
64504 +++ b/include/linux/proc_fs.h
64505 @@ -155,6 +155,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
64506 return proc_create_data(name, mode, parent, proc_fops, NULL);
64507 }
64508
64509 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
64510 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
64511 +{
64512 +#ifdef CONFIG_GRKERNSEC_PROC_USER
64513 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
64514 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64515 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
64516 +#else
64517 + return proc_create_data(name, mode, parent, proc_fops, NULL);
64518 +#endif
64519 +}
64520 +
64521 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
64522 umode_t mode, struct proc_dir_entry *base,
64523 read_proc_t *read_proc, void * data)
64524 @@ -258,7 +270,7 @@ union proc_op {
64525 int (*proc_show)(struct seq_file *m,
64526 struct pid_namespace *ns, struct pid *pid,
64527 struct task_struct *task);
64528 -};
64529 +} __no_const;
64530
64531 struct ctl_table_header;
64532 struct ctl_table;
64533 diff --git a/include/linux/random.h b/include/linux/random.h
64534 index ac621ce..c1215f3 100644
64535 --- a/include/linux/random.h
64536 +++ b/include/linux/random.h
64537 @@ -53,6 +53,10 @@ extern void add_input_randomness(unsigned int type, unsigned int code,
64538 unsigned int value);
64539 extern void add_interrupt_randomness(int irq, int irq_flags);
64540
64541 +#ifdef CONFIG_PAX_LATENT_ENTROPY
64542 +extern void transfer_latent_entropy(void);
64543 +#endif
64544 +
64545 extern void get_random_bytes(void *buf, int nbytes);
64546 extern void get_random_bytes_arch(void *buf, int nbytes);
64547 void generate_random_uuid(unsigned char uuid_out[16]);
64548 @@ -69,12 +73,17 @@ void srandom32(u32 seed);
64549
64550 u32 prandom32(struct rnd_state *);
64551
64552 +static inline unsigned long pax_get_random_long(void)
64553 +{
64554 + return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
64555 +}
64556 +
64557 /*
64558 * Handle minimum values for seeds
64559 */
64560 static inline u32 __seed(u32 x, u32 m)
64561 {
64562 - return (x < m) ? x + m : x;
64563 + return (x <= m) ? x + m + 1 : x;
64564 }
64565
64566 /**
64567 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
64568 index e0879a7..a12f962 100644
64569 --- a/include/linux/reboot.h
64570 +++ b/include/linux/reboot.h
64571 @@ -52,9 +52,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
64572 * Architecture-specific implementations of sys_reboot commands.
64573 */
64574
64575 -extern void machine_restart(char *cmd);
64576 -extern void machine_halt(void);
64577 -extern void machine_power_off(void);
64578 +extern void machine_restart(char *cmd) __noreturn;
64579 +extern void machine_halt(void) __noreturn;
64580 +extern void machine_power_off(void) __noreturn;
64581
64582 extern void machine_shutdown(void);
64583 struct pt_regs;
64584 @@ -65,9 +65,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
64585 */
64586
64587 extern void kernel_restart_prepare(char *cmd);
64588 -extern void kernel_restart(char *cmd);
64589 -extern void kernel_halt(void);
64590 -extern void kernel_power_off(void);
64591 +extern void kernel_restart(char *cmd) __noreturn;
64592 +extern void kernel_halt(void) __noreturn;
64593 +extern void kernel_power_off(void) __noreturn;
64594
64595 extern int C_A_D; /* for sysctl */
64596 void ctrl_alt_del(void);
64597 @@ -81,7 +81,7 @@ extern int orderly_poweroff(bool force);
64598 * Emergency restart, callable from an interrupt handler.
64599 */
64600
64601 -extern void emergency_restart(void);
64602 +extern void emergency_restart(void) __noreturn;
64603 #include <asm/emergency-restart.h>
64604
64605 #endif
64606 diff --git a/include/linux/relay.h b/include/linux/relay.h
64607 index 91cacc3..b55ff74 100644
64608 --- a/include/linux/relay.h
64609 +++ b/include/linux/relay.h
64610 @@ -160,7 +160,7 @@ struct rchan_callbacks
64611 * The callback should return 0 if successful, negative if not.
64612 */
64613 int (*remove_buf_file)(struct dentry *dentry);
64614 -};
64615 +} __no_const;
64616
64617 /*
64618 * CONFIG_RELAY kernel API, kernel/relay.c
64619 diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
64620 index 6fdf027..ff72610 100644
64621 --- a/include/linux/rfkill.h
64622 +++ b/include/linux/rfkill.h
64623 @@ -147,6 +147,7 @@ struct rfkill_ops {
64624 void (*query)(struct rfkill *rfkill, void *data);
64625 int (*set_block)(void *data, bool blocked);
64626 };
64627 +typedef struct rfkill_ops __no_const rfkill_ops_no_const;
64628
64629 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
64630 /**
64631 diff --git a/include/linux/rio.h b/include/linux/rio.h
64632 index a90ebad..fd87b5d 100644
64633 --- a/include/linux/rio.h
64634 +++ b/include/linux/rio.h
64635 @@ -321,7 +321,7 @@ struct rio_ops {
64636 int mbox, void *buffer, size_t len);
64637 int (*add_inb_buffer)(struct rio_mport *mport, int mbox, void *buf);
64638 void *(*get_inb_message)(struct rio_mport *mport, int mbox);
64639 -};
64640 +} __no_const;
64641
64642 #define RIO_RESOURCE_MEM 0x00000100
64643 #define RIO_RESOURCE_DOORBELL 0x00000200
64644 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
64645 index 3fce545..b4fed6e 100644
64646 --- a/include/linux/rmap.h
64647 +++ b/include/linux/rmap.h
64648 @@ -119,9 +119,9 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
64649 void anon_vma_init(void); /* create anon_vma_cachep */
64650 int anon_vma_prepare(struct vm_area_struct *);
64651 void unlink_anon_vmas(struct vm_area_struct *);
64652 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
64653 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
64654 void anon_vma_moveto_tail(struct vm_area_struct *);
64655 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
64656 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
64657
64658 static inline void anon_vma_merge(struct vm_area_struct *vma,
64659 struct vm_area_struct *next)
64660 diff --git a/include/linux/sched.h b/include/linux/sched.h
64661 index 23bddac..5976055 100644
64662 --- a/include/linux/sched.h
64663 +++ b/include/linux/sched.h
64664 @@ -101,6 +101,7 @@ struct bio_list;
64665 struct fs_struct;
64666 struct perf_event_context;
64667 struct blk_plug;
64668 +struct linux_binprm;
64669
64670 /*
64671 * List of flags we want to share for kernel threads,
64672 @@ -384,10 +385,13 @@ struct user_namespace;
64673 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
64674
64675 extern int sysctl_max_map_count;
64676 +extern unsigned long sysctl_heap_stack_gap;
64677
64678 #include <linux/aio.h>
64679
64680 #ifdef CONFIG_MMU
64681 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
64682 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
64683 extern void arch_pick_mmap_layout(struct mm_struct *mm);
64684 extern unsigned long
64685 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
64686 @@ -651,6 +655,17 @@ struct signal_struct {
64687 #ifdef CONFIG_TASKSTATS
64688 struct taskstats *stats;
64689 #endif
64690 +
64691 +#ifdef CONFIG_GRKERNSEC
64692 + u32 curr_ip;
64693 + u32 saved_ip;
64694 + u32 gr_saddr;
64695 + u32 gr_daddr;
64696 + u16 gr_sport;
64697 + u16 gr_dport;
64698 + u8 used_accept:1;
64699 +#endif
64700 +
64701 #ifdef CONFIG_AUDIT
64702 unsigned audit_tty;
64703 struct tty_audit_buf *tty_audit_buf;
64704 @@ -734,6 +749,11 @@ struct user_struct {
64705 struct key *session_keyring; /* UID's default session keyring */
64706 #endif
64707
64708 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
64709 + unsigned int banned;
64710 + unsigned long ban_expires;
64711 +#endif
64712 +
64713 /* Hash table maintenance information */
64714 struct hlist_node uidhash_node;
64715 kuid_t uid;
64716 @@ -1356,8 +1376,8 @@ struct task_struct {
64717 struct list_head thread_group;
64718
64719 struct completion *vfork_done; /* for vfork() */
64720 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
64721 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
64722 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
64723 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
64724
64725 cputime_t utime, stime, utimescaled, stimescaled;
64726 cputime_t gtime;
64727 @@ -1373,11 +1393,6 @@ struct task_struct {
64728 struct task_cputime cputime_expires;
64729 struct list_head cpu_timers[3];
64730
64731 -/* process credentials */
64732 - const struct cred __rcu *real_cred; /* objective and real subjective task
64733 - * credentials (COW) */
64734 - const struct cred __rcu *cred; /* effective (overridable) subjective task
64735 - * credentials (COW) */
64736 char comm[TASK_COMM_LEN]; /* executable name excluding path
64737 - access with [gs]et_task_comm (which lock
64738 it with task_lock())
64739 @@ -1394,6 +1409,10 @@ struct task_struct {
64740 #endif
64741 /* CPU-specific state of this task */
64742 struct thread_struct thread;
64743 +/* thread_info moved to task_struct */
64744 +#ifdef CONFIG_X86
64745 + struct thread_info tinfo;
64746 +#endif
64747 /* filesystem information */
64748 struct fs_struct *fs;
64749 /* open file information */
64750 @@ -1467,6 +1486,10 @@ struct task_struct {
64751 gfp_t lockdep_reclaim_gfp;
64752 #endif
64753
64754 +/* process credentials */
64755 + const struct cred __rcu *real_cred; /* objective and real subjective task
64756 + * credentials (COW) */
64757 +
64758 /* journalling filesystem info */
64759 void *journal_info;
64760
64761 @@ -1505,6 +1528,10 @@ struct task_struct {
64762 /* cg_list protected by css_set_lock and tsk->alloc_lock */
64763 struct list_head cg_list;
64764 #endif
64765 +
64766 + const struct cred __rcu *cred; /* effective (overridable) subjective task
64767 + * credentials (COW) */
64768 +
64769 #ifdef CONFIG_FUTEX
64770 struct robust_list_head __user *robust_list;
64771 #ifdef CONFIG_COMPAT
64772 @@ -1589,8 +1616,74 @@ struct task_struct {
64773 #ifdef CONFIG_UPROBES
64774 struct uprobe_task *utask;
64775 #endif
64776 +
64777 +#ifdef CONFIG_GRKERNSEC
64778 + /* grsecurity */
64779 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64780 + u64 exec_id;
64781 +#endif
64782 +#ifdef CONFIG_GRKERNSEC_SETXID
64783 + const struct cred *delayed_cred;
64784 +#endif
64785 + struct dentry *gr_chroot_dentry;
64786 + struct acl_subject_label *acl;
64787 + struct acl_role_label *role;
64788 + struct file *exec_file;
64789 + u16 acl_role_id;
64790 + /* is this the task that authenticated to the special role */
64791 + u8 acl_sp_role;
64792 + u8 is_writable;
64793 + u8 brute;
64794 + u8 gr_is_chrooted;
64795 +#endif
64796 +
64797 };
64798
64799 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
64800 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
64801 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
64802 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
64803 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
64804 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
64805 +
64806 +#ifdef CONFIG_PAX_SOFTMODE
64807 +extern int pax_softmode;
64808 +#endif
64809 +
64810 +extern int pax_check_flags(unsigned long *);
64811 +
64812 +/* if tsk != current then task_lock must be held on it */
64813 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
64814 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
64815 +{
64816 + if (likely(tsk->mm))
64817 + return tsk->mm->pax_flags;
64818 + else
64819 + return 0UL;
64820 +}
64821 +
64822 +/* if tsk != current then task_lock must be held on it */
64823 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
64824 +{
64825 + if (likely(tsk->mm)) {
64826 + tsk->mm->pax_flags = flags;
64827 + return 0;
64828 + }
64829 + return -EINVAL;
64830 +}
64831 +#endif
64832 +
64833 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
64834 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
64835 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
64836 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
64837 +#endif
64838 +
64839 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
64840 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
64841 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
64842 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
64843 +
64844 /* Future-safe accessor for struct task_struct's cpus_allowed. */
64845 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
64846
64847 @@ -2125,7 +2218,9 @@ void yield(void);
64848 extern struct exec_domain default_exec_domain;
64849
64850 union thread_union {
64851 +#ifndef CONFIG_X86
64852 struct thread_info thread_info;
64853 +#endif
64854 unsigned long stack[THREAD_SIZE/sizeof(long)];
64855 };
64856
64857 @@ -2158,6 +2253,7 @@ extern struct pid_namespace init_pid_ns;
64858 */
64859
64860 extern struct task_struct *find_task_by_vpid(pid_t nr);
64861 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
64862 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
64863 struct pid_namespace *ns);
64864
64865 @@ -2314,7 +2410,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
64866 extern void exit_itimers(struct signal_struct *);
64867 extern void flush_itimer_signals(void);
64868
64869 -extern void do_group_exit(int);
64870 +extern __noreturn void do_group_exit(int);
64871
64872 extern void daemonize(const char *, ...);
64873 extern int allow_signal(int);
64874 @@ -2515,9 +2611,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
64875
64876 #endif
64877
64878 -static inline int object_is_on_stack(void *obj)
64879 +static inline int object_starts_on_stack(void *obj)
64880 {
64881 - void *stack = task_stack_page(current);
64882 + const void *stack = task_stack_page(current);
64883
64884 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
64885 }
64886 diff --git a/include/linux/screen_info.h b/include/linux/screen_info.h
64887 index 899fbb4..1cb4138 100644
64888 --- a/include/linux/screen_info.h
64889 +++ b/include/linux/screen_info.h
64890 @@ -43,7 +43,8 @@ struct screen_info {
64891 __u16 pages; /* 0x32 */
64892 __u16 vesa_attributes; /* 0x34 */
64893 __u32 capabilities; /* 0x36 */
64894 - __u8 _reserved[6]; /* 0x3a */
64895 + __u16 vesapm_size; /* 0x3a */
64896 + __u8 _reserved[4]; /* 0x3c */
64897 } __attribute__((packed));
64898
64899 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
64900 diff --git a/include/linux/security.h b/include/linux/security.h
64901 index d143b8e..9f27b95 100644
64902 --- a/include/linux/security.h
64903 +++ b/include/linux/security.h
64904 @@ -26,6 +26,7 @@
64905 #include <linux/capability.h>
64906 #include <linux/slab.h>
64907 #include <linux/err.h>
64908 +#include <linux/grsecurity.h>
64909
64910 struct linux_binprm;
64911 struct cred;
64912 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
64913 index 83c44ee..e8a9eba 100644
64914 --- a/include/linux/seq_file.h
64915 +++ b/include/linux/seq_file.h
64916 @@ -25,6 +25,9 @@ struct seq_file {
64917 struct mutex lock;
64918 const struct seq_operations *op;
64919 int poll_event;
64920 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64921 + u64 exec_id;
64922 +#endif
64923 void *private;
64924 };
64925
64926 @@ -34,6 +37,7 @@ struct seq_operations {
64927 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
64928 int (*show) (struct seq_file *m, void *v);
64929 };
64930 +typedef struct seq_operations __no_const seq_operations_no_const;
64931
64932 #define SEQ_SKIP 1
64933
64934 diff --git a/include/linux/shm.h b/include/linux/shm.h
64935 index edd0868..f98feee 100644
64936 --- a/include/linux/shm.h
64937 +++ b/include/linux/shm.h
64938 @@ -98,6 +98,10 @@ struct shmid_kernel /* private to the kernel */
64939
64940 /* The task created the shm object. NULL if the task is dead. */
64941 struct task_struct *shm_creator;
64942 +#ifdef CONFIG_GRKERNSEC
64943 + time_t shm_createtime;
64944 + pid_t shm_lapid;
64945 +#endif
64946 };
64947
64948 /* shm_mode upper byte flags */
64949 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
64950 index f3165d2..2cb3cb7 100644
64951 --- a/include/linux/skbuff.h
64952 +++ b/include/linux/skbuff.h
64953 @@ -577,7 +577,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
64954 extern struct sk_buff *__alloc_skb(unsigned int size,
64955 gfp_t priority, int flags, int node);
64956 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
64957 -static inline struct sk_buff *alloc_skb(unsigned int size,
64958 +static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
64959 gfp_t priority)
64960 {
64961 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
64962 @@ -687,7 +687,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
64963 */
64964 static inline int skb_queue_empty(const struct sk_buff_head *list)
64965 {
64966 - return list->next == (struct sk_buff *)list;
64967 + return list->next == (const struct sk_buff *)list;
64968 }
64969
64970 /**
64971 @@ -700,7 +700,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
64972 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
64973 const struct sk_buff *skb)
64974 {
64975 - return skb->next == (struct sk_buff *)list;
64976 + return skb->next == (const struct sk_buff *)list;
64977 }
64978
64979 /**
64980 @@ -713,7 +713,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
64981 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
64982 const struct sk_buff *skb)
64983 {
64984 - return skb->prev == (struct sk_buff *)list;
64985 + return skb->prev == (const struct sk_buff *)list;
64986 }
64987
64988 /**
64989 @@ -1623,7 +1623,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
64990 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
64991 */
64992 #ifndef NET_SKB_PAD
64993 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
64994 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
64995 #endif
64996
64997 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
64998 @@ -2201,7 +2201,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
64999 int noblock, int *err);
65000 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
65001 struct poll_table_struct *wait);
65002 -extern int skb_copy_datagram_iovec(const struct sk_buff *from,
65003 +extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
65004 int offset, struct iovec *to,
65005 int size);
65006 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
65007 diff --git a/include/linux/slab.h b/include/linux/slab.h
65008 index 0dd2dfa..2b8677c 100644
65009 --- a/include/linux/slab.h
65010 +++ b/include/linux/slab.h
65011 @@ -11,12 +11,20 @@
65012
65013 #include <linux/gfp.h>
65014 #include <linux/types.h>
65015 +#include <linux/err.h>
65016
65017 /*
65018 * Flags to pass to kmem_cache_create().
65019 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
65020 */
65021 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
65022 +
65023 +#ifdef CONFIG_PAX_USERCOPY_SLABS
65024 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
65025 +#else
65026 +#define SLAB_USERCOPY 0x00000000UL
65027 +#endif
65028 +
65029 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
65030 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
65031 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
65032 @@ -87,10 +95,13 @@
65033 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
65034 * Both make kfree a no-op.
65035 */
65036 -#define ZERO_SIZE_PTR ((void *)16)
65037 +#define ZERO_SIZE_PTR \
65038 +({ \
65039 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
65040 + (void *)(-MAX_ERRNO-1L); \
65041 +})
65042
65043 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
65044 - (unsigned long)ZERO_SIZE_PTR)
65045 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
65046
65047 /*
65048 * Common fields provided in kmem_cache by all slab allocators
65049 @@ -185,6 +196,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
65050 void kfree(const void *);
65051 void kzfree(const void *);
65052 size_t ksize(const void *);
65053 +const char *check_heap_object(const void *ptr, unsigned long n, bool to);
65054 +bool is_usercopy_object(const void *ptr);
65055
65056 /*
65057 * Allocator specific definitions. These are mainly used to establish optimized
65058 @@ -322,7 +335,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
65059 */
65060 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
65061 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
65062 -extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
65063 +extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
65064 #define kmalloc_track_caller(size, flags) \
65065 __kmalloc_track_caller(size, flags, _RET_IP_)
65066 #else
65067 @@ -341,7 +354,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
65068 */
65069 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
65070 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
65071 -extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
65072 +extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
65073 #define kmalloc_node_track_caller(size, flags, node) \
65074 __kmalloc_node_track_caller(size, flags, node, \
65075 _RET_IP_)
65076 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
65077 index 0c634fa..8616300 100644
65078 --- a/include/linux/slab_def.h
65079 +++ b/include/linux/slab_def.h
65080 @@ -69,10 +69,10 @@ struct kmem_cache {
65081 unsigned long node_allocs;
65082 unsigned long node_frees;
65083 unsigned long node_overflow;
65084 - atomic_t allochit;
65085 - atomic_t allocmiss;
65086 - atomic_t freehit;
65087 - atomic_t freemiss;
65088 + atomic_unchecked_t allochit;
65089 + atomic_unchecked_t allocmiss;
65090 + atomic_unchecked_t freehit;
65091 + atomic_unchecked_t freemiss;
65092
65093 /*
65094 * If debugging is enabled, then the allocator can add additional
65095 @@ -105,11 +105,16 @@ struct cache_sizes {
65096 #ifdef CONFIG_ZONE_DMA
65097 struct kmem_cache *cs_dmacachep;
65098 #endif
65099 +
65100 +#ifdef CONFIG_PAX_USERCOPY_SLABS
65101 + struct kmem_cache *cs_usercopycachep;
65102 +#endif
65103 +
65104 };
65105 extern struct cache_sizes malloc_sizes[];
65106
65107 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
65108 -void *__kmalloc(size_t size, gfp_t flags);
65109 +void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
65110
65111 #ifdef CONFIG_TRACING
65112 extern void *kmem_cache_alloc_trace(size_t size,
65113 @@ -152,6 +157,13 @@ found:
65114 cachep = malloc_sizes[i].cs_dmacachep;
65115 else
65116 #endif
65117 +
65118 +#ifdef CONFIG_PAX_USERCOPY_SLABS
65119 + if (flags & GFP_USERCOPY)
65120 + cachep = malloc_sizes[i].cs_usercopycachep;
65121 + else
65122 +#endif
65123 +
65124 cachep = malloc_sizes[i].cs_cachep;
65125
65126 ret = kmem_cache_alloc_trace(size, cachep, flags);
65127 @@ -162,7 +174,7 @@ found:
65128 }
65129
65130 #ifdef CONFIG_NUMA
65131 -extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
65132 +extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
65133 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
65134
65135 #ifdef CONFIG_TRACING
65136 @@ -205,6 +217,13 @@ found:
65137 cachep = malloc_sizes[i].cs_dmacachep;
65138 else
65139 #endif
65140 +
65141 +#ifdef CONFIG_PAX_USERCOPY_SLABS
65142 + if (flags & GFP_USERCOPY)
65143 + cachep = malloc_sizes[i].cs_usercopycachep;
65144 + else
65145 +#endif
65146 +
65147 cachep = malloc_sizes[i].cs_cachep;
65148
65149 return kmem_cache_alloc_node_trace(size, cachep, flags, node);
65150 diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
65151 index 0ec00b3..22b4715 100644
65152 --- a/include/linux/slob_def.h
65153 +++ b/include/linux/slob_def.h
65154 @@ -9,7 +9,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
65155 return kmem_cache_alloc_node(cachep, flags, -1);
65156 }
65157
65158 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
65159 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
65160
65161 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
65162 {
65163 @@ -29,7 +29,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
65164 return __kmalloc_node(size, flags, -1);
65165 }
65166
65167 -static __always_inline void *__kmalloc(size_t size, gfp_t flags)
65168 +static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
65169 {
65170 return kmalloc(size, flags);
65171 }
65172 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
65173 index df448ad..b99e7f6 100644
65174 --- a/include/linux/slub_def.h
65175 +++ b/include/linux/slub_def.h
65176 @@ -91,7 +91,7 @@ struct kmem_cache {
65177 struct kmem_cache_order_objects max;
65178 struct kmem_cache_order_objects min;
65179 gfp_t allocflags; /* gfp flags to use on each alloc */
65180 - int refcount; /* Refcount for slab cache destroy */
65181 + atomic_t refcount; /* Refcount for slab cache destroy */
65182 void (*ctor)(void *);
65183 int inuse; /* Offset to metadata */
65184 int align; /* Alignment */
65185 @@ -152,7 +152,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
65186 * Sorry that the following has to be that ugly but some versions of GCC
65187 * have trouble with constant propagation and loops.
65188 */
65189 -static __always_inline int kmalloc_index(size_t size)
65190 +static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
65191 {
65192 if (!size)
65193 return 0;
65194 @@ -217,7 +217,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
65195 }
65196
65197 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
65198 -void *__kmalloc(size_t size, gfp_t flags);
65199 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
65200
65201 static __always_inline void *
65202 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
65203 @@ -258,7 +258,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
65204 }
65205 #endif
65206
65207 -static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
65208 +static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
65209 {
65210 unsigned int order = get_order(size);
65211 return kmalloc_order_trace(size, flags, order);
65212 @@ -283,7 +283,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
65213 }
65214
65215 #ifdef CONFIG_NUMA
65216 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
65217 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
65218 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
65219
65220 #ifdef CONFIG_TRACING
65221 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
65222 index de8832d..0147b46 100644
65223 --- a/include/linux/sonet.h
65224 +++ b/include/linux/sonet.h
65225 @@ -61,7 +61,7 @@ struct sonet_stats {
65226 #include <linux/atomic.h>
65227
65228 struct k_sonet_stats {
65229 -#define __HANDLE_ITEM(i) atomic_t i
65230 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
65231 __SONET_ITEMS
65232 #undef __HANDLE_ITEM
65233 };
65234 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
65235 index 523547e..2cb7140 100644
65236 --- a/include/linux/sunrpc/clnt.h
65237 +++ b/include/linux/sunrpc/clnt.h
65238 @@ -174,9 +174,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
65239 {
65240 switch (sap->sa_family) {
65241 case AF_INET:
65242 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
65243 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
65244 case AF_INET6:
65245 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
65246 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
65247 }
65248 return 0;
65249 }
65250 @@ -209,7 +209,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
65251 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
65252 const struct sockaddr *src)
65253 {
65254 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
65255 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
65256 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
65257
65258 dsin->sin_family = ssin->sin_family;
65259 @@ -312,7 +312,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
65260 if (sa->sa_family != AF_INET6)
65261 return 0;
65262
65263 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
65264 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
65265 }
65266
65267 #endif /* __KERNEL__ */
65268 diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h
65269 index dc0c3cc..8503fb6 100644
65270 --- a/include/linux/sunrpc/sched.h
65271 +++ b/include/linux/sunrpc/sched.h
65272 @@ -106,6 +106,7 @@ struct rpc_call_ops {
65273 void (*rpc_count_stats)(struct rpc_task *, void *);
65274 void (*rpc_release)(void *);
65275 };
65276 +typedef struct rpc_call_ops __no_const rpc_call_ops_no_const;
65277
65278 struct rpc_task_setup {
65279 struct rpc_task *task;
65280 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
65281 index 0b8e3e6..33e0a01 100644
65282 --- a/include/linux/sunrpc/svc_rdma.h
65283 +++ b/include/linux/sunrpc/svc_rdma.h
65284 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
65285 extern unsigned int svcrdma_max_requests;
65286 extern unsigned int svcrdma_max_req_size;
65287
65288 -extern atomic_t rdma_stat_recv;
65289 -extern atomic_t rdma_stat_read;
65290 -extern atomic_t rdma_stat_write;
65291 -extern atomic_t rdma_stat_sq_starve;
65292 -extern atomic_t rdma_stat_rq_starve;
65293 -extern atomic_t rdma_stat_rq_poll;
65294 -extern atomic_t rdma_stat_rq_prod;
65295 -extern atomic_t rdma_stat_sq_poll;
65296 -extern atomic_t rdma_stat_sq_prod;
65297 +extern atomic_unchecked_t rdma_stat_recv;
65298 +extern atomic_unchecked_t rdma_stat_read;
65299 +extern atomic_unchecked_t rdma_stat_write;
65300 +extern atomic_unchecked_t rdma_stat_sq_starve;
65301 +extern atomic_unchecked_t rdma_stat_rq_starve;
65302 +extern atomic_unchecked_t rdma_stat_rq_poll;
65303 +extern atomic_unchecked_t rdma_stat_rq_prod;
65304 +extern atomic_unchecked_t rdma_stat_sq_poll;
65305 +extern atomic_unchecked_t rdma_stat_sq_prod;
65306
65307 #define RPCRDMA_VERSION 1
65308
65309 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
65310 index c34b4c8..a65b67d 100644
65311 --- a/include/linux/sysctl.h
65312 +++ b/include/linux/sysctl.h
65313 @@ -155,7 +155,11 @@ enum
65314 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
65315 };
65316
65317 -
65318 +#ifdef CONFIG_PAX_SOFTMODE
65319 +enum {
65320 + PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
65321 +};
65322 +#endif
65323
65324 /* CTL_VM names: */
65325 enum
65326 @@ -948,6 +952,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
65327
65328 extern int proc_dostring(struct ctl_table *, int,
65329 void __user *, size_t *, loff_t *);
65330 +extern int proc_dostring_modpriv(struct ctl_table *, int,
65331 + void __user *, size_t *, loff_t *);
65332 extern int proc_dointvec(struct ctl_table *, int,
65333 void __user *, size_t *, loff_t *);
65334 extern int proc_dointvec_minmax(struct ctl_table *, int,
65335 diff --git a/include/linux/tty.h b/include/linux/tty.h
65336 index 9f47ab5..73da944 100644
65337 --- a/include/linux/tty.h
65338 +++ b/include/linux/tty.h
65339 @@ -225,7 +225,7 @@ struct tty_port {
65340 const struct tty_port_operations *ops; /* Port operations */
65341 spinlock_t lock; /* Lock protecting tty field */
65342 int blocked_open; /* Waiting to open */
65343 - int count; /* Usage count */
65344 + atomic_t count; /* Usage count */
65345 wait_queue_head_t open_wait; /* Open waiters */
65346 wait_queue_head_t close_wait; /* Close waiters */
65347 wait_queue_head_t delta_msr_wait; /* Modem status change */
65348 @@ -525,7 +525,7 @@ extern int tty_port_open(struct tty_port *port,
65349 struct tty_struct *tty, struct file *filp);
65350 static inline int tty_port_users(struct tty_port *port)
65351 {
65352 - return port->count + port->blocked_open;
65353 + return atomic_read(&port->count) + port->blocked_open;
65354 }
65355
65356 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
65357 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
65358 index fb79dd8d..07d4773 100644
65359 --- a/include/linux/tty_ldisc.h
65360 +++ b/include/linux/tty_ldisc.h
65361 @@ -149,7 +149,7 @@ struct tty_ldisc_ops {
65362
65363 struct module *owner;
65364
65365 - int refcount;
65366 + atomic_t refcount;
65367 };
65368
65369 struct tty_ldisc {
65370 diff --git a/include/linux/types.h b/include/linux/types.h
65371 index bf0dd75..a1f23aaa 100644
65372 --- a/include/linux/types.h
65373 +++ b/include/linux/types.h
65374 @@ -220,10 +220,26 @@ typedef struct {
65375 int counter;
65376 } atomic_t;
65377
65378 +#ifdef CONFIG_PAX_REFCOUNT
65379 +typedef struct {
65380 + int counter;
65381 +} atomic_unchecked_t;
65382 +#else
65383 +typedef atomic_t atomic_unchecked_t;
65384 +#endif
65385 +
65386 #ifdef CONFIG_64BIT
65387 typedef struct {
65388 long counter;
65389 } atomic64_t;
65390 +
65391 +#ifdef CONFIG_PAX_REFCOUNT
65392 +typedef struct {
65393 + long counter;
65394 +} atomic64_unchecked_t;
65395 +#else
65396 +typedef atomic64_t atomic64_unchecked_t;
65397 +#endif
65398 #endif
65399
65400 struct list_head {
65401 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
65402 index 5ca0951..ab496a5 100644
65403 --- a/include/linux/uaccess.h
65404 +++ b/include/linux/uaccess.h
65405 @@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
65406 long ret; \
65407 mm_segment_t old_fs = get_fs(); \
65408 \
65409 - set_fs(KERNEL_DS); \
65410 pagefault_disable(); \
65411 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
65412 - pagefault_enable(); \
65413 + set_fs(KERNEL_DS); \
65414 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
65415 set_fs(old_fs); \
65416 + pagefault_enable(); \
65417 ret; \
65418 })
65419
65420 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
65421 index 99c1b4d..bb94261 100644
65422 --- a/include/linux/unaligned/access_ok.h
65423 +++ b/include/linux/unaligned/access_ok.h
65424 @@ -6,32 +6,32 @@
65425
65426 static inline u16 get_unaligned_le16(const void *p)
65427 {
65428 - return le16_to_cpup((__le16 *)p);
65429 + return le16_to_cpup((const __le16 *)p);
65430 }
65431
65432 static inline u32 get_unaligned_le32(const void *p)
65433 {
65434 - return le32_to_cpup((__le32 *)p);
65435 + return le32_to_cpup((const __le32 *)p);
65436 }
65437
65438 static inline u64 get_unaligned_le64(const void *p)
65439 {
65440 - return le64_to_cpup((__le64 *)p);
65441 + return le64_to_cpup((const __le64 *)p);
65442 }
65443
65444 static inline u16 get_unaligned_be16(const void *p)
65445 {
65446 - return be16_to_cpup((__be16 *)p);
65447 + return be16_to_cpup((const __be16 *)p);
65448 }
65449
65450 static inline u32 get_unaligned_be32(const void *p)
65451 {
65452 - return be32_to_cpup((__be32 *)p);
65453 + return be32_to_cpup((const __be32 *)p);
65454 }
65455
65456 static inline u64 get_unaligned_be64(const void *p)
65457 {
65458 - return be64_to_cpup((__be64 *)p);
65459 + return be64_to_cpup((const __be64 *)p);
65460 }
65461
65462 static inline void put_unaligned_le16(u16 val, void *p)
65463 diff --git a/include/linux/usb.h b/include/linux/usb.h
65464 index 30d1ae3..aecd07e 100644
65465 --- a/include/linux/usb.h
65466 +++ b/include/linux/usb.h
65467 @@ -546,7 +546,7 @@ struct usb_device {
65468 struct usb_device **children;
65469
65470 u32 quirks;
65471 - atomic_t urbnum;
65472 + atomic_unchecked_t urbnum;
65473
65474 unsigned long active_duration;
65475
65476 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
65477 index c5d36c6..8478c90 100644
65478 --- a/include/linux/usb/renesas_usbhs.h
65479 +++ b/include/linux/usb/renesas_usbhs.h
65480 @@ -39,7 +39,7 @@ enum {
65481 */
65482 struct renesas_usbhs_driver_callback {
65483 int (*notify_hotplug)(struct platform_device *pdev);
65484 -};
65485 +} __no_const;
65486
65487 /*
65488 * callback functions for platform
65489 @@ -97,7 +97,7 @@ struct renesas_usbhs_platform_callback {
65490 * VBUS control is needed for Host
65491 */
65492 int (*set_vbus)(struct platform_device *pdev, int enable);
65493 -};
65494 +} __no_const;
65495
65496 /*
65497 * parameters for renesas usbhs
65498 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
65499 index 6f8fbcf..8259001 100644
65500 --- a/include/linux/vermagic.h
65501 +++ b/include/linux/vermagic.h
65502 @@ -25,9 +25,35 @@
65503 #define MODULE_ARCH_VERMAGIC ""
65504 #endif
65505
65506 +#ifdef CONFIG_PAX_REFCOUNT
65507 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
65508 +#else
65509 +#define MODULE_PAX_REFCOUNT ""
65510 +#endif
65511 +
65512 +#ifdef CONSTIFY_PLUGIN
65513 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
65514 +#else
65515 +#define MODULE_CONSTIFY_PLUGIN ""
65516 +#endif
65517 +
65518 +#ifdef STACKLEAK_PLUGIN
65519 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
65520 +#else
65521 +#define MODULE_STACKLEAK_PLUGIN ""
65522 +#endif
65523 +
65524 +#ifdef CONFIG_GRKERNSEC
65525 +#define MODULE_GRSEC "GRSEC "
65526 +#else
65527 +#define MODULE_GRSEC ""
65528 +#endif
65529 +
65530 #define VERMAGIC_STRING \
65531 UTS_RELEASE " " \
65532 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
65533 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
65534 - MODULE_ARCH_VERMAGIC
65535 + MODULE_ARCH_VERMAGIC \
65536 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
65537 + MODULE_GRSEC
65538
65539 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
65540 index 6071e91..ca6a489 100644
65541 --- a/include/linux/vmalloc.h
65542 +++ b/include/linux/vmalloc.h
65543 @@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
65544 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
65545 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
65546 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
65547 +
65548 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
65549 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
65550 +#endif
65551 +
65552 /* bits [20..32] reserved for arch specific ioremap internals */
65553
65554 /*
65555 @@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
65556 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
65557 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
65558 unsigned long start, unsigned long end, gfp_t gfp_mask,
65559 - pgprot_t prot, int node, const void *caller);
65560 + pgprot_t prot, int node, const void *caller) __size_overflow(1);
65561 extern void vfree(const void *addr);
65562
65563 extern void *vmap(struct page **pages, unsigned int count,
65564 @@ -124,8 +129,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
65565 extern void free_vm_area(struct vm_struct *area);
65566
65567 /* for /dev/kmem */
65568 -extern long vread(char *buf, char *addr, unsigned long count);
65569 -extern long vwrite(char *buf, char *addr, unsigned long count);
65570 +extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
65571 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
65572
65573 /*
65574 * Internals. Dont't use..
65575 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
65576 index ad2cfd5..74c94ad 100644
65577 --- a/include/linux/vmstat.h
65578 +++ b/include/linux/vmstat.h
65579 @@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
65580 /*
65581 * Zone based page accounting with per cpu differentials.
65582 */
65583 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
65584 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
65585
65586 static inline void zone_page_state_add(long x, struct zone *zone,
65587 enum zone_stat_item item)
65588 {
65589 - atomic_long_add(x, &zone->vm_stat[item]);
65590 - atomic_long_add(x, &vm_stat[item]);
65591 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
65592 + atomic_long_add_unchecked(x, &vm_stat[item]);
65593 }
65594
65595 static inline unsigned long global_page_state(enum zone_stat_item item)
65596 {
65597 - long x = atomic_long_read(&vm_stat[item]);
65598 + long x = atomic_long_read_unchecked(&vm_stat[item]);
65599 #ifdef CONFIG_SMP
65600 if (x < 0)
65601 x = 0;
65602 @@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
65603 static inline unsigned long zone_page_state(struct zone *zone,
65604 enum zone_stat_item item)
65605 {
65606 - long x = atomic_long_read(&zone->vm_stat[item]);
65607 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
65608 #ifdef CONFIG_SMP
65609 if (x < 0)
65610 x = 0;
65611 @@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
65612 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
65613 enum zone_stat_item item)
65614 {
65615 - long x = atomic_long_read(&zone->vm_stat[item]);
65616 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
65617
65618 #ifdef CONFIG_SMP
65619 int cpu;
65620 @@ -216,8 +216,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
65621
65622 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
65623 {
65624 - atomic_long_inc(&zone->vm_stat[item]);
65625 - atomic_long_inc(&vm_stat[item]);
65626 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
65627 + atomic_long_inc_unchecked(&vm_stat[item]);
65628 }
65629
65630 static inline void __inc_zone_page_state(struct page *page,
65631 @@ -228,8 +228,8 @@ static inline void __inc_zone_page_state(struct page *page,
65632
65633 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
65634 {
65635 - atomic_long_dec(&zone->vm_stat[item]);
65636 - atomic_long_dec(&vm_stat[item]);
65637 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
65638 + atomic_long_dec_unchecked(&vm_stat[item]);
65639 }
65640
65641 static inline void __dec_zone_page_state(struct page *page,
65642 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
65643 index e5d1220..ef6e406 100644
65644 --- a/include/linux/xattr.h
65645 +++ b/include/linux/xattr.h
65646 @@ -57,6 +57,11 @@
65647 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
65648 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
65649
65650 +/* User namespace */
65651 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
65652 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
65653 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
65654 +
65655 #ifdef __KERNEL__
65656
65657 #include <linux/types.h>
65658 diff --git a/include/media/saa7146_vv.h b/include/media/saa7146_vv.h
65659 index 944ecdf..a3994fc 100644
65660 --- a/include/media/saa7146_vv.h
65661 +++ b/include/media/saa7146_vv.h
65662 @@ -161,8 +161,8 @@ struct saa7146_ext_vv
65663 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
65664
65665 /* the extension can override this */
65666 - struct v4l2_ioctl_ops vid_ops;
65667 - struct v4l2_ioctl_ops vbi_ops;
65668 + v4l2_ioctl_ops_no_const vid_ops;
65669 + v4l2_ioctl_ops_no_const vbi_ops;
65670 /* pointer to the saa7146 core ops */
65671 const struct v4l2_ioctl_ops *core_ops;
65672
65673 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
65674 index 5c416cd..20021aa 100644
65675 --- a/include/media/v4l2-dev.h
65676 +++ b/include/media/v4l2-dev.h
65677 @@ -73,7 +73,8 @@ struct v4l2_file_operations {
65678 int (*mmap) (struct file *, struct vm_area_struct *);
65679 int (*open) (struct file *);
65680 int (*release) (struct file *);
65681 -};
65682 +} __do_const;
65683 +typedef struct v4l2_file_operations __no_const v4l2_file_operations_no_const;
65684
65685 /*
65686 * Newer version of video_device, handled by videodev2.c
65687 diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
65688 index e614c9c..20602b7 100644
65689 --- a/include/media/v4l2-ioctl.h
65690 +++ b/include/media/v4l2-ioctl.h
65691 @@ -289,7 +289,7 @@ struct v4l2_ioctl_ops {
65692 long (*vidioc_default) (struct file *file, void *fh,
65693 bool valid_prio, int cmd, void *arg);
65694 };
65695 -
65696 +typedef struct v4l2_ioctl_ops __no_const v4l2_ioctl_ops_no_const;
65697
65698 /* v4l debugging and diagnostics */
65699
65700 diff --git a/include/net/caif/caif_hsi.h b/include/net/caif/caif_hsi.h
65701 index bcb9cc3..f4ec722e 100644
65702 --- a/include/net/caif/caif_hsi.h
65703 +++ b/include/net/caif/caif_hsi.h
65704 @@ -98,7 +98,7 @@ struct cfhsi_cb_ops {
65705 void (*rx_done_cb) (struct cfhsi_cb_ops *drv);
65706 void (*wake_up_cb) (struct cfhsi_cb_ops *drv);
65707 void (*wake_down_cb) (struct cfhsi_cb_ops *drv);
65708 -};
65709 +} __no_const;
65710
65711 /* Structure implemented by HSI device. */
65712 struct cfhsi_ops {
65713 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
65714 index 9e5425b..8136ffc 100644
65715 --- a/include/net/caif/cfctrl.h
65716 +++ b/include/net/caif/cfctrl.h
65717 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
65718 void (*radioset_rsp)(void);
65719 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
65720 struct cflayer *client_layer);
65721 -};
65722 +} __no_const;
65723
65724 /* Link Setup Parameters for CAIF-Links. */
65725 struct cfctrl_link_param {
65726 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
65727 struct cfctrl {
65728 struct cfsrvl serv;
65729 struct cfctrl_rsp res;
65730 - atomic_t req_seq_no;
65731 - atomic_t rsp_seq_no;
65732 + atomic_unchecked_t req_seq_no;
65733 + atomic_unchecked_t rsp_seq_no;
65734 struct list_head list;
65735 /* Protects from simultaneous access to first_req list */
65736 spinlock_t info_list_lock;
65737 diff --git a/include/net/flow.h b/include/net/flow.h
65738 index 628e11b..4c475df 100644
65739 --- a/include/net/flow.h
65740 +++ b/include/net/flow.h
65741 @@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
65742
65743 extern void flow_cache_flush(void);
65744 extern void flow_cache_flush_deferred(void);
65745 -extern atomic_t flow_cache_genid;
65746 +extern atomic_unchecked_t flow_cache_genid;
65747
65748 #endif
65749 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
65750 index 53f464d..ba76aaa 100644
65751 --- a/include/net/inetpeer.h
65752 +++ b/include/net/inetpeer.h
65753 @@ -47,8 +47,8 @@ struct inet_peer {
65754 */
65755 union {
65756 struct {
65757 - atomic_t rid; /* Frag reception counter */
65758 - atomic_t ip_id_count; /* IP ID for the next packet */
65759 + atomic_unchecked_t rid; /* Frag reception counter */
65760 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
65761 };
65762 struct rcu_head rcu;
65763 struct inet_peer *gc_next;
65764 @@ -182,11 +182,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
65765 more++;
65766 inet_peer_refcheck(p);
65767 do {
65768 - old = atomic_read(&p->ip_id_count);
65769 + old = atomic_read_unchecked(&p->ip_id_count);
65770 new = old + more;
65771 if (!new)
65772 new = 1;
65773 - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
65774 + } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
65775 return new;
65776 }
65777
65778 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
65779 index 9497be1..5a4fafe 100644
65780 --- a/include/net/ip_fib.h
65781 +++ b/include/net/ip_fib.h
65782 @@ -169,7 +169,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
65783
65784 #define FIB_RES_SADDR(net, res) \
65785 ((FIB_RES_NH(res).nh_saddr_genid == \
65786 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
65787 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
65788 FIB_RES_NH(res).nh_saddr : \
65789 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
65790 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
65791 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
65792 index 95374d1..2300e36 100644
65793 --- a/include/net/ip_vs.h
65794 +++ b/include/net/ip_vs.h
65795 @@ -510,7 +510,7 @@ struct ip_vs_conn {
65796 struct ip_vs_conn *control; /* Master control connection */
65797 atomic_t n_control; /* Number of controlled ones */
65798 struct ip_vs_dest *dest; /* real server */
65799 - atomic_t in_pkts; /* incoming packet counter */
65800 + atomic_unchecked_t in_pkts; /* incoming packet counter */
65801
65802 /* packet transmitter for different forwarding methods. If it
65803 mangles the packet, it must return NF_DROP or better NF_STOLEN,
65804 @@ -648,7 +648,7 @@ struct ip_vs_dest {
65805 __be16 port; /* port number of the server */
65806 union nf_inet_addr addr; /* IP address of the server */
65807 volatile unsigned int flags; /* dest status flags */
65808 - atomic_t conn_flags; /* flags to copy to conn */
65809 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
65810 atomic_t weight; /* server weight */
65811
65812 atomic_t refcnt; /* reference counter */
65813 diff --git a/include/net/irda/ircomm_core.h b/include/net/irda/ircomm_core.h
65814 index 69b610a..fe3962c 100644
65815 --- a/include/net/irda/ircomm_core.h
65816 +++ b/include/net/irda/ircomm_core.h
65817 @@ -51,7 +51,7 @@ typedef struct {
65818 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
65819 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
65820 struct ircomm_info *);
65821 -} call_t;
65822 +} __no_const call_t;
65823
65824 struct ircomm_cb {
65825 irda_queue_t queue;
65826 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
65827 index 59ba38bc..d515662 100644
65828 --- a/include/net/irda/ircomm_tty.h
65829 +++ b/include/net/irda/ircomm_tty.h
65830 @@ -35,6 +35,7 @@
65831 #include <linux/termios.h>
65832 #include <linux/timer.h>
65833 #include <linux/tty.h> /* struct tty_struct */
65834 +#include <asm/local.h>
65835
65836 #include <net/irda/irias_object.h>
65837 #include <net/irda/ircomm_core.h>
65838 @@ -105,8 +106,8 @@ struct ircomm_tty_cb {
65839 unsigned short close_delay;
65840 unsigned short closing_wait; /* time to wait before closing */
65841
65842 - int open_count;
65843 - int blocked_open; /* # of blocked opens */
65844 + local_t open_count;
65845 + local_t blocked_open; /* # of blocked opens */
65846
65847 /* Protect concurent access to :
65848 * o self->open_count
65849 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
65850 index cc7c197..9f2da2a 100644
65851 --- a/include/net/iucv/af_iucv.h
65852 +++ b/include/net/iucv/af_iucv.h
65853 @@ -141,7 +141,7 @@ struct iucv_sock {
65854 struct iucv_sock_list {
65855 struct hlist_head head;
65856 rwlock_t lock;
65857 - atomic_t autobind_name;
65858 + atomic_unchecked_t autobind_name;
65859 };
65860
65861 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
65862 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
65863 index 344d898..2ae1302 100644
65864 --- a/include/net/neighbour.h
65865 +++ b/include/net/neighbour.h
65866 @@ -123,7 +123,7 @@ struct neigh_ops {
65867 void (*error_report)(struct neighbour *, struct sk_buff *);
65868 int (*output)(struct neighbour *, struct sk_buff *);
65869 int (*connected_output)(struct neighbour *, struct sk_buff *);
65870 -};
65871 +} __do_const;
65872
65873 struct pneigh_entry {
65874 struct pneigh_entry *next;
65875 diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
65876 index fd87963..312a11f 100644
65877 --- a/include/net/net_namespace.h
65878 +++ b/include/net/net_namespace.h
65879 @@ -102,7 +102,7 @@ struct net {
65880 #endif
65881 struct netns_ipvs *ipvs;
65882 struct sock *diag_nlsk;
65883 - atomic_t rt_genid;
65884 + atomic_unchecked_t rt_genid;
65885 };
65886
65887
65888 @@ -303,12 +303,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
65889
65890 static inline int rt_genid(struct net *net)
65891 {
65892 - return atomic_read(&net->rt_genid);
65893 + return atomic_read_unchecked(&net->rt_genid);
65894 }
65895
65896 static inline void rt_genid_bump(struct net *net)
65897 {
65898 - atomic_inc(&net->rt_genid);
65899 + atomic_inc_unchecked(&net->rt_genid);
65900 }
65901
65902 #endif /* __NET_NET_NAMESPACE_H */
65903 diff --git a/include/net/netdma.h b/include/net/netdma.h
65904 index 8ba8ce2..99b7fff 100644
65905 --- a/include/net/netdma.h
65906 +++ b/include/net/netdma.h
65907 @@ -24,7 +24,7 @@
65908 #include <linux/dmaengine.h>
65909 #include <linux/skbuff.h>
65910
65911 -int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
65912 +int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
65913 struct sk_buff *skb, int offset, struct iovec *to,
65914 size_t len, struct dma_pinned_list *pinned_list);
65915
65916 diff --git a/include/net/netlink.h b/include/net/netlink.h
65917 index 785f37a..c81dc0c 100644
65918 --- a/include/net/netlink.h
65919 +++ b/include/net/netlink.h
65920 @@ -520,7 +520,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
65921 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
65922 {
65923 if (mark)
65924 - skb_trim(skb, (unsigned char *) mark - skb->data);
65925 + skb_trim(skb, (const unsigned char *) mark - skb->data);
65926 }
65927
65928 /**
65929 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
65930 index eb24dbc..567d6ed 100644
65931 --- a/include/net/netns/ipv4.h
65932 +++ b/include/net/netns/ipv4.h
65933 @@ -65,7 +65,7 @@ struct netns_ipv4 {
65934 unsigned int sysctl_ping_group_range[2];
65935 long sysctl_tcp_mem[3];
65936
65937 - atomic_t dev_addr_genid;
65938 + atomic_unchecked_t dev_addr_genid;
65939
65940 #ifdef CONFIG_IP_MROUTE
65941 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
65942 diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
65943 index ff49964..1411fee 100644
65944 --- a/include/net/sctp/sctp.h
65945 +++ b/include/net/sctp/sctp.h
65946 @@ -320,9 +320,9 @@ do { \
65947
65948 #else /* SCTP_DEBUG */
65949
65950 -#define SCTP_DEBUG_PRINTK(whatever...)
65951 -#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
65952 -#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
65953 +#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
65954 +#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
65955 +#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
65956 #define SCTP_ENABLE_DEBUG
65957 #define SCTP_DISABLE_DEBUG
65958 #define SCTP_ASSERT(expr, str, func)
65959 diff --git a/include/net/sock.h b/include/net/sock.h
65960 index adb7da2..1100002 100644
65961 --- a/include/net/sock.h
65962 +++ b/include/net/sock.h
65963 @@ -305,7 +305,7 @@ struct sock {
65964 #ifdef CONFIG_RPS
65965 __u32 sk_rxhash;
65966 #endif
65967 - atomic_t sk_drops;
65968 + atomic_unchecked_t sk_drops;
65969 int sk_rcvbuf;
65970
65971 struct sk_filter __rcu *sk_filter;
65972 @@ -1764,7 +1764,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
65973 }
65974
65975 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
65976 - char __user *from, char *to,
65977 + char __user *from, unsigned char *to,
65978 int copy, int offset)
65979 {
65980 if (skb->ip_summed == CHECKSUM_NONE) {
65981 @@ -2023,7 +2023,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
65982 }
65983 }
65984
65985 -struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
65986 +struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
65987
65988 static inline struct page *sk_stream_alloc_page(struct sock *sk)
65989 {
65990 diff --git a/include/net/tcp.h b/include/net/tcp.h
65991 index 1f000ff..e5a8dfb 100644
65992 --- a/include/net/tcp.h
65993 +++ b/include/net/tcp.h
65994 @@ -508,7 +508,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
65995 extern void tcp_xmit_retransmit_queue(struct sock *);
65996 extern void tcp_simple_retransmit(struct sock *);
65997 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
65998 -extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
65999 +extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
66000
66001 extern void tcp_send_probe0(struct sock *);
66002 extern void tcp_send_partial(struct sock *);
66003 @@ -677,8 +677,8 @@ struct tcp_skb_cb {
66004 struct inet6_skb_parm h6;
66005 #endif
66006 } header; /* For incoming frames */
66007 - __u32 seq; /* Starting sequence number */
66008 - __u32 end_seq; /* SEQ + FIN + SYN + datalen */
66009 + __u32 seq __intentional_overflow(0); /* Starting sequence number */
66010 + __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
66011 __u32 when; /* used to compute rtt's */
66012 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
66013
66014 @@ -692,7 +692,7 @@ struct tcp_skb_cb {
66015
66016 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
66017 /* 1 byte hole */
66018 - __u32 ack_seq; /* Sequence number ACK'd */
66019 + __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
66020 };
66021
66022 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
66023 @@ -1502,7 +1502,7 @@ struct tcp_seq_afinfo {
66024 char *name;
66025 sa_family_t family;
66026 const struct file_operations *seq_fops;
66027 - struct seq_operations seq_ops;
66028 + seq_operations_no_const seq_ops;
66029 };
66030
66031 struct tcp_iter_state {
66032 diff --git a/include/net/udp.h b/include/net/udp.h
66033 index 065f379..b661b40 100644
66034 --- a/include/net/udp.h
66035 +++ b/include/net/udp.h
66036 @@ -244,7 +244,7 @@ struct udp_seq_afinfo {
66037 sa_family_t family;
66038 struct udp_table *udp_table;
66039 const struct file_operations *seq_fops;
66040 - struct seq_operations seq_ops;
66041 + seq_operations_no_const seq_ops;
66042 };
66043
66044 struct udp_iter_state {
66045 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
66046 index 639dd13..15b206c 100644
66047 --- a/include/net/xfrm.h
66048 +++ b/include/net/xfrm.h
66049 @@ -514,7 +514,7 @@ struct xfrm_policy {
66050 struct timer_list timer;
66051
66052 struct flow_cache_object flo;
66053 - atomic_t genid;
66054 + atomic_unchecked_t genid;
66055 u32 priority;
66056 u32 index;
66057 struct xfrm_mark mark;
66058 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
66059 index 1a046b1..ee0bef0 100644
66060 --- a/include/rdma/iw_cm.h
66061 +++ b/include/rdma/iw_cm.h
66062 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
66063 int backlog);
66064
66065 int (*destroy_listen)(struct iw_cm_id *cm_id);
66066 -};
66067 +} __no_const;
66068
66069 /**
66070 * iw_create_cm_id - Create an IW CM identifier.
66071 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
66072 index 399162b..b337f1a 100644
66073 --- a/include/scsi/libfc.h
66074 +++ b/include/scsi/libfc.h
66075 @@ -762,6 +762,7 @@ struct libfc_function_template {
66076 */
66077 void (*disc_stop_final) (struct fc_lport *);
66078 };
66079 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
66080
66081 /**
66082 * struct fc_disc - Discovery context
66083 @@ -866,7 +867,7 @@ struct fc_lport {
66084 struct fc_vport *vport;
66085
66086 /* Operational Information */
66087 - struct libfc_function_template tt;
66088 + libfc_function_template_no_const tt;
66089 u8 link_up;
66090 u8 qfull;
66091 enum fc_lport_state state;
66092 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
66093 index 9895f69..f1418f0 100644
66094 --- a/include/scsi/scsi_device.h
66095 +++ b/include/scsi/scsi_device.h
66096 @@ -166,9 +166,9 @@ struct scsi_device {
66097 unsigned int max_device_blocked; /* what device_blocked counts down from */
66098 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
66099
66100 - atomic_t iorequest_cnt;
66101 - atomic_t iodone_cnt;
66102 - atomic_t ioerr_cnt;
66103 + atomic_unchecked_t iorequest_cnt;
66104 + atomic_unchecked_t iodone_cnt;
66105 + atomic_unchecked_t ioerr_cnt;
66106
66107 struct device sdev_gendev,
66108 sdev_dev;
66109 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
66110 index b797e8f..8e2c3aa 100644
66111 --- a/include/scsi/scsi_transport_fc.h
66112 +++ b/include/scsi/scsi_transport_fc.h
66113 @@ -751,7 +751,8 @@ struct fc_function_template {
66114 unsigned long show_host_system_hostname:1;
66115
66116 unsigned long disable_target_scan:1;
66117 -};
66118 +} __do_const;
66119 +typedef struct fc_function_template __no_const fc_function_template_no_const;
66120
66121
66122 /**
66123 diff --git a/include/sound/ak4xxx-adda.h b/include/sound/ak4xxx-adda.h
66124 index 030b87c..98a6954 100644
66125 --- a/include/sound/ak4xxx-adda.h
66126 +++ b/include/sound/ak4xxx-adda.h
66127 @@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
66128 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
66129 unsigned char val);
66130 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
66131 -};
66132 +} __no_const;
66133
66134 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
66135
66136 diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h
66137 index 8c05e47..2b5df97 100644
66138 --- a/include/sound/hwdep.h
66139 +++ b/include/sound/hwdep.h
66140 @@ -49,7 +49,7 @@ struct snd_hwdep_ops {
66141 struct snd_hwdep_dsp_status *status);
66142 int (*dsp_load)(struct snd_hwdep *hw,
66143 struct snd_hwdep_dsp_image *image);
66144 -};
66145 +} __no_const;
66146
66147 struct snd_hwdep {
66148 struct snd_card *card;
66149 diff --git a/include/sound/info.h b/include/sound/info.h
66150 index 9ca1a49..aba1728 100644
66151 --- a/include/sound/info.h
66152 +++ b/include/sound/info.h
66153 @@ -44,7 +44,7 @@ struct snd_info_entry_text {
66154 struct snd_info_buffer *buffer);
66155 void (*write)(struct snd_info_entry *entry,
66156 struct snd_info_buffer *buffer);
66157 -};
66158 +} __no_const;
66159
66160 struct snd_info_entry_ops {
66161 int (*open)(struct snd_info_entry *entry,
66162 diff --git a/include/sound/pcm.h b/include/sound/pcm.h
66163 index cdca2ab..10bbe05 100644
66164 --- a/include/sound/pcm.h
66165 +++ b/include/sound/pcm.h
66166 @@ -81,6 +81,7 @@ struct snd_pcm_ops {
66167 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
66168 int (*ack)(struct snd_pcm_substream *substream);
66169 };
66170 +typedef struct snd_pcm_ops __no_const snd_pcm_ops_no_const;
66171
66172 /*
66173 *
66174 diff --git a/include/sound/sb16_csp.h b/include/sound/sb16_csp.h
66175 index af1b49e..a5d55a5 100644
66176 --- a/include/sound/sb16_csp.h
66177 +++ b/include/sound/sb16_csp.h
66178 @@ -146,7 +146,7 @@ struct snd_sb_csp_ops {
66179 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
66180 int (*csp_stop) (struct snd_sb_csp * p);
66181 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
66182 -};
66183 +} __no_const;
66184
66185 /*
66186 * CSP private data
66187 diff --git a/include/sound/soc.h b/include/sound/soc.h
66188 index e063380..e8077d5 100644
66189 --- a/include/sound/soc.h
66190 +++ b/include/sound/soc.h
66191 @@ -801,7 +801,7 @@ struct snd_soc_platform_driver {
66192 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
66193 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
66194 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
66195 -};
66196 +} __do_const;
66197
66198 struct snd_soc_platform {
66199 const char *name;
66200 @@ -1016,7 +1016,7 @@ struct snd_soc_pcm_runtime {
66201 struct snd_soc_dai_link *dai_link;
66202 struct mutex pcm_mutex;
66203 enum snd_soc_pcm_subclass pcm_subclass;
66204 - struct snd_pcm_ops ops;
66205 + snd_pcm_ops_no_const ops;
66206
66207 unsigned int dev_registered:1;
66208
66209 diff --git a/include/sound/tea575x-tuner.h b/include/sound/tea575x-tuner.h
66210 index fe8590c..aaed363 100644
66211 --- a/include/sound/tea575x-tuner.h
66212 +++ b/include/sound/tea575x-tuner.h
66213 @@ -48,7 +48,7 @@ struct snd_tea575x_ops {
66214
66215 struct snd_tea575x {
66216 struct v4l2_device *v4l2_dev;
66217 - struct v4l2_file_operations fops;
66218 + v4l2_file_operations_no_const fops;
66219 struct video_device vd; /* video device */
66220 int radio_nr; /* radio_nr */
66221 bool tea5759; /* 5759 chip is present */
66222 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
66223 index 5be8937..a8e46e9 100644
66224 --- a/include/target/target_core_base.h
66225 +++ b/include/target/target_core_base.h
66226 @@ -434,7 +434,7 @@ struct t10_reservation_ops {
66227 int (*t10_seq_non_holder)(struct se_cmd *, unsigned char *, u32);
66228 int (*t10_pr_register)(struct se_cmd *);
66229 int (*t10_pr_clear)(struct se_cmd *);
66230 -};
66231 +} __no_const;
66232
66233 struct t10_reservation {
66234 /* Reservation effects all target ports */
66235 @@ -758,7 +758,7 @@ struct se_device {
66236 spinlock_t stats_lock;
66237 /* Active commands on this virtual SE device */
66238 atomic_t simple_cmds;
66239 - atomic_t dev_ordered_id;
66240 + atomic_unchecked_t dev_ordered_id;
66241 atomic_t dev_ordered_sync;
66242 atomic_t dev_qf_count;
66243 struct se_obj dev_obj;
66244 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
66245 new file mode 100644
66246 index 0000000..2efe49d
66247 --- /dev/null
66248 +++ b/include/trace/events/fs.h
66249 @@ -0,0 +1,53 @@
66250 +#undef TRACE_SYSTEM
66251 +#define TRACE_SYSTEM fs
66252 +
66253 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
66254 +#define _TRACE_FS_H
66255 +
66256 +#include <linux/fs.h>
66257 +#include <linux/tracepoint.h>
66258 +
66259 +TRACE_EVENT(do_sys_open,
66260 +
66261 + TP_PROTO(char *filename, int flags, int mode),
66262 +
66263 + TP_ARGS(filename, flags, mode),
66264 +
66265 + TP_STRUCT__entry(
66266 + __string( filename, filename )
66267 + __field( int, flags )
66268 + __field( int, mode )
66269 + ),
66270 +
66271 + TP_fast_assign(
66272 + __assign_str(filename, filename);
66273 + __entry->flags = flags;
66274 + __entry->mode = mode;
66275 + ),
66276 +
66277 + TP_printk("\"%s\" %x %o",
66278 + __get_str(filename), __entry->flags, __entry->mode)
66279 +);
66280 +
66281 +TRACE_EVENT(open_exec,
66282 +
66283 + TP_PROTO(const char *filename),
66284 +
66285 + TP_ARGS(filename),
66286 +
66287 + TP_STRUCT__entry(
66288 + __string( filename, filename )
66289 + ),
66290 +
66291 + TP_fast_assign(
66292 + __assign_str(filename, filename);
66293 + ),
66294 +
66295 + TP_printk("\"%s\"",
66296 + __get_str(filename))
66297 +);
66298 +
66299 +#endif /* _TRACE_FS_H */
66300 +
66301 +/* This part must be outside protection */
66302 +#include <trace/define_trace.h>
66303 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
66304 index 1c09820..7f5ec79 100644
66305 --- a/include/trace/events/irq.h
66306 +++ b/include/trace/events/irq.h
66307 @@ -36,7 +36,7 @@ struct softirq_action;
66308 */
66309 TRACE_EVENT(irq_handler_entry,
66310
66311 - TP_PROTO(int irq, struct irqaction *action),
66312 + TP_PROTO(int irq, const struct irqaction *action),
66313
66314 TP_ARGS(irq, action),
66315
66316 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
66317 */
66318 TRACE_EVENT(irq_handler_exit,
66319
66320 - TP_PROTO(int irq, struct irqaction *action, int ret),
66321 + TP_PROTO(int irq, const struct irqaction *action, int ret),
66322
66323 TP_ARGS(irq, action, ret),
66324
66325 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
66326 index f9466fa..f4e2b81 100644
66327 --- a/include/video/udlfb.h
66328 +++ b/include/video/udlfb.h
66329 @@ -53,10 +53,10 @@ struct dlfb_data {
66330 u32 pseudo_palette[256];
66331 int blank_mode; /*one of FB_BLANK_ */
66332 /* blit-only rendering path metrics, exposed through sysfs */
66333 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
66334 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
66335 - atomic_t bytes_sent; /* to usb, after compression including overhead */
66336 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
66337 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
66338 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
66339 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
66340 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
66341 };
66342
66343 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
66344 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
66345 index 0993a22..32ba2fe 100644
66346 --- a/include/video/uvesafb.h
66347 +++ b/include/video/uvesafb.h
66348 @@ -177,6 +177,7 @@ struct uvesafb_par {
66349 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
66350 u8 pmi_setpal; /* PMI for palette changes */
66351 u16 *pmi_base; /* protected mode interface location */
66352 + u8 *pmi_code; /* protected mode code location */
66353 void *pmi_start;
66354 void *pmi_pal;
66355 u8 *vbe_state_orig; /*
66356 diff --git a/init/Kconfig b/init/Kconfig
66357 index af6c7f8..5c188f8 100644
66358 --- a/init/Kconfig
66359 +++ b/init/Kconfig
66360 @@ -850,6 +850,7 @@ endif # CGROUPS
66361
66362 config CHECKPOINT_RESTORE
66363 bool "Checkpoint/restore support" if EXPERT
66364 + depends on !GRKERNSEC
66365 default n
66366 help
66367 Enables additional kernel features in a sake of checkpoint/restore.
66368 @@ -1029,6 +1030,7 @@ config UIDGID_CONVERTED
66369 # Security modules
66370 depends on SECURITY_TOMOYO = n
66371 depends on SECURITY_APPARMOR = n
66372 + depends on GRKERNSEC = n
66373
66374 config UIDGID_STRICT_TYPE_CHECKS
66375 bool "Require conversions between uid/gids and their internal representation"
66376 @@ -1416,7 +1418,7 @@ config SLUB_DEBUG
66377
66378 config COMPAT_BRK
66379 bool "Disable heap randomization"
66380 - default y
66381 + default n
66382 help
66383 Randomizing heap placement makes heap exploits harder, but it
66384 also breaks ancient binaries (including anything libc5 based).
66385 @@ -1599,7 +1601,7 @@ config INIT_ALL_POSSIBLE
66386 config STOP_MACHINE
66387 bool
66388 default y
66389 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
66390 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
66391 help
66392 Need stop_machine() primitive.
66393
66394 diff --git a/init/Makefile b/init/Makefile
66395 index 7bc47ee..6da2dc7 100644
66396 --- a/init/Makefile
66397 +++ b/init/Makefile
66398 @@ -2,6 +2,9 @@
66399 # Makefile for the linux kernel.
66400 #
66401
66402 +ccflags-y := $(GCC_PLUGINS_CFLAGS)
66403 +asflags-y := $(GCC_PLUGINS_AFLAGS)
66404 +
66405 obj-y := main.o version.o mounts.o
66406 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
66407 obj-y += noinitramfs.o
66408 diff --git a/init/do_mounts.c b/init/do_mounts.c
66409 index d3f0aee..c9322f5 100644
66410 --- a/init/do_mounts.c
66411 +++ b/init/do_mounts.c
66412 @@ -336,11 +336,11 @@ static void __init get_fs_names(char *page)
66413 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
66414 {
66415 struct super_block *s;
66416 - int err = sys_mount(name, "/root", fs, flags, data);
66417 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
66418 if (err)
66419 return err;
66420
66421 - sys_chdir("/root");
66422 + sys_chdir((const char __force_user *)"/root");
66423 s = current->fs->pwd.dentry->d_sb;
66424 ROOT_DEV = s->s_dev;
66425 printk(KERN_INFO
66426 @@ -460,18 +460,18 @@ void __init change_floppy(char *fmt, ...)
66427 va_start(args, fmt);
66428 vsprintf(buf, fmt, args);
66429 va_end(args);
66430 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
66431 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
66432 if (fd >= 0) {
66433 sys_ioctl(fd, FDEJECT, 0);
66434 sys_close(fd);
66435 }
66436 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
66437 - fd = sys_open("/dev/console", O_RDWR, 0);
66438 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
66439 if (fd >= 0) {
66440 sys_ioctl(fd, TCGETS, (long)&termios);
66441 termios.c_lflag &= ~ICANON;
66442 sys_ioctl(fd, TCSETSF, (long)&termios);
66443 - sys_read(fd, &c, 1);
66444 + sys_read(fd, (char __user *)&c, 1);
66445 termios.c_lflag |= ICANON;
66446 sys_ioctl(fd, TCSETSF, (long)&termios);
66447 sys_close(fd);
66448 @@ -565,6 +565,6 @@ void __init prepare_namespace(void)
66449 mount_root();
66450 out:
66451 devtmpfs_mount("dev");
66452 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
66453 - sys_chroot(".");
66454 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
66455 + sys_chroot((const char __force_user *)".");
66456 }
66457 diff --git a/init/do_mounts.h b/init/do_mounts.h
66458 index f5b978a..69dbfe8 100644
66459 --- a/init/do_mounts.h
66460 +++ b/init/do_mounts.h
66461 @@ -15,15 +15,15 @@ extern int root_mountflags;
66462
66463 static inline int create_dev(char *name, dev_t dev)
66464 {
66465 - sys_unlink(name);
66466 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
66467 + sys_unlink((char __force_user *)name);
66468 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
66469 }
66470
66471 #if BITS_PER_LONG == 32
66472 static inline u32 bstat(char *name)
66473 {
66474 struct stat64 stat;
66475 - if (sys_stat64(name, &stat) != 0)
66476 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
66477 return 0;
66478 if (!S_ISBLK(stat.st_mode))
66479 return 0;
66480 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
66481 static inline u32 bstat(char *name)
66482 {
66483 struct stat stat;
66484 - if (sys_newstat(name, &stat) != 0)
66485 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
66486 return 0;
66487 if (!S_ISBLK(stat.st_mode))
66488 return 0;
66489 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
66490 index 135959a2..28a3f43 100644
66491 --- a/init/do_mounts_initrd.c
66492 +++ b/init/do_mounts_initrd.c
66493 @@ -53,13 +53,13 @@ static void __init handle_initrd(void)
66494 create_dev("/dev/root.old", Root_RAM0);
66495 /* mount initrd on rootfs' /root */
66496 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
66497 - sys_mkdir("/old", 0700);
66498 - root_fd = sys_open("/", 0, 0);
66499 - old_fd = sys_open("/old", 0, 0);
66500 + sys_mkdir((const char __force_user *)"/old", 0700);
66501 + root_fd = sys_open((const char __force_user *)"/", 0, 0);
66502 + old_fd = sys_open((const char __force_user *)"/old", 0, 0);
66503 /* move initrd over / and chdir/chroot in initrd root */
66504 - sys_chdir("/root");
66505 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
66506 - sys_chroot(".");
66507 + sys_chdir((const char __force_user *)"/root");
66508 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
66509 + sys_chroot((const char __force_user *)".");
66510
66511 /*
66512 * In case that a resume from disk is carried out by linuxrc or one of
66513 @@ -76,15 +76,15 @@ static void __init handle_initrd(void)
66514
66515 /* move initrd to rootfs' /old */
66516 sys_fchdir(old_fd);
66517 - sys_mount("/", ".", NULL, MS_MOVE, NULL);
66518 + sys_mount((char __force_user *)"/", (char __force_user *)".", NULL, MS_MOVE, NULL);
66519 /* switch root and cwd back to / of rootfs */
66520 sys_fchdir(root_fd);
66521 - sys_chroot(".");
66522 + sys_chroot((const char __force_user *)".");
66523 sys_close(old_fd);
66524 sys_close(root_fd);
66525
66526 if (new_decode_dev(real_root_dev) == Root_RAM0) {
66527 - sys_chdir("/old");
66528 + sys_chdir((const char __force_user *)"/old");
66529 return;
66530 }
66531
66532 @@ -92,17 +92,17 @@ static void __init handle_initrd(void)
66533 mount_root();
66534
66535 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
66536 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
66537 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
66538 if (!error)
66539 printk("okay\n");
66540 else {
66541 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
66542 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
66543 if (error == -ENOENT)
66544 printk("/initrd does not exist. Ignored.\n");
66545 else
66546 printk("failed\n");
66547 printk(KERN_NOTICE "Unmounting old root\n");
66548 - sys_umount("/old", MNT_DETACH);
66549 + sys_umount((char __force_user *)"/old", MNT_DETACH);
66550 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
66551 if (fd < 0) {
66552 error = fd;
66553 @@ -125,11 +125,11 @@ int __init initrd_load(void)
66554 * mounted in the normal path.
66555 */
66556 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
66557 - sys_unlink("/initrd.image");
66558 + sys_unlink((const char __force_user *)"/initrd.image");
66559 handle_initrd();
66560 return 1;
66561 }
66562 }
66563 - sys_unlink("/initrd.image");
66564 + sys_unlink((const char __force_user *)"/initrd.image");
66565 return 0;
66566 }
66567 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
66568 index 8cb6db5..d729f50 100644
66569 --- a/init/do_mounts_md.c
66570 +++ b/init/do_mounts_md.c
66571 @@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
66572 partitioned ? "_d" : "", minor,
66573 md_setup_args[ent].device_names);
66574
66575 - fd = sys_open(name, 0, 0);
66576 + fd = sys_open((char __force_user *)name, 0, 0);
66577 if (fd < 0) {
66578 printk(KERN_ERR "md: open failed - cannot start "
66579 "array %s\n", name);
66580 @@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
66581 * array without it
66582 */
66583 sys_close(fd);
66584 - fd = sys_open(name, 0, 0);
66585 + fd = sys_open((char __force_user *)name, 0, 0);
66586 sys_ioctl(fd, BLKRRPART, 0);
66587 }
66588 sys_close(fd);
66589 @@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
66590
66591 wait_for_device_probe();
66592
66593 - fd = sys_open("/dev/md0", 0, 0);
66594 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
66595 if (fd >= 0) {
66596 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
66597 sys_close(fd);
66598 diff --git a/init/init_task.c b/init/init_task.c
66599 index 8b2f399..f0797c9 100644
66600 --- a/init/init_task.c
66601 +++ b/init/init_task.c
66602 @@ -20,5 +20,9 @@ EXPORT_SYMBOL(init_task);
66603 * Initial thread structure. Alignment of this is handled by a special
66604 * linker map entry.
66605 */
66606 +#ifdef CONFIG_X86
66607 +union thread_union init_thread_union __init_task_data;
66608 +#else
66609 union thread_union init_thread_union __init_task_data =
66610 { INIT_THREAD_INFO(init_task) };
66611 +#endif
66612 diff --git a/init/initramfs.c b/init/initramfs.c
66613 index 84c6bf1..8899338 100644
66614 --- a/init/initramfs.c
66615 +++ b/init/initramfs.c
66616 @@ -84,7 +84,7 @@ static void __init free_hash(void)
66617 }
66618 }
66619
66620 -static long __init do_utime(char *filename, time_t mtime)
66621 +static long __init do_utime(char __force_user *filename, time_t mtime)
66622 {
66623 struct timespec t[2];
66624
66625 @@ -119,7 +119,7 @@ static void __init dir_utime(void)
66626 struct dir_entry *de, *tmp;
66627 list_for_each_entry_safe(de, tmp, &dir_list, list) {
66628 list_del(&de->list);
66629 - do_utime(de->name, de->mtime);
66630 + do_utime((char __force_user *)de->name, de->mtime);
66631 kfree(de->name);
66632 kfree(de);
66633 }
66634 @@ -281,7 +281,7 @@ static int __init maybe_link(void)
66635 if (nlink >= 2) {
66636 char *old = find_link(major, minor, ino, mode, collected);
66637 if (old)
66638 - return (sys_link(old, collected) < 0) ? -1 : 1;
66639 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
66640 }
66641 return 0;
66642 }
66643 @@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
66644 {
66645 struct stat st;
66646
66647 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
66648 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
66649 if (S_ISDIR(st.st_mode))
66650 - sys_rmdir(path);
66651 + sys_rmdir((char __force_user *)path);
66652 else
66653 - sys_unlink(path);
66654 + sys_unlink((char __force_user *)path);
66655 }
66656 }
66657
66658 @@ -315,7 +315,7 @@ static int __init do_name(void)
66659 int openflags = O_WRONLY|O_CREAT;
66660 if (ml != 1)
66661 openflags |= O_TRUNC;
66662 - wfd = sys_open(collected, openflags, mode);
66663 + wfd = sys_open((char __force_user *)collected, openflags, mode);
66664
66665 if (wfd >= 0) {
66666 sys_fchown(wfd, uid, gid);
66667 @@ -327,17 +327,17 @@ static int __init do_name(void)
66668 }
66669 }
66670 } else if (S_ISDIR(mode)) {
66671 - sys_mkdir(collected, mode);
66672 - sys_chown(collected, uid, gid);
66673 - sys_chmod(collected, mode);
66674 + sys_mkdir((char __force_user *)collected, mode);
66675 + sys_chown((char __force_user *)collected, uid, gid);
66676 + sys_chmod((char __force_user *)collected, mode);
66677 dir_add(collected, mtime);
66678 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
66679 S_ISFIFO(mode) || S_ISSOCK(mode)) {
66680 if (maybe_link() == 0) {
66681 - sys_mknod(collected, mode, rdev);
66682 - sys_chown(collected, uid, gid);
66683 - sys_chmod(collected, mode);
66684 - do_utime(collected, mtime);
66685 + sys_mknod((char __force_user *)collected, mode, rdev);
66686 + sys_chown((char __force_user *)collected, uid, gid);
66687 + sys_chmod((char __force_user *)collected, mode);
66688 + do_utime((char __force_user *)collected, mtime);
66689 }
66690 }
66691 return 0;
66692 @@ -346,15 +346,15 @@ static int __init do_name(void)
66693 static int __init do_copy(void)
66694 {
66695 if (count >= body_len) {
66696 - sys_write(wfd, victim, body_len);
66697 + sys_write(wfd, (char __force_user *)victim, body_len);
66698 sys_close(wfd);
66699 - do_utime(vcollected, mtime);
66700 + do_utime((char __force_user *)vcollected, mtime);
66701 kfree(vcollected);
66702 eat(body_len);
66703 state = SkipIt;
66704 return 0;
66705 } else {
66706 - sys_write(wfd, victim, count);
66707 + sys_write(wfd, (char __force_user *)victim, count);
66708 body_len -= count;
66709 eat(count);
66710 return 1;
66711 @@ -365,9 +365,9 @@ static int __init do_symlink(void)
66712 {
66713 collected[N_ALIGN(name_len) + body_len] = '\0';
66714 clean_path(collected, 0);
66715 - sys_symlink(collected + N_ALIGN(name_len), collected);
66716 - sys_lchown(collected, uid, gid);
66717 - do_utime(collected, mtime);
66718 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
66719 + sys_lchown((char __force_user *)collected, uid, gid);
66720 + do_utime((char __force_user *)collected, mtime);
66721 state = SkipIt;
66722 next_state = Reset;
66723 return 0;
66724 diff --git a/init/main.c b/init/main.c
66725 index d61ec54..bd3144f 100644
66726 --- a/init/main.c
66727 +++ b/init/main.c
66728 @@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
66729 extern void tc_init(void);
66730 #endif
66731
66732 +extern void grsecurity_init(void);
66733 +
66734 /*
66735 * Debug helper: via this flag we know that we are in 'early bootup code'
66736 * where only the boot processor is running with IRQ disabled. This means
66737 @@ -149,6 +151,61 @@ static int __init set_reset_devices(char *str)
66738
66739 __setup("reset_devices", set_reset_devices);
66740
66741 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66742 +int grsec_proc_gid = CONFIG_GRKERNSEC_PROC_GID;
66743 +static int __init setup_grsec_proc_gid(char *str)
66744 +{
66745 + grsec_proc_gid = (int)simple_strtol(str, NULL, 0);
66746 + return 1;
66747 +}
66748 +__setup("grsec_proc_gid=", setup_grsec_proc_gid);
66749 +#endif
66750 +
66751 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
66752 +extern char pax_enter_kernel_user[];
66753 +extern char pax_exit_kernel_user[];
66754 +extern pgdval_t clone_pgd_mask;
66755 +#endif
66756 +
66757 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
66758 +static int __init setup_pax_nouderef(char *str)
66759 +{
66760 +#ifdef CONFIG_X86_32
66761 + unsigned int cpu;
66762 + struct desc_struct *gdt;
66763 +
66764 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
66765 + gdt = get_cpu_gdt_table(cpu);
66766 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
66767 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
66768 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
66769 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
66770 + }
66771 + loadsegment(ds, __KERNEL_DS);
66772 + loadsegment(es, __KERNEL_DS);
66773 + loadsegment(ss, __KERNEL_DS);
66774 +#else
66775 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
66776 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
66777 + clone_pgd_mask = ~(pgdval_t)0UL;
66778 +#endif
66779 +
66780 + return 0;
66781 +}
66782 +early_param("pax_nouderef", setup_pax_nouderef);
66783 +#endif
66784 +
66785 +#ifdef CONFIG_PAX_SOFTMODE
66786 +int pax_softmode;
66787 +
66788 +static int __init setup_pax_softmode(char *str)
66789 +{
66790 + get_option(&str, &pax_softmode);
66791 + return 1;
66792 +}
66793 +__setup("pax_softmode=", setup_pax_softmode);
66794 +#endif
66795 +
66796 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
66797 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
66798 static const char *panic_later, *panic_param;
66799 @@ -678,6 +735,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
66800 {
66801 int count = preempt_count();
66802 int ret;
66803 + const char *msg1 = "", *msg2 = "";
66804
66805 if (initcall_debug)
66806 ret = do_one_initcall_debug(fn);
66807 @@ -690,15 +748,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
66808 sprintf(msgbuf, "error code %d ", ret);
66809
66810 if (preempt_count() != count) {
66811 - strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
66812 + msg1 = " preemption imbalance";
66813 preempt_count() = count;
66814 }
66815 if (irqs_disabled()) {
66816 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
66817 + msg2 = " disabled interrupts";
66818 local_irq_enable();
66819 }
66820 - if (msgbuf[0]) {
66821 - printk("initcall %pF returned with %s\n", fn, msgbuf);
66822 + if (msgbuf[0] || *msg1 || *msg2) {
66823 + printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
66824 }
66825
66826 return ret;
66827 @@ -752,8 +810,14 @@ static void __init do_initcall_level(int level)
66828 level, level,
66829 &repair_env_string);
66830
66831 - for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
66832 + for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
66833 do_one_initcall(*fn);
66834 +
66835 +#ifdef CONFIG_PAX_LATENT_ENTROPY
66836 + transfer_latent_entropy();
66837 +#endif
66838 +
66839 + }
66840 }
66841
66842 static void __init do_initcalls(void)
66843 @@ -787,8 +851,14 @@ static void __init do_pre_smp_initcalls(void)
66844 {
66845 initcall_t *fn;
66846
66847 - for (fn = __initcall_start; fn < __initcall0_start; fn++)
66848 + for (fn = __initcall_start; fn < __initcall0_start; fn++) {
66849 do_one_initcall(*fn);
66850 +
66851 +#ifdef CONFIG_PAX_LATENT_ENTROPY
66852 + transfer_latent_entropy();
66853 +#endif
66854 +
66855 + }
66856 }
66857
66858 static void run_init_process(const char *init_filename)
66859 @@ -870,7 +940,7 @@ static int __init kernel_init(void * unused)
66860 do_basic_setup();
66861
66862 /* Open the /dev/console on the rootfs, this should never fail */
66863 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
66864 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
66865 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
66866
66867 (void) sys_dup(0);
66868 @@ -883,11 +953,13 @@ static int __init kernel_init(void * unused)
66869 if (!ramdisk_execute_command)
66870 ramdisk_execute_command = "/init";
66871
66872 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
66873 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
66874 ramdisk_execute_command = NULL;
66875 prepare_namespace();
66876 }
66877
66878 + grsecurity_init();
66879 +
66880 /*
66881 * Ok, we have completed the initial bootup, and
66882 * we're essentially up and running. Get rid of the
66883 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
66884 index 9a08acc..e65ebe7 100644
66885 --- a/ipc/mqueue.c
66886 +++ b/ipc/mqueue.c
66887 @@ -279,6 +279,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
66888 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
66889 info->attr.mq_msgsize);
66890
66891 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
66892 spin_lock(&mq_lock);
66893 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
66894 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
66895 diff --git a/ipc/msg.c b/ipc/msg.c
66896 index 7385de2..a8180e08 100644
66897 --- a/ipc/msg.c
66898 +++ b/ipc/msg.c
66899 @@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
66900 return security_msg_queue_associate(msq, msgflg);
66901 }
66902
66903 +static struct ipc_ops msg_ops = {
66904 + .getnew = newque,
66905 + .associate = msg_security,
66906 + .more_checks = NULL
66907 +};
66908 +
66909 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
66910 {
66911 struct ipc_namespace *ns;
66912 - struct ipc_ops msg_ops;
66913 struct ipc_params msg_params;
66914
66915 ns = current->nsproxy->ipc_ns;
66916
66917 - msg_ops.getnew = newque;
66918 - msg_ops.associate = msg_security;
66919 - msg_ops.more_checks = NULL;
66920 -
66921 msg_params.key = key;
66922 msg_params.flg = msgflg;
66923
66924 diff --git a/ipc/sem.c b/ipc/sem.c
66925 index 5215a81..cfc0cac 100644
66926 --- a/ipc/sem.c
66927 +++ b/ipc/sem.c
66928 @@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
66929 return 0;
66930 }
66931
66932 +static struct ipc_ops sem_ops = {
66933 + .getnew = newary,
66934 + .associate = sem_security,
66935 + .more_checks = sem_more_checks
66936 +};
66937 +
66938 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
66939 {
66940 struct ipc_namespace *ns;
66941 - struct ipc_ops sem_ops;
66942 struct ipc_params sem_params;
66943
66944 ns = current->nsproxy->ipc_ns;
66945 @@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
66946 if (nsems < 0 || nsems > ns->sc_semmsl)
66947 return -EINVAL;
66948
66949 - sem_ops.getnew = newary;
66950 - sem_ops.associate = sem_security;
66951 - sem_ops.more_checks = sem_more_checks;
66952 -
66953 sem_params.key = key;
66954 sem_params.flg = semflg;
66955 sem_params.u.nsems = nsems;
66956 diff --git a/ipc/shm.c b/ipc/shm.c
66957 index 00faa05..7040960 100644
66958 --- a/ipc/shm.c
66959 +++ b/ipc/shm.c
66960 @@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
66961 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
66962 #endif
66963
66964 +#ifdef CONFIG_GRKERNSEC
66965 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
66966 + const time_t shm_createtime, const uid_t cuid,
66967 + const int shmid);
66968 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
66969 + const time_t shm_createtime);
66970 +#endif
66971 +
66972 void shm_init_ns(struct ipc_namespace *ns)
66973 {
66974 ns->shm_ctlmax = SHMMAX;
66975 @@ -520,6 +528,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
66976 shp->shm_lprid = 0;
66977 shp->shm_atim = shp->shm_dtim = 0;
66978 shp->shm_ctim = get_seconds();
66979 +#ifdef CONFIG_GRKERNSEC
66980 + {
66981 + struct timespec timeval;
66982 + do_posix_clock_monotonic_gettime(&timeval);
66983 +
66984 + shp->shm_createtime = timeval.tv_sec;
66985 + }
66986 +#endif
66987 shp->shm_segsz = size;
66988 shp->shm_nattch = 0;
66989 shp->shm_file = file;
66990 @@ -571,18 +587,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
66991 return 0;
66992 }
66993
66994 +static struct ipc_ops shm_ops = {
66995 + .getnew = newseg,
66996 + .associate = shm_security,
66997 + .more_checks = shm_more_checks
66998 +};
66999 +
67000 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
67001 {
67002 struct ipc_namespace *ns;
67003 - struct ipc_ops shm_ops;
67004 struct ipc_params shm_params;
67005
67006 ns = current->nsproxy->ipc_ns;
67007
67008 - shm_ops.getnew = newseg;
67009 - shm_ops.associate = shm_security;
67010 - shm_ops.more_checks = shm_more_checks;
67011 -
67012 shm_params.key = key;
67013 shm_params.flg = shmflg;
67014 shm_params.u.size = size;
67015 @@ -1001,6 +1018,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
67016 f_mode = FMODE_READ | FMODE_WRITE;
67017 }
67018 if (shmflg & SHM_EXEC) {
67019 +
67020 +#ifdef CONFIG_PAX_MPROTECT
67021 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
67022 + goto out;
67023 +#endif
67024 +
67025 prot |= PROT_EXEC;
67026 acc_mode |= S_IXUGO;
67027 }
67028 @@ -1024,9 +1047,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
67029 if (err)
67030 goto out_unlock;
67031
67032 +#ifdef CONFIG_GRKERNSEC
67033 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
67034 + shp->shm_perm.cuid, shmid) ||
67035 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
67036 + err = -EACCES;
67037 + goto out_unlock;
67038 + }
67039 +#endif
67040 +
67041 path = shp->shm_file->f_path;
67042 path_get(&path);
67043 shp->shm_nattch++;
67044 +#ifdef CONFIG_GRKERNSEC
67045 + shp->shm_lapid = current->pid;
67046 +#endif
67047 size = i_size_read(path.dentry->d_inode);
67048 shm_unlock(shp);
67049
67050 diff --git a/kernel/acct.c b/kernel/acct.c
67051 index 02e6167..54824f7 100644
67052 --- a/kernel/acct.c
67053 +++ b/kernel/acct.c
67054 @@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
67055 */
67056 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
67057 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
67058 - file->f_op->write(file, (char *)&ac,
67059 + file->f_op->write(file, (char __force_user *)&ac,
67060 sizeof(acct_t), &file->f_pos);
67061 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
67062 set_fs(fs);
67063 diff --git a/kernel/audit.c b/kernel/audit.c
67064 index a8c84be..8bd034c 100644
67065 --- a/kernel/audit.c
67066 +++ b/kernel/audit.c
67067 @@ -115,7 +115,7 @@ u32 audit_sig_sid = 0;
67068 3) suppressed due to audit_rate_limit
67069 4) suppressed due to audit_backlog_limit
67070 */
67071 -static atomic_t audit_lost = ATOMIC_INIT(0);
67072 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
67073
67074 /* The netlink socket. */
67075 static struct sock *audit_sock;
67076 @@ -237,7 +237,7 @@ void audit_log_lost(const char *message)
67077 unsigned long now;
67078 int print;
67079
67080 - atomic_inc(&audit_lost);
67081 + atomic_inc_unchecked(&audit_lost);
67082
67083 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
67084
67085 @@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
67086 printk(KERN_WARNING
67087 "audit: audit_lost=%d audit_rate_limit=%d "
67088 "audit_backlog_limit=%d\n",
67089 - atomic_read(&audit_lost),
67090 + atomic_read_unchecked(&audit_lost),
67091 audit_rate_limit,
67092 audit_backlog_limit);
67093 audit_panic(message);
67094 @@ -690,7 +690,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
67095 status_set.pid = audit_pid;
67096 status_set.rate_limit = audit_rate_limit;
67097 status_set.backlog_limit = audit_backlog_limit;
67098 - status_set.lost = atomic_read(&audit_lost);
67099 + status_set.lost = atomic_read_unchecked(&audit_lost);
67100 status_set.backlog = skb_queue_len(&audit_skb_queue);
67101 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
67102 &status_set, sizeof(status_set));
67103 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
67104 index 4b96415..d8c16ee 100644
67105 --- a/kernel/auditsc.c
67106 +++ b/kernel/auditsc.c
67107 @@ -2289,7 +2289,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
67108 }
67109
67110 /* global counter which is incremented every time something logs in */
67111 -static atomic_t session_id = ATOMIC_INIT(0);
67112 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
67113
67114 /**
67115 * audit_set_loginuid - set current task's audit_context loginuid
67116 @@ -2313,7 +2313,7 @@ int audit_set_loginuid(uid_t loginuid)
67117 return -EPERM;
67118 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
67119
67120 - sessionid = atomic_inc_return(&session_id);
67121 + sessionid = atomic_inc_return_unchecked(&session_id);
67122 if (context && context->in_syscall) {
67123 struct audit_buffer *ab;
67124
67125 diff --git a/kernel/capability.c b/kernel/capability.c
67126 index 493d972..ea17248 100644
67127 --- a/kernel/capability.c
67128 +++ b/kernel/capability.c
67129 @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
67130 * before modification is attempted and the application
67131 * fails.
67132 */
67133 + if (tocopy > ARRAY_SIZE(kdata))
67134 + return -EFAULT;
67135 +
67136 if (copy_to_user(dataptr, kdata, tocopy
67137 * sizeof(struct __user_cap_data_struct))) {
67138 return -EFAULT;
67139 @@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
67140 int ret;
67141
67142 rcu_read_lock();
67143 - ret = security_capable(__task_cred(t), ns, cap);
67144 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
67145 + gr_task_is_capable(t, __task_cred(t), cap);
67146 rcu_read_unlock();
67147
67148 - return (ret == 0);
67149 + return ret;
67150 }
67151
67152 /**
67153 @@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
67154 int ret;
67155
67156 rcu_read_lock();
67157 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
67158 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
67159 rcu_read_unlock();
67160
67161 - return (ret == 0);
67162 + return ret;
67163 }
67164
67165 /**
67166 @@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
67167 BUG();
67168 }
67169
67170 - if (security_capable(current_cred(), ns, cap) == 0) {
67171 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
67172 current->flags |= PF_SUPERPRIV;
67173 return true;
67174 }
67175 @@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
67176 }
67177 EXPORT_SYMBOL(ns_capable);
67178
67179 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
67180 +{
67181 + if (unlikely(!cap_valid(cap))) {
67182 + printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
67183 + BUG();
67184 + }
67185 +
67186 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
67187 + current->flags |= PF_SUPERPRIV;
67188 + return true;
67189 + }
67190 + return false;
67191 +}
67192 +EXPORT_SYMBOL(ns_capable_nolog);
67193 +
67194 /**
67195 * capable - Determine if the current task has a superior capability in effect
67196 * @cap: The capability to be tested for
67197 @@ -408,6 +427,12 @@ bool capable(int cap)
67198 }
67199 EXPORT_SYMBOL(capable);
67200
67201 +bool capable_nolog(int cap)
67202 +{
67203 + return ns_capable_nolog(&init_user_ns, cap);
67204 +}
67205 +EXPORT_SYMBOL(capable_nolog);
67206 +
67207 /**
67208 * nsown_capable - Check superior capability to one's own user_ns
67209 * @cap: The capability in question
67210 @@ -440,3 +465,10 @@ bool inode_capable(const struct inode *inode, int cap)
67211
67212 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
67213 }
67214 +
67215 +bool inode_capable_nolog(const struct inode *inode, int cap)
67216 +{
67217 + struct user_namespace *ns = current_user_ns();
67218 +
67219 + return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
67220 +}
67221 diff --git a/kernel/cgroup.c b/kernel/cgroup.c
67222 index ff2bce5..a41e8f9 100644
67223 --- a/kernel/cgroup.c
67224 +++ b/kernel/cgroup.c
67225 @@ -5390,7 +5390,7 @@ static int cgroup_css_links_read(struct cgroup *cont,
67226 struct css_set *cg = link->cg;
67227 struct task_struct *task;
67228 int count = 0;
67229 - seq_printf(seq, "css_set %p\n", cg);
67230 + seq_printf(seq, "css_set %pK\n", cg);
67231 list_for_each_entry(task, &cg->tasks, cg_list) {
67232 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
67233 seq_puts(seq, " ...\n");
67234 diff --git a/kernel/compat.c b/kernel/compat.c
67235 index c28a306..b4d0cf3 100644
67236 --- a/kernel/compat.c
67237 +++ b/kernel/compat.c
67238 @@ -13,6 +13,7 @@
67239
67240 #include <linux/linkage.h>
67241 #include <linux/compat.h>
67242 +#include <linux/module.h>
67243 #include <linux/errno.h>
67244 #include <linux/time.h>
67245 #include <linux/signal.h>
67246 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
67247 mm_segment_t oldfs;
67248 long ret;
67249
67250 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
67251 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
67252 oldfs = get_fs();
67253 set_fs(KERNEL_DS);
67254 ret = hrtimer_nanosleep_restart(restart);
67255 @@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
67256 oldfs = get_fs();
67257 set_fs(KERNEL_DS);
67258 ret = hrtimer_nanosleep(&tu,
67259 - rmtp ? (struct timespec __user *)&rmt : NULL,
67260 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
67261 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
67262 set_fs(oldfs);
67263
67264 @@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
67265 mm_segment_t old_fs = get_fs();
67266
67267 set_fs(KERNEL_DS);
67268 - ret = sys_sigpending((old_sigset_t __user *) &s);
67269 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
67270 set_fs(old_fs);
67271 if (ret == 0)
67272 ret = put_user(s, set);
67273 @@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
67274 mm_segment_t old_fs = get_fs();
67275
67276 set_fs(KERNEL_DS);
67277 - ret = sys_old_getrlimit(resource, &r);
67278 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
67279 set_fs(old_fs);
67280
67281 if (!ret) {
67282 @@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
67283 mm_segment_t old_fs = get_fs();
67284
67285 set_fs(KERNEL_DS);
67286 - ret = sys_getrusage(who, (struct rusage __user *) &r);
67287 + ret = sys_getrusage(who, (struct rusage __force_user *) &r);
67288 set_fs(old_fs);
67289
67290 if (ret)
67291 @@ -550,8 +551,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
67292 set_fs (KERNEL_DS);
67293 ret = sys_wait4(pid,
67294 (stat_addr ?
67295 - (unsigned int __user *) &status : NULL),
67296 - options, (struct rusage __user *) &r);
67297 + (unsigned int __force_user *) &status : NULL),
67298 + options, (struct rusage __force_user *) &r);
67299 set_fs (old_fs);
67300
67301 if (ret > 0) {
67302 @@ -576,8 +577,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
67303 memset(&info, 0, sizeof(info));
67304
67305 set_fs(KERNEL_DS);
67306 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
67307 - uru ? (struct rusage __user *)&ru : NULL);
67308 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
67309 + uru ? (struct rusage __force_user *)&ru : NULL);
67310 set_fs(old_fs);
67311
67312 if ((ret < 0) || (info.si_signo == 0))
67313 @@ -707,8 +708,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
67314 oldfs = get_fs();
67315 set_fs(KERNEL_DS);
67316 err = sys_timer_settime(timer_id, flags,
67317 - (struct itimerspec __user *) &newts,
67318 - (struct itimerspec __user *) &oldts);
67319 + (struct itimerspec __force_user *) &newts,
67320 + (struct itimerspec __force_user *) &oldts);
67321 set_fs(oldfs);
67322 if (!err && old && put_compat_itimerspec(old, &oldts))
67323 return -EFAULT;
67324 @@ -725,7 +726,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
67325 oldfs = get_fs();
67326 set_fs(KERNEL_DS);
67327 err = sys_timer_gettime(timer_id,
67328 - (struct itimerspec __user *) &ts);
67329 + (struct itimerspec __force_user *) &ts);
67330 set_fs(oldfs);
67331 if (!err && put_compat_itimerspec(setting, &ts))
67332 return -EFAULT;
67333 @@ -744,7 +745,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
67334 oldfs = get_fs();
67335 set_fs(KERNEL_DS);
67336 err = sys_clock_settime(which_clock,
67337 - (struct timespec __user *) &ts);
67338 + (struct timespec __force_user *) &ts);
67339 set_fs(oldfs);
67340 return err;
67341 }
67342 @@ -759,7 +760,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
67343 oldfs = get_fs();
67344 set_fs(KERNEL_DS);
67345 err = sys_clock_gettime(which_clock,
67346 - (struct timespec __user *) &ts);
67347 + (struct timespec __force_user *) &ts);
67348 set_fs(oldfs);
67349 if (!err && put_compat_timespec(&ts, tp))
67350 return -EFAULT;
67351 @@ -779,7 +780,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
67352
67353 oldfs = get_fs();
67354 set_fs(KERNEL_DS);
67355 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
67356 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
67357 set_fs(oldfs);
67358
67359 err = compat_put_timex(utp, &txc);
67360 @@ -799,7 +800,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
67361 oldfs = get_fs();
67362 set_fs(KERNEL_DS);
67363 err = sys_clock_getres(which_clock,
67364 - (struct timespec __user *) &ts);
67365 + (struct timespec __force_user *) &ts);
67366 set_fs(oldfs);
67367 if (!err && tp && put_compat_timespec(&ts, tp))
67368 return -EFAULT;
67369 @@ -811,9 +812,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
67370 long err;
67371 mm_segment_t oldfs;
67372 struct timespec tu;
67373 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
67374 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
67375
67376 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
67377 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
67378 oldfs = get_fs();
67379 set_fs(KERNEL_DS);
67380 err = clock_nanosleep_restart(restart);
67381 @@ -845,8 +846,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
67382 oldfs = get_fs();
67383 set_fs(KERNEL_DS);
67384 err = sys_clock_nanosleep(which_clock, flags,
67385 - (struct timespec __user *) &in,
67386 - (struct timespec __user *) &out);
67387 + (struct timespec __force_user *) &in,
67388 + (struct timespec __force_user *) &out);
67389 set_fs(oldfs);
67390
67391 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
67392 diff --git a/kernel/configs.c b/kernel/configs.c
67393 index 42e8fa0..9e7406b 100644
67394 --- a/kernel/configs.c
67395 +++ b/kernel/configs.c
67396 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
67397 struct proc_dir_entry *entry;
67398
67399 /* create the current config file */
67400 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
67401 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
67402 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
67403 + &ikconfig_file_ops);
67404 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67405 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
67406 + &ikconfig_file_ops);
67407 +#endif
67408 +#else
67409 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
67410 &ikconfig_file_ops);
67411 +#endif
67412 +
67413 if (!entry)
67414 return -ENOMEM;
67415
67416 diff --git a/kernel/cred.c b/kernel/cred.c
67417 index de728ac..e3c267c 100644
67418 --- a/kernel/cred.c
67419 +++ b/kernel/cred.c
67420 @@ -207,6 +207,16 @@ void exit_creds(struct task_struct *tsk)
67421 validate_creds(cred);
67422 alter_cred_subscribers(cred, -1);
67423 put_cred(cred);
67424 +
67425 +#ifdef CONFIG_GRKERNSEC_SETXID
67426 + cred = (struct cred *) tsk->delayed_cred;
67427 + if (cred != NULL) {
67428 + tsk->delayed_cred = NULL;
67429 + validate_creds(cred);
67430 + alter_cred_subscribers(cred, -1);
67431 + put_cred(cred);
67432 + }
67433 +#endif
67434 }
67435
67436 /**
67437 @@ -469,7 +479,7 @@ error_put:
67438 * Always returns 0 thus allowing this function to be tail-called at the end
67439 * of, say, sys_setgid().
67440 */
67441 -int commit_creds(struct cred *new)
67442 +static int __commit_creds(struct cred *new)
67443 {
67444 struct task_struct *task = current;
67445 const struct cred *old = task->real_cred;
67446 @@ -488,6 +498,8 @@ int commit_creds(struct cred *new)
67447
67448 get_cred(new); /* we will require a ref for the subj creds too */
67449
67450 + gr_set_role_label(task, new->uid, new->gid);
67451 +
67452 /* dumpability changes */
67453 if (!uid_eq(old->euid, new->euid) ||
67454 !gid_eq(old->egid, new->egid) ||
67455 @@ -537,6 +549,101 @@ int commit_creds(struct cred *new)
67456 put_cred(old);
67457 return 0;
67458 }
67459 +#ifdef CONFIG_GRKERNSEC_SETXID
67460 +extern int set_user(struct cred *new);
67461 +
67462 +void gr_delayed_cred_worker(void)
67463 +{
67464 + const struct cred *new = current->delayed_cred;
67465 + struct cred *ncred;
67466 +
67467 + current->delayed_cred = NULL;
67468 +
67469 + if (current_uid() && new != NULL) {
67470 + // from doing get_cred on it when queueing this
67471 + put_cred(new);
67472 + return;
67473 + } else if (new == NULL)
67474 + return;
67475 +
67476 + ncred = prepare_creds();
67477 + if (!ncred)
67478 + goto die;
67479 + // uids
67480 + ncred->uid = new->uid;
67481 + ncred->euid = new->euid;
67482 + ncred->suid = new->suid;
67483 + ncred->fsuid = new->fsuid;
67484 + // gids
67485 + ncred->gid = new->gid;
67486 + ncred->egid = new->egid;
67487 + ncred->sgid = new->sgid;
67488 + ncred->fsgid = new->fsgid;
67489 + // groups
67490 + if (set_groups(ncred, new->group_info) < 0) {
67491 + abort_creds(ncred);
67492 + goto die;
67493 + }
67494 + // caps
67495 + ncred->securebits = new->securebits;
67496 + ncred->cap_inheritable = new->cap_inheritable;
67497 + ncred->cap_permitted = new->cap_permitted;
67498 + ncred->cap_effective = new->cap_effective;
67499 + ncred->cap_bset = new->cap_bset;
67500 +
67501 + if (set_user(ncred)) {
67502 + abort_creds(ncred);
67503 + goto die;
67504 + }
67505 +
67506 + // from doing get_cred on it when queueing this
67507 + put_cred(new);
67508 +
67509 + __commit_creds(ncred);
67510 + return;
67511 +die:
67512 + // from doing get_cred on it when queueing this
67513 + put_cred(new);
67514 + do_group_exit(SIGKILL);
67515 +}
67516 +#endif
67517 +
67518 +int commit_creds(struct cred *new)
67519 +{
67520 +#ifdef CONFIG_GRKERNSEC_SETXID
67521 + int ret;
67522 + int schedule_it = 0;
67523 + struct task_struct *t;
67524 +
67525 + /* we won't get called with tasklist_lock held for writing
67526 + and interrupts disabled as the cred struct in that case is
67527 + init_cred
67528 + */
67529 + if (grsec_enable_setxid && !current_is_single_threaded() &&
67530 + !current_uid() && new->uid) {
67531 + schedule_it = 1;
67532 + }
67533 + ret = __commit_creds(new);
67534 + if (schedule_it) {
67535 + rcu_read_lock();
67536 + read_lock(&tasklist_lock);
67537 + for (t = next_thread(current); t != current;
67538 + t = next_thread(t)) {
67539 + if (t->delayed_cred == NULL) {
67540 + t->delayed_cred = get_cred(new);
67541 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
67542 + set_tsk_need_resched(t);
67543 + }
67544 + }
67545 + read_unlock(&tasklist_lock);
67546 + rcu_read_unlock();
67547 + }
67548 + return ret;
67549 +#else
67550 + return __commit_creds(new);
67551 +#endif
67552 +}
67553 +
67554 EXPORT_SYMBOL(commit_creds);
67555
67556 /**
67557 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
67558 index 0557f24..1a00d9a 100644
67559 --- a/kernel/debug/debug_core.c
67560 +++ b/kernel/debug/debug_core.c
67561 @@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
67562 */
67563 static atomic_t masters_in_kgdb;
67564 static atomic_t slaves_in_kgdb;
67565 -static atomic_t kgdb_break_tasklet_var;
67566 +static atomic_unchecked_t kgdb_break_tasklet_var;
67567 atomic_t kgdb_setting_breakpoint;
67568
67569 struct task_struct *kgdb_usethread;
67570 @@ -132,7 +132,7 @@ int kgdb_single_step;
67571 static pid_t kgdb_sstep_pid;
67572
67573 /* to keep track of the CPU which is doing the single stepping*/
67574 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
67575 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
67576
67577 /*
67578 * If you are debugging a problem where roundup (the collection of
67579 @@ -540,7 +540,7 @@ return_normal:
67580 * kernel will only try for the value of sstep_tries before
67581 * giving up and continuing on.
67582 */
67583 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
67584 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
67585 (kgdb_info[cpu].task &&
67586 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
67587 atomic_set(&kgdb_active, -1);
67588 @@ -634,8 +634,8 @@ cpu_master_loop:
67589 }
67590
67591 kgdb_restore:
67592 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
67593 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
67594 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
67595 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
67596 if (kgdb_info[sstep_cpu].task)
67597 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
67598 else
67599 @@ -861,18 +861,18 @@ static void kgdb_unregister_callbacks(void)
67600 static void kgdb_tasklet_bpt(unsigned long ing)
67601 {
67602 kgdb_breakpoint();
67603 - atomic_set(&kgdb_break_tasklet_var, 0);
67604 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
67605 }
67606
67607 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
67608
67609 void kgdb_schedule_breakpoint(void)
67610 {
67611 - if (atomic_read(&kgdb_break_tasklet_var) ||
67612 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
67613 atomic_read(&kgdb_active) != -1 ||
67614 atomic_read(&kgdb_setting_breakpoint))
67615 return;
67616 - atomic_inc(&kgdb_break_tasklet_var);
67617 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
67618 tasklet_schedule(&kgdb_tasklet_breakpoint);
67619 }
67620 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
67621 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
67622 index 31df170..bc98840 100644
67623 --- a/kernel/debug/kdb/kdb_main.c
67624 +++ b/kernel/debug/kdb/kdb_main.c
67625 @@ -1971,7 +1971,7 @@ static int kdb_lsmod(int argc, const char **argv)
67626 list_for_each_entry(mod, kdb_modules, list) {
67627
67628 kdb_printf("%-20s%8u 0x%p ", mod->name,
67629 - mod->core_size, (void *)mod);
67630 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
67631 #ifdef CONFIG_MODULE_UNLOAD
67632 kdb_printf("%4ld ", module_refcount(mod));
67633 #endif
67634 @@ -1981,7 +1981,7 @@ static int kdb_lsmod(int argc, const char **argv)
67635 kdb_printf(" (Loading)");
67636 else
67637 kdb_printf(" (Live)");
67638 - kdb_printf(" 0x%p", mod->module_core);
67639 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
67640
67641 #ifdef CONFIG_MODULE_UNLOAD
67642 {
67643 diff --git a/kernel/events/core.c b/kernel/events/core.c
67644 index 7fee567..8affa2c 100644
67645 --- a/kernel/events/core.c
67646 +++ b/kernel/events/core.c
67647 @@ -181,7 +181,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
67648 return 0;
67649 }
67650
67651 -static atomic64_t perf_event_id;
67652 +static atomic64_unchecked_t perf_event_id;
67653
67654 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
67655 enum event_type_t event_type);
67656 @@ -2665,7 +2665,7 @@ static void __perf_event_read(void *info)
67657
67658 static inline u64 perf_event_count(struct perf_event *event)
67659 {
67660 - return local64_read(&event->count) + atomic64_read(&event->child_count);
67661 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
67662 }
67663
67664 static u64 perf_event_read(struct perf_event *event)
67665 @@ -2995,9 +2995,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
67666 mutex_lock(&event->child_mutex);
67667 total += perf_event_read(event);
67668 *enabled += event->total_time_enabled +
67669 - atomic64_read(&event->child_total_time_enabled);
67670 + atomic64_read_unchecked(&event->child_total_time_enabled);
67671 *running += event->total_time_running +
67672 - atomic64_read(&event->child_total_time_running);
67673 + atomic64_read_unchecked(&event->child_total_time_running);
67674
67675 list_for_each_entry(child, &event->child_list, child_list) {
67676 total += perf_event_read(child);
67677 @@ -3406,10 +3406,10 @@ void perf_event_update_userpage(struct perf_event *event)
67678 userpg->offset -= local64_read(&event->hw.prev_count);
67679
67680 userpg->time_enabled = enabled +
67681 - atomic64_read(&event->child_total_time_enabled);
67682 + atomic64_read_unchecked(&event->child_total_time_enabled);
67683
67684 userpg->time_running = running +
67685 - atomic64_read(&event->child_total_time_running);
67686 + atomic64_read_unchecked(&event->child_total_time_running);
67687
67688 arch_perf_update_userpage(userpg, now);
67689
67690 @@ -3842,11 +3842,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
67691 values[n++] = perf_event_count(event);
67692 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
67693 values[n++] = enabled +
67694 - atomic64_read(&event->child_total_time_enabled);
67695 + atomic64_read_unchecked(&event->child_total_time_enabled);
67696 }
67697 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
67698 values[n++] = running +
67699 - atomic64_read(&event->child_total_time_running);
67700 + atomic64_read_unchecked(&event->child_total_time_running);
67701 }
67702 if (read_format & PERF_FORMAT_ID)
67703 values[n++] = primary_event_id(event);
67704 @@ -4524,12 +4524,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
67705 * need to add enough zero bytes after the string to handle
67706 * the 64bit alignment we do later.
67707 */
67708 - buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
67709 + buf = kzalloc(PATH_MAX, GFP_KERNEL);
67710 if (!buf) {
67711 name = strncpy(tmp, "//enomem", sizeof(tmp));
67712 goto got_name;
67713 }
67714 - name = d_path(&file->f_path, buf, PATH_MAX);
67715 + name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
67716 if (IS_ERR(name)) {
67717 name = strncpy(tmp, "//toolong", sizeof(tmp));
67718 goto got_name;
67719 @@ -5968,7 +5968,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
67720 event->parent = parent_event;
67721
67722 event->ns = get_pid_ns(current->nsproxy->pid_ns);
67723 - event->id = atomic64_inc_return(&perf_event_id);
67724 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
67725
67726 event->state = PERF_EVENT_STATE_INACTIVE;
67727
67728 @@ -6567,10 +6567,10 @@ static void sync_child_event(struct perf_event *child_event,
67729 /*
67730 * Add back the child's count to the parent's count:
67731 */
67732 - atomic64_add(child_val, &parent_event->child_count);
67733 - atomic64_add(child_event->total_time_enabled,
67734 + atomic64_add_unchecked(child_val, &parent_event->child_count);
67735 + atomic64_add_unchecked(child_event->total_time_enabled,
67736 &parent_event->child_total_time_enabled);
67737 - atomic64_add(child_event->total_time_running,
67738 + atomic64_add_unchecked(child_event->total_time_running,
67739 &parent_event->child_total_time_running);
67740
67741 /*
67742 diff --git a/kernel/exit.c b/kernel/exit.c
67743 index f65345f9..1423231 100644
67744 --- a/kernel/exit.c
67745 +++ b/kernel/exit.c
67746 @@ -182,6 +182,10 @@ void release_task(struct task_struct * p)
67747 struct task_struct *leader;
67748 int zap_leader;
67749 repeat:
67750 +#ifdef CONFIG_NET
67751 + gr_del_task_from_ip_table(p);
67752 +#endif
67753 +
67754 /* don't need to get the RCU readlock here - the process is dead and
67755 * can't be modifying its own credentials. But shut RCU-lockdep up */
67756 rcu_read_lock();
67757 @@ -394,7 +398,7 @@ int allow_signal(int sig)
67758 * know it'll be handled, so that they don't get converted to
67759 * SIGKILL or just silently dropped.
67760 */
67761 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
67762 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
67763 recalc_sigpending();
67764 spin_unlock_irq(&current->sighand->siglock);
67765 return 0;
67766 @@ -430,6 +434,8 @@ void daemonize(const char *name, ...)
67767 vsnprintf(current->comm, sizeof(current->comm), name, args);
67768 va_end(args);
67769
67770 + gr_set_kernel_label(current);
67771 +
67772 /*
67773 * If we were started as result of loading a module, close all of the
67774 * user space pages. We don't need them, and if we didn't close them
67775 @@ -907,6 +913,8 @@ void do_exit(long code)
67776 struct task_struct *tsk = current;
67777 int group_dead;
67778
67779 + set_fs(USER_DS);
67780 +
67781 profile_task_exit(tsk);
67782
67783 WARN_ON(blk_needs_flush_plug(tsk));
67784 @@ -923,7 +931,6 @@ void do_exit(long code)
67785 * mm_release()->clear_child_tid() from writing to a user-controlled
67786 * kernel address.
67787 */
67788 - set_fs(USER_DS);
67789
67790 ptrace_event(PTRACE_EVENT_EXIT, code);
67791
67792 @@ -982,6 +989,9 @@ void do_exit(long code)
67793 tsk->exit_code = code;
67794 taskstats_exit(tsk, group_dead);
67795
67796 + gr_acl_handle_psacct(tsk, code);
67797 + gr_acl_handle_exit();
67798 +
67799 exit_mm(tsk);
67800
67801 if (group_dead)
67802 @@ -1099,7 +1109,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
67803 * Take down every thread in the group. This is called by fatal signals
67804 * as well as by sys_exit_group (below).
67805 */
67806 -void
67807 +__noreturn void
67808 do_group_exit(int exit_code)
67809 {
67810 struct signal_struct *sig = current->signal;
67811 diff --git a/kernel/fork.c b/kernel/fork.c
67812 index 2c8857e..288c9c7 100644
67813 --- a/kernel/fork.c
67814 +++ b/kernel/fork.c
67815 @@ -318,7 +318,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
67816 *stackend = STACK_END_MAGIC; /* for overflow detection */
67817
67818 #ifdef CONFIG_CC_STACKPROTECTOR
67819 - tsk->stack_canary = get_random_int();
67820 + tsk->stack_canary = pax_get_random_long();
67821 #endif
67822
67823 /*
67824 @@ -343,13 +343,78 @@ free_tsk:
67825 }
67826
67827 #ifdef CONFIG_MMU
67828 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
67829 +{
67830 + struct vm_area_struct *tmp;
67831 + unsigned long charge;
67832 + struct mempolicy *pol;
67833 + struct file *file;
67834 +
67835 + charge = 0;
67836 + if (mpnt->vm_flags & VM_ACCOUNT) {
67837 + unsigned long len = vma_pages(mpnt);
67838 +
67839 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
67840 + goto fail_nomem;
67841 + charge = len;
67842 + }
67843 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
67844 + if (!tmp)
67845 + goto fail_nomem;
67846 + *tmp = *mpnt;
67847 + tmp->vm_mm = mm;
67848 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
67849 + pol = mpol_dup(vma_policy(mpnt));
67850 + if (IS_ERR(pol))
67851 + goto fail_nomem_policy;
67852 + vma_set_policy(tmp, pol);
67853 + if (anon_vma_fork(tmp, mpnt))
67854 + goto fail_nomem_anon_vma_fork;
67855 + tmp->vm_flags &= ~VM_LOCKED;
67856 + tmp->vm_next = tmp->vm_prev = NULL;
67857 + tmp->vm_mirror = NULL;
67858 + file = tmp->vm_file;
67859 + if (file) {
67860 + struct inode *inode = file->f_path.dentry->d_inode;
67861 + struct address_space *mapping = file->f_mapping;
67862 +
67863 + get_file(file);
67864 + if (tmp->vm_flags & VM_DENYWRITE)
67865 + atomic_dec(&inode->i_writecount);
67866 + mutex_lock(&mapping->i_mmap_mutex);
67867 + if (tmp->vm_flags & VM_SHARED)
67868 + mapping->i_mmap_writable++;
67869 + flush_dcache_mmap_lock(mapping);
67870 + /* insert tmp into the share list, just after mpnt */
67871 + vma_prio_tree_add(tmp, mpnt);
67872 + flush_dcache_mmap_unlock(mapping);
67873 + mutex_unlock(&mapping->i_mmap_mutex);
67874 + }
67875 +
67876 + /*
67877 + * Clear hugetlb-related page reserves for children. This only
67878 + * affects MAP_PRIVATE mappings. Faults generated by the child
67879 + * are not guaranteed to succeed, even if read-only
67880 + */
67881 + if (is_vm_hugetlb_page(tmp))
67882 + reset_vma_resv_huge_pages(tmp);
67883 +
67884 + return tmp;
67885 +
67886 +fail_nomem_anon_vma_fork:
67887 + mpol_put(pol);
67888 +fail_nomem_policy:
67889 + kmem_cache_free(vm_area_cachep, tmp);
67890 +fail_nomem:
67891 + vm_unacct_memory(charge);
67892 + return NULL;
67893 +}
67894 +
67895 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67896 {
67897 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
67898 struct rb_node **rb_link, *rb_parent;
67899 int retval;
67900 - unsigned long charge;
67901 - struct mempolicy *pol;
67902
67903 down_write(&oldmm->mmap_sem);
67904 flush_cache_dup_mm(oldmm);
67905 @@ -361,8 +426,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67906 mm->locked_vm = 0;
67907 mm->mmap = NULL;
67908 mm->mmap_cache = NULL;
67909 - mm->free_area_cache = oldmm->mmap_base;
67910 - mm->cached_hole_size = ~0UL;
67911 + mm->free_area_cache = oldmm->free_area_cache;
67912 + mm->cached_hole_size = oldmm->cached_hole_size;
67913 mm->map_count = 0;
67914 cpumask_clear(mm_cpumask(mm));
67915 mm->mm_rb = RB_ROOT;
67916 @@ -378,52 +443,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67917
67918 prev = NULL;
67919 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
67920 - struct file *file;
67921 -
67922 if (mpnt->vm_flags & VM_DONTCOPY) {
67923 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
67924 -vma_pages(mpnt));
67925 continue;
67926 }
67927 - charge = 0;
67928 - if (mpnt->vm_flags & VM_ACCOUNT) {
67929 - unsigned long len = vma_pages(mpnt);
67930 -
67931 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
67932 - goto fail_nomem;
67933 - charge = len;
67934 - }
67935 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
67936 - if (!tmp)
67937 - goto fail_nomem;
67938 - *tmp = *mpnt;
67939 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
67940 - pol = mpol_dup(vma_policy(mpnt));
67941 - retval = PTR_ERR(pol);
67942 - if (IS_ERR(pol))
67943 - goto fail_nomem_policy;
67944 - vma_set_policy(tmp, pol);
67945 - tmp->vm_mm = mm;
67946 - if (anon_vma_fork(tmp, mpnt))
67947 - goto fail_nomem_anon_vma_fork;
67948 - tmp->vm_flags &= ~VM_LOCKED;
67949 - tmp->vm_next = tmp->vm_prev = NULL;
67950 - file = tmp->vm_file;
67951 - if (file) {
67952 - struct inode *inode = file->f_path.dentry->d_inode;
67953 - struct address_space *mapping = file->f_mapping;
67954 -
67955 - get_file(file);
67956 - if (tmp->vm_flags & VM_DENYWRITE)
67957 - atomic_dec(&inode->i_writecount);
67958 - mutex_lock(&mapping->i_mmap_mutex);
67959 - if (tmp->vm_flags & VM_SHARED)
67960 - mapping->i_mmap_writable++;
67961 - flush_dcache_mmap_lock(mapping);
67962 - /* insert tmp into the share list, just after mpnt */
67963 - vma_prio_tree_add(tmp, mpnt);
67964 - flush_dcache_mmap_unlock(mapping);
67965 - mutex_unlock(&mapping->i_mmap_mutex);
67966 + tmp = dup_vma(mm, oldmm, mpnt);
67967 + if (!tmp) {
67968 + retval = -ENOMEM;
67969 + goto out;
67970 }
67971
67972 /*
67973 @@ -455,9 +483,34 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67974 if (retval)
67975 goto out;
67976
67977 - if (file)
67978 + if (tmp->vm_file)
67979 uprobe_mmap(tmp);
67980 }
67981 +
67982 +#ifdef CONFIG_PAX_SEGMEXEC
67983 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
67984 + struct vm_area_struct *mpnt_m;
67985 +
67986 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
67987 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
67988 +
67989 + if (!mpnt->vm_mirror)
67990 + continue;
67991 +
67992 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
67993 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
67994 + mpnt->vm_mirror = mpnt_m;
67995 + } else {
67996 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
67997 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
67998 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
67999 + mpnt->vm_mirror->vm_mirror = mpnt;
68000 + }
68001 + }
68002 + BUG_ON(mpnt_m);
68003 + }
68004 +#endif
68005 +
68006 /* a new mm has just been created */
68007 arch_dup_mmap(oldmm, mm);
68008 retval = 0;
68009 @@ -466,14 +519,6 @@ out:
68010 flush_tlb_mm(oldmm);
68011 up_write(&oldmm->mmap_sem);
68012 return retval;
68013 -fail_nomem_anon_vma_fork:
68014 - mpol_put(pol);
68015 -fail_nomem_policy:
68016 - kmem_cache_free(vm_area_cachep, tmp);
68017 -fail_nomem:
68018 - retval = -ENOMEM;
68019 - vm_unacct_memory(charge);
68020 - goto out;
68021 }
68022
68023 static inline int mm_alloc_pgd(struct mm_struct *mm)
68024 @@ -710,8 +755,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
68025 return ERR_PTR(err);
68026
68027 mm = get_task_mm(task);
68028 - if (mm && mm != current->mm &&
68029 - !ptrace_may_access(task, mode)) {
68030 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
68031 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
68032 mmput(mm);
68033 mm = ERR_PTR(-EACCES);
68034 }
68035 @@ -932,13 +977,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
68036 spin_unlock(&fs->lock);
68037 return -EAGAIN;
68038 }
68039 - fs->users++;
68040 + atomic_inc(&fs->users);
68041 spin_unlock(&fs->lock);
68042 return 0;
68043 }
68044 tsk->fs = copy_fs_struct(fs);
68045 if (!tsk->fs)
68046 return -ENOMEM;
68047 + /* Carry through gr_chroot_dentry and is_chrooted instead
68048 + of recomputing it here. Already copied when the task struct
68049 + is duplicated. This allows pivot_root to not be treated as
68050 + a chroot
68051 + */
68052 + //gr_set_chroot_entries(tsk, &tsk->fs->root);
68053 +
68054 return 0;
68055 }
68056
68057 @@ -1205,6 +1257,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
68058 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
68059 #endif
68060 retval = -EAGAIN;
68061 +
68062 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
68063 +
68064 if (atomic_read(&p->real_cred->user->processes) >=
68065 task_rlimit(p, RLIMIT_NPROC)) {
68066 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
68067 @@ -1427,6 +1482,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
68068 /* Need tasklist lock for parent etc handling! */
68069 write_lock_irq(&tasklist_lock);
68070
68071 + /* synchronizes with gr_set_acls() */
68072 + gr_copy_label(p);
68073 +
68074 /* CLONE_PARENT re-uses the old parent */
68075 if (clone_flags & (CLONE_PARENT|CLONE_THREAD)) {
68076 p->real_parent = current->real_parent;
68077 @@ -1537,6 +1595,8 @@ bad_fork_cleanup_count:
68078 bad_fork_free:
68079 free_task(p);
68080 fork_out:
68081 + gr_log_forkfail(retval);
68082 +
68083 return ERR_PTR(retval);
68084 }
68085
68086 @@ -1637,6 +1697,8 @@ long do_fork(unsigned long clone_flags,
68087 if (clone_flags & CLONE_PARENT_SETTID)
68088 put_user(nr, parent_tidptr);
68089
68090 + gr_handle_brute_check();
68091 +
68092 if (clone_flags & CLONE_VFORK) {
68093 p->vfork_done = &vfork;
68094 init_completion(&vfork);
68095 @@ -1735,7 +1797,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
68096 return 0;
68097
68098 /* don't need lock here; in the worst case we'll do useless copy */
68099 - if (fs->users == 1)
68100 + if (atomic_read(&fs->users) == 1)
68101 return 0;
68102
68103 *new_fsp = copy_fs_struct(fs);
68104 @@ -1824,7 +1886,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
68105 fs = current->fs;
68106 spin_lock(&fs->lock);
68107 current->fs = new_fs;
68108 - if (--fs->users)
68109 + gr_set_chroot_entries(current, &current->fs->root);
68110 + if (atomic_dec_return(&fs->users))
68111 new_fs = NULL;
68112 else
68113 new_fs = fs;
68114 diff --git a/kernel/futex.c b/kernel/futex.c
68115 index 19eb089..b8c65ea 100644
68116 --- a/kernel/futex.c
68117 +++ b/kernel/futex.c
68118 @@ -54,6 +54,7 @@
68119 #include <linux/mount.h>
68120 #include <linux/pagemap.h>
68121 #include <linux/syscalls.h>
68122 +#include <linux/ptrace.h>
68123 #include <linux/signal.h>
68124 #include <linux/export.h>
68125 #include <linux/magic.h>
68126 @@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
68127 struct page *page, *page_head;
68128 int err, ro = 0;
68129
68130 +#ifdef CONFIG_PAX_SEGMEXEC
68131 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
68132 + return -EFAULT;
68133 +#endif
68134 +
68135 /*
68136 * The futex address must be "naturally" aligned.
68137 */
68138 @@ -2733,6 +2739,7 @@ static int __init futex_init(void)
68139 {
68140 u32 curval;
68141 int i;
68142 + mm_segment_t oldfs;
68143
68144 /*
68145 * This will fail and we want it. Some arch implementations do
68146 @@ -2744,8 +2751,11 @@ static int __init futex_init(void)
68147 * implementation, the non-functional ones will return
68148 * -ENOSYS.
68149 */
68150 + oldfs = get_fs();
68151 + set_fs(USER_DS);
68152 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
68153 futex_cmpxchg_enabled = 1;
68154 + set_fs(oldfs);
68155
68156 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
68157 plist_head_init(&futex_queues[i].chain);
68158 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
68159 index 9b22d03..6295b62 100644
68160 --- a/kernel/gcov/base.c
68161 +++ b/kernel/gcov/base.c
68162 @@ -102,11 +102,6 @@ void gcov_enable_events(void)
68163 }
68164
68165 #ifdef CONFIG_MODULES
68166 -static inline int within(void *addr, void *start, unsigned long size)
68167 -{
68168 - return ((addr >= start) && (addr < start + size));
68169 -}
68170 -
68171 /* Update list and generate events when modules are unloaded. */
68172 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
68173 void *data)
68174 @@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
68175 prev = NULL;
68176 /* Remove entries located in module from linked list. */
68177 for (info = gcov_info_head; info; info = info->next) {
68178 - if (within(info, mod->module_core, mod->core_size)) {
68179 + if (within_module_core_rw((unsigned long)info, mod)) {
68180 if (prev)
68181 prev->next = info->next;
68182 else
68183 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
68184 index 6db7a5e..25b6648 100644
68185 --- a/kernel/hrtimer.c
68186 +++ b/kernel/hrtimer.c
68187 @@ -1407,7 +1407,7 @@ void hrtimer_peek_ahead_timers(void)
68188 local_irq_restore(flags);
68189 }
68190
68191 -static void run_hrtimer_softirq(struct softirq_action *h)
68192 +static void run_hrtimer_softirq(void)
68193 {
68194 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
68195
68196 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
68197 index 4304919..408c4c0 100644
68198 --- a/kernel/jump_label.c
68199 +++ b/kernel/jump_label.c
68200 @@ -13,6 +13,7 @@
68201 #include <linux/sort.h>
68202 #include <linux/err.h>
68203 #include <linux/static_key.h>
68204 +#include <linux/mm.h>
68205
68206 #ifdef HAVE_JUMP_LABEL
68207
68208 @@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
68209
68210 size = (((unsigned long)stop - (unsigned long)start)
68211 / sizeof(struct jump_entry));
68212 + pax_open_kernel();
68213 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
68214 + pax_close_kernel();
68215 }
68216
68217 static void jump_label_update(struct static_key *key, int enable);
68218 @@ -356,10 +359,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
68219 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
68220 struct jump_entry *iter;
68221
68222 + pax_open_kernel();
68223 for (iter = iter_start; iter < iter_stop; iter++) {
68224 if (within_module_init(iter->code, mod))
68225 iter->code = 0;
68226 }
68227 + pax_close_kernel();
68228 }
68229
68230 static int
68231 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
68232 index 2169fee..45c017a 100644
68233 --- a/kernel/kallsyms.c
68234 +++ b/kernel/kallsyms.c
68235 @@ -11,6 +11,9 @@
68236 * Changed the compression method from stem compression to "table lookup"
68237 * compression (see scripts/kallsyms.c for a more complete description)
68238 */
68239 +#ifdef CONFIG_GRKERNSEC_HIDESYM
68240 +#define __INCLUDED_BY_HIDESYM 1
68241 +#endif
68242 #include <linux/kallsyms.h>
68243 #include <linux/module.h>
68244 #include <linux/init.h>
68245 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
68246
68247 static inline int is_kernel_inittext(unsigned long addr)
68248 {
68249 + if (system_state != SYSTEM_BOOTING)
68250 + return 0;
68251 +
68252 if (addr >= (unsigned long)_sinittext
68253 && addr <= (unsigned long)_einittext)
68254 return 1;
68255 return 0;
68256 }
68257
68258 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
68259 +#ifdef CONFIG_MODULES
68260 +static inline int is_module_text(unsigned long addr)
68261 +{
68262 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
68263 + return 1;
68264 +
68265 + addr = ktla_ktva(addr);
68266 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
68267 +}
68268 +#else
68269 +static inline int is_module_text(unsigned long addr)
68270 +{
68271 + return 0;
68272 +}
68273 +#endif
68274 +#endif
68275 +
68276 static inline int is_kernel_text(unsigned long addr)
68277 {
68278 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
68279 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
68280
68281 static inline int is_kernel(unsigned long addr)
68282 {
68283 +
68284 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
68285 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
68286 + return 1;
68287 +
68288 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
68289 +#else
68290 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
68291 +#endif
68292 +
68293 return 1;
68294 return in_gate_area_no_mm(addr);
68295 }
68296
68297 static int is_ksym_addr(unsigned long addr)
68298 {
68299 +
68300 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
68301 + if (is_module_text(addr))
68302 + return 0;
68303 +#endif
68304 +
68305 if (all_var)
68306 return is_kernel(addr);
68307
68308 @@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
68309
68310 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
68311 {
68312 - iter->name[0] = '\0';
68313 iter->nameoff = get_symbol_offset(new_pos);
68314 iter->pos = new_pos;
68315 }
68316 @@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
68317 {
68318 struct kallsym_iter *iter = m->private;
68319
68320 +#ifdef CONFIG_GRKERNSEC_HIDESYM
68321 + if (current_uid())
68322 + return 0;
68323 +#endif
68324 +
68325 /* Some debugging symbols have no name. Ignore them. */
68326 if (!iter->name[0])
68327 return 0;
68328 @@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
68329 */
68330 type = iter->exported ? toupper(iter->type) :
68331 tolower(iter->type);
68332 +
68333 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
68334 type, iter->name, iter->module_name);
68335 } else
68336 @@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
68337 struct kallsym_iter *iter;
68338 int ret;
68339
68340 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
68341 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
68342 if (!iter)
68343 return -ENOMEM;
68344 reset_iter(iter, 0);
68345 diff --git a/kernel/kcmp.c b/kernel/kcmp.c
68346 index 30b7b22..c726387 100644
68347 --- a/kernel/kcmp.c
68348 +++ b/kernel/kcmp.c
68349 @@ -98,6 +98,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
68350 struct task_struct *task1, *task2;
68351 int ret;
68352
68353 +#ifdef CONFIG_GRKERNSEC
68354 + return -ENOSYS;
68355 +#endif
68356 +
68357 rcu_read_lock();
68358
68359 /*
68360 diff --git a/kernel/kexec.c b/kernel/kexec.c
68361 index 0668d58..591b6fc 100644
68362 --- a/kernel/kexec.c
68363 +++ b/kernel/kexec.c
68364 @@ -1046,7 +1046,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
68365 unsigned long flags)
68366 {
68367 struct compat_kexec_segment in;
68368 - struct kexec_segment out, __user *ksegments;
68369 + struct kexec_segment out;
68370 + struct kexec_segment __user *ksegments;
68371 unsigned long i, result;
68372
68373 /* Don't allow clients that don't understand the native
68374 diff --git a/kernel/kmod.c b/kernel/kmod.c
68375 index 6f99aea..eb6e3a0 100644
68376 --- a/kernel/kmod.c
68377 +++ b/kernel/kmod.c
68378 @@ -73,7 +73,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
68379 kfree(info->argv);
68380 }
68381
68382 -static int call_modprobe(char *module_name, int wait)
68383 +static int call_modprobe(char *module_name, char *module_param, int wait)
68384 {
68385 static char *envp[] = {
68386 "HOME=/",
68387 @@ -82,7 +82,7 @@ static int call_modprobe(char *module_name, int wait)
68388 NULL
68389 };
68390
68391 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
68392 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
68393 if (!argv)
68394 goto out;
68395
68396 @@ -94,7 +94,8 @@ static int call_modprobe(char *module_name, int wait)
68397 argv[1] = "-q";
68398 argv[2] = "--";
68399 argv[3] = module_name; /* check free_modprobe_argv() */
68400 - argv[4] = NULL;
68401 + argv[4] = module_param;
68402 + argv[5] = NULL;
68403
68404 return call_usermodehelper_fns(modprobe_path, argv, envp,
68405 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
68406 @@ -119,9 +120,8 @@ out:
68407 * If module auto-loading support is disabled then this function
68408 * becomes a no-operation.
68409 */
68410 -int __request_module(bool wait, const char *fmt, ...)
68411 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
68412 {
68413 - va_list args;
68414 char module_name[MODULE_NAME_LEN];
68415 unsigned int max_modprobes;
68416 int ret;
68417 @@ -129,9 +129,7 @@ int __request_module(bool wait, const char *fmt, ...)
68418 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
68419 static int kmod_loop_msg;
68420
68421 - va_start(args, fmt);
68422 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
68423 - va_end(args);
68424 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
68425 if (ret >= MODULE_NAME_LEN)
68426 return -ENAMETOOLONG;
68427
68428 @@ -139,6 +137,20 @@ int __request_module(bool wait, const char *fmt, ...)
68429 if (ret)
68430 return ret;
68431
68432 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68433 + if (!current_uid()) {
68434 + /* hack to workaround consolekit/udisks stupidity */
68435 + read_lock(&tasklist_lock);
68436 + if (!strcmp(current->comm, "mount") &&
68437 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
68438 + read_unlock(&tasklist_lock);
68439 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
68440 + return -EPERM;
68441 + }
68442 + read_unlock(&tasklist_lock);
68443 + }
68444 +#endif
68445 +
68446 /* If modprobe needs a service that is in a module, we get a recursive
68447 * loop. Limit the number of running kmod threads to max_threads/2 or
68448 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
68449 @@ -167,11 +179,52 @@ int __request_module(bool wait, const char *fmt, ...)
68450
68451 trace_module_request(module_name, wait, _RET_IP_);
68452
68453 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
68454 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
68455
68456 atomic_dec(&kmod_concurrent);
68457 return ret;
68458 }
68459 +
68460 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
68461 +{
68462 + va_list args;
68463 + int ret;
68464 +
68465 + va_start(args, fmt);
68466 + ret = ____request_module(wait, module_param, fmt, args);
68467 + va_end(args);
68468 +
68469 + return ret;
68470 +}
68471 +
68472 +int __request_module(bool wait, const char *fmt, ...)
68473 +{
68474 + va_list args;
68475 + int ret;
68476 +
68477 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68478 + if (current_uid()) {
68479 + char module_param[MODULE_NAME_LEN];
68480 +
68481 + memset(module_param, 0, sizeof(module_param));
68482 +
68483 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
68484 +
68485 + va_start(args, fmt);
68486 + ret = ____request_module(wait, module_param, fmt, args);
68487 + va_end(args);
68488 +
68489 + return ret;
68490 + }
68491 +#endif
68492 +
68493 + va_start(args, fmt);
68494 + ret = ____request_module(wait, NULL, fmt, args);
68495 + va_end(args);
68496 +
68497 + return ret;
68498 +}
68499 +
68500 EXPORT_SYMBOL(__request_module);
68501 #endif /* CONFIG_MODULES */
68502
68503 @@ -280,7 +333,7 @@ static int wait_for_helper(void *data)
68504 *
68505 * Thus the __user pointer cast is valid here.
68506 */
68507 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
68508 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
68509
68510 /*
68511 * If ret is 0, either ____call_usermodehelper failed and the
68512 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
68513 index c62b854..6fc810d 100644
68514 --- a/kernel/kprobes.c
68515 +++ b/kernel/kprobes.c
68516 @@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
68517 * kernel image and loaded module images reside. This is required
68518 * so x86_64 can correctly handle the %rip-relative fixups.
68519 */
68520 - kip->insns = module_alloc(PAGE_SIZE);
68521 + kip->insns = module_alloc_exec(PAGE_SIZE);
68522 if (!kip->insns) {
68523 kfree(kip);
68524 return NULL;
68525 @@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
68526 */
68527 if (!list_is_singular(&kip->list)) {
68528 list_del(&kip->list);
68529 - module_free(NULL, kip->insns);
68530 + module_free_exec(NULL, kip->insns);
68531 kfree(kip);
68532 }
68533 return 1;
68534 @@ -1955,7 +1955,7 @@ static int __init init_kprobes(void)
68535 {
68536 int i, err = 0;
68537 unsigned long offset = 0, size = 0;
68538 - char *modname, namebuf[128];
68539 + char *modname, namebuf[KSYM_NAME_LEN];
68540 const char *symbol_name;
68541 void *addr;
68542 struct kprobe_blackpoint *kb;
68543 @@ -2040,11 +2040,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
68544 kprobe_type = "k";
68545
68546 if (sym)
68547 - seq_printf(pi, "%p %s %s+0x%x %s ",
68548 + seq_printf(pi, "%pK %s %s+0x%x %s ",
68549 p->addr, kprobe_type, sym, offset,
68550 (modname ? modname : " "));
68551 else
68552 - seq_printf(pi, "%p %s %p ",
68553 + seq_printf(pi, "%pK %s %pK ",
68554 p->addr, kprobe_type, p->addr);
68555
68556 if (!pp)
68557 @@ -2081,7 +2081,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
68558 const char *sym = NULL;
68559 unsigned int i = *(loff_t *) v;
68560 unsigned long offset = 0;
68561 - char *modname, namebuf[128];
68562 + char *modname, namebuf[KSYM_NAME_LEN];
68563
68564 head = &kprobe_table[i];
68565 preempt_disable();
68566 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
68567 index 4e316e1..5501eef 100644
68568 --- a/kernel/ksysfs.c
68569 +++ b/kernel/ksysfs.c
68570 @@ -47,6 +47,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
68571 {
68572 if (count+1 > UEVENT_HELPER_PATH_LEN)
68573 return -ENOENT;
68574 + if (!capable(CAP_SYS_ADMIN))
68575 + return -EPERM;
68576 memcpy(uevent_helper, buf, count);
68577 uevent_helper[count] = '\0';
68578 if (count && uevent_helper[count-1] == '\n')
68579 diff --git a/kernel/lockdep.c b/kernel/lockdep.c
68580 index ea9ee45..67ebc8f 100644
68581 --- a/kernel/lockdep.c
68582 +++ b/kernel/lockdep.c
68583 @@ -590,6 +590,10 @@ static int static_obj(void *obj)
68584 end = (unsigned long) &_end,
68585 addr = (unsigned long) obj;
68586
68587 +#ifdef CONFIG_PAX_KERNEXEC
68588 + start = ktla_ktva(start);
68589 +#endif
68590 +
68591 /*
68592 * static variable?
68593 */
68594 @@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
68595 if (!static_obj(lock->key)) {
68596 debug_locks_off();
68597 printk("INFO: trying to register non-static key.\n");
68598 + printk("lock:%pS key:%pS.\n", lock, lock->key);
68599 printk("the code is fine but needs lockdep annotation.\n");
68600 printk("turning off the locking correctness validator.\n");
68601 dump_stack();
68602 @@ -3042,7 +3047,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
68603 if (!class)
68604 return 0;
68605 }
68606 - atomic_inc((atomic_t *)&class->ops);
68607 + atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
68608 if (very_verbose(class)) {
68609 printk("\nacquire class [%p] %s", class->key, class->name);
68610 if (class->name_version > 1)
68611 diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
68612 index 91c32a0..7b88d63 100644
68613 --- a/kernel/lockdep_proc.c
68614 +++ b/kernel/lockdep_proc.c
68615 @@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
68616
68617 static void print_name(struct seq_file *m, struct lock_class *class)
68618 {
68619 - char str[128];
68620 + char str[KSYM_NAME_LEN];
68621 const char *name = class->name;
68622
68623 if (!name) {
68624 @@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
68625 return 0;
68626 }
68627
68628 - seq_printf(m, "%p", class->key);
68629 + seq_printf(m, "%pK", class->key);
68630 #ifdef CONFIG_DEBUG_LOCKDEP
68631 seq_printf(m, " OPS:%8ld", class->ops);
68632 #endif
68633 @@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
68634
68635 list_for_each_entry(entry, &class->locks_after, entry) {
68636 if (entry->distance == 1) {
68637 - seq_printf(m, " -> [%p] ", entry->class->key);
68638 + seq_printf(m, " -> [%pK] ", entry->class->key);
68639 print_name(m, entry->class);
68640 seq_puts(m, "\n");
68641 }
68642 @@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
68643 if (!class->key)
68644 continue;
68645
68646 - seq_printf(m, "[%p] ", class->key);
68647 + seq_printf(m, "[%pK] ", class->key);
68648 print_name(m, class);
68649 seq_puts(m, "\n");
68650 }
68651 @@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
68652 if (!i)
68653 seq_line(m, '-', 40-namelen, namelen);
68654
68655 - snprintf(ip, sizeof(ip), "[<%p>]",
68656 + snprintf(ip, sizeof(ip), "[<%pK>]",
68657 (void *)class->contention_point[i]);
68658 seq_printf(m, "%40s %14lu %29s %pS\n",
68659 name, stats->contention_point[i],
68660 @@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
68661 if (!i)
68662 seq_line(m, '-', 40-namelen, namelen);
68663
68664 - snprintf(ip, sizeof(ip), "[<%p>]",
68665 + snprintf(ip, sizeof(ip), "[<%pK>]",
68666 (void *)class->contending_point[i]);
68667 seq_printf(m, "%40s %14lu %29s %pS\n",
68668 name, stats->contending_point[i],
68669 diff --git a/kernel/module.c b/kernel/module.c
68670 index 2a15c59..731c128 100644
68671 --- a/kernel/module.c
68672 +++ b/kernel/module.c
68673 @@ -58,6 +58,7 @@
68674 #include <linux/jump_label.h>
68675 #include <linux/pfn.h>
68676 #include <linux/bsearch.h>
68677 +#include <linux/grsecurity.h>
68678
68679 #define CREATE_TRACE_POINTS
68680 #include <trace/events/module.h>
68681 @@ -114,7 +115,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
68682
68683 /* Bounds of module allocation, for speeding __module_address.
68684 * Protected by module_mutex. */
68685 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
68686 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
68687 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
68688
68689 int register_module_notifier(struct notifier_block * nb)
68690 {
68691 @@ -278,7 +280,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
68692 return true;
68693
68694 list_for_each_entry_rcu(mod, &modules, list) {
68695 - struct symsearch arr[] = {
68696 + struct symsearch modarr[] = {
68697 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
68698 NOT_GPL_ONLY, false },
68699 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
68700 @@ -300,7 +302,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
68701 #endif
68702 };
68703
68704 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
68705 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
68706 return true;
68707 }
68708 return false;
68709 @@ -432,7 +434,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
68710 static int percpu_modalloc(struct module *mod,
68711 unsigned long size, unsigned long align)
68712 {
68713 - if (align > PAGE_SIZE) {
68714 + if (align-1 >= PAGE_SIZE) {
68715 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
68716 mod->name, align, PAGE_SIZE);
68717 align = PAGE_SIZE;
68718 @@ -1032,7 +1034,7 @@ struct module_attribute module_uevent =
68719 static ssize_t show_coresize(struct module_attribute *mattr,
68720 struct module_kobject *mk, char *buffer)
68721 {
68722 - return sprintf(buffer, "%u\n", mk->mod->core_size);
68723 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
68724 }
68725
68726 static struct module_attribute modinfo_coresize =
68727 @@ -1041,7 +1043,7 @@ static struct module_attribute modinfo_coresize =
68728 static ssize_t show_initsize(struct module_attribute *mattr,
68729 struct module_kobject *mk, char *buffer)
68730 {
68731 - return sprintf(buffer, "%u\n", mk->mod->init_size);
68732 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
68733 }
68734
68735 static struct module_attribute modinfo_initsize =
68736 @@ -1255,7 +1257,7 @@ resolve_symbol_wait(struct module *mod,
68737 */
68738 #ifdef CONFIG_SYSFS
68739
68740 -#ifdef CONFIG_KALLSYMS
68741 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
68742 static inline bool sect_empty(const Elf_Shdr *sect)
68743 {
68744 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
68745 @@ -1721,21 +1723,21 @@ static void set_section_ro_nx(void *base,
68746
68747 static void unset_module_core_ro_nx(struct module *mod)
68748 {
68749 - set_page_attributes(mod->module_core + mod->core_text_size,
68750 - mod->module_core + mod->core_size,
68751 + set_page_attributes(mod->module_core_rw,
68752 + mod->module_core_rw + mod->core_size_rw,
68753 set_memory_x);
68754 - set_page_attributes(mod->module_core,
68755 - mod->module_core + mod->core_ro_size,
68756 + set_page_attributes(mod->module_core_rx,
68757 + mod->module_core_rx + mod->core_size_rx,
68758 set_memory_rw);
68759 }
68760
68761 static void unset_module_init_ro_nx(struct module *mod)
68762 {
68763 - set_page_attributes(mod->module_init + mod->init_text_size,
68764 - mod->module_init + mod->init_size,
68765 + set_page_attributes(mod->module_init_rw,
68766 + mod->module_init_rw + mod->init_size_rw,
68767 set_memory_x);
68768 - set_page_attributes(mod->module_init,
68769 - mod->module_init + mod->init_ro_size,
68770 + set_page_attributes(mod->module_init_rx,
68771 + mod->module_init_rx + mod->init_size_rx,
68772 set_memory_rw);
68773 }
68774
68775 @@ -1746,14 +1748,14 @@ void set_all_modules_text_rw(void)
68776
68777 mutex_lock(&module_mutex);
68778 list_for_each_entry_rcu(mod, &modules, list) {
68779 - if ((mod->module_core) && (mod->core_text_size)) {
68780 - set_page_attributes(mod->module_core,
68781 - mod->module_core + mod->core_text_size,
68782 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
68783 + set_page_attributes(mod->module_core_rx,
68784 + mod->module_core_rx + mod->core_size_rx,
68785 set_memory_rw);
68786 }
68787 - if ((mod->module_init) && (mod->init_text_size)) {
68788 - set_page_attributes(mod->module_init,
68789 - mod->module_init + mod->init_text_size,
68790 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
68791 + set_page_attributes(mod->module_init_rx,
68792 + mod->module_init_rx + mod->init_size_rx,
68793 set_memory_rw);
68794 }
68795 }
68796 @@ -1767,14 +1769,14 @@ void set_all_modules_text_ro(void)
68797
68798 mutex_lock(&module_mutex);
68799 list_for_each_entry_rcu(mod, &modules, list) {
68800 - if ((mod->module_core) && (mod->core_text_size)) {
68801 - set_page_attributes(mod->module_core,
68802 - mod->module_core + mod->core_text_size,
68803 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
68804 + set_page_attributes(mod->module_core_rx,
68805 + mod->module_core_rx + mod->core_size_rx,
68806 set_memory_ro);
68807 }
68808 - if ((mod->module_init) && (mod->init_text_size)) {
68809 - set_page_attributes(mod->module_init,
68810 - mod->module_init + mod->init_text_size,
68811 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
68812 + set_page_attributes(mod->module_init_rx,
68813 + mod->module_init_rx + mod->init_size_rx,
68814 set_memory_ro);
68815 }
68816 }
68817 @@ -1820,16 +1822,19 @@ static void free_module(struct module *mod)
68818
68819 /* This may be NULL, but that's OK */
68820 unset_module_init_ro_nx(mod);
68821 - module_free(mod, mod->module_init);
68822 + module_free(mod, mod->module_init_rw);
68823 + module_free_exec(mod, mod->module_init_rx);
68824 kfree(mod->args);
68825 percpu_modfree(mod);
68826
68827 /* Free lock-classes: */
68828 - lockdep_free_key_range(mod->module_core, mod->core_size);
68829 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
68830 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
68831
68832 /* Finally, free the core (containing the module structure) */
68833 unset_module_core_ro_nx(mod);
68834 - module_free(mod, mod->module_core);
68835 + module_free_exec(mod, mod->module_core_rx);
68836 + module_free(mod, mod->module_core_rw);
68837
68838 #ifdef CONFIG_MPU
68839 update_protections(current->mm);
68840 @@ -1899,9 +1904,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68841 int ret = 0;
68842 const struct kernel_symbol *ksym;
68843
68844 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68845 + int is_fs_load = 0;
68846 + int register_filesystem_found = 0;
68847 + char *p;
68848 +
68849 + p = strstr(mod->args, "grsec_modharden_fs");
68850 + if (p) {
68851 + char *endptr = p + sizeof("grsec_modharden_fs") - 1;
68852 + /* copy \0 as well */
68853 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
68854 + is_fs_load = 1;
68855 + }
68856 +#endif
68857 +
68858 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
68859 const char *name = info->strtab + sym[i].st_name;
68860
68861 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68862 + /* it's a real shame this will never get ripped and copied
68863 + upstream! ;(
68864 + */
68865 + if (is_fs_load && !strcmp(name, "register_filesystem"))
68866 + register_filesystem_found = 1;
68867 +#endif
68868 +
68869 switch (sym[i].st_shndx) {
68870 case SHN_COMMON:
68871 /* We compiled with -fno-common. These are not
68872 @@ -1922,7 +1949,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68873 ksym = resolve_symbol_wait(mod, info, name);
68874 /* Ok if resolved. */
68875 if (ksym && !IS_ERR(ksym)) {
68876 + pax_open_kernel();
68877 sym[i].st_value = ksym->value;
68878 + pax_close_kernel();
68879 break;
68880 }
68881
68882 @@ -1941,11 +1970,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68883 secbase = (unsigned long)mod_percpu(mod);
68884 else
68885 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
68886 + pax_open_kernel();
68887 sym[i].st_value += secbase;
68888 + pax_close_kernel();
68889 break;
68890 }
68891 }
68892
68893 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68894 + if (is_fs_load && !register_filesystem_found) {
68895 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
68896 + ret = -EPERM;
68897 + }
68898 +#endif
68899 +
68900 return ret;
68901 }
68902
68903 @@ -2049,22 +2087,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
68904 || s->sh_entsize != ~0UL
68905 || strstarts(sname, ".init"))
68906 continue;
68907 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
68908 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
68909 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
68910 + else
68911 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
68912 pr_debug("\t%s\n", sname);
68913 }
68914 - switch (m) {
68915 - case 0: /* executable */
68916 - mod->core_size = debug_align(mod->core_size);
68917 - mod->core_text_size = mod->core_size;
68918 - break;
68919 - case 1: /* RO: text and ro-data */
68920 - mod->core_size = debug_align(mod->core_size);
68921 - mod->core_ro_size = mod->core_size;
68922 - break;
68923 - case 3: /* whole core */
68924 - mod->core_size = debug_align(mod->core_size);
68925 - break;
68926 - }
68927 }
68928
68929 pr_debug("Init section allocation order:\n");
68930 @@ -2078,23 +2106,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
68931 || s->sh_entsize != ~0UL
68932 || !strstarts(sname, ".init"))
68933 continue;
68934 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
68935 - | INIT_OFFSET_MASK);
68936 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
68937 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
68938 + else
68939 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
68940 + s->sh_entsize |= INIT_OFFSET_MASK;
68941 pr_debug("\t%s\n", sname);
68942 }
68943 - switch (m) {
68944 - case 0: /* executable */
68945 - mod->init_size = debug_align(mod->init_size);
68946 - mod->init_text_size = mod->init_size;
68947 - break;
68948 - case 1: /* RO: text and ro-data */
68949 - mod->init_size = debug_align(mod->init_size);
68950 - mod->init_ro_size = mod->init_size;
68951 - break;
68952 - case 3: /* whole init */
68953 - mod->init_size = debug_align(mod->init_size);
68954 - break;
68955 - }
68956 }
68957 }
68958
68959 @@ -2266,7 +2284,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
68960
68961 /* Put symbol section at end of init part of module. */
68962 symsect->sh_flags |= SHF_ALLOC;
68963 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
68964 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
68965 info->index.sym) | INIT_OFFSET_MASK;
68966 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
68967
68968 @@ -2286,13 +2304,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
68969 }
68970
68971 /* Append room for core symbols at end of core part. */
68972 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
68973 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
68974 - mod->core_size += strtab_size;
68975 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
68976 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
68977 + mod->core_size_rx += strtab_size;
68978
68979 /* Put string table section at end of init part of module. */
68980 strsect->sh_flags |= SHF_ALLOC;
68981 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
68982 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
68983 info->index.str) | INIT_OFFSET_MASK;
68984 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
68985 }
68986 @@ -2310,12 +2328,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
68987 /* Make sure we get permanent strtab: don't use info->strtab. */
68988 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
68989
68990 + pax_open_kernel();
68991 +
68992 /* Set types up while we still have access to sections. */
68993 for (i = 0; i < mod->num_symtab; i++)
68994 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
68995
68996 - mod->core_symtab = dst = mod->module_core + info->symoffs;
68997 - mod->core_strtab = s = mod->module_core + info->stroffs;
68998 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
68999 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
69000 src = mod->symtab;
69001 *s++ = 0;
69002 for (ndst = i = 0; i < mod->num_symtab; i++) {
69003 @@ -2328,6 +2348,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
69004 }
69005 }
69006 mod->core_num_syms = ndst;
69007 +
69008 + pax_close_kernel();
69009 }
69010 #else
69011 static inline void layout_symtab(struct module *mod, struct load_info *info)
69012 @@ -2361,17 +2383,33 @@ void * __weak module_alloc(unsigned long size)
69013 return size == 0 ? NULL : vmalloc_exec(size);
69014 }
69015
69016 -static void *module_alloc_update_bounds(unsigned long size)
69017 +static void *module_alloc_update_bounds_rw(unsigned long size)
69018 {
69019 void *ret = module_alloc(size);
69020
69021 if (ret) {
69022 mutex_lock(&module_mutex);
69023 /* Update module bounds. */
69024 - if ((unsigned long)ret < module_addr_min)
69025 - module_addr_min = (unsigned long)ret;
69026 - if ((unsigned long)ret + size > module_addr_max)
69027 - module_addr_max = (unsigned long)ret + size;
69028 + if ((unsigned long)ret < module_addr_min_rw)
69029 + module_addr_min_rw = (unsigned long)ret;
69030 + if ((unsigned long)ret + size > module_addr_max_rw)
69031 + module_addr_max_rw = (unsigned long)ret + size;
69032 + mutex_unlock(&module_mutex);
69033 + }
69034 + return ret;
69035 +}
69036 +
69037 +static void *module_alloc_update_bounds_rx(unsigned long size)
69038 +{
69039 + void *ret = module_alloc_exec(size);
69040 +
69041 + if (ret) {
69042 + mutex_lock(&module_mutex);
69043 + /* Update module bounds. */
69044 + if ((unsigned long)ret < module_addr_min_rx)
69045 + module_addr_min_rx = (unsigned long)ret;
69046 + if ((unsigned long)ret + size > module_addr_max_rx)
69047 + module_addr_max_rx = (unsigned long)ret + size;
69048 mutex_unlock(&module_mutex);
69049 }
69050 return ret;
69051 @@ -2549,8 +2587,14 @@ static struct module *setup_load_info(struct load_info *info)
69052 static int check_modinfo(struct module *mod, struct load_info *info)
69053 {
69054 const char *modmagic = get_modinfo(info, "vermagic");
69055 + const char *license = get_modinfo(info, "license");
69056 int err;
69057
69058 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
69059 + if (!license || !license_is_gpl_compatible(license))
69060 + return -ENOEXEC;
69061 +#endif
69062 +
69063 /* This is allowed: modprobe --force will invalidate it. */
69064 if (!modmagic) {
69065 err = try_to_force_load(mod, "bad vermagic");
69066 @@ -2573,7 +2617,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
69067 }
69068
69069 /* Set up license info based on the info section */
69070 - set_license(mod, get_modinfo(info, "license"));
69071 + set_license(mod, license);
69072
69073 return 0;
69074 }
69075 @@ -2667,7 +2711,7 @@ static int move_module(struct module *mod, struct load_info *info)
69076 void *ptr;
69077
69078 /* Do the allocs. */
69079 - ptr = module_alloc_update_bounds(mod->core_size);
69080 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
69081 /*
69082 * The pointer to this block is stored in the module structure
69083 * which is inside the block. Just mark it as not being a
69084 @@ -2677,23 +2721,50 @@ static int move_module(struct module *mod, struct load_info *info)
69085 if (!ptr)
69086 return -ENOMEM;
69087
69088 - memset(ptr, 0, mod->core_size);
69089 - mod->module_core = ptr;
69090 + memset(ptr, 0, mod->core_size_rw);
69091 + mod->module_core_rw = ptr;
69092
69093 - ptr = module_alloc_update_bounds(mod->init_size);
69094 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
69095 /*
69096 * The pointer to this block is stored in the module structure
69097 * which is inside the block. This block doesn't need to be
69098 * scanned as it contains data and code that will be freed
69099 * after the module is initialized.
69100 */
69101 - kmemleak_ignore(ptr);
69102 - if (!ptr && mod->init_size) {
69103 - module_free(mod, mod->module_core);
69104 + kmemleak_not_leak(ptr);
69105 + if (!ptr && mod->init_size_rw) {
69106 + module_free(mod, mod->module_core_rw);
69107 return -ENOMEM;
69108 }
69109 - memset(ptr, 0, mod->init_size);
69110 - mod->module_init = ptr;
69111 + memset(ptr, 0, mod->init_size_rw);
69112 + mod->module_init_rw = ptr;
69113 +
69114 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
69115 + kmemleak_not_leak(ptr);
69116 + if (!ptr) {
69117 + module_free(mod, mod->module_init_rw);
69118 + module_free(mod, mod->module_core_rw);
69119 + return -ENOMEM;
69120 + }
69121 +
69122 + pax_open_kernel();
69123 + memset(ptr, 0, mod->core_size_rx);
69124 + pax_close_kernel();
69125 + mod->module_core_rx = ptr;
69126 +
69127 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
69128 + kmemleak_not_leak(ptr);
69129 + if (!ptr && mod->init_size_rx) {
69130 + module_free_exec(mod, mod->module_core_rx);
69131 + module_free(mod, mod->module_init_rw);
69132 + module_free(mod, mod->module_core_rw);
69133 + return -ENOMEM;
69134 + }
69135 +
69136 + pax_open_kernel();
69137 + memset(ptr, 0, mod->init_size_rx);
69138 + pax_close_kernel();
69139 + mod->module_init_rx = ptr;
69140
69141 /* Transfer each section which specifies SHF_ALLOC */
69142 pr_debug("final section addresses:\n");
69143 @@ -2704,16 +2775,45 @@ static int move_module(struct module *mod, struct load_info *info)
69144 if (!(shdr->sh_flags & SHF_ALLOC))
69145 continue;
69146
69147 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
69148 - dest = mod->module_init
69149 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
69150 - else
69151 - dest = mod->module_core + shdr->sh_entsize;
69152 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
69153 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
69154 + dest = mod->module_init_rw
69155 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
69156 + else
69157 + dest = mod->module_init_rx
69158 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
69159 + } else {
69160 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
69161 + dest = mod->module_core_rw + shdr->sh_entsize;
69162 + else
69163 + dest = mod->module_core_rx + shdr->sh_entsize;
69164 + }
69165 +
69166 + if (shdr->sh_type != SHT_NOBITS) {
69167 +
69168 +#ifdef CONFIG_PAX_KERNEXEC
69169 +#ifdef CONFIG_X86_64
69170 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
69171 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
69172 +#endif
69173 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
69174 + pax_open_kernel();
69175 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
69176 + pax_close_kernel();
69177 + } else
69178 +#endif
69179
69180 - if (shdr->sh_type != SHT_NOBITS)
69181 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
69182 + }
69183 /* Update sh_addr to point to copy in image. */
69184 - shdr->sh_addr = (unsigned long)dest;
69185 +
69186 +#ifdef CONFIG_PAX_KERNEXEC
69187 + if (shdr->sh_flags & SHF_EXECINSTR)
69188 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
69189 + else
69190 +#endif
69191 +
69192 + shdr->sh_addr = (unsigned long)dest;
69193 pr_debug("\t0x%lx %s\n",
69194 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
69195 }
69196 @@ -2768,12 +2868,12 @@ static void flush_module_icache(const struct module *mod)
69197 * Do it before processing of module parameters, so the module
69198 * can provide parameter accessor functions of its own.
69199 */
69200 - if (mod->module_init)
69201 - flush_icache_range((unsigned long)mod->module_init,
69202 - (unsigned long)mod->module_init
69203 - + mod->init_size);
69204 - flush_icache_range((unsigned long)mod->module_core,
69205 - (unsigned long)mod->module_core + mod->core_size);
69206 + if (mod->module_init_rx)
69207 + flush_icache_range((unsigned long)mod->module_init_rx,
69208 + (unsigned long)mod->module_init_rx
69209 + + mod->init_size_rx);
69210 + flush_icache_range((unsigned long)mod->module_core_rx,
69211 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
69212
69213 set_fs(old_fs);
69214 }
69215 @@ -2843,8 +2943,10 @@ out:
69216 static void module_deallocate(struct module *mod, struct load_info *info)
69217 {
69218 percpu_modfree(mod);
69219 - module_free(mod, mod->module_init);
69220 - module_free(mod, mod->module_core);
69221 + module_free_exec(mod, mod->module_init_rx);
69222 + module_free_exec(mod, mod->module_core_rx);
69223 + module_free(mod, mod->module_init_rw);
69224 + module_free(mod, mod->module_core_rw);
69225 }
69226
69227 int __weak module_finalize(const Elf_Ehdr *hdr,
69228 @@ -2857,7 +2959,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
69229 static int post_relocation(struct module *mod, const struct load_info *info)
69230 {
69231 /* Sort exception table now relocations are done. */
69232 + pax_open_kernel();
69233 sort_extable(mod->extable, mod->extable + mod->num_exentries);
69234 + pax_close_kernel();
69235
69236 /* Copy relocated percpu area over. */
69237 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
69238 @@ -2908,9 +3012,38 @@ static struct module *load_module(void __user *umod,
69239 if (err)
69240 goto free_unload;
69241
69242 + /* Now copy in args */
69243 + mod->args = strndup_user(uargs, ~0UL >> 1);
69244 + if (IS_ERR(mod->args)) {
69245 + err = PTR_ERR(mod->args);
69246 + goto free_unload;
69247 + }
69248 +
69249 /* Set up MODINFO_ATTR fields */
69250 setup_modinfo(mod, &info);
69251
69252 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
69253 + {
69254 + char *p, *p2;
69255 +
69256 + if (strstr(mod->args, "grsec_modharden_netdev")) {
69257 + 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);
69258 + err = -EPERM;
69259 + goto free_modinfo;
69260 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
69261 + p += sizeof("grsec_modharden_normal") - 1;
69262 + p2 = strstr(p, "_");
69263 + if (p2) {
69264 + *p2 = '\0';
69265 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
69266 + *p2 = '_';
69267 + }
69268 + err = -EPERM;
69269 + goto free_modinfo;
69270 + }
69271 + }
69272 +#endif
69273 +
69274 /* Fix up syms, so that st_value is a pointer to location. */
69275 err = simplify_symbols(mod, &info);
69276 if (err < 0)
69277 @@ -2926,13 +3059,6 @@ static struct module *load_module(void __user *umod,
69278
69279 flush_module_icache(mod);
69280
69281 - /* Now copy in args */
69282 - mod->args = strndup_user(uargs, ~0UL >> 1);
69283 - if (IS_ERR(mod->args)) {
69284 - err = PTR_ERR(mod->args);
69285 - goto free_arch_cleanup;
69286 - }
69287 -
69288 /* Mark state as coming so strong_try_module_get() ignores us. */
69289 mod->state = MODULE_STATE_COMING;
69290
69291 @@ -2990,11 +3116,10 @@ static struct module *load_module(void __user *umod,
69292 unlock:
69293 mutex_unlock(&module_mutex);
69294 synchronize_sched();
69295 - kfree(mod->args);
69296 - free_arch_cleanup:
69297 module_arch_cleanup(mod);
69298 free_modinfo:
69299 free_modinfo(mod);
69300 + kfree(mod->args);
69301 free_unload:
69302 module_unload_free(mod);
69303 free_module:
69304 @@ -3035,16 +3160,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
69305 MODULE_STATE_COMING, mod);
69306
69307 /* Set RO and NX regions for core */
69308 - set_section_ro_nx(mod->module_core,
69309 - mod->core_text_size,
69310 - mod->core_ro_size,
69311 - mod->core_size);
69312 + set_section_ro_nx(mod->module_core_rx,
69313 + mod->core_size_rx,
69314 + mod->core_size_rx,
69315 + mod->core_size_rx);
69316
69317 /* Set RO and NX regions for init */
69318 - set_section_ro_nx(mod->module_init,
69319 - mod->init_text_size,
69320 - mod->init_ro_size,
69321 - mod->init_size);
69322 + set_section_ro_nx(mod->module_init_rx,
69323 + mod->init_size_rx,
69324 + mod->init_size_rx,
69325 + mod->init_size_rx);
69326
69327 do_mod_ctors(mod);
69328 /* Start the module */
69329 @@ -3090,11 +3215,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
69330 mod->strtab = mod->core_strtab;
69331 #endif
69332 unset_module_init_ro_nx(mod);
69333 - module_free(mod, mod->module_init);
69334 - mod->module_init = NULL;
69335 - mod->init_size = 0;
69336 - mod->init_ro_size = 0;
69337 - mod->init_text_size = 0;
69338 + module_free(mod, mod->module_init_rw);
69339 + module_free_exec(mod, mod->module_init_rx);
69340 + mod->module_init_rw = NULL;
69341 + mod->module_init_rx = NULL;
69342 + mod->init_size_rw = 0;
69343 + mod->init_size_rx = 0;
69344 mutex_unlock(&module_mutex);
69345
69346 return 0;
69347 @@ -3125,10 +3251,16 @@ static const char *get_ksymbol(struct module *mod,
69348 unsigned long nextval;
69349
69350 /* At worse, next value is at end of module */
69351 - if (within_module_init(addr, mod))
69352 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
69353 + if (within_module_init_rx(addr, mod))
69354 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
69355 + else if (within_module_init_rw(addr, mod))
69356 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
69357 + else if (within_module_core_rx(addr, mod))
69358 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
69359 + else if (within_module_core_rw(addr, mod))
69360 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
69361 else
69362 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
69363 + return NULL;
69364
69365 /* Scan for closest preceding symbol, and next symbol. (ELF
69366 starts real symbols at 1). */
69367 @@ -3363,7 +3495,7 @@ static int m_show(struct seq_file *m, void *p)
69368 char buf[8];
69369
69370 seq_printf(m, "%s %u",
69371 - mod->name, mod->init_size + mod->core_size);
69372 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
69373 print_unload_info(m, mod);
69374
69375 /* Informative for users. */
69376 @@ -3372,7 +3504,7 @@ static int m_show(struct seq_file *m, void *p)
69377 mod->state == MODULE_STATE_COMING ? "Loading":
69378 "Live");
69379 /* Used by oprofile and other similar tools. */
69380 - seq_printf(m, " 0x%pK", mod->module_core);
69381 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
69382
69383 /* Taints info */
69384 if (mod->taints)
69385 @@ -3408,7 +3540,17 @@ static const struct file_operations proc_modules_operations = {
69386
69387 static int __init proc_modules_init(void)
69388 {
69389 +#ifndef CONFIG_GRKERNSEC_HIDESYM
69390 +#ifdef CONFIG_GRKERNSEC_PROC_USER
69391 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
69392 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69393 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
69394 +#else
69395 proc_create("modules", 0, NULL, &proc_modules_operations);
69396 +#endif
69397 +#else
69398 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
69399 +#endif
69400 return 0;
69401 }
69402 module_init(proc_modules_init);
69403 @@ -3467,12 +3609,12 @@ struct module *__module_address(unsigned long addr)
69404 {
69405 struct module *mod;
69406
69407 - if (addr < module_addr_min || addr > module_addr_max)
69408 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
69409 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
69410 return NULL;
69411
69412 list_for_each_entry_rcu(mod, &modules, list)
69413 - if (within_module_core(addr, mod)
69414 - || within_module_init(addr, mod))
69415 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
69416 return mod;
69417 return NULL;
69418 }
69419 @@ -3506,11 +3648,20 @@ bool is_module_text_address(unsigned long addr)
69420 */
69421 struct module *__module_text_address(unsigned long addr)
69422 {
69423 - struct module *mod = __module_address(addr);
69424 + struct module *mod;
69425 +
69426 +#ifdef CONFIG_X86_32
69427 + addr = ktla_ktva(addr);
69428 +#endif
69429 +
69430 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
69431 + return NULL;
69432 +
69433 + mod = __module_address(addr);
69434 +
69435 if (mod) {
69436 /* Make sure it's within the text section. */
69437 - if (!within(addr, mod->module_init, mod->init_text_size)
69438 - && !within(addr, mod->module_core, mod->core_text_size))
69439 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
69440 mod = NULL;
69441 }
69442 return mod;
69443 diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
69444 index 7e3443f..b2a1e6b 100644
69445 --- a/kernel/mutex-debug.c
69446 +++ b/kernel/mutex-debug.c
69447 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
69448 }
69449
69450 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
69451 - struct thread_info *ti)
69452 + struct task_struct *task)
69453 {
69454 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
69455
69456 /* Mark the current thread as blocked on the lock: */
69457 - ti->task->blocked_on = waiter;
69458 + task->blocked_on = waiter;
69459 }
69460
69461 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
69462 - struct thread_info *ti)
69463 + struct task_struct *task)
69464 {
69465 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
69466 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
69467 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
69468 - ti->task->blocked_on = NULL;
69469 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
69470 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
69471 + task->blocked_on = NULL;
69472
69473 list_del_init(&waiter->list);
69474 waiter->task = NULL;
69475 diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
69476 index 0799fd3..d06ae3b 100644
69477 --- a/kernel/mutex-debug.h
69478 +++ b/kernel/mutex-debug.h
69479 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
69480 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
69481 extern void debug_mutex_add_waiter(struct mutex *lock,
69482 struct mutex_waiter *waiter,
69483 - struct thread_info *ti);
69484 + struct task_struct *task);
69485 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
69486 - struct thread_info *ti);
69487 + struct task_struct *task);
69488 extern void debug_mutex_unlock(struct mutex *lock);
69489 extern void debug_mutex_init(struct mutex *lock, const char *name,
69490 struct lock_class_key *key);
69491 diff --git a/kernel/mutex.c b/kernel/mutex.c
69492 index a307cc9..27fd2e9 100644
69493 --- a/kernel/mutex.c
69494 +++ b/kernel/mutex.c
69495 @@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
69496 spin_lock_mutex(&lock->wait_lock, flags);
69497
69498 debug_mutex_lock_common(lock, &waiter);
69499 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
69500 + debug_mutex_add_waiter(lock, &waiter, task);
69501
69502 /* add waiting tasks to the end of the waitqueue (FIFO): */
69503 list_add_tail(&waiter.list, &lock->wait_list);
69504 @@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
69505 * TASK_UNINTERRUPTIBLE case.)
69506 */
69507 if (unlikely(signal_pending_state(state, task))) {
69508 - mutex_remove_waiter(lock, &waiter,
69509 - task_thread_info(task));
69510 + mutex_remove_waiter(lock, &waiter, task);
69511 mutex_release(&lock->dep_map, 1, ip);
69512 spin_unlock_mutex(&lock->wait_lock, flags);
69513
69514 @@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
69515 done:
69516 lock_acquired(&lock->dep_map, ip);
69517 /* got the lock - rejoice! */
69518 - mutex_remove_waiter(lock, &waiter, current_thread_info());
69519 + mutex_remove_waiter(lock, &waiter, task);
69520 mutex_set_owner(lock);
69521
69522 /* set it to 0 if there are no waiters left: */
69523 diff --git a/kernel/panic.c b/kernel/panic.c
69524 index e1b2822..5edc1d9 100644
69525 --- a/kernel/panic.c
69526 +++ b/kernel/panic.c
69527 @@ -410,7 +410,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
69528 const char *board;
69529
69530 printk(KERN_WARNING "------------[ cut here ]------------\n");
69531 - printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
69532 + printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
69533 board = dmi_get_system_info(DMI_PRODUCT_NAME);
69534 if (board)
69535 printk(KERN_WARNING "Hardware name: %s\n", board);
69536 @@ -465,7 +465,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
69537 */
69538 void __stack_chk_fail(void)
69539 {
69540 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
69541 + dump_stack();
69542 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
69543 __builtin_return_address(0));
69544 }
69545 EXPORT_SYMBOL(__stack_chk_fail);
69546 diff --git a/kernel/pid.c b/kernel/pid.c
69547 index e86b291a..e8b0fb5 100644
69548 --- a/kernel/pid.c
69549 +++ b/kernel/pid.c
69550 @@ -33,6 +33,7 @@
69551 #include <linux/rculist.h>
69552 #include <linux/bootmem.h>
69553 #include <linux/hash.h>
69554 +#include <linux/security.h>
69555 #include <linux/pid_namespace.h>
69556 #include <linux/init_task.h>
69557 #include <linux/syscalls.h>
69558 @@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
69559
69560 int pid_max = PID_MAX_DEFAULT;
69561
69562 -#define RESERVED_PIDS 300
69563 +#define RESERVED_PIDS 500
69564
69565 int pid_max_min = RESERVED_PIDS + 1;
69566 int pid_max_max = PID_MAX_LIMIT;
69567 @@ -420,10 +421,18 @@ EXPORT_SYMBOL(pid_task);
69568 */
69569 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
69570 {
69571 + struct task_struct *task;
69572 +
69573 rcu_lockdep_assert(rcu_read_lock_held(),
69574 "find_task_by_pid_ns() needs rcu_read_lock()"
69575 " protection");
69576 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
69577 +
69578 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
69579 +
69580 + if (gr_pid_is_chrooted(task))
69581 + return NULL;
69582 +
69583 + return task;
69584 }
69585
69586 struct task_struct *find_task_by_vpid(pid_t vnr)
69587 @@ -431,6 +440,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
69588 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
69589 }
69590
69591 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
69592 +{
69593 + rcu_lockdep_assert(rcu_read_lock_held(),
69594 + "find_task_by_pid_ns() needs rcu_read_lock()"
69595 + " protection");
69596 + return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
69597 +}
69598 +
69599 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
69600 {
69601 struct pid *pid;
69602 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
69603 index 125cb67..a4d1c30 100644
69604 --- a/kernel/posix-cpu-timers.c
69605 +++ b/kernel/posix-cpu-timers.c
69606 @@ -6,6 +6,7 @@
69607 #include <linux/posix-timers.h>
69608 #include <linux/errno.h>
69609 #include <linux/math64.h>
69610 +#include <linux/security.h>
69611 #include <asm/uaccess.h>
69612 #include <linux/kernel_stat.h>
69613 #include <trace/events/timer.h>
69614 @@ -1578,14 +1579,14 @@ struct k_clock clock_posix_cpu = {
69615
69616 static __init int init_posix_cpu_timers(void)
69617 {
69618 - struct k_clock process = {
69619 + static struct k_clock process = {
69620 .clock_getres = process_cpu_clock_getres,
69621 .clock_get = process_cpu_clock_get,
69622 .timer_create = process_cpu_timer_create,
69623 .nsleep = process_cpu_nsleep,
69624 .nsleep_restart = process_cpu_nsleep_restart,
69625 };
69626 - struct k_clock thread = {
69627 + static struct k_clock thread = {
69628 .clock_getres = thread_cpu_clock_getres,
69629 .clock_get = thread_cpu_clock_get,
69630 .timer_create = thread_cpu_timer_create,
69631 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
69632 index 69185ae..cc2847a 100644
69633 --- a/kernel/posix-timers.c
69634 +++ b/kernel/posix-timers.c
69635 @@ -43,6 +43,7 @@
69636 #include <linux/idr.h>
69637 #include <linux/posix-clock.h>
69638 #include <linux/posix-timers.h>
69639 +#include <linux/grsecurity.h>
69640 #include <linux/syscalls.h>
69641 #include <linux/wait.h>
69642 #include <linux/workqueue.h>
69643 @@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
69644 * which we beg off on and pass to do_sys_settimeofday().
69645 */
69646
69647 -static struct k_clock posix_clocks[MAX_CLOCKS];
69648 +static struct k_clock *posix_clocks[MAX_CLOCKS];
69649
69650 /*
69651 * These ones are defined below.
69652 @@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
69653 */
69654 static __init int init_posix_timers(void)
69655 {
69656 - struct k_clock clock_realtime = {
69657 + static struct k_clock clock_realtime = {
69658 .clock_getres = hrtimer_get_res,
69659 .clock_get = posix_clock_realtime_get,
69660 .clock_set = posix_clock_realtime_set,
69661 @@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
69662 .timer_get = common_timer_get,
69663 .timer_del = common_timer_del,
69664 };
69665 - struct k_clock clock_monotonic = {
69666 + static struct k_clock clock_monotonic = {
69667 .clock_getres = hrtimer_get_res,
69668 .clock_get = posix_ktime_get_ts,
69669 .nsleep = common_nsleep,
69670 @@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
69671 .timer_get = common_timer_get,
69672 .timer_del = common_timer_del,
69673 };
69674 - struct k_clock clock_monotonic_raw = {
69675 + static struct k_clock clock_monotonic_raw = {
69676 .clock_getres = hrtimer_get_res,
69677 .clock_get = posix_get_monotonic_raw,
69678 };
69679 - struct k_clock clock_realtime_coarse = {
69680 + static struct k_clock clock_realtime_coarse = {
69681 .clock_getres = posix_get_coarse_res,
69682 .clock_get = posix_get_realtime_coarse,
69683 };
69684 - struct k_clock clock_monotonic_coarse = {
69685 + static struct k_clock clock_monotonic_coarse = {
69686 .clock_getres = posix_get_coarse_res,
69687 .clock_get = posix_get_monotonic_coarse,
69688 };
69689 - struct k_clock clock_boottime = {
69690 + static struct k_clock clock_boottime = {
69691 .clock_getres = hrtimer_get_res,
69692 .clock_get = posix_get_boottime,
69693 .nsleep = common_nsleep,
69694 @@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
69695 return;
69696 }
69697
69698 - posix_clocks[clock_id] = *new_clock;
69699 + posix_clocks[clock_id] = new_clock;
69700 }
69701 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
69702
69703 @@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
69704 return (id & CLOCKFD_MASK) == CLOCKFD ?
69705 &clock_posix_dynamic : &clock_posix_cpu;
69706
69707 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
69708 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
69709 return NULL;
69710 - return &posix_clocks[id];
69711 + return posix_clocks[id];
69712 }
69713
69714 static int common_timer_create(struct k_itimer *new_timer)
69715 @@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
69716 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
69717 return -EFAULT;
69718
69719 + /* only the CLOCK_REALTIME clock can be set, all other clocks
69720 + have their clock_set fptr set to a nosettime dummy function
69721 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
69722 + call common_clock_set, which calls do_sys_settimeofday, which
69723 + we hook
69724 + */
69725 +
69726 return kc->clock_set(which_clock, &new_tp);
69727 }
69728
69729 diff --git a/kernel/power/poweroff.c b/kernel/power/poweroff.c
69730 index d523593..68197a4 100644
69731 --- a/kernel/power/poweroff.c
69732 +++ b/kernel/power/poweroff.c
69733 @@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_poweroff_op = {
69734 .enable_mask = SYSRQ_ENABLE_BOOT,
69735 };
69736
69737 -static int pm_sysrq_init(void)
69738 +static int __init pm_sysrq_init(void)
69739 {
69740 register_sysrq_key('o', &sysrq_poweroff_op);
69741 return 0;
69742 diff --git a/kernel/power/process.c b/kernel/power/process.c
69743 index 19db29f..33b52b6 100644
69744 --- a/kernel/power/process.c
69745 +++ b/kernel/power/process.c
69746 @@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
69747 u64 elapsed_csecs64;
69748 unsigned int elapsed_csecs;
69749 bool wakeup = false;
69750 + bool timedout = false;
69751
69752 do_gettimeofday(&start);
69753
69754 @@ -43,6 +44,8 @@ static int try_to_freeze_tasks(bool user_only)
69755
69756 while (true) {
69757 todo = 0;
69758 + if (time_after(jiffies, end_time))
69759 + timedout = true;
69760 read_lock(&tasklist_lock);
69761 do_each_thread(g, p) {
69762 if (p == current || !freeze_task(p))
69763 @@ -58,9 +61,13 @@ static int try_to_freeze_tasks(bool user_only)
69764 * guaranteed that TASK_STOPPED/TRACED -> TASK_RUNNING
69765 * transition can't race with task state testing here.
69766 */
69767 - if (!task_is_stopped_or_traced(p) &&
69768 - !freezer_should_skip(p))
69769 + if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
69770 todo++;
69771 + if (timedout) {
69772 + printk(KERN_ERR "Task refusing to freeze:\n");
69773 + sched_show_task(p);
69774 + }
69775 + }
69776 } while_each_thread(g, p);
69777 read_unlock(&tasklist_lock);
69778
69779 @@ -69,7 +76,7 @@ static int try_to_freeze_tasks(bool user_only)
69780 todo += wq_busy;
69781 }
69782
69783 - if (!todo || time_after(jiffies, end_time))
69784 + if (!todo || timedout)
69785 break;
69786
69787 if (pm_wakeup_pending()) {
69788 diff --git a/kernel/printk.c b/kernel/printk.c
69789 index 66a2ea3..10f3a01 100644
69790 --- a/kernel/printk.c
69791 +++ b/kernel/printk.c
69792 @@ -817,6 +817,11 @@ static int check_syslog_permissions(int type, bool from_file)
69793 if (from_file && type != SYSLOG_ACTION_OPEN)
69794 return 0;
69795
69796 +#ifdef CONFIG_GRKERNSEC_DMESG
69797 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
69798 + return -EPERM;
69799 +#endif
69800 +
69801 if (syslog_action_restricted(type)) {
69802 if (capable(CAP_SYSLOG))
69803 return 0;
69804 diff --git a/kernel/profile.c b/kernel/profile.c
69805 index 76b8e77..a2930e8 100644
69806 --- a/kernel/profile.c
69807 +++ b/kernel/profile.c
69808 @@ -39,7 +39,7 @@ struct profile_hit {
69809 /* Oprofile timer tick hook */
69810 static int (*timer_hook)(struct pt_regs *) __read_mostly;
69811
69812 -static atomic_t *prof_buffer;
69813 +static atomic_unchecked_t *prof_buffer;
69814 static unsigned long prof_len, prof_shift;
69815
69816 int prof_on __read_mostly;
69817 @@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
69818 hits[i].pc = 0;
69819 continue;
69820 }
69821 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
69822 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
69823 hits[i].hits = hits[i].pc = 0;
69824 }
69825 }
69826 @@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
69827 * Add the current hit(s) and flush the write-queue out
69828 * to the global buffer:
69829 */
69830 - atomic_add(nr_hits, &prof_buffer[pc]);
69831 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
69832 for (i = 0; i < NR_PROFILE_HIT; ++i) {
69833 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
69834 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
69835 hits[i].pc = hits[i].hits = 0;
69836 }
69837 out:
69838 @@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
69839 {
69840 unsigned long pc;
69841 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
69842 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
69843 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
69844 }
69845 #endif /* !CONFIG_SMP */
69846
69847 @@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
69848 return -EFAULT;
69849 buf++; p++; count--; read++;
69850 }
69851 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
69852 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
69853 if (copy_to_user(buf, (void *)pnt, count))
69854 return -EFAULT;
69855 read += count;
69856 @@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
69857 }
69858 #endif
69859 profile_discard_flip_buffers();
69860 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
69861 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
69862 return count;
69863 }
69864
69865 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
69866 index a232bb5..2a65ef9 100644
69867 --- a/kernel/ptrace.c
69868 +++ b/kernel/ptrace.c
69869 @@ -279,7 +279,7 @@ static int ptrace_attach(struct task_struct *task, long request,
69870
69871 if (seize)
69872 flags |= PT_SEIZED;
69873 - if (ns_capable(task_user_ns(task), CAP_SYS_PTRACE))
69874 + if (ns_capable_nolog(task_user_ns(task), CAP_SYS_PTRACE))
69875 flags |= PT_PTRACE_CAP;
69876 task->ptrace = flags;
69877
69878 @@ -486,7 +486,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
69879 break;
69880 return -EIO;
69881 }
69882 - if (copy_to_user(dst, buf, retval))
69883 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
69884 return -EFAULT;
69885 copied += retval;
69886 src += retval;
69887 @@ -671,7 +671,7 @@ int ptrace_request(struct task_struct *child, long request,
69888 bool seized = child->ptrace & PT_SEIZED;
69889 int ret = -EIO;
69890 siginfo_t siginfo, *si;
69891 - void __user *datavp = (void __user *) data;
69892 + void __user *datavp = (__force void __user *) data;
69893 unsigned long __user *datalp = datavp;
69894 unsigned long flags;
69895
69896 @@ -873,14 +873,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
69897 goto out;
69898 }
69899
69900 + if (gr_handle_ptrace(child, request)) {
69901 + ret = -EPERM;
69902 + goto out_put_task_struct;
69903 + }
69904 +
69905 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
69906 ret = ptrace_attach(child, request, addr, data);
69907 /*
69908 * Some architectures need to do book-keeping after
69909 * a ptrace attach.
69910 */
69911 - if (!ret)
69912 + if (!ret) {
69913 arch_ptrace_attach(child);
69914 + gr_audit_ptrace(child);
69915 + }
69916 goto out_put_task_struct;
69917 }
69918
69919 @@ -906,7 +913,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
69920 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
69921 if (copied != sizeof(tmp))
69922 return -EIO;
69923 - return put_user(tmp, (unsigned long __user *)data);
69924 + return put_user(tmp, (__force unsigned long __user *)data);
69925 }
69926
69927 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
69928 @@ -1016,14 +1023,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
69929 goto out;
69930 }
69931
69932 + if (gr_handle_ptrace(child, request)) {
69933 + ret = -EPERM;
69934 + goto out_put_task_struct;
69935 + }
69936 +
69937 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
69938 ret = ptrace_attach(child, request, addr, data);
69939 /*
69940 * Some architectures need to do book-keeping after
69941 * a ptrace attach.
69942 */
69943 - if (!ret)
69944 + if (!ret) {
69945 arch_ptrace_attach(child);
69946 + gr_audit_ptrace(child);
69947 + }
69948 goto out_put_task_struct;
69949 }
69950
69951 diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
69952 index 547b1fe..65e874e 100644
69953 --- a/kernel/rcutiny.c
69954 +++ b/kernel/rcutiny.c
69955 @@ -46,7 +46,7 @@
69956 struct rcu_ctrlblk;
69957 static void invoke_rcu_callbacks(void);
69958 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
69959 -static void rcu_process_callbacks(struct softirq_action *unused);
69960 +static void rcu_process_callbacks(void);
69961 static void __call_rcu(struct rcu_head *head,
69962 void (*func)(struct rcu_head *rcu),
69963 struct rcu_ctrlblk *rcp);
69964 @@ -307,7 +307,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
69965 rcu_is_callbacks_kthread()));
69966 }
69967
69968 -static void rcu_process_callbacks(struct softirq_action *unused)
69969 +static void rcu_process_callbacks(void)
69970 {
69971 __rcu_process_callbacks(&rcu_sched_ctrlblk);
69972 __rcu_process_callbacks(&rcu_bh_ctrlblk);
69973 diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
69974 index 918fd1e..85089bb 100644
69975 --- a/kernel/rcutiny_plugin.h
69976 +++ b/kernel/rcutiny_plugin.h
69977 @@ -893,7 +893,7 @@ static int rcu_kthread(void *arg)
69978 have_rcu_kthread_work = morework;
69979 local_irq_restore(flags);
69980 if (work)
69981 - rcu_process_callbacks(NULL);
69982 + rcu_process_callbacks();
69983 schedule_timeout_interruptible(1); /* Leave CPU for others. */
69984 }
69985
69986 diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
69987 index 25b1503..1988a74 100644
69988 --- a/kernel/rcutorture.c
69989 +++ b/kernel/rcutorture.c
69990 @@ -162,12 +162,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
69991 { 0 };
69992 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
69993 { 0 };
69994 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
69995 -static atomic_t n_rcu_torture_alloc;
69996 -static atomic_t n_rcu_torture_alloc_fail;
69997 -static atomic_t n_rcu_torture_free;
69998 -static atomic_t n_rcu_torture_mberror;
69999 -static atomic_t n_rcu_torture_error;
70000 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
70001 +static atomic_unchecked_t n_rcu_torture_alloc;
70002 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
70003 +static atomic_unchecked_t n_rcu_torture_free;
70004 +static atomic_unchecked_t n_rcu_torture_mberror;
70005 +static atomic_unchecked_t n_rcu_torture_error;
70006 static long n_rcu_torture_barrier_error;
70007 static long n_rcu_torture_boost_ktrerror;
70008 static long n_rcu_torture_boost_rterror;
70009 @@ -265,11 +265,11 @@ rcu_torture_alloc(void)
70010
70011 spin_lock_bh(&rcu_torture_lock);
70012 if (list_empty(&rcu_torture_freelist)) {
70013 - atomic_inc(&n_rcu_torture_alloc_fail);
70014 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
70015 spin_unlock_bh(&rcu_torture_lock);
70016 return NULL;
70017 }
70018 - atomic_inc(&n_rcu_torture_alloc);
70019 + atomic_inc_unchecked(&n_rcu_torture_alloc);
70020 p = rcu_torture_freelist.next;
70021 list_del_init(p);
70022 spin_unlock_bh(&rcu_torture_lock);
70023 @@ -282,7 +282,7 @@ rcu_torture_alloc(void)
70024 static void
70025 rcu_torture_free(struct rcu_torture *p)
70026 {
70027 - atomic_inc(&n_rcu_torture_free);
70028 + atomic_inc_unchecked(&n_rcu_torture_free);
70029 spin_lock_bh(&rcu_torture_lock);
70030 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
70031 spin_unlock_bh(&rcu_torture_lock);
70032 @@ -403,7 +403,7 @@ rcu_torture_cb(struct rcu_head *p)
70033 i = rp->rtort_pipe_count;
70034 if (i > RCU_TORTURE_PIPE_LEN)
70035 i = RCU_TORTURE_PIPE_LEN;
70036 - atomic_inc(&rcu_torture_wcount[i]);
70037 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
70038 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
70039 rp->rtort_mbtest = 0;
70040 rcu_torture_free(rp);
70041 @@ -452,7 +452,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
70042 i = rp->rtort_pipe_count;
70043 if (i > RCU_TORTURE_PIPE_LEN)
70044 i = RCU_TORTURE_PIPE_LEN;
70045 - atomic_inc(&rcu_torture_wcount[i]);
70046 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
70047 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
70048 rp->rtort_mbtest = 0;
70049 list_del(&rp->rtort_free);
70050 @@ -995,7 +995,7 @@ rcu_torture_writer(void *arg)
70051 i = old_rp->rtort_pipe_count;
70052 if (i > RCU_TORTURE_PIPE_LEN)
70053 i = RCU_TORTURE_PIPE_LEN;
70054 - atomic_inc(&rcu_torture_wcount[i]);
70055 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
70056 old_rp->rtort_pipe_count++;
70057 cur_ops->deferred_free(old_rp);
70058 }
70059 @@ -1080,7 +1080,7 @@ static void rcu_torture_timer(unsigned long unused)
70060 }
70061 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
70062 if (p->rtort_mbtest == 0)
70063 - atomic_inc(&n_rcu_torture_mberror);
70064 + atomic_inc_unchecked(&n_rcu_torture_mberror);
70065 spin_lock(&rand_lock);
70066 cur_ops->read_delay(&rand);
70067 n_rcu_torture_timers++;
70068 @@ -1144,7 +1144,7 @@ rcu_torture_reader(void *arg)
70069 }
70070 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
70071 if (p->rtort_mbtest == 0)
70072 - atomic_inc(&n_rcu_torture_mberror);
70073 + atomic_inc_unchecked(&n_rcu_torture_mberror);
70074 cur_ops->read_delay(&rand);
70075 preempt_disable();
70076 pipe_count = p->rtort_pipe_count;
70077 @@ -1203,11 +1203,11 @@ rcu_torture_printk(char *page)
70078 rcu_torture_current,
70079 rcu_torture_current_version,
70080 list_empty(&rcu_torture_freelist),
70081 - atomic_read(&n_rcu_torture_alloc),
70082 - atomic_read(&n_rcu_torture_alloc_fail),
70083 - atomic_read(&n_rcu_torture_free));
70084 + atomic_read_unchecked(&n_rcu_torture_alloc),
70085 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
70086 + atomic_read_unchecked(&n_rcu_torture_free));
70087 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
70088 - atomic_read(&n_rcu_torture_mberror),
70089 + atomic_read_unchecked(&n_rcu_torture_mberror),
70090 n_rcu_torture_boost_ktrerror,
70091 n_rcu_torture_boost_rterror);
70092 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
70093 @@ -1224,14 +1224,14 @@ rcu_torture_printk(char *page)
70094 n_barrier_attempts,
70095 n_rcu_torture_barrier_error);
70096 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
70097 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
70098 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
70099 n_rcu_torture_barrier_error != 0 ||
70100 n_rcu_torture_boost_ktrerror != 0 ||
70101 n_rcu_torture_boost_rterror != 0 ||
70102 n_rcu_torture_boost_failure != 0 ||
70103 i > 1) {
70104 cnt += sprintf(&page[cnt], "!!! ");
70105 - atomic_inc(&n_rcu_torture_error);
70106 + atomic_inc_unchecked(&n_rcu_torture_error);
70107 WARN_ON_ONCE(1);
70108 }
70109 cnt += sprintf(&page[cnt], "Reader Pipe: ");
70110 @@ -1245,7 +1245,7 @@ rcu_torture_printk(char *page)
70111 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
70112 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
70113 cnt += sprintf(&page[cnt], " %d",
70114 - atomic_read(&rcu_torture_wcount[i]));
70115 + atomic_read_unchecked(&rcu_torture_wcount[i]));
70116 }
70117 cnt += sprintf(&page[cnt], "\n");
70118 if (cur_ops->stats)
70119 @@ -1905,7 +1905,7 @@ rcu_torture_cleanup(void)
70120
70121 if (cur_ops->cleanup)
70122 cur_ops->cleanup();
70123 - if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
70124 + if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
70125 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
70126 else if (n_online_successes != n_online_attempts ||
70127 n_offline_successes != n_offline_attempts)
70128 @@ -1974,18 +1974,18 @@ rcu_torture_init(void)
70129
70130 rcu_torture_current = NULL;
70131 rcu_torture_current_version = 0;
70132 - atomic_set(&n_rcu_torture_alloc, 0);
70133 - atomic_set(&n_rcu_torture_alloc_fail, 0);
70134 - atomic_set(&n_rcu_torture_free, 0);
70135 - atomic_set(&n_rcu_torture_mberror, 0);
70136 - atomic_set(&n_rcu_torture_error, 0);
70137 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
70138 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
70139 + atomic_set_unchecked(&n_rcu_torture_free, 0);
70140 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
70141 + atomic_set_unchecked(&n_rcu_torture_error, 0);
70142 n_rcu_torture_barrier_error = 0;
70143 n_rcu_torture_boost_ktrerror = 0;
70144 n_rcu_torture_boost_rterror = 0;
70145 n_rcu_torture_boost_failure = 0;
70146 n_rcu_torture_boosts = 0;
70147 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
70148 - atomic_set(&rcu_torture_wcount[i], 0);
70149 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
70150 for_each_possible_cpu(cpu) {
70151 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
70152 per_cpu(rcu_torture_count, cpu)[i] = 0;
70153 diff --git a/kernel/rcutree.c b/kernel/rcutree.c
70154 index f7bcd9e..8973e14 100644
70155 --- a/kernel/rcutree.c
70156 +++ b/kernel/rcutree.c
70157 @@ -369,9 +369,9 @@ static void rcu_idle_enter_common(struct rcu_dynticks *rdtp, long long oldval)
70158 rcu_prepare_for_idle(smp_processor_id());
70159 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
70160 smp_mb__before_atomic_inc(); /* See above. */
70161 - atomic_inc(&rdtp->dynticks);
70162 + atomic_inc_unchecked(&rdtp->dynticks);
70163 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
70164 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
70165 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
70166
70167 /*
70168 * The idle task is not permitted to enter the idle loop while
70169 @@ -460,10 +460,10 @@ void rcu_irq_exit(void)
70170 static void rcu_idle_exit_common(struct rcu_dynticks *rdtp, long long oldval)
70171 {
70172 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
70173 - atomic_inc(&rdtp->dynticks);
70174 + atomic_inc_unchecked(&rdtp->dynticks);
70175 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
70176 smp_mb__after_atomic_inc(); /* See above. */
70177 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
70178 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
70179 rcu_cleanup_after_idle(smp_processor_id());
70180 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
70181 if (!is_idle_task(current)) {
70182 @@ -557,14 +557,14 @@ void rcu_nmi_enter(void)
70183 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
70184
70185 if (rdtp->dynticks_nmi_nesting == 0 &&
70186 - (atomic_read(&rdtp->dynticks) & 0x1))
70187 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
70188 return;
70189 rdtp->dynticks_nmi_nesting++;
70190 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
70191 - atomic_inc(&rdtp->dynticks);
70192 + atomic_inc_unchecked(&rdtp->dynticks);
70193 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
70194 smp_mb__after_atomic_inc(); /* See above. */
70195 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
70196 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
70197 }
70198
70199 /**
70200 @@ -583,9 +583,9 @@ void rcu_nmi_exit(void)
70201 return;
70202 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
70203 smp_mb__before_atomic_inc(); /* See above. */
70204 - atomic_inc(&rdtp->dynticks);
70205 + atomic_inc_unchecked(&rdtp->dynticks);
70206 smp_mb__after_atomic_inc(); /* Force delay to next write. */
70207 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
70208 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
70209 }
70210
70211 /**
70212 @@ -599,7 +599,7 @@ int rcu_is_cpu_idle(void)
70213 int ret;
70214
70215 preempt_disable();
70216 - ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
70217 + ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
70218 preempt_enable();
70219 return ret;
70220 }
70221 @@ -667,7 +667,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
70222 */
70223 static int dyntick_save_progress_counter(struct rcu_data *rdp)
70224 {
70225 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
70226 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
70227 return (rdp->dynticks_snap & 0x1) == 0;
70228 }
70229
70230 @@ -682,7 +682,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
70231 unsigned int curr;
70232 unsigned int snap;
70233
70234 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
70235 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
70236 snap = (unsigned int)rdp->dynticks_snap;
70237
70238 /*
70239 @@ -712,10 +712,10 @@ static int jiffies_till_stall_check(void)
70240 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
70241 */
70242 if (till_stall_check < 3) {
70243 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
70244 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
70245 till_stall_check = 3;
70246 } else if (till_stall_check > 300) {
70247 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
70248 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
70249 till_stall_check = 300;
70250 }
70251 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
70252 @@ -1351,7 +1351,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
70253 rsp->qlen += rdp->qlen;
70254 rdp->n_cbs_orphaned += rdp->qlen;
70255 rdp->qlen_lazy = 0;
70256 - ACCESS_ONCE(rdp->qlen) = 0;
70257 + ACCESS_ONCE_RW(rdp->qlen) = 0;
70258 }
70259
70260 /*
70261 @@ -1604,7 +1604,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
70262 }
70263 smp_mb(); /* List handling before counting for rcu_barrier(). */
70264 rdp->qlen_lazy -= count_lazy;
70265 - ACCESS_ONCE(rdp->qlen) -= count;
70266 + ACCESS_ONCE_RW(rdp->qlen) -= count;
70267 rdp->n_cbs_invoked += count;
70268
70269 /* Reinstate batch limit if we have worked down the excess. */
70270 @@ -1836,7 +1836,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
70271 /*
70272 * Do RCU core processing for the current CPU.
70273 */
70274 -static void rcu_process_callbacks(struct softirq_action *unused)
70275 +static void rcu_process_callbacks(void)
70276 {
70277 struct rcu_state *rsp;
70278
70279 @@ -1943,7 +1943,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
70280 rdp = this_cpu_ptr(rsp->rda);
70281
70282 /* Add the callback to our list. */
70283 - ACCESS_ONCE(rdp->qlen)++;
70284 + ACCESS_ONCE_RW(rdp->qlen)++;
70285 if (lazy)
70286 rdp->qlen_lazy++;
70287 else
70288 @@ -2057,8 +2057,8 @@ void synchronize_rcu_bh(void)
70289 }
70290 EXPORT_SYMBOL_GPL(synchronize_rcu_bh);
70291
70292 -static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
70293 -static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
70294 +static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
70295 +static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
70296
70297 static int synchronize_sched_expedited_cpu_stop(void *data)
70298 {
70299 @@ -2119,7 +2119,7 @@ void synchronize_sched_expedited(void)
70300 int firstsnap, s, snap, trycount = 0;
70301
70302 /* Note that atomic_inc_return() implies full memory barrier. */
70303 - firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
70304 + firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
70305 get_online_cpus();
70306 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
70307
70308 @@ -2141,7 +2141,7 @@ void synchronize_sched_expedited(void)
70309 }
70310
70311 /* Check to see if someone else did our work for us. */
70312 - s = atomic_read(&sync_sched_expedited_done);
70313 + s = atomic_read_unchecked(&sync_sched_expedited_done);
70314 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
70315 smp_mb(); /* ensure test happens before caller kfree */
70316 return;
70317 @@ -2156,7 +2156,7 @@ void synchronize_sched_expedited(void)
70318 * grace period works for us.
70319 */
70320 get_online_cpus();
70321 - snap = atomic_read(&sync_sched_expedited_started);
70322 + snap = atomic_read_unchecked(&sync_sched_expedited_started);
70323 smp_mb(); /* ensure read is before try_stop_cpus(). */
70324 }
70325
70326 @@ -2167,12 +2167,12 @@ void synchronize_sched_expedited(void)
70327 * than we did beat us to the punch.
70328 */
70329 do {
70330 - s = atomic_read(&sync_sched_expedited_done);
70331 + s = atomic_read_unchecked(&sync_sched_expedited_done);
70332 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
70333 smp_mb(); /* ensure test happens before caller kfree */
70334 break;
70335 }
70336 - } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
70337 + } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
70338
70339 put_online_cpus();
70340 }
70341 @@ -2366,7 +2366,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
70342 * ACCESS_ONCE() to prevent the compiler from speculating
70343 * the increment to precede the early-exit check.
70344 */
70345 - ACCESS_ONCE(rsp->n_barrier_done)++;
70346 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
70347 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
70348 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
70349 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
70350 @@ -2448,7 +2448,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
70351
70352 /* Increment ->n_barrier_done to prevent duplicate work. */
70353 smp_mb(); /* Keep increment after above mechanism. */
70354 - ACCESS_ONCE(rsp->n_barrier_done)++;
70355 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
70356 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
70357 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
70358 smp_mb(); /* Keep increment before caller's subsequent code. */
70359 @@ -2495,10 +2495,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
70360 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
70361 init_callback_list(rdp);
70362 rdp->qlen_lazy = 0;
70363 - ACCESS_ONCE(rdp->qlen) = 0;
70364 + ACCESS_ONCE_RW(rdp->qlen) = 0;
70365 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
70366 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
70367 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
70368 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
70369 rdp->cpu = cpu;
70370 rdp->rsp = rsp;
70371 raw_spin_unlock_irqrestore(&rnp->lock, flags);
70372 @@ -2526,8 +2526,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
70373 rdp->n_force_qs_snap = rsp->n_force_qs;
70374 rdp->blimit = blimit;
70375 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
70376 - atomic_set(&rdp->dynticks->dynticks,
70377 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
70378 + atomic_set_unchecked(&rdp->dynticks->dynticks,
70379 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
70380 rcu_prepare_for_idle_init(cpu);
70381 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
70382
70383 diff --git a/kernel/rcutree.h b/kernel/rcutree.h
70384 index 4d29169..d104a3c 100644
70385 --- a/kernel/rcutree.h
70386 +++ b/kernel/rcutree.h
70387 @@ -86,7 +86,7 @@ struct rcu_dynticks {
70388 long long dynticks_nesting; /* Track irq/process nesting level. */
70389 /* Process level is worth LLONG_MAX/2. */
70390 int dynticks_nmi_nesting; /* Track NMI nesting level. */
70391 - atomic_t dynticks; /* Even value for idle, else odd. */
70392 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
70393 #ifdef CONFIG_RCU_FAST_NO_HZ
70394 int dyntick_drain; /* Prepare-for-idle state variable. */
70395 unsigned long dyntick_holdoff;
70396 diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
70397 index 7f3244c..417d606 100644
70398 --- a/kernel/rcutree_plugin.h
70399 +++ b/kernel/rcutree_plugin.h
70400 @@ -843,7 +843,7 @@ void synchronize_rcu_expedited(void)
70401
70402 /* Clean up and exit. */
70403 smp_mb(); /* ensure expedited GP seen before counter increment. */
70404 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
70405 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
70406 unlock_mb_ret:
70407 mutex_unlock(&sync_rcu_preempt_exp_mutex);
70408 mb_ret:
70409 diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
70410 index abffb48..cbfa6d3 100644
70411 --- a/kernel/rcutree_trace.c
70412 +++ b/kernel/rcutree_trace.c
70413 @@ -93,7 +93,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
70414 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
70415 rdp->qs_pending);
70416 seq_printf(m, " dt=%d/%llx/%d df=%lu",
70417 - atomic_read(&rdp->dynticks->dynticks),
70418 + atomic_read_unchecked(&rdp->dynticks->dynticks),
70419 rdp->dynticks->dynticks_nesting,
70420 rdp->dynticks->dynticks_nmi_nesting,
70421 rdp->dynticks_fqs);
70422 @@ -157,7 +157,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
70423 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
70424 rdp->qs_pending);
70425 seq_printf(m, ",%d,%llx,%d,%lu",
70426 - atomic_read(&rdp->dynticks->dynticks),
70427 + atomic_read_unchecked(&rdp->dynticks->dynticks),
70428 rdp->dynticks->dynticks_nesting,
70429 rdp->dynticks->dynticks_nmi_nesting,
70430 rdp->dynticks_fqs);
70431 diff --git a/kernel/resource.c b/kernel/resource.c
70432 index 34d4588..10baa6a 100644
70433 --- a/kernel/resource.c
70434 +++ b/kernel/resource.c
70435 @@ -143,8 +143,18 @@ static const struct file_operations proc_iomem_operations = {
70436
70437 static int __init ioresources_init(void)
70438 {
70439 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
70440 +#ifdef CONFIG_GRKERNSEC_PROC_USER
70441 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
70442 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
70443 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
70444 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
70445 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
70446 +#endif
70447 +#else
70448 proc_create("ioports", 0, NULL, &proc_ioports_operations);
70449 proc_create("iomem", 0, NULL, &proc_iomem_operations);
70450 +#endif
70451 return 0;
70452 }
70453 __initcall(ioresources_init);
70454 diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
70455 index 98ec494..4241d6d 100644
70456 --- a/kernel/rtmutex-tester.c
70457 +++ b/kernel/rtmutex-tester.c
70458 @@ -20,7 +20,7 @@
70459 #define MAX_RT_TEST_MUTEXES 8
70460
70461 static spinlock_t rttest_lock;
70462 -static atomic_t rttest_event;
70463 +static atomic_unchecked_t rttest_event;
70464
70465 struct test_thread_data {
70466 int opcode;
70467 @@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
70468
70469 case RTTEST_LOCKCONT:
70470 td->mutexes[td->opdata] = 1;
70471 - td->event = atomic_add_return(1, &rttest_event);
70472 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70473 return 0;
70474
70475 case RTTEST_RESET:
70476 @@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
70477 return 0;
70478
70479 case RTTEST_RESETEVENT:
70480 - atomic_set(&rttest_event, 0);
70481 + atomic_set_unchecked(&rttest_event, 0);
70482 return 0;
70483
70484 default:
70485 @@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
70486 return ret;
70487
70488 td->mutexes[id] = 1;
70489 - td->event = atomic_add_return(1, &rttest_event);
70490 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70491 rt_mutex_lock(&mutexes[id]);
70492 - td->event = atomic_add_return(1, &rttest_event);
70493 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70494 td->mutexes[id] = 4;
70495 return 0;
70496
70497 @@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
70498 return ret;
70499
70500 td->mutexes[id] = 1;
70501 - td->event = atomic_add_return(1, &rttest_event);
70502 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70503 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
70504 - td->event = atomic_add_return(1, &rttest_event);
70505 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70506 td->mutexes[id] = ret ? 0 : 4;
70507 return ret ? -EINTR : 0;
70508
70509 @@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
70510 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
70511 return ret;
70512
70513 - td->event = atomic_add_return(1, &rttest_event);
70514 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70515 rt_mutex_unlock(&mutexes[id]);
70516 - td->event = atomic_add_return(1, &rttest_event);
70517 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70518 td->mutexes[id] = 0;
70519 return 0;
70520
70521 @@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
70522 break;
70523
70524 td->mutexes[dat] = 2;
70525 - td->event = atomic_add_return(1, &rttest_event);
70526 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70527 break;
70528
70529 default:
70530 @@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
70531 return;
70532
70533 td->mutexes[dat] = 3;
70534 - td->event = atomic_add_return(1, &rttest_event);
70535 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70536 break;
70537
70538 case RTTEST_LOCKNOWAIT:
70539 @@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
70540 return;
70541
70542 td->mutexes[dat] = 1;
70543 - td->event = atomic_add_return(1, &rttest_event);
70544 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70545 return;
70546
70547 default:
70548 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
70549 index 0984a21..7e50319 100644
70550 --- a/kernel/sched/auto_group.c
70551 +++ b/kernel/sched/auto_group.c
70552 @@ -11,7 +11,7 @@
70553
70554 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
70555 static struct autogroup autogroup_default;
70556 -static atomic_t autogroup_seq_nr;
70557 +static atomic_unchecked_t autogroup_seq_nr;
70558
70559 void __init autogroup_init(struct task_struct *init_task)
70560 {
70561 @@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
70562
70563 kref_init(&ag->kref);
70564 init_rwsem(&ag->lock);
70565 - ag->id = atomic_inc_return(&autogroup_seq_nr);
70566 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
70567 ag->tg = tg;
70568 #ifdef CONFIG_RT_GROUP_SCHED
70569 /*
70570 @@ -143,15 +143,11 @@ autogroup_move_group(struct task_struct *p, struct autogroup *ag)
70571
70572 p->signal->autogroup = autogroup_kref_get(ag);
70573
70574 - if (!ACCESS_ONCE(sysctl_sched_autogroup_enabled))
70575 - goto out;
70576 -
70577 t = p;
70578 do {
70579 sched_move_task(t);
70580 } while_each_thread(p, t);
70581
70582 -out:
70583 unlock_task_sighand(p, &flags);
70584 autogroup_kref_put(prev);
70585 }
70586 diff --git a/kernel/sched/auto_group.h b/kernel/sched/auto_group.h
70587 index 8bd0471..443232e 100644
70588 --- a/kernel/sched/auto_group.h
70589 +++ b/kernel/sched/auto_group.h
70590 @@ -4,11 +4,6 @@
70591 #include <linux/rwsem.h>
70592
70593 struct autogroup {
70594 - /*
70595 - * reference doesn't mean how many thread attach to this
70596 - * autogroup now. It just stands for the number of task
70597 - * could use this autogroup.
70598 - */
70599 struct kref kref;
70600 struct task_group *tg;
70601 struct rw_semaphore lock;
70602 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
70603 index 1a48cdb..d3949ff 100644
70604 --- a/kernel/sched/core.c
70605 +++ b/kernel/sched/core.c
70606 @@ -4103,6 +4103,8 @@ int can_nice(const struct task_struct *p, const int nice)
70607 /* convert nice value [19,-20] to rlimit style value [1,40] */
70608 int nice_rlim = 20 - nice;
70609
70610 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
70611 +
70612 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
70613 capable(CAP_SYS_NICE));
70614 }
70615 @@ -4136,7 +4138,8 @@ SYSCALL_DEFINE1(nice, int, increment)
70616 if (nice > 19)
70617 nice = 19;
70618
70619 - if (increment < 0 && !can_nice(current, nice))
70620 + if (increment < 0 && (!can_nice(current, nice) ||
70621 + gr_handle_chroot_nice()))
70622 return -EPERM;
70623
70624 retval = security_task_setnice(current, nice);
70625 @@ -4290,6 +4293,7 @@ recheck:
70626 unsigned long rlim_rtprio =
70627 task_rlimit(p, RLIMIT_RTPRIO);
70628
70629 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
70630 /* can't set/change the rt policy */
70631 if (policy != p->policy && !rlim_rtprio)
70632 return -EPERM;
70633 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
70634 index 96e2b18..bb31eec 100644
70635 --- a/kernel/sched/fair.c
70636 +++ b/kernel/sched/fair.c
70637 @@ -4923,7 +4923,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
70638 * run_rebalance_domains is triggered when needed from the scheduler tick.
70639 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
70640 */
70641 -static void run_rebalance_domains(struct softirq_action *h)
70642 +static void run_rebalance_domains(void)
70643 {
70644 int this_cpu = smp_processor_id();
70645 struct rq *this_rq = cpu_rq(this_cpu);
70646 diff --git a/kernel/signal.c b/kernel/signal.c
70647 index be4f856..453401c 100644
70648 --- a/kernel/signal.c
70649 +++ b/kernel/signal.c
70650 @@ -48,12 +48,12 @@ static struct kmem_cache *sigqueue_cachep;
70651
70652 int print_fatal_signals __read_mostly;
70653
70654 -static void __user *sig_handler(struct task_struct *t, int sig)
70655 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
70656 {
70657 return t->sighand->action[sig - 1].sa.sa_handler;
70658 }
70659
70660 -static int sig_handler_ignored(void __user *handler, int sig)
70661 +static int sig_handler_ignored(__sighandler_t handler, int sig)
70662 {
70663 /* Is it explicitly or implicitly ignored? */
70664 return handler == SIG_IGN ||
70665 @@ -62,7 +62,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
70666
70667 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
70668 {
70669 - void __user *handler;
70670 + __sighandler_t handler;
70671
70672 handler = sig_handler(t, sig);
70673
70674 @@ -366,6 +366,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
70675 atomic_inc(&user->sigpending);
70676 rcu_read_unlock();
70677
70678 + if (!override_rlimit)
70679 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
70680 +
70681 if (override_rlimit ||
70682 atomic_read(&user->sigpending) <=
70683 task_rlimit(t, RLIMIT_SIGPENDING)) {
70684 @@ -490,7 +493,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
70685
70686 int unhandled_signal(struct task_struct *tsk, int sig)
70687 {
70688 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
70689 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
70690 if (is_global_init(tsk))
70691 return 1;
70692 if (handler != SIG_IGN && handler != SIG_DFL)
70693 @@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
70694 }
70695 }
70696
70697 + /* allow glibc communication via tgkill to other threads in our
70698 + thread group */
70699 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
70700 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
70701 + && gr_handle_signal(t, sig))
70702 + return -EPERM;
70703 +
70704 return security_task_kill(t, info, sig, 0);
70705 }
70706
70707 @@ -1197,7 +1207,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
70708 return send_signal(sig, info, p, 1);
70709 }
70710
70711 -static int
70712 +int
70713 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
70714 {
70715 return send_signal(sig, info, t, 0);
70716 @@ -1234,6 +1244,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
70717 unsigned long int flags;
70718 int ret, blocked, ignored;
70719 struct k_sigaction *action;
70720 + int is_unhandled = 0;
70721
70722 spin_lock_irqsave(&t->sighand->siglock, flags);
70723 action = &t->sighand->action[sig-1];
70724 @@ -1248,9 +1259,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
70725 }
70726 if (action->sa.sa_handler == SIG_DFL)
70727 t->signal->flags &= ~SIGNAL_UNKILLABLE;
70728 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
70729 + is_unhandled = 1;
70730 ret = specific_send_sig_info(sig, info, t);
70731 spin_unlock_irqrestore(&t->sighand->siglock, flags);
70732
70733 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
70734 + normal operation */
70735 + if (is_unhandled) {
70736 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
70737 + gr_handle_crash(t, sig);
70738 + }
70739 +
70740 return ret;
70741 }
70742
70743 @@ -1317,8 +1337,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
70744 ret = check_kill_permission(sig, info, p);
70745 rcu_read_unlock();
70746
70747 - if (!ret && sig)
70748 + if (!ret && sig) {
70749 ret = do_send_sig_info(sig, info, p, true);
70750 + if (!ret)
70751 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
70752 + }
70753
70754 return ret;
70755 }
70756 @@ -2873,7 +2896,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
70757 int error = -ESRCH;
70758
70759 rcu_read_lock();
70760 - p = find_task_by_vpid(pid);
70761 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
70762 + /* allow glibc communication via tgkill to other threads in our
70763 + thread group */
70764 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
70765 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
70766 + p = find_task_by_vpid_unrestricted(pid);
70767 + else
70768 +#endif
70769 + p = find_task_by_vpid(pid);
70770 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
70771 error = check_kill_permission(sig, info, p);
70772 /*
70773 diff --git a/kernel/softirq.c b/kernel/softirq.c
70774 index b73e681..645ab62 100644
70775 --- a/kernel/softirq.c
70776 +++ b/kernel/softirq.c
70777 @@ -56,7 +56,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
70778
70779 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
70780
70781 -char *softirq_to_name[NR_SOFTIRQS] = {
70782 +const char * const softirq_to_name[NR_SOFTIRQS] = {
70783 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
70784 "TASKLET", "SCHED", "HRTIMER", "RCU"
70785 };
70786 @@ -243,7 +243,7 @@ restart:
70787 kstat_incr_softirqs_this_cpu(vec_nr);
70788
70789 trace_softirq_entry(vec_nr);
70790 - h->action(h);
70791 + h->action();
70792 trace_softirq_exit(vec_nr);
70793 if (unlikely(prev_count != preempt_count())) {
70794 printk(KERN_ERR "huh, entered softirq %u %s %p"
70795 @@ -390,9 +390,11 @@ void __raise_softirq_irqoff(unsigned int nr)
70796 or_softirq_pending(1UL << nr);
70797 }
70798
70799 -void open_softirq(int nr, void (*action)(struct softirq_action *))
70800 +void open_softirq(int nr, void (*action)(void))
70801 {
70802 - softirq_vec[nr].action = action;
70803 + pax_open_kernel();
70804 + *(void **)&softirq_vec[nr].action = action;
70805 + pax_close_kernel();
70806 }
70807
70808 /*
70809 @@ -446,7 +448,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
70810
70811 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
70812
70813 -static void tasklet_action(struct softirq_action *a)
70814 +static void tasklet_action(void)
70815 {
70816 struct tasklet_struct *list;
70817
70818 @@ -481,7 +483,7 @@ static void tasklet_action(struct softirq_action *a)
70819 }
70820 }
70821
70822 -static void tasklet_hi_action(struct softirq_action *a)
70823 +static void tasklet_hi_action(void)
70824 {
70825 struct tasklet_struct *list;
70826
70827 diff --git a/kernel/srcu.c b/kernel/srcu.c
70828 index 2095be3..9a5b89d 100644
70829 --- a/kernel/srcu.c
70830 +++ b/kernel/srcu.c
70831 @@ -302,9 +302,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
70832 preempt_disable();
70833 idx = rcu_dereference_index_check(sp->completed,
70834 rcu_read_lock_sched_held()) & 0x1;
70835 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
70836 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
70837 smp_mb(); /* B */ /* Avoid leaking the critical section. */
70838 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
70839 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
70840 preempt_enable();
70841 return idx;
70842 }
70843 @@ -320,7 +320,7 @@ void __srcu_read_unlock(struct srcu_struct *sp, int idx)
70844 {
70845 preempt_disable();
70846 smp_mb(); /* C */ /* Avoid leaking the critical section. */
70847 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
70848 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
70849 preempt_enable();
70850 }
70851 EXPORT_SYMBOL_GPL(__srcu_read_unlock);
70852 diff --git a/kernel/sys.c b/kernel/sys.c
70853 index 909148a..cd51acf 100644
70854 --- a/kernel/sys.c
70855 +++ b/kernel/sys.c
70856 @@ -157,6 +157,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
70857 error = -EACCES;
70858 goto out;
70859 }
70860 +
70861 + if (gr_handle_chroot_setpriority(p, niceval)) {
70862 + error = -EACCES;
70863 + goto out;
70864 + }
70865 +
70866 no_nice = security_task_setnice(p, niceval);
70867 if (no_nice) {
70868 error = no_nice;
70869 @@ -595,6 +601,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
70870 goto error;
70871 }
70872
70873 + if (gr_check_group_change(new->gid, new->egid, -1))
70874 + goto error;
70875 +
70876 if (rgid != (gid_t) -1 ||
70877 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
70878 new->sgid = new->egid;
70879 @@ -630,6 +639,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
70880 old = current_cred();
70881
70882 retval = -EPERM;
70883 +
70884 + if (gr_check_group_change(kgid, kgid, kgid))
70885 + goto error;
70886 +
70887 if (nsown_capable(CAP_SETGID))
70888 new->gid = new->egid = new->sgid = new->fsgid = kgid;
70889 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
70890 @@ -647,7 +660,7 @@ error:
70891 /*
70892 * change the user struct in a credentials set to match the new UID
70893 */
70894 -static int set_user(struct cred *new)
70895 +int set_user(struct cred *new)
70896 {
70897 struct user_struct *new_user;
70898
70899 @@ -727,6 +740,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
70900 goto error;
70901 }
70902
70903 + if (gr_check_user_change(new->uid, new->euid, -1))
70904 + goto error;
70905 +
70906 if (!uid_eq(new->uid, old->uid)) {
70907 retval = set_user(new);
70908 if (retval < 0)
70909 @@ -777,6 +793,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
70910 old = current_cred();
70911
70912 retval = -EPERM;
70913 +
70914 + if (gr_check_crash_uid(kuid))
70915 + goto error;
70916 + if (gr_check_user_change(kuid, kuid, kuid))
70917 + goto error;
70918 +
70919 if (nsown_capable(CAP_SETUID)) {
70920 new->suid = new->uid = kuid;
70921 if (!uid_eq(kuid, old->uid)) {
70922 @@ -846,6 +868,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
70923 goto error;
70924 }
70925
70926 + if (gr_check_user_change(kruid, keuid, -1))
70927 + goto error;
70928 +
70929 if (ruid != (uid_t) -1) {
70930 new->uid = kruid;
70931 if (!uid_eq(kruid, old->uid)) {
70932 @@ -928,6 +953,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
70933 goto error;
70934 }
70935
70936 + if (gr_check_group_change(krgid, kegid, -1))
70937 + goto error;
70938 +
70939 if (rgid != (gid_t) -1)
70940 new->gid = krgid;
70941 if (egid != (gid_t) -1)
70942 @@ -981,6 +1009,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
70943 if (!uid_valid(kuid))
70944 return old_fsuid;
70945
70946 + if (gr_check_user_change(-1, -1, kuid))
70947 + goto error;
70948 +
70949 new = prepare_creds();
70950 if (!new)
70951 return old_fsuid;
70952 @@ -995,6 +1026,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
70953 }
70954 }
70955
70956 +error:
70957 abort_creds(new);
70958 return old_fsuid;
70959
70960 @@ -1027,12 +1059,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
70961 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
70962 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
70963 nsown_capable(CAP_SETGID)) {
70964 + if (gr_check_group_change(-1, -1, kgid))
70965 + goto error;
70966 +
70967 if (!gid_eq(kgid, old->fsgid)) {
70968 new->fsgid = kgid;
70969 goto change_okay;
70970 }
70971 }
70972
70973 +error:
70974 abort_creds(new);
70975 return old_fsgid;
70976
70977 @@ -1340,19 +1376,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
70978 return -EFAULT;
70979
70980 down_read(&uts_sem);
70981 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
70982 + error = __copy_to_user(name->sysname, &utsname()->sysname,
70983 __OLD_UTS_LEN);
70984 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
70985 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
70986 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
70987 __OLD_UTS_LEN);
70988 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
70989 - error |= __copy_to_user(&name->release, &utsname()->release,
70990 + error |= __copy_to_user(name->release, &utsname()->release,
70991 __OLD_UTS_LEN);
70992 error |= __put_user(0, name->release + __OLD_UTS_LEN);
70993 - error |= __copy_to_user(&name->version, &utsname()->version,
70994 + error |= __copy_to_user(name->version, &utsname()->version,
70995 __OLD_UTS_LEN);
70996 error |= __put_user(0, name->version + __OLD_UTS_LEN);
70997 - error |= __copy_to_user(&name->machine, &utsname()->machine,
70998 + error |= __copy_to_user(name->machine, &utsname()->machine,
70999 __OLD_UTS_LEN);
71000 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
71001 up_read(&uts_sem);
71002 @@ -2026,7 +2062,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
71003 error = get_dumpable(me->mm);
71004 break;
71005 case PR_SET_DUMPABLE:
71006 - if (arg2 < 0 || arg2 > 1) {
71007 + if (arg2 > 1) {
71008 error = -EINVAL;
71009 break;
71010 }
71011 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
71012 index 87174ef..68cbb82 100644
71013 --- a/kernel/sysctl.c
71014 +++ b/kernel/sysctl.c
71015 @@ -92,7 +92,6 @@
71016
71017
71018 #if defined(CONFIG_SYSCTL)
71019 -
71020 /* External variables not in a header file. */
71021 extern int sysctl_overcommit_memory;
71022 extern int sysctl_overcommit_ratio;
71023 @@ -170,10 +169,8 @@ static int proc_taint(struct ctl_table *table, int write,
71024 void __user *buffer, size_t *lenp, loff_t *ppos);
71025 #endif
71026
71027 -#ifdef CONFIG_PRINTK
71028 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
71029 void __user *buffer, size_t *lenp, loff_t *ppos);
71030 -#endif
71031
71032 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
71033 void __user *buffer, size_t *lenp, loff_t *ppos);
71034 @@ -202,6 +199,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
71035
71036 #endif
71037
71038 +extern struct ctl_table grsecurity_table[];
71039 +
71040 static struct ctl_table kern_table[];
71041 static struct ctl_table vm_table[];
71042 static struct ctl_table fs_table[];
71043 @@ -216,6 +215,20 @@ extern struct ctl_table epoll_table[];
71044 int sysctl_legacy_va_layout;
71045 #endif
71046
71047 +#ifdef CONFIG_PAX_SOFTMODE
71048 +static ctl_table pax_table[] = {
71049 + {
71050 + .procname = "softmode",
71051 + .data = &pax_softmode,
71052 + .maxlen = sizeof(unsigned int),
71053 + .mode = 0600,
71054 + .proc_handler = &proc_dointvec,
71055 + },
71056 +
71057 + { }
71058 +};
71059 +#endif
71060 +
71061 /* The default sysctl tables: */
71062
71063 static struct ctl_table sysctl_base_table[] = {
71064 @@ -262,6 +275,22 @@ static int max_extfrag_threshold = 1000;
71065 #endif
71066
71067 static struct ctl_table kern_table[] = {
71068 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
71069 + {
71070 + .procname = "grsecurity",
71071 + .mode = 0500,
71072 + .child = grsecurity_table,
71073 + },
71074 +#endif
71075 +
71076 +#ifdef CONFIG_PAX_SOFTMODE
71077 + {
71078 + .procname = "pax",
71079 + .mode = 0500,
71080 + .child = pax_table,
71081 + },
71082 +#endif
71083 +
71084 {
71085 .procname = "sched_child_runs_first",
71086 .data = &sysctl_sched_child_runs_first,
71087 @@ -546,7 +575,7 @@ static struct ctl_table kern_table[] = {
71088 .data = &modprobe_path,
71089 .maxlen = KMOD_PATH_LEN,
71090 .mode = 0644,
71091 - .proc_handler = proc_dostring,
71092 + .proc_handler = proc_dostring_modpriv,
71093 },
71094 {
71095 .procname = "modules_disabled",
71096 @@ -713,16 +742,20 @@ static struct ctl_table kern_table[] = {
71097 .extra1 = &zero,
71098 .extra2 = &one,
71099 },
71100 +#endif
71101 {
71102 .procname = "kptr_restrict",
71103 .data = &kptr_restrict,
71104 .maxlen = sizeof(int),
71105 .mode = 0644,
71106 .proc_handler = proc_dointvec_minmax_sysadmin,
71107 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71108 + .extra1 = &two,
71109 +#else
71110 .extra1 = &zero,
71111 +#endif
71112 .extra2 = &two,
71113 },
71114 -#endif
71115 {
71116 .procname = "ngroups_max",
71117 .data = &ngroups_max,
71118 @@ -1219,6 +1252,13 @@ static struct ctl_table vm_table[] = {
71119 .proc_handler = proc_dointvec_minmax,
71120 .extra1 = &zero,
71121 },
71122 + {
71123 + .procname = "heap_stack_gap",
71124 + .data = &sysctl_heap_stack_gap,
71125 + .maxlen = sizeof(sysctl_heap_stack_gap),
71126 + .mode = 0644,
71127 + .proc_handler = proc_doulongvec_minmax,
71128 + },
71129 #else
71130 {
71131 .procname = "nr_trim_pages",
71132 @@ -1670,6 +1710,16 @@ int proc_dostring(struct ctl_table *table, int write,
71133 buffer, lenp, ppos);
71134 }
71135
71136 +int proc_dostring_modpriv(struct ctl_table *table, int write,
71137 + void __user *buffer, size_t *lenp, loff_t *ppos)
71138 +{
71139 + if (write && !capable(CAP_SYS_MODULE))
71140 + return -EPERM;
71141 +
71142 + return _proc_do_string(table->data, table->maxlen, write,
71143 + buffer, lenp, ppos);
71144 +}
71145 +
71146 static size_t proc_skip_spaces(char **buf)
71147 {
71148 size_t ret;
71149 @@ -1775,6 +1825,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
71150 len = strlen(tmp);
71151 if (len > *size)
71152 len = *size;
71153 + if (len > sizeof(tmp))
71154 + len = sizeof(tmp);
71155 if (copy_to_user(*buf, tmp, len))
71156 return -EFAULT;
71157 *size -= len;
71158 @@ -1967,7 +2019,6 @@ static int proc_taint(struct ctl_table *table, int write,
71159 return err;
71160 }
71161
71162 -#ifdef CONFIG_PRINTK
71163 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
71164 void __user *buffer, size_t *lenp, loff_t *ppos)
71165 {
71166 @@ -1976,7 +2027,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
71167
71168 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
71169 }
71170 -#endif
71171
71172 struct do_proc_dointvec_minmax_conv_param {
71173 int *min;
71174 @@ -2119,8 +2169,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
71175 *i = val;
71176 } else {
71177 val = convdiv * (*i) / convmul;
71178 - if (!first)
71179 + if (!first) {
71180 err = proc_put_char(&buffer, &left, '\t');
71181 + if (err)
71182 + break;
71183 + }
71184 err = proc_put_long(&buffer, &left, val, false);
71185 if (err)
71186 break;
71187 @@ -2512,6 +2565,12 @@ int proc_dostring(struct ctl_table *table, int write,
71188 return -ENOSYS;
71189 }
71190
71191 +int proc_dostring_modpriv(struct ctl_table *table, int write,
71192 + void __user *buffer, size_t *lenp, loff_t *ppos)
71193 +{
71194 + return -ENOSYS;
71195 +}
71196 +
71197 int proc_dointvec(struct ctl_table *table, int write,
71198 void __user *buffer, size_t *lenp, loff_t *ppos)
71199 {
71200 @@ -2568,5 +2627,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
71201 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
71202 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
71203 EXPORT_SYMBOL(proc_dostring);
71204 +EXPORT_SYMBOL(proc_dostring_modpriv);
71205 EXPORT_SYMBOL(proc_doulongvec_minmax);
71206 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
71207 diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
71208 index 65bdcf1..21eb831 100644
71209 --- a/kernel/sysctl_binary.c
71210 +++ b/kernel/sysctl_binary.c
71211 @@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
71212 int i;
71213
71214 set_fs(KERNEL_DS);
71215 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
71216 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
71217 set_fs(old_fs);
71218 if (result < 0)
71219 goto out_kfree;
71220 @@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
71221 }
71222
71223 set_fs(KERNEL_DS);
71224 - result = vfs_write(file, buffer, str - buffer, &pos);
71225 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
71226 set_fs(old_fs);
71227 if (result < 0)
71228 goto out_kfree;
71229 @@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
71230 int i;
71231
71232 set_fs(KERNEL_DS);
71233 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
71234 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
71235 set_fs(old_fs);
71236 if (result < 0)
71237 goto out_kfree;
71238 @@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
71239 }
71240
71241 set_fs(KERNEL_DS);
71242 - result = vfs_write(file, buffer, str - buffer, &pos);
71243 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
71244 set_fs(old_fs);
71245 if (result < 0)
71246 goto out_kfree;
71247 @@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
71248 int i;
71249
71250 set_fs(KERNEL_DS);
71251 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
71252 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
71253 set_fs(old_fs);
71254 if (result < 0)
71255 goto out;
71256 @@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
71257 __le16 dnaddr;
71258
71259 set_fs(KERNEL_DS);
71260 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
71261 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
71262 set_fs(old_fs);
71263 if (result < 0)
71264 goto out;
71265 @@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
71266 le16_to_cpu(dnaddr) & 0x3ff);
71267
71268 set_fs(KERNEL_DS);
71269 - result = vfs_write(file, buf, len, &pos);
71270 + result = vfs_write(file, (const char __force_user *)buf, len, &pos);
71271 set_fs(old_fs);
71272 if (result < 0)
71273 goto out;
71274 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
71275 index d0a3279..db0ad99 100644
71276 --- a/kernel/taskstats.c
71277 +++ b/kernel/taskstats.c
71278 @@ -27,9 +27,12 @@
71279 #include <linux/cgroup.h>
71280 #include <linux/fs.h>
71281 #include <linux/file.h>
71282 +#include <linux/grsecurity.h>
71283 #include <net/genetlink.h>
71284 #include <linux/atomic.h>
71285
71286 +extern int gr_is_taskstats_denied(int pid);
71287 +
71288 /*
71289 * Maximum length of a cpumask that can be specified in
71290 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
71291 @@ -561,6 +564,9 @@ err:
71292
71293 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
71294 {
71295 + if (gr_is_taskstats_denied(current->pid))
71296 + return -EACCES;
71297 +
71298 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
71299 return cmd_attr_register_cpumask(info);
71300 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
71301 diff --git a/kernel/time.c b/kernel/time.c
71302 index ba744cf..267b7c5 100644
71303 --- a/kernel/time.c
71304 +++ b/kernel/time.c
71305 @@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
71306 return error;
71307
71308 if (tz) {
71309 + /* we log in do_settimeofday called below, so don't log twice
71310 + */
71311 + if (!tv)
71312 + gr_log_timechange();
71313 +
71314 sys_tz = *tz;
71315 update_vsyscall_tz();
71316 if (firsttime) {
71317 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
71318 index aa27d39..34d221c 100644
71319 --- a/kernel/time/alarmtimer.c
71320 +++ b/kernel/time/alarmtimer.c
71321 @@ -779,7 +779,7 @@ static int __init alarmtimer_init(void)
71322 struct platform_device *pdev;
71323 int error = 0;
71324 int i;
71325 - struct k_clock alarm_clock = {
71326 + static struct k_clock alarm_clock = {
71327 .clock_getres = alarm_clock_getres,
71328 .clock_get = alarm_clock_get,
71329 .timer_create = alarm_timer_create,
71330 diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
71331 index f113755..ec24223 100644
71332 --- a/kernel/time/tick-broadcast.c
71333 +++ b/kernel/time/tick-broadcast.c
71334 @@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
71335 * then clear the broadcast bit.
71336 */
71337 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
71338 - int cpu = smp_processor_id();
71339 + cpu = smp_processor_id();
71340
71341 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
71342 tick_broadcast_clear_oneshot(cpu);
71343 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
71344 index f791637..00051de 100644
71345 --- a/kernel/time/timekeeping.c
71346 +++ b/kernel/time/timekeeping.c
71347 @@ -14,6 +14,7 @@
71348 #include <linux/init.h>
71349 #include <linux/mm.h>
71350 #include <linux/sched.h>
71351 +#include <linux/grsecurity.h>
71352 #include <linux/syscore_ops.h>
71353 #include <linux/clocksource.h>
71354 #include <linux/jiffies.h>
71355 @@ -434,6 +435,8 @@ int do_settimeofday(const struct timespec *tv)
71356 if (!timespec_valid_strict(tv))
71357 return -EINVAL;
71358
71359 + gr_log_timechange();
71360 +
71361 write_seqlock_irqsave(&tk->lock, flags);
71362
71363 timekeeping_forward_now(tk);
71364 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
71365 index af5a7e9..715611a 100644
71366 --- a/kernel/time/timer_list.c
71367 +++ b/kernel/time/timer_list.c
71368 @@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
71369
71370 static void print_name_offset(struct seq_file *m, void *sym)
71371 {
71372 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71373 + SEQ_printf(m, "<%p>", NULL);
71374 +#else
71375 char symname[KSYM_NAME_LEN];
71376
71377 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
71378 SEQ_printf(m, "<%pK>", sym);
71379 else
71380 SEQ_printf(m, "%s", symname);
71381 +#endif
71382 }
71383
71384 static void
71385 @@ -112,7 +116,11 @@ next_one:
71386 static void
71387 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
71388 {
71389 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71390 + SEQ_printf(m, " .base: %p\n", NULL);
71391 +#else
71392 SEQ_printf(m, " .base: %pK\n", base);
71393 +#endif
71394 SEQ_printf(m, " .index: %d\n",
71395 base->index);
71396 SEQ_printf(m, " .resolution: %Lu nsecs\n",
71397 @@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
71398 {
71399 struct proc_dir_entry *pe;
71400
71401 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
71402 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
71403 +#else
71404 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
71405 +#endif
71406 if (!pe)
71407 return -ENOMEM;
71408 return 0;
71409 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
71410 index 0b537f2..40d6c20 100644
71411 --- a/kernel/time/timer_stats.c
71412 +++ b/kernel/time/timer_stats.c
71413 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
71414 static unsigned long nr_entries;
71415 static struct entry entries[MAX_ENTRIES];
71416
71417 -static atomic_t overflow_count;
71418 +static atomic_unchecked_t overflow_count;
71419
71420 /*
71421 * The entries are in a hash-table, for fast lookup:
71422 @@ -140,7 +140,7 @@ static void reset_entries(void)
71423 nr_entries = 0;
71424 memset(entries, 0, sizeof(entries));
71425 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
71426 - atomic_set(&overflow_count, 0);
71427 + atomic_set_unchecked(&overflow_count, 0);
71428 }
71429
71430 static struct entry *alloc_entry(void)
71431 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
71432 if (likely(entry))
71433 entry->count++;
71434 else
71435 - atomic_inc(&overflow_count);
71436 + atomic_inc_unchecked(&overflow_count);
71437
71438 out_unlock:
71439 raw_spin_unlock_irqrestore(lock, flags);
71440 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
71441
71442 static void print_name_offset(struct seq_file *m, unsigned long addr)
71443 {
71444 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71445 + seq_printf(m, "<%p>", NULL);
71446 +#else
71447 char symname[KSYM_NAME_LEN];
71448
71449 if (lookup_symbol_name(addr, symname) < 0)
71450 - seq_printf(m, "<%p>", (void *)addr);
71451 + seq_printf(m, "<%pK>", (void *)addr);
71452 else
71453 seq_printf(m, "%s", symname);
71454 +#endif
71455 }
71456
71457 static int tstats_show(struct seq_file *m, void *v)
71458 @@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
71459
71460 seq_puts(m, "Timer Stats Version: v0.2\n");
71461 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
71462 - if (atomic_read(&overflow_count))
71463 + if (atomic_read_unchecked(&overflow_count))
71464 seq_printf(m, "Overflow: %d entries\n",
71465 - atomic_read(&overflow_count));
71466 + atomic_read_unchecked(&overflow_count));
71467
71468 for (i = 0; i < nr_entries; i++) {
71469 entry = entries + i;
71470 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
71471 {
71472 struct proc_dir_entry *pe;
71473
71474 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
71475 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
71476 +#else
71477 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
71478 +#endif
71479 if (!pe)
71480 return -ENOMEM;
71481 return 0;
71482 diff --git a/kernel/timer.c b/kernel/timer.c
71483 index 46ef2b1..ad081f144 100644
71484 --- a/kernel/timer.c
71485 +++ b/kernel/timer.c
71486 @@ -1377,7 +1377,7 @@ void update_process_times(int user_tick)
71487 /*
71488 * This function runs timers and the timer-tq in bottom half context.
71489 */
71490 -static void run_timer_softirq(struct softirq_action *h)
71491 +static void run_timer_softirq(void)
71492 {
71493 struct tvec_base *base = __this_cpu_read(tvec_bases);
71494
71495 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
71496 index c0bd030..62a1927 100644
71497 --- a/kernel/trace/blktrace.c
71498 +++ b/kernel/trace/blktrace.c
71499 @@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
71500 struct blk_trace *bt = filp->private_data;
71501 char buf[16];
71502
71503 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
71504 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
71505
71506 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
71507 }
71508 @@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
71509 return 1;
71510
71511 bt = buf->chan->private_data;
71512 - atomic_inc(&bt->dropped);
71513 + atomic_inc_unchecked(&bt->dropped);
71514 return 0;
71515 }
71516
71517 @@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
71518
71519 bt->dir = dir;
71520 bt->dev = dev;
71521 - atomic_set(&bt->dropped, 0);
71522 + atomic_set_unchecked(&bt->dropped, 0);
71523
71524 ret = -EIO;
71525 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
71526 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
71527 index b4f20fb..483c5fa 100644
71528 --- a/kernel/trace/ftrace.c
71529 +++ b/kernel/trace/ftrace.c
71530 @@ -1785,12 +1785,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
71531 if (unlikely(ftrace_disabled))
71532 return 0;
71533
71534 + ret = ftrace_arch_code_modify_prepare();
71535 + FTRACE_WARN_ON(ret);
71536 + if (ret)
71537 + return 0;
71538 +
71539 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
71540 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
71541 if (ret) {
71542 ftrace_bug(ret, ip);
71543 - return 0;
71544 }
71545 - return 1;
71546 + return ret ? 0 : 1;
71547 }
71548
71549 /*
71550 @@ -2885,7 +2890,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
71551
71552 int
71553 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
71554 - void *data)
71555 + void *data)
71556 {
71557 struct ftrace_func_probe *entry;
71558 struct ftrace_page *pg;
71559 @@ -3697,8 +3702,10 @@ static int ftrace_process_locs(struct module *mod,
71560 if (!count)
71561 return 0;
71562
71563 + pax_open_kernel();
71564 sort(start, count, sizeof(*start),
71565 ftrace_cmp_ips, ftrace_swap_ips);
71566 + pax_close_kernel();
71567
71568 start_pg = ftrace_allocate_pages(count);
71569 if (!start_pg)
71570 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
71571 index 5c38c81..88012af 100644
71572 --- a/kernel/trace/trace.c
71573 +++ b/kernel/trace/trace.c
71574 @@ -4437,10 +4437,9 @@ static const struct file_operations tracing_dyn_info_fops = {
71575 };
71576 #endif
71577
71578 -static struct dentry *d_tracer;
71579 -
71580 struct dentry *tracing_init_dentry(void)
71581 {
71582 + static struct dentry *d_tracer;
71583 static int once;
71584
71585 if (d_tracer)
71586 @@ -4460,10 +4459,9 @@ struct dentry *tracing_init_dentry(void)
71587 return d_tracer;
71588 }
71589
71590 -static struct dentry *d_percpu;
71591 -
71592 struct dentry *tracing_dentry_percpu(void)
71593 {
71594 + static struct dentry *d_percpu;
71595 static int once;
71596 struct dentry *d_tracer;
71597
71598 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
71599 index 29111da..d190fe2 100644
71600 --- a/kernel/trace/trace_events.c
71601 +++ b/kernel/trace/trace_events.c
71602 @@ -1308,10 +1308,6 @@ static LIST_HEAD(ftrace_module_file_list);
71603 struct ftrace_module_file_ops {
71604 struct list_head list;
71605 struct module *mod;
71606 - struct file_operations id;
71607 - struct file_operations enable;
71608 - struct file_operations format;
71609 - struct file_operations filter;
71610 };
71611
71612 static struct ftrace_module_file_ops *
71613 @@ -1332,17 +1328,12 @@ trace_create_file_ops(struct module *mod)
71614
71615 file_ops->mod = mod;
71616
71617 - file_ops->id = ftrace_event_id_fops;
71618 - file_ops->id.owner = mod;
71619 -
71620 - file_ops->enable = ftrace_enable_fops;
71621 - file_ops->enable.owner = mod;
71622 -
71623 - file_ops->filter = ftrace_event_filter_fops;
71624 - file_ops->filter.owner = mod;
71625 -
71626 - file_ops->format = ftrace_event_format_fops;
71627 - file_ops->format.owner = mod;
71628 + pax_open_kernel();
71629 + *(void **)&mod->trace_id.owner = mod;
71630 + *(void **)&mod->trace_enable.owner = mod;
71631 + *(void **)&mod->trace_filter.owner = mod;
71632 + *(void **)&mod->trace_format.owner = mod;
71633 + pax_close_kernel();
71634
71635 list_add(&file_ops->list, &ftrace_module_file_list);
71636
71637 @@ -1366,8 +1357,8 @@ static void trace_module_add_events(struct module *mod)
71638
71639 for_each_event(call, start, end) {
71640 __trace_add_event_call(*call, mod,
71641 - &file_ops->id, &file_ops->enable,
71642 - &file_ops->filter, &file_ops->format);
71643 + &mod->trace_id, &mod->trace_enable,
71644 + &mod->trace_filter, &mod->trace_format);
71645 }
71646 }
71647
71648 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
71649 index fd3c8aa..5f324a6 100644
71650 --- a/kernel/trace/trace_mmiotrace.c
71651 +++ b/kernel/trace/trace_mmiotrace.c
71652 @@ -24,7 +24,7 @@ struct header_iter {
71653 static struct trace_array *mmio_trace_array;
71654 static bool overrun_detected;
71655 static unsigned long prev_overruns;
71656 -static atomic_t dropped_count;
71657 +static atomic_unchecked_t dropped_count;
71658
71659 static void mmio_reset_data(struct trace_array *tr)
71660 {
71661 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
71662
71663 static unsigned long count_overruns(struct trace_iterator *iter)
71664 {
71665 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
71666 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
71667 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
71668
71669 if (over > prev_overruns)
71670 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
71671 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
71672 sizeof(*entry), 0, pc);
71673 if (!event) {
71674 - atomic_inc(&dropped_count);
71675 + atomic_inc_unchecked(&dropped_count);
71676 return;
71677 }
71678 entry = ring_buffer_event_data(event);
71679 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
71680 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
71681 sizeof(*entry), 0, pc);
71682 if (!event) {
71683 - atomic_inc(&dropped_count);
71684 + atomic_inc_unchecked(&dropped_count);
71685 return;
71686 }
71687 entry = ring_buffer_event_data(event);
71688 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
71689 index 123b189..97b81f5 100644
71690 --- a/kernel/trace/trace_output.c
71691 +++ b/kernel/trace/trace_output.c
71692 @@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
71693
71694 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
71695 if (!IS_ERR(p)) {
71696 - p = mangle_path(s->buffer + s->len, p, "\n");
71697 + p = mangle_path(s->buffer + s->len, p, "\n\\");
71698 if (p) {
71699 s->len = p - s->buffer;
71700 return 1;
71701 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
71702 index d4545f4..a9010a1 100644
71703 --- a/kernel/trace/trace_stack.c
71704 +++ b/kernel/trace/trace_stack.c
71705 @@ -53,7 +53,7 @@ static inline void check_stack(void)
71706 return;
71707
71708 /* we do not handle interrupt stacks yet */
71709 - if (!object_is_on_stack(&this_size))
71710 + if (!object_starts_on_stack(&this_size))
71711 return;
71712
71713 local_irq_save(flags);
71714 diff --git a/kernel/workqueue.c b/kernel/workqueue.c
71715 index 872bd6d..b727b3a 100644
71716 --- a/kernel/workqueue.c
71717 +++ b/kernel/workqueue.c
71718 @@ -1422,7 +1422,7 @@ retry:
71719 /* morph UNBOUND to REBIND atomically */
71720 worker_flags &= ~WORKER_UNBOUND;
71721 worker_flags |= WORKER_REBIND;
71722 - ACCESS_ONCE(worker->flags) = worker_flags;
71723 + ACCESS_ONCE_RW(worker->flags) = worker_flags;
71724
71725 idle_rebind.cnt++;
71726 worker->idle_rebind = &idle_rebind;
71727 @@ -1448,7 +1448,7 @@ retry:
71728 /* morph UNBOUND to REBIND atomically */
71729 worker_flags &= ~WORKER_UNBOUND;
71730 worker_flags |= WORKER_REBIND;
71731 - ACCESS_ONCE(worker->flags) = worker_flags;
71732 + ACCESS_ONCE_RW(worker->flags) = worker_flags;
71733
71734 if (test_and_set_bit(WORK_STRUCT_PENDING_BIT,
71735 work_data_bits(rebind_work)))
71736 @@ -2266,8 +2266,10 @@ static int rescuer_thread(void *__wq)
71737 repeat:
71738 set_current_state(TASK_INTERRUPTIBLE);
71739
71740 - if (kthread_should_stop())
71741 + if (kthread_should_stop()) {
71742 + __set_current_state(TASK_RUNNING);
71743 return 0;
71744 + }
71745
71746 /*
71747 * See whether any cpu is asking for help. Unbounded
71748 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
71749 index 2403a63..5c4be4c 100644
71750 --- a/lib/Kconfig.debug
71751 +++ b/lib/Kconfig.debug
71752 @@ -1252,6 +1252,7 @@ config LATENCYTOP
71753 depends on DEBUG_KERNEL
71754 depends on STACKTRACE_SUPPORT
71755 depends on PROC_FS
71756 + depends on !GRKERNSEC_HIDESYM
71757 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
71758 select KALLSYMS
71759 select KALLSYMS_ALL
71760 @@ -1267,7 +1268,7 @@ source kernel/trace/Kconfig
71761
71762 config PROVIDE_OHCI1394_DMA_INIT
71763 bool "Remote debugging over FireWire early on boot"
71764 - depends on PCI && X86
71765 + depends on PCI && X86 && !GRKERNSEC
71766 help
71767 If you want to debug problems which hang or crash the kernel early
71768 on boot and the crashing machine has a FireWire port, you can use
71769 @@ -1296,7 +1297,7 @@ config PROVIDE_OHCI1394_DMA_INIT
71770
71771 config FIREWIRE_OHCI_REMOTE_DMA
71772 bool "Remote debugging over FireWire with firewire-ohci"
71773 - depends on FIREWIRE_OHCI
71774 + depends on FIREWIRE_OHCI && !GRKERNSEC
71775 help
71776 This option lets you use the FireWire bus for remote debugging
71777 with help of the firewire-ohci driver. It enables unfiltered
71778 diff --git a/lib/bitmap.c b/lib/bitmap.c
71779 index 06fdfa1..97c5c7d 100644
71780 --- a/lib/bitmap.c
71781 +++ b/lib/bitmap.c
71782 @@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
71783 {
71784 int c, old_c, totaldigits, ndigits, nchunks, nbits;
71785 u32 chunk;
71786 - const char __user __force *ubuf = (const char __user __force *)buf;
71787 + const char __user *ubuf = (const char __force_user *)buf;
71788
71789 bitmap_zero(maskp, nmaskbits);
71790
71791 @@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
71792 {
71793 if (!access_ok(VERIFY_READ, ubuf, ulen))
71794 return -EFAULT;
71795 - return __bitmap_parse((const char __force *)ubuf,
71796 + return __bitmap_parse((const char __force_kernel *)ubuf,
71797 ulen, 1, maskp, nmaskbits);
71798
71799 }
71800 @@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
71801 {
71802 unsigned a, b;
71803 int c, old_c, totaldigits;
71804 - const char __user __force *ubuf = (const char __user __force *)buf;
71805 + const char __user *ubuf = (const char __force_user *)buf;
71806 int exp_digit, in_range;
71807
71808 totaldigits = c = 0;
71809 @@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
71810 {
71811 if (!access_ok(VERIFY_READ, ubuf, ulen))
71812 return -EFAULT;
71813 - return __bitmap_parselist((const char __force *)ubuf,
71814 + return __bitmap_parselist((const char __force_kernel *)ubuf,
71815 ulen, 1, maskp, nmaskbits);
71816 }
71817 EXPORT_SYMBOL(bitmap_parselist_user);
71818 diff --git a/lib/bug.c b/lib/bug.c
71819 index a28c141..2bd3d95 100644
71820 --- a/lib/bug.c
71821 +++ b/lib/bug.c
71822 @@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
71823 return BUG_TRAP_TYPE_NONE;
71824
71825 bug = find_bug(bugaddr);
71826 + if (!bug)
71827 + return BUG_TRAP_TYPE_NONE;
71828
71829 file = NULL;
71830 line = 0;
71831 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
71832 index d11808c..dc2d6f8 100644
71833 --- a/lib/debugobjects.c
71834 +++ b/lib/debugobjects.c
71835 @@ -287,7 +287,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
71836 if (limit > 4)
71837 return;
71838
71839 - is_on_stack = object_is_on_stack(addr);
71840 + is_on_stack = object_starts_on_stack(addr);
71841 if (is_on_stack == onstack)
71842 return;
71843
71844 diff --git a/lib/devres.c b/lib/devres.c
71845 index 80b9c76..9e32279 100644
71846 --- a/lib/devres.c
71847 +++ b/lib/devres.c
71848 @@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
71849 void devm_iounmap(struct device *dev, void __iomem *addr)
71850 {
71851 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
71852 - (void *)addr));
71853 + (void __force *)addr));
71854 iounmap(addr);
71855 }
71856 EXPORT_SYMBOL(devm_iounmap);
71857 @@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
71858 {
71859 ioport_unmap(addr);
71860 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
71861 - devm_ioport_map_match, (void *)addr));
71862 + devm_ioport_map_match, (void __force *)addr));
71863 }
71864 EXPORT_SYMBOL(devm_ioport_unmap);
71865
71866 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
71867 index 66ce414..6f0a0dd 100644
71868 --- a/lib/dma-debug.c
71869 +++ b/lib/dma-debug.c
71870 @@ -924,7 +924,7 @@ out:
71871
71872 static void check_for_stack(struct device *dev, void *addr)
71873 {
71874 - if (object_is_on_stack(addr))
71875 + if (object_starts_on_stack(addr))
71876 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
71877 "stack [addr=%p]\n", addr);
71878 }
71879 diff --git a/lib/inflate.c b/lib/inflate.c
71880 index 013a761..c28f3fc 100644
71881 --- a/lib/inflate.c
71882 +++ b/lib/inflate.c
71883 @@ -269,7 +269,7 @@ static void free(void *where)
71884 malloc_ptr = free_mem_ptr;
71885 }
71886 #else
71887 -#define malloc(a) kmalloc(a, GFP_KERNEL)
71888 +#define malloc(a) kmalloc((a), GFP_KERNEL)
71889 #define free(a) kfree(a)
71890 #endif
71891
71892 diff --git a/lib/ioremap.c b/lib/ioremap.c
71893 index 0c9216c..863bd89 100644
71894 --- a/lib/ioremap.c
71895 +++ b/lib/ioremap.c
71896 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
71897 unsigned long next;
71898
71899 phys_addr -= addr;
71900 - pmd = pmd_alloc(&init_mm, pud, addr);
71901 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
71902 if (!pmd)
71903 return -ENOMEM;
71904 do {
71905 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
71906 unsigned long next;
71907
71908 phys_addr -= addr;
71909 - pud = pud_alloc(&init_mm, pgd, addr);
71910 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
71911 if (!pud)
71912 return -ENOMEM;
71913 do {
71914 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
71915 index bd2bea9..6b3c95e 100644
71916 --- a/lib/is_single_threaded.c
71917 +++ b/lib/is_single_threaded.c
71918 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
71919 struct task_struct *p, *t;
71920 bool ret;
71921
71922 + if (!mm)
71923 + return true;
71924 +
71925 if (atomic_read(&task->signal->live) != 1)
71926 return false;
71927
71928 diff --git a/lib/list_debug.c b/lib/list_debug.c
71929 index c24c2f7..bef49ee 100644
71930 --- a/lib/list_debug.c
71931 +++ b/lib/list_debug.c
71932 @@ -23,17 +23,19 @@ void __list_add(struct list_head *new,
71933 struct list_head *prev,
71934 struct list_head *next)
71935 {
71936 - WARN(next->prev != prev,
71937 + if (WARN(next->prev != prev,
71938 "list_add corruption. next->prev should be "
71939 "prev (%p), but was %p. (next=%p).\n",
71940 - prev, next->prev, next);
71941 - WARN(prev->next != next,
71942 + prev, next->prev, next) ||
71943 + WARN(prev->next != next,
71944 "list_add corruption. prev->next should be "
71945 "next (%p), but was %p. (prev=%p).\n",
71946 - next, prev->next, prev);
71947 - WARN(new == prev || new == next,
71948 + next, prev->next, prev) ||
71949 + WARN(new == prev || new == next,
71950 "list_add double add: new=%p, prev=%p, next=%p.\n",
71951 - new, prev, next);
71952 + new, prev, next))
71953 + return;
71954 +
71955 next->prev = new;
71956 new->next = next;
71957 new->prev = prev;
71958 @@ -86,12 +88,14 @@ EXPORT_SYMBOL(list_del);
71959 void __list_add_rcu(struct list_head *new,
71960 struct list_head *prev, struct list_head *next)
71961 {
71962 - WARN(next->prev != prev,
71963 + if (WARN(next->prev != prev,
71964 "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
71965 - prev, next->prev, next);
71966 - WARN(prev->next != next,
71967 + prev, next->prev, next) ||
71968 + WARN(prev->next != next,
71969 "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
71970 - next, prev->next, prev);
71971 + next, prev->next, prev))
71972 + return;
71973 +
71974 new->next = next;
71975 new->prev = prev;
71976 rcu_assign_pointer(list_next_rcu(prev), new);
71977 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
71978 index e796429..6e38f9f 100644
71979 --- a/lib/radix-tree.c
71980 +++ b/lib/radix-tree.c
71981 @@ -92,7 +92,7 @@ struct radix_tree_preload {
71982 int nr;
71983 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
71984 };
71985 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
71986 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
71987
71988 static inline void *ptr_to_indirect(void *ptr)
71989 {
71990 diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
71991 index bb2b201..46abaf9 100644
71992 --- a/lib/strncpy_from_user.c
71993 +++ b/lib/strncpy_from_user.c
71994 @@ -21,7 +21,7 @@
71995 */
71996 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
71997 {
71998 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
71999 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
72000 long res = 0;
72001
72002 /*
72003 diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
72004 index a28df52..3d55877 100644
72005 --- a/lib/strnlen_user.c
72006 +++ b/lib/strnlen_user.c
72007 @@ -26,7 +26,7 @@
72008 */
72009 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
72010 {
72011 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
72012 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
72013 long align, res = 0;
72014 unsigned long c;
72015
72016 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
72017 index 0e33754..50a0e63 100644
72018 --- a/lib/vsprintf.c
72019 +++ b/lib/vsprintf.c
72020 @@ -16,6 +16,9 @@
72021 * - scnprintf and vscnprintf
72022 */
72023
72024 +#ifdef CONFIG_GRKERNSEC_HIDESYM
72025 +#define __INCLUDED_BY_HIDESYM 1
72026 +#endif
72027 #include <stdarg.h>
72028 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
72029 #include <linux/types.h>
72030 @@ -536,7 +539,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
72031 char sym[KSYM_SYMBOL_LEN];
72032 if (ext == 'B')
72033 sprint_backtrace(sym, value);
72034 - else if (ext != 'f' && ext != 's')
72035 + else if (ext != 'f' && ext != 's' && ext != 'a')
72036 sprint_symbol(sym, value);
72037 else
72038 sprint_symbol_no_offset(sym, value);
72039 @@ -969,7 +972,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
72040 return number(buf, end, *(const netdev_features_t *)addr, spec);
72041 }
72042
72043 +#ifdef CONFIG_GRKERNSEC_HIDESYM
72044 +int kptr_restrict __read_mostly = 2;
72045 +#else
72046 int kptr_restrict __read_mostly;
72047 +#endif
72048
72049 /*
72050 * Show a '%p' thing. A kernel extension is that the '%p' is followed
72051 @@ -983,6 +990,8 @@ int kptr_restrict __read_mostly;
72052 * - 'S' For symbolic direct pointers with offset
72053 * - 's' For symbolic direct pointers without offset
72054 * - 'B' For backtraced symbolic direct pointers with offset
72055 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
72056 + * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
72057 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
72058 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
72059 * - 'M' For a 6-byte MAC address, it prints the address in the
72060 @@ -1038,12 +1047,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
72061
72062 if (!ptr && *fmt != 'K') {
72063 /*
72064 - * Print (null) with the same width as a pointer so it makes
72065 + * Print (nil) with the same width as a pointer so it makes
72066 * tabular output look nice.
72067 */
72068 if (spec.field_width == -1)
72069 spec.field_width = default_width;
72070 - return string(buf, end, "(null)", spec);
72071 + return string(buf, end, "(nil)", spec);
72072 }
72073
72074 switch (*fmt) {
72075 @@ -1053,6 +1062,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
72076 /* Fallthrough */
72077 case 'S':
72078 case 's':
72079 +#ifdef CONFIG_GRKERNSEC_HIDESYM
72080 + break;
72081 +#else
72082 + return symbol_string(buf, end, ptr, spec, *fmt);
72083 +#endif
72084 + case 'A':
72085 + case 'a':
72086 case 'B':
72087 return symbol_string(buf, end, ptr, spec, *fmt);
72088 case 'R':
72089 @@ -1093,6 +1109,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
72090 va_end(va);
72091 return buf;
72092 }
72093 + case 'P':
72094 + break;
72095 case 'K':
72096 /*
72097 * %pK cannot be used in IRQ context because its test
72098 @@ -1116,6 +1134,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
72099 }
72100 break;
72101 }
72102 +
72103 +#ifdef CONFIG_GRKERNSEC_HIDESYM
72104 + /* 'P' = approved pointers to copy to userland,
72105 + as in the /proc/kallsyms case, as we make it display nothing
72106 + for non-root users, and the real contents for root users
72107 + Also ignore 'K' pointers, since we force their NULLing for non-root users
72108 + above
72109 + */
72110 + if (ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
72111 + printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
72112 + dump_stack();
72113 + ptr = NULL;
72114 + }
72115 +#endif
72116 +
72117 spec.flags |= SMALL;
72118 if (spec.field_width == -1) {
72119 spec.field_width = default_width;
72120 @@ -1831,11 +1864,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
72121 typeof(type) value; \
72122 if (sizeof(type) == 8) { \
72123 args = PTR_ALIGN(args, sizeof(u32)); \
72124 - *(u32 *)&value = *(u32 *)args; \
72125 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
72126 + *(u32 *)&value = *(const u32 *)args; \
72127 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
72128 } else { \
72129 args = PTR_ALIGN(args, sizeof(type)); \
72130 - value = *(typeof(type) *)args; \
72131 + value = *(const typeof(type) *)args; \
72132 } \
72133 args += sizeof(type); \
72134 value; \
72135 @@ -1898,7 +1931,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
72136 case FORMAT_TYPE_STR: {
72137 const char *str_arg = args;
72138 args += strlen(str_arg) + 1;
72139 - str = string(str, end, (char *)str_arg, spec);
72140 + str = string(str, end, str_arg, spec);
72141 break;
72142 }
72143
72144 diff --git a/localversion-grsec b/localversion-grsec
72145 new file mode 100644
72146 index 0000000..7cd6065
72147 --- /dev/null
72148 +++ b/localversion-grsec
72149 @@ -0,0 +1 @@
72150 +-grsec
72151 diff --git a/mm/Kconfig b/mm/Kconfig
72152 index d5c8019..f513038 100644
72153 --- a/mm/Kconfig
72154 +++ b/mm/Kconfig
72155 @@ -251,10 +251,10 @@ config KSM
72156 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
72157
72158 config DEFAULT_MMAP_MIN_ADDR
72159 - int "Low address space to protect from user allocation"
72160 + int "Low address space to protect from user allocation"
72161 depends on MMU
72162 - default 4096
72163 - help
72164 + default 65536
72165 + help
72166 This is the portion of low virtual memory which should be protected
72167 from userspace allocation. Keeping a user from writing to low pages
72168 can help reduce the impact of kernel NULL pointer bugs.
72169 @@ -285,7 +285,7 @@ config MEMORY_FAILURE
72170
72171 config HWPOISON_INJECT
72172 tristate "HWPoison pages injector"
72173 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
72174 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
72175 select PROC_PAGE_MONITOR
72176
72177 config NOMMU_INITIAL_TRIM_EXCESS
72178 diff --git a/mm/filemap.c b/mm/filemap.c
72179 index 3843445..4fe6833 100644
72180 --- a/mm/filemap.c
72181 +++ b/mm/filemap.c
72182 @@ -1746,7 +1746,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
72183 struct address_space *mapping = file->f_mapping;
72184
72185 if (!mapping->a_ops->readpage)
72186 - return -ENOEXEC;
72187 + return -ENODEV;
72188 file_accessed(file);
72189 vma->vm_ops = &generic_file_vm_ops;
72190 vma->vm_flags |= VM_CAN_NONLINEAR;
72191 @@ -2087,6 +2087,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
72192 *pos = i_size_read(inode);
72193
72194 if (limit != RLIM_INFINITY) {
72195 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
72196 if (*pos >= limit) {
72197 send_sig(SIGXFSZ, current, 0);
72198 return -EFBIG;
72199 diff --git a/mm/fremap.c b/mm/fremap.c
72200 index 9ed4fd4..c42648d 100644
72201 --- a/mm/fremap.c
72202 +++ b/mm/fremap.c
72203 @@ -155,6 +155,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
72204 retry:
72205 vma = find_vma(mm, start);
72206
72207 +#ifdef CONFIG_PAX_SEGMEXEC
72208 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
72209 + goto out;
72210 +#endif
72211 +
72212 /*
72213 * Make sure the vma is shared, that it supports prefaulting,
72214 * and that the remapped range is valid and fully within
72215 diff --git a/mm/highmem.c b/mm/highmem.c
72216 index d517cd1..9568fec 100644
72217 --- a/mm/highmem.c
72218 +++ b/mm/highmem.c
72219 @@ -98,7 +98,7 @@ struct page *kmap_to_page(void *vaddr)
72220 {
72221 unsigned long addr = (unsigned long)vaddr;
72222
72223 - if (addr >= PKMAP_ADDR(0) && addr <= PKMAP_ADDR(LAST_PKMAP)) {
72224 + if (addr >= PKMAP_ADDR(0) && addr < PKMAP_ADDR(LAST_PKMAP)) {
72225 int i = (addr - PKMAP_ADDR(0)) >> PAGE_SHIFT;
72226 return pte_page(pkmap_page_table[i]);
72227 }
72228 @@ -137,9 +137,10 @@ static void flush_all_zero_pkmaps(void)
72229 * So no dangers, even with speculative execution.
72230 */
72231 page = pte_page(pkmap_page_table[i]);
72232 + pax_open_kernel();
72233 pte_clear(&init_mm, (unsigned long)page_address(page),
72234 &pkmap_page_table[i]);
72235 -
72236 + pax_close_kernel();
72237 set_page_address(page, NULL);
72238 need_flush = 1;
72239 }
72240 @@ -198,9 +199,11 @@ start:
72241 }
72242 }
72243 vaddr = PKMAP_ADDR(last_pkmap_nr);
72244 +
72245 + pax_open_kernel();
72246 set_pte_at(&init_mm, vaddr,
72247 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
72248 -
72249 + pax_close_kernel();
72250 pkmap_count[last_pkmap_nr] = 1;
72251 set_page_address(page, (void *)vaddr);
72252
72253 diff --git a/mm/huge_memory.c b/mm/huge_memory.c
72254 index 141dbb6..ebff057 100644
72255 --- a/mm/huge_memory.c
72256 +++ b/mm/huge_memory.c
72257 @@ -735,7 +735,7 @@ out:
72258 * run pte_offset_map on the pmd, if an huge pmd could
72259 * materialize from under us from a different thread.
72260 */
72261 - if (unlikely(__pte_alloc(mm, vma, pmd, address)))
72262 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
72263 return VM_FAULT_OOM;
72264 /* if an huge pmd materialized from under us just retry later */
72265 if (unlikely(pmd_trans_huge(*pmd)))
72266 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
72267 index 3adceaf..dccfea3 100644
72268 --- a/mm/hugetlb.c
72269 +++ b/mm/hugetlb.c
72270 @@ -2512,6 +2512,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
72271 return 1;
72272 }
72273
72274 +#ifdef CONFIG_PAX_SEGMEXEC
72275 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
72276 +{
72277 + struct mm_struct *mm = vma->vm_mm;
72278 + struct vm_area_struct *vma_m;
72279 + unsigned long address_m;
72280 + pte_t *ptep_m;
72281 +
72282 + vma_m = pax_find_mirror_vma(vma);
72283 + if (!vma_m)
72284 + return;
72285 +
72286 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72287 + address_m = address + SEGMEXEC_TASK_SIZE;
72288 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
72289 + get_page(page_m);
72290 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
72291 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
72292 +}
72293 +#endif
72294 +
72295 /*
72296 * Hugetlb_cow() should be called with page lock of the original hugepage held.
72297 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
72298 @@ -2628,6 +2649,11 @@ retry_avoidcopy:
72299 make_huge_pte(vma, new_page, 1));
72300 page_remove_rmap(old_page);
72301 hugepage_add_new_anon_rmap(new_page, vma, address);
72302 +
72303 +#ifdef CONFIG_PAX_SEGMEXEC
72304 + pax_mirror_huge_pte(vma, address, new_page);
72305 +#endif
72306 +
72307 /* Make the old page be freed below */
72308 new_page = old_page;
72309 mmu_notifier_invalidate_range_end(mm,
72310 @@ -2786,6 +2812,10 @@ retry:
72311 && (vma->vm_flags & VM_SHARED)));
72312 set_huge_pte_at(mm, address, ptep, new_pte);
72313
72314 +#ifdef CONFIG_PAX_SEGMEXEC
72315 + pax_mirror_huge_pte(vma, address, page);
72316 +#endif
72317 +
72318 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
72319 /* Optimization, do the COW without a second fault */
72320 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
72321 @@ -2815,6 +2845,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72322 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
72323 struct hstate *h = hstate_vma(vma);
72324
72325 +#ifdef CONFIG_PAX_SEGMEXEC
72326 + struct vm_area_struct *vma_m;
72327 +#endif
72328 +
72329 address &= huge_page_mask(h);
72330
72331 ptep = huge_pte_offset(mm, address);
72332 @@ -2828,6 +2862,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72333 VM_FAULT_SET_HINDEX(hstate_index(h));
72334 }
72335
72336 +#ifdef CONFIG_PAX_SEGMEXEC
72337 + vma_m = pax_find_mirror_vma(vma);
72338 + if (vma_m) {
72339 + unsigned long address_m;
72340 +
72341 + if (vma->vm_start > vma_m->vm_start) {
72342 + address_m = address;
72343 + address -= SEGMEXEC_TASK_SIZE;
72344 + vma = vma_m;
72345 + h = hstate_vma(vma);
72346 + } else
72347 + address_m = address + SEGMEXEC_TASK_SIZE;
72348 +
72349 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
72350 + return VM_FAULT_OOM;
72351 + address_m &= HPAGE_MASK;
72352 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
72353 + }
72354 +#endif
72355 +
72356 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
72357 if (!ptep)
72358 return VM_FAULT_OOM;
72359 diff --git a/mm/internal.h b/mm/internal.h
72360 index b8c91b3..93e95a3 100644
72361 --- a/mm/internal.h
72362 +++ b/mm/internal.h
72363 @@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
72364 * in mm/page_alloc.c
72365 */
72366 extern void __free_pages_bootmem(struct page *page, unsigned int order);
72367 +extern void free_compound_page(struct page *page);
72368 extern void prep_compound_page(struct page *page, unsigned long order);
72369 #ifdef CONFIG_MEMORY_FAILURE
72370 extern bool is_free_buddy_page(struct page *page);
72371 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
72372 index 45eb621..6ccd8ea 100644
72373 --- a/mm/kmemleak.c
72374 +++ b/mm/kmemleak.c
72375 @@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
72376
72377 for (i = 0; i < object->trace_len; i++) {
72378 void *ptr = (void *)object->trace[i];
72379 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
72380 + seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
72381 }
72382 }
72383
72384 diff --git a/mm/maccess.c b/mm/maccess.c
72385 index d53adf9..03a24bf 100644
72386 --- a/mm/maccess.c
72387 +++ b/mm/maccess.c
72388 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
72389 set_fs(KERNEL_DS);
72390 pagefault_disable();
72391 ret = __copy_from_user_inatomic(dst,
72392 - (__force const void __user *)src, size);
72393 + (const void __force_user *)src, size);
72394 pagefault_enable();
72395 set_fs(old_fs);
72396
72397 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
72398
72399 set_fs(KERNEL_DS);
72400 pagefault_disable();
72401 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
72402 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
72403 pagefault_enable();
72404 set_fs(old_fs);
72405
72406 diff --git a/mm/madvise.c b/mm/madvise.c
72407 index 14d260f..b2a80fd 100644
72408 --- a/mm/madvise.c
72409 +++ b/mm/madvise.c
72410 @@ -48,6 +48,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
72411 pgoff_t pgoff;
72412 unsigned long new_flags = vma->vm_flags;
72413
72414 +#ifdef CONFIG_PAX_SEGMEXEC
72415 + struct vm_area_struct *vma_m;
72416 +#endif
72417 +
72418 switch (behavior) {
72419 case MADV_NORMAL:
72420 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
72421 @@ -119,6 +123,13 @@ success:
72422 /*
72423 * vm_flags is protected by the mmap_sem held in write mode.
72424 */
72425 +
72426 +#ifdef CONFIG_PAX_SEGMEXEC
72427 + vma_m = pax_find_mirror_vma(vma);
72428 + if (vma_m)
72429 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
72430 +#endif
72431 +
72432 vma->vm_flags = new_flags;
72433
72434 out:
72435 @@ -177,6 +188,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
72436 struct vm_area_struct ** prev,
72437 unsigned long start, unsigned long end)
72438 {
72439 +
72440 +#ifdef CONFIG_PAX_SEGMEXEC
72441 + struct vm_area_struct *vma_m;
72442 +#endif
72443 +
72444 *prev = vma;
72445 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
72446 return -EINVAL;
72447 @@ -189,6 +205,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
72448 zap_page_range(vma, start, end - start, &details);
72449 } else
72450 zap_page_range(vma, start, end - start, NULL);
72451 +
72452 +#ifdef CONFIG_PAX_SEGMEXEC
72453 + vma_m = pax_find_mirror_vma(vma);
72454 + if (vma_m) {
72455 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
72456 + struct zap_details details = {
72457 + .nonlinear_vma = vma_m,
72458 + .last_index = ULONG_MAX,
72459 + };
72460 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
72461 + } else
72462 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
72463 + }
72464 +#endif
72465 +
72466 return 0;
72467 }
72468
72469 @@ -393,6 +424,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
72470 if (end < start)
72471 goto out;
72472
72473 +#ifdef CONFIG_PAX_SEGMEXEC
72474 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
72475 + if (end > SEGMEXEC_TASK_SIZE)
72476 + goto out;
72477 + } else
72478 +#endif
72479 +
72480 + if (end > TASK_SIZE)
72481 + goto out;
72482 +
72483 error = 0;
72484 if (end == start)
72485 goto out;
72486 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
72487 index a6e2141..0e32042 100644
72488 --- a/mm/memory-failure.c
72489 +++ b/mm/memory-failure.c
72490 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
72491
72492 int sysctl_memory_failure_recovery __read_mostly = 1;
72493
72494 -atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
72495 +atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
72496
72497 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
72498
72499 @@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
72500 pfn, t->comm, t->pid);
72501 si.si_signo = SIGBUS;
72502 si.si_errno = 0;
72503 - si.si_addr = (void *)addr;
72504 + si.si_addr = (void __user *)addr;
72505 #ifdef __ARCH_SI_TRAPNO
72506 si.si_trapno = trapno;
72507 #endif
72508 @@ -1038,7 +1038,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
72509 }
72510
72511 nr_pages = 1 << compound_trans_order(hpage);
72512 - atomic_long_add(nr_pages, &mce_bad_pages);
72513 + atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
72514
72515 /*
72516 * We need/can do nothing about count=0 pages.
72517 @@ -1068,7 +1068,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
72518 if (!PageHWPoison(hpage)
72519 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
72520 || (p != hpage && TestSetPageHWPoison(hpage))) {
72521 - atomic_long_sub(nr_pages, &mce_bad_pages);
72522 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
72523 return 0;
72524 }
72525 set_page_hwpoison_huge_page(hpage);
72526 @@ -1126,7 +1126,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
72527 }
72528 if (hwpoison_filter(p)) {
72529 if (TestClearPageHWPoison(p))
72530 - atomic_long_sub(nr_pages, &mce_bad_pages);
72531 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
72532 unlock_page(hpage);
72533 put_page(hpage);
72534 return 0;
72535 @@ -1321,7 +1321,7 @@ int unpoison_memory(unsigned long pfn)
72536 return 0;
72537 }
72538 if (TestClearPageHWPoison(p))
72539 - atomic_long_sub(nr_pages, &mce_bad_pages);
72540 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
72541 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
72542 return 0;
72543 }
72544 @@ -1335,7 +1335,7 @@ int unpoison_memory(unsigned long pfn)
72545 */
72546 if (TestClearPageHWPoison(page)) {
72547 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
72548 - atomic_long_sub(nr_pages, &mce_bad_pages);
72549 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
72550 freeit = 1;
72551 if (PageHuge(page))
72552 clear_page_hwpoison_huge_page(page);
72553 @@ -1440,7 +1440,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
72554 }
72555 done:
72556 if (!PageHWPoison(hpage))
72557 - atomic_long_add(1 << compound_trans_order(hpage),
72558 + atomic_long_add_unchecked(1 << compound_trans_order(hpage),
72559 &mce_bad_pages);
72560 set_page_hwpoison_huge_page(hpage);
72561 dequeue_hwpoisoned_huge_page(hpage);
72562 @@ -1474,9 +1474,17 @@ int soft_offline_page(struct page *page, int flags)
72563 {
72564 int ret;
72565 unsigned long pfn = page_to_pfn(page);
72566 + struct page *hpage = compound_trans_head(page);
72567
72568 if (PageHuge(page))
72569 return soft_offline_huge_page(page, flags);
72570 + if (PageTransHuge(hpage)) {
72571 + if (PageAnon(hpage) && unlikely(split_huge_page(hpage))) {
72572 + pr_info("soft offline: %#lx: failed to split THP\n",
72573 + pfn);
72574 + return -EBUSY;
72575 + }
72576 + }
72577
72578 ret = get_any_page(page, pfn, flags);
72579 if (ret < 0)
72580 @@ -1572,7 +1580,7 @@ int soft_offline_page(struct page *page, int flags)
72581 return ret;
72582
72583 done:
72584 - atomic_long_add(1, &mce_bad_pages);
72585 + atomic_long_add_unchecked(1, &mce_bad_pages);
72586 SetPageHWPoison(page);
72587 /* keep elevated page count for bad page */
72588 return ret;
72589 diff --git a/mm/memory.c b/mm/memory.c
72590 index 5736170..8e04800 100644
72591 --- a/mm/memory.c
72592 +++ b/mm/memory.c
72593 @@ -426,6 +426,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
72594 free_pte_range(tlb, pmd, addr);
72595 } while (pmd++, addr = next, addr != end);
72596
72597 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
72598 start &= PUD_MASK;
72599 if (start < floor)
72600 return;
72601 @@ -440,6 +441,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
72602 pmd = pmd_offset(pud, start);
72603 pud_clear(pud);
72604 pmd_free_tlb(tlb, pmd, start);
72605 +#endif
72606 +
72607 }
72608
72609 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
72610 @@ -459,6 +462,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
72611 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
72612 } while (pud++, addr = next, addr != end);
72613
72614 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
72615 start &= PGDIR_MASK;
72616 if (start < floor)
72617 return;
72618 @@ -473,6 +477,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
72619 pud = pud_offset(pgd, start);
72620 pgd_clear(pgd);
72621 pud_free_tlb(tlb, pud, start);
72622 +#endif
72623 +
72624 }
72625
72626 /*
72627 @@ -1614,12 +1620,6 @@ no_page_table:
72628 return page;
72629 }
72630
72631 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
72632 -{
72633 - return stack_guard_page_start(vma, addr) ||
72634 - stack_guard_page_end(vma, addr+PAGE_SIZE);
72635 -}
72636 -
72637 /**
72638 * __get_user_pages() - pin user pages in memory
72639 * @tsk: task_struct of target task
72640 @@ -1692,10 +1692,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
72641 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
72642 i = 0;
72643
72644 - do {
72645 + while (nr_pages) {
72646 struct vm_area_struct *vma;
72647
72648 - vma = find_extend_vma(mm, start);
72649 + vma = find_vma(mm, start);
72650 if (!vma && in_gate_area(mm, start)) {
72651 unsigned long pg = start & PAGE_MASK;
72652 pgd_t *pgd;
72653 @@ -1743,7 +1743,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
72654 goto next_page;
72655 }
72656
72657 - if (!vma ||
72658 + if (!vma || start < vma->vm_start ||
72659 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
72660 !(vm_flags & vma->vm_flags))
72661 return i ? : -EFAULT;
72662 @@ -1770,11 +1770,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
72663 int ret;
72664 unsigned int fault_flags = 0;
72665
72666 - /* For mlock, just skip the stack guard page. */
72667 - if (foll_flags & FOLL_MLOCK) {
72668 - if (stack_guard_page(vma, start))
72669 - goto next_page;
72670 - }
72671 if (foll_flags & FOLL_WRITE)
72672 fault_flags |= FAULT_FLAG_WRITE;
72673 if (nonblocking)
72674 @@ -1848,7 +1843,7 @@ next_page:
72675 start += PAGE_SIZE;
72676 nr_pages--;
72677 } while (nr_pages && start < vma->vm_end);
72678 - } while (nr_pages);
72679 + }
72680 return i;
72681 }
72682 EXPORT_SYMBOL(__get_user_pages);
72683 @@ -2055,6 +2050,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
72684 page_add_file_rmap(page);
72685 set_pte_at(mm, addr, pte, mk_pte(page, prot));
72686
72687 +#ifdef CONFIG_PAX_SEGMEXEC
72688 + pax_mirror_file_pte(vma, addr, page, ptl);
72689 +#endif
72690 +
72691 retval = 0;
72692 pte_unmap_unlock(pte, ptl);
72693 return retval;
72694 @@ -2089,10 +2088,22 @@ out:
72695 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
72696 struct page *page)
72697 {
72698 +
72699 +#ifdef CONFIG_PAX_SEGMEXEC
72700 + struct vm_area_struct *vma_m;
72701 +#endif
72702 +
72703 if (addr < vma->vm_start || addr >= vma->vm_end)
72704 return -EFAULT;
72705 if (!page_count(page))
72706 return -EINVAL;
72707 +
72708 +#ifdef CONFIG_PAX_SEGMEXEC
72709 + vma_m = pax_find_mirror_vma(vma);
72710 + if (vma_m)
72711 + vma_m->vm_flags |= VM_INSERTPAGE;
72712 +#endif
72713 +
72714 vma->vm_flags |= VM_INSERTPAGE;
72715 return insert_page(vma, addr, page, vma->vm_page_prot);
72716 }
72717 @@ -2178,6 +2189,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
72718 unsigned long pfn)
72719 {
72720 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
72721 + BUG_ON(vma->vm_mirror);
72722
72723 if (addr < vma->vm_start || addr >= vma->vm_end)
72724 return -EFAULT;
72725 @@ -2385,7 +2397,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
72726
72727 BUG_ON(pud_huge(*pud));
72728
72729 - pmd = pmd_alloc(mm, pud, addr);
72730 + pmd = (mm == &init_mm) ?
72731 + pmd_alloc_kernel(mm, pud, addr) :
72732 + pmd_alloc(mm, pud, addr);
72733 if (!pmd)
72734 return -ENOMEM;
72735 do {
72736 @@ -2405,7 +2419,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
72737 unsigned long next;
72738 int err;
72739
72740 - pud = pud_alloc(mm, pgd, addr);
72741 + pud = (mm == &init_mm) ?
72742 + pud_alloc_kernel(mm, pgd, addr) :
72743 + pud_alloc(mm, pgd, addr);
72744 if (!pud)
72745 return -ENOMEM;
72746 do {
72747 @@ -2493,6 +2509,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
72748 copy_user_highpage(dst, src, va, vma);
72749 }
72750
72751 +#ifdef CONFIG_PAX_SEGMEXEC
72752 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
72753 +{
72754 + struct mm_struct *mm = vma->vm_mm;
72755 + spinlock_t *ptl;
72756 + pte_t *pte, entry;
72757 +
72758 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
72759 + entry = *pte;
72760 + if (!pte_present(entry)) {
72761 + if (!pte_none(entry)) {
72762 + BUG_ON(pte_file(entry));
72763 + free_swap_and_cache(pte_to_swp_entry(entry));
72764 + pte_clear_not_present_full(mm, address, pte, 0);
72765 + }
72766 + } else {
72767 + struct page *page;
72768 +
72769 + flush_cache_page(vma, address, pte_pfn(entry));
72770 + entry = ptep_clear_flush(vma, address, pte);
72771 + BUG_ON(pte_dirty(entry));
72772 + page = vm_normal_page(vma, address, entry);
72773 + if (page) {
72774 + update_hiwater_rss(mm);
72775 + if (PageAnon(page))
72776 + dec_mm_counter_fast(mm, MM_ANONPAGES);
72777 + else
72778 + dec_mm_counter_fast(mm, MM_FILEPAGES);
72779 + page_remove_rmap(page);
72780 + page_cache_release(page);
72781 + }
72782 + }
72783 + pte_unmap_unlock(pte, ptl);
72784 +}
72785 +
72786 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
72787 + *
72788 + * the ptl of the lower mapped page is held on entry and is not released on exit
72789 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
72790 + */
72791 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
72792 +{
72793 + struct mm_struct *mm = vma->vm_mm;
72794 + unsigned long address_m;
72795 + spinlock_t *ptl_m;
72796 + struct vm_area_struct *vma_m;
72797 + pmd_t *pmd_m;
72798 + pte_t *pte_m, entry_m;
72799 +
72800 + BUG_ON(!page_m || !PageAnon(page_m));
72801 +
72802 + vma_m = pax_find_mirror_vma(vma);
72803 + if (!vma_m)
72804 + return;
72805 +
72806 + BUG_ON(!PageLocked(page_m));
72807 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72808 + address_m = address + SEGMEXEC_TASK_SIZE;
72809 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
72810 + pte_m = pte_offset_map(pmd_m, address_m);
72811 + ptl_m = pte_lockptr(mm, pmd_m);
72812 + if (ptl != ptl_m) {
72813 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
72814 + if (!pte_none(*pte_m))
72815 + goto out;
72816 + }
72817 +
72818 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
72819 + page_cache_get(page_m);
72820 + page_add_anon_rmap(page_m, vma_m, address_m);
72821 + inc_mm_counter_fast(mm, MM_ANONPAGES);
72822 + set_pte_at(mm, address_m, pte_m, entry_m);
72823 + update_mmu_cache(vma_m, address_m, entry_m);
72824 +out:
72825 + if (ptl != ptl_m)
72826 + spin_unlock(ptl_m);
72827 + pte_unmap(pte_m);
72828 + unlock_page(page_m);
72829 +}
72830 +
72831 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
72832 +{
72833 + struct mm_struct *mm = vma->vm_mm;
72834 + unsigned long address_m;
72835 + spinlock_t *ptl_m;
72836 + struct vm_area_struct *vma_m;
72837 + pmd_t *pmd_m;
72838 + pte_t *pte_m, entry_m;
72839 +
72840 + BUG_ON(!page_m || PageAnon(page_m));
72841 +
72842 + vma_m = pax_find_mirror_vma(vma);
72843 + if (!vma_m)
72844 + return;
72845 +
72846 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72847 + address_m = address + SEGMEXEC_TASK_SIZE;
72848 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
72849 + pte_m = pte_offset_map(pmd_m, address_m);
72850 + ptl_m = pte_lockptr(mm, pmd_m);
72851 + if (ptl != ptl_m) {
72852 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
72853 + if (!pte_none(*pte_m))
72854 + goto out;
72855 + }
72856 +
72857 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
72858 + page_cache_get(page_m);
72859 + page_add_file_rmap(page_m);
72860 + inc_mm_counter_fast(mm, MM_FILEPAGES);
72861 + set_pte_at(mm, address_m, pte_m, entry_m);
72862 + update_mmu_cache(vma_m, address_m, entry_m);
72863 +out:
72864 + if (ptl != ptl_m)
72865 + spin_unlock(ptl_m);
72866 + pte_unmap(pte_m);
72867 +}
72868 +
72869 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
72870 +{
72871 + struct mm_struct *mm = vma->vm_mm;
72872 + unsigned long address_m;
72873 + spinlock_t *ptl_m;
72874 + struct vm_area_struct *vma_m;
72875 + pmd_t *pmd_m;
72876 + pte_t *pte_m, entry_m;
72877 +
72878 + vma_m = pax_find_mirror_vma(vma);
72879 + if (!vma_m)
72880 + return;
72881 +
72882 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72883 + address_m = address + SEGMEXEC_TASK_SIZE;
72884 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
72885 + pte_m = pte_offset_map(pmd_m, address_m);
72886 + ptl_m = pte_lockptr(mm, pmd_m);
72887 + if (ptl != ptl_m) {
72888 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
72889 + if (!pte_none(*pte_m))
72890 + goto out;
72891 + }
72892 +
72893 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
72894 + set_pte_at(mm, address_m, pte_m, entry_m);
72895 +out:
72896 + if (ptl != ptl_m)
72897 + spin_unlock(ptl_m);
72898 + pte_unmap(pte_m);
72899 +}
72900 +
72901 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
72902 +{
72903 + struct page *page_m;
72904 + pte_t entry;
72905 +
72906 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
72907 + goto out;
72908 +
72909 + entry = *pte;
72910 + page_m = vm_normal_page(vma, address, entry);
72911 + if (!page_m)
72912 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
72913 + else if (PageAnon(page_m)) {
72914 + if (pax_find_mirror_vma(vma)) {
72915 + pte_unmap_unlock(pte, ptl);
72916 + lock_page(page_m);
72917 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
72918 + if (pte_same(entry, *pte))
72919 + pax_mirror_anon_pte(vma, address, page_m, ptl);
72920 + else
72921 + unlock_page(page_m);
72922 + }
72923 + } else
72924 + pax_mirror_file_pte(vma, address, page_m, ptl);
72925 +
72926 +out:
72927 + pte_unmap_unlock(pte, ptl);
72928 +}
72929 +#endif
72930 +
72931 /*
72932 * This routine handles present pages, when users try to write
72933 * to a shared page. It is done by copying the page to a new address
72934 @@ -2703,6 +2899,12 @@ gotten:
72935 */
72936 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
72937 if (likely(pte_same(*page_table, orig_pte))) {
72938 +
72939 +#ifdef CONFIG_PAX_SEGMEXEC
72940 + if (pax_find_mirror_vma(vma))
72941 + BUG_ON(!trylock_page(new_page));
72942 +#endif
72943 +
72944 if (old_page) {
72945 if (!PageAnon(old_page)) {
72946 dec_mm_counter_fast(mm, MM_FILEPAGES);
72947 @@ -2754,6 +2956,10 @@ gotten:
72948 page_remove_rmap(old_page);
72949 }
72950
72951 +#ifdef CONFIG_PAX_SEGMEXEC
72952 + pax_mirror_anon_pte(vma, address, new_page, ptl);
72953 +#endif
72954 +
72955 /* Free the old page.. */
72956 new_page = old_page;
72957 ret |= VM_FAULT_WRITE;
72958 @@ -3033,6 +3239,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
72959 swap_free(entry);
72960 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
72961 try_to_free_swap(page);
72962 +
72963 +#ifdef CONFIG_PAX_SEGMEXEC
72964 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
72965 +#endif
72966 +
72967 unlock_page(page);
72968 if (swapcache) {
72969 /*
72970 @@ -3056,6 +3267,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
72971
72972 /* No need to invalidate - it was non-present before */
72973 update_mmu_cache(vma, address, page_table);
72974 +
72975 +#ifdef CONFIG_PAX_SEGMEXEC
72976 + pax_mirror_anon_pte(vma, address, page, ptl);
72977 +#endif
72978 +
72979 unlock:
72980 pte_unmap_unlock(page_table, ptl);
72981 out:
72982 @@ -3075,40 +3291,6 @@ out_release:
72983 }
72984
72985 /*
72986 - * This is like a special single-page "expand_{down|up}wards()",
72987 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
72988 - * doesn't hit another vma.
72989 - */
72990 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
72991 -{
72992 - address &= PAGE_MASK;
72993 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
72994 - struct vm_area_struct *prev = vma->vm_prev;
72995 -
72996 - /*
72997 - * Is there a mapping abutting this one below?
72998 - *
72999 - * That's only ok if it's the same stack mapping
73000 - * that has gotten split..
73001 - */
73002 - if (prev && prev->vm_end == address)
73003 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
73004 -
73005 - expand_downwards(vma, address - PAGE_SIZE);
73006 - }
73007 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
73008 - struct vm_area_struct *next = vma->vm_next;
73009 -
73010 - /* As VM_GROWSDOWN but s/below/above/ */
73011 - if (next && next->vm_start == address + PAGE_SIZE)
73012 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
73013 -
73014 - expand_upwards(vma, address + PAGE_SIZE);
73015 - }
73016 - return 0;
73017 -}
73018 -
73019 -/*
73020 * We enter with non-exclusive mmap_sem (to exclude vma changes,
73021 * but allow concurrent faults), and pte mapped but not yet locked.
73022 * We return with mmap_sem still held, but pte unmapped and unlocked.
73023 @@ -3117,27 +3299,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
73024 unsigned long address, pte_t *page_table, pmd_t *pmd,
73025 unsigned int flags)
73026 {
73027 - struct page *page;
73028 + struct page *page = NULL;
73029 spinlock_t *ptl;
73030 pte_t entry;
73031
73032 - pte_unmap(page_table);
73033 -
73034 - /* Check if we need to add a guard page to the stack */
73035 - if (check_stack_guard_page(vma, address) < 0)
73036 - return VM_FAULT_SIGBUS;
73037 -
73038 - /* Use the zero-page for reads */
73039 if (!(flags & FAULT_FLAG_WRITE)) {
73040 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
73041 vma->vm_page_prot));
73042 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
73043 + ptl = pte_lockptr(mm, pmd);
73044 + spin_lock(ptl);
73045 if (!pte_none(*page_table))
73046 goto unlock;
73047 goto setpte;
73048 }
73049
73050 /* Allocate our own private page. */
73051 + pte_unmap(page_table);
73052 +
73053 if (unlikely(anon_vma_prepare(vma)))
73054 goto oom;
73055 page = alloc_zeroed_user_highpage_movable(vma, address);
73056 @@ -3156,6 +3334,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
73057 if (!pte_none(*page_table))
73058 goto release;
73059
73060 +#ifdef CONFIG_PAX_SEGMEXEC
73061 + if (pax_find_mirror_vma(vma))
73062 + BUG_ON(!trylock_page(page));
73063 +#endif
73064 +
73065 inc_mm_counter_fast(mm, MM_ANONPAGES);
73066 page_add_new_anon_rmap(page, vma, address);
73067 setpte:
73068 @@ -3163,6 +3346,12 @@ setpte:
73069
73070 /* No need to invalidate - it was non-present before */
73071 update_mmu_cache(vma, address, page_table);
73072 +
73073 +#ifdef CONFIG_PAX_SEGMEXEC
73074 + if (page)
73075 + pax_mirror_anon_pte(vma, address, page, ptl);
73076 +#endif
73077 +
73078 unlock:
73079 pte_unmap_unlock(page_table, ptl);
73080 return 0;
73081 @@ -3306,6 +3495,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
73082 */
73083 /* Only go through if we didn't race with anybody else... */
73084 if (likely(pte_same(*page_table, orig_pte))) {
73085 +
73086 +#ifdef CONFIG_PAX_SEGMEXEC
73087 + if (anon && pax_find_mirror_vma(vma))
73088 + BUG_ON(!trylock_page(page));
73089 +#endif
73090 +
73091 flush_icache_page(vma, page);
73092 entry = mk_pte(page, vma->vm_page_prot);
73093 if (flags & FAULT_FLAG_WRITE)
73094 @@ -3325,6 +3520,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
73095
73096 /* no need to invalidate: a not-present page won't be cached */
73097 update_mmu_cache(vma, address, page_table);
73098 +
73099 +#ifdef CONFIG_PAX_SEGMEXEC
73100 + if (anon)
73101 + pax_mirror_anon_pte(vma, address, page, ptl);
73102 + else
73103 + pax_mirror_file_pte(vma, address, page, ptl);
73104 +#endif
73105 +
73106 } else {
73107 if (cow_page)
73108 mem_cgroup_uncharge_page(cow_page);
73109 @@ -3479,6 +3682,12 @@ int handle_pte_fault(struct mm_struct *mm,
73110 if (flags & FAULT_FLAG_WRITE)
73111 flush_tlb_fix_spurious_fault(vma, address);
73112 }
73113 +
73114 +#ifdef CONFIG_PAX_SEGMEXEC
73115 + pax_mirror_pte(vma, address, pte, pmd, ptl);
73116 + return 0;
73117 +#endif
73118 +
73119 unlock:
73120 pte_unmap_unlock(pte, ptl);
73121 return 0;
73122 @@ -3495,6 +3704,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
73123 pmd_t *pmd;
73124 pte_t *pte;
73125
73126 +#ifdef CONFIG_PAX_SEGMEXEC
73127 + struct vm_area_struct *vma_m;
73128 +#endif
73129 +
73130 __set_current_state(TASK_RUNNING);
73131
73132 count_vm_event(PGFAULT);
73133 @@ -3506,6 +3719,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
73134 if (unlikely(is_vm_hugetlb_page(vma)))
73135 return hugetlb_fault(mm, vma, address, flags);
73136
73137 +#ifdef CONFIG_PAX_SEGMEXEC
73138 + vma_m = pax_find_mirror_vma(vma);
73139 + if (vma_m) {
73140 + unsigned long address_m;
73141 + pgd_t *pgd_m;
73142 + pud_t *pud_m;
73143 + pmd_t *pmd_m;
73144 +
73145 + if (vma->vm_start > vma_m->vm_start) {
73146 + address_m = address;
73147 + address -= SEGMEXEC_TASK_SIZE;
73148 + vma = vma_m;
73149 + } else
73150 + address_m = address + SEGMEXEC_TASK_SIZE;
73151 +
73152 + pgd_m = pgd_offset(mm, address_m);
73153 + pud_m = pud_alloc(mm, pgd_m, address_m);
73154 + if (!pud_m)
73155 + return VM_FAULT_OOM;
73156 + pmd_m = pmd_alloc(mm, pud_m, address_m);
73157 + if (!pmd_m)
73158 + return VM_FAULT_OOM;
73159 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
73160 + return VM_FAULT_OOM;
73161 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
73162 + }
73163 +#endif
73164 +
73165 retry:
73166 pgd = pgd_offset(mm, address);
73167 pud = pud_alloc(mm, pgd, address);
73168 @@ -3547,7 +3788,7 @@ retry:
73169 * run pte_offset_map on the pmd, if an huge pmd could
73170 * materialize from under us from a different thread.
73171 */
73172 - if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
73173 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
73174 return VM_FAULT_OOM;
73175 /* if an huge pmd materialized from under us just retry later */
73176 if (unlikely(pmd_trans_huge(*pmd)))
73177 @@ -3584,6 +3825,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
73178 spin_unlock(&mm->page_table_lock);
73179 return 0;
73180 }
73181 +
73182 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
73183 +{
73184 + pud_t *new = pud_alloc_one(mm, address);
73185 + if (!new)
73186 + return -ENOMEM;
73187 +
73188 + smp_wmb(); /* See comment in __pte_alloc */
73189 +
73190 + spin_lock(&mm->page_table_lock);
73191 + if (pgd_present(*pgd)) /* Another has populated it */
73192 + pud_free(mm, new);
73193 + else
73194 + pgd_populate_kernel(mm, pgd, new);
73195 + spin_unlock(&mm->page_table_lock);
73196 + return 0;
73197 +}
73198 #endif /* __PAGETABLE_PUD_FOLDED */
73199
73200 #ifndef __PAGETABLE_PMD_FOLDED
73201 @@ -3614,6 +3872,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
73202 spin_unlock(&mm->page_table_lock);
73203 return 0;
73204 }
73205 +
73206 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
73207 +{
73208 + pmd_t *new = pmd_alloc_one(mm, address);
73209 + if (!new)
73210 + return -ENOMEM;
73211 +
73212 + smp_wmb(); /* See comment in __pte_alloc */
73213 +
73214 + spin_lock(&mm->page_table_lock);
73215 +#ifndef __ARCH_HAS_4LEVEL_HACK
73216 + if (pud_present(*pud)) /* Another has populated it */
73217 + pmd_free(mm, new);
73218 + else
73219 + pud_populate_kernel(mm, pud, new);
73220 +#else
73221 + if (pgd_present(*pud)) /* Another has populated it */
73222 + pmd_free(mm, new);
73223 + else
73224 + pgd_populate_kernel(mm, pud, new);
73225 +#endif /* __ARCH_HAS_4LEVEL_HACK */
73226 + spin_unlock(&mm->page_table_lock);
73227 + return 0;
73228 +}
73229 #endif /* __PAGETABLE_PMD_FOLDED */
73230
73231 int make_pages_present(unsigned long addr, unsigned long end)
73232 @@ -3651,7 +3933,7 @@ static int __init gate_vma_init(void)
73233 gate_vma.vm_start = FIXADDR_USER_START;
73234 gate_vma.vm_end = FIXADDR_USER_END;
73235 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
73236 - gate_vma.vm_page_prot = __P101;
73237 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
73238
73239 return 0;
73240 }
73241 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
73242 index 3d64b36..c6ab69c 100644
73243 --- a/mm/mempolicy.c
73244 +++ b/mm/mempolicy.c
73245 @@ -655,6 +655,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
73246 unsigned long vmstart;
73247 unsigned long vmend;
73248
73249 +#ifdef CONFIG_PAX_SEGMEXEC
73250 + struct vm_area_struct *vma_m;
73251 +#endif
73252 +
73253 vma = find_vma(mm, start);
73254 if (!vma || vma->vm_start > start)
73255 return -EFAULT;
73256 @@ -691,9 +695,20 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
73257 if (err)
73258 goto out;
73259 }
73260 +
73261 err = vma_replace_policy(vma, new_pol);
73262 if (err)
73263 goto out;
73264 +
73265 +#ifdef CONFIG_PAX_SEGMEXEC
73266 + vma_m = pax_find_mirror_vma(vma);
73267 + if (vma_m) {
73268 + err = vma_replace_policy(vma_m, new_pol);
73269 + if (err)
73270 + goto out;
73271 + }
73272 +#endif
73273 +
73274 }
73275
73276 out:
73277 @@ -1147,6 +1162,17 @@ static long do_mbind(unsigned long start, unsigned long len,
73278
73279 if (end < start)
73280 return -EINVAL;
73281 +
73282 +#ifdef CONFIG_PAX_SEGMEXEC
73283 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
73284 + if (end > SEGMEXEC_TASK_SIZE)
73285 + return -EINVAL;
73286 + } else
73287 +#endif
73288 +
73289 + if (end > TASK_SIZE)
73290 + return -EINVAL;
73291 +
73292 if (end == start)
73293 return 0;
73294
73295 @@ -1370,8 +1396,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
73296 */
73297 tcred = __task_cred(task);
73298 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
73299 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
73300 - !capable(CAP_SYS_NICE)) {
73301 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
73302 rcu_read_unlock();
73303 err = -EPERM;
73304 goto out_put;
73305 @@ -1402,6 +1427,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
73306 goto out;
73307 }
73308
73309 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
73310 + if (mm != current->mm &&
73311 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
73312 + mmput(mm);
73313 + err = -EPERM;
73314 + goto out;
73315 + }
73316 +#endif
73317 +
73318 err = do_migrate_pages(mm, old, new,
73319 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
73320
73321 diff --git a/mm/migrate.c b/mm/migrate.c
73322 index 77ed2d7..317d528 100644
73323 --- a/mm/migrate.c
73324 +++ b/mm/migrate.c
73325 @@ -1350,8 +1350,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
73326 */
73327 tcred = __task_cred(task);
73328 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
73329 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
73330 - !capable(CAP_SYS_NICE)) {
73331 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
73332 rcu_read_unlock();
73333 err = -EPERM;
73334 goto out;
73335 diff --git a/mm/mlock.c b/mm/mlock.c
73336 index ef726e8..cd7f1ec 100644
73337 --- a/mm/mlock.c
73338 +++ b/mm/mlock.c
73339 @@ -13,6 +13,7 @@
73340 #include <linux/pagemap.h>
73341 #include <linux/mempolicy.h>
73342 #include <linux/syscalls.h>
73343 +#include <linux/security.h>
73344 #include <linux/sched.h>
73345 #include <linux/export.h>
73346 #include <linux/rmap.h>
73347 @@ -376,7 +377,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
73348 {
73349 unsigned long nstart, end, tmp;
73350 struct vm_area_struct * vma, * prev;
73351 - int error;
73352 + int error = 0;
73353
73354 VM_BUG_ON(start & ~PAGE_MASK);
73355 VM_BUG_ON(len != PAGE_ALIGN(len));
73356 @@ -385,6 +386,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
73357 return -EINVAL;
73358 if (end == start)
73359 return 0;
73360 + if (end > TASK_SIZE)
73361 + return -EINVAL;
73362 +
73363 vma = find_vma(current->mm, start);
73364 if (!vma || vma->vm_start > start)
73365 return -ENOMEM;
73366 @@ -396,6 +400,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
73367 for (nstart = start ; ; ) {
73368 vm_flags_t newflags;
73369
73370 +#ifdef CONFIG_PAX_SEGMEXEC
73371 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
73372 + break;
73373 +#endif
73374 +
73375 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
73376
73377 newflags = vma->vm_flags | VM_LOCKED;
73378 @@ -501,6 +510,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
73379 lock_limit >>= PAGE_SHIFT;
73380
73381 /* check against resource limits */
73382 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
73383 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
73384 error = do_mlock(start, len, 1);
73385 up_write(&current->mm->mmap_sem);
73386 @@ -524,17 +534,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
73387 static int do_mlockall(int flags)
73388 {
73389 struct vm_area_struct * vma, * prev = NULL;
73390 - unsigned int def_flags = 0;
73391
73392 if (flags & MCL_FUTURE)
73393 - def_flags = VM_LOCKED;
73394 - current->mm->def_flags = def_flags;
73395 + current->mm->def_flags |= VM_LOCKED;
73396 + else
73397 + current->mm->def_flags &= ~VM_LOCKED;
73398 if (flags == MCL_FUTURE)
73399 goto out;
73400
73401 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
73402 vm_flags_t newflags;
73403
73404 +#ifdef CONFIG_PAX_SEGMEXEC
73405 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
73406 + break;
73407 +#endif
73408 +
73409 + BUG_ON(vma->vm_end > TASK_SIZE);
73410 newflags = vma->vm_flags | VM_LOCKED;
73411 if (!(flags & MCL_CURRENT))
73412 newflags &= ~VM_LOCKED;
73413 @@ -567,6 +583,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
73414 lock_limit >>= PAGE_SHIFT;
73415
73416 ret = -ENOMEM;
73417 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
73418 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
73419 capable(CAP_IPC_LOCK))
73420 ret = do_mlockall(flags);
73421 diff --git a/mm/mmap.c b/mm/mmap.c
73422 index ae18a48..86cf99e 100644
73423 --- a/mm/mmap.c
73424 +++ b/mm/mmap.c
73425 @@ -47,6 +47,16 @@
73426 #define arch_rebalance_pgtables(addr, len) (addr)
73427 #endif
73428
73429 +static inline void verify_mm_writelocked(struct mm_struct *mm)
73430 +{
73431 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
73432 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
73433 + up_read(&mm->mmap_sem);
73434 + BUG();
73435 + }
73436 +#endif
73437 +}
73438 +
73439 static void unmap_region(struct mm_struct *mm,
73440 struct vm_area_struct *vma, struct vm_area_struct *prev,
73441 unsigned long start, unsigned long end);
73442 @@ -72,22 +82,32 @@ static void unmap_region(struct mm_struct *mm,
73443 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
73444 *
73445 */
73446 -pgprot_t protection_map[16] = {
73447 +pgprot_t protection_map[16] __read_only = {
73448 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
73449 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
73450 };
73451
73452 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
73453 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
73454 {
73455 - return __pgprot(pgprot_val(protection_map[vm_flags &
73456 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
73457 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
73458 pgprot_val(arch_vm_get_page_prot(vm_flags)));
73459 +
73460 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
73461 + if (!(__supported_pte_mask & _PAGE_NX) &&
73462 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
73463 + (vm_flags & (VM_READ | VM_WRITE)))
73464 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
73465 +#endif
73466 +
73467 + return prot;
73468 }
73469 EXPORT_SYMBOL(vm_get_page_prot);
73470
73471 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
73472 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
73473 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
73474 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
73475 /*
73476 * Make sure vm_committed_as in one cacheline and not cacheline shared with
73477 * other variables. It can be updated by several CPUs frequently.
73478 @@ -229,6 +249,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
73479 struct vm_area_struct *next = vma->vm_next;
73480
73481 might_sleep();
73482 + BUG_ON(vma->vm_mirror);
73483 if (vma->vm_ops && vma->vm_ops->close)
73484 vma->vm_ops->close(vma);
73485 if (vma->vm_file) {
73486 @@ -275,6 +296,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
73487 * not page aligned -Ram Gupta
73488 */
73489 rlim = rlimit(RLIMIT_DATA);
73490 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
73491 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
73492 (mm->end_data - mm->start_data) > rlim)
73493 goto out;
73494 @@ -708,6 +730,12 @@ static int
73495 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
73496 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
73497 {
73498 +
73499 +#ifdef CONFIG_PAX_SEGMEXEC
73500 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
73501 + return 0;
73502 +#endif
73503 +
73504 if (is_mergeable_vma(vma, file, vm_flags) &&
73505 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
73506 if (vma->vm_pgoff == vm_pgoff)
73507 @@ -727,6 +755,12 @@ static int
73508 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
73509 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
73510 {
73511 +
73512 +#ifdef CONFIG_PAX_SEGMEXEC
73513 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
73514 + return 0;
73515 +#endif
73516 +
73517 if (is_mergeable_vma(vma, file, vm_flags) &&
73518 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
73519 pgoff_t vm_pglen;
73520 @@ -769,13 +803,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
73521 struct vm_area_struct *vma_merge(struct mm_struct *mm,
73522 struct vm_area_struct *prev, unsigned long addr,
73523 unsigned long end, unsigned long vm_flags,
73524 - struct anon_vma *anon_vma, struct file *file,
73525 + struct anon_vma *anon_vma, struct file *file,
73526 pgoff_t pgoff, struct mempolicy *policy)
73527 {
73528 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
73529 struct vm_area_struct *area, *next;
73530 int err;
73531
73532 +#ifdef CONFIG_PAX_SEGMEXEC
73533 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
73534 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
73535 +
73536 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
73537 +#endif
73538 +
73539 /*
73540 * We later require that vma->vm_flags == vm_flags,
73541 * so this tests vma->vm_flags & VM_SPECIAL, too.
73542 @@ -791,6 +832,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
73543 if (next && next->vm_end == end) /* cases 6, 7, 8 */
73544 next = next->vm_next;
73545
73546 +#ifdef CONFIG_PAX_SEGMEXEC
73547 + if (prev)
73548 + prev_m = pax_find_mirror_vma(prev);
73549 + if (area)
73550 + area_m = pax_find_mirror_vma(area);
73551 + if (next)
73552 + next_m = pax_find_mirror_vma(next);
73553 +#endif
73554 +
73555 /*
73556 * Can it merge with the predecessor?
73557 */
73558 @@ -810,9 +860,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
73559 /* cases 1, 6 */
73560 err = vma_adjust(prev, prev->vm_start,
73561 next->vm_end, prev->vm_pgoff, NULL);
73562 - } else /* cases 2, 5, 7 */
73563 +
73564 +#ifdef CONFIG_PAX_SEGMEXEC
73565 + if (!err && prev_m)
73566 + err = vma_adjust(prev_m, prev_m->vm_start,
73567 + next_m->vm_end, prev_m->vm_pgoff, NULL);
73568 +#endif
73569 +
73570 + } else { /* cases 2, 5, 7 */
73571 err = vma_adjust(prev, prev->vm_start,
73572 end, prev->vm_pgoff, NULL);
73573 +
73574 +#ifdef CONFIG_PAX_SEGMEXEC
73575 + if (!err && prev_m)
73576 + err = vma_adjust(prev_m, prev_m->vm_start,
73577 + end_m, prev_m->vm_pgoff, NULL);
73578 +#endif
73579 +
73580 + }
73581 if (err)
73582 return NULL;
73583 khugepaged_enter_vma_merge(prev);
73584 @@ -826,12 +891,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
73585 mpol_equal(policy, vma_policy(next)) &&
73586 can_vma_merge_before(next, vm_flags,
73587 anon_vma, file, pgoff+pglen)) {
73588 - if (prev && addr < prev->vm_end) /* case 4 */
73589 + if (prev && addr < prev->vm_end) { /* case 4 */
73590 err = vma_adjust(prev, prev->vm_start,
73591 addr, prev->vm_pgoff, NULL);
73592 - else /* cases 3, 8 */
73593 +
73594 +#ifdef CONFIG_PAX_SEGMEXEC
73595 + if (!err && prev_m)
73596 + err = vma_adjust(prev_m, prev_m->vm_start,
73597 + addr_m, prev_m->vm_pgoff, NULL);
73598 +#endif
73599 +
73600 + } else { /* cases 3, 8 */
73601 err = vma_adjust(area, addr, next->vm_end,
73602 next->vm_pgoff - pglen, NULL);
73603 +
73604 +#ifdef CONFIG_PAX_SEGMEXEC
73605 + if (!err && area_m)
73606 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
73607 + next_m->vm_pgoff - pglen, NULL);
73608 +#endif
73609 +
73610 + }
73611 if (err)
73612 return NULL;
73613 khugepaged_enter_vma_merge(area);
73614 @@ -940,16 +1020,13 @@ none:
73615 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
73616 struct file *file, long pages)
73617 {
73618 - const unsigned long stack_flags
73619 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
73620 -
73621 mm->total_vm += pages;
73622
73623 if (file) {
73624 mm->shared_vm += pages;
73625 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
73626 mm->exec_vm += pages;
73627 - } else if (flags & stack_flags)
73628 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
73629 mm->stack_vm += pages;
73630 if (flags & (VM_RESERVED|VM_IO))
73631 mm->reserved_vm += pages;
73632 @@ -987,7 +1064,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73633 * (the exception is when the underlying filesystem is noexec
73634 * mounted, in which case we dont add PROT_EXEC.)
73635 */
73636 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
73637 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
73638 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
73639 prot |= PROT_EXEC;
73640
73641 @@ -1013,7 +1090,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73642 /* Obtain the address to map to. we verify (or select) it and ensure
73643 * that it represents a valid section of the address space.
73644 */
73645 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
73646 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
73647 if (addr & ~PAGE_MASK)
73648 return addr;
73649
73650 @@ -1024,6 +1101,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73651 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
73652 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
73653
73654 +#ifdef CONFIG_PAX_MPROTECT
73655 + if (mm->pax_flags & MF_PAX_MPROTECT) {
73656 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
73657 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
73658 + gr_log_rwxmmap(file);
73659 +
73660 +#ifdef CONFIG_PAX_EMUPLT
73661 + vm_flags &= ~VM_EXEC;
73662 +#else
73663 + return -EPERM;
73664 +#endif
73665 +
73666 + }
73667 +
73668 + if (!(vm_flags & VM_EXEC))
73669 + vm_flags &= ~VM_MAYEXEC;
73670 +#else
73671 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
73672 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
73673 +#endif
73674 + else
73675 + vm_flags &= ~VM_MAYWRITE;
73676 + }
73677 +#endif
73678 +
73679 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
73680 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
73681 + vm_flags &= ~VM_PAGEEXEC;
73682 +#endif
73683 +
73684 if (flags & MAP_LOCKED)
73685 if (!can_do_mlock())
73686 return -EPERM;
73687 @@ -1035,6 +1142,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73688 locked += mm->locked_vm;
73689 lock_limit = rlimit(RLIMIT_MEMLOCK);
73690 lock_limit >>= PAGE_SHIFT;
73691 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
73692 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
73693 return -EAGAIN;
73694 }
73695 @@ -1101,6 +1209,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73696 }
73697 }
73698
73699 + if (!gr_acl_handle_mmap(file, prot))
73700 + return -EACCES;
73701 +
73702 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
73703 }
73704
73705 @@ -1177,7 +1288,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
73706 vm_flags_t vm_flags = vma->vm_flags;
73707
73708 /* If it was private or non-writable, the write bit is already clear */
73709 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
73710 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
73711 return 0;
73712
73713 /* The backer wishes to know when pages are first written to? */
73714 @@ -1226,14 +1337,24 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
73715 unsigned long charged = 0;
73716 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
73717
73718 +#ifdef CONFIG_PAX_SEGMEXEC
73719 + struct vm_area_struct *vma_m = NULL;
73720 +#endif
73721 +
73722 + /*
73723 + * mm->mmap_sem is required to protect against another thread
73724 + * changing the mappings in case we sleep.
73725 + */
73726 + verify_mm_writelocked(mm);
73727 +
73728 /* Clear old maps */
73729 error = -ENOMEM;
73730 -munmap_back:
73731 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73732 if (vma && vma->vm_start < addr + len) {
73733 if (do_munmap(mm, addr, len))
73734 return -ENOMEM;
73735 - goto munmap_back;
73736 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73737 + BUG_ON(vma && vma->vm_start < addr + len);
73738 }
73739
73740 /* Check against address space limit. */
73741 @@ -1282,6 +1403,16 @@ munmap_back:
73742 goto unacct_error;
73743 }
73744
73745 +#ifdef CONFIG_PAX_SEGMEXEC
73746 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
73747 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73748 + if (!vma_m) {
73749 + error = -ENOMEM;
73750 + goto free_vma;
73751 + }
73752 + }
73753 +#endif
73754 +
73755 vma->vm_mm = mm;
73756 vma->vm_start = addr;
73757 vma->vm_end = addr + len;
73758 @@ -1306,6 +1437,19 @@ munmap_back:
73759 error = file->f_op->mmap(file, vma);
73760 if (error)
73761 goto unmap_and_free_vma;
73762 +
73763 +#ifdef CONFIG_PAX_SEGMEXEC
73764 + if (vma_m && (vm_flags & VM_EXECUTABLE))
73765 + added_exe_file_vma(mm);
73766 +#endif
73767 +
73768 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
73769 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
73770 + vma->vm_flags |= VM_PAGEEXEC;
73771 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
73772 + }
73773 +#endif
73774 +
73775 if (vm_flags & VM_EXECUTABLE)
73776 added_exe_file_vma(mm);
73777
73778 @@ -1343,6 +1487,11 @@ munmap_back:
73779 vma_link(mm, vma, prev, rb_link, rb_parent);
73780 file = vma->vm_file;
73781
73782 +#ifdef CONFIG_PAX_SEGMEXEC
73783 + if (vma_m)
73784 + BUG_ON(pax_mirror_vma(vma_m, vma));
73785 +#endif
73786 +
73787 /* Once vma denies write, undo our temporary denial count */
73788 if (correct_wcount)
73789 atomic_inc(&inode->i_writecount);
73790 @@ -1350,6 +1499,7 @@ out:
73791 perf_event_mmap(vma);
73792
73793 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
73794 + track_exec_limit(mm, addr, addr + len, vm_flags);
73795 if (vm_flags & VM_LOCKED) {
73796 if (!mlock_vma_pages_range(vma, addr, addr + len))
73797 mm->locked_vm += (len >> PAGE_SHIFT);
73798 @@ -1371,6 +1521,12 @@ unmap_and_free_vma:
73799 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
73800 charged = 0;
73801 free_vma:
73802 +
73803 +#ifdef CONFIG_PAX_SEGMEXEC
73804 + if (vma_m)
73805 + kmem_cache_free(vm_area_cachep, vma_m);
73806 +#endif
73807 +
73808 kmem_cache_free(vm_area_cachep, vma);
73809 unacct_error:
73810 if (charged)
73811 @@ -1378,6 +1534,44 @@ unacct_error:
73812 return error;
73813 }
73814
73815 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
73816 +{
73817 + if (!vma) {
73818 +#ifdef CONFIG_STACK_GROWSUP
73819 + if (addr > sysctl_heap_stack_gap)
73820 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
73821 + else
73822 + vma = find_vma(current->mm, 0);
73823 + if (vma && (vma->vm_flags & VM_GROWSUP))
73824 + return false;
73825 +#endif
73826 + return true;
73827 + }
73828 +
73829 + if (addr + len > vma->vm_start)
73830 + return false;
73831 +
73832 + if (vma->vm_flags & VM_GROWSDOWN)
73833 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
73834 +#ifdef CONFIG_STACK_GROWSUP
73835 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
73836 + return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
73837 +#endif
73838 +
73839 + return true;
73840 +}
73841 +
73842 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
73843 +{
73844 + if (vma->vm_start < len)
73845 + return -ENOMEM;
73846 + if (!(vma->vm_flags & VM_GROWSDOWN))
73847 + return vma->vm_start - len;
73848 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
73849 + return vma->vm_start - len - sysctl_heap_stack_gap;
73850 + return -ENOMEM;
73851 +}
73852 +
73853 /* Get an address range which is currently unmapped.
73854 * For shmat() with addr=0.
73855 *
73856 @@ -1404,18 +1598,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
73857 if (flags & MAP_FIXED)
73858 return addr;
73859
73860 +#ifdef CONFIG_PAX_RANDMMAP
73861 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
73862 +#endif
73863 +
73864 if (addr) {
73865 addr = PAGE_ALIGN(addr);
73866 - vma = find_vma(mm, addr);
73867 - if (TASK_SIZE - len >= addr &&
73868 - (!vma || addr + len <= vma->vm_start))
73869 - return addr;
73870 + if (TASK_SIZE - len >= addr) {
73871 + vma = find_vma(mm, addr);
73872 + if (check_heap_stack_gap(vma, addr, len))
73873 + return addr;
73874 + }
73875 }
73876 if (len > mm->cached_hole_size) {
73877 - start_addr = addr = mm->free_area_cache;
73878 + start_addr = addr = mm->free_area_cache;
73879 } else {
73880 - start_addr = addr = TASK_UNMAPPED_BASE;
73881 - mm->cached_hole_size = 0;
73882 + start_addr = addr = mm->mmap_base;
73883 + mm->cached_hole_size = 0;
73884 }
73885
73886 full_search:
73887 @@ -1426,34 +1625,40 @@ full_search:
73888 * Start a new search - just in case we missed
73889 * some holes.
73890 */
73891 - if (start_addr != TASK_UNMAPPED_BASE) {
73892 - addr = TASK_UNMAPPED_BASE;
73893 - start_addr = addr;
73894 + if (start_addr != mm->mmap_base) {
73895 + start_addr = addr = mm->mmap_base;
73896 mm->cached_hole_size = 0;
73897 goto full_search;
73898 }
73899 return -ENOMEM;
73900 }
73901 - if (!vma || addr + len <= vma->vm_start) {
73902 - /*
73903 - * Remember the place where we stopped the search:
73904 - */
73905 - mm->free_area_cache = addr + len;
73906 - return addr;
73907 - }
73908 + if (check_heap_stack_gap(vma, addr, len))
73909 + break;
73910 if (addr + mm->cached_hole_size < vma->vm_start)
73911 mm->cached_hole_size = vma->vm_start - addr;
73912 addr = vma->vm_end;
73913 }
73914 +
73915 + /*
73916 + * Remember the place where we stopped the search:
73917 + */
73918 + mm->free_area_cache = addr + len;
73919 + return addr;
73920 }
73921 #endif
73922
73923 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
73924 {
73925 +
73926 +#ifdef CONFIG_PAX_SEGMEXEC
73927 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
73928 + return;
73929 +#endif
73930 +
73931 /*
73932 * Is this a new hole at the lowest possible address?
73933 */
73934 - if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
73935 + if (addr >= mm->mmap_base && addr < mm->free_area_cache)
73936 mm->free_area_cache = addr;
73937 }
73938
73939 @@ -1469,7 +1674,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
73940 {
73941 struct vm_area_struct *vma;
73942 struct mm_struct *mm = current->mm;
73943 - unsigned long addr = addr0, start_addr;
73944 + unsigned long base = mm->mmap_base, addr = addr0, start_addr;
73945
73946 /* requested length too big for entire address space */
73947 if (len > TASK_SIZE)
73948 @@ -1478,13 +1683,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
73949 if (flags & MAP_FIXED)
73950 return addr;
73951
73952 +#ifdef CONFIG_PAX_RANDMMAP
73953 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
73954 +#endif
73955 +
73956 /* requesting a specific address */
73957 if (addr) {
73958 addr = PAGE_ALIGN(addr);
73959 - vma = find_vma(mm, addr);
73960 - if (TASK_SIZE - len >= addr &&
73961 - (!vma || addr + len <= vma->vm_start))
73962 - return addr;
73963 + if (TASK_SIZE - len >= addr) {
73964 + vma = find_vma(mm, addr);
73965 + if (check_heap_stack_gap(vma, addr, len))
73966 + return addr;
73967 + }
73968 }
73969
73970 /* check if free_area_cache is useful for us */
73971 @@ -1508,7 +1718,7 @@ try_again:
73972 * return with success:
73973 */
73974 vma = find_vma(mm, addr);
73975 - if (!vma || addr+len <= vma->vm_start)
73976 + if (check_heap_stack_gap(vma, addr, len))
73977 /* remember the address as a hint for next time */
73978 return (mm->free_area_cache = addr);
73979
73980 @@ -1517,8 +1727,8 @@ try_again:
73981 mm->cached_hole_size = vma->vm_start - addr;
73982
73983 /* try just below the current vma->vm_start */
73984 - addr = vma->vm_start-len;
73985 - } while (len < vma->vm_start);
73986 + addr = skip_heap_stack_gap(vma, len);
73987 + } while (!IS_ERR_VALUE(addr));
73988
73989 fail:
73990 /*
73991 @@ -1541,13 +1751,21 @@ fail:
73992 * can happen with large stack limits and large mmap()
73993 * allocations.
73994 */
73995 + mm->mmap_base = TASK_UNMAPPED_BASE;
73996 +
73997 +#ifdef CONFIG_PAX_RANDMMAP
73998 + if (mm->pax_flags & MF_PAX_RANDMMAP)
73999 + mm->mmap_base += mm->delta_mmap;
74000 +#endif
74001 +
74002 + mm->free_area_cache = mm->mmap_base;
74003 mm->cached_hole_size = ~0UL;
74004 - mm->free_area_cache = TASK_UNMAPPED_BASE;
74005 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
74006 /*
74007 * Restore the topdown base:
74008 */
74009 - mm->free_area_cache = mm->mmap_base;
74010 + mm->mmap_base = base;
74011 + mm->free_area_cache = base;
74012 mm->cached_hole_size = ~0UL;
74013
74014 return addr;
74015 @@ -1556,6 +1774,12 @@ fail:
74016
74017 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
74018 {
74019 +
74020 +#ifdef CONFIG_PAX_SEGMEXEC
74021 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
74022 + return;
74023 +#endif
74024 +
74025 /*
74026 * Is this a new hole at the highest possible address?
74027 */
74028 @@ -1563,8 +1787,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
74029 mm->free_area_cache = addr;
74030
74031 /* dont allow allocations above current base */
74032 - if (mm->free_area_cache > mm->mmap_base)
74033 + if (mm->free_area_cache > mm->mmap_base) {
74034 mm->free_area_cache = mm->mmap_base;
74035 + mm->cached_hole_size = ~0UL;
74036 + }
74037 }
74038
74039 unsigned long
74040 @@ -1663,6 +1889,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
74041 return vma;
74042 }
74043
74044 +#ifdef CONFIG_PAX_SEGMEXEC
74045 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
74046 +{
74047 + struct vm_area_struct *vma_m;
74048 +
74049 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
74050 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
74051 + BUG_ON(vma->vm_mirror);
74052 + return NULL;
74053 + }
74054 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
74055 + vma_m = vma->vm_mirror;
74056 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
74057 + BUG_ON(vma->vm_file != vma_m->vm_file);
74058 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
74059 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
74060 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
74061 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
74062 + return vma_m;
74063 +}
74064 +#endif
74065 +
74066 /*
74067 * Verify that the stack growth is acceptable and
74068 * update accounting. This is shared with both the
74069 @@ -1679,6 +1927,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
74070 return -ENOMEM;
74071
74072 /* Stack limit test */
74073 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
74074 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
74075 return -ENOMEM;
74076
74077 @@ -1689,6 +1938,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
74078 locked = mm->locked_vm + grow;
74079 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
74080 limit >>= PAGE_SHIFT;
74081 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
74082 if (locked > limit && !capable(CAP_IPC_LOCK))
74083 return -ENOMEM;
74084 }
74085 @@ -1718,37 +1968,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
74086 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
74087 * vma is the last one with address > vma->vm_end. Have to extend vma.
74088 */
74089 +#ifndef CONFIG_IA64
74090 +static
74091 +#endif
74092 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
74093 {
74094 int error;
74095 + bool locknext;
74096
74097 if (!(vma->vm_flags & VM_GROWSUP))
74098 return -EFAULT;
74099
74100 + /* Also guard against wrapping around to address 0. */
74101 + if (address < PAGE_ALIGN(address+1))
74102 + address = PAGE_ALIGN(address+1);
74103 + else
74104 + return -ENOMEM;
74105 +
74106 /*
74107 * We must make sure the anon_vma is allocated
74108 * so that the anon_vma locking is not a noop.
74109 */
74110 if (unlikely(anon_vma_prepare(vma)))
74111 return -ENOMEM;
74112 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
74113 + if (locknext && anon_vma_prepare(vma->vm_next))
74114 + return -ENOMEM;
74115 vma_lock_anon_vma(vma);
74116 + if (locknext)
74117 + vma_lock_anon_vma(vma->vm_next);
74118
74119 /*
74120 * vma->vm_start/vm_end cannot change under us because the caller
74121 * is required to hold the mmap_sem in read mode. We need the
74122 - * anon_vma lock to serialize against concurrent expand_stacks.
74123 - * Also guard against wrapping around to address 0.
74124 + * anon_vma locks to serialize against concurrent expand_stacks
74125 + * and expand_upwards.
74126 */
74127 - if (address < PAGE_ALIGN(address+4))
74128 - address = PAGE_ALIGN(address+4);
74129 - else {
74130 - vma_unlock_anon_vma(vma);
74131 - return -ENOMEM;
74132 - }
74133 error = 0;
74134
74135 /* Somebody else might have raced and expanded it already */
74136 - if (address > vma->vm_end) {
74137 + 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)
74138 + error = -ENOMEM;
74139 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
74140 unsigned long size, grow;
74141
74142 size = address - vma->vm_start;
74143 @@ -1763,6 +2024,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
74144 }
74145 }
74146 }
74147 + if (locknext)
74148 + vma_unlock_anon_vma(vma->vm_next);
74149 vma_unlock_anon_vma(vma);
74150 khugepaged_enter_vma_merge(vma);
74151 return error;
74152 @@ -1776,6 +2039,8 @@ int expand_downwards(struct vm_area_struct *vma,
74153 unsigned long address)
74154 {
74155 int error;
74156 + bool lockprev = false;
74157 + struct vm_area_struct *prev;
74158
74159 /*
74160 * We must make sure the anon_vma is allocated
74161 @@ -1789,6 +2054,15 @@ int expand_downwards(struct vm_area_struct *vma,
74162 if (error)
74163 return error;
74164
74165 + prev = vma->vm_prev;
74166 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
74167 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
74168 +#endif
74169 + if (lockprev && anon_vma_prepare(prev))
74170 + return -ENOMEM;
74171 + if (lockprev)
74172 + vma_lock_anon_vma(prev);
74173 +
74174 vma_lock_anon_vma(vma);
74175
74176 /*
74177 @@ -1798,9 +2072,17 @@ int expand_downwards(struct vm_area_struct *vma,
74178 */
74179
74180 /* Somebody else might have raced and expanded it already */
74181 - if (address < vma->vm_start) {
74182 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
74183 + error = -ENOMEM;
74184 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
74185 unsigned long size, grow;
74186
74187 +#ifdef CONFIG_PAX_SEGMEXEC
74188 + struct vm_area_struct *vma_m;
74189 +
74190 + vma_m = pax_find_mirror_vma(vma);
74191 +#endif
74192 +
74193 size = vma->vm_end - address;
74194 grow = (vma->vm_start - address) >> PAGE_SHIFT;
74195
74196 @@ -1810,11 +2092,22 @@ int expand_downwards(struct vm_area_struct *vma,
74197 if (!error) {
74198 vma->vm_start = address;
74199 vma->vm_pgoff -= grow;
74200 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
74201 +
74202 +#ifdef CONFIG_PAX_SEGMEXEC
74203 + if (vma_m) {
74204 + vma_m->vm_start -= grow << PAGE_SHIFT;
74205 + vma_m->vm_pgoff -= grow;
74206 + }
74207 +#endif
74208 +
74209 perf_event_mmap(vma);
74210 }
74211 }
74212 }
74213 vma_unlock_anon_vma(vma);
74214 + if (lockprev)
74215 + vma_unlock_anon_vma(prev);
74216 khugepaged_enter_vma_merge(vma);
74217 return error;
74218 }
74219 @@ -1886,6 +2179,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
74220 do {
74221 long nrpages = vma_pages(vma);
74222
74223 +#ifdef CONFIG_PAX_SEGMEXEC
74224 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
74225 + vma = remove_vma(vma);
74226 + continue;
74227 + }
74228 +#endif
74229 +
74230 if (vma->vm_flags & VM_ACCOUNT)
74231 nr_accounted += nrpages;
74232 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
74233 @@ -1931,6 +2231,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
74234 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
74235 vma->vm_prev = NULL;
74236 do {
74237 +
74238 +#ifdef CONFIG_PAX_SEGMEXEC
74239 + if (vma->vm_mirror) {
74240 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
74241 + vma->vm_mirror->vm_mirror = NULL;
74242 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
74243 + vma->vm_mirror = NULL;
74244 + }
74245 +#endif
74246 +
74247 rb_erase(&vma->vm_rb, &mm->mm_rb);
74248 mm->map_count--;
74249 tail_vma = vma;
74250 @@ -1959,14 +2269,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
74251 struct vm_area_struct *new;
74252 int err = -ENOMEM;
74253
74254 +#ifdef CONFIG_PAX_SEGMEXEC
74255 + struct vm_area_struct *vma_m, *new_m = NULL;
74256 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
74257 +#endif
74258 +
74259 if (is_vm_hugetlb_page(vma) && (addr &
74260 ~(huge_page_mask(hstate_vma(vma)))))
74261 return -EINVAL;
74262
74263 +#ifdef CONFIG_PAX_SEGMEXEC
74264 + vma_m = pax_find_mirror_vma(vma);
74265 +#endif
74266 +
74267 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
74268 if (!new)
74269 goto out_err;
74270
74271 +#ifdef CONFIG_PAX_SEGMEXEC
74272 + if (vma_m) {
74273 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
74274 + if (!new_m) {
74275 + kmem_cache_free(vm_area_cachep, new);
74276 + goto out_err;
74277 + }
74278 + }
74279 +#endif
74280 +
74281 /* most fields are the same, copy all, and then fixup */
74282 *new = *vma;
74283
74284 @@ -1979,6 +2308,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
74285 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
74286 }
74287
74288 +#ifdef CONFIG_PAX_SEGMEXEC
74289 + if (vma_m) {
74290 + *new_m = *vma_m;
74291 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
74292 + new_m->vm_mirror = new;
74293 + new->vm_mirror = new_m;
74294 +
74295 + if (new_below)
74296 + new_m->vm_end = addr_m;
74297 + else {
74298 + new_m->vm_start = addr_m;
74299 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
74300 + }
74301 + }
74302 +#endif
74303 +
74304 pol = mpol_dup(vma_policy(vma));
74305 if (IS_ERR(pol)) {
74306 err = PTR_ERR(pol);
74307 @@ -2004,6 +2349,42 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
74308 else
74309 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
74310
74311 +#ifdef CONFIG_PAX_SEGMEXEC
74312 + if (!err && vma_m) {
74313 + if (anon_vma_clone(new_m, vma_m))
74314 + goto out_free_mpol;
74315 +
74316 + mpol_get(pol);
74317 + vma_set_policy(new_m, pol);
74318 +
74319 + if (new_m->vm_file) {
74320 + get_file(new_m->vm_file);
74321 + if (vma_m->vm_flags & VM_EXECUTABLE)
74322 + added_exe_file_vma(mm);
74323 + }
74324 +
74325 + if (new_m->vm_ops && new_m->vm_ops->open)
74326 + new_m->vm_ops->open(new_m);
74327 +
74328 + if (new_below)
74329 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
74330 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
74331 + else
74332 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
74333 +
74334 + if (err) {
74335 + if (new_m->vm_ops && new_m->vm_ops->close)
74336 + new_m->vm_ops->close(new_m);
74337 + if (new_m->vm_file) {
74338 + if (vma_m->vm_flags & VM_EXECUTABLE)
74339 + removed_exe_file_vma(mm);
74340 + fput(new_m->vm_file);
74341 + }
74342 + mpol_put(pol);
74343 + }
74344 + }
74345 +#endif
74346 +
74347 /* Success. */
74348 if (!err)
74349 return 0;
74350 @@ -2016,10 +2397,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
74351 removed_exe_file_vma(mm);
74352 fput(new->vm_file);
74353 }
74354 - unlink_anon_vmas(new);
74355 out_free_mpol:
74356 mpol_put(pol);
74357 out_free_vma:
74358 +
74359 +#ifdef CONFIG_PAX_SEGMEXEC
74360 + if (new_m) {
74361 + unlink_anon_vmas(new_m);
74362 + kmem_cache_free(vm_area_cachep, new_m);
74363 + }
74364 +#endif
74365 +
74366 + unlink_anon_vmas(new);
74367 kmem_cache_free(vm_area_cachep, new);
74368 out_err:
74369 return err;
74370 @@ -2032,6 +2421,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
74371 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
74372 unsigned long addr, int new_below)
74373 {
74374 +
74375 +#ifdef CONFIG_PAX_SEGMEXEC
74376 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
74377 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
74378 + if (mm->map_count >= sysctl_max_map_count-1)
74379 + return -ENOMEM;
74380 + } else
74381 +#endif
74382 +
74383 if (mm->map_count >= sysctl_max_map_count)
74384 return -ENOMEM;
74385
74386 @@ -2043,11 +2441,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
74387 * work. This now handles partial unmappings.
74388 * Jeremy Fitzhardinge <jeremy@goop.org>
74389 */
74390 +#ifdef CONFIG_PAX_SEGMEXEC
74391 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
74392 {
74393 + int ret = __do_munmap(mm, start, len);
74394 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
74395 + return ret;
74396 +
74397 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
74398 +}
74399 +
74400 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
74401 +#else
74402 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
74403 +#endif
74404 +{
74405 unsigned long end;
74406 struct vm_area_struct *vma, *prev, *last;
74407
74408 + /*
74409 + * mm->mmap_sem is required to protect against another thread
74410 + * changing the mappings in case we sleep.
74411 + */
74412 + verify_mm_writelocked(mm);
74413 +
74414 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
74415 return -EINVAL;
74416
74417 @@ -2122,6 +2539,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
74418 /* Fix up all other VM information */
74419 remove_vma_list(mm, vma);
74420
74421 + track_exec_limit(mm, start, end, 0UL);
74422 +
74423 return 0;
74424 }
74425
74426 @@ -2130,6 +2549,13 @@ int vm_munmap(unsigned long start, size_t len)
74427 int ret;
74428 struct mm_struct *mm = current->mm;
74429
74430 +
74431 +#ifdef CONFIG_PAX_SEGMEXEC
74432 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
74433 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
74434 + return -EINVAL;
74435 +#endif
74436 +
74437 down_write(&mm->mmap_sem);
74438 ret = do_munmap(mm, start, len);
74439 up_write(&mm->mmap_sem);
74440 @@ -2143,16 +2569,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
74441 return vm_munmap(addr, len);
74442 }
74443
74444 -static inline void verify_mm_writelocked(struct mm_struct *mm)
74445 -{
74446 -#ifdef CONFIG_DEBUG_VM
74447 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
74448 - WARN_ON(1);
74449 - up_read(&mm->mmap_sem);
74450 - }
74451 -#endif
74452 -}
74453 -
74454 /*
74455 * this is really a simplified "do_mmap". it only handles
74456 * anonymous maps. eventually we may be able to do some
74457 @@ -2166,6 +2582,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
74458 struct rb_node ** rb_link, * rb_parent;
74459 pgoff_t pgoff = addr >> PAGE_SHIFT;
74460 int error;
74461 + unsigned long charged;
74462
74463 len = PAGE_ALIGN(len);
74464 if (!len)
74465 @@ -2173,16 +2590,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
74466
74467 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
74468
74469 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
74470 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
74471 + flags &= ~VM_EXEC;
74472 +
74473 +#ifdef CONFIG_PAX_MPROTECT
74474 + if (mm->pax_flags & MF_PAX_MPROTECT)
74475 + flags &= ~VM_MAYEXEC;
74476 +#endif
74477 +
74478 + }
74479 +#endif
74480 +
74481 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
74482 if (error & ~PAGE_MASK)
74483 return error;
74484
74485 + charged = len >> PAGE_SHIFT;
74486 +
74487 /*
74488 * mlock MCL_FUTURE?
74489 */
74490 if (mm->def_flags & VM_LOCKED) {
74491 unsigned long locked, lock_limit;
74492 - locked = len >> PAGE_SHIFT;
74493 + locked = charged;
74494 locked += mm->locked_vm;
74495 lock_limit = rlimit(RLIMIT_MEMLOCK);
74496 lock_limit >>= PAGE_SHIFT;
74497 @@ -2199,22 +2630,22 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
74498 /*
74499 * Clear old maps. this also does some error checking for us
74500 */
74501 - munmap_back:
74502 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
74503 if (vma && vma->vm_start < addr + len) {
74504 if (do_munmap(mm, addr, len))
74505 return -ENOMEM;
74506 - goto munmap_back;
74507 - }
74508 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
74509 + BUG_ON(vma && vma->vm_start < addr + len);
74510 + }
74511
74512 /* Check against address space limits *after* clearing old maps... */
74513 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
74514 + if (!may_expand_vm(mm, charged))
74515 return -ENOMEM;
74516
74517 if (mm->map_count > sysctl_max_map_count)
74518 return -ENOMEM;
74519
74520 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
74521 + if (security_vm_enough_memory_mm(mm, charged))
74522 return -ENOMEM;
74523
74524 /* Can we just expand an old private anonymous mapping? */
74525 @@ -2228,7 +2659,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
74526 */
74527 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
74528 if (!vma) {
74529 - vm_unacct_memory(len >> PAGE_SHIFT);
74530 + vm_unacct_memory(charged);
74531 return -ENOMEM;
74532 }
74533
74534 @@ -2242,11 +2673,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
74535 vma_link(mm, vma, prev, rb_link, rb_parent);
74536 out:
74537 perf_event_mmap(vma);
74538 - mm->total_vm += len >> PAGE_SHIFT;
74539 + mm->total_vm += charged;
74540 if (flags & VM_LOCKED) {
74541 if (!mlock_vma_pages_range(vma, addr, addr + len))
74542 - mm->locked_vm += (len >> PAGE_SHIFT);
74543 + mm->locked_vm += charged;
74544 }
74545 + track_exec_limit(mm, addr, addr + len, flags);
74546 return addr;
74547 }
74548
74549 @@ -2304,6 +2736,7 @@ void exit_mmap(struct mm_struct *mm)
74550 while (vma) {
74551 if (vma->vm_flags & VM_ACCOUNT)
74552 nr_accounted += vma_pages(vma);
74553 + vma->vm_mirror = NULL;
74554 vma = remove_vma(vma);
74555 }
74556 vm_unacct_memory(nr_accounted);
74557 @@ -2320,6 +2753,13 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
74558 struct vm_area_struct * __vma, * prev;
74559 struct rb_node ** rb_link, * rb_parent;
74560
74561 +#ifdef CONFIG_PAX_SEGMEXEC
74562 + struct vm_area_struct *vma_m = NULL;
74563 +#endif
74564 +
74565 + if (security_mmap_addr(vma->vm_start))
74566 + return -EPERM;
74567 +
74568 /*
74569 * The vm_pgoff of a purely anonymous vma should be irrelevant
74570 * until its first write fault, when page's anon_vma and index
74571 @@ -2343,7 +2783,21 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
74572 security_vm_enough_memory_mm(mm, vma_pages(vma)))
74573 return -ENOMEM;
74574
74575 +#ifdef CONFIG_PAX_SEGMEXEC
74576 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
74577 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
74578 + if (!vma_m)
74579 + return -ENOMEM;
74580 + }
74581 +#endif
74582 +
74583 vma_link(mm, vma, prev, rb_link, rb_parent);
74584 +
74585 +#ifdef CONFIG_PAX_SEGMEXEC
74586 + if (vma_m)
74587 + BUG_ON(pax_mirror_vma(vma_m, vma));
74588 +#endif
74589 +
74590 return 0;
74591 }
74592
74593 @@ -2362,6 +2816,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
74594 struct mempolicy *pol;
74595 bool faulted_in_anon_vma = true;
74596
74597 + BUG_ON(vma->vm_mirror);
74598 +
74599 /*
74600 * If anonymous vma has not yet been faulted, update new pgoff
74601 * to match new location, to increase its chance of merging.
74602 @@ -2430,6 +2886,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
74603 return NULL;
74604 }
74605
74606 +#ifdef CONFIG_PAX_SEGMEXEC
74607 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
74608 +{
74609 + struct vm_area_struct *prev_m;
74610 + struct rb_node **rb_link_m, *rb_parent_m;
74611 + struct mempolicy *pol_m;
74612 +
74613 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
74614 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
74615 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
74616 + *vma_m = *vma;
74617 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
74618 + if (anon_vma_clone(vma_m, vma))
74619 + return -ENOMEM;
74620 + pol_m = vma_policy(vma_m);
74621 + mpol_get(pol_m);
74622 + vma_set_policy(vma_m, pol_m);
74623 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
74624 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
74625 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
74626 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
74627 + if (vma_m->vm_file)
74628 + get_file(vma_m->vm_file);
74629 + if (vma_m->vm_ops && vma_m->vm_ops->open)
74630 + vma_m->vm_ops->open(vma_m);
74631 + find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
74632 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
74633 + vma_m->vm_mirror = vma;
74634 + vma->vm_mirror = vma_m;
74635 + return 0;
74636 +}
74637 +#endif
74638 +
74639 /*
74640 * Return true if the calling process may expand its vm space by the passed
74641 * number of pages
74642 @@ -2441,6 +2930,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
74643
74644 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
74645
74646 +#ifdef CONFIG_PAX_RANDMMAP
74647 + if (mm->pax_flags & MF_PAX_RANDMMAP)
74648 + cur -= mm->brk_gap;
74649 +#endif
74650 +
74651 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
74652 if (cur + npages > lim)
74653 return 0;
74654 return 1;
74655 @@ -2511,6 +3006,22 @@ int install_special_mapping(struct mm_struct *mm,
74656 vma->vm_start = addr;
74657 vma->vm_end = addr + len;
74658
74659 +#ifdef CONFIG_PAX_MPROTECT
74660 + if (mm->pax_flags & MF_PAX_MPROTECT) {
74661 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
74662 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
74663 + return -EPERM;
74664 + if (!(vm_flags & VM_EXEC))
74665 + vm_flags &= ~VM_MAYEXEC;
74666 +#else
74667 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
74668 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
74669 +#endif
74670 + else
74671 + vm_flags &= ~VM_MAYWRITE;
74672 + }
74673 +#endif
74674 +
74675 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
74676 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
74677
74678 diff --git a/mm/mprotect.c b/mm/mprotect.c
74679 index a409926..8b32e6d 100644
74680 --- a/mm/mprotect.c
74681 +++ b/mm/mprotect.c
74682 @@ -23,10 +23,17 @@
74683 #include <linux/mmu_notifier.h>
74684 #include <linux/migrate.h>
74685 #include <linux/perf_event.h>
74686 +
74687 +#ifdef CONFIG_PAX_MPROTECT
74688 +#include <linux/elf.h>
74689 +#include <linux/binfmts.h>
74690 +#endif
74691 +
74692 #include <asm/uaccess.h>
74693 #include <asm/pgtable.h>
74694 #include <asm/cacheflush.h>
74695 #include <asm/tlbflush.h>
74696 +#include <asm/mmu_context.h>
74697
74698 #ifndef pgprot_modify
74699 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
74700 @@ -141,6 +148,48 @@ static void change_protection(struct vm_area_struct *vma,
74701 flush_tlb_range(vma, start, end);
74702 }
74703
74704 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
74705 +/* called while holding the mmap semaphor for writing except stack expansion */
74706 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
74707 +{
74708 + unsigned long oldlimit, newlimit = 0UL;
74709 +
74710 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
74711 + return;
74712 +
74713 + spin_lock(&mm->page_table_lock);
74714 + oldlimit = mm->context.user_cs_limit;
74715 + if ((prot & VM_EXEC) && oldlimit < end)
74716 + /* USER_CS limit moved up */
74717 + newlimit = end;
74718 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
74719 + /* USER_CS limit moved down */
74720 + newlimit = start;
74721 +
74722 + if (newlimit) {
74723 + mm->context.user_cs_limit = newlimit;
74724 +
74725 +#ifdef CONFIG_SMP
74726 + wmb();
74727 + cpus_clear(mm->context.cpu_user_cs_mask);
74728 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
74729 +#endif
74730 +
74731 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
74732 + }
74733 + spin_unlock(&mm->page_table_lock);
74734 + if (newlimit == end) {
74735 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
74736 +
74737 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
74738 + if (is_vm_hugetlb_page(vma))
74739 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
74740 + else
74741 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
74742 + }
74743 +}
74744 +#endif
74745 +
74746 int
74747 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
74748 unsigned long start, unsigned long end, unsigned long newflags)
74749 @@ -153,11 +202,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
74750 int error;
74751 int dirty_accountable = 0;
74752
74753 +#ifdef CONFIG_PAX_SEGMEXEC
74754 + struct vm_area_struct *vma_m = NULL;
74755 + unsigned long start_m, end_m;
74756 +
74757 + start_m = start + SEGMEXEC_TASK_SIZE;
74758 + end_m = end + SEGMEXEC_TASK_SIZE;
74759 +#endif
74760 +
74761 if (newflags == oldflags) {
74762 *pprev = vma;
74763 return 0;
74764 }
74765
74766 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
74767 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
74768 +
74769 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
74770 + return -ENOMEM;
74771 +
74772 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
74773 + return -ENOMEM;
74774 + }
74775 +
74776 /*
74777 * If we make a private mapping writable we increase our commit;
74778 * but (without finer accounting) cannot reduce our commit if we
74779 @@ -174,6 +241,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
74780 }
74781 }
74782
74783 +#ifdef CONFIG_PAX_SEGMEXEC
74784 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
74785 + if (start != vma->vm_start) {
74786 + error = split_vma(mm, vma, start, 1);
74787 + if (error)
74788 + goto fail;
74789 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
74790 + *pprev = (*pprev)->vm_next;
74791 + }
74792 +
74793 + if (end != vma->vm_end) {
74794 + error = split_vma(mm, vma, end, 0);
74795 + if (error)
74796 + goto fail;
74797 + }
74798 +
74799 + if (pax_find_mirror_vma(vma)) {
74800 + error = __do_munmap(mm, start_m, end_m - start_m);
74801 + if (error)
74802 + goto fail;
74803 + } else {
74804 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
74805 + if (!vma_m) {
74806 + error = -ENOMEM;
74807 + goto fail;
74808 + }
74809 + vma->vm_flags = newflags;
74810 + error = pax_mirror_vma(vma_m, vma);
74811 + if (error) {
74812 + vma->vm_flags = oldflags;
74813 + goto fail;
74814 + }
74815 + }
74816 + }
74817 +#endif
74818 +
74819 /*
74820 * First try to merge with previous and/or next vma.
74821 */
74822 @@ -204,9 +307,21 @@ success:
74823 * vm_flags and vm_page_prot are protected by the mmap_sem
74824 * held in write mode.
74825 */
74826 +
74827 +#ifdef CONFIG_PAX_SEGMEXEC
74828 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
74829 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
74830 +#endif
74831 +
74832 vma->vm_flags = newflags;
74833 +
74834 +#ifdef CONFIG_PAX_MPROTECT
74835 + if (mm->binfmt && mm->binfmt->handle_mprotect)
74836 + mm->binfmt->handle_mprotect(vma, newflags);
74837 +#endif
74838 +
74839 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
74840 - vm_get_page_prot(newflags));
74841 + vm_get_page_prot(vma->vm_flags));
74842
74843 if (vma_wants_writenotify(vma)) {
74844 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
74845 @@ -248,6 +363,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74846 end = start + len;
74847 if (end <= start)
74848 return -ENOMEM;
74849 +
74850 +#ifdef CONFIG_PAX_SEGMEXEC
74851 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
74852 + if (end > SEGMEXEC_TASK_SIZE)
74853 + return -EINVAL;
74854 + } else
74855 +#endif
74856 +
74857 + if (end > TASK_SIZE)
74858 + return -EINVAL;
74859 +
74860 if (!arch_validate_prot(prot))
74861 return -EINVAL;
74862
74863 @@ -255,7 +381,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74864 /*
74865 * Does the application expect PROT_READ to imply PROT_EXEC:
74866 */
74867 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
74868 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
74869 prot |= PROT_EXEC;
74870
74871 vm_flags = calc_vm_prot_bits(prot);
74872 @@ -288,6 +414,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74873 if (start > vma->vm_start)
74874 prev = vma;
74875
74876 +#ifdef CONFIG_PAX_MPROTECT
74877 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
74878 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
74879 +#endif
74880 +
74881 for (nstart = start ; ; ) {
74882 unsigned long newflags;
74883
74884 @@ -297,6 +428,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74885
74886 /* newflags >> 4 shift VM_MAY% in place of VM_% */
74887 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
74888 + if (prot & (PROT_WRITE | PROT_EXEC))
74889 + gr_log_rwxmprotect(vma->vm_file);
74890 +
74891 + error = -EACCES;
74892 + goto out;
74893 + }
74894 +
74895 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
74896 error = -EACCES;
74897 goto out;
74898 }
74899 @@ -311,6 +450,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74900 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
74901 if (error)
74902 goto out;
74903 +
74904 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
74905 +
74906 nstart = tmp;
74907
74908 if (nstart < prev->vm_end)
74909 diff --git a/mm/mremap.c b/mm/mremap.c
74910 index cc06d0e..40b5d18 100644
74911 --- a/mm/mremap.c
74912 +++ b/mm/mremap.c
74913 @@ -106,6 +106,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
74914 continue;
74915 pte = ptep_get_and_clear(mm, old_addr, old_pte);
74916 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
74917 +
74918 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
74919 + if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
74920 + pte = pte_exprotect(pte);
74921 +#endif
74922 +
74923 set_pte_at(mm, new_addr, new_pte, pte);
74924 }
74925
74926 @@ -298,6 +304,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
74927 if (is_vm_hugetlb_page(vma))
74928 goto Einval;
74929
74930 +#ifdef CONFIG_PAX_SEGMEXEC
74931 + if (pax_find_mirror_vma(vma))
74932 + goto Einval;
74933 +#endif
74934 +
74935 /* We can't remap across vm area boundaries */
74936 if (old_len > vma->vm_end - addr)
74937 goto Efault;
74938 @@ -354,20 +365,25 @@ static unsigned long mremap_to(unsigned long addr,
74939 unsigned long ret = -EINVAL;
74940 unsigned long charged = 0;
74941 unsigned long map_flags;
74942 + unsigned long pax_task_size = TASK_SIZE;
74943
74944 if (new_addr & ~PAGE_MASK)
74945 goto out;
74946
74947 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
74948 +#ifdef CONFIG_PAX_SEGMEXEC
74949 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
74950 + pax_task_size = SEGMEXEC_TASK_SIZE;
74951 +#endif
74952 +
74953 + pax_task_size -= PAGE_SIZE;
74954 +
74955 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
74956 goto out;
74957
74958 /* Check if the location we're moving into overlaps the
74959 * old location at all, and fail if it does.
74960 */
74961 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
74962 - goto out;
74963 -
74964 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
74965 + if (addr + old_len > new_addr && new_addr + new_len > addr)
74966 goto out;
74967
74968 ret = do_munmap(mm, new_addr, new_len);
74969 @@ -435,6 +451,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74970 struct vm_area_struct *vma;
74971 unsigned long ret = -EINVAL;
74972 unsigned long charged = 0;
74973 + unsigned long pax_task_size = TASK_SIZE;
74974
74975 down_write(&current->mm->mmap_sem);
74976
74977 @@ -455,6 +472,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74978 if (!new_len)
74979 goto out;
74980
74981 +#ifdef CONFIG_PAX_SEGMEXEC
74982 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
74983 + pax_task_size = SEGMEXEC_TASK_SIZE;
74984 +#endif
74985 +
74986 + pax_task_size -= PAGE_SIZE;
74987 +
74988 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
74989 + old_len > pax_task_size || addr > pax_task_size-old_len)
74990 + goto out;
74991 +
74992 if (flags & MREMAP_FIXED) {
74993 if (flags & MREMAP_MAYMOVE)
74994 ret = mremap_to(addr, old_len, new_addr, new_len);
74995 @@ -503,6 +531,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74996 addr + new_len);
74997 }
74998 ret = addr;
74999 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
75000 goto out;
75001 }
75002 }
75003 @@ -526,7 +555,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
75004 goto out;
75005 }
75006
75007 + map_flags = vma->vm_flags;
75008 ret = move_vma(vma, addr, old_len, new_len, new_addr);
75009 + if (!(ret & ~PAGE_MASK)) {
75010 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
75011 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
75012 + }
75013 }
75014 out:
75015 if (ret & ~PAGE_MASK)
75016 diff --git a/mm/nommu.c b/mm/nommu.c
75017 index d4b0c10..ed421b5 100644
75018 --- a/mm/nommu.c
75019 +++ b/mm/nommu.c
75020 @@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
75021 int sysctl_overcommit_ratio = 50; /* default is 50% */
75022 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
75023 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
75024 -int heap_stack_gap = 0;
75025
75026 atomic_long_t mmap_pages_allocated;
75027
75028 @@ -827,15 +826,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
75029 EXPORT_SYMBOL(find_vma);
75030
75031 /*
75032 - * find a VMA
75033 - * - we don't extend stack VMAs under NOMMU conditions
75034 - */
75035 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
75036 -{
75037 - return find_vma(mm, addr);
75038 -}
75039 -
75040 -/*
75041 * expand a stack to a given address
75042 * - not supported under NOMMU conditions
75043 */
75044 @@ -1551,6 +1541,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
75045
75046 /* most fields are the same, copy all, and then fixup */
75047 *new = *vma;
75048 + INIT_LIST_HEAD(&new->anon_vma_chain);
75049 *region = *vma->vm_region;
75050 new->vm_region = region;
75051
75052 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
75053 index d2d8f54..be2a87c 100644
75054 --- a/mm/page_alloc.c
75055 +++ b/mm/page_alloc.c
75056 @@ -340,7 +340,7 @@ out:
75057 * This usage means that zero-order pages may not be compound.
75058 */
75059
75060 -static void free_compound_page(struct page *page)
75061 +void free_compound_page(struct page *page)
75062 {
75063 __free_pages_ok(page, compound_order(page));
75064 }
75065 @@ -697,6 +697,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
75066 int i;
75067 int bad = 0;
75068
75069 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
75070 + unsigned long index = 1UL << order;
75071 +#endif
75072 +
75073 trace_mm_page_free(page, order);
75074 kmemcheck_free_shadow(page, order);
75075
75076 @@ -712,6 +716,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
75077 debug_check_no_obj_freed(page_address(page),
75078 PAGE_SIZE << order);
75079 }
75080 +
75081 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
75082 + for (; index; --index)
75083 + sanitize_highpage(page + index - 1);
75084 +#endif
75085 +
75086 arch_free_page(page, order);
75087 kernel_map_pages(page, 1 << order, 0);
75088
75089 @@ -853,8 +863,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
75090 arch_alloc_page(page, order);
75091 kernel_map_pages(page, 1 << order, 1);
75092
75093 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
75094 if (gfp_flags & __GFP_ZERO)
75095 prep_zero_page(page, order, gfp_flags);
75096 +#endif
75097
75098 if (order && (gfp_flags & __GFP_COMP))
75099 prep_compound_page(page, order);
75100 @@ -3648,7 +3660,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
75101 unsigned long pfn;
75102
75103 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
75104 +#ifdef CONFIG_X86_32
75105 + /* boot failures in VMware 8 on 32bit vanilla since
75106 + this change */
75107 + if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
75108 +#else
75109 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
75110 +#endif
75111 return 1;
75112 }
75113 return 0;
75114 diff --git a/mm/percpu.c b/mm/percpu.c
75115 index bb4be74..a43ea85 100644
75116 --- a/mm/percpu.c
75117 +++ b/mm/percpu.c
75118 @@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
75119 static unsigned int pcpu_high_unit_cpu __read_mostly;
75120
75121 /* the address of the first chunk which starts with the kernel static area */
75122 -void *pcpu_base_addr __read_mostly;
75123 +void *pcpu_base_addr __read_only;
75124 EXPORT_SYMBOL_GPL(pcpu_base_addr);
75125
75126 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
75127 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
75128 index 926b466..b23df53 100644
75129 --- a/mm/process_vm_access.c
75130 +++ b/mm/process_vm_access.c
75131 @@ -13,6 +13,7 @@
75132 #include <linux/uio.h>
75133 #include <linux/sched.h>
75134 #include <linux/highmem.h>
75135 +#include <linux/security.h>
75136 #include <linux/ptrace.h>
75137 #include <linux/slab.h>
75138 #include <linux/syscalls.h>
75139 @@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
75140 size_t iov_l_curr_offset = 0;
75141 ssize_t iov_len;
75142
75143 + return -ENOSYS; // PaX: until properly audited
75144 +
75145 /*
75146 * Work out how many pages of struct pages we're going to need
75147 * when eventually calling get_user_pages
75148 */
75149 for (i = 0; i < riovcnt; i++) {
75150 iov_len = rvec[i].iov_len;
75151 - if (iov_len > 0) {
75152 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
75153 - + iov_len)
75154 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
75155 - / PAGE_SIZE + 1;
75156 - nr_pages = max(nr_pages, nr_pages_iov);
75157 - }
75158 + if (iov_len <= 0)
75159 + continue;
75160 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
75161 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
75162 + nr_pages = max(nr_pages, nr_pages_iov);
75163 }
75164
75165 if (nr_pages == 0)
75166 @@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
75167 goto free_proc_pages;
75168 }
75169
75170 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
75171 + rc = -EPERM;
75172 + goto put_task_struct;
75173 + }
75174 +
75175 mm = mm_access(task, PTRACE_MODE_ATTACH);
75176 if (!mm || IS_ERR(mm)) {
75177 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
75178 diff --git a/mm/rmap.c b/mm/rmap.c
75179 index aa95e59..b681a63 100644
75180 --- a/mm/rmap.c
75181 +++ b/mm/rmap.c
75182 @@ -168,6 +168,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
75183 struct anon_vma *anon_vma = vma->anon_vma;
75184 struct anon_vma_chain *avc;
75185
75186 +#ifdef CONFIG_PAX_SEGMEXEC
75187 + struct anon_vma_chain *avc_m = NULL;
75188 +#endif
75189 +
75190 might_sleep();
75191 if (unlikely(!anon_vma)) {
75192 struct mm_struct *mm = vma->vm_mm;
75193 @@ -177,6 +181,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
75194 if (!avc)
75195 goto out_enomem;
75196
75197 +#ifdef CONFIG_PAX_SEGMEXEC
75198 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
75199 + if (!avc_m)
75200 + goto out_enomem_free_avc;
75201 +#endif
75202 +
75203 anon_vma = find_mergeable_anon_vma(vma);
75204 allocated = NULL;
75205 if (!anon_vma) {
75206 @@ -190,6 +200,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
75207 /* page_table_lock to protect against threads */
75208 spin_lock(&mm->page_table_lock);
75209 if (likely(!vma->anon_vma)) {
75210 +
75211 +#ifdef CONFIG_PAX_SEGMEXEC
75212 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
75213 +
75214 + if (vma_m) {
75215 + BUG_ON(vma_m->anon_vma);
75216 + vma_m->anon_vma = anon_vma;
75217 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
75218 + avc_m = NULL;
75219 + }
75220 +#endif
75221 +
75222 vma->anon_vma = anon_vma;
75223 anon_vma_chain_link(vma, avc, anon_vma);
75224 allocated = NULL;
75225 @@ -200,12 +222,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
75226
75227 if (unlikely(allocated))
75228 put_anon_vma(allocated);
75229 +
75230 +#ifdef CONFIG_PAX_SEGMEXEC
75231 + if (unlikely(avc_m))
75232 + anon_vma_chain_free(avc_m);
75233 +#endif
75234 +
75235 if (unlikely(avc))
75236 anon_vma_chain_free(avc);
75237 }
75238 return 0;
75239
75240 out_enomem_free_avc:
75241 +
75242 +#ifdef CONFIG_PAX_SEGMEXEC
75243 + if (avc_m)
75244 + anon_vma_chain_free(avc_m);
75245 +#endif
75246 +
75247 anon_vma_chain_free(avc);
75248 out_enomem:
75249 return -ENOMEM;
75250 @@ -241,7 +275,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
75251 * Attach the anon_vmas from src to dst.
75252 * Returns 0 on success, -ENOMEM on failure.
75253 */
75254 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
75255 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
75256 {
75257 struct anon_vma_chain *avc, *pavc;
75258 struct anon_vma *root = NULL;
75259 @@ -319,7 +353,7 @@ void anon_vma_moveto_tail(struct vm_area_struct *dst)
75260 * the corresponding VMA in the parent process is attached to.
75261 * Returns 0 on success, non-zero on failure.
75262 */
75263 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
75264 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
75265 {
75266 struct anon_vma_chain *avc;
75267 struct anon_vma *anon_vma;
75268 diff --git a/mm/shmem.c b/mm/shmem.c
75269 index 31e1506..dbf3647 100644
75270 --- a/mm/shmem.c
75271 +++ b/mm/shmem.c
75272 @@ -31,7 +31,7 @@
75273 #include <linux/export.h>
75274 #include <linux/swap.h>
75275
75276 -static struct vfsmount *shm_mnt;
75277 +struct vfsmount *shm_mnt;
75278
75279 #ifdef CONFIG_SHMEM
75280 /*
75281 @@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
75282 #define BOGO_DIRENT_SIZE 20
75283
75284 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
75285 -#define SHORT_SYMLINK_LEN 128
75286 +#define SHORT_SYMLINK_LEN 64
75287
75288 struct shmem_xattr {
75289 struct list_head list; /* anchored by shmem_inode_info->xattr_list */
75290 @@ -2219,6 +2219,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
75291 static int shmem_xattr_validate(const char *name)
75292 {
75293 struct { const char *prefix; size_t len; } arr[] = {
75294 +
75295 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
75296 + { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
75297 +#endif
75298 +
75299 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
75300 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
75301 };
75302 @@ -2272,6 +2277,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
75303 if (err)
75304 return err;
75305
75306 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
75307 + if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
75308 + if (strcmp(name, XATTR_NAME_PAX_FLAGS))
75309 + return -EOPNOTSUPP;
75310 + if (size > 8)
75311 + return -EINVAL;
75312 + }
75313 +#endif
75314 +
75315 if (size == 0)
75316 value = ""; /* empty EA, do not remove */
75317
75318 @@ -2606,8 +2620,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
75319 int err = -ENOMEM;
75320
75321 /* Round up to L1_CACHE_BYTES to resist false sharing */
75322 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
75323 - L1_CACHE_BYTES), GFP_KERNEL);
75324 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
75325 if (!sbinfo)
75326 return -ENOMEM;
75327
75328 diff --git a/mm/slab.c b/mm/slab.c
75329 index d066037..5bb78d9 100644
75330 --- a/mm/slab.c
75331 +++ b/mm/slab.c
75332 @@ -164,7 +164,7 @@ static bool pfmemalloc_active __read_mostly;
75333
75334 /* Legal flag mask for kmem_cache_create(). */
75335 #if DEBUG
75336 -# define CREATE_MASK (SLAB_RED_ZONE | \
75337 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
75338 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
75339 SLAB_CACHE_DMA | \
75340 SLAB_STORE_USER | \
75341 @@ -172,7 +172,7 @@ static bool pfmemalloc_active __read_mostly;
75342 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
75343 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
75344 #else
75345 -# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
75346 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
75347 SLAB_CACHE_DMA | \
75348 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
75349 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
75350 @@ -322,7 +322,7 @@ struct kmem_list3 {
75351 * Need this for bootstrapping a per node allocator.
75352 */
75353 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
75354 -static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
75355 +static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
75356 #define CACHE_CACHE 0
75357 #define SIZE_AC MAX_NUMNODES
75358 #define SIZE_L3 (2 * MAX_NUMNODES)
75359 @@ -423,10 +423,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
75360 if ((x)->max_freeable < i) \
75361 (x)->max_freeable = i; \
75362 } while (0)
75363 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
75364 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
75365 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
75366 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
75367 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
75368 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
75369 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
75370 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
75371 #else
75372 #define STATS_INC_ACTIVE(x) do { } while (0)
75373 #define STATS_DEC_ACTIVE(x) do { } while (0)
75374 @@ -549,7 +549,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
75375 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
75376 */
75377 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
75378 - const struct slab *slab, void *obj)
75379 + const struct slab *slab, const void *obj)
75380 {
75381 u32 offset = (obj - slab->s_mem);
75382 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
75383 @@ -570,12 +570,13 @@ EXPORT_SYMBOL(malloc_sizes);
75384 struct cache_names {
75385 char *name;
75386 char *name_dma;
75387 + char *name_usercopy;
75388 };
75389
75390 static struct cache_names __initdata cache_names[] = {
75391 -#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
75392 +#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
75393 #include <linux/kmalloc_sizes.h>
75394 - {NULL,}
75395 + {NULL}
75396 #undef CACHE
75397 };
75398
75399 @@ -736,6 +737,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
75400 if (unlikely(gfpflags & GFP_DMA))
75401 return csizep->cs_dmacachep;
75402 #endif
75403 +
75404 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75405 + if (unlikely(gfpflags & GFP_USERCOPY))
75406 + return csizep->cs_usercopycachep;
75407 +#endif
75408 +
75409 return csizep->cs_cachep;
75410 }
75411
75412 @@ -1684,7 +1691,7 @@ void __init kmem_cache_init(void)
75413 sizes[INDEX_AC].cs_cachep = __kmem_cache_create(names[INDEX_AC].name,
75414 sizes[INDEX_AC].cs_size,
75415 ARCH_KMALLOC_MINALIGN,
75416 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
75417 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
75418 NULL);
75419
75420 if (INDEX_AC != INDEX_L3) {
75421 @@ -1692,7 +1699,7 @@ void __init kmem_cache_init(void)
75422 __kmem_cache_create(names[INDEX_L3].name,
75423 sizes[INDEX_L3].cs_size,
75424 ARCH_KMALLOC_MINALIGN,
75425 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
75426 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
75427 NULL);
75428 }
75429
75430 @@ -1710,7 +1717,7 @@ void __init kmem_cache_init(void)
75431 sizes->cs_cachep = __kmem_cache_create(names->name,
75432 sizes->cs_size,
75433 ARCH_KMALLOC_MINALIGN,
75434 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
75435 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
75436 NULL);
75437 }
75438 #ifdef CONFIG_ZONE_DMA
75439 @@ -1722,6 +1729,16 @@ void __init kmem_cache_init(void)
75440 SLAB_PANIC,
75441 NULL);
75442 #endif
75443 +
75444 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75445 + sizes->cs_usercopycachep = kmem_cache_create(
75446 + names->name_usercopy,
75447 + sizes->cs_size,
75448 + ARCH_KMALLOC_MINALIGN,
75449 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
75450 + NULL);
75451 +#endif
75452 +
75453 sizes++;
75454 names++;
75455 }
75456 @@ -4467,10 +4484,10 @@ static int s_show(struct seq_file *m, void *p)
75457 }
75458 /* cpu stats */
75459 {
75460 - unsigned long allochit = atomic_read(&cachep->allochit);
75461 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
75462 - unsigned long freehit = atomic_read(&cachep->freehit);
75463 - unsigned long freemiss = atomic_read(&cachep->freemiss);
75464 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
75465 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
75466 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
75467 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
75468
75469 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
75470 allochit, allocmiss, freehit, freemiss);
75471 @@ -4729,13 +4746,71 @@ static int __init slab_proc_init(void)
75472 {
75473 proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);
75474 #ifdef CONFIG_DEBUG_SLAB_LEAK
75475 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
75476 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
75477 #endif
75478 return 0;
75479 }
75480 module_init(slab_proc_init);
75481 #endif
75482
75483 +bool is_usercopy_object(const void *ptr)
75484 +{
75485 + struct page *page;
75486 + struct kmem_cache *cachep;
75487 +
75488 + if (ZERO_OR_NULL_PTR(ptr))
75489 + return false;
75490 +
75491 + if (!slab_is_available())
75492 + return false;
75493 +
75494 + if (!virt_addr_valid(ptr))
75495 + return false;
75496 +
75497 + page = virt_to_head_page(ptr);
75498 +
75499 + if (!PageSlab(page))
75500 + return false;
75501 +
75502 + cachep = page_get_cache(page);
75503 + return cachep->flags & SLAB_USERCOPY;
75504 +}
75505 +
75506 +#ifdef CONFIG_PAX_USERCOPY
75507 +const char *check_heap_object(const void *ptr, unsigned long n, bool to)
75508 +{
75509 + struct page *page;
75510 + struct kmem_cache *cachep;
75511 + struct slab *slabp;
75512 + unsigned int objnr;
75513 + unsigned long offset;
75514 +
75515 + if (ZERO_OR_NULL_PTR(ptr))
75516 + return "<null>";
75517 +
75518 + if (!virt_addr_valid(ptr))
75519 + return NULL;
75520 +
75521 + page = virt_to_head_page(ptr);
75522 +
75523 + if (!PageSlab(page))
75524 + return NULL;
75525 +
75526 + cachep = page_get_cache(page);
75527 + if (!(cachep->flags & SLAB_USERCOPY))
75528 + return cachep->name;
75529 +
75530 + slabp = page->slab_page;
75531 + objnr = obj_to_index(cachep, slabp, ptr);
75532 + BUG_ON(objnr >= cachep->num);
75533 + offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
75534 + if (offset <= cachep->object_size && n <= cachep->object_size - offset)
75535 + return NULL;
75536 +
75537 + return cachep->name;
75538 +}
75539 +#endif
75540 +
75541 /**
75542 * ksize - get the actual amount of memory allocated for a given object
75543 * @objp: Pointer to the object
75544 diff --git a/mm/slob.c b/mm/slob.c
75545 index 45d4ca7..88943c1 100644
75546 --- a/mm/slob.c
75547 +++ b/mm/slob.c
75548 @@ -159,7 +159,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
75549 /*
75550 * Return the size of a slob block.
75551 */
75552 -static slobidx_t slob_units(slob_t *s)
75553 +static slobidx_t slob_units(const slob_t *s)
75554 {
75555 if (s->units > 0)
75556 return s->units;
75557 @@ -169,7 +169,7 @@ static slobidx_t slob_units(slob_t *s)
75558 /*
75559 * Return the next free slob block pointer after this one.
75560 */
75561 -static slob_t *slob_next(slob_t *s)
75562 +static slob_t *slob_next(const slob_t *s)
75563 {
75564 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
75565 slobidx_t next;
75566 @@ -184,14 +184,14 @@ static slob_t *slob_next(slob_t *s)
75567 /*
75568 * Returns true if s is the last free block in its page.
75569 */
75570 -static int slob_last(slob_t *s)
75571 +static int slob_last(const slob_t *s)
75572 {
75573 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
75574 }
75575
75576 -static void *slob_new_pages(gfp_t gfp, int order, int node)
75577 +static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
75578 {
75579 - void *page;
75580 + struct page *page;
75581
75582 #ifdef CONFIG_NUMA
75583 if (node != -1)
75584 @@ -203,14 +203,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
75585 if (!page)
75586 return NULL;
75587
75588 - return page_address(page);
75589 + __SetPageSlab(page);
75590 + return page;
75591 }
75592
75593 -static void slob_free_pages(void *b, int order)
75594 +static void slob_free_pages(struct page *sp, int order)
75595 {
75596 if (current->reclaim_state)
75597 current->reclaim_state->reclaimed_slab += 1 << order;
75598 - free_pages((unsigned long)b, order);
75599 + __ClearPageSlab(sp);
75600 + reset_page_mapcount(sp);
75601 + sp->private = 0;
75602 + __free_pages(sp, order);
75603 }
75604
75605 /*
75606 @@ -315,15 +319,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
75607
75608 /* Not enough space: must allocate a new page */
75609 if (!b) {
75610 - b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
75611 - if (!b)
75612 + sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
75613 + if (!sp)
75614 return NULL;
75615 - sp = virt_to_page(b);
75616 - __SetPageSlab(sp);
75617 + b = page_address(sp);
75618
75619 spin_lock_irqsave(&slob_lock, flags);
75620 sp->units = SLOB_UNITS(PAGE_SIZE);
75621 sp->freelist = b;
75622 + sp->private = 0;
75623 INIT_LIST_HEAD(&sp->list);
75624 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
75625 set_slob_page_free(sp, slob_list);
75626 @@ -361,9 +365,7 @@ static void slob_free(void *block, int size)
75627 if (slob_page_free(sp))
75628 clear_slob_page_free(sp);
75629 spin_unlock_irqrestore(&slob_lock, flags);
75630 - __ClearPageSlab(sp);
75631 - reset_page_mapcount(sp);
75632 - slob_free_pages(b, 0);
75633 + slob_free_pages(sp, 0);
75634 return;
75635 }
75636
75637 @@ -425,11 +427,10 @@ out:
75638 * End of slob allocator proper. Begin kmem_cache_alloc and kmalloc frontend.
75639 */
75640
75641 -void *__kmalloc_node(size_t size, gfp_t gfp, int node)
75642 +static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
75643 {
75644 - unsigned int *m;
75645 - int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
75646 - void *ret;
75647 + slob_t *m;
75648 + void *ret = NULL;
75649
75650 gfp &= gfp_allowed_mask;
75651
75652 @@ -443,20 +444,23 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
75653
75654 if (!m)
75655 return NULL;
75656 - *m = size;
75657 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
75658 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
75659 + m[0].units = size;
75660 + m[1].units = align;
75661 ret = (void *)m + align;
75662
75663 trace_kmalloc_node(_RET_IP_, ret,
75664 size, size + align, gfp, node);
75665 } else {
75666 unsigned int order = get_order(size);
75667 + struct page *page;
75668
75669 if (likely(order))
75670 gfp |= __GFP_COMP;
75671 - ret = slob_new_pages(gfp, order, node);
75672 - if (ret) {
75673 - struct page *page;
75674 - page = virt_to_page(ret);
75675 + page = slob_new_pages(gfp, order, node);
75676 + if (page) {
75677 + ret = page_address(page);
75678 page->private = size;
75679 }
75680
75681 @@ -464,7 +468,16 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
75682 size, PAGE_SIZE << order, gfp, node);
75683 }
75684
75685 - kmemleak_alloc(ret, size, 1, gfp);
75686 + return ret;
75687 +}
75688 +
75689 +void *__kmalloc_node(size_t size, gfp_t gfp, int node)
75690 +{
75691 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
75692 + void *ret = __kmalloc_node_align(size, gfp, node, align);
75693 +
75694 + if (!ZERO_OR_NULL_PTR(ret))
75695 + kmemleak_alloc(ret, size, 1, gfp);
75696 return ret;
75697 }
75698 EXPORT_SYMBOL(__kmalloc_node);
75699 @@ -480,15 +493,91 @@ void kfree(const void *block)
75700 kmemleak_free(block);
75701
75702 sp = virt_to_page(block);
75703 - if (PageSlab(sp)) {
75704 + VM_BUG_ON(!PageSlab(sp));
75705 + if (!sp->private) {
75706 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
75707 - unsigned int *m = (unsigned int *)(block - align);
75708 - slob_free(m, *m + align);
75709 - } else
75710 + slob_t *m = (slob_t *)(block - align);
75711 + slob_free(m, m[0].units + align);
75712 + } else {
75713 + __ClearPageSlab(sp);
75714 + reset_page_mapcount(sp);
75715 + sp->private = 0;
75716 put_page(sp);
75717 + }
75718 }
75719 EXPORT_SYMBOL(kfree);
75720
75721 +bool is_usercopy_object(const void *ptr)
75722 +{
75723 + if (!slab_is_available())
75724 + return false;
75725 +
75726 + // PAX: TODO
75727 +
75728 + return false;
75729 +}
75730 +
75731 +#ifdef CONFIG_PAX_USERCOPY
75732 +const char *check_heap_object(const void *ptr, unsigned long n, bool to)
75733 +{
75734 + struct page *page;
75735 + const slob_t *free;
75736 + const void *base;
75737 + unsigned long flags;
75738 +
75739 + if (ZERO_OR_NULL_PTR(ptr))
75740 + return "<null>";
75741 +
75742 + if (!virt_addr_valid(ptr))
75743 + return NULL;
75744 +
75745 + page = virt_to_head_page(ptr);
75746 + if (!PageSlab(page))
75747 + return NULL;
75748 +
75749 + if (page->private) {
75750 + base = page;
75751 + if (base <= ptr && n <= page->private - (ptr - base))
75752 + return NULL;
75753 + return "<slob>";
75754 + }
75755 +
75756 + /* some tricky double walking to find the chunk */
75757 + spin_lock_irqsave(&slob_lock, flags);
75758 + base = (void *)((unsigned long)ptr & PAGE_MASK);
75759 + free = page->freelist;
75760 +
75761 + while (!slob_last(free) && (void *)free <= ptr) {
75762 + base = free + slob_units(free);
75763 + free = slob_next(free);
75764 + }
75765 +
75766 + while (base < (void *)free) {
75767 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
75768 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
75769 + int offset;
75770 +
75771 + if (ptr < base + align)
75772 + break;
75773 +
75774 + offset = ptr - base - align;
75775 + if (offset >= m) {
75776 + base += size;
75777 + continue;
75778 + }
75779 +
75780 + if (n > m - offset)
75781 + break;
75782 +
75783 + spin_unlock_irqrestore(&slob_lock, flags);
75784 + return NULL;
75785 + }
75786 +
75787 + spin_unlock_irqrestore(&slob_lock, flags);
75788 + return "<slob>";
75789 +}
75790 +#endif
75791 +
75792 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
75793 size_t ksize(const void *block)
75794 {
75795 @@ -499,10 +588,11 @@ size_t ksize(const void *block)
75796 return 0;
75797
75798 sp = virt_to_page(block);
75799 - if (PageSlab(sp)) {
75800 + VM_BUG_ON(!PageSlab(sp));
75801 + if (!sp->private) {
75802 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
75803 - unsigned int *m = (unsigned int *)(block - align);
75804 - return SLOB_UNITS(*m) * SLOB_UNIT;
75805 + slob_t *m = (slob_t *)(block - align);
75806 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
75807 } else
75808 return sp->private;
75809 }
75810 @@ -513,8 +603,13 @@ struct kmem_cache *__kmem_cache_create(const char *name, size_t size,
75811 {
75812 struct kmem_cache *c;
75813
75814 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75815 + c = __kmalloc_node_align(sizeof(struct kmem_cache),
75816 + GFP_KERNEL, -1, ARCH_KMALLOC_MINALIGN);
75817 +#else
75818 c = slob_alloc(sizeof(struct kmem_cache),
75819 GFP_KERNEL, ARCH_KMALLOC_MINALIGN, -1);
75820 +#endif
75821
75822 if (c) {
75823 c->name = name;
75824 @@ -549,23 +644,33 @@ EXPORT_SYMBOL(kmem_cache_destroy);
75825
75826 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
75827 {
75828 - void *b;
75829 + void *b = NULL;
75830
75831 flags &= gfp_allowed_mask;
75832
75833 lockdep_trace_alloc(flags);
75834
75835 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75836 + b = __kmalloc_node_align(c->size, flags, node, c->align);
75837 +#else
75838 if (c->size < PAGE_SIZE) {
75839 b = slob_alloc(c->size, flags, c->align, node);
75840 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
75841 SLOB_UNITS(c->size) * SLOB_UNIT,
75842 flags, node);
75843 } else {
75844 - b = slob_new_pages(flags, get_order(c->size), node);
75845 + struct page *sp;
75846 +
75847 + sp = slob_new_pages(flags, get_order(c->size), node);
75848 + if (sp) {
75849 + b = page_address(sp);
75850 + sp->private = c->size;
75851 + }
75852 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
75853 PAGE_SIZE << get_order(c->size),
75854 flags, node);
75855 }
75856 +#endif
75857
75858 if (c->ctor)
75859 c->ctor(b);
75860 @@ -577,10 +682,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
75861
75862 static void __kmem_cache_free(void *b, int size)
75863 {
75864 - if (size < PAGE_SIZE)
75865 + struct page *sp;
75866 +
75867 + sp = virt_to_page(b);
75868 + BUG_ON(!PageSlab(sp));
75869 + if (!sp->private)
75870 slob_free(b, size);
75871 else
75872 - slob_free_pages(b, get_order(size));
75873 + slob_free_pages(sp, get_order(size));
75874 }
75875
75876 static void kmem_rcu_free(struct rcu_head *head)
75877 @@ -593,17 +702,31 @@ static void kmem_rcu_free(struct rcu_head *head)
75878
75879 void kmem_cache_free(struct kmem_cache *c, void *b)
75880 {
75881 + int size = c->size;
75882 +
75883 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75884 + if (size + c->align < PAGE_SIZE) {
75885 + size += c->align;
75886 + b -= c->align;
75887 + }
75888 +#endif
75889 +
75890 kmemleak_free_recursive(b, c->flags);
75891 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
75892 struct slob_rcu *slob_rcu;
75893 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
75894 - slob_rcu->size = c->size;
75895 + slob_rcu = b + (size - sizeof(struct slob_rcu));
75896 + slob_rcu->size = size;
75897 call_rcu(&slob_rcu->head, kmem_rcu_free);
75898 } else {
75899 - __kmem_cache_free(b, c->size);
75900 + __kmem_cache_free(b, size);
75901 }
75902
75903 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75904 + trace_kfree(_RET_IP_, b);
75905 +#else
75906 trace_kmem_cache_free(_RET_IP_, b);
75907 +#endif
75908 +
75909 }
75910 EXPORT_SYMBOL(kmem_cache_free);
75911
75912 diff --git a/mm/slub.c b/mm/slub.c
75913 index 2fdd96f..1e2f893 100644
75914 --- a/mm/slub.c
75915 +++ b/mm/slub.c
75916 @@ -201,7 +201,7 @@ struct track {
75917
75918 enum track_item { TRACK_ALLOC, TRACK_FREE };
75919
75920 -#ifdef CONFIG_SYSFS
75921 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75922 static int sysfs_slab_add(struct kmem_cache *);
75923 static int sysfs_slab_alias(struct kmem_cache *, const char *);
75924 static void sysfs_slab_remove(struct kmem_cache *);
75925 @@ -525,7 +525,7 @@ static void print_track(const char *s, struct track *t)
75926 if (!t->addr)
75927 return;
75928
75929 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
75930 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
75931 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
75932 #ifdef CONFIG_STACKTRACE
75933 {
75934 @@ -2612,6 +2612,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
75935
75936 page = virt_to_head_page(x);
75937
75938 + BUG_ON(!PageSlab(page));
75939 +
75940 slab_free(s, page, x, _RET_IP_);
75941
75942 trace_kmem_cache_free(_RET_IP_, x);
75943 @@ -2645,7 +2647,7 @@ static int slub_min_objects;
75944 * Merge control. If this is set then no merging of slab caches will occur.
75945 * (Could be removed. This was introduced to pacify the merge skeptics.)
75946 */
75947 -static int slub_nomerge;
75948 +static int slub_nomerge = 1;
75949
75950 /*
75951 * Calculate the order of allocation given an slab object size.
75952 @@ -3098,7 +3100,7 @@ static int kmem_cache_open(struct kmem_cache *s,
75953 else
75954 s->cpu_partial = 30;
75955
75956 - s->refcount = 1;
75957 + atomic_set(&s->refcount, 1);
75958 #ifdef CONFIG_NUMA
75959 s->remote_node_defrag_ratio = 1000;
75960 #endif
75961 @@ -3202,8 +3204,7 @@ static inline int kmem_cache_close(struct kmem_cache *s)
75962 void kmem_cache_destroy(struct kmem_cache *s)
75963 {
75964 mutex_lock(&slab_mutex);
75965 - s->refcount--;
75966 - if (!s->refcount) {
75967 + if (atomic_dec_and_test(&s->refcount)) {
75968 list_del(&s->list);
75969 mutex_unlock(&slab_mutex);
75970 if (kmem_cache_close(s)) {
75971 @@ -3232,6 +3233,10 @@ static struct kmem_cache *kmem_cache;
75972 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
75973 #endif
75974
75975 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75976 +static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
75977 +#endif
75978 +
75979 static int __init setup_slub_min_order(char *str)
75980 {
75981 get_option(&str, &slub_min_order);
75982 @@ -3346,6 +3351,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
75983 return kmalloc_dma_caches[index];
75984
75985 #endif
75986 +
75987 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75988 + if (flags & SLAB_USERCOPY)
75989 + return kmalloc_usercopy_caches[index];
75990 +
75991 +#endif
75992 +
75993 return kmalloc_caches[index];
75994 }
75995
75996 @@ -3414,6 +3426,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
75997 EXPORT_SYMBOL(__kmalloc_node);
75998 #endif
75999
76000 +bool is_usercopy_object(const void *ptr)
76001 +{
76002 + struct page *page;
76003 + struct kmem_cache *s;
76004 +
76005 + if (ZERO_OR_NULL_PTR(ptr))
76006 + return false;
76007 +
76008 + if (!slab_is_available())
76009 + return false;
76010 +
76011 + if (!virt_addr_valid(ptr))
76012 + return false;
76013 +
76014 + page = virt_to_head_page(ptr);
76015 +
76016 + if (!PageSlab(page))
76017 + return false;
76018 +
76019 + s = page->slab;
76020 + return s->flags & SLAB_USERCOPY;
76021 +}
76022 +
76023 +#ifdef CONFIG_PAX_USERCOPY
76024 +const char *check_heap_object(const void *ptr, unsigned long n, bool to)
76025 +{
76026 + struct page *page;
76027 + struct kmem_cache *s;
76028 + unsigned long offset;
76029 +
76030 + if (ZERO_OR_NULL_PTR(ptr))
76031 + return "<null>";
76032 +
76033 + if (!virt_addr_valid(ptr))
76034 + return NULL;
76035 +
76036 + page = virt_to_head_page(ptr);
76037 +
76038 + if (!PageSlab(page))
76039 + return NULL;
76040 +
76041 + s = page->slab;
76042 + if (!(s->flags & SLAB_USERCOPY))
76043 + return s->name;
76044 +
76045 + offset = (ptr - page_address(page)) % s->size;
76046 + if (offset <= s->object_size && n <= s->object_size - offset)
76047 + return NULL;
76048 +
76049 + return s->name;
76050 +}
76051 +#endif
76052 +
76053 size_t ksize(const void *object)
76054 {
76055 struct page *page;
76056 @@ -3688,7 +3753,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
76057 int node;
76058
76059 list_add(&s->list, &slab_caches);
76060 - s->refcount = -1;
76061 + atomic_set(&s->refcount, -1);
76062
76063 for_each_node_state(node, N_NORMAL_MEMORY) {
76064 struct kmem_cache_node *n = get_node(s, node);
76065 @@ -3808,17 +3873,17 @@ void __init kmem_cache_init(void)
76066
76067 /* Caches that are not of the two-to-the-power-of size */
76068 if (KMALLOC_MIN_SIZE <= 32) {
76069 - kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
76070 + kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
76071 caches++;
76072 }
76073
76074 if (KMALLOC_MIN_SIZE <= 64) {
76075 - kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
76076 + kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
76077 caches++;
76078 }
76079
76080 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
76081 - kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
76082 + kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
76083 caches++;
76084 }
76085
76086 @@ -3860,6 +3925,22 @@ void __init kmem_cache_init(void)
76087 }
76088 }
76089 #endif
76090 +
76091 +#ifdef CONFIG_PAX_USERCOPY_SLABS
76092 + for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
76093 + struct kmem_cache *s = kmalloc_caches[i];
76094 +
76095 + if (s && s->size) {
76096 + char *name = kasprintf(GFP_NOWAIT,
76097 + "usercopy-kmalloc-%d", s->object_size);
76098 +
76099 + BUG_ON(!name);
76100 + kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
76101 + s->object_size, SLAB_USERCOPY);
76102 + }
76103 + }
76104 +#endif
76105 +
76106 printk(KERN_INFO
76107 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
76108 " CPUs=%d, Nodes=%d\n",
76109 @@ -3886,7 +3967,7 @@ static int slab_unmergeable(struct kmem_cache *s)
76110 /*
76111 * We may have set a slab to be unmergeable during bootstrap.
76112 */
76113 - if (s->refcount < 0)
76114 + if (atomic_read(&s->refcount) < 0)
76115 return 1;
76116
76117 return 0;
76118 @@ -3941,7 +4022,7 @@ struct kmem_cache *__kmem_cache_create(const char *name, size_t size,
76119
76120 s = find_mergeable(size, align, flags, name, ctor);
76121 if (s) {
76122 - s->refcount++;
76123 + atomic_inc(&s->refcount);
76124 /*
76125 * Adjust the object sizes so that we clear
76126 * the complete object on kzalloc.
76127 @@ -3950,7 +4031,7 @@ struct kmem_cache *__kmem_cache_create(const char *name, size_t size,
76128 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
76129
76130 if (sysfs_slab_alias(s, name)) {
76131 - s->refcount--;
76132 + atomic_dec(&s->refcount);
76133 return NULL;
76134 }
76135 return s;
76136 @@ -4072,7 +4153,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
76137 }
76138 #endif
76139
76140 -#ifdef CONFIG_SYSFS
76141 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
76142 static int count_inuse(struct page *page)
76143 {
76144 return page->inuse;
76145 @@ -4459,12 +4540,12 @@ static void resiliency_test(void)
76146 validate_slab_cache(kmalloc_caches[9]);
76147 }
76148 #else
76149 -#ifdef CONFIG_SYSFS
76150 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
76151 static void resiliency_test(void) {};
76152 #endif
76153 #endif
76154
76155 -#ifdef CONFIG_SYSFS
76156 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
76157 enum slab_stat_type {
76158 SL_ALL, /* All slabs */
76159 SL_PARTIAL, /* Only partially allocated slabs */
76160 @@ -4708,7 +4789,7 @@ SLAB_ATTR_RO(ctor);
76161
76162 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
76163 {
76164 - return sprintf(buf, "%d\n", s->refcount - 1);
76165 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
76166 }
76167 SLAB_ATTR_RO(aliases);
76168
76169 @@ -5279,6 +5360,7 @@ static char *create_unique_id(struct kmem_cache *s)
76170 return name;
76171 }
76172
76173 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
76174 static int sysfs_slab_add(struct kmem_cache *s)
76175 {
76176 int err;
76177 @@ -5341,6 +5423,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
76178 kobject_del(&s->kobj);
76179 kobject_put(&s->kobj);
76180 }
76181 +#endif
76182
76183 /*
76184 * Need to buffer aliases during bootup until sysfs becomes
76185 @@ -5354,6 +5437,7 @@ struct saved_alias {
76186
76187 static struct saved_alias *alias_list;
76188
76189 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
76190 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
76191 {
76192 struct saved_alias *al;
76193 @@ -5376,6 +5460,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
76194 alias_list = al;
76195 return 0;
76196 }
76197 +#endif
76198
76199 static int __init slab_sysfs_init(void)
76200 {
76201 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
76202 index 1b7e22a..3fcd4f3 100644
76203 --- a/mm/sparse-vmemmap.c
76204 +++ b/mm/sparse-vmemmap.c
76205 @@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
76206 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
76207 if (!p)
76208 return NULL;
76209 - pud_populate(&init_mm, pud, p);
76210 + pud_populate_kernel(&init_mm, pud, p);
76211 }
76212 return pud;
76213 }
76214 @@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
76215 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
76216 if (!p)
76217 return NULL;
76218 - pgd_populate(&init_mm, pgd, p);
76219 + pgd_populate_kernel(&init_mm, pgd, p);
76220 }
76221 return pgd;
76222 }
76223 diff --git a/mm/sparse.c b/mm/sparse.c
76224 index fac95f2..a83de2f 100644
76225 --- a/mm/sparse.c
76226 +++ b/mm/sparse.c
76227 @@ -617,7 +617,7 @@ static void __kfree_section_memmap(struct page *memmap, unsigned long nr_pages)
76228 {
76229 return; /* XXX: Not implemented yet */
76230 }
76231 -static void free_map_bootmem(struct page *page, unsigned long nr_pages)
76232 +static void free_map_bootmem(struct page *memmap, unsigned long nr_pages)
76233 {
76234 }
76235 #else
76236 @@ -658,10 +658,11 @@ static void __kfree_section_memmap(struct page *memmap, unsigned long nr_pages)
76237 get_order(sizeof(struct page) * nr_pages));
76238 }
76239
76240 -static void free_map_bootmem(struct page *page, unsigned long nr_pages)
76241 +static void free_map_bootmem(struct page *memmap, unsigned long nr_pages)
76242 {
76243 unsigned long maps_section_nr, removing_section_nr, i;
76244 unsigned long magic;
76245 + struct page *page = virt_to_page(memmap);
76246
76247 for (i = 0; i < nr_pages; i++, page++) {
76248 magic = (unsigned long) page->lru.next;
76249 @@ -710,13 +711,10 @@ static void free_section_usemap(struct page *memmap, unsigned long *usemap)
76250 */
76251
76252 if (memmap) {
76253 - struct page *memmap_page;
76254 - memmap_page = virt_to_page(memmap);
76255 -
76256 nr_pages = PAGE_ALIGN(PAGES_PER_SECTION * sizeof(struct page))
76257 >> PAGE_SHIFT;
76258
76259 - free_map_bootmem(memmap_page, nr_pages);
76260 + free_map_bootmem(memmap, nr_pages);
76261 }
76262 }
76263
76264 diff --git a/mm/swap.c b/mm/swap.c
76265 index 7782588..228c784 100644
76266 --- a/mm/swap.c
76267 +++ b/mm/swap.c
76268 @@ -30,6 +30,7 @@
76269 #include <linux/backing-dev.h>
76270 #include <linux/memcontrol.h>
76271 #include <linux/gfp.h>
76272 +#include <linux/hugetlb.h>
76273
76274 #include "internal.h"
76275
76276 @@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
76277
76278 __page_cache_release(page);
76279 dtor = get_compound_page_dtor(page);
76280 + if (!PageHuge(page))
76281 + BUG_ON(dtor != free_compound_page);
76282 (*dtor)(page);
76283 }
76284
76285 diff --git a/mm/swapfile.c b/mm/swapfile.c
76286 index 14e254c..a6af32c 100644
76287 --- a/mm/swapfile.c
76288 +++ b/mm/swapfile.c
76289 @@ -64,7 +64,7 @@ static DEFINE_MUTEX(swapon_mutex);
76290
76291 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
76292 /* Activity counter to indicate that a swapon or swapoff has occurred */
76293 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
76294 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
76295
76296 static inline unsigned char swap_count(unsigned char ent)
76297 {
76298 @@ -1603,7 +1603,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
76299 }
76300 filp_close(swap_file, NULL);
76301 err = 0;
76302 - atomic_inc(&proc_poll_event);
76303 + atomic_inc_unchecked(&proc_poll_event);
76304 wake_up_interruptible(&proc_poll_wait);
76305
76306 out_dput:
76307 @@ -1619,8 +1619,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
76308
76309 poll_wait(file, &proc_poll_wait, wait);
76310
76311 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
76312 - seq->poll_event = atomic_read(&proc_poll_event);
76313 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
76314 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
76315 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
76316 }
76317
76318 @@ -1718,7 +1718,7 @@ static int swaps_open(struct inode *inode, struct file *file)
76319 return ret;
76320
76321 seq = file->private_data;
76322 - seq->poll_event = atomic_read(&proc_poll_event);
76323 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
76324 return 0;
76325 }
76326
76327 @@ -2060,7 +2060,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
76328 (frontswap_map) ? "FS" : "");
76329
76330 mutex_unlock(&swapon_mutex);
76331 - atomic_inc(&proc_poll_event);
76332 + atomic_inc_unchecked(&proc_poll_event);
76333 wake_up_interruptible(&proc_poll_wait);
76334
76335 if (S_ISREG(inode->i_mode))
76336 diff --git a/mm/util.c b/mm/util.c
76337 index 8c7265a..c96d884 100644
76338 --- a/mm/util.c
76339 +++ b/mm/util.c
76340 @@ -285,6 +285,12 @@ done:
76341 void arch_pick_mmap_layout(struct mm_struct *mm)
76342 {
76343 mm->mmap_base = TASK_UNMAPPED_BASE;
76344 +
76345 +#ifdef CONFIG_PAX_RANDMMAP
76346 + if (mm->pax_flags & MF_PAX_RANDMMAP)
76347 + mm->mmap_base += mm->delta_mmap;
76348 +#endif
76349 +
76350 mm->get_unmapped_area = arch_get_unmapped_area;
76351 mm->unmap_area = arch_unmap_area;
76352 }
76353 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
76354 index 2bb90b1..3795e47 100644
76355 --- a/mm/vmalloc.c
76356 +++ b/mm/vmalloc.c
76357 @@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
76358
76359 pte = pte_offset_kernel(pmd, addr);
76360 do {
76361 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
76362 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
76363 +
76364 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
76365 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
76366 + BUG_ON(!pte_exec(*pte));
76367 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
76368 + continue;
76369 + }
76370 +#endif
76371 +
76372 + {
76373 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
76374 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
76375 + }
76376 } while (pte++, addr += PAGE_SIZE, addr != end);
76377 }
76378
76379 @@ -100,16 +111,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
76380 pte = pte_alloc_kernel(pmd, addr);
76381 if (!pte)
76382 return -ENOMEM;
76383 +
76384 + pax_open_kernel();
76385 do {
76386 struct page *page = pages[*nr];
76387
76388 - if (WARN_ON(!pte_none(*pte)))
76389 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
76390 + if (pgprot_val(prot) & _PAGE_NX)
76391 +#endif
76392 +
76393 + if (!pte_none(*pte)) {
76394 + pax_close_kernel();
76395 + WARN_ON(1);
76396 return -EBUSY;
76397 - if (WARN_ON(!page))
76398 + }
76399 + if (!page) {
76400 + pax_close_kernel();
76401 + WARN_ON(1);
76402 return -ENOMEM;
76403 + }
76404 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
76405 (*nr)++;
76406 } while (pte++, addr += PAGE_SIZE, addr != end);
76407 + pax_close_kernel();
76408 return 0;
76409 }
76410
76411 @@ -119,7 +143,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
76412 pmd_t *pmd;
76413 unsigned long next;
76414
76415 - pmd = pmd_alloc(&init_mm, pud, addr);
76416 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
76417 if (!pmd)
76418 return -ENOMEM;
76419 do {
76420 @@ -136,7 +160,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
76421 pud_t *pud;
76422 unsigned long next;
76423
76424 - pud = pud_alloc(&init_mm, pgd, addr);
76425 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
76426 if (!pud)
76427 return -ENOMEM;
76428 do {
76429 @@ -191,11 +215,20 @@ int is_vmalloc_or_module_addr(const void *x)
76430 * and fall back on vmalloc() if that fails. Others
76431 * just put it in the vmalloc space.
76432 */
76433 -#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
76434 +#ifdef CONFIG_MODULES
76435 +#ifdef MODULES_VADDR
76436 unsigned long addr = (unsigned long)x;
76437 if (addr >= MODULES_VADDR && addr < MODULES_END)
76438 return 1;
76439 #endif
76440 +
76441 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
76442 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
76443 + return 1;
76444 +#endif
76445 +
76446 +#endif
76447 +
76448 return is_vmalloc_addr(x);
76449 }
76450
76451 @@ -216,8 +249,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
76452
76453 if (!pgd_none(*pgd)) {
76454 pud_t *pud = pud_offset(pgd, addr);
76455 +#ifdef CONFIG_X86
76456 + if (!pud_large(*pud))
76457 +#endif
76458 if (!pud_none(*pud)) {
76459 pmd_t *pmd = pmd_offset(pud, addr);
76460 +#ifdef CONFIG_X86
76461 + if (!pmd_large(*pmd))
76462 +#endif
76463 if (!pmd_none(*pmd)) {
76464 pte_t *ptep, pte;
76465
76466 @@ -329,7 +368,7 @@ static void purge_vmap_area_lazy(void);
76467 * Allocate a region of KVA of the specified size and alignment, within the
76468 * vstart and vend.
76469 */
76470 -static struct vmap_area *alloc_vmap_area(unsigned long size,
76471 +static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
76472 unsigned long align,
76473 unsigned long vstart, unsigned long vend,
76474 int node, gfp_t gfp_mask)
76475 @@ -1328,6 +1367,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
76476 struct vm_struct *area;
76477
76478 BUG_ON(in_interrupt());
76479 +
76480 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
76481 + if (flags & VM_KERNEXEC) {
76482 + if (start != VMALLOC_START || end != VMALLOC_END)
76483 + return NULL;
76484 + start = (unsigned long)MODULES_EXEC_VADDR;
76485 + end = (unsigned long)MODULES_EXEC_END;
76486 + }
76487 +#endif
76488 +
76489 if (flags & VM_IOREMAP) {
76490 int bit = fls(size);
76491
76492 @@ -1568,6 +1617,11 @@ void *vmap(struct page **pages, unsigned int count,
76493 if (count > totalram_pages)
76494 return NULL;
76495
76496 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
76497 + if (!(pgprot_val(prot) & _PAGE_NX))
76498 + flags |= VM_KERNEXEC;
76499 +#endif
76500 +
76501 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
76502 __builtin_return_address(0));
76503 if (!area)
76504 @@ -1669,6 +1723,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
76505 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
76506 goto fail;
76507
76508 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
76509 + if (!(pgprot_val(prot) & _PAGE_NX))
76510 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
76511 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
76512 + else
76513 +#endif
76514 +
76515 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
76516 start, end, node, gfp_mask, caller);
76517 if (!area)
76518 @@ -1842,10 +1903,9 @@ EXPORT_SYMBOL(vzalloc_node);
76519 * For tight control over page level allocator and protection flags
76520 * use __vmalloc() instead.
76521 */
76522 -
76523 void *vmalloc_exec(unsigned long size)
76524 {
76525 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
76526 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
76527 -1, __builtin_return_address(0));
76528 }
76529
76530 @@ -2136,6 +2196,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
76531 unsigned long uaddr = vma->vm_start;
76532 unsigned long usize = vma->vm_end - vma->vm_start;
76533
76534 + BUG_ON(vma->vm_mirror);
76535 +
76536 if ((PAGE_SIZE-1) & (unsigned long)addr)
76537 return -EINVAL;
76538
76539 @@ -2572,7 +2634,7 @@ static int s_show(struct seq_file *m, void *p)
76540 {
76541 struct vm_struct *v = p;
76542
76543 - seq_printf(m, "0x%p-0x%p %7ld",
76544 + seq_printf(m, "0x%pK-0x%pK %7ld",
76545 v->addr, v->addr + v->size, v->size);
76546
76547 if (v->caller)
76548 diff --git a/mm/vmscan.c b/mm/vmscan.c
76549 index 40db7d1..be5a9c1 100644
76550 --- a/mm/vmscan.c
76551 +++ b/mm/vmscan.c
76552 @@ -2383,6 +2383,19 @@ static void age_active_anon(struct zone *zone, struct scan_control *sc)
76553 } while (memcg);
76554 }
76555
76556 +static bool zone_balanced(struct zone *zone, int order,
76557 + unsigned long balance_gap, int classzone_idx)
76558 +{
76559 + if (!zone_watermark_ok_safe(zone, order, high_wmark_pages(zone) +
76560 + balance_gap, classzone_idx, 0))
76561 + return false;
76562 +
76563 + if (COMPACTION_BUILD && order && !compaction_suitable(zone, order))
76564 + return false;
76565 +
76566 + return true;
76567 +}
76568 +
76569 /*
76570 * pgdat_balanced is used when checking if a node is balanced for high-order
76571 * allocations. Only zones that meet watermarks and are in a zone allowed
76572 @@ -2461,8 +2474,7 @@ static bool prepare_kswapd_sleep(pg_data_t *pgdat, int order, long remaining,
76573 continue;
76574 }
76575
76576 - if (!zone_watermark_ok_safe(zone, order, high_wmark_pages(zone),
76577 - i, 0))
76578 + if (!zone_balanced(zone, order, 0, i))
76579 all_zones_ok = false;
76580 else
76581 balanced += zone->present_pages;
76582 @@ -2571,8 +2583,7 @@ loop_again:
76583 break;
76584 }
76585
76586 - if (!zone_watermark_ok_safe(zone, order,
76587 - high_wmark_pages(zone), 0, 0)) {
76588 + if (!zone_balanced(zone, order, 0, 0)) {
76589 end_zone = i;
76590 break;
76591 } else {
76592 @@ -2648,9 +2659,8 @@ loop_again:
76593 testorder = 0;
76594
76595 if ((buffer_heads_over_limit && is_highmem_idx(i)) ||
76596 - !zone_watermark_ok_safe(zone, testorder,
76597 - high_wmark_pages(zone) + balance_gap,
76598 - end_zone, 0)) {
76599 + !zone_balanced(zone, testorder,
76600 + balance_gap, end_zone)) {
76601 shrink_zone(zone, &sc);
76602
76603 reclaim_state->reclaimed_slab = 0;
76604 @@ -2677,8 +2687,7 @@ loop_again:
76605 continue;
76606 }
76607
76608 - if (!zone_watermark_ok_safe(zone, testorder,
76609 - high_wmark_pages(zone), end_zone, 0)) {
76610 + if (!zone_balanced(zone, testorder, 0, end_zone)) {
76611 all_zones_ok = 0;
76612 /*
76613 * We are still under min water mark. This
76614 diff --git a/mm/vmstat.c b/mm/vmstat.c
76615 index df7a674..8b4a4f3 100644
76616 --- a/mm/vmstat.c
76617 +++ b/mm/vmstat.c
76618 @@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
76619 *
76620 * vm_stat contains the global counters
76621 */
76622 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
76623 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
76624 EXPORT_SYMBOL(vm_stat);
76625
76626 #ifdef CONFIG_SMP
76627 @@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
76628 v = p->vm_stat_diff[i];
76629 p->vm_stat_diff[i] = 0;
76630 local_irq_restore(flags);
76631 - atomic_long_add(v, &zone->vm_stat[i]);
76632 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
76633 global_diff[i] += v;
76634 #ifdef CONFIG_NUMA
76635 /* 3 seconds idle till flush */
76636 @@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
76637
76638 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
76639 if (global_diff[i])
76640 - atomic_long_add(global_diff[i], &vm_stat[i]);
76641 + atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
76642 }
76643
76644 #endif
76645 @@ -1212,10 +1212,20 @@ static int __init setup_vmstat(void)
76646 start_cpu_timer(cpu);
76647 #endif
76648 #ifdef CONFIG_PROC_FS
76649 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
76650 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
76651 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
76652 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
76653 + {
76654 + mode_t gr_mode = S_IRUGO;
76655 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
76656 + gr_mode = S_IRUSR;
76657 +#endif
76658 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
76659 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
76660 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
76661 + proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
76662 +#else
76663 + proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
76664 +#endif
76665 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
76666 + }
76667 #endif
76668 return 0;
76669 }
76670 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
76671 index 9096bcb..43ed7bb 100644
76672 --- a/net/8021q/vlan.c
76673 +++ b/net/8021q/vlan.c
76674 @@ -557,8 +557,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
76675 err = -EPERM;
76676 if (!capable(CAP_NET_ADMIN))
76677 break;
76678 - if ((args.u.name_type >= 0) &&
76679 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
76680 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
76681 struct vlan_net *vn;
76682
76683 vn = net_generic(net, vlan_net_id);
76684 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
76685 index 6449bae..8c1f454 100644
76686 --- a/net/9p/trans_fd.c
76687 +++ b/net/9p/trans_fd.c
76688 @@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
76689 oldfs = get_fs();
76690 set_fs(get_ds());
76691 /* The cast to a user pointer is valid due to the set_fs() */
76692 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
76693 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
76694 set_fs(oldfs);
76695
76696 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
76697 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
76698 index 876fbe8..8bbea9f 100644
76699 --- a/net/atm/atm_misc.c
76700 +++ b/net/atm/atm_misc.c
76701 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
76702 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
76703 return 1;
76704 atm_return(vcc, truesize);
76705 - atomic_inc(&vcc->stats->rx_drop);
76706 + atomic_inc_unchecked(&vcc->stats->rx_drop);
76707 return 0;
76708 }
76709 EXPORT_SYMBOL(atm_charge);
76710 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
76711 }
76712 }
76713 atm_return(vcc, guess);
76714 - atomic_inc(&vcc->stats->rx_drop);
76715 + atomic_inc_unchecked(&vcc->stats->rx_drop);
76716 return NULL;
76717 }
76718 EXPORT_SYMBOL(atm_alloc_charge);
76719 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
76720
76721 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
76722 {
76723 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
76724 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
76725 __SONET_ITEMS
76726 #undef __HANDLE_ITEM
76727 }
76728 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
76729
76730 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
76731 {
76732 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
76733 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
76734 __SONET_ITEMS
76735 #undef __HANDLE_ITEM
76736 }
76737 diff --git a/net/atm/lec.h b/net/atm/lec.h
76738 index a86aff9..3a0d6f6 100644
76739 --- a/net/atm/lec.h
76740 +++ b/net/atm/lec.h
76741 @@ -48,7 +48,7 @@ struct lane2_ops {
76742 const u8 *tlvs, u32 sizeoftlvs);
76743 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
76744 const u8 *tlvs, u32 sizeoftlvs);
76745 -};
76746 +} __no_const;
76747
76748 /*
76749 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
76750 diff --git a/net/atm/mpc.h b/net/atm/mpc.h
76751 index 0919a88..a23d54e 100644
76752 --- a/net/atm/mpc.h
76753 +++ b/net/atm/mpc.h
76754 @@ -33,7 +33,7 @@ struct mpoa_client {
76755 struct mpc_parameters parameters; /* parameters for this client */
76756
76757 const struct net_device_ops *old_ops;
76758 - struct net_device_ops new_ops;
76759 + net_device_ops_no_const new_ops;
76760 };
76761
76762
76763 diff --git a/net/atm/proc.c b/net/atm/proc.c
76764 index 0d020de..011c7bb 100644
76765 --- a/net/atm/proc.c
76766 +++ b/net/atm/proc.c
76767 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
76768 const struct k_atm_aal_stats *stats)
76769 {
76770 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
76771 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
76772 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
76773 - atomic_read(&stats->rx_drop));
76774 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
76775 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
76776 + atomic_read_unchecked(&stats->rx_drop));
76777 }
76778
76779 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
76780 diff --git a/net/atm/resources.c b/net/atm/resources.c
76781 index 23f45ce..c748f1a 100644
76782 --- a/net/atm/resources.c
76783 +++ b/net/atm/resources.c
76784 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
76785 static void copy_aal_stats(struct k_atm_aal_stats *from,
76786 struct atm_aal_stats *to)
76787 {
76788 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
76789 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
76790 __AAL_STAT_ITEMS
76791 #undef __HANDLE_ITEM
76792 }
76793 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
76794 static void subtract_aal_stats(struct k_atm_aal_stats *from,
76795 struct atm_aal_stats *to)
76796 {
76797 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
76798 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
76799 __AAL_STAT_ITEMS
76800 #undef __HANDLE_ITEM
76801 }
76802 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
76803 index 469daab..262851c 100644
76804 --- a/net/batman-adv/bat_iv_ogm.c
76805 +++ b/net/batman-adv/bat_iv_ogm.c
76806 @@ -62,7 +62,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
76807
76808 /* randomize initial seqno to avoid collision */
76809 get_random_bytes(&random_seqno, sizeof(random_seqno));
76810 - atomic_set(&hard_iface->seqno, random_seqno);
76811 + atomic_set_unchecked(&hard_iface->seqno, random_seqno);
76812
76813 hard_iface->packet_len = BATADV_OGM_HLEN;
76814 hard_iface->packet_buff = kmalloc(hard_iface->packet_len, GFP_ATOMIC);
76815 @@ -600,8 +600,8 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
76816
76817 /* change sequence number to network order */
76818 batadv_ogm_packet->seqno =
76819 - htonl((uint32_t)atomic_read(&hard_iface->seqno));
76820 - atomic_inc(&hard_iface->seqno);
76821 + htonl((uint32_t)atomic_read_unchecked(&hard_iface->seqno));
76822 + atomic_inc_unchecked(&hard_iface->seqno);
76823
76824 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->ttvn);
76825 batadv_ogm_packet->tt_crc = htons(bat_priv->tt_crc);
76826 @@ -1001,7 +1001,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
76827 return;
76828
76829 /* could be changed by schedule_own_packet() */
76830 - if_incoming_seqno = atomic_read(&if_incoming->seqno);
76831 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
76832
76833 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
76834 has_directlink_flag = 1;
76835 diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
76836 index 282bf6e..4b2603d 100644
76837 --- a/net/batman-adv/hard-interface.c
76838 +++ b/net/batman-adv/hard-interface.c
76839 @@ -320,7 +320,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
76840 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
76841 dev_add_pack(&hard_iface->batman_adv_ptype);
76842
76843 - atomic_set(&hard_iface->frag_seqno, 1);
76844 + atomic_set_unchecked(&hard_iface->frag_seqno, 1);
76845 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
76846 hard_iface->net_dev->name);
76847
76848 @@ -443,7 +443,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
76849 /* This can't be called via a bat_priv callback because
76850 * we have no bat_priv yet.
76851 */
76852 - atomic_set(&hard_iface->seqno, 1);
76853 + atomic_set_unchecked(&hard_iface->seqno, 1);
76854 hard_iface->packet_buff = NULL;
76855
76856 return hard_iface;
76857 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
76858 index 21c5357..768be1a 100644
76859 --- a/net/batman-adv/soft-interface.c
76860 +++ b/net/batman-adv/soft-interface.c
76861 @@ -227,7 +227,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
76862
76863 /* set broadcast sequence number */
76864 bcast_packet->seqno =
76865 - htonl(atomic_inc_return(&bat_priv->bcast_seqno));
76866 + htonl(atomic_inc_return_unchecked(&bat_priv->bcast_seqno));
76867
76868 batadv_add_bcast_packet_to_list(bat_priv, skb, 1);
76869
76870 @@ -407,7 +407,7 @@ struct net_device *batadv_softif_create(const char *name)
76871 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
76872
76873 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
76874 - atomic_set(&bat_priv->bcast_seqno, 1);
76875 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
76876 atomic_set(&bat_priv->ttvn, 0);
76877 atomic_set(&bat_priv->tt_local_changes, 0);
76878 atomic_set(&bat_priv->tt_ogm_append_cnt, 0);
76879 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
76880 index 12635fd..d99d837 100644
76881 --- a/net/batman-adv/types.h
76882 +++ b/net/batman-adv/types.h
76883 @@ -33,8 +33,8 @@ struct batadv_hard_iface {
76884 int16_t if_num;
76885 char if_status;
76886 struct net_device *net_dev;
76887 - atomic_t seqno;
76888 - atomic_t frag_seqno;
76889 + atomic_unchecked_t seqno;
76890 + atomic_unchecked_t frag_seqno;
76891 unsigned char *packet_buff;
76892 int packet_len;
76893 struct kobject *hardif_obj;
76894 @@ -176,7 +176,7 @@ struct batadv_priv {
76895 atomic_t orig_interval; /* uint */
76896 atomic_t hop_penalty; /* uint */
76897 atomic_t log_level; /* uint */
76898 - atomic_t bcast_seqno;
76899 + atomic_unchecked_t bcast_seqno;
76900 atomic_t bcast_queue_left;
76901 atomic_t batman_queue_left;
76902 atomic_t ttvn; /* translation table version number */
76903 diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
76904 index 0016464..0ef3e53 100644
76905 --- a/net/batman-adv/unicast.c
76906 +++ b/net/batman-adv/unicast.c
76907 @@ -269,7 +269,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
76908 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
76909 frag2->flags = large_tail;
76910
76911 - seqno = atomic_add_return(2, &hard_iface->frag_seqno);
76912 + seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
76913 frag1->seqno = htons(seqno - 1);
76914 frag2->seqno = htons(seqno);
76915
76916 diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
76917 index d5ace1e..231c4bf 100644
76918 --- a/net/bluetooth/hci_sock.c
76919 +++ b/net/bluetooth/hci_sock.c
76920 @@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
76921 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
76922 }
76923
76924 - len = min_t(unsigned int, len, sizeof(uf));
76925 + len = min((size_t)len, sizeof(uf));
76926 if (copy_from_user(&uf, optval, len)) {
76927 err = -EFAULT;
76928 break;
76929 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
76930 index 38c00f1..e9d566e 100644
76931 --- a/net/bluetooth/l2cap_core.c
76932 +++ b/net/bluetooth/l2cap_core.c
76933 @@ -3165,8 +3165,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
76934 break;
76935
76936 case L2CAP_CONF_RFC:
76937 - if (olen == sizeof(rfc))
76938 - memcpy(&rfc, (void *)val, olen);
76939 + if (olen != sizeof(rfc))
76940 + break;
76941 +
76942 + memcpy(&rfc, (void *)val, olen);
76943
76944 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
76945 rfc.mode != chan->mode)
76946 diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
76947 index 34bbe1c..451c19b 100644
76948 --- a/net/bluetooth/l2cap_sock.c
76949 +++ b/net/bluetooth/l2cap_sock.c
76950 @@ -467,7 +467,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
76951 struct sock *sk = sock->sk;
76952 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
76953 struct l2cap_options opts;
76954 - int len, err = 0;
76955 + int err = 0;
76956 + size_t len = optlen;
76957 u32 opt;
76958
76959 BT_DBG("sk %p", sk);
76960 @@ -489,7 +490,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
76961 opts.max_tx = chan->max_tx;
76962 opts.txwin_size = chan->tx_win;
76963
76964 - len = min_t(unsigned int, sizeof(opts), optlen);
76965 + len = min(sizeof(opts), len);
76966 if (copy_from_user((char *) &opts, optval, len)) {
76967 err = -EFAULT;
76968 break;
76969 @@ -567,7 +568,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
76970 struct bt_security sec;
76971 struct bt_power pwr;
76972 struct l2cap_conn *conn;
76973 - int len, err = 0;
76974 + int err = 0;
76975 + size_t len = optlen;
76976 u32 opt;
76977
76978 BT_DBG("sk %p", sk);
76979 @@ -590,7 +592,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
76980
76981 sec.level = BT_SECURITY_LOW;
76982
76983 - len = min_t(unsigned int, sizeof(sec), optlen);
76984 + len = min(sizeof(sec), len);
76985 if (copy_from_user((char *) &sec, optval, len)) {
76986 err = -EFAULT;
76987 break;
76988 @@ -687,7 +689,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
76989
76990 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
76991
76992 - len = min_t(unsigned int, sizeof(pwr), optlen);
76993 + len = min(sizeof(pwr), len);
76994 if (copy_from_user((char *) &pwr, optval, len)) {
76995 err = -EFAULT;
76996 break;
76997 diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
76998 index 1a17850..65a3129 100644
76999 --- a/net/bluetooth/rfcomm/sock.c
77000 +++ b/net/bluetooth/rfcomm/sock.c
77001 @@ -667,7 +667,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
77002 struct sock *sk = sock->sk;
77003 struct bt_security sec;
77004 int err = 0;
77005 - size_t len;
77006 + size_t len = optlen;
77007 u32 opt;
77008
77009 BT_DBG("sk %p", sk);
77010 @@ -689,7 +689,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
77011
77012 sec.level = BT_SECURITY_LOW;
77013
77014 - len = min_t(unsigned int, sizeof(sec), optlen);
77015 + len = min(sizeof(sec), len);
77016 if (copy_from_user((char *) &sec, optval, len)) {
77017 err = -EFAULT;
77018 break;
77019 diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
77020 index 56f1823..da44330 100644
77021 --- a/net/bluetooth/rfcomm/tty.c
77022 +++ b/net/bluetooth/rfcomm/tty.c
77023 @@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
77024 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
77025
77026 spin_lock_irqsave(&dev->port.lock, flags);
77027 - if (dev->port.count > 0) {
77028 + if (atomic_read(&dev->port.count) > 0) {
77029 spin_unlock_irqrestore(&dev->port.lock, flags);
77030 return;
77031 }
77032 @@ -664,10 +664,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
77033 return -ENODEV;
77034
77035 BT_DBG("dev %p dst %s channel %d opened %d", dev, batostr(&dev->dst),
77036 - dev->channel, dev->port.count);
77037 + dev->channel, atomic_read(&dev->port.count));
77038
77039 spin_lock_irqsave(&dev->port.lock, flags);
77040 - if (++dev->port.count > 1) {
77041 + if (atomic_inc_return(&dev->port.count) > 1) {
77042 spin_unlock_irqrestore(&dev->port.lock, flags);
77043 return 0;
77044 }
77045 @@ -732,10 +732,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
77046 return;
77047
77048 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
77049 - dev->port.count);
77050 + atomic_read(&dev->port.count));
77051
77052 spin_lock_irqsave(&dev->port.lock, flags);
77053 - if (!--dev->port.count) {
77054 + if (!atomic_dec_return(&dev->port.count)) {
77055 spin_unlock_irqrestore(&dev->port.lock, flags);
77056 if (dev->tty_dev->parent)
77057 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
77058 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
77059 index 5fe2ff3..121d696 100644
77060 --- a/net/bridge/netfilter/ebtables.c
77061 +++ b/net/bridge/netfilter/ebtables.c
77062 @@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77063 tmp.valid_hooks = t->table->valid_hooks;
77064 }
77065 mutex_unlock(&ebt_mutex);
77066 - if (copy_to_user(user, &tmp, *len) != 0){
77067 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
77068 BUGPRINT("c2u Didn't work\n");
77069 ret = -EFAULT;
77070 break;
77071 @@ -2327,7 +2327,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
77072 goto out;
77073 tmp.valid_hooks = t->valid_hooks;
77074
77075 - if (copy_to_user(user, &tmp, *len) != 0) {
77076 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
77077 ret = -EFAULT;
77078 break;
77079 }
77080 @@ -2338,7 +2338,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
77081 tmp.entries_size = t->table->entries_size;
77082 tmp.valid_hooks = t->table->valid_hooks;
77083
77084 - if (copy_to_user(user, &tmp, *len) != 0) {
77085 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
77086 ret = -EFAULT;
77087 break;
77088 }
77089 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
77090 index 44f270f..1f5602d 100644
77091 --- a/net/caif/cfctrl.c
77092 +++ b/net/caif/cfctrl.c
77093 @@ -10,6 +10,7 @@
77094 #include <linux/spinlock.h>
77095 #include <linux/slab.h>
77096 #include <linux/pkt_sched.h>
77097 +#include <linux/sched.h>
77098 #include <net/caif/caif_layer.h>
77099 #include <net/caif/cfpkt.h>
77100 #include <net/caif/cfctrl.h>
77101 @@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
77102 memset(&dev_info, 0, sizeof(dev_info));
77103 dev_info.id = 0xff;
77104 cfsrvl_init(&this->serv, 0, &dev_info, false);
77105 - atomic_set(&this->req_seq_no, 1);
77106 - atomic_set(&this->rsp_seq_no, 1);
77107 + atomic_set_unchecked(&this->req_seq_no, 1);
77108 + atomic_set_unchecked(&this->rsp_seq_no, 1);
77109 this->serv.layer.receive = cfctrl_recv;
77110 sprintf(this->serv.layer.name, "ctrl");
77111 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
77112 @@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
77113 struct cfctrl_request_info *req)
77114 {
77115 spin_lock_bh(&ctrl->info_list_lock);
77116 - atomic_inc(&ctrl->req_seq_no);
77117 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
77118 + atomic_inc_unchecked(&ctrl->req_seq_no);
77119 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
77120 list_add_tail(&req->list, &ctrl->list);
77121 spin_unlock_bh(&ctrl->info_list_lock);
77122 }
77123 @@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
77124 if (p != first)
77125 pr_warn("Requests are not received in order\n");
77126
77127 - atomic_set(&ctrl->rsp_seq_no,
77128 + atomic_set_unchecked(&ctrl->rsp_seq_no,
77129 p->sequence_no);
77130 list_del(&p->list);
77131 goto out;
77132 diff --git a/net/can/gw.c b/net/can/gw.c
77133 index b54d5e6..91c3b25 100644
77134 --- a/net/can/gw.c
77135 +++ b/net/can/gw.c
77136 @@ -96,7 +96,7 @@ struct cf_mod {
77137 struct {
77138 void (*xor)(struct can_frame *cf, struct cgw_csum_xor *xor);
77139 void (*crc8)(struct can_frame *cf, struct cgw_csum_crc8 *crc8);
77140 - } csumfunc;
77141 + } __no_const csumfunc;
77142 };
77143
77144
77145 diff --git a/net/compat.c b/net/compat.c
77146 index 74ed1d7..3695bd9 100644
77147 --- a/net/compat.c
77148 +++ b/net/compat.c
77149 @@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
77150 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
77151 __get_user(kmsg->msg_flags, &umsg->msg_flags))
77152 return -EFAULT;
77153 - kmsg->msg_name = compat_ptr(tmp1);
77154 - kmsg->msg_iov = compat_ptr(tmp2);
77155 - kmsg->msg_control = compat_ptr(tmp3);
77156 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
77157 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
77158 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
77159 return 0;
77160 }
77161
77162 @@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
77163
77164 if (kern_msg->msg_namelen) {
77165 if (mode == VERIFY_READ) {
77166 - int err = move_addr_to_kernel(kern_msg->msg_name,
77167 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
77168 kern_msg->msg_namelen,
77169 kern_address);
77170 if (err < 0)
77171 @@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
77172 kern_msg->msg_name = NULL;
77173
77174 tot_len = iov_from_user_compat_to_kern(kern_iov,
77175 - (struct compat_iovec __user *)kern_msg->msg_iov,
77176 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
77177 kern_msg->msg_iovlen);
77178 if (tot_len >= 0)
77179 kern_msg->msg_iov = kern_iov;
77180 @@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
77181
77182 #define CMSG_COMPAT_FIRSTHDR(msg) \
77183 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
77184 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
77185 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
77186 (struct compat_cmsghdr __user *)NULL)
77187
77188 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
77189 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
77190 (ucmlen) <= (unsigned long) \
77191 ((mhdr)->msg_controllen - \
77192 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
77193 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
77194
77195 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
77196 struct compat_cmsghdr __user *cmsg, int cmsg_len)
77197 {
77198 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
77199 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
77200 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
77201 msg->msg_controllen)
77202 return NULL;
77203 return (struct compat_cmsghdr __user *)ptr;
77204 @@ -219,7 +219,7 @@ Efault:
77205
77206 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
77207 {
77208 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
77209 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
77210 struct compat_cmsghdr cmhdr;
77211 struct compat_timeval ctv;
77212 struct compat_timespec cts[3];
77213 @@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
77214
77215 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
77216 {
77217 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
77218 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
77219 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
77220 int fdnum = scm->fp->count;
77221 struct file **fp = scm->fp->fp;
77222 @@ -364,7 +364,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
77223 return -EFAULT;
77224 old_fs = get_fs();
77225 set_fs(KERNEL_DS);
77226 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
77227 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
77228 set_fs(old_fs);
77229
77230 return err;
77231 @@ -425,7 +425,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
77232 len = sizeof(ktime);
77233 old_fs = get_fs();
77234 set_fs(KERNEL_DS);
77235 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
77236 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
77237 set_fs(old_fs);
77238
77239 if (!err) {
77240 @@ -568,7 +568,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
77241 case MCAST_JOIN_GROUP:
77242 case MCAST_LEAVE_GROUP:
77243 {
77244 - struct compat_group_req __user *gr32 = (void *)optval;
77245 + struct compat_group_req __user *gr32 = (void __user *)optval;
77246 struct group_req __user *kgr =
77247 compat_alloc_user_space(sizeof(struct group_req));
77248 u32 interface;
77249 @@ -589,7 +589,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
77250 case MCAST_BLOCK_SOURCE:
77251 case MCAST_UNBLOCK_SOURCE:
77252 {
77253 - struct compat_group_source_req __user *gsr32 = (void *)optval;
77254 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
77255 struct group_source_req __user *kgsr = compat_alloc_user_space(
77256 sizeof(struct group_source_req));
77257 u32 interface;
77258 @@ -610,7 +610,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
77259 }
77260 case MCAST_MSFILTER:
77261 {
77262 - struct compat_group_filter __user *gf32 = (void *)optval;
77263 + struct compat_group_filter __user *gf32 = (void __user *)optval;
77264 struct group_filter __user *kgf;
77265 u32 interface, fmode, numsrc;
77266
77267 @@ -648,7 +648,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
77268 char __user *optval, int __user *optlen,
77269 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
77270 {
77271 - struct compat_group_filter __user *gf32 = (void *)optval;
77272 + struct compat_group_filter __user *gf32 = (void __user *)optval;
77273 struct group_filter __user *kgf;
77274 int __user *koptlen;
77275 u32 interface, fmode, numsrc;
77276 @@ -797,7 +797,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
77277
77278 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
77279 return -EINVAL;
77280 - if (copy_from_user(a, args, nas[call]))
77281 + if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
77282 return -EFAULT;
77283 a0 = a[0];
77284 a1 = a[1];
77285 diff --git a/net/core/datagram.c b/net/core/datagram.c
77286 index 0337e2b..47914a0 100644
77287 --- a/net/core/datagram.c
77288 +++ b/net/core/datagram.c
77289 @@ -289,7 +289,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
77290 }
77291
77292 kfree_skb(skb);
77293 - atomic_inc(&sk->sk_drops);
77294 + atomic_inc_unchecked(&sk->sk_drops);
77295 sk_mem_reclaim_partial(sk);
77296
77297 return err;
77298 diff --git a/net/core/dev.c b/net/core/dev.c
77299 index 1dce5b5..363a522 100644
77300 --- a/net/core/dev.c
77301 +++ b/net/core/dev.c
77302 @@ -1138,9 +1138,13 @@ void dev_load(struct net *net, const char *name)
77303 if (no_module && capable(CAP_NET_ADMIN))
77304 no_module = request_module("netdev-%s", name);
77305 if (no_module && capable(CAP_SYS_MODULE)) {
77306 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
77307 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
77308 +#else
77309 if (!request_module("%s", name))
77310 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
77311 name);
77312 +#endif
77313 }
77314 }
77315 EXPORT_SYMBOL(dev_load);
77316 @@ -1605,7 +1609,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
77317 {
77318 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
77319 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
77320 - atomic_long_inc(&dev->rx_dropped);
77321 + atomic_long_inc_unchecked(&dev->rx_dropped);
77322 kfree_skb(skb);
77323 return NET_RX_DROP;
77324 }
77325 @@ -1615,7 +1619,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
77326 nf_reset(skb);
77327
77328 if (unlikely(!is_skb_forwardable(dev, skb))) {
77329 - atomic_long_inc(&dev->rx_dropped);
77330 + atomic_long_inc_unchecked(&dev->rx_dropped);
77331 kfree_skb(skb);
77332 return NET_RX_DROP;
77333 }
77334 @@ -2071,7 +2075,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
77335
77336 struct dev_gso_cb {
77337 void (*destructor)(struct sk_buff *skb);
77338 -};
77339 +} __no_const;
77340
77341 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
77342
77343 @@ -2930,7 +2934,7 @@ enqueue:
77344
77345 local_irq_restore(flags);
77346
77347 - atomic_long_inc(&skb->dev->rx_dropped);
77348 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
77349 kfree_skb(skb);
77350 return NET_RX_DROP;
77351 }
77352 @@ -3002,7 +3006,7 @@ int netif_rx_ni(struct sk_buff *skb)
77353 }
77354 EXPORT_SYMBOL(netif_rx_ni);
77355
77356 -static void net_tx_action(struct softirq_action *h)
77357 +static void net_tx_action(void)
77358 {
77359 struct softnet_data *sd = &__get_cpu_var(softnet_data);
77360
77361 @@ -3333,7 +3337,7 @@ ncls:
77362 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
77363 } else {
77364 drop:
77365 - atomic_long_inc(&skb->dev->rx_dropped);
77366 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
77367 kfree_skb(skb);
77368 /* Jamal, now you will not able to escape explaining
77369 * me how you were going to use this. :-)
77370 @@ -3900,7 +3904,7 @@ void netif_napi_del(struct napi_struct *napi)
77371 }
77372 EXPORT_SYMBOL(netif_napi_del);
77373
77374 -static void net_rx_action(struct softirq_action *h)
77375 +static void net_rx_action(void)
77376 {
77377 struct softnet_data *sd = &__get_cpu_var(softnet_data);
77378 unsigned long time_limit = jiffies + 2;
77379 @@ -4370,8 +4374,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
77380 else
77381 seq_printf(seq, "%04x", ntohs(pt->type));
77382
77383 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77384 + seq_printf(seq, " %-8s %p\n",
77385 + pt->dev ? pt->dev->name : "", NULL);
77386 +#else
77387 seq_printf(seq, " %-8s %pF\n",
77388 pt->dev ? pt->dev->name : "", pt->func);
77389 +#endif
77390 }
77391
77392 return 0;
77393 @@ -5924,7 +5933,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
77394 } else {
77395 netdev_stats_to_stats64(storage, &dev->stats);
77396 }
77397 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
77398 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
77399 return storage;
77400 }
77401 EXPORT_SYMBOL(dev_get_stats);
77402 diff --git a/net/core/flow.c b/net/core/flow.c
77403 index e318c7e..168b1d0 100644
77404 --- a/net/core/flow.c
77405 +++ b/net/core/flow.c
77406 @@ -61,7 +61,7 @@ struct flow_cache {
77407 struct timer_list rnd_timer;
77408 };
77409
77410 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
77411 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
77412 EXPORT_SYMBOL(flow_cache_genid);
77413 static struct flow_cache flow_cache_global;
77414 static struct kmem_cache *flow_cachep __read_mostly;
77415 @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
77416
77417 static int flow_entry_valid(struct flow_cache_entry *fle)
77418 {
77419 - if (atomic_read(&flow_cache_genid) != fle->genid)
77420 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
77421 return 0;
77422 if (fle->object && !fle->object->ops->check(fle->object))
77423 return 0;
77424 @@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
77425 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
77426 fcp->hash_count++;
77427 }
77428 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
77429 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
77430 flo = fle->object;
77431 if (!flo)
77432 goto ret_object;
77433 @@ -280,7 +280,7 @@ nocache:
77434 }
77435 flo = resolver(net, key, family, dir, flo, ctx);
77436 if (fle) {
77437 - fle->genid = atomic_read(&flow_cache_genid);
77438 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
77439 if (!IS_ERR(flo))
77440 fle->object = flo;
77441 else
77442 diff --git a/net/core/iovec.c b/net/core/iovec.c
77443 index 7e7aeb0..2a998cb 100644
77444 --- a/net/core/iovec.c
77445 +++ b/net/core/iovec.c
77446 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
77447 if (m->msg_namelen) {
77448 if (mode == VERIFY_READ) {
77449 void __user *namep;
77450 - namep = (void __user __force *) m->msg_name;
77451 + namep = (void __force_user *) m->msg_name;
77452 err = move_addr_to_kernel(namep, m->msg_namelen,
77453 address);
77454 if (err < 0)
77455 @@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
77456 }
77457
77458 size = m->msg_iovlen * sizeof(struct iovec);
77459 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
77460 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
77461 return -EFAULT;
77462
77463 m->msg_iov = iov;
77464 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
77465 index 2c5a0a0..a45f90c 100644
77466 --- a/net/core/rtnetlink.c
77467 +++ b/net/core/rtnetlink.c
77468 @@ -58,7 +58,7 @@ struct rtnl_link {
77469 rtnl_doit_func doit;
77470 rtnl_dumpit_func dumpit;
77471 rtnl_calcit_func calcit;
77472 -};
77473 +} __no_const;
77474
77475 static DEFINE_MUTEX(rtnl_mutex);
77476
77477 diff --git a/net/core/scm.c b/net/core/scm.c
77478 index 040cebe..5b1e312 100644
77479 --- a/net/core/scm.c
77480 +++ b/net/core/scm.c
77481 @@ -203,7 +203,7 @@ EXPORT_SYMBOL(__scm_send);
77482 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
77483 {
77484 struct cmsghdr __user *cm
77485 - = (__force struct cmsghdr __user *)msg->msg_control;
77486 + = (struct cmsghdr __force_user *)msg->msg_control;
77487 struct cmsghdr cmhdr;
77488 int cmlen = CMSG_LEN(len);
77489 int err;
77490 @@ -226,7 +226,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
77491 err = -EFAULT;
77492 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
77493 goto out;
77494 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
77495 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
77496 goto out;
77497 cmlen = CMSG_SPACE(len);
77498 if (msg->msg_controllen < cmlen)
77499 @@ -242,7 +242,7 @@ EXPORT_SYMBOL(put_cmsg);
77500 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
77501 {
77502 struct cmsghdr __user *cm
77503 - = (__force struct cmsghdr __user*)msg->msg_control;
77504 + = (struct cmsghdr __force_user *)msg->msg_control;
77505
77506 int fdmax = 0;
77507 int fdnum = scm->fp->count;
77508 @@ -262,7 +262,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
77509 if (fdnum < fdmax)
77510 fdmax = fdnum;
77511
77512 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
77513 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
77514 i++, cmfptr++)
77515 {
77516 struct socket *sock;
77517 diff --git a/net/core/sock.c b/net/core/sock.c
77518 index a6000fb..d4aee72 100644
77519 --- a/net/core/sock.c
77520 +++ b/net/core/sock.c
77521 @@ -399,7 +399,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
77522 struct sk_buff_head *list = &sk->sk_receive_queue;
77523
77524 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
77525 - atomic_inc(&sk->sk_drops);
77526 + atomic_inc_unchecked(&sk->sk_drops);
77527 trace_sock_rcvqueue_full(sk, skb);
77528 return -ENOMEM;
77529 }
77530 @@ -409,7 +409,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
77531 return err;
77532
77533 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
77534 - atomic_inc(&sk->sk_drops);
77535 + atomic_inc_unchecked(&sk->sk_drops);
77536 return -ENOBUFS;
77537 }
77538
77539 @@ -429,7 +429,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
77540 skb_dst_force(skb);
77541
77542 spin_lock_irqsave(&list->lock, flags);
77543 - skb->dropcount = atomic_read(&sk->sk_drops);
77544 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
77545 __skb_queue_tail(list, skb);
77546 spin_unlock_irqrestore(&list->lock, flags);
77547
77548 @@ -449,7 +449,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
77549 skb->dev = NULL;
77550
77551 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
77552 - atomic_inc(&sk->sk_drops);
77553 + atomic_inc_unchecked(&sk->sk_drops);
77554 goto discard_and_relse;
77555 }
77556 if (nested)
77557 @@ -467,7 +467,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
77558 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
77559 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
77560 bh_unlock_sock(sk);
77561 - atomic_inc(&sk->sk_drops);
77562 + atomic_inc_unchecked(&sk->sk_drops);
77563 goto discard_and_relse;
77564 }
77565
77566 @@ -886,12 +886,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
77567 struct timeval tm;
77568 } v;
77569
77570 - int lv = sizeof(int);
77571 - int len;
77572 + unsigned int lv = sizeof(int);
77573 + unsigned int len;
77574
77575 if (get_user(len, optlen))
77576 return -EFAULT;
77577 - if (len < 0)
77578 + if (len > INT_MAX)
77579 return -EINVAL;
77580
77581 memset(&v, 0, sizeof(v));
77582 @@ -1039,11 +1039,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
77583
77584 case SO_PEERNAME:
77585 {
77586 - char address[128];
77587 + char address[_K_SS_MAXSIZE];
77588
77589 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
77590 return -ENOTCONN;
77591 - if (lv < len)
77592 + if (lv < len || sizeof address < len)
77593 return -EINVAL;
77594 if (copy_to_user(optval, address, len))
77595 return -EFAULT;
77596 @@ -1091,7 +1091,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
77597
77598 if (len > lv)
77599 len = lv;
77600 - if (copy_to_user(optval, &v, len))
77601 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
77602 return -EFAULT;
77603 lenout:
77604 if (put_user(len, optlen))
77605 @@ -2193,7 +2193,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
77606 */
77607 smp_wmb();
77608 atomic_set(&sk->sk_refcnt, 1);
77609 - atomic_set(&sk->sk_drops, 0);
77610 + atomic_set_unchecked(&sk->sk_drops, 0);
77611 }
77612 EXPORT_SYMBOL(sock_init_data);
77613
77614 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
77615 index 9d8755e..26de8bc 100644
77616 --- a/net/core/sock_diag.c
77617 +++ b/net/core/sock_diag.c
77618 @@ -15,20 +15,27 @@ static DEFINE_MUTEX(sock_diag_table_mutex);
77619
77620 int sock_diag_check_cookie(void *sk, __u32 *cookie)
77621 {
77622 +#ifndef CONFIG_GRKERNSEC_HIDESYM
77623 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
77624 cookie[1] != INET_DIAG_NOCOOKIE) &&
77625 ((u32)(unsigned long)sk != cookie[0] ||
77626 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
77627 return -ESTALE;
77628 else
77629 +#endif
77630 return 0;
77631 }
77632 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
77633
77634 void sock_diag_save_cookie(void *sk, __u32 *cookie)
77635 {
77636 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77637 + cookie[0] = 0;
77638 + cookie[1] = 0;
77639 +#else
77640 cookie[0] = (u32)(unsigned long)sk;
77641 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
77642 +#endif
77643 }
77644 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
77645
77646 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
77647 index a55eecc..dd8428c 100644
77648 --- a/net/decnet/sysctl_net_decnet.c
77649 +++ b/net/decnet/sysctl_net_decnet.c
77650 @@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
77651
77652 if (len > *lenp) len = *lenp;
77653
77654 - if (copy_to_user(buffer, addr, len))
77655 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
77656 return -EFAULT;
77657
77658 *lenp = len;
77659 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
77660
77661 if (len > *lenp) len = *lenp;
77662
77663 - if (copy_to_user(buffer, devname, len))
77664 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
77665 return -EFAULT;
77666
77667 *lenp = len;
77668 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
77669 index f444ac7..b7bdda9 100644
77670 --- a/net/ipv4/fib_frontend.c
77671 +++ b/net/ipv4/fib_frontend.c
77672 @@ -1020,12 +1020,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
77673 #ifdef CONFIG_IP_ROUTE_MULTIPATH
77674 fib_sync_up(dev);
77675 #endif
77676 - atomic_inc(&net->ipv4.dev_addr_genid);
77677 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
77678 rt_cache_flush(dev_net(dev));
77679 break;
77680 case NETDEV_DOWN:
77681 fib_del_ifaddr(ifa, NULL);
77682 - atomic_inc(&net->ipv4.dev_addr_genid);
77683 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
77684 if (ifa->ifa_dev->ifa_list == NULL) {
77685 /* Last address was deleted from this interface.
77686 * Disable IP.
77687 @@ -1062,7 +1062,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
77688 #ifdef CONFIG_IP_ROUTE_MULTIPATH
77689 fib_sync_up(dev);
77690 #endif
77691 - atomic_inc(&net->ipv4.dev_addr_genid);
77692 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
77693 rt_cache_flush(dev_net(dev));
77694 break;
77695 case NETDEV_DOWN:
77696 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
77697 index 9633661..4e0bc08 100644
77698 --- a/net/ipv4/fib_semantics.c
77699 +++ b/net/ipv4/fib_semantics.c
77700 @@ -767,7 +767,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
77701 nh->nh_saddr = inet_select_addr(nh->nh_dev,
77702 nh->nh_gw,
77703 nh->nh_parent->fib_scope);
77704 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
77705 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
77706
77707 return nh->nh_saddr;
77708 }
77709 diff --git a/net/ipv4/icmp.c b/net/ipv4/icmp.c
77710 index f2eccd5..17ff9fd 100644
77711 --- a/net/ipv4/icmp.c
77712 +++ b/net/ipv4/icmp.c
77713 @@ -257,7 +257,8 @@ static inline bool icmpv4_xrlim_allow(struct net *net, struct rtable *rt,
77714 struct inet_peer *peer = inet_getpeer_v4(net->ipv4.peers, fl4->daddr, 1);
77715 rc = inet_peer_xrlim_allow(peer,
77716 net->ipv4.sysctl_icmp_ratelimit);
77717 - inet_putpeer(peer);
77718 + if (peer)
77719 + inet_putpeer(peer);
77720 }
77721 out:
77722 return rc;
77723 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
77724 index 7880af9..70f92a3 100644
77725 --- a/net/ipv4/inet_hashtables.c
77726 +++ b/net/ipv4/inet_hashtables.c
77727 @@ -18,12 +18,15 @@
77728 #include <linux/sched.h>
77729 #include <linux/slab.h>
77730 #include <linux/wait.h>
77731 +#include <linux/security.h>
77732
77733 #include <net/inet_connection_sock.h>
77734 #include <net/inet_hashtables.h>
77735 #include <net/secure_seq.h>
77736 #include <net/ip.h>
77737
77738 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
77739 +
77740 /*
77741 * Allocate and initialize a new local port bind bucket.
77742 * The bindhash mutex for snum's hash chain must be held here.
77743 @@ -530,6 +533,8 @@ ok:
77744 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
77745 spin_unlock(&head->lock);
77746
77747 + gr_update_task_in_ip_table(current, inet_sk(sk));
77748 +
77749 if (tw) {
77750 inet_twsk_deschedule(tw, death_row);
77751 while (twrefcnt) {
77752 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
77753 index c7527f6..d8bba61 100644
77754 --- a/net/ipv4/inetpeer.c
77755 +++ b/net/ipv4/inetpeer.c
77756 @@ -503,8 +503,8 @@ relookup:
77757 if (p) {
77758 p->daddr = *daddr;
77759 atomic_set(&p->refcnt, 1);
77760 - atomic_set(&p->rid, 0);
77761 - atomic_set(&p->ip_id_count,
77762 + atomic_set_unchecked(&p->rid, 0);
77763 + atomic_set_unchecked(&p->ip_id_count,
77764 (daddr->family == AF_INET) ?
77765 secure_ip_id(daddr->addr.a4) :
77766 secure_ipv6_id(daddr->addr.a6));
77767 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
77768 index 8d07c97..d0812ef 100644
77769 --- a/net/ipv4/ip_fragment.c
77770 +++ b/net/ipv4/ip_fragment.c
77771 @@ -322,7 +322,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
77772 return 0;
77773
77774 start = qp->rid;
77775 - end = atomic_inc_return(&peer->rid);
77776 + end = atomic_inc_return_unchecked(&peer->rid);
77777 qp->rid = end;
77778
77779 rc = qp->q.fragments && (end - start) > max;
77780 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
77781 index 14bbfcf..644f472 100644
77782 --- a/net/ipv4/ip_sockglue.c
77783 +++ b/net/ipv4/ip_sockglue.c
77784 @@ -1151,7 +1151,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
77785 len = min_t(unsigned int, len, opt->optlen);
77786 if (put_user(len, optlen))
77787 return -EFAULT;
77788 - if (copy_to_user(optval, opt->__data, len))
77789 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
77790 + copy_to_user(optval, opt->__data, len))
77791 return -EFAULT;
77792 return 0;
77793 }
77794 @@ -1282,7 +1283,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
77795 if (sk->sk_type != SOCK_STREAM)
77796 return -ENOPROTOOPT;
77797
77798 - msg.msg_control = optval;
77799 + msg.msg_control = (void __force_kernel *)optval;
77800 msg.msg_controllen = len;
77801 msg.msg_flags = flags;
77802
77803 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
77804 index 67e8a6b..386764d 100644
77805 --- a/net/ipv4/ipconfig.c
77806 +++ b/net/ipv4/ipconfig.c
77807 @@ -321,7 +321,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
77808
77809 mm_segment_t oldfs = get_fs();
77810 set_fs(get_ds());
77811 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
77812 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
77813 set_fs(oldfs);
77814 return res;
77815 }
77816 @@ -332,7 +332,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
77817
77818 mm_segment_t oldfs = get_fs();
77819 set_fs(get_ds());
77820 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
77821 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
77822 set_fs(oldfs);
77823 return res;
77824 }
77825 @@ -343,7 +343,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
77826
77827 mm_segment_t oldfs = get_fs();
77828 set_fs(get_ds());
77829 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
77830 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
77831 set_fs(oldfs);
77832 return res;
77833 }
77834 diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c
77835 index ebdf06f..f797f59 100644
77836 --- a/net/ipv4/ipmr.c
77837 +++ b/net/ipv4/ipmr.c
77838 @@ -1318,6 +1318,10 @@ int ip_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, unsi
77839 if (get_user(v, (u32 __user *)optval))
77840 return -EFAULT;
77841
77842 + /* "pimreg%u" should not exceed 16 bytes (IFNAMSIZ) */
77843 + if (v != RT_TABLE_DEFAULT && v >= 1000000000)
77844 + return -EINVAL;
77845 +
77846 rtnl_lock();
77847 ret = 0;
77848 if (sk == rtnl_dereference(mrt->mroute_sk)) {
77849 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
77850 index 97e61ea..cac1bbb 100644
77851 --- a/net/ipv4/netfilter/arp_tables.c
77852 +++ b/net/ipv4/netfilter/arp_tables.c
77853 @@ -879,14 +879,14 @@ static int compat_table_info(const struct xt_table_info *info,
77854 #endif
77855
77856 static int get_info(struct net *net, void __user *user,
77857 - const int *len, int compat)
77858 + int len, int compat)
77859 {
77860 char name[XT_TABLE_MAXNAMELEN];
77861 struct xt_table *t;
77862 int ret;
77863
77864 - if (*len != sizeof(struct arpt_getinfo)) {
77865 - duprintf("length %u != %Zu\n", *len,
77866 + if (len != sizeof(struct arpt_getinfo)) {
77867 + duprintf("length %u != %Zu\n", len,
77868 sizeof(struct arpt_getinfo));
77869 return -EINVAL;
77870 }
77871 @@ -923,7 +923,7 @@ static int get_info(struct net *net, void __user *user,
77872 info.size = private->size;
77873 strcpy(info.name, name);
77874
77875 - if (copy_to_user(user, &info, *len) != 0)
77876 + if (copy_to_user(user, &info, len) != 0)
77877 ret = -EFAULT;
77878 else
77879 ret = 0;
77880 @@ -1682,7 +1682,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
77881
77882 switch (cmd) {
77883 case ARPT_SO_GET_INFO:
77884 - ret = get_info(sock_net(sk), user, len, 1);
77885 + ret = get_info(sock_net(sk), user, *len, 1);
77886 break;
77887 case ARPT_SO_GET_ENTRIES:
77888 ret = compat_get_entries(sock_net(sk), user, len);
77889 @@ -1727,7 +1727,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
77890
77891 switch (cmd) {
77892 case ARPT_SO_GET_INFO:
77893 - ret = get_info(sock_net(sk), user, len, 0);
77894 + ret = get_info(sock_net(sk), user, *len, 0);
77895 break;
77896
77897 case ARPT_SO_GET_ENTRIES:
77898 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
77899 index 170b1fd..6105b91 100644
77900 --- a/net/ipv4/netfilter/ip_tables.c
77901 +++ b/net/ipv4/netfilter/ip_tables.c
77902 @@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
77903 #endif
77904
77905 static int get_info(struct net *net, void __user *user,
77906 - const int *len, int compat)
77907 + int len, int compat)
77908 {
77909 char name[XT_TABLE_MAXNAMELEN];
77910 struct xt_table *t;
77911 int ret;
77912
77913 - if (*len != sizeof(struct ipt_getinfo)) {
77914 - duprintf("length %u != %zu\n", *len,
77915 + if (len != sizeof(struct ipt_getinfo)) {
77916 + duprintf("length %u != %zu\n", len,
77917 sizeof(struct ipt_getinfo));
77918 return -EINVAL;
77919 }
77920 @@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
77921 info.size = private->size;
77922 strcpy(info.name, name);
77923
77924 - if (copy_to_user(user, &info, *len) != 0)
77925 + if (copy_to_user(user, &info, len) != 0)
77926 ret = -EFAULT;
77927 else
77928 ret = 0;
77929 @@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77930
77931 switch (cmd) {
77932 case IPT_SO_GET_INFO:
77933 - ret = get_info(sock_net(sk), user, len, 1);
77934 + ret = get_info(sock_net(sk), user, *len, 1);
77935 break;
77936 case IPT_SO_GET_ENTRIES:
77937 ret = compat_get_entries(sock_net(sk), user, len);
77938 @@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77939
77940 switch (cmd) {
77941 case IPT_SO_GET_INFO:
77942 - ret = get_info(sock_net(sk), user, len, 0);
77943 + ret = get_info(sock_net(sk), user, *len, 0);
77944 break;
77945
77946 case IPT_SO_GET_ENTRIES:
77947 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
77948 index 6232d47..6b88607 100644
77949 --- a/net/ipv4/ping.c
77950 +++ b/net/ipv4/ping.c
77951 @@ -847,7 +847,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
77952 sk_rmem_alloc_get(sp),
77953 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
77954 atomic_read(&sp->sk_refcnt), sp,
77955 - atomic_read(&sp->sk_drops), len);
77956 + atomic_read_unchecked(&sp->sk_drops), len);
77957 }
77958
77959 static int ping_seq_show(struct seq_file *seq, void *v)
77960 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
77961 index d23c657..cb69cc2 100644
77962 --- a/net/ipv4/raw.c
77963 +++ b/net/ipv4/raw.c
77964 @@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
77965 int raw_rcv(struct sock *sk, struct sk_buff *skb)
77966 {
77967 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
77968 - atomic_inc(&sk->sk_drops);
77969 + atomic_inc_unchecked(&sk->sk_drops);
77970 kfree_skb(skb);
77971 return NET_RX_DROP;
77972 }
77973 @@ -747,16 +747,20 @@ static int raw_init(struct sock *sk)
77974
77975 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
77976 {
77977 + struct icmp_filter filter;
77978 +
77979 if (optlen > sizeof(struct icmp_filter))
77980 optlen = sizeof(struct icmp_filter);
77981 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
77982 + if (copy_from_user(&filter, optval, optlen))
77983 return -EFAULT;
77984 + raw_sk(sk)->filter = filter;
77985 return 0;
77986 }
77987
77988 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
77989 {
77990 int len, ret = -EFAULT;
77991 + struct icmp_filter filter;
77992
77993 if (get_user(len, optlen))
77994 goto out;
77995 @@ -766,8 +770,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
77996 if (len > sizeof(struct icmp_filter))
77997 len = sizeof(struct icmp_filter);
77998 ret = -EFAULT;
77999 - if (put_user(len, optlen) ||
78000 - copy_to_user(optval, &raw_sk(sk)->filter, len))
78001 + filter = raw_sk(sk)->filter;
78002 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
78003 goto out;
78004 ret = 0;
78005 out: return ret;
78006 @@ -995,7 +999,13 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
78007 sk_wmem_alloc_get(sp),
78008 sk_rmem_alloc_get(sp),
78009 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
78010 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
78011 + atomic_read(&sp->sk_refcnt),
78012 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78013 + NULL,
78014 +#else
78015 + sp,
78016 +#endif
78017 + atomic_read_unchecked(&sp->sk_drops));
78018 }
78019
78020 static int raw_seq_show(struct seq_file *seq, void *v)
78021 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
78022 index c017cb1..9eb15b7d 100644
78023 --- a/net/ipv4/route.c
78024 +++ b/net/ipv4/route.c
78025 @@ -2526,7 +2526,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
78026
78027 static __net_init int rt_genid_init(struct net *net)
78028 {
78029 - atomic_set(&net->rt_genid, 0);
78030 + atomic_set_unchecked(&net->rt_genid, 0);
78031 get_random_bytes(&net->ipv4.dev_addr_genid,
78032 sizeof(net->ipv4.dev_addr_genid));
78033 return 0;
78034 diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
78035 index c92c4da..f19e3ec 100644
78036 --- a/net/ipv4/tcp_input.c
78037 +++ b/net/ipv4/tcp_input.c
78038 @@ -4731,7 +4731,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
78039 * simplifies code)
78040 */
78041 static void
78042 -tcp_collapse(struct sock *sk, struct sk_buff_head *list,
78043 +__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
78044 struct sk_buff *head, struct sk_buff *tail,
78045 u32 start, u32 end)
78046 {
78047 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
78048 index db7bfad..bfea796 100644
78049 --- a/net/ipv4/tcp_ipv4.c
78050 +++ b/net/ipv4/tcp_ipv4.c
78051 @@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
78052 EXPORT_SYMBOL(sysctl_tcp_low_latency);
78053
78054
78055 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78056 +extern int grsec_enable_blackhole;
78057 +#endif
78058 +
78059 #ifdef CONFIG_TCP_MD5SIG
78060 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
78061 __be32 daddr, __be32 saddr, const struct tcphdr *th);
78062 @@ -1664,6 +1668,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
78063 return 0;
78064
78065 reset:
78066 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78067 + if (!grsec_enable_blackhole)
78068 +#endif
78069 tcp_v4_send_reset(rsk, skb);
78070 discard:
78071 kfree_skb(skb);
78072 @@ -1764,12 +1771,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
78073 TCP_SKB_CB(skb)->sacked = 0;
78074
78075 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
78076 - if (!sk)
78077 + if (!sk) {
78078 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78079 + ret = 1;
78080 +#endif
78081 goto no_tcp_socket;
78082 -
78083 + }
78084 process:
78085 - if (sk->sk_state == TCP_TIME_WAIT)
78086 + if (sk->sk_state == TCP_TIME_WAIT) {
78087 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78088 + ret = 2;
78089 +#endif
78090 goto do_time_wait;
78091 + }
78092
78093 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
78094 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
78095 @@ -1820,6 +1834,10 @@ no_tcp_socket:
78096 bad_packet:
78097 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
78098 } else {
78099 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78100 + if (!grsec_enable_blackhole || (ret == 1 &&
78101 + (skb->dev->flags & IFF_LOOPBACK)))
78102 +#endif
78103 tcp_v4_send_reset(NULL, skb);
78104 }
78105
78106 @@ -2415,7 +2433,11 @@ static void get_openreq4(const struct sock *sk, const struct request_sock *req,
78107 0, /* non standard timer */
78108 0, /* open_requests have no inode */
78109 atomic_read(&sk->sk_refcnt),
78110 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78111 + NULL,
78112 +#else
78113 req,
78114 +#endif
78115 len);
78116 }
78117
78118 @@ -2465,7 +2487,12 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
78119 sock_i_uid(sk),
78120 icsk->icsk_probes_out,
78121 sock_i_ino(sk),
78122 - atomic_read(&sk->sk_refcnt), sk,
78123 + atomic_read(&sk->sk_refcnt),
78124 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78125 + NULL,
78126 +#else
78127 + sk,
78128 +#endif
78129 jiffies_to_clock_t(icsk->icsk_rto),
78130 jiffies_to_clock_t(icsk->icsk_ack.ato),
78131 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
78132 @@ -2493,7 +2520,13 @@ static void get_timewait4_sock(const struct inet_timewait_sock *tw,
78133 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK%n",
78134 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
78135 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
78136 - atomic_read(&tw->tw_refcnt), tw, len);
78137 + atomic_read(&tw->tw_refcnt),
78138 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78139 + NULL,
78140 +#else
78141 + tw,
78142 +#endif
78143 + len);
78144 }
78145
78146 #define TMPSZ 150
78147 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
78148 index 6ff7f10..38de56e 100644
78149 --- a/net/ipv4/tcp_minisocks.c
78150 +++ b/net/ipv4/tcp_minisocks.c
78151 @@ -27,6 +27,10 @@
78152 #include <net/inet_common.h>
78153 #include <net/xfrm.h>
78154
78155 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78156 +extern int grsec_enable_blackhole;
78157 +#endif
78158 +
78159 int sysctl_tcp_syncookies __read_mostly = 1;
78160 EXPORT_SYMBOL(sysctl_tcp_syncookies);
78161
78162 @@ -707,6 +711,10 @@ listen_overflow:
78163
78164 embryonic_reset:
78165 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
78166 +
78167 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78168 + if (!grsec_enable_blackhole)
78169 +#endif
78170 if (!(flg & TCP_FLAG_RST))
78171 req->rsk_ops->send_reset(sk, skb);
78172
78173 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
78174 index 4526fe6..1a34e43 100644
78175 --- a/net/ipv4/tcp_probe.c
78176 +++ b/net/ipv4/tcp_probe.c
78177 @@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
78178 if (cnt + width >= len)
78179 break;
78180
78181 - if (copy_to_user(buf + cnt, tbuf, width))
78182 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
78183 return -EFAULT;
78184 cnt += width;
78185 }
78186 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
78187 index b774a03..3873efe 100644
78188 --- a/net/ipv4/tcp_timer.c
78189 +++ b/net/ipv4/tcp_timer.c
78190 @@ -22,6 +22,10 @@
78191 #include <linux/gfp.h>
78192 #include <net/tcp.h>
78193
78194 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78195 +extern int grsec_lastack_retries;
78196 +#endif
78197 +
78198 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
78199 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
78200 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
78201 @@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
78202 }
78203 }
78204
78205 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78206 + if ((sk->sk_state == TCP_LAST_ACK) &&
78207 + (grsec_lastack_retries > 0) &&
78208 + (grsec_lastack_retries < retry_until))
78209 + retry_until = grsec_lastack_retries;
78210 +#endif
78211 +
78212 if (retransmits_timed_out(sk, retry_until,
78213 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
78214 /* Has it gone just too far? */
78215 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
78216 index 2814f66..fa2b223 100644
78217 --- a/net/ipv4/udp.c
78218 +++ b/net/ipv4/udp.c
78219 @@ -87,6 +87,7 @@
78220 #include <linux/types.h>
78221 #include <linux/fcntl.h>
78222 #include <linux/module.h>
78223 +#include <linux/security.h>
78224 #include <linux/socket.h>
78225 #include <linux/sockios.h>
78226 #include <linux/igmp.h>
78227 @@ -111,6 +112,10 @@
78228 #include <trace/events/skb.h>
78229 #include "udp_impl.h"
78230
78231 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78232 +extern int grsec_enable_blackhole;
78233 +#endif
78234 +
78235 struct udp_table udp_table __read_mostly;
78236 EXPORT_SYMBOL(udp_table);
78237
78238 @@ -569,6 +574,9 @@ found:
78239 return s;
78240 }
78241
78242 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
78243 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
78244 +
78245 /*
78246 * This routine is called by the ICMP module when it gets some
78247 * sort of error condition. If err < 0 then the socket should
78248 @@ -864,9 +872,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
78249 dport = usin->sin_port;
78250 if (dport == 0)
78251 return -EINVAL;
78252 +
78253 + err = gr_search_udp_sendmsg(sk, usin);
78254 + if (err)
78255 + return err;
78256 } else {
78257 if (sk->sk_state != TCP_ESTABLISHED)
78258 return -EDESTADDRREQ;
78259 +
78260 + err = gr_search_udp_sendmsg(sk, NULL);
78261 + if (err)
78262 + return err;
78263 +
78264 daddr = inet->inet_daddr;
78265 dport = inet->inet_dport;
78266 /* Open fast path for connected socket.
78267 @@ -1108,7 +1125,7 @@ static unsigned int first_packet_length(struct sock *sk)
78268 udp_lib_checksum_complete(skb)) {
78269 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
78270 IS_UDPLITE(sk));
78271 - atomic_inc(&sk->sk_drops);
78272 + atomic_inc_unchecked(&sk->sk_drops);
78273 __skb_unlink(skb, rcvq);
78274 __skb_queue_tail(&list_kill, skb);
78275 }
78276 @@ -1194,6 +1211,10 @@ try_again:
78277 if (!skb)
78278 goto out;
78279
78280 + err = gr_search_udp_recvmsg(sk, skb);
78281 + if (err)
78282 + goto out_free;
78283 +
78284 ulen = skb->len - sizeof(struct udphdr);
78285 copied = len;
78286 if (copied > ulen)
78287 @@ -1227,7 +1248,7 @@ try_again:
78288 if (unlikely(err)) {
78289 trace_kfree_skb(skb, udp_recvmsg);
78290 if (!peeked) {
78291 - atomic_inc(&sk->sk_drops);
78292 + atomic_inc_unchecked(&sk->sk_drops);
78293 UDP_INC_STATS_USER(sock_net(sk),
78294 UDP_MIB_INERRORS, is_udplite);
78295 }
78296 @@ -1510,7 +1531,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
78297
78298 drop:
78299 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
78300 - atomic_inc(&sk->sk_drops);
78301 + atomic_inc_unchecked(&sk->sk_drops);
78302 kfree_skb(skb);
78303 return -1;
78304 }
78305 @@ -1529,7 +1550,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
78306 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
78307
78308 if (!skb1) {
78309 - atomic_inc(&sk->sk_drops);
78310 + atomic_inc_unchecked(&sk->sk_drops);
78311 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
78312 IS_UDPLITE(sk));
78313 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
78314 @@ -1698,6 +1719,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
78315 goto csum_error;
78316
78317 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
78318 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78319 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
78320 +#endif
78321 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
78322
78323 /*
78324 @@ -2116,8 +2140,13 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
78325 sk_wmem_alloc_get(sp),
78326 sk_rmem_alloc_get(sp),
78327 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
78328 - atomic_read(&sp->sk_refcnt), sp,
78329 - atomic_read(&sp->sk_drops), len);
78330 + atomic_read(&sp->sk_refcnt),
78331 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78332 + NULL,
78333 +#else
78334 + sp,
78335 +#endif
78336 + atomic_read_unchecked(&sp->sk_drops), len);
78337 }
78338
78339 int udp4_seq_show(struct seq_file *seq, void *v)
78340 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
78341 index b10374d..0baa1f9 100644
78342 --- a/net/ipv6/addrconf.c
78343 +++ b/net/ipv6/addrconf.c
78344 @@ -2144,7 +2144,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
78345 p.iph.ihl = 5;
78346 p.iph.protocol = IPPROTO_IPV6;
78347 p.iph.ttl = 64;
78348 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
78349 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
78350
78351 if (ops->ndo_do_ioctl) {
78352 mm_segment_t oldfs = get_fs();
78353 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
78354 index e02faed..9780f28 100644
78355 --- a/net/ipv6/ipv6_sockglue.c
78356 +++ b/net/ipv6/ipv6_sockglue.c
78357 @@ -990,7 +990,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
78358 if (sk->sk_type != SOCK_STREAM)
78359 return -ENOPROTOOPT;
78360
78361 - msg.msg_control = optval;
78362 + msg.msg_control = (void __force_kernel *)optval;
78363 msg.msg_controllen = len;
78364 msg.msg_flags = flags;
78365
78366 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
78367 index d7cb045..8c0ded6 100644
78368 --- a/net/ipv6/netfilter/ip6_tables.c
78369 +++ b/net/ipv6/netfilter/ip6_tables.c
78370 @@ -1078,14 +1078,14 @@ static int compat_table_info(const struct xt_table_info *info,
78371 #endif
78372
78373 static int get_info(struct net *net, void __user *user,
78374 - const int *len, int compat)
78375 + int len, int compat)
78376 {
78377 char name[XT_TABLE_MAXNAMELEN];
78378 struct xt_table *t;
78379 int ret;
78380
78381 - if (*len != sizeof(struct ip6t_getinfo)) {
78382 - duprintf("length %u != %zu\n", *len,
78383 + if (len != sizeof(struct ip6t_getinfo)) {
78384 + duprintf("length %u != %zu\n", len,
78385 sizeof(struct ip6t_getinfo));
78386 return -EINVAL;
78387 }
78388 @@ -1122,7 +1122,7 @@ static int get_info(struct net *net, void __user *user,
78389 info.size = private->size;
78390 strcpy(info.name, name);
78391
78392 - if (copy_to_user(user, &info, *len) != 0)
78393 + if (copy_to_user(user, &info, len) != 0)
78394 ret = -EFAULT;
78395 else
78396 ret = 0;
78397 @@ -1976,7 +1976,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
78398
78399 switch (cmd) {
78400 case IP6T_SO_GET_INFO:
78401 - ret = get_info(sock_net(sk), user, len, 1);
78402 + ret = get_info(sock_net(sk), user, *len, 1);
78403 break;
78404 case IP6T_SO_GET_ENTRIES:
78405 ret = compat_get_entries(sock_net(sk), user, len);
78406 @@ -2023,7 +2023,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
78407
78408 switch (cmd) {
78409 case IP6T_SO_GET_INFO:
78410 - ret = get_info(sock_net(sk), user, len, 0);
78411 + ret = get_info(sock_net(sk), user, *len, 0);
78412 break;
78413
78414 case IP6T_SO_GET_ENTRIES:
78415 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
78416 index 4a5f78b..3f22ebe 100644
78417 --- a/net/ipv6/raw.c
78418 +++ b/net/ipv6/raw.c
78419 @@ -379,7 +379,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
78420 {
78421 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
78422 skb_checksum_complete(skb)) {
78423 - atomic_inc(&sk->sk_drops);
78424 + atomic_inc_unchecked(&sk->sk_drops);
78425 kfree_skb(skb);
78426 return NET_RX_DROP;
78427 }
78428 @@ -407,7 +407,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
78429 struct raw6_sock *rp = raw6_sk(sk);
78430
78431 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
78432 - atomic_inc(&sk->sk_drops);
78433 + atomic_inc_unchecked(&sk->sk_drops);
78434 kfree_skb(skb);
78435 return NET_RX_DROP;
78436 }
78437 @@ -431,7 +431,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
78438
78439 if (inet->hdrincl) {
78440 if (skb_checksum_complete(skb)) {
78441 - atomic_inc(&sk->sk_drops);
78442 + atomic_inc_unchecked(&sk->sk_drops);
78443 kfree_skb(skb);
78444 return NET_RX_DROP;
78445 }
78446 @@ -604,7 +604,7 @@ out:
78447 return err;
78448 }
78449
78450 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
78451 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
78452 struct flowi6 *fl6, struct dst_entry **dstp,
78453 unsigned int flags)
78454 {
78455 @@ -916,12 +916,15 @@ do_confirm:
78456 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
78457 char __user *optval, int optlen)
78458 {
78459 + struct icmp6_filter filter;
78460 +
78461 switch (optname) {
78462 case ICMPV6_FILTER:
78463 if (optlen > sizeof(struct icmp6_filter))
78464 optlen = sizeof(struct icmp6_filter);
78465 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
78466 + if (copy_from_user(&filter, optval, optlen))
78467 return -EFAULT;
78468 + raw6_sk(sk)->filter = filter;
78469 return 0;
78470 default:
78471 return -ENOPROTOOPT;
78472 @@ -934,6 +937,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
78473 char __user *optval, int __user *optlen)
78474 {
78475 int len;
78476 + struct icmp6_filter filter;
78477
78478 switch (optname) {
78479 case ICMPV6_FILTER:
78480 @@ -945,7 +949,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
78481 len = sizeof(struct icmp6_filter);
78482 if (put_user(len, optlen))
78483 return -EFAULT;
78484 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
78485 + filter = raw6_sk(sk)->filter;
78486 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
78487 return -EFAULT;
78488 return 0;
78489 default:
78490 @@ -1252,7 +1257,13 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
78491 0, 0L, 0,
78492 sock_i_uid(sp), 0,
78493 sock_i_ino(sp),
78494 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
78495 + atomic_read(&sp->sk_refcnt),
78496 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78497 + NULL,
78498 +#else
78499 + sp,
78500 +#endif
78501 + atomic_read_unchecked(&sp->sk_drops));
78502 }
78503
78504 static int raw6_seq_show(struct seq_file *seq, void *v)
78505 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
78506 index 7e32d42..5d975ba 100644
78507 --- a/net/ipv6/tcp_ipv6.c
78508 +++ b/net/ipv6/tcp_ipv6.c
78509 @@ -106,6 +106,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
78510 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
78511 }
78512
78513 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78514 +extern int grsec_enable_blackhole;
78515 +#endif
78516 +
78517 static void tcp_v6_hash(struct sock *sk)
78518 {
78519 if (sk->sk_state != TCP_CLOSE) {
78520 @@ -1511,6 +1515,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
78521 return 0;
78522
78523 reset:
78524 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78525 + if (!grsec_enable_blackhole)
78526 +#endif
78527 tcp_v6_send_reset(sk, skb);
78528 discard:
78529 if (opt_skb)
78530 @@ -1592,12 +1599,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
78531 TCP_SKB_CB(skb)->sacked = 0;
78532
78533 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
78534 - if (!sk)
78535 + if (!sk) {
78536 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78537 + ret = 1;
78538 +#endif
78539 goto no_tcp_socket;
78540 + }
78541
78542 process:
78543 - if (sk->sk_state == TCP_TIME_WAIT)
78544 + if (sk->sk_state == TCP_TIME_WAIT) {
78545 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78546 + ret = 2;
78547 +#endif
78548 goto do_time_wait;
78549 + }
78550
78551 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
78552 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
78553 @@ -1646,6 +1661,10 @@ no_tcp_socket:
78554 bad_packet:
78555 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
78556 } else {
78557 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78558 + if (!grsec_enable_blackhole || (ret == 1 &&
78559 + (skb->dev->flags & IFF_LOOPBACK)))
78560 +#endif
78561 tcp_v6_send_reset(NULL, skb);
78562 }
78563
78564 @@ -1857,7 +1876,13 @@ static void get_openreq6(struct seq_file *seq,
78565 uid,
78566 0, /* non standard timer */
78567 0, /* open_requests have no inode */
78568 - 0, req);
78569 + 0,
78570 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78571 + NULL
78572 +#else
78573 + req
78574 +#endif
78575 + );
78576 }
78577
78578 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
78579 @@ -1907,7 +1932,12 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
78580 sock_i_uid(sp),
78581 icsk->icsk_probes_out,
78582 sock_i_ino(sp),
78583 - atomic_read(&sp->sk_refcnt), sp,
78584 + atomic_read(&sp->sk_refcnt),
78585 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78586 + NULL,
78587 +#else
78588 + sp,
78589 +#endif
78590 jiffies_to_clock_t(icsk->icsk_rto),
78591 jiffies_to_clock_t(icsk->icsk_ack.ato),
78592 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
78593 @@ -1942,7 +1972,13 @@ static void get_timewait6_sock(struct seq_file *seq,
78594 dest->s6_addr32[2], dest->s6_addr32[3], destp,
78595 tw->tw_substate, 0, 0,
78596 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
78597 - atomic_read(&tw->tw_refcnt), tw);
78598 + atomic_read(&tw->tw_refcnt),
78599 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78600 + NULL
78601 +#else
78602 + tw
78603 +#endif
78604 + );
78605 }
78606
78607 static int tcp6_seq_show(struct seq_file *seq, void *v)
78608 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
78609 index 07e2bfe..328dae8 100644
78610 --- a/net/ipv6/udp.c
78611 +++ b/net/ipv6/udp.c
78612 @@ -51,6 +51,10 @@
78613 #include <trace/events/skb.h>
78614 #include "udp_impl.h"
78615
78616 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78617 +extern int grsec_enable_blackhole;
78618 +#endif
78619 +
78620 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
78621 {
78622 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
78623 @@ -395,7 +399,7 @@ try_again:
78624 if (unlikely(err)) {
78625 trace_kfree_skb(skb, udpv6_recvmsg);
78626 if (!peeked) {
78627 - atomic_inc(&sk->sk_drops);
78628 + atomic_inc_unchecked(&sk->sk_drops);
78629 if (is_udp4)
78630 UDP_INC_STATS_USER(sock_net(sk),
78631 UDP_MIB_INERRORS,
78632 @@ -633,7 +637,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
78633 return rc;
78634 drop:
78635 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
78636 - atomic_inc(&sk->sk_drops);
78637 + atomic_inc_unchecked(&sk->sk_drops);
78638 kfree_skb(skb);
78639 return -1;
78640 }
78641 @@ -691,7 +695,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
78642 if (likely(skb1 == NULL))
78643 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
78644 if (!skb1) {
78645 - atomic_inc(&sk->sk_drops);
78646 + atomic_inc_unchecked(&sk->sk_drops);
78647 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
78648 IS_UDPLITE(sk));
78649 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
78650 @@ -862,6 +866,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
78651 goto discard;
78652
78653 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
78654 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78655 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
78656 +#endif
78657 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
78658
78659 kfree_skb(skb);
78660 @@ -1471,8 +1478,13 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
78661 0, 0L, 0,
78662 sock_i_uid(sp), 0,
78663 sock_i_ino(sp),
78664 - atomic_read(&sp->sk_refcnt), sp,
78665 - atomic_read(&sp->sk_drops));
78666 + atomic_read(&sp->sk_refcnt),
78667 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78668 + NULL,
78669 +#else
78670 + sp,
78671 +#endif
78672 + atomic_read_unchecked(&sp->sk_drops));
78673 }
78674
78675 int udp6_seq_show(struct seq_file *seq, void *v)
78676 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
78677 index 6b9d5a0..4dffaf1 100644
78678 --- a/net/irda/ircomm/ircomm_tty.c
78679 +++ b/net/irda/ircomm/ircomm_tty.c
78680 @@ -281,16 +281,16 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
78681 add_wait_queue(&self->open_wait, &wait);
78682
78683 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
78684 - __FILE__,__LINE__, tty->driver->name, self->open_count );
78685 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
78686
78687 /* As far as I can see, we protect open_count - Jean II */
78688 spin_lock_irqsave(&self->spinlock, flags);
78689 if (!tty_hung_up_p(filp)) {
78690 extra_count = 1;
78691 - self->open_count--;
78692 + local_dec(&self->open_count);
78693 }
78694 spin_unlock_irqrestore(&self->spinlock, flags);
78695 - self->blocked_open++;
78696 + local_inc(&self->blocked_open);
78697
78698 while (1) {
78699 if (tty->termios->c_cflag & CBAUD) {
78700 @@ -330,7 +330,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
78701 }
78702
78703 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
78704 - __FILE__,__LINE__, tty->driver->name, self->open_count );
78705 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
78706
78707 schedule();
78708 }
78709 @@ -341,13 +341,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
78710 if (extra_count) {
78711 /* ++ is not atomic, so this should be protected - Jean II */
78712 spin_lock_irqsave(&self->spinlock, flags);
78713 - self->open_count++;
78714 + local_inc(&self->open_count);
78715 spin_unlock_irqrestore(&self->spinlock, flags);
78716 }
78717 - self->blocked_open--;
78718 + local_dec(&self->blocked_open);
78719
78720 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
78721 - __FILE__,__LINE__, tty->driver->name, self->open_count);
78722 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
78723
78724 if (!retval)
78725 self->flags |= ASYNC_NORMAL_ACTIVE;
78726 @@ -412,14 +412,14 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
78727 }
78728 /* ++ is not atomic, so this should be protected - Jean II */
78729 spin_lock_irqsave(&self->spinlock, flags);
78730 - self->open_count++;
78731 + local_inc(&self->open_count);
78732
78733 tty->driver_data = self;
78734 self->tty = tty;
78735 spin_unlock_irqrestore(&self->spinlock, flags);
78736
78737 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
78738 - self->line, self->open_count);
78739 + self->line, local_read(&self->open_count));
78740
78741 /* Not really used by us, but lets do it anyway */
78742 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
78743 @@ -505,7 +505,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
78744 return;
78745 }
78746
78747 - if ((tty->count == 1) && (self->open_count != 1)) {
78748 + if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
78749 /*
78750 * Uh, oh. tty->count is 1, which means that the tty
78751 * structure will be freed. state->count should always
78752 @@ -515,16 +515,16 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
78753 */
78754 IRDA_DEBUG(0, "%s(), bad serial port count; "
78755 "tty->count is 1, state->count is %d\n", __func__ ,
78756 - self->open_count);
78757 - self->open_count = 1;
78758 + local_read(&self->open_count));
78759 + local_set(&self->open_count, 1);
78760 }
78761
78762 - if (--self->open_count < 0) {
78763 + if (local_dec_return(&self->open_count) < 0) {
78764 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
78765 - __func__, self->line, self->open_count);
78766 - self->open_count = 0;
78767 + __func__, self->line, local_read(&self->open_count));
78768 + local_set(&self->open_count, 0);
78769 }
78770 - if (self->open_count) {
78771 + if (local_read(&self->open_count)) {
78772 spin_unlock_irqrestore(&self->spinlock, flags);
78773
78774 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
78775 @@ -556,7 +556,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
78776 tty->closing = 0;
78777 self->tty = NULL;
78778
78779 - if (self->blocked_open) {
78780 + if (local_read(&self->blocked_open)) {
78781 if (self->close_delay)
78782 schedule_timeout_interruptible(self->close_delay);
78783 wake_up_interruptible(&self->open_wait);
78784 @@ -1008,7 +1008,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
78785 spin_lock_irqsave(&self->spinlock, flags);
78786 self->flags &= ~ASYNC_NORMAL_ACTIVE;
78787 self->tty = NULL;
78788 - self->open_count = 0;
78789 + local_set(&self->open_count, 0);
78790 spin_unlock_irqrestore(&self->spinlock, flags);
78791
78792 wake_up_interruptible(&self->open_wait);
78793 @@ -1355,7 +1355,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
78794 seq_putc(m, '\n');
78795
78796 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
78797 - seq_printf(m, "Open count: %d\n", self->open_count);
78798 + seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
78799 seq_printf(m, "Max data size: %d\n", self->max_data_size);
78800 seq_printf(m, "Max header size: %d\n", self->max_header_size);
78801
78802 diff --git a/net/irda/irttp.c b/net/irda/irttp.c
78803 index 5c93f29..71498f0 100644
78804 --- a/net/irda/irttp.c
78805 +++ b/net/irda/irttp.c
78806 @@ -441,6 +441,7 @@ struct tsap_cb *irttp_open_tsap(__u8 stsap_sel, int credit, notify_t *notify)
78807 lsap = irlmp_open_lsap(stsap_sel, &ttp_notify, 0);
78808 if (lsap == NULL) {
78809 IRDA_WARNING("%s: unable to allocate LSAP!!\n", __func__);
78810 + __irttp_close_tsap(self);
78811 return NULL;
78812 }
78813
78814 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
78815 index cd6f7a9..e63fe89 100644
78816 --- a/net/iucv/af_iucv.c
78817 +++ b/net/iucv/af_iucv.c
78818 @@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
78819
78820 write_lock_bh(&iucv_sk_list.lock);
78821
78822 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
78823 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
78824 while (__iucv_get_sock_by_name(name)) {
78825 sprintf(name, "%08x",
78826 - atomic_inc_return(&iucv_sk_list.autobind_name));
78827 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
78828 }
78829
78830 write_unlock_bh(&iucv_sk_list.lock);
78831 diff --git a/net/key/af_key.c b/net/key/af_key.c
78832 index 34e4185..8823368 100644
78833 --- a/net/key/af_key.c
78834 +++ b/net/key/af_key.c
78835 @@ -3016,10 +3016,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
78836 static u32 get_acqseq(void)
78837 {
78838 u32 res;
78839 - static atomic_t acqseq;
78840 + static atomic_unchecked_t acqseq;
78841
78842 do {
78843 - res = atomic_inc_return(&acqseq);
78844 + res = atomic_inc_return_unchecked(&acqseq);
78845 } while (!res);
78846 return res;
78847 }
78848 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
78849 index 642a2a3..9dcc3dd 100644
78850 --- a/net/mac80211/ieee80211_i.h
78851 +++ b/net/mac80211/ieee80211_i.h
78852 @@ -28,6 +28,7 @@
78853 #include <net/ieee80211_radiotap.h>
78854 #include <net/cfg80211.h>
78855 #include <net/mac80211.h>
78856 +#include <asm/local.h>
78857 #include "key.h"
78858 #include "sta_info.h"
78859 #include "debug.h"
78860 @@ -840,7 +841,7 @@ struct ieee80211_local {
78861 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
78862 spinlock_t queue_stop_reason_lock;
78863
78864 - int open_count;
78865 + local_t open_count;
78866 int monitors, cooked_mntrs;
78867 /* number of interfaces with corresponding FIF_ flags */
78868 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
78869 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
78870 index c93d395..a305570 100644
78871 --- a/net/mac80211/iface.c
78872 +++ b/net/mac80211/iface.c
78873 @@ -454,7 +454,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
78874 break;
78875 }
78876
78877 - if (local->open_count == 0) {
78878 + if (local_read(&local->open_count) == 0) {
78879 res = drv_start(local);
78880 if (res)
78881 goto err_del_bss;
78882 @@ -497,7 +497,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
78883 break;
78884 }
78885
78886 - if (local->monitors == 0 && local->open_count == 0) {
78887 + if (local->monitors == 0 && local_read(&local->open_count) == 0) {
78888 res = ieee80211_add_virtual_monitor(local);
78889 if (res)
78890 goto err_stop;
78891 @@ -594,7 +594,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
78892 mutex_unlock(&local->mtx);
78893
78894 if (coming_up)
78895 - local->open_count++;
78896 + local_inc(&local->open_count);
78897
78898 if (hw_reconf_flags)
78899 ieee80211_hw_config(local, hw_reconf_flags);
78900 @@ -607,7 +607,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
78901 err_del_interface:
78902 drv_remove_interface(local, sdata);
78903 err_stop:
78904 - if (!local->open_count)
78905 + if (!local_read(&local->open_count))
78906 drv_stop(local);
78907 err_del_bss:
78908 sdata->bss = NULL;
78909 @@ -736,7 +736,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
78910 }
78911
78912 if (going_down)
78913 - local->open_count--;
78914 + local_dec(&local->open_count);
78915
78916 switch (sdata->vif.type) {
78917 case NL80211_IFTYPE_AP_VLAN:
78918 @@ -796,7 +796,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
78919
78920 ieee80211_recalc_ps(local, -1);
78921
78922 - if (local->open_count == 0) {
78923 + if (local_read(&local->open_count) == 0) {
78924 if (local->ops->napi_poll)
78925 napi_disable(&local->napi);
78926 ieee80211_clear_tx_pending(local);
78927 @@ -828,7 +828,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
78928 }
78929 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
78930
78931 - if (local->monitors == local->open_count && local->monitors > 0)
78932 + if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
78933 ieee80211_add_virtual_monitor(local);
78934 }
78935
78936 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
78937 index c26e231..8916637 100644
78938 --- a/net/mac80211/main.c
78939 +++ b/net/mac80211/main.c
78940 @@ -166,7 +166,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
78941 local->hw.conf.power_level = power;
78942 }
78943
78944 - if (changed && local->open_count) {
78945 + if (changed && local_read(&local->open_count)) {
78946 ret = drv_config(local, changed);
78947 /*
78948 * Goal:
78949 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
78950 index 5c572e7..ecf75ce 100644
78951 --- a/net/mac80211/pm.c
78952 +++ b/net/mac80211/pm.c
78953 @@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
78954 struct ieee80211_sub_if_data *sdata;
78955 struct sta_info *sta;
78956
78957 - if (!local->open_count)
78958 + if (!local_read(&local->open_count))
78959 goto suspend;
78960
78961 ieee80211_scan_cancel(local);
78962 @@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
78963 cancel_work_sync(&local->dynamic_ps_enable_work);
78964 del_timer_sync(&local->dynamic_ps_timer);
78965
78966 - local->wowlan = wowlan && local->open_count;
78967 + local->wowlan = wowlan && local_read(&local->open_count);
78968 if (local->wowlan) {
78969 int err = drv_suspend(local, wowlan);
78970 if (err < 0) {
78971 @@ -143,7 +143,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
78972 drv_remove_interface(local, sdata);
78973
78974 /* stop hardware - this must stop RX */
78975 - if (local->open_count)
78976 + if (local_read(&local->open_count))
78977 ieee80211_stop_device(local);
78978
78979 suspend:
78980 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
78981 index 3313c11..bec9f17 100644
78982 --- a/net/mac80211/rate.c
78983 +++ b/net/mac80211/rate.c
78984 @@ -494,7 +494,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
78985
78986 ASSERT_RTNL();
78987
78988 - if (local->open_count)
78989 + if (local_read(&local->open_count))
78990 return -EBUSY;
78991
78992 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
78993 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
78994 index c97a065..ff61928 100644
78995 --- a/net/mac80211/rc80211_pid_debugfs.c
78996 +++ b/net/mac80211/rc80211_pid_debugfs.c
78997 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
78998
78999 spin_unlock_irqrestore(&events->lock, status);
79000
79001 - if (copy_to_user(buf, pb, p))
79002 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
79003 return -EFAULT;
79004
79005 return p;
79006 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
79007 index 7883449..17c6a9a 100644
79008 --- a/net/mac80211/util.c
79009 +++ b/net/mac80211/util.c
79010 @@ -1279,7 +1279,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
79011 }
79012 #endif
79013 /* everything else happens only if HW was up & running */
79014 - if (!local->open_count)
79015 + if (!local_read(&local->open_count))
79016 goto wake_up;
79017
79018 /*
79019 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
79020 index c19b214..471fad1 100644
79021 --- a/net/netfilter/Kconfig
79022 +++ b/net/netfilter/Kconfig
79023 @@ -872,6 +872,16 @@ config NETFILTER_XT_MATCH_ESP
79024
79025 To compile it as a module, choose M here. If unsure, say N.
79026
79027 +config NETFILTER_XT_MATCH_GRADM
79028 + tristate '"gradm" match support'
79029 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
79030 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
79031 + ---help---
79032 + The gradm match allows to match on grsecurity RBAC being enabled.
79033 + It is useful when iptables rules are applied early on bootup to
79034 + prevent connections to the machine (except from a trusted host)
79035 + while the RBAC system is disabled.
79036 +
79037 config NETFILTER_XT_MATCH_HASHLIMIT
79038 tristate '"hashlimit" match support'
79039 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
79040 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
79041 index 1c5160f..145ae21 100644
79042 --- a/net/netfilter/Makefile
79043 +++ b/net/netfilter/Makefile
79044 @@ -90,6 +90,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
79045 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
79046 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
79047 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
79048 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
79049 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
79050 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
79051 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
79052 diff --git a/net/netfilter/ipset/ip_set_hash_netiface.c b/net/netfilter/ipset/ip_set_hash_netiface.c
79053 index d5d3607..1b6fa7b 100644
79054 --- a/net/netfilter/ipset/ip_set_hash_netiface.c
79055 +++ b/net/netfilter/ipset/ip_set_hash_netiface.c
79056 @@ -791,7 +791,7 @@ static struct ip_set_type hash_netiface_type __read_mostly = {
79057 [IPSET_ATTR_IP] = { .type = NLA_NESTED },
79058 [IPSET_ATTR_IP_TO] = { .type = NLA_NESTED },
79059 [IPSET_ATTR_IFACE] = { .type = NLA_NUL_STRING,
79060 - .len = IPSET_MAXNAMELEN - 1 },
79061 + .len = IFNAMSIZ - 1 },
79062 [IPSET_ATTR_CADT_FLAGS] = { .type = NLA_U32 },
79063 [IPSET_ATTR_CIDR] = { .type = NLA_U8 },
79064 [IPSET_ATTR_TIMEOUT] = { .type = NLA_U32 },
79065 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
79066 index 1548df9..98ad9b4 100644
79067 --- a/net/netfilter/ipvs/ip_vs_conn.c
79068 +++ b/net/netfilter/ipvs/ip_vs_conn.c
79069 @@ -557,7 +557,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
79070 /* Increase the refcnt counter of the dest */
79071 atomic_inc(&dest->refcnt);
79072
79073 - conn_flags = atomic_read(&dest->conn_flags);
79074 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
79075 if (cp->protocol != IPPROTO_UDP)
79076 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
79077 flags = cp->flags;
79078 @@ -902,7 +902,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
79079 atomic_set(&cp->refcnt, 1);
79080
79081 atomic_set(&cp->n_control, 0);
79082 - atomic_set(&cp->in_pkts, 0);
79083 + atomic_set_unchecked(&cp->in_pkts, 0);
79084
79085 atomic_inc(&ipvs->conn_count);
79086 if (flags & IP_VS_CONN_F_NO_CPORT)
79087 @@ -1183,7 +1183,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
79088
79089 /* Don't drop the entry if its number of incoming packets is not
79090 located in [0, 8] */
79091 - i = atomic_read(&cp->in_pkts);
79092 + i = atomic_read_unchecked(&cp->in_pkts);
79093 if (i > 8 || i < 0) return 0;
79094
79095 if (!todrop_rate[i]) return 0;
79096 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
79097 index b54ecce..fc5f6cf 100644
79098 --- a/net/netfilter/ipvs/ip_vs_core.c
79099 +++ b/net/netfilter/ipvs/ip_vs_core.c
79100 @@ -562,7 +562,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
79101 ret = cp->packet_xmit(skb, cp, pd->pp);
79102 /* do not touch skb anymore */
79103
79104 - atomic_inc(&cp->in_pkts);
79105 + atomic_inc_unchecked(&cp->in_pkts);
79106 ip_vs_conn_put(cp);
79107 return ret;
79108 }
79109 @@ -1611,7 +1611,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
79110 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
79111 pkts = sysctl_sync_threshold(ipvs);
79112 else
79113 - pkts = atomic_add_return(1, &cp->in_pkts);
79114 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
79115
79116 if (ipvs->sync_state & IP_VS_STATE_MASTER)
79117 ip_vs_sync_conn(net, cp, pkts);
79118 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
79119 index f51013c..c99ee52 100644
79120 --- a/net/netfilter/ipvs/ip_vs_ctl.c
79121 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
79122 @@ -788,7 +788,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
79123 ip_vs_rs_hash(ipvs, dest);
79124 write_unlock_bh(&ipvs->rs_lock);
79125 }
79126 - atomic_set(&dest->conn_flags, conn_flags);
79127 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
79128
79129 /* bind the service */
79130 if (!dest->svc) {
79131 @@ -2076,7 +2076,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
79132 " %-7s %-6d %-10d %-10d\n",
79133 &dest->addr.in6,
79134 ntohs(dest->port),
79135 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
79136 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
79137 atomic_read(&dest->weight),
79138 atomic_read(&dest->activeconns),
79139 atomic_read(&dest->inactconns));
79140 @@ -2087,7 +2087,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
79141 "%-7s %-6d %-10d %-10d\n",
79142 ntohl(dest->addr.ip),
79143 ntohs(dest->port),
79144 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
79145 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
79146 atomic_read(&dest->weight),
79147 atomic_read(&dest->activeconns),
79148 atomic_read(&dest->inactconns));
79149 @@ -2557,7 +2557,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
79150
79151 entry.addr = dest->addr.ip;
79152 entry.port = dest->port;
79153 - entry.conn_flags = atomic_read(&dest->conn_flags);
79154 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
79155 entry.weight = atomic_read(&dest->weight);
79156 entry.u_threshold = dest->u_threshold;
79157 entry.l_threshold = dest->l_threshold;
79158 @@ -3092,7 +3092,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
79159 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
79160 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
79161 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
79162 - (atomic_read(&dest->conn_flags) &
79163 + (atomic_read_unchecked(&dest->conn_flags) &
79164 IP_VS_CONN_F_FWD_MASK)) ||
79165 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
79166 atomic_read(&dest->weight)) ||
79167 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
79168 index effa10c..9058928 100644
79169 --- a/net/netfilter/ipvs/ip_vs_sync.c
79170 +++ b/net/netfilter/ipvs/ip_vs_sync.c
79171 @@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
79172 cp = cp->control;
79173 if (cp) {
79174 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
79175 - pkts = atomic_add_return(1, &cp->in_pkts);
79176 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
79177 else
79178 pkts = sysctl_sync_threshold(ipvs);
79179 ip_vs_sync_conn(net, cp->control, pkts);
79180 @@ -758,7 +758,7 @@ control:
79181 if (!cp)
79182 return;
79183 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
79184 - pkts = atomic_add_return(1, &cp->in_pkts);
79185 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
79186 else
79187 pkts = sysctl_sync_threshold(ipvs);
79188 goto sloop;
79189 @@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
79190
79191 if (opt)
79192 memcpy(&cp->in_seq, opt, sizeof(*opt));
79193 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
79194 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
79195 cp->state = state;
79196 cp->old_state = cp->state;
79197 /*
79198 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
79199 index c3c6291..3376d73 100644
79200 --- a/net/netfilter/ipvs/ip_vs_xmit.c
79201 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
79202 @@ -1157,7 +1157,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
79203 else
79204 rc = NF_ACCEPT;
79205 /* do not touch skb anymore */
79206 - atomic_inc(&cp->in_pkts);
79207 + atomic_inc_unchecked(&cp->in_pkts);
79208 goto out;
79209 }
79210
79211 @@ -1278,7 +1278,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
79212 else
79213 rc = NF_ACCEPT;
79214 /* do not touch skb anymore */
79215 - atomic_inc(&cp->in_pkts);
79216 + atomic_inc_unchecked(&cp->in_pkts);
79217 goto out;
79218 }
79219
79220 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
79221 index 2ceec64..a5b8a61 100644
79222 --- a/net/netfilter/nf_conntrack_core.c
79223 +++ b/net/netfilter/nf_conntrack_core.c
79224 @@ -1529,6 +1529,10 @@ err_extend:
79225 #define UNCONFIRMED_NULLS_VAL ((1<<30)+0)
79226 #define DYING_NULLS_VAL ((1<<30)+1)
79227
79228 +#ifdef CONFIG_GRKERNSEC_HIDESYM
79229 +static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
79230 +#endif
79231 +
79232 static int nf_conntrack_init_net(struct net *net)
79233 {
79234 int ret;
79235 @@ -1542,7 +1546,11 @@ static int nf_conntrack_init_net(struct net *net)
79236 goto err_stat;
79237 }
79238
79239 +#ifdef CONFIG_GRKERNSEC_HIDESYM
79240 + net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
79241 +#else
79242 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
79243 +#endif
79244 if (!net->ct.slabname) {
79245 ret = -ENOMEM;
79246 goto err_slabname;
79247 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
79248 index 5cfb5be..217c6d8 100644
79249 --- a/net/netfilter/nfnetlink_log.c
79250 +++ b/net/netfilter/nfnetlink_log.c
79251 @@ -70,7 +70,7 @@ struct nfulnl_instance {
79252 };
79253
79254 static DEFINE_SPINLOCK(instances_lock);
79255 -static atomic_t global_seq;
79256 +static atomic_unchecked_t global_seq;
79257
79258 #define INSTANCE_BUCKETS 16
79259 static struct hlist_head instance_table[INSTANCE_BUCKETS];
79260 @@ -523,7 +523,7 @@ __build_packet_message(struct nfulnl_instance *inst,
79261 /* global sequence number */
79262 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
79263 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
79264 - htonl(atomic_inc_return(&global_seq))))
79265 + htonl(atomic_inc_return_unchecked(&global_seq))))
79266 goto nla_put_failure;
79267
79268 if (data_len) {
79269 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
79270 new file mode 100644
79271 index 0000000..c566332
79272 --- /dev/null
79273 +++ b/net/netfilter/xt_gradm.c
79274 @@ -0,0 +1,51 @@
79275 +/*
79276 + * gradm match for netfilter
79277 + * Copyright © Zbigniew Krzystolik, 2010
79278 + *
79279 + * This program is free software; you can redistribute it and/or modify
79280 + * it under the terms of the GNU General Public License; either version
79281 + * 2 or 3 as published by the Free Software Foundation.
79282 + */
79283 +#include <linux/module.h>
79284 +#include <linux/moduleparam.h>
79285 +#include <linux/skbuff.h>
79286 +#include <linux/netfilter/x_tables.h>
79287 +#include <linux/grsecurity.h>
79288 +#include <linux/netfilter/xt_gradm.h>
79289 +
79290 +static bool
79291 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
79292 +{
79293 + const struct xt_gradm_mtinfo *info = par->matchinfo;
79294 + bool retval = false;
79295 + if (gr_acl_is_enabled())
79296 + retval = true;
79297 + return retval ^ info->invflags;
79298 +}
79299 +
79300 +static struct xt_match gradm_mt_reg __read_mostly = {
79301 + .name = "gradm",
79302 + .revision = 0,
79303 + .family = NFPROTO_UNSPEC,
79304 + .match = gradm_mt,
79305 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
79306 + .me = THIS_MODULE,
79307 +};
79308 +
79309 +static int __init gradm_mt_init(void)
79310 +{
79311 + return xt_register_match(&gradm_mt_reg);
79312 +}
79313 +
79314 +static void __exit gradm_mt_exit(void)
79315 +{
79316 + xt_unregister_match(&gradm_mt_reg);
79317 +}
79318 +
79319 +module_init(gradm_mt_init);
79320 +module_exit(gradm_mt_exit);
79321 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
79322 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
79323 +MODULE_LICENSE("GPL");
79324 +MODULE_ALIAS("ipt_gradm");
79325 +MODULE_ALIAS("ip6t_gradm");
79326 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
79327 index 4fe4fb4..87a89e5 100644
79328 --- a/net/netfilter/xt_statistic.c
79329 +++ b/net/netfilter/xt_statistic.c
79330 @@ -19,7 +19,7 @@
79331 #include <linux/module.h>
79332
79333 struct xt_statistic_priv {
79334 - atomic_t count;
79335 + atomic_unchecked_t count;
79336 } ____cacheline_aligned_in_smp;
79337
79338 MODULE_LICENSE("GPL");
79339 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
79340 break;
79341 case XT_STATISTIC_MODE_NTH:
79342 do {
79343 - oval = atomic_read(&info->master->count);
79344 + oval = atomic_read_unchecked(&info->master->count);
79345 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
79346 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
79347 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
79348 if (nval == 0)
79349 ret = !ret;
79350 break;
79351 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
79352 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
79353 if (info->master == NULL)
79354 return -ENOMEM;
79355 - atomic_set(&info->master->count, info->u.nth.count);
79356 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
79357
79358 return 0;
79359 }
79360 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
79361 index 0426b67..d6ddaca 100644
79362 --- a/net/netlink/af_netlink.c
79363 +++ b/net/netlink/af_netlink.c
79364 @@ -780,7 +780,7 @@ static void netlink_overrun(struct sock *sk)
79365 sk->sk_error_report(sk);
79366 }
79367 }
79368 - atomic_inc(&sk->sk_drops);
79369 + atomic_inc_unchecked(&sk->sk_drops);
79370 }
79371
79372 static struct sock *netlink_getsockbypid(struct sock *ssk, u32 pid)
79373 @@ -2070,7 +2070,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
79374 sk_wmem_alloc_get(s),
79375 nlk->cb,
79376 atomic_read(&s->sk_refcnt),
79377 - atomic_read(&s->sk_drops),
79378 + atomic_read_unchecked(&s->sk_drops),
79379 sock_i_ino(s)
79380 );
79381
79382 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
79383 index 7261eb8..44e8ac6 100644
79384 --- a/net/netrom/af_netrom.c
79385 +++ b/net/netrom/af_netrom.c
79386 @@ -838,6 +838,7 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
79387 struct sock *sk = sock->sk;
79388 struct nr_sock *nr = nr_sk(sk);
79389
79390 + memset(sax, 0, sizeof(*sax));
79391 lock_sock(sk);
79392 if (peer != 0) {
79393 if (sk->sk_state != TCP_ESTABLISHED) {
79394 @@ -852,7 +853,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
79395 *uaddr_len = sizeof(struct full_sockaddr_ax25);
79396 } else {
79397 sax->fsa_ax25.sax25_family = AF_NETROM;
79398 - sax->fsa_ax25.sax25_ndigis = 0;
79399 sax->fsa_ax25.sax25_call = nr->source_addr;
79400 *uaddr_len = sizeof(struct sockaddr_ax25);
79401 }
79402 diff --git a/net/nfc/llcp/sock.c b/net/nfc/llcp/sock.c
79403 index ddeb9aa..e18fffd 100644
79404 --- a/net/nfc/llcp/sock.c
79405 +++ b/net/nfc/llcp/sock.c
79406 @@ -443,15 +443,11 @@ static int llcp_sock_connect(struct socket *sock, struct sockaddr *_addr,
79407 pr_debug("sock %p sk %p flags 0x%x\n", sock, sk, flags);
79408
79409 if (!addr || len < sizeof(struct sockaddr_nfc) ||
79410 - addr->sa_family != AF_NFC) {
79411 - pr_err("Invalid socket\n");
79412 + addr->sa_family != AF_NFC)
79413 return -EINVAL;
79414 - }
79415
79416 - if (addr->service_name_len == 0 && addr->dsap == 0) {
79417 - pr_err("Missing service name or dsap\n");
79418 + if (addr->service_name_len == 0 && addr->dsap == 0)
79419 return -EINVAL;
79420 - }
79421
79422 pr_debug("addr dev_idx=%u target_idx=%u protocol=%u\n", addr->dev_idx,
79423 addr->target_idx, addr->nfc_protocol);
79424 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
79425 index c5c9e2a..4814ab1 100644
79426 --- a/net/packet/af_packet.c
79427 +++ b/net/packet/af_packet.c
79428 @@ -1689,7 +1689,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
79429
79430 spin_lock(&sk->sk_receive_queue.lock);
79431 po->stats.tp_packets++;
79432 - skb->dropcount = atomic_read(&sk->sk_drops);
79433 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
79434 __skb_queue_tail(&sk->sk_receive_queue, skb);
79435 spin_unlock(&sk->sk_receive_queue.lock);
79436 sk->sk_data_ready(sk, skb->len);
79437 @@ -1698,7 +1698,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
79438 drop_n_acct:
79439 spin_lock(&sk->sk_receive_queue.lock);
79440 po->stats.tp_drops++;
79441 - atomic_inc(&sk->sk_drops);
79442 + atomic_inc_unchecked(&sk->sk_drops);
79443 spin_unlock(&sk->sk_receive_queue.lock);
79444
79445 drop_n_restore:
79446 @@ -2642,6 +2642,7 @@ out:
79447
79448 static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
79449 {
79450 + struct sock_extended_err ee;
79451 struct sock_exterr_skb *serr;
79452 struct sk_buff *skb, *skb2;
79453 int copied, err;
79454 @@ -2663,8 +2664,9 @@ static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
79455 sock_recv_timestamp(msg, sk, skb);
79456
79457 serr = SKB_EXT_ERR(skb);
79458 + ee = serr->ee;
79459 put_cmsg(msg, SOL_PACKET, PACKET_TX_TIMESTAMP,
79460 - sizeof(serr->ee), &serr->ee);
79461 + sizeof ee, &ee);
79462
79463 msg->msg_flags |= MSG_ERRQUEUE;
79464 err = copied;
79465 @@ -3276,7 +3278,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
79466 case PACKET_HDRLEN:
79467 if (len > sizeof(int))
79468 len = sizeof(int);
79469 - if (copy_from_user(&val, optval, len))
79470 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
79471 return -EFAULT;
79472 switch (val) {
79473 case TPACKET_V1:
79474 @@ -3315,7 +3317,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
79475 len = lv;
79476 if (put_user(len, optlen))
79477 return -EFAULT;
79478 - if (copy_to_user(optval, data, len))
79479 + if (len > sizeof(st) || copy_to_user(optval, data, len))
79480 return -EFAULT;
79481 return 0;
79482 }
79483 diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
79484 index 5a940db..f0b9c12 100644
79485 --- a/net/phonet/af_phonet.c
79486 +++ b/net/phonet/af_phonet.c
79487 @@ -41,7 +41,7 @@ static struct phonet_protocol *phonet_proto_get(unsigned int protocol)
79488 {
79489 struct phonet_protocol *pp;
79490
79491 - if (protocol >= PHONET_NPROTO)
79492 + if (protocol < 0 || protocol >= PHONET_NPROTO)
79493 return NULL;
79494
79495 rcu_read_lock();
79496 @@ -469,7 +469,7 @@ int __init_or_module phonet_proto_register(unsigned int protocol,
79497 {
79498 int err = 0;
79499
79500 - if (protocol >= PHONET_NPROTO)
79501 + if (protocol < 0 || protocol >= PHONET_NPROTO)
79502 return -EINVAL;
79503
79504 err = proto_register(pp->prot, 1);
79505 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
79506 index 576f22c..bc7a71b 100644
79507 --- a/net/phonet/pep.c
79508 +++ b/net/phonet/pep.c
79509 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
79510
79511 case PNS_PEP_CTRL_REQ:
79512 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
79513 - atomic_inc(&sk->sk_drops);
79514 + atomic_inc_unchecked(&sk->sk_drops);
79515 break;
79516 }
79517 __skb_pull(skb, 4);
79518 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
79519 }
79520
79521 if (pn->rx_credits == 0) {
79522 - atomic_inc(&sk->sk_drops);
79523 + atomic_inc_unchecked(&sk->sk_drops);
79524 err = -ENOBUFS;
79525 break;
79526 }
79527 @@ -580,7 +580,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
79528 }
79529
79530 if (pn->rx_credits == 0) {
79531 - atomic_inc(&sk->sk_drops);
79532 + atomic_inc_unchecked(&sk->sk_drops);
79533 err = NET_RX_DROP;
79534 break;
79535 }
79536 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
79537 index 0acc943..c727611 100644
79538 --- a/net/phonet/socket.c
79539 +++ b/net/phonet/socket.c
79540 @@ -613,8 +613,13 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
79541 pn->resource, sk->sk_state,
79542 sk_wmem_alloc_get(sk), sk_rmem_alloc_get(sk),
79543 sock_i_uid(sk), sock_i_ino(sk),
79544 - atomic_read(&sk->sk_refcnt), sk,
79545 - atomic_read(&sk->sk_drops), &len);
79546 + atomic_read(&sk->sk_refcnt),
79547 +#ifdef CONFIG_GRKERNSEC_HIDESYM
79548 + NULL,
79549 +#else
79550 + sk,
79551 +#endif
79552 + atomic_read_unchecked(&sk->sk_drops), &len);
79553 }
79554 seq_printf(seq, "%*s\n", 127 - len, "");
79555 return 0;
79556 diff --git a/net/rds/cong.c b/net/rds/cong.c
79557 index e5b65ac..f3b6fb7 100644
79558 --- a/net/rds/cong.c
79559 +++ b/net/rds/cong.c
79560 @@ -78,7 +78,7 @@
79561 * finds that the saved generation number is smaller than the global generation
79562 * number, it wakes up the process.
79563 */
79564 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
79565 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
79566
79567 /*
79568 * Congestion monitoring
79569 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
79570 rdsdebug("waking map %p for %pI4\n",
79571 map, &map->m_addr);
79572 rds_stats_inc(s_cong_update_received);
79573 - atomic_inc(&rds_cong_generation);
79574 + atomic_inc_unchecked(&rds_cong_generation);
79575 if (waitqueue_active(&map->m_waitq))
79576 wake_up(&map->m_waitq);
79577 if (waitqueue_active(&rds_poll_waitq))
79578 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
79579
79580 int rds_cong_updated_since(unsigned long *recent)
79581 {
79582 - unsigned long gen = atomic_read(&rds_cong_generation);
79583 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
79584
79585 if (likely(*recent == gen))
79586 return 0;
79587 diff --git a/net/rds/ib.h b/net/rds/ib.h
79588 index 8d2b3d5..227ec5b 100644
79589 --- a/net/rds/ib.h
79590 +++ b/net/rds/ib.h
79591 @@ -128,7 +128,7 @@ struct rds_ib_connection {
79592 /* sending acks */
79593 unsigned long i_ack_flags;
79594 #ifdef KERNEL_HAS_ATOMIC64
79595 - atomic64_t i_ack_next; /* next ACK to send */
79596 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
79597 #else
79598 spinlock_t i_ack_lock; /* protect i_ack_next */
79599 u64 i_ack_next; /* next ACK to send */
79600 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
79601 index a1e1162..265e129 100644
79602 --- a/net/rds/ib_cm.c
79603 +++ b/net/rds/ib_cm.c
79604 @@ -718,7 +718,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
79605 /* Clear the ACK state */
79606 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
79607 #ifdef KERNEL_HAS_ATOMIC64
79608 - atomic64_set(&ic->i_ack_next, 0);
79609 + atomic64_set_unchecked(&ic->i_ack_next, 0);
79610 #else
79611 ic->i_ack_next = 0;
79612 #endif
79613 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
79614 index 8d19491..05a3e65 100644
79615 --- a/net/rds/ib_recv.c
79616 +++ b/net/rds/ib_recv.c
79617 @@ -592,7 +592,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
79618 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
79619 int ack_required)
79620 {
79621 - atomic64_set(&ic->i_ack_next, seq);
79622 + atomic64_set_unchecked(&ic->i_ack_next, seq);
79623 if (ack_required) {
79624 smp_mb__before_clear_bit();
79625 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
79626 @@ -604,7 +604,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
79627 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
79628 smp_mb__after_clear_bit();
79629
79630 - return atomic64_read(&ic->i_ack_next);
79631 + return atomic64_read_unchecked(&ic->i_ack_next);
79632 }
79633 #endif
79634
79635 diff --git a/net/rds/iw.h b/net/rds/iw.h
79636 index 04ce3b1..48119a6 100644
79637 --- a/net/rds/iw.h
79638 +++ b/net/rds/iw.h
79639 @@ -134,7 +134,7 @@ struct rds_iw_connection {
79640 /* sending acks */
79641 unsigned long i_ack_flags;
79642 #ifdef KERNEL_HAS_ATOMIC64
79643 - atomic64_t i_ack_next; /* next ACK to send */
79644 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
79645 #else
79646 spinlock_t i_ack_lock; /* protect i_ack_next */
79647 u64 i_ack_next; /* next ACK to send */
79648 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
79649 index a91e1db..cf3053f 100644
79650 --- a/net/rds/iw_cm.c
79651 +++ b/net/rds/iw_cm.c
79652 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
79653 /* Clear the ACK state */
79654 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
79655 #ifdef KERNEL_HAS_ATOMIC64
79656 - atomic64_set(&ic->i_ack_next, 0);
79657 + atomic64_set_unchecked(&ic->i_ack_next, 0);
79658 #else
79659 ic->i_ack_next = 0;
79660 #endif
79661 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
79662 index 4503335..db566b4 100644
79663 --- a/net/rds/iw_recv.c
79664 +++ b/net/rds/iw_recv.c
79665 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
79666 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
79667 int ack_required)
79668 {
79669 - atomic64_set(&ic->i_ack_next, seq);
79670 + atomic64_set_unchecked(&ic->i_ack_next, seq);
79671 if (ack_required) {
79672 smp_mb__before_clear_bit();
79673 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
79674 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
79675 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
79676 smp_mb__after_clear_bit();
79677
79678 - return atomic64_read(&ic->i_ack_next);
79679 + return atomic64_read_unchecked(&ic->i_ack_next);
79680 }
79681 #endif
79682
79683 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
79684 index edac9ef..16bcb98 100644
79685 --- a/net/rds/tcp.c
79686 +++ b/net/rds/tcp.c
79687 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
79688 int val = 1;
79689
79690 set_fs(KERNEL_DS);
79691 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
79692 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
79693 sizeof(val));
79694 set_fs(oldfs);
79695 }
79696 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
79697 index 1b4fd68..2234175 100644
79698 --- a/net/rds/tcp_send.c
79699 +++ b/net/rds/tcp_send.c
79700 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
79701
79702 oldfs = get_fs();
79703 set_fs(KERNEL_DS);
79704 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
79705 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
79706 sizeof(val));
79707 set_fs(oldfs);
79708 }
79709 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
79710 index 05996d0..5a1dfe0 100644
79711 --- a/net/rxrpc/af_rxrpc.c
79712 +++ b/net/rxrpc/af_rxrpc.c
79713 @@ -39,7 +39,7 @@ static const struct proto_ops rxrpc_rpc_ops;
79714 __be32 rxrpc_epoch;
79715
79716 /* current debugging ID */
79717 -atomic_t rxrpc_debug_id;
79718 +atomic_unchecked_t rxrpc_debug_id;
79719
79720 /* count of skbs currently in use */
79721 atomic_t rxrpc_n_skbs;
79722 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
79723 index e4d9cbc..b229649 100644
79724 --- a/net/rxrpc/ar-ack.c
79725 +++ b/net/rxrpc/ar-ack.c
79726 @@ -175,7 +175,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
79727
79728 _enter("{%d,%d,%d,%d},",
79729 call->acks_hard, call->acks_unacked,
79730 - atomic_read(&call->sequence),
79731 + atomic_read_unchecked(&call->sequence),
79732 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
79733
79734 stop = 0;
79735 @@ -199,7 +199,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
79736
79737 /* each Tx packet has a new serial number */
79738 sp->hdr.serial =
79739 - htonl(atomic_inc_return(&call->conn->serial));
79740 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
79741
79742 hdr = (struct rxrpc_header *) txb->head;
79743 hdr->serial = sp->hdr.serial;
79744 @@ -403,7 +403,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
79745 */
79746 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
79747 {
79748 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
79749 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
79750 }
79751
79752 /*
79753 @@ -629,7 +629,7 @@ process_further:
79754
79755 latest = ntohl(sp->hdr.serial);
79756 hard = ntohl(ack.firstPacket);
79757 - tx = atomic_read(&call->sequence);
79758 + tx = atomic_read_unchecked(&call->sequence);
79759
79760 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
79761 latest,
79762 @@ -1161,7 +1161,7 @@ void rxrpc_process_call(struct work_struct *work)
79763 goto maybe_reschedule;
79764
79765 send_ACK_with_skew:
79766 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
79767 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
79768 ntohl(ack.serial));
79769 send_ACK:
79770 mtu = call->conn->trans->peer->if_mtu;
79771 @@ -1173,7 +1173,7 @@ send_ACK:
79772 ackinfo.rxMTU = htonl(5692);
79773 ackinfo.jumbo_max = htonl(4);
79774
79775 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
79776 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
79777 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
79778 ntohl(hdr.serial),
79779 ntohs(ack.maxSkew),
79780 @@ -1191,7 +1191,7 @@ send_ACK:
79781 send_message:
79782 _debug("send message");
79783
79784 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
79785 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
79786 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
79787 send_message_2:
79788
79789 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
79790 index a3bbb36..3341fb9 100644
79791 --- a/net/rxrpc/ar-call.c
79792 +++ b/net/rxrpc/ar-call.c
79793 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
79794 spin_lock_init(&call->lock);
79795 rwlock_init(&call->state_lock);
79796 atomic_set(&call->usage, 1);
79797 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
79798 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
79799 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
79800
79801 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
79802 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
79803 index 4106ca9..a338d7a 100644
79804 --- a/net/rxrpc/ar-connection.c
79805 +++ b/net/rxrpc/ar-connection.c
79806 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
79807 rwlock_init(&conn->lock);
79808 spin_lock_init(&conn->state_lock);
79809 atomic_set(&conn->usage, 1);
79810 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
79811 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
79812 conn->avail_calls = RXRPC_MAXCALLS;
79813 conn->size_align = 4;
79814 conn->header_size = sizeof(struct rxrpc_header);
79815 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
79816 index e7ed43a..6afa140 100644
79817 --- a/net/rxrpc/ar-connevent.c
79818 +++ b/net/rxrpc/ar-connevent.c
79819 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
79820
79821 len = iov[0].iov_len + iov[1].iov_len;
79822
79823 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
79824 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
79825 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
79826
79827 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
79828 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
79829 index 529572f..c758ca7 100644
79830 --- a/net/rxrpc/ar-input.c
79831 +++ b/net/rxrpc/ar-input.c
79832 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
79833 /* track the latest serial number on this connection for ACK packet
79834 * information */
79835 serial = ntohl(sp->hdr.serial);
79836 - hi_serial = atomic_read(&call->conn->hi_serial);
79837 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
79838 while (serial > hi_serial)
79839 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
79840 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
79841 serial);
79842
79843 /* request ACK generation for any ACK or DATA packet that requests
79844 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
79845 index a693aca..81e7293 100644
79846 --- a/net/rxrpc/ar-internal.h
79847 +++ b/net/rxrpc/ar-internal.h
79848 @@ -272,8 +272,8 @@ struct rxrpc_connection {
79849 int error; /* error code for local abort */
79850 int debug_id; /* debug ID for printks */
79851 unsigned int call_counter; /* call ID counter */
79852 - atomic_t serial; /* packet serial number counter */
79853 - atomic_t hi_serial; /* highest serial number received */
79854 + atomic_unchecked_t serial; /* packet serial number counter */
79855 + atomic_unchecked_t hi_serial; /* highest serial number received */
79856 u8 avail_calls; /* number of calls available */
79857 u8 size_align; /* data size alignment (for security) */
79858 u8 header_size; /* rxrpc + security header size */
79859 @@ -346,7 +346,7 @@ struct rxrpc_call {
79860 spinlock_t lock;
79861 rwlock_t state_lock; /* lock for state transition */
79862 atomic_t usage;
79863 - atomic_t sequence; /* Tx data packet sequence counter */
79864 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
79865 u32 abort_code; /* local/remote abort code */
79866 enum { /* current state of call */
79867 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
79868 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
79869 */
79870 extern atomic_t rxrpc_n_skbs;
79871 extern __be32 rxrpc_epoch;
79872 -extern atomic_t rxrpc_debug_id;
79873 +extern atomic_unchecked_t rxrpc_debug_id;
79874 extern struct workqueue_struct *rxrpc_workqueue;
79875
79876 /*
79877 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
79878 index 87f7135..74d3703 100644
79879 --- a/net/rxrpc/ar-local.c
79880 +++ b/net/rxrpc/ar-local.c
79881 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
79882 spin_lock_init(&local->lock);
79883 rwlock_init(&local->services_lock);
79884 atomic_set(&local->usage, 1);
79885 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
79886 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
79887 memcpy(&local->srx, srx, sizeof(*srx));
79888 }
79889
79890 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
79891 index e1ac183..b43e10e 100644
79892 --- a/net/rxrpc/ar-output.c
79893 +++ b/net/rxrpc/ar-output.c
79894 @@ -682,9 +682,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
79895 sp->hdr.cid = call->cid;
79896 sp->hdr.callNumber = call->call_id;
79897 sp->hdr.seq =
79898 - htonl(atomic_inc_return(&call->sequence));
79899 + htonl(atomic_inc_return_unchecked(&call->sequence));
79900 sp->hdr.serial =
79901 - htonl(atomic_inc_return(&conn->serial));
79902 + htonl(atomic_inc_return_unchecked(&conn->serial));
79903 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
79904 sp->hdr.userStatus = 0;
79905 sp->hdr.securityIndex = conn->security_ix;
79906 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
79907 index bebaa43..2644591 100644
79908 --- a/net/rxrpc/ar-peer.c
79909 +++ b/net/rxrpc/ar-peer.c
79910 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
79911 INIT_LIST_HEAD(&peer->error_targets);
79912 spin_lock_init(&peer->lock);
79913 atomic_set(&peer->usage, 1);
79914 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
79915 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
79916 memcpy(&peer->srx, srx, sizeof(*srx));
79917
79918 rxrpc_assess_MTU_size(peer);
79919 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
79920 index 38047f7..9f48511 100644
79921 --- a/net/rxrpc/ar-proc.c
79922 +++ b/net/rxrpc/ar-proc.c
79923 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
79924 atomic_read(&conn->usage),
79925 rxrpc_conn_states[conn->state],
79926 key_serial(conn->key),
79927 - atomic_read(&conn->serial),
79928 - atomic_read(&conn->hi_serial));
79929 + atomic_read_unchecked(&conn->serial),
79930 + atomic_read_unchecked(&conn->hi_serial));
79931
79932 return 0;
79933 }
79934 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
79935 index 92df566..87ec1bf 100644
79936 --- a/net/rxrpc/ar-transport.c
79937 +++ b/net/rxrpc/ar-transport.c
79938 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
79939 spin_lock_init(&trans->client_lock);
79940 rwlock_init(&trans->conn_lock);
79941 atomic_set(&trans->usage, 1);
79942 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
79943 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
79944
79945 if (peer->srx.transport.family == AF_INET) {
79946 switch (peer->srx.transport_type) {
79947 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
79948 index f226709..0e735a8 100644
79949 --- a/net/rxrpc/rxkad.c
79950 +++ b/net/rxrpc/rxkad.c
79951 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
79952
79953 len = iov[0].iov_len + iov[1].iov_len;
79954
79955 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
79956 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
79957 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
79958
79959 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
79960 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
79961
79962 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
79963
79964 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
79965 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
79966 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
79967
79968 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
79969 diff --git a/net/sctp/chunk.c b/net/sctp/chunk.c
79970 index 6c85564..9534bf9 100644
79971 --- a/net/sctp/chunk.c
79972 +++ b/net/sctp/chunk.c
79973 @@ -284,7 +284,7 @@ struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *asoc,
79974 goto errout;
79975 err = sctp_user_addto_chunk(chunk, offset, len, msgh->msg_iov);
79976 if (err < 0)
79977 - goto errout;
79978 + goto errout_chunk_free;
79979
79980 offset += len;
79981
79982 @@ -324,7 +324,7 @@ struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *asoc,
79983 __skb_pull(chunk->skb, (__u8 *)chunk->chunk_hdr
79984 - (__u8 *)chunk->skb->data);
79985 if (err < 0)
79986 - goto errout;
79987 + goto errout_chunk_free;
79988
79989 sctp_datamsg_assign(msg, chunk);
79990 list_add_tail(&chunk->frag_list, &msg->chunks);
79991 @@ -332,6 +332,9 @@ struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *asoc,
79992
79993 return msg;
79994
79995 +errout_chunk_free:
79996 + sctp_chunk_free(chunk);
79997 +
79998 errout:
79999 list_for_each_safe(pos, temp, &msg->chunks) {
80000 list_del_init(pos);
80001 diff --git a/net/sctp/proc.c b/net/sctp/proc.c
80002 index 1e2eee8..ce3967e 100644
80003 --- a/net/sctp/proc.c
80004 +++ b/net/sctp/proc.c
80005 @@ -319,7 +319,8 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
80006 seq_printf(seq,
80007 "%8pK %8pK %-3d %-3d %-2d %-4d "
80008 "%4d %8d %8d %7d %5lu %-5d %5d ",
80009 - assoc, sk, sctp_sk(sk)->type, sk->sk_state,
80010 + assoc, sk,
80011 + sctp_sk(sk)->type, sk->sk_state,
80012 assoc->state, hash,
80013 assoc->assoc_id,
80014 assoc->sndbuf_used,
80015 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
80016 index 5e25981..dbda919 100644
80017 --- a/net/sctp/socket.c
80018 +++ b/net/sctp/socket.c
80019 @@ -4630,6 +4630,8 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
80020 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
80021 if (space_left < addrlen)
80022 return -ENOMEM;
80023 + if (addrlen > sizeof(temp) || addrlen < 0)
80024 + return -EFAULT;
80025 if (copy_to_user(to, &temp, addrlen))
80026 return -EFAULT;
80027 to += addrlen;
80028 diff --git a/net/sctp/transport.c b/net/sctp/transport.c
80029 index c97472b..3f7c94b 100644
80030 --- a/net/sctp/transport.c
80031 +++ b/net/sctp/transport.c
80032 @@ -328,7 +328,7 @@ void sctp_transport_update_rto(struct sctp_transport *tp, __u32 rtt)
80033 * 1/8, rto_alpha would be expressed as 3.
80034 */
80035 tp->rttvar = tp->rttvar - (tp->rttvar >> sctp_rto_beta)
80036 - + ((abs(tp->srtt - rtt)) >> sctp_rto_beta);
80037 + + (((__u32)abs64((__s64)tp->srtt - (__s64)rtt)) >> sctp_rto_beta);
80038 tp->srtt = tp->srtt - (tp->srtt >> sctp_rto_alpha)
80039 + (rtt >> sctp_rto_alpha);
80040 } else {
80041 diff --git a/net/socket.c b/net/socket.c
80042 index edc3c4a..4b4e4a8 100644
80043 --- a/net/socket.c
80044 +++ b/net/socket.c
80045 @@ -88,6 +88,7 @@
80046 #include <linux/nsproxy.h>
80047 #include <linux/magic.h>
80048 #include <linux/slab.h>
80049 +#include <linux/in.h>
80050
80051 #include <asm/uaccess.h>
80052 #include <asm/unistd.h>
80053 @@ -105,6 +106,8 @@
80054 #include <linux/sockios.h>
80055 #include <linux/atalk.h>
80056
80057 +#include <linux/grsock.h>
80058 +
80059 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
80060 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
80061 unsigned long nr_segs, loff_t pos);
80062 @@ -321,7 +324,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
80063 &sockfs_dentry_operations, SOCKFS_MAGIC);
80064 }
80065
80066 -static struct vfsmount *sock_mnt __read_mostly;
80067 +struct vfsmount *sock_mnt __read_mostly;
80068
80069 static struct file_system_type sock_fs_type = {
80070 .name = "sockfs",
80071 @@ -1209,6 +1212,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
80072 return -EAFNOSUPPORT;
80073 if (type < 0 || type >= SOCK_MAX)
80074 return -EINVAL;
80075 + if (protocol < 0)
80076 + return -EINVAL;
80077
80078 /* Compatibility.
80079
80080 @@ -1340,6 +1345,16 @@ SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)
80081 if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
80082 flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
80083
80084 + if(!gr_search_socket(family, type, protocol)) {
80085 + retval = -EACCES;
80086 + goto out;
80087 + }
80088 +
80089 + if (gr_handle_sock_all(family, type, protocol)) {
80090 + retval = -EACCES;
80091 + goto out;
80092 + }
80093 +
80094 retval = sock_create(family, type, protocol, &sock);
80095 if (retval < 0)
80096 goto out;
80097 @@ -1452,6 +1467,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
80098 if (sock) {
80099 err = move_addr_to_kernel(umyaddr, addrlen, &address);
80100 if (err >= 0) {
80101 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
80102 + err = -EACCES;
80103 + goto error;
80104 + }
80105 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
80106 + if (err)
80107 + goto error;
80108 +
80109 err = security_socket_bind(sock,
80110 (struct sockaddr *)&address,
80111 addrlen);
80112 @@ -1460,6 +1483,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
80113 (struct sockaddr *)
80114 &address, addrlen);
80115 }
80116 +error:
80117 fput_light(sock->file, fput_needed);
80118 }
80119 return err;
80120 @@ -1483,10 +1507,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
80121 if ((unsigned int)backlog > somaxconn)
80122 backlog = somaxconn;
80123
80124 + if (gr_handle_sock_server_other(sock->sk)) {
80125 + err = -EPERM;
80126 + goto error;
80127 + }
80128 +
80129 + err = gr_search_listen(sock);
80130 + if (err)
80131 + goto error;
80132 +
80133 err = security_socket_listen(sock, backlog);
80134 if (!err)
80135 err = sock->ops->listen(sock, backlog);
80136
80137 +error:
80138 fput_light(sock->file, fput_needed);
80139 }
80140 return err;
80141 @@ -1530,6 +1564,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
80142 newsock->type = sock->type;
80143 newsock->ops = sock->ops;
80144
80145 + if (gr_handle_sock_server_other(sock->sk)) {
80146 + err = -EPERM;
80147 + sock_release(newsock);
80148 + goto out_put;
80149 + }
80150 +
80151 + err = gr_search_accept(sock);
80152 + if (err) {
80153 + sock_release(newsock);
80154 + goto out_put;
80155 + }
80156 +
80157 /*
80158 * We don't need try_module_get here, as the listening socket (sock)
80159 * has the protocol module (sock->ops->owner) held.
80160 @@ -1568,6 +1614,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
80161 fd_install(newfd, newfile);
80162 err = newfd;
80163
80164 + gr_attach_curr_ip(newsock->sk);
80165 +
80166 out_put:
80167 fput_light(sock->file, fput_needed);
80168 out:
80169 @@ -1600,6 +1648,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
80170 int, addrlen)
80171 {
80172 struct socket *sock;
80173 + struct sockaddr *sck;
80174 struct sockaddr_storage address;
80175 int err, fput_needed;
80176
80177 @@ -1610,6 +1659,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
80178 if (err < 0)
80179 goto out_put;
80180
80181 + sck = (struct sockaddr *)&address;
80182 +
80183 + if (gr_handle_sock_client(sck)) {
80184 + err = -EACCES;
80185 + goto out_put;
80186 + }
80187 +
80188 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
80189 + if (err)
80190 + goto out_put;
80191 +
80192 err =
80193 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
80194 if (err)
80195 @@ -1964,7 +2024,7 @@ static int __sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
80196 * checking falls down on this.
80197 */
80198 if (copy_from_user(ctl_buf,
80199 - (void __user __force *)msg_sys->msg_control,
80200 + (void __force_user *)msg_sys->msg_control,
80201 ctl_len))
80202 goto out_freectl;
80203 msg_sys->msg_control = ctl_buf;
80204 @@ -2132,7 +2192,7 @@ static int __sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
80205 * kernel msghdr to use the kernel address space)
80206 */
80207
80208 - uaddr = (__force void __user *)msg_sys->msg_name;
80209 + uaddr = (void __force_user *)msg_sys->msg_name;
80210 uaddr_len = COMPAT_NAMELEN(msg);
80211 if (MSG_CMSG_COMPAT & flags) {
80212 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
80213 @@ -2761,7 +2821,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
80214 }
80215
80216 ifr = compat_alloc_user_space(buf_size);
80217 - rxnfc = (void *)ifr + ALIGN(sizeof(struct ifreq), 8);
80218 + rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
80219
80220 if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
80221 return -EFAULT;
80222 @@ -2785,12 +2845,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
80223 offsetof(struct ethtool_rxnfc, fs.ring_cookie));
80224
80225 if (copy_in_user(rxnfc, compat_rxnfc,
80226 - (void *)(&rxnfc->fs.m_ext + 1) -
80227 - (void *)rxnfc) ||
80228 + (void __user *)(&rxnfc->fs.m_ext + 1) -
80229 + (void __user *)rxnfc) ||
80230 copy_in_user(&rxnfc->fs.ring_cookie,
80231 &compat_rxnfc->fs.ring_cookie,
80232 - (void *)(&rxnfc->fs.location + 1) -
80233 - (void *)&rxnfc->fs.ring_cookie) ||
80234 + (void __user *)(&rxnfc->fs.location + 1) -
80235 + (void __user *)&rxnfc->fs.ring_cookie) ||
80236 copy_in_user(&rxnfc->rule_cnt, &compat_rxnfc->rule_cnt,
80237 sizeof(rxnfc->rule_cnt)))
80238 return -EFAULT;
80239 @@ -2802,12 +2862,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
80240
80241 if (convert_out) {
80242 if (copy_in_user(compat_rxnfc, rxnfc,
80243 - (const void *)(&rxnfc->fs.m_ext + 1) -
80244 - (const void *)rxnfc) ||
80245 + (const void __user *)(&rxnfc->fs.m_ext + 1) -
80246 + (const void __user *)rxnfc) ||
80247 copy_in_user(&compat_rxnfc->fs.ring_cookie,
80248 &rxnfc->fs.ring_cookie,
80249 - (const void *)(&rxnfc->fs.location + 1) -
80250 - (const void *)&rxnfc->fs.ring_cookie) ||
80251 + (const void __user *)(&rxnfc->fs.location + 1) -
80252 + (const void __user *)&rxnfc->fs.ring_cookie) ||
80253 copy_in_user(&compat_rxnfc->rule_cnt, &rxnfc->rule_cnt,
80254 sizeof(rxnfc->rule_cnt)))
80255 return -EFAULT;
80256 @@ -2877,7 +2937,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
80257 old_fs = get_fs();
80258 set_fs(KERNEL_DS);
80259 err = dev_ioctl(net, cmd,
80260 - (struct ifreq __user __force *) &kifr);
80261 + (struct ifreq __force_user *) &kifr);
80262 set_fs(old_fs);
80263
80264 return err;
80265 @@ -2986,7 +3046,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
80266
80267 old_fs = get_fs();
80268 set_fs(KERNEL_DS);
80269 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
80270 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
80271 set_fs(old_fs);
80272
80273 if (cmd == SIOCGIFMAP && !err) {
80274 @@ -3091,7 +3151,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
80275 ret |= __get_user(rtdev, &(ur4->rt_dev));
80276 if (rtdev) {
80277 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
80278 - r4.rt_dev = (char __user __force *)devname;
80279 + r4.rt_dev = (char __force_user *)devname;
80280 devname[15] = 0;
80281 } else
80282 r4.rt_dev = NULL;
80283 @@ -3317,8 +3377,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
80284 int __user *uoptlen;
80285 int err;
80286
80287 - uoptval = (char __user __force *) optval;
80288 - uoptlen = (int __user __force *) optlen;
80289 + uoptval = (char __force_user *) optval;
80290 + uoptlen = (int __force_user *) optlen;
80291
80292 set_fs(KERNEL_DS);
80293 if (level == SOL_SOCKET)
80294 @@ -3338,7 +3398,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
80295 char __user *uoptval;
80296 int err;
80297
80298 - uoptval = (char __user __force *) optval;
80299 + uoptval = (char __force_user *) optval;
80300
80301 set_fs(KERNEL_DS);
80302 if (level == SOL_SOCKET)
80303 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
80304 index 128494e..775d0e0 100644
80305 --- a/net/sunrpc/sched.c
80306 +++ b/net/sunrpc/sched.c
80307 @@ -240,9 +240,9 @@ static int rpc_wait_bit_killable(void *word)
80308 #ifdef RPC_DEBUG
80309 static void rpc_task_set_debuginfo(struct rpc_task *task)
80310 {
80311 - static atomic_t rpc_pid;
80312 + static atomic_unchecked_t rpc_pid;
80313
80314 - task->tk_pid = atomic_inc_return(&rpc_pid);
80315 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
80316 }
80317 #else
80318 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
80319 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
80320 index 8343737..677025e 100644
80321 --- a/net/sunrpc/xprtrdma/svc_rdma.c
80322 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
80323 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
80324 static unsigned int min_max_inline = 4096;
80325 static unsigned int max_max_inline = 65536;
80326
80327 -atomic_t rdma_stat_recv;
80328 -atomic_t rdma_stat_read;
80329 -atomic_t rdma_stat_write;
80330 -atomic_t rdma_stat_sq_starve;
80331 -atomic_t rdma_stat_rq_starve;
80332 -atomic_t rdma_stat_rq_poll;
80333 -atomic_t rdma_stat_rq_prod;
80334 -atomic_t rdma_stat_sq_poll;
80335 -atomic_t rdma_stat_sq_prod;
80336 +atomic_unchecked_t rdma_stat_recv;
80337 +atomic_unchecked_t rdma_stat_read;
80338 +atomic_unchecked_t rdma_stat_write;
80339 +atomic_unchecked_t rdma_stat_sq_starve;
80340 +atomic_unchecked_t rdma_stat_rq_starve;
80341 +atomic_unchecked_t rdma_stat_rq_poll;
80342 +atomic_unchecked_t rdma_stat_rq_prod;
80343 +atomic_unchecked_t rdma_stat_sq_poll;
80344 +atomic_unchecked_t rdma_stat_sq_prod;
80345
80346 /* Temporary NFS request map and context caches */
80347 struct kmem_cache *svc_rdma_map_cachep;
80348 @@ -110,7 +110,7 @@ static int read_reset_stat(ctl_table *table, int write,
80349 len -= *ppos;
80350 if (len > *lenp)
80351 len = *lenp;
80352 - if (len && copy_to_user(buffer, str_buf, len))
80353 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
80354 return -EFAULT;
80355 *lenp = len;
80356 *ppos += len;
80357 @@ -151,63 +151,63 @@ static ctl_table svcrdma_parm_table[] = {
80358 {
80359 .procname = "rdma_stat_read",
80360 .data = &rdma_stat_read,
80361 - .maxlen = sizeof(atomic_t),
80362 + .maxlen = sizeof(atomic_unchecked_t),
80363 .mode = 0644,
80364 .proc_handler = read_reset_stat,
80365 },
80366 {
80367 .procname = "rdma_stat_recv",
80368 .data = &rdma_stat_recv,
80369 - .maxlen = sizeof(atomic_t),
80370 + .maxlen = sizeof(atomic_unchecked_t),
80371 .mode = 0644,
80372 .proc_handler = read_reset_stat,
80373 },
80374 {
80375 .procname = "rdma_stat_write",
80376 .data = &rdma_stat_write,
80377 - .maxlen = sizeof(atomic_t),
80378 + .maxlen = sizeof(atomic_unchecked_t),
80379 .mode = 0644,
80380 .proc_handler = read_reset_stat,
80381 },
80382 {
80383 .procname = "rdma_stat_sq_starve",
80384 .data = &rdma_stat_sq_starve,
80385 - .maxlen = sizeof(atomic_t),
80386 + .maxlen = sizeof(atomic_unchecked_t),
80387 .mode = 0644,
80388 .proc_handler = read_reset_stat,
80389 },
80390 {
80391 .procname = "rdma_stat_rq_starve",
80392 .data = &rdma_stat_rq_starve,
80393 - .maxlen = sizeof(atomic_t),
80394 + .maxlen = sizeof(atomic_unchecked_t),
80395 .mode = 0644,
80396 .proc_handler = read_reset_stat,
80397 },
80398 {
80399 .procname = "rdma_stat_rq_poll",
80400 .data = &rdma_stat_rq_poll,
80401 - .maxlen = sizeof(atomic_t),
80402 + .maxlen = sizeof(atomic_unchecked_t),
80403 .mode = 0644,
80404 .proc_handler = read_reset_stat,
80405 },
80406 {
80407 .procname = "rdma_stat_rq_prod",
80408 .data = &rdma_stat_rq_prod,
80409 - .maxlen = sizeof(atomic_t),
80410 + .maxlen = sizeof(atomic_unchecked_t),
80411 .mode = 0644,
80412 .proc_handler = read_reset_stat,
80413 },
80414 {
80415 .procname = "rdma_stat_sq_poll",
80416 .data = &rdma_stat_sq_poll,
80417 - .maxlen = sizeof(atomic_t),
80418 + .maxlen = sizeof(atomic_unchecked_t),
80419 .mode = 0644,
80420 .proc_handler = read_reset_stat,
80421 },
80422 {
80423 .procname = "rdma_stat_sq_prod",
80424 .data = &rdma_stat_sq_prod,
80425 - .maxlen = sizeof(atomic_t),
80426 + .maxlen = sizeof(atomic_unchecked_t),
80427 .mode = 0644,
80428 .proc_handler = read_reset_stat,
80429 },
80430 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
80431 index 41cb63b..c4a1489 100644
80432 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
80433 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
80434 @@ -501,7 +501,7 @@ next_sge:
80435 svc_rdma_put_context(ctxt, 0);
80436 goto out;
80437 }
80438 - atomic_inc(&rdma_stat_read);
80439 + atomic_inc_unchecked(&rdma_stat_read);
80440
80441 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
80442 chl_map->ch[ch_no].count -= read_wr.num_sge;
80443 @@ -611,7 +611,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
80444 dto_q);
80445 list_del_init(&ctxt->dto_q);
80446 } else {
80447 - atomic_inc(&rdma_stat_rq_starve);
80448 + atomic_inc_unchecked(&rdma_stat_rq_starve);
80449 clear_bit(XPT_DATA, &xprt->xpt_flags);
80450 ctxt = NULL;
80451 }
80452 @@ -631,7 +631,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
80453 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
80454 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
80455 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
80456 - atomic_inc(&rdma_stat_recv);
80457 + atomic_inc_unchecked(&rdma_stat_recv);
80458
80459 /* Build up the XDR from the receive buffers. */
80460 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
80461 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
80462 index 42eb7ba..c887c45 100644
80463 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
80464 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
80465 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
80466 write_wr.wr.rdma.remote_addr = to;
80467
80468 /* Post It */
80469 - atomic_inc(&rdma_stat_write);
80470 + atomic_inc_unchecked(&rdma_stat_write);
80471 if (svc_rdma_send(xprt, &write_wr))
80472 goto err;
80473 return 0;
80474 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
80475 index 73b428b..5f3f8f3 100644
80476 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
80477 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
80478 @@ -292,7 +292,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
80479 return;
80480
80481 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
80482 - atomic_inc(&rdma_stat_rq_poll);
80483 + atomic_inc_unchecked(&rdma_stat_rq_poll);
80484
80485 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
80486 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
80487 @@ -314,7 +314,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
80488 }
80489
80490 if (ctxt)
80491 - atomic_inc(&rdma_stat_rq_prod);
80492 + atomic_inc_unchecked(&rdma_stat_rq_prod);
80493
80494 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
80495 /*
80496 @@ -386,7 +386,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
80497 return;
80498
80499 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
80500 - atomic_inc(&rdma_stat_sq_poll);
80501 + atomic_inc_unchecked(&rdma_stat_sq_poll);
80502 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
80503 if (wc.status != IB_WC_SUCCESS)
80504 /* Close the transport */
80505 @@ -404,7 +404,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
80506 }
80507
80508 if (ctxt)
80509 - atomic_inc(&rdma_stat_sq_prod);
80510 + atomic_inc_unchecked(&rdma_stat_sq_prod);
80511 }
80512
80513 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
80514 @@ -1266,7 +1266,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
80515 spin_lock_bh(&xprt->sc_lock);
80516 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
80517 spin_unlock_bh(&xprt->sc_lock);
80518 - atomic_inc(&rdma_stat_sq_starve);
80519 + atomic_inc_unchecked(&rdma_stat_sq_starve);
80520
80521 /* See if we can opportunistically reap SQ WR to make room */
80522 sq_cq_reap(xprt);
80523 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
80524 index e3a6e37..be2ea77 100644
80525 --- a/net/sysctl_net.c
80526 +++ b/net/sysctl_net.c
80527 @@ -43,7 +43,7 @@ static int net_ctl_permissions(struct ctl_table_root *root,
80528 struct ctl_table *table)
80529 {
80530 /* Allow network administrator to have same access as root. */
80531 - if (capable(CAP_NET_ADMIN)) {
80532 + if (capable_nolog(CAP_NET_ADMIN)) {
80533 int mode = (table->mode >> 6) & 7;
80534 return (mode << 6) | (mode << 3) | mode;
80535 }
80536 diff --git a/net/tipc/link.c b/net/tipc/link.c
80537 index 1c1e615..113e0ae 100644
80538 --- a/net/tipc/link.c
80539 +++ b/net/tipc/link.c
80540 @@ -1171,7 +1171,7 @@ static int link_send_sections_long(struct tipc_port *sender,
80541 struct tipc_msg fragm_hdr;
80542 struct sk_buff *buf, *buf_chain, *prev;
80543 u32 fragm_crs, fragm_rest, hsz, sect_rest;
80544 - const unchar *sect_crs;
80545 + const unchar __user *sect_crs;
80546 int curr_sect;
80547 u32 fragm_no;
80548
80549 @@ -1212,7 +1212,7 @@ again:
80550
80551 if (!sect_rest) {
80552 sect_rest = msg_sect[++curr_sect].iov_len;
80553 - sect_crs = (const unchar *)msg_sect[curr_sect].iov_base;
80554 + sect_crs = (const unchar __user *)msg_sect[curr_sect].iov_base;
80555 }
80556
80557 if (sect_rest < fragm_rest)
80558 @@ -1231,7 +1231,7 @@ error:
80559 }
80560 } else
80561 skb_copy_to_linear_data_offset(buf, fragm_crs,
80562 - sect_crs, sz);
80563 + (const void __force_kernel *)sect_crs, sz);
80564 sect_crs += sz;
80565 sect_rest -= sz;
80566 fragm_crs += sz;
80567 diff --git a/net/tipc/msg.c b/net/tipc/msg.c
80568 index f2db8a8..9245aa4 100644
80569 --- a/net/tipc/msg.c
80570 +++ b/net/tipc/msg.c
80571 @@ -98,7 +98,7 @@ int tipc_msg_build(struct tipc_msg *hdr, struct iovec const *msg_sect,
80572 msg_sect[cnt].iov_len);
80573 else
80574 skb_copy_to_linear_data_offset(*buf, pos,
80575 - msg_sect[cnt].iov_base,
80576 + (const void __force_kernel *)msg_sect[cnt].iov_base,
80577 msg_sect[cnt].iov_len);
80578 pos += msg_sect[cnt].iov_len;
80579 }
80580 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
80581 index 5ed5965..90abe34 100644
80582 --- a/net/tipc/subscr.c
80583 +++ b/net/tipc/subscr.c
80584 @@ -96,7 +96,7 @@ static void subscr_send_event(struct tipc_subscription *sub,
80585 {
80586 struct iovec msg_sect;
80587
80588 - msg_sect.iov_base = (void *)&sub->evt;
80589 + msg_sect.iov_base = (void __force_user *)&sub->evt;
80590 msg_sect.iov_len = sizeof(struct tipc_event);
80591
80592 sub->evt.event = htohl(event, sub->swap);
80593 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
80594 index c5ee4ff..e905948 100644
80595 --- a/net/unix/af_unix.c
80596 +++ b/net/unix/af_unix.c
80597 @@ -789,6 +789,12 @@ static struct sock *unix_find_other(struct net *net,
80598 err = -ECONNREFUSED;
80599 if (!S_ISSOCK(inode->i_mode))
80600 goto put_fail;
80601 +
80602 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
80603 + err = -EACCES;
80604 + goto put_fail;
80605 + }
80606 +
80607 u = unix_find_socket_byinode(inode);
80608 if (!u)
80609 goto put_fail;
80610 @@ -809,6 +815,13 @@ static struct sock *unix_find_other(struct net *net,
80611 if (u) {
80612 struct dentry *dentry;
80613 dentry = unix_sk(u)->path.dentry;
80614 +
80615 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
80616 + err = -EPERM;
80617 + sock_put(u);
80618 + goto fail;
80619 + }
80620 +
80621 if (dentry)
80622 touch_atime(&unix_sk(u)->path);
80623 } else
80624 @@ -842,12 +855,18 @@ static int unix_mknod(const char *sun_path, umode_t mode, struct path *res)
80625 */
80626 err = security_path_mknod(&path, dentry, mode, 0);
80627 if (!err) {
80628 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
80629 + err = -EACCES;
80630 + goto out;
80631 + }
80632 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
80633 if (!err) {
80634 res->mnt = mntget(path.mnt);
80635 res->dentry = dget(dentry);
80636 + gr_handle_create(dentry, path.mnt);
80637 }
80638 }
80639 +out:
80640 done_path_create(&path, dentry);
80641 return err;
80642 }
80643 diff --git a/net/wireless/core.h b/net/wireless/core.h
80644 index bc7430b..35349de 100644
80645 --- a/net/wireless/core.h
80646 +++ b/net/wireless/core.h
80647 @@ -28,7 +28,7 @@ struct cfg80211_registered_device {
80648 struct mutex mtx;
80649
80650 /* rfkill support */
80651 - struct rfkill_ops rfkill_ops;
80652 + rfkill_ops_no_const rfkill_ops;
80653 struct rfkill *rfkill;
80654 struct work_struct rfkill_sync;
80655
80656 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
80657 index b0eb7aa..7d73e82 100644
80658 --- a/net/wireless/wext-core.c
80659 +++ b/net/wireless/wext-core.c
80660 @@ -748,8 +748,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
80661 */
80662
80663 /* Support for very large requests */
80664 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
80665 - (user_length > descr->max_tokens)) {
80666 + if (user_length > descr->max_tokens) {
80667 /* Allow userspace to GET more than max so
80668 * we can support any size GET requests.
80669 * There is still a limit : -ENOMEM.
80670 @@ -788,22 +787,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
80671 }
80672 }
80673
80674 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
80675 - /*
80676 - * If this is a GET, but not NOMAX, it means that the extra
80677 - * data is not bounded by userspace, but by max_tokens. Thus
80678 - * set the length to max_tokens. This matches the extra data
80679 - * allocation.
80680 - * The driver should fill it with the number of tokens it
80681 - * provided, and it may check iwp->length rather than having
80682 - * knowledge of max_tokens. If the driver doesn't change the
80683 - * iwp->length, this ioctl just copies back max_token tokens
80684 - * filled with zeroes. Hopefully the driver isn't claiming
80685 - * them to be valid data.
80686 - */
80687 - iwp->length = descr->max_tokens;
80688 - }
80689 -
80690 err = handler(dev, info, (union iwreq_data *) iwp, extra);
80691
80692 iwp->length += essid_compat;
80693 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
80694 index 387848e..a6667a2 100644
80695 --- a/net/xfrm/xfrm_policy.c
80696 +++ b/net/xfrm/xfrm_policy.c
80697 @@ -300,7 +300,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
80698 {
80699 policy->walk.dead = 1;
80700
80701 - atomic_inc(&policy->genid);
80702 + atomic_inc_unchecked(&policy->genid);
80703
80704 if (del_timer(&policy->timer))
80705 xfrm_pol_put(policy);
80706 @@ -584,7 +584,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
80707 hlist_add_head(&policy->bydst, chain);
80708 xfrm_pol_hold(policy);
80709 net->xfrm.policy_count[dir]++;
80710 - atomic_inc(&flow_cache_genid);
80711 + atomic_inc_unchecked(&flow_cache_genid);
80712 rt_genid_bump(net);
80713 if (delpol)
80714 __xfrm_policy_unlink(delpol, dir);
80715 @@ -1533,7 +1533,7 @@ free_dst:
80716 goto out;
80717 }
80718
80719 -static int inline
80720 +static inline int
80721 xfrm_dst_alloc_copy(void **target, const void *src, int size)
80722 {
80723 if (!*target) {
80724 @@ -1545,7 +1545,7 @@ xfrm_dst_alloc_copy(void **target, const void *src, int size)
80725 return 0;
80726 }
80727
80728 -static int inline
80729 +static inline int
80730 xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
80731 {
80732 #ifdef CONFIG_XFRM_SUB_POLICY
80733 @@ -1557,7 +1557,7 @@ xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
80734 #endif
80735 }
80736
80737 -static int inline
80738 +static inline int
80739 xfrm_dst_update_origin(struct dst_entry *dst, const struct flowi *fl)
80740 {
80741 #ifdef CONFIG_XFRM_SUB_POLICY
80742 @@ -1651,7 +1651,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
80743
80744 xdst->num_pols = num_pols;
80745 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols);
80746 - xdst->policy_genid = atomic_read(&pols[0]->genid);
80747 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
80748
80749 return xdst;
80750 }
80751 @@ -2352,7 +2352,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
80752 if (xdst->xfrm_genid != dst->xfrm->genid)
80753 return 0;
80754 if (xdst->num_pols > 0 &&
80755 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
80756 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
80757 return 0;
80758
80759 mtu = dst_mtu(dst->child);
80760 @@ -2891,7 +2891,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
80761 sizeof(pol->xfrm_vec[i].saddr));
80762 pol->xfrm_vec[i].encap_family = mp->new_family;
80763 /* flush bundles */
80764 - atomic_inc(&pol->genid);
80765 + atomic_inc_unchecked(&pol->genid);
80766 }
80767 }
80768
80769 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
80770 index ff1720d..ed8475e 100644
80771 --- a/scripts/Makefile.build
80772 +++ b/scripts/Makefile.build
80773 @@ -111,7 +111,7 @@ endif
80774 endif
80775
80776 # Do not include host rules unless needed
80777 -ifneq ($(hostprogs-y)$(hostprogs-m),)
80778 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
80779 include scripts/Makefile.host
80780 endif
80781
80782 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
80783 index 686cb0d..9d653bf 100644
80784 --- a/scripts/Makefile.clean
80785 +++ b/scripts/Makefile.clean
80786 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
80787 __clean-files := $(extra-y) $(always) \
80788 $(targets) $(clean-files) \
80789 $(host-progs) \
80790 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
80791 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
80792 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
80793
80794 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
80795
80796 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
80797 index 1ac414f..38575f7 100644
80798 --- a/scripts/Makefile.host
80799 +++ b/scripts/Makefile.host
80800 @@ -31,6 +31,8 @@
80801 # Note: Shared libraries consisting of C++ files are not supported
80802
80803 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
80804 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
80805 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
80806
80807 # C code
80808 # Executables compiled from a single .c file
80809 @@ -54,11 +56,15 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
80810 # Shared libaries (only .c supported)
80811 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
80812 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
80813 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
80814 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
80815 # Remove .so files from "xxx-objs"
80816 host-cobjs := $(filter-out %.so,$(host-cobjs))
80817 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
80818
80819 -#Object (.o) files used by the shared libaries
80820 +# Object (.o) files used by the shared libaries
80821 host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
80822 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
80823
80824 # output directory for programs/.o files
80825 # hostprogs-y := tools/build may have been specified. Retrieve directory
80826 @@ -82,7 +88,9 @@ host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
80827 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
80828 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
80829 host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
80830 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
80831 host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
80832 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
80833 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
80834
80835 obj-dirs += $(host-objdirs)
80836 @@ -156,6 +164,13 @@ quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
80837 $(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
80838 $(call if_changed_dep,host-cshobjs)
80839
80840 +# Compile .c file, create position independent .o file
80841 +# host-cxxshobjs -> .o
80842 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
80843 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
80844 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
80845 + $(call if_changed_dep,host-cxxshobjs)
80846 +
80847 # Link a shared library, based on position independent .o files
80848 # *.o -> .so shared library (host-cshlib)
80849 quiet_cmd_host-cshlib = HOSTLLD -shared $@
80850 @@ -165,6 +180,15 @@ quiet_cmd_host-cshlib = HOSTLLD -shared $@
80851 $(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
80852 $(call if_changed,host-cshlib)
80853
80854 +# Link a shared library, based on position independent .o files
80855 +# *.o -> .so shared library (host-cxxshlib)
80856 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
80857 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
80858 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
80859 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
80860 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
80861 + $(call if_changed,host-cxxshlib)
80862 +
80863 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
80864 - $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs)
80865 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
80866
80867 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
80868 index cb1f50c..cef2a7c 100644
80869 --- a/scripts/basic/fixdep.c
80870 +++ b/scripts/basic/fixdep.c
80871 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
80872 /*
80873 * Lookup a value in the configuration string.
80874 */
80875 -static int is_defined_config(const char *name, int len, unsigned int hash)
80876 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
80877 {
80878 struct item *aux;
80879
80880 @@ -211,10 +211,10 @@ static void clear_config(void)
80881 /*
80882 * Record the use of a CONFIG_* word.
80883 */
80884 -static void use_config(const char *m, int slen)
80885 +static void use_config(const char *m, unsigned int slen)
80886 {
80887 unsigned int hash = strhash(m, slen);
80888 - int c, i;
80889 + unsigned int c, i;
80890
80891 if (is_defined_config(m, slen, hash))
80892 return;
80893 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
80894
80895 static void parse_config_file(const char *map, size_t len)
80896 {
80897 - const int *end = (const int *) (map + len);
80898 + const unsigned int *end = (const unsigned int *) (map + len);
80899 /* start at +1, so that p can never be < map */
80900 - const int *m = (const int *) map + 1;
80901 + const unsigned int *m = (const unsigned int *) map + 1;
80902 const char *p, *q;
80903
80904 for (; m < end; m++) {
80905 @@ -406,7 +406,7 @@ static void print_deps(void)
80906 static void traps(void)
80907 {
80908 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
80909 - int *p = (int *)test;
80910 + unsigned int *p = (unsigned int *)test;
80911
80912 if (*p != INT_CONF) {
80913 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
80914 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
80915 new file mode 100644
80916 index 0000000..008ac1a
80917 --- /dev/null
80918 +++ b/scripts/gcc-plugin.sh
80919 @@ -0,0 +1,17 @@
80920 +#!/bin/bash
80921 +plugincc=`$1 -x c -shared - -o /dev/null -I\`$3 -print-file-name=plugin\`/include 2>&1 <<EOF
80922 +#include "gcc-plugin.h"
80923 +#include "tree.h"
80924 +#include "tm.h"
80925 +#include "rtl.h"
80926 +#ifdef ENABLE_BUILD_WITH_CXX
80927 +#warning $2
80928 +#else
80929 +#warning $1
80930 +#endif
80931 +EOF`
80932 +if [ $? -eq 0 ]
80933 +then
80934 + [[ "$plugincc" =~ "$1" ]] && echo "$1"
80935 + [[ "$plugincc" =~ "$2" ]] && echo "$2"
80936 +fi
80937 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
80938 index b3d907e..a4782ab 100644
80939 --- a/scripts/link-vmlinux.sh
80940 +++ b/scripts/link-vmlinux.sh
80941 @@ -152,7 +152,7 @@ else
80942 fi;
80943
80944 # final build of init/
80945 -${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
80946 +${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}" GCC_PLUGINS_AFLAGS="${GCC_PLUGINS_AFLAGS}"
80947
80948 kallsymso=""
80949 kallsyms_vmlinux=""
80950 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
80951 index 7ed6864..b6e90e6 100644
80952 --- a/scripts/mod/file2alias.c
80953 +++ b/scripts/mod/file2alias.c
80954 @@ -128,7 +128,7 @@ static void device_id_check(const char *modname, const char *device_id,
80955 unsigned long size, unsigned long id_size,
80956 void *symval)
80957 {
80958 - int i;
80959 + unsigned int i;
80960
80961 if (size % id_size || size < id_size) {
80962 if (cross_build != 0)
80963 @@ -158,7 +158,7 @@ static void device_id_check(const char *modname, const char *device_id,
80964 /* USB is special because the bcdDevice can be matched against a numeric range */
80965 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */
80966 static void do_usb_entry(struct usb_device_id *id,
80967 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
80968 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
80969 unsigned char range_lo, unsigned char range_hi,
80970 unsigned char max, struct module *mod)
80971 {
80972 @@ -262,7 +262,7 @@ static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod)
80973 {
80974 unsigned int devlo, devhi;
80975 unsigned char chi, clo, max;
80976 - int ndigits;
80977 + unsigned int ndigits;
80978
80979 id->match_flags = TO_NATIVE(id->match_flags);
80980 id->idVendor = TO_NATIVE(id->idVendor);
80981 @@ -507,7 +507,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
80982 for (i = 0; i < count; i++) {
80983 const char *id = (char *)devs[i].id;
80984 char acpi_id[sizeof(devs[0].id)];
80985 - int j;
80986 + unsigned int j;
80987
80988 buf_printf(&mod->dev_table_buf,
80989 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
80990 @@ -537,7 +537,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
80991
80992 for (j = 0; j < PNP_MAX_DEVICES; j++) {
80993 const char *id = (char *)card->devs[j].id;
80994 - int i2, j2;
80995 + unsigned int i2, j2;
80996 int dup = 0;
80997
80998 if (!id[0])
80999 @@ -563,7 +563,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
81000 /* add an individual alias for every device entry */
81001 if (!dup) {
81002 char acpi_id[sizeof(card->devs[0].id)];
81003 - int k;
81004 + unsigned int k;
81005
81006 buf_printf(&mod->dev_table_buf,
81007 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
81008 @@ -888,7 +888,7 @@ static void dmi_ascii_filter(char *d, const char *s)
81009 static int do_dmi_entry(const char *filename, struct dmi_system_id *id,
81010 char *alias)
81011 {
81012 - int i, j;
81013 + unsigned int i, j;
81014
81015 sprintf(alias, "dmi*");
81016
81017 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
81018 index 68e9f5e..ac7759b 100644
81019 --- a/scripts/mod/modpost.c
81020 +++ b/scripts/mod/modpost.c
81021 @@ -930,6 +930,7 @@ enum mismatch {
81022 ANY_INIT_TO_ANY_EXIT,
81023 ANY_EXIT_TO_ANY_INIT,
81024 EXPORT_TO_INIT_EXIT,
81025 + DATA_TO_TEXT
81026 };
81027
81028 struct sectioncheck {
81029 @@ -1044,6 +1045,12 @@ const struct sectioncheck sectioncheck[] = {
81030 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
81031 .mismatch = EXPORT_TO_INIT_EXIT,
81032 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
81033 +},
81034 +/* Do not reference code from writable data */
81035 +{
81036 + .fromsec = { DATA_SECTIONS, NULL },
81037 + .tosec = { TEXT_SECTIONS, NULL },
81038 + .mismatch = DATA_TO_TEXT
81039 }
81040 };
81041
81042 @@ -1166,10 +1173,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
81043 continue;
81044 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
81045 continue;
81046 - if (sym->st_value == addr)
81047 - return sym;
81048 /* Find a symbol nearby - addr are maybe negative */
81049 d = sym->st_value - addr;
81050 + if (d == 0)
81051 + return sym;
81052 if (d < 0)
81053 d = addr - sym->st_value;
81054 if (d < distance) {
81055 @@ -1448,6 +1455,14 @@ static void report_sec_mismatch(const char *modname,
81056 tosym, prl_to, prl_to, tosym);
81057 free(prl_to);
81058 break;
81059 + case DATA_TO_TEXT:
81060 +#if 0
81061 + fprintf(stderr,
81062 + "The %s %s:%s references\n"
81063 + "the %s %s:%s%s\n",
81064 + from, fromsec, fromsym, to, tosec, tosym, to_p);
81065 +#endif
81066 + break;
81067 }
81068 fprintf(stderr, "\n");
81069 }
81070 @@ -1682,7 +1697,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
81071 static void check_sec_ref(struct module *mod, const char *modname,
81072 struct elf_info *elf)
81073 {
81074 - int i;
81075 + unsigned int i;
81076 Elf_Shdr *sechdrs = elf->sechdrs;
81077
81078 /* Walk through all sections */
81079 @@ -1780,7 +1795,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
81080 va_end(ap);
81081 }
81082
81083 -void buf_write(struct buffer *buf, const char *s, int len)
81084 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
81085 {
81086 if (buf->size - buf->pos < len) {
81087 buf->size += len + SZ;
81088 @@ -1998,7 +2013,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
81089 if (fstat(fileno(file), &st) < 0)
81090 goto close_write;
81091
81092 - if (st.st_size != b->pos)
81093 + if (st.st_size != (off_t)b->pos)
81094 goto close_write;
81095
81096 tmp = NOFAIL(malloc(b->pos));
81097 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
81098 index 51207e4..f7d603d 100644
81099 --- a/scripts/mod/modpost.h
81100 +++ b/scripts/mod/modpost.h
81101 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
81102
81103 struct buffer {
81104 char *p;
81105 - int pos;
81106 - int size;
81107 + unsigned int pos;
81108 + unsigned int size;
81109 };
81110
81111 void __attribute__((format(printf, 2, 3)))
81112 buf_printf(struct buffer *buf, const char *fmt, ...);
81113
81114 void
81115 -buf_write(struct buffer *buf, const char *s, int len);
81116 +buf_write(struct buffer *buf, const char *s, unsigned int len);
81117
81118 struct module {
81119 struct module *next;
81120 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
81121 index 9dfcd6d..099068e 100644
81122 --- a/scripts/mod/sumversion.c
81123 +++ b/scripts/mod/sumversion.c
81124 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
81125 goto out;
81126 }
81127
81128 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
81129 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
81130 warn("writing sum in %s failed: %s\n",
81131 filename, strerror(errno));
81132 goto out;
81133 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
81134 index 5c11312..72742b5 100644
81135 --- a/scripts/pnmtologo.c
81136 +++ b/scripts/pnmtologo.c
81137 @@ -237,14 +237,14 @@ static void write_header(void)
81138 fprintf(out, " * Linux logo %s\n", logoname);
81139 fputs(" */\n\n", out);
81140 fputs("#include <linux/linux_logo.h>\n\n", out);
81141 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
81142 + fprintf(out, "static unsigned char %s_data[] = {\n",
81143 logoname);
81144 }
81145
81146 static void write_footer(void)
81147 {
81148 fputs("\n};\n\n", out);
81149 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
81150 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
81151 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
81152 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
81153 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
81154 @@ -374,7 +374,7 @@ static void write_logo_clut224(void)
81155 fputs("\n};\n\n", out);
81156
81157 /* write logo clut */
81158 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
81159 + fprintf(out, "static unsigned char %s_clut[] = {\n",
81160 logoname);
81161 write_hex_cnt = 0;
81162 for (i = 0; i < logo_clutsize; i++) {
81163 diff --git a/security/Kconfig b/security/Kconfig
81164 index e9c6ac7..e7feb0d 100644
81165 --- a/security/Kconfig
81166 +++ b/security/Kconfig
81167 @@ -4,6 +4,896 @@
81168
81169 menu "Security options"
81170
81171 +menu "Grsecurity"
81172 +
81173 + config ARCH_TRACK_EXEC_LIMIT
81174 + bool
81175 +
81176 + config PAX_KERNEXEC_PLUGIN
81177 + bool
81178 +
81179 + config PAX_PER_CPU_PGD
81180 + bool
81181 +
81182 + config TASK_SIZE_MAX_SHIFT
81183 + int
81184 + depends on X86_64
81185 + default 47 if !PAX_PER_CPU_PGD
81186 + default 42 if PAX_PER_CPU_PGD
81187 +
81188 + config PAX_ENABLE_PAE
81189 + bool
81190 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
81191 +
81192 + config PAX_USERCOPY_SLABS
81193 + bool
81194 +
81195 +config GRKERNSEC
81196 + bool "Grsecurity"
81197 + select CRYPTO
81198 + select CRYPTO_SHA256
81199 + select PROC_FS
81200 + select STOP_MACHINE
81201 + help
81202 + If you say Y here, you will be able to configure many features
81203 + that will enhance the security of your system. It is highly
81204 + recommended that you say Y here and read through the help
81205 + for each option so that you fully understand the features and
81206 + can evaluate their usefulness for your machine.
81207 +
81208 +choice
81209 + prompt "Configuration Method"
81210 + depends on GRKERNSEC
81211 + default GRKERNSEC_CONFIG_CUSTOM
81212 + help
81213 +
81214 +config GRKERNSEC_CONFIG_AUTO
81215 + bool "Automatic"
81216 + help
81217 + If you choose this configuration method, you'll be able to answer a small
81218 + number of simple questions about how you plan to use this kernel.
81219 + The settings of grsecurity and PaX will be automatically configured for
81220 + the highest commonly-used settings within the provided constraints.
81221 +
81222 + If you require additional configuration, custom changes can still be made
81223 + from the "custom configuration" menu.
81224 +
81225 +config GRKERNSEC_CONFIG_CUSTOM
81226 + bool "Custom"
81227 + help
81228 + If you choose this configuration method, you'll be able to configure all
81229 + grsecurity and PaX settings manually. Via this method, no options are
81230 + automatically enabled.
81231 +
81232 +endchoice
81233 +
81234 +choice
81235 + prompt "Usage Type"
81236 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
81237 + default GRKERNSEC_CONFIG_SERVER
81238 + help
81239 +
81240 +config GRKERNSEC_CONFIG_SERVER
81241 + bool "Server"
81242 + help
81243 + Choose this option if you plan to use this kernel on a server.
81244 +
81245 +config GRKERNSEC_CONFIG_DESKTOP
81246 + bool "Desktop"
81247 + help
81248 + Choose this option if you plan to use this kernel on a desktop.
81249 +
81250 +endchoice
81251 +
81252 +choice
81253 + prompt "Virtualization Type"
81254 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
81255 + default GRKERNSEC_CONFIG_VIRT_NONE
81256 + help
81257 +
81258 +config GRKERNSEC_CONFIG_VIRT_NONE
81259 + bool "None"
81260 + help
81261 + Choose this option if this kernel will be run on bare metal.
81262 +
81263 +config GRKERNSEC_CONFIG_VIRT_GUEST
81264 + bool "Guest"
81265 + help
81266 + Choose this option if this kernel will be run as a VM guest.
81267 +
81268 +config GRKERNSEC_CONFIG_VIRT_HOST
81269 + bool "Host"
81270 + help
81271 + Choose this option if this kernel will be run as a VM host.
81272 +
81273 +endchoice
81274 +
81275 +choice
81276 + prompt "Virtualization Hardware"
81277 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
81278 + help
81279 +
81280 +config GRKERNSEC_CONFIG_VIRT_EPT
81281 + bool "EPT/RVI Processor Support"
81282 + depends on X86
81283 + help
81284 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
81285 + hardware virtualization. This allows for additional kernel hardening protections
81286 + to operate without additional performance impact.
81287 +
81288 + To see if your Intel processor supports EPT, see:
81289 + http://ark.intel.com/Products/VirtualizationTechnology
81290 + (Most Core i3/5/7 support EPT)
81291 +
81292 + To see if your AMD processor supports RVI, see:
81293 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
81294 +
81295 +config GRKERNSEC_CONFIG_VIRT_SOFT
81296 + bool "First-gen/No Hardware Virtualization"
81297 + help
81298 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
81299 + support hardware virtualization or doesn't support the EPT/RVI extensions.
81300 +
81301 +endchoice
81302 +
81303 +choice
81304 + prompt "Virtualization Software"
81305 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
81306 + help
81307 +
81308 +config GRKERNSEC_CONFIG_VIRT_XEN
81309 + bool "Xen"
81310 + help
81311 + Choose this option if this kernel is running as a Xen guest or host.
81312 +
81313 +config GRKERNSEC_CONFIG_VIRT_VMWARE
81314 + bool "VMWare"
81315 + help
81316 + Choose this option if this kernel is running as a VMWare guest or host.
81317 +
81318 +config GRKERNSEC_CONFIG_VIRT_KVM
81319 + bool "KVM"
81320 + help
81321 + Choose this option if this kernel is running as a KVM guest or host.
81322 +
81323 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
81324 + bool "VirtualBox"
81325 + help
81326 + Choose this option if this kernel is running as a VirtualBox guest or host.
81327 +
81328 +endchoice
81329 +
81330 +choice
81331 + prompt "Required Priorities"
81332 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
81333 + default GRKERNSEC_CONFIG_PRIORITY_PERF
81334 + help
81335 +
81336 +config GRKERNSEC_CONFIG_PRIORITY_PERF
81337 + bool "Performance"
81338 + help
81339 + Choose this option if performance is of highest priority for this deployment
81340 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
81341 + and freed memory sanitizing will be disabled.
81342 +
81343 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
81344 + bool "Security"
81345 + help
81346 + Choose this option if security is of highest priority for this deployment of
81347 + grsecurity. UDEREF, kernel stack clearing, and freed memory sanitizing will
81348 + be enabled for this kernel. In a worst-case scenario, these features can
81349 + introduce a 20% performance hit (UDEREF on x64 contributing half of this hit).
81350 +
81351 +endchoice
81352 +
81353 +menu "Default Special Groups"
81354 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
81355 +
81356 +config GRKERNSEC_PROC_GID
81357 + int "GID exempted from /proc restrictions"
81358 + default 1001
81359 + help
81360 + Setting this GID determines which group will be exempted from
81361 + grsecurity's /proc restrictions, allowing users of the specified
81362 + group to view network statistics and the existence of other users'
81363 + processes on the system. This GID may also be chosen at boot time
81364 + via "grsec_proc_gid=" on the kernel commandline.
81365 +
81366 +config GRKERNSEC_TPE_UNTRUSTED_GID
81367 + int "GID for TPE-untrusted users"
81368 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
81369 + default 1005
81370 + help
81371 + Setting this GID determines which group untrusted users should
81372 + be added to. These users will be placed under grsecurity's Trusted Path
81373 + Execution mechanism, preventing them from executing their own binaries.
81374 + The users will only be able to execute binaries in directories owned and
81375 + writable only by the root user. If the sysctl option is enabled, a sysctl
81376 + option with name "tpe_gid" is created.
81377 +
81378 +config GRKERNSEC_TPE_TRUSTED_GID
81379 + int "GID for TPE-trusted users"
81380 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
81381 + default 1005
81382 + help
81383 + Setting this GID determines what group TPE restrictions will be
81384 + *disabled* for. If the sysctl option is enabled, a sysctl option
81385 + with name "tpe_gid" is created.
81386 +
81387 +config GRKERNSEC_SYMLINKOWN_GID
81388 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
81389 + depends on GRKERNSEC_CONFIG_SERVER
81390 + default 1006
81391 + help
81392 + Setting this GID determines what group kernel-enforced
81393 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
81394 + is enabled, a sysctl option with name "symlinkown_gid" is created.
81395 +
81396 +
81397 +endmenu
81398 +
81399 +menu "Customize Configuration"
81400 +depends on GRKERNSEC
81401 +
81402 +menu "PaX"
81403 +
81404 +config PAX
81405 + bool "Enable various PaX features"
81406 + default y if GRKERNSEC_CONFIG_AUTO
81407 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
81408 + help
81409 + This allows you to enable various PaX features. PaX adds
81410 + intrusion prevention mechanisms to the kernel that reduce
81411 + the risks posed by exploitable memory corruption bugs.
81412 +
81413 +menu "PaX Control"
81414 + depends on PAX
81415 +
81416 +config PAX_SOFTMODE
81417 + bool 'Support soft mode'
81418 + help
81419 + Enabling this option will allow you to run PaX in soft mode, that
81420 + is, PaX features will not be enforced by default, only on executables
81421 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
81422 + support as they are the only way to mark executables for soft mode use.
81423 +
81424 + Soft mode can be activated by using the "pax_softmode=1" kernel command
81425 + line option on boot. Furthermore you can control various PaX features
81426 + at runtime via the entries in /proc/sys/kernel/pax.
81427 +
81428 +config PAX_EI_PAX
81429 + bool 'Use legacy ELF header marking'
81430 + default y if GRKERNSEC_CONFIG_AUTO
81431 + help
81432 + Enabling this option will allow you to control PaX features on
81433 + a per executable basis via the 'chpax' utility available at
81434 + http://pax.grsecurity.net/. The control flags will be read from
81435 + an otherwise reserved part of the ELF header. This marking has
81436 + numerous drawbacks (no support for soft-mode, toolchain does not
81437 + know about the non-standard use of the ELF header) therefore it
81438 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
81439 + support.
81440 +
81441 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
81442 + support as well, they will override the legacy EI_PAX marks.
81443 +
81444 + If you enable none of the marking options then all applications
81445 + will run with PaX enabled on them by default.
81446 +
81447 +config PAX_PT_PAX_FLAGS
81448 + bool 'Use ELF program header marking'
81449 + default y if GRKERNSEC_CONFIG_AUTO
81450 + help
81451 + Enabling this option will allow you to control PaX features on
81452 + a per executable basis via the 'paxctl' utility available at
81453 + http://pax.grsecurity.net/. The control flags will be read from
81454 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
81455 + has the benefits of supporting both soft mode and being fully
81456 + integrated into the toolchain (the binutils patch is available
81457 + from http://pax.grsecurity.net).
81458 +
81459 + Note that if you enable the legacy EI_PAX marking support as well,
81460 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
81461 +
81462 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
81463 + must make sure that the marks are the same if a binary has both marks.
81464 +
81465 + If you enable none of the marking options then all applications
81466 + will run with PaX enabled on them by default.
81467 +
81468 +config PAX_XATTR_PAX_FLAGS
81469 + bool 'Use filesystem extended attributes marking'
81470 + default y if GRKERNSEC_CONFIG_AUTO
81471 + select CIFS_XATTR if CIFS
81472 + select EXT2_FS_XATTR if EXT2_FS
81473 + select EXT3_FS_XATTR if EXT3_FS
81474 + select EXT4_FS_XATTR if EXT4_FS
81475 + select JFFS2_FS_XATTR if JFFS2_FS
81476 + select REISERFS_FS_XATTR if REISERFS_FS
81477 + select SQUASHFS_XATTR if SQUASHFS
81478 + select TMPFS_XATTR if TMPFS
81479 + select UBIFS_FS_XATTR if UBIFS_FS
81480 + help
81481 + Enabling this option will allow you to control PaX features on
81482 + a per executable basis via the 'setfattr' utility. The control
81483 + flags will be read from the user.pax.flags extended attribute of
81484 + the file. This marking has the benefit of supporting binary-only
81485 + applications that self-check themselves (e.g., skype) and would
81486 + not tolerate chpax/paxctl changes. The main drawback is that
81487 + extended attributes are not supported by some filesystems (e.g.,
81488 + isofs, udf, vfat) so copying files through such filesystems will
81489 + lose the extended attributes and these PaX markings.
81490 +
81491 + Note that if you enable the legacy EI_PAX marking support as well,
81492 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
81493 +
81494 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
81495 + must make sure that the marks are the same if a binary has both marks.
81496 +
81497 + If you enable none of the marking options then all applications
81498 + will run with PaX enabled on them by default.
81499 +
81500 +choice
81501 + prompt 'MAC system integration'
81502 + default PAX_HAVE_ACL_FLAGS
81503 + help
81504 + Mandatory Access Control systems have the option of controlling
81505 + PaX flags on a per executable basis, choose the method supported
81506 + by your particular system.
81507 +
81508 + - "none": if your MAC system does not interact with PaX,
81509 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
81510 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
81511 +
81512 + NOTE: this option is for developers/integrators only.
81513 +
81514 + config PAX_NO_ACL_FLAGS
81515 + bool 'none'
81516 +
81517 + config PAX_HAVE_ACL_FLAGS
81518 + bool 'direct'
81519 +
81520 + config PAX_HOOK_ACL_FLAGS
81521 + bool 'hook'
81522 +endchoice
81523 +
81524 +endmenu
81525 +
81526 +menu "Non-executable pages"
81527 + depends on PAX
81528 +
81529 +config PAX_NOEXEC
81530 + bool "Enforce non-executable pages"
81531 + default y if GRKERNSEC_CONFIG_AUTO
81532 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
81533 + help
81534 + By design some architectures do not allow for protecting memory
81535 + pages against execution or even if they do, Linux does not make
81536 + use of this feature. In practice this means that if a page is
81537 + readable (such as the stack or heap) it is also executable.
81538 +
81539 + There is a well known exploit technique that makes use of this
81540 + fact and a common programming mistake where an attacker can
81541 + introduce code of his choice somewhere in the attacked program's
81542 + memory (typically the stack or the heap) and then execute it.
81543 +
81544 + If the attacked program was running with different (typically
81545 + higher) privileges than that of the attacker, then he can elevate
81546 + his own privilege level (e.g. get a root shell, write to files for
81547 + which he does not have write access to, etc).
81548 +
81549 + Enabling this option will let you choose from various features
81550 + that prevent the injection and execution of 'foreign' code in
81551 + a program.
81552 +
81553 + This will also break programs that rely on the old behaviour and
81554 + expect that dynamically allocated memory via the malloc() family
81555 + of functions is executable (which it is not). Notable examples
81556 + are the XFree86 4.x server, the java runtime and wine.
81557 +
81558 +config PAX_PAGEEXEC
81559 + bool "Paging based non-executable pages"
81560 + default y if GRKERNSEC_CONFIG_AUTO
81561 + 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)
81562 + select S390_SWITCH_AMODE if S390
81563 + select S390_EXEC_PROTECT if S390
81564 + select ARCH_TRACK_EXEC_LIMIT if X86_32
81565 + help
81566 + This implementation is based on the paging feature of the CPU.
81567 + On i386 without hardware non-executable bit support there is a
81568 + variable but usually low performance impact, however on Intel's
81569 + P4 core based CPUs it is very high so you should not enable this
81570 + for kernels meant to be used on such CPUs.
81571 +
81572 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
81573 + with hardware non-executable bit support there is no performance
81574 + impact, on ppc the impact is negligible.
81575 +
81576 + Note that several architectures require various emulations due to
81577 + badly designed userland ABIs, this will cause a performance impact
81578 + but will disappear as soon as userland is fixed. For example, ppc
81579 + userland MUST have been built with secure-plt by a recent toolchain.
81580 +
81581 +config PAX_SEGMEXEC
81582 + bool "Segmentation based non-executable pages"
81583 + default y if GRKERNSEC_CONFIG_AUTO
81584 + depends on PAX_NOEXEC && X86_32
81585 + help
81586 + This implementation is based on the segmentation feature of the
81587 + CPU and has a very small performance impact, however applications
81588 + will be limited to a 1.5 GB address space instead of the normal
81589 + 3 GB.
81590 +
81591 +config PAX_EMUTRAMP
81592 + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
81593 + default y if PARISC
81594 + help
81595 + There are some programs and libraries that for one reason or
81596 + another attempt to execute special small code snippets from
81597 + non-executable memory pages. Most notable examples are the
81598 + signal handler return code generated by the kernel itself and
81599 + the GCC trampolines.
81600 +
81601 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
81602 + such programs will no longer work under your kernel.
81603 +
81604 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
81605 + utilities to enable trampoline emulation for the affected programs
81606 + yet still have the protection provided by the non-executable pages.
81607 +
81608 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
81609 + your system will not even boot.
81610 +
81611 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
81612 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
81613 + for the affected files.
81614 +
81615 + NOTE: enabling this feature *may* open up a loophole in the
81616 + protection provided by non-executable pages that an attacker
81617 + could abuse. Therefore the best solution is to not have any
81618 + files on your system that would require this option. This can
81619 + be achieved by not using libc5 (which relies on the kernel
81620 + signal handler return code) and not using or rewriting programs
81621 + that make use of the nested function implementation of GCC.
81622 + Skilled users can just fix GCC itself so that it implements
81623 + nested function calls in a way that does not interfere with PaX.
81624 +
81625 +config PAX_EMUSIGRT
81626 + bool "Automatically emulate sigreturn trampolines"
81627 + depends on PAX_EMUTRAMP && PARISC
81628 + default y
81629 + help
81630 + Enabling this option will have the kernel automatically detect
81631 + and emulate signal return trampolines executing on the stack
81632 + that would otherwise lead to task termination.
81633 +
81634 + This solution is intended as a temporary one for users with
81635 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
81636 + Modula-3 runtime, etc) or executables linked to such, basically
81637 + everything that does not specify its own SA_RESTORER function in
81638 + normal executable memory like glibc 2.1+ does.
81639 +
81640 + On parisc you MUST enable this option, otherwise your system will
81641 + not even boot.
81642 +
81643 + NOTE: this feature cannot be disabled on a per executable basis
81644 + and since it *does* open up a loophole in the protection provided
81645 + by non-executable pages, the best solution is to not have any
81646 + files on your system that would require this option.
81647 +
81648 +config PAX_MPROTECT
81649 + bool "Restrict mprotect()"
81650 + default y if GRKERNSEC_CONFIG_AUTO
81651 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
81652 + help
81653 + Enabling this option will prevent programs from
81654 + - changing the executable status of memory pages that were
81655 + not originally created as executable,
81656 + - making read-only executable pages writable again,
81657 + - creating executable pages from anonymous memory,
81658 + - making read-only-after-relocations (RELRO) data pages writable again.
81659 +
81660 + You should say Y here to complete the protection provided by
81661 + the enforcement of non-executable pages.
81662 +
81663 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
81664 + this feature on a per file basis.
81665 +
81666 +config PAX_MPROTECT_COMPAT
81667 + bool "Use legacy/compat protection demoting (read help)"
81668 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
81669 + depends on PAX_MPROTECT
81670 + help
81671 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
81672 + by sending the proper error code to the application. For some broken
81673 + userland, this can cause problems with Python or other applications. The
81674 + current implementation however allows for applications like clamav to
81675 + detect if JIT compilation/execution is allowed and to fall back gracefully
81676 + to an interpreter-based mode if it does not. While we encourage everyone
81677 + to use the current implementation as-is and push upstream to fix broken
81678 + userland (note that the RWX logging option can assist with this), in some
81679 + environments this may not be possible. Having to disable MPROTECT
81680 + completely on certain binaries reduces the security benefit of PaX,
81681 + so this option is provided for those environments to revert to the old
81682 + behavior.
81683 +
81684 +config PAX_ELFRELOCS
81685 + bool "Allow ELF text relocations (read help)"
81686 + depends on PAX_MPROTECT
81687 + default n
81688 + help
81689 + Non-executable pages and mprotect() restrictions are effective
81690 + in preventing the introduction of new executable code into an
81691 + attacked task's address space. There remain only two venues
81692 + for this kind of attack: if the attacker can execute already
81693 + existing code in the attacked task then he can either have it
81694 + create and mmap() a file containing his code or have it mmap()
81695 + an already existing ELF library that does not have position
81696 + independent code in it and use mprotect() on it to make it
81697 + writable and copy his code there. While protecting against
81698 + the former approach is beyond PaX, the latter can be prevented
81699 + by having only PIC ELF libraries on one's system (which do not
81700 + need to relocate their code). If you are sure this is your case,
81701 + as is the case with all modern Linux distributions, then leave
81702 + this option disabled. You should say 'n' here.
81703 +
81704 +config PAX_ETEXECRELOCS
81705 + bool "Allow ELF ET_EXEC text relocations"
81706 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
81707 + select PAX_ELFRELOCS
81708 + default y
81709 + help
81710 + On some architectures there are incorrectly created applications
81711 + that require text relocations and would not work without enabling
81712 + this option. If you are an alpha, ia64 or parisc user, you should
81713 + enable this option and disable it once you have made sure that
81714 + none of your applications need it.
81715 +
81716 +config PAX_EMUPLT
81717 + bool "Automatically emulate ELF PLT"
81718 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
81719 + default y
81720 + help
81721 + Enabling this option will have the kernel automatically detect
81722 + and emulate the Procedure Linkage Table entries in ELF files.
81723 + On some architectures such entries are in writable memory, and
81724 + become non-executable leading to task termination. Therefore
81725 + it is mandatory that you enable this option on alpha, parisc,
81726 + sparc and sparc64, otherwise your system would not even boot.
81727 +
81728 + NOTE: this feature *does* open up a loophole in the protection
81729 + provided by the non-executable pages, therefore the proper
81730 + solution is to modify the toolchain to produce a PLT that does
81731 + not need to be writable.
81732 +
81733 +config PAX_DLRESOLVE
81734 + bool 'Emulate old glibc resolver stub'
81735 + depends on PAX_EMUPLT && SPARC
81736 + default n
81737 + help
81738 + This option is needed if userland has an old glibc (before 2.4)
81739 + that puts a 'save' instruction into the runtime generated resolver
81740 + stub that needs special emulation.
81741 +
81742 +config PAX_KERNEXEC
81743 + bool "Enforce non-executable kernel pages"
81744 + 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))
81745 + depends on (PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN
81746 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
81747 + select PAX_KERNEXEC_PLUGIN if X86_64
81748 + help
81749 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
81750 + that is, enabling this option will make it harder to inject
81751 + and execute 'foreign' code in kernel memory itself.
81752 +
81753 +choice
81754 + prompt "Return Address Instrumentation Method"
81755 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
81756 + depends on PAX_KERNEXEC_PLUGIN
81757 + help
81758 + Select the method used to instrument function pointer dereferences.
81759 + Note that binary modules cannot be instrumented by this approach.
81760 +
81761 + Note that the implementation requires a gcc with plugin support,
81762 + i.e., gcc 4.5 or newer. You may need to install the supporting
81763 + headers explicitly in addition to the normal gcc package.
81764 +
81765 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
81766 + bool "bts"
81767 + help
81768 + This method is compatible with binary only modules but has
81769 + a higher runtime overhead.
81770 +
81771 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
81772 + bool "or"
81773 + depends on !PARAVIRT
81774 + help
81775 + This method is incompatible with binary only modules but has
81776 + a lower runtime overhead.
81777 +endchoice
81778 +
81779 +config PAX_KERNEXEC_PLUGIN_METHOD
81780 + string
81781 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
81782 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
81783 + default ""
81784 +
81785 +config PAX_KERNEXEC_MODULE_TEXT
81786 + int "Minimum amount of memory reserved for module code"
81787 + default "4" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
81788 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
81789 + depends on PAX_KERNEXEC && X86_32 && MODULES
81790 + help
81791 + Due to implementation details the kernel must reserve a fixed
81792 + amount of memory for module code at compile time that cannot be
81793 + changed at runtime. Here you can specify the minimum amount
81794 + in MB that will be reserved. Due to the same implementation
81795 + details this size will always be rounded up to the next 2/4 MB
81796 + boundary (depends on PAE) so the actually available memory for
81797 + module code will usually be more than this minimum.
81798 +
81799 + The default 4 MB should be enough for most users but if you have
81800 + an excessive number of modules (e.g., most distribution configs
81801 + compile many drivers as modules) or use huge modules such as
81802 + nvidia's kernel driver, you will need to adjust this amount.
81803 + A good rule of thumb is to look at your currently loaded kernel
81804 + modules and add up their sizes.
81805 +
81806 +endmenu
81807 +
81808 +menu "Address Space Layout Randomization"
81809 + depends on PAX
81810 +
81811 +config PAX_ASLR
81812 + bool "Address Space Layout Randomization"
81813 + default y if GRKERNSEC_CONFIG_AUTO
81814 + help
81815 + Many if not most exploit techniques rely on the knowledge of
81816 + certain addresses in the attacked program. The following options
81817 + will allow the kernel to apply a certain amount of randomization
81818 + to specific parts of the program thereby forcing an attacker to
81819 + guess them in most cases. Any failed guess will most likely crash
81820 + the attacked program which allows the kernel to detect such attempts
81821 + and react on them. PaX itself provides no reaction mechanisms,
81822 + instead it is strongly encouraged that you make use of Nergal's
81823 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
81824 + (http://www.grsecurity.net/) built-in crash detection features or
81825 + develop one yourself.
81826 +
81827 + By saying Y here you can choose to randomize the following areas:
81828 + - top of the task's kernel stack
81829 + - top of the task's userland stack
81830 + - base address for mmap() requests that do not specify one
81831 + (this includes all libraries)
81832 + - base address of the main executable
81833 +
81834 + It is strongly recommended to say Y here as address space layout
81835 + randomization has negligible impact on performance yet it provides
81836 + a very effective protection.
81837 +
81838 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
81839 + this feature on a per file basis.
81840 +
81841 +config PAX_RANDKSTACK
81842 + bool "Randomize kernel stack base"
81843 + default y if GRKERNSEC_CONFIG_AUTO
81844 + depends on X86_TSC && X86
81845 + help
81846 + By saying Y here the kernel will randomize every task's kernel
81847 + stack on every system call. This will not only force an attacker
81848 + to guess it but also prevent him from making use of possible
81849 + leaked information about it.
81850 +
81851 + Since the kernel stack is a rather scarce resource, randomization
81852 + may cause unexpected stack overflows, therefore you should very
81853 + carefully test your system. Note that once enabled in the kernel
81854 + configuration, this feature cannot be disabled on a per file basis.
81855 +
81856 +config PAX_RANDUSTACK
81857 + bool "Randomize user stack base"
81858 + default y if GRKERNSEC_CONFIG_AUTO
81859 + depends on PAX_ASLR
81860 + help
81861 + By saying Y here the kernel will randomize every task's userland
81862 + stack. The randomization is done in two steps where the second
81863 + one may apply a big amount of shift to the top of the stack and
81864 + cause problems for programs that want to use lots of memory (more
81865 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
81866 + For this reason the second step can be controlled by 'chpax' or
81867 + 'paxctl' on a per file basis.
81868 +
81869 +config PAX_RANDMMAP
81870 + bool "Randomize mmap() base"
81871 + default y if GRKERNSEC_CONFIG_AUTO
81872 + depends on PAX_ASLR
81873 + help
81874 + By saying Y here the kernel will use a randomized base address for
81875 + mmap() requests that do not specify one themselves. As a result
81876 + all dynamically loaded libraries will appear at random addresses
81877 + and therefore be harder to exploit by a technique where an attacker
81878 + attempts to execute library code for his purposes (e.g. spawn a
81879 + shell from an exploited program that is running at an elevated
81880 + privilege level).
81881 +
81882 + Furthermore, if a program is relinked as a dynamic ELF file, its
81883 + base address will be randomized as well, completing the full
81884 + randomization of the address space layout. Attacking such programs
81885 + becomes a guess game. You can find an example of doing this at
81886 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
81887 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
81888 +
81889 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
81890 + feature on a per file basis.
81891 +
81892 +endmenu
81893 +
81894 +menu "Miscellaneous hardening features"
81895 +
81896 +config PAX_MEMORY_SANITIZE
81897 + bool "Sanitize all freed memory"
81898 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
81899 + depends on !HIBERNATION
81900 + help
81901 + By saying Y here the kernel will erase memory pages as soon as they
81902 + are freed. This in turn reduces the lifetime of data stored in the
81903 + pages, making it less likely that sensitive information such as
81904 + passwords, cryptographic secrets, etc stay in memory for too long.
81905 +
81906 + This is especially useful for programs whose runtime is short, long
81907 + lived processes and the kernel itself benefit from this as long as
81908 + they operate on whole memory pages and ensure timely freeing of pages
81909 + that may hold sensitive information.
81910 +
81911 + The tradeoff is performance impact, on a single CPU system kernel
81912 + compilation sees a 3% slowdown, other systems and workloads may vary
81913 + and you are advised to test this feature on your expected workload
81914 + before deploying it.
81915 +
81916 + Note that this feature does not protect data stored in live pages,
81917 + e.g., process memory swapped to disk may stay there for a long time.
81918 +
81919 +config PAX_MEMORY_STACKLEAK
81920 + bool "Sanitize kernel stack"
81921 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
81922 + depends on X86
81923 + help
81924 + By saying Y here the kernel will erase the kernel stack before it
81925 + returns from a system call. This in turn reduces the information
81926 + that a kernel stack leak bug can reveal.
81927 +
81928 + Note that such a bug can still leak information that was put on
81929 + the stack by the current system call (the one eventually triggering
81930 + the bug) but traces of earlier system calls on the kernel stack
81931 + cannot leak anymore.
81932 +
81933 + The tradeoff is performance impact: on a single CPU system kernel
81934 + compilation sees a 1% slowdown, other systems and workloads may vary
81935 + and you are advised to test this feature on your expected workload
81936 + before deploying it.
81937 +
81938 + Note that the full feature requires a gcc with plugin support,
81939 + i.e., gcc 4.5 or newer. You may need to install the supporting
81940 + headers explicitly in addition to the normal gcc package. Using
81941 + older gcc versions means that functions with large enough stack
81942 + frames may leave uninitialized memory behind that may be exposed
81943 + to a later syscall leaking the stack.
81944 +
81945 +config PAX_MEMORY_UDEREF
81946 + bool "Prevent invalid userland pointer dereference"
81947 + default y if GRKERNSEC_CONFIG_AUTO && (X86_32 || (X86_64 && GRKERNSEC_CONFIG_PRIORITY_SECURITY)) && (GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
81948 + depends on X86 && !UML_X86 && !XEN
81949 + select PAX_PER_CPU_PGD if X86_64
81950 + help
81951 + By saying Y here the kernel will be prevented from dereferencing
81952 + userland pointers in contexts where the kernel expects only kernel
81953 + pointers. This is both a useful runtime debugging feature and a
81954 + security measure that prevents exploiting a class of kernel bugs.
81955 +
81956 + The tradeoff is that some virtualization solutions may experience
81957 + a huge slowdown and therefore you should not enable this feature
81958 + for kernels meant to run in such environments. Whether a given VM
81959 + solution is affected or not is best determined by simply trying it
81960 + out, the performance impact will be obvious right on boot as this
81961 + mechanism engages from very early on. A good rule of thumb is that
81962 + VMs running on CPUs without hardware virtualization support (i.e.,
81963 + the majority of IA-32 CPUs) will likely experience the slowdown.
81964 +
81965 +config PAX_REFCOUNT
81966 + bool "Prevent various kernel object reference counter overflows"
81967 + default y if GRKERNSEC_CONFIG_AUTO
81968 + depends on GRKERNSEC && ((ARM && (CPU_32v6 || CPU_32v6K || CPU_32v7)) || SPARC64 || X86)
81969 + help
81970 + By saying Y here the kernel will detect and prevent overflowing
81971 + various (but not all) kinds of object reference counters. Such
81972 + overflows can normally occur due to bugs only and are often, if
81973 + not always, exploitable.
81974 +
81975 + The tradeoff is that data structures protected by an overflowed
81976 + refcount will never be freed and therefore will leak memory. Note
81977 + that this leak also happens even without this protection but in
81978 + that case the overflow can eventually trigger the freeing of the
81979 + data structure while it is still being used elsewhere, resulting
81980 + in the exploitable situation that this feature prevents.
81981 +
81982 + Since this has a negligible performance impact, you should enable
81983 + this feature.
81984 +
81985 +config PAX_USERCOPY
81986 + bool "Harden heap object copies between kernel and userland"
81987 + default y if GRKERNSEC_CONFIG_AUTO
81988 + depends on X86 || PPC || SPARC || ARM
81989 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
81990 + select PAX_USERCOPY_SLABS
81991 + help
81992 + By saying Y here the kernel will enforce the size of heap objects
81993 + when they are copied in either direction between the kernel and
81994 + userland, even if only a part of the heap object is copied.
81995 +
81996 + Specifically, this checking prevents information leaking from the
81997 + kernel heap during kernel to userland copies (if the kernel heap
81998 + object is otherwise fully initialized) and prevents kernel heap
81999 + overflows during userland to kernel copies.
82000 +
82001 + Note that the current implementation provides the strictest bounds
82002 + checks for the SLUB allocator.
82003 +
82004 + Enabling this option also enables per-slab cache protection against
82005 + data in a given cache being copied into/out of via userland
82006 + accessors. Though the whitelist of regions will be reduced over
82007 + time, it notably protects important data structures like task structs.
82008 +
82009 + If frame pointers are enabled on x86, this option will also restrict
82010 + copies into and out of the kernel stack to local variables within a
82011 + single frame.
82012 +
82013 + Since this has a negligible performance impact, you should enable
82014 + this feature.
82015 +
82016 +config PAX_SIZE_OVERFLOW
82017 + bool "Prevent various integer overflows in function size parameters"
82018 + default y if GRKERNSEC_CONFIG_AUTO
82019 + depends on X86
82020 + help
82021 + By saying Y here the kernel recomputes expressions of function
82022 + arguments marked by a size_overflow attribute with double integer
82023 + precision (DImode/TImode for 32/64 bit integer types).
82024 +
82025 + The recomputed argument is checked against TYPE_MAX and an event
82026 + is logged on overflow and the triggering process is killed.
82027 +
82028 + Homepage: http://www.grsecurity.net/~ephox/overflow_plugin/
82029 +
82030 + Note that the implementation requires a gcc with plugin support,
82031 + i.e., gcc 4.5 or newer. You may need to install the supporting
82032 + headers explicitly in addition to the normal gcc package.
82033 +
82034 +config PAX_LATENT_ENTROPY
82035 + bool "Generate some entropy during boot"
82036 + default y if GRKERNSEC_CONFIG_AUTO
82037 + help
82038 + By saying Y here the kernel will instrument early boot code to
82039 + extract some entropy from both original and artificially created
82040 + program state. This will help especially embedded systems where
82041 + there is little 'natural' source of entropy normally. The cost
82042 + is some slowdown of the boot process.
82043 +
82044 + Note that the implementation requires a gcc with plugin support,
82045 + i.e., gcc 4.5 or newer. You may need to install the supporting
82046 + headers explicitly in addition to the normal gcc package.
82047 +
82048 + Note that entropy extracted this way is not cryptographically
82049 + secure!
82050 +
82051 +endmenu
82052 +
82053 +endmenu
82054 +
82055 +source grsecurity/Kconfig
82056 +
82057 +endmenu
82058 +
82059 +endmenu
82060 +
82061 source security/keys/Kconfig
82062
82063 config SECURITY_DMESG_RESTRICT
82064 @@ -103,7 +993,7 @@ config INTEL_TXT
82065 config LSM_MMAP_MIN_ADDR
82066 int "Low address space for LSM to protect from user allocation"
82067 depends on SECURITY && SECURITY_SELINUX
82068 - default 32768 if ARM
82069 + default 32768 if ALPHA || ARM || PARISC || SPARC32
82070 default 65536
82071 help
82072 This is the portion of low virtual memory which should be protected
82073 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
82074 index 8ea39aa..8569ac5 100644
82075 --- a/security/apparmor/lsm.c
82076 +++ b/security/apparmor/lsm.c
82077 @@ -614,7 +614,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
82078 return error;
82079 }
82080
82081 -static struct security_operations apparmor_ops = {
82082 +static struct security_operations apparmor_ops __read_only = {
82083 .name = "apparmor",
82084
82085 .ptrace_access_check = apparmor_ptrace_access_check,
82086 diff --git a/security/commoncap.c b/security/commoncap.c
82087 index 6dbae46..d5611fd 100644
82088 --- a/security/commoncap.c
82089 +++ b/security/commoncap.c
82090 @@ -415,6 +415,32 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data
82091 return 0;
82092 }
82093
82094 +/* returns:
82095 + 1 for suid privilege
82096 + 2 for sgid privilege
82097 + 3 for fscap privilege
82098 +*/
82099 +int is_privileged_binary(const struct dentry *dentry)
82100 +{
82101 + struct cpu_vfs_cap_data capdata;
82102 + struct inode *inode = dentry->d_inode;
82103 +
82104 + if (!inode || S_ISDIR(inode->i_mode))
82105 + return 0;
82106 +
82107 + if (inode->i_mode & S_ISUID)
82108 + return 1;
82109 + if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
82110 + return 2;
82111 +
82112 + if (!get_vfs_caps_from_disk(dentry, &capdata)) {
82113 + if (!cap_isclear(capdata.inheritable) || !cap_isclear(capdata.permitted))
82114 + return 3;
82115 + }
82116 +
82117 + return 0;
82118 +}
82119 +
82120 /*
82121 * Attempt to get the on-exec apply capability sets for an executable file from
82122 * its xattrs and, if present, apply them to the proposed credentials being
82123 @@ -583,6 +609,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
82124 const struct cred *cred = current_cred();
82125 kuid_t root_uid = make_kuid(cred->user_ns, 0);
82126
82127 + if (gr_acl_enable_at_secure())
82128 + return 1;
82129 +
82130 if (!uid_eq(cred->uid, root_uid)) {
82131 if (bprm->cap_effective)
82132 return 1;
82133 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
82134 index e7c99fd..5b2fa24 100644
82135 --- a/security/integrity/ima/ima.h
82136 +++ b/security/integrity/ima/ima.h
82137 @@ -95,8 +95,8 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
82138 extern spinlock_t ima_queue_lock;
82139
82140 struct ima_h_table {
82141 - atomic_long_t len; /* number of stored measurements in the list */
82142 - atomic_long_t violations;
82143 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
82144 + atomic_long_unchecked_t violations;
82145 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
82146 };
82147 extern struct ima_h_table ima_htable;
82148 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
82149 index 032ff03..c428a74 100644
82150 --- a/security/integrity/ima/ima_api.c
82151 +++ b/security/integrity/ima/ima_api.c
82152 @@ -75,7 +75,7 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
82153 int result;
82154
82155 /* can overflow, only indicator */
82156 - atomic_long_inc(&ima_htable.violations);
82157 + atomic_long_inc_unchecked(&ima_htable.violations);
82158
82159 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
82160 if (!entry) {
82161 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
82162 index 38477c9..87a60c7 100644
82163 --- a/security/integrity/ima/ima_fs.c
82164 +++ b/security/integrity/ima/ima_fs.c
82165 @@ -28,12 +28,12 @@
82166 static int valid_policy = 1;
82167 #define TMPBUFLEN 12
82168 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
82169 - loff_t *ppos, atomic_long_t *val)
82170 + loff_t *ppos, atomic_long_unchecked_t *val)
82171 {
82172 char tmpbuf[TMPBUFLEN];
82173 ssize_t len;
82174
82175 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
82176 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
82177 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
82178 }
82179
82180 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
82181 index 55a6271..ad829c3 100644
82182 --- a/security/integrity/ima/ima_queue.c
82183 +++ b/security/integrity/ima/ima_queue.c
82184 @@ -81,7 +81,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
82185 INIT_LIST_HEAD(&qe->later);
82186 list_add_tail_rcu(&qe->later, &ima_measurements);
82187
82188 - atomic_long_inc(&ima_htable.len);
82189 + atomic_long_inc_unchecked(&ima_htable.len);
82190 key = ima_hash_key(entry->digest);
82191 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
82192 return 0;
82193 diff --git a/security/keys/compat.c b/security/keys/compat.c
82194 index 1c26176..64a1ba2 100644
82195 --- a/security/keys/compat.c
82196 +++ b/security/keys/compat.c
82197 @@ -44,7 +44,7 @@ static long compat_keyctl_instantiate_key_iov(
82198 if (ret == 0)
82199 goto no_payload_free;
82200
82201 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
82202 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
82203
82204 if (iov != iovstack)
82205 kfree(iov);
82206 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
82207 index 3364fbf..1f10f31 100644
82208 --- a/security/keys/keyctl.c
82209 +++ b/security/keys/keyctl.c
82210 @@ -966,7 +966,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
82211 /*
82212 * Copy the iovec data from userspace
82213 */
82214 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
82215 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
82216 unsigned ioc)
82217 {
82218 for (; ioc > 0; ioc--) {
82219 @@ -988,7 +988,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
82220 * If successful, 0 will be returned.
82221 */
82222 long keyctl_instantiate_key_common(key_serial_t id,
82223 - const struct iovec *payload_iov,
82224 + const struct iovec __user *payload_iov,
82225 unsigned ioc,
82226 size_t plen,
82227 key_serial_t ringid)
82228 @@ -1083,7 +1083,7 @@ long keyctl_instantiate_key(key_serial_t id,
82229 [0].iov_len = plen
82230 };
82231
82232 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
82233 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
82234 }
82235
82236 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
82237 @@ -1116,7 +1116,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
82238 if (ret == 0)
82239 goto no_payload_free;
82240
82241 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
82242 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
82243
82244 if (iov != iovstack)
82245 kfree(iov);
82246 diff --git a/security/keys/keyring.c b/security/keys/keyring.c
82247 index 81e7852..2b2ecc3 100644
82248 --- a/security/keys/keyring.c
82249 +++ b/security/keys/keyring.c
82250 @@ -227,16 +227,16 @@ static long keyring_read(const struct key *keyring,
82251 ret = -EFAULT;
82252
82253 for (loop = 0; loop < klist->nkeys; loop++) {
82254 + key_serial_t serial;
82255 key = rcu_deref_link_locked(klist, loop,
82256 keyring);
82257 + serial = key->serial;
82258
82259 tmp = sizeof(key_serial_t);
82260 if (tmp > buflen)
82261 tmp = buflen;
82262
82263 - if (copy_to_user(buffer,
82264 - &key->serial,
82265 - tmp) != 0)
82266 + if (copy_to_user(buffer, &serial, tmp))
82267 goto error;
82268
82269 buflen -= tmp;
82270 diff --git a/security/min_addr.c b/security/min_addr.c
82271 index f728728..6457a0c 100644
82272 --- a/security/min_addr.c
82273 +++ b/security/min_addr.c
82274 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
82275 */
82276 static void update_mmap_min_addr(void)
82277 {
82278 +#ifndef SPARC
82279 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
82280 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
82281 mmap_min_addr = dac_mmap_min_addr;
82282 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
82283 #else
82284 mmap_min_addr = dac_mmap_min_addr;
82285 #endif
82286 +#endif
82287 }
82288
82289 /*
82290 diff --git a/security/security.c b/security/security.c
82291 index 860aeb3..45765c0 100644
82292 --- a/security/security.c
82293 +++ b/security/security.c
82294 @@ -20,6 +20,7 @@
82295 #include <linux/ima.h>
82296 #include <linux/evm.h>
82297 #include <linux/fsnotify.h>
82298 +#include <linux/mm.h>
82299 #include <linux/mman.h>
82300 #include <linux/mount.h>
82301 #include <linux/personality.h>
82302 @@ -32,8 +33,8 @@
82303 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
82304 CONFIG_DEFAULT_SECURITY;
82305
82306 -static struct security_operations *security_ops;
82307 -static struct security_operations default_security_ops = {
82308 +static struct security_operations *security_ops __read_only;
82309 +static struct security_operations default_security_ops __read_only = {
82310 .name = "default",
82311 };
82312
82313 @@ -74,7 +75,9 @@ int __init security_init(void)
82314
82315 void reset_security_ops(void)
82316 {
82317 + pax_open_kernel();
82318 security_ops = &default_security_ops;
82319 + pax_close_kernel();
82320 }
82321
82322 /* Save user chosen LSM */
82323 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
82324 index 6c77f63..7496c76 100644
82325 --- a/security/selinux/hooks.c
82326 +++ b/security/selinux/hooks.c
82327 @@ -95,8 +95,6 @@
82328
82329 #define NUM_SEL_MNT_OPTS 5
82330
82331 -extern struct security_operations *security_ops;
82332 -
82333 /* SECMARK reference count */
82334 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
82335
82336 @@ -5511,7 +5509,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
82337
82338 #endif
82339
82340 -static struct security_operations selinux_ops = {
82341 +static struct security_operations selinux_ops __read_only = {
82342 .name = "selinux",
82343
82344 .ptrace_access_check = selinux_ptrace_access_check,
82345 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
82346 index 65f67cb..3f141ef 100644
82347 --- a/security/selinux/include/xfrm.h
82348 +++ b/security/selinux/include/xfrm.h
82349 @@ -50,7 +50,7 @@ int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall);
82350
82351 static inline void selinux_xfrm_notify_policyload(void)
82352 {
82353 - atomic_inc(&flow_cache_genid);
82354 + atomic_inc_unchecked(&flow_cache_genid);
82355 rt_genid_bump(&init_net);
82356 }
82357 #else
82358 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
82359 index 8221514..5c4775f 100644
82360 --- a/security/smack/smack_lsm.c
82361 +++ b/security/smack/smack_lsm.c
82362 @@ -3429,7 +3429,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
82363 return 0;
82364 }
82365
82366 -struct security_operations smack_ops = {
82367 +struct security_operations smack_ops __read_only = {
82368 .name = "smack",
82369
82370 .ptrace_access_check = smack_ptrace_access_check,
82371 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
82372 index c2d04a5..e6a1aeb 100644
82373 --- a/security/tomoyo/tomoyo.c
82374 +++ b/security/tomoyo/tomoyo.c
82375 @@ -501,7 +501,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
82376 * tomoyo_security_ops is a "struct security_operations" which is used for
82377 * registering TOMOYO.
82378 */
82379 -static struct security_operations tomoyo_security_ops = {
82380 +static struct security_operations tomoyo_security_ops __read_only = {
82381 .name = "tomoyo",
82382 .cred_alloc_blank = tomoyo_cred_alloc_blank,
82383 .cred_prepare = tomoyo_cred_prepare,
82384 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
82385 index 51d6709..1f3dbe2 100644
82386 --- a/security/yama/Kconfig
82387 +++ b/security/yama/Kconfig
82388 @@ -1,6 +1,6 @@
82389 config SECURITY_YAMA
82390 bool "Yama support"
82391 - depends on SECURITY
82392 + depends on SECURITY && !GRKERNSEC
82393 select SECURITYFS
82394 select SECURITY_PATH
82395 default n
82396 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
82397 index 4cedc69..e59d8a3 100644
82398 --- a/sound/aoa/codecs/onyx.c
82399 +++ b/sound/aoa/codecs/onyx.c
82400 @@ -54,7 +54,7 @@ struct onyx {
82401 spdif_locked:1,
82402 analog_locked:1,
82403 original_mute:2;
82404 - int open_count;
82405 + local_t open_count;
82406 struct codec_info *codec_info;
82407
82408 /* mutex serializes concurrent access to the device
82409 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
82410 struct onyx *onyx = cii->codec_data;
82411
82412 mutex_lock(&onyx->mutex);
82413 - onyx->open_count++;
82414 + local_inc(&onyx->open_count);
82415 mutex_unlock(&onyx->mutex);
82416
82417 return 0;
82418 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
82419 struct onyx *onyx = cii->codec_data;
82420
82421 mutex_lock(&onyx->mutex);
82422 - onyx->open_count--;
82423 - if (!onyx->open_count)
82424 + if (local_dec_and_test(&onyx->open_count))
82425 onyx->spdif_locked = onyx->analog_locked = 0;
82426 mutex_unlock(&onyx->mutex);
82427
82428 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
82429 index ffd2025..df062c9 100644
82430 --- a/sound/aoa/codecs/onyx.h
82431 +++ b/sound/aoa/codecs/onyx.h
82432 @@ -11,6 +11,7 @@
82433 #include <linux/i2c.h>
82434 #include <asm/pmac_low_i2c.h>
82435 #include <asm/prom.h>
82436 +#include <asm/local.h>
82437
82438 /* PCM3052 register definitions */
82439
82440 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
82441 index 4c1cc51..16040040 100644
82442 --- a/sound/core/oss/pcm_oss.c
82443 +++ b/sound/core/oss/pcm_oss.c
82444 @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
82445 if (in_kernel) {
82446 mm_segment_t fs;
82447 fs = snd_enter_user();
82448 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
82449 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
82450 snd_leave_user(fs);
82451 } else {
82452 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
82453 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
82454 }
82455 if (ret != -EPIPE && ret != -ESTRPIPE)
82456 break;
82457 @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
82458 if (in_kernel) {
82459 mm_segment_t fs;
82460 fs = snd_enter_user();
82461 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
82462 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
82463 snd_leave_user(fs);
82464 } else {
82465 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
82466 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
82467 }
82468 if (ret == -EPIPE) {
82469 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
82470 @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
82471 struct snd_pcm_plugin_channel *channels;
82472 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
82473 if (!in_kernel) {
82474 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
82475 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
82476 return -EFAULT;
82477 buf = runtime->oss.buffer;
82478 }
82479 @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
82480 }
82481 } else {
82482 tmp = snd_pcm_oss_write2(substream,
82483 - (const char __force *)buf,
82484 + (const char __force_kernel *)buf,
82485 runtime->oss.period_bytes, 0);
82486 if (tmp <= 0)
82487 goto err;
82488 @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
82489 struct snd_pcm_runtime *runtime = substream->runtime;
82490 snd_pcm_sframes_t frames, frames1;
82491 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
82492 - char __user *final_dst = (char __force __user *)buf;
82493 + char __user *final_dst = (char __force_user *)buf;
82494 if (runtime->oss.plugin_first) {
82495 struct snd_pcm_plugin_channel *channels;
82496 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
82497 @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
82498 xfer += tmp;
82499 runtime->oss.buffer_used -= tmp;
82500 } else {
82501 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
82502 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
82503 runtime->oss.period_bytes, 0);
82504 if (tmp <= 0)
82505 goto err;
82506 @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
82507 size1);
82508 size1 /= runtime->channels; /* frames */
82509 fs = snd_enter_user();
82510 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
82511 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
82512 snd_leave_user(fs);
82513 }
82514 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
82515 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
82516 index 91cdf94..4085161 100644
82517 --- a/sound/core/pcm_compat.c
82518 +++ b/sound/core/pcm_compat.c
82519 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
82520 int err;
82521
82522 fs = snd_enter_user();
82523 - err = snd_pcm_delay(substream, &delay);
82524 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
82525 snd_leave_user(fs);
82526 if (err < 0)
82527 return err;
82528 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
82529 index bf3bf43..3826cbc 100644
82530 --- a/sound/core/pcm_native.c
82531 +++ b/sound/core/pcm_native.c
82532 @@ -2803,11 +2803,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
82533 switch (substream->stream) {
82534 case SNDRV_PCM_STREAM_PLAYBACK:
82535 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
82536 - (void __user *)arg);
82537 + (void __force_user *)arg);
82538 break;
82539 case SNDRV_PCM_STREAM_CAPTURE:
82540 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
82541 - (void __user *)arg);
82542 + (void __force_user *)arg);
82543 break;
82544 default:
82545 result = -EINVAL;
82546 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
82547 index 5cf8d65..912a79c 100644
82548 --- a/sound/core/seq/seq_device.c
82549 +++ b/sound/core/seq/seq_device.c
82550 @@ -64,7 +64,7 @@ struct ops_list {
82551 int argsize; /* argument size */
82552
82553 /* operators */
82554 - struct snd_seq_dev_ops ops;
82555 + struct snd_seq_dev_ops *ops;
82556
82557 /* registred devices */
82558 struct list_head dev_list; /* list of devices */
82559 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
82560
82561 mutex_lock(&ops->reg_mutex);
82562 /* copy driver operators */
82563 - ops->ops = *entry;
82564 + ops->ops = entry;
82565 ops->driver |= DRIVER_LOADED;
82566 ops->argsize = argsize;
82567
82568 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
82569 dev->name, ops->id, ops->argsize, dev->argsize);
82570 return -EINVAL;
82571 }
82572 - if (ops->ops.init_device(dev) >= 0) {
82573 + if (ops->ops->init_device(dev) >= 0) {
82574 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
82575 ops->num_init_devices++;
82576 } else {
82577 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
82578 dev->name, ops->id, ops->argsize, dev->argsize);
82579 return -EINVAL;
82580 }
82581 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
82582 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
82583 dev->status = SNDRV_SEQ_DEVICE_FREE;
82584 dev->driver_data = NULL;
82585 ops->num_init_devices--;
82586 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
82587 index 2d5514b..3afae9c 100644
82588 --- a/sound/drivers/mts64.c
82589 +++ b/sound/drivers/mts64.c
82590 @@ -29,6 +29,7 @@
82591 #include <sound/initval.h>
82592 #include <sound/rawmidi.h>
82593 #include <sound/control.h>
82594 +#include <asm/local.h>
82595
82596 #define CARD_NAME "Miditerminal 4140"
82597 #define DRIVER_NAME "MTS64"
82598 @@ -67,7 +68,7 @@ struct mts64 {
82599 struct pardevice *pardev;
82600 int pardev_claimed;
82601
82602 - int open_count;
82603 + local_t open_count;
82604 int current_midi_output_port;
82605 int current_midi_input_port;
82606 u8 mode[MTS64_NUM_INPUT_PORTS];
82607 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
82608 {
82609 struct mts64 *mts = substream->rmidi->private_data;
82610
82611 - if (mts->open_count == 0) {
82612 + if (local_read(&mts->open_count) == 0) {
82613 /* We don't need a spinlock here, because this is just called
82614 if the device has not been opened before.
82615 So there aren't any IRQs from the device */
82616 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
82617
82618 msleep(50);
82619 }
82620 - ++(mts->open_count);
82621 + local_inc(&mts->open_count);
82622
82623 return 0;
82624 }
82625 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
82626 struct mts64 *mts = substream->rmidi->private_data;
82627 unsigned long flags;
82628
82629 - --(mts->open_count);
82630 - if (mts->open_count == 0) {
82631 + if (local_dec_return(&mts->open_count) == 0) {
82632 /* We need the spinlock_irqsave here because we can still
82633 have IRQs at this point */
82634 spin_lock_irqsave(&mts->lock, flags);
82635 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
82636
82637 msleep(500);
82638
82639 - } else if (mts->open_count < 0)
82640 - mts->open_count = 0;
82641 + } else if (local_read(&mts->open_count) < 0)
82642 + local_set(&mts->open_count, 0);
82643
82644 return 0;
82645 }
82646 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
82647 index b953fb4..1999c01 100644
82648 --- a/sound/drivers/opl4/opl4_lib.c
82649 +++ b/sound/drivers/opl4/opl4_lib.c
82650 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
82651 MODULE_DESCRIPTION("OPL4 driver");
82652 MODULE_LICENSE("GPL");
82653
82654 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
82655 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
82656 {
82657 int timeout = 10;
82658 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
82659 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
82660 index 8364855..59f2e2b 100644
82661 --- a/sound/drivers/portman2x4.c
82662 +++ b/sound/drivers/portman2x4.c
82663 @@ -48,6 +48,7 @@
82664 #include <sound/initval.h>
82665 #include <sound/rawmidi.h>
82666 #include <sound/control.h>
82667 +#include <asm/local.h>
82668
82669 #define CARD_NAME "Portman 2x4"
82670 #define DRIVER_NAME "portman"
82671 @@ -85,7 +86,7 @@ struct portman {
82672 struct pardevice *pardev;
82673 int pardev_claimed;
82674
82675 - int open_count;
82676 + local_t open_count;
82677 int mode[PORTMAN_NUM_INPUT_PORTS];
82678 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
82679 };
82680 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
82681 index ea995af..f1bfa37 100644
82682 --- a/sound/firewire/amdtp.c
82683 +++ b/sound/firewire/amdtp.c
82684 @@ -389,7 +389,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
82685 ptr = s->pcm_buffer_pointer + data_blocks;
82686 if (ptr >= pcm->runtime->buffer_size)
82687 ptr -= pcm->runtime->buffer_size;
82688 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
82689 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
82690
82691 s->pcm_period_pointer += data_blocks;
82692 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
82693 @@ -557,7 +557,7 @@ EXPORT_SYMBOL(amdtp_out_stream_pcm_pointer);
82694 */
82695 void amdtp_out_stream_update(struct amdtp_out_stream *s)
82696 {
82697 - ACCESS_ONCE(s->source_node_id_field) =
82698 + ACCESS_ONCE_RW(s->source_node_id_field) =
82699 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
82700 }
82701 EXPORT_SYMBOL(amdtp_out_stream_update);
82702 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
82703 index b680c5e..061b7a0 100644
82704 --- a/sound/firewire/amdtp.h
82705 +++ b/sound/firewire/amdtp.h
82706 @@ -139,7 +139,7 @@ static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s)
82707 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
82708 struct snd_pcm_substream *pcm)
82709 {
82710 - ACCESS_ONCE(s->pcm) = pcm;
82711 + ACCESS_ONCE_RW(s->pcm) = pcm;
82712 }
82713
82714 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
82715 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
82716 index d428ffe..751ef78 100644
82717 --- a/sound/firewire/isight.c
82718 +++ b/sound/firewire/isight.c
82719 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
82720 ptr += count;
82721 if (ptr >= runtime->buffer_size)
82722 ptr -= runtime->buffer_size;
82723 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
82724 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
82725
82726 isight->period_counter += count;
82727 if (isight->period_counter >= runtime->period_size) {
82728 @@ -307,7 +307,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
82729 if (err < 0)
82730 return err;
82731
82732 - ACCESS_ONCE(isight->pcm_active) = true;
82733 + ACCESS_ONCE_RW(isight->pcm_active) = true;
82734
82735 return 0;
82736 }
82737 @@ -340,7 +340,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
82738 {
82739 struct isight *isight = substream->private_data;
82740
82741 - ACCESS_ONCE(isight->pcm_active) = false;
82742 + ACCESS_ONCE_RW(isight->pcm_active) = false;
82743
82744 mutex_lock(&isight->mutex);
82745 isight_stop_streaming(isight);
82746 @@ -433,10 +433,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
82747
82748 switch (cmd) {
82749 case SNDRV_PCM_TRIGGER_START:
82750 - ACCESS_ONCE(isight->pcm_running) = true;
82751 + ACCESS_ONCE_RW(isight->pcm_running) = true;
82752 break;
82753 case SNDRV_PCM_TRIGGER_STOP:
82754 - ACCESS_ONCE(isight->pcm_running) = false;
82755 + ACCESS_ONCE_RW(isight->pcm_running) = false;
82756 break;
82757 default:
82758 return -EINVAL;
82759 diff --git a/sound/isa/cmi8330.c b/sound/isa/cmi8330.c
82760 index 7bd5e33..1fcab12 100644
82761 --- a/sound/isa/cmi8330.c
82762 +++ b/sound/isa/cmi8330.c
82763 @@ -172,7 +172,7 @@ struct snd_cmi8330 {
82764
82765 struct snd_pcm *pcm;
82766 struct snd_cmi8330_stream {
82767 - struct snd_pcm_ops ops;
82768 + snd_pcm_ops_no_const ops;
82769 snd_pcm_open_callback_t open;
82770 void *private_data; /* sb or wss */
82771 } streams[2];
82772 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
82773 index b2b3c01..e1c1e1f 100644
82774 --- a/sound/oss/sb_audio.c
82775 +++ b/sound/oss/sb_audio.c
82776 @@ -903,7 +903,7 @@ sb16_copy_from_user(int dev,
82777 buf16 = (signed short *)(localbuf + localoffs);
82778 while (c)
82779 {
82780 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
82781 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
82782 if (copy_from_user(lbuf8,
82783 userbuf+useroffs + p,
82784 locallen))
82785 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
82786 index 7d8803a..559f8d0 100644
82787 --- a/sound/oss/swarm_cs4297a.c
82788 +++ b/sound/oss/swarm_cs4297a.c
82789 @@ -2621,7 +2621,6 @@ static int __init cs4297a_init(void)
82790 {
82791 struct cs4297a_state *s;
82792 u32 pwr, id;
82793 - mm_segment_t fs;
82794 int rval;
82795 #ifndef CONFIG_BCM_CS4297A_CSWARM
82796 u64 cfg;
82797 @@ -2711,22 +2710,23 @@ static int __init cs4297a_init(void)
82798 if (!rval) {
82799 char *sb1250_duart_present;
82800
82801 +#if 0
82802 + mm_segment_t fs;
82803 fs = get_fs();
82804 set_fs(KERNEL_DS);
82805 -#if 0
82806 val = SOUND_MASK_LINE;
82807 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
82808 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
82809 val = initvol[i].vol;
82810 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
82811 }
82812 + set_fs(fs);
82813 // cs4297a_write_ac97(s, 0x18, 0x0808);
82814 #else
82815 // cs4297a_write_ac97(s, 0x5e, 0x180);
82816 cs4297a_write_ac97(s, 0x02, 0x0808);
82817 cs4297a_write_ac97(s, 0x18, 0x0808);
82818 #endif
82819 - set_fs(fs);
82820
82821 list_add(&s->list, &cs4297a_devs);
82822
82823 diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
82824 index e5a7e19..4049063 100644
82825 --- a/sound/pci/hda/hda_codec.h
82826 +++ b/sound/pci/hda/hda_codec.h
82827 @@ -614,7 +614,7 @@ struct hda_bus_ops {
82828 /* notify power-up/down from codec to controller */
82829 void (*pm_notify)(struct hda_bus *bus);
82830 #endif
82831 -};
82832 +} __no_const;
82833
82834 /* template to pass to the bus constructor */
82835 struct hda_bus_template {
82836 @@ -714,6 +714,7 @@ struct hda_codec_ops {
82837 #endif
82838 void (*reboot_notify)(struct hda_codec *codec);
82839 };
82840 +typedef struct hda_codec_ops __no_const hda_codec_ops_no_const;
82841
82842 /* record for amp information cache */
82843 struct hda_cache_head {
82844 @@ -744,7 +745,7 @@ struct hda_pcm_ops {
82845 struct snd_pcm_substream *substream);
82846 int (*cleanup)(struct hda_pcm_stream *info, struct hda_codec *codec,
82847 struct snd_pcm_substream *substream);
82848 -};
82849 +} __no_const;
82850
82851 /* PCM information for each substream */
82852 struct hda_pcm_stream {
82853 @@ -802,7 +803,7 @@ struct hda_codec {
82854 const char *modelname; /* model name for preset */
82855
82856 /* set by patch */
82857 - struct hda_codec_ops patch_ops;
82858 + hda_codec_ops_no_const patch_ops;
82859
82860 /* PCM to create, set by patch_ops.build_pcms callback */
82861 unsigned int num_pcms;
82862 diff --git a/sound/pci/ice1712/ice1712.h b/sound/pci/ice1712/ice1712.h
82863 index 0da778a..bc38b84 100644
82864 --- a/sound/pci/ice1712/ice1712.h
82865 +++ b/sound/pci/ice1712/ice1712.h
82866 @@ -269,7 +269,7 @@ struct snd_ak4xxx_private {
82867 unsigned int mask_flags; /* total mask bits */
82868 struct snd_akm4xxx_ops {
82869 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
82870 - } ops;
82871 + } __no_const ops;
82872 };
82873
82874 struct snd_ice1712_spdif {
82875 @@ -285,7 +285,7 @@ struct snd_ice1712_spdif {
82876 int (*default_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
82877 void (*stream_get)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
82878 int (*stream_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
82879 - } ops;
82880 + } __no_const ops;
82881 };
82882
82883
82884 diff --git a/sound/pci/ymfpci/ymfpci.h b/sound/pci/ymfpci/ymfpci.h
82885 index bddc405..2c0733c 100644
82886 --- a/sound/pci/ymfpci/ymfpci.h
82887 +++ b/sound/pci/ymfpci/ymfpci.h
82888 @@ -358,7 +358,7 @@ struct snd_ymfpci {
82889 spinlock_t reg_lock;
82890 spinlock_t voice_lock;
82891 wait_queue_head_t interrupt_sleep;
82892 - atomic_t interrupt_sleep_count;
82893 + atomic_unchecked_t interrupt_sleep_count;
82894 struct snd_info_entry *proc_entry;
82895 const struct firmware *dsp_microcode;
82896 const struct firmware *controller_microcode;
82897 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
82898 index 62b2363..ee77972 100644
82899 --- a/sound/pci/ymfpci/ymfpci_main.c
82900 +++ b/sound/pci/ymfpci/ymfpci_main.c
82901 @@ -203,8 +203,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
82902 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
82903 break;
82904 }
82905 - if (atomic_read(&chip->interrupt_sleep_count)) {
82906 - atomic_set(&chip->interrupt_sleep_count, 0);
82907 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
82908 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
82909 wake_up(&chip->interrupt_sleep);
82910 }
82911 __end:
82912 @@ -788,7 +788,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
82913 continue;
82914 init_waitqueue_entry(&wait, current);
82915 add_wait_queue(&chip->interrupt_sleep, &wait);
82916 - atomic_inc(&chip->interrupt_sleep_count);
82917 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
82918 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
82919 remove_wait_queue(&chip->interrupt_sleep, &wait);
82920 }
82921 @@ -826,8 +826,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
82922 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
82923 spin_unlock(&chip->reg_lock);
82924
82925 - if (atomic_read(&chip->interrupt_sleep_count)) {
82926 - atomic_set(&chip->interrupt_sleep_count, 0);
82927 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
82928 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
82929 wake_up(&chip->interrupt_sleep);
82930 }
82931 }
82932 @@ -2402,7 +2402,7 @@ int __devinit snd_ymfpci_create(struct snd_card *card,
82933 spin_lock_init(&chip->reg_lock);
82934 spin_lock_init(&chip->voice_lock);
82935 init_waitqueue_head(&chip->interrupt_sleep);
82936 - atomic_set(&chip->interrupt_sleep_count, 0);
82937 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
82938 chip->card = card;
82939 chip->pci = pci;
82940 chip->irq = -1;
82941 diff --git a/tools/gcc/.gitignore b/tools/gcc/.gitignore
82942 new file mode 100644
82943 index 0000000..50f2f2f
82944 --- /dev/null
82945 +++ b/tools/gcc/.gitignore
82946 @@ -0,0 +1 @@
82947 +size_overflow_hash.h
82948 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
82949 new file mode 100644
82950 index 0000000..1d09b7e
82951 --- /dev/null
82952 +++ b/tools/gcc/Makefile
82953 @@ -0,0 +1,43 @@
82954 +#CC := gcc
82955 +#PLUGIN_SOURCE_FILES := pax_plugin.c
82956 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
82957 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
82958 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
82959 +
82960 +ifeq ($(PLUGINCC),$(HOSTCC))
82961 +HOSTLIBS := hostlibs
82962 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu99 -ggdb
82963 +else
82964 +HOSTLIBS := hostcxxlibs
82965 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu++98 -ggdb -Wno-unused-parameter
82966 +endif
82967 +
82968 +$(HOSTLIBS)-y := constify_plugin.so
82969 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
82970 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
82971 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
82972 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
82973 +$(HOSTLIBS)-y += colorize_plugin.so
82974 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
82975 +$(HOSTLIBS)-$(CONFIG_PAX_LATENT_ENTROPY) += latent_entropy_plugin.so
82976 +
82977 +always := $($(HOSTLIBS)-y)
82978 +
82979 +constify_plugin-objs := constify_plugin.o
82980 +stackleak_plugin-objs := stackleak_plugin.o
82981 +kallocstat_plugin-objs := kallocstat_plugin.o
82982 +kernexec_plugin-objs := kernexec_plugin.o
82983 +checker_plugin-objs := checker_plugin.o
82984 +colorize_plugin-objs := colorize_plugin.o
82985 +size_overflow_plugin-objs := size_overflow_plugin.o
82986 +latent_entropy_plugin-objs := latent_entropy_plugin.o
82987 +
82988 +$(obj)/size_overflow_plugin.o: $(objtree)/$(obj)/size_overflow_hash.h
82989 +
82990 +quiet_cmd_build_size_overflow_hash = GENHASH $@
82991 + cmd_build_size_overflow_hash = \
82992 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -d $< -o $@
82993 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
82994 + $(call if_changed,build_size_overflow_hash)
82995 +
82996 +targets += size_overflow_hash.h
82997 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
82998 new file mode 100644
82999 index 0000000..d41b5af
83000 --- /dev/null
83001 +++ b/tools/gcc/checker_plugin.c
83002 @@ -0,0 +1,171 @@
83003 +/*
83004 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
83005 + * Licensed under the GPL v2
83006 + *
83007 + * Note: the choice of the license means that the compilation process is
83008 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
83009 + * but for the kernel it doesn't matter since it doesn't link against
83010 + * any of the gcc libraries
83011 + *
83012 + * gcc plugin to implement various sparse (source code checker) features
83013 + *
83014 + * TODO:
83015 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
83016 + *
83017 + * BUGS:
83018 + * - none known
83019 + */
83020 +#include "gcc-plugin.h"
83021 +#include "config.h"
83022 +#include "system.h"
83023 +#include "coretypes.h"
83024 +#include "tree.h"
83025 +#include "tree-pass.h"
83026 +#include "flags.h"
83027 +#include "intl.h"
83028 +#include "toplev.h"
83029 +#include "plugin.h"
83030 +//#include "expr.h" where are you...
83031 +#include "diagnostic.h"
83032 +#include "plugin-version.h"
83033 +#include "tm.h"
83034 +#include "function.h"
83035 +#include "basic-block.h"
83036 +#include "gimple.h"
83037 +#include "rtl.h"
83038 +#include "emit-rtl.h"
83039 +#include "tree-flow.h"
83040 +#include "target.h"
83041 +
83042 +extern void c_register_addr_space (const char *str, addr_space_t as);
83043 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
83044 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
83045 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
83046 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
83047 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
83048 +
83049 +extern void print_gimple_stmt(FILE *, gimple, int, int);
83050 +extern rtx emit_move_insn(rtx x, rtx y);
83051 +
83052 +int plugin_is_GPL_compatible;
83053 +
83054 +static struct plugin_info checker_plugin_info = {
83055 + .version = "201111150100",
83056 +};
83057 +
83058 +#define ADDR_SPACE_KERNEL 0
83059 +#define ADDR_SPACE_FORCE_KERNEL 1
83060 +#define ADDR_SPACE_USER 2
83061 +#define ADDR_SPACE_FORCE_USER 3
83062 +#define ADDR_SPACE_IOMEM 0
83063 +#define ADDR_SPACE_FORCE_IOMEM 0
83064 +#define ADDR_SPACE_PERCPU 0
83065 +#define ADDR_SPACE_FORCE_PERCPU 0
83066 +#define ADDR_SPACE_RCU 0
83067 +#define ADDR_SPACE_FORCE_RCU 0
83068 +
83069 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
83070 +{
83071 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
83072 +}
83073 +
83074 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
83075 +{
83076 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
83077 +}
83078 +
83079 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
83080 +{
83081 + return default_addr_space_valid_pointer_mode(mode, as);
83082 +}
83083 +
83084 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
83085 +{
83086 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
83087 +}
83088 +
83089 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
83090 +{
83091 + return default_addr_space_legitimize_address(x, oldx, mode, as);
83092 +}
83093 +
83094 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
83095 +{
83096 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
83097 + return true;
83098 +
83099 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
83100 + return true;
83101 +
83102 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
83103 + return true;
83104 +
83105 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
83106 + return true;
83107 +
83108 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
83109 + return true;
83110 +
83111 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
83112 + return true;
83113 +
83114 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
83115 + return true;
83116 +
83117 + return subset == superset;
83118 +}
83119 +
83120 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
83121 +{
83122 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
83123 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
83124 +
83125 + return op;
83126 +}
83127 +
83128 +static void register_checker_address_spaces(void *event_data, void *data)
83129 +{
83130 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
83131 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
83132 + c_register_addr_space("__user", ADDR_SPACE_USER);
83133 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
83134 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
83135 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
83136 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
83137 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
83138 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
83139 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
83140 +
83141 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
83142 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
83143 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
83144 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
83145 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
83146 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
83147 + targetm.addr_space.convert = checker_addr_space_convert;
83148 +}
83149 +
83150 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
83151 +{
83152 + const char * const plugin_name = plugin_info->base_name;
83153 + const int argc = plugin_info->argc;
83154 + const struct plugin_argument * const argv = plugin_info->argv;
83155 + int i;
83156 +
83157 + if (!plugin_default_version_check(version, &gcc_version)) {
83158 + error(G_("incompatible gcc/plugin versions"));
83159 + return 1;
83160 + }
83161 +
83162 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
83163 +
83164 + for (i = 0; i < argc; ++i)
83165 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
83166 +
83167 + if (TARGET_64BIT == 0)
83168 + return 0;
83169 +
83170 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
83171 +
83172 + return 0;
83173 +}
83174 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
83175 new file mode 100644
83176 index 0000000..846aeb0
83177 --- /dev/null
83178 +++ b/tools/gcc/colorize_plugin.c
83179 @@ -0,0 +1,148 @@
83180 +/*
83181 + * Copyright 2012 by PaX Team <pageexec@freemail.hu>
83182 + * Licensed under the GPL v2
83183 + *
83184 + * Note: the choice of the license means that the compilation process is
83185 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
83186 + * but for the kernel it doesn't matter since it doesn't link against
83187 + * any of the gcc libraries
83188 + *
83189 + * gcc plugin to colorize diagnostic output
83190 + *
83191 + */
83192 +
83193 +#include "gcc-plugin.h"
83194 +#include "config.h"
83195 +#include "system.h"
83196 +#include "coretypes.h"
83197 +#include "tree.h"
83198 +#include "tree-pass.h"
83199 +#include "flags.h"
83200 +#include "intl.h"
83201 +#include "toplev.h"
83202 +#include "plugin.h"
83203 +#include "diagnostic.h"
83204 +#include "plugin-version.h"
83205 +#include "tm.h"
83206 +
83207 +int plugin_is_GPL_compatible;
83208 +
83209 +static struct plugin_info colorize_plugin_info = {
83210 + .version = "201203092200",
83211 + .help = NULL,
83212 +};
83213 +
83214 +#define GREEN "\033[32m\033[2m"
83215 +#define LIGHTGREEN "\033[32m\033[1m"
83216 +#define YELLOW "\033[33m\033[2m"
83217 +#define LIGHTYELLOW "\033[33m\033[1m"
83218 +#define RED "\033[31m\033[2m"
83219 +#define LIGHTRED "\033[31m\033[1m"
83220 +#define BLUE "\033[34m\033[2m"
83221 +#define LIGHTBLUE "\033[34m\033[1m"
83222 +#define BRIGHT "\033[m\033[1m"
83223 +#define NORMAL "\033[m"
83224 +
83225 +static diagnostic_starter_fn old_starter;
83226 +static diagnostic_finalizer_fn old_finalizer;
83227 +
83228 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
83229 +{
83230 + const char *color;
83231 + char *newprefix;
83232 +
83233 + switch (diagnostic->kind) {
83234 + case DK_NOTE:
83235 + color = LIGHTBLUE;
83236 + break;
83237 +
83238 + case DK_PEDWARN:
83239 + case DK_WARNING:
83240 + color = LIGHTYELLOW;
83241 + break;
83242 +
83243 + case DK_ERROR:
83244 + case DK_FATAL:
83245 + case DK_ICE:
83246 + case DK_PERMERROR:
83247 + case DK_SORRY:
83248 + color = LIGHTRED;
83249 + break;
83250 +
83251 + default:
83252 + color = NORMAL;
83253 + }
83254 +
83255 + old_starter(context, diagnostic);
83256 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
83257 + return;
83258 + pp_destroy_prefix(context->printer);
83259 + pp_set_prefix(context->printer, newprefix);
83260 +}
83261 +
83262 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
83263 +{
83264 + old_finalizer(context, diagnostic);
83265 +}
83266 +
83267 +static void colorize_arm(void)
83268 +{
83269 + old_starter = diagnostic_starter(global_dc);
83270 + old_finalizer = diagnostic_finalizer(global_dc);
83271 +
83272 + diagnostic_starter(global_dc) = start_colorize;
83273 + diagnostic_finalizer(global_dc) = finalize_colorize;
83274 +}
83275 +
83276 +static unsigned int execute_colorize_rearm(void)
83277 +{
83278 + if (diagnostic_starter(global_dc) == start_colorize)
83279 + return 0;
83280 +
83281 + colorize_arm();
83282 + return 0;
83283 +}
83284 +
83285 +struct simple_ipa_opt_pass pass_ipa_colorize_rearm = {
83286 + .pass = {
83287 + .type = SIMPLE_IPA_PASS,
83288 + .name = "colorize_rearm",
83289 + .gate = NULL,
83290 + .execute = execute_colorize_rearm,
83291 + .sub = NULL,
83292 + .next = NULL,
83293 + .static_pass_number = 0,
83294 + .tv_id = TV_NONE,
83295 + .properties_required = 0,
83296 + .properties_provided = 0,
83297 + .properties_destroyed = 0,
83298 + .todo_flags_start = 0,
83299 + .todo_flags_finish = 0
83300 + }
83301 +};
83302 +
83303 +static void colorize_start_unit(void *gcc_data, void *user_data)
83304 +{
83305 + colorize_arm();
83306 +}
83307 +
83308 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
83309 +{
83310 + const char * const plugin_name = plugin_info->base_name;
83311 + struct register_pass_info colorize_rearm_pass_info = {
83312 + .pass = &pass_ipa_colorize_rearm.pass,
83313 + .reference_pass_name = "*free_lang_data",
83314 + .ref_pass_instance_number = 1,
83315 + .pos_op = PASS_POS_INSERT_AFTER
83316 + };
83317 +
83318 + if (!plugin_default_version_check(version, &gcc_version)) {
83319 + error(G_("incompatible gcc/plugin versions"));
83320 + return 1;
83321 + }
83322 +
83323 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
83324 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
83325 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
83326 + return 0;
83327 +}
83328 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
83329 new file mode 100644
83330 index 0000000..92ed719
83331 --- /dev/null
83332 +++ b/tools/gcc/constify_plugin.c
83333 @@ -0,0 +1,331 @@
83334 +/*
83335 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
83336 + * Copyright 2011 by PaX Team <pageexec@freemail.hu>
83337 + * Licensed under the GPL v2, or (at your option) v3
83338 + *
83339 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
83340 + *
83341 + * Homepage:
83342 + * http://www.grsecurity.net/~ephox/const_plugin/
83343 + *
83344 + * Usage:
83345 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
83346 + * $ gcc -fplugin=constify_plugin.so test.c -O2
83347 + */
83348 +
83349 +#include "gcc-plugin.h"
83350 +#include "config.h"
83351 +#include "system.h"
83352 +#include "coretypes.h"
83353 +#include "tree.h"
83354 +#include "tree-pass.h"
83355 +#include "flags.h"
83356 +#include "intl.h"
83357 +#include "toplev.h"
83358 +#include "plugin.h"
83359 +#include "diagnostic.h"
83360 +#include "plugin-version.h"
83361 +#include "tm.h"
83362 +#include "function.h"
83363 +#include "basic-block.h"
83364 +#include "gimple.h"
83365 +#include "rtl.h"
83366 +#include "emit-rtl.h"
83367 +#include "tree-flow.h"
83368 +
83369 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
83370 +
83371 +int plugin_is_GPL_compatible;
83372 +
83373 +static struct plugin_info const_plugin_info = {
83374 + .version = "201205300030",
83375 + .help = "no-constify\tturn off constification\n",
83376 +};
83377 +
83378 +static void deconstify_tree(tree node);
83379 +
83380 +static void deconstify_type(tree type)
83381 +{
83382 + tree field;
83383 +
83384 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
83385 + tree type = TREE_TYPE(field);
83386 +
83387 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
83388 + continue;
83389 + if (!TYPE_READONLY(type))
83390 + continue;
83391 +
83392 + deconstify_tree(field);
83393 + }
83394 + TYPE_READONLY(type) = 0;
83395 + C_TYPE_FIELDS_READONLY(type) = 0;
83396 +}
83397 +
83398 +static void deconstify_tree(tree node)
83399 +{
83400 + tree old_type, new_type, field;
83401 +
83402 + old_type = TREE_TYPE(node);
83403 +
83404 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
83405 +
83406 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
83407 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
83408 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
83409 + DECL_FIELD_CONTEXT(field) = new_type;
83410 +
83411 + deconstify_type(new_type);
83412 +
83413 + TREE_READONLY(node) = 0;
83414 + TREE_TYPE(node) = new_type;
83415 +}
83416 +
83417 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
83418 +{
83419 + tree type;
83420 +
83421 + *no_add_attrs = true;
83422 + if (TREE_CODE(*node) == FUNCTION_DECL) {
83423 + error("%qE attribute does not apply to functions", name);
83424 + return NULL_TREE;
83425 + }
83426 +
83427 + if (TREE_CODE(*node) == VAR_DECL) {
83428 + error("%qE attribute does not apply to variables", name);
83429 + return NULL_TREE;
83430 + }
83431 +
83432 + if (TYPE_P(*node)) {
83433 + if (TREE_CODE(*node) == RECORD_TYPE || TREE_CODE(*node) == UNION_TYPE)
83434 + *no_add_attrs = false;
83435 + else
83436 + error("%qE attribute applies to struct and union types only", name);
83437 + return NULL_TREE;
83438 + }
83439 +
83440 + type = TREE_TYPE(*node);
83441 +
83442 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
83443 + error("%qE attribute applies to struct and union types only", name);
83444 + return NULL_TREE;
83445 + }
83446 +
83447 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
83448 + error("%qE attribute is already applied to the type", name);
83449 + return NULL_TREE;
83450 + }
83451 +
83452 + if (TREE_CODE(*node) == TYPE_DECL && !TYPE_READONLY(type)) {
83453 + error("%qE attribute used on type that is not constified", name);
83454 + return NULL_TREE;
83455 + }
83456 +
83457 + if (TREE_CODE(*node) == TYPE_DECL) {
83458 + deconstify_tree(*node);
83459 + return NULL_TREE;
83460 + }
83461 +
83462 + return NULL_TREE;
83463 +}
83464 +
83465 +static void constify_type(tree type)
83466 +{
83467 + TYPE_READONLY(type) = 1;
83468 + C_TYPE_FIELDS_READONLY(type) = 1;
83469 +}
83470 +
83471 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
83472 +{
83473 + *no_add_attrs = true;
83474 + if (!TYPE_P(*node)) {
83475 + error("%qE attribute applies to types only", name);
83476 + return NULL_TREE;
83477 + }
83478 +
83479 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
83480 + error("%qE attribute applies to struct and union types only", name);
83481 + return NULL_TREE;
83482 + }
83483 +
83484 + *no_add_attrs = false;
83485 + constify_type(*node);
83486 + return NULL_TREE;
83487 +}
83488 +
83489 +static struct attribute_spec no_const_attr = {
83490 + .name = "no_const",
83491 + .min_length = 0,
83492 + .max_length = 0,
83493 + .decl_required = false,
83494 + .type_required = false,
83495 + .function_type_required = false,
83496 + .handler = handle_no_const_attribute,
83497 +#if BUILDING_GCC_VERSION >= 4007
83498 + .affects_type_identity = true
83499 +#endif
83500 +};
83501 +
83502 +static struct attribute_spec do_const_attr = {
83503 + .name = "do_const",
83504 + .min_length = 0,
83505 + .max_length = 0,
83506 + .decl_required = false,
83507 + .type_required = false,
83508 + .function_type_required = false,
83509 + .handler = handle_do_const_attribute,
83510 +#if BUILDING_GCC_VERSION >= 4007
83511 + .affects_type_identity = true
83512 +#endif
83513 +};
83514 +
83515 +static void register_attributes(void *event_data, void *data)
83516 +{
83517 + register_attribute(&no_const_attr);
83518 + register_attribute(&do_const_attr);
83519 +}
83520 +
83521 +static bool is_fptr(tree field)
83522 +{
83523 + tree ptr = TREE_TYPE(field);
83524 +
83525 + if (TREE_CODE(ptr) != POINTER_TYPE)
83526 + return false;
83527 +
83528 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
83529 +}
83530 +
83531 +static bool walk_struct(tree node)
83532 +{
83533 + tree field;
83534 +
83535 + if (TYPE_FIELDS(node) == NULL_TREE)
83536 + return false;
83537 +
83538 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
83539 + gcc_assert(!TYPE_READONLY(node));
83540 + deconstify_type(node);
83541 + return false;
83542 + }
83543 +
83544 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
83545 + tree type = TREE_TYPE(field);
83546 + enum tree_code code = TREE_CODE(type);
83547 +
83548 + if (node == type)
83549 + return false;
83550 + if (code == RECORD_TYPE || code == UNION_TYPE) {
83551 + if (!(walk_struct(type)))
83552 + return false;
83553 + } else if (!is_fptr(field) && !TREE_READONLY(field))
83554 + return false;
83555 + }
83556 + return true;
83557 +}
83558 +
83559 +static void finish_type(void *event_data, void *data)
83560 +{
83561 + tree type = (tree)event_data;
83562 +
83563 + if (type == NULL_TREE || type == error_mark_node)
83564 + return;
83565 +
83566 + if (TYPE_READONLY(type))
83567 + return;
83568 +
83569 + if (walk_struct(type))
83570 + constify_type(type);
83571 +}
83572 +
83573 +static unsigned int check_local_variables(void);
83574 +
83575 +struct gimple_opt_pass pass_local_variable = {
83576 + {
83577 + .type = GIMPLE_PASS,
83578 + .name = "check_local_variables",
83579 + .gate = NULL,
83580 + .execute = check_local_variables,
83581 + .sub = NULL,
83582 + .next = NULL,
83583 + .static_pass_number = 0,
83584 + .tv_id = TV_NONE,
83585 + .properties_required = 0,
83586 + .properties_provided = 0,
83587 + .properties_destroyed = 0,
83588 + .todo_flags_start = 0,
83589 + .todo_flags_finish = 0
83590 + }
83591 +};
83592 +
83593 +static unsigned int check_local_variables(void)
83594 +{
83595 + tree var;
83596 + referenced_var_iterator rvi;
83597 +
83598 +#if BUILDING_GCC_VERSION == 4005
83599 + FOR_EACH_REFERENCED_VAR(var, rvi) {
83600 +#else
83601 + FOR_EACH_REFERENCED_VAR(cfun, var, rvi) {
83602 +#endif
83603 + tree type = TREE_TYPE(var);
83604 +
83605 + if (!DECL_P(var) || TREE_STATIC(var) || DECL_EXTERNAL(var))
83606 + continue;
83607 +
83608 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
83609 + continue;
83610 +
83611 + if (!TYPE_READONLY(type))
83612 + continue;
83613 +
83614 +// if (lookup_attribute("no_const", DECL_ATTRIBUTES(var)))
83615 +// continue;
83616 +
83617 +// if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
83618 +// continue;
83619 +
83620 + if (walk_struct(type)) {
83621 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
83622 + return 1;
83623 + }
83624 + }
83625 + return 0;
83626 +}
83627 +
83628 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
83629 +{
83630 + const char * const plugin_name = plugin_info->base_name;
83631 + const int argc = plugin_info->argc;
83632 + const struct plugin_argument * const argv = plugin_info->argv;
83633 + int i;
83634 + bool constify = true;
83635 +
83636 + struct register_pass_info local_variable_pass_info = {
83637 + .pass = &pass_local_variable.pass,
83638 + .reference_pass_name = "*referenced_vars",
83639 + .ref_pass_instance_number = 1,
83640 + .pos_op = PASS_POS_INSERT_AFTER
83641 + };
83642 +
83643 + if (!plugin_default_version_check(version, &gcc_version)) {
83644 + error(G_("incompatible gcc/plugin versions"));
83645 + return 1;
83646 + }
83647 +
83648 + for (i = 0; i < argc; ++i) {
83649 + if (!(strcmp(argv[i].key, "no-constify"))) {
83650 + constify = false;
83651 + continue;
83652 + }
83653 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
83654 + }
83655 +
83656 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
83657 + if (constify) {
83658 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
83659 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &local_variable_pass_info);
83660 + }
83661 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
83662 +
83663 + return 0;
83664 +}
83665 diff --git a/tools/gcc/generate_size_overflow_hash.sh b/tools/gcc/generate_size_overflow_hash.sh
83666 new file mode 100755
83667 index 0000000..02c6bec
83668 --- /dev/null
83669 +++ b/tools/gcc/generate_size_overflow_hash.sh
83670 @@ -0,0 +1,94 @@
83671 +#!/bin/bash
83672 +
83673 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
83674 +
83675 +header1="size_overflow_hash.h"
83676 +database="size_overflow_hash.data"
83677 +n=65536
83678 +
83679 +usage() {
83680 +cat <<EOF
83681 +usage: $0 options
83682 +OPTIONS:
83683 + -h|--help help
83684 + -o header file
83685 + -d database file
83686 + -n hash array size
83687 +EOF
83688 + return 0
83689 +}
83690 +
83691 +while true
83692 +do
83693 + case "$1" in
83694 + -h|--help) usage && exit 0;;
83695 + -n) n=$2; shift 2;;
83696 + -o) header1="$2"; shift 2;;
83697 + -d) database="$2"; shift 2;;
83698 + --) shift 1; break ;;
83699 + *) break ;;
83700 + esac
83701 +done
83702 +
83703 +create_defines() {
83704 + for i in `seq 1 32`
83705 + do
83706 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
83707 + done
83708 + echo >> "$header1"
83709 +}
83710 +
83711 +create_structs () {
83712 + rm -f "$header1"
83713 +
83714 + create_defines
83715 +
83716 + cat "$database" | while read data
83717 + do
83718 + data_array=($data)
83719 + struct_hash_name="${data_array[0]}"
83720 + funcn="${data_array[1]}"
83721 + params="${data_array[2]}"
83722 + next="${data_array[5]}"
83723 +
83724 + echo "const struct size_overflow_hash $struct_hash_name = {" >> "$header1"
83725 +
83726 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
83727 + echo -en "\t.param\t= " >> "$header1"
83728 + line=
83729 + for param_num in ${params//-/ };
83730 + do
83731 + line="${line}PARAM"$param_num"|"
83732 + done
83733 +
83734 + echo -e "${line%?},\n};\n" >> "$header1"
83735 + done
83736 +}
83737 +
83738 +create_headers () {
83739 + echo "const struct size_overflow_hash * const size_overflow_hash[$n] = {" >> "$header1"
83740 +}
83741 +
83742 +create_array_elements () {
83743 + index=0
83744 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
83745 + do
83746 + data_array=($data)
83747 + i="${data_array[3]}"
83748 + hash="${data_array[4]}"
83749 + while [[ $index -lt $i ]]
83750 + do
83751 + echo -e "\t["$index"]\t= NULL," >> "$header1"
83752 + index=$(($index + 1))
83753 + done
83754 + index=$(($index + 1))
83755 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
83756 + done
83757 + echo '};' >> $header1
83758 +}
83759 +
83760 +create_structs
83761 +create_headers
83762 +create_array_elements
83763 +
83764 +exit 0
83765 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
83766 new file mode 100644
83767 index 0000000..a86e422
83768 --- /dev/null
83769 +++ b/tools/gcc/kallocstat_plugin.c
83770 @@ -0,0 +1,167 @@
83771 +/*
83772 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
83773 + * Licensed under the GPL v2
83774 + *
83775 + * Note: the choice of the license means that the compilation process is
83776 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
83777 + * but for the kernel it doesn't matter since it doesn't link against
83778 + * any of the gcc libraries
83779 + *
83780 + * gcc plugin to find the distribution of k*alloc sizes
83781 + *
83782 + * TODO:
83783 + *
83784 + * BUGS:
83785 + * - none known
83786 + */
83787 +#include "gcc-plugin.h"
83788 +#include "config.h"
83789 +#include "system.h"
83790 +#include "coretypes.h"
83791 +#include "tree.h"
83792 +#include "tree-pass.h"
83793 +#include "flags.h"
83794 +#include "intl.h"
83795 +#include "toplev.h"
83796 +#include "plugin.h"
83797 +//#include "expr.h" where are you...
83798 +#include "diagnostic.h"
83799 +#include "plugin-version.h"
83800 +#include "tm.h"
83801 +#include "function.h"
83802 +#include "basic-block.h"
83803 +#include "gimple.h"
83804 +#include "rtl.h"
83805 +#include "emit-rtl.h"
83806 +
83807 +extern void print_gimple_stmt(FILE *, gimple, int, int);
83808 +
83809 +int plugin_is_GPL_compatible;
83810 +
83811 +static const char * const kalloc_functions[] = {
83812 + "__kmalloc",
83813 + "kmalloc",
83814 + "kmalloc_large",
83815 + "kmalloc_node",
83816 + "kmalloc_order",
83817 + "kmalloc_order_trace",
83818 + "kmalloc_slab",
83819 + "kzalloc",
83820 + "kzalloc_node",
83821 +};
83822 +
83823 +static struct plugin_info kallocstat_plugin_info = {
83824 + .version = "201111150100",
83825 +};
83826 +
83827 +static unsigned int execute_kallocstat(void);
83828 +
83829 +static struct gimple_opt_pass kallocstat_pass = {
83830 + .pass = {
83831 + .type = GIMPLE_PASS,
83832 + .name = "kallocstat",
83833 + .gate = NULL,
83834 + .execute = execute_kallocstat,
83835 + .sub = NULL,
83836 + .next = NULL,
83837 + .static_pass_number = 0,
83838 + .tv_id = TV_NONE,
83839 + .properties_required = 0,
83840 + .properties_provided = 0,
83841 + .properties_destroyed = 0,
83842 + .todo_flags_start = 0,
83843 + .todo_flags_finish = 0
83844 + }
83845 +};
83846 +
83847 +static bool is_kalloc(const char *fnname)
83848 +{
83849 + size_t i;
83850 +
83851 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
83852 + if (!strcmp(fnname, kalloc_functions[i]))
83853 + return true;
83854 + return false;
83855 +}
83856 +
83857 +static unsigned int execute_kallocstat(void)
83858 +{
83859 + basic_block bb;
83860 +
83861 + // 1. loop through BBs and GIMPLE statements
83862 + FOR_EACH_BB(bb) {
83863 + gimple_stmt_iterator gsi;
83864 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
83865 + // gimple match:
83866 + tree fndecl, size;
83867 + gimple call_stmt;
83868 + const char *fnname;
83869 +
83870 + // is it a call
83871 + call_stmt = gsi_stmt(gsi);
83872 + if (!is_gimple_call(call_stmt))
83873 + continue;
83874 + fndecl = gimple_call_fndecl(call_stmt);
83875 + if (fndecl == NULL_TREE)
83876 + continue;
83877 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
83878 + continue;
83879 +
83880 + // is it a call to k*alloc
83881 + fnname = IDENTIFIER_POINTER(DECL_NAME(fndecl));
83882 + if (!is_kalloc(fnname))
83883 + continue;
83884 +
83885 + // is the size arg the result of a simple const assignment
83886 + size = gimple_call_arg(call_stmt, 0);
83887 + while (true) {
83888 + gimple def_stmt;
83889 + expanded_location xloc;
83890 + size_t size_val;
83891 +
83892 + if (TREE_CODE(size) != SSA_NAME)
83893 + break;
83894 + def_stmt = SSA_NAME_DEF_STMT(size);
83895 + if (!def_stmt || !is_gimple_assign(def_stmt))
83896 + break;
83897 + if (gimple_num_ops(def_stmt) != 2)
83898 + break;
83899 + size = gimple_assign_rhs1(def_stmt);
83900 + if (!TREE_CONSTANT(size))
83901 + continue;
83902 + xloc = expand_location(gimple_location(def_stmt));
83903 + if (!xloc.file)
83904 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
83905 + size_val = TREE_INT_CST_LOW(size);
83906 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
83907 + break;
83908 + }
83909 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
83910 +//debug_tree(gimple_call_fn(call_stmt));
83911 +//print_node(stderr, "pax", fndecl, 4);
83912 + }
83913 + }
83914 +
83915 + return 0;
83916 +}
83917 +
83918 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
83919 +{
83920 + const char * const plugin_name = plugin_info->base_name;
83921 + struct register_pass_info kallocstat_pass_info = {
83922 + .pass = &kallocstat_pass.pass,
83923 + .reference_pass_name = "ssa",
83924 + .ref_pass_instance_number = 1,
83925 + .pos_op = PASS_POS_INSERT_AFTER
83926 + };
83927 +
83928 + if (!plugin_default_version_check(version, &gcc_version)) {
83929 + error(G_("incompatible gcc/plugin versions"));
83930 + return 1;
83931 + }
83932 +
83933 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
83934 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
83935 +
83936 + return 0;
83937 +}
83938 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
83939 new file mode 100644
83940 index 0000000..8856202
83941 --- /dev/null
83942 +++ b/tools/gcc/kernexec_plugin.c
83943 @@ -0,0 +1,432 @@
83944 +/*
83945 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
83946 + * Licensed under the GPL v2
83947 + *
83948 + * Note: the choice of the license means that the compilation process is
83949 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
83950 + * but for the kernel it doesn't matter since it doesn't link against
83951 + * any of the gcc libraries
83952 + *
83953 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
83954 + *
83955 + * TODO:
83956 + *
83957 + * BUGS:
83958 + * - none known
83959 + */
83960 +#include "gcc-plugin.h"
83961 +#include "config.h"
83962 +#include "system.h"
83963 +#include "coretypes.h"
83964 +#include "tree.h"
83965 +#include "tree-pass.h"
83966 +#include "flags.h"
83967 +#include "intl.h"
83968 +#include "toplev.h"
83969 +#include "plugin.h"
83970 +//#include "expr.h" where are you...
83971 +#include "diagnostic.h"
83972 +#include "plugin-version.h"
83973 +#include "tm.h"
83974 +#include "function.h"
83975 +#include "basic-block.h"
83976 +#include "gimple.h"
83977 +#include "rtl.h"
83978 +#include "emit-rtl.h"
83979 +#include "tree-flow.h"
83980 +
83981 +extern void print_gimple_stmt(FILE *, gimple, int, int);
83982 +extern rtx emit_move_insn(rtx x, rtx y);
83983 +
83984 +#if BUILDING_GCC_VERSION <= 4006
83985 +#define ANY_RETURN_P(rtx) (GET_CODE(rtx) == RETURN)
83986 +#endif
83987 +
83988 +int plugin_is_GPL_compatible;
83989 +
83990 +static struct plugin_info kernexec_plugin_info = {
83991 + .version = "201111291120",
83992 + .help = "method=[bts|or]\tinstrumentation method\n"
83993 +};
83994 +
83995 +static unsigned int execute_kernexec_reload(void);
83996 +static unsigned int execute_kernexec_fptr(void);
83997 +static unsigned int execute_kernexec_retaddr(void);
83998 +static bool kernexec_cmodel_check(void);
83999 +
84000 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
84001 +static void (*kernexec_instrument_retaddr)(rtx);
84002 +
84003 +static struct gimple_opt_pass kernexec_reload_pass = {
84004 + .pass = {
84005 + .type = GIMPLE_PASS,
84006 + .name = "kernexec_reload",
84007 + .gate = kernexec_cmodel_check,
84008 + .execute = execute_kernexec_reload,
84009 + .sub = NULL,
84010 + .next = NULL,
84011 + .static_pass_number = 0,
84012 + .tv_id = TV_NONE,
84013 + .properties_required = 0,
84014 + .properties_provided = 0,
84015 + .properties_destroyed = 0,
84016 + .todo_flags_start = 0,
84017 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
84018 + }
84019 +};
84020 +
84021 +static struct gimple_opt_pass kernexec_fptr_pass = {
84022 + .pass = {
84023 + .type = GIMPLE_PASS,
84024 + .name = "kernexec_fptr",
84025 + .gate = kernexec_cmodel_check,
84026 + .execute = execute_kernexec_fptr,
84027 + .sub = NULL,
84028 + .next = NULL,
84029 + .static_pass_number = 0,
84030 + .tv_id = TV_NONE,
84031 + .properties_required = 0,
84032 + .properties_provided = 0,
84033 + .properties_destroyed = 0,
84034 + .todo_flags_start = 0,
84035 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
84036 + }
84037 +};
84038 +
84039 +static struct rtl_opt_pass kernexec_retaddr_pass = {
84040 + .pass = {
84041 + .type = RTL_PASS,
84042 + .name = "kernexec_retaddr",
84043 + .gate = kernexec_cmodel_check,
84044 + .execute = execute_kernexec_retaddr,
84045 + .sub = NULL,
84046 + .next = NULL,
84047 + .static_pass_number = 0,
84048 + .tv_id = TV_NONE,
84049 + .properties_required = 0,
84050 + .properties_provided = 0,
84051 + .properties_destroyed = 0,
84052 + .todo_flags_start = 0,
84053 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
84054 + }
84055 +};
84056 +
84057 +static bool kernexec_cmodel_check(void)
84058 +{
84059 + tree section;
84060 +
84061 + if (ix86_cmodel != CM_KERNEL)
84062 + return false;
84063 +
84064 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
84065 + if (!section || !TREE_VALUE(section))
84066 + return true;
84067 +
84068 + section = TREE_VALUE(TREE_VALUE(section));
84069 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
84070 + return true;
84071 +
84072 + return false;
84073 +}
84074 +
84075 +/*
84076 + * add special KERNEXEC instrumentation: reload %r10 after it has been clobbered
84077 + */
84078 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
84079 +{
84080 + gimple asm_movabs_stmt;
84081 +
84082 + // build asm volatile("movabs $0x8000000000000000, %%r10\n\t" : : : );
84083 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r10\n\t", NULL, NULL, NULL, NULL);
84084 + gimple_asm_set_volatile(asm_movabs_stmt, true);
84085 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
84086 + update_stmt(asm_movabs_stmt);
84087 +}
84088 +
84089 +/*
84090 + * find all asm() stmts that clobber r10 and add a reload of r10
84091 + */
84092 +static unsigned int execute_kernexec_reload(void)
84093 +{
84094 + basic_block bb;
84095 +
84096 + // 1. loop through BBs and GIMPLE statements
84097 + FOR_EACH_BB(bb) {
84098 + gimple_stmt_iterator gsi;
84099 +
84100 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
84101 + // gimple match: __asm__ ("" : : : "r10");
84102 + gimple asm_stmt;
84103 + size_t nclobbers;
84104 +
84105 + // is it an asm ...
84106 + asm_stmt = gsi_stmt(gsi);
84107 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
84108 + continue;
84109 +
84110 + // ... clobbering r10
84111 + nclobbers = gimple_asm_nclobbers(asm_stmt);
84112 + while (nclobbers--) {
84113 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
84114 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r10"))
84115 + continue;
84116 + kernexec_reload_fptr_mask(&gsi);
84117 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
84118 + break;
84119 + }
84120 + }
84121 + }
84122 +
84123 + return 0;
84124 +}
84125 +
84126 +/*
84127 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
84128 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
84129 + */
84130 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
84131 +{
84132 + gimple assign_intptr, assign_new_fptr, call_stmt;
84133 + tree intptr, old_fptr, new_fptr, kernexec_mask;
84134 +
84135 + call_stmt = gsi_stmt(*gsi);
84136 + old_fptr = gimple_call_fn(call_stmt);
84137 +
84138 + // create temporary unsigned long variable used for bitops and cast fptr to it
84139 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
84140 + add_referenced_var(intptr);
84141 + mark_sym_for_renaming(intptr);
84142 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
84143 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
84144 + update_stmt(assign_intptr);
84145 +
84146 + // apply logical or to temporary unsigned long and bitmask
84147 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
84148 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
84149 + assign_intptr = gimple_build_assign(intptr, fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask));
84150 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
84151 + update_stmt(assign_intptr);
84152 +
84153 + // cast temporary unsigned long back to a temporary fptr variable
84154 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
84155 + add_referenced_var(new_fptr);
84156 + mark_sym_for_renaming(new_fptr);
84157 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
84158 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
84159 + update_stmt(assign_new_fptr);
84160 +
84161 + // replace call stmt fn with the new fptr
84162 + gimple_call_set_fn(call_stmt, new_fptr);
84163 + update_stmt(call_stmt);
84164 +}
84165 +
84166 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
84167 +{
84168 + gimple asm_or_stmt, call_stmt;
84169 + tree old_fptr, new_fptr, input, output;
84170 + VEC(tree, gc) *inputs = NULL;
84171 + VEC(tree, gc) *outputs = NULL;
84172 +
84173 + call_stmt = gsi_stmt(*gsi);
84174 + old_fptr = gimple_call_fn(call_stmt);
84175 +
84176 + // create temporary fptr variable
84177 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
84178 + add_referenced_var(new_fptr);
84179 + mark_sym_for_renaming(new_fptr);
84180 +
84181 + // build asm volatile("orq %%r10, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
84182 + input = build_tree_list(NULL_TREE, build_string(2, "0"));
84183 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
84184 + output = build_tree_list(NULL_TREE, build_string(3, "=r"));
84185 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
84186 + VEC_safe_push(tree, gc, inputs, input);
84187 + VEC_safe_push(tree, gc, outputs, output);
84188 + asm_or_stmt = gimple_build_asm_vec("orq %%r10, %0\n\t", inputs, outputs, NULL, NULL);
84189 + gimple_asm_set_volatile(asm_or_stmt, true);
84190 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
84191 + update_stmt(asm_or_stmt);
84192 +
84193 + // replace call stmt fn with the new fptr
84194 + gimple_call_set_fn(call_stmt, new_fptr);
84195 + update_stmt(call_stmt);
84196 +}
84197 +
84198 +/*
84199 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
84200 + */
84201 +static unsigned int execute_kernexec_fptr(void)
84202 +{
84203 + basic_block bb;
84204 +
84205 + // 1. loop through BBs and GIMPLE statements
84206 + FOR_EACH_BB(bb) {
84207 + gimple_stmt_iterator gsi;
84208 +
84209 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
84210 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
84211 + tree fn;
84212 + gimple call_stmt;
84213 +
84214 + // is it a call ...
84215 + call_stmt = gsi_stmt(gsi);
84216 + if (!is_gimple_call(call_stmt))
84217 + continue;
84218 + fn = gimple_call_fn(call_stmt);
84219 + if (TREE_CODE(fn) == ADDR_EXPR)
84220 + continue;
84221 + if (TREE_CODE(fn) != SSA_NAME)
84222 + gcc_unreachable();
84223 +
84224 + // ... through a function pointer
84225 + fn = SSA_NAME_VAR(fn);
84226 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL)
84227 + continue;
84228 + fn = TREE_TYPE(fn);
84229 + if (TREE_CODE(fn) != POINTER_TYPE)
84230 + continue;
84231 + fn = TREE_TYPE(fn);
84232 + if (TREE_CODE(fn) != FUNCTION_TYPE)
84233 + continue;
84234 +
84235 + kernexec_instrument_fptr(&gsi);
84236 +
84237 +//debug_tree(gimple_call_fn(call_stmt));
84238 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
84239 + }
84240 + }
84241 +
84242 + return 0;
84243 +}
84244 +
84245 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
84246 +static void kernexec_instrument_retaddr_bts(rtx insn)
84247 +{
84248 + rtx btsq;
84249 + rtvec argvec, constraintvec, labelvec;
84250 + int line;
84251 +
84252 + // create asm volatile("btsq $63,(%%rsp)":::)
84253 + argvec = rtvec_alloc(0);
84254 + constraintvec = rtvec_alloc(0);
84255 + labelvec = rtvec_alloc(0);
84256 + line = expand_location(RTL_LOCATION(insn)).line;
84257 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
84258 + MEM_VOLATILE_P(btsq) = 1;
84259 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
84260 + emit_insn_before(btsq, insn);
84261 +}
84262 +
84263 +// add special KERNEXEC instrumentation: orq %r10,(%rsp) just before retn
84264 +static void kernexec_instrument_retaddr_or(rtx insn)
84265 +{
84266 + rtx orq;
84267 + rtvec argvec, constraintvec, labelvec;
84268 + int line;
84269 +
84270 + // create asm volatile("orq %%r10,(%%rsp)":::)
84271 + argvec = rtvec_alloc(0);
84272 + constraintvec = rtvec_alloc(0);
84273 + labelvec = rtvec_alloc(0);
84274 + line = expand_location(RTL_LOCATION(insn)).line;
84275 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r10,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
84276 + MEM_VOLATILE_P(orq) = 1;
84277 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
84278 + emit_insn_before(orq, insn);
84279 +}
84280 +
84281 +/*
84282 + * find all asm level function returns and forcibly set the highest bit of the return address
84283 + */
84284 +static unsigned int execute_kernexec_retaddr(void)
84285 +{
84286 + rtx insn;
84287 +
84288 + // 1. find function returns
84289 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
84290 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
84291 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
84292 + // (jump_insn 97 96 98 6 (simple_return) fptr.c:50 -1 (nil) -> simple_return)
84293 + rtx body;
84294 +
84295 + // is it a retn
84296 + if (!JUMP_P(insn))
84297 + continue;
84298 + body = PATTERN(insn);
84299 + if (GET_CODE(body) == PARALLEL)
84300 + body = XVECEXP(body, 0, 0);
84301 + if (!ANY_RETURN_P(body))
84302 + continue;
84303 + kernexec_instrument_retaddr(insn);
84304 + }
84305 +
84306 +// print_simple_rtl(stderr, get_insns());
84307 +// print_rtl(stderr, get_insns());
84308 +
84309 + return 0;
84310 +}
84311 +
84312 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
84313 +{
84314 + const char * const plugin_name = plugin_info->base_name;
84315 + const int argc = plugin_info->argc;
84316 + const struct plugin_argument * const argv = plugin_info->argv;
84317 + int i;
84318 + struct register_pass_info kernexec_reload_pass_info = {
84319 + .pass = &kernexec_reload_pass.pass,
84320 + .reference_pass_name = "ssa",
84321 + .ref_pass_instance_number = 1,
84322 + .pos_op = PASS_POS_INSERT_AFTER
84323 + };
84324 + struct register_pass_info kernexec_fptr_pass_info = {
84325 + .pass = &kernexec_fptr_pass.pass,
84326 + .reference_pass_name = "ssa",
84327 + .ref_pass_instance_number = 1,
84328 + .pos_op = PASS_POS_INSERT_AFTER
84329 + };
84330 + struct register_pass_info kernexec_retaddr_pass_info = {
84331 + .pass = &kernexec_retaddr_pass.pass,
84332 + .reference_pass_name = "pro_and_epilogue",
84333 + .ref_pass_instance_number = 1,
84334 + .pos_op = PASS_POS_INSERT_AFTER
84335 + };
84336 +
84337 + if (!plugin_default_version_check(version, &gcc_version)) {
84338 + error(G_("incompatible gcc/plugin versions"));
84339 + return 1;
84340 + }
84341 +
84342 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
84343 +
84344 + if (TARGET_64BIT == 0)
84345 + return 0;
84346 +
84347 + for (i = 0; i < argc; ++i) {
84348 + if (!strcmp(argv[i].key, "method")) {
84349 + if (!argv[i].value) {
84350 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
84351 + continue;
84352 + }
84353 + if (!strcmp(argv[i].value, "bts")) {
84354 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
84355 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
84356 + } else if (!strcmp(argv[i].value, "or")) {
84357 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
84358 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
84359 + fix_register("r10", 1, 1);
84360 + } else
84361 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
84362 + continue;
84363 + }
84364 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
84365 + }
84366 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
84367 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
84368 +
84369 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
84370 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
84371 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
84372 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
84373 +
84374 + return 0;
84375 +}
84376 diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
84377 new file mode 100644
84378 index 0000000..b8008f7
84379 --- /dev/null
84380 +++ b/tools/gcc/latent_entropy_plugin.c
84381 @@ -0,0 +1,295 @@
84382 +/*
84383 + * Copyright 2012 by the PaX Team <pageexec@freemail.hu>
84384 + * Licensed under the GPL v2
84385 + *
84386 + * Note: the choice of the license means that the compilation process is
84387 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
84388 + * but for the kernel it doesn't matter since it doesn't link against
84389 + * any of the gcc libraries
84390 + *
84391 + * gcc plugin to help generate a little bit of entropy from program state,
84392 + * used during boot in the kernel
84393 + *
84394 + * TODO:
84395 + * - add ipa pass to identify not explicitly marked candidate functions
84396 + * - mix in more program state (function arguments/return values, loop variables, etc)
84397 + * - more instrumentation control via attribute parameters
84398 + *
84399 + * BUGS:
84400 + * - LTO needs -flto-partition=none for now
84401 + */
84402 +#include "gcc-plugin.h"
84403 +#include "config.h"
84404 +#include "system.h"
84405 +#include "coretypes.h"
84406 +#include "tree.h"
84407 +#include "tree-pass.h"
84408 +#include "flags.h"
84409 +#include "intl.h"
84410 +#include "toplev.h"
84411 +#include "plugin.h"
84412 +//#include "expr.h" where are you...
84413 +#include "diagnostic.h"
84414 +#include "plugin-version.h"
84415 +#include "tm.h"
84416 +#include "function.h"
84417 +#include "basic-block.h"
84418 +#include "gimple.h"
84419 +#include "rtl.h"
84420 +#include "emit-rtl.h"
84421 +#include "tree-flow.h"
84422 +
84423 +int plugin_is_GPL_compatible;
84424 +
84425 +static tree latent_entropy_decl;
84426 +
84427 +static struct plugin_info latent_entropy_plugin_info = {
84428 + .version = "201207271820",
84429 + .help = NULL
84430 +};
84431 +
84432 +static unsigned int execute_latent_entropy(void);
84433 +static bool gate_latent_entropy(void);
84434 +
84435 +static struct gimple_opt_pass latent_entropy_pass = {
84436 + .pass = {
84437 + .type = GIMPLE_PASS,
84438 + .name = "latent_entropy",
84439 + .gate = gate_latent_entropy,
84440 + .execute = execute_latent_entropy,
84441 + .sub = NULL,
84442 + .next = NULL,
84443 + .static_pass_number = 0,
84444 + .tv_id = TV_NONE,
84445 + .properties_required = PROP_gimple_leh | PROP_cfg,
84446 + .properties_provided = 0,
84447 + .properties_destroyed = 0,
84448 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
84449 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
84450 + }
84451 +};
84452 +
84453 +static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
84454 +{
84455 + if (TREE_CODE(*node) != FUNCTION_DECL) {
84456 + *no_add_attrs = true;
84457 + error("%qE attribute only applies to functions", name);
84458 + }
84459 + return NULL_TREE;
84460 +}
84461 +
84462 +static struct attribute_spec latent_entropy_attr = {
84463 + .name = "latent_entropy",
84464 + .min_length = 0,
84465 + .max_length = 0,
84466 + .decl_required = true,
84467 + .type_required = false,
84468 + .function_type_required = false,
84469 + .handler = handle_latent_entropy_attribute,
84470 +#if BUILDING_GCC_VERSION >= 4007
84471 + .affects_type_identity = false
84472 +#endif
84473 +};
84474 +
84475 +static void register_attributes(void *event_data, void *data)
84476 +{
84477 + register_attribute(&latent_entropy_attr);
84478 +}
84479 +
84480 +static bool gate_latent_entropy(void)
84481 +{
84482 + tree latent_entropy_attr;
84483 +
84484 + latent_entropy_attr = lookup_attribute("latent_entropy", DECL_ATTRIBUTES(current_function_decl));
84485 + return latent_entropy_attr != NULL_TREE;
84486 +}
84487 +
84488 +static unsigned HOST_WIDE_INT seed;
84489 +static unsigned HOST_WIDE_INT get_random_const(void)
84490 +{
84491 + seed = (seed >> 1U) ^ (-(seed & 1ULL) & 0xD800000000000000ULL);
84492 + return seed;
84493 +}
84494 +
84495 +static enum tree_code get_op(tree *rhs)
84496 +{
84497 + static enum tree_code op;
84498 + unsigned HOST_WIDE_INT random_const;
84499 +
84500 + random_const = get_random_const();
84501 +
84502 + switch (op) {
84503 + case BIT_XOR_EXPR:
84504 + op = PLUS_EXPR;
84505 + break;
84506 +
84507 + case PLUS_EXPR:
84508 + if (rhs) {
84509 + op = LROTATE_EXPR;
84510 + random_const &= HOST_BITS_PER_WIDE_INT - 1;
84511 + break;
84512 + }
84513 +
84514 + case LROTATE_EXPR:
84515 + default:
84516 + op = BIT_XOR_EXPR;
84517 + break;
84518 + }
84519 + if (rhs)
84520 + *rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
84521 + return op;
84522 +}
84523 +
84524 +static void perturb_local_entropy(basic_block bb, tree local_entropy)
84525 +{
84526 + gimple_stmt_iterator gsi;
84527 + gimple assign;
84528 + tree addxorrol, rhs;
84529 + enum tree_code op;
84530 +
84531 + op = get_op(&rhs);
84532 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, op, unsigned_intDI_type_node, local_entropy, rhs);
84533 + assign = gimple_build_assign(local_entropy, addxorrol);
84534 + find_referenced_vars_in(assign);
84535 +//debug_bb(bb);
84536 + gsi = gsi_after_labels(bb);
84537 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
84538 + update_stmt(assign);
84539 +}
84540 +
84541 +static void perturb_latent_entropy(basic_block bb, tree rhs)
84542 +{
84543 + gimple_stmt_iterator gsi;
84544 + gimple assign;
84545 + tree addxorrol, temp;
84546 +
84547 + // 1. create temporary copy of latent_entropy
84548 + temp = create_tmp_var(unsigned_intDI_type_node, "temp_latent_entropy");
84549 + add_referenced_var(temp);
84550 + mark_sym_for_renaming(temp);
84551 +
84552 + // 2. read...
84553 + assign = gimple_build_assign(temp, latent_entropy_decl);
84554 + find_referenced_vars_in(assign);
84555 + gsi = gsi_after_labels(bb);
84556 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
84557 + update_stmt(assign);
84558 +
84559 + // 3. ...modify...
84560 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, get_op(NULL), unsigned_intDI_type_node, temp, rhs);
84561 + assign = gimple_build_assign(temp, addxorrol);
84562 + find_referenced_vars_in(assign);
84563 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
84564 + update_stmt(assign);
84565 +
84566 + // 4. ...write latent_entropy
84567 + assign = gimple_build_assign(latent_entropy_decl, temp);
84568 + find_referenced_vars_in(assign);
84569 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
84570 + update_stmt(assign);
84571 +}
84572 +
84573 +static unsigned int execute_latent_entropy(void)
84574 +{
84575 + basic_block bb;
84576 + gimple assign;
84577 + gimple_stmt_iterator gsi;
84578 + tree local_entropy;
84579 +
84580 + if (!latent_entropy_decl) {
84581 + struct varpool_node *node;
84582 +
84583 + for (node = varpool_nodes; node; node = node->next) {
84584 + tree var = node->decl;
84585 + if (strcmp(IDENTIFIER_POINTER(DECL_NAME(var)), "latent_entropy"))
84586 + continue;
84587 + latent_entropy_decl = var;
84588 +// debug_tree(var);
84589 + break;
84590 + }
84591 + if (!latent_entropy_decl) {
84592 +// debug_tree(current_function_decl);
84593 + return 0;
84594 + }
84595 + }
84596 +
84597 +//fprintf(stderr, "latent_entropy: %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
84598 +
84599 + // 1. create local entropy variable
84600 + local_entropy = create_tmp_var(unsigned_intDI_type_node, "local_entropy");
84601 + add_referenced_var(local_entropy);
84602 + mark_sym_for_renaming(local_entropy);
84603 +
84604 + // 2. initialize local entropy variable
84605 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
84606 + if (dom_info_available_p(CDI_DOMINATORS))
84607 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
84608 + gsi = gsi_start_bb(bb);
84609 +
84610 + assign = gimple_build_assign(local_entropy, build_int_cstu(unsigned_intDI_type_node, get_random_const()));
84611 +// gimple_set_location(assign, loc);
84612 + find_referenced_vars_in(assign);
84613 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
84614 + update_stmt(assign);
84615 + bb = bb->next_bb;
84616 +
84617 + // 3. instrument each BB with an operation on the local entropy variable
84618 + while (bb != EXIT_BLOCK_PTR) {
84619 + perturb_local_entropy(bb, local_entropy);
84620 + bb = bb->next_bb;
84621 + };
84622 +
84623 + // 4. mix local entropy into the global entropy variable
84624 + perturb_latent_entropy(EXIT_BLOCK_PTR->prev_bb, local_entropy);
84625 + return 0;
84626 +}
84627 +
84628 +static void start_unit_callback(void *gcc_data, void *user_data)
84629 +{
84630 +#if BUILDING_GCC_VERSION >= 4007
84631 + seed = get_random_seed(false);
84632 +#else
84633 + sscanf(get_random_seed(false), "%" HOST_WIDE_INT_PRINT "x", &seed);
84634 + seed *= seed;
84635 +#endif
84636 +
84637 + if (in_lto_p)
84638 + return;
84639 +
84640 + // extern u64 latent_entropy
84641 + latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("latent_entropy"), unsigned_intDI_type_node);
84642 +
84643 + TREE_STATIC(latent_entropy_decl) = 1;
84644 + TREE_PUBLIC(latent_entropy_decl) = 1;
84645 + TREE_USED(latent_entropy_decl) = 1;
84646 + TREE_THIS_VOLATILE(latent_entropy_decl) = 1;
84647 + DECL_EXTERNAL(latent_entropy_decl) = 1;
84648 + DECL_ARTIFICIAL(latent_entropy_decl) = 0;
84649 + DECL_INITIAL(latent_entropy_decl) = NULL;
84650 +// DECL_ASSEMBLER_NAME(latent_entropy_decl);
84651 +// varpool_finalize_decl(latent_entropy_decl);
84652 +// varpool_mark_needed_node(latent_entropy_decl);
84653 +}
84654 +
84655 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
84656 +{
84657 + const char * const plugin_name = plugin_info->base_name;
84658 + struct register_pass_info latent_entropy_pass_info = {
84659 + .pass = &latent_entropy_pass.pass,
84660 + .reference_pass_name = "optimized",
84661 + .ref_pass_instance_number = 1,
84662 + .pos_op = PASS_POS_INSERT_BEFORE
84663 + };
84664 +
84665 + if (!plugin_default_version_check(version, &gcc_version)) {
84666 + error(G_("incompatible gcc/plugin versions"));
84667 + return 1;
84668 + }
84669 +
84670 + register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
84671 + register_callback ("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
84672 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
84673 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
84674 +
84675 + return 0;
84676 +}
84677 diff --git a/tools/gcc/size_overflow_hash.data b/tools/gcc/size_overflow_hash.data
84678 new file mode 100644
84679 index 0000000..67468e3
84680 --- /dev/null
84681 +++ b/tools/gcc/size_overflow_hash.data
84682 @@ -0,0 +1,3600 @@
84683 +_000001_hash alloc_dr 2 65495 _000001_hash NULL
84684 +_000002_hash __copy_from_user 3 10918 _000002_hash NULL
84685 +_000003_hash copy_from_user 3 17559 _000003_hash NULL
84686 +_000004_hash __copy_from_user_inatomic 3 4365 _000004_hash NULL
84687 +_000005_hash __copy_from_user_nocache 3 39351 _000005_hash NULL
84688 +_000006_hash __copy_to_user_inatomic 3 19214 _000006_hash NULL
84689 +_000007_hash do_xip_mapping_read 5 60297 _000007_hash NULL
84690 +_000008_hash hugetlbfs_read 3 11268 _000008_hash NULL
84691 +_000009_hash kmalloc 1 60432 _003302_hash NULL nohasharray
84692 +_000010_hash kmalloc_array 1-2 9444 _000010_hash NULL
84693 +_000012_hash __kmalloc_reserve 1 17080 _000012_hash NULL
84694 +_000013_hash kmalloc_slab 1 11917 _000013_hash NULL
84695 +_000014_hash kmemdup 2 64015 _000014_hash NULL
84696 +_000015_hash __krealloc 2 14857 _000340_hash NULL nohasharray
84697 +_000016_hash memdup_user 2 59590 _000016_hash NULL
84698 +_000017_hash module_alloc 1 63630 _000017_hash NULL
84699 +_000018_hash read_default_ldt 2 14302 _000018_hash NULL
84700 +_000019_hash read_kcore 3 63488 _000019_hash NULL
84701 +_000020_hash read_ldt 2 47570 _000020_hash NULL
84702 +_000021_hash read_zero 3 19366 _000021_hash NULL
84703 +_000022_hash __vmalloc_node 1 39308 _000022_hash NULL
84704 +_000023_hash aac_convert_sgraw2 4 51598 _000023_hash NULL
84705 +_000024_hash aa_simple_write_to_buffer 4-3 49683 _000024_hash NULL
84706 +_000025_hash ablkcipher_copy_iv 3 64140 _000025_hash NULL
84707 +_000026_hash ablkcipher_next_slow 3-4 47274 _000026_hash NULL
84708 +_000028_hash acpi_battery_write_alarm 3 1240 _000028_hash NULL
84709 +_000029_hash acpi_os_allocate 1 14892 _000029_hash NULL
84710 +_000030_hash acpi_system_write_wakeup_device 3 34853 _000030_hash NULL
84711 +_000031_hash adu_write 3 30487 _000031_hash NULL
84712 +_000032_hash aer_inject_write 3 52399 _000032_hash NULL
84713 +_000033_hash afs_alloc_flat_call 2-3 36399 _000033_hash NULL
84714 +_000035_hash afs_proc_cells_write 3 61139 _000035_hash NULL
84715 +_000036_hash afs_proc_rootcell_write 3 15822 _000036_hash NULL
84716 +_000037_hash agp_3_5_isochronous_node_enable 3 49465 _000037_hash NULL
84717 +_000038_hash agp_alloc_page_array 1 22554 _000038_hash NULL
84718 +_000039_hash ah_alloc_tmp 2-3 54378 _000039_hash NULL
84719 +_000041_hash ahash_setkey_unaligned 3 33521 _000041_hash NULL
84720 +_000042_hash alg_setkey 3 31485 _000042_hash NULL
84721 +_000043_hash aligned_kmalloc 1 3628 _000043_hash NULL
84722 +_000044_hash alloc_context 1 3194 _000044_hash NULL
84723 +_000045_hash alloc_ep_req 2 54860 _000045_hash NULL
84724 +_000046_hash alloc_fdmem 1 27083 _000046_hash NULL
84725 +_000047_hash alloc_flex_gd 1 57259 _000047_hash NULL
84726 +_000048_hash alloc_sglist 1-3-2 22960 _000048_hash NULL
84727 +_000049_hash __alloc_skb 1 23940 _000049_hash NULL
84728 +_000050_hash aoedev_flush 2 44398 _000050_hash NULL
84729 +_000051_hash append_to_buffer 3 63550 _000051_hash NULL
84730 +_000052_hash asix_read_cmd 5 13245 _000052_hash NULL
84731 +_000053_hash asix_write_cmd 5 58192 _000053_hash NULL
84732 +_000054_hash at76_set_card_command 4 4471 _000054_hash NULL
84733 +_000055_hash ath6kl_add_bss_if_needed 6 24317 _000055_hash NULL
84734 +_000056_hash ath6kl_debug_roam_tbl_event 3 5224 _000056_hash NULL
84735 +_000057_hash ath6kl_mgmt_powersave_ap 6 13791 _000057_hash NULL
84736 +_000058_hash ath6kl_send_go_probe_resp 3 21113 _000058_hash NULL
84737 +_000059_hash ath6kl_set_ap_probe_resp_ies 3 50539 _000059_hash NULL
84738 +_000060_hash ath6kl_set_assoc_req_ies 3 43185 _000060_hash NULL
84739 +_000061_hash ath6kl_wmi_bssinfo_event_rx 3 2275 _000061_hash NULL
84740 +_000062_hash ath6kl_wmi_send_action_cmd 7 58860 _000062_hash NULL
84741 +_000063_hash __ath6kl_wmi_send_mgmt_cmd 7 38971 _000063_hash NULL
84742 +_000064_hash attach_hdlc_protocol 3 19986 _000064_hash NULL
84743 +_000065_hash audio_write 4 54261 _001782_hash NULL nohasharray
84744 +_000066_hash audit_unpack_string 3 13748 _000066_hash NULL
84745 +_000067_hash ax25_setsockopt 5 42740 _000067_hash NULL
84746 +_000068_hash b43_debugfs_write 3 34838 _000068_hash NULL
84747 +_000069_hash b43legacy_debugfs_write 3 28556 _000069_hash NULL
84748 +_000070_hash batadv_hash_new 1 40491 _000070_hash NULL
84749 +_000071_hash batadv_orig_node_add_if 2 18433 _000071_hash NULL
84750 +_000072_hash batadv_orig_node_del_if 2 4 _000072_hash NULL
84751 +_000073_hash batadv_tt_changes_fill_buff 4 40323 _000073_hash NULL
84752 +_000074_hash batadv_tt_realloc_packet_buff 4 49960 _000074_hash NULL
84753 +_000075_hash bch_alloc 1 4593 _000075_hash NULL
84754 +_000076_hash befs_nls2utf 3 17163 _000076_hash NULL
84755 +_000077_hash befs_utf2nls 3 25628 _000077_hash NULL
84756 +_000078_hash bfad_debugfs_write_regrd 3 15218 _000078_hash NULL
84757 +_000079_hash bfad_debugfs_write_regwr 3 61841 _000079_hash NULL
84758 +_000080_hash bio_alloc_map_data 1-2 50782 _000080_hash NULL
84759 +_000082_hash bio_kmalloc 2 54672 _000082_hash NULL
84760 +_000083_hash bitmap_storage_alloc 2 55077 _000083_hash NULL
84761 +_000084_hash blkcipher_copy_iv 3 24075 _000084_hash NULL
84762 +_000085_hash blkcipher_next_slow 3-4 52733 _000085_hash NULL
84763 +_000087_hash bl_pipe_downcall 3 34264 _000087_hash NULL
84764 +_000088_hash bnad_debugfs_write_regrd 3 6706 _000088_hash NULL
84765 +_000089_hash bnad_debugfs_write_regwr 3 57500 _000089_hash NULL
84766 +_000090_hash bnx2fc_cmd_mgr_alloc 2-3 24873 _000090_hash NULL
84767 +_000092_hash bnx2fc_process_unsol_compl 2 15576 _000092_hash NULL
84768 +_000093_hash bnx2_nvram_write 2-4 7790 _000093_hash NULL
84769 +_000095_hash btmrvl_gpiogap_write 3 35053 _000095_hash NULL
84770 +_000096_hash btmrvl_hscfgcmd_write 3 27143 _000096_hash NULL
84771 +_000097_hash btmrvl_hscmd_write 3 27089 _000097_hash NULL
84772 +_000098_hash btmrvl_hsmode_write 3 42252 _000098_hash NULL
84773 +_000099_hash btmrvl_pscmd_write 3 29504 _000099_hash NULL
84774 +_000100_hash btmrvl_psmode_write 3 3703 _000100_hash NULL
84775 +_000101_hash btrfs_alloc_delayed_item 1 11678 _000101_hash NULL
84776 +_000102_hash c4iw_id_table_alloc 3 48163 _000102_hash NULL
84777 +_000103_hash cache_do_downcall 3 6926 _000103_hash NULL
84778 +_000104_hash cachefiles_cook_key 2 33274 _000104_hash NULL
84779 +_000105_hash cachefiles_daemon_write 3 43535 _000105_hash NULL
84780 +_000106_hash capi_write 3 35104 _003607_hash NULL nohasharray
84781 +_000107_hash carl9170_debugfs_write 3 50857 _000107_hash NULL
84782 +_000108_hash cciss_allocate_sg_chain_blocks 2-3 5368 _000108_hash NULL
84783 +_000110_hash cciss_proc_write 3 10259 _000110_hash NULL
84784 +_000111_hash cdrom_read_cdda_old 4 27664 _000111_hash NULL
84785 +_000112_hash ceph_alloc_page_vector 1 18710 _000112_hash NULL
84786 +_000113_hash ceph_buffer_new 1 35974 _000113_hash NULL
84787 +_000114_hash ceph_copy_user_to_page_vector 3-4 656 _000114_hash NULL
84788 +_000116_hash ceph_get_direct_page_vector 2 41917 _000116_hash NULL
84789 +_000117_hash ceph_msg_new 2 5846 _000117_hash NULL
84790 +_000118_hash ceph_setxattr 4 18913 _000118_hash NULL
84791 +_000119_hash cfi_read_pri 3 24366 _000119_hash NULL
84792 +_000120_hash cgroup_write_string 5 10900 _000120_hash NULL
84793 +_000121_hash cgroup_write_X64 5 54514 _000121_hash NULL
84794 +_000122_hash change_xattr 5 61390 _000122_hash NULL
84795 +_000123_hash check_load_and_stores 2 2143 _000123_hash NULL
84796 +_000124_hash cifs_idmap_key_instantiate 3 54503 _000124_hash NULL
84797 +_000125_hash cifs_security_flags_proc_write 3 5484 _000125_hash NULL
84798 +_000126_hash cifs_setxattr 4 23957 _000126_hash NULL
84799 +_000127_hash cifs_spnego_key_instantiate 3 23588 _000127_hash NULL
84800 +_000128_hash cld_pipe_downcall 3 15058 _000128_hash NULL
84801 +_000129_hash clear_refs_write 3 61904 _000129_hash NULL
84802 +_000130_hash clusterip_proc_write 3 44729 _000130_hash NULL
84803 +_000131_hash cm4040_write 3 58079 _000131_hash NULL
84804 +_000132_hash cm_copy_private_data 2 3649 _000132_hash NULL
84805 +_000133_hash cmm_write 3 2896 _000133_hash NULL
84806 +_000134_hash cm_write 3 36858 _000134_hash NULL
84807 +_000135_hash coda_psdev_write 3 1711 _000135_hash NULL
84808 +_000136_hash codec_reg_read_file 3 36280 _000136_hash NULL
84809 +_000137_hash command_file_write 3 31318 _000137_hash NULL
84810 +_000138_hash command_write 3 58841 _000138_hash NULL
84811 +_000139_hash comm_write 3 44537 _001714_hash NULL nohasharray
84812 +_000140_hash concat_writev 3 21451 _000140_hash NULL
84813 +_000141_hash copy_and_check 3 19089 _000141_hash NULL
84814 +_000142_hash copy_from_user_toio 3 31966 _000142_hash NULL
84815 +_000143_hash copy_items 6 50140 _000143_hash NULL
84816 +_000144_hash copy_macs 4 45534 _000144_hash NULL
84817 +_000145_hash __copy_to_user 3 17551 _000145_hash NULL
84818 +_000146_hash copy_vm86_regs_from_user 3 45340 _000146_hash NULL
84819 +_000147_hash core_sys_select 1 47494 _000147_hash NULL
84820 +_000148_hash cosa_write 3 1774 _000148_hash NULL
84821 +_000149_hash cp210x_set_config 4 46447 _000149_hash NULL
84822 +_000150_hash create_entry 2 33479 _000150_hash NULL
84823 +_000151_hash create_queues 2-3 9088 _000151_hash NULL
84824 +_000153_hash create_xattr 5 54106 _000153_hash NULL
84825 +_000154_hash create_xattr_datum 5 33356 _003443_hash NULL nohasharray
84826 +_000155_hash csum_partial_copy_fromiovecend 3-4 9957 _000155_hash NULL
84827 +_000157_hash ctrl_out 3-5 8712 _000157_hash NULL
84828 +_000159_hash cxacru_cm_get_array 4 4412 _000159_hash NULL
84829 +_000160_hash cxgbi_alloc_big_mem 1 4707 _000160_hash NULL
84830 +_000161_hash dac960_user_command_proc_write 3 3071 _000161_hash NULL
84831 +_000162_hash datablob_format 2 39571 _002490_hash NULL nohasharray
84832 +_000163_hash dccp_feat_clone_sp_val 3 11942 _000163_hash NULL
84833 +_000164_hash dccp_setsockopt_ccid 4 30701 _000164_hash NULL
84834 +_000165_hash dccp_setsockopt_cscov 2 37766 _000165_hash NULL
84835 +_000166_hash dccp_setsockopt_service 4 65336 _000166_hash NULL
84836 +_000167_hash ddebug_proc_write 3 18055 _000167_hash NULL
84837 +_000168_hash dev_config 3 8506 _000168_hash NULL
84838 +_000169_hash device_write 3 45156 _000169_hash NULL
84839 +_000170_hash devm_kzalloc 2 4966 _000170_hash NULL
84840 +_000171_hash devres_alloc 2 551 _000171_hash NULL
84841 +_000172_hash dfs_file_write 3 41196 _000172_hash NULL
84842 +_000173_hash direct_entry 3 38836 _000173_hash NULL
84843 +_000174_hash dispatch_ioctl 2 32357 _000174_hash NULL
84844 +_000175_hash dispatch_proc_write 3 44320 _000175_hash NULL
84845 +_000176_hash diva_os_copy_from_user 4 7792 _000176_hash NULL
84846 +_000177_hash dlm_alloc_pagevec 1 54296 _000177_hash NULL
84847 +_000178_hash dlmfs_file_read 3 28385 _000178_hash NULL
84848 +_000179_hash dlmfs_file_write 3 6892 _000179_hash NULL
84849 +_000180_hash dm_read 3 15674 _000180_hash NULL
84850 +_000181_hash dm_write 3 2513 _000181_hash NULL
84851 +_000182_hash __dn_setsockopt 5 13060 _000182_hash NULL
84852 +_000183_hash dns_query 3 9676 _000183_hash NULL
84853 +_000184_hash dns_resolver_instantiate 3 63314 _000184_hash NULL
84854 +_000185_hash do_add_counters 3 3992 _000185_hash NULL
84855 +_000186_hash __do_config_autodelink 3 58763 _000186_hash NULL
84856 +_000187_hash do_ip_setsockopt 5 41852 _000187_hash NULL
84857 +_000188_hash do_ipv6_setsockopt 5 18215 _000188_hash NULL
84858 +_000189_hash do_ip_vs_set_ctl 4 48641 _000189_hash NULL
84859 +_000190_hash do_kimage_alloc 3 64827 _000190_hash NULL
84860 +_000191_hash do_register_entry 4 29478 _000191_hash NULL
84861 +_000192_hash do_tty_write 5 44896 _000192_hash NULL
84862 +_000193_hash do_update_counters 4 2259 _000193_hash NULL
84863 +_000194_hash dsp_write 2 46218 _000194_hash NULL
84864 +_000195_hash dup_to_netobj 3 26363 _000195_hash NULL
84865 +_000196_hash dwc3_link_state_write 3 12641 _000196_hash NULL
84866 +_000197_hash dwc3_mode_write 3 51997 _000197_hash NULL
84867 +_000198_hash dwc3_testmode_write 3 30516 _000198_hash NULL
84868 +_000199_hash ecryptfs_copy_filename 4 11868 _000199_hash NULL
84869 +_000200_hash ecryptfs_miscdev_write 3 26847 _000200_hash NULL
84870 +_000201_hash ecryptfs_send_miscdev 2 64816 _000201_hash NULL
84871 +_000202_hash efx_tsoh_heap_alloc 2 58545 _000202_hash NULL
84872 +_000203_hash emi26_writememory 4 57908 _000203_hash NULL
84873 +_000204_hash emi62_writememory 4 29731 _000204_hash NULL
84874 +_000205_hash encrypted_instantiate 3 3168 _000205_hash NULL
84875 +_000206_hash encrypted_update 3 13414 _000206_hash NULL
84876 +_000207_hash ep0_write 3 14536 _001422_hash NULL nohasharray
84877 +_000208_hash ep_read 3 58813 _000208_hash NULL
84878 +_000209_hash ep_write 3 59008 _000209_hash NULL
84879 +_000210_hash erst_dbg_write 3 46715 _000210_hash NULL
84880 +_000211_hash esp_alloc_tmp 2-3 40558 _000211_hash NULL
84881 +_000213_hash evdev_do_ioctl 2 24459 _000213_hash NULL
84882 +_000214_hash exofs_read_lookup_dev_table 3 17733 _000214_hash NULL
84883 +_000215_hash ext4_kvmalloc 1 14796 _000215_hash NULL
84884 +_000216_hash ezusb_writememory 4 45976 _000216_hash NULL
84885 +_000217_hash fanotify_write 3 64623 _000217_hash NULL
84886 +_000218_hash fd_copyin 3 56247 _000218_hash NULL
84887 +_000219_hash ffs_epfile_io 3 64886 _000219_hash NULL
84888 +_000220_hash ffs_prepare_buffer 2 59892 _000220_hash NULL
84889 +_000221_hash f_hidg_write 3 7932 _000221_hash NULL
84890 +_000222_hash file_read_actor 4 1401 _000222_hash NULL
84891 +_000223_hash fill_write_buffer 3 3142 _000223_hash NULL
84892 +_000224_hash __find_xattr 6 2117 _002425_hash NULL nohasharray
84893 +_000225_hash fl_create 5 56435 _000225_hash NULL
84894 +_000226_hash fs_path_ensure_buf 2 59445 _000226_hash NULL
84895 +_000227_hash ftdi_elan_write 3 57309 _000227_hash NULL
84896 +_000228_hash fw_iso_buffer_alloc 2 13704 _000228_hash NULL
84897 +_000229_hash garmin_write_bulk 3 58191 _000229_hash NULL
84898 +_000230_hash garp_attr_create 3 3883 _000230_hash NULL
84899 +_000231_hash get_arg 3 5694 _000231_hash NULL
84900 +_000232_hash getdqbuf 1 62908 _000232_hash NULL
84901 +_000233_hash get_fdb_entries 3 41916 _000233_hash NULL
84902 +_000234_hash get_fd_set 1 3866 _000234_hash NULL
84903 +_000235_hash get_indirect_ea 4 51869 _000235_hash NULL
84904 +_000236_hash get_registers 3 26187 _000236_hash NULL
84905 +_000237_hash get_scq 2 10897 _000237_hash NULL
84906 +_000238_hash get_server_iovec 2 16804 _000238_hash NULL
84907 +_000239_hash get_ucode_user 3 38202 _000239_hash NULL
84908 +_000240_hash get_user_cpu_mask 2 14861 _000240_hash NULL
84909 +_000241_hash gfs2_alloc_sort_buffer 1 18275 _000241_hash NULL
84910 +_000242_hash gfs2_glock_nq_m 1 20347 _000242_hash NULL
84911 +_000243_hash gigaset_initcs 2 43753 _000243_hash NULL
84912 +_000244_hash gigaset_initdriver 2 1060 _000244_hash NULL
84913 +_000245_hash groups_alloc 1 7614 _000245_hash NULL
84914 +_000246_hash gs_alloc_req 2 58883 _000246_hash NULL
84915 +_000247_hash gs_buf_alloc 2 25067 _000247_hash NULL
84916 +_000248_hash gsm_data_alloc 3 42437 _000248_hash NULL
84917 +_000249_hash gss_pipe_downcall 3 23182 _000249_hash NULL
84918 +_000250_hash handle_request 9 10024 _000250_hash NULL
84919 +_000251_hash hashtab_create 3 33769 _000251_hash NULL
84920 +_000252_hash hcd_buffer_alloc 2 27495 _000252_hash NULL
84921 +_000253_hash hci_sock_setsockopt 5 28993 _000253_hash NULL
84922 +_000254_hash heap_init 2 49617 _000254_hash NULL
84923 +_000255_hash hest_ghes_dev_register 1 46766 _000255_hash NULL
84924 +_000256_hash hidg_alloc_ep_req 2 10159 _000256_hash NULL
84925 +_000257_hash hid_parse_report 3 51737 _000257_hash NULL
84926 +_000258_hash hidraw_get_report 3 45609 _000258_hash NULL
84927 +_000259_hash hidraw_report_event 3 20503 _000259_hash NULL
84928 +_000260_hash hidraw_send_report 3 23449 _000260_hash NULL
84929 +_000261_hash hpfs_translate_name 3 41497 _000261_hash NULL
84930 +_000262_hash hysdn_conf_write 3 52145 _000262_hash NULL
84931 +_000263_hash __i2400mu_send_barker 3 23652 _000263_hash NULL
84932 +_000264_hash i2cdev_read 3 1206 _000264_hash NULL
84933 +_000265_hash i2cdev_write 3 23310 _000265_hash NULL
84934 +_000266_hash i2o_parm_field_get 5 34477 _000266_hash NULL
84935 +_000267_hash i2o_parm_table_get 6 61635 _000267_hash NULL
84936 +_000268_hash ib_copy_from_udata 3 59502 _000268_hash NULL
84937 +_000269_hash ib_ucm_alloc_data 3 36885 _000269_hash NULL
84938 +_000270_hash ib_umad_write 3 47993 _000270_hash NULL
84939 +_000271_hash ib_uverbs_unmarshall_recv 5 12251 _000271_hash NULL
84940 +_000272_hash icn_writecmd 2 38629 _000272_hash NULL
84941 +_000273_hash ide_driver_proc_write 3 32493 _000273_hash NULL
84942 +_000274_hash ide_settings_proc_write 3 35110 _000274_hash NULL
84943 +_000275_hash idetape_chrdev_write 3 53976 _000275_hash NULL
84944 +_000276_hash idmap_pipe_downcall 3 14591 _000276_hash NULL
84945 +_000277_hash ieee80211_build_probe_req 7-5 27660 _000277_hash NULL
84946 +_000278_hash ieee80211_if_write 3 34894 _000278_hash NULL
84947 +_000279_hash if_write 3 51756 _000279_hash NULL
84948 +_000280_hash ilo_write 3 64378 _000280_hash NULL
84949 +_000281_hash ima_write_policy 3 40548 _000281_hash NULL
84950 +_000282_hash init_data_container 1 60709 _000282_hash NULL
84951 +_000283_hash init_send_hfcd 1 34586 _000283_hash NULL
84952 +_000284_hash insert_dent 7 65034 _000284_hash NULL
84953 +_000285_hash interpret_user_input 2 19393 _000285_hash NULL
84954 +_000286_hash int_proc_write 3 39542 _000286_hash NULL
84955 +_000287_hash ioctl_private_iw_point 7 1273 _000287_hash NULL
84956 +_000288_hash iov_iter_copy_from_user 4 31942 _000288_hash NULL
84957 +_000289_hash iov_iter_copy_from_user_atomic 4 56368 _000289_hash NULL
84958 +_000290_hash iowarrior_write 3 18604 _000290_hash NULL
84959 +_000291_hash ipc_alloc 1 1192 _000291_hash NULL
84960 +_000292_hash ipc_rcu_alloc 1 21208 _000292_hash NULL
84961 +_000293_hash ip_options_get_from_user 4 64958 _000293_hash NULL
84962 +_000294_hash ipv6_renew_option 3 38813 _000294_hash NULL
84963 +_000295_hash ip_vs_conn_fill_param_sync 6 29771 _001898_hash NULL nohasharray
84964 +_000296_hash ip_vs_create_timeout_table 2 64478 _000296_hash NULL
84965 +_000297_hash ipw_queue_tx_init 3 49161 _000297_hash NULL
84966 +_000298_hash irda_setsockopt 5 19824 _000298_hash NULL
84967 +_000299_hash irias_new_octseq_value 2 13596 _003821_hash NULL nohasharray
84968 +_000300_hash irnet_ctrl_write 3 24139 _000300_hash NULL
84969 +_000301_hash isdn_add_channels 3 40905 _000301_hash NULL
84970 +_000302_hash isdn_ppp_fill_rq 2 41428 _000302_hash NULL
84971 +_000303_hash isdn_ppp_write 4 29109 _000303_hash NULL
84972 +_000304_hash isdn_read 3 50021 _000304_hash NULL
84973 +_000305_hash isdn_v110_open 3 2418 _000305_hash NULL
84974 +_000306_hash isdn_writebuf_stub 4 52383 _000306_hash NULL
84975 +_000307_hash islpci_mgt_transmit 5 34133 _000307_hash NULL
84976 +_000308_hash iso_callback 3 43208 _000308_hash NULL
84977 +_000309_hash iso_packets_buffer_init 3-4 29061 _000309_hash NULL
84978 +_000310_hash it821x_firmware_command 3 8628 _000310_hash NULL
84979 +_000311_hash iwch_alloc_fastreg_pbl 2 40153 _000311_hash NULL
84980 +_000312_hash iwl_calib_set 3 34400 _003754_hash NULL nohasharray
84981 +_000313_hash jbd2_journal_init_revoke_table 1 36336 _000313_hash NULL
84982 +_000314_hash jffs2_alloc_full_dirent 1 60179 _001158_hash NULL nohasharray
84983 +_000315_hash journal_init_revoke_table 1 56331 _000315_hash NULL
84984 +_000316_hash kcalloc 1-2 27770 _000316_hash NULL
84985 +_000318_hash keyctl_instantiate_key_common 4 47889 _000318_hash NULL
84986 +_000319_hash keyctl_update_key 3 26061 _000319_hash NULL
84987 +_000320_hash __kfifo_alloc 2-3 22173 _000320_hash NULL
84988 +_000322_hash kfifo_copy_from_user 3 5091 _000322_hash NULL
84989 +_000323_hash kmalloc_node 1 50163 _003818_hash NULL nohasharray
84990 +_000324_hash kmalloc_parameter 1 65279 _000324_hash NULL
84991 +_000325_hash kmem_alloc 1 31920 _000325_hash NULL
84992 +_000326_hash kobj_map 2-3 9566 _000326_hash NULL
84993 +_000328_hash kone_receive 4 4690 _000328_hash NULL
84994 +_000329_hash kone_send 4 63435 _000329_hash NULL
84995 +_000330_hash krealloc 2 14908 _000330_hash NULL
84996 +_000331_hash kvmalloc 1 32646 _000331_hash NULL
84997 +_000332_hash kvm_read_guest_atomic 4 10765 _000332_hash NULL
84998 +_000333_hash kvm_read_guest_cached 4 39666 _000333_hash NULL
84999 +_000334_hash kvm_read_guest_page 5 18074 _000334_hash NULL
85000 +_000335_hash kzalloc 1 54740 _000335_hash NULL
85001 +_000336_hash l2cap_sock_setsockopt 5 50207 _000336_hash NULL
85002 +_000337_hash l2cap_sock_setsockopt_old 4 29346 _000337_hash NULL
85003 +_000338_hash lane2_associate_req 4 45398 _000338_hash NULL
85004 +_000339_hash lbs_debugfs_write 3 48413 _000339_hash NULL
85005 +_000340_hash lcd_write 3 14857 _000340_hash &_000015_hash
85006 +_000341_hash ldm_frag_add 2 5611 _000341_hash NULL
85007 +_000342_hash __lgread 4 31668 _000342_hash NULL
85008 +_000343_hash libipw_alloc_txb 1-3-2 27579 _000343_hash NULL
85009 +_000344_hash link_send_sections_long 4 46556 _000344_hash NULL
85010 +_000345_hash listxattr 3 12769 _000345_hash NULL
85011 +_000346_hash load_msg 2 95 _000346_hash NULL
85012 +_000347_hash lpfc_debugfs_dif_err_write 3 17424 _000347_hash NULL
85013 +_000348_hash lp_write 3 9511 _000348_hash NULL
85014 +_000349_hash mb_cache_create 2 17307 _000349_hash NULL
85015 +_000350_hash mce_write 3 26201 _000350_hash NULL
85016 +_000351_hash mcs7830_get_reg 3 33308 _000351_hash NULL
85017 +_000352_hash mcs7830_set_reg 3 31413 _000352_hash NULL
85018 +_000353_hash memcpy_fromiovec 3 55247 _000353_hash NULL
85019 +_000354_hash memcpy_fromiovecend 3-4 2707 _000354_hash NULL
85020 +_000356_hash mempool_resize 2 47983 _002039_hash NULL nohasharray
85021 +_000357_hash mem_rw 3 22085 _000357_hash NULL
85022 +_000358_hash mgmt_control 3 7349 _000358_hash NULL
85023 +_000359_hash mgmt_pending_add 5 46976 _000359_hash NULL
85024 +_000360_hash mlx4_ib_alloc_fast_reg_page_list 2 46119 _000360_hash NULL
85025 +_000361_hash mmc_alloc_sg 1 21504 _000361_hash NULL
85026 +_000362_hash mmc_send_bus_test 4 18285 _000362_hash NULL
85027 +_000363_hash mmc_send_cxd_data 5 38655 _000363_hash NULL
85028 +_000364_hash module_alloc_update_bounds 1 47205 _000364_hash NULL
85029 +_000365_hash move_addr_to_kernel 2 32673 _000365_hash NULL
85030 +_000366_hash mpi_alloc_limb_space 1 23190 _000366_hash NULL
85031 +_000367_hash mpi_resize 2 44674 _000367_hash NULL
85032 +_000368_hash mptctl_getiocinfo 2 28545 _000368_hash NULL
85033 +_000369_hash mtdchar_readoob 4 31200 _000369_hash NULL
85034 +_000370_hash mtdchar_write 3 56831 _002122_hash NULL nohasharray
85035 +_000371_hash mtdchar_writeoob 4 3393 _000371_hash NULL
85036 +_000372_hash mtd_device_parse_register 5 5024 _000372_hash NULL
85037 +_000373_hash mtf_test_write 3 18844 _000373_hash NULL
85038 +_000374_hash mthca_alloc_icm_table 3-4 38268 _002459_hash NULL nohasharray
85039 +_000376_hash mthca_alloc_init 2 21754 _000376_hash NULL
85040 +_000377_hash mthca_array_init 2 39987 _000377_hash NULL
85041 +_000378_hash mthca_buf_alloc 2 35861 _000378_hash NULL
85042 +_000379_hash mtrr_write 3 59622 _000379_hash NULL
85043 +_000380_hash musb_test_mode_write 3 33518 _000380_hash NULL
85044 +_000381_hash mwifiex_get_common_rates 3 17131 _000381_hash NULL
85045 +_000382_hash __mxt_write_reg 3 57326 _000382_hash NULL
85046 +_000383_hash nand_bch_init 2-3 16280 _001439_hash NULL nohasharray
85047 +_000385_hash ncp_file_write 3 3813 _000385_hash NULL
85048 +_000386_hash ncp__vol2io 5 4804 _000386_hash NULL
85049 +_000387_hash nes_alloc_fast_reg_page_list 2 33523 _000387_hash NULL
85050 +_000388_hash nfc_targets_found 3 29886 _000388_hash NULL
85051 +_000389_hash __nf_ct_ext_add_length 3 12364 _000389_hash NULL
85052 +_000390_hash nfs4_acl_new 1 49806 _000390_hash NULL
85053 +_000391_hash nfs4_write_cached_acl 4 15070 _000391_hash NULL
85054 +_000392_hash nfsd_symlink 6 63442 _000392_hash NULL
85055 +_000393_hash nfs_idmap_get_desc 2-4 42990 _000393_hash NULL
85056 +_000395_hash nfs_readdir_make_qstr 3 12509 _000395_hash NULL
85057 +_000396_hash note_last_dentry 3 12285 _000396_hash NULL
85058 +_000397_hash ntfs_copy_from_user 3-5 15072 _000397_hash NULL
85059 +_000399_hash __ntfs_copy_from_user_iovec_inatomic 3-4 38153 _000399_hash NULL
85060 +_000401_hash ntfs_ucstonls 3-5 23097 _000401_hash NULL
85061 +_000403_hash nvme_alloc_iod 1 56027 _000403_hash NULL
85062 +_000404_hash nvram_write 3 3894 _000404_hash NULL
85063 +_000405_hash o2hb_debug_create 4 18744 _000405_hash NULL
85064 +_000406_hash o2net_send_message_vec 4 879 _002013_hash NULL nohasharray
85065 +_000407_hash ocfs2_control_cfu 2 37750 _000407_hash NULL
85066 +_000408_hash oom_adjust_write 3 41116 _000408_hash NULL
85067 +_000409_hash oom_score_adj_write 3 42594 _000409_hash NULL
85068 +_000410_hash oprofilefs_ulong_from_user 3 57251 _000410_hash NULL
85069 +_000411_hash opticon_write 4 60775 _000411_hash NULL
85070 +_000412_hash p9_check_zc_errors 4 15534 _000412_hash NULL
85071 +_000413_hash packet_buffer_init 2 1607 _000413_hash NULL
85072 +_000414_hash packet_setsockopt 5 17662 _000414_hash NULL
85073 +_000415_hash parse_command 2 37079 _000415_hash NULL
85074 +_000416_hash pcbit_writecmd 2 12332 _000416_hash NULL
85075 +_000417_hash pcmcia_replace_cis 3 57066 _000417_hash NULL
85076 +_000418_hash pgctrl_write 3 50453 _000418_hash NULL
85077 +_000419_hash pg_write 3 40766 _000419_hash NULL
85078 +_000420_hash pidlist_allocate 1 64404 _000420_hash NULL
85079 +_000421_hash pipe_iov_copy_from_user 3 23102 _000421_hash NULL
85080 +_000422_hash pipe_iov_copy_to_user 3 3447 _000422_hash NULL
85081 +_000423_hash pkt_add 3 39897 _000423_hash NULL
85082 +_000424_hash pktgen_if_write 3 55628 _000424_hash NULL
85083 +_000425_hash platform_device_add_data 3 310 _000425_hash NULL
85084 +_000426_hash platform_device_add_resources 3 13289 _000426_hash NULL
85085 +_000427_hash pmcraid_copy_sglist 3 38431 _000427_hash NULL
85086 +_000428_hash pm_qos_power_write 3 52513 _000428_hash NULL
85087 +_000429_hash pnpbios_proc_write 3 19758 _000429_hash NULL
85088 +_000430_hash pool_allocate 3 42012 _000430_hash NULL
85089 +_000431_hash posix_acl_alloc 1 48063 _000431_hash NULL
85090 +_000432_hash ppp_cp_parse_cr 4 5214 _000432_hash NULL
85091 +_000433_hash ppp_write 3 34034 _000433_hash NULL
85092 +_000434_hash pp_read 3 33210 _000434_hash NULL
85093 +_000435_hash pp_write 3 39554 _000435_hash NULL
85094 +_000436_hash printer_req_alloc 2 62687 _000436_hash NULL
85095 +_000437_hash printer_write 3 60276 _000437_hash NULL
85096 +_000438_hash prism2_info_scanresults 3 59729 _000438_hash NULL
85097 +_000439_hash prism2_set_genericelement 3 29277 _000439_hash NULL
85098 +_000440_hash __probe_kernel_read 3 61119 _000440_hash NULL
85099 +_000441_hash __probe_kernel_write 3 29842 _000441_hash NULL
85100 +_000442_hash proc_coredump_filter_write 3 25625 _000442_hash NULL
85101 +_000443_hash _proc_do_string 2 6376 _000443_hash NULL
85102 +_000444_hash process_vm_rw_pages 5-6 15954 _000444_hash NULL
85103 +_000446_hash proc_loginuid_write 3 63648 _000446_hash NULL
85104 +_000447_hash proc_pid_attr_write 3 63845 _000447_hash NULL
85105 +_000448_hash proc_scsi_devinfo_write 3 32064 _000448_hash NULL
85106 +_000449_hash proc_scsi_write 3 29142 _000449_hash NULL
85107 +_000450_hash proc_scsi_write_proc 3 267 _000450_hash NULL
85108 +_000451_hash pskb_expand_head 2-3 42881 _000451_hash NULL
85109 +_000453_hash pstore_mkfile 5 50830 _000453_hash NULL
85110 +_000454_hash pti_char_write 3 60960 _000454_hash NULL
85111 +_000455_hash ptrace_writedata 4 45021 _000455_hash NULL
85112 +_000456_hash pt_write 3 40159 _000456_hash NULL
85113 +_000457_hash qdisc_class_hash_alloc 1 18262 _000457_hash NULL
85114 +_000458_hash r3964_write 4 57662 _000458_hash NULL
85115 +_000459_hash raw_seticmpfilter 3 6888 _000459_hash NULL
85116 +_000460_hash raw_setsockopt 5 45800 _000460_hash NULL
85117 +_000461_hash rawv6_seticmpfilter 5 12137 _000461_hash NULL
85118 +_000462_hash ray_cs_essid_proc_write 3 17875 _000462_hash NULL
85119 +_000463_hash rbd_add 3 16366 _000463_hash NULL
85120 +_000464_hash rbd_snap_add 4 19678 _000464_hash NULL
85121 +_000465_hash rdma_set_ib_paths 3 45592 _000465_hash NULL
85122 +_000466_hash rds_page_copy_user 4 35691 _000466_hash NULL
85123 +_000467_hash read 3 9397 _000467_hash NULL
85124 +_000468_hash read_buf 2 20469 _000468_hash NULL
85125 +_000469_hash read_cis_cache 4 29735 _000469_hash NULL
85126 +_000470_hash realloc_buffer 2 25816 _000470_hash NULL
85127 +_000471_hash receive_DataRequest 3 9904 _000471_hash NULL
85128 +_000472_hash recent_mt_proc_write 3 8206 _000472_hash NULL
85129 +_000473_hash regmap_access_read_file 3 37223 _000473_hash NULL
85130 +_000474_hash regmap_bulk_write 4 59049 _000474_hash NULL
85131 +_000475_hash regmap_map_read_file 3 37685 _000475_hash NULL
85132 +_000476_hash regset_tls_set 4 18459 _000476_hash NULL
85133 +_000477_hash reiserfs_add_entry 4 23062 _002792_hash NULL nohasharray
85134 +_000478_hash remote_settings_file_write 3 22987 _000478_hash NULL
85135 +_000479_hash request_key_auth_new 3 38092 _000479_hash NULL
85136 +_000480_hash restore_i387_fxsave 2 17528 _000480_hash NULL
85137 +_000481_hash revalidate 2 19043 _000481_hash NULL
85138 +_000482_hash rfcomm_sock_setsockopt 5 18254 _000482_hash NULL
85139 +_000483_hash rndis_add_response 2 58544 _000483_hash NULL
85140 +_000484_hash rndis_set_oid 4 6547 _000484_hash NULL
85141 +_000485_hash rngapi_reset 3 34366 _002137_hash NULL nohasharray
85142 +_000486_hash roccat_common2_receive 4 50369 _000486_hash NULL
85143 +_000487_hash roccat_common2_send 4 2422 _000487_hash NULL
85144 +_000488_hash rpc_malloc 2 43573 _000488_hash NULL
85145 +_000489_hash rt2x00debug_write_bbp 3 8212 _000489_hash NULL
85146 +_000490_hash rt2x00debug_write_csr 3 64753 _000490_hash NULL
85147 +_000491_hash rt2x00debug_write_eeprom 3 23091 _000491_hash NULL
85148 +_000492_hash rt2x00debug_write_rf 3 38195 _000492_hash NULL
85149 +_000493_hash rt2x00debug_write_rfcsr 3 41473 _000493_hash NULL
85150 +_000494_hash rts51x_read_mem 4 26577 _002730_hash NULL nohasharray
85151 +_000495_hash rts51x_read_status 4 11830 _000495_hash NULL
85152 +_000496_hash rts51x_write_mem 4 17598 _000496_hash NULL
85153 +_000497_hash rw_copy_check_uvector 3 45748 _003716_hash NULL nohasharray
85154 +_000498_hash rxrpc_request_key 3 27235 _000498_hash NULL
85155 +_000499_hash rxrpc_server_keyring 3 16431 _000499_hash NULL
85156 +_000500_hash savemem 3 58129 _000500_hash NULL
85157 +_000501_hash sb16_copy_from_user 10-7-6 55836 _000501_hash NULL
85158 +_000504_hash sched_autogroup_write 3 10984 _000504_hash NULL
85159 +_000505_hash scsi_mode_select 6 37330 _000505_hash NULL
85160 +_000506_hash scsi_tgt_copy_sense 3 26933 _000506_hash NULL
85161 +_000507_hash sctp_auth_create_key 1 51641 _000507_hash NULL
85162 +_000508_hash sctp_getsockopt_delayed_ack 2 9232 _000508_hash NULL
85163 +_000509_hash sctp_getsockopt_local_addrs 2 25178 _000509_hash NULL
85164 +_000510_hash sctp_make_abort_user 3 29654 _000510_hash NULL
85165 +_000511_hash sctp_setsockopt_active_key 3 43755 _000511_hash NULL
85166 +_000512_hash sctp_setsockopt_adaptation_layer 3 26935 _003246_hash NULL nohasharray
85167 +_000513_hash sctp_setsockopt_associnfo 3 51684 _000513_hash NULL
85168 +_000514_hash sctp_setsockopt_auth_chunk 3 30843 _000514_hash NULL
85169 +_000515_hash sctp_setsockopt_auth_key 3 3793 _000515_hash NULL
85170 +_000516_hash sctp_setsockopt_autoclose 3 5775 _000516_hash NULL
85171 +_000517_hash sctp_setsockopt_bindx 3 49870 _000517_hash NULL
85172 +_000518_hash __sctp_setsockopt_connectx 3 46949 _000518_hash NULL
85173 +_000519_hash sctp_setsockopt_context 3 31091 _000519_hash NULL
85174 +_000520_hash sctp_setsockopt_default_send_param 3 49578 _000520_hash NULL
85175 +_000521_hash sctp_setsockopt_delayed_ack 3 40129 _000521_hash NULL
85176 +_000522_hash sctp_setsockopt_del_key 3 42304 _002709_hash NULL nohasharray
85177 +_000523_hash sctp_setsockopt_events 3 18862 _000523_hash NULL
85178 +_000524_hash sctp_setsockopt_hmac_ident 3 11687 _000524_hash NULL
85179 +_000525_hash sctp_setsockopt_initmsg 3 1383 _000525_hash NULL
85180 +_000526_hash sctp_setsockopt_maxburst 3 28041 _000526_hash NULL
85181 +_000527_hash sctp_setsockopt_maxseg 3 11829 _000527_hash NULL
85182 +_000528_hash sctp_setsockopt_peer_addr_params 3 734 _000528_hash NULL
85183 +_000529_hash sctp_setsockopt_peer_primary_addr 3 13440 _000529_hash NULL
85184 +_000530_hash sctp_setsockopt_rtoinfo 3 30941 _000530_hash NULL
85185 +_000531_hash security_context_to_sid_core 2 29248 _000531_hash NULL
85186 +_000532_hash sel_commit_bools_write 3 46077 _000532_hash NULL
85187 +_000533_hash sel_write_avc_cache_threshold 3 2256 _000533_hash NULL
85188 +_000534_hash sel_write_bool 3 46996 _000534_hash NULL
85189 +_000535_hash sel_write_checkreqprot 3 60774 _000535_hash NULL
85190 +_000536_hash sel_write_disable 3 10511 _000536_hash NULL
85191 +_000537_hash sel_write_enforce 3 48998 _000537_hash NULL
85192 +_000538_hash sel_write_load 3 63830 _000538_hash NULL
85193 +_000539_hash send_bulk_static_data 3 61932 _000539_hash NULL
85194 +_000540_hash set_aoe_iflist 2 42737 _000540_hash NULL
85195 +_000541_hash setkey_unaligned 3 39474 _000541_hash NULL
85196 +_000542_hash set_registers 3 53582 _000542_hash NULL
85197 +_000543_hash setsockopt 5 54539 _000543_hash NULL
85198 +_000544_hash setup_req 3 5848 _000544_hash NULL
85199 +_000545_hash setxattr 4 37006 _000545_hash NULL
85200 +_000546_hash sfq_alloc 1 2861 _000546_hash NULL
85201 +_000547_hash sg_kmalloc 1 50240 _000547_hash NULL
85202 +_000548_hash sgl_map_user_pages 2 30610 _000548_hash NULL
85203 +_000549_hash shash_setkey_unaligned 3 8620 _000549_hash NULL
85204 +_000550_hash shmem_xattr_alloc 2 61190 _000550_hash NULL
85205 +_000551_hash sierra_setup_urb 5 46029 _000551_hash NULL
85206 +_000552_hash simple_transaction_get 3 50633 _000552_hash NULL
85207 +_000553_hash simple_write_to_buffer 2-5 3122 _000553_hash NULL
85208 +_000555_hash sisusb_send_bulk_msg 3 17864 _000555_hash NULL
85209 +_000556_hash skb_add_data 3 48363 _000556_hash NULL
85210 +_000557_hash skb_do_copy_data_nocache 5 12465 _000557_hash NULL
85211 +_000558_hash sl_alloc_bufs 2 50380 _000558_hash NULL
85212 +_000559_hash sl_realloc_bufs 2 64086 _000559_hash NULL
85213 +_000560_hash smk_set_cipso 3 20379 _000560_hash NULL
85214 +_000561_hash smk_write_ambient 3 45691 _000561_hash NULL
85215 +_000562_hash smk_write_direct 3 46363 _000562_hash NULL
85216 +_000563_hash smk_write_doi 3 49621 _000563_hash NULL
85217 +_000564_hash smk_write_logging 3 2618 _000564_hash NULL
85218 +_000565_hash smk_write_mapped 3 13519 _000565_hash NULL
85219 +_000566_hash smk_write_netlbladdr 3 42525 _000566_hash NULL
85220 +_000567_hash smk_write_onlycap 3 14400 _000567_hash NULL
85221 +_000568_hash smk_write_rules_list 3 18565 _000568_hash NULL
85222 +_000569_hash snd_ctl_elem_user_tlv 3 11695 _000569_hash NULL
85223 +_000570_hash snd_emu10k1_fx8010_read 5 9605 _000570_hash NULL
85224 +_000571_hash snd_emu10k1_synth_copy_from_user 3-5 9061 _000571_hash NULL
85225 +_000573_hash snd_gus_dram_poke 4 18525 _000573_hash NULL
85226 +_000574_hash snd_hdsp_playback_copy 5 20676 _000574_hash NULL
85227 +_000575_hash snd_info_entry_write 3 63474 _000575_hash NULL
85228 +_000576_hash snd_korg1212_copy_from 6 36169 _000576_hash NULL
85229 +_000577_hash snd_mem_proc_write 3 9786 _000577_hash NULL
85230 +_000578_hash snd_midi_channel_init_set 1 30092 _000578_hash NULL
85231 +_000579_hash snd_midi_event_new 1 9893 _000764_hash NULL nohasharray
85232 +_000580_hash snd_opl4_mem_proc_write 5 9670 _000580_hash NULL
85233 +_000581_hash snd_pcm_aio_read 3 13900 _000581_hash NULL
85234 +_000582_hash snd_pcm_aio_write 3 28738 _000582_hash NULL
85235 +_000583_hash snd_pcm_oss_write1 3 10872 _000583_hash NULL
85236 +_000584_hash snd_pcm_oss_write2 3 27332 _000584_hash NULL
85237 +_000585_hash snd_rawmidi_kernel_write1 4 56847 _000585_hash NULL
85238 +_000586_hash snd_rme9652_playback_copy 5 20970 _000586_hash NULL
85239 +_000587_hash snd_sb_csp_load_user 3 45190 _000587_hash NULL
85240 +_000588_hash snd_usb_ctl_msg 8 8436 _000588_hash NULL
85241 +_000589_hash sock_bindtodevice 3 50942 _000589_hash NULL
85242 +_000590_hash sock_kmalloc 2 62205 _000590_hash NULL
85243 +_000591_hash spidev_ioctl 2 12846 _000591_hash NULL
85244 +_000592_hash spidev_write 3 44510 _000592_hash NULL
85245 +_000593_hash squashfs_read_table 3 16945 _000593_hash NULL
85246 +_000594_hash srpt_alloc_ioctx 2-3 51042 _000594_hash NULL
85247 +_000596_hash srpt_alloc_ioctx_ring 2-4-3 49330 _000596_hash NULL
85248 +_000597_hash st5481_setup_isocpipes 6-4 61340 _000597_hash NULL
85249 +_000598_hash sta_agg_status_write 3 45164 _000598_hash NULL
85250 +_000599_hash svc_setsockopt 5 36876 _000599_hash NULL
85251 +_000600_hash sys_add_key 4 61288 _000600_hash NULL
85252 +_000601_hash sys_modify_ldt 3 18824 _000601_hash NULL
85253 +_000602_hash sys_semtimedop 3 4486 _000602_hash NULL
85254 +_000603_hash sys_setdomainname 2 4373 _000603_hash NULL
85255 +_000604_hash sys_sethostname 2 42962 _000604_hash NULL
85256 +_000605_hash tomoyo_write_self 3 45161 _000605_hash NULL
85257 +_000606_hash tower_write 3 8580 _000606_hash NULL
85258 +_000607_hash tpm_write 3 50798 _000607_hash NULL
85259 +_000608_hash trusted_instantiate 3 4710 _000608_hash NULL
85260 +_000609_hash trusted_update 3 12664 _000609_hash NULL
85261 +_000610_hash tty_buffer_alloc 2 45437 _000610_hash NULL
85262 +_000611_hash __tun_chr_ioctl 4 22300 _000611_hash NULL
85263 +_000612_hash ubi_more_leb_change_data 4 63534 _000612_hash NULL
85264 +_000613_hash ubi_more_update_data 4 39189 _000613_hash NULL
85265 +_000614_hash ubi_resize_volume 2 50172 _000614_hash NULL
85266 +_000615_hash udf_alloc_i_data 2 35786 _000615_hash NULL
85267 +_000616_hash uea_idma_write 3 64139 _000616_hash NULL
85268 +_000617_hash uea_request 4 47613 _000617_hash NULL
85269 +_000618_hash uea_send_modem_cmd 3 3888 _000618_hash NULL
85270 +_000619_hash uio_write 3 43202 _000619_hash NULL
85271 +_000620_hash um_idi_write 3 18293 _000620_hash NULL
85272 +_000621_hash us122l_ctl_msg 8 13330 _000621_hash NULL
85273 +_000622_hash usb_alloc_urb 1 43436 _000622_hash NULL
85274 +_000623_hash usblp_new_writeurb 2 22894 _000623_hash NULL
85275 +_000624_hash usblp_write 3 23178 _000624_hash NULL
85276 +_000625_hash usbtest_alloc_urb 3-5 34446 _000625_hash NULL
85277 +_000627_hash usbtmc_write 3 64340 _000627_hash NULL
85278 +_000628_hash user_instantiate 3 26131 _000628_hash NULL
85279 +_000629_hash user_update 3 41332 _000629_hash NULL
85280 +_000630_hash uwb_rc_cmd_done 4 35892 _000630_hash NULL
85281 +_000631_hash uwb_rc_neh_grok_event 3 55799 _000631_hash NULL
85282 +_000632_hash v9fs_alloc_rdir_buf 2 42150 _000632_hash NULL
85283 +_000633_hash vc_do_resize 3-4 48842 _000633_hash NULL
85284 +_000635_hash vcs_write 3 3910 _000635_hash NULL
85285 +_000636_hash vga_arb_write 3 36112 _000636_hash NULL
85286 +_000637_hash vga_switcheroo_debugfs_write 3 33984 _000637_hash NULL
85287 +_000638_hash vhci_get_user 3 45039 _000638_hash NULL
85288 +_000639_hash video_proc_write 3 6724 _000639_hash NULL
85289 +_000640_hash vlsi_alloc_ring 3-4 57003 _000640_hash NULL
85290 +_000642_hash __vmalloc 1 61168 _000642_hash NULL
85291 +_000643_hash vmalloc_32 1 1135 _000643_hash NULL
85292 +_000644_hash vmalloc_32_user 1 37519 _000644_hash NULL
85293 +_000645_hash vmalloc_exec 1 36132 _000645_hash NULL
85294 +_000646_hash vmalloc_node 1 58700 _000646_hash NULL
85295 +_000647_hash __vmalloc_node_flags 1 30352 _000647_hash NULL
85296 +_000648_hash vmalloc_user 1 32308 _000648_hash NULL
85297 +_000649_hash vol_cdev_direct_write 3 20751 _000649_hash NULL
85298 +_000650_hash vp_request_msix_vectors 2 28849 _000650_hash NULL
85299 +_000651_hash vring_add_indirect 3-4 20737 _000651_hash NULL
85300 +_000653_hash vring_new_virtqueue 1 9671 _000653_hash NULL
85301 +_000654_hash vxge_os_dma_malloc 2 46184 _000654_hash NULL
85302 +_000655_hash vxge_os_dma_malloc_async 3 56348 _000655_hash NULL
85303 +_000656_hash wdm_write 3 53735 _000656_hash NULL
85304 +_000657_hash wiimote_hid_send 3 48528 _000657_hash NULL
85305 +_000658_hash wlc_phy_loadsampletable_nphy 3 64367 _000658_hash NULL
85306 +_000659_hash write 3 62671 _000659_hash NULL
85307 +_000660_hash write_flush 3 50803 _000660_hash NULL
85308 +_000661_hash write_rio 3 54837 _000661_hash NULL
85309 +_000662_hash x25_asy_change_mtu 2 26928 _000662_hash NULL
85310 +_000663_hash xdi_copy_from_user 4 8395 _000663_hash NULL
85311 +_000664_hash xfrm_dst_alloc_copy 3 3034 _000664_hash NULL
85312 +_000665_hash xfrm_user_policy 4 62573 _000665_hash NULL
85313 +_000666_hash xfs_attrmulti_attr_set 4 59346 _000666_hash NULL
85314 +_000667_hash xfs_handle_to_dentry 3 12135 _000667_hash NULL
85315 +_000668_hash xip_file_read 3 58592 _000668_hash NULL
85316 +_000669_hash __xip_file_write 3-4 2733 _000669_hash NULL
85317 +_000671_hash xprt_rdma_allocate 2 31372 _000671_hash NULL
85318 +_000672_hash zd_usb_iowrite16v_async 3 23984 _000672_hash NULL
85319 +_000673_hash zd_usb_read_fw 4 22049 _000673_hash NULL
85320 +_000674_hash zerocopy_sg_from_iovec 3 11828 _000674_hash NULL
85321 +_000675_hash __a2mp_build 3 60987 _000675_hash NULL
85322 +_000677_hash acpi_ex_allocate_name_string 2-1 7685 _001169_hash NULL nohasharray
85323 +_000678_hash acpi_os_allocate_zeroed 1 37422 _000678_hash NULL
85324 +_000679_hash acpi_ut_initialize_buffer 2 47143 _002830_hash NULL nohasharray
85325 +_000680_hash ad7879_spi_xfer 3 36311 _000680_hash NULL
85326 +_000681_hash add_new_gdb 3 27643 _000681_hash NULL
85327 +_000682_hash add_numbered_child 5 14273 _000682_hash NULL
85328 +_000683_hash add_res_range 4 21310 _000683_hash NULL
85329 +_000684_hash addtgt 3 54703 _000684_hash NULL
85330 +_000685_hash add_uuid 4 49831 _000685_hash NULL
85331 +_000686_hash afs_cell_alloc 2 24052 _000686_hash NULL
85332 +_000687_hash aggr_recv_addba_req_evt 4 38037 _000687_hash NULL
85333 +_000688_hash agp_create_memory 1 1075 _000688_hash NULL
85334 +_000689_hash agp_create_user_memory 1 62955 _000689_hash NULL
85335 +_000690_hash alg_setsockopt 5 20985 _000690_hash NULL
85336 +_000691_hash alloc_async 1 14208 _000691_hash NULL
85337 +_000692_hash ___alloc_bootmem_nopanic 1 53626 _000692_hash NULL
85338 +_000693_hash alloc_buf 1 34532 _000693_hash NULL
85339 +_000694_hash alloc_chunk 1 49575 _000694_hash NULL
85340 +_000695_hash alloc_context 1 41283 _000695_hash NULL
85341 +_000696_hash alloc_ctrl_packet 1 44667 _000696_hash NULL
85342 +_000697_hash alloc_data_packet 1 46698 _000697_hash NULL
85343 +_000698_hash alloc_dca_provider 2 59670 _000698_hash NULL
85344 +_000699_hash __alloc_dev_table 2 54343 _000699_hash NULL
85345 +_000700_hash alloc_ep 1 17269 _000700_hash NULL
85346 +_000701_hash __alloc_extent_buffer 3 15093 _000701_hash NULL
85347 +_000702_hash alloc_group_attrs 2 9194 _000727_hash NULL nohasharray
85348 +_000703_hash alloc_large_system_hash 2 22391 _000703_hash NULL
85349 +_000704_hash alloc_netdev_mqs 1 30030 _000704_hash NULL
85350 +_000705_hash __alloc_objio_seg 1 7203 _000705_hash NULL
85351 +_000706_hash alloc_ring 2-4 15345 _000706_hash NULL
85352 +_000707_hash alloc_ring 2-4 39151 _000707_hash NULL
85353 +_000710_hash alloc_session 1-2 64171 _000710_hash NULL
85354 +_000714_hash alloc_skb 1 55439 _000714_hash NULL
85355 +_000715_hash alloc_skb_fclone 1 3467 _000715_hash NULL
85356 +_000716_hash alloc_smp_req 1 51337 _000716_hash NULL
85357 +_000717_hash alloc_smp_resp 1 3566 _000717_hash NULL
85358 +_000718_hash alloc_ts_config 1 45775 _000718_hash NULL
85359 +_000719_hash alloc_upcall 2 62186 _000719_hash NULL
85360 +_000720_hash altera_drscan 2 48698 _000720_hash NULL
85361 +_000721_hash altera_irscan 2 62396 _000721_hash NULL
85362 +_000722_hash altera_set_dr_post 2 54291 _000722_hash NULL
85363 +_000723_hash altera_set_dr_pre 2 64862 _000723_hash NULL
85364 +_000724_hash altera_set_ir_post 2 20948 _000724_hash NULL
85365 +_000725_hash altera_set_ir_pre 2 54103 _000725_hash NULL
85366 +_000726_hash altera_swap_dr 2 50090 _000726_hash NULL
85367 +_000727_hash altera_swap_ir 2 9194 _000727_hash &_000702_hash
85368 +_000728_hash amd_create_gatt_pages 1 20537 _000728_hash NULL
85369 +_000729_hash aoechr_write 3 62883 _003674_hash NULL nohasharray
85370 +_000730_hash applesmc_create_nodes 2 49392 _000730_hash NULL
85371 +_000731_hash array_zalloc 1-2 7519 _000731_hash NULL
85372 +_000733_hash arvo_sysfs_read 6 31617 _000733_hash NULL
85373 +_000734_hash arvo_sysfs_write 6 3311 _000734_hash NULL
85374 +_000735_hash asd_store_update_bios 4 10165 _000735_hash NULL
85375 +_000736_hash ata_host_alloc 2 46094 _000736_hash NULL
85376 +_000737_hash atalk_sendmsg 4 21677 _000737_hash NULL
85377 +_000738_hash ath6kl_cfg80211_connect_event 7-9-8 13443 _000738_hash NULL
85378 +_000739_hash ath6kl_mgmt_tx 9 21153 _000739_hash NULL
85379 +_000740_hash ath6kl_wmi_proc_events_vif 5 42549 _003190_hash NULL nohasharray
85380 +_000741_hash ath6kl_wmi_roam_tbl_event_rx 3 43440 _000741_hash NULL
85381 +_000742_hash ath6kl_wmi_send_mgmt_cmd 7 17347 _000742_hash NULL
85382 +_000743_hash ath_descdma_setup 5 12257 _000743_hash NULL
85383 +_000744_hash ath_rx_edma_init 2 65483 _000744_hash NULL
85384 +_000745_hash ati_create_gatt_pages 1 4722 _003275_hash NULL nohasharray
85385 +_000746_hash audit_expand 2 2098 _000746_hash NULL
85386 +_000747_hash audit_init_entry 1 38644 _000747_hash NULL
85387 +_000748_hash ax25_sendmsg 4 62770 _000748_hash NULL
85388 +_000749_hash b1_alloc_card 1 36155 _000749_hash NULL
85389 +_000750_hash b43_nphy_load_samples 3 36481 _000750_hash NULL
85390 +_000751_hash batadv_orig_hash_add_if 2 10033 _000751_hash NULL
85391 +_000752_hash batadv_orig_hash_del_if 2 48972 _000752_hash NULL
85392 +_000753_hash batadv_tt_append_diff 4 20588 _000753_hash NULL
85393 +_000754_hash batadv_tt_commit_changes 4 2008 _000754_hash NULL
85394 +_000755_hash batadv_tt_prepare_packet_buff 4 1280 _000755_hash NULL
85395 +_000756_hash bio_copy_user_iov 4 37660 _000756_hash NULL
85396 +_000757_hash __bio_map_kern 3 47379 _000757_hash NULL
85397 +_000758_hash bitmap_resize 2 33054 _000758_hash NULL
85398 +_000759_hash blk_check_plugged 3 50736 _000759_hash NULL
85399 +_000760_hash blk_register_region 1-2 51424 _000760_hash NULL
85400 +_000762_hash bm_entry_write 3 28338 _000762_hash NULL
85401 +_000763_hash bm_realloc_pages 2 9431 _000763_hash NULL
85402 +_000764_hash bm_register_write 3 9893 _000764_hash &_000579_hash
85403 +_000765_hash bm_status_write 3 12964 _000765_hash NULL
85404 +_000766_hash br_mdb_rehash 2 42643 _000766_hash NULL
85405 +_000767_hash btmrvl_sdio_host_to_card 3 12152 _000767_hash NULL
85406 +_000768_hash btrfs_copy_from_user 1-3 43806 _000768_hash NULL
85407 +_000770_hash btrfs_insert_delayed_dir_index 4 63720 _000770_hash NULL
85408 +_000771_hash __btrfs_map_block 3 49839 _000771_hash NULL
85409 +_000772_hash c4iw_init_resource 2-3 30393 _000772_hash NULL
85410 +_000774_hash cache_downcall 3 13666 _000774_hash NULL
85411 +_000775_hash cache_slow_downcall 2 8570 _000775_hash NULL
85412 +_000776_hash caif_seqpkt_sendmsg 4 22961 _000776_hash NULL
85413 +_000777_hash caif_stream_sendmsg 4 9110 _000777_hash NULL
85414 +_000778_hash carl9170_cmd_buf 3 950 _000778_hash NULL
85415 +_000779_hash cdev_add 2-3 38176 _000779_hash NULL
85416 +_000781_hash cdrom_read_cdda 4 50478 _000781_hash NULL
85417 +_000782_hash ceph_dns_resolve_name 2 62488 _000782_hash NULL
85418 +_000783_hash ceph_msgpool_get 2 54258 _000783_hash NULL
85419 +_000784_hash cfg80211_connect_result 4-6 56515 _000784_hash NULL
85420 +_000786_hash cfg80211_disconnected 4 57 _000786_hash NULL
85421 +_000787_hash cfg80211_inform_bss 8 19332 _000787_hash NULL
85422 +_000788_hash cfg80211_inform_bss_frame 4 41078 _000788_hash NULL
85423 +_000789_hash cfg80211_mlme_register_mgmt 5 19852 _000789_hash NULL
85424 +_000790_hash cfg80211_roamed_bss 4-6 50198 _000790_hash NULL
85425 +_000792_hash cgroup_file_write 3 52417 _000792_hash NULL
85426 +_000793_hash cifs_readdata_alloc 1 26360 _000793_hash NULL
85427 +_000794_hash cifs_readv_from_socket 3 19109 _000794_hash NULL
85428 +_000795_hash cifs_writedata_alloc 1 32880 _003097_hash NULL nohasharray
85429 +_000796_hash cnic_alloc_dma 3 34641 _000796_hash NULL
85430 +_000797_hash cnic_init_id_tbl 2 41354 _000797_hash NULL
85431 +_000798_hash configfs_write_file 3 61621 _000798_hash NULL
85432 +_000799_hash construct_key 3 11329 _000799_hash NULL
85433 +_000800_hash context_alloc 3 24645 _000800_hash NULL
85434 +_000801_hash copy_to_user 3 57835 _000801_hash NULL
85435 +_000802_hash cp210x_get_config 4 56229 _000802_hash NULL
85436 +_000803_hash create_attr_set 1 22861 _000803_hash NULL
85437 +_000804_hash create_bounce_buffer 3 39155 _000804_hash NULL
85438 +_000805_hash create_gpadl_header 2 19064 _000805_hash NULL
85439 +_000806_hash _create_sg_bios 4 31244 _000806_hash NULL
85440 +_000807_hash cryptd_alloc_instance 2-3 18048 _000807_hash NULL
85441 +_000809_hash crypto_ahash_setkey 3 55134 _000809_hash NULL
85442 +_000810_hash crypto_alloc_instance2 3 25277 _000810_hash NULL
85443 +_000811_hash crypto_shash_setkey 3 60483 _000811_hash NULL
85444 +_000812_hash cxgb_alloc_mem 1 24007 _000812_hash NULL
85445 +_000813_hash cxgbi_device_portmap_create 3 25747 _000813_hash NULL
85446 +_000814_hash cxgbi_device_register 1-2 36746 _000814_hash NULL
85447 +_000816_hash __cxio_init_resource_fifo 3 23447 _000816_hash NULL
85448 +_000817_hash dccp_sendmsg 4 56058 _000817_hash NULL
85449 +_000818_hash ddp_make_gl 1 12179 _000818_hash NULL
85450 +_000819_hash depth_write 3 3021 _000819_hash NULL
85451 +_000820_hash dev_irnet_write 3 11398 _000820_hash NULL
85452 +_000821_hash dev_set_alias 3 50084 _000821_hash NULL
85453 +_000822_hash dev_write 3 7708 _000822_hash NULL
85454 +_000823_hash dfs_global_file_write 3 6112 _000823_hash NULL
85455 +_000824_hash dgram_sendmsg 4 45679 _000824_hash NULL
85456 +_000825_hash disconnect 4 32521 _000825_hash NULL
85457 +_000826_hash dma_attach 6-7 50831 _000826_hash NULL
85458 +_000828_hash dma_declare_coherent_memory 4-2 14244 _000828_hash NULL
85459 +_000829_hash dn_sendmsg 4 38390 _000829_hash NULL
85460 +_000830_hash dn_setsockopt 5 314 _000830_hash NULL
85461 +_000831_hash do_arpt_set_ctl 4 51053 _000831_hash NULL
85462 +_000832_hash do_dccp_setsockopt 5 54377 _003195_hash NULL nohasharray
85463 +_000833_hash do_ip6t_set_ctl 4 60040 _000833_hash NULL
85464 +_000834_hash do_ipt_set_ctl 4 56238 _000834_hash NULL
85465 +_000835_hash do_jffs2_setxattr 5 25910 _000835_hash NULL
85466 +_000836_hash do_msgsnd 4 1387 _000836_hash NULL
85467 +_000837_hash do_pselect 1 62061 _000837_hash NULL
85468 +_000838_hash do_raw_setsockopt 5 55215 _000838_hash NULL
85469 +_000839_hash do_readv_writev 4 51849 _000839_hash NULL
85470 +_000840_hash do_sync 1 9604 _000840_hash NULL
85471 +_000841_hash dup_array 3 33551 _000841_hash NULL
85472 +_000842_hash ecryptfs_decode_and_decrypt_filename 5 10379 _000842_hash NULL
85473 +_000843_hash ecryptfs_encrypt_and_encode_filename 6 2109 _000843_hash NULL
85474 +_000844_hash ecryptfs_send_message_locked 2 31801 _000844_hash NULL
85475 +_000845_hash edac_device_alloc_ctl_info 1 5941 _000845_hash NULL
85476 +_000846_hash edac_mc_alloc 4 3611 _000846_hash NULL
85477 +_000847_hash edac_pci_alloc_ctl_info 1 63388 _000847_hash NULL
85478 +_000848_hash efivar_create_sysfs_entry 2 19485 _000848_hash NULL
85479 +_000849_hash enable_write 3 30456 _000849_hash NULL
85480 +_000850_hash enclosure_register 3 57412 _000850_hash NULL
85481 +_000851_hash enlarge_skb 2 44248 _002839_hash NULL nohasharray
85482 +_000852_hash evdev_ioctl_handler 2 21705 _000852_hash NULL
85483 +_000853_hash ext4_kvzalloc 1 47605 _000853_hash NULL
85484 +_000854_hash extend_netdev_table 2 21453 _000854_hash NULL
85485 +_000855_hash fcoe_ctlr_device_add 3 1793 _000855_hash NULL
85486 +_000856_hash fd_do_readv 3 51297 _000856_hash NULL
85487 +_000857_hash fd_do_writev 3 29329 _000857_hash NULL
85488 +_000858_hash __feat_register_sp 6 64712 _000858_hash NULL
85489 +_000859_hash __ffs_ep0_read_events 3 48868 _000859_hash NULL
85490 +_000860_hash ffs_ep0_write 3 9438 _000860_hash NULL
85491 +_000861_hash ffs_epfile_read 3 18775 _000861_hash NULL
85492 +_000862_hash ffs_epfile_write 3 48014 _000862_hash NULL
85493 +_000863_hash fib_info_hash_alloc 1 9075 _000863_hash NULL
85494 +_000864_hash fillonedir 3 41746 _000864_hash NULL
85495 +_000865_hash fs_devrw_entry 3 11924 _000865_hash NULL
85496 +_000866_hash fs_path_prepare_for_add 2 61854 _000866_hash NULL
85497 +_000867_hash fuse_fill_write_pages 4 53682 _000867_hash NULL
85498 +_000868_hash fw_device_op_ioctl 2 11595 _000868_hash NULL
85499 +_000869_hash fw_iso_buffer_init 3 54582 _000869_hash NULL
85500 +_000870_hash fw_node_create 2 9559 _000870_hash NULL
85501 +_000871_hash garmin_read_process 3 27509 _000871_hash NULL
85502 +_000872_hash garp_request_join 4 7471 _000872_hash NULL
85503 +_000873_hash generic_perform_write 3 54832 _000873_hash NULL
85504 +_000874_hash gen_pool_add_virt 4 39913 _000874_hash NULL
85505 +_000875_hash get_derived_key 4 61100 _000875_hash NULL
85506 +_000876_hash get_new_cssid 2 51665 _000876_hash NULL
85507 +_000877_hash getxattr 4 24398 _003758_hash NULL nohasharray
85508 +_000878_hash gsm_control_reply 4 53333 _000878_hash NULL
85509 +_000879_hash hcd_alloc_coherent 5 55862 _000879_hash NULL
85510 +_000880_hash hci_sock_sendmsg 4 37420 _000880_hash NULL
85511 +_000881_hash hidraw_ioctl 2 63658 _000881_hash NULL
85512 +_000882_hash hidraw_write 3 31536 _000882_hash NULL
85513 +_000883_hash hid_register_field 2-3 4874 _000883_hash NULL
85514 +_000885_hash hid_report_raw_event 4 2762 _000885_hash NULL
85515 +_000886_hash hpi_alloc_control_cache 1 35351 _000886_hash NULL
85516 +_000887_hash hugetlbfs_read_actor 2-5-4 34547 _000887_hash NULL
85517 +_000890_hash hvc_alloc 4 12579 _000890_hash NULL
85518 +_000891_hash __hwahc_dev_set_key 5 46328 _000891_hash NULL
85519 +_000892_hash i2400m_zrealloc_2x 3 54166 _001549_hash NULL nohasharray
85520 +_000893_hash ib_alloc_device 1 26483 _000893_hash NULL
85521 +_000894_hash ib_create_send_mad 5 1196 _000894_hash NULL
85522 +_000895_hash ibmasm_new_command 2 25714 _000895_hash NULL
85523 +_000896_hash ib_send_cm_drep 3 50186 _000896_hash NULL
85524 +_000897_hash ib_send_cm_mra 4 60202 _003063_hash NULL nohasharray
85525 +_000898_hash ib_send_cm_rtu 3 63138 _000898_hash NULL
85526 +_000899_hash ide_core_cp_entry 3 22636 _000899_hash NULL
85527 +_000900_hash ieee80211_if_write_smps 3 35550 _000900_hash NULL
85528 +_000901_hash ieee80211_if_write_tkip_mic_test 3 58748 _000901_hash NULL
85529 +_000902_hash ieee80211_if_write_tsf 3 36077 _000902_hash NULL
85530 +_000903_hash ieee80211_if_write_uapsd_max_sp_len 3 14233 _000903_hash NULL
85531 +_000904_hash ieee80211_if_write_uapsd_queues 3 51526 _000904_hash NULL
85532 +_000905_hash ieee80211_key_alloc 3 19065 _000905_hash NULL
85533 +_000906_hash ieee80211_send_probe_req 6-4 6924 _000906_hash NULL
85534 +_000907_hash ieee80211_skb_resize 3 50211 _000907_hash NULL
85535 +_000908_hash if_spi_host_to_card 4 62890 _000908_hash NULL
85536 +_000909_hash if_writecmd 2 815 _000909_hash NULL
85537 +_000910_hash init_bch 1-2 64130 _000910_hash NULL
85538 +_000912_hash init_ipath 1 48187 _000912_hash NULL
85539 +_000913_hash init_list_set 2-3 39188 _000913_hash NULL
85540 +_000915_hash init_q 4 132 _000915_hash NULL
85541 +_000916_hash init_state 2 60165 _000916_hash NULL
85542 +_000917_hash init_tag_map 3 57515 _000917_hash NULL
85543 +_000918_hash input_ff_create 2 21240 _000918_hash NULL
85544 +_000919_hash input_mt_init_slots 2 31183 _000919_hash NULL
85545 +_000920_hash interfaces 2 38859 _000920_hash NULL
85546 +_000921_hash int_hardware_entry 3 36833 _000921_hash NULL
85547 +_000922_hash int_hw_irq_en 3 46776 _000922_hash NULL
85548 +_000923_hash int_tasklet_entry 3 52500 _000923_hash NULL
85549 +_000924_hash ioat2_alloc_ring 2 11172 _000924_hash NULL
85550 +_000925_hash ip_generic_getfrag 3-4 12187 _000925_hash NULL
85551 +_000927_hash ip_options_get_alloc 1 7448 _000927_hash NULL
85552 +_000928_hash ipr_alloc_ucode_buffer 1 40199 _000928_hash NULL
85553 +_000929_hash ip_set_alloc 1 57953 _000929_hash NULL
85554 +_000930_hash ip_setsockopt 5 33487 _000930_hash NULL
85555 +_000931_hash ipv6_flowlabel_opt 3 58135 _001179_hash NULL nohasharray
85556 +_000932_hash ipv6_renew_options 5 28867 _000932_hash NULL
85557 +_000933_hash ipv6_setsockopt 5 29871 _000933_hash NULL
85558 +_000934_hash ipxrtr_route_packet 4 54036 _000934_hash NULL
85559 +_000935_hash irda_sendmsg 4 4388 _000935_hash NULL
85560 +_000936_hash irda_sendmsg_dgram 4 38563 _000936_hash NULL
85561 +_000937_hash irda_sendmsg_ultra 4 42047 _000937_hash NULL
85562 +_000938_hash irias_add_octseq_attrib 4 29983 _000938_hash NULL
85563 +_000939_hash irq_alloc_generic_chip 2 26650 _000939_hash NULL
85564 +_000940_hash iscsi_alloc_session 3 49390 _000940_hash NULL
85565 +_000941_hash iscsi_create_conn 2 50425 _000941_hash NULL
85566 +_000942_hash iscsi_create_endpoint 1 15193 _000942_hash NULL
85567 +_000943_hash iscsi_create_iface 5 38510 _000943_hash NULL
85568 +_000944_hash iscsi_decode_text_input 4 58292 _000944_hash NULL
85569 +_000945_hash iscsi_pool_init 2-4 54913 _000945_hash NULL
85570 +_000947_hash iscsit_dump_data_payload 2 38683 _000947_hash NULL
85571 +_000948_hash isdn_write 3 45863 _000948_hash NULL
85572 +_000949_hash isku_receive 4 54130 _000949_hash NULL
85573 +_000950_hash islpci_mgt_transaction 5 23610 _000950_hash NULL
85574 +_000951_hash iso_alloc_urb 4-5 45206 _000951_hash NULL
85575 +_000952_hash iso_sched_alloc 1 13377 _003325_hash NULL nohasharray
85576 +_000953_hash iwl_trans_txq_alloc 3 36147 _000953_hash NULL
85577 +_000954_hash ixgbe_alloc_q_vector 4-6 24439 _000954_hash NULL
85578 +_000956_hash jbd2_journal_init_revoke 2 51088 _000956_hash NULL
85579 +_000957_hash jffs2_write_dirent 5 37311 _000957_hash NULL
85580 +_000958_hash journal_init_revoke 2 56933 _000958_hash NULL
85581 +_000959_hash keyctl_instantiate_key 3 41855 _000959_hash NULL
85582 +_000960_hash keyctl_instantiate_key_iov 3 16969 _000960_hash NULL
85583 +_000961_hash __kfifo_from_user 3 20399 _000961_hash NULL
85584 +_000962_hash kimage_crash_alloc 3 3233 _000962_hash NULL
85585 +_000963_hash kimage_normal_alloc 3 31140 _000963_hash NULL
85586 +_000964_hash kmem_realloc 2 37489 _000964_hash NULL
85587 +_000965_hash kmem_zalloc 1 11510 _000965_hash NULL
85588 +_000966_hash koneplus_sysfs_read 6 42792 _000966_hash NULL
85589 +_000967_hash kvm_kvzalloc 1 52894 _000967_hash NULL
85590 +_000968_hash kvm_read_guest_page_mmu 6 37611 _000968_hash NULL
85591 +_000969_hash kvm_set_irq_routing 3 48704 _000969_hash NULL
85592 +_000970_hash kvm_write_guest_cached 4 11106 _000970_hash NULL
85593 +_000971_hash kvm_write_guest_page 5 63555 _002812_hash NULL nohasharray
85594 +_000972_hash kzalloc_node 1 24352 _000972_hash NULL
85595 +_000973_hash l2cap_skbuff_fromiovec 3-4 35003 _000973_hash NULL
85596 +_000975_hash l2tp_ip_sendmsg 4 50411 _000975_hash NULL
85597 +_000976_hash l2tp_session_create 1 25286 _000976_hash NULL
85598 +_000977_hash lc_create 3 48662 _000977_hash NULL
85599 +_000978_hash leaf_dealloc 3 29566 _000978_hash NULL
85600 +_000979_hash linear_conf 2 23485 _003837_hash NULL nohasharray
85601 +_000980_hash llc_ui_sendmsg 4 24987 _000980_hash NULL
85602 +_000981_hash load_module 2 60056 _003010_hash NULL nohasharray
85603 +_000982_hash lpfc_sli4_queue_alloc 3 62646 _000982_hash NULL
85604 +_000983_hash mdiobus_alloc_size 1 52259 _000983_hash NULL
85605 +_000984_hash mempool_create_node 1 3191 _000984_hash NULL
85606 +_000985_hash mem_read 3 57631 _000985_hash NULL
85607 +_000986_hash memstick_alloc_host 1 142 _000986_hash NULL
85608 +_000987_hash mem_swapout_entry 3 32586 _000987_hash NULL
85609 +_000988_hash mem_write 3 22232 _000988_hash NULL
85610 +_000989_hash mesh_table_alloc 1 22305 _000989_hash NULL
85611 +_000990_hash mfd_add_devices 4 16668 _000990_hash NULL
85612 +_000991_hash mISDN_sock_sendmsg 4 41035 _000991_hash NULL
85613 +_000992_hash mlx4_init_icm_table 4-5 2151 _000992_hash NULL
85614 +_000994_hash mmc_alloc_host 1 48097 _000994_hash NULL
85615 +_000995_hash mmc_test_alloc_mem 2-3 28102 _000995_hash NULL
85616 +_000997_hash mon_bin_ioctl 3 2771 _000997_hash NULL
85617 +_000998_hash mpi_alloc 1 18094 _000998_hash NULL
85618 +_000999_hash mpihelp_mul_karatsuba_case 5-3 23918 _003061_hash NULL nohasharray
85619 +_001000_hash __mptctl_ioctl 2 15875 _001000_hash NULL
85620 +_001001_hash mtd_concat_create 2 14416 _001001_hash NULL
85621 +_001002_hash mthca_alloc_cq_buf 3 46512 _001002_hash NULL
85622 +_001003_hash mvumi_alloc_mem_resource 3 47750 _001003_hash NULL
85623 +_001004_hash mwifiex_11n_create_rx_reorder_tbl 4 63806 _001004_hash NULL
85624 +_001005_hash mwifiex_alloc_sdio_mpa_buffers 2-3 60961 _001005_hash NULL
85625 +_001007_hash mwl8k_cmd_set_beacon 4 23110 _001007_hash NULL
85626 +_001008_hash neigh_hash_alloc 1 17595 _001008_hash NULL
85627 +_001009_hash __netdev_alloc_skb 2 18595 _001009_hash NULL
85628 +_001010_hash __netlink_change_ngroups 2 46156 _001010_hash NULL
85629 +_001011_hash netlink_sendmsg 4 33708 _001236_hash NULL nohasharray
85630 +_001012_hash netxen_alloc_sds_rings 2 13417 _001012_hash NULL
85631 +_001013_hash new_bind_ctl 2 35324 _001013_hash NULL
85632 +_001014_hash new_dir 3 31919 _001014_hash NULL
85633 +_001015_hash new_tape_buffer 2 32866 _001015_hash NULL
85634 +_001016_hash nfc_llcp_build_tlv 3 19536 _001016_hash NULL
85635 +_001017_hash nfc_llcp_send_i_frame 3 59130 _001017_hash NULL
85636 +_001018_hash nf_ct_ext_create 3 51232 _001018_hash NULL
85637 +_001019_hash nfs4_alloc_pages 1 48426 _001019_hash NULL
85638 +_001020_hash nfs4_alloc_slots 1 2454 _003345_hash NULL nohasharray
85639 +_001021_hash nfsctl_transaction_write 3 64800 _001021_hash NULL
85640 +_001022_hash nfs_fscache_get_super_cookie 3 44355 _001850_hash NULL nohasharray
85641 +_001023_hash nfs_idmap_request_key 3 30208 _001023_hash NULL
85642 +_001024_hash nfs_pgarray_set 2 1085 _001024_hash NULL
85643 +_001025_hash nl_pid_hash_zalloc 1 23314 _001025_hash NULL
85644 +_001026_hash nr_sendmsg 4 53656 _001026_hash NULL
85645 +_001027_hash nsm_create_handle 4 38060 _001027_hash NULL
85646 +_001028_hash ntfs_copy_from_user_iovec 3-6 49829 _001028_hash NULL
85647 +_001030_hash ntfs_file_buffered_write 4-6 41442 _001030_hash NULL
85648 +_001032_hash __ntfs_malloc 1 34022 _001032_hash NULL
85649 +_001033_hash nvme_alloc_queue 3 46865 _001033_hash NULL
85650 +_001034_hash nvme_map_user_pages 3-4 41093 _001639_hash NULL nohasharray
85651 +_001036_hash ocfs2_acl_from_xattr 2 21604 _001036_hash NULL
85652 +_001037_hash ocfs2_control_message 3 19564 _001037_hash NULL
85653 +_001038_hash _ore_get_io_state 3-5-4 2166 _001038_hash NULL
85654 +_001041_hash orinoco_set_key 5-7 17878 _001041_hash NULL
85655 +_001043_hash osdmap_set_max_osd 2 57630 _002267_hash NULL nohasharray
85656 +_001044_hash _osd_realloc_seg 3 54352 _001044_hash NULL
85657 +_001045_hash osst_execute 7-6 17607 _001045_hash NULL
85658 +_001046_hash osst_write 3 31581 _001046_hash NULL
85659 +_001047_hash otp_read 2-5-4 10594 _001047_hash NULL
85660 +_001050_hash ovs_vport_alloc 1 33475 _001050_hash NULL
85661 +_001051_hash p54_parse_rssical 3 64493 _001051_hash NULL
85662 +_001052_hash p9_client_zc_rpc 7 14345 _001052_hash NULL
85663 +_001053_hash packet_sendmsg_spkt 4 28885 _001053_hash NULL
85664 +_001054_hash pair_device 4 61175 _003161_hash NULL nohasharray
85665 +_001055_hash pccard_store_cis 6 18176 _001055_hash NULL
85666 +_001056_hash pci_add_cap_save_buffer 3 3426 _001056_hash NULL
85667 +_001057_hash pcnet32_realloc_rx_ring 3 36598 _001057_hash NULL
85668 +_001058_hash pcnet32_realloc_tx_ring 3 38428 _001058_hash NULL
85669 +_001059_hash pcpu_mem_zalloc 1 22948 _001059_hash NULL
85670 +_001060_hash pep_sendmsg 4 62524 _001060_hash NULL
85671 +_001061_hash pfkey_sendmsg 4 47394 _001061_hash NULL
85672 +_001062_hash pidlist_resize 2 496 _001062_hash NULL
85673 +_001063_hash pin_code_reply 4 46510 _001063_hash NULL
85674 +_001064_hash ping_getfrag 3-4 8360 _001064_hash NULL
85675 +_001066_hash pipe_set_size 2 5204 _001066_hash NULL
85676 +_001067_hash pkt_bio_alloc 1 48284 _001067_hash NULL
85677 +_001068_hash platform_create_bundle 4-6 12785 _001068_hash NULL
85678 +_001070_hash pm8001_store_update_fw 4 55716 _001070_hash NULL
85679 +_001071_hash pmcraid_alloc_sglist 1 9864 _001071_hash NULL
85680 +_001072_hash pn533_dep_link_up 5 22154 _001072_hash NULL
85681 +_001073_hash pn533_init_target_frame 3 65438 _001073_hash NULL
85682 +_001074_hash pnp_alloc 1 24869 _001538_hash NULL nohasharray
85683 +_001075_hash pn_sendmsg 4 12640 _001075_hash NULL
85684 +_001076_hash pppoe_sendmsg 4 48039 _001076_hash NULL
85685 +_001077_hash pppol2tp_sendmsg 4 56420 _001077_hash NULL
85686 +_001078_hash prism2_info_hostscanresults 3 39657 _001078_hash NULL
85687 +_001079_hash process_vm_rw 3-5 47533 _001079_hash NULL
85688 +_001081_hash process_vm_rw_single_vec 1-2 26213 _001081_hash NULL
85689 +_001083_hash proc_write 3 51003 _001083_hash NULL
85690 +_001084_hash profile_load 3 58267 _001084_hash NULL
85691 +_001085_hash profile_remove 3 8556 _001085_hash NULL
85692 +_001086_hash profile_replace 3 14652 _001086_hash NULL
85693 +_001087_hash pscsi_get_bio 1 56103 _001087_hash NULL
85694 +_001088_hash __pskb_copy 2 9038 _001088_hash NULL
85695 +_001089_hash __pskb_pull_tail 2 60287 _001089_hash NULL
85696 +_001090_hash qla4xxx_alloc_work 2 44813 _001090_hash NULL
85697 +_001091_hash qlcnic_alloc_msix_entries 2 46160 _001091_hash NULL
85698 +_001092_hash qlcnic_alloc_sds_rings 2 26795 _001092_hash NULL
85699 +_001093_hash queue_received_packet 5 9657 _001093_hash NULL
85700 +_001094_hash raw_send_hdrinc 4 58803 _001094_hash NULL
85701 +_001095_hash raw_sendmsg 4 23078 _003316_hash NULL nohasharray
85702 +_001096_hash rawsock_sendmsg 4 60010 _001096_hash NULL
85703 +_001097_hash rawv6_send_hdrinc 3 35425 _001097_hash NULL
85704 +_001098_hash rawv6_setsockopt 5 56165 _001098_hash NULL
85705 +_001099_hash rb_alloc 1 3102 _001099_hash NULL
85706 +_001100_hash rbd_alloc_coll 1 33678 _001100_hash NULL
85707 +_001101_hash rbd_create_rw_ops 1 55297 _001101_hash NULL
85708 +_001102_hash rds_ib_inc_copy_to_user 3 55007 _001102_hash NULL
85709 +_001103_hash rds_iw_inc_copy_to_user 3 29214 _001103_hash NULL
85710 +_001104_hash rds_message_alloc 1 10517 _001104_hash NULL
85711 +_001105_hash rds_message_copy_from_user 3 45510 _001105_hash NULL
85712 +_001106_hash rds_message_inc_copy_to_user 3 26540 _001106_hash NULL
85713 +_001107_hash regcache_rbtree_insert_to_block 5 58009 _001107_hash NULL
85714 +_001108_hash _regmap_raw_write 4 42652 _001108_hash NULL
85715 +_001109_hash regmap_register_patch 3 21681 _001109_hash NULL
85716 +_001110_hash relay_alloc_page_array 1 52735 _001110_hash NULL
85717 +_001111_hash remove_uuid 4 64505 _001111_hash NULL
85718 +_001112_hash reshape_ring 2 29147 _001112_hash NULL
85719 +_001113_hash RESIZE_IF_NEEDED 2 56286 _001113_hash NULL
85720 +_001114_hash resize_info_buffer 2 62889 _001114_hash NULL
85721 +_001115_hash resize_stripes 2 61650 _001115_hash NULL
85722 +_001116_hash rfcomm_sock_sendmsg 4 37661 _003661_hash NULL nohasharray
85723 +_001117_hash roccat_common2_send_with_status 4 50343 _001117_hash NULL
85724 +_001118_hash rose_sendmsg 4 20249 _001118_hash NULL
85725 +_001119_hash rsc_mgr_init 3 16299 _001119_hash NULL
85726 +_001120_hash rxrpc_send_data 5 21553 _001120_hash NULL
85727 +_001121_hash rxrpc_setsockopt 5 50286 _001121_hash NULL
85728 +_001122_hash savu_sysfs_read 6 49473 _001122_hash NULL
85729 +_001124_hash sco_send_frame 3 41815 _001124_hash NULL
85730 +_001125_hash scsi_dispatch_cmd_entry 3 49848 _001125_hash NULL
85731 +_001126_hash scsi_host_alloc 2 63041 _001126_hash NULL
85732 +_001127_hash scsi_tgt_kspace_exec 8 9522 _001127_hash NULL
85733 +_001128_hash sctp_sendmsg 4 61919 _001128_hash NULL
85734 +_001129_hash sctp_setsockopt 5 44788 _001129_hash NULL
85735 +_001130_hash sctp_setsockopt_connectx 3 6073 _001130_hash NULL
85736 +_001131_hash sctp_setsockopt_connectx_old 3 22631 _001131_hash NULL
85737 +_001132_hash sctp_tsnmap_grow 2 32784 _001132_hash NULL
85738 +_001133_hash sctp_tsnmap_init 2 36446 _001133_hash NULL
85739 +_001134_hash sctp_user_addto_chunk 2-3 62047 _001134_hash NULL
85740 +_001136_hash security_context_to_sid 2 19839 _001136_hash NULL
85741 +_001137_hash security_context_to_sid_default 2 3492 _003841_hash NULL nohasharray
85742 +_001138_hash security_context_to_sid_force 2 20724 _001138_hash NULL
85743 +_001139_hash self_check_write 5 50856 _001139_hash NULL
85744 +_001140_hash selinux_transaction_write 3 59038 _001140_hash NULL
85745 +_001141_hash sel_write_access 3 51704 _001141_hash NULL
85746 +_001142_hash sel_write_create 3 11353 _001142_hash NULL
85747 +_001143_hash sel_write_member 3 28800 _001143_hash NULL
85748 +_001144_hash sel_write_relabel 3 55195 _001144_hash NULL
85749 +_001145_hash sel_write_user 3 45060 _001145_hash NULL
85750 +_001146_hash __seq_open_private 3 40715 _001146_hash NULL
85751 +_001147_hash serverworks_create_gatt_pages 1 46582 _001147_hash NULL
85752 +_001148_hash set_connectable 4 56458 _001148_hash NULL
85753 +_001149_hash set_dev_class 4 39645 _001921_hash NULL nohasharray
85754 +_001150_hash set_discoverable 4 48141 _001150_hash NULL
85755 +_001151_hash set_fd_set 1 35249 _001151_hash NULL
85756 +_001152_hash setkey 3 14987 _001152_hash NULL
85757 +_001153_hash set_le 4 30581 _001153_hash NULL
85758 +_001154_hash set_link_security 4 4502 _001154_hash NULL
85759 +_001155_hash set_local_name 4 55757 _001155_hash NULL
85760 +_001156_hash set_powered 4 12129 _001156_hash NULL
85761 +_001157_hash set_ssp 4 62411 _001157_hash NULL
85762 +_001158_hash sg_build_sgat 3 60179 _001158_hash &_000314_hash
85763 +_001159_hash sg_read_oxfer 3 51724 _001159_hash NULL
85764 +_001160_hash shmem_xattr_set 4 11843 _001160_hash NULL
85765 +_001161_hash simple_alloc_urb 3 60420 _001161_hash NULL
85766 +_001162_hash sisusb_send_bridge_packet 2 11649 _001162_hash NULL
85767 +_001163_hash sisusb_send_packet 2 20891 _001163_hash NULL
85768 +_001164_hash sisusb_write_mem_bulk 4 29678 _001164_hash NULL
85769 +_001165_hash skb_add_data_nocache 4 4682 _001165_hash NULL
85770 +_001166_hash skb_copy_datagram_from_iovec 2-5-4 52014 _001166_hash NULL
85771 +_001169_hash skb_copy_expand 2-3 7685 _001169_hash &_000677_hash
85772 +_001171_hash skb_copy_to_page_nocache 6 58624 _001171_hash NULL
85773 +_001172_hash __skb_cow 2 39254 _001172_hash NULL
85774 +_001173_hash skb_cow_data 2 11565 _001173_hash NULL
85775 +_001174_hash skb_pad 2 17302 _001174_hash NULL
85776 +_001175_hash skb_realloc_headroom 2 19516 _001175_hash NULL
85777 +_001176_hash sk_chk_filter 2 42095 _001176_hash NULL
85778 +_001177_hash skcipher_sendmsg 4 30290 _001177_hash NULL
85779 +_001178_hash sl_change_mtu 2 7396 _001178_hash NULL
85780 +_001179_hash slhc_init 1-2 58135 _001179_hash &_000931_hash
85781 +_001181_hash sm501_create_subdev 3-4 48668 _001245_hash NULL nohasharray
85782 +_001183_hash smk_user_access 3 24440 _001183_hash NULL
85783 +_001184_hash smk_write_cipso2 3 1021 _001184_hash NULL
85784 +_001185_hash smk_write_cipso 3 17989 _001185_hash NULL
85785 +_001186_hash smk_write_load2 3 52155 _001186_hash NULL
85786 +_001187_hash smk_write_load 3 26829 _001187_hash NULL
85787 +_001188_hash smk_write_load_self2 3 591 _001188_hash NULL
85788 +_001189_hash smk_write_load_self 3 7958 _001189_hash NULL
85789 +_001190_hash snapshot_write 3 28351 _001190_hash NULL
85790 +_001191_hash snd_ac97_pcm_assign 2 30218 _001191_hash NULL
85791 +_001192_hash snd_card_create 4 64418 _001529_hash NULL nohasharray
85792 +_001193_hash snd_emux_create_port 3 42533 _001193_hash NULL
85793 +_001194_hash snd_gus_dram_write 4 38784 _001194_hash NULL
85794 +_001195_hash snd_midi_channel_alloc_set 1 28153 _001195_hash NULL
85795 +_001196_hash _snd_pcm_lib_alloc_vmalloc_buffer 2 17820 _001196_hash NULL
85796 +_001197_hash snd_pcm_oss_sync1 2 45298 _001197_hash NULL
85797 +_001198_hash snd_pcm_oss_write 3 38108 _001198_hash NULL
85798 +_001199_hash snd_pcm_plugin_build 5 25505 _001199_hash NULL
85799 +_001200_hash snd_rawmidi_kernel_write 3 25106 _001200_hash NULL
85800 +_001201_hash snd_rawmidi_write 3 28008 _001201_hash NULL
85801 +_001202_hash snd_rme32_playback_copy 5 43732 _001202_hash NULL
85802 +_001203_hash snd_rme96_playback_copy 5 13111 _001203_hash NULL
85803 +_001204_hash snd_seq_device_new 4 31753 _001204_hash NULL
85804 +_001205_hash snd_seq_oss_readq_new 2 14283 _001205_hash NULL
85805 +_001206_hash snd_vx_create 4 40948 _001206_hash NULL
85806 +_001207_hash sock_setsockopt 5 50088 _001207_hash NULL
85807 +_001208_hash sound_write 3 5102 _001208_hash NULL
85808 +_001209_hash _sp2d_alloc 1-3-2 16944 _001209_hash NULL
85809 +_001212_hash spi_alloc_master 2 45223 _001212_hash NULL
85810 +_001213_hash spidev_message 3 5518 _001213_hash NULL
85811 +_001214_hash spi_register_board_info 2 35651 _001214_hash NULL
85812 +_001215_hash squashfs_cache_init 2 41656 _001215_hash NULL
85813 +_001216_hash squashfs_read_data 6 59440 _001216_hash NULL
85814 +_001217_hash squashfs_read_fragment_index_table 4 2506 _001217_hash NULL
85815 +_001218_hash squashfs_read_id_index_table 4 61961 _001218_hash NULL
85816 +_001219_hash squashfs_read_inode_lookup_table 4 64739 _001219_hash NULL
85817 +_001220_hash srp_alloc_iu 2 44227 _001220_hash NULL
85818 +_001221_hash srp_iu_pool_alloc 2 17920 _001221_hash NULL
85819 +_001222_hash srp_ring_alloc 2 26760 _001222_hash NULL
85820 +_001226_hash start_isoc_chain 2 565 _001226_hash NULL
85821 +_001227_hash st_write 3 16874 _001227_hash NULL
85822 +_001228_hash svc_pool_map_alloc_arrays 2 47181 _001228_hash NULL
85823 +_001229_hash symtab_init 2 61050 _001229_hash NULL
85824 +_001230_hash sys_bind 3 10799 _001230_hash NULL
85825 +_001231_hash sys_connect 3 15291 _003816_hash NULL nohasharray
85826 +_001232_hash sys_flistxattr 3 41407 _001232_hash NULL
85827 +_001233_hash sys_fsetxattr 4 49736 _001233_hash NULL
85828 +_001234_hash sysfs_write_file 3 57116 _001234_hash NULL
85829 +_001235_hash sys_ipc 3 4889 _001235_hash NULL
85830 +_001236_hash sys_keyctl 4 33708 _001236_hash &_001011_hash
85831 +_001237_hash sys_listxattr 3 27833 _001237_hash NULL
85832 +_001238_hash sys_llistxattr 3 4532 _001238_hash NULL
85833 +_001239_hash sys_lsetxattr 4 61177 _001239_hash NULL
85834 +_001240_hash sys_mq_timedsend 3 57661 _001240_hash NULL
85835 +_001241_hash sys_sched_setaffinity 2 32046 _001241_hash NULL
85836 +_001242_hash sys_select 1 38827 _001242_hash NULL
85837 +_001243_hash sys_semop 3 39457 _001243_hash NULL
85838 +_001244_hash sys_sendto 6 20809 _001244_hash NULL
85839 +_001245_hash sys_setgroups 1 48668 _001245_hash &_001181_hash
85840 +_001246_hash sys_setgroups16 1 48882 _001246_hash NULL
85841 +_001247_hash sys_setxattr 4 37880 _001247_hash NULL
85842 +_001248_hash t4_alloc_mem 1 32342 _001248_hash NULL
85843 +_001249_hash tcf_hash_create 4 54360 _001249_hash NULL
85844 +_001250_hash tcp_send_rcvq 3 11316 _001250_hash NULL
85845 +_001251_hash __team_options_register 3 63941 _001251_hash NULL
85846 +_001252_hash test_unaligned_bulk 3 52333 _001252_hash NULL
85847 +_001253_hash tifm_alloc_adapter 1 10903 _001253_hash NULL
85848 +_001254_hash timeout_write 3 50991 _001254_hash NULL
85849 +_001255_hash timeradd_entry 3 49850 _001255_hash NULL
85850 +_001256_hash tipc_link_send_sections_fast 4 37920 _001256_hash NULL
85851 +_001257_hash tipc_subseq_alloc 1 5957 _001257_hash NULL
85852 +_001258_hash tnode_alloc 1 49407 _001258_hash NULL
85853 +_001259_hash tomoyo_commit_ok 2 20167 _001259_hash NULL
85854 +_001260_hash tomoyo_scan_bprm 2-4 15642 _003488_hash NULL nohasharray
85855 +_001262_hash tps6586x_writes 3 58689 _001262_hash NULL
85856 +_001263_hash tty_buffer_find 2 2443 _001263_hash NULL
85857 +_001264_hash tty_write 3 5494 _001264_hash NULL
85858 +_001265_hash ubifs_setxattr 4 59650 _001477_hash NULL nohasharray
85859 +_001266_hash ubi_self_check_all_ff 4 41959 _001266_hash NULL
85860 +_001267_hash udf_sb_alloc_partition_maps 2 62313 _001267_hash NULL
85861 +_001268_hash udplite_getfrag 3-4 14479 _001268_hash NULL
85862 +_001270_hash ulong_write_file 3 26485 _001270_hash NULL
85863 +_001271_hash unix_stream_sendmsg 4 61455 _001271_hash NULL
85864 +_001272_hash unlink_queued 3-4 645 _001272_hash NULL
85865 +_001273_hash update_pmkid 4 2481 _001273_hash NULL
85866 +_001274_hash usb_alloc_coherent 2 65444 _001274_hash NULL
85867 +_001275_hash vc_resize 2-3 3585 _001275_hash NULL
85868 +_001277_hash vhci_write 3 2224 _001277_hash NULL
85869 +_001278_hash __vhost_add_used_n 3 26554 _001278_hash NULL
85870 +_001279_hash virtqueue_add_buf 3-4 59470 _001279_hash NULL
85871 +_001281_hash vmalloc 1 15464 _001281_hash NULL
85872 +_001282_hash vol_cdev_write 3 40915 _001282_hash NULL
85873 +_001283_hash vxge_device_register 4 7752 _001283_hash NULL
85874 +_001284_hash __vxge_hw_blockpool_malloc 2 5786 _001284_hash NULL
85875 +_001285_hash __vxge_hw_channel_allocate 3 55462 _001285_hash NULL
85876 +_001286_hash vzalloc 1 47421 _001286_hash NULL
85877 +_001287_hash vzalloc_node 1 23424 _001287_hash NULL
85878 +_001288_hash wa_nep_queue 2 8858 _001288_hash NULL
85879 +_001289_hash __wa_xfer_setup_segs 2 56725 _001289_hash NULL
85880 +_001290_hash wiphy_new 2 2482 _001290_hash NULL
85881 +_001291_hash wm8350_block_write 3 19727 _001291_hash NULL
85882 +_001292_hash wpan_phy_alloc 1 48056 _001292_hash NULL
85883 +_001293_hash write_flush_pipefs 3 2021 _001293_hash NULL
85884 +_001294_hash write_flush_procfs 3 44011 _001294_hash NULL
85885 +_001295_hash wusb_ccm_mac 7 32199 _001295_hash NULL
85886 +_001296_hash x25_sendmsg 4 12487 _001296_hash NULL
85887 +_001297_hash xfrm_hash_alloc 1 10997 _001297_hash NULL
85888 +_001298_hash _xfs_buf_get_pages 2 46811 _001298_hash NULL
85889 +_001299_hash xfs_da_grow_inode_int 3 21785 _001299_hash NULL
85890 +_001300_hash xfs_dir_cilookup_result 3 64288 _003160_hash NULL nohasharray
85891 +_001301_hash xfs_idata_realloc 2 26199 _001301_hash NULL
85892 +_001302_hash xfs_iext_add_indirect_multi 3 32400 _001302_hash NULL
85893 +_001303_hash xfs_iext_inline_to_direct 2 12384 _001303_hash NULL
85894 +_001304_hash xfs_iformat_local 4 49472 _001304_hash NULL
85895 +_001305_hash xfs_iroot_realloc 2 46826 _001305_hash NULL
85896 +_001306_hash xhci_alloc_stream_info 3 63902 _001306_hash NULL
85897 +_001307_hash xlog_recover_add_to_trans 4 62839 _001307_hash NULL
85898 +_001308_hash xprt_alloc 2 1475 _001308_hash NULL
85899 +_001309_hash xt_alloc_table_info 1 57903 _001309_hash NULL
85900 +_001310_hash _zd_iowrite32v_async_locked 3 39034 _001310_hash NULL
85901 +_001311_hash zd_usb_iowrite16v 3 49744 _001311_hash NULL
85902 +_001312_hash a2mp_send 4 41615 _001312_hash NULL
85903 +_001313_hash acpi_ds_build_internal_package_obj 3 58271 _001313_hash NULL
85904 +_001314_hash acpi_system_read_event 3 55362 _001314_hash NULL
85905 +_001315_hash acpi_ut_create_buffer_object 1 42030 _001315_hash NULL
85906 +_001316_hash acpi_ut_create_package_object 1 17594 _001316_hash NULL
85907 +_001317_hash acpi_ut_create_string_object 1 15360 _001317_hash NULL
85908 +_001318_hash ad7879_spi_multi_read 3 8218 _001318_hash NULL
85909 +_001319_hash add_child 4 45201 _001319_hash NULL
85910 +_001320_hash add_port 2 54941 _001320_hash NULL
85911 +_001321_hash adu_read 3 24177 _001321_hash NULL
85912 +_001322_hash afs_cell_create 2 27346 _001322_hash NULL
85913 +_001323_hash agp_allocate_memory 2 58761 _001323_hash NULL
85914 +_001324_hash agp_generic_alloc_user 1 9470 _001324_hash NULL
85915 +_001325_hash alc_auto_create_extra_outs 2 18975 _001325_hash NULL
85916 +_001326_hash alloc_agpphysmem_i8xx 1 39427 _001326_hash NULL
85917 +_001327_hash allocate_cnodes 1 5329 _001327_hash NULL
85918 +_001328_hash ___alloc_bootmem 1 11410 _001328_hash NULL
85919 +_001329_hash __alloc_bootmem_low_node 2 25726 _001662_hash NULL nohasharray
85920 +_001330_hash __alloc_bootmem_node 2 1992 _001330_hash NULL
85921 +_001331_hash __alloc_bootmem_node_nopanic 2 6432 _001331_hash NULL
85922 +_001332_hash __alloc_bootmem_nopanic 1 65397 _001332_hash NULL
85923 +_001333_hash alloc_candev 1-2 7776 _001333_hash NULL
85924 +_001335_hash _alloc_cdb_cont 2 23609 _001335_hash NULL
85925 +_001336_hash alloc_dummy_extent_buffer 2 56374 _001336_hash NULL
85926 +_001337_hash ____alloc_ei_netdev 1 51475 _001337_hash NULL
85927 +_001338_hash alloc_etherdev_mqs 1 36450 _001338_hash NULL
85928 +_001339_hash alloc_extent_buffer 3 52824 _001339_hash NULL
85929 +_001340_hash alloc_fcdev 1 18780 _001340_hash NULL
85930 +_001341_hash alloc_fddidev 1 15382 _001341_hash NULL
85931 +_001342_hash _alloc_get_attr_desc 2 470 _001342_hash NULL
85932 +_001343_hash alloc_hippi_dev 1 51320 _001343_hash NULL
85933 +_001344_hash alloc_irdadev 1 19140 _001344_hash NULL
85934 +_001345_hash alloc_ldt 2 21972 _001345_hash NULL
85935 +_001346_hash alloc_ltalkdev 1 38071 _001346_hash NULL
85936 +_001347_hash alloc_one_pg_vec_page 1 10747 _001347_hash NULL
85937 +_001348_hash alloc_orinocodev 1 21371 _001348_hash NULL
85938 +_001349_hash alloc_ring 2-4 18278 _001349_hash NULL
85939 +_001351_hash _alloc_set_attr_list 4 48991 _001351_hash NULL
85940 +_001353_hash alloc_tx 2 32143 _001353_hash NULL
85941 +_001354_hash alloc_wr 1-2 24635 _001354_hash NULL
85942 +_001356_hash async_setkey 3 35521 _001356_hash NULL
85943 +_001357_hash ata_host_alloc_pinfo 3 17325 _001357_hash NULL
85944 +_001360_hash ath6kl_connect_event 7-9-8 14267 _001360_hash NULL
85945 +_001361_hash ath6kl_fwlog_block_read 3 49836 _001361_hash NULL
85946 +_001362_hash ath6kl_fwlog_read 3 32101 _001362_hash NULL
85947 +_001363_hash ath9k_wmi_cmd 4 327 _001363_hash NULL
85948 +_001364_hash ath_rx_init 2 43564 _001364_hash NULL
85949 +_001365_hash ath_tx_init 2 60515 _001365_hash NULL
85950 +_001366_hash atm_alloc_charge 2 19517 _001914_hash NULL nohasharray
85951 +_001367_hash atm_get_addr 3 31221 _001367_hash NULL
85952 +_001368_hash audit_log_n_hex 3 45617 _001368_hash NULL
85953 +_001369_hash audit_log_n_string 3 31705 _001369_hash NULL
85954 +_001370_hash ax25_output 2 22736 _001370_hash NULL
85955 +_001371_hash bcsp_prepare_pkt 3 12961 _001371_hash NULL
85956 +_001372_hash bdx_rxdb_create 1 46525 _001372_hash NULL
85957 +_001373_hash bdx_tx_db_init 2 41719 _001373_hash NULL
85958 +_001374_hash bio_map_kern 3 64751 _001374_hash NULL
85959 +_001375_hash bits_to_user 2-3 47733 _001375_hash NULL
85960 +_001377_hash __blk_queue_init_tags 2 9778 _001377_hash NULL
85961 +_001378_hash blk_queue_resize_tags 2 28670 _001378_hash NULL
85962 +_001379_hash blk_rq_map_user_iov 5 16772 _001379_hash NULL
85963 +_001380_hash bm_init 2 13529 _001380_hash NULL
85964 +_001381_hash brcmf_alloc_wdev 1 60347 _001381_hash NULL
85965 +_001382_hash __btrfs_buffered_write 3 35311 _002735_hash NULL nohasharray
85966 +_001383_hash btrfs_insert_dir_item 4 59304 _001383_hash NULL
85967 +_001384_hash btrfs_map_block 3 64379 _001384_hash NULL
85968 +_001385_hash bt_skb_alloc 1 6404 _001385_hash NULL
85969 +_001386_hash c4_add_card 3 54968 _001386_hash NULL
85970 +_001387_hash cache_read 3 24790 _001387_hash NULL
85971 +_001388_hash cache_write 3 13589 _001388_hash NULL
85972 +_001389_hash calc_hmac 3 32010 _001389_hash NULL
85973 +_001390_hash capinc_tty_write 3 28539 _001390_hash NULL
85974 +_001391_hash ccid_getsockopt_builtin_ccids 2 53634 _001391_hash NULL
85975 +_001392_hash ceph_copy_page_vector_to_user 3-4 31270 _001392_hash NULL
85976 +_001394_hash ceph_parse_server_name 2 60318 _001394_hash NULL
85977 +_001395_hash ceph_read_dir 3 17005 _001395_hash NULL
85978 +_001396_hash cfg80211_roamed 5-7 32632 _001396_hash NULL
85979 +_001398_hash cfpkt_add_body 3 44630 _001398_hash NULL
85980 +_001399_hash cfpkt_create_pfx 1-2 23594 _001399_hash NULL
85981 +_001401_hash cmd_complete 6 51629 _001401_hash NULL
85982 +_001402_hash cmtp_add_msgpart 4 9252 _001402_hash NULL
85983 +_001403_hash cmtp_send_interopmsg 7 376 _001403_hash NULL
85984 +_001404_hash coda_psdev_read 3 35029 _001404_hash NULL
85985 +_001405_hash construct_key_and_link 4 8321 _001405_hash NULL
85986 +_001406_hash copy_counters_to_user 5 17027 _001406_hash NULL
85987 +_001407_hash copy_entries_to_user 1 52367 _001407_hash NULL
85988 +_001408_hash copy_from_buf 2-4 27308 _001408_hash NULL
85989 +_001410_hash copy_oldmem_page 3-1 26164 _001410_hash NULL
85990 +_001411_hash copy_to_user_fromio 3 57432 _001411_hash NULL
85991 +_001412_hash cryptd_hash_setkey 3 42781 _001412_hash NULL
85992 +_001413_hash crypto_authenc_esn_setkey 3 6985 _001413_hash NULL
85993 +_001414_hash crypto_authenc_setkey 3 80 _001414_hash NULL
85994 +_001415_hash cxgb3_get_cpl_reply_skb 2 10620 _001415_hash NULL
85995 +_001416_hash cxgbi_ddp_reserve 4 30091 _001416_hash NULL
85996 +_001417_hash cxio_init_resource_fifo 3 28764 _001417_hash NULL
85997 +_001418_hash cxio_init_resource_fifo_random 3 47151 _001418_hash NULL
85998 +_001419_hash datablob_hmac_append 3 40038 _001419_hash NULL
85999 +_001420_hash datablob_hmac_verify 4 24786 _001420_hash NULL
86000 +_001421_hash dataflash_read_fact_otp 3-2 33204 _001421_hash NULL
86001 +_001422_hash dataflash_read_user_otp 3-2 14536 _001422_hash &_000207_hash
86002 +_001423_hash dccp_feat_register_sp 5 17914 _001423_hash NULL
86003 +_001424_hash dccp_setsockopt 5 60367 _001424_hash NULL
86004 +_001425_hash __dev_alloc_skb 1 28681 _001425_hash NULL
86005 +_001426_hash disk_expand_part_tbl 2 30561 _001426_hash NULL
86006 +_001427_hash diva_os_alloc_message_buffer 1 64568 _001427_hash NULL
86007 +_001428_hash diva_os_copy_to_user 4 48508 _001428_hash NULL
86008 +_001429_hash diva_os_malloc 2 16406 _001429_hash NULL
86009 +_001430_hash dmam_declare_coherent_memory 4-2 43679 _001430_hash NULL
86010 +_001431_hash dm_vcalloc 1-2 16814 _001431_hash NULL
86011 +_001433_hash dn_alloc_skb 2 6631 _001433_hash NULL
86012 +_001434_hash do_proc_readlink 3 14096 _001434_hash NULL
86013 +_001435_hash do_readlink 2 43518 _001435_hash NULL
86014 +_001436_hash __do_replace 5 37227 _001436_hash NULL
86015 +_001437_hash do_sigpending 2 9766 _001437_hash NULL
86016 +_001438_hash drbd_bm_resize 2 20522 _001438_hash NULL
86017 +_001439_hash drbd_setsockopt 5 16280 _001439_hash &_000383_hash
86018 +_001440_hash dump_midi 3 51040 _001440_hash NULL
86019 +_001441_hash ecryptfs_filldir 3 6622 _001441_hash NULL
86020 +_001442_hash ecryptfs_send_message 2 18322 _001442_hash NULL
86021 +_001443_hash ep0_read 3 38095 _001443_hash NULL
86022 +_001444_hash evdev_ioctl 2 22371 _001444_hash NULL
86023 +_001445_hash ext4_add_new_descs 3 19509 _001445_hash NULL
86024 +_001446_hash fat_ioctl_filldir 3 36621 _001446_hash NULL
86025 +_001447_hash _fc_frame_alloc 1 43568 _001447_hash NULL
86026 +_001448_hash fc_host_post_vendor_event 3 30903 _001448_hash NULL
86027 +_001449_hash fd_copyout 3 59323 _001449_hash NULL
86028 +_001450_hash f_hidg_read 3 6238 _001450_hash NULL
86029 +_001451_hash filldir 3 55137 _001451_hash NULL
86030 +_001452_hash filldir64 3 46469 _001452_hash NULL
86031 +_001453_hash find_skb 2 20431 _001453_hash NULL
86032 +_001454_hash from_buffer 3 18625 _001454_hash NULL
86033 +_001455_hash fsm_init 2 16134 _001455_hash NULL
86034 +_001456_hash fs_path_add 3 15648 _001456_hash NULL
86035 +_001457_hash fs_path_add_from_extent_buffer 4 27702 _001457_hash NULL
86036 +_001458_hash fuse_perform_write 4 18457 _001458_hash NULL
86037 +_001459_hash gem_alloc_skb 2 51715 _001459_hash NULL
86038 +_001460_hash generic_file_buffered_write 4 25464 _001460_hash NULL
86039 +_001461_hash gen_pool_add 3 21776 _001461_hash NULL
86040 +_001462_hash get_packet 3 41914 _001462_hash NULL
86041 +_001463_hash get_packet 3 5747 _001463_hash NULL
86042 +_001464_hash get_packet_pg 4 28023 _001464_hash NULL
86043 +_001465_hash get_skb 2 63008 _001465_hash NULL
86044 +_001466_hash get_subdir 3 62581 _001466_hash NULL
86045 +_001467_hash gsm_control_message 4 18209 _001467_hash NULL
86046 +_001468_hash gsm_control_modem 3 55303 _001468_hash NULL
86047 +_001469_hash gsm_control_rls 3 3353 _001469_hash NULL
86048 +_001470_hash handle_received_packet 3 22457 _001470_hash NULL
86049 +_001471_hash hash_setkey 3 48310 _001471_hash NULL
86050 +_001472_hash hdlcdrv_register 2 6792 _001472_hash NULL
86051 +_001473_hash hiddev_ioctl 2 36816 _001473_hash NULL
86052 +_001474_hash hid_input_report 4 32458 _001474_hash NULL
86053 +_001475_hash hidp_queue_report 3 1881 _001475_hash NULL
86054 +_001476_hash __hidp_send_ctrl_message 4 28303 _001476_hash NULL
86055 +_001477_hash hidraw_read 3 59650 _001477_hash &_001265_hash
86056 +_001478_hash HiSax_readstatus 2 15752 _001478_hash NULL
86057 +_001480_hash __hwahc_op_set_gtk 4 42038 _001480_hash NULL
86058 +_001481_hash __hwahc_op_set_ptk 5 36510 _001481_hash NULL
86059 +_001482_hash hycapi_rx_capipkt 3 11602 _001482_hash NULL
86060 +_001483_hash i2400m_net_rx 5 27170 _001483_hash NULL
86061 +_001484_hash ib_copy_to_udata 3 27525 _001484_hash NULL
86062 +_001485_hash idetape_chrdev_read 3 2097 _001485_hash NULL
86063 +_001486_hash ieee80211_alloc_hw 1 43829 _001486_hash NULL
86064 +_001487_hash ieee80211_bss_info_update 4 13991 _001487_hash NULL
86065 +_001488_hash igmpv3_newpack 2 35912 _001488_hash NULL
86066 +_001489_hash ilo_read 3 32531 _001489_hash NULL
86067 +_001490_hash init_map_ipmac 3-4 63896 _001490_hash NULL
86068 +_001492_hash init_tid_tabs 2-4-3 13252 _001492_hash NULL
86069 +_001495_hash iowarrior_read 3 53483 _001495_hash NULL
86070 +_001496_hash ip_options_get 4 56538 _001496_hash NULL
86071 +_001497_hash ipv6_getsockopt_sticky 5 56711 _001497_hash NULL
86072 +_001498_hash ipwireless_send_packet 4 8328 _001498_hash NULL
86073 +_001499_hash ipx_sendmsg 4 1362 _001499_hash NULL
86074 +_001500_hash irq_domain_add_linear 2 29236 _001500_hash NULL
86075 +_001501_hash iscsi_conn_setup 2 35159 _001501_hash NULL
86076 +_001502_hash iscsi_create_session 3 51647 _001502_hash NULL
86077 +_001503_hash iscsi_host_alloc 2 36671 _001503_hash NULL
86078 +_001504_hash iscsi_if_send_reply 7 52219 _001504_hash NULL
86079 +_001505_hash iscsi_offload_mesg 5 58425 _001505_hash NULL
86080 +_001506_hash iscsi_ping_comp_event 5 38263 _001506_hash NULL
86081 +_001507_hash iscsi_post_host_event 4 13473 _001507_hash NULL
86082 +_001508_hash iscsi_recv_pdu 4 16755 _001508_hash NULL
86083 +_001509_hash iscsi_session_setup 4-5 196 _001509_hash NULL
86084 +_001511_hash iscsit_find_cmd_from_itt_or_dump 3 17194 _003122_hash NULL nohasharray
86085 +_001512_hash isdn_net_ciscohdlck_alloc_skb 2 55209 _001951_hash NULL nohasharray
86086 +_001513_hash isdn_ppp_ccp_xmit_reset 6 63297 _001513_hash NULL
86087 +_001514_hash isdn_ppp_read 4 50356 _001514_hash NULL
86088 +_001515_hash isdn_ppp_skb_push 2 5236 _001515_hash NULL
86089 +_001516_hash isku_sysfs_read 6 58806 _001516_hash NULL
86090 +_001517_hash isku_sysfs_write 6 49767 _001517_hash NULL
86091 +_001520_hash jbd2_alloc 1 41359 _001520_hash NULL
86092 +_001521_hash jffs2_do_link 6 42048 _001521_hash NULL
86093 +_001522_hash jffs2_do_unlink 4 62020 _001522_hash NULL
86094 +_001523_hash jffs2_security_setxattr 4 62107 _001523_hash NULL
86095 +_001524_hash jffs2_trusted_setxattr 4 17048 _001524_hash NULL
86096 +_001525_hash jffs2_user_setxattr 4 10182 _001525_hash NULL
86097 +_001526_hash joydev_ioctl_common 2 49359 _001526_hash NULL
86098 +_001527_hash kernel_setsockopt 5 35913 _001527_hash NULL
86099 +_001528_hash keyctl_describe_key 3 36853 _001528_hash NULL
86100 +_001529_hash keyctl_get_security 3 64418 _001529_hash &_001192_hash
86101 +_001530_hash keyring_read 3 13438 _001530_hash NULL
86102 +_001531_hash kfifo_copy_to_user 3 20646 _001531_hash NULL
86103 +_001532_hash kmem_zalloc_large 1 56128 _001532_hash NULL
86104 +_001533_hash kmp_init 2 41373 _001533_hash NULL
86105 +_001534_hash koneplus_sysfs_write 6 35993 _001534_hash NULL
86106 +_001535_hash kvm_clear_guest_page 4 2308 _001535_hash NULL
86107 +_001536_hash kvm_read_nested_guest_page 5 13337 _001536_hash NULL
86108 +_001537_hash _l2_alloc_skb 1 11883 _001537_hash NULL
86109 +_001538_hash l2cap_create_basic_pdu 3 24869 _001538_hash &_001074_hash
86110 +_001539_hash l2cap_create_connless_pdu 3 37327 _001539_hash NULL
86111 +_001540_hash l2cap_create_iframe_pdu 3 40055 _001540_hash NULL
86112 +_001541_hash l3_alloc_skb 1 32289 _001541_hash NULL
86113 +_001542_hash __lgwrite 4 57669 _001542_hash NULL
86114 +_001543_hash libfc_host_alloc 2 7917 _001543_hash NULL
86115 +_001544_hash llc_alloc_frame 4 64366 _001544_hash NULL
86116 +_001545_hash llcp_sock_sendmsg 4 1092 _001545_hash NULL
86117 +_001546_hash mac_drv_rx_init 2 48898 _001546_hash NULL
86118 +_001547_hash macvtap_get_user 4 28185 _001547_hash NULL
86119 +_001548_hash mdc800_device_read 3 22896 _001548_hash NULL
86120 +_001549_hash memcpy_toiovec 3 54166 _001549_hash &_000892_hash
86121 +_001550_hash memcpy_toiovecend 3-4 19736 _001550_hash NULL
86122 +_001552_hash mempool_create 1 29437 _001552_hash NULL
86123 +_001553_hash mgmt_event 4 12810 _001553_hash NULL
86124 +_001554_hash mgt_set_varlen 4 60916 _001554_hash NULL
86125 +_001555_hash mI_alloc_skb 1 24770 _001555_hash NULL
86126 +_001556_hash mlx4_en_create_rx_ring 3 62498 _001556_hash NULL
86127 +_001557_hash mlx4_en_create_tx_ring 4 48501 _001557_hash NULL
86128 +_001558_hash mlx4_init_cmpt_table 3 11569 _001558_hash NULL
86129 +_001559_hash mon_bin_get_event 4 52863 _001559_hash NULL
86130 +_001560_hash mousedev_read 3 47123 _001560_hash NULL
86131 +_001561_hash move_addr_to_user 2 2868 _001561_hash NULL
86132 +_001562_hash mpihelp_mul 5-3 27805 _001562_hash NULL
86133 +_001564_hash mpi_set_buffer 3 65294 _001564_hash NULL
86134 +_001565_hash mptctl_ioctl 2 12355 _001565_hash NULL
86135 +_001566_hash msnd_fifo_alloc 2 23179 _001566_hash NULL
86136 +_001567_hash mtdswap_init 2 55719 _001567_hash NULL
86137 +_001568_hash mthca_alloc_resize_buf 3 60394 _001568_hash NULL
86138 +_001569_hash mthca_init_cq 2 60011 _001569_hash NULL
86139 +_001570_hash nci_skb_alloc 2 49757 _001570_hash NULL
86140 +_001571_hash neigh_hash_grow 2 17283 _001571_hash NULL
86141 +_001572_hash netdev_alloc_skb 2 62437 _001572_hash NULL
86142 +_001573_hash __netdev_alloc_skb_ip_align 2 55067 _001573_hash NULL
86143 +_001574_hash netlink_change_ngroups 2 16457 _001574_hash NULL
86144 +_001575_hash new_skb 1 21148 _001575_hash NULL
86145 +_001576_hash nfc_alloc_recv_skb 1 10244 _001576_hash NULL
86146 +_001577_hash nfcwilink_skb_alloc 1 16167 _001577_hash NULL
86147 +_001578_hash __nf_nat_mangle_tcp_packet 5-7 8190 _001578_hash NULL
86148 +_001580_hash nf_nat_mangle_udp_packet 5-7 13321 _001580_hash NULL
86149 +_001582_hash nfqnl_mangle 4-2 36226 _001582_hash NULL
86150 +_001583_hash nfs4_realloc_slot_table 2 22859 _001583_hash NULL
86151 +_001584_hash nfs_idmap_get_key 2 39616 _001584_hash NULL
86152 +_001585_hash nfs_readdata_alloc 2 65015 _001585_hash NULL
86153 +_001586_hash nfs_writedata_alloc 2 12133 _001586_hash NULL
86154 +_001587_hash nfulnl_alloc_skb 2 65207 _001587_hash NULL
86155 +_001588_hash ni65_alloc_mem 3 10664 _001588_hash NULL
86156 +_001589_hash nsm_get_handle 4 52089 _001589_hash NULL
86157 +_001590_hash ntfs_malloc_nofs 1 49572 _001590_hash NULL
86158 +_001591_hash ntfs_malloc_nofs_nofail 1 63631 _001591_hash NULL
86159 +_001592_hash nvme_create_queue 3 170 _001592_hash NULL
86160 +_001593_hash ocfs2_control_write 3 54737 _001593_hash NULL
86161 +_001595_hash orinoco_add_extscan_result 3 18207 _001595_hash NULL
86162 +_001596_hash osd_req_read_sg_kern 5 6378 _001596_hash NULL
86163 +_001597_hash osd_req_write_sg_kern 5 10514 _001597_hash NULL
86164 +_001599_hash override_release 2 52032 _001599_hash NULL
86165 +_001600_hash p9_client_read 5 19750 _001600_hash NULL
86166 +_001601_hash packet_snd 3 13634 _001601_hash NULL
86167 +_001602_hash pcbit_stat 2 27364 _001602_hash NULL
86168 +_001603_hash pcpu_extend_area_map 2 12589 _001603_hash NULL
86169 +_001604_hash pep_alloc_skb 3 46303 _001604_hash NULL
86170 +_001605_hash pg_read 3 17276 _001605_hash NULL
86171 +_001606_hash picolcd_debug_eeprom_read 3 14549 _001606_hash NULL
86172 +_001607_hash pkt_alloc_packet_data 1 37928 _001607_hash NULL
86173 +_001608_hash pmcraid_build_passthrough_ioadls 2 62034 _001608_hash NULL
86174 +_001609_hash pn_raw_send 2 54330 _001609_hash NULL
86175 +_001610_hash posix_clock_register 2 5662 _001610_hash NULL
86176 +_001611_hash printer_read 3 54851 _001611_hash NULL
86177 +_001612_hash __proc_file_read 3 54978 _001612_hash NULL
86178 +_001613_hash pskb_may_pull 2 22546 _001613_hash NULL
86179 +_001614_hash __pskb_pull 2 42602 _001614_hash NULL
86180 +_001615_hash ptp_read 4 63251 _001615_hash NULL
86181 +_001616_hash pt_read 3 49136 _001616_hash NULL
86182 +_001617_hash put_cmsg 4 36589 _001617_hash NULL
86183 +_001618_hash px_raw_event 4 49371 _001618_hash NULL
86184 +_001619_hash qla4xxx_post_aen_work 3 46953 _001619_hash NULL
86185 +_001620_hash qla4xxx_post_ping_evt_work 4 8074 _001819_hash NULL nohasharray
86186 +_001621_hash raid5_resize 2 63306 _001621_hash NULL
86187 +_001622_hash rawv6_sendmsg 4 20080 _001622_hash NULL
86188 +_001623_hash rds_message_map_pages 2 31487 _001623_hash NULL
86189 +_001624_hash rds_sendmsg 4 40976 _001624_hash NULL
86190 +_001625_hash read_flush 3 43851 _001625_hash NULL
86191 +_001626_hash read_profile 3 27859 _001626_hash NULL
86192 +_001627_hash read_vmcore 3 26501 _001627_hash NULL
86193 +_001628_hash redirected_tty_write 3 65297 _001628_hash NULL
86194 +_001629_hash refill_pool 2 19477 _001629_hash NULL
86195 +_001630_hash __register_chrdev 2-3 54223 _001630_hash NULL
86196 +_001632_hash regmap_raw_write 4 53803 _001632_hash NULL
86197 +_001633_hash reiserfs_allocate_list_bitmaps 3 21732 _001633_hash NULL
86198 +_001634_hash reiserfs_resize 2 34377 _001634_hash NULL
86199 +_001635_hash request_key_auth_read 3 24109 _001635_hash NULL
86200 +_001636_hash rfcomm_wmalloc 2 58090 _001636_hash NULL
86201 +_001637_hash rfkill_fop_read 3 54711 _001637_hash NULL
86202 +_001638_hash rng_dev_read 3 41581 _001638_hash NULL
86203 +_001639_hash roccat_read 3 41093 _001639_hash &_001034_hash
86204 +_001640_hash rx 4 57944 _001640_hash NULL
86205 +_001641_hash rxrpc_client_sendmsg 5 23236 _001641_hash NULL
86206 +_001642_hash rxrpc_kernel_send_data 3 60083 _001642_hash NULL
86207 +_001643_hash rxrpc_server_sendmsg 4 37331 _001643_hash NULL
86208 +_001644_hash savu_sysfs_write 6 42273 _001644_hash NULL
86209 +_001645_hash sco_sock_sendmsg 4 62542 _001645_hash NULL
86210 +_001646_hash scsi_nl_send_vendor_msg 5 16394 _001646_hash NULL
86211 +_001647_hash scsi_register 2 49094 _001647_hash NULL
86212 +_001648_hash sctp_datamsg_from_user 4 55342 _001648_hash NULL
86213 +_001649_hash sctp_getsockopt_events 2 3607 _001649_hash NULL
86214 +_001650_hash sctp_getsockopt_maxburst 2 42941 _001650_hash NULL
86215 +_001651_hash sctp_getsockopt_maxseg 2 10737 _001651_hash NULL
86216 +_001652_hash sctp_make_chunk 4 12986 _001652_hash NULL
86217 +_001653_hash sctpprobe_read 3 17741 _001653_hash NULL
86218 +_001654_hash sctp_tsnmap_mark 2 35929 _001654_hash NULL
86219 +_001655_hash sctp_ulpevent_new 1 33377 _001655_hash NULL
86220 +_001656_hash sdhci_alloc_host 2 7509 _001656_hash NULL
86221 +_001657_hash selinux_inode_post_setxattr 4 26037 _001657_hash NULL
86222 +_001658_hash selinux_inode_setsecurity 4 18148 _001658_hash NULL
86223 +_001659_hash selinux_inode_setxattr 4 10708 _001659_hash NULL
86224 +_001660_hash selinux_secctx_to_secid 2 63744 _001660_hash NULL
86225 +_001661_hash selinux_setprocattr 4 55611 _001661_hash NULL
86226 +_001662_hash sel_write_context 3 25726 _001662_hash &_001329_hash
86227 +_001663_hash send_command 4 10832 _001663_hash NULL
86228 +_001664_hash seq_copy_in_user 3 18543 _001664_hash NULL
86229 +_001665_hash seq_open_net 4 8968 _001779_hash NULL nohasharray
86230 +_001666_hash seq_open_private 3 61589 _001666_hash NULL
86231 +_001667_hash set_arg 3 42824 _001667_hash NULL
86232 +_001668_hash sg_read 3 25799 _001668_hash NULL
86233 +_001669_hash shash_async_setkey 3 10720 _003506_hash NULL nohasharray
86234 +_001670_hash shash_compat_setkey 3 12267 _001670_hash NULL
86235 +_001671_hash shmem_setxattr 4 55867 _001671_hash NULL
86236 +_001672_hash simple_read_from_buffer 2-5 55957 _001672_hash NULL
86237 +_001674_hash sisusb_clear_vram 2-3 57466 _001674_hash NULL
86238 +_001676_hash sisusbcon_do_font_op 9 52271 _001676_hash NULL
86239 +_001677_hash sisusb_copy_memory 4 35016 _001677_hash NULL
86240 +_001678_hash sisusb_write 3 44834 _001678_hash NULL
86241 +_001680_hash skb_cow 2 26138 _001680_hash NULL
86242 +_001681_hash skb_cow_head 2 52495 _001681_hash NULL
86243 +_001682_hash skb_make_writable 2 24783 _001682_hash NULL
86244 +_001683_hash skb_padto 2 50759 _001683_hash NULL
86245 +_001684_hash sk_stream_alloc_skb 2 57622 _001684_hash NULL
86246 +_001685_hash smk_write_access2 3 19170 _001685_hash NULL
86247 +_001686_hash smk_write_access 3 49561 _001686_hash NULL
86248 +_001687_hash snd_es1938_capture_copy 5 25930 _001687_hash NULL
86249 +_001688_hash snd_gus_dram_peek 4 9062 _001688_hash NULL
86250 +_001689_hash snd_hdsp_capture_copy 5 4011 _001689_hash NULL
86251 +_001690_hash snd_korg1212_copy_to 6 92 _001690_hash NULL
86252 +_001691_hash snd_opl4_mem_proc_read 5 63774 _001691_hash NULL
86253 +_001692_hash snd_pcm_oss_read1 3 63771 _001692_hash NULL
86254 +_001693_hash snd_pcm_plugin_alloc 2 12580 _001693_hash NULL
86255 +_001694_hash snd_rawmidi_kernel_read1 4 36740 _001694_hash NULL
86256 +_001695_hash snd_rme9652_capture_copy 5 10287 _001695_hash NULL
86257 +_001696_hash sock_alloc_send_pskb 2 21246 _001696_hash NULL
86258 +_001697_hash sock_rmalloc 2 59740 _002491_hash NULL nohasharray
86259 +_001698_hash sock_wmalloc 2 16472 _001698_hash NULL
86260 +_001699_hash solos_param_store 4 34755 _001699_hash NULL
86261 +_001702_hash srp_target_alloc 3 37288 _001702_hash NULL
86262 +_001703_hash store_ifalias 4 35088 _001703_hash NULL
86263 +_001704_hash store_msg 3 56417 _001704_hash NULL
86264 +_001705_hash str_to_user 2 11411 _001705_hash NULL
86265 +_001706_hash subbuf_read_actor 3 2071 _001706_hash NULL
86266 +_001707_hash sys_fgetxattr 4 25166 _001707_hash NULL
86267 +_001708_hash sys_gethostname 2 49698 _001708_hash NULL
86268 +_001709_hash sys_getxattr 4 37418 _001709_hash NULL
86269 +_001710_hash sys_init_module 2 36047 _001710_hash NULL
86270 +_001711_hash sys_kexec_load 2 14222 _001711_hash NULL
86271 +_001712_hash sys_lgetxattr 4 45531 _001712_hash NULL
86272 +_001713_hash syslog_print 2 307 _001713_hash NULL
86273 +_001714_hash sys_msgsnd 3 44537 _001714_hash &_000139_hash
86274 +_001715_hash sys_process_vm_readv 3-5 19090 _003104_hash NULL nohasharray
86275 +_001717_hash sys_process_vm_writev 3-5 4928 _001717_hash NULL
86276 +_001719_hash sys_pselect6 1 57449 _001719_hash NULL
86277 +_001720_hash sys_sched_getaffinity 2 60033 _001720_hash NULL
86278 +_001721_hash sys_setsockopt 5 35320 _001721_hash NULL
86279 +_001722_hash t3_init_l2t 1 8261 _001722_hash NULL
86280 +_001723_hash t4vf_pktgl_to_skb 2 39005 _001723_hash NULL
86281 +_001724_hash tcp_collapse 5-6 63294 _001724_hash NULL
86282 +_001726_hash tcp_sendmsg 4 30296 _001726_hash NULL
86283 +_001727_hash team_options_register 3 20091 _001727_hash NULL
86284 +_001728_hash tipc_buf_acquire 1 60437 _001728_hash NULL
86285 +_001729_hash tipc_cfg_reply_alloc 1 27606 _001729_hash NULL
86286 +_001730_hash tipc_send2name 6 16809 _001730_hash NULL
86287 +_001731_hash tipc_send2port 5 63935 _001731_hash NULL
86288 +_001732_hash tipc_send 4 51238 _001732_hash NULL
86289 +_001733_hash tnode_new 3 44757 _002769_hash NULL nohasharray
86290 +_001734_hash tomoyo_read_self 3 33539 _001734_hash NULL
86291 +_001735_hash tomoyo_update_domain 2 5498 _001735_hash NULL
86292 +_001736_hash tomoyo_update_policy 2 40458 _001736_hash NULL
86293 +_001737_hash tpm_read 3 50344 _001737_hash NULL
86294 +_001738_hash TSS_rawhmac 3 17486 _001738_hash NULL
86295 +_001739_hash __tty_buffer_request_room 2 27700 _001739_hash NULL
86296 +_001740_hash tun_get_user 4 39099 _001740_hash NULL
86297 +_001741_hash ubi_dump_flash 4 46381 _001741_hash NULL
86298 +_001742_hash ubi_io_write 4-5 15870 _003453_hash NULL nohasharray
86299 +_001744_hash udp_setsockopt 5 25985 _001744_hash NULL
86300 +_001745_hash udpv6_setsockopt 5 18487 _001745_hash NULL
86301 +_001746_hash uio_read 3 49300 _001746_hash NULL
86302 +_001747_hash ulog_alloc_skb 1 23427 _001747_hash NULL
86303 +_001748_hash unix_dgram_sendmsg 4 45699 _001748_hash NULL
86304 +_001749_hash unlink1 3 63059 _001749_hash NULL
86305 +_001751_hash usbdev_read 3 45114 _001751_hash NULL
86306 +_001752_hash usblp_ioctl 2 30203 _001752_hash NULL
86307 +_001753_hash usblp_read 3 57342 _003832_hash NULL nohasharray
86308 +_001754_hash usbtmc_read 3 32377 _001754_hash NULL
86309 +_001755_hash _usb_writeN_sync 4 31682 _001755_hash NULL
86310 +_001756_hash user_read 3 51881 _001756_hash NULL
86311 +_001757_hash vcs_read 3 8017 _001757_hash NULL
86312 +_001758_hash vdma_mem_alloc 1 6171 _001758_hash NULL
86313 +_001759_hash venus_create 4 20555 _001759_hash NULL
86314 +_001760_hash venus_link 5 32165 _001760_hash NULL
86315 +_001761_hash venus_lookup 4 8121 _001761_hash NULL
86316 +_001762_hash venus_mkdir 4 8967 _001762_hash NULL
86317 +_001763_hash venus_remove 4 59781 _001763_hash NULL
86318 +_001764_hash venus_rename 4-5 17707 _003784_hash NULL nohasharray
86319 +_001766_hash venus_rmdir 4 45564 _001766_hash NULL
86320 +_001767_hash venus_symlink 4-6 23570 _001767_hash NULL
86321 +_001769_hash vfs_readlink 3 54368 _001769_hash NULL
86322 +_001770_hash vfs_readv 3 38011 _001770_hash NULL
86323 +_001771_hash vfs_writev 3 25278 _001771_hash NULL
86324 +_001772_hash vga_arb_read 3 4886 _001772_hash NULL
86325 +_001773_hash vgacon_adjust_height 2 28124 _001773_hash NULL
86326 +_001774_hash vhci_put_user 4 12604 _001774_hash NULL
86327 +_001775_hash vhost_add_used_n 3 10760 _001775_hash NULL
86328 +_001776_hash virtnet_send_command 5-6 61993 _001776_hash NULL
86329 +_001778_hash vmbus_establish_gpadl 3 4495 _001778_hash NULL
86330 +_001779_hash vol_cdev_read 3 8968 _001779_hash &_001665_hash
86331 +_001780_hash wdm_read 3 6549 _001780_hash NULL
86332 +_001781_hash write_adapter_mem 3 3234 _001781_hash NULL
86333 +_001782_hash wusb_prf 7 54261 _001782_hash &_000065_hash
86334 +_001783_hash xdi_copy_to_user 4 48900 _001783_hash NULL
86335 +_001784_hash xfs_buf_associate_memory 3 17915 _001784_hash NULL
86336 +_001785_hash xfs_buf_get_maps 2 4581 _001785_hash NULL
86337 +_001786_hash xfs_buf_get_uncached 2 51477 _001786_hash NULL
86338 +_001787_hash xfs_buf_item_get_format 2 189 _001787_hash NULL
86339 +_001788_hash xfs_buf_map_from_irec 5 2368 _002641_hash NULL nohasharray
86340 +_001789_hash xfs_dir2_block_to_sf 3 37868 _001789_hash NULL
86341 +_001790_hash xfs_dir2_leaf_getdents 3 23841 _001790_hash NULL
86342 +_001791_hash xfs_dir2_sf_addname_hard 3 54254 _001791_hash NULL
86343 +_001792_hash xfs_efd_init 3 5463 _001792_hash NULL
86344 +_001793_hash xfs_efi_init 2 5476 _001793_hash NULL
86345 +_001794_hash xfs_iext_realloc_direct 2 20521 _001794_hash NULL
86346 +_001795_hash xfs_iext_realloc_indirect 2 59211 _001795_hash NULL
86347 +_001796_hash xfs_inumbers_fmt 3 12817 _001796_hash NULL
86348 +_001797_hash xhci_alloc_streams 5 37586 _001797_hash NULL
86349 +_001798_hash xlog_recover_add_to_cont_trans 4 44102 _001798_hash NULL
86350 +_001799_hash xz_dec_lzma2_create 2 36353 _002713_hash NULL nohasharray
86351 +_001800_hash _zd_iowrite32v_locked 3 44725 _001800_hash NULL
86352 +_001801_hash a2mp_chan_alloc_skb_cb 2 27159 _001801_hash NULL
86353 +_001802_hash aat2870_reg_read_file 3 12221 _001802_hash NULL
86354 +_001803_hash add_partition 2 55588 _001803_hash NULL
86355 +_001804_hash add_sctp_bind_addr 3 12269 _001804_hash NULL
86356 +_001805_hash _add_sg_continuation_descriptor 3 54721 _001805_hash NULL
86357 +_001806_hash afs_cell_lookup 2 8482 _001806_hash NULL
86358 +_001807_hash afs_send_simple_reply 3 63940 _001807_hash NULL
86359 +_001808_hash agp_allocate_memory_wrap 1 16576 _001808_hash NULL
86360 +_001809_hash __alloc_bootmem 1 31498 _001809_hash NULL
86361 +_001810_hash __alloc_bootmem_low 1 43423 _003425_hash NULL nohasharray
86362 +_001811_hash __alloc_bootmem_node_high 2 65076 _001811_hash NULL
86363 +_001812_hash alloc_cc770dev 1 48186 _001812_hash NULL
86364 +_001813_hash __alloc_ei_netdev 1 29338 _001813_hash NULL
86365 +_001814_hash __alloc_eip_netdev 1 51549 _001814_hash NULL
86366 +_001815_hash alloc_libipw 1 22708 _001815_hash NULL
86367 +_001816_hash _alloc_mISDN_skb 3 52232 _001816_hash NULL
86368 +_001817_hash alloc_pg_vec 2 8533 _001817_hash NULL
86369 +_001818_hash alloc_sja1000dev 1 17868 _001818_hash NULL
86370 +_001819_hash alloc_targets 2 8074 _001819_hash &_001620_hash
86371 +_001822_hash ath6kl_disconnect_timeout_read 3 3650 _001822_hash NULL
86372 +_001823_hash ath6kl_endpoint_stats_read 3 41554 _001823_hash NULL
86373 +_001824_hash ath6kl_fwlog_mask_read 3 2050 _001824_hash NULL
86374 +_001825_hash ath6kl_keepalive_read 3 44303 _001825_hash NULL
86375 +_001826_hash ath6kl_listen_int_read 3 10355 _001826_hash NULL
86376 +_001827_hash ath6kl_lrssi_roam_read 3 61022 _001827_hash NULL
86377 +_001828_hash ath6kl_regdump_read 3 14393 _001828_hash NULL
86378 +_001829_hash ath6kl_regread_read 3 25884 _001829_hash NULL
86379 +_001830_hash ath6kl_regwrite_read 3 48747 _001830_hash NULL
86380 +_001831_hash ath6kl_roam_table_read 3 26166 _001831_hash NULL
86381 +_001832_hash ath9k_debugfs_read_buf 3 25316 _001832_hash NULL
86382 +_001833_hash ath9k_multi_regread 4 65056 _001833_hash NULL
86383 +_001834_hash ath_rxbuf_alloc 2 24745 _001834_hash NULL
86384 +_001835_hash atk_debugfs_ggrp_read 3 29522 _001835_hash NULL
86385 +_001836_hash audit_log_n_untrustedstring 3 9548 _001836_hash NULL
86386 +_001837_hash ax25_send_frame 2 19964 _001837_hash NULL
86387 +_001838_hash b43_debugfs_read 3 24425 _001838_hash NULL
86388 +_001839_hash b43legacy_debugfs_read 3 2473 _001839_hash NULL
86389 +_001840_hash batadv_bla_is_backbone_gw 3 58488 _001840_hash NULL
86390 +_001841_hash batadv_check_management_packet 3 52993 _001841_hash NULL
86391 +_001842_hash batadv_check_unicast_packet 2 10866 _001842_hash NULL
86392 +_001843_hash batadv_interface_rx 4 8568 _001843_hash NULL
86393 +_001844_hash batadv_skb_head_push 2 11360 _001844_hash NULL
86394 +_001845_hash bchannel_get_rxbuf 2 37213 _001845_hash NULL
86395 +_001846_hash bcm_recvmsg 4 43992 _001846_hash NULL
86396 +_001847_hash bfad_debugfs_read 3 13119 _001847_hash NULL
86397 +_001848_hash bfad_debugfs_read_regrd 3 57830 _001848_hash NULL
86398 +_001849_hash blk_init_tags 1 30592 _001849_hash NULL
86399 +_001850_hash blk_queue_init_tags 2 44355 _001850_hash &_001022_hash
86400 +_001851_hash blk_rq_map_kern 4 47004 _001851_hash NULL
86401 +_001852_hash bm_entry_read 3 10976 _001852_hash NULL
86402 +_001853_hash bm_status_read 3 19583 _001853_hash NULL
86403 +_001854_hash bnad_debugfs_read 3 50665 _001854_hash NULL
86404 +_001855_hash bnad_debugfs_read_regrd 3 51308 _001855_hash NULL
86405 +_001856_hash bnx2i_send_nl_mesg 4 53353 _001856_hash NULL
86406 +_001857_hash brcmf_debugfs_sdio_counter_read 3 58369 _001857_hash NULL
86407 +_001858_hash brcmf_sdio_assert_info 4 52653 _001858_hash NULL
86408 +_001859_hash brcmf_sdio_dump_console 4 37455 _001859_hash NULL
86409 +_001860_hash brcmf_sdio_trap_info 4 48510 _001860_hash NULL
86410 +_001861_hash btmrvl_curpsmode_read 3 46939 _001861_hash NULL
86411 +_001862_hash btmrvl_gpiogap_read 3 4718 _001862_hash NULL
86412 +_001863_hash btmrvl_hscfgcmd_read 3 56303 _001863_hash NULL
86413 +_001864_hash btmrvl_hscmd_read 3 1614 _001864_hash NULL
86414 +_001865_hash btmrvl_hsmode_read 3 1647 _001865_hash NULL
86415 +_001866_hash btmrvl_hsstate_read 3 920 _001866_hash NULL
86416 +_001867_hash btmrvl_pscmd_read 3 24308 _001867_hash NULL
86417 +_001868_hash btmrvl_psmode_read 3 22395 _001868_hash NULL
86418 +_001869_hash btmrvl_psstate_read 3 50683 _001869_hash NULL
86419 +_001870_hash btmrvl_txdnldready_read 3 413 _001870_hash NULL
86420 +_001871_hash btrfs_add_link 5 9973 _001871_hash NULL
86421 +_001872_hash __btrfs_direct_write 4 22273 _001872_hash NULL
86422 +_001873_hash btrfs_discard_extent 2 38547 _001873_hash NULL
86423 +_001874_hash btrfs_file_aio_write 4 21520 _001874_hash NULL
86424 +_001875_hash btrfs_find_create_tree_block 3 55812 _001875_hash NULL
86425 +_001876_hash btrfsic_map_block 2 56751 _001876_hash NULL
86426 +_001877_hash cache_read_pipefs 3 47615 _001877_hash NULL
86427 +_001878_hash cache_read_procfs 3 52882 _001878_hash NULL
86428 +_001879_hash cache_write_pipefs 3 48270 _001879_hash NULL
86429 +_001880_hash cache_write_procfs 3 22491 _001880_hash NULL
86430 +_001881_hash caif_stream_recvmsg 4 13173 _001881_hash NULL
86431 +_001882_hash carl9170_alloc 1 27 _001882_hash NULL
86432 +_001883_hash carl9170_debugfs_read 3 47738 _001883_hash NULL
86433 +_001884_hash ceph_msgpool_init 4 34599 _001884_hash NULL
86434 +_001885_hash cfpkt_add_trail 3 27260 _001885_hash NULL
86435 +_001886_hash cfpkt_create 1 18197 _001886_hash NULL
86436 +_001887_hash cfpkt_pad_trail 2 55511 _003606_hash NULL nohasharray
86437 +_001888_hash cfpkt_split 2 47541 _001888_hash NULL
86438 +_001889_hash cgroup_read_s64 5 19570 _001889_hash NULL
86439 +_001890_hash cgroup_read_u64 5 45532 _001890_hash NULL
86440 +_001891_hash channel_type_read 3 47308 _001891_hash NULL
86441 +_001892_hash check_header 2 56930 _001892_hash NULL
86442 +_001893_hash codec_list_read_file 3 24910 _001893_hash NULL
86443 +_001894_hash configfs_read_file 3 1683 _001894_hash NULL
86444 +_001895_hash console_store 4 36007 _001895_hash NULL
86445 +_001896_hash cpuset_common_file_read 5 8800 _001896_hash NULL
86446 +_001897_hash create_subvol 4 30836 _001897_hash NULL
86447 +_001898_hash cxio_hal_init_resource 2-7-6 29771 _001898_hash &_000295_hash
86448 +_001901_hash cxio_hal_init_rhdl_resource 1 25104 _001901_hash NULL
86449 +_001902_hash dai_list_read_file 3 25421 _001902_hash NULL
86450 +_001903_hash dapm_bias_read_file 3 64715 _001903_hash NULL
86451 +_001904_hash dapm_widget_power_read_file 3 59950 _001983_hash NULL nohasharray
86452 +_001907_hash dbgfs_frame 3 45917 _001907_hash NULL
86453 +_001908_hash dbgfs_state 3 38894 _001908_hash NULL
86454 +_001909_hash dccp_manip_pkt 2 30229 _001909_hash NULL
86455 +_001910_hash ddp_ppod_write_idata 5 25610 _001910_hash NULL
86456 +_001911_hash debugfs_read 3 62535 _001911_hash NULL
86457 +_001912_hash debug_output 3 18575 _001912_hash NULL
86458 +_001913_hash debug_read 3 19322 _001913_hash NULL
86459 +_001914_hash dev_alloc_skb 1 19517 _001914_hash &_001366_hash
86460 +_001915_hash dfs_file_read 3 18116 _001915_hash NULL
86461 +_001916_hash diva_alloc_dma_map 2 23798 _001916_hash NULL
86462 +_001917_hash diva_xdi_write 4 63975 _001917_hash NULL
86463 +_001918_hash dma_memcpy_pg_to_iovec 6 1725 _001918_hash NULL
86464 +_001919_hash dma_memcpy_to_iovec 5 12173 _001919_hash NULL
86465 +_001920_hash dma_show_regs 3 35266 _001920_hash NULL
86466 +_001921_hash dm_exception_table_init 2 39645 _001921_hash &_001149_hash
86467 +_001922_hash dn_nsp_do_disc 2-6 49474 _001922_hash NULL
86468 +_001924_hash dn_recvmsg 4 17213 _001924_hash NULL
86469 +_001925_hash dns_resolver_read 3 54658 _001925_hash NULL
86470 +_001926_hash do_msgrcv 4 5590 _001926_hash NULL
86471 +_001927_hash do_syslog 3 56807 _001927_hash NULL
86472 +_001928_hash dpcm_state_read_file 3 65489 _001928_hash NULL
86473 +_001929_hash dsp_cmx_send_member 2 15625 _001929_hash NULL
86474 +_001930_hash fallback_on_nodma_alloc 2 35332 _001930_hash NULL
86475 +_001931_hash fc_frame_alloc 2 1596 _001931_hash NULL
86476 +_001932_hash fc_frame_alloc_fill 2 59394 _001932_hash NULL
86477 +_001933_hash filter_read 3 61692 _001933_hash NULL
86478 +_001934_hash __finish_unordered_dir 4 33198 _001934_hash NULL
86479 +_001935_hash format_devstat_counter 3 32550 _001935_hash NULL
86480 +_001936_hash fragmentation_threshold_read 3 61718 _001936_hash NULL
86481 +_001937_hash fuse_conn_limit_read 3 20084 _001937_hash NULL
86482 +_001938_hash fuse_conn_waiting_read 3 49762 _001938_hash NULL
86483 +_001939_hash fuse_file_aio_write 4 46399 _001939_hash NULL
86484 +_001940_hash generic_readlink 3 32654 _001940_hash NULL
86485 +_001941_hash gre_manip_pkt 2 38785 _001941_hash NULL
86486 +_001942_hash handle_eviocgbit 3 44193 _001942_hash NULL
86487 +_001943_hash handle_response 5 55951 _001943_hash NULL
86488 +_001944_hash handle_response_icmp 7 39574 _001944_hash NULL
86489 +_001945_hash hash_recvmsg 4 50924 _001945_hash NULL
86490 +_001946_hash hci_send_cmd 3 43810 _001946_hash NULL
86491 +_001947_hash hci_si_event 3 1404 _001947_hash NULL
86492 +_001948_hash help 4 14971 _001948_hash NULL
86493 +_001949_hash hfcpci_empty_bfifo 4 62323 _001949_hash NULL
86494 +_001950_hash hidp_send_ctrl_message 4 43702 _001950_hash NULL
86495 +_001951_hash ht40allow_map_read 3 55209 _001951_hash &_001512_hash
86496 +_001952_hash hwflags_read 3 52318 _001952_hash NULL
86497 +_001953_hash hysdn_conf_read 3 42324 _001953_hash NULL
86498 +_001954_hash hysdn_sched_rx 3 60533 _001954_hash NULL
86499 +_001955_hash i2400m_rx_stats_read 3 57706 _001955_hash NULL
86500 +_001956_hash i2400m_tx_stats_read 3 28527 _001956_hash NULL
86501 +_001957_hash icmp_manip_pkt 2 48801 _001957_hash NULL
86502 +_001958_hash idmouse_read 3 63374 _001958_hash NULL
86503 +_001959_hash ieee80211_if_read 3 6785 _001959_hash NULL
86504 +_001960_hash ieee80211_rx_bss_info 3 61630 _001960_hash NULL
86505 +_001961_hash ikconfig_read_current 3 1658 _001961_hash NULL
86506 +_001962_hash il3945_sta_dbgfs_stats_table_read 3 48802 _001962_hash NULL
86507 +_001963_hash il3945_ucode_general_stats_read 3 46111 _001963_hash NULL
86508 +_001964_hash il3945_ucode_rx_stats_read 3 3048 _001964_hash NULL
86509 +_001965_hash il3945_ucode_tx_stats_read 3 36016 _001965_hash NULL
86510 +_001966_hash il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 _001966_hash NULL
86511 +_001967_hash il4965_rs_sta_dbgfs_scale_table_read 3 38564 _001967_hash NULL
86512 +_001968_hash il4965_rs_sta_dbgfs_stats_table_read 3 49206 _001968_hash NULL
86513 +_001969_hash il4965_ucode_general_stats_read 3 56277 _001969_hash NULL
86514 +_001970_hash il4965_ucode_rx_stats_read 3 61948 _001970_hash NULL
86515 +_001971_hash il4965_ucode_tx_stats_read 3 12064 _001971_hash NULL
86516 +_001972_hash il_dbgfs_chain_noise_read 3 38044 _001972_hash NULL
86517 +_001973_hash il_dbgfs_channels_read 3 25005 _001973_hash NULL
86518 +_001974_hash il_dbgfs_disable_ht40_read 3 42386 _001974_hash NULL
86519 +_001975_hash il_dbgfs_fh_reg_read 3 40993 _001975_hash NULL
86520 +_001976_hash il_dbgfs_force_reset_read 3 57517 _001976_hash NULL
86521 +_001977_hash il_dbgfs_interrupt_read 3 3351 _001977_hash NULL
86522 +_001978_hash il_dbgfs_missed_beacon_read 3 59956 _001978_hash NULL
86523 +_001979_hash il_dbgfs_nvm_read 3 12288 _001979_hash NULL
86524 +_001980_hash il_dbgfs_power_save_status_read 3 43165 _001980_hash NULL
86525 +_001981_hash il_dbgfs_qos_read 3 33615 _001981_hash NULL
86526 +_001982_hash il_dbgfs_rxon_filter_flags_read 3 19281 _001982_hash NULL
86527 +_001983_hash il_dbgfs_rxon_flags_read 3 59950 _001983_hash &_001904_hash
86528 +_001984_hash il_dbgfs_rx_queue_read 3 11221 _001984_hash NULL
86529 +_001985_hash il_dbgfs_rx_stats_read 3 15243 _001985_hash NULL
86530 +_001986_hash il_dbgfs_sensitivity_read 3 2370 _001986_hash NULL
86531 +_001987_hash il_dbgfs_sram_read 3 62296 _001987_hash NULL
86532 +_001988_hash il_dbgfs_stations_read 3 21532 _001988_hash NULL
86533 +_001989_hash il_dbgfs_status_read 3 58388 _001989_hash NULL
86534 +_001990_hash il_dbgfs_tx_queue_read 3 55668 _001990_hash NULL
86535 +_001991_hash il_dbgfs_tx_stats_read 3 32913 _001991_hash NULL
86536 +_001992_hash ima_show_htable_value 2 57136 _001992_hash NULL
86537 +_001994_hash intel_fake_agp_alloc_by_type 1 1 _001994_hash NULL
86538 +_001995_hash ip4ip6_err 5 36772 _001995_hash NULL
86539 +_001996_hash ip6_append_data 4-5 36490 _003601_hash NULL nohasharray
86540 +_001997_hash ip6ip6_err 5 18308 _001997_hash NULL
86541 +_001998_hash __ip_append_data 7-8 36191 _001998_hash NULL
86542 +_001999_hash ip_vs_icmp_xmit 4 59624 _001999_hash NULL
86543 +_002000_hash ip_vs_icmp_xmit_v6 4 20464 _002000_hash NULL
86544 +_002001_hash ipw_write 3 59807 _002001_hash NULL
86545 +_002002_hash irda_recvmsg_stream 4 35280 _002002_hash NULL
86546 +_002003_hash irq_domain_add_simple 2 46734 _002003_hash NULL
86547 +_002004_hash __iscsi_complete_pdu 4 10726 _002004_hash NULL
86548 +_002005_hash iscsi_nop_out_rsp 4 51117 _002005_hash NULL
86549 +_002006_hash iscsi_tcp_conn_setup 2 16376 _002006_hash NULL
86550 +_002007_hash iwl_dbgfs_bt_traffic_read 3 35534 _002007_hash NULL
86551 +_002008_hash iwl_dbgfs_calib_disabled_read 3 22649 _002008_hash NULL
86552 +_002009_hash iwl_dbgfs_chain_noise_read 3 46355 _002009_hash NULL
86553 +_002010_hash iwl_dbgfs_channels_read 3 6784 _002010_hash NULL
86554 +_002011_hash iwl_dbgfs_current_sleep_command_read 3 2081 _002011_hash NULL
86555 +_002012_hash iwl_dbgfs_disable_ht40_read 3 35761 _002012_hash NULL
86556 +_002013_hash iwl_dbgfs_fh_reg_read 3 879 _002013_hash &_000406_hash
86557 +_002014_hash iwl_dbgfs_interrupt_read 3 23574 _002014_hash NULL
86558 +_002015_hash iwl_dbgfs_log_event_read 3 2107 _002015_hash NULL
86559 +_002016_hash iwl_dbgfs_missed_beacon_read 3 50584 _002016_hash NULL
86560 +_002017_hash iwl_dbgfs_nvm_read 3 23845 _002017_hash NULL
86561 +_002018_hash iwl_dbgfs_plcp_delta_read 3 55407 _002018_hash NULL
86562 +_002019_hash iwl_dbgfs_power_save_status_read 3 54392 _002019_hash NULL
86563 +_002020_hash iwl_dbgfs_protection_mode_read 3 13943 _002020_hash NULL
86564 +_002021_hash iwl_dbgfs_qos_read 3 11753 _002021_hash NULL
86565 +_002022_hash iwl_dbgfs_reply_tx_error_read 3 19205 _002022_hash NULL
86566 +_002023_hash iwl_dbgfs_rf_reset_read 3 26512 _002023_hash NULL
86567 +_002024_hash iwl_dbgfs_rx_handlers_read 3 18708 _002024_hash NULL
86568 +_002025_hash iwl_dbgfs_rxon_filter_flags_read 3 28832 _002025_hash NULL
86569 +_002026_hash iwl_dbgfs_rxon_flags_read 3 20795 _002026_hash NULL
86570 +_002027_hash iwl_dbgfs_rx_queue_read 3 19943 _002027_hash NULL
86571 +_002028_hash iwl_dbgfs_sensitivity_read 3 63116 _002731_hash NULL nohasharray
86572 +_002029_hash iwl_dbgfs_sleep_level_override_read 3 3038 _002029_hash NULL
86573 +_002030_hash iwl_dbgfs_sram_read 3 44505 _002030_hash NULL
86574 +_002031_hash iwl_dbgfs_stations_read 3 9309 _002031_hash NULL
86575 +_002032_hash iwl_dbgfs_status_read 3 5171 _002032_hash NULL
86576 +_002033_hash iwl_dbgfs_temperature_read 3 29224 _002033_hash NULL
86577 +_002034_hash iwl_dbgfs_thermal_throttling_read 3 38779 _002034_hash NULL
86578 +_002035_hash iwl_dbgfs_tx_queue_read 3 4635 _002035_hash NULL
86579 +_002036_hash iwl_dbgfs_ucode_bt_stats_read 3 42820 _002036_hash NULL
86580 +_002037_hash iwl_dbgfs_ucode_general_stats_read 3 49199 _002037_hash NULL
86581 +_002038_hash iwl_dbgfs_ucode_rx_stats_read 3 58023 _002038_hash NULL
86582 +_002039_hash iwl_dbgfs_ucode_tracing_read 3 47983 _002039_hash &_000356_hash
86583 +_002040_hash iwl_dbgfs_ucode_tx_stats_read 3 31611 _002040_hash NULL
86584 +_002041_hash iwl_dbgfs_wowlan_sram_read 3 540 _002041_hash NULL
86585 +_002042_hash joydev_ioctl 2 33343 _002042_hash NULL
86586 +_002043_hash kernel_readv 3 35617 _002043_hash NULL
86587 +_002044_hash key_algorithm_read 3 57946 _002044_hash NULL
86588 +_002045_hash key_icverrors_read 3 20895 _002045_hash NULL
86589 +_002046_hash key_key_read 3 3241 _002046_hash NULL
86590 +_002047_hash key_replays_read 3 62746 _002047_hash NULL
86591 +_002048_hash key_rx_spec_read 3 12736 _002048_hash NULL
86592 +_002049_hash key_tx_spec_read 3 4862 _002049_hash NULL
86593 +_002050_hash __kfifo_to_user 3 36555 _002568_hash NULL nohasharray
86594 +_002051_hash __kfifo_to_user_r 3 39123 _002051_hash NULL
86595 +_002052_hash kmem_zalloc_greedy 2-3 65268 _002052_hash NULL
86596 +_002054_hash l1oip_socket_recv 6 56537 _002054_hash NULL
86597 +_002055_hash l2cap_build_cmd 4 48676 _002055_hash NULL
86598 +_002056_hash l2cap_chan_send 3 49995 _002056_hash NULL
86599 +_002057_hash l2cap_segment_sdu 4 48772 _002057_hash NULL
86600 +_002058_hash l2down_create 4 21755 _002058_hash NULL
86601 +_002059_hash l2tp_xmit_skb 3 42672 _002059_hash NULL
86602 +_002060_hash l2up_create 3 6430 _002060_hash NULL
86603 +_002061_hash lbs_debugfs_read 3 30721 _002061_hash NULL
86604 +_002062_hash lbs_dev_info 3 51023 _002062_hash NULL
86605 +_002063_hash lbs_host_sleep_read 3 31013 _002063_hash NULL
86606 +_002064_hash lbs_rdbbp_read 3 45805 _002064_hash NULL
86607 +_002065_hash lbs_rdmac_read 3 418 _002065_hash NULL
86608 +_002066_hash lbs_rdrf_read 3 41431 _002066_hash NULL
86609 +_002067_hash lbs_sleepparams_read 3 10840 _002067_hash NULL
86610 +_002068_hash lbs_threshold_read 5 21046 _002068_hash NULL
86611 +_002069_hash ldisc_receive 4 41516 _002069_hash NULL
86612 +_002070_hash libfc_vport_create 2 4415 _002070_hash NULL
86613 +_002073_hash lkdtm_debugfs_read 3 45752 _002073_hash NULL
86614 +_002074_hash llcp_sock_recvmsg 4 13556 _002074_hash NULL
86615 +_002075_hash long_retry_limit_read 3 59766 _002075_hash NULL
86616 +_002076_hash lpfc_debugfs_dif_err_read 3 36303 _002076_hash NULL
86617 +_002077_hash lpfc_debugfs_read 3 16566 _002077_hash NULL
86618 +_002078_hash lpfc_idiag_baracc_read 3 58466 _002972_hash NULL nohasharray
86619 +_002079_hash lpfc_idiag_ctlacc_read 3 33943 _002079_hash NULL
86620 +_002080_hash lpfc_idiag_drbacc_read 3 15948 _002080_hash NULL
86621 +_002081_hash lpfc_idiag_extacc_read 3 48301 _002081_hash NULL
86622 +_002082_hash lpfc_idiag_mbxacc_read 3 28061 _002082_hash NULL
86623 +_002083_hash lpfc_idiag_pcicfg_read 3 50334 _002083_hash NULL
86624 +_002084_hash lpfc_idiag_queacc_read 3 13950 _002084_hash NULL
86625 +_002085_hash lpfc_idiag_queinfo_read 3 55662 _002085_hash NULL
86626 +_002086_hash lro_gen_skb 6 2644 _002086_hash NULL
86627 +_002087_hash mac80211_format_buffer 2 41010 _002087_hash NULL
86628 +_002088_hash macvtap_alloc_skb 2-4-3 50629 _002088_hash NULL
86629 +_002091_hash macvtap_put_user 4 55609 _002091_hash NULL
86630 +_002092_hash macvtap_sendmsg 4 30629 _002092_hash NULL
86631 +_002093_hash mangle_packet 6-8 27864 _002093_hash NULL
86632 +_002095_hash manip_pkt 3 7741 _002095_hash NULL
86633 +_002096_hash mempool_create_kmalloc_pool 1 41650 _002096_hash NULL
86634 +_002097_hash mempool_create_page_pool 1 30189 _002097_hash NULL
86635 +_002098_hash mempool_create_slab_pool 1 62907 _002098_hash NULL
86636 +_002099_hash mgmt_device_found 10 14146 _002099_hash NULL
86637 +_002100_hash minstrel_stats_read 3 17290 _002100_hash NULL
86638 +_002101_hash mmc_ext_csd_read 3 13205 _002101_hash NULL
86639 +_002102_hash mon_bin_read 3 6841 _002102_hash NULL
86640 +_002103_hash mon_stat_read 3 25238 _002103_hash NULL
86641 +_002105_hash mqueue_read_file 3 6228 _002105_hash NULL
86642 +_002106_hash mwifiex_debug_read 3 53074 _002106_hash NULL
86643 +_002107_hash mwifiex_getlog_read 3 54269 _002107_hash NULL
86644 +_002108_hash mwifiex_info_read 3 53447 _002108_hash NULL
86645 +_002109_hash mwifiex_rdeeprom_read 3 51429 _002109_hash NULL
86646 +_002110_hash mwifiex_regrdwr_read 3 34472 _002110_hash NULL
86647 +_002111_hash named_prepare_buf 2 24532 _002111_hash NULL
86648 +_002112_hash nci_send_cmd 3 58206 _002112_hash NULL
86649 +_002113_hash netdev_alloc_skb_ip_align 2 40811 _002113_hash NULL
86650 +_002114_hash netpoll_send_udp 3 58955 _002114_hash NULL
86651 +_002115_hash nfcwilink_send_bts_cmd 3 10802 _002115_hash NULL
86652 +_002116_hash nf_nat_mangle_tcp_packet 5-7 8643 _002116_hash NULL
86653 +_002119_hash nfsd_vfs_read 6 62605 _002616_hash NULL nohasharray
86654 +_002120_hash nfsd_vfs_write 6 54577 _002120_hash NULL
86655 +_002121_hash nfs_idmap_lookup_id 2 10660 _002121_hash NULL
86656 +_002122_hash ntfs_rl_realloc 3 56831 _002122_hash &_000370_hash
86657 +_002123_hash ntfs_rl_realloc_nofail 3 32173 _002123_hash NULL
86658 +_002124_hash o2hb_debug_read 3 37851 _002124_hash NULL
86659 +_002125_hash o2net_debug_read 3 52105 _002125_hash NULL
86660 +_002126_hash ocfs2_control_read 3 56405 _002126_hash NULL
86661 +_002127_hash ocfs2_debug_read 3 14507 _002127_hash NULL
86662 +_002128_hash oom_adjust_read 3 25127 _002128_hash NULL
86663 +_002129_hash oom_score_adj_read 3 39921 _002426_hash NULL nohasharray
86664 +_002130_hash oprofilefs_str_to_user 3 42182 _002130_hash NULL
86665 +_002131_hash oprofilefs_ulong_to_user 3 11582 _002131_hash NULL
86666 +_002132_hash osd_req_add_get_attr_list 3 49278 _002132_hash NULL
86667 +_002133_hash _osd_req_list_objects 6 4204 _002133_hash NULL
86668 +_002134_hash osd_req_read_kern 5 59990 _002134_hash NULL
86669 +_002135_hash osd_req_write_kern 5 53486 _002135_hash NULL
86670 +_002136_hash osst_read 3 40237 _002136_hash NULL
86671 +_002137_hash p54_alloc_skb 3 34366 _002137_hash &_000485_hash
86672 +_002138_hash p54_init_common 1 23850 _002138_hash NULL
86673 +_002139_hash packet_alloc_skb 2-5-4 62602 _002139_hash NULL
86674 +_002142_hash packet_sendmsg 4 24954 _002142_hash NULL
86675 +_002143_hash page_readlink 3 23346 _002143_hash NULL
86676 +_002144_hash pcf50633_write_block 3 2124 _002144_hash NULL
86677 +_002145_hash pcpu_alloc_alloc_info 1-2 45813 _002145_hash NULL
86678 +_002147_hash pep_indicate 5 38611 _002147_hash NULL
86679 +_002148_hash pep_reply 5 50582 _002148_hash NULL
86680 +_002149_hash pipe_handler_request 5 50774 _003582_hash NULL nohasharray
86681 +_002150_hash platform_list_read_file 3 34734 _002150_hash NULL
86682 +_002151_hash pm860x_bulk_write 3 43875 _002151_hash NULL
86683 +_002152_hash pm_qos_power_read 3 55891 _002152_hash NULL
86684 +_002153_hash port_show_regs 3 5904 _002153_hash NULL
86685 +_002154_hash proc_coredump_filter_read 3 39153 _002154_hash NULL
86686 +_002155_hash proc_fdinfo_read 3 62043 _002155_hash NULL
86687 +_002156_hash proc_file_read 3 53905 _002156_hash NULL
86688 +_002157_hash proc_info_read 3 63344 _002157_hash NULL
86689 +_002158_hash proc_loginuid_read 3 15631 _002158_hash NULL
86690 +_002159_hash proc_pid_attr_read 3 10173 _002159_hash NULL
86691 +_002160_hash proc_pid_readlink 3 52186 _002160_hash NULL
86692 +_002161_hash proc_read 3 43614 _002161_hash NULL
86693 +_002162_hash proc_self_readlink 3 38094 _002162_hash NULL
86694 +_002163_hash proc_sessionid_read 3 6911 _002299_hash NULL nohasharray
86695 +_002164_hash provide_user_output 3 41105 _002164_hash NULL
86696 +_002165_hash pskb_network_may_pull 2 35336 _002165_hash NULL
86697 +_002166_hash pskb_pull 2 65005 _002166_hash NULL
86698 +_002167_hash pstore_file_read 3 57288 _002167_hash NULL
86699 +_002168_hash ql_process_mac_rx_page 4 15543 _002168_hash NULL
86700 +_002169_hash ql_process_mac_rx_skb 4 6689 _002169_hash NULL
86701 +_002170_hash queues_read 3 24877 _002170_hash NULL
86702 +_002171_hash raw_recvmsg 4 17277 _002171_hash NULL
86703 +_002172_hash rcname_read 3 25919 _002172_hash NULL
86704 +_002173_hash read_4k_modal_eeprom 3 30212 _002173_hash NULL
86705 +_002174_hash read_9287_modal_eeprom 3 59327 _002174_hash NULL
86706 +_002175_hash reada_find_extent 2 63486 _002175_hash NULL
86707 +_002176_hash read_def_modal_eeprom 3 14041 _002176_hash NULL
86708 +_002177_hash read_enabled_file_bool 3 37744 _002177_hash NULL
86709 +_002178_hash read_file_ani 3 23161 _002178_hash NULL
86710 +_002179_hash read_file_antenna 3 13574 _002179_hash NULL
86711 +_002180_hash read_file_base_eeprom 3 42168 _002180_hash NULL
86712 +_002181_hash read_file_beacon 3 32595 _002181_hash NULL
86713 +_002182_hash read_file_blob 3 57406 _002182_hash NULL
86714 +_002183_hash read_file_bool 3 4180 _002183_hash NULL
86715 +_002184_hash read_file_credit_dist_stats 3 54367 _002184_hash NULL
86716 +_002185_hash read_file_debug 3 58256 _002185_hash NULL
86717 +_002186_hash read_file_disable_ani 3 6536 _002186_hash NULL
86718 +_002187_hash read_file_dma 3 9530 _002187_hash NULL
86719 +_002188_hash read_file_dump_nfcal 3 18766 _002188_hash NULL
86720 +_002189_hash read_file_frameerrors 3 64001 _002189_hash NULL
86721 +_002190_hash read_file_interrupt 3 61742 _002197_hash NULL nohasharray
86722 +_002191_hash read_file_misc 3 9948 _002191_hash NULL
86723 +_002192_hash read_file_modal_eeprom 3 39909 _002192_hash NULL
86724 +_002193_hash read_file_queue 3 40895 _002193_hash NULL
86725 +_002194_hash read_file_rcstat 3 22854 _002194_hash NULL
86726 +_002195_hash read_file_recv 3 48232 _002195_hash NULL
86727 +_002196_hash read_file_regidx 3 33370 _002196_hash NULL
86728 +_002197_hash read_file_regval 3 61742 _002197_hash &_002190_hash
86729 +_002198_hash read_file_reset 3 52310 _002198_hash NULL
86730 +_002199_hash read_file_rx_chainmask 3 41605 _002199_hash NULL
86731 +_002200_hash read_file_slot 3 50111 _002200_hash NULL
86732 +_002201_hash read_file_stations 3 35795 _002201_hash NULL
86733 +_002202_hash read_file_tgt_int_stats 3 20697 _002202_hash NULL
86734 +_002203_hash read_file_tgt_rx_stats 3 33944 _002203_hash NULL
86735 +_002204_hash read_file_tgt_stats 3 8959 _002204_hash NULL
86736 +_002205_hash read_file_tgt_tx_stats 3 51847 _002205_hash NULL
86737 +_002206_hash read_file_tx_chainmask 3 3829 _002206_hash NULL
86738 +_002207_hash read_file_war_stats 3 292 _002207_hash NULL
86739 +_002208_hash read_file_xmit 3 21487 _002208_hash NULL
86740 +_002209_hash read_flush_pipefs 3 20171 _002209_hash NULL
86741 +_002210_hash read_flush_procfs 3 27642 _002210_hash NULL
86742 +_002211_hash read_from_oldmem 2 3337 _002211_hash NULL
86743 +_002212_hash read_oldmem 3 55658 _002212_hash NULL
86744 +_002213_hash receive_packet 2 12367 _002213_hash NULL
86745 +_002214_hash regmap_name_read_file 3 39379 _002214_hash NULL
86746 +_002215_hash repair_io_failure 4 4815 _002215_hash NULL
86747 +_002216_hash request_key_and_link 4 42693 _002216_hash NULL
86748 +_002217_hash res_counter_read 4 33499 _002217_hash NULL
86749 +_002218_hash rfcomm_tty_write 3 51603 _002218_hash NULL
86750 +_002219_hash rs_sta_dbgfs_rate_scale_data_read 3 47165 _002219_hash NULL
86751 +_002220_hash rs_sta_dbgfs_scale_table_read 3 40262 _002220_hash NULL
86752 +_002221_hash rs_sta_dbgfs_stats_table_read 3 56573 _002221_hash NULL
86753 +_002222_hash rts_threshold_read 3 44384 _002222_hash NULL
86754 +_002223_hash rxrpc_sendmsg 4 29049 _002223_hash NULL
86755 +_002224_hash scrub_setup_recheck_block 3-4 56245 _002224_hash NULL
86756 +_002226_hash scsi_adjust_queue_depth 3 12802 _002226_hash NULL
86757 +_002227_hash sctp_make_abort 3 34459 _002227_hash NULL
86758 +_002228_hash sctp_make_asconf 3 4078 _002228_hash NULL
86759 +_002229_hash sctp_make_asconf_ack 3 31726 _002229_hash NULL
86760 +_002230_hash sctp_make_datafrag_empty 3 34737 _002230_hash NULL
86761 +_002231_hash sctp_make_fwdtsn 3 53265 _002231_hash NULL
86762 +_002232_hash sctp_make_heartbeat_ack 4 34411 _002232_hash NULL
86763 +_002233_hash sctp_make_init 4 58401 _002233_hash NULL
86764 +_002234_hash sctp_make_init_ack 4 3335 _002234_hash NULL
86765 +_002235_hash sctp_make_op_error_space 3 5528 _002235_hash NULL
86766 +_002236_hash sctp_manip_pkt 2 40620 _002236_hash NULL
86767 +_002237_hash selinux_inode_notifysecctx 3 36896 _002237_hash NULL
86768 +_002238_hash sel_read_avc_cache_threshold 3 33942 _002238_hash NULL
86769 +_002239_hash sel_read_avc_hash_stats 3 1984 _002239_hash NULL
86770 +_002240_hash sel_read_bool 3 24236 _002240_hash NULL
86771 +_002241_hash sel_read_checkreqprot 3 33068 _002241_hash NULL
86772 +_002242_hash sel_read_class 3 12669 _002960_hash NULL nohasharray
86773 +_002243_hash sel_read_enforce 3 2828 _002243_hash NULL
86774 +_002244_hash sel_read_handle_status 3 56139 _002244_hash NULL
86775 +_002245_hash sel_read_handle_unknown 3 57933 _002245_hash NULL
86776 +_002246_hash sel_read_initcon 3 32362 _002246_hash NULL
86777 +_002247_hash sel_read_mls 3 25369 _002247_hash NULL
86778 +_002248_hash sel_read_perm 3 42302 _002248_hash NULL
86779 +_002249_hash sel_read_policy 3 55947 _002249_hash NULL
86780 +_002250_hash sel_read_policycap 3 28544 _002250_hash NULL
86781 +_002251_hash sel_read_policyvers 3 55 _002827_hash NULL nohasharray
86782 +_002252_hash send_mpa_reject 3 7135 _002252_hash NULL
86783 +_002253_hash send_mpa_reply 3 32372 _002253_hash NULL
86784 +_002254_hash send_msg 4 37323 _002254_hash NULL
86785 +_002255_hash send_packet 4 52960 _002255_hash NULL
86786 +_002256_hash set_rxd_buffer_pointer 8 9950 _002256_hash NULL
86787 +_002257_hash sge_rx 3 50594 _002257_hash NULL
86788 +_002258_hash short_retry_limit_read 3 4687 _002258_hash NULL
86789 +_002259_hash simple_attr_read 3 24738 _002259_hash NULL
86790 +_002260_hash simple_transaction_read 3 17076 _002260_hash NULL
86791 +_002261_hash sisusbcon_bmove 5-7-6 21873 _002261_hash NULL
86792 +_002264_hash sisusbcon_clear 3-5-4 64329 _002264_hash NULL
86793 +_002267_hash sisusbcon_putcs 3 57630 _002267_hash &_001043_hash
86794 +_002268_hash sisusbcon_scroll 5-3-2 31315 _002268_hash NULL
86795 +_002269_hash sisusbcon_scroll_area 3-4 25899 _002269_hash NULL
86796 +_002271_hash skb_copy_datagram_const_iovec 2-5-4 48102 _002271_hash NULL
86797 +_002274_hash skb_copy_datagram_iovec 2-4 5806 _002274_hash NULL
86798 +_002276_hash skb_gro_header_slow 2 34958 _002276_hash NULL
86799 +_002277_hash smk_read_ambient 3 61220 _002277_hash NULL
86800 +_002278_hash smk_read_direct 3 15803 _002278_hash NULL
86801 +_002279_hash smk_read_doi 3 30813 _002279_hash NULL
86802 +_002280_hash smk_read_logging 3 37804 _002280_hash NULL
86803 +_002281_hash smk_read_mapped 3 7562 _002281_hash NULL
86804 +_002282_hash smk_read_onlycap 3 3855 _002282_hash NULL
86805 +_002283_hash smp_build_cmd 3 45853 _002283_hash NULL
86806 +_002284_hash snapshot_read 3 22601 _002284_hash NULL
86807 +_002285_hash snd_cs4281_BA0_read 5 6847 _002285_hash NULL
86808 +_002286_hash snd_cs4281_BA1_read 5 20323 _002286_hash NULL
86809 +_002287_hash snd_cs46xx_io_read 5 45734 _002287_hash NULL
86810 +_002288_hash snd_gus_dram_read 4 56686 _002288_hash NULL
86811 +_002289_hash snd_mixart_BA0_read 5 45069 _002289_hash NULL
86812 +_002290_hash snd_mixart_BA1_read 5 5082 _002290_hash NULL
86813 +_002291_hash snd_pcm_oss_read 3 28317 _002291_hash NULL
86814 +_002292_hash snd_pcm_plug_alloc 2 42339 _002292_hash NULL
86815 +_002293_hash snd_rawmidi_kernel_read 3 4328 _002293_hash NULL
86816 +_002294_hash snd_rawmidi_read 3 56337 _002294_hash NULL
86817 +_002295_hash snd_rme32_capture_copy 5 39653 _002295_hash NULL
86818 +_002296_hash snd_rme96_capture_copy 5 58484 _002296_hash NULL
86819 +_002297_hash snd_soc_hw_bulk_write_raw 4 14245 _002297_hash NULL
86820 +_002298_hash sock_alloc_send_skb 2 23720 _002298_hash NULL
86821 +_002299_hash spi_show_regs 3 6911 _002299_hash &_002163_hash
86822 +_002300_hash sta_agg_status_read 3 14058 _002300_hash NULL
86823 +_002301_hash sta_connected_time_read 3 17435 _002301_hash NULL
86824 +_002302_hash sta_flags_read 3 56710 _002302_hash NULL
86825 +_002303_hash sta_ht_capa_read 3 10366 _002303_hash NULL
86826 +_002304_hash sta_last_seq_ctrl_read 3 19106 _002304_hash NULL
86827 +_002305_hash sta_num_ps_buf_frames_read 3 1488 _002305_hash NULL
86828 +_002306_hash st_read 3 51251 _002306_hash NULL
86829 +_002307_hash supply_map_read_file 3 10608 _002307_hash NULL
86830 +_002308_hash sysfs_read_file 3 42113 _002308_hash NULL
86831 +_002309_hash sys_preadv 3 17100 _002309_hash NULL
86832 +_002310_hash sys_pwritev 3 41722 _002310_hash NULL
86833 +_002311_hash sys_readv 3 50664 _002311_hash NULL
86834 +_002312_hash sys_rt_sigpending 2 24961 _002312_hash NULL
86835 +_002313_hash sys_writev 3 28384 _002313_hash NULL
86836 +_002314_hash tcf_csum_skb_nextlayer 3 64025 _002314_hash NULL
86837 +_002315_hash tcp_fragment 3 20436 _002315_hash NULL
86838 +_002316_hash tcp_manip_pkt 2 14202 _002316_hash NULL
86839 +_002317_hash teiup_create 3 43201 _002317_hash NULL
86840 +_002318_hash test_iso_queue 5 62534 _002318_hash NULL
86841 +_002319_hash tg3_run_loopback 2 30093 _002319_hash NULL
86842 +_002320_hash tipc_msg_build 4 12326 _002320_hash NULL
86843 +_002321_hash TSS_authhmac 3 12839 _002321_hash NULL
86844 +_002322_hash TSS_checkhmac1 5 31429 _002322_hash NULL
86845 +_002323_hash TSS_checkhmac2 5-7 40520 _002323_hash NULL
86846 +_002325_hash tty_audit_log 8 47280 _002325_hash NULL
86847 +_002326_hash tty_buffer_request_room 2 23228 _002326_hash NULL
86848 +_002327_hash tty_insert_flip_string_fixed_flag 4 37428 _002327_hash NULL
86849 +_002328_hash tty_insert_flip_string_flags 4 30969 _002328_hash NULL
86850 +_002329_hash tty_prepare_flip_string 3 39955 _002329_hash NULL
86851 +_002330_hash tty_prepare_flip_string_flags 4 59240 _002330_hash NULL
86852 +_002331_hash tun_alloc_skb 2-4-3 41216 _002331_hash NULL
86853 +_002334_hash tun_sendmsg 4 10337 _002334_hash NULL
86854 +_002335_hash u32_array_read 3 2219 _002335_hash NULL
86855 +_002336_hash ubi_io_write_data 4-5 40305 _002336_hash NULL
86856 +_002338_hash udplite_manip_pkt 2 62433 _002338_hash NULL
86857 +_002339_hash udp_manip_pkt 2 50770 _002339_hash NULL
86858 +_002340_hash uhci_debug_read 3 5911 _002340_hash NULL
86859 +_002341_hash um_idi_read 3 850 _002341_hash NULL
86860 +_002342_hash unix_seqpacket_sendmsg 4 27893 _002342_hash NULL
86861 +_002343_hash unix_stream_recvmsg 4 35210 _002343_hash NULL
86862 +_002344_hash unlink_simple 3 47506 _002344_hash NULL
86863 +_002345_hash use_pool 2 64607 _002345_hash NULL
86864 +_002346_hash v9fs_fid_readn 4 60544 _002346_hash NULL
86865 +_002347_hash v9fs_file_read 3 40858 _002347_hash NULL
86866 +_002348_hash vhci_read 3 47878 _002348_hash NULL
86867 +_002349_hash vhost_add_used_and_signal_n 4 8038 _002349_hash NULL
86868 +_002350_hash vmbus_open 2-3 12154 _002350_hash NULL
86869 +_002352_hash vxge_rx_alloc 3 52024 _002352_hash NULL
86870 +_002353_hash waiters_read 3 40902 _002353_hash NULL
86871 +_002354_hash wm8994_bulk_write 3 13615 _002354_hash NULL
86872 +_002355_hash write_pbl 4 59583 _002355_hash NULL
86873 +_002356_hash wusb_prf_256 7 29203 _002356_hash NULL
86874 +_002357_hash wusb_prf_64 7 51065 _002357_hash NULL
86875 +_002358_hash _xfs_buf_alloc 3 38058 _002358_hash NULL
86876 +_002359_hash xfs_buf_read_uncached 3 42844 _002359_hash NULL
86877 +_002360_hash xfs_file_buffered_aio_write 4 11492 _002360_hash NULL
86878 +_002361_hash xfs_iext_add 3 41422 _002361_hash NULL
86879 +_002362_hash xfs_iext_remove_direct 3 40744 _002362_hash NULL
86880 +_002363_hash xfs_readdir 3 41200 _002363_hash NULL
86881 +_002364_hash xfs_trans_get_efd 3 51148 _002364_hash NULL
86882 +_002365_hash xfs_trans_get_efi 2 7898 _002365_hash NULL
86883 +_002366_hash xlog_bread_offset 3 60030 _002366_hash NULL
86884 +_002367_hash xlog_get_bp 2 23229 _002367_hash NULL
86885 +_002368_hash xz_dec_init 2 29029 _002368_hash NULL
86886 +_002369_hash aac_change_queue_depth 2 825 _002369_hash NULL
86887 +_002370_hash add_rx_skb 3 8257 _002370_hash NULL
86888 +_002371_hash afs_extract_data 5 50261 _002371_hash NULL
86889 +_002372_hash arcmsr_adjust_disk_queue_depth 2 16756 _002372_hash NULL
86890 +_002373_hash atalk_recvmsg 4 22053 _002373_hash NULL
86891 +_002374_hash ath6kl_buf_alloc 1 57304 _002374_hash NULL
86892 +_002376_hash atomic_read_file 3 16227 _002376_hash NULL
86893 +_002377_hash ax25_recvmsg 4 64441 _002377_hash NULL
86894 +_002378_hash batadv_add_packet 3 12136 _002378_hash NULL
86895 +_002379_hash batadv_iv_ogm_aggregate_new 2 54761 _002379_hash NULL
86896 +_002380_hash batadv_tt_response_fill_table 1 39236 _002380_hash NULL
86897 +_002381_hash beiscsi_process_async_pdu 7 39834 _002381_hash NULL
86898 +_002382_hash bioset_create 1 5580 _002382_hash NULL
86899 +_002383_hash bioset_integrity_create 2 62708 _002383_hash NULL
86900 +_002384_hash biovec_create_pools 2 9575 _002384_hash NULL
86901 +_002385_hash bnx2fc_process_l2_frame_compl 3 65072 _002385_hash NULL
86902 +_002386_hash brcmf_sdbrcm_died_dump 3 15841 _002386_hash NULL
86903 +_002387_hash brcmu_pkt_buf_get_skb 1 5556 _002387_hash NULL
86904 +_002388_hash br_send_bpdu 3 29669 _002388_hash NULL
86905 +_002389_hash btrfs_error_discard_extent 2 50444 _002389_hash NULL
86906 +_002390_hash __btrfs_free_reserved_extent 2 31207 _002390_hash NULL
86907 +_002391_hash btrfsic_cmp_log_and_dev_bytenr 2 49628 _002391_hash NULL
86908 +_002392_hash btrfsic_create_link_to_next_block 4 58246 _002392_hash NULL
86909 +_002393_hash btrfs_init_new_buffer 4 55761 _002393_hash NULL
86910 +_002394_hash btrfs_mksubvol 3 58240 _002394_hash NULL
86911 +_002395_hash bt_skb_send_alloc 2 6581 _002395_hash NULL
86912 +_002396_hash bt_sock_recvmsg 4 12316 _002396_hash NULL
86913 +_002397_hash bt_sock_stream_recvmsg 4 52518 _002397_hash NULL
86914 +_002398_hash c4iw_reject_cr 3 28174 _002398_hash NULL
86915 +_002399_hash caif_seqpkt_recvmsg 4 32241 _002399_hash NULL
86916 +_002400_hash carl9170_rx_copy_data 2 21656 _002400_hash NULL
86917 +_002401_hash cfpkt_append 3 61206 _002401_hash NULL
86918 +_002402_hash cfpkt_setlen 2 49343 _002402_hash NULL
86919 +_002403_hash cgroup_file_read 3 28804 _002403_hash NULL
86920 +_002404_hash cosa_net_setup_rx 2 38594 _002404_hash NULL
86921 +_002405_hash cpu_type_read 3 36540 _002405_hash NULL
86922 +_002406_hash cxgb4_pktgl_to_skb 2 61899 _002406_hash NULL
86923 +_002408_hash dccp_recvmsg 4 16056 _002408_hash NULL
86924 +_002409_hash ddp_clear_map 4 46152 _002409_hash NULL
86925 +_002410_hash ddp_set_map 4 751 _002410_hash NULL
86926 +_002411_hash depth_read 3 31112 _002411_hash NULL
86927 +_002412_hash dfs_global_file_read 3 7787 _002412_hash NULL
86928 +_002413_hash dgram_recvmsg 4 23104 _002413_hash NULL
86929 +_002414_hash diva_init_dma_map 3 58336 _002414_hash NULL
86930 +_002415_hash divas_write 3 63901 _002415_hash NULL
86931 +_002416_hash dma_push_rx 2 39973 _002416_hash NULL
86932 +_002417_hash dma_skb_copy_datagram_iovec 3-5 21516 _002417_hash NULL
86933 +_002419_hash dm_table_create 3 35687 _002419_hash NULL
86934 +_002420_hash dn_alloc_send_pskb 2 4465 _002420_hash NULL
86935 +_002421_hash dn_nsp_return_disc 2 60296 _002421_hash NULL
86936 +_002422_hash dn_nsp_send_disc 2 23469 _002422_hash NULL
86937 +_002423_hash dsp_tone_hw_message 3 17678 _002423_hash NULL
86938 +_002424_hash e1000_check_copybreak 3 62448 _002424_hash NULL
86939 +_002425_hash enable_read 3 2117 _002425_hash &_000224_hash
86940 +_002426_hash exofs_read_kern 6 39921 _002426_hash &_002129_hash
86941 +_002427_hash fast_rx_path 3 59214 _002427_hash NULL
86942 +_002428_hash fc_change_queue_depth 2 36841 _002428_hash NULL
86943 +_002429_hash fc_fcp_frame_alloc 2 12624 _002429_hash NULL
86944 +_002430_hash fcoe_ctlr_send_keep_alive 3 15308 _002430_hash NULL
86945 +_002431_hash frequency_read 3 64031 _003698_hash NULL nohasharray
86946 +_002432_hash ftdi_process_packet 5 45005 _002432_hash NULL
86947 +_002433_hash fuse_conn_congestion_threshold_read 3 51028 _002433_hash NULL
86948 +_002434_hash fuse_conn_max_background_read 3 10855 _002434_hash NULL
86949 +_002435_hash fwnet_incoming_packet 3 40380 _002435_hash NULL
86950 +_002436_hash fwnet_pd_new 4 39947 _003402_hash NULL nohasharray
86951 +_002437_hash get_alua_req 3 4166 _002437_hash NULL
86952 +_002438_hash get_rdac_req 3 45882 _002438_hash NULL
86953 +_002439_hash got_frame 2 16028 _002439_hash NULL
86954 +_002440_hash gsm_mux_rx_netchar 3 33336 _002440_hash NULL
86955 +_002441_hash hci_sock_recvmsg 4 7072 _002441_hash NULL
86956 +_002442_hash hdlcdev_rx 3 997 _002442_hash NULL
86957 +_002443_hash hdlc_empty_fifo 2 18397 _002443_hash NULL
86958 +_002444_hash hfc_empty_fifo 2 57972 _002444_hash NULL
86959 +_002445_hash hfcpci_empty_fifo 4 2427 _002445_hash NULL
86960 +_002446_hash hfcsusb_rx_frame 3 52745 _002446_hash NULL
86961 +_002447_hash hidp_output_raw_report 3 5629 _002447_hash NULL
86962 +_002448_hash hpsa_change_queue_depth 2 15449 _002448_hash NULL
86963 +_002449_hash hptiop_adjust_disk_queue_depth 2 20122 _002449_hash NULL
86964 +_002450_hash hscx_empty_fifo 2 13360 _002450_hash NULL
86965 +_002451_hash hysdn_rx_netpkt 3 16136 _002451_hash NULL
86966 +_002452_hash i2o_pool_alloc 4 55485 _002452_hash NULL
86967 +_002453_hash ide_queue_pc_tail 5 11673 _002453_hash NULL
86968 +_002454_hash ide_raw_taskfile 4 42355 _002454_hash NULL
86969 +_002455_hash idetape_queue_rw_tail 3 29562 _002455_hash NULL
86970 +_002456_hash ieee80211_amsdu_to_8023s 5 15561 _002456_hash NULL
86971 +_002457_hash ieee80211_fragment 4 33112 _002457_hash NULL
86972 +_002458_hash ieee80211_if_read_aid 3 9705 _002458_hash NULL
86973 +_002459_hash ieee80211_if_read_auto_open_plinks 3 38268 _002459_hash &_000374_hash
86974 +_002460_hash ieee80211_if_read_ave_beacon 3 64924 _002460_hash NULL
86975 +_002461_hash ieee80211_if_read_bssid 3 35161 _002461_hash NULL
86976 +_002462_hash ieee80211_if_read_channel_type 3 23884 _002462_hash NULL
86977 +_002463_hash ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 _002463_hash NULL
86978 +_002464_hash ieee80211_if_read_dot11MeshForwarding 3 13940 _002464_hash NULL
86979 +_002465_hash ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 _002465_hash NULL
86980 +_002466_hash ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 _002466_hash NULL
86981 +_002467_hash ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 _002467_hash NULL
86982 +_002468_hash ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout 3 17618 _002468_hash NULL
86983 +_002469_hash ieee80211_if_read_dot11MeshHWMPconfirmationInterval 3 57722 _002469_hash NULL
86984 +_002470_hash ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 _002470_hash NULL
86985 +_002471_hash ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 _002471_hash NULL
86986 +_002472_hash ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 _002472_hash NULL
86987 +_002473_hash ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 _002473_hash NULL
86988 +_002474_hash ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 _002474_hash NULL
86989 +_002475_hash ieee80211_if_read_dot11MeshHWMProotInterval 3 27873 _002475_hash NULL
86990 +_002476_hash ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 _002476_hash NULL
86991 +_002477_hash ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 _002477_hash NULL
86992 +_002478_hash ieee80211_if_read_dot11MeshMaxRetries 3 12756 _002478_hash NULL
86993 +_002479_hash ieee80211_if_read_dot11MeshRetryTimeout 3 52168 _002479_hash NULL
86994 +_002480_hash ieee80211_if_read_dot11MeshTTL 3 58307 _002480_hash NULL
86995 +_002481_hash ieee80211_if_read_dropped_frames_congestion 3 32603 _002481_hash NULL
86996 +_002482_hash ieee80211_if_read_dropped_frames_no_route 3 33383 _002482_hash NULL
86997 +_002483_hash ieee80211_if_read_dropped_frames_ttl 3 44500 _002483_hash NULL
86998 +_002484_hash ieee80211_if_read_drop_unencrypted 3 37053 _002484_hash NULL
86999 +_002485_hash ieee80211_if_read_dtim_count 3 38419 _002485_hash NULL
87000 +_002486_hash ieee80211_if_read_element_ttl 3 18869 _002486_hash NULL
87001 +_002487_hash ieee80211_if_read_estab_plinks 3 32533 _002487_hash NULL
87002 +_002488_hash ieee80211_if_read_flags 3 57470 _002919_hash NULL nohasharray
87003 +_002489_hash ieee80211_if_read_fwded_frames 3 36520 _002489_hash NULL
87004 +_002490_hash ieee80211_if_read_fwded_mcast 3 39571 _002490_hash &_000162_hash
87005 +_002491_hash ieee80211_if_read_fwded_unicast 3 59740 _002491_hash &_001697_hash
87006 +_002492_hash ieee80211_if_read_ht_opmode 3 29044 _002492_hash NULL
87007 +_002493_hash ieee80211_if_read_last_beacon 3 31257 _002493_hash NULL
87008 +_002494_hash ieee80211_if_read_min_discovery_timeout 3 13946 _002494_hash NULL
87009 +_002495_hash ieee80211_if_read_num_buffered_multicast 3 12716 _002495_hash NULL
87010 +_002496_hash ieee80211_if_read_num_mcast_sta 3 12419 _002496_hash NULL
87011 +_002497_hash ieee80211_if_read_num_sta_ps 3 34722 _002497_hash NULL
87012 +_002498_hash ieee80211_if_read_path_refresh_time 3 25545 _002498_hash NULL
87013 +_002499_hash ieee80211_if_read_peer 3 45233 _002499_hash NULL
87014 +_002500_hash ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 _002500_hash NULL
87015 +_002501_hash ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 _002501_hash NULL
87016 +_002502_hash ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 _002502_hash NULL
87017 +_002503_hash ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 _002503_hash NULL
87018 +_002504_hash ieee80211_if_read_rssi_threshold 3 49260 _002504_hash NULL
87019 +_002505_hash ieee80211_if_read_smps 3 27416 _002505_hash NULL
87020 +_002506_hash ieee80211_if_read_state 3 9813 _002707_hash NULL nohasharray
87021 +_002507_hash ieee80211_if_read_tkip_mic_test 3 19565 _002507_hash NULL
87022 +_002508_hash ieee80211_if_read_tsf 3 16420 _002508_hash NULL
87023 +_002509_hash ieee80211_if_read_uapsd_max_sp_len 3 15067 _002509_hash NULL
87024 +_002510_hash ieee80211_if_read_uapsd_queues 3 55150 _002510_hash NULL
87025 +_002511_hash ieee80211_mgmt_tx 9 46860 _002511_hash NULL
87026 +_002512_hash ieee80211_probereq_get 4-6 29069 _002512_hash NULL
87027 +_002514_hash ieee80211_rx_mgmt_beacon 3 24430 _002514_hash NULL
87028 +_002515_hash ieee80211_rx_mgmt_probe_resp 3 6918 _002515_hash NULL
87029 +_002516_hash ieee80211_send_auth 5 24121 _002516_hash NULL
87030 +_002517_hash ieee80211_set_probe_resp 3 10077 _002517_hash NULL
87031 +_002518_hash ieee80211_tdls_mgmt 8 9581 _002518_hash NULL
87032 +_002519_hash ima_show_htable_violations 3 10619 _002519_hash NULL
87033 +_002520_hash ima_show_measurements_count 3 23536 _002520_hash NULL
87034 +_002521_hash insert_one_name 7 61668 _002521_hash NULL
87035 +_002522_hash ip6_ufo_append_data 5-7-6 4780 _002522_hash NULL
87036 +_002525_hash ip_append_data 5-6 16942 _002525_hash NULL
87037 +_002526_hash ip_make_skb 5-6 13129 _002526_hash NULL
87038 +_002527_hash ip_nat_sdp_port 6 52938 _002527_hash NULL
87039 +_002528_hash ip_nat_sip_expect 7 45693 _002528_hash NULL
87040 +_002529_hash ipr_change_queue_depth 2 6431 _002529_hash NULL
87041 +_002530_hash ip_recv_error 3 23109 _002530_hash NULL
87042 +_002531_hash ip_ufo_append_data 6-8-7 12775 _002531_hash NULL
87043 +_002534_hash ipv6_recv_error 3 56347 _002534_hash NULL
87044 +_002535_hash ipv6_recv_rxpmtu 3 7142 _002535_hash NULL
87045 +_002536_hash ipw_packet_received_skb 2 1230 _002536_hash NULL
87046 +_002537_hash ipx_recvmsg 4 44366 _002537_hash NULL
87047 +_002538_hash irda_recvmsg_dgram 4 32631 _002538_hash NULL
87048 +_002539_hash iscsi_change_queue_depth 2 23416 _002539_hash NULL
87049 +_002540_hash iscsi_complete_pdu 4 48372 _002540_hash NULL
87050 +_002541_hash iwch_reject_cr 3 23901 _002541_hash NULL
87051 +_002542_hash ixgb_check_copybreak 3 5847 _002542_hash NULL
87052 +_002543_hash key_conf_hw_key_idx_read 3 25003 _002543_hash NULL
87053 +_002544_hash key_conf_keyidx_read 3 42443 _002544_hash NULL
87054 +_002545_hash key_conf_keylen_read 3 49758 _002545_hash NULL
87055 +_002546_hash key_flags_read 3 25931 _002546_hash NULL
87056 +_002547_hash key_ifindex_read 3 31411 _002547_hash NULL
87057 +_002548_hash key_tx_rx_count_read 3 44742 _002548_hash NULL
87058 +_002549_hash kmsg_read 3 46514 _002549_hash NULL
87059 +_002550_hash l1oip_socket_parse 4 4507 _002550_hash NULL
87060 +_002551_hash l2cap_send_cmd 4 14548 _002551_hash NULL
87061 +_002552_hash l2cap_sock_sendmsg 4 63427 _002552_hash NULL
87062 +_002553_hash l2tp_ip6_recvmsg 4 62874 _002553_hash NULL
87063 +_002554_hash l2tp_ip6_sendmsg 4 7461 _002554_hash NULL
87064 +_002555_hash l2tp_ip_recvmsg 4 22681 _002555_hash NULL
87065 +_002556_hash lbs_bcnmiss_read 3 8678 _002556_hash NULL
87066 +_002557_hash lbs_failcount_read 3 31063 _002557_hash NULL
87067 +_002558_hash lbs_highrssi_read 3 64089 _002558_hash NULL
87068 +_002559_hash lbs_highsnr_read 3 5931 _002559_hash NULL
87069 +_002560_hash lbs_lowrssi_read 3 32242 _002560_hash NULL
87070 +_002561_hash lbs_lowsnr_read 3 29571 _002561_hash NULL
87071 +_002563_hash llc_ui_recvmsg 4 3826 _002563_hash NULL
87072 +_002564_hash lowpan_fragment_xmit 3-4 22095 _002564_hash NULL
87073 +_002566_hash lpfc_change_queue_depth 2 25905 _002566_hash NULL
87074 +_002568_hash macvtap_do_read 4 36555 _002568_hash &_002050_hash
87075 +_002569_hash mangle_sdp_packet 9 36279 _002569_hash NULL
87076 +_002570_hash map_addr 6 4666 _002570_hash NULL
87077 +_002571_hash mcs_unwrap_fir 3 25733 _002571_hash NULL
87078 +_002572_hash mcs_unwrap_mir 3 9455 _002572_hash NULL
87079 +_002573_hash megaraid_change_queue_depth 2 64815 _002573_hash NULL
87080 +_002574_hash megasas_change_queue_depth 2 32747 _002574_hash NULL
87081 +_002575_hash mld_newpack 2 50950 _002575_hash NULL
87082 +_002576_hash mptscsih_change_queue_depth 2 26036 _002576_hash NULL
87083 +_002577_hash named_distribute 4 48544 _002577_hash NULL
87084 +_002578_hash NCR_700_change_queue_depth 2 31742 _002578_hash NULL
87085 +_002579_hash netlink_recvmsg 4 61600 _002579_hash NULL
87086 +_002580_hash nfc_alloc_send_skb 4 3167 _002580_hash NULL
87087 +_002581_hash nf_nat_ftp 5 47948 _002581_hash NULL
87088 +_002582_hash nfsctl_transaction_read 3 48250 _002582_hash NULL
87089 +_002583_hash nfsd_read 5 19568 _002583_hash NULL
87090 +_002584_hash nfsd_read_file 6 62241 _002584_hash NULL
87091 +_002585_hash nfsd_write 6 54809 _002585_hash NULL
87092 +_002586_hash nfs_map_group_to_gid 3 15892 _002586_hash NULL
87093 +_002587_hash nfs_map_name_to_uid 3 51132 _002587_hash NULL
87094 +_002588_hash nr_recvmsg 4 12649 _002588_hash NULL
87095 +_002589_hash ntfs_rl_append 2-4 6037 _002589_hash NULL
87096 +_002591_hash ntfs_rl_insert 2-4 4931 _002591_hash NULL
87097 +_002593_hash ntfs_rl_replace 2-4 14136 _002593_hash NULL
87098 +_002595_hash ntfs_rl_split 2-4 52328 _002595_hash NULL
87099 +_002597_hash osd_req_list_collection_objects 5 36664 _002597_hash NULL
87100 +_002598_hash osd_req_list_partition_objects 5 56464 _002598_hash NULL
87101 +_002599_hash osd_req_read_sg 5 47905 _002599_hash NULL
87102 +_002600_hash osd_req_write_sg 5 50908 _002600_hash NULL
87103 +_002602_hash p54_download_eeprom 4 43842 _002602_hash NULL
87104 +_002604_hash packet_recv_error 3 16669 _002604_hash NULL
87105 +_002605_hash packet_recvmsg 4 47700 _002605_hash NULL
87106 +_002606_hash pep_recvmsg 4 19402 _002606_hash NULL
87107 +_002607_hash pfkey_recvmsg 4 53604 _002607_hash NULL
87108 +_002608_hash ping_recvmsg 4 25597 _002608_hash NULL
87109 +_002609_hash pmcraid_change_queue_depth 2 9116 _002609_hash NULL
87110 +_002610_hash pn_recvmsg 4 30887 _002610_hash NULL
87111 +_002611_hash pointer_size_read 3 51863 _002611_hash NULL
87112 +_002612_hash power_read 3 15939 _002612_hash NULL
87113 +_002613_hash pppoe_recvmsg 4 15073 _002613_hash NULL
87114 +_002614_hash pppol2tp_recvmsg 4 57742 _002993_hash NULL nohasharray
87115 +_002615_hash ppp_tx_cp 5 62044 _002615_hash NULL
87116 +_002616_hash prism2_send_mgmt 4 62605 _002616_hash &_002119_hash
87117 +_002617_hash prism2_sta_send_mgmt 5 43916 _002617_hash NULL
87118 +_002618_hash prison_create 1 43623 _002618_hash NULL
87119 +_002619_hash qla2x00_adjust_sdev_qdepth_up 2 20097 _002619_hash NULL
87120 +_002620_hash qla2x00_change_queue_depth 2 24742 _002620_hash NULL
87121 +_002621_hash _queue_data 4 54983 _002621_hash NULL
87122 +_002622_hash raw_recvmsg 4 52529 _002622_hash NULL
87123 +_002623_hash rawsock_recvmsg 4 12144 _002623_hash NULL
87124 +_002624_hash rawv6_recvmsg 4 30265 _002624_hash NULL
87125 +_002625_hash rds_tcp_data_recv 3 53476 _002625_hash NULL
87126 +_002626_hash reada_add_block 2 54247 _002626_hash NULL
87127 +_002627_hash readahead_tree_block 3 36285 _002627_hash NULL
87128 +_002628_hash reada_tree_block_flagged 3 18402 _002628_hash NULL
87129 +_002629_hash read_dma 3 55086 _002629_hash NULL
87130 +_002630_hash read_fifo 3 826 _002630_hash NULL
87131 +_002631_hash read_tree_block 3 841 _002631_hash NULL
87132 +_002632_hash receive_copy 3 12216 _002632_hash NULL
87133 +_002633_hash recover_peb 6-7 29238 _002633_hash NULL
87134 +_002635_hash recv_msg 4 48709 _002635_hash NULL
87135 +_002636_hash recv_stream 4 30138 _002636_hash NULL
87136 +_002637_hash _req_append_segment 2 41031 _002637_hash NULL
87137 +_002638_hash request_key_async 4 6990 _002638_hash NULL
87138 +_002639_hash request_key_async_with_auxdata 4 46624 _002639_hash NULL
87139 +_002640_hash request_key_with_auxdata 4 24515 _002640_hash NULL
87140 +_002641_hash rose_recvmsg 4 2368 _002641_hash &_001788_hash
87141 +_002642_hash rtl8169_try_rx_copy 3 705 _002642_hash NULL
87142 +_002643_hash _rtl92s_firmware_downloadcode 3 14021 _002643_hash NULL
87143 +_002644_hash rx_data 4 60442 _002644_hash NULL
87144 +_002645_hash rxrpc_recvmsg 4 26233 _002645_hash NULL
87145 +_002646_hash sas_change_queue_depth 2 18555 _002646_hash NULL
87146 +_002647_hash scsi_activate_tcq 2 42640 _002647_hash NULL
87147 +_002648_hash scsi_deactivate_tcq 2 47086 _002648_hash NULL
87148 +_002649_hash scsi_execute 5 33596 _002649_hash NULL
87149 +_002650_hash _scsih_adjust_queue_depth 2 1083 _002650_hash NULL
87150 +_002651_hash scsi_init_shared_tag_map 2 59812 _002651_hash NULL
87151 +_002652_hash scsi_track_queue_full 2 44239 _002652_hash NULL
87152 +_002653_hash sctp_abort_pkt_new 5 55218 _002653_hash NULL
87153 +_002654_hash sctp_make_abort_violation 4 27959 _002654_hash NULL
87154 +_002655_hash sctp_make_op_error 5-6 7057 _002655_hash NULL
87155 +_002657_hash sctp_recvmsg 4 23265 _002657_hash NULL
87156 +_002658_hash send_stream 4 3397 _002658_hash NULL
87157 +_002659_hash sis190_try_rx_copy 3 57069 _002659_hash NULL
87158 +_002664_hash skb_copy_and_csum_datagram_iovec 2 24466 _002664_hash NULL
87159 +_002666_hash skge_rx_get 3 40598 _002666_hash NULL
87160 +_002667_hash smp_send_cmd 3 512 _002667_hash NULL
87161 +_002668_hash snd_gf1_mem_proc_dump 5 16926 _003499_hash NULL nohasharray
87162 +_002669_hash sta_dev_read 3 14782 _002669_hash NULL
87163 +_002670_hash sta_inactive_ms_read 3 25690 _002670_hash NULL
87164 +_002671_hash sta_last_signal_read 3 31818 _002671_hash NULL
87165 +_002672_hash stats_dot11ACKFailureCount_read 3 45558 _002672_hash NULL
87166 +_002673_hash stats_dot11FCSErrorCount_read 3 28154 _002673_hash NULL
87167 +_002674_hash stats_dot11RTSFailureCount_read 3 43948 _002674_hash NULL
87168 +_002675_hash stats_dot11RTSSuccessCount_read 3 33065 _002675_hash NULL
87169 +_002676_hash storvsc_connect_to_vsp 2 22 _002676_hash NULL
87170 +_002677_hash sys_msgrcv 3 959 _002677_hash NULL
87171 +_002678_hash sys_syslog 3 10746 _002678_hash NULL
87172 +_002679_hash tcf_csum_ipv4_icmp 3 9258 _002679_hash NULL
87173 +_002680_hash tcf_csum_ipv4_igmp 3 60446 _002680_hash NULL
87174 +_002681_hash tcf_csum_ipv4_tcp 4 39713 _002681_hash NULL
87175 +_002682_hash tcf_csum_ipv4_udp 4 30777 _002682_hash NULL
87176 +_002683_hash tcf_csum_ipv6_icmp 4 11738 _002683_hash NULL
87177 +_002684_hash tcf_csum_ipv6_tcp 4 54877 _002684_hash NULL
87178 +_002685_hash tcf_csum_ipv6_udp 4 25241 _002685_hash NULL
87179 +_002686_hash tcm_loop_change_queue_depth 2 42454 _002686_hash NULL
87180 +_002687_hash tcp_copy_to_iovec 3 28344 _002687_hash NULL
87181 +_002688_hash tcp_mark_head_lost 2 35895 _002688_hash NULL
87182 +_002689_hash tcp_match_skb_to_sack 4 23568 _002689_hash NULL
87183 +_002690_hash timeout_read 3 47915 _002690_hash NULL
87184 +_002691_hash tipc_multicast 5 49144 _002691_hash NULL
87185 +_002692_hash tipc_port_recv_sections 4 42890 _002692_hash NULL
87186 +_002693_hash tipc_port_reject_sections 5 55229 _002693_hash NULL
87187 +_002694_hash total_ps_buffered_read 3 16365 _002694_hash NULL
87188 +_002695_hash tso_fragment 3 29050 _002695_hash NULL
87189 +_002696_hash tty_insert_flip_string 3 34042 _002696_hash NULL
87190 +_002698_hash tun_put_user 4 59849 _002698_hash NULL
87191 +_002699_hash twa_change_queue_depth 2 48808 _002699_hash NULL
87192 +_002700_hash tw_change_queue_depth 2 11116 _002700_hash NULL
87193 +_002701_hash twl_change_queue_depth 2 41342 _002701_hash NULL
87194 +_002702_hash ubi_eba_atomic_leb_change 5 60379 _002702_hash NULL
87195 +_002703_hash ubi_eba_write_leb 5-6 36029 _002703_hash NULL
87196 +_002705_hash ubi_eba_write_leb_st 5 44343 _002705_hash NULL
87197 +_002706_hash udp_recvmsg 4 42558 _002706_hash NULL
87198 +_002707_hash udpv6_recvmsg 4 9813 _002707_hash &_002506_hash
87199 +_002708_hash udpv6_sendmsg 4 22316 _002708_hash NULL
87200 +_002709_hash ulong_read_file 3 42304 _002709_hash &_000522_hash
87201 +_002710_hash unix_dgram_recvmsg 4 14952 _002710_hash NULL
87202 +_002711_hash user_power_read 3 39414 _002711_hash NULL
87203 +_002712_hash v9fs_direct_read 3 45546 _002712_hash NULL
87204 +_002713_hash v9fs_file_readn 4 36353 _002713_hash &_001799_hash
87205 +_002714_hash vcc_recvmsg 4 37198 _002714_hash NULL
87206 +_002715_hash velocity_rx_copy 2 34583 _002715_hash NULL
87207 +_002716_hash W6692_empty_Bfifo 2 47804 _002716_hash NULL
87208 +_002717_hash wep_iv_read 3 54744 _002717_hash NULL
87209 +_002718_hash x25_recvmsg 4 42777 _002718_hash NULL
87210 +_002719_hash xfs_buf_get_map 3 24522 _002719_hash NULL
87211 +_002720_hash xfs_file_aio_write 4 33234 _002720_hash NULL
87212 +_002721_hash xfs_iext_insert 3 18667 _002741_hash NULL nohasharray
87213 +_002722_hash xfs_iext_remove 3 50909 _002722_hash NULL
87214 +_002723_hash xlog_do_recovery_pass 3 21618 _002723_hash NULL
87215 +_002724_hash xlog_find_verify_log_record 2 18870 _002724_hash NULL
87216 +_002725_hash zd_mac_rx 3 38296 _002725_hash NULL
87217 +_002726_hash aircable_process_packet 5 46639 _002726_hash NULL
87218 +_002727_hash ath6kl_wmi_get_new_buf 1 52304 _002727_hash NULL
87219 +_002728_hash batadv_iv_ogm_queue_add 3 46319 _002728_hash NULL
87220 +_002729_hash batadv_receive_client_update_packet 3 41578 _002729_hash NULL
87221 +_002730_hash batadv_receive_server_sync_packet 3 26577 _002730_hash &_000494_hash
87222 +_002731_hash brcmf_alloc_pkt_and_read 2 63116 _002731_hash &_002028_hash
87223 +_002732_hash brcmf_sdcard_recv_buf 6 38179 _002732_hash NULL
87224 +_002733_hash brcmf_sdcard_rwdata 5 65041 _002733_hash NULL
87225 +_002734_hash brcmf_sdcard_send_buf 6 7713 _002734_hash NULL
87226 +_002735_hash brcmf_sdio_forensic_read 3 35311 _002735_hash &_001382_hash
87227 +_002736_hash btrfs_alloc_free_block 3 8986 _002736_hash NULL
87228 +_002737_hash btrfs_free_and_pin_reserved_extent 2 53016 _002737_hash NULL
87229 +_002738_hash btrfs_free_reserved_extent 2 9867 _002738_hash NULL
87230 +_002739_hash carl9170_handle_mpdu 3 11056 _002739_hash NULL
87231 +_002740_hash do_trimming 3 26952 _002740_hash NULL
87232 +_002741_hash edge_tty_recv 4 18667 _002741_hash &_002721_hash
87233 +_002742_hash fwnet_receive_packet 9 50537 _002742_hash NULL
87234 +_002743_hash gigaset_if_receive 3 4861 _002743_hash NULL
87235 +_002744_hash gsm_dlci_data 3 14155 _002744_hash NULL
87236 +_002745_hash handle_rx_packet 3 58993 _002745_hash NULL
87237 +_002746_hash HDLC_irq 2 8709 _002746_hash NULL
87238 +_002747_hash hdlc_rpr_irq 2 10240 _002747_hash NULL
87239 +_002749_hash ifx_spi_insert_flip_string 3 51752 _002749_hash NULL
87240 +_002753_hash ip_nat_sdp_media 8 23386 _002753_hash NULL
87241 +_002754_hash ip_send_unicast_reply 6 38714 _002754_hash NULL
87242 +_002756_hash ipwireless_network_packet_received 4 51277 _002756_hash NULL
87243 +_002757_hash ipwireless_tty_received 3 49154 _002757_hash NULL
87244 +_002758_hash iscsi_iser_recv 4 41948 _002758_hash NULL
87245 +_002759_hash l2cap_bredr_sig_cmd 3 49065 _002759_hash NULL
87246 +_002760_hash l2cap_sock_alloc_skb_cb 2 33532 _002760_hash NULL
87247 +_002761_hash l2cap_sock_recvmsg 4 59886 _002761_hash NULL
87248 +_002762_hash llcp_allocate_pdu 3 19866 _002762_hash NULL
87249 +_002763_hash macvtap_recvmsg 4 63949 _002763_hash NULL
87250 +_002764_hash osd_req_list_dev_partitions 4 60027 _002764_hash NULL
87251 +_002765_hash osd_req_list_partition_collections 5 38223 _002765_hash NULL
87252 +_002766_hash osst_do_scsi 4 44410 _002766_hash NULL
87253 +_002767_hash ping_sendmsg 4 3782 _002767_hash NULL
87254 +_002768_hash ppp_cp_event 6 2965 _002768_hash NULL
87255 +_002769_hash pty_write 3 44757 _002769_hash &_001733_hash
87256 +_002770_hash push_rx 3 28939 _002770_hash NULL
87257 +_002772_hash qla2x00_handle_queue_full 2 24365 _002772_hash NULL
87258 +_002773_hash qla4xxx_change_queue_depth 2 1268 _002773_hash NULL
87259 +_002774_hash rfcomm_sock_recvmsg 4 22227 _002774_hash NULL
87260 +_002775_hash scsi_execute_req 5 42088 _002775_hash NULL
87261 +_002776_hash _scsih_change_queue_depth 2 26230 _002776_hash NULL
87262 +_002777_hash sctp_sf_abort_violation 6 38380 _002777_hash NULL
87263 +_002778_hash send_to_tty 3 45141 _002778_hash NULL
87264 +_002780_hash sky2_receive 2 13407 _002780_hash NULL
87265 +_002781_hash spi_execute 5 28736 _002781_hash NULL
87266 +_002782_hash submit_inquiry 3 42108 _002782_hash NULL
87267 +_002783_hash tcp_dma_try_early_copy 3 4457 _002783_hash NULL
87268 +_002784_hash tcp_sacktag_walk 6 49703 _002784_hash NULL
87269 +_002785_hash tcp_write_xmit 2 64602 _002785_hash NULL
87270 +_002786_hash ti_recv 4 22027 _002786_hash NULL
87271 +_002787_hash tun_do_read 4 50800 _002787_hash NULL
87272 +_002788_hash ubi_leb_change 4 10289 _002788_hash NULL
87273 +_002789_hash ubi_leb_write 4-5 5478 _002789_hash NULL
87274 +_002791_hash udp_sendmsg 4 4492 _002791_hash NULL
87275 +_002792_hash unix_seqpacket_recvmsg 4 23062 _002792_hash &_000477_hash
87276 +_002793_hash v9fs_cached_file_read 3 2514 _002793_hash NULL
87277 +_002794_hash write_leb 5 36957 _002794_hash NULL
87278 +_002795_hash xfs_buf_read_map 3 40226 _002795_hash NULL
87279 +_002796_hash xfs_trans_get_buf_map 4 2927 _002796_hash NULL
87280 +_002797_hash xlog_do_log_recovery 3 17550 _002797_hash NULL
87281 +_002798_hash ath6kl_wmi_add_wow_pattern_cmd 4 12842 _002798_hash NULL
87282 +_002799_hash ath6kl_wmi_beginscan_cmd 8 25462 _002799_hash NULL
87283 +_002800_hash ath6kl_wmi_send_probe_response_cmd 6 31728 _002800_hash NULL
87284 +_002801_hash ath6kl_wmi_set_appie_cmd 5 39266 _002801_hash NULL
87285 +_002802_hash ath6kl_wmi_set_ie_cmd 6 37260 _002802_hash NULL
87286 +_002803_hash ath6kl_wmi_startscan_cmd 8 33674 _002803_hash NULL
87287 +_002804_hash ath6kl_wmi_test_cmd 3 27312 _002804_hash NULL
87288 +_002805_hash brcmf_sdbrcm_membytes 3-5 37324 _002805_hash NULL
87289 +_002807_hash brcmf_sdbrcm_read_control 3 22721 _002807_hash NULL
87290 +_002808_hash brcmf_tx_frame 3 20978 _002808_hash NULL
87291 +_002809_hash __carl9170_rx 3 56784 _002809_hash NULL
87292 +_002810_hash ch_do_scsi 4 31171 _002810_hash NULL
87293 +_002811_hash dbg_leb_change 4 23555 _002811_hash NULL
87294 +_002812_hash dbg_leb_write 4-5 63555 _002812_hash &_000971_hash
87295 +_002814_hash gluebi_write 3 27905 _002814_hash NULL
87296 +_002815_hash hdlc_irq_one 2 3944 _002815_hash NULL
87297 +_002819_hash iser_rcv_completion 2 8048 _002819_hash NULL
87298 +_002820_hash lock_loop 1 61681 _002820_hash NULL
87299 +_002821_hash process_rcvd_data 3 6679 _002821_hash NULL
87300 +_002822_hash brcmf_sdbrcm_bus_txctl 3 42492 _002822_hash NULL
87301 +_002823_hash carl9170_rx 3 13272 _002823_hash NULL
87302 +_002824_hash carl9170_rx_stream 3 1334 _002824_hash NULL
87303 +_002826_hash mpt_lan_receive_post_turbo 2 13592 _002826_hash NULL
87304 +_002827_hash padzero 1 55 _002827_hash &_002251_hash
87305 +_002828_hash scsi_mode_sense 5 16835 _002828_hash NULL
87306 +_002829_hash scsi_vpd_inquiry 4 30040 _002829_hash NULL
87307 +_002830_hash ses_recv_diag 4 47143 _002830_hash &_000679_hash
87308 +_002831_hash ses_send_diag 4 64527 _002831_hash NULL
87309 +_002832_hash tcp_push_one 2 48816 _002832_hash NULL
87310 +_002833_hash __tcp_push_pending_frames 2 48148 _002833_hash NULL
87311 +_002834_hash trim_bitmaps 3 24158 _002834_hash NULL
87312 +_002835_hash tun_recvmsg 4 48463 _002835_hash NULL
87313 +_002836_hash ubifs_leb_change 4 17789 _002836_hash NULL
87314 +_002837_hash ubifs_leb_write 4-5 22679 _002837_hash NULL
87315 +_002839_hash xfs_buf_readahead_map 3 44248 _002839_hash &_000851_hash
87316 +_002840_hash xfs_trans_read_buf_map 5 37487 _002840_hash NULL
87317 +_002841_hash xlog_do_recover 3 59789 _002841_hash NULL
87318 +_002842_hash btrfs_trim_block_group 3 28963 _002842_hash NULL
87319 +_002843_hash do_write_orph_node 2 64343 _002843_hash NULL
87320 +_002844_hash fix_unclean_leb 3 23188 _002844_hash NULL
87321 +_002845_hash fixup_leb 3 43256 _002845_hash NULL
87322 +_002846_hash recover_head 3 17904 _002846_hash NULL
87323 +_002847_hash scsi_get_vpd_page 4 51951 _002847_hash NULL
87324 +_002848_hash sd_do_mode_sense 5 11507 _002848_hash NULL
87325 +_002849_hash tcp_push 3 10680 _002849_hash NULL
87326 +_002850_hash ubifs_wbuf_write_nolock 3 64946 _002850_hash NULL
87327 +_002851_hash ubifs_write_node 3-5 11258 _002851_hash NULL
87328 +_002852_hash ubifs_recover_leb 3 60639 _002852_hash NULL
87329 +_002853_hash write_head 4 30481 _002853_hash NULL
87330 +_002854_hash write_node 4 33121 _002854_hash NULL
87331 +_002855_hash ubifs_recover_log_leb 3 12079 _002855_hash NULL
87332 +_002856_hash replay_log_leb 3 18704 _002856_hash NULL
87333 +_002857_hash alloc_cpu_rmap 1 65363 _002857_hash NULL
87334 +_002858_hash alloc_ebda_hpc 1-2 50046 _002858_hash NULL
87335 +_002860_hash alloc_sched_domains 1 28972 _002860_hash NULL
87336 +_002861_hash amthi_read 4 45831 _002861_hash NULL
87337 +_002862_hash bcm_char_read 3 31750 _002862_hash NULL
87338 +_002863_hash BcmCopySection 5 2035 _002863_hash NULL
87339 +_002864_hash buffer_from_user 3 51826 _002864_hash NULL
87340 +_002865_hash buffer_to_user 3 35439 _002865_hash NULL
87341 +_002866_hash card_send_command 3 40757 _002866_hash NULL
87342 +_002867_hash chd_dec_fetch_cdata 3 50926 _002867_hash NULL
87343 +_002868_hash copy_nodes_to_user 2 63807 _002868_hash NULL
87344 +_002869_hash create_log 2 8225 _002869_hash NULL
87345 +_002870_hash crystalhd_create_dio_pool 2 3427 _002870_hash NULL
87346 +_002871_hash crystalhd_user_data 3 18407 _002871_hash NULL
87347 +_002872_hash do_pages_stat 2 4437 _002872_hash NULL
87348 +_002873_hash do_read_log_to_user 4 3236 _002873_hash NULL
87349 +_002874_hash do_write_log_from_user 3 39362 _002874_hash NULL
87350 +_002875_hash evm_read_key 3 54674 _002875_hash NULL
87351 +_002876_hash evm_write_key 3 27715 _002876_hash NULL
87352 +_002877_hash fir16_create 3 5574 _002877_hash NULL
87353 +_002878_hash get_nodes 3 39012 _002878_hash NULL
87354 +_002879_hash __iio_allocate_kfifo 2-3 55738 _002879_hash NULL
87355 +_002881_hash __iio_allocate_sw_ring_buffer 3 4843 _002881_hash NULL
87356 +_002882_hash iio_debugfs_read_reg 3 60908 _002882_hash NULL
87357 +_002883_hash iio_debugfs_write_reg 3 22742 _002883_hash NULL
87358 +_002884_hash iio_device_alloc 1 41440 _002884_hash NULL
87359 +_002885_hash iio_event_chrdev_read 3 54757 _002885_hash NULL
87360 +_002886_hash iio_read_first_n_kfifo 2 57910 _002886_hash NULL
87361 +_002887_hash iio_read_first_n_sw_rb 2 51911 _002887_hash NULL
87362 +_002888_hash ioapic_setup_resources 1 35255 _002888_hash NULL
87363 +_002889_hash keymap_store 4 45406 _002889_hash NULL
87364 +_002890_hash line6_alloc_sysex_buffer 4 28225 _002890_hash NULL
87365 +_002891_hash line6_dumpreq_initbuf 3 53123 _002891_hash NULL
87366 +_002892_hash line6_midibuf_init 2 52425 _002892_hash NULL
87367 +_002893_hash _malloc 1 54077 _002893_hash NULL
87368 +_002894_hash mei_read 3 6507 _002894_hash NULL
87369 +_002895_hash mei_write 3 4005 _002895_hash NULL
87370 +_002896_hash msg_set 3 51725 _002896_hash NULL
87371 +_002897_hash newpart 6 47485 _002897_hash NULL
87372 +_002898_hash OS_kmalloc 1 36909 _002898_hash NULL
87373 +_002899_hash OS_mem_token_alloc 1 14276 _002899_hash NULL
87374 +_002900_hash packet_came 3 18072 _002900_hash NULL
87375 +_002901_hash pcpu_alloc_bootmem 2 62074 _002901_hash NULL
87376 +_002902_hash pcpu_build_alloc_info 1-3-2 41443 _002902_hash NULL
87377 +_002905_hash pcpu_get_vm_areas 3 50085 _002905_hash NULL
87378 +_002906_hash resource_from_user 3 30341 _002906_hash NULL
87379 +_002907_hash rtsx_read_cfg_seq 3-5 48139 _002907_hash NULL
87380 +_002909_hash rtsx_write_cfg_seq 3-5 27485 _002909_hash NULL
87381 +_002911_hash sca3000_read_data 4 57064 _002911_hash NULL
87382 +_002912_hash sca3000_read_first_n_hw_rb 2 11479 _002912_hash NULL
87383 +_002913_hash send_midi_async 3 57463 _002913_hash NULL
87384 +_002914_hash sep_create_dcb_dmatables_context 6 37551 _002914_hash NULL
87385 +_002915_hash sep_create_dcb_dmatables_context_kernel 6 49728 _002915_hash NULL
87386 +_002916_hash sep_create_msgarea_context 4 33829 _002916_hash NULL
87387 +_002917_hash sep_lli_table_secure_dma 2-3 64042 _002917_hash NULL
87388 +_002919_hash sep_lock_user_pages 2-3 57470 _002919_hash &_002488_hash
87389 +_002921_hash sep_prepare_input_output_dma_table_in_dcb 4-5-2-3 63087 _002921_hash NULL
87390 +_002923_hash sep_read 3 17161 _002923_hash NULL
87391 +_002924_hash TransmitTcb 4 12989 _002924_hash NULL
87392 +_002925_hash ValidateDSDParamsChecksum 3 63654 _002925_hash NULL
87393 +_002926_hash Wb35Reg_BurstWrite 4 62327 _002926_hash NULL
87394 +_002927_hash alloc_irq_cpu_rmap 1 28459 _002927_hash NULL
87395 +_002928_hash InterfaceTransmitPacket 3 42058 _002928_hash NULL
87396 +_002929_hash line6_dumpreq_init 3 34473 _002929_hash NULL
87397 +_002931_hash pcpu_embed_first_chunk 1-3-2 24224 _002931_hash NULL
87398 +_002933_hash pcpu_fc_alloc 2 11818 _002933_hash NULL
87399 +_002934_hash pcpu_page_first_chunk 1 20712 _002934_hash NULL
87400 +_002935_hash pod_alloc_sysex_buffer 3 31651 _002935_hash NULL
87401 +_002936_hash r8712_usbctrl_vendorreq 6 48489 _002936_hash NULL
87402 +_002937_hash r871x_set_wpa_ie 3 7000 _002937_hash NULL
87403 +_002938_hash sep_prepare_input_dma_table 2-3 2009 _002938_hash NULL
87404 +_002940_hash sep_prepare_input_output_dma_table 2-4-3 63429 _002940_hash NULL
87405 +_002943_hash sys_get_mempolicy 3 30379 _002943_hash NULL
87406 +_002944_hash sys_mbind 5 7990 _002944_hash NULL
87407 +_002945_hash sys_migrate_pages 2 39825 _002945_hash NULL
87408 +_002946_hash sys_move_pages 2 42626 _002946_hash NULL
87409 +_002947_hash sys_set_mempolicy 3 32608 _002947_hash NULL
87410 +_002948_hash variax_alloc_sysex_buffer 3 15237 _002948_hash NULL
87411 +_002949_hash vme_user_read 3 55338 _002949_hash NULL
87412 +_002950_hash vme_user_write 3 15587 _002950_hash NULL
87413 +_002954_hash variax_set_raw2 4 32374 _002954_hash NULL
87414 +_002955_hash copy_in_user 3 57502 _002955_hash NULL
87415 +_002956_hash __earlyonly_bootmem_alloc 2 23824 _002956_hash NULL
87416 +_002957_hash rfc4106_set_key 3 54519 _002957_hash NULL
87417 +_002958_hash sparse_early_usemaps_alloc_pgdat_section 2 62304 _002958_hash NULL
87418 +_002959_hash sparse_early_usemaps_alloc_node 4 9269 _002959_hash NULL
87419 +_002960_hash sparse_mem_maps_populate_node 4 12669 _002960_hash &_002242_hash
87420 +_002961_hash vmemmap_alloc_block 1 43245 _002961_hash NULL
87421 +_002962_hash sparse_early_mem_maps_alloc_node 4 36971 _002962_hash NULL
87422 +_002963_hash vmemmap_alloc_block_buf 1 61126 _002963_hash NULL
87423 +_002964_hash alloc_mr 1 45935 _002964_hash NULL
87424 +_002965_hash atomic_counters_read 3 48827 _002965_hash NULL
87425 +_002966_hash atomic_stats_read 3 36228 _002966_hash NULL
87426 +_002967_hash capabilities_read 3 58457 _002967_hash NULL
87427 +_002968_hash compat_core_sys_select 1 65285 _002968_hash NULL
87428 +_002969_hash compat_dccp_setsockopt 5 51263 _002969_hash NULL
87429 +_002970_hash compat_do_arpt_set_ctl 4 12184 _002970_hash NULL
87430 +_002971_hash compat_do_ip6t_set_ctl 4 3184 _002971_hash NULL
87431 +_002972_hash compat_do_ipt_set_ctl 4 58466 _002972_hash &_002078_hash
87432 +_002973_hash compat_filldir 3 32999 _002973_hash NULL
87433 +_002974_hash compat_filldir64 3 35354 _002974_hash NULL
87434 +_002975_hash compat_fillonedir 3 15620 _002975_hash NULL
87435 +_002976_hash compat_ip_setsockopt 5 13870 _003094_hash NULL nohasharray
87436 +_002977_hash compat_ipv6_setsockopt 5 20468 _002977_hash NULL
87437 +_002978_hash compat_mpctl_ioctl 2 45671 _002978_hash NULL
87438 +_002979_hash compat_raw_setsockopt 5 30634 _002979_hash NULL
87439 +_002980_hash compat_rawv6_setsockopt 5 4967 _002980_hash NULL
87440 +_002981_hash compat_rw_copy_check_uvector 3 22001 _003263_hash NULL nohasharray
87441 +_002982_hash compat_sock_setsockopt 5 23 _002982_hash NULL
87442 +_002983_hash compat_sys_get_mempolicy 3 31109 _002983_hash NULL
87443 +_002984_hash compat_sys_kexec_load 2 35674 _002984_hash NULL
87444 +_002985_hash compat_sys_keyctl 4 9639 _002985_hash NULL
87445 +_002986_hash compat_sys_mbind 5 36256 _002986_hash NULL
87446 +_002987_hash compat_sys_migrate_pages 2 3157 _002987_hash NULL
87447 +_002988_hash compat_sys_move_pages 2 5861 _002988_hash NULL
87448 +_002989_hash compat_sys_mq_timedsend 3 31060 _002989_hash NULL
87449 +_002990_hash compat_sys_msgrcv 2 7482 _002990_hash NULL
87450 +_002991_hash compat_sys_msgsnd 2 10738 _002991_hash NULL
87451 +_002992_hash compat_sys_semtimedop 3 3606 _002992_hash NULL
87452 +_002993_hash compat_sys_set_mempolicy 3 57742 _002993_hash &_002614_hash
87453 +_002994_hash __copy_in_user 3 34790 _002994_hash NULL
87454 +_002995_hash dev_counters_read 3 19216 _002995_hash NULL
87455 +_002996_hash dev_names_read 3 38509 _002996_hash NULL
87456 +_002997_hash driver_names_read 3 60399 _002997_hash NULL
87457 +_002998_hash driver_stats_read 3 8944 _002998_hash NULL
87458 +_002999_hash evdev_ioctl_compat 2 13851 _002999_hash NULL
87459 +_003000_hash evtchn_read 3 3569 _003000_hash NULL
87460 +_003001_hash evtchn_write 3 43278 _003001_hash NULL
87461 +_003002_hash fat_compat_ioctl_filldir 3 36328 _003002_hash NULL
87462 +_003003_hash flash_read 3 57843 _003003_hash NULL
87463 +_003004_hash flash_write 3 62354 _003004_hash NULL
87464 +_003005_hash fw_device_op_compat_ioctl 2 42804 _003005_hash NULL
87465 +_003006_hash gather_array 3 56641 _003006_hash NULL
87466 +_003007_hash ghash_async_setkey 3 60001 _003007_hash NULL
87467 +_003008_hash gntdev_alloc_map 2 35145 _003008_hash NULL
87468 +_003009_hash gnttab_map 2 56439 _003009_hash NULL
87469 +_003010_hash gru_alloc_gts 2-3 60056 _003010_hash &_000981_hash
87470 +_003012_hash hiddev_compat_ioctl 2 41255 _003012_hash NULL
87471 +_003013_hash init_cdev 1 8274 _003013_hash NULL
87472 +_003014_hash init_per_cpu 1 17880 _003014_hash NULL
87473 +_003015_hash ipath_create_cq 2 45586 _003015_hash NULL
87474 +_003016_hash ipath_get_base_info 3 7043 _003016_hash NULL
87475 +_003017_hash ipath_init_qp_table 2 25167 _003017_hash NULL
87476 +_003018_hash ipath_resize_cq 2 712 _003018_hash NULL
87477 +_003019_hash joydev_compat_ioctl 2 8765 _003019_hash NULL
87478 +_003020_hash mon_bin_compat_ioctl 3 50234 _003020_hash NULL
87479 +_003021_hash options_write 3 47243 _003021_hash NULL
87480 +_003022_hash portcntrs_1_read 3 47253 _003022_hash NULL
87481 +_003023_hash portcntrs_2_read 3 56586 _003023_hash NULL
87482 +_003024_hash portnames_read 3 41958 _003024_hash NULL
87483 +_003025_hash ptc_proc_write 3 12076 _003025_hash NULL
87484 +_003026_hash put_cmsg_compat 4 35937 _003026_hash NULL
87485 +_003027_hash qib_alloc_devdata 2 51819 _003027_hash NULL
87486 +_003028_hash qib_alloc_fast_reg_page_list 2 10507 _003028_hash NULL
87487 +_003029_hash qib_cdev_init 1 34778 _003029_hash NULL
87488 +_003030_hash qib_create_cq 2 27497 _003030_hash NULL
87489 +_003031_hash qib_diag_write 3 62133 _003031_hash NULL
87490 +_003032_hash qib_get_base_info 3 11369 _003032_hash NULL
87491 +_003033_hash qib_resize_cq 2 53090 _003033_hash NULL
87492 +_003034_hash qsfp_1_read 3 21915 _003034_hash NULL
87493 +_003035_hash qsfp_2_read 3 31491 _003035_hash NULL
87494 +_003036_hash queue_reply 3 22416 _003036_hash NULL
87495 +_003037_hash spidev_compat_ioctl 2 63778 _003037_hash NULL
87496 +_003038_hash split 2 11691 _003038_hash NULL
87497 +_003039_hash stats_read_ul 3 32751 _003039_hash NULL
87498 +_003040_hash sys32_ipc 3 7238 _003040_hash NULL
87499 +_003041_hash sys32_rt_sigpending 2 25814 _003041_hash NULL
87500 +_003042_hash tunables_read 3 36385 _003042_hash NULL
87501 +_003043_hash tunables_write 3 59563 _003043_hash NULL
87502 +_003044_hash xenbus_file_write 3 6282 _003044_hash NULL
87503 +_003045_hash xlbd_reserve_minors 1-2 18365 _003045_hash NULL
87504 +_003047_hash xpc_kmalloc_cacheline_aligned 1 42895 _003047_hash NULL
87505 +_003048_hash xpc_kzalloc_cacheline_aligned 1 65433 _003048_hash NULL
87506 +_003049_hash xsd_read 3 15653 _003049_hash NULL
87507 +_003050_hash compat_do_readv_writev 4 49102 _003050_hash NULL
87508 +_003051_hash compat_keyctl_instantiate_key_iov 3 57431 _003088_hash NULL nohasharray
87509 +_003052_hash compat_process_vm_rw 3-5 22254 _003052_hash NULL
87510 +_003054_hash compat_sys_select 1 16131 _003054_hash NULL
87511 +_003055_hash compat_sys_setsockopt 5 3326 _003055_hash NULL
87512 +_003056_hash compat_udp_setsockopt 5 38840 _003056_hash NULL
87513 +_003057_hash compat_udpv6_setsockopt 5 42981 _003057_hash NULL
87514 +_003058_hash do_compat_pselect 1 10398 _003058_hash NULL
87515 +_003059_hash gnttab_expand 1 15817 _003059_hash NULL
87516 +_003060_hash ipath_cdev_init 1 37752 _003060_hash NULL
87517 +_003061_hash ipath_reg_phys_mr 3 23918 _003061_hash &_000999_hash
87518 +_003062_hash qib_alloc_fast_reg_mr 2 12526 _003062_hash NULL
87519 +_003063_hash qib_reg_phys_mr 3 60202 _003063_hash &_000897_hash
87520 +_003064_hash compat_readv 3 30273 _003064_hash NULL
87521 +_003065_hash compat_sys_process_vm_readv 3-5 15374 _003065_hash NULL
87522 +_003067_hash compat_sys_process_vm_writev 3-5 41194 _003067_hash NULL
87523 +_003069_hash compat_sys_pselect6 1 14105 _003069_hash NULL
87524 +_003070_hash compat_writev 3 60063 _003070_hash NULL
87525 +_003071_hash get_free_entries 1 46030 _003071_hash NULL
87526 +_003072_hash compat_sys_preadv64 3 24283 _003072_hash NULL
87527 +_003073_hash compat_sys_pwritev64 3 51151 _003073_hash NULL
87528 +_003074_hash compat_sys_readv 3 20911 _003074_hash NULL
87529 +_003075_hash compat_sys_writev 3 5784 _003075_hash NULL
87530 +_003076_hash gnttab_alloc_grant_references 1 18240 _003076_hash NULL
87531 +_003077_hash compat_sys_preadv 3 583 _003077_hash NULL
87532 +_003078_hash compat_sys_pwritev 3 17886 _003078_hash NULL
87533 +_003079_hash aes_decrypt_fail_read 3 54815 _003079_hash NULL
87534 +_003080_hash aes_decrypt_interrupt_read 3 19910 _003080_hash NULL
87535 +_003081_hash aes_decrypt_packets_read 3 10155 _003081_hash NULL
87536 +_003082_hash aes_encrypt_fail_read 3 32562 _003082_hash NULL
87537 +_003083_hash aes_encrypt_interrupt_read 3 39919 _003083_hash NULL
87538 +_003084_hash aes_encrypt_packets_read 3 48666 _003084_hash NULL
87539 +_003085_hash agp_remap 2 30665 _003085_hash NULL
87540 +_003086_hash alloc_apertures 1 56561 _003086_hash NULL
87541 +_003087_hash allocate_probes 1 40204 _003087_hash NULL
87542 +_003088_hash alloc_ftrace_hash 1 57431 _003088_hash &_003051_hash
87543 +_003089_hash alloc_page_cgroup 1 2919 _003089_hash NULL
87544 +_003090_hash __alloc_preds 2 9492 _003090_hash NULL
87545 +_003091_hash __alloc_pred_stack 2 26687 _003091_hash NULL
87546 +_003092_hash alloc_sched_domains 1 47756 _003092_hash NULL
87547 +_003093_hash alloc_trace_probe 6 38720 _003093_hash NULL
87548 +_003094_hash alloc_trace_uprobe 3 13870 _003094_hash &_002976_hash
87549 +_003095_hash ath6kl_sdio_alloc_prep_scat_req 2 51986 _003095_hash NULL
87550 +_003096_hash ath6kl_usb_post_recv_transfers 2 32892 _003096_hash NULL
87551 +_003097_hash ath6kl_usb_submit_ctrl_in 6 32880 _003097_hash &_000795_hash
87552 +_003098_hash ath6kl_usb_submit_ctrl_out 6 9978 _003098_hash NULL
87553 +_003099_hash av7110_ipack_init 2 46655 _003099_hash NULL
87554 +_003100_hash av7110_vbi_write 3 34384 _003100_hash NULL
87555 +_003101_hash bin_uuid 3 28999 _003101_hash NULL
87556 +_003102_hash blk_dropped_read 3 4168 _003102_hash NULL
87557 +_003103_hash blk_msg_write 3 13655 _003103_hash NULL
87558 +_003104_hash brcmf_usbdev_qinit 2 19090 _003104_hash &_001715_hash
87559 +_003105_hash brcmf_usb_dl_cmd 4 53130 _003105_hash NULL
87560 +_003106_hash ci_ll_init 3 12930 _003106_hash NULL
87561 +_003107_hash ci_ll_write 4 3740 _003107_hash NULL
87562 +_003108_hash conf_read 3 55786 _003108_hash NULL
87563 +_003109_hash __copy_from_user_inatomic_nocache 3 49921 _003109_hash NULL
87564 +_003110_hash cx24116_writeregN 4 41975 _003110_hash NULL
87565 +_003111_hash cyttsp_probe 4 1940 _003111_hash NULL
87566 +_003112_hash dccpprobe_read 3 52549 _003112_hash NULL
87567 +_003113_hash ddb_input_read 3 9743 _003113_hash NULL
87568 +_003114_hash ddb_output_write 3 31902 _003114_hash NULL
87569 +_003115_hash __devres_alloc 2 25598 _003115_hash NULL
87570 +_003116_hash dma_rx_errors_read 3 52045 _003116_hash NULL
87571 +_003117_hash dma_rx_requested_read 3 65354 _003117_hash NULL
87572 +_003118_hash dma_tx_errors_read 3 46060 _003118_hash NULL
87573 +_003119_hash dma_tx_requested_read 3 16110 _003203_hash NULL nohasharray
87574 +_003120_hash do_dmabuf_dirty_sou 7 3017 _003120_hash NULL
87575 +_003121_hash do_surface_dirty_sou 7 39678 _003121_hash NULL
87576 +_003122_hash driver_state_read 3 17194 _003122_hash &_001511_hash
87577 +_003123_hash drm_agp_bind_pages 3 56748 _003123_hash NULL
87578 +_003124_hash drm_buffer_alloc 2 44405 _003124_hash NULL
87579 +_003125_hash drm_calloc_large 1-2 65421 _003125_hash NULL
87580 +_003127_hash drm_fb_helper_init 3-4 19044 _003127_hash NULL
87581 +_003129_hash drm_ht_create 2 18853 _003129_hash NULL
87582 +_003130_hash drm_ioctl 2 42813 _003130_hash NULL
87583 +_003131_hash drm_malloc_ab 1-2 16831 _003131_hash NULL
87584 +_003133_hash drm_mode_crtc_set_gamma_size 2 31881 _003133_hash NULL
87585 +_003134_hash drm_plane_init 6 28731 _003134_hash NULL
87586 +_003135_hash drm_property_create 4 51239 _003135_hash NULL
87587 +_003136_hash drm_property_create_blob 2 7414 _003136_hash NULL
87588 +_003137_hash drm_vblank_init 2 11362 _003137_hash NULL
87589 +_003138_hash drm_vmalloc_dma 1 14550 _003138_hash NULL
87590 +_003139_hash dvb_aplay 3 56296 _003139_hash NULL
87591 +_003140_hash dvb_ca_en50221_init 4 45718 _003140_hash NULL
87592 +_003141_hash dvb_ca_en50221_io_write 3 43533 _003141_hash NULL
87593 +_003142_hash dvb_dmxdev_set_buffer_size 2 55643 _003142_hash NULL
87594 +_003143_hash dvbdmx_write 3 19423 _003143_hash NULL
87595 +_003144_hash dvb_dvr_set_buffer_size 2 9840 _003144_hash NULL
87596 +_003145_hash dvb_net_sec 3 37884 _003145_hash NULL
87597 +_003146_hash dvb_play 3 50814 _003146_hash NULL
87598 +_003147_hash dvb_ringbuffer_pkt_read_user 2-5-3 4303 _003147_hash NULL
87599 +_003150_hash dvb_ringbuffer_read_user 3 56702 _003150_hash NULL
87600 +_003151_hash dvb_usercopy 2 14036 _003151_hash NULL
87601 +_003152_hash dw210x_op_rw 6 39915 _003152_hash NULL
87602 +_003153_hash edt_ft5x06_debugfs_raw_data_read 3 28002 _003153_hash NULL
87603 +_003154_hash em_canid_change 3 14150 _003154_hash NULL
87604 +_003155_hash event_calibration_read 3 21083 _003155_hash NULL
87605 +_003156_hash event_enable_read 3 7074 _003156_hash NULL
87606 +_003157_hash event_filter_read 3 23494 _003157_hash NULL
87607 +_003158_hash event_filter_write 3 56609 _003158_hash NULL
87608 +_003159_hash event_heart_beat_read 3 48961 _003159_hash NULL
87609 +_003160_hash event_id_read 3 64288 _003160_hash &_001300_hash
87610 +_003161_hash event_oom_late_read 3 61175 _003161_hash &_001054_hash
87611 +_003162_hash event_phy_transmit_error_read 3 10471 _003162_hash NULL
87612 +_003163_hash event_rx_mem_empty_read 3 40363 _003163_hash NULL
87613 +_003164_hash event_rx_mismatch_read 3 38518 _003164_hash NULL
87614 +_003165_hash event_rx_pool_read 3 25792 _003165_hash NULL
87615 +_003166_hash event_tx_stuck_read 3 19305 _003166_hash NULL
87616 +_003167_hash excessive_retries_read 3 60425 _003167_hash NULL
87617 +_003168_hash flexcop_device_kmalloc 1 54793 _003168_hash NULL
87618 +_003169_hash fm_send_cmd 5 39639 _003169_hash NULL
87619 +_003170_hash __fprog_create 2 41263 _003170_hash NULL
87620 +_003171_hash fq_codel_zalloc 1 15378 _003171_hash NULL
87621 +_003172_hash ftrace_pid_write 3 39710 _003172_hash NULL
87622 +_003173_hash ftrace_profile_read 3 21327 _003173_hash NULL
87623 +_003174_hash fw_stats_raw_read 3 1369 _003174_hash NULL
87624 +_003175_hash get_info 3 55681 _003175_hash NULL
87625 +_003176_hash __get_vm_area_node 1 55305 _003176_hash NULL
87626 +_003177_hash gpio_power_read 3 36059 _003177_hash NULL
87627 +_003178_hash h5_prepare_pkt 4 12085 _003178_hash NULL
87628 +_003179_hash hsc_msg_alloc 1 60990 _003179_hash NULL
87629 +_003180_hash hsc_write 3 55875 _003180_hash NULL
87630 +_003181_hash hsi_alloc_controller 1 41802 _003181_hash NULL
87631 +_003182_hash hsi_register_board_info 2 13820 _003182_hash NULL
87632 +_003183_hash hugetlb_cgroup_read 5 49259 _003183_hash NULL
87633 +_003184_hash i915_cache_sharing_read 3 24775 _003184_hash NULL
87634 +_003185_hash i915_cache_sharing_write 3 57961 _003185_hash NULL
87635 +_003186_hash i915_max_freq_read 3 20581 _003186_hash NULL
87636 +_003187_hash i915_max_freq_write 3 11350 _003187_hash NULL
87637 +_003188_hash i915_min_freq_read 3 38470 _003188_hash NULL
87638 +_003189_hash i915_min_freq_write 3 10981 _003189_hash NULL
87639 +_003190_hash i915_ring_stop_read 3 42549 _003190_hash &_000740_hash
87640 +_003191_hash i915_ring_stop_write 3 59010 _003191_hash NULL
87641 +_003192_hash i915_wedged_read 3 35474 _003192_hash NULL
87642 +_003193_hash i915_wedged_write 3 47771 _003193_hash NULL
87643 +_003194_hash ieee802154_alloc_device 1 13767 _003194_hash NULL
87644 +_003195_hash intel_sdvo_write_cmd 4 54377 _003195_hash &_000832_hash
87645 +_003196_hash isr_cmd_cmplt_read 3 53439 _003196_hash NULL
87646 +_003197_hash isr_commands_read 3 41398 _003197_hash NULL
87647 +_003198_hash isr_decrypt_done_read 3 49490 _003198_hash NULL
87648 +_003199_hash isr_dma0_done_read 3 8574 _003199_hash NULL
87649 +_003200_hash isr_dma1_done_read 3 48159 _003200_hash NULL
87650 +_003201_hash isr_fiqs_read 3 34687 _003201_hash NULL
87651 +_003202_hash isr_host_acknowledges_read 3 54136 _003202_hash NULL
87652 +_003203_hash isr_hw_pm_mode_changes_read 3 16110 _003203_hash &_003119_hash
87653 +_003204_hash isr_irqs_read 3 9181 _003204_hash NULL
87654 +_003205_hash isr_low_rssi_read 3 64789 _003205_hash NULL
87655 +_003206_hash isr_pci_pm_read 3 30271 _003206_hash NULL
87656 +_003207_hash isr_rx_headers_read 3 38325 _003207_hash NULL
87657 +_003208_hash isr_rx_mem_overflow_read 3 43025 _003208_hash NULL
87658 +_003209_hash isr_rx_procs_read 3 31804 _003209_hash NULL
87659 +_003210_hash isr_rx_rdys_read 3 35283 _003210_hash NULL
87660 +_003211_hash isr_tx_exch_complete_read 3 16103 _003211_hash NULL
87661 +_003212_hash isr_tx_procs_read 3 23084 _003212_hash NULL
87662 +_003213_hash isr_wakeups_read 3 49607 _003213_hash NULL
87663 +_003214_hash LoadBitmap 2 19658 _003214_hash NULL
87664 +_003215_hash mem_cgroup_read 5 22461 _003215_hash NULL
87665 +_003216_hash mic_calc_failure_read 3 59700 _003216_hash NULL
87666 +_003217_hash mic_rx_pkts_read 3 27972 _003217_hash NULL
87667 +_003218_hash __module_alloc 1 50004 _003218_hash NULL
87668 +_003219_hash module_alloc_update_bounds_rw 1 63233 _003219_hash NULL
87669 +_003220_hash module_alloc_update_bounds_rx 1 58634 _003220_hash NULL
87670 +_003221_hash mwifiex_usb_submit_rx_urb 2 54558 _003221_hash NULL
87671 +_003222_hash nfc_hci_hcp_message_tx 6 14534 _003222_hash NULL
87672 +_003223_hash nfc_hci_set_param 5 40697 _003223_hash NULL
87673 +_003224_hash nfc_shdlc_alloc_skb 2 12741 _003224_hash NULL
87674 +_003225_hash opera1_xilinx_rw 5 31453 _003225_hash NULL
87675 +_003226_hash persistent_ram_vmap 1-2 709 _003226_hash NULL
87676 +_003228_hash prctl_set_mm 3 64538 _003228_hash NULL
87677 +_003229_hash probe_kernel_write 3 17481 _003229_hash NULL
87678 +_003230_hash proc_fault_inject_read 3 36802 _003230_hash NULL
87679 +_003231_hash proc_fault_inject_write 3 21058 _003231_hash NULL
87680 +_003232_hash ps_pspoll_max_apturn_read 3 6699 _003232_hash NULL
87681 +_003233_hash ps_pspoll_timeouts_read 3 11776 _003233_hash NULL
87682 +_003234_hash ps_pspoll_utilization_read 3 5361 _003234_hash NULL
87683 +_003235_hash ps_upsd_max_apturn_read 3 19918 _003235_hash NULL
87684 +_003236_hash ps_upsd_max_sptime_read 3 63362 _003236_hash NULL
87685 +_003237_hash ps_upsd_timeouts_read 3 28924 _003237_hash NULL
87686 +_003238_hash ps_upsd_utilization_read 3 51669 _003238_hash NULL
87687 +_003239_hash ptp_filter_init 2 36780 _003239_hash NULL
87688 +_003240_hash pwr_disable_ps_read 3 13176 _003240_hash NULL
87689 +_003241_hash pwr_elp_enter_read 3 5324 _003241_hash NULL
87690 +_003242_hash pwr_enable_ps_read 3 17686 _003242_hash NULL
87691 +_003243_hash pwr_fix_tsf_ps_read 3 26627 _003243_hash NULL
87692 +_003244_hash pwr_missing_bcns_read 3 25824 _003244_hash NULL
87693 +_003245_hash pwr_power_save_off_read 3 18355 _003245_hash NULL
87694 +_003246_hash pwr_ps_enter_read 3 26935 _003246_hash &_000512_hash
87695 +_003247_hash pwr_rcvd_awake_beacons_read 3 50505 _003247_hash NULL
87696 +_003248_hash pwr_rcvd_beacons_read 3 52836 _003248_hash NULL
87697 +_003249_hash pwr_tx_without_ps_read 3 48423 _003249_hash NULL
87698 +_003250_hash pwr_tx_with_ps_read 3 60851 _003250_hash NULL
87699 +_003251_hash pwr_wake_on_host_read 3 26321 _003251_hash NULL
87700 +_003252_hash pwr_wake_on_timer_exp_read 3 22640 _003252_hash NULL
87701 +_003253_hash rb_simple_read 3 45972 _003253_hash NULL
87702 +_003254_hash read_file_dfs 3 43145 _003254_hash NULL
87703 +_003255_hash retry_count_read 3 52129 _003255_hash NULL
87704 +_003256_hash rx_dropped_read 3 44799 _003256_hash NULL
87705 +_003257_hash rx_fcs_err_read 3 62844 _003257_hash NULL
87706 +_003258_hash rx_hdr_overflow_read 3 64407 _003258_hash NULL
87707 +_003259_hash rx_hw_stuck_read 3 57179 _003259_hash NULL
87708 +_003260_hash rx_out_of_mem_read 3 10157 _003260_hash NULL
87709 +_003261_hash rx_path_reset_read 3 23801 _003261_hash NULL
87710 +_003262_hash rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 _003262_hash NULL
87711 +_003263_hash rxpipe_descr_host_int_trig_rx_data_read 3 22001 _003263_hash &_002981_hash
87712 +_003264_hash rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 _003264_hash NULL
87713 +_003265_hash rxpipe_rx_prep_beacon_drop_read 3 2403 _003265_hash NULL
87714 +_003266_hash rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 _003266_hash NULL
87715 +_003267_hash rx_reset_counter_read 3 58001 _003267_hash NULL
87716 +_003268_hash rx_xfr_hint_trig_read 3 40283 _003268_hash NULL
87717 +_003269_hash saa7146_vmalloc_build_pgtable 2 19780 _003269_hash NULL
87718 +_003270_hash sched_feat_write 3 55202 _003270_hash NULL
87719 +_003271_hash sd_alloc_ctl_entry 1 29708 _003271_hash NULL
87720 +_003272_hash shmem_pread_fast 3 34147 _003272_hash NULL
87721 +_003273_hash shmem_pread_slow 3 3198 _003273_hash NULL
87722 +_003274_hash shmem_pwrite_slow 3 31741 _003274_hash NULL
87723 +_003275_hash show_header 3 4722 _003275_hash &_000745_hash
87724 +_003276_hash stack_max_size_read 3 1445 _003276_hash NULL
87725 +_003277_hash subsystem_filter_read 3 62310 _003277_hash NULL
87726 +_003278_hash subsystem_filter_write 3 13022 _003278_hash NULL
87727 +_003279_hash swap_cgroup_swapon 2 13614 _003279_hash NULL
87728 +_003280_hash system_enable_read 3 25815 _003280_hash NULL
87729 +_003281_hash tda10048_writeregbulk 4 11050 _003281_hash NULL
87730 +_003282_hash tlbflush_read_file 3 64661 _003282_hash NULL
87731 +_003283_hash trace_options_core_read 3 47390 _003283_hash NULL
87732 +_003284_hash trace_options_read 3 11419 _003284_hash NULL
87733 +_003285_hash trace_parser_get_init 2 31379 _003285_hash NULL
87734 +_003286_hash traceprobe_probes_write 3 64969 _003286_hash NULL
87735 +_003287_hash trace_seq_to_user 3 65398 _003287_hash NULL
87736 +_003288_hash tracing_buffers_read 3 11124 _003288_hash NULL
87737 +_003289_hash tracing_clock_write 3 27961 _003289_hash NULL
87738 +_003290_hash tracing_cpumask_read 3 7010 _003290_hash NULL
87739 +_003291_hash tracing_ctrl_read 3 46922 _003291_hash NULL
87740 +_003292_hash tracing_entries_read 3 8345 _003292_hash NULL
87741 +_003293_hash tracing_max_lat_read 3 8890 _003293_hash NULL
87742 +_003294_hash tracing_read_dyn_info 3 45468 _003294_hash NULL
87743 +_003295_hash tracing_readme_read 3 16493 _003295_hash NULL
87744 +_003296_hash tracing_saved_cmdlines_read 3 21434 _003296_hash NULL
87745 +_003297_hash tracing_set_trace_read 3 44122 _003297_hash NULL
87746 +_003298_hash tracing_set_trace_write 3 57096 _003298_hash NULL
87747 +_003299_hash tracing_stats_read 3 34537 _003299_hash NULL
87748 +_003300_hash tracing_total_entries_read 3 62817 _003300_hash NULL
87749 +_003301_hash tracing_trace_options_write 3 153 _003301_hash NULL
87750 +_003302_hash tstats_write 3 60432 _003302_hash &_000009_hash
87751 +_003303_hash ttm_bo_fbdev_io 4 9805 _003303_hash NULL
87752 +_003304_hash ttm_bo_io 5 47000 _003304_hash NULL
87753 +_003305_hash ttm_dma_page_pool_free 2 34135 _003305_hash NULL
87754 +_003306_hash ttm_page_pool_free 2 61661 _003306_hash NULL
87755 +_003307_hash ttusb2_msg 4 3100 _003307_hash NULL
87756 +_003308_hash tx_internal_desc_overflow_read 3 47300 _003308_hash NULL
87757 +_003309_hash tx_queue_len_read 3 1463 _003309_hash NULL
87758 +_003310_hash tx_queue_status_read 3 44978 _003310_hash NULL
87759 +_003311_hash u_memcpya 2-3 30139 _003311_hash NULL
87760 +_003313_hash usb_allocate_stream_buffers 3 8964 _003313_hash NULL
87761 +_003314_hash vifs_state_read 3 33762 _003314_hash NULL
87762 +_003315_hash vmalloc_to_sg 2 58354 _003315_hash NULL
87763 +_003316_hash vm_map_ram 2 23078 _003316_hash &_001095_hash
87764 +_003317_hash vmw_execbuf_process 5 22885 _003317_hash NULL
87765 +_003318_hash vmw_fifo_reserve 2 12141 _003318_hash NULL
87766 +_003319_hash vmw_kms_present 9 38130 _003319_hash NULL
87767 +_003320_hash vmw_kms_readback 6 5727 _003320_hash NULL
87768 +_003321_hash wep_addr_key_count_read 3 20174 _003321_hash NULL
87769 +_003322_hash wep_decrypt_fail_read 3 58567 _003322_hash NULL
87770 +_003323_hash wep_default_key_count_read 3 43035 _003323_hash NULL
87771 +_003324_hash wep_interrupt_read 3 41492 _003324_hash NULL
87772 +_003325_hash wep_key_not_found_read 3 13377 _003325_hash &_000952_hash
87773 +_003326_hash wep_packets_read 3 18751 _003326_hash NULL
87774 +_003327_hash wl1251_cmd_template_set 4 6172 _003327_hash NULL
87775 +_003328_hash wl1271_format_buffer 2 20834 _003328_hash NULL
87776 +_003329_hash wl1271_rx_filter_alloc_field 5 46721 _003329_hash NULL
87777 +_003330_hash wl12xx_cmd_build_probe_req 6-8 54946 _003330_hash NULL
87778 +_003332_hash wlcore_alloc_hw 1 7785 _003332_hash NULL
87779 +_003333_hash aggr_size_rx_size_read 3 33526 _003333_hash NULL
87780 +_003334_hash aggr_size_tx_agg_vs_rate_read 3 21438 _003334_hash NULL
87781 +_003335_hash alloc_and_copy_ftrace_hash 1 29368 _003335_hash NULL
87782 +_003336_hash alloc_bulk_urbs_generic 5 12127 _003336_hash NULL
87783 +_003337_hash alloc_ieee80211 1 20063 _003337_hash NULL
87784 +_003338_hash alloc_ieee80211_rsl 1 34564 _003338_hash NULL
87785 +_003339_hash alloc_perm_bits 2 1532 _003339_hash NULL
87786 +_003340_hash alloc_private 2 22399 _003340_hash NULL
87787 +_003341_hash alloc_rtllib 1 51136 _003341_hash NULL
87788 +_003342_hash alloc_rx_desc_ring 2 18016 _003342_hash NULL
87789 +_003343_hash arcfb_write 3 8702 _003343_hash NULL
87790 +_003344_hash ath6kl_usb_bmi_read 3 48745 _003344_hash NULL
87791 +_003345_hash ath6kl_usb_bmi_write 3 2454 _003345_hash &_001020_hash
87792 +_003346_hash ath6kl_usb_ctrl_msg_exchange 4 33327 _003346_hash NULL
87793 +_003347_hash au0828_init_isoc 2-3 61917 _003347_hash NULL
87794 +_003349_hash auok190xfb_write 3 37001 _003349_hash NULL
87795 +_003350_hash beacon_interval_read 3 7091 _003350_hash NULL
87796 +_003351_hash brcmf_usb_attach 1-2 44656 _003351_hash NULL
87797 +_003353_hash broadsheetfb_write 3 39976 _003353_hash NULL
87798 +_003354_hash broadsheet_spiflash_rewrite_sector 2 54864 _003354_hash NULL
87799 +_003355_hash ci13xxx_add_device 3 14456 _003355_hash NULL
87800 +_003356_hash cmpk_message_handle_tx 4 54024 _003356_hash NULL
87801 +_003357_hash comedi_alloc_subdevices 2 29207 _003357_hash NULL
87802 +_003358_hash comedi_buf_alloc 3 24822 _003358_hash NULL
87803 +_003359_hash comedi_read 3 13199 _003359_hash NULL
87804 +_003360_hash comedi_write 3 47926 _003360_hash NULL
87805 +_003361_hash create_trace_probe 1 20175 _003361_hash NULL
87806 +_003362_hash create_trace_uprobe 1 13184 _003362_hash NULL
87807 +_003363_hash cx18_copy_buf_to_user 4 22735 _003363_hash NULL
87808 +_003364_hash cx231xx_init_bulk 2-3 47024 _003364_hash NULL
87809 +_003366_hash cx231xx_init_isoc 2-3 56453 _003366_hash NULL
87810 +_003368_hash cx231xx_init_vbi_isoc 2-3 28053 _003368_hash NULL
87811 +_003370_hash da9052_group_write 3 4534 _003370_hash NULL
87812 +_003371_hash debug_debug1_read 3 8856 _003371_hash NULL
87813 +_003372_hash debug_debug2_read 3 30526 _003372_hash NULL
87814 +_003373_hash debug_debug3_read 3 56894 _003373_hash NULL
87815 +_003374_hash debug_debug4_read 3 61367 _003374_hash NULL
87816 +_003375_hash debug_debug5_read 3 2291 _003375_hash NULL
87817 +_003376_hash debug_debug6_read 3 33168 _003376_hash NULL
87818 +_003377_hash dev_read 3 56369 _003377_hash NULL
87819 +_003378_hash do_dmabuf_dirty_ldu 6 52241 _003378_hash NULL
87820 +_003379_hash drm_compat_ioctl 2 51717 _003379_hash NULL
87821 +_003380_hash drm_mode_create_tv_properties 2 23122 _003380_hash NULL
87822 +_003381_hash drm_property_create_bitmask 5 30195 _003381_hash NULL
87823 +_003382_hash drm_property_create_enum 5 29201 _003382_hash NULL
87824 +_003383_hash dsp_buffer_alloc 2 11684 _003383_hash NULL
87825 +_003384_hash dt3155_alloc_coherent 2 58073 _003384_hash NULL
87826 +_003385_hash dtim_interval_read 3 654 _003385_hash NULL
87827 +_003386_hash dvb_audio_write 3 51275 _003386_hash NULL
87828 +_003387_hash dvb_ca_en50221_io_ioctl 2 26490 _003387_hash NULL
87829 +_003388_hash dvb_ca_write 3 41171 _003388_hash NULL
87830 +_003389_hash dvb_demux_ioctl 2 42733 _003389_hash NULL
87831 +_003390_hash dvb_dmxdev_buffer_read 4 20682 _003390_hash NULL
87832 +_003391_hash dvb_dvr_ioctl 2 49182 _003391_hash NULL
87833 +_003392_hash dvb_generic_ioctl 2 21810 _003392_hash NULL
87834 +_003393_hash dvb_net_ioctl 2 61559 _003393_hash NULL
87835 +_003394_hash dvb_net_sec_callback 2 28786 _003394_hash NULL
87836 +_003396_hash dvb_video_write 3 754 _003396_hash NULL
87837 +_003397_hash dynamic_ps_timeout_read 3 10110 _003397_hash NULL
87838 +_003398_hash easycap_alsa_vmalloc 2 14426 _003398_hash NULL
87839 +_003399_hash em28xx_alloc_isoc 4 46892 _003399_hash NULL
87840 +_003400_hash error_error_bar_retry_read 3 64305 _003400_hash NULL
87841 +_003401_hash error_error_frame_cts_nul_flid_read 3 17262 _003401_hash NULL
87842 +_003402_hash error_error_frame_read 3 39947 _003402_hash &_002436_hash
87843 +_003403_hash error_error_null_Frame_tx_start_read 3 55024 _003403_hash NULL
87844 +_003404_hash error_error_numll_frame_cts_start_read 3 47781 _003404_hash NULL
87845 +_003405_hash ext_sd_execute_read_data 9 48589 _003405_hash NULL
87846 +_003406_hash ext_sd_execute_write_data 9 8175 _003406_hash NULL
87847 +_003407_hash fast_user_write 5 20494 _003407_hash NULL
87848 +_003408_hash f_audio_buffer_alloc 1 41110 _003408_hash NULL
87849 +_003409_hash fb_alloc_cmap_gfp 2 20792 _003409_hash NULL
87850 +_003410_hash fbcon_do_set_font 2-3 4079 _003410_hash NULL
87851 +_003412_hash fb_read 3 33506 _003412_hash NULL
87852 +_003413_hash fb_sys_read 3 13778 _003413_hash NULL
87853 +_003414_hash fb_sys_write 3 33130 _003414_hash NULL
87854 +_003415_hash fb_write 3 46924 _003415_hash NULL
87855 +_003416_hash firmwareUpload 3 32794 _003416_hash NULL
87856 +_003417_hash fmc_send_cmd 5 20435 _003417_hash NULL
87857 +_003418_hash fops_read 3 40672 _003418_hash NULL
87858 +_003419_hash forced_ps_read 3 31685 _003419_hash NULL
87859 +_003420_hash frame_alloc 4 15981 _003420_hash NULL
87860 +_003421_hash framebuffer_alloc 1 59145 _003421_hash NULL
87861 +_003422_hash ftrace_write 3 29551 _003422_hash NULL
87862 +_003423_hash fw_download_code 3 13249 _003423_hash NULL
87863 +_003424_hash fwSendNullPacket 2 54618 _003424_hash NULL
87864 +_003425_hash gdm_wimax_netif_rx 3 43423 _003425_hash &_001810_hash
87865 +_003426_hash get_vm_area 1 18080 _003426_hash NULL
87866 +_003427_hash __get_vm_area 1 61599 _003427_hash NULL
87867 +_003428_hash get_vm_area_caller 1 10527 _003428_hash NULL
87868 +_003429_hash __get_vm_area_caller 1 56416 _003828_hash NULL nohasharray
87869 +_003430_hash gspca_dev_probe2 4 59833 _003430_hash NULL
87870 +_003431_hash hdpvr_read 3 9273 _003431_hash NULL
87871 +_003432_hash hecubafb_write 3 26942 _003432_hash NULL
87872 +_003433_hash i915_compat_ioctl 2 3656 _003433_hash NULL
87873 +_003434_hash i915_gem_execbuffer_relocate_slow 7 25355 _003434_hash NULL
87874 +_003435_hash ieee80211_alloc_txb 1-2 52477 _003435_hash NULL
87875 +_003437_hash ieee80211_authentication_req 3 63973 _003437_hash NULL
87876 +_003438_hash ieee80211_wx_set_gen_ie 3 51399 _003438_hash NULL
87877 +_003439_hash ieee80211_wx_set_gen_ie_rsl 3 3521 _003458_hash NULL nohasharray
87878 +_003440_hash intel_sdvo_set_value 4 2311 _003440_hash NULL
87879 +_003441_hash ir_lirc_transmit_ir 3 64403 _003441_hash NULL
87880 +_003442_hash irq_blk_threshold_read 3 33666 _003442_hash NULL
87881 +_003443_hash irq_pkt_threshold_read 3 33356 _003443_hash &_000154_hash
87882 +_003444_hash irq_timeout_read 3 54653 _003444_hash NULL
87883 +_003445_hash ivtv_buf_copy_from_user 4 25502 _003445_hash NULL
87884 +_003446_hash ivtv_copy_buf_to_user 4 6159 _003446_hash NULL
87885 +_003447_hash ivtvfb_write 3 40023 _003447_hash NULL
87886 +_003448_hash kgdb_hex2mem 3 24755 _003448_hash NULL
87887 +_003449_hash lirc_buffer_init 2-3 53282 _003449_hash NULL
87888 +_003451_hash lirc_write 3 20604 _003451_hash NULL
87889 +_003452_hash mce_request_packet 3 1073 _003452_hash NULL
87890 +_003453_hash media_entity_init 2-4 15870 _003453_hash &_001742_hash
87891 +_003455_hash mem_fw_gen_free_mem_blks_read 3 11413 _003455_hash NULL
87892 +_003456_hash mem_fwlog_free_mem_blks_read 3 59616 _003456_hash NULL
87893 +_003457_hash mem_rx_free_mem_blks_read 3 675 _003457_hash NULL
87894 +_003458_hash mem_tx_free_mem_blks_read 3 3521 _003458_hash &_003439_hash
87895 +_003459_hash metronomefb_write 3 8823 _003459_hash NULL
87896 +_003460_hash mga_compat_ioctl 2 52170 _003460_hash NULL
87897 +_003461_hash mmio_read 4 40348 _003461_hash NULL
87898 +_003462_hash netlink_send 5 38434 _003462_hash NULL
87899 +_003463_hash nfc_hci_execute_cmd 5 43882 _003463_hash NULL
87900 +_003464_hash nfc_hci_send_event 5 21452 _003464_hash NULL
87901 +_003465_hash nfc_hci_send_response 5 56462 _003465_hash NULL
87902 +_003466_hash ni_gpct_device_construct 5 610 _003466_hash NULL
87903 +_003467_hash nouveau_compat_ioctl 2 28305 _003467_hash NULL
87904 +_003468_hash odev_update 2 50169 _003468_hash NULL
87905 +_003469_hash opera1_usb_i2c_msgxfer 4 64521 _003469_hash NULL
87906 +_003470_hash OSDSetBlock 2-4 38986 _003470_hash NULL
87907 +_003472_hash oz_add_farewell 5 20652 _003472_hash NULL
87908 +_003473_hash oz_cdev_read 3 20659 _003473_hash NULL
87909 +_003474_hash oz_cdev_write 3 33852 _003474_hash NULL
87910 +_003475_hash oz_ep_alloc 2 5587 _003475_hash NULL
87911 +_003476_hash oz_events_read 3 47535 _003476_hash NULL
87912 +_003477_hash persistent_ram_buffer_map 1-2 11332 _003477_hash NULL
87913 +_003479_hash pipeline_cs_rx_packet_in_read 3 37089 _003479_hash NULL
87914 +_003480_hash pipeline_cs_rx_packet_out_read 3 58926 _003480_hash NULL
87915 +_003481_hash pipeline_csum_to_rx_xfer_swi_read 3 15403 _003481_hash NULL
87916 +_003482_hash pipeline_dec_packet_in_fifo_full_read 3 33052 _003482_hash NULL
87917 +_003483_hash pipeline_dec_packet_in_read 3 47076 _003483_hash NULL
87918 +_003484_hash pipeline_dec_packet_out_read 3 54052 _003484_hash NULL
87919 +_003485_hash pipeline_defrag_to_csum_swi_read 3 63037 _003485_hash NULL
87920 +_003486_hash pipeline_enc_rx_stat_fifo_int_read 3 7107 _003486_hash NULL
87921 +_003487_hash pipeline_enc_tx_stat_fifo_int_read 3 14680 _003487_hash NULL
87922 +_003488_hash pipeline_hs_tx_stat_fifo_int_read 3 15642 _003488_hash &_001260_hash
87923 +_003489_hash pipeline_pipeline_fifo_full_read 3 34095 _003489_hash NULL
87924 +_003490_hash pipeline_post_proc_swi_read 3 24108 _003490_hash NULL
87925 +_003491_hash pipeline_pre_proc_swi_read 3 3898 _003491_hash NULL
87926 +_003492_hash pipeline_pre_to_defrag_swi_read 3 56321 _003492_hash NULL
87927 +_003493_hash pipeline_rx_complete_stat_fifo_int_read 3 40671 _003493_hash NULL
87928 +_003494_hash pipeline_sec_frag_swi_read 3 30294 _003494_hash NULL
87929 +_003495_hash pipeline_tcp_rx_stat_fifo_int_read 3 26745 _003495_hash NULL
87930 +_003496_hash pipeline_tcp_tx_stat_fifo_int_read 3 32589 _003496_hash NULL
87931 +_003497_hash play_iframe 3 8219 _003497_hash NULL
87932 +_003498_hash probes_write 3 29711 _003498_hash NULL
87933 +_003499_hash psb_unlocked_ioctl 2 16926 _003499_hash &_002668_hash
87934 +_003500_hash ps_poll_ps_poll_max_ap_turn_read 3 53140 _003500_hash NULL
87935 +_003501_hash ps_poll_ps_poll_timeouts_read 3 5934 _003501_hash NULL
87936 +_003502_hash ps_poll_ps_poll_utilization_read 3 39383 _003502_hash NULL
87937 +_003503_hash ps_poll_upsd_max_ap_turn_read 3 42050 _003503_hash NULL
87938 +_003504_hash ps_poll_upsd_timeouts_read 3 36755 _003504_hash NULL
87939 +_003505_hash ps_poll_upsd_utilization_read 3 28519 _003505_hash NULL
87940 +_003506_hash pvr2_ioread_read 3 10720 _003506_hash &_001669_hash
87941 +_003507_hash pvr2_ioread_set_sync_key 3 59882 _003507_hash NULL
87942 +_003508_hash pvr2_stream_buffer_count 2 33719 _003508_hash NULL
87943 +_003509_hash pwr_connection_out_of_sync_read 3 35061 _003509_hash NULL
87944 +_003510_hash pwr_cont_miss_bcns_spread_read 3 39250 _003515_hash NULL nohasharray
87945 +_003511_hash pwr_missing_bcns_cnt_read 3 45113 _003511_hash NULL
87946 +_003512_hash pwr_rcvd_awake_bcns_cnt_read 3 12632 _003512_hash NULL
87947 +_003513_hash pwr_rcvd_bcns_cnt_read 3 4774 _003513_hash NULL
87948 +_003514_hash qc_capture 3 19298 _003514_hash NULL
87949 +_003515_hash r128_compat_ioctl 2 39250 _003515_hash &_003510_hash
87950 +_003516_hash radeon_compat_ioctl 2 59150 _003516_hash NULL
87951 +_003517_hash radeon_kms_compat_ioctl 2 51371 _003517_hash NULL
87952 +_003518_hash Realloc 2 34961 _003518_hash NULL
87953 +_003519_hash redrat3_transmit_ir 3 64244 _003519_hash NULL
87954 +_003520_hash reg_w_buf 3 27724 _003520_hash NULL
87955 +_003521_hash reg_w_ixbuf 4 34736 _003521_hash NULL
87956 +_003522_hash rtllib_alloc_txb 1-2 21687 _003522_hash NULL
87957 +_003524_hash rtllib_authentication_req 3 26713 _003524_hash NULL
87958 +_003525_hash rtllib_wx_set_gen_ie 3 59808 _003525_hash NULL
87959 +_003526_hash rts51x_transfer_data_partial 6 5735 _003526_hash NULL
87960 +_003527_hash rvmalloc 1 46873 _003527_hash NULL
87961 +_003528_hash rx_decrypt_key_not_found_read 3 37820 _003528_hash NULL
87962 +_003529_hash rx_defrag_called_read 3 1897 _003529_hash NULL
87963 +_003530_hash rx_defrag_decrypt_failed_read 3 41411 _003530_hash NULL
87964 +_003531_hash rx_defrag_init_called_read 3 35935 _003531_hash NULL
87965 +_003532_hash rx_defrag_in_process_called_read 3 59338 _003532_hash NULL
87966 +_003533_hash rx_defrag_need_decrypt_read 3 42253 _003533_hash NULL
87967 +_003534_hash rx_defrag_need_defrag_read 3 28117 _003534_hash NULL
87968 +_003535_hash rx_defrag_tkip_called_read 3 21031 _003535_hash NULL
87969 +_003536_hash rx_filter_accum_arp_pend_requests_read 3 11003 _003536_hash NULL
87970 +_003537_hash rx_filter_arp_filter_read 3 61914 _003537_hash NULL
87971 +_003538_hash rx_filter_beacon_filter_read 3 49279 _003538_hash NULL
87972 +_003539_hash rx_filter_data_filter_read 3 30098 _003539_hash NULL
87973 +_003540_hash rx_filter_dup_filter_read 3 37238 _003540_hash NULL
87974 +_003541_hash rx_filter_ibss_filter_read 3 50167 _003541_hash NULL
87975 +_003542_hash rx_filter_max_arp_queue_dep_read 3 5851 _003542_hash NULL
87976 +_003543_hash rx_filter_mc_filter_read 3 25712 _003543_hash NULL
87977 +_003544_hash rx_filter_protection_filter_read 3 39282 _003544_hash NULL
87978 +_003545_hash rx_rate_rx_frames_per_rates_read 3 7282 _003545_hash NULL
87979 +_003546_hash rx_rx_beacon_early_term_read 3 21559 _003546_hash NULL
87980 +_003547_hash rx_rx_checksum_result_read 3 50617 _003547_hash NULL
87981 +_003548_hash rx_rx_cmplt_read 3 14753 _003548_hash NULL
87982 +_003549_hash rx_rx_cmplt_task_read 3 35226 _003549_hash NULL
87983 +_003550_hash rx_rx_defrag_end_read 3 505 _003550_hash NULL
87984 +_003551_hash rx_rx_defrag_read 3 2010 _003551_hash NULL
87985 +_003552_hash rx_rx_done_read 3 65217 _003552_hash NULL
87986 +_003553_hash rx_rx_dropped_frame_read 3 23748 _003553_hash NULL
87987 +_003554_hash rx_rx_frame_checksum_read 3 40140 _003554_hash NULL
87988 +_003555_hash rx_rx_hdr_overflow_read 3 35002 _003555_hash NULL
87989 +_003556_hash rx_rx_out_of_mpdu_nodes_read 3 64668 _003556_hash NULL
87990 +_003557_hash rx_rx_phy_hdr_read 3 20950 _003557_hash NULL
87991 +_003558_hash rx_rx_pre_complt_read 3 41653 _003558_hash NULL
87992 +_003559_hash rx_rx_timeout_read 3 62389 _003559_hash NULL
87993 +_003560_hash rx_rx_timeout_wa_read 3 50204 _003560_hash NULL
87994 +_003561_hash rx_rx_tkip_replays_read 3 60193 _003561_hash NULL
87995 +_003562_hash rx_rx_wa_ba_not_expected_read 3 61341 _003562_hash NULL
87996 +_003563_hash rx_rx_wa_density_dropped_frame_read 3 26095 _003563_hash NULL
87997 +_003564_hash rx_streaming_always_read 3 49401 _003564_hash NULL
87998 +_003565_hash rx_streaming_interval_read 3 55291 _003565_hash NULL
87999 +_003566_hash saa7164_buffer_alloc_user 2 9627 _003566_hash NULL
88000 +_003567_hash send_control_msg 6 48498 _003567_hash NULL
88001 +_003568_hash SendTxCommandPacket 3 42901 _003568_hash NULL
88002 +_003569_hash setup_window 2-7-5-4 59178 _003569_hash NULL
88003 +_003573_hash shmem_pwrite_fast 3 46842 _003573_hash NULL
88004 +_003574_hash sleep_auth_read 3 19159 _003574_hash NULL
88005 +_003575_hash sn9c102_read 3 29305 _003575_hash NULL
88006 +_003576_hash snd_pcm_alloc_vmalloc_buffer 2 44595 _003576_hash NULL
88007 +_003577_hash split_scan_timeout_read 3 20029 _003577_hash NULL
88008 +_003578_hash stk_prepare_sio_buffers 2 57168 _003578_hash NULL
88009 +_003579_hash store_debug_level 3 35652 _003579_hash NULL
88010 +_003580_hash suspend_dtim_interval_read 3 64971 _003580_hash NULL
88011 +_003581_hash sys_prctl 4 8766 _003581_hash NULL
88012 +_003582_hash tm6000_read_write_usb 7 50774 _003582_hash &_002149_hash
88013 +_003583_hash tracing_read_pipe 3 35312 _003583_hash NULL
88014 +_003584_hash ts_read 3 44687 _003584_hash NULL
88015 +_003585_hash ts_write 3 64336 _003585_hash NULL
88016 +_003586_hash tt3650_ci_msg 4 57219 _003586_hash NULL
88017 +_003587_hash ttm_object_device_init 2 10321 _003587_hash NULL
88018 +_003588_hash ttm_object_file_init 2 27804 _003588_hash NULL
88019 +_003589_hash tx_frag_bad_mblk_num_read 3 28064 _003589_hash NULL
88020 +_003590_hash tx_frag_cache_hit_read 3 29639 _003590_hash NULL
88021 +_003591_hash tx_frag_cache_miss_read 3 28394 _003591_hash NULL
88022 +_003592_hash tx_frag_called_read 3 1748 _003592_hash NULL
88023 +_003593_hash tx_frag_failed_read 3 43540 _003593_hash NULL
88024 +_003594_hash tx_frag_init_called_read 3 48377 _003594_hash NULL
88025 +_003595_hash tx_frag_in_process_called_read 3 1290 _003595_hash NULL
88026 +_003596_hash tx_frag_key_not_found_read 3 22971 _003596_hash NULL
88027 +_003597_hash tx_frag_mpdu_alloc_failed_read 3 41167 _003597_hash NULL
88028 +_003598_hash tx_frag_need_fragmentation_read 3 50153 _003598_hash NULL
88029 +_003599_hash tx_frag_tkip_called_read 3 31575 _003599_hash NULL
88030 +_003600_hash tx_tx_burst_programmed_read 3 20320 _003600_hash NULL
88031 +_003601_hash tx_tx_checksum_result_read 3 36490 _003601_hash &_001996_hash
88032 +_003602_hash tx_tx_cmplt_read 3 35854 _003602_hash NULL
88033 +_003603_hash tx_tx_data_prepared_read 3 43497 _003603_hash NULL
88034 +_003604_hash tx_tx_data_programmed_read 3 36871 _003604_hash NULL
88035 +_003605_hash tx_tx_done_data_read 3 6799 _003605_hash NULL
88036 +_003606_hash tx_tx_done_int_template_read 3 55511 _003606_hash &_001887_hash
88037 +_003607_hash tx_tx_done_template_read 3 35104 _003607_hash &_000106_hash
88038 +_003608_hash tx_tx_exch_expiry_read 3 8749 _003608_hash NULL
88039 +_003609_hash tx_tx_exch_pending_read 3 53018 _003609_hash NULL
88040 +_003610_hash tx_tx_exch_read 3 52986 _003610_hash NULL
88041 +_003611_hash tx_tx_frame_checksum_read 3 41553 _003611_hash NULL
88042 +_003612_hash tx_tx_imm_resp_read 3 55964 _003612_hash NULL
88043 +_003613_hash tx_tx_prepared_descs_read 3 9221 _003613_hash NULL
88044 +_003614_hash tx_tx_retry_data_read 3 1926 _003614_hash NULL
88045 +_003615_hash tx_tx_retry_template_read 3 57623 _003615_hash NULL
88046 +_003616_hash tx_tx_start_data_read 3 53219 _003616_hash NULL
88047 +_003617_hash tx_tx_start_fw_gen_read 3 58648 _003617_hash NULL
88048 +_003618_hash tx_tx_start_int_templates_read 3 58324 _003618_hash NULL
88049 +_003619_hash tx_tx_start_null_frame_read 3 6281 _003619_hash NULL
88050 +_003620_hash tx_tx_starts_read 3 3617 _003620_hash NULL
88051 +_003621_hash tx_tx_start_templates_read 3 17164 _003621_hash NULL
88052 +_003622_hash tx_tx_template_prepared_read 3 30424 _003622_hash NULL
88053 +_003623_hash tx_tx_template_programmed_read 3 30461 _003623_hash NULL
88054 +_003624_hash udi_log_event 3 58105 _003624_hash NULL
88055 +_003625_hash udl_prime_create 2 57159 _003625_hash NULL
88056 +_003626_hash uf_create_device_nodes 2 24948 _003626_hash NULL
88057 +_003627_hash uf_sme_queue_message 3 15697 _003627_hash NULL
88058 +_003628_hash ufx_alloc_urb_list 3 10349 _003628_hash NULL
88059 +_003629_hash unifi_net_data_malloc 3 24716 _003629_hash NULL
88060 +_003630_hash unifi_read 3 14899 _003630_hash NULL
88061 +_003631_hash unifi_write 3 65012 _003631_hash NULL
88062 +_003632_hash usb_buffer_alloc 2 36276 _003632_hash NULL
88063 +_003633_hash usbvision_rvmalloc 1 19655 _003633_hash NULL
88064 +_003634_hash usbvision_v4l2_read 3 34386 _003634_hash NULL
88065 +_003635_hash uvc_alloc_buffers 2-3 9656 _003635_hash NULL
88066 +_003637_hash uvc_alloc_entity 3-4 20836 _003637_hash NULL
88067 +_003639_hash uvc_debugfs_stats_read 3 56651 _003639_hash NULL
88068 +_003640_hash uvc_simplify_fraction 3 31303 _003640_hash NULL
88069 +_003641_hash v4l2_ctrl_new 7 24927 _003641_hash NULL
88070 +_003642_hash v4l2_event_subscribe 3 53687 _003642_hash NULL
88071 +_003643_hash v4l_stk_read 3 39672 _003643_hash NULL
88072 +_003644_hash __vb2_perform_fileio 3 63033 _003644_hash NULL
88073 +_003645_hash vfd_write 3 14717 _003645_hash NULL
88074 +_003646_hash vfio_config_do_rw 3 46091 _003646_hash NULL
88075 +_003647_hash vfio_msi_enable 2 20906 _003647_hash NULL
88076 +_003648_hash viafb_dvp0_proc_write 3 23023 _003648_hash NULL
88077 +_003649_hash viafb_dvp1_proc_write 3 48864 _003649_hash NULL
88078 +_003650_hash viafb_vt1636_proc_write 3 16018 _003650_hash NULL
88079 +_003651_hash __videobuf_alloc_vb 1 27062 _003651_hash NULL
88080 +_003652_hash __videobuf_alloc_vb 1 5665 _003652_hash NULL
88081 +_003653_hash __videobuf_copy_to_user 4 15423 _003653_hash NULL
88082 +_003654_hash videobuf_dma_init_kernel 3 6963 _003654_hash NULL
88083 +_003655_hash videobuf_pages_to_sg 2 3708 _003655_hash NULL
88084 +_003656_hash videobuf_vmalloc_to_sg 2 4548 _003656_hash NULL
88085 +_003657_hash video_usercopy 2 62151 _003657_hash NULL
88086 +_003658_hash virtscsi_alloc_tgt 2 6643 _003658_hash NULL
88087 +_003659_hash vmw_cursor_update_image 3-4 16332 _003659_hash NULL
88088 +_003661_hash vmw_framebuffer_dmabuf_dirty 6 37661 _003661_hash &_001116_hash
88089 +_003662_hash vmw_framebuffer_surface_dirty 6 48132 _003662_hash NULL
88090 +_003663_hash vmw_gmr2_bind 3 21305 _003663_hash NULL
88091 +_003664_hash vmw_unlocked_ioctl 2 19212 _003664_hash NULL
88092 +_003665_hash w9966_v4l_read 3 31148 _003665_hash NULL
88093 +_003666_hash wl1273_fm_fops_write 3 60621 _003666_hash NULL
88094 +_003667_hash zoran_write 3 22404 _003667_hash NULL
88095 +_003668_hash alloc_vm_area 1 15989 _003668_hash NULL
88096 +_003669_hash cx18_copy_mdl_to_user 4 45549 _003669_hash NULL
88097 +_003670_hash dlfb_ops_write 3 64150 _003670_hash NULL
88098 +_003671_hash dvb_demux_read 3 13981 _003671_hash NULL
88099 +_003672_hash dvb_dmxdev_read_sec 4 7892 _003672_hash NULL
88100 +_003673_hash dvb_dvr_read 3 17073 _003673_hash NULL
88101 +_003674_hash em28xx_init_isoc 4 62883 _003674_hash &_000729_hash
88102 +_003675_hash fb_alloc_cmap 2 6554 _003675_hash NULL
88103 +_003676_hash gspca_dev_probe 4 2570 _003676_hash NULL
88104 +_003677_hash ieee80211_auth_challenge 3 18810 _003677_hash NULL
88105 +_003678_hash ieee80211_rtl_auth_challenge 3 61897 _003678_hash NULL
88106 +_003679_hash init_pci_cap_msi_perm 2 59033 _003679_hash NULL
88107 +_003680_hash __ioremap_caller 1-2 21800 _003680_hash NULL
88108 +_003682_hash ivtv_read 3 57796 _003682_hash NULL
88109 +_003683_hash ivtv_v4l2_write 3 39226 _003683_hash NULL
88110 +_003684_hash mce_async_out 3 58056 _003684_hash NULL
88111 +_003685_hash mce_flush_rx_buffer 2 14976 _003685_hash NULL
88112 +_003686_hash ms_read_multiple_pages 4-5 8052 _003686_hash NULL
88113 +_003688_hash ms_write_multiple_pages 5-6 10362 _003688_hash NULL
88114 +_003690_hash nfc_hci_send_cmd 5 55714 _003690_hash NULL
88115 +_003691_hash persistent_ram_new 1-2 40501 _003691_hash NULL
88116 +_003693_hash picolcd_fb_write 3 2318 _003693_hash NULL
88117 +_003694_hash process_bulk_data_command 4 38906 _003694_hash NULL
88118 +_003695_hash pvr2_v4l2_read 3 18006 _003695_hash NULL
88119 +_003696_hash qcam_read 3 13977 _003696_hash NULL
88120 +_003697_hash register_unifi_sdio 2 55239 _003697_hash NULL
88121 +_003698_hash resize_async_buffer 4 64031 _003698_hash &_002431_hash
88122 +_003699_hash rtllib_auth_challenge 3 12493 _003699_hash NULL
88123 +_003702_hash stk_allocate_buffers 2 16291 _003702_hash NULL
88124 +_003703_hash subdev_ioctl 2 28417 _003703_hash NULL
88125 +_003704_hash _sys_packet_req 4 46793 _003704_hash NULL
88126 +_003705_hash tm6000_i2c_recv_regs16 5 2949 _003705_hash NULL
88127 +_003706_hash tm6000_i2c_recv_regs 5 46215 _003706_hash NULL
88128 +_003707_hash tm6000_i2c_send_regs 5 20250 _003707_hash NULL
88129 +_003708_hash tt3650_ci_msg_locked 4 8013 _003708_hash NULL
88130 +_003709_hash ufx_ops_write 3 54848 _003709_hash NULL
88131 +_003710_hash update_macheader 7 1775 _003710_hash NULL
88132 +_003711_hash usbdux_attach_common 4 51764 _003750_hash NULL nohasharray
88133 +_003712_hash usbduxfast_attach_common 4 52538 _003712_hash NULL
88134 +_003713_hash usbduxsigma_attach_common 4 40847 _003713_hash NULL
88135 +_003714_hash uvc_v4l2_ioctl 2 8411 _003714_hash NULL
88136 +_003715_hash v4l2_ctrl_new_int_menu 4 41151 _003715_hash NULL
88137 +_003716_hash v4l2_ctrl_new_std 5 45748 _003716_hash &_000497_hash
88138 +_003717_hash v4l2_ctrl_new_std_menu 4 6221 _003717_hash NULL
88139 +_003718_hash vb2_read 3 42703 _003718_hash NULL
88140 +_003719_hash vb2_write 3 31948 _003719_hash NULL
88141 +_003720_hash vfio_pci_set_msi_trigger 3-4 26507 _003720_hash NULL
88142 +_003722_hash viafb_iga1_odev_proc_write 3 36241 _003722_hash NULL
88143 +_003723_hash viafb_iga2_odev_proc_write 3 2363 _003723_hash NULL
88144 +_003724_hash __videobuf_alloc_cached 1 12740 _003724_hash NULL
88145 +_003725_hash __videobuf_alloc_uncached 1 55711 _003725_hash NULL
88146 +_003726_hash __videobuf_copy_stream 4 44769 _003726_hash NULL
88147 +_003727_hash videobuf_read_one 3 31637 _003727_hash NULL
88148 +_003728_hash video_ioctl2 2 21380 _003728_hash NULL
88149 +_003729_hash vmap 2 15025 _003729_hash NULL
88150 +_003730_hash vmw_cursor_update_dmabuf 3-4 32045 _003730_hash NULL
88151 +_003732_hash vmw_gmr_bind 3 44130 _003732_hash NULL
88152 +_003733_hash xd_read_multiple_pages 4-5 11422 _003733_hash NULL
88153 +_003735_hash xd_write_multiple_pages 5-6 53633 _003735_hash NULL
88154 +_003737_hash xenfb_write 3 43412 _003737_hash NULL
88155 +_003738_hash arch_gnttab_map_shared 3 41306 _003738_hash NULL
88156 +_003739_hash arch_gnttab_map_status 3 49812 _003739_hash NULL
88157 +_003740_hash bttv_read 3 11432 _003740_hash NULL
88158 +_003741_hash cx18_read 3 23699 _003741_hash NULL
88159 +_003742_hash cx2341x_ctrl_new_menu 3 49700 _003742_hash NULL
88160 +_003743_hash cx2341x_ctrl_new_std 4 57061 _003743_hash NULL
88161 +_003744_hash cx25821_video_ioctl 2 30188 _003744_hash NULL
88162 +_003745_hash dt3155_read 3 59226 _003745_hash NULL
88163 +_003746_hash ioremap_cache 1-2 47189 _003746_hash NULL
88164 +_003748_hash ioremap_nocache 1-2 2439 _003748_hash NULL
88165 +_003750_hash ioremap_prot 1-2 51764 _003750_hash &_003711_hash
88166 +_003752_hash ioremap_wc 1-2 62695 _003752_hash NULL
88167 +_003754_hash ivtv_read_pos 3 34400 _003754_hash &_000312_hash
88168 +_003755_hash mcam_v4l_read 3 36513 _003755_hash NULL
88169 +_003756_hash ms_rw_multi_sector 3-4 7459 _003756_hash NULL
88170 +_003758_hash pvr2_v4l2_ioctl 2 24398 _003758_hash &_000877_hash
88171 +_003759_hash ramoops_init_prz 5 12134 _003759_hash NULL
88172 +_003761_hash ttm_bo_kmap_ttm 3 5922 _003761_hash NULL
88173 +_003762_hash uf_ap_process_data_pdu 7 25860 _003762_hash NULL
88174 +_003763_hash vb2_fop_read 3 24080 _003763_hash NULL
88175 +_003764_hash vb2_fop_write 3 30420 _003764_hash NULL
88176 +_003765_hash videobuf_read_stream 3 14956 _003765_hash NULL
88177 +_003766_hash video_read 3 28148 _003766_hash NULL
88178 +_003767_hash vmw_du_crtc_cursor_set 4-5 28479 _003767_hash NULL
88179 +_003769_hash xd_rw 3-4 49020 _003769_hash NULL
88180 +_003771_hash zoran_ioctl 2 30465 _003771_hash NULL
88181 +_003772_hash zr364xx_read 3 2354 _003772_hash NULL
88182 +_003773_hash acpi_os_ioremap 1-2 49523 _003773_hash NULL
88183 +_003775_hash au0828_v4l2_read 3 40220 _003775_hash NULL
88184 +_003776_hash ca91cx42_alloc_resource 2 10502 _003776_hash NULL
88185 +_003778_hash cx18_read_pos 3 4683 _003778_hash NULL
88186 +_003779_hash cx18_v4l2_read 3 21196 _003779_hash NULL
88187 +_003780_hash cx231xx_v4l2_read 3 55014 _003780_hash NULL
88188 +_003781_hash devm_ioremap_nocache 2-3 2036 _003781_hash NULL
88189 +_003783_hash do_test 1 15766 _003783_hash NULL
88190 +_003784_hash __einj_error_trigger 1 17707 _003784_hash &_001764_hash
88191 +_003785_hash em28xx_v4l2_read 3 16701 _003785_hash NULL
88192 +_003786_hash init_chip_wc_pat 2 62768 _003786_hash NULL
88193 +_003787_hash intel_render_ring_init_dri 2-3 45446 _003787_hash NULL
88194 +_003789_hash io_mapping_create_wc 1-2 1354 _003789_hash NULL
88195 +_003791_hash iommu_map_mmio_space 1 30919 _003791_hash NULL
88196 +_003792_hash ioremap 1-2 23172 _003792_hash NULL
88197 +_003794_hash ivtv_v4l2_read 3 1964 _003794_hash NULL
88198 +_003795_hash mga_ioremap 1-2 8571 _003795_hash NULL
88199 +_003797_hash mpeg_read 3 6708 _003797_hash NULL
88200 +_003798_hash msix_map_region 3 3411 _003798_hash NULL
88201 +_003799_hash ms_rw 3-4 17220 _003799_hash NULL
88202 +_003801_hash pci_iomap 3 47575 _003801_hash NULL
88203 +_003802_hash pd_video_read 3 24510 _003802_hash NULL
88204 +_003803_hash sfi_map_memory 1-2 5183 _003803_hash NULL
88205 +_003805_hash solo_enc_read 3 33553 _003805_hash NULL
88206 +_003806_hash solo_v4l2_read 3 59247 _003806_hash NULL
88207 +_003807_hash timblogiw_read 3 48305 _003807_hash NULL
88208 +_003808_hash tm6000_read 3 4151 _003808_hash NULL
88209 +_003809_hash tsi148_alloc_resource 2 24563 _003809_hash NULL
88210 +_003810_hash ttm_bo_ioremap 2-3 31082 _003810_hash NULL
88211 +_003812_hash ttm_bo_kmap 3-2 60118 _003812_hash NULL
88212 +_003813_hash vb2_vmalloc_get_userptr 3 31374 _003813_hash NULL
88213 +_003814_hash vbi_read 3 63673 _003814_hash NULL
88214 +_003815_hash viacam_read 3 54526 _003815_hash NULL
88215 +_003816_hash xlate_dev_mem_ptr 1 15291 _003816_hash &_001231_hash
88216 +_003817_hash a4t_cs_init 3 27734 _003817_hash NULL
88217 +_003818_hash aac_nark_ioremap 2 50163 _003818_hash &_000323_hash
88218 +_003819_hash aac_rkt_ioremap 2 3333 _003819_hash NULL
88219 +_003820_hash aac_rx_ioremap 2 52410 _003820_hash NULL
88220 +_003821_hash aac_sa_ioremap 2 13596 _003821_hash &_000299_hash
88221 +_003822_hash aac_src_ioremap 2 41688 _003822_hash NULL
88222 +_003823_hash aac_srcv_ioremap 2 6659 _003823_hash NULL
88223 +_003824_hash acpi_map 1-2 58725 _003824_hash NULL
88224 +_003826_hash acpi_os_read_memory 1-3 54186 _003826_hash NULL
88225 +_003828_hash acpi_os_write_memory 1-3 56416 _003828_hash &_003429_hash
88226 +_003830_hash atyfb_setup_generic 3 49151 _003830_hash NULL
88227 +_003831_hash ca91cx42_master_set 4 23146 _003831_hash NULL
88228 +_003832_hash check_mirror 1-2 57342 _003832_hash &_001753_hash
88229 +_003834_hash cycx_setup 4 47562 _003834_hash NULL
88230 +_003835_hash devm_ioremap 2-3 29235 _003835_hash NULL
88231 +_003837_hash divasa_remap_pci_bar 3-4 23485 _003837_hash &_000979_hash
88232 +_003839_hash doc_probe 1 23285 _003839_hash NULL
88233 +_003840_hash DoC_Probe 1 57534 _003840_hash NULL
88234 +_003841_hash efi_ioremap 1-2 3492 _003841_hash &_001137_hash
88235 +_003843_hash ems_pcmcia_add_card 2 62627 _003843_hash NULL
88236 +_003844_hash isp1760_register 1-2 628 _003844_hash NULL
88237 +_003846_hash mid_get_vbt_data_r0 2 10876 _003846_hash NULL
88238 +_003847_hash mid_get_vbt_data_r10 2 6308 _003847_hash NULL
88239 +_003848_hash mid_get_vbt_data_r1 2 26170 _003848_hash NULL
88240 +_003849_hash mthca_map_reg 2-3 5664 _003849_hash NULL
88241 +_003851_hash mthca_setup_cmd_doorbells 2 53954 _003851_hash NULL
88242 +_003852_hash netxen_nic_map_indirect_address_128M 2 42257 _003852_hash NULL
88243 +_003853_hash pcim_iomap 3 58334 _003853_hash NULL
88244 +_003854_hash persistent_ram_iomap 1-2 47156 _003854_hash NULL
88245 +_003856_hash read_vbt_r0 1 503 _003856_hash NULL
88246 +_003857_hash read_vbt_r10 1 60679 _003857_hash NULL
88247 +_003858_hash register_device 2-3 60015 _003858_hash NULL
88248 +_003860_hash remap_pci_mem 1-2 15966 _003860_hash NULL
88249 +_003862_hash rtl_port_map 1-2 2385 _003862_hash NULL
88250 +_003864_hash sfi_map_table 1 5462 _003864_hash NULL
88251 +_003865_hash sriov_enable_migration 2 14889 _003865_hash NULL
88252 +_003866_hash ssb_bus_scan 2 36578 _003866_hash NULL
88253 +_003867_hash ssb_ioremap 2 5228 _003867_hash NULL
88254 +_003868_hash tpci200_slot_map_space 2 3848 _003868_hash NULL
88255 +_003869_hash tpm_tis_init 2-3 15304 _003869_hash NULL
88256 +_003871_hash tsi148_master_set 4 14685 _003871_hash NULL
88257 +_003872_hash acpi_os_map_memory 1-2 11161 _003872_hash NULL
88258 +_003874_hash com90xx_found 3 13974 _003874_hash NULL
88259 +_003875_hash netxen_nic_hw_read_wx_128M 2 26858 _003875_hash NULL
88260 +_003876_hash netxen_nic_hw_write_wx_128M 2 33488 _003876_hash NULL
88261 +_003877_hash sfi_check_table 1 6772 _003877_hash NULL
88262 +_003878_hash sfi_sysfs_install_table 1 51688 _003878_hash NULL
88263 +_003879_hash sriov_enable 2 59689 _003879_hash NULL
88264 +_003880_hash ssb_bus_register 3 65183 _003880_hash NULL
88265 +_003881_hash acpi_ex_system_memory_space_handler 2 31192 _003881_hash NULL
88266 +_003882_hash acpi_tb_check_xsdt 1 21862 _003882_hash NULL
88267 +_003883_hash acpi_tb_install_table 1 12988 _003883_hash NULL
88268 +_003884_hash acpi_tb_parse_root_table 1 53455 _003884_hash NULL
88269 +_003885_hash check_vendor_extension 1 3254 _003885_hash NULL
88270 +_003886_hash pci_enable_sriov 2 35745 _003886_hash NULL
88271 +_003887_hash ssb_bus_pcmciabus_register 3 56020 _003887_hash NULL
88272 +_003888_hash ssb_bus_ssbbus_register 2 2217 _003888_hash NULL
88273 +_003889_hash lpfc_sli_probe_sriov_nr_virtfn 2 26004 _003889_hash NULL
88274 +_003890_hash alloc_vm_area 1 36149 _003890_hash NULL
88275 +_003891_hash cma_create_area 2 38642 _003891_hash NULL
88276 +_003893_hash fbcon_prepare_logo 5 6246 _003893_hash NULL
88277 +_003894_hash io_mapping_map_wc 2 19284 _003894_hash NULL
88278 +_003895_hash nfs_dns_resolve_name 3 25036 _003895_hash NULL
88279 +_003896_hash nfs_parse_server_name 2 1899 _003896_hash NULL
88280 +_003897_hash acl_alloc 1 35979 _003897_hash NULL
88281 +_003898_hash acl_alloc_stack_init 1 60630 _003898_hash NULL
88282 +_003899_hash create_table 2 16213 _003899_hash NULL
88283 diff --git a/tools/gcc/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin.c
88284 new file mode 100644
88285 index 0000000..1aa0dce
88286 --- /dev/null
88287 +++ b/tools/gcc/size_overflow_plugin.c
88288 @@ -0,0 +1,1865 @@
88289 +/*
88290 + * Copyright 2011, 2012 by Emese Revfy <re.emese@gmail.com>
88291 + * Licensed under the GPL v2, or (at your option) v3
88292 + *
88293 + * Homepage:
88294 + * http://www.grsecurity.net/~ephox/overflow_plugin/
88295 + *
88296 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
88297 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
88298 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
88299 + *
88300 + * Usage:
88301 + * $ 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
88302 + * $ gcc -fplugin=size_overflow_plugin.so test.c -O2
88303 + */
88304 +
88305 +#include "gcc-plugin.h"
88306 +#include "config.h"
88307 +#include "system.h"
88308 +#include "coretypes.h"
88309 +#include "tree.h"
88310 +#include "tree-pass.h"
88311 +#include "intl.h"
88312 +#include "plugin-version.h"
88313 +#include "tm.h"
88314 +#include "toplev.h"
88315 +#include "function.h"
88316 +#include "tree-flow.h"
88317 +#include "plugin.h"
88318 +#include "gimple.h"
88319 +#include "c-common.h"
88320 +#include "diagnostic.h"
88321 +#include "cfgloop.h"
88322 +
88323 +#if BUILDING_GCC_VERSION >= 4007
88324 +#include "c-tree.h"
88325 +#else
88326 +#define C_DECL_IMPLICIT(EXP) DECL_LANG_FLAG_2 (EXP)
88327 +#endif
88328 +
88329 +struct size_overflow_hash {
88330 + const struct size_overflow_hash * const next;
88331 + const char * const name;
88332 + const unsigned int param;
88333 +};
88334 +
88335 +#include "size_overflow_hash.h"
88336 +
88337 +enum marked {
88338 + MARKED_NO, MARKED_YES, MARKED_NOT_INTENTIONAL
88339 +};
88340 +
88341 +#define __unused __attribute__((__unused__))
88342 +#define NAME(node) IDENTIFIER_POINTER(DECL_NAME(node))
88343 +#define NAME_LEN(node) IDENTIFIER_LENGTH(DECL_NAME(node))
88344 +#define BEFORE_STMT true
88345 +#define AFTER_STMT false
88346 +#define CREATE_NEW_VAR NULL_TREE
88347 +#define CODES_LIMIT 32
88348 +#define MAX_PARAM 32
88349 +#define MY_STMT GF_PLF_1
88350 +#define NO_CAST_CHECK GF_PLF_2
88351 +
88352 +#if BUILDING_GCC_VERSION == 4005
88353 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
88354 +#endif
88355 +
88356 +int plugin_is_GPL_compatible;
88357 +void debug_gimple_stmt(gimple gs);
88358 +
88359 +static tree expand(struct pointer_set_t *visited, tree lhs);
88360 +static bool pre_expand(struct pointer_set_t *visited, const_tree lhs);
88361 +static tree report_size_overflow_decl;
88362 +static const_tree const_char_ptr_type_node;
88363 +static unsigned int handle_function(void);
88364 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before);
88365 +static tree get_size_overflow_type(gimple stmt, const_tree node);
88366 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3);
88367 +
88368 +static struct plugin_info size_overflow_plugin_info = {
88369 + .version = "20121113beta",
88370 + .help = "no-size-overflow\tturn off size overflow checking\n",
88371 +};
88372 +
88373 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
88374 +{
88375 + unsigned int arg_count;
88376 + enum tree_code code = TREE_CODE(*node);
88377 +
88378 + switch (code) {
88379 + case FUNCTION_DECL:
88380 + arg_count = type_num_arguments(TREE_TYPE(*node));
88381 + break;
88382 + case FUNCTION_TYPE:
88383 + case METHOD_TYPE:
88384 + arg_count = type_num_arguments(*node);
88385 + break;
88386 + default:
88387 + *no_add_attrs = true;
88388 + error("%s: %qE attribute only applies to functions", __func__, name);
88389 + return NULL_TREE;
88390 + }
88391 +
88392 + for (; args; args = TREE_CHAIN(args)) {
88393 + tree position = TREE_VALUE(args);
88394 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) < 1 || TREE_INT_CST_LOW(position) > arg_count ) {
88395 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
88396 + *no_add_attrs = true;
88397 + }
88398 + }
88399 + return NULL_TREE;
88400 +}
88401 +
88402 +static const char* get_asm_name(tree node)
88403 +{
88404 + return IDENTIFIER_POINTER(DECL_ASSEMBLER_NAME(node));
88405 +}
88406 +
88407 +static tree handle_intentional_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
88408 +{
88409 + unsigned int arg_count, arg_num;
88410 + enum tree_code code = TREE_CODE(*node);
88411 +
88412 + switch (code) {
88413 + case FUNCTION_DECL:
88414 + arg_count = type_num_arguments(TREE_TYPE(*node));
88415 + break;
88416 + case FUNCTION_TYPE:
88417 + case METHOD_TYPE:
88418 + arg_count = type_num_arguments(*node);
88419 + break;
88420 + case FIELD_DECL:
88421 + arg_num = TREE_INT_CST_LOW(TREE_VALUE(args));
88422 + if (arg_num != 0) {
88423 + *no_add_attrs = true;
88424 + error("%s: %qE attribute parameter can only be 0 in structure fields", __func__, name);
88425 + }
88426 + return NULL_TREE;
88427 + default:
88428 + *no_add_attrs = true;
88429 + error("%qE attribute only applies to functions", name);
88430 + return NULL_TREE;
88431 + }
88432 +
88433 + for (; args; args = TREE_CHAIN(args)) {
88434 + tree position = TREE_VALUE(args);
88435 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) > arg_count ) {
88436 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
88437 + *no_add_attrs = true;
88438 + }
88439 + }
88440 + return NULL_TREE;
88441 +}
88442 +
88443 +static struct attribute_spec size_overflow_attr = {
88444 + .name = "size_overflow",
88445 + .min_length = 1,
88446 + .max_length = -1,
88447 + .decl_required = true,
88448 + .type_required = false,
88449 + .function_type_required = false,
88450 + .handler = handle_size_overflow_attribute,
88451 +#if BUILDING_GCC_VERSION >= 4007
88452 + .affects_type_identity = false
88453 +#endif
88454 +};
88455 +
88456 +static struct attribute_spec intentional_overflow_attr = {
88457 + .name = "intentional_overflow",
88458 + .min_length = 1,
88459 + .max_length = -1,
88460 + .decl_required = true,
88461 + .type_required = false,
88462 + .function_type_required = false,
88463 + .handler = handle_intentional_overflow_attribute,
88464 +#if BUILDING_GCC_VERSION >= 4007
88465 + .affects_type_identity = false
88466 +#endif
88467 +};
88468 +
88469 +static void register_attributes(void __unused *event_data, void __unused *data)
88470 +{
88471 + register_attribute(&size_overflow_attr);
88472 + register_attribute(&intentional_overflow_attr);
88473 +}
88474 +
88475 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
88476 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
88477 +{
88478 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
88479 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
88480 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
88481 +
88482 + unsigned int m = 0x57559429;
88483 + unsigned int n = 0x5052acdb;
88484 + const unsigned int *key4 = (const unsigned int *)key;
88485 + unsigned int h = len;
88486 + unsigned int k = len + seed + n;
88487 + unsigned long long p;
88488 +
88489 + while (len >= 8) {
88490 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
88491 + len -= 8;
88492 + }
88493 + if (len >= 4) {
88494 + cwmixb(key4[0]) key4 += 1;
88495 + len -= 4;
88496 + }
88497 + if (len)
88498 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
88499 + cwmixb(h ^ (k + n));
88500 + return k ^ h;
88501 +
88502 +#undef cwfold
88503 +#undef cwmixa
88504 +#undef cwmixb
88505 +}
88506 +
88507 +static inline unsigned int get_hash_num(const char *fndecl, const char *tree_codes, unsigned int len, unsigned int seed)
88508 +{
88509 + unsigned int fn = CrapWow(fndecl, strlen(fndecl), seed) & 0xffff;
88510 + unsigned int codes = CrapWow(tree_codes, len, seed) & 0xffff;
88511 + return fn ^ codes;
88512 +}
88513 +
88514 +static inline tree get_original_function_decl(tree fndecl)
88515 +{
88516 + if (DECL_ABSTRACT_ORIGIN(fndecl))
88517 + return DECL_ABSTRACT_ORIGIN(fndecl);
88518 + return fndecl;
88519 +}
88520 +
88521 +static inline gimple get_def_stmt(const_tree node)
88522 +{
88523 + gcc_assert(node != NULL_TREE);
88524 + gcc_assert(TREE_CODE(node) == SSA_NAME);
88525 + return SSA_NAME_DEF_STMT(node);
88526 +}
88527 +
88528 +static unsigned char get_tree_code(const_tree type)
88529 +{
88530 + switch (TREE_CODE(type)) {
88531 + case ARRAY_TYPE:
88532 + return 0;
88533 + case BOOLEAN_TYPE:
88534 + return 1;
88535 + case ENUMERAL_TYPE:
88536 + return 2;
88537 + case FUNCTION_TYPE:
88538 + return 3;
88539 + case INTEGER_TYPE:
88540 + return 4;
88541 + case POINTER_TYPE:
88542 + return 5;
88543 + case RECORD_TYPE:
88544 + return 6;
88545 + case UNION_TYPE:
88546 + return 7;
88547 + case VOID_TYPE:
88548 + return 8;
88549 + case REAL_TYPE:
88550 + return 9;
88551 + case VECTOR_TYPE:
88552 + return 10;
88553 + case REFERENCE_TYPE:
88554 + return 11;
88555 + case OFFSET_TYPE:
88556 + return 12;
88557 + case COMPLEX_TYPE:
88558 + return 13;
88559 + default:
88560 + debug_tree((tree)type);
88561 + gcc_unreachable();
88562 + }
88563 +}
88564 +
88565 +static size_t add_type_codes(const_tree type, unsigned char *tree_codes, size_t len)
88566 +{
88567 + gcc_assert(type != NULL_TREE);
88568 +
88569 + while (type && len < CODES_LIMIT) {
88570 + tree_codes[len] = get_tree_code(type);
88571 + len++;
88572 + type = TREE_TYPE(type);
88573 + }
88574 + return len;
88575 +}
88576 +
88577 +static unsigned int get_function_decl(const_tree fndecl, unsigned char *tree_codes)
88578 +{
88579 + const_tree arg, result, arg_field, type = TREE_TYPE(fndecl);
88580 + enum tree_code code = TREE_CODE(type);
88581 + size_t len = 0;
88582 +
88583 + gcc_assert(code == FUNCTION_TYPE || code == METHOD_TYPE);
88584 +
88585 + arg = TYPE_ARG_TYPES(type);
88586 + // skip builtins __builtin_constant_p
88587 + if (!arg && DECL_BUILT_IN(fndecl))
88588 + return 0;
88589 +
88590 + if (TREE_CODE_CLASS(code) == tcc_type)
88591 + result = type;
88592 + else
88593 + result = DECL_RESULT(fndecl);
88594 +
88595 + gcc_assert(result != NULL_TREE);
88596 + len = add_type_codes(TREE_TYPE(result), tree_codes, len);
88597 +
88598 + if (arg == NULL_TREE) {
88599 + gcc_assert(CODE_CONTAINS_STRUCT(TREE_CODE(fndecl), TS_DECL_NON_COMMON));
88600 + arg_field = DECL_ARGUMENT_FLD(fndecl);
88601 + if (arg_field == NULL_TREE)
88602 + return 0;
88603 + arg = TREE_TYPE(arg_field);
88604 + len = add_type_codes(arg, tree_codes, len);
88605 + gcc_assert(len != 0);
88606 + return len;
88607 + }
88608 +
88609 + gcc_assert(arg != NULL_TREE && TREE_CODE(arg) == TREE_LIST);
88610 + while (arg && len < CODES_LIMIT) {
88611 + len = add_type_codes(TREE_VALUE(arg), tree_codes, len);
88612 + arg = TREE_CHAIN(arg);
88613 + }
88614 +
88615 + gcc_assert(len != 0);
88616 + return len;
88617 +}
88618 +
88619 +static const struct size_overflow_hash *get_function_hash(tree fndecl)
88620 +{
88621 + unsigned int hash;
88622 + const struct size_overflow_hash *entry;
88623 + unsigned char tree_codes[CODES_LIMIT];
88624 + size_t len;
88625 + const char *func_name = get_asm_name(fndecl);
88626 +
88627 + len = get_function_decl(fndecl, tree_codes);
88628 + if (len == 0)
88629 + return NULL;
88630 +
88631 + hash = get_hash_num(func_name, (const char*) tree_codes, len, 0);
88632 +
88633 + entry = size_overflow_hash[hash];
88634 + while (entry) {
88635 + if (!strcmp(entry->name, func_name))
88636 + return entry;
88637 + entry = entry->next;
88638 + }
88639 +
88640 + return NULL;
88641 +}
88642 +
88643 +static void check_arg_type(const_tree arg)
88644 +{
88645 + const_tree type = TREE_TYPE(arg);
88646 + enum tree_code code = TREE_CODE(type);
88647 +
88648 + gcc_assert(code == INTEGER_TYPE || code == ENUMERAL_TYPE ||
88649 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == VOID_TYPE) ||
88650 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == INTEGER_TYPE));
88651 +}
88652 +
88653 +static int find_arg_number(const_tree arg, tree func)
88654 +{
88655 + tree var;
88656 + unsigned int argnum = 1;
88657 +
88658 + if (TREE_CODE(arg) == SSA_NAME)
88659 + arg = SSA_NAME_VAR(arg);
88660 +
88661 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var)) {
88662 + if (strcmp(NAME(arg), NAME(var))) {
88663 + argnum++;
88664 + continue;
88665 + }
88666 + check_arg_type(var);
88667 + return argnum;
88668 + }
88669 + gcc_unreachable();
88670 +}
88671 +
88672 +static tree create_new_var(tree type)
88673 +{
88674 + tree new_var = create_tmp_var(type, "cicus");
88675 +
88676 + add_referenced_var(new_var);
88677 + mark_sym_for_renaming(new_var);
88678 + return new_var;
88679 +}
88680 +
88681 +static gimple create_binary_assign(enum tree_code code, gimple stmt, tree rhs1, tree rhs2)
88682 +{
88683 + gimple assign;
88684 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
88685 + tree type = TREE_TYPE(rhs1);
88686 + tree lhs = create_new_var(type);
88687 +
88688 + gcc_assert(types_compatible_p(type, TREE_TYPE(rhs2)));
88689 + assign = gimple_build_assign_with_ops(code, lhs, rhs1, rhs2);
88690 + gimple_set_lhs(assign, make_ssa_name(lhs, assign));
88691 +
88692 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
88693 + update_stmt(assign);
88694 + gimple_set_plf(assign, MY_STMT, true);
88695 + return assign;
88696 +}
88697 +
88698 +static bool is_bool(const_tree node)
88699 +{
88700 + const_tree type;
88701 +
88702 + if (node == NULL_TREE)
88703 + return false;
88704 +
88705 + type = TREE_TYPE(node);
88706 + if (!INTEGRAL_TYPE_P(type))
88707 + return false;
88708 + if (TREE_CODE(type) == BOOLEAN_TYPE)
88709 + return true;
88710 + if (TYPE_PRECISION(type) == 1)
88711 + return true;
88712 + return false;
88713 +}
88714 +
88715 +static tree cast_a_tree(tree type, tree var)
88716 +{
88717 + gcc_assert(type != NULL_TREE);
88718 + gcc_assert(var != NULL_TREE);
88719 + gcc_assert(fold_convertible_p(type, var));
88720 +
88721 + return fold_convert(type, var);
88722 +}
88723 +
88724 +static gimple build_cast_stmt(tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before)
88725 +{
88726 + gimple assign;
88727 +
88728 + gcc_assert(dst_type != NULL_TREE && rhs != NULL_TREE);
88729 + if (gsi_end_p(*gsi) && before == AFTER_STMT)
88730 + gcc_unreachable();
88731 +
88732 + if (lhs == CREATE_NEW_VAR)
88733 + lhs = create_new_var(dst_type);
88734 +
88735 + assign = gimple_build_assign(lhs, cast_a_tree(dst_type, rhs));
88736 +
88737 + if (!gsi_end_p(*gsi)) {
88738 + location_t loc = gimple_location(gsi_stmt(*gsi));
88739 + gimple_set_location(assign, loc);
88740 + }
88741 +
88742 + gimple_set_lhs(assign, make_ssa_name(lhs, assign));
88743 +
88744 + if (before)
88745 + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
88746 + else
88747 + gsi_insert_after(gsi, assign, GSI_NEW_STMT);
88748 + update_stmt(assign);
88749 + gimple_set_plf(assign, MY_STMT, true);
88750 +
88751 + return assign;
88752 +}
88753 +
88754 +static tree cast_to_new_size_overflow_type(gimple stmt, tree rhs, tree size_overflow_type, bool before)
88755 +{
88756 + gimple assign;
88757 + gimple_stmt_iterator gsi;
88758 +
88759 + if (rhs == NULL_TREE)
88760 + return NULL_TREE;
88761 +
88762 + if (types_compatible_p(TREE_TYPE(rhs), size_overflow_type) && gimple_plf(stmt, MY_STMT))
88763 + return rhs;
88764 +
88765 + gsi = gsi_for_stmt(stmt);
88766 + assign = build_cast_stmt(size_overflow_type, rhs, CREATE_NEW_VAR, &gsi, before);
88767 + gimple_set_plf(assign, MY_STMT, true);
88768 + return gimple_get_lhs(assign);
88769 +}
88770 +
88771 +static tree cast_to_TI_type(gimple stmt, tree node)
88772 +{
88773 + gimple_stmt_iterator gsi;
88774 + gimple cast_stmt;
88775 + tree type = TREE_TYPE(node);
88776 +
88777 + if (types_compatible_p(type, intTI_type_node))
88778 + return node;
88779 +
88780 + gsi = gsi_for_stmt(stmt);
88781 + cast_stmt = build_cast_stmt(intTI_type_node, node, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
88782 + gimple_set_plf(cast_stmt, MY_STMT, true);
88783 + return gimple_get_lhs(cast_stmt);
88784 +}
88785 +
88786 +static tree create_assign(struct pointer_set_t *visited, gimple oldstmt, tree rhs1, bool before)
88787 +{
88788 + tree lhs;
88789 + gimple_stmt_iterator gsi;
88790 +
88791 + if (rhs1 == NULL_TREE) {
88792 + debug_gimple_stmt(oldstmt);
88793 + error("%s: rhs1 is NULL_TREE", __func__);
88794 + gcc_unreachable();
88795 + }
88796 +
88797 + if (gimple_code(oldstmt) == GIMPLE_ASM)
88798 + lhs = rhs1;
88799 + else
88800 + lhs = gimple_get_lhs(oldstmt);
88801 +
88802 + gsi = gsi_for_stmt(oldstmt);
88803 + pointer_set_insert(visited, oldstmt);
88804 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
88805 + basic_block next_bb, cur_bb;
88806 + const_edge e;
88807 +
88808 + gcc_assert(before == false);
88809 + gcc_assert(stmt_can_throw_internal(oldstmt));
88810 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
88811 + gcc_assert(!gsi_end_p(gsi));
88812 +
88813 + cur_bb = gimple_bb(oldstmt);
88814 + next_bb = cur_bb->next_bb;
88815 + e = find_edge(cur_bb, next_bb);
88816 + gcc_assert(e != NULL);
88817 + gcc_assert(e->flags & EDGE_FALLTHRU);
88818 +
88819 + gsi = gsi_after_labels(next_bb);
88820 + gcc_assert(!gsi_end_p(gsi));
88821 +
88822 + before = true;
88823 + oldstmt = gsi_stmt(gsi);
88824 + }
88825 +
88826 + return cast_to_new_size_overflow_type(oldstmt, rhs1, get_size_overflow_type(oldstmt, lhs), before);
88827 +}
88828 +
88829 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3)
88830 +{
88831 + gimple stmt;
88832 + gimple_stmt_iterator gsi;
88833 + tree size_overflow_type, new_var, lhs = gimple_get_lhs(oldstmt);
88834 +
88835 + if (gimple_plf(oldstmt, MY_STMT))
88836 + return lhs;
88837 +
88838 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
88839 + rhs1 = gimple_assign_rhs1(oldstmt);
88840 + rhs1 = create_assign(visited, oldstmt, rhs1, BEFORE_STMT);
88841 + }
88842 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
88843 + rhs2 = gimple_assign_rhs2(oldstmt);
88844 + rhs2 = create_assign(visited, oldstmt, rhs2, BEFORE_STMT);
88845 + }
88846 +
88847 + stmt = gimple_copy(oldstmt);
88848 + gimple_set_location(stmt, gimple_location(oldstmt));
88849 + gimple_set_plf(stmt, MY_STMT, true);
88850 +
88851 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
88852 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
88853 +
88854 + size_overflow_type = get_size_overflow_type(oldstmt, node);
88855 +
88856 + if (is_bool(lhs))
88857 + new_var = SSA_NAME_VAR(lhs);
88858 + else
88859 + new_var = create_new_var(size_overflow_type);
88860 + new_var = make_ssa_name(new_var, stmt);
88861 + gimple_set_lhs(stmt, new_var);
88862 +
88863 + if (rhs1 != NULL_TREE) {
88864 + if (!gimple_assign_cast_p(oldstmt) && TREE_CODE_CLASS(gimple_assign_rhs_code(oldstmt)) != tcc_comparison)
88865 + rhs1 = cast_a_tree(size_overflow_type, rhs1);
88866 + gimple_assign_set_rhs1(stmt, rhs1);
88867 + }
88868 +
88869 + if (rhs2 != NULL_TREE)
88870 + gimple_assign_set_rhs2(stmt, rhs2);
88871 +#if BUILDING_GCC_VERSION >= 4007
88872 + if (rhs3 != NULL_TREE)
88873 + gimple_assign_set_rhs3(stmt, rhs3);
88874 +#endif
88875 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
88876 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
88877 +
88878 + gsi = gsi_for_stmt(oldstmt);
88879 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
88880 + update_stmt(stmt);
88881 + pointer_set_insert(visited, oldstmt);
88882 + return gimple_get_lhs(stmt);
88883 +}
88884 +
88885 +static gimple overflow_create_phi_node(gimple oldstmt, tree result)
88886 +{
88887 + basic_block bb;
88888 + gimple phi;
88889 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
88890 +
88891 + bb = gsi_bb(gsi);
88892 +
88893 + phi = create_phi_node(result, bb);
88894 + gsi = gsi_last(phi_nodes(bb));
88895 + gsi_remove(&gsi, false);
88896 +
88897 + gsi = gsi_for_stmt(oldstmt);
88898 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
88899 + gimple_set_bb(phi, bb);
88900 + gimple_set_plf(phi, MY_STMT, true);
88901 + return phi;
88902 +}
88903 +
88904 +static basic_block create_a_first_bb(void)
88905 +{
88906 + basic_block first_bb;
88907 +
88908 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
88909 + if (dom_info_available_p(CDI_DOMINATORS))
88910 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR);
88911 + return first_bb;
88912 +}
88913 +
88914 +static tree cast_old_phi_arg(gimple oldstmt, tree size_overflow_type, tree arg, tree new_var, unsigned int i)
88915 +{
88916 + basic_block bb;
88917 + const_gimple newstmt;
88918 + gimple_stmt_iterator gsi;
88919 + bool before = BEFORE_STMT;
88920 +
88921 + if (TREE_CODE(arg) == SSA_NAME && gimple_code(get_def_stmt(arg)) != GIMPLE_NOP) {
88922 + gsi = gsi_for_stmt(get_def_stmt(arg));
88923 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, AFTER_STMT);
88924 + return gimple_get_lhs(newstmt);
88925 + }
88926 +
88927 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
88928 + gsi = gsi_after_labels(bb);
88929 + if (bb->index == 0) {
88930 + bb = create_a_first_bb();
88931 + gsi = gsi_start_bb(bb);
88932 + }
88933 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, before);
88934 + return gimple_get_lhs(newstmt);
88935 +}
88936 +
88937 +static const_gimple handle_new_phi_arg(const_tree arg, tree new_var, tree new_rhs)
88938 +{
88939 + gimple newstmt;
88940 + gimple_stmt_iterator gsi;
88941 + void (*gsi_insert)(gimple_stmt_iterator *, gimple, enum gsi_iterator_update);
88942 + gimple def_newstmt = get_def_stmt(new_rhs);
88943 +
88944 + gsi_insert = gsi_insert_after;
88945 + gsi = gsi_for_stmt(def_newstmt);
88946 +
88947 + switch (gimple_code(get_def_stmt(arg))) {
88948 + case GIMPLE_PHI:
88949 + newstmt = gimple_build_assign(new_var, new_rhs);
88950 + gsi = gsi_after_labels(gimple_bb(def_newstmt));
88951 + gsi_insert = gsi_insert_before;
88952 + break;
88953 + case GIMPLE_ASM:
88954 + case GIMPLE_CALL:
88955 + newstmt = gimple_build_assign(new_var, new_rhs);
88956 + break;
88957 + case GIMPLE_ASSIGN:
88958 + newstmt = gimple_build_assign(new_var, gimple_get_lhs(def_newstmt));
88959 + break;
88960 + default:
88961 + /* unknown gimple_code (handle_build_new_phi_arg) */
88962 + gcc_unreachable();
88963 + }
88964 +
88965 + gimple_set_lhs(newstmt, make_ssa_name(new_var, newstmt));
88966 + gsi_insert(&gsi, newstmt, GSI_NEW_STMT);
88967 + gimple_set_plf(newstmt, MY_STMT, true);
88968 + update_stmt(newstmt);
88969 + return newstmt;
88970 +}
88971 +
88972 +static tree build_new_phi_arg(struct pointer_set_t *visited, tree size_overflow_type, tree arg, tree new_var)
88973 +{
88974 + const_gimple newstmt;
88975 + gimple def_stmt;
88976 + tree new_rhs;
88977 +
88978 + new_rhs = expand(visited, arg);
88979 + if (new_rhs == NULL_TREE)
88980 + return NULL_TREE;
88981 +
88982 + def_stmt = get_def_stmt(new_rhs);
88983 + if (gimple_code(def_stmt) == GIMPLE_NOP)
88984 + return NULL_TREE;
88985 + new_rhs = cast_to_new_size_overflow_type(def_stmt, new_rhs, size_overflow_type, AFTER_STMT);
88986 +
88987 + newstmt = handle_new_phi_arg(arg, new_var, new_rhs);
88988 + return gimple_get_lhs(newstmt);
88989 +}
88990 +
88991 +static tree build_new_phi(struct pointer_set_t *visited, tree orig_result)
88992 +{
88993 + gimple phi, oldstmt = get_def_stmt(orig_result);
88994 + tree new_result, size_overflow_type;
88995 + unsigned int i;
88996 + unsigned int n = gimple_phi_num_args(oldstmt);
88997 +
88998 + size_overflow_type = get_size_overflow_type(oldstmt, orig_result);
88999 +
89000 + new_result = create_new_var(size_overflow_type);
89001 +
89002 + pointer_set_insert(visited, oldstmt);
89003 + phi = overflow_create_phi_node(oldstmt, new_result);
89004 + for (i = 0; i < n; i++) {
89005 + tree arg, lhs;
89006 +
89007 + arg = gimple_phi_arg_def(oldstmt, i);
89008 + if (is_gimple_constant(arg))
89009 + arg = cast_a_tree(size_overflow_type, arg);
89010 + lhs = build_new_phi_arg(visited, size_overflow_type, arg, new_result);
89011 + if (lhs == NULL_TREE)
89012 + lhs = cast_old_phi_arg(oldstmt, size_overflow_type, arg, new_result, i);
89013 + add_phi_arg(phi, lhs, gimple_phi_arg_edge(oldstmt, i), gimple_location(oldstmt));
89014 + }
89015 +
89016 + update_stmt(phi);
89017 + return gimple_phi_result(phi);
89018 +}
89019 +
89020 +static tree change_assign_rhs(gimple stmt, const_tree orig_rhs, tree new_rhs)
89021 +{
89022 + const_gimple assign;
89023 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
89024 + tree origtype = TREE_TYPE(orig_rhs);
89025 +
89026 + gcc_assert(gimple_code(stmt) == GIMPLE_ASSIGN);
89027 +
89028 + assign = build_cast_stmt(origtype, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
89029 + return gimple_get_lhs(assign);
89030 +}
89031 +
89032 +static void change_rhs1(gimple stmt, tree new_rhs1)
89033 +{
89034 + tree assign_rhs;
89035 + const_tree rhs = gimple_assign_rhs1(stmt);
89036 +
89037 + assign_rhs = change_assign_rhs(stmt, rhs, new_rhs1);
89038 + gimple_assign_set_rhs1(stmt, assign_rhs);
89039 + update_stmt(stmt);
89040 +}
89041 +
89042 +static bool check_mode_type(const_gimple stmt)
89043 +{
89044 + const_tree lhs = gimple_get_lhs(stmt);
89045 + const_tree lhs_type = TREE_TYPE(lhs);
89046 + const_tree rhs_type = TREE_TYPE(gimple_assign_rhs1(stmt));
89047 + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
89048 + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
89049 +
89050 + if (rhs_mode == lhs_mode && TYPE_UNSIGNED(rhs_type) == TYPE_UNSIGNED(lhs_type))
89051 + return false;
89052 +
89053 + if (rhs_mode == SImode && lhs_mode == DImode && (TYPE_UNSIGNED(rhs_type) || !TYPE_UNSIGNED(lhs_type)))
89054 + return false;
89055 +
89056 + return true;
89057 +}
89058 +
89059 +static bool check_undefined_integer_operation(const_gimple stmt)
89060 +{
89061 + const_gimple def_stmt;
89062 + const_tree lhs = gimple_get_lhs(stmt);
89063 + const_tree rhs1 = gimple_assign_rhs1(stmt);
89064 + const_tree rhs1_type = TREE_TYPE(rhs1);
89065 + const_tree lhs_type = TREE_TYPE(lhs);
89066 +
89067 + if (TYPE_MODE(rhs1_type) != TYPE_MODE(lhs_type) || TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
89068 + return false;
89069 +
89070 + def_stmt = get_def_stmt(rhs1);
89071 + if (gimple_code(def_stmt) != GIMPLE_ASSIGN)
89072 + return false;
89073 +
89074 + if (gimple_assign_rhs_code(def_stmt) != MINUS_EXPR)
89075 + return false;
89076 + return true;
89077 +}
89078 +
89079 +static bool is_a_cast_and_const_overflow(const_tree no_const_rhs)
89080 +{
89081 + const_tree rhs1, lhs, rhs1_type, lhs_type;
89082 + enum machine_mode lhs_mode, rhs_mode;
89083 + gimple def_stmt = get_def_stmt(no_const_rhs);
89084 +
89085 + if (!gimple_assign_cast_p(def_stmt))
89086 + return false;
89087 +
89088 + rhs1 = gimple_assign_rhs1(def_stmt);
89089 + lhs = gimple_get_lhs(def_stmt);
89090 + rhs1_type = TREE_TYPE(rhs1);
89091 + lhs_type = TREE_TYPE(lhs);
89092 + rhs_mode = TYPE_MODE(rhs1_type);
89093 + lhs_mode = TYPE_MODE(lhs_type);
89094 + if (TYPE_UNSIGNED(lhs_type) == TYPE_UNSIGNED(rhs1_type) || lhs_mode != rhs_mode)
89095 + return false;
89096 +
89097 + return true;
89098 +}
89099 +
89100 +static tree handle_unary_rhs(struct pointer_set_t *visited, gimple stmt)
89101 +{
89102 + tree size_overflow_type, lhs = gimple_get_lhs(stmt);
89103 + tree new_rhs1, rhs1 = gimple_assign_rhs1(stmt);
89104 + const_tree rhs1_type = TREE_TYPE(rhs1);
89105 + const_tree lhs_type = TREE_TYPE(lhs);
89106 +
89107 + new_rhs1 = expand(visited, rhs1);
89108 +
89109 + if (new_rhs1 == NULL_TREE || TREE_CODE(rhs1_type) == POINTER_TYPE)
89110 + return create_assign(visited, stmt, lhs, AFTER_STMT);
89111 +
89112 + if (gimple_plf(stmt, MY_STMT))
89113 + return lhs;
89114 +
89115 + if (gimple_plf(stmt, NO_CAST_CHECK))
89116 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
89117 +
89118 + if (gimple_assign_rhs_code(stmt) == BIT_NOT_EXPR) {
89119 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
89120 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
89121 + check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
89122 + return create_assign(visited, stmt, lhs, AFTER_STMT);
89123 + }
89124 +
89125 + if (!gimple_assign_cast_p(stmt) || check_undefined_integer_operation(stmt))
89126 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
89127 +
89128 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
89129 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
89130 +
89131 + change_rhs1(stmt, new_rhs1);
89132 + check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
89133 +
89134 + rhs1 = gimple_assign_rhs1(stmt);
89135 + rhs1_type = TREE_TYPE(rhs1);
89136 + if (TYPE_UNSIGNED(rhs1_type) != TYPE_UNSIGNED(lhs_type))
89137 + return create_assign(visited, stmt, rhs1, AFTER_STMT);
89138 +
89139 + if (!check_mode_type(stmt))
89140 + return create_assign(visited, stmt, lhs, AFTER_STMT);
89141 +
89142 + size_overflow_type = get_size_overflow_type(stmt, lhs);
89143 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
89144 +
89145 + check_size_overflow(stmt, size_overflow_type, new_rhs1, lhs, BEFORE_STMT);
89146 +
89147 + return create_assign(visited, stmt, lhs, AFTER_STMT);
89148 +}
89149 +
89150 +static tree handle_unary_ops(struct pointer_set_t *visited, tree lhs)
89151 +{
89152 + gimple def_stmt = get_def_stmt(lhs);
89153 + tree rhs1 = gimple_assign_rhs1(def_stmt);
89154 +
89155 + if (is_gimple_constant(rhs1))
89156 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
89157 +
89158 + gcc_assert(TREE_CODE(rhs1) != COND_EXPR);
89159 + switch (TREE_CODE(rhs1)) {
89160 + case SSA_NAME:
89161 + return handle_unary_rhs(visited, def_stmt);
89162 + case ARRAY_REF:
89163 + case BIT_FIELD_REF:
89164 + case ADDR_EXPR:
89165 + case COMPONENT_REF:
89166 + case INDIRECT_REF:
89167 +#if BUILDING_GCC_VERSION >= 4006
89168 + case MEM_REF:
89169 +#endif
89170 + case PARM_DECL:
89171 + case TARGET_MEM_REF:
89172 + case VAR_DECL:
89173 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
89174 +
89175 + default:
89176 + debug_gimple_stmt(def_stmt);
89177 + debug_tree(rhs1);
89178 + gcc_unreachable();
89179 + }
89180 +}
89181 +
89182 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
89183 +{
89184 + gimple cond_stmt;
89185 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
89186 +
89187 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
89188 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
89189 + update_stmt(cond_stmt);
89190 +}
89191 +
89192 +static tree create_string_param(tree string)
89193 +{
89194 + tree i_type, a_type;
89195 + const int length = TREE_STRING_LENGTH(string);
89196 +
89197 + gcc_assert(length > 0);
89198 +
89199 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
89200 + a_type = build_array_type(char_type_node, i_type);
89201 +
89202 + TREE_TYPE(string) = a_type;
89203 + TREE_CONSTANT(string) = 1;
89204 + TREE_READONLY(string) = 1;
89205 +
89206 + return build1(ADDR_EXPR, ptr_type_node, string);
89207 +}
89208 +
89209 +static void insert_cond_result(basic_block bb_true, const_gimple stmt, const_tree arg, bool min)
89210 +{
89211 + gimple func_stmt;
89212 + const_gimple def_stmt;
89213 + const_tree loc_line;
89214 + tree loc_file, ssa_name, current_func;
89215 + expanded_location xloc;
89216 + char ssa_name_buf[256];
89217 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
89218 +
89219 + def_stmt = get_def_stmt(arg);
89220 + xloc = expand_location(gimple_location(def_stmt));
89221 +
89222 + if (!gimple_has_location(def_stmt)) {
89223 + xloc = expand_location(gimple_location(stmt));
89224 + if (!gimple_has_location(stmt))
89225 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
89226 + }
89227 +
89228 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
89229 +
89230 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
89231 + loc_file = create_string_param(loc_file);
89232 +
89233 + current_func = build_string(NAME_LEN(current_function_decl) + 1, NAME(current_function_decl));
89234 + current_func = create_string_param(current_func);
89235 +
89236 + snprintf(ssa_name_buf, 256, "%s_%u (%s)\n", NAME(SSA_NAME_VAR(arg)), SSA_NAME_VERSION(arg), min ? "min" : "max");
89237 + ssa_name = build_string(256, ssa_name_buf);
89238 + ssa_name = create_string_param(ssa_name);
89239 +
89240 + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
89241 + func_stmt = gimple_build_call(report_size_overflow_decl, 4, loc_file, loc_line, current_func, ssa_name);
89242 +
89243 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
89244 +}
89245 +
89246 +static void __unused print_the_code_insertions(const_gimple stmt)
89247 +{
89248 + location_t loc = gimple_location(stmt);
89249 +
89250 + inform(loc, "Integer size_overflow check applied here.");
89251 +}
89252 +
89253 +static void insert_check_size_overflow(gimple stmt, enum tree_code cond_code, tree arg, tree type_value, bool before, bool min)
89254 +{
89255 + basic_block cond_bb, join_bb, bb_true;
89256 + edge e;
89257 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
89258 +
89259 + cond_bb = gimple_bb(stmt);
89260 + if (before)
89261 + gsi_prev(&gsi);
89262 + if (gsi_end_p(gsi))
89263 + e = split_block_after_labels(cond_bb);
89264 + else
89265 + e = split_block(cond_bb, gsi_stmt(gsi));
89266 + cond_bb = e->src;
89267 + join_bb = e->dest;
89268 + e->flags = EDGE_FALSE_VALUE;
89269 + e->probability = REG_BR_PROB_BASE;
89270 +
89271 + bb_true = create_empty_bb(cond_bb);
89272 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
89273 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
89274 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
89275 +
89276 + if (dom_info_available_p(CDI_DOMINATORS)) {
89277 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
89278 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
89279 + }
89280 +
89281 + if (current_loops != NULL) {
89282 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
89283 + add_bb_to_loop(bb_true, cond_bb->loop_father);
89284 + }
89285 +
89286 + insert_cond(cond_bb, arg, cond_code, type_value);
89287 + insert_cond_result(bb_true, stmt, arg, min);
89288 +
89289 +// print_the_code_insertions(stmt);
89290 +}
89291 +
89292 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before)
89293 +{
89294 + const_tree rhs_type = TREE_TYPE(rhs);
89295 + tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min;
89296 +
89297 + gcc_assert(rhs_type != NULL_TREE);
89298 + if (TREE_CODE(rhs_type) == POINTER_TYPE)
89299 + return;
89300 +
89301 + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == BOOLEAN_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
89302 +
89303 + type_max = cast_a_tree(size_overflow_type, TYPE_MAX_VALUE(rhs_type));
89304 + type_min = cast_a_tree(size_overflow_type, TYPE_MIN_VALUE(rhs_type));
89305 +
89306 + gcc_assert(!TREE_OVERFLOW(type_max));
89307 +
89308 + cast_rhs_type = TREE_TYPE(cast_rhs);
89309 + type_max_type = TREE_TYPE(type_max);
89310 + type_min_type = TREE_TYPE(type_min);
89311 + gcc_assert(types_compatible_p(cast_rhs_type, type_max_type));
89312 + gcc_assert(types_compatible_p(type_max_type, type_min_type));
89313 +
89314 + insert_check_size_overflow(stmt, GT_EXPR, cast_rhs, type_max, before, false);
89315 + insert_check_size_overflow(stmt, LT_EXPR, cast_rhs, type_min, before, true);
89316 +}
89317 +
89318 +static tree get_size_overflow_type_for_intentional_overflow(gimple def_stmt, tree change_rhs)
89319 +{
89320 + gimple change_rhs_def_stmt;
89321 + tree lhs = gimple_get_lhs(def_stmt);
89322 + tree lhs_type = TREE_TYPE(lhs);
89323 + tree rhs1_type = TREE_TYPE(gimple_assign_rhs1(def_stmt));
89324 + tree rhs2_type = TREE_TYPE(gimple_assign_rhs2(def_stmt));
89325 +
89326 + if (change_rhs == NULL_TREE)
89327 + return get_size_overflow_type(def_stmt, lhs);
89328 +
89329 + change_rhs_def_stmt = get_def_stmt(change_rhs);
89330 +
89331 + if (TREE_CODE_CLASS(gimple_assign_rhs_code(def_stmt)) == tcc_comparison)
89332 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
89333 +
89334 + if (gimple_assign_rhs_code(def_stmt) == LSHIFT_EXPR)
89335 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
89336 +
89337 + if (gimple_assign_rhs_code(def_stmt) == RSHIFT_EXPR)
89338 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
89339 +
89340 + if (!types_compatible_p(lhs_type, rhs1_type) || !useless_type_conversion_p(rhs1_type, rhs2_type)) {
89341 + debug_gimple_stmt(def_stmt);
89342 + gcc_unreachable();
89343 + }
89344 +
89345 + return get_size_overflow_type(def_stmt, lhs);
89346 +}
89347 +
89348 +static bool is_a_constant_overflow(const_gimple stmt, const_tree rhs)
89349 +{
89350 + if (gimple_assign_rhs_code(stmt) == MIN_EXPR)
89351 + return false;
89352 + if (!is_gimple_constant(rhs))
89353 + return false;
89354 + return true;
89355 +}
89356 +
89357 +static bool is_subtraction_special(const_gimple stmt)
89358 +{
89359 + gimple rhs1_def_stmt, rhs2_def_stmt;
89360 + const_tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1, rhs1_def_stmt_lhs, rhs2_def_stmt_lhs;
89361 + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode, rhs1_def_stmt_lhs_mode, rhs2_def_stmt_lhs_mode;
89362 + const_tree rhs1 = gimple_assign_rhs1(stmt);
89363 + const_tree rhs2 = gimple_assign_rhs2(stmt);
89364 +
89365 + if (is_gimple_constant(rhs1) || is_gimple_constant(rhs2))
89366 + return false;
89367 +
89368 + gcc_assert(TREE_CODE(rhs1) == SSA_NAME && TREE_CODE(rhs2) == SSA_NAME);
89369 +
89370 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
89371 + return false;
89372 +
89373 + rhs1_def_stmt = get_def_stmt(rhs1);
89374 + rhs2_def_stmt = get_def_stmt(rhs2);
89375 + if (!gimple_assign_cast_p(rhs1_def_stmt) || !gimple_assign_cast_p(rhs2_def_stmt))
89376 + return false;
89377 +
89378 + rhs1_def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
89379 + rhs2_def_stmt_rhs1 = gimple_assign_rhs1(rhs2_def_stmt);
89380 + rhs1_def_stmt_lhs = gimple_get_lhs(rhs1_def_stmt);
89381 + rhs2_def_stmt_lhs = gimple_get_lhs(rhs2_def_stmt);
89382 + rhs1_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_rhs1));
89383 + rhs2_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_rhs1));
89384 + rhs1_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_lhs));
89385 + rhs2_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_lhs));
89386 + if (GET_MODE_BITSIZE(rhs1_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs1_def_stmt_lhs_mode))
89387 + return false;
89388 + if (GET_MODE_BITSIZE(rhs2_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs2_def_stmt_lhs_mode))
89389 + return false;
89390 +
89391 + gimple_set_plf(rhs1_def_stmt, NO_CAST_CHECK, true);
89392 + gimple_set_plf(rhs2_def_stmt, NO_CAST_CHECK, true);
89393 + return true;
89394 +}
89395 +
89396 +static tree get_def_stmt_rhs(const_tree var)
89397 +{
89398 + tree rhs1, def_stmt_rhs1;
89399 + gimple rhs1_def_stmt, def_stmt_rhs1_def_stmt, def_stmt;
89400 +
89401 + def_stmt = get_def_stmt(var);
89402 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP && gimple_plf(def_stmt, MY_STMT) && gimple_assign_cast_p(def_stmt));
89403 +
89404 + rhs1 = gimple_assign_rhs1(def_stmt);
89405 + rhs1_def_stmt = get_def_stmt(rhs1);
89406 + gcc_assert(gimple_code(rhs1_def_stmt) != GIMPLE_NOP);
89407 + if (!gimple_assign_cast_p(rhs1_def_stmt))
89408 + return rhs1;
89409 +
89410 + def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
89411 + def_stmt_rhs1_def_stmt = get_def_stmt(def_stmt_rhs1);
89412 +
89413 + switch (gimple_code(def_stmt_rhs1_def_stmt)) {
89414 + case GIMPLE_CALL:
89415 + case GIMPLE_NOP:
89416 + case GIMPLE_ASM:
89417 + return def_stmt_rhs1;
89418 + case GIMPLE_ASSIGN:
89419 + return rhs1;
89420 + default:
89421 + debug_gimple_stmt(def_stmt_rhs1_def_stmt);
89422 + gcc_unreachable();
89423 + }
89424 +}
89425 +
89426 +static tree handle_integer_truncation(struct pointer_set_t *visited, const_tree lhs)
89427 +{
89428 + tree new_rhs1, new_rhs2;
89429 + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
89430 + gimple assign, stmt = get_def_stmt(lhs);
89431 + tree rhs1 = gimple_assign_rhs1(stmt);
89432 + tree rhs2 = gimple_assign_rhs2(stmt);
89433 +
89434 + if (!is_subtraction_special(stmt))
89435 + return NULL_TREE;
89436 +
89437 + new_rhs1 = expand(visited, rhs1);
89438 + new_rhs2 = expand(visited, rhs2);
89439 +
89440 + new_rhs1_def_stmt_rhs1 = get_def_stmt_rhs(new_rhs1);
89441 + new_rhs2_def_stmt_rhs1 = get_def_stmt_rhs(new_rhs2);
89442 +
89443 + if (!types_compatible_p(TREE_TYPE(new_rhs1_def_stmt_rhs1), TREE_TYPE(new_rhs2_def_stmt_rhs1))) {
89444 + new_rhs1_def_stmt_rhs1 = cast_to_TI_type(stmt, new_rhs1_def_stmt_rhs1);
89445 + new_rhs2_def_stmt_rhs1 = cast_to_TI_type(stmt, new_rhs2_def_stmt_rhs1);
89446 + }
89447 +
89448 + assign = create_binary_assign(MINUS_EXPR, stmt, new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1);
89449 + new_lhs = gimple_get_lhs(assign);
89450 + check_size_overflow(assign, TREE_TYPE(new_lhs), new_lhs, rhs1, AFTER_STMT);
89451 +
89452 + return dup_assign(visited, stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
89453 +}
89454 +
89455 +static bool is_a_neg_overflow(const_gimple stmt, const_tree rhs)
89456 +{
89457 + const_gimple def_stmt;
89458 +
89459 + if (TREE_CODE(rhs) != SSA_NAME)
89460 + return false;
89461 +
89462 + if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
89463 + return false;
89464 +
89465 + def_stmt = get_def_stmt(rhs);
89466 + if (gimple_code(def_stmt) != GIMPLE_ASSIGN || gimple_assign_rhs_code(def_stmt) != BIT_NOT_EXPR)
89467 + return false;
89468 +
89469 + return true;
89470 +}
89471 +
89472 +static tree handle_intentional_overflow(struct pointer_set_t *visited, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs1, tree new_rhs2)
89473 +{
89474 + tree new_rhs, size_overflow_type, orig_rhs;
89475 + void (*gimple_assign_set_rhs)(gimple, tree);
89476 + tree rhs1 = gimple_assign_rhs1(stmt);
89477 + tree rhs2 = gimple_assign_rhs2(stmt);
89478 + tree lhs = gimple_get_lhs(stmt);
89479 +
89480 + if (change_rhs == NULL_TREE)
89481 + return create_assign(visited, stmt, lhs, AFTER_STMT);
89482 +
89483 + if (new_rhs2 == NULL_TREE) {
89484 + size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs1);
89485 + new_rhs2 = cast_a_tree(size_overflow_type, rhs2);
89486 + orig_rhs = rhs1;
89487 + gimple_assign_set_rhs = &gimple_assign_set_rhs1;
89488 + } else {
89489 + size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs2);
89490 + new_rhs1 = cast_a_tree(size_overflow_type, rhs1);
89491 + orig_rhs = rhs2;
89492 + gimple_assign_set_rhs = &gimple_assign_set_rhs2;
89493 + }
89494 +
89495 + change_rhs = cast_to_new_size_overflow_type(stmt, change_rhs, size_overflow_type, BEFORE_STMT);
89496 +
89497 + if (check_overflow)
89498 + check_size_overflow(stmt, size_overflow_type, change_rhs, orig_rhs, BEFORE_STMT);
89499 +
89500 + new_rhs = change_assign_rhs(stmt, orig_rhs, change_rhs);
89501 + gimple_assign_set_rhs(stmt, new_rhs);
89502 + update_stmt(stmt);
89503 +
89504 + return create_assign(visited, stmt, lhs, AFTER_STMT);
89505 +}
89506 +
89507 +static tree handle_binary_ops(struct pointer_set_t *visited, tree lhs)
89508 +{
89509 + tree rhs1, rhs2, new_lhs;
89510 + gimple def_stmt = get_def_stmt(lhs);
89511 + tree new_rhs1 = NULL_TREE;
89512 + tree new_rhs2 = NULL_TREE;
89513 +
89514 + rhs1 = gimple_assign_rhs1(def_stmt);
89515 + rhs2 = gimple_assign_rhs2(def_stmt);
89516 +
89517 + /* no DImode/TImode division in the 32/64 bit kernel */
89518 + switch (gimple_assign_rhs_code(def_stmt)) {
89519 + case RDIV_EXPR:
89520 + case TRUNC_DIV_EXPR:
89521 + case CEIL_DIV_EXPR:
89522 + case FLOOR_DIV_EXPR:
89523 + case ROUND_DIV_EXPR:
89524 + case TRUNC_MOD_EXPR:
89525 + case CEIL_MOD_EXPR:
89526 + case FLOOR_MOD_EXPR:
89527 + case ROUND_MOD_EXPR:
89528 + case EXACT_DIV_EXPR:
89529 + case POINTER_PLUS_EXPR:
89530 + case BIT_AND_EXPR:
89531 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
89532 + default:
89533 + break;
89534 + }
89535 +
89536 + new_lhs = handle_integer_truncation(visited, lhs);
89537 + if (new_lhs != NULL_TREE)
89538 + return new_lhs;
89539 +
89540 + if (TREE_CODE(rhs1) == SSA_NAME)
89541 + new_rhs1 = expand(visited, rhs1);
89542 + if (TREE_CODE(rhs2) == SSA_NAME)
89543 + new_rhs2 = expand(visited, rhs2);
89544 +
89545 + if (is_a_neg_overflow(def_stmt, rhs2))
89546 + return handle_intentional_overflow(visited, true, def_stmt, new_rhs1, new_rhs1, NULL_TREE);
89547 + if (is_a_neg_overflow(def_stmt, rhs1))
89548 + return handle_intentional_overflow(visited, true, def_stmt, new_rhs2, NULL_TREE, new_rhs2);
89549 +
89550 + if (is_a_constant_overflow(def_stmt, rhs2))
89551 + return handle_intentional_overflow(visited, !is_a_cast_and_const_overflow(rhs1), def_stmt, new_rhs1, new_rhs1, NULL_TREE);
89552 + if (is_a_constant_overflow(def_stmt, rhs1))
89553 + return handle_intentional_overflow(visited, !is_a_cast_and_const_overflow(rhs2), def_stmt, new_rhs2, NULL_TREE, new_rhs2);
89554 +
89555 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
89556 +}
89557 +
89558 +#if BUILDING_GCC_VERSION >= 4007
89559 +static tree get_new_rhs(struct pointer_set_t *visited, tree size_overflow_type, tree rhs)
89560 +{
89561 + if (is_gimple_constant(rhs))
89562 + return cast_a_tree(size_overflow_type, rhs);
89563 + if (TREE_CODE(rhs) != SSA_NAME)
89564 + return NULL_TREE;
89565 + return expand(visited, rhs);
89566 +}
89567 +
89568 +static tree handle_ternary_ops(struct pointer_set_t *visited, tree lhs)
89569 +{
89570 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
89571 + gimple def_stmt = get_def_stmt(lhs);
89572 +
89573 + size_overflow_type = get_size_overflow_type(def_stmt, lhs);
89574 +
89575 + rhs1 = gimple_assign_rhs1(def_stmt);
89576 + rhs2 = gimple_assign_rhs2(def_stmt);
89577 + rhs3 = gimple_assign_rhs3(def_stmt);
89578 + new_rhs1 = get_new_rhs(visited, size_overflow_type, rhs1);
89579 + new_rhs2 = get_new_rhs(visited, size_overflow_type, rhs2);
89580 + new_rhs3 = get_new_rhs(visited, size_overflow_type, rhs3);
89581 +
89582 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, new_rhs3);
89583 +}
89584 +#endif
89585 +
89586 +static tree get_size_overflow_type(gimple stmt, const_tree node)
89587 +{
89588 + const_tree type;
89589 +
89590 + gcc_assert(node != NULL_TREE);
89591 +
89592 + type = TREE_TYPE(node);
89593 +
89594 + if (gimple_plf(stmt, MY_STMT))
89595 + return TREE_TYPE(node);
89596 +
89597 + switch (TYPE_MODE(type)) {
89598 + case QImode:
89599 + return (TYPE_UNSIGNED(type)) ? unsigned_intHI_type_node : intHI_type_node;
89600 + case HImode:
89601 + return (TYPE_UNSIGNED(type)) ? unsigned_intSI_type_node : intSI_type_node;
89602 + case SImode:
89603 + return (TYPE_UNSIGNED(type)) ? unsigned_intDI_type_node : intDI_type_node;
89604 + case DImode:
89605 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
89606 + return (TYPE_UNSIGNED(type)) ? unsigned_intDI_type_node : intDI_type_node;
89607 + return (TYPE_UNSIGNED(type)) ? unsigned_intTI_type_node : intTI_type_node;
89608 + default:
89609 + debug_tree((tree)node);
89610 + error("%s: unsupported gcc configuration.", __func__);
89611 + gcc_unreachable();
89612 + }
89613 +}
89614 +
89615 +static tree expand_visited(gimple def_stmt)
89616 +{
89617 + const_gimple next_stmt;
89618 + gimple_stmt_iterator gsi = gsi_for_stmt(def_stmt);
89619 +
89620 + gsi_next(&gsi);
89621 + next_stmt = gsi_stmt(gsi);
89622 +
89623 + gcc_assert(gimple_plf((gimple)next_stmt, MY_STMT));
89624 +
89625 + switch (gimple_code(next_stmt)) {
89626 + case GIMPLE_ASSIGN:
89627 + return gimple_get_lhs(next_stmt);
89628 + case GIMPLE_PHI:
89629 + return gimple_phi_result(next_stmt);
89630 + case GIMPLE_CALL:
89631 + return gimple_call_lhs(next_stmt);
89632 + default:
89633 + return NULL_TREE;
89634 + }
89635 +}
89636 +
89637 +static tree expand(struct pointer_set_t *visited, tree lhs)
89638 +{
89639 + gimple def_stmt;
89640 + enum tree_code code = TREE_CODE(TREE_TYPE(lhs));
89641 +
89642 + if (is_gimple_constant(lhs))
89643 + return NULL_TREE;
89644 +
89645 + if (TREE_CODE(lhs) == ADDR_EXPR)
89646 + return NULL_TREE;
89647 +
89648 + if (code == REAL_TYPE)
89649 + return NULL_TREE;
89650 +
89651 + gcc_assert(code == INTEGER_TYPE || code == POINTER_TYPE || code == BOOLEAN_TYPE || code == ENUMERAL_TYPE);
89652 +
89653 +
89654 + def_stmt = get_def_stmt(lhs);
89655 +
89656 + if (!def_stmt)
89657 + return NULL_TREE;
89658 +
89659 + if (gimple_plf(def_stmt, MY_STMT))
89660 + return lhs;
89661 +
89662 + if (pointer_set_contains(visited, def_stmt))
89663 + return expand_visited(def_stmt);
89664 +
89665 + switch (gimple_code(def_stmt)) {
89666 + case GIMPLE_NOP:
89667 + return NULL_TREE;
89668 + case GIMPLE_PHI:
89669 + return build_new_phi(visited, lhs);
89670 + case GIMPLE_CALL:
89671 + case GIMPLE_ASM:
89672 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
89673 + case GIMPLE_ASSIGN:
89674 + switch (gimple_num_ops(def_stmt)) {
89675 + case 2:
89676 + return handle_unary_ops(visited, lhs);
89677 + case 3:
89678 + return handle_binary_ops(visited, lhs);
89679 +#if BUILDING_GCC_VERSION >= 4007
89680 + case 4:
89681 + return handle_ternary_ops(visited, lhs);
89682 +#endif
89683 + }
89684 + default:
89685 + debug_gimple_stmt(def_stmt);
89686 + error("%s: unknown gimple code", __func__);
89687 + gcc_unreachable();
89688 + }
89689 +}
89690 +
89691 +static void change_function_arg(gimple stmt, const_tree origarg, unsigned int argnum, tree newarg)
89692 +{
89693 + const_gimple assign;
89694 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
89695 + tree origtype = TREE_TYPE(origarg);
89696 +
89697 + gcc_assert(gimple_code(stmt) == GIMPLE_CALL);
89698 +
89699 + assign = build_cast_stmt(origtype, newarg, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
89700 +
89701 + gimple_call_set_arg(stmt, argnum, gimple_get_lhs(assign));
89702 + update_stmt(stmt);
89703 +}
89704 +
89705 +static bool get_function_arg(unsigned int* argnum, const_tree fndecl)
89706 +{
89707 + const char *origid;
89708 + tree arg;
89709 + const_tree origarg;
89710 +
89711 + if (!DECL_ABSTRACT_ORIGIN(fndecl))
89712 + return true;
89713 +
89714 + origarg = DECL_ARGUMENTS(DECL_ABSTRACT_ORIGIN(fndecl));
89715 + while (origarg && *argnum) {
89716 + (*argnum)--;
89717 + origarg = TREE_CHAIN(origarg);
89718 + }
89719 +
89720 + gcc_assert(*argnum == 0);
89721 +
89722 + gcc_assert(origarg != NULL_TREE);
89723 + origid = NAME(origarg);
89724 + *argnum = 0;
89725 + for (arg = DECL_ARGUMENTS(fndecl); arg; arg = TREE_CHAIN(arg)) {
89726 + if (!strcmp(origid, NAME(arg)))
89727 + return true;
89728 + (*argnum)++;
89729 + }
89730 + return false;
89731 +}
89732 +
89733 +static bool skip_types(const_tree var)
89734 +{
89735 + switch (TREE_CODE(var)) {
89736 + case ADDR_EXPR:
89737 +#if BUILDING_GCC_VERSION >= 4006
89738 + case MEM_REF:
89739 +#endif
89740 + case ARRAY_REF:
89741 + case BIT_FIELD_REF:
89742 + case INDIRECT_REF:
89743 + case TARGET_MEM_REF:
89744 + case VAR_DECL:
89745 + return true;
89746 + default:
89747 + break;
89748 + }
89749 + return false;
89750 +}
89751 +
89752 +static bool walk_phi(struct pointer_set_t *visited, const_tree result)
89753 +{
89754 + gimple phi = get_def_stmt(result);
89755 + unsigned int i, n = gimple_phi_num_args(phi);
89756 +
89757 + if (!phi)
89758 + return false;
89759 +
89760 + pointer_set_insert(visited, phi);
89761 + for (i = 0; i < n; i++) {
89762 + const_tree arg = gimple_phi_arg_def(phi, i);
89763 + if (pre_expand(visited, arg))
89764 + return true;
89765 + }
89766 + return false;
89767 +}
89768 +
89769 +static bool walk_unary_ops(struct pointer_set_t *visited, const_tree lhs)
89770 +{
89771 + gimple def_stmt = get_def_stmt(lhs);
89772 + const_tree rhs;
89773 +
89774 + if (!def_stmt)
89775 + return false;
89776 +
89777 + rhs = gimple_assign_rhs1(def_stmt);
89778 + if (pre_expand(visited, rhs))
89779 + return true;
89780 + return false;
89781 +}
89782 +
89783 +static bool walk_binary_ops(struct pointer_set_t *visited, const_tree lhs)
89784 +{
89785 + bool rhs1_found, rhs2_found;
89786 + gimple def_stmt = get_def_stmt(lhs);
89787 + const_tree rhs1, rhs2;
89788 +
89789 + if (!def_stmt)
89790 + return false;
89791 +
89792 + rhs1 = gimple_assign_rhs1(def_stmt);
89793 + rhs2 = gimple_assign_rhs2(def_stmt);
89794 + rhs1_found = pre_expand(visited, rhs1);
89795 + rhs2_found = pre_expand(visited, rhs2);
89796 +
89797 + return rhs1_found || rhs2_found;
89798 +}
89799 +
89800 +static const_tree search_field_decl(const_tree comp_ref)
89801 +{
89802 + const_tree field = NULL_TREE;
89803 + unsigned int i, len = TREE_OPERAND_LENGTH(comp_ref);
89804 +
89805 + for (i = 0; i < len; i++) {
89806 + field = TREE_OPERAND(comp_ref, i);
89807 + if (TREE_CODE(field) == FIELD_DECL)
89808 + break;
89809 + }
89810 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
89811 + return field;
89812 +}
89813 +
89814 +static enum marked mark_status(const_tree fndecl, unsigned int argnum)
89815 +{
89816 + const_tree attr, p;
89817 +
89818 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(fndecl));
89819 + if (!attr || !TREE_VALUE(attr))
89820 + return MARKED_NO;
89821 +
89822 + p = TREE_VALUE(attr);
89823 + if (!TREE_INT_CST_LOW(TREE_VALUE(p)))
89824 + return MARKED_NOT_INTENTIONAL;
89825 +
89826 + do {
89827 + if (argnum == TREE_INT_CST_LOW(TREE_VALUE(p)))
89828 + return MARKED_YES;
89829 + p = TREE_CHAIN(p);
89830 + } while (p);
89831 +
89832 + return MARKED_NO;
89833 +}
89834 +
89835 +static void print_missing_msg(tree func, unsigned int argnum)
89836 +{
89837 + unsigned int new_hash;
89838 + size_t len;
89839 + unsigned char tree_codes[CODES_LIMIT];
89840 + location_t loc = DECL_SOURCE_LOCATION(func);
89841 + const char *curfunc = get_asm_name(func);
89842 +
89843 + len = get_function_decl(func, tree_codes);
89844 + new_hash = get_hash_num(curfunc, (const char *) tree_codes, len, 0);
89845 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%u+%u+", curfunc, curfunc, argnum, new_hash);
89846 +}
89847 +
89848 +static unsigned int search_missing_attribute(const_tree arg)
89849 +{
89850 + const_tree type = TREE_TYPE(arg);
89851 + tree func = get_original_function_decl(current_function_decl);
89852 + unsigned int argnum;
89853 + const struct size_overflow_hash *hash;
89854 +
89855 + gcc_assert(TREE_CODE(arg) != COMPONENT_REF);
89856 +
89857 + if (TREE_CODE(type) == POINTER_TYPE)
89858 + return 0;
89859 +
89860 + argnum = find_arg_number(arg, func);
89861 + if (argnum == 0)
89862 + return 0;
89863 +
89864 + if (lookup_attribute("size_overflow", DECL_ATTRIBUTES(func)))
89865 + return argnum;
89866 +
89867 + hash = get_function_hash(func);
89868 + if (!hash || !(hash->param & (1U << argnum))) {
89869 + print_missing_msg(func, argnum);
89870 + return 0;
89871 + }
89872 + return argnum;
89873 +}
89874 +
89875 +static bool is_already_marked(const_tree lhs)
89876 +{
89877 + unsigned int argnum;
89878 + const_tree fndecl;
89879 +
89880 + argnum = search_missing_attribute(lhs);
89881 + fndecl = get_original_function_decl(current_function_decl);
89882 + if (argnum && mark_status(fndecl, argnum) == MARKED_YES)
89883 + return true;
89884 + return false;
89885 +}
89886 +
89887 +static bool pre_expand(struct pointer_set_t *visited, const_tree lhs)
89888 +{
89889 + const_gimple def_stmt;
89890 +
89891 + if (is_gimple_constant(lhs))
89892 + return false;
89893 +
89894 + if (skip_types(lhs))
89895 + return false;
89896 +
89897 + if (TREE_CODE(lhs) == PARM_DECL)
89898 + return is_already_marked(lhs);
89899 +
89900 + if (TREE_CODE(lhs) == COMPONENT_REF) {
89901 + const_tree field, attr;
89902 +
89903 + field = search_field_decl(lhs);
89904 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(field));
89905 + if (!attr || !TREE_VALUE(attr))
89906 + return false;
89907 + return true;
89908 + }
89909 +
89910 + def_stmt = get_def_stmt(lhs);
89911 +
89912 + if (!def_stmt)
89913 + return false;
89914 +
89915 + if (pointer_set_contains(visited, def_stmt))
89916 + return false;
89917 +
89918 + switch (gimple_code(def_stmt)) {
89919 + case GIMPLE_NOP:
89920 + if (TREE_CODE(SSA_NAME_VAR(lhs)) == PARM_DECL)
89921 + return is_already_marked(lhs);
89922 + return false;
89923 + case GIMPLE_PHI:
89924 + return walk_phi(visited, lhs);
89925 + case GIMPLE_CALL:
89926 + case GIMPLE_ASM:
89927 + return false;
89928 + case GIMPLE_ASSIGN:
89929 + switch (gimple_num_ops(def_stmt)) {
89930 + case 2:
89931 + return walk_unary_ops(visited, lhs);
89932 + case 3:
89933 + return walk_binary_ops(visited, lhs);
89934 + }
89935 + default:
89936 + debug_gimple_stmt((gimple)def_stmt);
89937 + error("%s: unknown gimple code", __func__);
89938 + gcc_unreachable();
89939 + }
89940 +}
89941 +
89942 +static bool search_attributes(tree fndecl, const_tree arg, unsigned int argnum)
89943 +{
89944 + struct pointer_set_t *visited;
89945 + bool is_found;
89946 + enum marked is_marked;
89947 + location_t loc;
89948 +
89949 + visited = pointer_set_create();
89950 + is_found = pre_expand(visited, arg);
89951 + pointer_set_destroy(visited);
89952 +
89953 + is_marked = mark_status(fndecl, argnum + 1);
89954 + if ((is_found && is_marked == MARKED_YES) || is_marked == MARKED_NOT_INTENTIONAL)
89955 + return true;
89956 +
89957 + if (is_found) {
89958 + loc = DECL_SOURCE_LOCATION(fndecl);
89959 + inform(loc, "The intentional_overflow attribute is missing from +%s+%u+", get_asm_name(fndecl), argnum + 1);
89960 + return true;
89961 + }
89962 + return false;
89963 +}
89964 +
89965 +static void handle_function_arg(gimple stmt, tree fndecl, unsigned int argnum)
89966 +{
89967 + struct pointer_set_t *visited;
89968 + tree arg, newarg;
89969 + bool match;
89970 +
89971 + match = get_function_arg(&argnum, fndecl);
89972 + if (!match)
89973 + return;
89974 + gcc_assert(gimple_call_num_args(stmt) > argnum);
89975 + arg = gimple_call_arg(stmt, argnum);
89976 + if (arg == NULL_TREE)
89977 + return;
89978 +
89979 + if (is_gimple_constant(arg))
89980 + return;
89981 +
89982 + if (search_attributes(fndecl, arg, argnum))
89983 + return;
89984 +
89985 + if (TREE_CODE(arg) != SSA_NAME)
89986 + return;
89987 +
89988 + check_arg_type(arg);
89989 +
89990 + visited = pointer_set_create();
89991 + newarg = expand(visited, arg);
89992 + pointer_set_destroy(visited);
89993 +
89994 + if (newarg == NULL_TREE)
89995 + return;
89996 +
89997 + change_function_arg(stmt, arg, argnum, newarg);
89998 +
89999 + check_size_overflow(stmt, TREE_TYPE(newarg), newarg, arg, BEFORE_STMT);
90000 +}
90001 +
90002 +static void handle_function_by_attribute(gimple stmt, const_tree attr, tree fndecl)
90003 +{
90004 + tree p = TREE_VALUE(attr);
90005 + do {
90006 + handle_function_arg(stmt, fndecl, TREE_INT_CST_LOW(TREE_VALUE(p))-1);
90007 + p = TREE_CHAIN(p);
90008 + } while (p);
90009 +}
90010 +
90011 +static void handle_function_by_hash(gimple stmt, tree fndecl)
90012 +{
90013 + tree orig_fndecl;
90014 + unsigned int num;
90015 + const struct size_overflow_hash *hash;
90016 +
90017 + orig_fndecl = get_original_function_decl(fndecl);
90018 + if (C_DECL_IMPLICIT(orig_fndecl))
90019 + return;
90020 + hash = get_function_hash(orig_fndecl);
90021 + if (!hash)
90022 + return;
90023 +
90024 + for (num = 1; num <= MAX_PARAM; num++)
90025 + if (hash->param & (1U << num))
90026 + handle_function_arg(stmt, fndecl, num - 1);
90027 +}
90028 +
90029 +static void set_plf_false(void)
90030 +{
90031 + basic_block bb;
90032 +
90033 + FOR_ALL_BB(bb) {
90034 + gimple_stmt_iterator si;
90035 +
90036 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
90037 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
90038 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
90039 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
90040 + }
90041 +}
90042 +
90043 +static unsigned int handle_function(void)
90044 +{
90045 + basic_block next, bb = ENTRY_BLOCK_PTR->next_bb;
90046 +
90047 + set_plf_false();
90048 +
90049 + do {
90050 + gimple_stmt_iterator gsi;
90051 + next = bb->next_bb;
90052 +
90053 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
90054 + tree fndecl, attr;
90055 + gimple stmt = gsi_stmt(gsi);
90056 +
90057 + if (!(is_gimple_call(stmt)))
90058 + continue;
90059 + fndecl = gimple_call_fndecl(stmt);
90060 + if (fndecl == NULL_TREE)
90061 + continue;
90062 + if (gimple_call_num_args(stmt) == 0)
90063 + continue;
90064 + attr = lookup_attribute("size_overflow", DECL_ATTRIBUTES(fndecl));
90065 + if (!attr || !TREE_VALUE(attr))
90066 + handle_function_by_hash(stmt, fndecl);
90067 + else
90068 + handle_function_by_attribute(stmt, attr, fndecl);
90069 + gsi = gsi_for_stmt(stmt);
90070 + next = gimple_bb(stmt)->next_bb;
90071 + }
90072 + bb = next;
90073 + } while (bb);
90074 + return 0;
90075 +}
90076 +
90077 +static struct gimple_opt_pass size_overflow_pass = {
90078 + .pass = {
90079 + .type = GIMPLE_PASS,
90080 + .name = "size_overflow",
90081 + .gate = NULL,
90082 + .execute = handle_function,
90083 + .sub = NULL,
90084 + .next = NULL,
90085 + .static_pass_number = 0,
90086 + .tv_id = TV_NONE,
90087 + .properties_required = PROP_cfg | PROP_referenced_vars,
90088 + .properties_provided = 0,
90089 + .properties_destroyed = 0,
90090 + .todo_flags_start = 0,
90091 + .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
90092 + }
90093 +};
90094 +
90095 +static void start_unit_callback(void __unused *gcc_data, void __unused *user_data)
90096 +{
90097 + tree fntype;
90098 +
90099 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
90100 +
90101 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func, const char *ssa_var)
90102 + fntype = build_function_type_list(void_type_node,
90103 + const_char_ptr_type_node,
90104 + unsigned_type_node,
90105 + const_char_ptr_type_node,
90106 + const_char_ptr_type_node,
90107 + NULL_TREE);
90108 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
90109 +
90110 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
90111 + TREE_PUBLIC(report_size_overflow_decl) = 1;
90112 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
90113 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
90114 + TREE_THIS_VOLATILE(report_size_overflow_decl) = 1;
90115 +}
90116 +
90117 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
90118 +{
90119 + int i;
90120 + const char * const plugin_name = plugin_info->base_name;
90121 + const int argc = plugin_info->argc;
90122 + const struct plugin_argument * const argv = plugin_info->argv;
90123 + bool enable = true;
90124 +
90125 + struct register_pass_info size_overflow_pass_info = {
90126 + .pass = &size_overflow_pass.pass,
90127 + .reference_pass_name = "ssa",
90128 + .ref_pass_instance_number = 1,
90129 + .pos_op = PASS_POS_INSERT_AFTER
90130 + };
90131 +
90132 + if (!plugin_default_version_check(version, &gcc_version)) {
90133 + error(G_("incompatible gcc/plugin versions"));
90134 + return 1;
90135 + }
90136 +
90137 + for (i = 0; i < argc; ++i) {
90138 + if (!strcmp(argv[i].key, "no-size-overflow")) {
90139 + enable = false;
90140 + continue;
90141 + }
90142 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
90143 + }
90144 +
90145 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
90146 + if (enable) {
90147 + register_callback("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
90148 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &size_overflow_pass_info);
90149 + }
90150 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
90151 +
90152 + return 0;
90153 +}
90154 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
90155 new file mode 100644
90156 index 0000000..38d2014
90157 --- /dev/null
90158 +++ b/tools/gcc/stackleak_plugin.c
90159 @@ -0,0 +1,313 @@
90160 +/*
90161 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
90162 + * Licensed under the GPL v2
90163 + *
90164 + * Note: the choice of the license means that the compilation process is
90165 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
90166 + * but for the kernel it doesn't matter since it doesn't link against
90167 + * any of the gcc libraries
90168 + *
90169 + * gcc plugin to help implement various PaX features
90170 + *
90171 + * - track lowest stack pointer
90172 + *
90173 + * TODO:
90174 + * - initialize all local variables
90175 + *
90176 + * BUGS:
90177 + * - none known
90178 + */
90179 +#include "gcc-plugin.h"
90180 +#include "config.h"
90181 +#include "system.h"
90182 +#include "coretypes.h"
90183 +#include "tree.h"
90184 +#include "tree-pass.h"
90185 +#include "flags.h"
90186 +#include "intl.h"
90187 +#include "toplev.h"
90188 +#include "plugin.h"
90189 +//#include "expr.h" where are you...
90190 +#include "diagnostic.h"
90191 +#include "plugin-version.h"
90192 +#include "tm.h"
90193 +#include "function.h"
90194 +#include "basic-block.h"
90195 +#include "gimple.h"
90196 +#include "rtl.h"
90197 +#include "emit-rtl.h"
90198 +
90199 +extern void print_gimple_stmt(FILE *, gimple, int, int);
90200 +
90201 +int plugin_is_GPL_compatible;
90202 +
90203 +static int track_frame_size = -1;
90204 +static const char track_function[] = "pax_track_stack";
90205 +static const char check_function[] = "pax_check_alloca";
90206 +static bool init_locals;
90207 +
90208 +static struct plugin_info stackleak_plugin_info = {
90209 + .version = "201203140940",
90210 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
90211 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
90212 +};
90213 +
90214 +static bool gate_stackleak_track_stack(void);
90215 +static unsigned int execute_stackleak_tree_instrument(void);
90216 +static unsigned int execute_stackleak_final(void);
90217 +
90218 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
90219 + .pass = {
90220 + .type = GIMPLE_PASS,
90221 + .name = "stackleak_tree_instrument",
90222 + .gate = gate_stackleak_track_stack,
90223 + .execute = execute_stackleak_tree_instrument,
90224 + .sub = NULL,
90225 + .next = NULL,
90226 + .static_pass_number = 0,
90227 + .tv_id = TV_NONE,
90228 + .properties_required = PROP_gimple_leh | PROP_cfg,
90229 + .properties_provided = 0,
90230 + .properties_destroyed = 0,
90231 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
90232 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
90233 + }
90234 +};
90235 +
90236 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
90237 + .pass = {
90238 + .type = RTL_PASS,
90239 + .name = "stackleak_final",
90240 + .gate = gate_stackleak_track_stack,
90241 + .execute = execute_stackleak_final,
90242 + .sub = NULL,
90243 + .next = NULL,
90244 + .static_pass_number = 0,
90245 + .tv_id = TV_NONE,
90246 + .properties_required = 0,
90247 + .properties_provided = 0,
90248 + .properties_destroyed = 0,
90249 + .todo_flags_start = 0,
90250 + .todo_flags_finish = TODO_dump_func
90251 + }
90252 +};
90253 +
90254 +static bool gate_stackleak_track_stack(void)
90255 +{
90256 + return track_frame_size >= 0;
90257 +}
90258 +
90259 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
90260 +{
90261 + gimple check_alloca;
90262 + tree fntype, fndecl, alloca_size;
90263 +
90264 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
90265 + fndecl = build_fn_decl(check_function, fntype);
90266 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
90267 +
90268 + // insert call to void pax_check_alloca(unsigned long size)
90269 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
90270 + check_alloca = gimple_build_call(fndecl, 1, alloca_size);
90271 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
90272 +}
90273 +
90274 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
90275 +{
90276 + gimple track_stack;
90277 + tree fntype, fndecl;
90278 +
90279 + fntype = build_function_type_list(void_type_node, NULL_TREE);
90280 + fndecl = build_fn_decl(track_function, fntype);
90281 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
90282 +
90283 + // insert call to void pax_track_stack(void)
90284 + track_stack = gimple_build_call(fndecl, 0);
90285 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
90286 +}
90287 +
90288 +#if BUILDING_GCC_VERSION == 4005
90289 +static bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
90290 +{
90291 + tree fndecl;
90292 +
90293 + if (!is_gimple_call(stmt))
90294 + return false;
90295 + fndecl = gimple_call_fndecl(stmt);
90296 + if (!fndecl)
90297 + return false;
90298 + if (DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
90299 + return false;
90300 +// print_node(stderr, "pax", fndecl, 4);
90301 + return DECL_FUNCTION_CODE(fndecl) == code;
90302 +}
90303 +#endif
90304 +
90305 +static bool is_alloca(gimple stmt)
90306 +{
90307 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
90308 + return true;
90309 +
90310 +#if BUILDING_GCC_VERSION >= 4007
90311 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
90312 + return true;
90313 +#endif
90314 +
90315 + return false;
90316 +}
90317 +
90318 +static unsigned int execute_stackleak_tree_instrument(void)
90319 +{
90320 + basic_block bb, entry_bb;
90321 + bool prologue_instrumented = false, is_leaf = true;
90322 +
90323 + entry_bb = ENTRY_BLOCK_PTR_FOR_FUNCTION(cfun)->next_bb;
90324 +
90325 + // 1. loop through BBs and GIMPLE statements
90326 + FOR_EACH_BB(bb) {
90327 + gimple_stmt_iterator gsi;
90328 +
90329 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
90330 + gimple stmt;
90331 +
90332 + stmt = gsi_stmt(gsi);
90333 +
90334 + if (is_gimple_call(stmt))
90335 + is_leaf = false;
90336 +
90337 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
90338 + if (!is_alloca(stmt))
90339 + continue;
90340 +
90341 + // 2. insert stack overflow check before each __builtin_alloca call
90342 + stackleak_check_alloca(&gsi);
90343 +
90344 + // 3. insert track call after each __builtin_alloca call
90345 + stackleak_add_instrumentation(&gsi);
90346 + if (bb == entry_bb)
90347 + prologue_instrumented = true;
90348 + }
90349 + }
90350 +
90351 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
90352 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
90353 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
90354 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
90355 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
90356 + return 0;
90357 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
90358 + return 0;
90359 +
90360 + // 4. insert track call at the beginning
90361 + if (!prologue_instrumented) {
90362 + gimple_stmt_iterator gsi;
90363 +
90364 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
90365 + if (dom_info_available_p(CDI_DOMINATORS))
90366 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
90367 + gsi = gsi_start_bb(bb);
90368 + stackleak_add_instrumentation(&gsi);
90369 + }
90370 +
90371 + return 0;
90372 +}
90373 +
90374 +static unsigned int execute_stackleak_final(void)
90375 +{
90376 + rtx insn;
90377 +
90378 + if (cfun->calls_alloca)
90379 + return 0;
90380 +
90381 + // keep calls only if function frame is big enough
90382 + if (get_frame_size() >= track_frame_size)
90383 + return 0;
90384 +
90385 + // 1. find pax_track_stack calls
90386 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
90387 + // 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))
90388 + rtx body;
90389 +
90390 + if (!CALL_P(insn))
90391 + continue;
90392 + body = PATTERN(insn);
90393 + if (GET_CODE(body) != CALL)
90394 + continue;
90395 + body = XEXP(body, 0);
90396 + if (GET_CODE(body) != MEM)
90397 + continue;
90398 + body = XEXP(body, 0);
90399 + if (GET_CODE(body) != SYMBOL_REF)
90400 + continue;
90401 + if (strcmp(XSTR(body, 0), track_function))
90402 + continue;
90403 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
90404 + // 2. delete call
90405 + insn = delete_insn_and_edges(insn);
90406 +#if BUILDING_GCC_VERSION >= 4007
90407 + if (GET_CODE(insn) == NOTE && NOTE_KIND(insn) == NOTE_INSN_CALL_ARG_LOCATION)
90408 + insn = delete_insn_and_edges(insn);
90409 +#endif
90410 + }
90411 +
90412 +// print_simple_rtl(stderr, get_insns());
90413 +// print_rtl(stderr, get_insns());
90414 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
90415 +
90416 + return 0;
90417 +}
90418 +
90419 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
90420 +{
90421 + const char * const plugin_name = plugin_info->base_name;
90422 + const int argc = plugin_info->argc;
90423 + const struct plugin_argument * const argv = plugin_info->argv;
90424 + int i;
90425 + struct register_pass_info stackleak_tree_instrument_pass_info = {
90426 + .pass = &stackleak_tree_instrument_pass.pass,
90427 +// .reference_pass_name = "tree_profile",
90428 + .reference_pass_name = "optimized",
90429 + .ref_pass_instance_number = 1,
90430 + .pos_op = PASS_POS_INSERT_BEFORE
90431 + };
90432 + struct register_pass_info stackleak_final_pass_info = {
90433 + .pass = &stackleak_final_rtl_opt_pass.pass,
90434 + .reference_pass_name = "final",
90435 + .ref_pass_instance_number = 1,
90436 + .pos_op = PASS_POS_INSERT_BEFORE
90437 + };
90438 +
90439 + if (!plugin_default_version_check(version, &gcc_version)) {
90440 + error(G_("incompatible gcc/plugin versions"));
90441 + return 1;
90442 + }
90443 +
90444 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
90445 +
90446 + for (i = 0; i < argc; ++i) {
90447 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
90448 + if (!argv[i].value) {
90449 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
90450 + continue;
90451 + }
90452 + track_frame_size = atoi(argv[i].value);
90453 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
90454 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
90455 + continue;
90456 + }
90457 + if (!strcmp(argv[i].key, "initialize-locals")) {
90458 + if (argv[i].value) {
90459 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
90460 + continue;
90461 + }
90462 + init_locals = true;
90463 + continue;
90464 + }
90465 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
90466 + }
90467 +
90468 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
90469 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
90470 +
90471 + return 0;
90472 +}
90473 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
90474 index 6789d78..4afd019e 100644
90475 --- a/tools/perf/util/include/asm/alternative-asm.h
90476 +++ b/tools/perf/util/include/asm/alternative-asm.h
90477 @@ -5,4 +5,7 @@
90478
90479 #define altinstruction_entry #
90480
90481 + .macro pax_force_retaddr rip=0, reload=0
90482 + .endm
90483 +
90484 #endif
90485 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
90486 index d617f69..6b445d2 100644
90487 --- a/virt/kvm/kvm_main.c
90488 +++ b/virt/kvm/kvm_main.c
90489 @@ -75,7 +75,7 @@ LIST_HEAD(vm_list);
90490
90491 static cpumask_var_t cpus_hardware_enabled;
90492 static int kvm_usage_count = 0;
90493 -static atomic_t hardware_enable_failed;
90494 +static atomic_unchecked_t hardware_enable_failed;
90495
90496 struct kmem_cache *kvm_vcpu_cache;
90497 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
90498 @@ -715,7 +715,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
90499 /* We can read the guest memory with __xxx_user() later on. */
90500 if (user_alloc &&
90501 ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
90502 - !access_ok(VERIFY_WRITE,
90503 + !__access_ok(VERIFY_WRITE,
90504 (void __user *)(unsigned long)mem->userspace_addr,
90505 mem->memory_size)))
90506 goto out;
90507 @@ -2304,7 +2304,7 @@ static void hardware_enable_nolock(void *junk)
90508
90509 if (r) {
90510 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
90511 - atomic_inc(&hardware_enable_failed);
90512 + atomic_inc_unchecked(&hardware_enable_failed);
90513 printk(KERN_INFO "kvm: enabling virtualization on "
90514 "CPU%d failed\n", cpu);
90515 }
90516 @@ -2358,10 +2358,10 @@ static int hardware_enable_all(void)
90517
90518 kvm_usage_count++;
90519 if (kvm_usage_count == 1) {
90520 - atomic_set(&hardware_enable_failed, 0);
90521 + atomic_set_unchecked(&hardware_enable_failed, 0);
90522 on_each_cpu(hardware_enable_nolock, NULL, 1);
90523
90524 - if (atomic_read(&hardware_enable_failed)) {
90525 + if (atomic_read_unchecked(&hardware_enable_failed)) {
90526 hardware_disable_all_nolock();
90527 r = -EBUSY;
90528 }
90529 @@ -2722,7 +2722,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
90530 kvm_arch_vcpu_put(vcpu);
90531 }
90532
90533 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
90534 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
90535 struct module *module)
90536 {
90537 int r;
90538 @@ -2785,7 +2785,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
90539 if (!vcpu_align)
90540 vcpu_align = __alignof__(struct kvm_vcpu);
90541 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
90542 - 0, NULL);
90543 + SLAB_USERCOPY, NULL);
90544 if (!kvm_vcpu_cache) {
90545 r = -ENOMEM;
90546 goto out_free_3;
90547 @@ -2795,9 +2795,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
90548 if (r)
90549 goto out_free;
90550
90551 - kvm_chardev_ops.owner = module;
90552 - kvm_vm_fops.owner = module;
90553 - kvm_vcpu_fops.owner = module;
90554 + pax_open_kernel();
90555 + *(void **)&kvm_chardev_ops.owner = module;
90556 + *(void **)&kvm_vm_fops.owner = module;
90557 + *(void **)&kvm_vcpu_fops.owner = module;
90558 + pax_close_kernel();
90559
90560 r = misc_register(&kvm_dev);
90561 if (r) {